root/src/turnMenu.py @ 107

Revision 107, 3.7 KB (checked in by ecoughlan, 2 years ago)

Spinners work yey!!! We can research!

Line 
1'''
2Created on Feb 18, 2012
3
4@author: TechTrek
5'''
6from globals import *
7from fileio import *
8from state import *
9from buildables import *
10from pygame import *
11from window import *
12from spinner import *
13
14class TurnMenu():
15    """ class to dynamically determine contents of build (and research) menu """
16    def __init__(self):
17        self.spinner = None
18       
19    def createBuildMenu(self,state,researchType):
20        """ create window containing options for building at given moment """
21        buildMenu = Window('buildMenu',20,20)
22        buildMenu.setDefaultResponse(Response('windows',[],True,True))
23        buildArt = pygame.image.load(os.path.abspath(pngDir + "build.png"))
24        buildIcon = WindowEntry(Response('windows',[],False,False))
25        buildIcon.addImage(Image((120,10),40,40,buildArt))
26        buildIcon.addImage(Image((345,10),40,40,buildArt))
27        buildIcon.addRectangle(Rectangle((0,0),MENU_W,MENU_H,BLUE))
28        buildIcon.addText(Text((210,17),typesLUT[researchType].upper(),42,WHITE))
29        buildMenu.addEntry(buildIcon)
30        buildables = self.calculateBuildables(state)
31       
32        i = 0
33        for building in buildables:
34            if building.buildingType == researchType:
35                buildIcon = WindowEntry(Response('describe',[],False,False,building.name))
36                buildArt = pygame.image.load(os.path.abspath(pngDir + building.imageFileName))
37                buildIcon.addImage(Image((390,110+ENTRY_SHIFT*i),ICON_SIZE,ICON_SIZE,buildArt))
38                buildIcon.addRectangle(Rectangle((20,100+ENTRY_SHIFT*i),460,100,CYAN))
39                buildIcon.addText(Text((25,110+ENTRY_SHIFT*i),building.name,32,WHITE))
40                buildIcon.addText(Text((25,140+ENTRY_SHIFT*i), building.menuDescript,24,WHITE))
41                buildMenu.addEntry(buildIcon)
42                i += 1
43        return buildMenu
44   
45    def calculateBuildables(self,state):
46        """ determine what can be build given state """
47        buildables = []
48        for building in buildingLUT.values():
49            if state.checkThresh(building):
50                buildables.append(building)
51        return buildables
52   
53    def createDescription(self, name):
54        """ create detailed description as pop-up menu """
55        descriptionWindow = Window(name,550,300)
56        descriptionWindow.setDefaultResponse(Response('windows',[],True,True))
57        buildIcon = WindowEntry(Response('build',[],True,False,name))
58        buildArt = pygame.image.load(os.path.abspath(pngDir + buildingLUT[name].imageFileName))
59        buildIcon.addImage(Image((370,10),ICON_SIZE,ICON_SIZE,buildArt))
60        buildIcon.addRectangle(Rectangle((0,0),460,100,CYAN))
61        buildIcon.addText(Text((5,10),name,32,WHITE))
62        buildIcon.addText(Text((5,40), buildingLUT[name].detailedDescript,24,WHITE, 350))
63        descriptionWindow.addEntry(buildIcon)
64        return descriptionWindow
65   
66    # window for researching
67    def researchDescription(self,state,researchType):
68        """ create detailed description as pop-up menu """
69        self.spinner = Spinner(state.getMoney(),researchType)
70        descriptionWindow = self.spinner.createWindow()
71        return descriptionWindow
72   
73    def incrementSpinner(self):
74        self.spinner.increment()
75        return self.spinner.createWindow()
76       
77    def decrementSpinner(self):
78        self.spinner.decrement()
79        return self.spinner.createWindow()
80   
81    def updateSpinner(self):
82        return self.spinner.createWindow()
83   
84    def getResearchType(self):
85        return self.spinner.getResearchType()
86   
87    def getValue(self):
88        return self.spinner.getValue()
89   
90   
91   
92   
93   
Note: See TracBrowser for help on using the browser.