source: trunk/PARPG/scripts/hud.py @ 74

Revision 74, 3.1 KB checked in by bretzel_parpg, 10 years ago (diff)

Added the first version of the HUD. Also updated the inventory so that when there is a different image then the normal one is dragged around, the imagebutton it was dragged from is restored to it's original "empty" image

Line 
1#!/usr/bin/python
2
3"""Import all necessary modules"""
4import fife
5import pychan
6from pychan.tools import callbackWithArguments as cbwa
7
8"""Main Hud class"""
9class Hud():
10    """
11    Arguments:
12        engine : an instance of the fife engine
13    """
14    def __init__(self, engine):
15        pychan.init(engine, debug = True)
16       
17        self.hud = pychan.loadXML("gui/hud.xml")
18
19        self.hp = self.hud.findChild(name="HealthPoints")
20        self.ap = self.hud.findChild(name="ActionPoints")
21        self.actionsBox = self.hud.findChild(name="ActionsBox")
22        self.actionsText = []
23        self.menu_displayed = False
24
25        self.events_to_map = {"menuButton":self.displayMenu, "saveButton":self.saveGame,
26                              "loadButton":self.loadGame}
27        self.hud.mapEvents(self.events_to_map) 
28        self.hud.show()
29
30        self.main_menu = pychan.loadXML("gui/hud_main_menu.xml")
31        self.menu_events = {"resumeButton":self.hideMenu, "saveButton":self.saveGame,
32                            "loadButton":self.loadGame, 
33                            "optionsButton":self.displayOptions}
34        self.main_menu.mapEvents(self.menu_events)
35
36    def refreshActionsBox(self):
37        """
38        Refresh the actions box so that it displays the contents of self.actionsText
39        """
40        self.actionsBox.items = self.actionsText
41
42
43    def addAction(self, action):
44        """
45        Add an action to the actions box.
46        All this function really does is append action to self.actionsText and then
47        call refreshActionsBox
48        """
49        self.actionsText.append(action)
50        self.refreshActionsBox()
51
52    def displayOptions(self):
53        print "options"
54
55    def displayMenu(self):
56        """
57        Displays the main in-game menu
58        """
59        if (self.menu_displayed == False):
60            self.main_menu.show()
61            self.menu_displayed = True
62        elif (self.menu_displayed == True):
63            self.hideMenu()
64
65    def hideMenu(self):
66        """
67        Hides the main in-game menu
68        """
69        self.main_menu.hide()
70        self.menu_displayed = False
71
72    def saveGame(self):
73        """
74        Open the save game dialog
75        """
76        print "save"
77
78    def loadGame(self):
79        """
80        Open the load game dialog
81        """
82        print "load"
83
84    def setHP(self, value):
85        """
86        Set the HP display on the HUD to value
87        NOTE: This does not in any way affect the character's actual health, only
88              what is displayed on the HUD
89        """
90        self.hp.text = value
91
92    def setAP(self, value):
93        """
94        Set the AP display on the HUD to value
95        NOTE: This does no in any way affect the character's actual AP, only
96              what is displayed on the HUD
97        """
98        self.ap.text = value
99       
100    def toggleInventory(self):
101        """
102        Manually toggles the inventory button
103        """
104        button = self.hud.findChild(name="inventoryButton")
105        if (button.toggled == 0):
106            button.toggled = 1
107        else:
108            button.toggled = 0
Note: See TracBrowser for help on using the repository browser.