factored out the EFFv2 saving into EFFImporter
[gemrb.git] / gemrb / GUIScripts / iwd2 / Portrait.py
blobdb1245d7546de55d59c374d2438a6a0fdb4b2ae9
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 *
23 AppearanceWindow = 0
24 PortraitButton = 0
25 PortraitsTable = 0
26 LastPortrait = 0
27 Gender = 0
29 def SetPicture ():
30 global PortraitsTable, LastPortrait
32 PortraitName = PortraitsTable.GetRowName (LastPortrait)+"L"
33 PortraitButton.SetPicture (PortraitName)
34 return
36 def OnLoad ():
37 global AppearanceWindow, PortraitButton, PortraitsTable, LastPortrait
38 global Gender
40 Gender=GemRB.GetVar ("Gender")
42 GemRB.LoadWindowPack ("GUICG", 800, 600)
43 AppearanceWindow = GemRB.LoadWindow (11)
44 #AppearanceWindow.SetFrame ()
46 #Load the Portraits Table
47 PortraitsTable = GemRB.LoadTable ("PICTURES")
48 LastPortrait = 0
50 PortraitButton = AppearanceWindow.GetControl (1)
51 PortraitButton.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_NO_IMAGE,OP_SET)
52 PortraitButton.SetState (IE_GUI_BUTTON_LOCKED)
54 LeftButton = AppearanceWindow.GetControl (2)
55 RightButton = AppearanceWindow.GetControl (3)
57 BackButton = AppearanceWindow.GetControl (5)
58 BackButton.SetText (15416)
59 BackButton.SetFlags (IE_GUI_BUTTON_CANCEL,OP_OR)
61 CustomButton = AppearanceWindow.GetControl (6)
62 CustomButton.SetText (17545)
64 DoneButton = AppearanceWindow.GetControl (0)
65 DoneButton.SetText (36789)
66 DoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT,OP_OR)
68 RightButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, RightPress)
69 LeftButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, LeftPress)
70 BackButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, BackPress)
71 CustomButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, CustomPress)
72 DoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, NextPress)
74 while True:
75 if PortraitsTable.GetValue (LastPortrait, 0) == Gender:
76 SetPicture ()
77 break
78 LastPortrait = LastPortrait + 1
79 AppearanceWindow.SetVisible (WINDOW_VISIBLE)
80 return
82 def RightPress ():
83 global LastPortrait
84 while True:
85 LastPortrait = LastPortrait + 1
86 if LastPortrait >= PortraitsTable.GetRowCount ():
87 LastPortrait = 0
88 if PortraitsTable.GetValue (LastPortrait, 0) == Gender:
89 SetPicture ()
90 return
92 def LeftPress ():
93 global LastPortrait
94 while True:
95 LastPortrait = LastPortrait - 1
96 if LastPortrait < 0:
97 LastPortrait = PortraitsTable.GetRowCount ()-1
98 if PortraitsTable.GetValue (LastPortrait, 0) == Gender:
99 SetPicture ()
100 return
102 def BackPress ():
103 if AppearanceWindow:
104 AppearanceWindow.Unload ()
105 GemRB.SetNextScript ("CharGen")
106 GemRB.SetVar ("Gender",0) #scrapping the gender value
107 return
109 def CustomDone ():
110 Window = CustomWindow
112 Portrait = PortraitList1.QueryText ()
113 GemRB.SetToken ("SmallPortrait", Portrait)
114 Portrait = PortraitList2.QueryText ()
115 GemRB.SetToken ("LargePortrait", Portrait)
116 if Window:
117 Window.Unload ()
118 if AppearanceWindow:
119 AppearanceWindow.Unload ()
120 GemRB.SetNextScript ("CharGen2")
121 return
123 def CustomAbort ():
124 if CustomWindow:
125 CustomWindow.Unload ()
126 return
128 def LargeCustomPortrait ():
129 Window = CustomWindow
131 Portrait = PortraitList1.QueryText ()
132 #small hack
133 if GemRB.GetVar ("Row1") == RowCount1:
134 return
136 Label = Window.GetControl (0x10000007)
137 Label.SetText (Portrait)
139 Button = Window.GetControl (6)
140 if Portrait=="":
141 Portrait = "NOPORTMD"
142 Button.SetState (IE_GUI_BUTTON_DISABLED)
143 else:
144 if PortraitList2.QueryText ()!="":
145 Button.SetState (IE_GUI_BUTTON_ENABLED)
147 Button = Window.GetControl (0)
148 Button.SetPicture (Portrait, "NOPORTMD")
149 return
151 def SmallCustomPortrait ():
152 Window = CustomWindow
154 Portrait = PortraitList2.QueryText ()
155 #small hack
156 if GemRB.GetVar ("Row2") == RowCount2:
157 return
159 Label = Window.GetControl (0x10000008)
160 Label.SetText (Portrait)
162 Button = Window.GetControl (6)
163 if Portrait=="":
164 Portrait = "NOPORTSM"
165 Button.SetState (IE_GUI_BUTTON_DISABLED)
166 else:
167 if PortraitList1.QueryText ()!="":
168 Button.SetState (IE_GUI_BUTTON_ENABLED)
170 Button = Window.GetControl (1)
171 Button.SetPicture (Portrait, "NOPORTSM")
172 return
174 def CustomPress ():
175 global PortraitList1, PortraitList2
176 global RowCount1, RowCount2
177 global CustomWindow
179 CustomWindow = Window = GemRB.LoadWindow (18)
180 PortraitList1 = Window.GetControl (2)
181 RowCount1 = PortraitList1.GetPortraits (0)
182 PortraitList1.SetEvent (IE_GUI_TEXTAREA_ON_CHANGE, LargeCustomPortrait)
183 GemRB.SetVar ("Row1", RowCount1)
184 PortraitList1.SetVarAssoc ("Row1",RowCount1)
186 PortraitList2 = Window.GetControl (4)
187 RowCount2 = PortraitList2.GetPortraits (1)
188 PortraitList2.SetEvent (IE_GUI_TEXTAREA_ON_CHANGE, SmallCustomPortrait)
189 GemRB.SetVar ("Row2", RowCount2)
190 PortraitList2.SetVarAssoc ("Row2",RowCount2)
192 Button = Window.GetControl (6)
193 Button.SetText (11973)
194 Button.SetFlags (IE_GUI_BUTTON_DEFAULT,OP_OR)
195 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, CustomDone)
196 Button.SetState (IE_GUI_BUTTON_DISABLED)
198 Button = Window.GetControl (7)
199 Button.SetText (15416)
200 Button.SetFlags (IE_GUI_BUTTON_CANCEL,OP_OR)
201 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, CustomAbort)
203 Button = Window.GetControl (0)
204 PortraitName = PortraitsTable.GetRowName (LastPortrait)+"L"
205 Button.SetPicture (PortraitName, "NOPORTMD")
206 Button.SetState (IE_GUI_BUTTON_LOCKED)
208 Button = Window.GetControl (1)
209 PortraitName = PortraitsTable.GetRowName (LastPortrait)+"S"
210 Button.SetPicture (PortraitName, "NOPORTSM")
211 Button.SetState (IE_GUI_BUTTON_LOCKED)
213 Window.ShowModal (MODAL_SHADOW_NONE)
214 return
216 def NextPress ():
217 if AppearanceWindow:
218 AppearanceWindow.Unload ()
219 PortraitTable = GemRB.LoadTable ("pictures")
220 PortraitName = PortraitTable.GetRowName (LastPortrait )
221 GemRB.SetToken ("SmallPortrait", PortraitName+"S")
222 GemRB.SetToken ("LargePortrait", PortraitName+"L")
223 #GemRB.SetVar ("PortraitIndex",LastPortrait)
224 GemRB.SetNextScript ("CharGen2") #Before race
225 return