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