iwd: more gcw syncing with bg2 - actonpc and dragging
[gemrb.git] / gemrb / GUIScripts / bg2 / GUICommonWindows.py
blob784a0861152d9a12c365e4b460a201eacb5be6f2
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 LUCommon
33 # needed for all the Open*Window callbacks in the OptionsWindow
34 import GUIJRNL
35 import GUIMA
36 import GUIMG
37 import GUIINV
38 import GUIOPT
39 import GUIPR
40 import GUIREC
42 FRAME_PC_SELECTED = 0
43 FRAME_PC_TARGET = 1
45 PortraitWindow = None
46 OptionsWindow = None
47 ActionsWindow = None
48 DraggedPortrait = None
50 def SetupMenuWindowControls (Window, Gears, ReturnToGame):
51 """Sets up all of the basic control windows."""
53 global OptionsWindow
55 OptionsWindow = Window
56 # Return to Game
57 Button = Window.GetControl (0)
58 Button.SetTooltip (16313)
59 Button.SetVarAssoc ("SelectedWindow", 0)
60 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, ReturnToGame)
61 Button.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
63 # Map
64 Button = Window.GetControl (1)
65 Button.SetTooltip (16310)
66 Button.SetVarAssoc ("SelectedWindow", 1)
67 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, GUIMA.OpenMapWindow)
69 # Journal
70 Button = Window.GetControl (2)
71 Button.SetTooltip (16308)
72 Button.SetVarAssoc ("SelectedWindow", 2)
73 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, GUIJRNL.OpenJournalWindow)
75 # Inventory
76 Button = Window.GetControl (3)
77 Button.SetTooltip (16307)
78 Button.SetVarAssoc ("SelectedWindow", 3)
79 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, GUIINV.OpenInventoryWindow)
81 # Records
82 Button = Window.GetControl (4)
83 Button.SetTooltip (16306)
84 Button.SetVarAssoc ("SelectedWindow", 4)
85 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, GUIREC.OpenRecordsWindow)
87 # Mage
88 Button = Window.GetControl (5)
89 Button.SetTooltip (16309)
90 Button.SetVarAssoc ("SelectedWindow", 5)
91 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, GUIMG.OpenMageWindow)
93 # Priest
94 Button = Window.GetControl (6)
95 Button.SetTooltip (14930)
96 Button.SetVarAssoc ("SelectedWindow", 6)
97 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, GUIPR.OpenPriestWindow)
99 # Options
100 Button = Window.GetControl (7)
101 Button.SetTooltip (16311)
102 Button.SetVarAssoc ("SelectedWindow", 7)
103 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, GUIOPT.OpenOptionsWindow)
105 # Multi player team setup?
106 Button = Window.GetControl (8)
107 Button.SetTooltip (13902)
109 if Gears:
110 # Pendulum, gears, sun/moon dial (time)
111 # FIXME: display all animations: CPEN, CGEAR, CDIAL
112 Button = Window.GetControl (9)
113 Label = Button.CreateLabelOnButton (0x10000009, "NORMAL", 0)
115 Label.SetAnimation ("CPEN")
116 Button.SetAnimation ("CGEAR")
117 Button.SetBAM ("CDIAL", 0, 0)
118 Button.SetState (IE_GUI_BUTTON_ENABLED)
119 Button.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_ANIMATED|IE_GUI_BUTTON_NORMAL, OP_SET)
120 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, GUICommon.GearsClicked)
121 GUICommon.SetGamedaysAndHourToken()
122 Button.SetTooltip(16041)
123 rb = 11
124 else:
125 rb = 9
127 # Rest
128 Button = Window.GetControl (rb)
129 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, GUICommon.RestPress)
130 Button.SetTooltip (11942)
132 if PortraitWindow:
133 UpdatePortraitWindow ()
135 def MarkMenuButton (WindowIndex):
136 Pressed = WindowIndex.GetControl( GemRB.GetVar ("SelectedWindow") )
138 for button in range (9):
139 Button = WindowIndex.GetControl (button)
140 Button.SetState (IE_GUI_BUTTON_ENABLED)
142 if Pressed: # don't draw the selection when returning to the game
143 Pressed.SetState (IE_GUI_BUTTON_SELECTED)
145 def AIPress ():
146 """Toggles the party AI."""
148 Button = PortraitWindow.GetControl (6)
149 AI = GemRB.GetMessageWindowSize () & GS_PARTYAI
151 if AI:
152 GemRB.GameSetScreenFlags (GS_PARTYAI, OP_NAND)
153 Button.SetTooltip (15918)
154 GemRB.SetVar ("AI", 0)
155 else:
156 GemRB.GameSetScreenFlags (GS_PARTYAI, OP_OR)
157 Button.SetTooltip (15917)
158 GemRB.SetVar ("AI", GS_PARTYAI)
159 return
161 def EmptyControls ():
162 global ActionsWindow
164 GemRB.SetVar ("ActionLevel", 0)
165 Window = ActionsWindow
166 for i in range (12):
167 Button = Window.GetControl (i)
168 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
169 Button.SetPicture ("")
170 return
172 def SelectFormationPreset ():
173 """Choose the default formation."""
174 GemRB.GameSetFormation (GemRB.GetVar ("Value"), GemRB.GetVar ("Formation") )
175 GroupControls ()
176 return
178 def SetupFormation ():
179 """Opens the formation selection section."""
180 global ActionsWindow
182 Window = ActionsWindow
183 for i in range (12):
184 Button = Window.GetControl (i)
185 Button.SetFlags (IE_GUI_BUTTON_NORMAL, OP_SET)
186 Button.SetSprites ("GUIBTBUT",0,0,1,2,3)
187 Button.SetBAM ("FORM%x"%i,0,0,-1)
188 Button.SetVarAssoc ("Value", i)
189 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, SelectFormationPreset)
190 return
192 def GroupControls ():
193 """Sections that control group actions."""
195 global ActionsWindow
197 GemRB.SetVar ("ActionLevel", 0)
198 Window = ActionsWindow
199 Button = Window.GetControl (0)
200 Button.SetActionIcon (globals(), 7)
201 Button = Window.GetControl (1)
202 Button.SetActionIcon (globals(), 15)
203 Button = Window.GetControl (2)
204 Button.SetActionIcon (globals(), 21)
205 Button = Window.GetControl (3)
206 Button.SetActionIcon (globals(), -1)
207 Button = Window.GetControl (4)
208 Button.SetActionIcon (globals(), -1)
209 Button = Window.GetControl (5)
210 Button.SetActionIcon (globals(), -1)
211 Button = Window.GetControl (6)
212 Button.SetActionIcon (globals(), -1)
213 GemRB.SetVar ("Formation", GemRB.GameGetFormation ())
214 for i in range (5):
215 Button = Window.GetControl (7+i)
216 Button.SetState (IE_GUI_BUTTON_ENABLED)
217 idx = GemRB.GameGetFormation (i)
218 Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON|IE_GUI_BUTTON_NORMAL, OP_SET)
219 Button.SetSprites ("GUIBTBUT",0,0,1,2,3)
220 Button.SetBAM ("FORM%x"%idx,0,0,-1)
221 Button.SetVarAssoc ("Formation", i)
222 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, GUICommon.SelectFormation)
223 Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, SetupFormation)
224 str = GemRB.GetString (4935)
225 Button.SetTooltip ("F%d - %s"%(8+i,str) )
226 return
228 def OpenActionsWindowControls (Window):
229 global ActionsWindow
231 ActionsWindow = Window
232 # Gears (time) when options pane is down
233 Button = Window.GetControl (62)
234 Label = Button.CreateLabelOnButton (0x1000003e, "NORMAL", 0)
236 # FIXME: display all animations
237 Label.SetAnimation ("CPEN")
238 Button.SetAnimation ("CGEAR")
239 Button.SetBAM ("CDIAL", 0, 0)
240 Button.SetState (IE_GUI_BUTTON_ENABLED)
241 Button.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_ANIMATED|IE_GUI_BUTTON_NORMAL, OP_SET)
242 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, GUICommon.GearsClicked)
243 GUICommon.SetGamedaysAndHourToken()
244 Button.SetTooltip(16041)
245 UpdateActionsWindow ()
246 return
248 def UpdateActionsWindow ():
249 """Redraws the actions section of the window."""
251 global ActionsWindow, PortraitWindow, OptionsWindow
252 global level, TopIndex
254 if ActionsWindow == -1:
255 return
257 if ActionsWindow == None:
258 return
260 #fully redraw the side panes to cover the actions window
261 #do this only when there is no 'otherwindow'
262 if GemRB.GetVar ("OtherWindow") == -1:
263 if PortraitWindow:
264 PortraitWindow.Invalidate ()
265 if OptionsWindow:
266 OptionsWindow.Invalidate ()
268 Selected = GemRB.GetSelectedSize()
270 #setting up the disabled button overlay (using the second border slot)
271 for i in range (12):
272 Button = ActionsWindow.GetControl (i)
273 Button.SetBorder (1, 0, 0, 0, 0, 50,30,10,120, 0, 1)
274 Button.SetFont ("NUMBER")
275 Button.SetText ("")
277 if Selected == 0:
278 EmptyControls ()
279 return
280 if Selected > 1:
281 GroupControls ()
282 return
283 #this is based on class
284 #we are sure there is only one actor selected
285 pc = 0
286 for i in range (PARTY_SIZE):
287 if GemRB.GameIsPCSelected (i+1):
288 pc = i+1
289 break
291 if pc == 0:
292 #summoned/charmed creature.
293 #TODO: some creatures have real actions window!!
294 GroupControls()
295 return
297 level = GemRB.GetVar ("ActionLevel")
298 TopIndex = GemRB.GetVar ("TopIndex")
299 if level == 0:
300 ActionsWindow.SetupControls (globals(), pc)
301 elif level == 1:
302 ActionsWindow.SetupEquipmentIcons(globals(), pc, TopIndex)
303 elif level == 2: #spells
304 GemRB.SetVar ("Type", 3)
305 ActionsWindow.SetupSpellIcons(globals(), pc, 3, TopIndex)
306 elif level == 3: #innates
307 GemRB.SetVar ("Type", 4)
308 ActionsWindow.SetupSpellIcons(globals(), pc, 4, TopIndex)
309 return
311 def ActionQWeaponPressed (which):
312 """Selects the given quickslot weapon if possible."""
314 pc = GemRB.GameGetFirstSelectedPC ()
315 qs = GemRB.GetEquippedQuickSlot (pc,1)
317 #38 is the magic slot
318 if ((qs==which) or (qs==38)) and GemRB.GameControlGetTargetMode() != TARGET_MODE_ATTACK:
319 GemRB.GameControlSetTargetMode (TARGET_MODE_ATTACK, GA_NO_DEAD|GA_NO_SELF|GA_NO_HIDDEN)
320 else:
321 GemRB.GameControlSetTargetMode (TARGET_MODE_NONE)
322 GemRB.SetEquippedQuickSlot (pc, which)
324 ActionsWindow.SetupControls (globals(), pc)
325 UpdateActionsWindow ()
326 return
328 def ActionQWeapon1Pressed ():
329 ActionQWeaponPressed(0)
331 def ActionQWeapon2Pressed ():
332 ActionQWeaponPressed(1)
334 def ActionQWeapon3Pressed ():
335 ActionQWeaponPressed(2)
337 def ActionQWeapon4Pressed ():
338 ActionQWeaponPressed(3)
340 #no check needed because the button wouldn't be drawn if illegal
341 def ActionLeftPressed ():
342 """Scrolls the actions window left.
344 Used primarily for spell selection."""
346 TopIndex = GemRB.GetVar ("TopIndex")
347 if TopIndex>10:
348 TopIndex -= 10
349 else:
350 TopIndex = 0
351 GemRB.SetVar ("TopIndex", TopIndex)
352 UpdateActionsWindow ()
353 return
355 #no check needed because the button wouldn't be drawn if illegal
356 def ActionRightPressed ():
357 """Scrolls the action window right.
359 Used primarily for spell selection."""
361 pc = GemRB.GameGetFirstSelectedPC ()
362 TopIndex = GemRB.GetVar ("TopIndex")
363 Type = GemRB.GetVar ("Type")
364 #Type is a bitfield if there is no level given
365 #This is to make sure cleric/mages get all spells listed
366 Max = GemRB.GetMemorizedSpellsCount(pc, Type)
367 TopIndex += 10
368 if TopIndex > Max - 10:
369 if Max>10:
370 TopIndex = Max-10
371 else:
372 TopIndex = 0
373 GemRB.SetVar ("TopIndex", TopIndex)
374 UpdateActionsWindow ()
375 return
377 def ActionBardSongPressed ():
378 """Toggles the battle song."""
379 pc = GemRB.GameGetFirstSelectedPC ()
380 GemRB.SetModalState (pc, MS_BATTLESONG)
381 GemRB.PlaySound ("act_01")
382 UpdateActionsWindow ()
383 return
385 def ActionSearchPressed ():
386 """Toggles detect traps."""
387 pc = GemRB.GameGetFirstSelectedPC ()
388 GemRB.SetModalState (pc, MS_DETECTTRAPS)
389 UpdateActionsWindow ()
390 return
392 def ActionStealthPressed ():
393 """Toggles stealth."""
394 pc = GemRB.GameGetFirstSelectedPC ()
395 GemRB.SetModalState (pc, MS_STEALTH)
396 GemRB.PlaySound ("act_07")
397 UpdateActionsWindow ()
398 return
400 def ActionTurnPressed ():
401 """Toggles turn undead."""
402 pc = GemRB.GameGetFirstSelectedPC ()
403 GemRB.SetModalState (pc, MS_TURNUNDEAD)
404 GemRB.PlaySound ("act_06")
405 UpdateActionsWindow ()
406 return
408 def ActionUseItemPressed ():
409 GemRB.SetVar ("TopIndex", 0)
410 GemRB.SetVar ("ActionLevel", 1)
411 UpdateActionsWindow ()
412 return
414 def ActionCastPressed ():
415 """Opens the spell choice scrollbar."""
416 GemRB.SetVar ("TopIndex", 0)
417 GemRB.SetVar ("ActionLevel", 2)
418 UpdateActionsWindow ()
419 return
421 def ActionQItemPressed (action):
422 """Uses the given quick item."""
423 pc = GemRB.GameGetFirstSelectedPC ()
424 #quick slot
425 GemRB.UseItem (pc, -2, action)
426 return
428 def ActionQItem1Pressed ():
429 ActionQItemPressed (ACT_QSLOT1)
430 return
432 def ActionQItem2Pressed ():
433 ActionQItemPressed (ACT_QSLOT2)
434 return
436 def ActionQItem3Pressed ():
437 ActionQItemPressed (ACT_QSLOT3)
438 return
440 def ActionQItem4Pressed ():
441 ActionQItemPressed (ACT_QSLOT4)
442 return
444 def ActionQItem5Pressed ():
445 ActionQItemPressed (ACT_QSLOT5)
446 return
448 def ActionInnatePressed ():
449 """Opens the innate spell scrollbar."""
450 GemRB.SetVar ("TopIndex", 0)
451 GemRB.SetVar ("ActionLevel", 3)
452 UpdateActionsWindow ()
453 return
455 def SpellPressed ():
456 """Prepares a spell to be cast."""
458 pc = GemRB.GameGetFirstSelectedPC ()
460 GemRB.GameControlSetTargetMode (TARGET_MODE_CAST)
461 Spell = GemRB.GetVar ("Spell")
462 Type = GemRB.GetVar ("Type")
463 GemRB.SpellCast (pc, Type, Spell)
464 GemRB.SetVar ("ActionLevel", 0)
465 UpdateActionsWindow ()
466 return
468 def EquipmentPressed ():
469 pc = GemRB.GameGetFirstSelectedPC ()
471 GemRB.GameControlSetTargetMode (TARGET_MODE_CAST)
472 Item = GemRB.GetVar ("Equipment")
473 #equipment index
474 GemRB.UseItem (pc, -1, Item)
475 GemRB.SetVar ("ActionLevel", 0)
476 UpdateActionsWindow ()
477 return
479 SelectionChangeHandler = None
481 def SetSelectionChangeHandler (handler):
482 """Updates the selection handler."""
484 global SelectionChangeHandler
486 # Switching from walking to non-walking environment:
487 # set the first selected PC in walking env as a selected
488 # in nonwalking env
489 if (not SelectionChangeHandler) and handler:
490 sel = GemRB.GameGetFirstSelectedPC ()
491 if not sel:
492 sel = 1
493 GemRB.GameSelectPCSingle (sel)
495 SelectionChangeHandler = handler
497 # redraw selection on change main selection | single selection
498 SelectionChanged ()
499 return
501 def RunSelectionChangeHandler ():
502 if SelectionChangeHandler:
503 SelectionChangeHandler ()
504 return
506 def OpenPortraitWindow (needcontrols):
507 global PortraitWindow
509 PortraitWindow = Window = GemRB.LoadWindow (1)
511 if needcontrols:
512 Button=Window.GetControl (8)
513 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, MinimizePortraits)
515 # AI
516 Button = Window.GetControl (6)
517 #fixing a gui bug, and while we are at it, hacking it to be easier
518 Button.SetSprites ("GUIBTACT", 0, 48, 47, 46, 49)
519 GSFlags = GemRB.GetMessageWindowSize ()&GS_PARTYAI
521 GemRB.SetVar ("AI", GSFlags)
522 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, AIPress)
523 Button.SetFlags (IE_GUI_BUTTON_CHECKBOX, OP_OR)
524 Button.SetVarAssoc ("AI", 1)
525 if GSFlags:
526 Button.SetTooltip (15917)
527 else:
528 Button.SetTooltip (15918)
530 #Select All
531 Button = Window.GetControl (7)
532 Button.SetTooltip (10485)
533 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, GUICommon.SelectAllOnPress)
535 for i in range (PARTY_SIZE):
536 Button = Window.GetControl (i)
537 Button.SetFont ("STATES2")
538 Button.SetVarAssoc ("PressedPortrait", i+1)
540 if (needcontrols):
541 Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, GUIINV.OpenInventoryWindowClick)
542 else:
543 Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, PortraitButtonOnPress)
545 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, PortraitButtonOnPress)
546 Button.SetEvent (IE_GUI_BUTTON_ON_SHIFT_PRESS, PortraitButtonOnShiftPress)
547 Button.SetEvent (IE_GUI_BUTTON_ON_DRAG_DROP, GUIINV.OnDropItemToPC)
548 Button.SetEvent (IE_GUI_BUTTON_ON_DRAG_DROP_PORTRAIT, OnDropPortraitToPC)
549 Button.SetEvent (IE_GUI_BUTTON_ON_DRAG, PortraitButtonOnDrag)
550 Button.SetEvent (IE_GUI_MOUSE_ENTER_BUTTON, PortraitButtonOnMouseEnter)
551 Button.SetEvent (IE_GUI_MOUSE_LEAVE_BUTTON, PortraitButtonOnMouseLeave)
553 Button.SetBorder (FRAME_PC_SELECTED, 1, 1, 2, 2, 0, 255, 0, 255)
554 Button.SetBorder (FRAME_PC_TARGET, 3, 3, 4, 4, 255, 255, 0, 255)
556 UpdatePortraitWindow ()
557 SelectionChanged ()
558 return Window
560 def UpdatePortraitWindow ():
561 """Updates all of the portraits."""
563 Window = PortraitWindow
565 pc = GemRB.GameGetSelectedPCSingle ()
566 Inventory = GemRB.GetVar ("Inventory")
568 for portid in range (PARTY_SIZE):
569 Button = Window.GetControl (portid)
570 pic = GemRB.GetPlayerPortrait (portid+1, 1)
571 if Inventory and pc != portid+1:
572 pic = None
574 if not pic:
575 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
576 Button.SetState (IE_GUI_BUTTON_DISABLED)
577 Button.SetText ("")
578 Button.SetTooltip ("")
579 continue
581 Button.SetFlags (IE_GUI_BUTTON_PICTURE| \
582 IE_GUI_BUTTON_HORIZONTAL| \
583 IE_GUI_BUTTON_ALIGN_LEFT| IE_GUI_BUTTON_ALIGN_TOP| \
584 IE_GUI_BUTTON_DRAGGABLE|IE_GUI_BUTTON_MULTILINE, OP_SET)
585 Button.SetState (IE_GUI_BUTTON_LOCKED)
586 Button.SetPicture (pic, "NOPORTSM")
587 hp = GemRB.GetPlayerStat (portid+1, IE_HITPOINTS)
588 hp_max = GemRB.GetPlayerStat (portid+1, IE_MAXHITPOINTS)
589 state = GemRB.GetPlayerStat (portid+1, IE_STATE_ID)
591 if (hp_max<1):
592 ratio = 0.0
593 else:
594 ratio = (hp+0.0) / hp_max
596 if hp<1 or (state & STATE_DEAD):
597 Button.SetOverlay (0, 64,64,64,200, 64,64,64,200)
598 else:
599 Button.SetOverlay (ratio, 255,0,0,200, 128,0,0,200)
600 Button.SetTooltip (GemRB.GetPlayerName (portid+1, 1) + "\n%d/%d" %(hp, hp_max))
602 #add effects on the portrait
603 effects = GemRB.GetPlayerStates (portid+1)
604 states = ""
605 for col in range(len(effects)):
606 states = effects[col:col+1] + states
607 if col % 3 == 2: states = "\n" + states
608 for x in range(3 - (len(effects)/3)):
609 states = "\n" + states
610 states = "\n" + states
612 # blank space
613 flag = blank = chr(238)
615 # shopping icon
616 if pc==portid+1:
617 if GemRB.GetStore()!=None:
618 flag = chr(155)
619 # talk icon
620 if GemRB.GameGetSelectedPCSingle(1)==portid+1:
621 flag = chr(154)
623 if LUCommon.CanLevelUp (portid+1):
624 states = flag+blank+chr(255) + states
625 else:
626 states = flag+blank+blank + states
627 Button.SetText(states)
628 return
630 def PortraitButtonOnDrag ():
631 global DraggedPortrait
633 #they start from 1
634 DraggedPortrait = GemRB.GetVar ("PressedPortrait")
635 GemRB.DragItem (DraggedPortrait, -1, "")
636 return
638 def PortraitButtonOnPress ():
639 """Selects the portrait individually."""
641 i = GemRB.GetVar ("PressedPortrait")
643 if not i:
644 return
646 if GemRB.GameControlGetTargetMode() != TARGET_MODE_NONE:
647 GemRB.ActOnPC (i)
648 return
650 if (not SelectionChangeHandler):
651 if GemRB.GameIsPCSelected (i):
652 GemRB.GameControlSetScreenFlags (SF_CENTERONACTOR, OP_OR)
653 GemRB.GameSelectPC (i, True, SELECT_REPLACE)
654 else:
655 GemRB.GameSelectPCSingle (i)
656 SelectionChanged ()
657 RunSelectionChangeHandler ()
658 return
660 def PortraitButtonOnShiftPress ():
661 """Handles selecting multiple portaits with shift."""
663 i = GemRB.GetVar ("PressedPortrait")
665 if not i:
666 return
668 if (not SelectionChangeHandler):
669 sel = GemRB.GameIsPCSelected (i)
670 sel = not sel
671 GemRB.GameSelectPC (i, sel)
672 else:
673 GemRB.GameSelectPCSingle (i)
674 SelectionChanged ()
675 RunSelectionChangeHandler ()
676 return
678 def SelectionChanged ():
679 """Ran by the Game class when a PC selection is changed."""
681 global PortraitWindow
683 if not PortraitWindow:
684 return
686 GemRB.SetVar ("ActionLevel", 0)
687 if (not SelectionChangeHandler):
688 UpdateActionsWindow ()
689 for i in range (PARTY_SIZE):
690 Button = PortraitWindow.GetControl (i)
691 Button.EnableBorder (FRAME_PC_SELECTED, GemRB.GameIsPCSelected (i + 1))
692 else:
693 sel = GemRB.GameGetSelectedPCSingle ()
695 #update mage school
696 GemRB.SetVar ("MAGESCHOOL", 0)
697 Kit = GUICommon.GetKitIndex (sel)
698 if Kit and GUICommon.KitListTable.GetValue (Kit, 7) == 1:
699 MageTable = GemRB.LoadTable ("magesch")
700 GemRB.SetVar ("MAGESCHOOL", MageTable.FindValue (3, GUICommon.KitListTable.GetValue (Kit, 6) ) )
702 for i in range (PARTY_SIZE):
703 Button = PortraitWindow.GetControl (i)
704 Button.EnableBorder (FRAME_PC_SELECTED, i + 1 == sel)
705 return
707 def PortraitButtonOnMouseEnter ():
708 global DraggedPortrait
710 i = GemRB.GetVar ("PressedPortrait")
712 GemRB.GameControlSetLastActor( i )
713 if GemRB.IsDraggingItem()==2:
714 if DraggedPortrait != None:
715 GemRB.SwapPCs (DraggedPortrait, i)
716 GemRB.SetVar ("PressedPortrait", DraggedPortrait)
717 DraggedPortrait = i
718 GemRB.SetTimedEvent (CheckDragging, 1)
719 else:
720 OnDropPortraitToPC()
721 return
723 if GemRB.IsDraggingItem ():
724 Button = PortraitWindow.GetControl (i)
725 Button.EnableBorder (FRAME_PC_TARGET, 1)
726 return
728 def OnDropPortraitToPC ():
729 GemRB.SetVar ("PressedPortrait",0)
730 GemRB.DragItem (0, -1, "")
731 DraggedPortrait = None
732 return
734 def CheckDragging():
735 """Contains portrait dragging in case of mouse out-of-range."""
737 global DraggedPortrait
739 i = GemRB.GetVar ("PressedPortrait")
740 if not i:
741 GemRB.DragItem (0, -1, "")
743 if GemRB.IsDraggingItem()!=2:
744 DraggedPortrait = None
745 return
747 def PortraitButtonOnMouseLeave ():
748 i = GemRB.GetVar ("PressedPortrait")
749 if not i:
750 return
752 Button = PortraitWindow.GetControl (i-1)
753 Button.EnableBorder (FRAME_PC_TARGET, 0)
754 GemRB.SetVar ("PressedPortrait", 0)
755 GemRB.SetTimedEvent (CheckDragging, 1)
756 return
758 def ActionStopPressed ():
759 for i in range (PARTY_SIZE):
760 if GemRB.GameIsPCSelected (i + 1):
761 GemRB.ClearActions (i + 1)
762 return
764 def ActionTalkPressed ():
765 GemRB.GameControlSetTargetMode (TARGET_MODE_TALK,GA_NO_DEAD|GA_NO_ENEMY|GA_NO_HIDDEN)
767 def ActionAttackPressed ():
768 GemRB.GameControlSetTargetMode (TARGET_MODE_ATTACK,GA_NO_DEAD|GA_NO_SELF|GA_NO_HIDDEN)
770 def ActionDefendPressed ():
771 GemRB.GameControlSetTargetMode (TARGET_MODE_DEFEND,GA_NO_SELF|GA_NO_ENEMY|GA_NO_HIDDEN)
773 def ActionThievingPressed ():
774 GemRB.GameControlSetTargetMode (TARGET_MODE_PICK, GA_NO_DEAD|GA_NO_SELF|GA_NO_ENEMY|GA_NO_HIDDEN)
776 def MinimizePortraits():
777 GemRB.GameSetScreenFlags(GS_PORTRAITPANE, OP_OR)
779 def OpenWaitForDiscWindow ():
780 global DiscWindow
782 if DiscWindow:
783 GemRB.HideGUI ()
784 if DiscWindow:
785 DiscWindow.Unload ()
786 GemRB.SetVar ("OtherWindow", -1)
787 # ...LoadWindowPack()
788 EnableAnimatedWindows ()
789 DiscWindow = None
790 GemRB.UnhideGUI ()
791 return
793 try:
794 GemRB.HideGUI ()
795 except:
796 pass
798 GemRB.LoadWindowPack ("GUIID")
799 DiscWindow = Window = GemRB.LoadWindow (0)
800 GemRB.SetVar ("OtherWindow", Window.ID)
801 label = DiscWindow.GetControl (0)
803 disc_num = GemRB.GetVar ("WaitForDisc")
804 #disc_path = GemRB.GetVar ("WaitForDiscPath")
805 disc_path = 'XX:'
807 text = GemRB.GetString (31483) + " " + str (disc_num) + " " + GemRB.GetString (31569) + " " + disc_path + "\n" + GemRB.GetString (49152)
808 label.SetText (text)
809 DisableAnimatedWindows ()
810 # 31483 - Please place PS:T disc number
811 # 31568 - Please place the PS:T DVD
812 # 31569 - in drive
813 # 31570 - Wrong disc in drive
814 # 31571 - There is no disc in drive
815 # 31578 - No disc could be found in drive. Please place Disc 1 in drive.
816 # 49152 - To quit the game, press Alt-F4
818 try:
819 GemRB.UnhideGUI ()
820 except:
821 DiscWindow.SetVisible (WINDOW_VISIBLE)
823 def CheckLevelUp(pc):
824 GemRB.SetVar ("CheckLevelUp"+str(pc), LUCommon.CanLevelUp (pc))