Lots of debugging. Fighter Status now displays when New Game is selected. This...
[asgard.git] / screen.py
blob4384f3006b8c95632803aaf35ccee6649c872ea5
1 ########################################################
2 #Copyright (c) 2006 Russ Adams, Sean Eubanks, Asgard Contributors
3 #This file is part of Asgard.
5 #Asgard is free software; you can redistribute it and/or modify
6 #it under the terms of the GNU General Public License as published by
7 #the Free Software Foundation; either version 2 of the License, or
8 #(at your option) any later version.
10 #Asgard is distributed in the hope that it will be useful,
11 #but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 #GNU General Public License for more details.
15 #You should have received a copy of the GNU General Public License
16 #along with Asgard; if not, write to the Free Software
17 #Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 ########################################################
19 from pygame import Surface
20 from drawable import *
22 class Screen:
24 layer1 = []
25 """ Layer 1 Drawables - Menu; this may change in the future. """
27 focus = None
28 """ Which drawable currently has focus on this Screen object. """
30 battle = None
31 """ Link to the Battle (model) """
33 cont = None
34 """ Link to Asgard (controller) """
36 def __init__(self,l1,f):
37 """
38 @param l1 : list of layer1 drawables
39 @type l1 : Drawable[]
40 @param f : drawable that has focus
41 @type f : drawable
42 """
44 self.layer1 = l1
45 self.focus = f
47 def draw(self):
48 """ Draw each layer of this Screen object onto a given Surface. """
49 pass
51 def addDrawable(self,d):
52 """ Add a drawable to layer1. """
53 self.layer1.append(d)
55 def removeDrawable(self,d):
56 """ Remove a drawable from layer1. """
57 self.layer1.remove(d)
59 def getDrawableById(self,id):
60 for d in self.layer1:
61 if d.id == id:
62 return d
64 class BattleScreen(Screen):
65 """
66 Driver for battle's graphical interface. All the methods in this
67 section will probably be rewritten to employ the use of a nicer, more
68 general user interface.
70 Given a draw method in this class, with the form draw*(): before
71 creating the datastructure for the MenuDrawable, layer1 must first be
72 checked. If it is in layer1, preserve the selected index of the
73 MenuDrawable, if it currently has focus and then delete the
74 MenuDrawable. Finally, create the MenuDrawable (that is, recreate it
75 if was just deleted).
77 """
79 def drawFighterStatus(self):
80 """ Draw the dialogue menu at the bottom left of the screen that is
81 used to describe that status of all in-game Fighter objects,
82 both playable and not. These should be sorted, monsters first
83 then playable heros. The columns are Name, HP, MP, Status.
84 Status contains a list of abbreviations for the current status
85 afflictions. """
87 selindex = 0
88 # Checking for existing startup menu drawable
89 for d in self.layer1:
90 if d.id == "fighterstatus":
91 # Preserving select index of drawable
92 selindex = d.selindex
93 # Removing drawable
94 self.removeDrawable(d)
96 # Retrieving fighters ("v"illains then "h"eros)
97 v = self.battle.getParty2().getFighters()
98 h = self.battle.getParty1().getFighters()
100 statl = []
101 subM = []
103 text = "NAME HP MP STATUS"
104 sItem = MenuDrawable("columns",self,(400,25),(0,0),False,text,None,1)
105 subM.append(sItem)
107 # Retrieving status afflictions of fighters
108 targetId = 1
110 for f in v:
111 statuses = f.getStatus()
112 for s in statuses:
113 statl.append(self.__abbrStatus(s))
114 vstring = self.__stringStatus(statl)
115 text = f.getName().ljust(10) + \
116 (str(f.getStat("hp").getCurrent()) + "/" + str(f.getStat("hp").getMax())).ljust(9) + \
117 (str(f.getStat("mp").getCurrent()) + "/" + str(f.getStat("mp").getMax())).ljust(7) + \
118 vstring.ljust(10)
119 sItem = MenuDrawable("fighter" + str(targetId),self,(400,25),(0,25*targetId),False,text,None,2)
120 subM.append(sItem)
121 statl = []
122 targetId += 1
124 for f in h:
125 statuses = f.getStatus()
126 for s in statuses:
127 statl.append(self.__abbrStatus(s))
128 vstring = self.__stringStatus(statl)
129 text = f.getName().ljust(10) + \
130 (str(f.getStat("hp").getCurrent()) + "/" + str(f.getStat("hp").getMax())).ljust(9) + \
131 (str(f.getStat("mp").getCurrent()) + "/" + str(f.getStat("mp").getMax())).ljust(7) + \
132 vstring.ljust(10)
133 sItem = MenuDrawable("fighter" + str(targetId),self,(400,25),(0,25*targetId),False,text,None,2)
134 subM.append(sItem)
135 statl = []
136 targetId += 1
139 # Creating Fighter Status Menu Drawable
140 fStatus = MenuDrawable("fighterstatus",self,(400,200),(0,400),True,None,subM,selindex)
141 fStatus.draw()
142 self.addDrawable(fStatus)
144 def drawCommands(self):
145 """ Draw a dialogue menu at the bottom right of the screen that
146 the user uses to select commands for playable Fighter objects.
147 At the moment, this should be limited to Attack, Magic, and
148 Quit. """
150 selindex = 0
151 # Checking for existing startup menu drawable
152 for d in self.layer1:
153 if d.id == "commands":
154 # Preserving select index of drawable
155 selindex = d.selindex
156 # Removing drawable
157 self.removeDrawable(d)
159 # Submenus
160 s1 = MenuDrawable("attack",self,(150,30),(0,0),True,"Attack",None,1)
161 s2 = MenuDrawable("magic",self,(150,30),(0,30),True,"Magic",None,2)
162 s3 = MenuDrawable("quit",self,(150,30),(0,60),True,"Quit",None,3)
163 subM = [s1,s2,s3]
165 # Creating Commands Menu Drawable
166 commands = MenuDrawable("commands",self,(150,150),(650,450),True,None,subM,selindex)
167 commands.draw()
168 self.addDrawable(commands)
170 def drawStartup(self):
171 """ Draw a the tentatitve startup/inbetween battle menu in the
172 center of the screen. It's current options are New Game, Load,
173 Save, Random Battle, and Quit. """
175 selindex = 0
176 pre_existed = False
177 # Checking for existing startup menu drawable
178 for d in self.layer1:
179 if d.id == "startup":
181 had_focus = (self.focus == d)
182 # Preserving select index of drawable
183 selindex = d.selindex
184 # Removing drawable
185 self.removeDrawable(d)
186 pre_existed = True
188 # Submenus...
189 s1 = MenuDrawable("NewGame",self,(200,30),(0,0),False,"New Game",None,1)
190 s2 = MenuDrawable("Load",self,(200,30),(0,30),False,"Load",None,2)
191 s3 = MenuDrawable("Save",self,(200,30),(0,60),False,"Save",None,3)
192 s4 = MenuDrawable("RandomBattle",self,(200,30),(0,90),False,"Random Battle",None,4)
193 s5 = MenuDrawable("Quit",self,(200,30),(0,120),False,"Quit",None,5)
194 subM = [s1,s2,s3,s4,s5]
196 # Creating Startup Menu Drawable
197 startup = MenuDrawable("startup",self,(200,150),(300,150),True,None,subM,selindex)
199 if not pre_existed or had_focus:
200 self.focus = startup
202 startup.draw()
204 self.addDrawable(startup)
206 def drawTransaction(self, transaction):
207 """ Draw a temporary transaction dialogue to the right of the
208 Fighter object that the transaction is taking place on. """
210 selindex = 0
211 # Checking for existing startup menu drawable
212 for d in self.layer1:
213 if d.id == "transaction":
214 # Preserving select index of drawable
215 selindex = d.selindex
216 # Removing drawable
217 self.removeDrawable(d)
219 # Retrieving target
220 t = transaction.getTarget().getName()
221 t = t + "\t\t"
222 # Retrieving stat changed
223 s = transaction.getStat()
224 s = s + ":\t"
225 # Retrieving stat change
226 c = transaction.getChange()
228 # Creating Transaction Menu Drawable
229 trans = MenuDrawable("transaction",self,(400,25),(0,375),True,None,None,selindex)
230 trans.draw()
231 self.addDrawable(trans)
233 def drawMagic(self, eventtypes):
234 """ Draw a menu used to select magic. "eventtypes" is the
235 list of strings that correspond to EventTypes that a particular
236 Fighter object can perform. If eventtypes is None, display a
237 blank menu."""
239 selindex = 0
240 # Checking for existing startup menu drawable
241 for d in self.layer1:
242 if d.id == "magic":
243 # Preserving select index of drawable
244 selindex = d.selindex
245 # Removing drawable
246 self.removeDrawable(d)
248 # Get available spells for fighter
249 spell1, spell2, spell3, spell4, spell5, spell6, spell7, spell8, spell9, spell10 = None
250 spell1 = eventtypes[0]
251 spell2 = eventtypes[1]
252 spell3 = eventtypes[2]
253 spell4 = eventtypes[3]
254 spell5 = eventtypes[4]
255 spell6 = eventtypes[5]
256 spell7 = eventtypes[6]
257 spell8 = eventtypes[7]
258 spell9 = eventtypes[8]
259 spell10 = eventtypes[9]
261 # Creating Spell Menu Drawables
262 mp = self.battle.getEventType(spell1).getMpCost()
263 spell1 = spell1 + " " + mp
264 s1 = MenuDrawable("spell1",self,(75,15),(0,0),False,spell1,None,1)
266 mp = self.battle.getEventType(spell2).getMpCost()
267 spell2 = spell2 + " " + mp
268 s2 = MenuDrawable("spell2",self,(75,15),(0,15),False,spell2,None,2)
270 mp = self.battle.getEventType(spell3).getMpCost()
271 spell3 = spell3 + " " + mp
272 s3 = MenuDrawable("spell3",self,(75,15),(0,30),False,spell3,None,3)
274 mp = self.battle.getEventType(spell4).getMpCost()
275 spell4 = spell4 + " " + mp
276 s4 = MenuDrawable("spell4",self,(75,15),(0,45),False,spell4,None,4)
278 mp = self.battle.getEventType(spell5).getMpCost()
279 spell5 = spell5 + " " + mp
280 s5 = MenuDrawable("spell5",self,(75,15),(0,60),False,spell5,None,5)
282 mp = self.battle.getEventType(spell6).getMpCost()
283 spell6 = spell6 + " " + mp
284 s6 = MenuDrawable("spell6",self,(75,15),(75,0),False,spell6,None,6)
286 mp = self.battle.getEventType(spell7).getMpCost()
287 spell7 = spell7 + " " + mp
288 s7 = MenuDrawable("spell7",self,(75,15),(75,15),False,spell7,None,7)
290 mp = self.battle.getEventType(spell8).getMpCost()
291 spell8 = spell8 + " " + mp
292 s8 = MenuDrawable("spell8",self,(75,15),(75,30),False,spell8,None,8)
294 mp = self.battle.getEventType(spell9).getMpCost()
295 spell9 = spell9 + " " + mp
296 s9 = MenuDrawable("spell9",self,(75,15),(75,45),False,spell9,None,9)
298 mp = self.battle.getEventType(spell10).getMpCost()
299 spell10 = spell10 + " " + mp
300 s10 = MenuDrawable("spell10",self,(75,15),(75,60),False,spell10,None,10)
302 subM = [s1,s2,s3,s4,s5,s6,s7,s8,s9,s10]
304 # Creating Magic Menu Drawable
305 magic = MenuDrawable("magic",self,(250,150),(550,275),True,None,subM,selindex)
306 magic.draw()
307 self.addDrawable(magic)
309 def __abbrStatus(self, s):
310 """ Helper function for abbreviating statuses for fighters. """
312 if s == "sleep":
313 return "SL"
314 elif s == "paralysis":
315 return "PA"
316 elif s == "poison":
317 return "PO"
318 elif s == "madness":
319 return "MA"
321 def __stringStatus(self, sList):
322 """ Helper function for concatinating status abbreviations for fighter. """
324 sString = ""
325 for s in sList:
326 sString = sString + s + " "
327 return sString