Changeset 519


Ignore:
Timestamp:
04/17/12 03:29:14 (3 years ago)
Author:
jelinson
Message:

optimized rendering; fixed bug with alerts; lots of tweaks with hover events

Files:
1 deleted
18 edited

Legend:

Unmodified
Added
Removed
  • .pydevproject

    r513 r519  
    44<pydev_project>
    55<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
    6 <path>/mt</path>
    7 <path>/mt/src</path>
    8 <path>/mt/dim</path>
     6<path>/cs121sp2012_5</path>
     7<path>/cs121sp2012_5/src</path>
     8<path>/cs121sp2012_5/dim</path>
    99</pydev_pathproperty>
    1010<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
  • design/testing/test_plans.tex

    r518 r519  
    8383 EC & 4/16/12 & 12:00 AM & Updated test for \hypl{state:check}{\tc{blue}{Check Thresholds}} with new space requirements & Passed \\
    8484 \hline
     85 JE & 4/17/12 & 1:00 AM & Rerunning regression test for \hypl{top:save}{\tc{blue}{Save and Load}} to ensure confirmation message works with new alert design & Failed, see \hypl{bug:saveloadalert}{\tc{blue}{save and load alert bug}}\\
     86 \hline
    8587\end{longtable}
    8688\end{center}
     
    9294ID & Date & Time & Description & Context \\
    9395\hline
    94 \hypt{bug:negres}{JE} & 3/23/12 & 4:00 PM & State erroneously allows more research to be performed than the current money, resulting in negative money. Moreover, it allows for negative research to be performed, which would provide a way to generated money. & This bug was found on the alpha release. It was found by running the Python unit test $$\verb+test_research()+$$ in the class$$\verb+/src/tests/test_state+$$ The assertion failures catch and describe the bug with a specified message.\\
    95 \hline
    96 \hypt{bug:button}{JE} & 3/26/12 & 11:00 PM & The right arrow button on the map display disappears & This bug was found on the March 26 prototype release. It was found by launching the game, then New Game $\rightarrow$ Build $\rightarrow$ Power $\rightarrow$ Windmill $\rightarrow$ Buy $\rightarrow$ End Turn. Then click on the icon of the windmill on the map and the right button disappears. Notice, however, that it disappears only for that block (which you can tell by selecting the icon of any of the other blocks)\\
     96\hypt{bug:negres}{JE} & 3/23/12 & 4:00 PM & State erroneously allows more research to be performed than the current money, resulting in negative money. Moreover, it allows for negative research to be performed, which would provide a way to generated money.\newline \textbf{Update}: Bug has been corrected -- JE, 4/16/12 & This bug was found on the alpha release. It was found by running the Python unit test $$\verb+test_research()+$$ in the class$$\verb+/src/tests/test_state+$$ The assertion failures catch and describe the bug with a specified message.\\
     97\hline
     98\hypt{bug:button}{JE} & 3/26/12 & 11:00 PM & The right arrow button on the map display disappears \newline\textbf{Update}: Bug has been corrected -- JE, 4/16/12 & This bug was found on the March 26 prototype release. It was found by launching the game, then New Game $\rightarrow$ Build $\rightarrow$ Power $\rightarrow$ Windmill $\rightarrow$ Buy $\rightarrow$ End Turn. Then click on the icon of the windmill on the map and the right button disappears. Notice, however, that it disappears only for that block (which you can tell by selecting the icon of any of the other blocks)\\
    9799\hline
    98100\hypt{bug:loadFalse}{EC} & 4/02/12 & 11:30 PM & The game just creates a new game and starts there without providing an alert that the user was unable to load or giving the user a second opportunity to load a game. & This bug was found by attempting to load a game that does not exist, i.e., one that was not previously saved.\\
     
    100102\hypt{bug:refreshBlock}{EC} & 4/02/12 & 11:30 PM & The map blocks do not reset to block 0 or whatever the correct block is for the saved game.  & This bug was found by starting a new game or loading a previously saved game after beginning progress on a new game and switching blocks.  The block that was open in the new game is the same which is open after these actions are preformed.  However, the menus are reset and any open ones are closed upon either of these actions. \\
    101103\hline
    102 \hypt{bug:skipinto}{JE} & 4/03/12 & 1:00 AM & The introduction scene can be skipped by starting a new game, going back and then resuming. Essentially, the scene can be truncated since resuming does not take the progression of the scene into consideration. & This bug was found in the most recent release of the game by doing: New Game $\rightarrow$ [Left arrow] $\rightarrow$ Resume. This will bring the player to the main screen, thereby skipping the remainder of the introduction scene.\\
     104\hypt{bug:skipinto}{JE} & 4/03/12 & 1:00 AM & The introduction scene can be skipped by starting a new game, going back and then resuming. Essentially, the scene can be truncated since resuming does not take the progression of the scene into consideration.\newline \textbf{Update}: Bug has been corrected -- JE, 4/16/12 & This bug was found in the most recent release of the game by doing: New Game $\rightarrow$ [Left arrow] $\rightarrow$ Resume. This will bring the player to the main screen, thereby skipping the remainder of the introduction scene.\\
    103105\hline
    104106\hypt{bug:outOfMemory}{EC} & 4/09/12 & 11:00 PM & The game runs out of memory by building one object and then continuously clicking end turn. & This bug was found in the April 10 Prototype by clicking New Game $\rightarrow$ Clicking through intro $\rightarrow$ Clicking through tutorial $\rightarrow$ End Turn (many times quickly).  Pygame crashes with error message Pygame.error Out of Memory.  Repeating this also gives various chains of updates where it crashes with the same error. \\
    105107\hline
    106 \hypt{bug:skipTutorial}{EC} & 4/09/12 & 11:00 PM & The tutorial can be skipped by using the left or right arrow keys to switch map blocks. & The bug was found in the April 10 Prototype by clicking New Game $\rightarrow$ Clicking through intro $\rightarrow$ [Left arrow] or [Right arrow].  This will bring the player to the main screen, skipping the entire tutorial.\\
     108\hypt{bug:skipTutorial}{EC} & 4/09/12 & 11:00 PM & The tutorial can be skipped by using the left or right arrow keys to switch map blocks. \newline \textbf{Update}: Bug has been corrected -- JE, 4/16/12 & The bug was found in the April 10 Prototype by clicking New Game $\rightarrow$ Clicking through intro $\rightarrow$ [Left arrow] or [Right arrow].  This will bring the player to the main screen, skipping the entire tutorial.\\
    107109\hline
    108110\hypt{bug:emptyMenuPage}{RT} & 4/16/12 & 4:00 PM & If the number of buildings in a build category is an even multiple of the page size there will be an extra blank page at the end. & The bug was found in the April 17th prototype by clicking [Right arrow]  $\rightarrow$ [Right arrow] in the vehicles menu with a page size of 2.\\
     111\hline
     112\hypl{bug:saveloadalert}{JE} & 4/17/12 & 1:00 AM & Save and load confirmation windows only work by clicking any \emph{except} the confirmation button; response must be improperly tied to the window itself, rather than its button & In pre-beta release, Main Menu $\rightarrow$ Save $\rightarrow$ [any input] $\rightarrow$ Save $\rightarrow$ OK\\
    109113\hline
    110114\end{longtable}
  • src/alert.py

    r511 r519  
    2020    """
    2121
    22     def __init__(self, pos, visible, message, yesResponse=None, yesText="Ok"):
     22    def __init__(self, pos, visible, message, yesResponses=None, yesText="Ok"):
    2323        """
    2424            Initializes object.
    25            
     25
    2626            input type: (int int)(pos) bool(visible) str(message)
    2727                        function(yesResponse) str(yesText)
     
    3737                              FAKEBLACK, DIM.MSG_WIDTH))
    3838
    39         if yesResponse is not None:
     39        if yesResponses is not None:
    4040
    4141            yesButton = SimpleButton((self.pos[0] +
     
    4343                                                 self.pos[1] + 150 - 30),
    4444                                                self.visible, yesText, True)
    45             yesButton.addResponse(yesResponse)
     45            for response in yesResponses:
     46                yesButton.addResponse(response)
    4647            yesButton.addResponse((self.closeWindow,))
    4748            self.subwindows.append(yesButton)
     
    6162        """
    6263            adds the function to call when the affirmative button is pressed.
    63            
     64
    6465            input type: function(response)
    6566            return type: none
     
    7071        """
    7172            opens the window and subwindows.
    72            
     73
    7374            input type: none
    7475            return type: none
     
    8182            runs default windows response and then returns true.
    8283            This ensures that no other windows will respond.
    83            
     84
    8485            input type: pygame.event(e)
    8586            return type: bool
     
    9192        """
    9293            Allows the update function to be redefined.
    93            
     94
    9495            input type: function(updateFunc)
    9596            return type: none
     
    100101        """
    101102            updates the window and all subwindows.
    102            
     103
    103104            input type: state(state)
    104105            return type: none
  • src/alien.py

    r511 r519  
    1717        The alien class creates random aliens on blocks.
    1818    """
    19    
     19
    2020    def __init__(self, pos, visible, blockNum, alienArt, message=None):
    2121        """
     
    3131        self.subwindows.append(responseAlert)
    3232        self.hoverDescription = HoverDescription('Click to talk!')
    33        
     33
    3434    def hover(self,surface):
    3535        """
    3636            Define the hover window for the object, by default none.
    37            
     37
    3838            input type: None
    3939            return type: None
  • src/background.py

    r511 r519  
    44@author: TechTrek
    55'''
    6 
    7 import pygame
    86
    97from window import Window
     
    1614        Background is an image that does not interact with the user.
    1715    """
    18    
     16
    1917    def __init__(self, pos, visible, image, doRestore=False):
    2018        """
  • src/dialogue.py

    r512 r519  
    192192            if self.subwindows[i].affirmative:
    193193                if self.confirm:
    194                     self.subwindows[i].subwindows[0].addResponse(response)
     194                    self.subwindows[i].subwindows[0].addYesResponse(response)
    195195                else:
    196196                    self.subwindows[i].addResponse(response)
  • src/dim/hoverDescriptionDim.py

    r495 r519  
    1 POS = (680, 500)
     1POS = (680, 660)
  • src/globals.py

    r490 r519  
    2020# 5 == NONE
    2121DEBUG = 5
     22
     23NO_HOVER = -1
  • src/hoverDescription.py

    r512 r519  
    66
    77from window import Window
    8 from rectangle import Rectangle
    98from text import Text
    109from image import Image
    1110from dim import hoverDescriptionDim as DIM
     11import dimensions
    1212from globals import *
    13 
    1413
    1514
     
    1817        The general hover description for other buttons.
    1918    """
    20    
     19
    2120    def __init__(self, text):
    2221        """
    2322            initializes the hover description.
    24            
     23
    2524            input type: str(text)
    2625            return type: none
     
    2827        Window.__init__(self, DIM.POS, True)
    2928
    30         self.images.append(Image(DIM.POS, 400, 60, buttonDir + "info_background"))
    31        
     29        self.images.append(Image(DIM.POS, 400, 80, buttonDir + "info_background"))
     30
    3231        self.text.append(Text((DIM.POS[0] + 5, DIM.POS[1] + 5),
    33                               text, XSM_TEXT, WHITE, width=380))
     32                              text, SM_TEXT, WHITE, width=380))
     33
     34    def render(self, surface):
     35        if surface is not None:
     36            self.resize(dimensions.SCREEN_W / float(ORIG_SCREEN_W),
     37                        dimensions.SCREEN_H / float(ORIG_SCREEN_H))
     38            Window.render(self, surface)
  • src/image.py

    r508 r519  
    3232            raw_image = pygame.image.load(os.path.join(imagePath + imgExt))
    3333            imageLUT[imagePath] = raw_image
    34    
     34
    3535        self.image = pygame.transform.smoothscale(raw_image, (width, height))
    3636        self.pos = (self.left, self.top) = pos
  • src/lang.py

    r509 r519  
    1111    """
    1212        Helper function for language analysis
    13        
     13
    1414        input type: [str(items)]
    1515        return type: str(output)
  • src/leftRight.py

    r509 r519  
    2626
    2727        self.images.append(Image(self.pos, ARROW_SIZE, ARROW_SIZE, icon))
    28    
    29        
  • src/main.py

    r516 r519  
    6060    newTop = top.Top(screenSurface)
    6161
    62     gameBackground = background.Background((90, 0), True,
    63                                            'background', True)
     62    gameBackground = background.Background((90, 0), True, None, True)
    6463    ###########################################################################
    6564
     
    106105    mainMenuWindow.addWindow(quitButton)
    107106    mainMenuWindow.update(None)
     107
    108108    menuBackground.addWindow(mainMenuWindow)
    109109
     
    195195    researchButtonIn.addResponse((researchButton.openWindow,))
    196196    researchButtonIn.addResponse((researchCatMenu.toggle,))
    197    
     197
    198198    researchButtonIn.hoverDescription = HoverDescription(researchText)
    199199
     
    211211    endTurnButton = onScreenButton.OnScreenButton((15, 650), True,
    212212                                                  'END TURN')
     213
     214    endTurnResponses = [(newTop.endTurn,),
     215                       (newTop.update, newTop.gameData.currentState)]
    213216    endTurnAlert = alert.Alert((300, 200), False,
    214                             '', (newTop.endTurn, ))
    215     endTurnAlert.addYesResponse((newTop.update, newTop.gameData.currentState))
     217                            '', endTurnResponses)
     218    #endTurnAlert.addYesResponse((newTop.update, newTop.gameData.currentState))
    216219    endTurnAlert.defineUpdate(alertUpdateFunc.endUpdate)
    217220    endTurnButton.addResponse((endTurnAlert.openWindow, ))
     
    224227    undoTurnText = "Click to undo everything you did this turn!"
    225228    undoTurnButton.hoverDescription = HoverDescription(undoTurnText)
    226    
     229
    227230    undoText = "You are about to undo the current turn. "
    228231    undoText += "Are you sure you want to do this?"
    229232    undoAlert = alert.Alert((300, 200), False,
    230233                            undoText,
    231                             (newTop.undoTurn, ))
     234                            [(newTop.undoTurn,)])
    232235    undoAlert.defineUpdate(alertUpdateFunc.undoUpdate)
    233236    undoTurnButton.addResponse((undoAlert.openWindow, ))
     
    237240                                               'MAIN MENU')
    238241    menuButton.addResponse((newTop.menu, False))
    239    
     242
    240243    menuText = "Click to return to the main menu!"
    241244    menuButton.hoverDescription = HoverDescription(menuText)
     
    302305    pygame.display.update()
    303306    return newTop
    304    
     307
     308
    305309def main():
    306310    # initialize pygame modules
     
    310314        pygame.quit()
    311315        sys.exit()
    312    
     316
    313317    # initialize our game
    314318    top = initialize()
     
    322326
    323327if __name__ == '__main__':
    324     main()
    325     #cProfile.run('main()')
     328    main()
     329    #cProfile.run('main()')
  • src/mainMenu.py

    r513 r519  
    100100            output type: none
    101101        """
     102        print "Main menu updating"
    102103        self.buildWindow()
    103104        Window.update(self, state)
  • src/mapBuilding.py

    r513 r519  
    3535
    3636        deleteAlert = Alert((300, 200), False, message,
    37                             (deleteResponse, self.blockNum, self.buildingSlot),
     37                            [(deleteResponse, self.blockNum, self.buildingSlot)],
    3838                            "Delete")
    3939
  • src/top.py

    r500 r519  
    4343        self.surface = surface
    4444        self.gameData = GameData(State(Spec()))
    45         self.hover = None
     45        self.hover = NO_HOVER
     46        self.inMainMenu = True
    4647
    4748    def event(self, e):
     
    5253            return type: none
    5354        """
     55        draw = False
    5456        if e.type == MOUSEBUTTONDOWN or e.type == KEYDOWN \
    55         or e.type == KEYUP or e.type == MOUSEMOTION:
    56             if DEBUG == 0:
    57                 print "+++++++++++++++++++++New Event+++++++++++++++++++++"
     57                or e.type == KEYUP or e.type == MOUSEMOTION:
     58            print "+++++++++++++++++++++New Key Event+++++++++++++++++++++"
    5859            for window in self.windows:
    5960                if window.isVisible() == True:
     
    6364                            self.windows.remove(window)
    6465                            self.windows.insert(0, window)
     66                        draw = True
    6567                        break
    66                     if returnValue != True and returnValue != False:
     68                    elif returnValue is not True and returnValue is not False:
    6769                        if self.hover == returnValue:
    6870                            break
    6971                        self.hover = returnValue
    70                         self.render(self.surface)
    71                         break
     72                        draw = True
     73                        break
     74            if self.inMainMenu:
     75                draw = True
    7276            if len(self.currentScene) != 0:
    7377                self.windows = self.currentScene
    7478            self.update(self.gameData.currentState)
    75             self.resize(dimensions.SCREEN_W / float(ORIG_SCREEN_W),
    76                         dimensions.SCREEN_H / float(ORIG_SCREEN_H))
    77             self.render(self.surface)
    7879
    7980        # if quit signal, quit
    80         if e.type == QUIT:
     81        elif e.type == QUIT:
    8182            self.quitWarning()
    82             self.resize(dimensions.SCREEN_W / float(ORIG_SCREEN_W),
    83                         dimensions.SCREEN_H / float(ORIG_SCREEN_H))
    84             self.render(self.surface)
     83            draw = True
    8584
    8685        # video resize signal occurs when dragging edge of screen
    87         if e.type == VIDEORESIZE:
     86        elif e.type == VIDEORESIZE:
    8887            dimensions.SCREEN_W = e.w
    8988            dimensions.SCREEN_H = e.h
     
    101100            screenSurface.fill(BLACK)
    102101            self.render(screenSurface)
     102        if draw:
     103            self.resize(dimensions.SCREEN_W / float(ORIG_SCREEN_W),
     104                        dimensions.SCREEN_H / float(ORIG_SCREEN_H))
     105            self.render(self.surface)
    103106
    104107    def quitWarning(self):
    105108        """
    106109            Creates an alert for quitting the game
    107            
     110
    108111            input type: none
    109112            return type: none
    110113        """
    111114        confirm = Alert((0, 0), True, "Are you sure you want to quit?",
    112                         (self.quitGame,))
     115                        [(self.quitGame,)])
    113116        self.windows.insert(0, confirm)
    114117
     
    116119        """
    117120            Quits the game
    118            
     121
    119122            input type: none
    120123            return type: none
     
    131134            return type: None
    132135        """
     136        print "Rendering in top"
    133137        for window in reversed(self.windows):
    134138            window.render(surface)
    135         if self.hover != None:
     139        if self.hover != NO_HOVER:
    136140            self.hover(surface)
    137141        pygame.display.update()
     
    304308            resumes a current game by opening main screen windows
    305309            without any changes
    306            
     310
    307311            input type: none
    308312            return type: none
     
    323327        """
    324328            loads a scene, sets responses, then opens the windows to "play" it
    325            
     329
    326330            input type: none
    327331            return type: none
     
    330334        if sceneName is not None:
    331335            (scene, backResponse, forwardResponse) = loadScene(sceneName, auxText)
    332             print "Forward response %s" %forwardResponse
    333336            scene.setBackResponse(self.parseResponse(backResponse))
    334337            scene.setForwardResponse(self.parseResponse(forwardResponse))
    335338            scene.openWindow()
    336339            self.currentScene.append(scene)
     340            self.inMainMenu = False
    337341
    338342    def parseResponse(self, response):
    339343        """
    340344            parses the responses for the scene
    341            
     345
    342346            input type: str(response)
    343347            return type: function pointer
     
    355359        """
    356360            deletes the current scene
    357            
     361
    358362            input type: none
    359363            return type: none
     
    364368        """
    365369            removes all alerts in windows
    366            
     370
    367371            input type: none
    368372            return type: none
     
    375379        """
    376380            opens all subwindows
    377            
     381
    378382            input type: none
    379383            return type: none
     
    385389        """
    386390            closes all windows, including subwindows
    387            
     391
    388392            input type: none
    389393            return type: none
     
    392396            window.closeWindow()
    393397
    394     def setMenuModifier(self, menuMethod):   
     398    def setMenuModifier(self, menuMethod):
    395399        self.menuModifier = menuMethod
    396400
     
    398402        """
    399403            Opens the menu screen, closes all other screens
    400            
     404
    401405            input type: bool(isLaunch)
    402406            return type: none
     
    409413        self.closeWindows()
    410414        self.openWindows()
     415        self.inMainMenu = True
    411416
    412417    def mainScreen(self):
    413418        """
    414419            Opens the main game screen, closes all other screens
    415            
     420
    416421            input type: none
    417422            return type: none
     
    424429        self.openWindows()
    425430        self.windows = self.windows
     431        self.inMainMenu = False
    426432
    427433    def tutorialScreen(self):
    428434        """
    429435            opens the tutorial and the main screen behind it
    430            
     436
    431437            input type: none
    432438            return type: none
     
    438444        self.closeWindows()
    439445        self.openWindows()
    440 
     446        self.inMainMenu = False
    441447        self.gameData.enqueueScene("post_tut")
  • src/window.py

    r500 r519  
    1717        """
    1818            initializes a window
    19            
     19
    2020            input type: int((x, y)), bool(visible), bool(stayBack)
    2121        """
     
    4646            if window.isVisible():
    4747                returnValue = window.event(e)
    48                 if returnValue != False:
     48                if returnValue is not False:
    4949                    if not window.stayBack:
    5050                        self.subwindows.remove(window)
     
    7474        """
    7575            call response functions that had been designated to window
    76            
     76
    7777            input type: none
    7878            return type: none
     
    156156            for r in self.rectangles:
    157157                r.resize(xScale, yScale)
    158    
     158
    159159            for i in self.images:
    160160                i.resize(xScale, yScale)
    161    
     161
    162162            for t in self.text:
    163163                t.resize(xScale, yScale)
     
    339339                self.subwindows.pop(i)
    340340
    341     def hover(self,surface):
     341    def hover(self, surface):
    342342        """
    343343            returns the hover description to display, by default none.
     
    346346            return type: None
    347347        """
    348         return None
     348        return NO_HOVER
Note: See TracChangeset for help on using the changeset viewer.