GUIScript: Use None instead if "", for null event handler.
[gemrb.git] / gemrb / GUIScripts / iwd / GUICommonWindows.py
blobdbddb25342ec729a512ecabb3436f7e33c86daeb
1 # -*-python-*-
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 ###################################################
25 import GemRB
26 from GUIDefines import *
27 from ie_stats import *
28 from ie_modal import *
29 from ie_action import *
30 from GUICommon import *
31 from LUCommon import *
33 FRAME_PC_SELECTED = 0
34 FRAME_PC_TARGET = 1
36 PortraitWindow = None
37 OptionsWindow = None
38 ActionsWindow = None
39 DraggedPortrait = None
41 def SetupMenuWindowControls (Window, Gears, ReturnToGame):
42 # FIXME: add "(key)" to tooltips!
44 # Return to Game
45 Button = Window.GetControl (0)
46 Button.SetTooltip (16313)
47 #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
48 Button.SetVarAssoc ("SelectedWindow", 0)
49 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, ReturnToGame)
50 Button.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
52 # Map
53 Button = Window.GetControl (1)
54 Button.SetTooltip (16310)
55 #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
56 Button.SetVarAssoc ("SelectedWindow", 1)
57 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenMapWindow")
59 # Journal
60 Button = Window.GetControl (2)
61 Button.SetTooltip (16308)
62 #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
63 Button.SetVarAssoc ("SelectedWindow", 2)
64 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenJournalWindow")
66 # Inventory
67 Button = Window.GetControl (3)
68 Button.SetTooltip (16307)
69 #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
70 Button.SetVarAssoc ("SelectedWindow", 3)
71 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenInventoryWindow")
73 # Records
74 Button = Window.GetControl (4)
75 Button.SetTooltip (16306)
76 #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
77 Button.SetVarAssoc ("SelectedWindow", 4)
78 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenRecordsWindow")
80 # Mage
81 Button = Window.GetControl (5)
82 Button.SetTooltip (16309)
83 #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
84 Button.SetVarAssoc ("SelectedWindow", 5)
85 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenMageWindow")
86 # Priest
87 Button = Window.GetControl (6)
88 Button.SetTooltip (14930)
89 #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
90 Button.SetVarAssoc ("SelectedWindow", 6)
91 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenPriestWindow")
93 # Options
94 Button = Window.GetControl (7)
95 Button.SetTooltip (16311)
96 #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
97 Button.SetVarAssoc ("SelectedWindow", 7)
98 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenOptionsWindow")
100 # Party mgmt
101 Button = Window.GetControl (8)
102 Button.SetTooltip (16312)
103 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, None)
105 if Gears:
106 # Gears (time), how doesn't have this in the right place
107 if HasHOW():
108 pos = GemRB.GetSystemVariable (SV_HEIGHT)-71
109 Window.CreateButton (9, 6, pos, 64, 71)
110 Button = Window.GetControl (9)
111 Button.SetAnimation ("CGEAR")
112 Button.SetState (IE_GUI_BUTTON_ENABLED)
113 Button.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_ANIMATED|IE_GUI_BUTTON_NORMAL, OP_SET)
114 Button.SetEventByName(IE_GUI_BUTTON_ON_PRESS, "GearsClicked")
115 SetGamedaysAndHourToken()
116 Button.SetTooltip(16041)
118 MarkMenuButton (Window)
119 return
121 def MarkMenuButton (WindowIndex):
122 Pressed = WindowIndex.GetControl( GemRB.GetVar ("SelectedWindow") )
124 for button in range (9):
125 Button = WindowIndex.GetControl (button)
126 Button.SetState (IE_GUI_BUTTON_ENABLED)
128 if Pressed:
129 Button = Pressed
130 else: # highlight return to game
131 Button = WindowIndex.GetControl (0)
133 Button.SetState (IE_GUI_BUTTON_PRESSED)
135 def AIPress ():
136 Button = PortraitWindow.GetControl (6)
137 AI = GemRB.GetMessageWindowSize () & GS_PARTYAI
138 if AI:
139 GemRB.GameSetScreenFlags (GS_PARTYAI, OP_NAND)
140 Button.SetTooltip (15918)
141 else:
142 GemRB.GameSetScreenFlags (GS_PARTYAI, OP_OR)
143 Button.SetTooltip (15917)
144 return
146 def EmptyControls ():
147 global ActionsWindow
149 GemRB.SetVar ("ActionLevel", 0)
150 Window = ActionsWindow
151 for i in range (12):
152 Button = Window.GetControl (i)
153 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
154 Button.SetPicture ("")
155 return
157 def SelectFormationPreset ():
158 GemRB.GameSetFormation (GemRB.GetVar ("Value"), GemRB.GetVar ("Formation") )
159 GroupControls ()
160 return
162 def SetupFormation ():
163 global ActionsWindow
165 Window = ActionsWindow
166 for i in range (12):
167 Button = Window.GetControl (i)
168 Button.SetFlags (IE_GUI_BUTTON_NORMAL, OP_SET)
169 Button.SetSprites ("GUIBTBUT",0,0,1,2,3)
170 Button.SetBAM ("FORM%x"%i,0,0,-1)
171 Button.SetVarAssoc ("Value", i)
172 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "SelectFormationPreset")
173 return
175 def GroupControls ():
176 global ActionsWindow
178 GemRB.SetVar ("ActionLevel", 0)
179 Window = ActionsWindow
180 Button = Window.GetControl (0)
181 Button.SetActionIcon (7)
182 Button = Window.GetControl (1)
183 Button.SetActionIcon (15)
184 Button = Window.GetControl (2)
185 Button.SetActionIcon (21)
186 Button = Window.GetControl (3)
187 Button.SetActionIcon (-1)
188 Button = Window.GetControl (4)
189 Button.SetActionIcon (-1)
190 Button = Window.GetControl (5)
191 Button.SetActionIcon (-1)
192 Button = Window.GetControl (6)
193 Button.SetActionIcon (-1)
194 GemRB.SetVar ("Formation", GemRB.GameGetFormation ())
195 for i in range (5):
196 Button = Window.GetControl (7+i)
197 Button.SetState (IE_GUI_BUTTON_ENABLED)
198 idx = GemRB.GameGetFormation (i)
199 Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON|IE_GUI_BUTTON_NORMAL, OP_SET)
200 Button.SetSprites ("GUIBTBUT",0,i*2,i*2+1,i*2+24,i*2+25)
201 Button.SetBAM ("FORM%x"%idx,0,0,-1)
202 Button.SetVarAssoc ("Formation", i)
203 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "SelectFormation")
204 Button.SetEventByName (IE_GUI_BUTTON_ON_RIGHT_PRESS, "SetupFormation")
205 str = GemRB.GetString (4935)
206 Button.SetTooltip ("F%d - %s"%(8+i,str) )
207 return
209 def OpenActionsWindowControls (Window):
210 global ActionsWindow
212 ActionsWindow = Window
213 UpdateActionsWindow ()
214 return
216 def UpdateActionsWindow ():
217 global ActionsWindow, PortraitWindow, OptionsWindow
219 if ActionsWindow == -1:
220 return
222 if ActionsWindow == None:
223 return
225 #fully redraw the side panes to cover the actions window
226 #do this only when there is no 'otherwindow'
227 if GemRB.GetVar ("OtherWindow") != -1:
228 if PortraitWindow:
229 PortraitWindow.Invalidate ()
230 if OptionsWindow:
231 OptionsWindow.Invalidate ()
233 pc = 0
234 for i in range (PARTY_SIZE):
235 if GemRB.GameIsPCSelected (i+1):
236 if pc == 0:
237 pc = i+1
238 else:
239 pc = -1
240 break
242 for i in range (12):
243 Button = ActionsWindow.GetControl (i)
244 Button.SetBorder (1, 0, 0, 0, 0, 50,30,10,120, 0, 1)
245 Button.SetFont ("NUMBER")
246 Button.SetText ("")
248 if pc == 0:
249 EmptyControls ()
250 return
251 if pc == -1:
252 GroupControls ()
253 return
254 #this is based on class
256 level = GemRB.GetVar ("ActionLevel")
257 TopIndex = GemRB.GetVar ("TopIndex")
258 if level == 0:
259 ActionsWindow.SetupControls (pc)
260 elif level == 1:
261 ActionsWindow.SetupEquipmentIcons(pc, TopIndex)
262 elif level == 2: #spells
263 GemRB.SetVar ("Type", 3)
264 ActionsWindow.SetupSpellIcons(pc, 3, TopIndex)
265 elif level == 3: #innates
266 GemRB.SetVar ("Type", 4)
267 ActionsWindow.SetupSpellIcons(pc, 4, TopIndex)
268 return
270 def ActionQWeaponPressed (which):
271 pc = GemRB.GameGetFirstSelectedPC ()
273 if GemRB.GetEquippedQuickSlot (pc,1)==which and GemRB.GameControlGetTargetMode() != TARGET_MODE_ATTACK:
274 GemRB.GameControlSetTargetMode (TARGET_MODE_ATTACK)
275 else:
276 GemRB.GameControlSetTargetMode (TARGET_MODE_NONE)
277 GemRB.SetEquippedQuickSlot (pc, which)
279 ActionsWindow.SetupControls (pc)
280 UpdateActionsWindow ()
281 return
283 def ActionQWeapon1Pressed ():
284 ActionQWeaponPressed(0)
286 def ActionQWeapon2Pressed ():
287 ActionQWeaponPressed(1)
289 def ActionQWeapon3Pressed ():
290 ActionQWeaponPressed(2)
292 def ActionQWeapon4Pressed ():
293 ActionQWeaponPressed(3)
295 #no check needed because the button wouldn't be drawn if illegal
296 def ActionLeftPressed ():
297 TopIndex = GemRB.GetVar ("TopIndex")
298 if TopIndex>10:
299 TopIndex -= 10
300 else:
301 TopIndex = 0
302 GemRB.SetVar ("TopIndex", TopIndex)
303 UpdateActionsWindow ()
304 return
306 #no check needed because the button wouldn't be drawn if illegal
307 def ActionRightPressed ():
308 pc = GemRB.GameGetFirstSelectedPC ()
309 TopIndex = GemRB.GetVar ("TopIndex")
310 Type = GemRB.GetVar ("Type")
311 Max = GemRB.GetMemorizedSpellsCount(pc, Type)
312 TopIndex += 10
313 if TopIndex > Max - 10:
314 if Max>10:
315 TopIndex = Max-10
316 else:
317 TopIndex = 0
319 GemRB.SetVar ("TopIndex", TopIndex)
320 UpdateActionsWindow ()
321 return
323 def ActionBardSongPressed ():
324 pc = GemRB.GameGetFirstSelectedPC ()
325 GemRB.SetModalState (pc, MS_BATTLESONG)
326 GemRB.PlaySound ("act_01")
327 UpdateActionsWindow ()
328 return
330 def ActionSearchPressed ():
331 pc = GemRB.GameGetFirstSelectedPC ()
332 GemRB.SetModalState (pc, MS_DETECTTRAPS)
333 UpdateActionsWindow ()
334 return
336 def ActionStealthPressed ():
337 pc = GemRB.GameGetFirstSelectedPC ()
338 GemRB.SetModalState (pc, MS_STEALTH)
339 GemRB.PlaySound ("act_07")
340 UpdateActionsWindow ()
341 return
343 def ActionTurnPressed ():
344 pc = GemRB.GameGetFirstSelectedPC ()
345 GemRB.SetModalState (pc, MS_TURNUNDEAD)
346 GemRB.PlaySound ("act_06")
347 UpdateActionsWindow ()
348 return
350 def ActionUseItemPressed ():
351 GemRB.SetVar ("TopIndex", 0)
352 GemRB.SetVar ("ActionLevel", 1)
353 UpdateActionsWindow ()
354 return
356 def ActionCastPressed ():
357 GemRB.SetVar ("TopIndex", 0)
358 GemRB.SetVar ("ActionLevel", 2)
359 UpdateActionsWindow ()
360 return
362 def ActionInnatePressed ():
363 GemRB.SetVar ("TopIndex", 0)
364 GemRB.SetVar ("ActionLevel", 3)
365 UpdateActionsWindow ()
366 return
368 def SpellPressed ():
369 pc = GemRB.GameGetFirstSelectedPC ()
371 GemRB.GameControlSetTargetMode (TARGET_MODE_CAST)
372 Spell = GemRB.GetVar ("Spell")
373 Type = GemRB.GetVar ("Type")
374 GemRB.SpellCast (pc, Type, Spell)
375 GemRB.SetVar ("ActionLevel", 0)
376 UpdateActionsWindow ()
377 return
379 def EquipmentPressed ():
380 pc = GemRB.GameGetFirstSelectedPC ()
382 GemRB.GameControlSetTargetMode (TARGET_MODE_CAST)
383 Item = GemRB.GetVar ("Equipment")
384 #equipment index
385 GemRB.UseItem (pc, -1, Item)
386 GemRB.SetVar ("ActionLevel", 0)
387 UpdateActionsWindow ()
388 return
390 SelectionChangeHandler = None
392 def SetSelectionChangeHandler (handler):
393 global SelectionChangeHandler
395 # Switching from walking to non-walking environment:
396 # set the first selected PC in walking env as a selected
397 # in nonwalking env
398 if (not SelectionChangeHandler) and handler:
399 sel = GemRB.GameGetFirstSelectedPC ()
400 if not sel:
401 sel = 1
402 GemRB.GameSelectPCSingle (sel)
404 SelectionChangeHandler = handler
406 # redraw selection on change main selection | single selection
407 SelectionChanged ()
409 def RunSelectionChangeHandler ():
410 if SelectionChangeHandler:
411 SelectionChangeHandler ()
413 def OpenPortraitWindow (needcontrols):
414 global PortraitWindow
416 #take care, this window is different in how/iwd
417 if HasHOW() and needcontrols:
418 PortraitWindow = Window = GemRB.LoadWindow (26)
419 else:
420 PortraitWindow = Window = GemRB.LoadWindow (1)
422 if needcontrols:
423 if HasHOW():
424 # Rest (how)
425 pos = GemRB.GetSystemVariable (SV_HEIGHT) - 37
426 Window.CreateButton (8, 6, pos, 55, 37)
427 Button = Window.GetControl (8)
428 Button.SetSprites ("GUIRSBUT", 0,0,1,0,0)
429 Button.SetTooltip (11942)
430 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "RestPress")
432 pos = pos - 37
433 Window.CreateButton (6, 6, pos, 27, 36)
434 # AI
435 Button = Window.GetControl (6)
436 #fixing a gui bug, and while we are at it, hacking it to be easier
437 Button.SetSprites ("GUIBTACT", 0, 46, 47, 48, 49)
438 GSFlags = GemRB.GetMessageWindowSize ()&GS_PARTYAI
440 GemRB.SetVar ("AI", GSFlags)
441 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "AIPress")
442 Button.SetFlags (IE_GUI_BUTTON_CHECKBOX, OP_OR)
443 Button.SetVarAssoc ("AI", 1)
444 if GSFlags:
445 Button.SetTooltip (15917)
446 else:
447 Button.SetTooltip (15918)
449 #Select All
450 if HasHOW():
451 Window.CreateButton (7, 33, pos, 27, 36)
452 Button = Window.GetControl (7)
453 Button.SetSprites ("GUIBTACT", 0, 50, 51, 50, 51)
454 Button.SetTooltip (10485)
455 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "SelectAllOnPress")
456 if not HasHOW():
457 # Rest (iwd)
458 Button = PortraitWindow.GetControl (8)
459 Button.SetTooltip (11942)
460 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "RestPress")
462 pc = GemRB.GameGetSelectedPCSingle ()
463 Inventory = GemRB.GetVar ("Inventory")
465 for i in range (PARTY_SIZE):
466 Button = Window.GetControl (i)
467 Button.SetFont ("STATES")
468 Button.SetVarAssoc ("PressedPortrait", i)
470 if (needcontrols):
471 Button.SetEventByName (IE_GUI_BUTTON_ON_RIGHT_PRESS, "OpenInventoryWindowClick")
472 else:
473 Button.SetEventByName (IE_GUI_BUTTON_ON_RIGHT_PRESS, "PortraitButtonOnPress")
475 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "PortraitButtonOnPress")
476 Button.SetEventByName (IE_GUI_BUTTON_ON_SHIFT_PRESS, "PortraitButtonOnShiftPress")
477 Button.SetEventByName (IE_GUI_BUTTON_ON_DRAG_DROP, "OnDropItemToPC")
478 Button.SetEventByName (IE_GUI_BUTTON_ON_DRAG, "PortraitButtonOnDrag")
479 Button.SetEventByName (IE_GUI_MOUSE_ENTER_BUTTON, "PortraitButtonOnMouseEnter")
480 Button.SetEventByName (IE_GUI_MOUSE_LEAVE_BUTTON, "PortraitButtonOnMouseLeave")
481 if Inventory and pc != i+1:
482 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
483 Button.SetState (IE_GUI_BUTTON_DISABLED)
484 Button.SetText ("")
485 Button.SetTooltip ("")
487 # overlay a label, so we can display the hp with the correct font
488 Button.CreateLabelOnButton(100+i, "NUMFONT", IE_GUI_BUTTON_ALIGN_TOP|IE_GUI_BUTTON_ALIGN_LEFT)
490 Button.SetBorder (FRAME_PC_SELECTED, 1, 1, 2, 2, 0, 255, 0, 255)
491 Button.SetBorder (FRAME_PC_TARGET, 3, 3, 4, 4, 255, 255, 0, 255)
493 UpdatePortraitWindow ()
494 SelectionChanged ()
495 return Window
497 def UpdatePortraitWindow ():
498 Window = PortraitWindow
500 pc = GemRB.GameGetSelectedPCSingle ()
501 Inventory = GemRB.GetVar ("Inventory")
503 for portid in range (PARTY_SIZE):
504 Button = Window.GetControl (portid)
505 pic = GemRB.GetPlayerPortrait (portid+1, 1)
506 if Inventory and pc != portid+1:
507 pic = None
509 if not pic:
510 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
511 Button.SetState (IE_GUI_BUTTON_DISABLED)
512 Button.SetText ("")
513 Button.SetTooltip ("")
514 continue
516 sel = GemRB.GameGetSelectedPCSingle () == portid + 1
517 Button.SetFlags (IE_GUI_BUTTON_PICTURE| \
518 IE_GUI_BUTTON_HORIZONTAL| \
519 IE_GUI_BUTTON_ALIGN_LEFT| IE_GUI_BUTTON_ALIGN_TOP| \
520 IE_GUI_BUTTON_DRAGGABLE|IE_GUI_BUTTON_MULTILINE, OP_SET)
521 Button.SetState (IE_GUI_BUTTON_LOCKED)
522 Button.SetPicture (pic, "NOPORTSM")
524 hp = GemRB.GetPlayerStat (portid+1, IE_HITPOINTS)
525 hp_max = GemRB.GetPlayerStat (portid+1, IE_MAXHITPOINTS)
526 state = GemRB.GetPlayerStat (portid+1, IE_STATE_ID)
528 if (hp_max<1):
529 ratio = 0.0
530 else:
531 ratio = (hp+0.0) / hp_max
533 if hp<1 or (state & STATE_DEAD):
534 Button.SetOverlay (0, 64,64,64,200, 64,64,64,200)
535 else:
536 Button.SetOverlay (ratio, 255,0,0,200, 128,0,0,200)
537 ratio_str = "\n%d/%d" %(hp, hp_max)
538 Button.SetTooltip (GemRB.GetPlayerName (portid+1, 1) + ratio_str)
540 #add effects on the portrait
541 #http://img.jeuxvideo.fr/00002663-photo-icewind-dale-heart-of-winter.jpg
542 effects = GemRB.GetPlayerStates (portid+1)
543 states = ""
544 for col in range(len(effects)):
545 states = effects[col:col+1] + states
546 if col % 3 == 2: states = "\n" + states
547 for x in range(2 - (len(effects)/3)):
548 states = "\n" + states
549 states = "\n" + states
551 # blank space
552 # TODO: missing, maybe add another string tag to make glyphs 100% transparent?
553 flag = blank = chr(238)
555 # these two are missing too
556 ## shopping icon
557 #if pc==portid+1:
558 #if GemRB.GetStore()!=None:
559 #flag = chr(155)
560 ## talk icon
561 #if GemRB.GameGetSelectedPCSingle(1)==portid+1:
562 #flag = chr(154)
564 if CanLevelUp (portid+1):
565 states = flag+blank+chr(255) + states
566 else:
567 #states = flag+blank+blank + states
568 #states = "\n" + states
569 pass
570 Button.SetText(states)
572 HPLabel = Window.GetControl (100+portid)
573 HPLabel.SetText (ratio_str) # TODO: color depending on the ratio
575 Button.EnableBorder (FRAME_PC_SELECTED, sel)
576 return
578 def PortraitButtonOnDrag ():
579 global DraggedPortrait
581 #they start from 1
582 DraggedPortrait = GemRB.GetVar ("PressedPortrait")+1
583 GemRB.DragItem (DraggedPortrait, -1, "")
584 return
586 def PortraitButtonOnPress ():
587 i = GemRB.GetVar ("PressedPortrait")
589 if (not SelectionChangeHandler):
590 if GemRB.GameIsPCSelected (i+1):
591 GemRB.GameControlSetScreenFlags (SF_CENTERONACTOR, OP_OR)
592 GemRB.GameSelectPC (i + 1, True, SELECT_REPLACE)
593 else:
594 GemRB.GameSelectPCSingle (i + 1)
595 SelectionChanged ()
596 RunSelectionChangeHandler ()
597 return
599 def PortraitButtonOnShiftPress ():
600 i = GemRB.GetVar ("PressedPortrait")
602 if (not SelectionChangeHandler):
603 sel = GemRB.GameIsPCSelected (i + 1)
604 sel = not sel
605 GemRB.GameSelectPC (i + 1, sel)
606 else:
607 GemRB.GameSelectPCSingle (i + 1)
608 SelectionChanged ()
609 RunSelectionChangeHandler ()
610 return
612 # Run by Game class when selection was changed
613 def SelectionChanged ():
614 global PortraitWindow
616 GemRB.SetVar ("ActionLevel", 0)
617 # FIXME: hack. If defined, display single selection
618 if (not SelectionChangeHandler):
619 UpdateActionsWindow ()
620 for i in range (PARTY_SIZE):
621 Button = PortraitWindow.GetControl (i)
622 Button.EnableBorder (FRAME_PC_SELECTED, GemRB.GameIsPCSelected (i + 1))
623 else:
624 sel = GemRB.GameGetSelectedPCSingle ()
625 for i in range (PARTY_SIZE):
626 Button = PortraitWindow.GetControl (i)
627 Button.EnableBorder (FRAME_PC_SELECTED, i + 1 == sel)
628 return
630 def PortraitButtonOnMouseEnter ():
631 global DraggedPortrait
633 i = GemRB.GetVar ("PressedPortrait")
635 if DraggedPortrait != None:
636 GemRB.DragItem (0, -1, "")
637 #this might not work
638 GemRB.SwapPCs (DraggedPortrait, i+1)
639 DraggedPortrait = None
640 return
642 if GemRB.IsDraggingItem ():
643 Button = PortraitWindow.GetControl (i)
644 Button.EnableBorder (FRAME_PC_TARGET, 1)
645 return
647 def PortraitButtonOnMouseLeave ():
648 i = GemRB.GetVar ("PressedPortrait")
649 Button = PortraitWindow.GetControl (i)
650 Button.EnableBorder (FRAME_PC_TARGET, 0)
651 return
653 def CheckLevelUp(pc):
654 GemRB.SetVar ("CheckLevelUp"+str(pc), CanLevelUp (pc))