1 # GemRB - Infinity Engine Emulator
2 # Copyright (C) 2003 The GemRB Project
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 # common character generation display code
23 from ie_stats
import *
24 from GUIDefines
import *
27 def __init__(self
,stages
,startText
,importFn
,resetButton
=False):
28 """Sets up a character generation system.
29 slot: index of slot for which to generate
31 startText: text to set info field in stage 0
32 importFn: function ran when import is pressed
33 resetButton: whether or not to show a reset button
35 where each stage is defined by either an intermediate screen:
37 control: id of the controle
38 text: id of button text or string to use
41 script | setFn: script name to proceed or function to request and set data for this stage
42 commentFn(area): function to append information to the text area
43 unsetFn: function to remove data for this stage
44 guard return wether or not to activate this stage
48 self
.showReset
= resetButton
51 self
.startText
=startText
53 def displayOverview(self
):
55 Sets up the primary character generation window.
56 show all comments of previous stages
59 CharGenWindow
= self
.window
61 GemRB
.LoadWindowPack ("GUICG", 640, 480)
62 CharGenWindow
= GemRB
.LoadWindow (0)
63 CharGenWindow
.SetFrame ()
68 PortraitButton
= CharGenWindow
.GetControl (12)
69 PortraitButton
.SetFlags(IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_NO_IMAGE
,OP_SET
)
70 PortraitName
= GemRB
.GetToken ("LargePortrait")
71 PortraitButton
.SetPicture (PortraitName
, "NOPORTMD")
72 PortraitButton
.SetState(IE_GUI_BUTTON_LOCKED
)
76 for stage
in self
.stages
:
77 if(len(stage
) == 3): #short stage
78 (name
,control
,text
) = stage
79 button
= CharGenWindow
.GetControl(control
)
82 button
.SetState(IE_GUI_BUTTON_ENABLED
)
83 button
.SetFlags (IE_GUI_BUTTON_DEFAULT
, OP_OR
)
84 button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, NextPress
)
86 button
.SetState(IE_GUI_BUTTON_DISABLED
)
90 BackButton
= CharGenWindow
.GetControl (11)
91 #BackButton.SetText (15416)
93 BackButton
.SetState (IE_GUI_BUTTON_ENABLED
)
95 BackButton
.SetState(IE_GUI_BUTTON_DISABLED
)
96 BackButton
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, BackPress
)
97 BackButton
.SetFlags (IE_GUI_BUTTON_CANCEL
, OP_OR
)
99 AcceptButton
= CharGenWindow
.GetControl (8)
100 playmode
= GemRB
.GetVar ("PlayMode")
102 AcceptButton
.SetText (11962)
104 AcceptButton
.SetText (13956)
107 ScrollBar
= CharGenWindow
.GetControl (10)
108 ScrollBar
.SetDefaultScrollBar()
111 ImportButton
= CharGenWindow
.GetControl (13)
112 ImportButton
.SetText (13955)
113 ImportButton
.SetState (IE_GUI_BUTTON_ENABLED
)
114 ImportButton
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, ImportPress
)
116 #set cancel and start over
117 CancelButton
= CharGenWindow
.GetControl (15)
118 if step
== 0 or not self
.showReset
:
119 CancelButton
.SetText (13727) # Cancel
121 CancelButton
.SetText (8159) # Start over
122 CancelButton
.SetState (IE_GUI_BUTTON_ENABLED
)
123 CancelButton
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, CancelPress
)
125 #set and fill overview
126 TextAreaControl
= CharGenWindow
.GetControl (9)
128 TextAreaControl
.SetText(self
.startText
)
130 TextAreaControl
.SetText("")
131 for part
in range(step
):
132 if(len(self
.stages
[part
]) == 5):
133 (name
,setFn
,commentFn
,unsetFn
,guard
) = self
.stages
[part
]
134 if(commentFn
!= None):
135 commentFn(TextAreaControl
)
138 CharGenWindow
.SetVisible(WINDOW_VISIBLE
)
139 CharGenWindow
.Invalidate()
140 self
.window
= CharGenWindow
142 def unset(self
,stage
):
143 #print "unset" , stage
144 if(len(self
.stages
[stage
]) == 5):
145 (name
,setFn
,commentFn
,unsetFn
,guard
) = self
.stages
[stage
]
148 #set next script to for step, return false if the current step should be skipped
150 #print 'set',self.step
151 if(len(self
.stages
[self
.step
]) == 5): #long record: script of function
152 (name
,setFn
,commentFn
,unsetFn
,guardFn
) = self
.stages
[self
.step
]
153 if(guardFn
and not guardFn()):
155 if(hasattr(setFn
, "__call__")):
158 GemRB
.SetNextScript(setFn
)
159 else: #short record: overview
160 GemRB
.SetNextScript ("CharGen")
164 """Revert back to the first step; unset all actions."""
166 # self.window.Unload()
168 for i
in range(self
.step
,-1,-1):
171 # if required back to main screen, otherwise reloop
172 if self
.step
== 0 or not self
.showReset
:
175 GemRB
.SetNextScript ("Start")
177 GemRB
.SetNextScript ("CharGen")
183 """Opens the character import window."""
187 """Moves to the previous step. Unsets last"""
188 GUICommon
.CloseOtherWindow(None)
189 self
.unset(self
.step
)
190 if len(self
.stages
[self
.step
]) == 3:
191 #short, return to other short
192 self
.step
= self
.step
- 1
193 self
.unset(self
.step
)
194 while len(self
.stages
[self
.step
]) != 3:
195 self
.step
= self
.step
- 1
196 self
.unset(self
.step
)
198 self
.step
= self
.step
- 1
199 self
.unset(self
.step
)
201 while(not self
.setScript()):
202 self
.step
= self
.step
- 1
203 self
.unset(self
.step
)
207 """Calls the next setter."""
208 GUICommon
.CloseOtherWindow(None)
209 self
.step
= self
.step
+ 1
210 while(not self
.setScript()):
211 self
.step
= self
.step
+ 1
220 for i
in range(len(self
.stages
)):
221 if(to
== self
.stages
[i
][0]):
225 raise ValueError("stage name not found: "+str(to
))
226 elif type(to
) == int:
228 to
= len(self
.stages
)+to
229 if(to
<0 or to
>=len(self
.stages
)):
230 raise ValueError("stage index not found: "+str(to
))
235 raise ValueError("bad arg type: "+str(type(to
)) + " " + str(to
))
236 GUICommon
.CloseOtherWindow(None)
237 while(not self
.setScript()):
238 self
.step
= self
.step
+ 1
243 """Revert back to the first step; if there, free the actor."""
245 CharGenMaster
.cancel()
248 """Opens the character import window."""
250 CharGenMaster
.imprt()
253 """Moves to the previous step."""
256 GemRB
.SetRepeatClickFlags(GEM_RK_DISABLE
, OP_OR
)
260 """Moves to the next step."""
265 """Moves to the previous step."""
270 """Moves to the next step."""
275 """Terminates CharGen."""
277 CharGenMaster
.close()
282 CharGenMaster
.jumpTo(stage
)