fixed the rest of the functions that needed globalid capabilities
[gemrb.git] / gemrb / GUIScripts / bg2 / GUICommonWindows.py
blob311cb75fa80231c34984604c563c5323bcd05249
1 # -*-python-*-
2 # GemRB - Infinity Engine Emulator
3 # Copyright (C) 2003-2004 The GemRB Project
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 # GUICommonWindows.py - functions to open common
22 # windows in lower part of the screen
23 ###################################################
25 import GemRB
26 from GUIDefines import *
27 from ie_stats import IE_MAXHITPOINTS, IE_STATE_ID, IE_HITPOINTS, STATE_DEAD
28 from ie_modal import *
29 from ie_action import *
30 import GUICommon
31 import CommonTables
32 import LUCommon
33 import InventoryCommon
35 # needed for all the Open*Window callbacks in the OptionsWindow
36 import GUIJRNL
37 import GUIMA
38 import GUIMG
39 import GUIINV
40 import GUIOPT
41 import GUIPR
42 import GUIREC
44 FRAME_PC_SELECTED = 0
45 FRAME_PC_TARGET = 1
47 PortraitWindow = None
48 OptionsWindow = None
49 ActionsWindow = None
50 DraggedPortrait = None
52 def SetupMenuWindowControls (Window, Gears, ReturnToGame):
53 """Sets up all of the basic control windows."""
55 global OptionsWindow
57 OptionsWindow = Window
58 # Return to Game
59 Button = Window.GetControl (0)
60 Button.SetTooltip (16313)
61 Button.SetVarAssoc ("SelectedWindow", 0)
62 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, ReturnToGame)
63 Button.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
65 # Map
66 Button = Window.GetControl (1)
67 Button.SetTooltip (16310)
68 Button.SetVarAssoc ("SelectedWindow", 1)
69 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, GUIMA.OpenMapWindow)
71 # Journal
72 Button = Window.GetControl (2)
73 Button.SetTooltip (16308)
74 Button.SetVarAssoc ("SelectedWindow", 2)
75 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, GUIJRNL.OpenJournalWindow)
77 # Inventory
78 Button = Window.GetControl (3)
79 Button.SetTooltip (16307)
80 Button.SetVarAssoc ("SelectedWindow", 3)
81 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, GUIINV.OpenInventoryWindow)
83 # Records
84 Button = Window.GetControl (4)
85 Button.SetTooltip (16306)
86 Button.SetVarAssoc ("SelectedWindow", 4)
87 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, GUIREC.OpenRecordsWindow)
89 # Mage
90 Button = Window.GetControl (5)
91 Button.SetTooltip (16309)
92 Button.SetVarAssoc ("SelectedWindow", 5)
93 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, GUIMG.OpenMageWindow)
95 # Priest
96 Button = Window.GetControl (6)
97 Button.SetTooltip (14930)
98 Button.SetVarAssoc ("SelectedWindow", 6)
99 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, GUIPR.OpenPriestWindow)
101 # Options
102 Button = Window.GetControl (7)
103 Button.SetTooltip (16311)
104 Button.SetVarAssoc ("SelectedWindow", 7)
105 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, GUIOPT.OpenOptionsWindow)
107 # Multi player team setup?
108 Button = Window.GetControl (8)
109 Button.SetTooltip (13902)
111 if Gears:
112 # Pendulum, gears, sun/moon dial (time)
113 # FIXME: display all animations: CPEN, CGEAR, CDIAL
114 Button = Window.GetControl (9)
115 Label = Button.CreateLabelOnButton (0x10000009, "NORMAL", 0)
117 Label.SetAnimation ("CPEN")
118 Button.SetAnimation ("CGEAR")
119 Button.SetBAM ("CDIAL", 0, 0)
120 Button.SetState (IE_GUI_BUTTON_ENABLED)
121 Button.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_ANIMATED|IE_GUI_BUTTON_NORMAL, OP_SET)
122 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, GUICommon.GearsClicked)
123 GUICommon.SetGamedaysAndHourToken()
124 Button.SetTooltip(16041)
125 rb = 11
126 else:
127 rb = 9
129 # Rest
130 Button = Window.GetControl (rb)
131 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, GUICommon.RestPress)
132 Button.SetTooltip (11942)
134 if PortraitWindow:
135 UpdatePortraitWindow ()
137 def MarkMenuButton (WindowIndex):
138 Pressed = WindowIndex.GetControl( GemRB.GetVar ("SelectedWindow") )
140 for button in range (9):
141 Button = WindowIndex.GetControl (button)
142 Button.SetState (IE_GUI_BUTTON_ENABLED)
144 if Pressed: # don't draw the selection when returning to the game
145 Pressed.SetState (IE_GUI_BUTTON_SELECTED)
147 def AIPress ():
148 """Toggles the party AI."""
150 Button = PortraitWindow.GetControl (6)
151 AI = GemRB.GetMessageWindowSize () & GS_PARTYAI
153 if AI:
154 GemRB.GameSetScreenFlags (GS_PARTYAI, OP_NAND)
155 Button.SetTooltip (15918)
156 GemRB.SetVar ("AI", 0)
157 else:
158 GemRB.GameSetScreenFlags (GS_PARTYAI, OP_OR)
159 Button.SetTooltip (15917)
160 GemRB.SetVar ("AI", GS_PARTYAI)
161 return
163 def EmptyControls ():
164 global ActionsWindow
166 GemRB.SetVar ("ActionLevel", 0)
167 Window = ActionsWindow
168 for i in range (12):
169 Button = Window.GetControl (i)
170 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
171 Button.SetPicture ("")
172 return
174 def SelectFormationPreset ():
175 """Choose the default formation."""
176 GemRB.GameSetFormation (GemRB.GetVar ("Value"), GemRB.GetVar ("Formation") )
177 GroupControls ()
178 return
180 def SetupFormation ():
181 """Opens the formation selection section."""
182 global ActionsWindow
184 Window = ActionsWindow
185 for i in range (12):
186 Button = Window.GetControl (i)
187 Button.SetFlags (IE_GUI_BUTTON_NORMAL, OP_SET)
188 Button.SetSprites ("GUIBTBUT",0,0,1,2,3)
189 Button.SetBAM ("FORM%x"%i,0,0,-1)
190 Button.SetVarAssoc ("Value", i)
191 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, SelectFormationPreset)
192 return
194 def GroupControls ():
195 """Sections that control group actions."""
197 global ActionsWindow
199 GemRB.SetVar ("ActionLevel", 0)
200 Window = ActionsWindow
201 Button = Window.GetControl (0)
202 Button.SetActionIcon (globals(), 7)
203 Button = Window.GetControl (1)
204 Button.SetActionIcon (globals(), 15)
205 Button = Window.GetControl (2)
206 Button.SetActionIcon (globals(), 21)
207 Button = Window.GetControl (3)
208 Button.SetActionIcon (globals(), -1)
209 Button = Window.GetControl (4)
210 Button.SetActionIcon (globals(), -1)
211 Button = Window.GetControl (5)
212 Button.SetActionIcon (globals(), -1)
213 Button = Window.GetControl (6)
214 Button.SetActionIcon (globals(), -1)
215 GemRB.SetVar ("Formation", GemRB.GameGetFormation ())
216 for i in range (5):
217 Button = Window.GetControl (7+i)
218 Button.SetState (IE_GUI_BUTTON_ENABLED)
219 idx = GemRB.GameGetFormation (i)
220 Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON|IE_GUI_BUTTON_NORMAL, OP_SET)
221 Button.SetSprites ("GUIBTBUT",0,0,1,2,3)
222 Button.SetBAM ("FORM%x"%idx,0,0,-1)
223 Button.SetVarAssoc ("Formation", i)
224 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, GUICommon.SelectFormation)
225 Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, SetupFormation)
226 str = GemRB.GetString (4935)
227 Button.SetTooltip ("F%d - %s"%(8+i,str) )
228 return
230 def OpenActionsWindowControls (Window):
231 global ActionsWindow
233 ActionsWindow = Window
234 # Gears (time) when options pane is down
235 Button = Window.GetControl (62)
236 Label = Button.CreateLabelOnButton (0x1000003e, "NORMAL", 0)
238 # FIXME: display all animations
239 Label.SetAnimation ("CPEN")
240 Button.SetAnimation ("CGEAR")
241 Button.SetBAM ("CDIAL", 0, 0)
242 Button.SetState (IE_GUI_BUTTON_ENABLED)
243 Button.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_ANIMATED|IE_GUI_BUTTON_NORMAL, OP_SET)
244 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, GUICommon.GearsClicked)
245 GUICommon.SetGamedaysAndHourToken()
246 Button.SetTooltip(16041)
247 UpdateActionsWindow ()
248 return
250 def SelectItemAbility():
251 pc = GemRB.GameGetFirstSelectedActor ()
252 slot = GemRB.GetVar ("Slot")
253 ability = GemRB.GetVar ("Ability")
254 GemRB.SetupQuickSlot (pc, 0, slot, ability, 1)
255 GemRB.SetVar ("ActionLevel", 0)
256 return
258 def SetupItemAbilities(pc, slot):
259 Window = ActionsWindow
261 slot_item = GemRB.GetSlotItem(pc, slot, 1)
262 item = GemRB.GetItem (slot_item["ItemResRef"])
263 Tips = item["Tooltips"]
265 for i in range (12):
266 Button = Window.GetControl (i)
267 Button.SetPicture ("")
268 if i<len(Tips):
269 Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON|IE_GUI_BUTTON_NORMAL, OP_SET)
270 Button.SetSprites ("GUIBTBUT",0,0,1,2,3)
271 Button.SetItemIcon (slot_item['ItemResRef'], i+6)
272 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, SelectItemAbility)
273 Button.SetVarAssoc ("Ability", i)
275 Button.SetTooltip ("F%d - %s"%(i+1,GemRB.GetString(Tips[i])) )
276 else:
277 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
278 return
280 def UpdateActionsWindow ():
281 """Redraws the actions section of the window."""
283 global ActionsWindow, PortraitWindow, OptionsWindow
284 global level, TopIndex
286 if ActionsWindow == -1:
287 return
289 if ActionsWindow == None:
290 return
292 #fully redraw the side panes to cover the actions window
293 #do this only when there is no 'otherwindow'
294 if GemRB.GetVar ("OtherWindow") == -1:
295 if PortraitWindow:
296 PortraitWindow.Invalidate ()
297 if OptionsWindow:
298 OptionsWindow.Invalidate ()
300 Selected = GemRB.GetSelectedSize()
302 #setting up the disabled button overlay (using the second border slot)
303 for i in range (12):
304 Button = ActionsWindow.GetControl (i)
305 Button.SetBorder (1, 0, 0, 0, 0, 50,30,10,120, 0, 1)
306 Button.SetFont ("NUMBER")
307 Button.SetText ("")
309 if Selected == 0:
310 EmptyControls ()
311 return
312 if Selected > 1:
313 GroupControls ()
314 return
316 #we are sure there is only one actor selected
317 pc = GemRB.GameGetFirstSelectedActor ()
319 level = GemRB.GetVar ("ActionLevel")
320 TopIndex = GemRB.GetVar ("TopIndex")
321 if level == 0:
322 #this is based on class
323 ActionsWindow.SetupControls (globals(), pc, 0, 1)
324 elif level == 1:
325 ActionsWindow.SetupEquipmentIcons(globals(), pc, TopIndex, 0, 1)
326 elif level == 2: #spells
327 GemRB.SetVar ("Type", 3)
328 ActionsWindow.SetupSpellIcons(globals(), pc, 3, TopIndex, 0, 1)
329 elif level == 3: #innates
330 GemRB.SetVar ("Type", 4)
331 ActionsWindow.SetupSpellIcons(globals(), pc, 4, TopIndex, 0, 1)
332 elif level == 4: #quick weapon/item ability selection
333 SetupItemAbilities(pc, GemRB.GetVar("Slot") )
334 return
336 def ActionQWeaponPressed (which):
337 """Selects the given quickslot weapon if possible."""
339 pc = GemRB.GameGetFirstSelectedActor ()
340 qs = GemRB.GetEquippedQuickSlot (pc, 1, 1)
342 #38 is the magic slot
343 if ((qs==which) or (qs==38)) and GemRB.GameControlGetTargetMode() != TARGET_MODE_ATTACK:
344 GemRB.GameControlSetTargetMode (TARGET_MODE_ATTACK, GA_NO_DEAD|GA_NO_SELF|GA_NO_HIDDEN)
345 else:
346 GemRB.GameControlSetTargetMode (TARGET_MODE_NONE)
347 GemRB.SetEquippedQuickSlot (pc, which, -1, 1)
349 ActionsWindow.SetupControls (globals(), pc, 0, 1)
350 UpdateActionsWindow ()
351 return
353 def ActionQWeapon1Pressed ():
354 ActionQWeaponPressed(0)
356 def ActionQWeapon2Pressed ():
357 ActionQWeaponPressed(1)
359 def ActionQWeapon3Pressed ():
360 ActionQWeaponPressed(2)
362 def ActionQWeapon4Pressed ():
363 ActionQWeaponPressed(3)
365 #no check needed because the button wouldn't be drawn if illegal
366 def ActionLeftPressed ():
367 """Scrolls the actions window left.
369 Used primarily for spell selection."""
371 TopIndex = GemRB.GetVar ("TopIndex")
372 if TopIndex>10:
373 TopIndex -= 10
374 else:
375 TopIndex = 0
376 GemRB.SetVar ("TopIndex", TopIndex)
377 UpdateActionsWindow ()
378 return
380 #no check needed because the button wouldn't be drawn if illegal
381 def ActionRightPressed ():
382 """Scrolls the action window right.
384 Used primarily for spell selection."""
386 pc = GemRB.GameGetFirstSelectedActor ()
387 TopIndex = GemRB.GetVar ("TopIndex")
388 Type = GemRB.GetVar ("Type")
389 #Type is a bitfield if there is no level given
390 #This is to make sure cleric/mages get all spells listed
391 Max = GemRB.GetMemorizedSpellsCount(pc, Type, -1, 1)
392 TopIndex += 10
393 if TopIndex > Max - 10:
394 if Max>10:
395 TopIndex = Max-10
396 else:
397 TopIndex = 0
398 GemRB.SetVar ("TopIndex", TopIndex)
399 UpdateActionsWindow ()
400 return
402 def ActionBardSongPressed ():
403 """Toggles the battle song."""
404 pc = GemRB.GameGetFirstSelectedActor ()
405 GemRB.SetModalState (pc, MS_BATTLESONG, 1)
406 GemRB.PlaySound ("act_01")
407 UpdateActionsWindow ()
408 return
410 def ActionSearchPressed ():
411 """Toggles detect traps."""
412 pc = GemRB.GameGetFirstSelectedActor ()
413 GemRB.SetModalState (pc, MS_DETECTTRAPS, 1)
414 UpdateActionsWindow ()
415 return
417 def ActionStealthPressed ():
418 """Toggles stealth."""
419 pc = GemRB.GameGetFirstSelectedActor ()
420 GemRB.SetModalState (pc, MS_STEALTH, 1)
421 GemRB.PlaySound ("act_07")
422 UpdateActionsWindow ()
423 return
425 def ActionTurnPressed ():
426 """Toggles turn undead."""
427 pc = GemRB.GameGetFirstSelectedActor ()
428 GemRB.SetModalState (pc, MS_TURNUNDEAD, 1)
429 GemRB.PlaySound ("act_06")
430 UpdateActionsWindow ()
431 return
433 def ActionUseItemPressed ():
434 GemRB.SetVar ("TopIndex", 0)
435 GemRB.SetVar ("ActionLevel", 1)
436 UpdateActionsWindow ()
437 return
439 def ActionCastPressed ():
440 """Opens the spell choice scrollbar."""
441 GemRB.SetVar ("TopIndex", 0)
442 GemRB.SetVar ("ActionLevel", 2)
443 UpdateActionsWindow ()
444 return
446 def ActionQItemPressed (action):
447 """Uses the given quick item."""
448 pc = GemRB.GameGetFirstSelectedActor ()
449 #quick slot
450 GemRB.UseItem (pc, -2, action, -1, 1)
451 return
453 def ActionQItem1Pressed ():
454 ActionQItemPressed (ACT_QSLOT1)
455 return
457 def ActionQItem2Pressed ():
458 ActionQItemPressed (ACT_QSLOT2)
459 return
461 def ActionQItem3Pressed ():
462 ActionQItemPressed (ACT_QSLOT3)
463 return
465 def ActionQItem4Pressed ():
466 ActionQItemPressed (ACT_QSLOT4)
467 return
469 def ActionQItem5Pressed ():
470 ActionQItemPressed (ACT_QSLOT5)
471 return
473 def ActionQItemRightPressed (action):
474 """Selects the used ability of the quick item."""
475 pc = GemRB.GameGetFirstSelectedActor ()
476 GemRB.SetVar ("Slot", action)
477 GemRB.SetVar ("ActionLevel", 4)
478 UpdateActionsWindow ()
479 return
481 def ActionQItem1RightPressed ():
482 ActionQItemRightPressed (19)
484 def ActionQItem2RightPressed ():
485 ActionQItemRightPressed (20)
487 def ActionQItem3RightPressed ():
488 ActionQItemRightPressed (21)
490 def ActionQItem4RightPressed ():
491 ActionQItemRightPressed (22)
493 def ActionQItem5RightPressed ():
494 ActionQItemRightPressed (23)
496 def ActionQWeapon1RightPressed ():
497 ActionQItemRightPressed (10)
499 def ActionQWeapon2RightPressed ():
500 ActionQItemRightPressed (11)
502 def ActionQWeapon3RightPressed ():
503 ActionQItemRightPressed (12)
505 def ActionQWeapon4RightPressed ():
506 ActionQItemRightPressed (13)
508 def ActionInnatePressed ():
509 """Opens the innate spell scrollbar."""
510 GemRB.SetVar ("TopIndex", 0)
511 GemRB.SetVar ("ActionLevel", 3)
512 UpdateActionsWindow ()
513 return
515 def SpellPressed ():
516 """Prepares a spell to be cast."""
518 pc = GemRB.GameGetFirstSelectedActor ()
520 GemRB.GameControlSetTargetMode (TARGET_MODE_CAST)
521 Spell = GemRB.GetVar ("Spell")
522 Type = GemRB.GetVar ("Type")
523 GemRB.SpellCast (pc, Type, Spell, 1)
524 GemRB.SetVar ("ActionLevel", 0)
525 UpdateActionsWindow ()
526 return
528 def EquipmentPressed ():
529 pc = GemRB.GameGetFirstSelectedActor ()
531 GemRB.GameControlSetTargetMode (TARGET_MODE_CAST)
532 Item = GemRB.GetVar ("Equipment")
533 #equipment index
534 GemRB.UseItem (pc, -1, Item, -1, 1)
535 GemRB.SetVar ("ActionLevel", 0)
536 UpdateActionsWindow ()
537 return
539 SelectionChangeHandler = None
541 def SetSelectionChangeHandler (handler):
542 """Updates the selection handler."""
544 global SelectionChangeHandler
546 # Switching from walking to non-walking environment:
547 # set the first selected PC in walking env as a selected
548 # in nonwalking env
549 #if (not SelectionChangeHandler) and handler:
550 if (not SelectionChangeHandler) and handler and (not GUICommon.NextWindowFn):
551 sel = GemRB.GameGetFirstSelectedPC ()
552 if not sel:
553 sel = 1
554 GemRB.GameSelectPCSingle (sel)
556 SelectionChangeHandler = handler
558 # redraw selection on change main selection | single selection
559 SelectionChanged ()
560 return
562 def RunSelectionChangeHandler ():
563 if SelectionChangeHandler:
564 SelectionChangeHandler ()
565 return
567 def OpenPortraitWindow (needcontrols):
568 global PortraitWindow
570 PortraitWindow = Window = GemRB.LoadWindow (1)
572 if needcontrols:
573 Button=Window.GetControl (8)
574 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, MinimizePortraits)
576 # AI
577 Button = Window.GetControl (6)
578 #fixing a gui bug, and while we are at it, hacking it to be easier
579 Button.SetSprites ("GUIBTACT", 0, 48, 47, 46, 49)
580 GSFlags = GemRB.GetMessageWindowSize ()&GS_PARTYAI
582 GemRB.SetVar ("AI", GSFlags)
583 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, AIPress)
584 Button.SetFlags (IE_GUI_BUTTON_CHECKBOX, OP_OR)
585 Button.SetVarAssoc ("AI", 1)
586 if GSFlags:
587 Button.SetTooltip (15917)
588 else:
589 Button.SetTooltip (15918)
591 #Select All
592 Button = Window.GetControl (7)
593 Button.SetTooltip (10485)
594 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, GUICommon.SelectAllOnPress)
596 for i in range (PARTY_SIZE):
597 Button = Window.GetControl (i)
598 Button.SetFont ("STATES2")
599 Button.SetVarAssoc ("PressedPortrait", i+1)
601 if (needcontrols):
602 Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, GUIINV.OpenInventoryWindowClick)
603 else:
604 Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, PortraitButtonOnPress)
606 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, PortraitButtonOnPress)
607 Button.SetEvent (IE_GUI_BUTTON_ON_SHIFT_PRESS, PortraitButtonOnShiftPress)
608 Button.SetEvent (IE_GUI_BUTTON_ON_DRAG_DROP, InventoryCommon.OnDropItemToPC)
609 Button.SetEvent (IE_GUI_BUTTON_ON_DRAG_DROP_PORTRAIT, OnDropPortraitToPC)
610 Button.SetEvent (IE_GUI_BUTTON_ON_DRAG, PortraitButtonOnDrag)
611 Button.SetEvent (IE_GUI_MOUSE_ENTER_BUTTON, PortraitButtonOnMouseEnter)
612 Button.SetEvent (IE_GUI_MOUSE_LEAVE_BUTTON, PortraitButtonOnMouseLeave)
614 Button.SetBorder (FRAME_PC_SELECTED, 1, 1, 2, 2, 0, 255, 0, 255)
615 Button.SetBorder (FRAME_PC_TARGET, 3, 3, 4, 4, 255, 255, 0, 255)
617 UpdatePortraitWindow ()
618 SelectionChanged ()
619 return Window
621 def UpdatePortraitWindow ():
622 """Updates all of the portraits."""
624 Window = PortraitWindow
626 pc = GemRB.GameGetSelectedPCSingle ()
627 Inventory = GemRB.GetVar ("Inventory")
629 for portid in range (PARTY_SIZE):
630 Button = Window.GetControl (portid)
631 pic = GemRB.GetPlayerPortrait (portid+1, 1)
632 if Inventory and pc != portid+1:
633 pic = None
634 if pic and GemRB.GetPlayerStat(portid+1, IE_STATE_ID) & STATE_DEAD:
635 import GUISTORE
636 # dead pcs are hidden in all stores but temples
637 if GUISTORE.StoreWindow and not GUISTORE.StoreHealWindow:
638 pic = None
640 if not pic:
641 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
642 Button.SetState (IE_GUI_BUTTON_DISABLED)
643 Button.SetText ("")
644 Button.SetTooltip ("")
645 continue
647 Button.SetFlags (IE_GUI_BUTTON_PICTURE| IE_GUI_BUTTON_HORIZONTAL| \
648 IE_GUI_BUTTON_ALIGN_LEFT| IE_GUI_BUTTON_ALIGN_TOP| \
649 IE_GUI_BUTTON_DRAGGABLE|IE_GUI_BUTTON_MULTILINE, OP_SET)
650 Button.SetState (IE_GUI_BUTTON_LOCKED)
651 Button.SetPicture (pic, "NOPORTSM")
652 GUICommon.SetupDamageInfo (portid+1, Button)
654 #add effects on the portrait
655 effects = GemRB.GetPlayerStates (portid+1)
656 states = ""
657 for col in range(len(effects)):
658 states = effects[col:col+1] + states
659 if col % 3 == 2: states = "\n" + states
660 for x in range(3 - (len(effects)/3)):
661 states = "\n" + states
662 states = "\n" + states
664 # blank space
665 flag = blank = chr(238)
667 # shopping icon
668 if pc==portid+1:
669 if GemRB.GetStore()!=None:
670 flag = chr(155)
671 # talk icon
672 if GemRB.GameGetSelectedPCSingle(1)==portid+1:
673 flag = chr(154)
675 if LUCommon.CanLevelUp (portid+1):
676 states = flag+blank+chr(255) + states
677 else:
678 states = flag+blank+blank + states
679 Button.SetText(states)
680 return
682 def PortraitButtonOnDrag ():
683 global DraggedPortrait
685 #they start from 1
686 DraggedPortrait = GemRB.GetVar ("PressedPortrait")
687 GemRB.DragItem (DraggedPortrait, -1, "")
688 return
690 def PortraitButtonOnPress ():
691 """Selects the portrait individually."""
693 i = GemRB.GetVar ("PressedPortrait")
695 if not i:
696 return
698 if GemRB.GameControlGetTargetMode() != TARGET_MODE_NONE:
699 GemRB.ActOnPC (i)
700 return
702 if (not SelectionChangeHandler):
703 if GemRB.GameIsPCSelected (i):
704 GemRB.GameControlSetScreenFlags (SF_CENTERONACTOR, OP_OR)
705 GemRB.GameSelectPC (i, True, SELECT_REPLACE)
706 else:
707 GemRB.GameSelectPCSingle (i)
708 SelectionChanged ()
709 RunSelectionChangeHandler ()
710 return
712 def PortraitButtonOnShiftPress ():
713 """Handles selecting multiple portaits with shift."""
715 i = GemRB.GetVar ("PressedPortrait")
717 if not i:
718 return
720 if (not SelectionChangeHandler):
721 sel = GemRB.GameIsPCSelected (i)
722 sel = not sel
723 GemRB.GameSelectPC (i, sel)
724 else:
725 GemRB.GameSelectPCSingle (i)
726 SelectionChanged ()
727 RunSelectionChangeHandler ()
728 return
730 def SelectionChanged ():
731 """Ran by the Game class when a PC selection is changed."""
733 global PortraitWindow
735 if not PortraitWindow:
736 return
738 GemRB.SetVar ("ActionLevel", 0)
739 if (not SelectionChangeHandler):
740 UpdateActionsWindow ()
741 for i in range (PARTY_SIZE):
742 Button = PortraitWindow.GetControl (i)
743 Button.EnableBorder (FRAME_PC_SELECTED, GemRB.GameIsPCSelected (i + 1))
744 else:
745 sel = GemRB.GameGetSelectedPCSingle ()
747 #update mage school
748 GemRB.SetVar ("MAGESCHOOL", 0)
749 Kit = GUICommon.GetKitIndex (sel)
750 if Kit and CommonTables.KitList.GetValue (Kit, 7) == 1:
751 MageTable = GemRB.LoadTable ("magesch")
752 GemRB.SetVar ("MAGESCHOOL", MageTable.FindValue (3, CommonTables.KitList.GetValue (Kit, 6) ) )
754 for i in range (PARTY_SIZE):
755 Button = PortraitWindow.GetControl (i)
756 Button.EnableBorder (FRAME_PC_SELECTED, i + 1 == sel)
757 import CommonWindow
758 CommonWindow.CloseContainerWindow()
759 return
761 def PortraitButtonOnMouseEnter ():
762 global DraggedPortrait
764 i = GemRB.GetVar ("PressedPortrait")
766 if not i:
767 return
769 GemRB.GameControlSetLastActor( i )
770 if GemRB.IsDraggingItem()==2:
771 if DraggedPortrait != None:
772 GemRB.SwapPCs (DraggedPortrait, i)
773 GemRB.SetVar ("PressedPortrait", DraggedPortrait)
774 DraggedPortrait = i
775 GemRB.SetTimedEvent (CheckDragging, 1)
776 else:
777 OnDropPortraitToPC()
778 return
780 if GemRB.IsDraggingItem ():
781 Button = PortraitWindow.GetControl (i-1)
782 Button.EnableBorder (FRAME_PC_TARGET, 1)
783 return
785 def OnDropPortraitToPC ():
786 GemRB.SetVar ("PressedPortrait",0)
787 GemRB.DragItem (0, -1, "")
788 DraggedPortrait = None
789 return
791 def CheckDragging():
792 """Contains portrait dragging in case of mouse out-of-range."""
794 global DraggedPortrait
796 i = GemRB.GetVar ("PressedPortrait")
797 if not i:
798 GemRB.DragItem (0, -1, "")
800 if GemRB.IsDraggingItem()!=2:
801 DraggedPortrait = None
802 return
804 def PortraitButtonOnMouseLeave ():
805 i = GemRB.GetVar ("PressedPortrait")
806 if not i:
807 return
809 Button = PortraitWindow.GetControl (i-1)
810 Button.EnableBorder (FRAME_PC_TARGET, 0)
811 GemRB.SetVar ("PressedPortrait", 0)
812 GemRB.SetTimedEvent (CheckDragging, 1)
813 return
815 #FIXME: iterate over the whole selection
816 def ActionStopPressed ():
817 for i in range (PARTY_SIZE):
818 if GemRB.GameIsPCSelected (i + 1):
819 GemRB.ClearActions (i + 1)
820 return
822 def ActionTalkPressed ():
823 GemRB.GameControlSetTargetMode (TARGET_MODE_TALK,GA_NO_DEAD|GA_NO_ENEMY|GA_NO_HIDDEN)
825 def ActionAttackPressed ():
826 GemRB.GameControlSetTargetMode (TARGET_MODE_ATTACK,GA_NO_DEAD|GA_NO_SELF|GA_NO_HIDDEN)
828 def ActionDefendPressed ():
829 GemRB.GameControlSetTargetMode (TARGET_MODE_DEFEND,GA_NO_SELF|GA_NO_ENEMY|GA_NO_HIDDEN)
831 def ActionThievingPressed ():
832 GemRB.GameControlSetTargetMode (TARGET_MODE_PICK, GA_NO_DEAD|GA_NO_SELF|GA_NO_ENEMY|GA_NO_HIDDEN)
834 def MinimizePortraits():
835 GemRB.GameSetScreenFlags(GS_PORTRAITPANE, OP_OR)
837 def OpenWaitForDiscWindow ():
838 global DiscWindow
840 if DiscWindow:
841 GemRB.HideGUI ()
842 if DiscWindow:
843 DiscWindow.Unload ()
844 GemRB.SetVar ("OtherWindow", -1)
845 # ...LoadWindowPack()
846 EnableAnimatedWindows ()
847 DiscWindow = None
848 GemRB.UnhideGUI ()
849 return
851 try:
852 GemRB.HideGUI ()
853 except:
854 pass
856 GemRB.LoadWindowPack ("GUIID")
857 DiscWindow = Window = GemRB.LoadWindow (0)
858 GemRB.SetVar ("OtherWindow", Window.ID)
859 label = DiscWindow.GetControl (0)
861 disc_num = GemRB.GetVar ("WaitForDisc")
862 #disc_path = GemRB.GetVar ("WaitForDiscPath")
863 disc_path = 'XX:'
865 text = GemRB.GetString (31483) + " " + str (disc_num) + " " + GemRB.GetString (31569) + " " + disc_path + "\n" + GemRB.GetString (49152)
866 label.SetText (text)
867 DisableAnimatedWindows ()
868 # 31483 - Please place PS:T disc number
869 # 31568 - Please place the PS:T DVD
870 # 31569 - in drive
871 # 31570 - Wrong disc in drive
872 # 31571 - There is no disc in drive
873 # 31578 - No disc could be found in drive. Please place Disc 1 in drive.
874 # 49152 - To quit the game, press Alt-F4
876 try:
877 GemRB.UnhideGUI ()
878 except:
879 DiscWindow.SetVisible (WINDOW_VISIBLE)
881 def CheckLevelUp(pc):
882 GemRB.SetVar ("CheckLevelUp"+str(pc), LUCommon.CanLevelUp (pc))