Mercurial > fife-parpg
comparison demos/rpg/scripts/guicontroller.py @ 511:773dc1dbe69d
Forgot to add guicontroller.py in my last commit.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Fri, 21 May 2010 13:48:49 +0000 |
parents | |
children | 6ddb1eb9dfa6 |
comparison
equal
deleted
inserted
replaced
510:cd959b05a262 | 511:773dc1dbe69d |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 # -*- coding: utf-8 -*- | |
4 | |
5 # #################################################################### | |
6 # Copyright (C) 2005-2010 by the FIFE team | |
7 # http://www.fifengine.net | |
8 # This file is part of FIFE. | |
9 # | |
10 # FIFE is free software; you can redistribute it and/or | |
11 # modify it under the terms of the GNU Lesser General Public | |
12 # License as published by the Free Software Foundation; either | |
13 # version 2.1 of the License, or (at your option) any later version. | |
14 # | |
15 # This library is distributed in the hope that it will be useful, | |
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 # Lesser General Public License for more details. | |
19 # | |
20 # You should have received a copy of the GNU Lesser General Public | |
21 # License along with this library; if not, write to the | |
22 # Free Software Foundation, Inc., | |
23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
24 # #################################################################### | |
25 # This is the rio de hola client for FIFE. | |
26 | |
27 import sys, os, re, math, random, shutil | |
28 | |
29 from fife import fife | |
30 from fife.extensions import pychan | |
31 from fife.extensions.pychan import widgets | |
32 | |
33 class MainMenu(object): | |
34 def __init__(self, guicontroller, gamecontroller, settings): | |
35 self._guicontroller = guicontroller | |
36 self._gamecontroller = gamecontroller | |
37 self._settings = settings | |
38 self._widget = pychan.loadXML('gui/mainmenu.xml') | |
39 | |
40 self._newgame = self._widget.findChild(name="new_game") | |
41 self._credits = self._widget.findChild(name="credits") | |
42 self._quit = self._widget.findChild(name="quit") | |
43 | |
44 self._widget.position = (0,0) | |
45 | |
46 eventMap = { | |
47 'new_game': self._gamecontroller.newGame, | |
48 'settings': self._settings.onOptionsPress, | |
49 'credits': self._guicontroller.showCredits, | |
50 'quit': self._gamecontroller.quit, | |
51 } | |
52 | |
53 self._widget.mapEvents(eventMap) | |
54 | |
55 def _getWidget(self): | |
56 return self._widget | |
57 | |
58 widget = property(_getWidget) | |
59 | |
60 class Credits(object): | |
61 def __init__(self, guicontroller): | |
62 self._guicontroller = guicontroller | |
63 self._widget = pychan.loadXML('gui/credits.xml') | |
64 | |
65 eventMap = { | |
66 'close': self._guicontroller.hideCredits, | |
67 } | |
68 | |
69 self._widget.mapEvents(eventMap) | |
70 | |
71 def _getWidget(self): | |
72 return self._widget | |
73 | |
74 widget = property(_getWidget) | |
75 | |
76 class GUIController(object): | |
77 def __init__(self, gamecontroller, engine, settings): | |
78 self._gamecontroller = gamecontroller | |
79 self._engine = engine | |
80 self._settings = settings | |
81 | |
82 self._mainmenu = None | |
83 self._credits = None | |
84 | |
85 def showMainMenu(self): | |
86 if self._mainmenu: | |
87 self._mainmenu.widget.show() | |
88 else: | |
89 #load and show the main menu | |
90 self._mainmenu = MainMenu(self, self._gamecontroller, self._settings) | |
91 self._mainmenu.widget.show() | |
92 | |
93 def hideMainMenu(self): | |
94 if self._mainmenu: | |
95 self._mainmenu.widget.hide() | |
96 self._mainmenu = None | |
97 | |
98 def showCredits(self): | |
99 if self._credits: | |
100 self._credits.widget.show() | |
101 else: | |
102 self._credits = Credits(self) | |
103 self._credits.widget.show() | |
104 | |
105 def hideCredits(self): | |
106 if self._credits: | |
107 self._credits.widget.hide() | |
108 self._credits = None |