Exemple #1
0
 def tileimage(self, x, y, scale):
     tile = self.gamemap.tile(x,y)
     tileimage = pygame.Surface((16, 16))
     backgroundpath = tile.background()
     if backgroundpath:
         backgroundimage = self.frontend.tilemaps.get_by_path(backgroundpath)
     else:
         backgroundimage = pygame.Surface((scale, scale))
     if backgroundpath and (tile.revealed() or self.frontend.mode == 'editor'):
         tileimage.blit(backgroundimage,(0,0))
         tileimage = pygame.transform.smoothscale(tileimage, (scale, scale))
         if self.frontend.mode == 'editor':
             tileimage.blit(render_text('%sX%s' %(x,y), size=(self.tilesize/2), color=(0,0,0), font=pygame.font.Font(None,16) ), (self.tilesize/2,self.tilesize/2))
     else:
         if self.frontend.mode == 'editor':
             if y%2 == 0 and x%2 == 0 or y%2 == 1 and x%2 == 1:
                 r, t = 255, 0
             else:
                 r, t = 0, 255
             backgroundimage.fill((r,r,r,0))
             backgroundimage.blit(render_text('%sX%s' %(x,y), size=(self.tilesize/2), color=(t,t,t), font=pygame.font.Font(None,16) ), (1,1))
             tileimage =backgroundimage
         else:
             tileimage.fill((0,0,0,0))
     return tileimage
Exemple #2
0
 def tile_editor(self, x, y, surface):
     surface.blit(render_text('Edit tile', color=(255,0,0)),(280,10))
     minx, miny = self.frontend.rightwindow_rect.x + 10, self.frontend.rightwindow_rect.y + 10
     maxx, maxy = minx + self.frontend.rightwindow_rect.w - 10, self.frontend.rightwindow_rect.h - 10
     te_canenter = checkboxbtn('Player can enter tile ?', self.canenter, (x,y), self.frontend.eventstack,self.frontend.imagecache, pos=(minx + 180,miny + 60))
     te_revealed = checkboxbtn('Tile has been revealed ?', self.revealed, (x,y), self.frontend.eventstack,self.frontend.imagecache, pos=(minx + 180,miny + 90))
     te_canenter.checked = self.gamemap.tile(x,y).canenter()
     te_revealed.checked = self.gamemap.tile(x,y).revealed()
     if self.tile.background():
         self._addtemp('te_rotate', Button('Rotate background', 
             self.rotate, (x,y), self.frontend.eventstack,self.frontend.imagecache, pos=(minx + 180, miny + 120)))
     self._addtemp('te_canenter', te_canenter)
     self._addtemp('te_revealed', te_revealed)
     self._addtemp('te_set_background', Button('Set Background', 
         self.selectbg, (x,y), self.frontend.eventstack,self.frontend.imagecache, pos=(minx + 180, miny + 30)))
     if self.tile.background() and self.tile.canenter():
         te_additem = Button('Add Item', self.additem, [x,y], self.frontend.eventstack,self.frontend.imagecache, pos=(minx,miny + 160))
         te_addnpc = Button('Add NPC', self.addnpc, [x,y], self.frontend.eventstack,self.frontend.imagecache, pos=(minx + 120,miny + 160))
         te_onenter = Button('Events/OnEnter', self.onenter, [x,y], self.frontend.eventstack,self.frontend.imagecache, pos=(minx + 250,miny + 160))
         self._addtemp('te_additem', te_additem)
         self._addtemp('te_addnpc', te_addnpc)
         self._addtemp('te_onenter', te_onenter)
     te_clone_tile = Button('Clone Tile', self.clonetile, [x,y], self.frontend.eventstack,self.frontend.imagecache, pos=(minx,miny + 200))
     self._addtemp('te_clone', te_clone_tile)
     clone_coords = TextInput(
         pygame.Rect(minx + 150,  miny + 200, 100,25),
         16, self.frontend.eventstack, 
         prompt='%sx%s' %(x,y), layer=3)
     self._addtemp('te_clone_coords', clone_coords)
     debug(self.frontend.sprites)
Exemple #3
0
 def layout(self):
     self.image.blit(render_text ('Game directory:', size=24, color=(255,0,0)),(10,10))
     self.gd = TextInput(pygame.Rect(self.rect.x + 220, self.rect.y + 10, self.rect.w-250, 30), 18, self.frontend.eventstack, prompt=self.settingsdata['gamedir'], clearprompt=False, layer=self._layer +1)
     self._addtemp('gamedirinput', self.gd)
     self.image.blit(render_text ('Resolution:', size=24, color=(255,0,0)),(10,60))
     res_left = ButtonArrow(self.resbtn, ['left'], self.frontend.eventstack,self.frontend.imagecache, 'left', pos=(self.rect.x+120,self.rect.y+60), layer=self._layer +1)
     res_right = ButtonArrow(self.resbtn, ['right'], self.frontend.eventstack,self.frontend.imagecache, 'right', pos=(self.rect.x+300,self.rect.y+60), layer=self._layer +1)
     self._addtemp('settings_res_left', res_left)
     self._addtemp('settings_res_right', res_right)
     self.image.blit(render_text ('%s X %s' %self.resolution, size=24, color=(255,0,0)),(170,60))
     self.fullscreenbtn = checkboxbtn('Full screen', self.fullscreen, [], self.frontend.eventstack,self.frontend.imagecache, fontsize=24, pos=(self.rect.x + 10,self.rect.y +100),layer=self._layer +1)
     self.fullscreenbtn.checked = self.settingsdata['fullscreen']        
     self._addtemp('fullscreen', self.fullscreenbtn)
     self.hardwarebtn = checkboxbtn('Hardware rendering(requires fullscreen)', self.hardware, [], self.frontend.eventstack,self.frontend.imagecache,fontsize=24, pos=(self.rect.x + 10,self.rect.y +130),layer=self._layer +1)
     self.hardwarebtn.checked = self.settingsdata['hardware_buffer']
     self._addtemp('hardware rendering', self.hardwarebtn)
     self.image.blit(render_text ('Note: changes only take effect when you restart', size=24, color=(255,0,0)),(10,200))
     save_btn = Button('Save changes', self.save, [], self.frontend.eventstack,self.frontend.imagecache, pos=(self.rect.x + 200,self.rect.y + 250), layer=self._layer +1)
     self._addtemp('savesettings', save_btn)
Exemple #4
0
 def baselayout(self):
     self.lastlayer = 18
     self.image.blit(render_text (self.title, size=32, color=(255,0,0)),(self.rect.w/2 - 20,10))
     split = self.frontend.imagecache['seperator']
     split = pygame.transform.smoothscale(split,(self.frontend.screensize.w -20, 10))
     self.image.blit(split,(10,60))
     save_btn = Button('Save Item', self.save, [], self.frontend.eventstack,self.frontend.imagecache, pos=(self.rect.x +  self.rect.w - 150,self.rect.y + self.rect.h - 50), layer=6)
     load_btn = Button('Load Item', self.load, [], self.frontend.eventstack,self.frontend.imagecache, pos=(self.rect.x +  10,self.rect.y + self.rect.h - 50), layer=6)
     self._addtemp('saveitem', save_btn)
     self._addtemp('loaditem', load_btn)
Exemple #5
0
 def update(self):
     self.image.blit(self.bg, (0,0))
     x = self.mb_rect.x
     y = self.mb_rect.y
     for line in self.journal.read():
         lineimg=render_text(line, 16, (0,0,0))
         y +=  lineimg.get_rect().h
         if y >= self.mb_rect.y + self.mb_rect.h:
             x = self.mb_rect.w/2 + 300
             y = self.mb_rect.y
         self.image.blit(lineimg,(x,y))
Exemple #6
0
 def resbtn(self, direction):
     if direction == 'left':
         if self.respage > 0:
             self.respage -= 1
         else:
             self.respage = len(self.resolutions) -1
     if direction == 'right':
         if self.respage < len(self.resolutions) -1:
             self.respage += 1
         else:
             self.respage = 0    
     self.resolution = self.resolutions[self.respage]
     self.image.blit(self.surface.subsurface(170,60,300,50),(170,60))
     self.image.blit(render_text ('%s X %s' %self.resolution, size=24, color=(255,0,0)),(170,60))
     self.settingsdata['res_x'], self.settingsdata['res_y'] = self.resolution[0], self.resolution[1]     
Exemple #7
0
 def __init__(self, rect, frontend, title, layer=20, items=[],onclose=None, onclose_parms=[], onselect=None,onselect_parms=[], animation='view',can_add=False, can_remove=False,addfrom=[]):
     self._layer = layer
     FloatDialog.__init__(self, rect, frontend, layer=layer)
     self.frontend = frontend
     self.image.blit(render_text (title, size=24, color=(255,0,0)),(10,10))
     self.rect = rect
     self.can_add = can_add
     self.can_remove = can_remove
     self.items = items
     self.addfrom = addfrom
     self.animation = animation
     self.onselect = onselect
     self.onclose = onclose
     self.onclose_parms = onclose_parms
     self.onselect_parms = onselect_parms
     self.selected = None
     debug(self.items)
     self.layout()
Exemple #8
0
 def minimap(self, filename):
     gamemap = GameMap(load_yaml('maps', filename))
     name = gamemap.name()
     surface = pygame.Surface((128,128))
     for x in range(0,20):
         for y in range(0,20):
             tilepath = gamemap.tile(x,y).background()
             if tilepath:
                 tileimage = self.frontend.tilemaps.get_by_path(tilepath)
                 tileimage = pygame.transform.smoothscale(tileimage, (6,6))
             else:
                 tileimage = pygame.Surface((6,6))
                 tileimage.fill((0,0,0))
             surface.blit(tileimage,(x*6, y*6))
     text = render_text(name, size=20, color=(0,0,0), font=pygame.font.Font(None,20))
     textrect = text.get_rect()
     textblock = pygame.Surface((textrect.w, textrect.h))
     textblock.fill((255,255,255))
     textblock.blit(text, (0,0))
     surface.blit(textblock, (0,60))
     return (surface, filename)
Exemple #9
0
 def update(self):
     self.image = self.surface.copy()
     col = 0
     row = 0
     x = 10
     y = 10
     filename = self.pages[self.page]
     self.pagepaths = []
     filenameblit = render_text (filename, size=32, color=(255,0,0))
     self.image.blit(filenameblit,(self.rect.x+self.rect.w/2 - filenameblit.get_rect().w/2, self.rect.y+self.rect.h -120))
     for imagepath in self.frontend.tilemaps.iterall(filename):
         if x >= self.rect.w - 75:
             col = 0
             row += 1
         x =  32 * col + 10
         y =  32 * row + 10
         thisrect = pygame.Rect(self.rect.x + x, self.rect.y+ y, 32, 32)
         self.pagepaths.append((thisrect, imagepath))
         image = pygame.transform.smoothscale(self.frontend.tilemaps.get_by_path(imagepath), (32,32))
         self.image.blit(image, (x,y))
         col += 1
Exemple #10
0
 def newgame(self):
     self.clearwindow()
     self.player = Player({})
     self.main.image.blit(render_text('Nyrac City Jail: Prisoner Record',64),(20,20))
     firstnamelbl = Label('First name:', (20, 150), layer=6)
     self._addtemp('firstnamelbl', firstnamelbl)
     firstname = TextInput(pygame.Rect(100,150,100,30), 16, self.frontend.eventstack, layer=6)
     self._addtemp('firstname', firstname)
     lastnamelbl = Label('Last name:', (20, 190), layer=6)
     self._addtemp('lastnamelbl', lastnamelbl)
     lastname = TextInput(pygame.Rect(100,190,100,30), 16, self.frontend.eventstack, layer=6)
     self._addtemp('lastname', lastname)
     portrait = BlitButton(
             self.nextportrait, 
             [],
             self.frontend.eventstack,
             self.frontend.imagecache,
             self.portrait,
             pos=(210,150),
             scale=128,
             layer=7
             )
     self._addtemp('portrait', portrait)
     sexlbl = Label('Sex', (20,230))
     self._addtemp('sexlbl', sexlbl)
     sex = Dropdown(self.frontend.eventstack,
         self.frontend.imagecache,
         16,
         pygame.Rect(100,230,100,30),
         ['male','female'],
         layer=18)
     self._addtemp('sex', sex)
     pclasslbl = Label('Class:',(340,150))
     self._addtemp('pclasslbl', pclasslbl)
     playerclass = Dropdown(self.frontend.eventstack,
         self.frontend.imagecache,
         16,
         pygame.Rect(420,150,200,30),
         PLAYER_CLASSES,
         layer=17)
     self._addtemp('playerclass', playerclass)
     racelbl = Label('Race:',(340,190))
     self._addtemp('racelbl',racelbl)
     race = Dropdown(self.frontend.eventstack,
         self.frontend.imagecache,
         16,
         pygame.Rect(420,190,200,30),
         ['human','elf','dwarf','half-elf','halfling','gnome','orc','goblin'],
         layer=16)
     self._addtemp('race', race)
     alignmentlbl = Label('Alignment', (340,230))
     self._addtemp('alignmentlbl', alignmentlbl)
     alignment = Dropdown(self.frontend.eventstack,
         self.frontend.imagecache,
         16,
         pygame.Rect(420,230,200,30),
         ['lawful-evil', 'neutral-evil', 'chaotic-evil'],
         layer=15)
     self._addtemp('alignment', alignment)
     create = Button('Create Character',
         self.createchar,
         [],
         self.frontend.eventstack,
         self.frontend.imagecache,
         pos=(210,350),
         layer=6,
         fontsize=16)
     self._addtemp('createchar', create)