factored out the EFFv2 saving into EFFImporter
[gemrb.git] / gemrb / GUIScripts / bg1 / GUICG13.py
blob6eacdc78b5882771f0e7a01d0851c12be0d29d52
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, color (GUICG13)
20 import GemRB
21 from GUIDefines import *
22 from ie_stats import *
23 import CharGenCommon
24 import GUICommon
25 import CommonTables
28 global IE_ANIM_ID
29 ColorTable = 0
30 ColorWindow = 0
31 ColorPicker = 0
32 DoneButton = 0
33 ColorIndex = 0
34 PickedColor = 0
35 HairButton = 0
36 SkinButton = 0
37 MajorButton = 0
38 MinorButton = 0
39 HairColor = 0
40 SkinColor = 0
41 MinorColor = 0
42 MajorColor = 0
43 PDollButton = 0
44 IE_ANIM_ID = 206
46 def RefreshPDoll():
47 MyChar = GemRB.GetVar ("Slot")
48 AnimID = 0x6000
49 table = GemRB.LoadTable("avprefr")
50 AnimID = AnimID+table.GetValue(GemRB.GetPlayerStat (MyChar, IE_RACE),0)
51 charclass = GemRB.GetPlayerStat (MyChar, IE_CLASS)
52 charclass = CommonTables.Classes.FindValue(5,charclass)
53 charclass = CommonTables.Classes.GetRowName(charclass)
54 table = GemRB.LoadTable("avprefc")
55 AnimID = AnimID+table.GetValue(table.GetRowIndex(charclass),0)
56 table = GemRB.LoadTable("avprefg")
57 AnimID = AnimID+table.GetValue(GemRB.GetPlayerStat (MyChar, IE_SEX),0)
58 ResRef = CommonTables.Pdolls.GetValue(hex(AnimID), "LEVEL1")
59 PDollButton.SetPLT(ResRef, 0, MinorColor, MajorColor, SkinColor, 0, 0, HairColor, 0)
61 return
63 def OnLoad():
64 global ColorWindow, DoneButton, PDollButton, ColorTable
65 global HairButton, SkinButton, MajorButton, MinorButton
66 global HairColor, SkinColor, MinorColor, MajorColor
68 GemRB.LoadWindowPack("GUICG")
69 ColorWindow=GemRB.LoadWindow(13)
70 GUICommon.CloseOtherWindow (ColorWindow.Unload)
72 ColorTable = GemRB.LoadTable("clowncol")
73 #set these colors to some default
74 PortraitTable = GemRB.LoadTable("pictures")
75 PortraitName = GemRB.GetToken("LargePortrait")
76 PortraitName = PortraitName[0:len(PortraitName)-1]
77 PortraitIndex = PortraitTable.GetRowIndex(PortraitName)
78 if PortraitIndex<0:
79 HairColor=PortraitTable.GetValue(0,1)
80 SkinColor=PortraitTable.GetValue(0,2)
81 MinorColor=PortraitTable.GetValue(0,3)
82 MajorColor=PortraitTable.GetValue(0,4)
83 else:
84 HairColor=PortraitTable.GetValue(PortraitIndex,1)
85 SkinColor=PortraitTable.GetValue(PortraitIndex,2)
86 MinorColor=PortraitTable.GetValue(PortraitIndex,3)
87 MajorColor=PortraitTable.GetValue(PortraitIndex,4)
89 PDollButton = ColorWindow.GetControl(1)
90 PDollButton.SetState (IE_GUI_BUTTON_LOCKED)
91 PDollButton.SetFlags(IE_GUI_BUTTON_PICTURE,OP_OR)
93 HairButton = ColorWindow.GetControl(2)
94 HairButton.SetFlags(IE_GUI_BUTTON_PICTURE,OP_OR)
95 HairButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, HairPress)
96 HairButton.SetBAM("COLGRAD", 0, 0, HairColor)
98 SkinButton = ColorWindow.GetControl(3)
99 SkinButton.SetFlags(IE_GUI_BUTTON_PICTURE,OP_OR)
100 SkinButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, SkinPress)
101 SkinButton.SetBAM("COLGRAD", 0, 0, SkinColor)
103 MajorButton = ColorWindow.GetControl(5)
104 MajorButton.SetFlags(IE_GUI_BUTTON_PICTURE,OP_OR)
105 MajorButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, MajorPress)
106 MajorButton.SetBAM("COLGRAD", 0, 0, MinorColor)
108 MinorButton = ColorWindow.GetControl(4)
109 MinorButton.SetFlags(IE_GUI_BUTTON_PICTURE,OP_OR)
110 MinorButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, MinorPress)
111 MinorButton.SetBAM("COLGRAD", 0, 0, MajorColor)
113 BackButton = ColorWindow.GetControl(13)
114 BackButton.SetText(15416)
115 DoneButton = ColorWindow.GetControl(0)
116 DoneButton.SetText(11973)
117 DoneButton.SetFlags(IE_GUI_BUTTON_DEFAULT,OP_OR)
119 DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, NextPress)
120 BackButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, CharGenCommon.BackPress)
121 RefreshPDoll()
122 ColorWindow.ShowModal(MODAL_SHADOW_NONE)
123 return
125 def DonePress():
126 global HairColor, SkinColor, MinorColor, MajorColor
128 if ColorPicker:
129 ColorPicker.Unload()
131 ColorWindow.ShowModal(MODAL_SHADOW_NONE)
132 PickedColor=ColorTable.GetValue(ColorIndex, GemRB.GetVar("Selected"))
133 if ColorIndex==0:
134 HairColor=PickedColor
135 HairButton.SetBAM("COLGRAD", 0, 0, HairColor)
136 RefreshPDoll()
137 return
138 if ColorIndex==1:
139 SkinColor=PickedColor
140 SkinButton.SetBAM("COLGRAD", 0, 0, SkinColor)
141 RefreshPDoll()
142 return
143 if ColorIndex==2:
144 MinorColor=PickedColor
145 MajorButton.SetBAM("COLGRAD", 0, 0, MinorColor)
146 RefreshPDoll()
147 return
149 MajorColor=PickedColor
150 MinorButton.SetBAM("COLGRAD", 0, 0, MajorColor)
151 RefreshPDoll()
152 return
154 def GetColor():
155 global ColorPicker
157 ColorPicker=GemRB.LoadWindow(14)
158 GemRB.SetVar("Selected",-1)
159 for i in range(34):
160 Button = ColorPicker.GetControl(i)
161 Button.SetState(IE_GUI_BUTTON_LOCKED)
162 Button.SetFlags(IE_GUI_BUTTON_PICTURE,OP_OR)
163 #Button.SetFlags(IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_RADIOBUTTON,OP_OR)
165 Selected = -1
166 for i in range(34):
167 MyColor = ColorTable.GetValue(ColorIndex, i)
168 if MyColor == "*":
169 break
170 Button = ColorPicker.GetControl(i)
171 Button.SetBAM("COLGRAD", 0, 0, MyColor)
172 if PickedColor == MyColor:
173 GemRB.SetVar("Selected",i)
174 Selected = i
175 Button.SetState(IE_GUI_BUTTON_ENABLED)
176 Button.SetVarAssoc("Selected",i)
177 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, DonePress)
179 ColorPicker.ShowModal(MODAL_SHADOW_NONE)
180 return
182 def HairPress():
183 global ColorIndex, PickedColor
185 ColorWindow.SetVisible(WINDOW_INVISIBLE)
186 ColorIndex = 0
187 PickedColor = HairColor
188 GetColor()
189 return
191 def SkinPress():
192 global ColorIndex, PickedColor
194 ColorWindow.SetVisible(WINDOW_INVISIBLE)
195 ColorIndex = 1
196 PickedColor = SkinColor
197 GetColor()
198 return
200 def MajorPress():
201 global ColorIndex, PickedColor
203 ColorWindow.SetVisible(WINDOW_INVISIBLE)
204 ColorIndex = 2
205 PickedColor = MinorColor
206 GetColor()
207 return
209 def MinorPress():
210 global ColorIndex, PickedColor
212 ColorWindow.SetVisible(WINDOW_INVISIBLE)
213 ColorIndex = 3
214 PickedColor = MajorColor
215 GetColor()
216 return
219 def NextPress():
220 MyChar = GemRB.GetVar ("Slot")
221 GUICommon.SetColorStat (MyChar, IE_HAIR_COLOR, HairColor )
222 GUICommon.SetColorStat (MyChar, IE_SKIN_COLOR, SkinColor )
223 GUICommon.SetColorStat (MyChar, IE_MAJOR_COLOR, MajorColor)
224 GUICommon.SetColorStat (MyChar, IE_MINOR_COLOR, MinorColor )
225 CharGenCommon.next()
226 return