Changeset 188


Ignore:
Timestamp:
03/17/2012 03:31:11 PM (3 years ago)
Author:
ecoughlan
Message:

Button class for quickly creating buttons

Files:
9 edited

Legend:

Unmodified
Added
Removed
  • .metadata/.plugins/org.eclipse.ui.workbench/workbench.xml

    r57 r188  
    11<?xml version="1.0" encoding="UTF-8"?>
    2 <workbench progressCount="32" version="2.0">
     2<workbench progressCount="9" version="2.0">
    33<workbenchAdvisor/>
    44<window height="768" maximized="true" width="1024" x="126" y="-7">
  • .metadata/.plugins/org.python.pydev/ping.log

    r57 r188  
    88editor.opened%5B%5D=1330165561231%3APydevEditor_2.4.0.2012020116
    99plugin.started%5B%5D=1330165574772%3APydev_2.4.0.2012020116
     10plugin.started%5B%5D=1332041113020%3APydev_2.4.0.2012020116
  • src/alert.py

    r148 r188  
    66from globals import *
    77from window import *
     8from button import *
    89
    910class Alert():
     
    4041        alertWindow.addEntry(alertIcon)
    4142        if self.options == True:
    42             okay = WindowEntry(Response(self.optionResponse,[],True,False))
    43             okay.addRectangle(Rectangle((378,120),56,25,GRAY))
    44             okay.addText(Text((378,125),'OKAY',24,FAKEBLACK,378+56,True,378))
     43            okay = Button('OKAY',self.optionResponse,[],(320,120),type_=1).createButton()
    4544            alertWindow.addEntry(okay)
    46             cancel = WindowEntry(Response('windows',[],True,False))
    47             cancel.addRectangle(Rectangle((438,120),56,25,GRAY))
    48             cancel.addText(Text((438,125),'CANCEL',24,FAKEBLACK,438+56,True,438))
     45            cancel = Button('CANCEL',pos=(410,120),type_=1).createButton()
    4946            alertWindow.addEntry(cancel)
    5047        else:
    51             close = WindowEntry(Response('windows',[],True,False))
    52             close.addRectangle(Rectangle((440,120),56,25,GRAY))
    53             close.addText(Text((440,125),'CLOSE',24,FAKEBLACK,440+56,True,440))
     48            close = Button('CLOSE',pos=(410,120),type_=1).createButton()
    5449            alertWindow.addEntry(close)
    5550        return alertWindow
  • src/button.py

    r187 r188  
     1'''
     2Created on Mar 17, 2012
     3
     4@author: TechTrek
     5'''
     6
     7from globals import *
     8from window import *
     9
     10class Button():
     11    """ A Button object which creates a windowEntry with the given text and responses """
     12   
     13    def __init__(self,text,responseType='windows',responseWindows=[],pos=(0,0),shift=0,
     14                 type_=0,close=True,colors=1,width=BUTTON_W,height=BUTTON_H,size=BUTTON_TEXT):
     15            """
     16                initializes the components of the Button class. 
     17               
     18            """
     19           
     20            # need to find a better way to do vertical shifts, height and size
     21            # are different units
     22           
     23            self.text = text
     24            self.responseType = responseType
     25            self.responseWindows = responseWindows
     26            self.close = close
     27            self.pos = pos
     28            self.shift = shift
     29           
     30            # for the alert/confirm buttons
     31            if type_ == 1:
     32                self.colors = GRAY_FAKEBLACK
     33                self.width = 80
     34                self.height = 20
     35                self.size = 24
     36                self.close = True
     37                self.shift = pos[0]
     38                self.vShift = (height-size) * 0.10
     39           
     40            # for the on screen buttons (Research, Build, etc.)
     41            elif type_ == 2:
     42                self.colors = BLUE_WHITE
     43                self.width = 160
     44                self.height = 50
     45                self.size = 29
     46                self.close = False
     47                self.vShift = (height-size) * 0.75
     48           
     49            # for the main menu
     50            elif type_ == 3:
     51                self.colors = BLUE_WHITE
     52                self.width = 200
     53                self.height = 70
     54                self.size = 48
     55                self.close = True
     56                self.shift = 50
     57                self.vShift = (height-size) * 0.75
     58           
     59            else:
     60                self.colors = colors
     61                self.width = width
     62                self.height = height
     63                self.size = size
     64                self.vShift = (height-size) * 0.75
     65               
     66               
     67           
     68           
     69   
     70    def createButton(self):
     71        """
     72            creates a generic button with text, width, height, and close response
     73            specified in self.
     74           
     75            input type: None
     76            return type WindowEntry(button)
     77        """
     78       
     79        if self.colors == 2:
     80            rectColor = BLUE
     81            textColor = WHITE
     82        else:
     83            rectColor = GRAY
     84            textColor = FAKEBLACK
     85           
     86       
     87        button = WindowEntry(Response(self.responseType,self.responseWindows, self.close, False))
     88        button.addRectangle(Rectangle(self.pos,self.width,self.height,rectColor))
     89        button.addText(Text((self.pos[0],self.pos[1]+self.vShift),self.text,self.size,textColor,self.width+self.shift,True,self.shift))
     90       
     91        return button
     92               
     93   
  • src/color.py

    r157 r188  
    1818MAUVE = (224,176,255)
    1919GRAY = (172,172,172)
     20
     21GRAY_FAKEBLACK = 1
     22BLUE_WHITE = 2
     23
    2024
    2125
  • src/spinner.py

    r156 r188  
    88from window import *
    99from fileio import *
     10from button import *
    1011
    1112class Spinner:
     
    4344        researchWindow.addEntry(background)
    4445
    45         cancelButton = WindowEntry(Response('spinner',[],True,False,'cancel'))
    46         cancelButton.addRectangle(Rectangle((285,75),80,20,GRAY))
    47         cancelButton.addText(Text((285,76),'CANCEL',24,FAKEBLACK,285+80,True,285))
     46        cancelButton = Button('CANCEL','spinner',[],(285,75),type_=1).createButton()
    4847        researchWindow.addEntry(cancelButton)
    4948       
    50         researchButton = WindowEntry(Response('spinner',[],True,False,'research'))
    51         researchButton.addRectangle(Rectangle((195,75),80,20,GRAY))
    52         researchButton.addText(Text((195,76),'RESEARCH',24,FAKEBLACK,195+80,True,195))
     49        researchButton = Button('RESEARCH','spinner',[],(195,75),type_=1).createButton()
    5350        researchWindow.addEntry(researchButton)
    5451       
  • src/staticWindows.py

    r158 r188  
    2020from game import *
    2121from state import *
     22from button import *
    2223
    2324# Windows Dictionary - holds all of the windows that are created
     
    4546
    4647# Build button
    47 buildIcon = WindowEntry(Response('windows',['buildMenu1'],False,False))
     48buildIcon = Button("BUILD",'windows',['buildMenu1'],(0,0),type_=2).createButton()
    4849buildArt = pygame.image.load(os.path.abspath(iconDir + "build.png"))
    4950buildIcon.addImage(Image((5,5),IMG_SM,IMG_SM,buildArt))
    50 buildIcon.addRectangle(Rectangle((0,0),BUTTON_W,BUTTON_H,BLUE))
    51 buildIcon.addText(Text((IMG_SM,17),"BUILD",BUTTON_TEXT,WHITE,BUTTON_W,True,IMG_SM))
    5251buttons.addEntry(buildIcon)
    5352
    5453# Research button
    55 researchIcon = WindowEntry(Response('windows',['researchMenu'],False,False))
     54researchIcon = Button("RESEARCH",'windows',['researchMenu'],(BUTTON_SHIFT,0),BUTTON_SHIFT,type_=2).createButton()
    5655buildArt = pygame.image.load(os.path.abspath(iconDir + "research.png"))
    5756researchIcon.addImage(Image((5+BUTTON_SHIFT,5),IMG_SM,IMG_SM,buildArt))
    58 researchIcon.addRectangle(Rectangle((BUTTON_SHIFT,0),BUTTON_W,BUTTON_H,BLUE))
    59 researchIcon.addText(Text((BUTTON_SHIFT+IMG_SM,17),"RESEARCH",BUTTON_TEXT,WHITE,BUTTON_W+BUTTON_SHIFT,True,BUTTON_SHIFT+IMG_SM))
    6057buttons.addEntry(researchIcon)
    6158
    6259# End Turn button
    63 endTurnButton = WindowEntry(Response('endTurn',[],False,False))
    64 endTurnButton.addRectangle(Rectangle((BUTTON_SHIFT*2,0),BUTTON_W,BUTTON_H,BLUE))
    65 endTurnButton.addText(Text((BUTTON_SHIFT*2,17),"END TURN",BUTTON_TEXT,WHITE,BUTTON_W+BUTTON_SHIFT*2,True,BUTTON_SHIFT*2))
     60endTurnButton = Button("END TURN",'endTurn',[],(BUTTON_SHIFT*2,0),BUTTON_SHIFT*2,type_=2).createButton()
    6661buttons.addEntry(endTurnButton)
    6762
     
    7469
    7570# Main Menu button
    76 mainMenuButton = WindowEntry(Response('mainMenu',[],False,False))
    77 mainMenuButton.addRectangle(Rectangle((0,0),BUTTON_W,BUTTON_H,BLUE))
    78 mainMenuButton.addText(Text((0,17),"MAIN MENU",BUTTON_TEXT,WHITE,BUTTON_W,True,0))
     71mainMenuButton = Button('MAIN MENU','mainMenu',[],type_=2).createButton()
    7972mainButtons.addEntry(mainMenuButton)
    8073
    8174# Undo Turn button
    82 undoTurnButton = WindowEntry(Response('windows',['undoAlert'],False,False))
    83 undoTurnButton.addRectangle(Rectangle((BUTTON_SHIFT,0),BUTTON_W,BUTTON_H,BLUE))
    84 undoTurnButton.addText(Text((BUTTON_SHIFT,17),"UNDO TURN",BUTTON_TEXT,WHITE,BUTTON_SHIFT+BUTTON_W,True,BUTTON_SHIFT))
     75undoTurnButton = Button('UNDO TURN','windows',['undoAlert'],(BUTTON_SHIFT,0),BUTTON_SHIFT,type_=2).createButton()
    8576mainButtons.addEntry(undoTurnButton)
    8677
     
    152143names = [('New Game','windows'), ('Resume','resume'), ('Load','load'), ('Save','save'), ('Quit','quit')]
    153144for i in range(len(names)):
    154     menuButton = WindowEntry(Response(names[i][1],['introScene_1'],True,False))
    155     menuButton.addRectangle(Rectangle((50,70+MAIN_SHIFT*i),200,70,BLUE))
    156     menuButton.addText(Text((50,85+MAIN_SHIFT*i),names[i][0],48,WHITE,250,True,50))
     145    button = Button(names[i][0],names[i][1],['introScene_1'],(50,70+MAIN_SHIFT*i),type_=3)
     146    menuButton = button.createButton()
    157147    mainMenu.addEntry(menuButton)
    158148   
  • src/turnMenu.py

    r165 r188  
    1313from window import *
    1414from spinner import *
     15from button import *
    1516
    1617class TurnMenu():
     
    8586        descriptionWindow.addEntry(buildIcon)
    8687       
    87         cancelButton = WindowEntry(Response('windows',[],True,False))
    88         cancelButton.addRectangle(Rectangle((285,75),80,20,GRAY))
    89         cancelButton.addText(Text((285,76),'CANCEL',24,FAKEBLACK,285+80,True,285))
     88        cancelButton = Button('CANCEL',pos=(285,75),type_=1).createButton()
    9089        descriptionWindow.addEntry(cancelButton)
    9190       
    92         buildButton = WindowEntry(Response('build',[],True,False,name))
    93         buildButton.addRectangle(Rectangle((195,75),80,20,GRAY))
    94         buildButton.addText(Text((195,76),'BUILD',24,FAKEBLACK,195+80,True,195))
     91        buildButton = Button('BUILD',pos=(195,75),type_=1).createButton()
    9592        descriptionWindow.addEntry(buildButton)
    9693       
Note: See TracChangeset for help on using the changeset viewer.