Changeset 766


Ignore:
Timestamp:
06/06/2012 01:19:26 PM (3 years ago)
Author:
jhoffswell
Message:

Fixed the new game bug and missing buttons

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/main.py

    r763 r766  
    5757    loadAllBuildings()
    5858   
    59 
    6059    # surface
    6160    screenSurface = pygame.display.set_mode((SCREEN_W, SCREEN_H), RESIZABLE)
     
    7675    top = Top(screenSurface)
    7776
    78     gameBackground = Background(DIM.GAME_BG_POS, True, None, True)
    79     ###########################################################################
    80 
    81     menuBackground = Background((0, 0), True, 'menuBackground')
    82 
    83     mainMenuWindow = MainMenu()
    84     top.setMenuModifier(mainMenuWindow.setConfiguration)
    85 
    86     ###########################################################################
    87     # main menu screen buttons
    88     newGameButton = MainMenuButton((0, 0), True, STR.MENU_NEW, 1)
    89     newGameButton.addResponse((top.newGame, ))
    90 
    91     resumeButton = MainMenuButton((0, 0), False, STR.MENU_RESUME, 0)
    92     resumeButton.addResponse((top.resume,))
    93 
    94     loadForm = LoadDialogue(STR.LOAD_MSG, STR.MENU_LOAD)
    95     loadForm.addResponse((top.loadGame,))
    96 
    97     loadButton = MainMenuButton((0, 0), True, STR.MENU_LOAD, 2)
    98     loadButton.addResponse((loadButton.openSubwindow,))
    99     loadButton.addWindow(loadForm)
    100 
    101     saveForm = Dialogue(STR.LOAD_SAVE_MSG, STR.MENU_SAVE, STR.SAVED)
    102     saveForm.setYesResponse((top.saveGame, saveForm.getValue))
    103     saveForm.setYesResponse((saveForm.close,))
    104     saveButton = MainMenuButton((0, 0), False, STR.MENU_SAVE, 3)
    105     saveButton.addWindow(saveForm)
    106     saveButton.addResponse((saveButton.openSubwindow,))
    107 
    108     quitButton = MainMenuButton((0, 0), True, STR.MENU_QUIT, 4)
    109     confirm = Alert(False, "Are you sure you want to quit?",
    110                         [(top.quitGame,)])
    111     quitButton.addWindow(confirm)
    112     quitButton.addResponse((quitButton.openSubwindow,))
    113 
    114     mainMenuWindow.addWindow(newGameButton)
    115     mainMenuWindow.addWindow(resumeButton)
    116     mainMenuWindow.addWindow(loadButton)
    117     mainMenuWindow.addWindow(saveButton)
    118     mainMenuWindow.addWindow(quitButton)
    119     mainMenuWindow.update(None)
    120 
    121     menuBackground.addWindow(mainMenuWindow)
    122 
    123     ###########################################################################
    124     # build and research buttons
    125     rButton = OnScreenButton(DIM.RESEARCH_POS, True, STR.RESEARCH.upper(), False)
    126     rButtonIn = OnScreenButton(DIM.RESEARCH_POS, False, STR.RESEARCH.upper(), True)
    127 
    128     rButton.addWindow(rButtonIn)
    129 
    130     bButton = OnScreenButton(DIM.BUILD_POS, True, STR.BUILD.upper(), False)
    131     bButtonIn = OnScreenButton(DIM.BUILD_POS, False, STR.BUILD.upper(), True)
    132 
    133     bButton.addWindow(bButtonIn)
    134 
    135     ###########################################################################
    136     # building category menu
    137     bCatMenu = InGameMenu(False, (bButtonIn.close,))
    138 
    139     bTutList = []
    140     for i, cat in enumerate(CAT_LUT):
    141         bMenu2 = BuildMenu(False, i, top.build,
    142                                          (bButtonIn.close,))
    143         bTutList.append(bMenu2)
    144 
    145         buildInfo = Info(cat, buildCatDescrip[i], buttonDir + cat)
    146         bMenuButton = MenuEntry((DIM.ENTRY_L, DIM.ENTRY_T + DIM.ENTRY_SHIFT * i),
    147                                 False, buildInfo)
    148         bMenuButton.addResponse((bMenu2.open,))
    149         bMenuButton.addResponse((bCatMenu.toggleHidden,))
    150         bMenu2.setBackResponse((bCatMenu.toggleHidden,))
    151         bMenuButton.addWindow(bMenu2)
    152         bCatMenu.addWindow(bMenuButton)
    153 
    154     ###########################################################################
    155     # research category menu
    156     rCatMenu = ResearchMenu(False, top.research, (rButtonIn.close,))
    157 
    158     ###########################################################################
    159 
    160     toolbarBack = Toolbar(True, 'toolbar_background')
    161 
    162     # responses for research and build buttons
    163     rButton.addResponse((rButtonIn.open,))
    164     rButton.addResponse((bButtonIn.close,))
    165     rButton.setHover(STR.RESEARCH_HOVER)
    166 
    167     rButtonIn.addWindow(rCatMenu)
    168     rButtonIn.addResponse((rButtonIn.close,))
    169     rButtonIn.addResponse((rButton.open,))
    170     rButtonIn.addResponse((rCatMenu.toggleVisible,))
    171     rButtonIn.setHover(STR.RESEARCH_HOVER)
    172 
    173     bButton.addResponse((bButtonIn.open,))
    174     bButton.addResponse((rButtonIn.close,))
    175     bButton.setHover(STR.BUILD_HOVER)
    176 
    177     bButtonIn.addWindow(bCatMenu)
    178     bButtonIn.addResponse((bButtonIn.close,))
    179     bButtonIn.addResponse((bButton.open,))
    180     bButtonIn.addResponse((bCatMenu.toggleVisible,))
    181     bButtonIn.setHover(STR.BUILD_HOVER)
    182     # end turn button
    183     endTurnButton = OnScreenButton(DIM.END_POS, True, 'END TURN')
    184 
    185     endTurnResponses = [(top.endTurn,),
    186                        (top.update,)]
    187     endTurnAlert = Alert(False, '', endTurnResponses)
    188     endTurnAlert.setUpdateHandler(alertUpdateHandlers.endUpdate)
    189     endTurnButton.addResponse((endTurnAlert.open, ))
    190     endTurnButton.addWindow(endTurnAlert)
    191 
    192     endTurnButton.setHover(STR.END_TURN_HOVER)
    193     # undo turn button
    194     undoTurnButton = OnScreenButton(DIM.UNDO_POS, True, 'UNDO TURN')
    195 
    196     undoAlert = Alert(False, STR.UNDO_ACTIVE, [(top.undoTurn,)])
    197     undoAlert.setUpdateHandler(alertUpdateHandlers.undoUpdate)
    198     undoTurnButton.addResponse((undoAlert.open, ))
    199     undoTurnButton.addWindow(undoAlert)
    200     undoTurnButton.setHover(STR.UNDO_HOVER)
    201     # main menu button
    202     menuButton = OnScreenButton(DIM.MENU_POS, True, 'MAIN MENU')
    203     menuButton.addResponse((top.menu, False))
    204 
    205     menuButton.setHover(STR.MAIN_MENU_HOVER)
    206 
    207     ###########################################################################
    208 
    209     newMap = map_.Map(True, top.deleteBuilding,
    210                       (top.mainScreen,))
    211 
    212     ###########################################################################
    213 
    214     statsWindow = StatDisplaySpec(top.getSpec(True))
    215 
    216     ###########################################################################
    217 
    218     top.addMenuWindow(menuBackground)
    219     toolbarBack.addWindow(menuButton)
    220     toolbarBack.addWindow(bButton)
    221     toolbarBack.addWindow(rButton)
    222     toolbarBack.addWindow(undoTurnButton)
    223     toolbarBack.addWindow(endTurnButton)
    224     toolbarBack.addResponse((top.mainScreen,))
    225     gameBackground.addWindow(toolbarBack)
    226     gameBackground.addWindow(statsWindow)
    227     gameBackground.addWindow(newMap)
    228 
    229     ###########################################################################
    230     """
    231     # Setup tutorial
    232     tutorial = Tutorial()
    233 
    234     # Research button
    235     tutorial.addWindow(TutBut(rButton))
    236 
    237     # Research power button
    238     rPowButtonIndex = rCatMenu.getElementByAttr(ResearchMenuEntry, "researchCat", POWER)
    239     tutorial.addWindow(TutBut(rCatMenu.subwindows[rPowButtonIndex]))
    240 
    241     # Research power description research button
    242     tutRButton = rCatMenu.subwindows[rPowButtonIndex].getElementByAttrRecursive(SimpleButton, "affirmative")
    243     #tutRButton = rCatMenu.subwindows[rPowButtonIndex].subwindows[0].subwindows[0]
    244     tutorial.addWindow(TutBut(tutRButton))
    245 
    246     # Build Button
    247     tutorial.addWindow(TutBut(bButton))
    248 
    249     # Build power button
    250     tutorial.addWindow(TutBut(bCatMenu.subwindows[POWER + 1]))
    251 
    252     # Build power windmill button
    253     pageOffset = bTutList[POWER].pageOffset
    254     windmillIndex = bTutList[POWER].subwindows[pageOffset].getElementByAttr(BuildMenuEntry, "buildingName", "windmill")
    255     tutorial.addWindow(TutBut(bTutList[POWER].subwindows[pageOffset].subwindows[windmillIndex]))
    256 
    257     # Build power windmill description build button
    258     windmillBuildButton = bTutList[POWER].subwindows[pageOffset].subwindows[windmillIndex].getElementByAttrRecursive(SimpleButton, "affirmative")
    259     tutorial.addWindow(TutBut(windmillBuildButton))
    260     #tutorial.addWindow(TutBut(bTutList[0].subwindows[2].subwindows[2].\
    261     #                            subwindows[0].subwindows[0]))
    262     # EndTurn Button
    263     tutorial.addWindow(TutBut(endTurnButton))
    264 
    265     top.addTutorialWindow(tutorial)
    266     """
    267 
    268     top.addGameWindow(gameBackground)
    269 
    270     ###########################################################################
    271 
    272     top.event(pygame.event.Event(VIDEORESIZE, {'w': SCREEN_W,
    273                                                   'h': SCREEN_H}))
     77    # Cut from here and put into top.py
     78   
    27479    top.render(screenSurface)
    275 
    27680    pygame.display.update()
    27781    return top
  • src/scripts/generateHeuristics.py

    r759 r766  
    3636    loseResource = Heuristic("lose_resource")
    3737    loseResource.setPriority()
    38     losingLowerSpec = Spec(-1, 1, -1, sys.maxint)
     38    losingLowerSpec = Spec(-1, -1, -1, sys.maxint)
    3939    loseResource.setLowerTrig(losingLowerSpec)
    4040    saveHeuristic(loseResource)
     
    6262    invasive.setBuildingTrig("plane", 1, False)
    6363    invasive.setBuildingTrig("car", 3, False)
    64     invasive.setStateChange(Spec(0, 0, 0, 0))
     64    invasive.setStateChange(Spec(0, 0, -50, 0))
    6565    invasive.setProb(.2, .07)
    6666    invasive.repeat = True
     
    7070    fire = Heuristic("fire")
    7171    fire.setAbsentBuildingTrig("fire truck")
    72     fire.setStateChange(Spec(-10, 0, 0, 20))
     72    fire.setBuildingTrig("tree", 1, False)
     73    fire.setBuildingsToDelete(["tree"])
     74    fire.setStateChange(Spec(0, 0, -50, 20))
    7375    fire.setProb(.1, .02)
    7476    fire.repeat = True
    7577    saveHeuristic(fire)
    7678
    77     ############################ invasive species  ###########################
     79    ############################ environmental ###############################
    7880    environmental = Heuristic("environmental")
    7981    environmental.setBuildingTrig("tree", 4, False)
  • src/top.py

    r758 r766  
    1919from rectangle import Rectangle
    2020from dim import hoverDescriptionDim as HOVER_DIM
     21from dim import mainDim as MAIN_DIM
    2122import strings as STR
    2223import dimensions as DIM
     
    2425from globals import *
    2526
     27from toolbar import Toolbar
     28from background import Background
     29from mainMenu import MainMenu
     30from statDisplaySpec import StatDisplaySpec
     31from inGameMenu import InGameMenu
     32from onScreenButton import OnScreenButton
     33from menuEntry import MenuEntry
     34from mainMenuButton import MainMenuButton
     35from info import Info
     36from researchMenu import ResearchMenu
     37from dialogue import Dialogue
     38from tutorial import Tutorial
     39from buildMenu import BuildMenu
     40from buildMenuEntry import BuildMenuEntry
     41import alertUpdateHandlers
     42from researchMenuEntry import ResearchMenuEntry
     43from tutorialButton import TutorialButton as TutBut
     44from simpleButton import SimpleButton
     45from loadDialogue import LoadDialogue
    2646
    2747class Top:
     
    4868        self.hover = NO_HOVER
    4969        self.inMainMenu = True
    50         self.hoverDescripRect = Rectangle(HOVER_DIM.POS, HOVER_DIM.W, HOVER_DIM.H)
    51 
     70        self.hoverDescripRect = Rectangle(HOVER_DIM.POS, HOVER_DIM.W, HOVER_DIM.H)
     71        self.map = Map(True, self.deleteBuilding,(self.mainScreen,))
     72        self.initialize()
     73
     74    def initialize(self):
     75        """
     76        Initializes the game (cut from main)
     77
     78        input type: none
     79        return type: none
     80        """
     81       
     82        gameBackground = Background(MAIN_DIM.GAME_BG_POS, True, None, True)
     83        ###########################################################################
     84
     85        menuBackground = Background((0, 0), True, 'menuBackground')
     86
     87        mainMenuWindow = MainMenu()
     88        self.setMenuModifier(mainMenuWindow.setConfiguration)
     89
     90        ###########################################################################
     91        # main menu screen buttons
     92        newGameButton = MainMenuButton((0, 0), True, STR.MENU_NEW, 1)
     93        newGameButton.addResponse((self.newGame, ))
     94
     95        resumeButton = MainMenuButton((0, 0), False, STR.MENU_RESUME, 0)
     96        resumeButton.addResponse((self.resume,))
     97
     98        loadForm = LoadDialogue(STR.LOAD_MSG, STR.MENU_LOAD)
     99        loadForm.addResponse((self.loadGame,))
     100
     101        loadButton = MainMenuButton((0, 0), True, STR.MENU_LOAD, 2)
     102        loadButton.addResponse((loadButton.openSubwindow,))
     103        loadButton.addWindow(loadForm)
     104
     105        saveForm = Dialogue(STR.LOAD_SAVE_MSG, STR.MENU_SAVE, STR.SAVED)
     106        saveForm.setYesResponse((self.saveGame, saveForm.getValue))
     107        saveForm.setYesResponse((saveForm.close,))
     108        saveButton = MainMenuButton((0, 0), False, STR.MENU_SAVE, 3)
     109        saveButton.addWindow(saveForm)
     110        saveButton.addResponse((saveButton.openSubwindow,))
     111
     112        quitButton = MainMenuButton((0, 0), True, STR.MENU_QUIT, 4)
     113        confirm = Alert(False, "Are you sure you want to quit?",
     114                            [(self.quitGame,)])
     115        quitButton.addWindow(confirm)
     116        quitButton.addResponse((quitButton.openSubwindow,))
     117
     118        mainMenuWindow.addWindow(newGameButton)
     119        mainMenuWindow.addWindow(resumeButton)
     120        mainMenuWindow.addWindow(loadButton)
     121        mainMenuWindow.addWindow(saveButton)
     122        mainMenuWindow.addWindow(quitButton)
     123        mainMenuWindow.update(None)
     124
     125        menuBackground.addWindow(mainMenuWindow)
     126
     127        ###########################################################################
     128        # build and research buttons
     129        rButton = OnScreenButton(MAIN_DIM.RESEARCH_POS, True, STR.RESEARCH.upper(), False)
     130        rButtonIn = OnScreenButton(MAIN_DIM.RESEARCH_POS, False, STR.RESEARCH.upper(), True)
     131
     132        rButton.addWindow(rButtonIn)
     133
     134        bButton = OnScreenButton(MAIN_DIM.BUILD_POS, True, STR.BUILD.upper(), False)
     135        bButtonIn = OnScreenButton(MAIN_DIM.BUILD_POS, False, STR.BUILD.upper(), True)
     136
     137        bButton.addWindow(bButtonIn)
     138
     139        ###########################################################################
     140        # building category menu
     141        bCatMenu = InGameMenu(False, (bButtonIn.close,))
     142
     143        bTutList = []
     144        for i, cat in enumerate(CAT_LUT):
     145            bMenu2 = BuildMenu(False, i, self.build,
     146                                             (bButtonIn.close,))
     147            bTutList.append(bMenu2)
     148
     149            buildInfo = Info(cat, buildCatDescrip[i], buttonDir + cat)
     150            bMenuButton = MenuEntry((MAIN_DIM.ENTRY_L, MAIN_DIM.ENTRY_T + MAIN_DIM.ENTRY_SHIFT * i),
     151                                    False, buildInfo)
     152            bMenuButton.addResponse((bMenu2.open,))
     153            bMenuButton.addResponse((bCatMenu.toggleHidden,))
     154            bMenu2.setBackResponse((bCatMenu.toggleHidden,))
     155            bMenuButton.addWindow(bMenu2)
     156            bCatMenu.addWindow(bMenuButton)
     157
     158        ###########################################################################
     159        # research category menu
     160        rCatMenu = ResearchMenu(False, self.research, (rButtonIn.close,))
     161
     162        ###########################################################################
     163
     164        toolbarBack = Toolbar(True, 'toolbar_background')
     165
     166        # responses for research and build buttons
     167        rButton.addResponse((rButtonIn.open,))
     168        rButton.addResponse((bButtonIn.close,))
     169        rButton.setHover(STR.RESEARCH_HOVER)
     170
     171        rButtonIn.addWindow(rCatMenu)
     172        rButtonIn.addResponse((rButtonIn.close,))
     173        rButtonIn.addResponse((rButton.open,))
     174        rButtonIn.addResponse((rCatMenu.toggleVisible,))
     175        rButtonIn.setHover(STR.RESEARCH_HOVER)
     176
     177        bButton.addResponse((bButtonIn.open,))
     178        bButton.addResponse((rButtonIn.close,))
     179        bButton.setHover(STR.BUILD_HOVER)
     180
     181        bButtonIn.addWindow(bCatMenu)
     182        bButtonIn.addResponse((bButtonIn.close,))
     183        bButtonIn.addResponse((bButton.open,))
     184        bButtonIn.addResponse((bCatMenu.toggleVisible,))
     185        bButtonIn.setHover(STR.BUILD_HOVER)
     186        # end turn button
     187        endTurnButton = OnScreenButton(MAIN_DIM.END_POS, True, 'END TURN')
     188
     189        endTurnResponses = [(self.endTurn,),
     190                           (self.update,)]
     191        endTurnAlert = Alert(False, '', endTurnResponses)
     192        endTurnAlert.setUpdateHandler(alertUpdateHandlers.endUpdate)
     193        endTurnButton.addResponse((endTurnAlert.open, ))
     194        endTurnButton.addWindow(endTurnAlert)
     195
     196        endTurnButton.setHover(STR.END_TURN_HOVER)
     197        # undo turn button
     198        undoTurnButton = OnScreenButton(MAIN_DIM.UNDO_POS, True, 'UNDO TURN')
     199
     200        undoAlert = Alert(False, STR.UNDO_ACTIVE, [(self.undoTurn,)])
     201        undoAlert.setUpdateHandler(alertUpdateHandlers.undoUpdate)
     202        undoTurnButton.addResponse((undoAlert.open, ))
     203        undoTurnButton.addWindow(undoAlert)
     204        undoTurnButton.setHover(STR.UNDO_HOVER)
     205        # main menu button
     206        menuButton = OnScreenButton(MAIN_DIM.MENU_POS, True, 'MAIN MENU')
     207        menuButton.addResponse((self.menu, False))
     208
     209        menuButton.setHover(STR.MAIN_MENU_HOVER)
     210
     211        ###########################################################################
     212
     213        #newMap = map_.Map(True, top.deleteBuilding,(top.mainScreen,))
     214
     215        ###########################################################################
     216
     217        statsWindow = StatDisplaySpec(self.getSpec(True))
     218
     219        ###########################################################################
     220
     221        self.addMenuWindow(menuBackground)
     222        toolbarBack.addWindow(menuButton)
     223        toolbarBack.addWindow(bButton)
     224        toolbarBack.addWindow(rButton)
     225        toolbarBack.addWindow(undoTurnButton)
     226        toolbarBack.addWindow(endTurnButton)
     227        toolbarBack.addResponse((self.mainScreen,))
     228        gameBackground.addWindow(toolbarBack)
     229        gameBackground.addWindow(statsWindow)
     230        gameBackground.addWindow(self.map)
     231
     232        ###########################################################################
     233        """
     234        # Setup tutorial
     235        tutorial = Tutorial()
     236
     237        # Research button
     238        tutorial.addWindow(TutBut(rButton))
     239
     240        # Research power button
     241        rPowButtonIndex = rCatMenu.getElementByAttr(ResearchMenuEntry, "researchCat", POWER)
     242        tutorial.addWindow(TutBut(rCatMenu.subwindows[rPowButtonIndex]))
     243
     244        # Research power description research button
     245        tutorial.addWindow(TutBut(rCatMenu.subwindows[rPowButtonIndex].getElementByAttrRecursive(SimpleButton, "affirmative")))
     246
     247        # Build Button
     248        tutorial.addWindow(TutBut(bButton))
     249
     250        # Build power button
     251        tutorial.addWindow(TutBut(bCatMenu.subwindows[POWER + 1]))
     252
     253        # Build power windmill button
     254        pageOffset = bTutList[POWER].pageOffset
     255        windmillIndex = bTutList[POWER].subwindows[pageOffset].getElementByAttr(BuildMenuEntry, "buildingName", "windmill")
     256        tutorial.addWindow(TutBut(bTutList[POWER].subwindows[pageOffset].subwindows[windmillIndex]))
     257
     258        # Build power windmill description build button
     259        windmillBuildButton = bTutList[POWER].subwindows[pageOffset].subwindows[windmillIndex].getElementByAttrRecursive(SimpleButton, "affirmative")
     260        tutorial.addWindow(TutBut(windmillBuildButton))
     261        #tutorial.addWindow(TutBut(bTutList[0].subwindows[2].subwindows[2].\
     262        #                            subwindows[0].subwindows[0]))
     263        # EndTurn Button
     264        tutorial.addWindow(TutBut(endTurnButton))
     265
     266        self.addTutorialWindow(tutorial)
     267        """
     268
     269        self.addGameWindow(gameBackground)
     270
     271        ###########################################################################
     272
     273        self.event(pygame.event.Event(VIDEORESIZE, {'w': DIM.SCREEN_W,
     274                                                      'h': DIM.SCREEN_H}))
     275       
    52276    def event(self, e):
    53277        """
     
    337561        """
    338562            Sets the game data to the default state and spec.
     563            Sets the game data to the default state and spec.
    339564
    340565            input type: None
     
    342567        """
    343568        self.gameData = GameData(State())
     569        self.map = Map(True, self.deleteBuilding,(self.mainScreen,))
     570        self.initialize()
    344571        self.handleScene()
    345572
     
    432659            return type: none
    433660        """
    434         self.menuModifier(isLaunch)
     661        mainMenu = self.menuWindows[0].getElementByAttrRecursive(MainMenu)
     662        mainMenu.setConfiguration(False)
    435663        self.windows = self.menuWindows
    436664        self.removeScene()
Note: See TracChangeset for help on using the changeset viewer.