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 *
25 """ Layer 1 Drawables - Menu; this may change in the future. """
28 """ Which drawable currently has focus on this Screen object. """
31 """ Link to the Battle (model) """
34 """ Link to Asgard (controller) """
36 def __init__(self
,l1
,f
):
38 @param l1 : list of layer1 drawables
40 @param f : drawable that has focus
48 """ Draw each layer of this Screen object onto a given Surface. """
51 def addDrawable(self
,d
):
52 """ Add a drawable to layer1. """
55 def removeDrawable(self
,d
):
56 """ Remove a drawable from layer1. """
59 def getDrawableById(self
,id):
64 class BattleScreen(Screen
):
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
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
88 # Checking for existing startup menu drawable
90 if d
.id == "fighterstatus":
91 # Preserving select index of 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()
103 text
= "NAME HP MP STATUS"
104 sItem
= MenuDrawable("columns",self
,(400,25),(0,0),False,text
,None,1)
107 # Retrieving status afflictions of fighters
111 statuses
= f
.getStatus()
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) + \
119 sItem
= MenuDrawable("fighter" + str(targetId
),self
,(400,25),(0,25*targetId
),False,text
,None,2)
125 statuses
= f
.getStatus()
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) + \
133 sItem
= MenuDrawable("fighter" + str(targetId
),self
,(400,25),(0,25*targetId
),False,text
,None,2)
139 # Creating Fighter Status Menu Drawable
140 fStatus
= MenuDrawable("fighterstatus",self
,(400,200),(0,400),True,None,subM
,selindex
)
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
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
157 self
.removeDrawable(d
)
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)
165 # Creating Commands Menu Drawable
166 commands
= MenuDrawable("commands",self
,(150,150),(650,450),True,None,subM
,selindex
)
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. """
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
185 self
.removeDrawable(d
)
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
:
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. """
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
217 self
.removeDrawable(d
)
220 t
= transaction
.getTarget().getName()
222 # Retrieving stat changed
223 s
= transaction
.getStat()
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
)
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
240 # Checking for existing startup menu drawable
241 for d
in self
.layer1
:
243 # Preserving select index of drawable
244 selindex
= d
.selindex
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
)
307 self
.addDrawable(magic
)
309 def __abbrStatus(self
, s
):
310 """ Helper function for abbreviating statuses for fighters. """
314 elif s
== "paralysis":
321 def __stringStatus(self
, sList
):
322 """ Helper function for concatinating status abbreviations for fighter. """
326 sString
= sString
+ s
+ " "