Button: Add separate event handler for dropping portraits.
[gemrb.git] / gemrb / GUIScripts / bg2 / GUICommonWindows.py
blobc39da7a3430fa03a9d4689fa0272b3ed300dded2
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 math import ceil
27 from GUIDefines import *
28 from ie_stats import *
29 from ie_modal import *
30 from ie_action import *
31 from ie_slots import *
32 from GUICommon import *
33 from LUCommon import *
35 FRAME_PC_SELECTED = 0
36 FRAME_PC_TARGET = 1
38 PortraitWindow = None
39 OptionsWindow = None
40 ActionsWindow = None
41 DraggedPortrait = None
43 def SetupMenuWindowControls (Window, Gears, ReturnToGame):
44 """Sets up all of the basic control windows."""
46 global OptionsWindow
48 OptionsWindow = Window
49 # Return to Game
50 Button = Window.GetControl (0)
51 Button.SetTooltip (16313)
52 Button.SetVarAssoc ("SelectedWindow", 0)
53 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, ReturnToGame)
54 Button.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
56 # Map
57 Button = Window.GetControl (1)
58 Button.SetTooltip (16310)
59 Button.SetVarAssoc ("SelectedWindow", 1)
60 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "OpenMapWindow")
62 # Journal
63 Button = Window.GetControl (2)
64 Button.SetTooltip (16308)
65 Button.SetVarAssoc ("SelectedWindow", 2)
66 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "OpenJournalWindow")
68 # Inventory
69 Button = Window.GetControl (3)
70 Button.SetTooltip (16307)
71 Button.SetVarAssoc ("SelectedWindow", 3)
72 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "OpenInventoryWindow")
74 # Records
75 Button = Window.GetControl (4)
76 Button.SetTooltip (16306)
77 Button.SetVarAssoc ("SelectedWindow", 4)
78 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "OpenRecordsWindow")
80 # Mage
81 Button = Window.GetControl (5)
82 Button.SetTooltip (16309)
83 Button.SetVarAssoc ("SelectedWindow", 5)
84 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "OpenMageWindow")
86 # Priest
87 Button = Window.GetControl (6)
88 Button.SetTooltip (14930)
89 Button.SetVarAssoc ("SelectedWindow", 6)
90 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "OpenPriestWindow")
92 # Options
93 Button = Window.GetControl (7)
94 Button.SetTooltip (16311)
95 Button.SetVarAssoc ("SelectedWindow", 7)
96 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "OpenOptionsWindow")
98 # Multi player team setup?
99 Button = Window.GetControl (8)
100 Button.SetTooltip (13902)
102 if Gears:
103 # Pendulum, gears, sun/moon dial (time)
104 # FIXME: display all animations: CPEN, CGEAR, CDIAL
105 Button = Window.GetControl (9)
106 Label = Button.CreateLabelOnButton (0x10000009, "NORMAL", 0)
108 Label.SetAnimation ("CPEN")
109 Button.SetAnimation ("CGEAR")
110 Button.SetBAM ("CDIAL", 0, 0)
111 Button.SetState (IE_GUI_BUTTON_ENABLED)
112 Button.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_ANIMATED|IE_GUI_BUTTON_NORMAL, OP_SET)
113 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, "GearsClicked")
114 SetGamedaysAndHourToken()
115 Button.SetTooltip(16041)
116 rb = 11
117 else:
118 rb = 9
120 # Rest
121 Button = Window.GetControl (rb)
122 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "RestPress")
123 Button.SetTooltip (11942)
125 if PortraitWindow:
126 UpdatePortraitWindow ()
128 def MarkMenuButton (WindowIndex):
129 Pressed = WindowIndex.GetControl( GemRB.GetVar ("SelectedWindow") )
131 for button in range (9):
132 Button = WindowIndex.GetControl (button)
133 Button.SetState (IE_GUI_BUTTON_ENABLED)
135 if Pressed: # don't draw the selection when returning to the game
136 Pressed.SetState (IE_GUI_BUTTON_SELECTED)
138 def AIPress ():
139 """Toggles the party AI."""
141 Button = PortraitWindow.GetControl (6)
142 AI = GemRB.GetMessageWindowSize () & GS_PARTYAI
144 if AI:
145 GemRB.GameSetScreenFlags (GS_PARTYAI, OP_NAND)
146 Button.SetTooltip (15918)
147 GemRB.SetVar ("AI", 0)
148 else:
149 GemRB.GameSetScreenFlags (GS_PARTYAI, OP_OR)
150 Button.SetTooltip (15917)
151 GemRB.SetVar ("AI", GS_PARTYAI)
152 return
154 def EmptyControls ():
155 global ActionsWindow
157 GemRB.SetVar ("ActionLevel", 0)
158 Window = ActionsWindow
159 for i in range (12):
160 Button = Window.GetControl (i)
161 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
162 Button.SetPicture ("")
163 return
165 def SelectFormationPreset ():
166 """Choose the default formation."""
167 GemRB.GameSetFormation (GemRB.GetVar ("Value"), GemRB.GetVar ("Formation") )
168 GroupControls ()
169 return
171 def SetupFormation ():
172 """Opens the formation selection section."""
173 global ActionsWindow
175 Window = ActionsWindow
176 for i in range (12):
177 Button = Window.GetControl (i)
178 Button.SetFlags (IE_GUI_BUTTON_NORMAL, OP_SET)
179 Button.SetSprites ("GUIBTBUT",0,0,1,2,3)
180 Button.SetBAM ("FORM%x"%i,0,0,-1)
181 Button.SetVarAssoc ("Value", i)
182 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "SelectFormationPreset")
183 return
185 def GroupControls ():
186 """Sections that control group actions."""
188 global ActionsWindow
190 GemRB.SetVar ("ActionLevel", 0)
191 Window = ActionsWindow
192 Button = Window.GetControl (0)
193 Button.SetActionIcon (7)
194 Button = Window.GetControl (1)
195 Button.SetActionIcon (15)
196 Button = Window.GetControl (2)
197 Button.SetActionIcon (21)
198 Button = Window.GetControl (3)
199 Button.SetActionIcon (-1)
200 Button = Window.GetControl (4)
201 Button.SetActionIcon (-1)
202 Button = Window.GetControl (5)
203 Button.SetActionIcon (-1)
204 Button = Window.GetControl (6)
205 Button.SetActionIcon (-1)
206 GemRB.SetVar ("Formation", GemRB.GameGetFormation ())
207 for i in range (5):
208 Button = Window.GetControl (7+i)
209 Button.SetState (IE_GUI_BUTTON_ENABLED)
210 idx = GemRB.GameGetFormation (i)
211 Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON|IE_GUI_BUTTON_NORMAL, OP_SET)
212 Button.SetSprites ("GUIBTBUT",0,0,1,2,3)
213 Button.SetBAM ("FORM%x"%idx,0,0,-1)
214 Button.SetVarAssoc ("Formation", i)
215 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "SelectFormation")
216 Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, "SetupFormation")
217 str = GemRB.GetString (4935)
218 Button.SetTooltip ("F%d - %s"%(8+i,str) )
219 return
221 def OpenActionsWindowControls (Window):
222 global ActionsWindow
224 ActionsWindow = Window
225 # Gears (time) when options pane is down
226 Button = Window.GetControl (62)
227 Label = Button.CreateLabelOnButton (0x1000003e, "NORMAL", 0)
229 # FIXME: display all animations
230 Label.SetAnimation ("CPEN")
231 Button.SetAnimation ("CGEAR")
232 Button.SetBAM ("CDIAL", 0, 0)
233 Button.SetState (IE_GUI_BUTTON_ENABLED)
234 Button.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_ANIMATED|IE_GUI_BUTTON_NORMAL, OP_SET)
235 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, "GearsClicked")
236 SetGamedaysAndHourToken()
237 Button.SetTooltip(16041)
238 UpdateActionsWindow ()
239 return
241 def UpdateActionsWindow ():
242 """Redraws the actions section of the window."""
244 global ActionsWindow, PortraitWindow, OptionsWindow
245 global level, TopIndex
247 if ActionsWindow == -1:
248 return
250 if ActionsWindow == None:
251 return
253 #fully redraw the side panes to cover the actions window
254 #do this only when there is no 'otherwindow'
255 if GemRB.GetVar ("OtherWindow") == -1:
256 if PortraitWindow:
257 PortraitWindow.Invalidate ()
258 if OptionsWindow:
259 OptionsWindow.Invalidate ()
261 Selected = GemRB.GetSelectedSize()
263 #setting up the disabled button overlay (using the second border slot)
264 for i in range (12):
265 Button = ActionsWindow.GetControl (i)
266 Button.SetBorder (1, 0, 0, 0, 0, 50,30,10,120, 0, 1)
267 Button.SetFont ("NUMBER")
268 Button.SetText ("")
270 if Selected == 0:
271 EmptyControls ()
272 return
273 if Selected > 1:
274 GroupControls ()
275 return
276 #this is based on class
277 #we are sure there is only one actor selected
278 pc = 0
279 for i in range (PARTY_SIZE):
280 if GemRB.GameIsPCSelected (i+1):
281 pc = i+1
282 break
284 if pc == 0:
285 #summoned/charmed creature.
286 #TODO: some creatures have real actions window!!
287 GroupControls()
288 return
290 level = GemRB.GetVar ("ActionLevel")
291 TopIndex = GemRB.GetVar ("TopIndex")
292 if level == 0:
293 ActionsWindow.SetupControls (pc)
294 elif level == 1:
295 ActionsWindow.SetupEquipmentIcons(pc, TopIndex)
296 elif level == 2: #spells
297 GemRB.SetVar ("Type", 3)
298 ActionsWindow.SetupSpellIcons(pc, 3, TopIndex)
299 elif level == 3: #innates
300 GemRB.SetVar ("Type", 4)
301 ActionsWindow.SetupSpellIcons(pc, 4, TopIndex)
302 return
304 def ActionQWeaponPressed (which):
305 """Selects the given quickslot weapon if possible."""
307 pc = GemRB.GameGetFirstSelectedPC ()
308 qs = GemRB.GetEquippedQuickSlot (pc,1)
310 #38 is the magic slot
311 if ((qs==which) or (qs==38)) and GemRB.GameControlGetTargetMode() != TARGET_MODE_ATTACK:
312 GemRB.GameControlSetTargetMode (TARGET_MODE_ATTACK, GA_NO_DEAD|GA_NO_SELF|GA_NO_HIDDEN)
313 else:
314 GemRB.GameControlSetTargetMode (TARGET_MODE_NONE)
315 GemRB.SetEquippedQuickSlot (pc, which)
317 ActionsWindow.SetupControls (pc)
318 UpdateActionsWindow ()
319 return
321 def ActionQWeapon1Pressed ():
322 ActionQWeaponPressed(0)
324 def ActionQWeapon2Pressed ():
325 ActionQWeaponPressed(1)
327 def ActionQWeapon3Pressed ():
328 ActionQWeaponPressed(2)
330 def ActionQWeapon4Pressed ():
331 ActionQWeaponPressed(3)
333 #no check needed because the button wouldn't be drawn if illegal
334 def ActionLeftPressed ():
335 """Scrolls the actions window left.
337 Used primarily for spell selection."""
339 TopIndex = GemRB.GetVar ("TopIndex")
340 if TopIndex>10:
341 TopIndex -= 10
342 else:
343 TopIndex = 0
344 GemRB.SetVar ("TopIndex", TopIndex)
345 UpdateActionsWindow ()
346 return
348 #no check needed because the button wouldn't be drawn if illegal
349 def ActionRightPressed ():
350 """Scrolls the action window right.
352 Used primarily for spell selection."""
354 pc = GemRB.GameGetFirstSelectedPC ()
355 TopIndex = GemRB.GetVar ("TopIndex")
356 Type = GemRB.GetVar ("Type")
357 #Type is a bitfield if there is no level given
358 #This is to make sure cleric/mages get all spells listed
359 Max = GemRB.GetMemorizedSpellsCount(pc, Type)
360 TopIndex += 10
361 if TopIndex > Max - 10:
362 if Max>10:
363 TopIndex = Max-10
364 else:
365 TopIndex = 0
366 GemRB.SetVar ("TopIndex", TopIndex)
367 UpdateActionsWindow ()
368 return
370 def ActionBardSongPressed ():
371 """Toggles the battle song."""
372 pc = GemRB.GameGetFirstSelectedPC ()
373 GemRB.SetModalState (pc, MS_BATTLESONG)
374 GemRB.PlaySound ("act_01")
375 UpdateActionsWindow ()
376 return
378 def ActionSearchPressed ():
379 """Toggles detect traps."""
380 pc = GemRB.GameGetFirstSelectedPC ()
381 GemRB.SetModalState (pc, MS_DETECTTRAPS)
382 UpdateActionsWindow ()
383 return
385 def ActionStealthPressed ():
386 """Toggles stealth."""
387 pc = GemRB.GameGetFirstSelectedPC ()
388 GemRB.SetModalState (pc, MS_STEALTH)
389 GemRB.PlaySound ("act_07")
390 UpdateActionsWindow ()
391 return
393 def ActionTurnPressed ():
394 """Toggles turn undead."""
395 pc = GemRB.GameGetFirstSelectedPC ()
396 GemRB.SetModalState (pc, MS_TURNUNDEAD)
397 GemRB.PlaySound ("act_06")
398 UpdateActionsWindow ()
399 return
401 def ActionUseItemPressed ():
402 GemRB.SetVar ("TopIndex", 0)
403 GemRB.SetVar ("ActionLevel", 1)
404 UpdateActionsWindow ()
405 return
407 def ActionCastPressed ():
408 """Opens the spell choice scrollbar."""
409 GemRB.SetVar ("TopIndex", 0)
410 GemRB.SetVar ("ActionLevel", 2)
411 UpdateActionsWindow ()
412 return
414 def ActionInnatePressed ():
415 """Opens the innate spell scrollbar."""
416 GemRB.SetVar ("TopIndex", 0)
417 GemRB.SetVar ("ActionLevel", 3)
418 UpdateActionsWindow ()
419 return
421 def SpellPressed ():
422 """Prepares a spell to be cast."""
424 pc = GemRB.GameGetFirstSelectedPC ()
426 GemRB.GameControlSetTargetMode (TARGET_MODE_CAST)
427 Spell = GemRB.GetVar ("Spell")
428 Type = GemRB.GetVar ("Type")
429 GemRB.SpellCast (pc, Type, Spell)
430 GemRB.SetVar ("ActionLevel", 0)
431 UpdateActionsWindow ()
432 return
434 def EquipmentPressed ():
435 pc = GemRB.GameGetFirstSelectedPC ()
437 GemRB.GameControlSetTargetMode (TARGET_MODE_CAST)
438 Item = GemRB.GetVar ("Equipment")
439 #equipment index
440 GemRB.UseItem (pc, -1, Item)
441 GemRB.SetVar ("ActionLevel", 0)
442 UpdateActionsWindow ()
443 return
445 SelectionChangeHandler = None
447 def SetSelectionChangeHandler (handler):
448 """Updates the selection handler."""
450 global SelectionChangeHandler
452 # Switching from walking to non-walking environment:
453 # set the first selected PC in walking env as a selected
454 # in nonwalking env
455 if (not SelectionChangeHandler) and handler:
456 sel = GemRB.GameGetFirstSelectedPC ()
457 if not sel:
458 sel = 1
459 GemRB.GameSelectPCSingle (sel)
461 SelectionChangeHandler = handler
463 # redraw selection on change main selection | single selection
464 SelectionChanged ()
465 return
467 def RunSelectionChangeHandler ():
468 if SelectionChangeHandler:
469 SelectionChangeHandler ()
470 return
472 def OpenPortraitWindow (needcontrols):
473 global PortraitWindow
475 PortraitWindow = Window = GemRB.LoadWindowObject (1)
477 if needcontrols:
478 Button=Window.GetControl (8)
479 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "MinimizePortraits")
481 # AI
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, 48, 47, 46, 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)
491 if GSFlags:
492 Button.SetTooltip (15917)
493 else:
494 Button.SetTooltip (15918)
496 #Select All
497 Button = Window.GetControl (7)
498 Button.SetTooltip (10485)
499 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "SelectAllOnPress")
501 for i in range (PARTY_SIZE):
502 Button = Window.GetControl (i)
503 Button.SetFont ("STATES2")
504 Button.SetVarAssoc ("PressedPortrait", i+1)
506 if (needcontrols):
507 Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, "OpenInventoryWindowClick")
508 else:
509 Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, "PortraitButtonOnPress")
511 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "PortraitButtonOnPress")
512 Button.SetEvent (IE_GUI_BUTTON_ON_SHIFT_PRESS, "PortraitButtonOnShiftPress")
513 Button.SetEvent (IE_GUI_BUTTON_ON_DRAG_DROP, "OnDropItemToPC")
514 Button.SetEvent (IE_GUI_BUTTON_ON_DRAG_DROP_PORTRAIT, "OnDropPortraitToPC")
515 Button.SetEvent (IE_GUI_BUTTON_ON_DRAG, "PortraitButtonOnDrag")
516 Button.SetEvent (IE_GUI_MOUSE_ENTER_BUTTON, "PortraitButtonOnMouseEnter")
517 Button.SetEvent (IE_GUI_MOUSE_LEAVE_BUTTON, "PortraitButtonOnMouseLeave")
519 Button.SetBorder (FRAME_PC_SELECTED, 1, 1, 2, 2, 0, 255, 0, 255)
520 Button.SetBorder (FRAME_PC_TARGET, 3, 3, 4, 4, 255, 255, 0, 255)
522 UpdatePortraitWindow ()
523 SelectionChanged ()
524 return Window
526 def UpdatePortraitWindow ():
527 """Updates all of the portraits."""
529 Window = PortraitWindow
531 pc = GemRB.GameGetSelectedPCSingle ()
532 Inventory = GemRB.GetVar ("Inventory")
534 for portid in range (PARTY_SIZE):
535 Button = Window.GetControl (portid)
536 pic = GemRB.GetPlayerPortrait (portid+1, 1)
537 if Inventory and pc != portid+1:
538 pic = None
540 if not pic:
541 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
542 Button.SetState (IE_GUI_BUTTON_DISABLED)
543 Button.SetText ("")
544 Button.SetTooltip ("")
545 continue
547 Button.SetFlags (IE_GUI_BUTTON_PICTURE| \
548 IE_GUI_BUTTON_HORIZONTAL| \
549 IE_GUI_BUTTON_ALIGN_LEFT| IE_GUI_BUTTON_ALIGN_TOP| \
550 IE_GUI_BUTTON_DRAGGABLE|IE_GUI_BUTTON_MULTILINE, OP_SET)
551 Button.SetState (IE_GUI_BUTTON_LOCKED)
552 Button.SetPicture (pic, "NOPORTSM")
553 hp = GemRB.GetPlayerStat (portid+1, IE_HITPOINTS)
554 hp_max = GemRB.GetPlayerStat (portid+1, IE_MAXHITPOINTS)
555 state = GemRB.GetPlayerStat (portid+1, IE_STATE_ID)
557 if (hp_max<1):
558 ratio = 0.0
559 else:
560 ratio = (hp+0.0) / hp_max
562 if hp<1 or (state & STATE_DEAD):
563 Button.SetOverlay (0, 64,64,64,200, 64,64,64,200)
564 else:
565 Button.SetOverlay (ratio, 255,0,0,200, 128,0,0,200)
566 Button.SetTooltip (GemRB.GetPlayerName (portid+1, 1) + "\n%d/%d" %(hp, hp_max))
568 #add effects on the portrait
569 effects = GemRB.GetPlayerStates (portid+1)
570 states = ""
571 for col in range(len(effects)):
572 states = effects[col:col+1] + states
573 if col % 3 == 2: states = "\n" + states
574 for x in range(3 - (len(effects)/3)):
575 states = "\n" + states
576 states = "\n" + states
578 # blank space
579 flag = blank = chr(238)
581 # shopping icon
582 if pc==portid+1:
583 if GemRB.GetStore()!=None:
584 flag = chr(155)
585 # talk icon
586 if GemRB.GameGetSelectedPCSingle(1)==portid+1:
587 flag = chr(154)
589 if CanLevelUp (portid+1):
590 states = flag+blank+chr(255) + states
591 else:
592 states = flag+blank+blank + states
593 Button.SetText(states)
594 return
596 def PortraitButtonOnDrag ():
597 global DraggedPortrait
599 #they start from 1
600 DraggedPortrait = GemRB.GetVar ("PressedPortrait")
601 GemRB.DragItem (DraggedPortrait, -1, "")
602 return
604 def PortraitButtonOnPress ():
605 """Selects the portrait individually."""
607 i = GemRB.GetVar ("PressedPortrait")
609 if not i:
610 return
612 if GemRB.GameControlGetTargetMode() != TARGET_MODE_NONE:
613 GemRB.ActOnPC (i)
614 return
616 if (not SelectionChangeHandler):
617 if GemRB.GameIsPCSelected (i):
618 GemRB.GameControlSetScreenFlags (SF_CENTERONACTOR, OP_OR)
619 GemRB.GameSelectPC (i, True, SELECT_REPLACE)
620 else:
621 GemRB.GameSelectPCSingle (i)
622 SelectionChanged ()
623 RunSelectionChangeHandler ()
624 return
626 def PortraitButtonOnShiftPress ():
627 """Handles selecting multiple portaits with shift."""
629 i = GemRB.GetVar ("PressedPortrait")
631 if not i:
632 return
634 if (not SelectionChangeHandler):
635 sel = GemRB.GameIsPCSelected (i)
636 sel = not sel
637 GemRB.GameSelectPC (i, sel)
638 else:
639 GemRB.GameSelectPCSingle (i)
640 SelectionChanged ()
641 RunSelectionChangeHandler ()
642 return
644 def SelectionChanged ():
645 """Ran by the Game class when a PC selection is changed."""
647 global PortraitWindow
649 GemRB.SetVar ("ActionLevel", 0)
650 if (not SelectionChangeHandler):
651 UpdateActionsWindow ()
652 for i in range (PARTY_SIZE):
653 Button = PortraitWindow.GetControl (i)
654 Button.EnableBorder (FRAME_PC_SELECTED, GemRB.GameIsPCSelected (i + 1))
655 else:
656 sel = GemRB.GameGetSelectedPCSingle ()
658 #update mage school
659 GemRB.SetVar ("MAGESCHOOL", 0)
660 Kit = GetKitIndex (sel)
661 if Kit and KitListTable.GetValue (Kit, 7) == 1:
662 MageTable = GemRB.LoadTableObject ("magesch")
663 GemRB.SetVar ("MAGESCHOOL", MageTable.FindValue (3, KitListTable.GetValue (Kit, 6) ) )
665 for i in range (PARTY_SIZE):
666 Button = PortraitWindow.GetControl (i)
667 Button.EnableBorder (FRAME_PC_SELECTED, i + 1 == sel)
668 return
670 def PortraitButtonOnMouseEnter ():
671 global DraggedPortrait
673 i = GemRB.GetVar ("PressedPortrait")
674 if GemRB.IsDraggingItem()==2:
675 if DraggedPortrait != None:
676 GemRB.SwapPCs (DraggedPortrait, i)
677 GemRB.SetVar ("PressedPortrait", DraggedPortrait)
678 DraggedPortrait = i
679 GemRB.SetTimedEvent ("CheckDragging",1)
680 else:
681 OnDropPortraitToPC()
682 return
684 if GemRB.IsDraggingItem ():
685 Button = PortraitWindow.GetControl (i)
686 Button.EnableBorder (FRAME_PC_TARGET, 1)
687 return
689 def OnDropPortraitToPC ():
690 GemRB.SetVar ("PressedPortrait",0)
691 GemRB.DragItem (0, -1, "")
692 DraggedPortrait = None
693 return
695 def CheckDragging():
696 """Contains portrait dragging in case of mouse out-of-range."""
698 global DraggedPortrait
700 i = GemRB.GetVar ("PressedPortrait")
701 if not i:
702 GemRB.DragItem (0, -1, "")
704 if GemRB.IsDraggingItem()!=2:
705 DraggedPortrait = None
706 return
708 def PortraitButtonOnMouseLeave ():
709 i = GemRB.GetVar ("PressedPortrait")
710 if not i:
711 return
713 Button = PortraitWindow.GetControl (i-1)
714 Button.EnableBorder (FRAME_PC_TARGET, 0)
715 GemRB.SetVar ("PressedPortrait", 0)
716 GemRB.SetTimedEvent ("CheckDragging",1)
717 return
719 def OpenWaitForDiscWindow ():
720 global DiscWindow
722 if DiscWindow:
723 GemRB.HideGUI ()
724 if DiscWindow:
725 DiscWindow.Unload ()
726 GemRB.SetVar ("OtherWindow", -1)
727 # ...LoadWindowPack()
728 EnableAnimatedWindows ()
729 DiscWindow = None
730 GemRB.UnhideGUI ()
731 return
733 try:
734 GemRB.HideGUI ()
735 except:
736 pass
738 GemRB.LoadWindowPack ("GUIID")
739 DiscWindow = Window = GemRB.LoadWindowObject (0)
740 GemRB.SetVar ("OtherWindow", Window.ID)
741 label = DiscWindow.GetControl (0)
743 disc_num = GemRB.GetVar ("WaitForDisc")
744 #disc_path = GemRB.GetVar ("WaitForDiscPath")
745 disc_path = 'XX:'
747 text = GemRB.GetString (31483) + " " + str (disc_num) + " " + GemRB.GetString (31569) + " " + disc_path + "\n" + GemRB.GetString (49152)
748 label.SetText (text)
749 DisableAnimatedWindows ()
750 # 31483 - Please place PS:T disc number
751 # 31568 - Please place the PS:T DVD
752 # 31569 - in drive
753 # 31570 - Wrong disc in drive
754 # 31571 - There is no disc in drive
755 # 31578 - No disc could be found in drive. Please place Disc 1 in drive.
756 # 49152 - To quit the game, press Alt-F4
758 try:
759 GemRB.UnhideGUI ()
760 except:
761 DiscWindow.SetVisible (WINDOW_VISIBLE)
763 def CheckLevelUp(pc):
764 GemRB.SetVar ("CheckLevelUp"+str(pc), CanLevelUp (pc))