Changeset 285


Ignore:
Timestamp:
03/25/12 00:55:42 (3 years ago)
Author:
mmorton
Message:

build menus working in full, build button broken

Location:
src
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • src/buildables.py

    r277 r285  
    33import os
    44
     5buildingLUT = {}
    56
    67def loadAllBuildings():
    7     buildingLUT = {}
    88    buildingFiles = os.listdir(buildingDir)
    99    for f in buildingFiles:
     
    1313            if building is not False:
    1414                buildingLUT[building.name] = building
    15                
    16     return buildingLUT
     15
  • src/buildingDescription.py

    r249 r285  
    66
    77from window import Window
    8 from rectanlge import Rectangle
     8from rectangle import Rectangle
    99from text import Text
    1010from image import Image
     
    1212from detailedDescription import DetailedDescription
    1313from simpleButton import SimpleButton
     14from globals import *
    1415
    1516class BuildDescription(DetailedDescription):
    1617    def __init__(self, pos, visible, description):
     18        if description == None:
     19            print "description is none"
     20        if description.title == None:
     21            print "title is none"
    1722        DetailedDescription.__init__(self, pos, visible, False)
    1823        self.text.append(Text((self.pos[0] + 5, self.pos[1] + 5), description.title, MD_TEXT, WHITE))
    1924        self.text.append(Text((self.pos[0] + 5, self.pos[1] + 20), description.text, MD_TEXT, WHITE))
    20         self.image.append(Image((self.pos[0] + 390, self.pos[1] + 5), ICON_SIZE, ICON_SIZE, description.icon))
     25        self.images.append(Image((self.pos[0] + 390, self.pos[1] + 5), ICON_SIZE, ICON_SIZE, description.icon))
    2126
    2227        self.subwindows.append(SimpleButton((self.pos[0] + 215, self.pos[1] + 45), True, "Build"))
    2328        self.subwindows.append(SimpleButton((self.pos[0] + 215, self.pos[1] + 60), True, "Cancel"))
     29
     30    def setYesResponse(self,response):
     31        self.subwindows[0].addResponse((response[0],))
     32       
     33    def setNoResponse(self,response):
     34        self.subwindows[1].addResponse(response)
     35   
     36    def toggle(self):
     37        print "toggling"
     38        self.visible = not self.visible
     39        for window in self.subwindows:
     40            window.toggle()
     41       
     42    def openWindow(self):
     43        self.visible = True
     44        for window in self.subwindows:
     45            window.openWindow()
  • src/description.py

    r268 r285  
    99from image import Image
    1010from building import Building
     11import pygame
     12from globals import *
    1113
    1214
     
    1820        self.icon = icon
    1921   
    20     def createFromBuilding(self,building):
     22    def createFromBuilding(self,building,isDetailed = False):
    2123        self.title = building.name
    22         self.text = building.menuDescript
     24        if isDetailed:
     25            self.text = building.detailedDescript
     26        else:
     27            self.text = building.menuDescript
    2328        self.icon = pygame.image.load(os.path.abspath(iconDir + building.imageFileName))
     29       
  • src/inGameMenu.py

    r264 r285  
    3939            window.openWindow()
    4040                         
     41    def response(self,e):
     42        for i, window in enumerate(self.subwindows):
     43            if i > 0:
     44                window.closeSubWindows()
     45        Window.response(self, e)
    4146       
    4247       
  • src/main.py

    r281 r285  
    1010from text import Text
    1111from rectangle import Rectangle
     12from buildables import loadAllBuildings
    1213import background
    1314import top
     
    2324import researchDescription
    2425import stats
     26import buildMenu
    2527
    2628from pygame.locals import *
     
    3537        return type: top
    3638    """
     39    loadAllBuildings()
     40   
    3741    # surface
    3842    screenSurface = pygame.display.set_mode((SCREEN_W,SCREEN_H),RESIZABLE)
    3943    screenSurface.fill(BLACK)
    40    
     44
    4145   
    4246    newTop = top.Top(screenSurface)
     
    8286    ###########################################################################################################
    8387   
     88    buildTransportationMenu = buildMenu.BuildMenu((20,20), False, 'TRANSPORTATION', 'build.png', TRANSPORTATION, newTop.build)
     89    buildMaterialMenu = buildMenu.BuildMenu((20,20), False, 'MATERIAL', 'build.png', MATERIALS, newTop.build)
     90    buildPowerMenu = buildMenu.BuildMenu((20,20), False, 'POWER', 'build.png', POWER, newTop.build)
     91   
    8492       
    8593    buildPowerDescription = description.Description('power',
     
    8795                                                    pygame.image.load(os.path.abspath(iconDir + "power.png")))
    8896    buildPowerButton = menuEntry.MenuEntry((40,100+ENTRY_SHIFT*0),False,buildPowerDescription)
     97    buildPowerButton.addResponse((buildPowerMenu.toggle,))
    8998   
    9099    buildTransportationDescription = description.Description('transportation',
     
    92101                                                    pygame.image.load(os.path.abspath(iconDir + "transportation.png")))
    93102    buildTransportationButton = menuEntry.MenuEntry((40,100+ENTRY_SHIFT*1),False,buildTransportationDescription)
     103    buildTransportationButton.addResponse((buildTransportationMenu.toggle,))
    94104   
    95105    buildMaterialDescription = description.Description('material',
     
    97107                                                    pygame.image.load(os.path.abspath(iconDir + "material.png")))
    98108    buildMaterialButton = menuEntry.MenuEntry((40,100+ENTRY_SHIFT*2),False,buildMaterialDescription)
    99    
    100     buildMenu = inGameMenu.InGameMenu((20,20),False,'BUILD MENU','build.png')
    101     buildMenu.addWindow(buildPowerButton)
    102     buildMenu.addWindow(buildTransportationButton)
    103     buildMenu.addWindow(buildMaterialButton)
     109    buildMaterialButton.addResponse((buildMaterialMenu.toggle,))
     110   
     111    buildCatMenu = inGameMenu.InGameMenu((20,20),False,'BUILD MENU','build.png')
     112   
     113    buildPowerButton.addWindow(buildPowerMenu)
     114    buildTransportationButton.addWindow(buildTransportationMenu)
     115    buildMaterialButton.addWindow(buildMaterialMenu)
     116   
     117    buildCatMenu.addWindow(buildPowerButton)
     118    buildCatMenu.addWindow(buildTransportationButton)
     119    buildCatMenu.addWindow(buildMaterialButton)
    104120   
    105121    ###########################################################################################################
     
    107123    powerDescription = description.Description("POWER", "you will unlock ... ",  pygame.image.load(os.path.abspath(iconDir + 'power.png')))
    108124    powerResearchDescription = researchDescription.ResearchDescription((550,250),False,powerDescription)
     125    powerResearchDescription.setYesResponse((newTop.research,0))
    109126   
    110127    researchPowerDescription = description.Description('power',
     
    117134
    118135    transportDescription = description.Description("TRANSPORTATION", "you will unlock ... ",  pygame.image.load(os.path.abspath(iconDir + 'transportation.png')))
    119     transportResearchDescription = researchDescription.ResearchDescription((500,300),False,transportDescription)
    120    
     136    transportResearchDescription = researchDescription.ResearchDescription((550,250),False,transportDescription)
     137    transportResearchDescription.setYesResponse((newTop.research,1))
    121138    researchTransportationDescription = description.Description('transportation',
    122139                                                    "This is where the text would go.",
     
    128145   
    129146    materialDescription = description.Description("MATERIAL", "you will unlock ... ",  pygame.image.load(os.path.abspath(iconDir + 'material.png')))
    130     materialResearchDescription = researchDescription.ResearchDescription((500,300),False,materialDescription)
    131    
     147    materialResearchDescription = researchDescription.ResearchDescription((550,250),False,materialDescription)
     148    materialResearchDescription.setYesResponse((newTop.research,2))
    132149    researchMaterialDescription = description.Description('material',
    133150                                                    "This is where the text would go.",
     
    148165    researchButton.addWindow(researchMenu)   
    149166    researchButton.addResponse((researchMenu.toggle,))
    150     researchButton.addResponse((buildMenu.closeWindow,))
     167    researchButton.addResponse((buildCatMenu.closeWindow,))
    151168   
    152169    buildButton = onScreenButton.OnScreenButton((20,720),True,'BUILD')
    153     buildButton.addWindow(buildMenu)   
    154     buildButton.addResponse((buildMenu.toggle,))
     170    buildButton.addWindow(buildCatMenu)   
     171    buildButton.addResponse((buildCatMenu.toggle,))
    155172    buildButton.addResponse((researchMenu.closeWindow,))
    156173   
     
    165182    newMap = map.Map((600,20),True)
    166183   
    167     statsWindow = stats.Stats((600, 450),True,newTop.getSpec())
     184    statsWindow = stats.Stats((600, 475),True,newTop.getSpec())
    168185   
    169186   
  • src/menuEntry.py

    r274 r285  
    1313class MenuEntry(Window):
    1414    def __init__(self, pos, visible, description):
    15         print 'window entry: ' + str(self)
    1615        Window.__init__(self, pos, visible)
    1716
     
    2019        self.text.append(Text((self.pos[0] + 10, self.pos[1] + 40), description.text, MD_TEXT, WHITE))
    2120        self.images.append(Image((self.pos[0] + 370, self.pos[1] + 10), ICON_SIZE, ICON_SIZE, description.icon))
    22 
  • src/researchDescription.py

    r274 r285  
    2020        self.text.append(Text((self.pos[0] + 5, self.pos[1] + 40), description.text, MD_TEXT, WHITE,width=460))
    2121        self.images.append(Image((self.pos[0] + 370, self.pos[1] + 10), ICON_SIZE, ICON_SIZE, description.icon))
     22       
     23        yesButton = SimpleButton((self.pos[0] + 215, self.pos[1] + 200), False, "Research")
     24        noButton = SimpleButton((self.pos[0] + 285, self.pos[1] + 200), False, "Cancel")
     25        yesButton.addResponse((self.closeWindow,))
     26        noButton.addResponse((self.closeWindow,))       
     27       
     28        self.subwindows.append(yesButton)
     29        self.subwindows.append(noButton)
    2230
    23         self.subwindows.append(SimpleButton((self.pos[0] + 285, self.pos[1] + 200), False, "Cancel"))
    24         self.subwindows.append(SimpleButton((self.pos[0] + 215, self.pos[1] + 200), False, "Research"))
    25        
    2631       
    2732        self.subwindows.append(Spinner((self.pos[0] + 100, self.pos[1] + 150), False))
    2833
    29     def update(self,state):
    30         # will need to get new description text
    31         None
    32        
    3334    def toggle(self):
    3435        print "toggling"
     
    4142        for window in self.subwindows:
    4243            window.openWindow()
     44           
     45    def setYesResponse(self,response):
     46        spinnerIndex = self.getElement(Spinner)
     47        self.subwindows[0].addResponse((response[0],response[1],self.subwindows[spinnerIndex].getValue))
     48       
     49    def setNoResponse(self,response):
     50        self.subwindows[1].addResponse(response)
  • src/spinner.py

    r268 r285  
    3737        if isUp and (self.value + self.step) <= self.max:
    3838            self.value += self.step
    39         elif (self.value - self.step) >= self.min:
     39        elif not isUp and (self.value - self.step) >= self.min:
    4040            self.value -= self.step
    41         self.text = []
    42         self.text.append(Text((self.pos[0] + 60, self.pos[1] + 25), str(self.value), MD_TEXT, FAKEBLACK))
     41
    4342
    4443#    def response(self,event):
     
    5150        self.max = state.getMoney()
    5251        self.text = []
    53         self.text.append(Text((60, 25), str(self.value), MD_TEXT, FAKEBLACK))
     52        self.text.append(Text((self.pos[0] + 60, self.pos[1] + 25), str(self.value), MD_TEXT, FAKEBLACK))
    5453       
    5554    def openWindow(self):
     
    5857        for window in self.subwindows:
    5958            window.openWindow()
     59        self.value = self.min
     60
     61           
     62    def closeWindow(self):
     63        self.visible = False
     64        for window in self.subwindows:
     65            window.closeWindow()
     66
     67       
     68    def getValue(self):
     69        return self.value
  • src/state.py

    r282 r285  
    1212from window import Window
    1313from fileio import *
    14 import buildables
     14from buildables import buildingLUT
    1515
    1616class State():
     
    2929            self.currentBuildings.append([])
    3030            self.buildingsToAdd.append([])
    31         self.buildingLUT = buildables.loadAllBuildings()
     31        self.buildingLUT = buildingLUT
    3232   
    3333    def checkThresh(self,building):
     
    193193        output = ""
    194194        output += "Buildings: "
    195         for i in self.currentBuildings:
    196             output += i.name + ", "
     195        for block in self.currentBuildings:
     196            for i in block:
     197                output += i + ", "
    197198        output += "\n Specs: "
    198199       
  • src/stats.py

    r280 r285  
    2222        i = 0
    2323        for (name, value, isBad) in self.spec:
    24             barPos = (self.pos[0] + 7 + STAT_SHIFT * i, self.pos[1] + 25)
     24            barPos = (self.pos[0] + 15 + STAT_SHIFT * i, self.pos[1] + 30)
    2525            self.subwindows.append(statusBar.StatusBar(barPos, True, name, value, isBad))
    2626            i += 1
  • src/statusBar.py

    r283 r285  
    2121        self.rectangles.append(Rectangle(self.pos, STAT_BAR_W, STAT_BAR_H, FAKEBLACK))
    2222        icon =  pygame.image.load(iconDir + category + '.png')
    23         self.images.append(Image((self.pos[0], self.pos[1] + STAT_BAR_H), STAT_ICON_SIZE, STAT_ICON_SIZE, icon))
     23        self.images.append(Image((self.pos[0] + 10, self.pos[1] + STAT_BAR_H), STAT_ICON_SIZE, STAT_ICON_SIZE, icon))
    2424
    2525        self.progress()
  • src/text.py

    r268 r285  
    4444            return type: None
    4545        """
    46         print "render text in"
     46        #print "render text in"
    4747        # wrap text into multiple lines as separate strings
    48         print self.text
     48        #print self.text
    4949        wrapped = self.wrapMultiLine()
    5050       
    5151       
    5252        if self.center:
    53             print "center"
    5453            # render each line
    5554            for i in range(len(wrapped)):
    56                 print "in for loop"
    5755                # create text
    5856                text = self.font.render(wrapped[i], True, self.color)
     
    6159                surface.blit(text, pygame.Rect(textRect.x + self.shift, self.top + (self.size) * i, 0, 0))
    6260        else:
    63             print "not center"
    6461            # render each line
    6562            for i in range(len(wrapped)):
    66                 print "in for loop"
    6763                surface.blit(self.font.render(wrapped[i], True, self.color),
    6864                             pygame.Rect(self.left, self.top + (self.size) * i, 0, 0))
    69         print "render text out"
    7065       
    7166    def resize(self, xScale, yScale):
  • src/top.py

    r282 r285  
    4646                self.subwindows.remove(window)
    4747                self.subwindows.insert(0,window)
     48                self.update(self.gameData.currentState)
    4849                self.resize(float(dimensions.SCREEN_W) / float(ORIG_SCREEN_W), float(dimensions.SCREEN_H) / float(ORIG_SCREEN_H))
    4950                self.render(self.surface)
     
    8485            window.render(surface)
    8586        pygame.display.update()
     87        print self.gameData.currentState
    8688           
    8789    def resize(self, xScale, yScale):
     
    102104            return type: none
    103105        """
     106        print "top update"
    104107        for window in self.subwindows:
    105108            window.update(state)
     
    157160            self.gameData.build(building,blockNumber)
    158161
    159     def research(self,researchType,value):
     162    def research(self,researchType,valueGetter):
    160163        """
    161164            adds research to a designated type.
    162165           
    163             input type: type(int), value(int)
     166            input type: type(int), valueGetter(function)
    164167            return type: none
    165168        """
    166         self.gameData.research(researchType,value)
     169       
     170        self.gameData.research(researchType,valueGetter())
    167171       
    168172    def getSpec(self):
  • src/window.py

    r257 r285  
    173173        """
    174174        self.visible = False
     175        self.closeSubWindows()
     176
     177       
     178    def closeSubWindows(self):
     179        """
     180            closes subwindows
     181           
     182            input type: none
     183            return type: none
     184        """
    175185        for window in self.subwindows:
    176186            window.closeWindow()
    177        
     187   
    178188    def toggle(self):
    179189        """
     
    195205            return type: none
    196206        """
    197         print 'opening: ' + str(self)
     207        #print 'opening: ' + str(self)
    198208        self.visible = True
    199209       
     
    243253        """
    244254        return self.visible
     255   
     256    def getElement(self,windowType):
     257        """
     258            returns the first subwindow of this window with the given type.
     259           
     260            input type: windowType(type)
     261            return type: window
     262        """
     263        print windowType
     264        for i,window in enumerate(self.subwindows):
     265            print type(window)
     266            if isinstance(window,windowType):
     267                return i
     268        print 'window doesn\'t exist!'
     269        return None
Note: See TracChangeset for help on using the changeset viewer.