2 # GemRB - Infinity Engine Emulator
3 # Copyright (C) 2003 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 windows in lower part of the screen
23 ###################################################
26 from GUIDefines
import *
27 from ie_stats
import *
28 from ie_modal
import *
29 from ie_action
import *
47 DraggedPortrait
= None
49 def SetupMenuWindowControls (Window
, Gears
, ReturnToGame
):
50 # FIXME: add "(key)" to tooltips!
53 Button
= Window
.GetControl (0)
54 Button
.SetTooltip (16313)
55 #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
56 Button
.SetVarAssoc ("SelectedWindow", 0)
57 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, ReturnToGame
)
58 Button
.SetFlags (IE_GUI_BUTTON_CANCEL
, OP_OR
)
61 Button
= Window
.GetControl (1)
62 Button
.SetTooltip (16310)
63 #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
64 Button
.SetVarAssoc ("SelectedWindow", 1)
65 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, GUIMA
.OpenMapWindow
)
68 Button
= Window
.GetControl (2)
69 Button
.SetTooltip (16308)
70 #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
71 Button
.SetVarAssoc ("SelectedWindow", 2)
72 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, GUIJRNL
.OpenJournalWindow
)
75 Button
= Window
.GetControl (3)
76 Button
.SetTooltip (16307)
77 #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
78 Button
.SetVarAssoc ("SelectedWindow", 3)
79 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, GUIINV
.OpenInventoryWindow
)
82 Button
= Window
.GetControl (4)
83 Button
.SetTooltip (16306)
84 #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
85 Button
.SetVarAssoc ("SelectedWindow", 4)
86 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, GUIREC
.OpenRecordsWindow
)
89 Button
= Window
.GetControl (5)
90 Button
.SetTooltip (16309)
91 #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
92 Button
.SetVarAssoc ("SelectedWindow", 5)
93 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, GUIMG
.OpenMageWindow
)
95 Button
= Window
.GetControl (6)
96 Button
.SetTooltip (14930)
97 #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
98 Button
.SetVarAssoc ("SelectedWindow", 6)
99 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, GUIPR
.OpenPriestWindow
)
102 Button
= Window
.GetControl (7)
103 Button
.SetTooltip (16311)
104 #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
105 Button
.SetVarAssoc ("SelectedWindow", 7)
106 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, GUIOPT
.OpenOptionsWindow
)
109 Button
= Window
.GetControl (8)
110 Button
.SetTooltip (16312)
111 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, None)
114 # Gears (time), how doesn't have this in the right place
115 if GUICommon
.HasHOW():
116 pos
= GemRB
.GetSystemVariable (SV_HEIGHT
)-71
117 Window
.CreateButton (9, 6, pos
, 64, 71)
118 Button
= Window
.GetControl (9)
119 Button
.SetAnimation ("CGEAR")
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)
126 MarkMenuButton (Window
)
129 def MarkMenuButton (WindowIndex
):
130 Pressed
= WindowIndex
.GetControl( GemRB
.GetVar ("SelectedWindow") )
132 for button
in range (9):
133 Button
= WindowIndex
.GetControl (button
)
134 Button
.SetState (IE_GUI_BUTTON_ENABLED
)
138 else: # highlight return to game
139 Button
= WindowIndex
.GetControl (0)
141 Button
.SetState (IE_GUI_BUTTON_PRESSED
)
144 Button
= PortraitWindow
.GetControl (6)
145 AI
= GemRB
.GetMessageWindowSize () & GS_PARTYAI
147 GemRB
.GameSetScreenFlags (GS_PARTYAI
, OP_NAND
)
148 Button
.SetTooltip (15918)
150 GemRB
.GameSetScreenFlags (GS_PARTYAI
, OP_OR
)
151 Button
.SetTooltip (15917)
154 def EmptyControls ():
157 GemRB
.SetVar ("ActionLevel", 0)
158 Window
= ActionsWindow
160 Button
= Window
.GetControl (i
)
161 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_SET
)
162 Button
.SetPicture ("")
165 def SelectFormationPreset ():
166 GemRB
.GameSetFormation (GemRB
.GetVar ("Value"), GemRB
.GetVar ("Formation") )
170 def SetupFormation ():
173 Window
= ActionsWindow
175 Button
= Window
.GetControl (i
)
176 Button
.SetFlags (IE_GUI_BUTTON_NORMAL
, OP_SET
)
177 Button
.SetSprites ("GUIBTBUT",0,0,1,2,3)
178 Button
.SetBAM ("FORM%x"%i,0,0,-1)
179 Button
.SetVarAssoc ("Value", i
)
180 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, SelectFormationPreset
)
183 def GroupControls ():
186 GemRB
.SetVar ("ActionLevel", 0)
187 Window
= ActionsWindow
188 Button
= Window
.GetControl (0)
189 Button
.SetActionIcon (globals(), 7)
190 Button
= Window
.GetControl (1)
191 Button
.SetActionIcon (globals(), 15)
192 Button
= Window
.GetControl (2)
193 Button
.SetActionIcon (globals(), 21)
194 Button
= Window
.GetControl (3)
195 Button
.SetActionIcon (globals(), -1)
196 Button
= Window
.GetControl (4)
197 Button
.SetActionIcon (globals(), -1)
198 Button
= Window
.GetControl (5)
199 Button
.SetActionIcon (globals(), -1)
200 Button
= Window
.GetControl (6)
201 Button
.SetActionIcon (globals(), -1)
202 GemRB
.SetVar ("Formation", GemRB
.GameGetFormation ())
204 Button
= Window
.GetControl (7+i
)
205 Button
.SetState (IE_GUI_BUTTON_ENABLED
)
206 idx
= GemRB
.GameGetFormation (i
)
207 Button
.SetFlags (IE_GUI_BUTTON_RADIOBUTTON|IE_GUI_BUTTON_NORMAL
, OP_SET
)
208 Button
.SetSprites ("GUIBTBUT",0,i
*2,i
*2+1,i
*2+24,i
*2+25)
209 Button
.SetBAM ("FORM%x"%idx,0,0,-1)
210 Button
.SetVarAssoc ("Formation", i
)
211 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, GUICommon
.SelectFormation
)
212 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, SetupFormation
)
213 str = GemRB
.GetString (4935)
214 Button
.SetTooltip ("F%d - %s"%(8+i
,str) )
217 def OpenActionsWindowControls (Window
):
220 ActionsWindow
= Window
221 UpdateActionsWindow ()
224 def UpdateActionsWindow ():
225 """Redraws the actions section of the window."""
227 global ActionsWindow
, PortraitWindow
, OptionsWindow
228 global level
, TopIndex
230 if ActionsWindow
== -1:
233 if ActionsWindow
== None:
236 #fully redraw the side panes to cover the actions window
237 #do this only when there is no 'otherwindow'
238 if GemRB
.GetVar ("OtherWindow") == -1:
240 PortraitWindow
.Invalidate ()
242 OptionsWindow
.Invalidate ()
244 Selected
= GemRB
.GetSelectedSize()
246 #setting up the disabled button overlay (using the second border slot)
248 Button
= ActionsWindow
.GetControl (i
)
249 Button
.SetBorder (1, 0, 0, 0, 0, 50,30,10,120, 0, 1)
250 Button
.SetFont ("NUMBER")
259 #this is based on class
260 #we are sure there is only one actor selected
262 for i
in range (PARTY_SIZE
):
263 if GemRB
.GameIsPCSelected (i
+1):
267 level
= GemRB
.GetVar ("ActionLevel")
268 TopIndex
= GemRB
.GetVar ("TopIndex")
270 ActionsWindow
.SetupControls (globals(), pc
)
272 ActionsWindow
.SetupEquipmentIcons(globals(), pc
, TopIndex
)
273 elif level
== 2: #spells
274 GemRB
.SetVar ("Type", 3)
275 ActionsWindow
.SetupSpellIcons(globals(), pc
, 3, TopIndex
)
276 elif level
== 3: #innates
277 GemRB
.SetVar ("Type", 4)
278 ActionsWindow
.SetupSpellIcons(globals(), pc
, 4, TopIndex
)
281 def ActionQWeaponPressed (which
):
282 """Selects the given quickslot weapon if possible."""
284 pc
= GemRB
.GameGetFirstSelectedPC ()
285 qs
= GemRB
.GetEquippedQuickSlot (pc
,1)
287 #38 is the magic slot
288 if ((qs
==which
) or (qs
==38)) and GemRB
.GameControlGetTargetMode() != TARGET_MODE_ATTACK
:
289 GemRB
.GameControlSetTargetMode (TARGET_MODE_ATTACK
, GA_NO_DEAD|GA_NO_SELF|GA_NO_HIDDEN
)
291 GemRB
.GameControlSetTargetMode (TARGET_MODE_NONE
)
292 GemRB
.SetEquippedQuickSlot (pc
, which
)
294 ActionsWindow
.SetupControls (globals(), pc
)
295 UpdateActionsWindow ()
298 def ActionQWeapon1Pressed ():
299 ActionQWeaponPressed(0)
301 def ActionQWeapon2Pressed ():
302 ActionQWeaponPressed(1)
304 def ActionQWeapon3Pressed ():
305 ActionQWeaponPressed(2)
307 def ActionQWeapon4Pressed ():
308 ActionQWeaponPressed(3)
310 #no check needed because the button wouldn't be drawn if illegal
311 def ActionLeftPressed ():
312 TopIndex
= GemRB
.GetVar ("TopIndex")
317 GemRB
.SetVar ("TopIndex", TopIndex
)
318 UpdateActionsWindow ()
321 #no check needed because the button wouldn't be drawn if illegal
322 def ActionRightPressed ():
323 pc
= GemRB
.GameGetFirstSelectedPC ()
324 TopIndex
= GemRB
.GetVar ("TopIndex")
325 Type
= GemRB
.GetVar ("Type")
326 Max
= GemRB
.GetMemorizedSpellsCount(pc
, Type
)
328 if TopIndex
> Max
- 10:
334 GemRB
.SetVar ("TopIndex", TopIndex
)
335 UpdateActionsWindow ()
338 def ActionBardSongPressed ():
339 pc
= GemRB
.GameGetFirstSelectedPC ()
340 GemRB
.SetModalState (pc
, MS_BATTLESONG
)
341 GemRB
.PlaySound ("act_01")
342 UpdateActionsWindow ()
345 def ActionSearchPressed ():
346 pc
= GemRB
.GameGetFirstSelectedPC ()
347 GemRB
.SetModalState (pc
, MS_DETECTTRAPS
)
348 UpdateActionsWindow ()
351 def ActionStealthPressed ():
352 pc
= GemRB
.GameGetFirstSelectedPC ()
353 GemRB
.SetModalState (pc
, MS_STEALTH
)
354 GemRB
.PlaySound ("act_07")
355 UpdateActionsWindow ()
358 def ActionTurnPressed ():
359 pc
= GemRB
.GameGetFirstSelectedPC ()
360 GemRB
.SetModalState (pc
, MS_TURNUNDEAD
)
361 GemRB
.PlaySound ("act_06")
362 UpdateActionsWindow ()
365 def ActionUseItemPressed ():
366 GemRB
.SetVar ("TopIndex", 0)
367 GemRB
.SetVar ("ActionLevel", 1)
368 UpdateActionsWindow ()
371 def ActionCastPressed ():
372 GemRB
.SetVar ("TopIndex", 0)
373 GemRB
.SetVar ("ActionLevel", 2)
374 UpdateActionsWindow ()
377 def ActionQItemPressed (action
):
378 pc
= GemRB
.GameGetFirstSelectedPC ()
380 GemRB
.UseItem (pc
, -2, action
)
383 def ActionQItem1Pressed ():
384 ActionQItemPressed (ACT_QSLOT1
)
387 def ActionQItem2Pressed ():
388 ActionQItemPressed (ACT_QSLOT2
)
391 def ActionQItem3Pressed ():
392 ActionQItemPressed (ACT_QSLOT3
)
395 def ActionQItem4Pressed ():
396 ActionQItemPressed (ACT_QSLOT4
)
399 def ActionQItem5Pressed ():
400 ActionQItemPressed (ACT_QSLOT5
)
403 def ActionInnatePressed ():
404 GemRB
.SetVar ("TopIndex", 0)
405 GemRB
.SetVar ("ActionLevel", 3)
406 UpdateActionsWindow ()
410 pc
= GemRB
.GameGetFirstSelectedPC ()
412 GemRB
.GameControlSetTargetMode (TARGET_MODE_CAST
)
413 Spell
= GemRB
.GetVar ("Spell")
414 Type
= GemRB
.GetVar ("Type")
415 GemRB
.SpellCast (pc
, Type
, Spell
)
416 GemRB
.SetVar ("ActionLevel", 0)
417 UpdateActionsWindow ()
420 def EquipmentPressed ():
421 pc
= GemRB
.GameGetFirstSelectedPC ()
423 GemRB
.GameControlSetTargetMode (TARGET_MODE_CAST
)
424 Item
= GemRB
.GetVar ("Equipment")
426 GemRB
.UseItem (pc
, -1, Item
)
427 GemRB
.SetVar ("ActionLevel", 0)
428 UpdateActionsWindow ()
431 SelectionChangeHandler
= None
433 def SetSelectionChangeHandler (handler
):
434 global SelectionChangeHandler
436 # Switching from walking to non-walking environment:
437 # set the first selected PC in walking env as a selected
439 #if (not SelectionChangeHandler) and handler:
440 if (not SelectionChangeHandler
) and handler
and (not GUICommon
.NextWindowFn
):
441 sel
= GemRB
.GameGetFirstSelectedPC ()
444 GemRB
.GameSelectPCSingle (sel
)
446 SelectionChangeHandler
= handler
448 # redraw selection on change main selection | single selection
451 def RunSelectionChangeHandler ():
452 if SelectionChangeHandler
:
453 SelectionChangeHandler ()
455 def OpenPortraitWindow (needcontrols
):
456 global PortraitWindow
458 #take care, this window is different in how/iwd
459 if GUICommon
.HasHOW() and needcontrols
:
460 PortraitWindow
= Window
= GemRB
.LoadWindow (26)
462 PortraitWindow
= Window
= GemRB
.LoadWindow (1)
465 if GUICommon
.HasHOW():
467 pos
= GemRB
.GetSystemVariable (SV_HEIGHT
) - 37
468 Window
.CreateButton (8, 6, pos
, 55, 37)
469 Button
= Window
.GetControl (8)
470 Button
.SetSprites ("GUIRSBUT", 0,0,1,0,0)
471 Button
.SetTooltip (11942)
472 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, GUICommon
.RestPress
)
475 Window
.CreateButton (6, 6, pos
, 27, 36)
477 Button
= Window
.GetControl (6)
478 #fixing a gui bug, and while we are at it, hacking it to be easier
479 Button
.SetSprites ("GUIBTACT", 0, 46, 47, 48, 49)
480 GSFlags
= GemRB
.GetMessageWindowSize ()&GS_PARTYAI
482 GemRB
.SetVar ("AI", GSFlags
)
483 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, AIPress
)
484 Button
.SetFlags (IE_GUI_BUTTON_CHECKBOX
, OP_OR
)
485 Button
.SetVarAssoc ("AI", 1)
487 Button
.SetTooltip (15917)
489 Button
.SetTooltip (15918)
492 if GUICommon
.HasHOW():
493 Window
.CreateButton (7, 33, pos
, 27, 36)
494 Button
= Window
.GetControl (7)
495 Button
.SetSprites ("GUIBTACT", 0, 50, 51, 50, 51)
496 Button
.SetTooltip (10485)
497 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, GUICommon
.SelectAllOnPress
)
498 if not GUICommon
.HasHOW():
500 Button
= PortraitWindow
.GetControl (8)
501 Button
.SetTooltip (11942)
502 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, GUICommon
.RestPress
)
504 pc
= GemRB
.GameGetSelectedPCSingle ()
505 Inventory
= GemRB
.GetVar ("Inventory")
507 for i
in range (PARTY_SIZE
):
508 Button
= Window
.GetControl (i
)
509 Button
.SetFont ("STATES")
510 Button
.SetVarAssoc ("PressedPortrait", i
+1)
513 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, GUIINV
.OpenInventoryWindowClick
)
515 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, PortraitButtonOnPress
)
517 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, PortraitButtonOnPress
)
518 Button
.SetEvent (IE_GUI_BUTTON_ON_SHIFT_PRESS
, PortraitButtonOnShiftPress
)
519 Button
.SetEvent (IE_GUI_BUTTON_ON_DRAG_DROP
, GUIINV
.OnDropItemToPC
)
520 Button
.SetEvent (IE_GUI_BUTTON_ON_DRAG_DROP_PORTRAIT
, OnDropPortraitToPC
)
521 Button
.SetEvent (IE_GUI_BUTTON_ON_DRAG
, PortraitButtonOnDrag
)
522 Button
.SetEvent (IE_GUI_MOUSE_ENTER_BUTTON
, PortraitButtonOnMouseEnter
)
523 Button
.SetEvent (IE_GUI_MOUSE_LEAVE_BUTTON
, PortraitButtonOnMouseLeave
)
524 if Inventory
and pc
!= i
+1:
525 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_SET
)
526 Button
.SetState (IE_GUI_BUTTON_DISABLED
)
528 Button
.SetTooltip ("")
530 # overlay a label, so we can display the hp with the correct font
531 Button
.CreateLabelOnButton(100+i
, "NUMFONT", IE_GUI_BUTTON_ALIGN_TOP|IE_GUI_BUTTON_ALIGN_LEFT
)
533 Button
.SetBorder (FRAME_PC_SELECTED
, 1, 1, 2, 2, 0, 255, 0, 255)
534 Button
.SetBorder (FRAME_PC_TARGET
, 3, 3, 4, 4, 255, 255, 0, 255)
536 UpdatePortraitWindow ()
540 def UpdatePortraitWindow ():
541 Window
= PortraitWindow
543 pc
= GemRB
.GameGetSelectedPCSingle ()
544 Inventory
= GemRB
.GetVar ("Inventory")
546 for portid
in range (PARTY_SIZE
):
547 Button
= Window
.GetControl (portid
)
548 pic
= GemRB
.GetPlayerPortrait (portid
+1, 1)
549 if Inventory
and pc
!= portid
+1:
553 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_SET
)
554 Button
.SetState (IE_GUI_BUTTON_DISABLED
)
556 Button
.SetTooltip ("")
559 sel
= GemRB
.GameGetSelectedPCSingle () == portid
+ 1
560 Button
.SetFlags (IE_GUI_BUTTON_PICTURE| \
561 IE_GUI_BUTTON_HORIZONTAL| \
562 IE_GUI_BUTTON_ALIGN_LEFT| IE_GUI_BUTTON_ALIGN_TOP| \
563 IE_GUI_BUTTON_DRAGGABLE|IE_GUI_BUTTON_MULTILINE
, OP_SET
)
564 Button
.SetState (IE_GUI_BUTTON_LOCKED
)
565 Button
.SetPicture (pic
, "NOPORTSM")
567 ratio_str
= GUICommon
.SetupDamageInfo (portid
+1, Button
)
569 #add effects on the portrait
570 #http://img.jeuxvideo.fr/00002663-photo-icewind-dale-heart-of-winter.jpg
571 effects
= GemRB
.GetPlayerStates (portid
+1)
573 for col
in range(len(effects
)):
574 states
= effects
[col
:col
+1] + states
575 if col
% 3 == 2: states
= "\n" + states
576 for x
in range(2 - (len(effects
)/3)):
577 states
= "\n" + states
578 states
= "\n" + states
581 # TODO: missing, maybe add another string tag to make glyphs 100% transparent?
582 flag
= blank
= chr(238)
584 # these two are missing too
587 #if GemRB.GetStore()!=None:
590 #if GemRB.GameGetSelectedPCSingle(1)==portid+1:
593 if LUCommon
.CanLevelUp (portid
+1):
594 states
= flag
+blank
+chr(255) + states
596 #states = flag+blank+blank + states
597 #states = "\n" + states
599 Button
.SetText(states
)
601 HPLabel
= Window
.GetControl (100+portid
)
602 HPLabel
.SetText (ratio_str
) # TODO: color depending on the ratio
604 #Button.EnableBorder (FRAME_PC_SELECTED, sel)
607 def PortraitButtonOnDrag ():
608 global DraggedPortrait
611 DraggedPortrait
= GemRB
.GetVar ("PressedPortrait")
612 GemRB
.DragItem (DraggedPortrait
, -1, "")
615 def PortraitButtonOnPress ():
616 i
= GemRB
.GetVar ("PressedPortrait")
621 if GemRB
.GameControlGetTargetMode() != TARGET_MODE_NONE
:
625 if (not SelectionChangeHandler
):
626 if GemRB
.GameIsPCSelected (i
):
627 GemRB
.GameControlSetScreenFlags (SF_CENTERONACTOR
, OP_OR
)
628 GemRB
.GameSelectPC (i
, True, SELECT_REPLACE
)
630 GemRB
.GameSelectPCSingle (i
)
632 RunSelectionChangeHandler ()
635 def PortraitButtonOnShiftPress ():
636 i
= GemRB
.GetVar ("PressedPortrait")
641 if (not SelectionChangeHandler
):
642 sel
= GemRB
.GameIsPCSelected (i
)
644 GemRB
.GameSelectPC (i
, sel
)
646 GemRB
.GameSelectPCSingle (i
)
648 RunSelectionChangeHandler ()
651 # Run by Game class when selection was changed
652 def SelectionChanged ():
653 global PortraitWindow
655 if not PortraitWindow
:
658 GemRB
.SetVar ("ActionLevel", 0)
659 # FIXME: hack. If defined, display single selection
660 if (not SelectionChangeHandler
):
661 UpdateActionsWindow ()
662 for i
in range (PARTY_SIZE
):
663 Button
= PortraitWindow
.GetControl (i
)
664 Button
.EnableBorder (FRAME_PC_SELECTED
, GemRB
.GameIsPCSelected (i
+ 1))
666 sel
= GemRB
.GameGetSelectedPCSingle ()
667 for i
in range (PARTY_SIZE
):
668 Button
= PortraitWindow
.GetControl (i
)
669 Button
.EnableBorder (FRAME_PC_SELECTED
, i
+ 1 == sel
)
671 GUIWORLD
.CloseContainerWindow()
674 def PortraitButtonOnMouseEnter ():
675 global DraggedPortrait
677 i
= GemRB
.GetVar ("PressedPortrait")
679 GemRB
.GameControlSetLastActor( i
)
680 if GemRB
.IsDraggingItem()==2:
681 if DraggedPortrait
!= None:
682 GemRB
.SwapPCs (DraggedPortrait
, i
)
683 GemRB
.SetVar ("PressedPortrait", DraggedPortrait
)
685 GemRB
.SetTimedEvent (CheckDragging
, 1)
690 if GemRB
.IsDraggingItem ():
691 Button
= PortraitWindow
.GetControl (i
)
692 Button
.EnableBorder (FRAME_PC_TARGET
, 1)
695 def OnDropPortraitToPC ():
696 GemRB
.SetVar ("PressedPortrait",0)
697 GemRB
.DragItem (0, -1, "")
698 DraggedPortrait
= None
702 """Contains portrait dragging in case of mouse out-of-range."""
704 global DraggedPortrait
706 i
= GemRB
.GetVar ("PressedPortrait")
708 GemRB
.DragItem (0, -1, "")
710 if GemRB
.IsDraggingItem()!=2:
711 DraggedPortrait
= None
714 def PortraitButtonOnMouseLeave ():
715 i
= GemRB
.GetVar ("PressedPortrait")
719 Button
= PortraitWindow
.GetControl (i
-1)
720 Button
.EnableBorder (FRAME_PC_TARGET
, 0)
721 GemRB
.SetVar ("PressedPortrait", 0)
722 GemRB
.SetTimedEvent (CheckDragging
, 1)
725 def ActionStopPressed ():
726 for i
in range (PARTY_SIZE
):
727 if GemRB
.GameIsPCSelected (i
+ 1):
728 GemRB
.ClearActions (i
+ 1)
731 def ActionTalkPressed ():
732 GemRB
.GameControlSetTargetMode (TARGET_MODE_TALK
,GA_NO_DEAD|GA_NO_ENEMY|GA_NO_HIDDEN
)
734 def ActionAttackPressed ():
735 GemRB
.GameControlSetTargetMode (TARGET_MODE_ATTACK
,GA_NO_DEAD|GA_NO_SELF|GA_NO_HIDDEN
)
737 def ActionDefendPressed ():
738 GemRB
.GameControlSetTargetMode (TARGET_MODE_DEFEND
,GA_NO_SELF|GA_NO_ENEMY|GA_NO_HIDDEN
)
740 def ActionThievingPressed ():
741 GemRB
.GameControlSetTargetMode (TARGET_MODE_PICK
, GA_NO_DEAD|GA_NO_SELF|GA_NO_ENEMY|GA_NO_HIDDEN
)
743 def CheckLevelUp(pc
):
744 GemRB
.SetVar ("CheckLevelUp"+str(pc
), LUCommon
.CanLevelUp (pc
))