[059f52]: gemrb / GUIScripts / bg1 / GUIINV.py  Maximize  Restore  History

Download this file

319 lines (269 with data), 10.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
#-*-python-*-
#GemRB - Infinity Engine Emulator
#Copyright (C) 2003-2004 The GemRB Project
#
#This program is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public License
#as published by the Free Software Foundation; either version 2
#of the License, or (at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
#GUIINV.py - scripts to control inventory windows from GUIINV winpack
###################################################
import GemRB
import GUICommon
import CommonTables
import InventoryCommon
from GUIDefines import *
from ie_stats import *
from ie_slots import *
InventoryWindow = None
PortraitWindow = None
OptionsWindow = None
OldPortraitWindow = None
OldOptionsWindow = None
def OpenInventoryWindowClick ():
tmp = GemRB.GetVar ("PressedPortrait")
GemRB.GameSelectPC (tmp, True, SELECT_REPLACE)
OpenInventoryWindow ()
return
def OpenInventoryWindow ():
"""Opens the inventory window."""
import GUICommonWindows
global InventoryWindow, OptionsWindow, PortraitWindow
global OldPortraitWindow, OldOptionsWindow
if GUICommon.CloseOtherWindow (OpenInventoryWindow):
if GemRB.IsDraggingItem () == 1:
pc = GemRB.GameGetSelectedPCSingle ()
#store the item in the inventory before window is closed
GemRB.DropDraggedItem (pc, -3)
#dropping on ground if cannot store in inventory
if GemRB.IsDraggingItem () == 1:
GemRB.DropDraggedItem (pc, -2)
if InventoryWindow:
InventoryWindow.Unload ()
if OptionsWindow:
OptionsWindow.Unload ()
if PortraitWindow:
PortraitWindow.Unload ()
InventoryWindow = None
GemRB.SetVar ("OtherWindow", -1)
GUICommon.GameWindow.SetVisible(WINDOW_VISIBLE)
GemRB.UnhideGUI ()
GUICommonWindows.PortraitWindow = OldPortraitWindow
GUICommonWindows.UpdatePortraitWindow ()
OldPortraitWindow = None
GUICommonWindows.OptionsWindow = OldOptionsWindow
OldOptionsWindow = None
GUICommonWindows.SetSelectionChangeHandler (None)
return
GemRB.HideGUI ()
GUICommon.GameWindow.SetVisible(WINDOW_INVISIBLE)
GemRB.LoadWindowPack ("GUIINV", 640, 480)
InventoryWindow = Window = GemRB.LoadWindow (2)
GemRB.SetVar ("OtherWindow", InventoryWindow.ID)
GemRB.SetVar ("MessageLabel", Window.GetControl (0x1000003f).ID )
OldOptionsWindow = GUICommonWindows.OptionsWindow
OptionsWindow = GemRB.LoadWindow (0)
OptionsWindow.SetFrame ()
GUICommonWindows.SetupMenuWindowControls (OptionsWindow, 0, OpenInventoryWindow)
#saving the original portrait window
OldPortraitWindow = GUICommonWindows.PortraitWindow
PortraitWindow = GUICommonWindows.OpenPortraitWindow (0)
#ground items scrollbar
ScrollBar = Window.GetControl (66)
ScrollBar.SetEvent (IE_GUI_SCROLLBAR_ON_CHANGE, RefreshInventoryWindow)
#Ground Item
for i in range (5):
Button = Window.GetControl (i+68)
Button.SetEvent (IE_GUI_MOUSE_ENTER_BUTTON, InventoryCommon.MouseEnterGround)
Button.SetEvent (IE_GUI_MOUSE_LEAVE_BUTTON, InventoryCommon.MouseLeaveGround)
Button.SetVarAssoc ("GroundItemButton", i)
#This IS different from BG2
Button.SetSprites ("STONSLOT",0,0,1,2,3)
Button.SetFont ("NUMBER")
Button.SetBorder (0,0,0,0,0,128,128,255,64,0,1)
Button.SetBorder (1,2,2,2,2,32,32,255,0,0,0)
Button.SetBorder (2,0,0,0,0,255,128,128,64,0,1)
Button.SetFlags (IE_GUI_BUTTON_ALIGN_RIGHT | IE_GUI_BUTTON_ALIGN_TOP | IE_GUI_BUTTON_PICTURE, OP_OR)
#major & minor clothing color
Button = Window.GetControl (62)
Button.SetFlags (IE_GUI_BUTTON_PICTURE,OP_OR)
Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, InventoryCommon.MajorPress)
Button.SetTooltip (12007)
Button = Window.GetControl (63)
Button.SetFlags (IE_GUI_BUTTON_PICTURE,OP_OR)
Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, InventoryCommon.MinorPress)
Button.SetTooltip (12008)
#portrait
Button = Window.GetControl (50)
Button.SetState (IE_GUI_BUTTON_LOCKED)
Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE | IE_GUI_BUTTON_PICTURE, OP_SET)
Button.SetEvent (IE_GUI_BUTTON_ON_DRAG_DROP, InventoryCommon.OnAutoEquip)
#encumbrance
Label = Window.CreateLabel (0x10000043, 14,375,60,20,"NUMBER","0:",IE_FONT_ALIGN_LEFT|IE_FONT_ALIGN_TOP)
Label = Window.CreateLabel (0x10000044, 8,445,60,20,"NUMBER","0:",IE_FONT_ALIGN_RIGHT|IE_FONT_ALIGN_TOP)
#armor class
Label = Window.GetControl (0x10000038)
Label.SetTooltip (17183)
#hp current
Label = Window.GetControl (0x10000039)
Label.SetTooltip (17184)
#hp max
Label = Window.GetControl (0x1000003a)
Label.SetTooltip (17378)
#info label, game paused, etc
Label = Window.GetControl (0x1000003f)
Label.SetText ("")
SlotCount = GemRB.GetSlotType (-1)["Count"]
for slot in range (SlotCount):
SlotType = GemRB.GetSlotType (slot+1)
if SlotType["ID"]:
Button = Window.GetControl (SlotType["ID"])
Button.SetEvent (IE_GUI_MOUSE_ENTER_BUTTON, InventoryCommon.MouseEnterSlot)
Button.SetEvent (IE_GUI_MOUSE_LEAVE_BUTTON, InventoryCommon.MouseLeaveSlot)
Button.SetVarAssoc ("ItemButton", slot+1)
#keeping 1 in the original place, because it is how
#the gui resource has it, but setting the other cycles
#This IS different from BG2
Button.SetSprites ("STONSLOT",0,0,1,2,3)
Button.SetFont ("NUMBER")
Button.SetBorder (0,0,0,0,0,128,128,255,64,0,1)
Button.SetBorder (1,2,2,2,2,32,32,255,0,0,0)
Button.SetBorder (2,0,0,0,0,255,128,128,64,0,1)
Button.SetFlags (IE_GUI_BUTTON_ALIGN_RIGHT | IE_GUI_BUTTON_ALIGN_TOP | IE_GUI_BUTTON_PICTURE, OP_OR)
GemRB.SetVar ("TopIndex", 0)
GUICommonWindows.SetSelectionChangeHandler (UpdateInventoryWindow)
UpdateInventoryWindow ()
OptionsWindow.SetVisible (WINDOW_VISIBLE)
Window.SetVisible (WINDOW_FRONT)
PortraitWindow.SetVisible (WINDOW_VISIBLE)
# force unpause the game
GemRB.GamePause(0, 0)
return
#complete update
def UpdateInventoryWindow ():
Window = InventoryWindow
pc = GemRB.GameGetSelectedPCSingle ()
Container = GemRB.GetContainer (pc, 1)
ScrollBar = Window.GetControl (66)
Count = Container['ItemCount']
if Count<1:
Count=1
ScrollBar.SetVarAssoc ("TopIndex", Count)
RefreshInventoryWindow ()
#populate inventory slot controls
SlotCount = GemRB.GetSlotType (-1)["Count"]
for i in range (SlotCount):
InventoryCommon.UpdateSlot (pc, i)
return
#partial update without altering TopIndex
def RefreshInventoryWindow ():
Window = InventoryWindow
pc = GemRB.GameGetSelectedPCSingle ()
#name
Label = Window.GetControl (0x10000032)
Label.SetText (GemRB.GetPlayerName (pc, 0))
#portrait
Button = Window.GetControl (50)
Color1 = GemRB.GetPlayerStat (pc, IE_METAL_COLOR)
Color2 = GemRB.GetPlayerStat (pc, IE_MINOR_COLOR)
Color3 = GemRB.GetPlayerStat (pc, IE_MAJOR_COLOR)
Color4 = GemRB.GetPlayerStat (pc, IE_SKIN_COLOR)
Color5 = GemRB.GetPlayerStat (pc, IE_LEATHER_COLOR)
Color6 = GemRB.GetPlayerStat (pc, IE_ARMOR_COLOR)
Color7 = GemRB.GetPlayerStat (pc, IE_HAIR_COLOR)
Button.SetPLT (GUICommon.GetActorPaperDoll (pc),
Color1, Color2, Color3, Color4, Color5, Color6, Color7, 0, 0)
anim_id = GemRB.GetPlayerStat (pc, IE_ANIMATION_ID)
row = "0x%04X" %anim_id
size = CommonTables.Pdolls.GetValue (row, "SIZE")
#Weapon
slot_item = GemRB.GetSlotItem (pc, GemRB.GetEquippedQuickSlot (pc) )
if slot_item:
item = GemRB.GetItem (slot_item["ItemResRef"])
if (item['AnimationType'] != ''):
Button.SetPLT("WP" + size + item['AnimationType'] + "INV", Color1, Color2, Color3, Color4, Color5, Color6, Color7, 0, 1)
#Shield
slot_item = GemRB.GetSlotItem (pc, 3)
if slot_item:
itemname = slot_item["ItemResRef"]
item = GemRB.GetItem (itemname)
if (item['AnimationType'] != ''):
if (GemRB.CanUseItemType (SLOT_WEAPON, itemname)):
#off-hand weapon
Button.SetPLT("WP" + size + item['AnimationType'] + "OIN", Color1, Color2, Color3, Color4, Color5, Color6, Color7, 0, 2)
else:
#shield
Button.SetPLT("WP" + size + item['AnimationType'] + "INV", Color1, Color2, Color3, Color4, Color5, Color6, Color7, 0, 2)
#Helmet
slot_item = GemRB.GetSlotItem (pc, 1)
if slot_item:
item = GemRB.GetItem (slot_item["ItemResRef"])
if (item['AnimationType'] != ''):
Button.SetPLT("WP" + size + item['AnimationType'] + "INV", Color1, Color2, Color3, Color4, Color5, Color6, Color7, 0, 3)
#encumbrance
GUICommon.SetEncumbranceLabels ( Window, 0x10000043, 0x10000044, pc)
#armor class
ac = GemRB.GetPlayerStat (pc, IE_ARMORCLASS)
ac += GemRB.GetAbilityBonus (IE_DEX, 2, GemRB.GetPlayerStat (pc, IE_DEX) )
Label = Window.GetControl (0x10000038)
Label.SetText (str (ac))
#hp current
hp = GemRB.GetPlayerStat (pc, IE_HITPOINTS)
Label = Window.GetControl (0x10000039)
Label.SetText (str (hp))
#hp max
hpmax = GemRB.GetPlayerStat (pc, IE_MAXHITPOINTS)
Label = Window.GetControl (0x1000003a)
Label.SetText (str (hpmax))
#party gold
Label = Window.GetControl (0x10000040)
Label.SetText (str (GemRB.GameGetPartyGold ()))
#class
ClassTitle = GUICommon.GetActorClassTitle (pc)
Label = Window.GetControl (0x10000042)
Label.SetText (ClassTitle)
Button = Window.GetControl (62)
Color = GemRB.GetPlayerStat (pc, IE_MAJOR_COLOR, 1) & 0xFF
Button.SetBAM ("COLGRAD", 0, 0, Color)
Button = Window.GetControl (63)
Color = GemRB.GetPlayerStat (pc, IE_MINOR_COLOR, 1) & 0xFF
Button.SetBAM ("COLGRAD", 0, 0, Color)
#update ground inventory slots
Container = GemRB.GetContainer (pc, 1)
TopIndex = GemRB.GetVar ("TopIndex")
for i in range (5):
Button = Window.GetControl (i+68)
if GemRB.IsDraggingItem ()==1:
Button.SetState (IE_GUI_BUTTON_SECOND)
else:
Button.SetState (IE_GUI_BUTTON_ENABLED)
Button.SetEvent (IE_GUI_BUTTON_ON_DRAG_DROP, InventoryCommon.OnDragItemGround)
Slot = GemRB.GetContainerItem (pc, i+TopIndex)
if Slot == None:
Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, None)
Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, None)
Button.SetEvent (IE_GUI_BUTTON_ON_SHIFT_PRESS, None)
else:
Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, InventoryCommon.OnDragItemGround)
Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, InventoryCommon.OpenGroundItemInfoWindow)
Button.SetEvent (IE_GUI_BUTTON_ON_SHIFT_PRESS, None) #TODO: implement OpenGroundItemAmountWindow
GUICommon.UpdateInventorySlot (pc, Button, Slot, "ground")
#making window visible/shaded depending on the pc's state
held = GemRB.GetPlayerStat (pc, IE_HELD) + GemRB.GetPlayerStat (pc, IE_CASTERHOLD)
if held == 0 and GemRB.GetPlayerStat (pc, IE_STATE_ID) & STATE_DEAD == 0:
Window.SetVisible (WINDOW_VISIBLE)
else:
Window.SetVisible (WINDOW_GRAYED)
return
###################################################
#End of file GUIINV.py

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks