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):
268 #summoned/charmed creature.
269 #TODO: some creatures have real actions window!!
273 level
= GemRB
.GetVar ("ActionLevel")
274 TopIndex
= GemRB
.GetVar ("TopIndex")
276 ActionsWindow
.SetupControls (globals(), pc
)
278 ActionsWindow
.SetupEquipmentIcons(globals(), pc
, TopIndex
)
279 elif level
== 2: #spells
280 GemRB
.SetVar ("Type", 3)
281 ActionsWindow
.SetupSpellIcons(globals(), pc
, 3, TopIndex
)
282 elif level
== 3: #innates
283 GemRB
.SetVar ("Type", 4)
284 ActionsWindow
.SetupSpellIcons(globals(), pc
, 4, TopIndex
)
287 def ActionQWeaponPressed (which
):
288 """Selects the given quickslot weapon if possible."""
290 pc
= GemRB
.GameGetFirstSelectedPC ()
291 qs
= GemRB
.GetEquippedQuickSlot (pc
,1)
293 #38 is the magic slot
294 if ((qs
==which
) or (qs
==38)) and GemRB
.GameControlGetTargetMode() != TARGET_MODE_ATTACK
:
295 GemRB
.GameControlSetTargetMode (TARGET_MODE_ATTACK
, GA_NO_DEAD|GA_NO_SELF|GA_NO_HIDDEN
)
297 GemRB
.GameControlSetTargetMode (TARGET_MODE_NONE
)
298 GemRB
.SetEquippedQuickSlot (pc
, which
)
300 ActionsWindow
.SetupControls (globals(), pc
)
301 UpdateActionsWindow ()
304 def ActionQWeapon1Pressed ():
305 ActionQWeaponPressed(0)
307 def ActionQWeapon2Pressed ():
308 ActionQWeaponPressed(1)
310 def ActionQWeapon3Pressed ():
311 ActionQWeaponPressed(2)
313 def ActionQWeapon4Pressed ():
314 ActionQWeaponPressed(3)
316 #no check needed because the button wouldn't be drawn if illegal
317 def ActionLeftPressed ():
318 TopIndex
= GemRB
.GetVar ("TopIndex")
323 GemRB
.SetVar ("TopIndex", TopIndex
)
324 UpdateActionsWindow ()
327 #no check needed because the button wouldn't be drawn if illegal
328 def ActionRightPressed ():
329 pc
= GemRB
.GameGetFirstSelectedPC ()
330 TopIndex
= GemRB
.GetVar ("TopIndex")
331 Type
= GemRB
.GetVar ("Type")
332 Max
= GemRB
.GetMemorizedSpellsCount(pc
, Type
)
334 if TopIndex
> Max
- 10:
340 GemRB
.SetVar ("TopIndex", TopIndex
)
341 UpdateActionsWindow ()
344 def ActionBardSongPressed ():
345 pc
= GemRB
.GameGetFirstSelectedPC ()
346 GemRB
.SetModalState (pc
, MS_BATTLESONG
)
347 GemRB
.PlaySound ("act_01")
348 UpdateActionsWindow ()
351 def ActionSearchPressed ():
352 pc
= GemRB
.GameGetFirstSelectedPC ()
353 GemRB
.SetModalState (pc
, MS_DETECTTRAPS
)
354 UpdateActionsWindow ()
357 def ActionStealthPressed ():
358 pc
= GemRB
.GameGetFirstSelectedPC ()
359 GemRB
.SetModalState (pc
, MS_STEALTH
)
360 GemRB
.PlaySound ("act_07")
361 UpdateActionsWindow ()
364 def ActionTurnPressed ():
365 pc
= GemRB
.GameGetFirstSelectedPC ()
366 GemRB
.SetModalState (pc
, MS_TURNUNDEAD
)
367 GemRB
.PlaySound ("act_06")
368 UpdateActionsWindow ()
371 def ActionUseItemPressed ():
372 GemRB
.SetVar ("TopIndex", 0)
373 GemRB
.SetVar ("ActionLevel", 1)
374 UpdateActionsWindow ()
377 def ActionCastPressed ():
378 GemRB
.SetVar ("TopIndex", 0)
379 GemRB
.SetVar ("ActionLevel", 2)
380 UpdateActionsWindow ()
383 def ActionQItemPressed (action
):
384 pc
= GemRB
.GameGetFirstSelectedPC ()
386 GemRB
.UseItem (pc
, -2, action
)
389 def ActionQItem1Pressed ():
390 ActionQItemPressed (ACT_QSLOT1
)
393 def ActionQItem2Pressed ():
394 ActionQItemPressed (ACT_QSLOT2
)
397 def ActionQItem3Pressed ():
398 ActionQItemPressed (ACT_QSLOT3
)
401 def ActionQItem4Pressed ():
402 ActionQItemPressed (ACT_QSLOT4
)
405 def ActionQItem5Pressed ():
406 ActionQItemPressed (ACT_QSLOT5
)
409 def ActionInnatePressed ():
410 GemRB
.SetVar ("TopIndex", 0)
411 GemRB
.SetVar ("ActionLevel", 3)
412 UpdateActionsWindow ()
416 pc
= GemRB
.GameGetFirstSelectedPC ()
418 GemRB
.GameControlSetTargetMode (TARGET_MODE_CAST
)
419 Spell
= GemRB
.GetVar ("Spell")
420 Type
= GemRB
.GetVar ("Type")
421 GemRB
.SpellCast (pc
, Type
, Spell
)
422 GemRB
.SetVar ("ActionLevel", 0)
423 UpdateActionsWindow ()
426 def EquipmentPressed ():
427 pc
= GemRB
.GameGetFirstSelectedPC ()
429 GemRB
.GameControlSetTargetMode (TARGET_MODE_CAST
)
430 Item
= GemRB
.GetVar ("Equipment")
432 GemRB
.UseItem (pc
, -1, Item
)
433 GemRB
.SetVar ("ActionLevel", 0)
434 UpdateActionsWindow ()
437 SelectionChangeHandler
= None
439 def SetSelectionChangeHandler (handler
):
440 global SelectionChangeHandler
442 # Switching from walking to non-walking environment:
443 # set the first selected PC in walking env as a selected
445 if (not SelectionChangeHandler
) and handler
:
446 sel
= GemRB
.GameGetFirstSelectedPC ()
449 GemRB
.GameSelectPCSingle (sel
)
451 SelectionChangeHandler
= handler
453 # redraw selection on change main selection | single selection
456 def RunSelectionChangeHandler ():
457 if SelectionChangeHandler
:
458 SelectionChangeHandler ()
460 def OpenPortraitWindow (needcontrols
):
461 global PortraitWindow
463 #take care, this window is different in how/iwd
464 if GUICommon
.HasHOW() and needcontrols
:
465 PortraitWindow
= Window
= GemRB
.LoadWindow (26)
467 PortraitWindow
= Window
= GemRB
.LoadWindow (1)
470 if GUICommon
.HasHOW():
472 pos
= GemRB
.GetSystemVariable (SV_HEIGHT
) - 37
473 Window
.CreateButton (8, 6, pos
, 55, 37)
474 Button
= Window
.GetControl (8)
475 Button
.SetSprites ("GUIRSBUT", 0,0,1,0,0)
476 Button
.SetTooltip (11942)
477 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, GUICommon
.RestPress
)
480 Window
.CreateButton (6, 6, pos
, 27, 36)
482 Button
= Window
.GetControl (6)
483 #fixing a gui bug, and while we are at it, hacking it to be easier
484 Button
.SetSprites ("GUIBTACT", 0, 46, 47, 48, 49)
485 GSFlags
= GemRB
.GetMessageWindowSize ()&GS_PARTYAI
487 GemRB
.SetVar ("AI", GSFlags
)
488 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, AIPress
)
489 Button
.SetFlags (IE_GUI_BUTTON_CHECKBOX
, OP_OR
)
490 Button
.SetVarAssoc ("AI", 1)
492 Button
.SetTooltip (15917)
494 Button
.SetTooltip (15918)
497 if GUICommon
.HasHOW():
498 Window
.CreateButton (7, 33, pos
, 27, 36)
499 Button
= Window
.GetControl (7)
500 Button
.SetSprites ("GUIBTACT", 0, 50, 51, 50, 51)
501 Button
.SetTooltip (10485)
502 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, GUICommon
.SelectAllOnPress
)
503 if not GUICommon
.HasHOW():
505 Button
= PortraitWindow
.GetControl (8)
506 Button
.SetTooltip (11942)
507 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, GUICommon
.RestPress
)
509 pc
= GemRB
.GameGetSelectedPCSingle ()
510 Inventory
= GemRB
.GetVar ("Inventory")
512 for i
in range (PARTY_SIZE
):
513 Button
= Window
.GetControl (i
)
514 Button
.SetFont ("STATES")
515 Button
.SetVarAssoc ("PressedPortrait", i
+1)
518 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, GUIINV
.OpenInventoryWindowClick
)
520 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, PortraitButtonOnPress
)
522 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, PortraitButtonOnPress
)
523 Button
.SetEvent (IE_GUI_BUTTON_ON_SHIFT_PRESS
, PortraitButtonOnShiftPress
)
524 Button
.SetEvent (IE_GUI_BUTTON_ON_DRAG_DROP
, GUIINV
.OnDropItemToPC
)
525 Button
.SetEvent (IE_GUI_BUTTON_ON_DRAG_DROP_PORTRAIT
, OnDropPortraitToPC
)
526 Button
.SetEvent (IE_GUI_BUTTON_ON_DRAG
, PortraitButtonOnDrag
)
527 Button
.SetEvent (IE_GUI_MOUSE_ENTER_BUTTON
, PortraitButtonOnMouseEnter
)
528 Button
.SetEvent (IE_GUI_MOUSE_LEAVE_BUTTON
, PortraitButtonOnMouseLeave
)
529 if Inventory
and pc
!= i
+1:
530 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_SET
)
531 Button
.SetState (IE_GUI_BUTTON_DISABLED
)
533 Button
.SetTooltip ("")
535 # overlay a label, so we can display the hp with the correct font
536 Button
.CreateLabelOnButton(100+i
, "NUMFONT", IE_GUI_BUTTON_ALIGN_TOP|IE_GUI_BUTTON_ALIGN_LEFT
)
538 Button
.SetBorder (FRAME_PC_SELECTED
, 1, 1, 2, 2, 0, 255, 0, 255)
539 Button
.SetBorder (FRAME_PC_TARGET
, 3, 3, 4, 4, 255, 255, 0, 255)
541 UpdatePortraitWindow ()
545 def UpdatePortraitWindow ():
546 Window
= PortraitWindow
548 pc
= GemRB
.GameGetSelectedPCSingle ()
549 Inventory
= GemRB
.GetVar ("Inventory")
551 for portid
in range (PARTY_SIZE
):
552 Button
= Window
.GetControl (portid
)
553 pic
= GemRB
.GetPlayerPortrait (portid
+1, 1)
554 if Inventory
and pc
!= portid
+1:
558 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_SET
)
559 Button
.SetState (IE_GUI_BUTTON_DISABLED
)
561 Button
.SetTooltip ("")
564 sel
= GemRB
.GameGetSelectedPCSingle () == portid
+ 1
565 Button
.SetFlags (IE_GUI_BUTTON_PICTURE| \
566 IE_GUI_BUTTON_HORIZONTAL| \
567 IE_GUI_BUTTON_ALIGN_LEFT| IE_GUI_BUTTON_ALIGN_TOP| \
568 IE_GUI_BUTTON_DRAGGABLE|IE_GUI_BUTTON_MULTILINE
, OP_SET
)
569 Button
.SetState (IE_GUI_BUTTON_LOCKED
)
570 Button
.SetPicture (pic
, "NOPORTSM")
572 hp
= GemRB
.GetPlayerStat (portid
+1, IE_HITPOINTS
)
573 hp_max
= GemRB
.GetPlayerStat (portid
+1, IE_MAXHITPOINTS
)
574 state
= GemRB
.GetPlayerStat (portid
+1, IE_STATE_ID
)
579 ratio
= (hp
+0.0) / hp_max
581 if hp
<1 or (state
& STATE_DEAD
):
582 Button
.SetOverlay (0, 64,64,64,200, 64,64,64,200)
584 Button
.SetOverlay (ratio
, 255,0,0,200, 128,0,0,200)
585 ratio_str
= "\n%d/%d" %(hp
, hp_max
)
586 Button
.SetTooltip (GemRB
.GetPlayerName (portid
+1, 1) + ratio_str
)
588 #add effects on the portrait
589 #http://img.jeuxvideo.fr/00002663-photo-icewind-dale-heart-of-winter.jpg
590 effects
= GemRB
.GetPlayerStates (portid
+1)
592 for col
in range(len(effects
)):
593 states
= effects
[col
:col
+1] + states
594 if col
% 3 == 2: states
= "\n" + states
595 for x
in range(2 - (len(effects
)/3)):
596 states
= "\n" + states
597 states
= "\n" + states
600 # TODO: missing, maybe add another string tag to make glyphs 100% transparent?
601 flag
= blank
= chr(238)
603 # these two are missing too
606 #if GemRB.GetStore()!=None:
609 #if GemRB.GameGetSelectedPCSingle(1)==portid+1:
612 if LUCommon
.CanLevelUp (portid
+1):
613 states
= flag
+blank
+chr(255) + states
615 #states = flag+blank+blank + states
616 #states = "\n" + states
618 Button
.SetText(states
)
620 HPLabel
= Window
.GetControl (100+portid
)
621 HPLabel
.SetText (ratio_str
) # TODO: color depending on the ratio
623 #Button.EnableBorder (FRAME_PC_SELECTED, sel)
626 def PortraitButtonOnDrag ():
627 global DraggedPortrait
630 DraggedPortrait
= GemRB
.GetVar ("PressedPortrait")
631 GemRB
.DragItem (DraggedPortrait
, -1, "")
634 def PortraitButtonOnPress ():
635 i
= GemRB
.GetVar ("PressedPortrait")
640 if GemRB
.GameControlGetTargetMode() != TARGET_MODE_NONE
:
644 if (not SelectionChangeHandler
):
645 if GemRB
.GameIsPCSelected (i
):
646 GemRB
.GameControlSetScreenFlags (SF_CENTERONACTOR
, OP_OR
)
647 GemRB
.GameSelectPC (i
, True, SELECT_REPLACE
)
649 GemRB
.GameSelectPCSingle (i
)
651 RunSelectionChangeHandler ()
654 def PortraitButtonOnShiftPress ():
655 i
= GemRB
.GetVar ("PressedPortrait")
660 if (not SelectionChangeHandler
):
661 sel
= GemRB
.GameIsPCSelected (i
)
663 GemRB
.GameSelectPC (i
, sel
)
665 GemRB
.GameSelectPCSingle (i
)
667 RunSelectionChangeHandler ()
670 # Run by Game class when selection was changed
671 def SelectionChanged ():
672 global PortraitWindow
674 if not PortraitWindow
:
677 GemRB
.SetVar ("ActionLevel", 0)
678 # FIXME: hack. If defined, display single selection
679 if (not SelectionChangeHandler
):
680 UpdateActionsWindow ()
681 for i
in range (PARTY_SIZE
):
682 Button
= PortraitWindow
.GetControl (i
)
683 Button
.EnableBorder (FRAME_PC_SELECTED
, GemRB
.GameIsPCSelected (i
+ 1))
685 sel
= GemRB
.GameGetSelectedPCSingle ()
686 for i
in range (PARTY_SIZE
):
687 Button
= PortraitWindow
.GetControl (i
)
688 Button
.EnableBorder (FRAME_PC_SELECTED
, i
+ 1 == sel
)
691 def PortraitButtonOnMouseEnter ():
692 global DraggedPortrait
694 i
= GemRB
.GetVar ("PressedPortrait")
696 GemRB
.GameControlSetLastActor( i
)
697 if GemRB
.IsDraggingItem()==2:
698 if DraggedPortrait
!= None:
699 GemRB
.SwapPCs (DraggedPortrait
, i
)
700 GemRB
.SetVar ("PressedPortrait", DraggedPortrait
)
702 GemRB
.SetTimedEvent (CheckDragging
, 1)
707 if GemRB
.IsDraggingItem ():
708 Button
= PortraitWindow
.GetControl (i
)
709 Button
.EnableBorder (FRAME_PC_TARGET
, 1)
712 def OnDropPortraitToPC ():
713 GemRB
.SetVar ("PressedPortrait",0)
714 GemRB
.DragItem (0, -1, "")
715 DraggedPortrait
= None
719 """Contains portrait dragging in case of mouse out-of-range."""
721 global DraggedPortrait
723 i
= GemRB
.GetVar ("PressedPortrait")
725 GemRB
.DragItem (0, -1, "")
727 if GemRB
.IsDraggingItem()!=2:
728 DraggedPortrait
= None
731 def PortraitButtonOnMouseLeave ():
732 i
= GemRB
.GetVar ("PressedPortrait")
736 Button
= PortraitWindow
.GetControl (i
-1)
737 Button
.EnableBorder (FRAME_PC_TARGET
, 0)
738 GemRB
.SetVar ("PressedPortrait", 0)
739 GemRB
.SetTimedEvent (CheckDragging
, 1)
742 def ActionStopPressed ():
743 for i
in range (PARTY_SIZE
):
744 if GemRB
.GameIsPCSelected (i
+ 1):
745 GemRB
.ClearActions (i
+ 1)
748 def ActionTalkPressed ():
749 GemRB
.GameControlSetTargetMode (TARGET_MODE_TALK
,GA_NO_DEAD|GA_NO_ENEMY|GA_NO_HIDDEN
)
751 def ActionAttackPressed ():
752 GemRB
.GameControlSetTargetMode (TARGET_MODE_ATTACK
,GA_NO_DEAD|GA_NO_SELF|GA_NO_HIDDEN
)
754 def ActionDefendPressed ():
755 GemRB
.GameControlSetTargetMode (TARGET_MODE_DEFEND
,GA_NO_SELF|GA_NO_ENEMY|GA_NO_HIDDEN
)
757 def ActionThievingPressed ():
758 GemRB
.GameControlSetTargetMode (TARGET_MODE_PICK
, GA_NO_DEAD|GA_NO_SELF|GA_NO_ENEMY|GA_NO_HIDDEN
)
760 def CheckLevelUp(pc
):
761 GemRB
.SetVar ("CheckLevelUp"+str(pc
), LUCommon
.CanLevelUp (pc
))