diff options
author | Kevin Hockey <Blitzkev@gmail.com> | 2010-08-02 20:45:10 (GMT) |
---|---|---|
committer | Kevin Hockey <Blitzkev@gmail.com> | 2010-08-02 20:45:10 (GMT) |
commit | 8272c55317c84a3548900540c96f04b4790e498c (patch) | |
tree | 289b985c4f82727567190fe52082dc50b64309c6 | |
parent | ffd60a0202cbb692f3d344242f783611b819e3dc (diff) |
in the process of changing over some menu files to DrawableObjects
-rw-r--r-- | MAFH2/BattleMenu.py | 48 | ||||
-rw-r--r-- | MAFH2/MagicMenu.py | 73 |
2 files changed, 73 insertions, 48 deletions
diff --git a/MAFH2/BattleMenu.py b/MAFH2/BattleMenu.py index f924a15..0dcde8d 100644 --- a/MAFH2/BattleMenu.py +++ b/MAFH2/BattleMenu.py @@ -113,9 +113,8 @@ class BattleMenu(GameEngineElement): def __init__(self, game_menu, x, y, type=NORMAL_MENU): GameEngineElement.__init__(self, has_draw=True, has_event=True) - self.menu = Menu(game_menu, type, self.game_engine.get_scene() ) + self.menu = Menu(game_menu, type, self.game_engine.get_scene(), x, y ) - self.menu.set_pos(x, y) self.add_to_engine() def event_handler(self, event): @@ -128,14 +127,14 @@ class BattleMenu(GameEngineElement): self.menu.clear() class Menu(object): - def __init__(self, options, cols, scene): + def __init__(self, options, cols, scene, x=237, y=375): """Initialize the EzMenu! options should be a sequence of lists in the format of [option_name, option_function]""" self.options = options self.scene = scene - self.x = 0 - self.y = 0 + self.x = x + self.y = y self.cols = cols self.font = pygame.font.SysFont("cmr10",18,False,False) self.option = 0 @@ -151,15 +150,37 @@ class Menu(object): ren = self.font.render(o[0], 1, [0,0,0]) if ren.get_width() > self.width: self.width = ren.get_width() + + i=0 # Row Spacing + h=0 # Selection Spacing + j=0 # Col Spacing for o in self.options: - surf = pygame.Surface((self.height,self.width)) - self.rect_list.append(DrawableObject([surf], "")) - self.rect_list.append(DrawableObject([surf], "")) + newX = self.x + 45 * j + newY = self.y + i * 45 + + surf = pygame.Surface((o[2],44)) + surf.fill((0, 74, 94)) + tempDO = DrawableObject([surf], "") + tempDO.setPosition(newX,newY) + self.rect_list.append(tempDO) + + surf = pygame.Surface((o[2]-4, 40)) + surf.fill((4, 119, 152)) + tempDO = DrawableObject([surf], "") + tempDO.setPosition(newX+2, newY+2) + self.rect_list.append(tempDO) + + j+=o[3] + h+=1 + if j >= self.cols: + i+=1 + j=0 self.scene.addObjects(self.rect_list) self.scene.addObjects(self.font_list) def draw(self, surface): + self.scene.drawEntireScene(surface) """Draw the menu to the surface.""" i=0 # Row Spacing h=0 # Selection Spacing @@ -176,18 +197,7 @@ class Menu(object): newX = self.x + 45 * j newY = self.y + i * 45 - - self.rect_list[k-1].scale(o[2], 44) - self.rect_list[k-1].setPosition(newX, newY) - self.rect_list[k-1].fill((0, 74, 94)) - self.rect_list[k].scale(o[2]-4, 40) - self.rect_list[k].setPosition(newX+2, newY+2) - self.rect_list[k].fill((4, 119, 152)) - - #pygame.draw.rect(surface, (0, 74, 94), ( newX, newY, o[2], 44)) - #pygame.draw.rect(surface, (4, 119, 152), ( newX + 2, newY + 2, o[2]-4, 40)) self.font_list[h].setPosition(newX + 15, newY + 12) - #surface.blit(ren, (newX + 15, newY + 12)) j+=o[3] h+=1 diff --git a/MAFH2/MagicMenu.py b/MAFH2/MagicMenu.py index 42d4bd9..66e978a 100644 --- a/MAFH2/MagicMenu.py +++ b/MAFH2/MagicMenu.py @@ -1,6 +1,7 @@ import pygame import random from fortuneengine.GameEngineElement import GameEngineElement +from fortuneengine.DrawableObject import DrawableObject from AnimatedSprite import Spritesheet from constants import MENU_PATH, PUZZLE_PATH @@ -89,7 +90,7 @@ class MagicMenu(GameEngineElement): def __init__(self, menu_options, x, y, spell_type): GameEngineElement.__init__(self, has_draw=True, has_event=True) magic_list = self.game_engine.get_object('battle').magic_list - self.menu = Menu(menu_options, spell_type, magic_list) + self.menu = Menu(menu_options, spell_type, magic_list, self.game_engine.get_scene()) self.menu.set_pos(x, y) @@ -102,10 +103,11 @@ class MagicMenu(GameEngineElement): self.menu.draw( screen ) class Menu(object): - def __init__(self, options, spelltype, magic_list): + def __init__(self, options, spelltype, magic_list, scene): """Initialize the EzMenu! options should be a sequence of lists in the format of [option_name, option_function]""" + self.scene = scene self.buttons = [] self.options = options self.x = 0 @@ -115,6 +117,7 @@ class Menu(object): self.width = 2 self.spelltype = spelltype self.magic_list = magic_list + self.reference = [] lightning = [] fire = [] @@ -130,56 +133,56 @@ class Menu(object): if(spelltype == 0): #fire attack for i in range(4): - self.buttons.append(pygame.transform.scale(fire[i] , (60,60))) + self.buttons.append(DrawableObject([pygame.transform.scale(fire[i] , (60,60))], "")) #filler buttons for i in range(0,2): - self.buttons.append(pygame.transform.scale(lightning[i] , (60,60))) + self.buttons.append(DrawableObject([pygame.transform.scale(lightning[i] , (60,60))], "")) random.seed() - self.buttons.append(pygame.transform.scale(heal[random.randint(0,3)] , (60,60))) - self.buttons.append(pygame.transform.scale(missile[random.randint(0,3)] , (60,60))) + self.buttons.append(DrawableObject([pygame.transform.scale(heal[random.randint(0,3)] , (60,60))], "")) + self.buttons.append(DrawableObject([pygame.transform.scale(missile[random.randint(0,3)] , (60,60))], "")) - self.mainGlyph = pygame.image.load(PUZZLE_PATH + "FireGlyph.gif").convert() + self.mainGlyph = DrawableObject([pygame.image.load(PUZZLE_PATH + "FireGlyph.gif").convert()], "") self.glyphs = fire elif(spelltype == 1): #lightning attack for i in range(4): - self.buttons.append(pygame.transform.scale(lightning[i] , (60,60))) + self.buttons.append(DrawableObject([pygame.transform.scale(lightning[i] , (60,60))], "")) #filler buttons for i in range(0,2): - self.buttons.append(pygame.transform.scale(fire[i] , (60,60))) + self.buttons.append(DrawableObject([pygame.transform.scale(fire[i] , (60,60))], "")) random.seed() - self.buttons.append(pygame.transform.scale(heal[random.randint(0,3)] , (60,60))) - self.buttons.append(pygame.transform.scale(missile[random.randint(0,3)] , (60,60))) + self.buttons.append(DrawableObject([pygame.transform.scale(heal[random.randint(0,3)] , (60,60))], "")) + self.buttons.append(DrawableObject([pygame.transform.scale(missile[random.randint(0,3)] , (60,60))], "")) - self.mainGlyph = pygame.image.load(PUZZLE_PATH + "LightningGlyph.gif").convert() + self.mainGlyph = DrawableObject([pygame.image.load(PUZZLE_PATH + "LightningGlyph.gif").convert()], "") self.glyphs = lightning elif(spelltype == 2): #missile attack for i in range(4): - self.buttons.append(pygame.transform.scale(missile[i] , (60,60))) + self.buttons.append(DrawableObject([pygame.transform.scale(missile[i] , (60,60))], "")) #filler buttons for i in range(0,2): - self.buttons.append(pygame.transform.scale(lightning[i] , (60,60))) + self.buttons.append(DrawableObject([pygame.transform.scale(lightning[i] , (60,60))], "")) random.seed() - self.buttons.append(pygame.transform.scale(heal[random.randint(0,3)] , (60,60))) - self.buttons.append(pygame.transform.scale(fire[random.randint(0,3)] , (60,60))) + self.buttons.append(DrawableObject([pygame.transform.scale(heal[random.randint(0,3)] , (60,60))], "")) + self.buttons.append(DrawableObject([pygame.transform.scale(fire[random.randint(0,3)] , (60,60))], "")) - self.mainGlyph = pygame.image.load(PUZZLE_PATH + "MissileGlyph.gif").convert() + self.mainGlyph = DrawableObject([pygame.image.load(PUZZLE_PATH + "MissileGlyph.gif").convert()], "") self.glyphs = missile elif(spelltype == 3): #heal for i in range(4): - self.buttons.append(pygame.transform.scale(heal[i] , (60,60))) + self.buttons.append(DrawableObject([pygame.transform.scale(heal[i] , (60,60))], "")) #filler buttons for i in range(0,2): - self.buttons.append(pygame.transform.scale(lightning[i] , (60,60))) + self.buttons.append(DrawableObject([pygame.transform.scale(lightning[i] , (60,60))], "")) random.seed() - self.buttons.append(pygame.transform.scale(missile[random.randint(0,3)] , (60,60))) - self.buttons.append(pygame.transform.scale(fire[random.randint(0,3)] , (60,60))) + self.buttons.append(DrawableObject([pygame.transform.scale(missile[random.randint(0,3)] , (60,60))], "")) + self.buttons.append(DrawableObject([pygame.transform.scale(fire[random.randint(0,3)] , (60,60))], "")) - self.mainGlyph = pygame.image.load(PUZZLE_PATH + "HealGlyph.gif").convert() + self.mainGlyph = DrawableObject([pygame.image.load(PUZZLE_PATH + "HealGlyph.gif").convert()], "") self.glyphs = heal deck = [0,1,2,3,4,5,6,7] @@ -194,7 +197,16 @@ class Menu(object): self.buttons = tButtons self.options = tOptions - self.height = (len(self.options)*self.buttons[1].get_height()) / self.cols + self.scene.addObjects(self.buttons) + + for image in self.glyphs: + tempDO = DrawableObject([image],"") + tempDO.makeTransparent(True) + self.reference.append(tempDO) + self.scene.addObjects(self.reference) + self.scene.addObject(self.mainGlyph) + + self.height = (len(self.options)*self.buttons[1].getYSize()) / self.cols def draw(self, surface): """Draw the menu to the surface.""" @@ -202,8 +214,8 @@ class Menu(object): h=0 # Selection Spacing j=0 # Col Spacing index=0 #current spot in buttons list - height = self.buttons[0].get_height() - width = self.buttons[0].get_width() + height = self.buttons[0].getYSize() + width = self.buttons[0].getXSize() for o in self.options: @@ -212,7 +224,8 @@ class Menu(object): if h==self.option: pygame.draw.rect(surface, (4, 119, 152), ( newX, newY, height, width)) - surface.blit(self.buttons[index], (newX, newY) ) + self.buttons[index].setPosition(newX, newY) + #surface.blit(self.buttons[index], (newX, newY) ) j+=1 h+=1 @@ -221,14 +234,16 @@ class Menu(object): i+=1 j=0 - self.mainGlyph.set_colorkey((255,0,255), pygame.RLEACCEL) - surface.blit(self.mainGlyph, (485,350)) + self.mainGlyph.setColorKey((255,0,255)) + self.mainGlyph.setPosition(485,350) # Draw reference glyphs for i in range(4): if i in self.magic_list: - surface.blit(self.glyphs[i], (800+((i%2) * 150), 350+(i/2 * 150))) + #surface.blit(self.glyphs[i], (800+((i%2) * 150), 350+(i/2 * 150))) + self.reference[i].makeTransparent(False) + self.reference[i].setPosition(800+((i%2) * 150), 350+(i/2 * 150)) def update(self, event): """Update the menu and get input for the menu.""" |