factored out the EFFv2 saving into EFFImporter
[gemrb.git] / gemrb / GUIScripts / bg1 / GUICG12.py
blobadc98f435dbb87c80072096fb475af2c40b1f2b5
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 #character generation, appearance (GUICG12)
20 import GemRB
21 from GUIDefines import *
22 from ie_stats import *
23 import CharGenCommon
24 import GUICommon
27 AppearanceWindow = 0
28 CustomWindow = 0
29 PortraitButton = 0
30 PortraitsTable = 0
31 LastPortrait = 0
32 Gender = 0
34 def SetPicture ():
35 global PortraitsTable, LastPortrait
37 PortraitName = PortraitsTable.GetRowName (LastPortrait)+"G"
38 PortraitButton.SetPicture (PortraitName)
39 return
41 def OnLoad():
42 global AppearanceWindow, PortraitButton, PortraitsTable, LastPortrait
43 global Gender
45 if GUICommon.CloseOtherWindow (OnLoad):
46 if(AppearanceWindow):
47 AppearanceWindow.Unload()
48 return
50 GemRB.LoadWindowPack("GUICG")
51 AppearanceWindow = GemRB.LoadWindow (11)
53 #Load the Gender
54 MyChar = GemRB.GetVar ("Slot")
55 Gender = GemRB.GetPlayerStat (MyChar, IE_SEX)
57 #Load the Portraits Table
58 PortraitsTable = GemRB.LoadTable ("PICTURES")
59 PortraitsStart = PortraitsTable.FindValue (0, 2)
60 FemaleCount = PortraitsTable.GetRowCount () - PortraitsStart + 1
61 if Gender == 2:
62 LastPortrait = GemRB.Roll (1, FemaleCount, PortraitsStart-1)
63 else:
64 LastPortrait = GemRB.Roll (1, PortraitsTable.GetRowCount()-FemaleCount, 0)
66 PortraitButton = AppearanceWindow.GetControl (1)
67 PortraitButton.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_NO_IMAGE,OP_SET)
68 PortraitButton.SetState (IE_GUI_BUTTON_LOCKED)
70 LeftButton = AppearanceWindow.GetControl (2)
71 RightButton = AppearanceWindow.GetControl (3)
73 BackButton = AppearanceWindow.GetControl (5)
74 BackButton.SetText (15416)
76 CustomButton = AppearanceWindow.GetControl (6)
77 CustomButton.SetText (17545)
79 DoneButton = AppearanceWindow.GetControl (0)
80 DoneButton.SetText (11973)
81 DoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT,OP_OR)
83 RightButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, RightPress)
84 LeftButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, LeftPress)
85 BackButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, CharGenCommon.BackPress)
86 CustomButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, CustomPress)
87 DoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, NextPress)
89 flag = False
90 while True:
91 if PortraitsTable.GetValue (LastPortrait, 0) == Gender:
92 SetPicture ()
93 break
94 LastPortrait = LastPortrait + 1
95 if LastPortrait >= PortraitsTable.GetRowCount ():
96 LastPortrait = 0
97 if flag:
98 SetPicture ()
99 break
100 flag = True
102 AppearanceWindow.ShowModal(MODAL_SHADOW_NONE)
103 return
105 def RightPress():
106 global LastPortrait
107 while True:
108 LastPortrait = LastPortrait + 1
109 if LastPortrait >= PortraitsTable.GetRowCount ():
110 LastPortrait = 0
111 if PortraitsTable.GetValue (LastPortrait, 0) == Gender:
112 SetPicture ()
113 return
115 def LeftPress():
116 global LastPortrait
117 while True:
118 LastPortrait = LastPortrait - 1
119 if LastPortrait < 0:
120 LastPortrait = PortraitsTable.GetRowCount ()-1
121 if PortraitsTable.GetValue (LastPortrait, 0) == Gender:
122 SetPicture ()
123 return
125 def CustomDone():
126 global AppearanceWindow
128 Window = CustomWindow
129 Portrait = PortraitList1.QueryText ()
130 GemRB.SetToken ("LargePortrait", Portrait)
131 Portrait = PortraitList2.QueryText ()
132 GemRB.SetToken ("SmallPortrait", Portrait)
133 if Window:
134 Window.Unload ()
135 CharGenCommon.next()
136 return
138 def CustomAbort():
139 global CustomWindow
141 if CustomWindow:
142 CustomWindow.Unload ()
143 return
145 def LargeCustomPortrait():
146 Window = CustomWindow
148 Portrait = PortraitList1.QueryText ()
149 #small hack
150 if GemRB.GetVar ("Row1") == RowCount1:
151 return
153 Label = Window.GetControl (0x10000007)
154 Label.SetText (Portrait)
156 Button = Window.GetControl (6)
157 if Portrait=="":
158 Portrait = "NOPORTLG"
159 Button.SetState (IE_GUI_BUTTON_DISABLED)
160 else:
161 if PortraitList2.QueryText ()!="":
162 Button.SetState (IE_GUI_BUTTON_ENABLED)
164 Button = Window.GetControl (0)
165 Button.SetPicture (Portrait, "NOPORTLG")
166 return
168 def SmallCustomPortrait():
169 Window = CustomWindow
171 Portrait = PortraitList2.QueryText ()
172 #small hack
173 if GemRB.GetVar ("Row2") == RowCount2:
174 return
176 Label = Window.GetControl (0x10000008)
177 Label.SetText (Portrait)
179 Button = Window.GetControl (6)
180 if Portrait=="":
181 Portrait = "NOPORTSM"
182 Button.SetState (IE_GUI_BUTTON_DISABLED)
183 else:
184 if PortraitList1.QueryText ()!="":
185 Button.SetState (IE_GUI_BUTTON_ENABLED)
187 Button = Window.GetControl (1)
188 Button.SetPicture (Portrait, "NOPORTSM")
189 return
191 def CustomPress():
192 global PortraitList1, PortraitList2
193 global RowCount1, RowCount2
194 global CustomWindow
196 CustomWindow = Window = GemRB.LoadWindow (18)
197 PortraitList1 = Window.GetControl (2)
198 RowCount1 = PortraitList1.GetPortraits (0)
199 PortraitList1.SetEvent (IE_GUI_TEXTAREA_ON_CHANGE, LargeCustomPortrait)
200 GemRB.SetVar ("Row1", RowCount1)
201 PortraitList1.SetVarAssoc ("Row1",RowCount1)
203 PortraitList2 = Window.GetControl (4)
204 RowCount2 = PortraitList2.GetPortraits (1)
205 PortraitList2.SetEvent (IE_GUI_TEXTAREA_ON_CHANGE, SmallCustomPortrait)
206 GemRB.SetVar ("Row2", RowCount2)
207 PortraitList2.SetVarAssoc ("Row2",RowCount2)
209 Button = Window.GetControl (6)
210 Button.SetText (11973)
211 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, CustomDone)
212 Button.SetState (IE_GUI_BUTTON_DISABLED)
214 Button = Window.GetControl (7)
215 Button.SetText (15416)
216 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, CustomAbort)
218 Button = Window.GetControl (0)
219 PortraitName = PortraitsTable.GetRowName (LastPortrait)+"L"
220 Button.SetPicture (PortraitName, "NOPORTLG")
221 Button.SetState (IE_GUI_BUTTON_LOCKED)
223 Button = Window.GetControl (1)
224 PortraitName = PortraitsTable.GetRowName (LastPortrait)+"S"
225 Button.SetPicture (PortraitName, "NOPORTSM")
226 Button.SetState (IE_GUI_BUTTON_LOCKED)
228 Window.ShowModal (MODAL_SHADOW_GRAY)
229 return
231 def NextPress():
232 PortraitTable = GemRB.LoadTable ("pictures")
233 PortraitName = PortraitTable.GetRowName (LastPortrait )
234 GemRB.SetToken ("SmallPortrait", PortraitName+"S")
235 GemRB.SetToken ("LargePortrait", PortraitName+"L")
236 CharGenCommon.next()
237 #GemRB.SetVar("Step",1)
238 #GemRB.SetNextScript("CharGen")
239 #GemRB.SetNextScript ("CharGen2") #Before race
240 #return