GUIScript: Rename SetTimedEvent to SetTimedEventByName.
[gemrb.git] / gemrb / GUIScripts / bg1 / GUICommonWindows.py
blob86111e205bc8ab42a9f9dbafaed004776a620687
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
22 # 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 GUICommon import *
30 from LUCommon import *
32 FRAME_PC_SELECTED = 0
33 FRAME_PC_TARGET = 1
35 PortraitWindow = None
36 OptionsWindow = None
37 ActionsWindow = None
38 DraggedPortrait = None
40 def SetupMenuWindowControls (Window, Gears, ReturnToGame):
41 """Sets up all of the basic control windows."""
42 global OptionsWindow
44 OptionsWindow = Window
45 # FIXME: add "(key)" to tooltips!
47 # Return to Game
48 Button = Window.GetControl (0)
49 Button.SetTooltip (16313)
50 #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
51 # enabled BAM isn't present in .chu, defining it here
52 Button.SetSprites ("GUILSOP", 0,16,17,28,16)
53 Button.SetVarAssoc ("SelectedWindow", 0)
54 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, ReturnToGame)
55 Button.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
57 # Map
58 Button = Window.GetControl (1)
59 Button.SetTooltip (16310)
60 #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
61 Button.SetSprites ("GUILSOP", 0,0,1,20,0)
62 Button.SetVarAssoc ("SelectedWindow", 1)
63 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenMapWindow")
65 # Journal
66 Button = Window.GetControl (2)
67 Button.SetTooltip (16308)
68 #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
69 Button.SetSprites ("GUILSOP", 0,4,5,22,4)
70 Button.SetVarAssoc ("SelectedWindow", 2)
71 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenJournalWindow")
73 # Inventory
74 Button = Window.GetControl (3)
75 Button.SetTooltip (16307)
76 #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
77 Button.SetSprites ("GUILSOP", 0,2,3,21,2)
78 Button.SetVarAssoc ("SelectedWindow", 3)
79 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenInventoryWindow")
81 # Records
82 Button = Window.GetControl (4)
83 Button.SetTooltip (16306)
84 #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
85 Button.SetSprites ("GUILSOP", 0,6,7,23,6)
86 Button.SetVarAssoc ("SelectedWindow", 4)
87 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenRecordsWindow")
89 # Mage
90 Button = Window.GetControl (5)
91 Button.SetTooltip (16309)
92 #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
93 Button.SetSprites ("GUILSOP", 0,8,9,24,8)
94 Button.SetVarAssoc ("SelectedWindow", 5)
95 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenMageWindow")
97 # Priest
98 Button = Window.GetControl (6)
99 Button.SetTooltip (14930)
100 #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
101 Button.SetSprites ("GUILSOP", 0,10,11,25,10)
102 Button.SetVarAssoc ("SelectedWindow", 6)
103 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenPriestWindow")
105 # Options
106 Button = Window.GetControl (7)
107 Button.SetTooltip (16311)
108 #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
109 Button.SetSprites ("GUILSOP", 0,12,13,26,12)
110 Button.SetVarAssoc ("SelectedWindow", 7)
111 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenOptionsWindow")
113 # Party mgmt
114 Button = Window.GetControl (8)
115 Button.SetTooltip (16312)
116 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenPartyWindow")
118 #gears
119 if Gears:
120 # Pendulum, gears, sun/moon dial (time)
121 # FIXME: display all animations: CPEN, CGEAR, CDIAL
122 Button = Window.GetControl (9)
123 Button.SetAnimation ("CGEAR")
124 Button.SetState (IE_GUI_BUTTON_ENABLED)
125 Button.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_ANIMATED|IE_GUI_BUTTON_NORMAL, OP_SET)
126 Button.SetEventByName(IE_GUI_BUTTON_ON_PRESS, "GearsClicked")
127 SetGamedaysAndHourToken()
128 Button.SetTooltip(16041)
130 MarkMenuButton (Window)
132 return
134 def MarkMenuButton (WindowIndex):
135 Pressed = WindowIndex.GetControl( GemRB.GetVar ("SelectedWindow") )
137 for button in range (9):
138 Button = WindowIndex.GetControl (button)
139 Button.SetState (IE_GUI_BUTTON_ENABLED)
141 if Pressed:
142 Button = Pressed
143 else: # highlight return to game
144 Button = WindowIndex.GetControl (0)
146 Button.SetState (IE_GUI_BUTTON_SELECTED)
148 def AIPress ():
149 Button = PortraitWindow.GetControl (6)
150 AI = GemRB.GetMessageWindowSize () & GS_PARTYAI
152 if AI:
153 GemRB.GameSetScreenFlags (GS_PARTYAI, OP_NAND)
154 Button.SetTooltip (15918)
155 else:
156 GemRB.GameSetScreenFlags (GS_PARTYAI, OP_OR)
157 Button.SetTooltip (15917)
158 return
160 def EmptyControls ():
161 global ActionsWindow
163 GemRB.SetVar ("ActionLevel", 0)
164 Window = ActionsWindow
165 for i in range (12):
166 Button = Window.GetControl (i)
167 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
168 Button.SetPicture ("")
169 return
171 def SelectFormationPreset ():
172 GemRB.GameSetFormation (GemRB.GetVar ("Value"), GemRB.GetVar ("Formation") )
173 GroupControls ()
174 return
176 def SetupFormation ():
177 global ActionsWindow
179 Window = ActionsWindow
180 for i in range (12):
181 Button = Window.GetControl (i)
182 Button.SetFlags (IE_GUI_BUTTON_NORMAL, OP_SET)
183 Button.SetSprites ("GUIBTBUT",0,0,1,2,3)
184 Button.SetBAM ("FORM%x"%i,0,0,-1)
185 Button.SetVarAssoc ("Value", i)
186 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "SelectFormationPreset")
187 return
189 def GroupControls ():
190 global ActionsWindow
192 GemRB.SetVar ("ActionLevel", 0)
193 Window = ActionsWindow
194 Button = Window.GetControl (0)
195 Button.SetActionIcon (7)
196 Button = Window.GetControl (1)
197 Button.SetActionIcon (15)
198 Button = Window.GetControl (2)
199 Button.SetActionIcon (21)
200 Button = Window.GetControl (3)
201 Button.SetActionIcon (-1)
202 Button = Window.GetControl (4)
203 Button.SetActionIcon (-1)
204 Button = Window.GetControl (5)
205 Button.SetActionIcon (-1)
206 Button = Window.GetControl (6)
207 Button.SetActionIcon (-1)
208 GemRB.SetVar ("Formation", GemRB.GameGetFormation ())
209 for i in range (5):
210 Button = Window.GetControl (7+i)
211 Button.SetState (IE_GUI_BUTTON_ENABLED)
212 idx = GemRB.GameGetFormation (i)
213 Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON|IE_GUI_BUTTON_NORMAL, OP_SET)
214 Button.SetSprites ("GUIBTBUT",0,0,1,2,3)
215 Button.SetBAM ("FORM%x"%idx,0,0,-1)
216 Button.SetVarAssoc ("Formation", i)
217 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "SelectFormation")
218 Button.SetEventByName (IE_GUI_BUTTON_ON_RIGHT_PRESS, "SetupFormation")
219 str = GemRB.GetString (4935)
220 Button.SetTooltip ("F%d - %s"%(8+i,str) )
221 return
223 def OpenActionsWindowControls (Window):
224 global ActionsWindow
226 ActionsWindow = Window
227 # Gears (time) when options pane is down
228 #Button = Window.GetControl (62)
229 #Button.SetAnimation ("CGEAR")
230 #Button.SetFlags (IE_GUI_BUTTON_PICTURE | IE_GUI_BUTTON_ANIMATED, OP_SET)
231 #Button.SetState (IE_GUI_BUTTON_LOCKED)
232 UpdateActionsWindow ()
233 return
235 def UpdateActionsWindow ():
236 global ActionsWindow
237 global level, TopIndex
239 if ActionsWindow == -1:
240 return
242 if ActionsWindow == None:
243 return
245 pc = 0
246 for i in range (PARTY_SIZE):
247 if GemRB.GameIsPCSelected (i+1):
248 if pc == 0:
249 pc = i+1
250 else:
251 pc = -1
252 break
254 #setting up the disabled button overlay (using the second border slot)
255 for i in range (12):
256 Button = ActionsWindow.GetControl (i)
257 Button.SetBorder (0,6,6,4,4,0,254,0,255)
258 Button.SetBorder (1, 0, 0, 0, 0, 50,30,10,120, 0, 1)
259 Button.SetFont ("NUMBER")
260 Button.SetText ("")
262 if pc == 0:
263 EmptyControls ()
264 return
265 if pc == -1:
266 GroupControls ()
267 return
268 #this is based on class
270 level = GemRB.GetVar ("ActionLevel")
271 TopIndex = GemRB.GetVar ("TopIndex")
272 if level == 0:
273 ActionsWindow.SetupControls (pc)
274 elif level == 1:
275 ActionsWindow.SetupEquipmentIcons(pc, TopIndex)
276 elif level == 2: #spells
277 GemRB.SetVar ("Type", 3)
278 ActionsWindow.SetupSpellIcons(pc, 3, TopIndex)
279 elif level == 3: #innates
280 GemRB.SetVar ("Type", 4)
281 ActionsWindow.SetupSpellIcons(pc, 4, TopIndex)
282 return
284 def ActionQWeaponPressed (which):
285 pc = GemRB.GameGetFirstSelectedPC ()
287 if GemRB.GetEquippedQuickSlot (pc,1)==which and GemRB.GameControlGetTargetMode() != TARGET_MODE_ATTACK:
288 GemRB.GameControlSetTargetMode (TARGET_MODE_ATTACK)
289 else:
290 GemRB.GameControlSetTargetMode (TARGET_MODE_NONE)
291 GemRB.SetEquippedQuickSlot (pc, which)
293 ActionsWindow.SetupControls (pc)
294 UpdateActionsWindow ()
295 return
297 def ActionQWeapon1Pressed ():
298 ActionQWeaponPressed(0)
300 def ActionQWeapon2Pressed ():
301 ActionQWeaponPressed(1)
303 def ActionQWeapon3Pressed ():
304 ActionQWeaponPressed(2)
306 def ActionQWeapon4Pressed ():
307 ActionQWeaponPressed(3)
309 #no check needed because the button wouldn't be drawn if illegal
310 def ActionLeftPressed ():
311 TopIndex = GemRB.GetVar ("TopIndex")
312 if TopIndex>10:
313 TopIndex -= 10
314 else:
315 TopIndex = 0
316 GemRB.SetVar ("TopIndex", TopIndex)
317 UpdateActionsWindow ()
318 return
320 #no check needed because the button wouldn't be drawn if illegal
321 def ActionRightPressed ():
322 pc = GemRB.GameGetFirstSelectedPC ()
323 TopIndex = GemRB.GetVar ("TopIndex")
324 Type = GemRB.GetVar ("Type")
325 Max = GemRB.GetMemorizedSpellsCount(pc, Type)
326 TopIndex += 10
327 if TopIndex > Max - 10:
328 if Max>10:
329 TopIndex = Max-10
330 else:
331 TopIndex = 0
333 GemRB.SetVar ("TopIndex", TopIndex)
334 UpdateActionsWindow ()
335 return
337 def ActionBardSongPressed ():
338 """Toggles the battle song."""
339 pc = GemRB.GameGetFirstSelectedPC ()
340 GemRB.SetModalState (pc, MS_BATTLESONG)
341 GemRB.PlaySound ("act_01")
342 UpdateActionsWindow ()
343 return
345 def ActionSearchPressed ():
346 pc = GemRB.GameGetFirstSelectedPC ()
347 GemRB.SetModalState (pc, MS_DETECTTRAPS)
348 UpdateActionsWindow ()
349 return
351 def ActionStealthPressed ():
352 pc = GemRB.GameGetFirstSelectedPC ()
353 GemRB.SetModalState (pc, MS_STEALTH)
354 GemRB.PlaySound ("act_07")
355 UpdateActionsWindow ()
356 return
358 def ActionTurnPressed ():
359 pc = GemRB.GameGetFirstSelectedPC ()
360 GemRB.SetModalState (pc, MS_TURNUNDEAD)
361 GemRB.PlaySound ("act_06")
362 UpdateActionsWindow ()
363 return
365 def ActionUseItemPressed ():
366 GemRB.SetVar ("TopIndex", 0)
367 GemRB.SetVar ("ActionLevel", 1)
368 UpdateActionsWindow ()
369 return
371 def ActionCastPressed ():
372 GemRB.SetVar ("TopIndex", 0)
373 GemRB.SetVar ("ActionLevel", 2)
374 UpdateActionsWindow ()
375 return
377 def ActionInnatePressed ():
378 GemRB.SetVar ("TopIndex", 0)
379 GemRB.SetVar ("ActionLevel", 3)
380 UpdateActionsWindow ()
381 return
383 def SpellPressed ():
384 pc = GemRB.GameGetFirstSelectedPC ()
386 GemRB.GameControlSetTargetMode (TARGET_MODE_CAST)
387 Spell = GemRB.GetVar ("Spell")
388 Type = GemRB.GetVar ("Type")
389 GemRB.SpellCast (pc, Type, Spell)
390 GemRB.SetVar ("ActionLevel", 0)
391 UpdateActionsWindow ()
392 return
394 def EquipmentPressed ():
395 pc = GemRB.GameGetFirstSelectedPC ()
397 GemRB.GameControlSetTargetMode (TARGET_MODE_CAST)
398 Item = GemRB.GetVar ("Equipment")
399 #equipment index
400 GemRB.UseItem (pc, -1, Item)
401 GemRB.SetVar ("ActionLevel", 0)
402 UpdateActionsWindow ()
403 return
405 SelectionChangeHandler = None
407 def SetSelectionChangeHandler (handler):
408 global SelectionChangeHandler
410 # Switching from walking to non-walking environment:
411 # set the first selected PC in walking env as a selected
412 # in nonwalking env
413 if (not SelectionChangeHandler) and handler:
414 sel = GemRB.GameGetFirstSelectedPC ()
415 if not sel:
416 sel = 1
417 GemRB.GameSelectPCSingle (sel)
419 SelectionChangeHandler = handler
421 # redraw selection on change main selection | single selection
422 SelectionChanged ()
424 def RunSelectionChangeHandler ():
425 if SelectionChangeHandler:
426 SelectionChangeHandler ()
428 def OpenPortraitWindow (needcontrols):
429 global PortraitWindow
431 PortraitWindow = Window = GemRB.LoadWindow (1)
433 if needcontrols:
434 #Button=Window.GetControl (8)
435 #Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "MinimizePortraits")
437 # AI
438 Button = Window.GetControl (6)
439 GSFlags = GemRB.GetMessageWindowSize ()&GS_PARTYAI
440 Button.SetFlags (IE_GUI_BUTTON_CHECKBOX, OP_OR)
441 #this control is crippled
442 Button.SetSprites ("GUIBTACT", 0, 46, 47, 48, 49)
443 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "AIPress")
444 Button.SetVarAssoc ("", GSFlags)
445 if GSFlags:
446 Button.SetTooltip (15917)
447 else:
448 Button.SetTooltip (15918)
450 #Select All
451 Button = Window.GetControl (7)
452 Button.SetTooltip (10485)
453 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "SelectAllOnPress")
454 else:
455 #Rest
456 Button = Window.GetControl (6)
457 Button.SetTooltip (11942)
458 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "RestPress")
460 for i in range (PARTY_SIZE):
461 Button = Window.GetControl (i)
462 Button.SetFont ("STATES2")
463 Button.SetVarAssoc ("PressedPortrait", i+1)
465 if (needcontrols):
466 Button.SetEventByName (IE_GUI_BUTTON_ON_RIGHT_PRESS, "OpenInventoryWindowClick")
467 else:
468 Button.SetEventByName (IE_GUI_BUTTON_ON_RIGHT_PRESS, "PortraitButtonOnPress")
470 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "PortraitButtonOnPress")
471 Button.SetEventByName (IE_GUI_BUTTON_ON_SHIFT_PRESS, "PortraitButtonOnShiftPress")
472 Button.SetEventByName (IE_GUI_BUTTON_ON_DRAG_DROP, "OnDropItemToPC")
473 Button.SetEventByName (IE_GUI_BUTTON_ON_DRAG_DROP_PORTRAIT, "OnDropPortraitToPC")
474 Button.SetEventByName (IE_GUI_BUTTON_ON_DRAG, "PortraitButtonOnDrag")
475 Button.SetEventByName (IE_GUI_MOUSE_ENTER_BUTTON, "PortraitButtonOnMouseEnter")
476 Button.SetEventByName (IE_GUI_MOUSE_LEAVE_BUTTON, "PortraitButtonOnMouseLeave")
478 Button.SetBorder (FRAME_PC_SELECTED, 1, 1, 2, 2, 0, 255, 0, 255)
479 Button.SetBorder (FRAME_PC_TARGET, 3, 3, 4, 4, 255, 255, 0, 255)
481 UpdatePortraitWindow ()
482 SelectionChanged ()
483 return Window
485 def UpdatePortraitWindow ():
486 """Updates all of the portraits."""
488 Window = PortraitWindow
490 pc = GemRB.GameGetSelectedPCSingle ()
491 Inventory = GemRB.GetVar ("Inventory")
493 for portid in range (PARTY_SIZE):
494 Button = Window.GetControl (portid)
495 pic = GemRB.GetPlayerPortrait (portid+1, 1)
496 if Inventory and pc != portid+1:
497 pic = None
499 if not pic:
500 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
501 Button.SetState (IE_GUI_BUTTON_DISABLED)
502 Button.SetText ("")
503 Button.SetTooltip ("")
504 continue
506 Button.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_ALIGN_BOTTOM|IE_GUI_BUTTON_ALIGN_LEFT|IE_GUI_BUTTON_HORIZONTAL|IE_GUI_BUTTON_DRAGGABLE, OP_SET)
507 Button.SetState (IE_GUI_BUTTON_ENABLED)
508 Button.SetPicture (pic, "NOPORTSM")
509 hp = GemRB.GetPlayerStat (portid+1, IE_HITPOINTS)
510 hp_max = GemRB.GetPlayerStat (portid+1, IE_MAXHITPOINTS)
511 state = GemRB.GetPlayerStat (portid+1, IE_STATE_ID)
513 if (hp_max<1):
514 ratio = 0.0
515 else:
516 ratio = (hp+0.0) / hp_max
518 if hp<1 or (state & STATE_DEAD):
519 Button.SetOverlay (ratio, 64,64,64,200, 64,64,64,200)
520 else:
521 Button.SetOverlay (ratio, 255,0,0,200, 128,0,0,200)
522 Button.SetTooltip (GemRB.GetPlayerName (portid+1, 1) + "\n%d/%d" %(hp, hp_max))
524 #add effects on the portrait
525 effects = GemRB.GetPlayerStates (portid+1)
526 states = ""
527 for col in range(len(effects)):
528 states = effects[col:col+1] + states
529 if col % 3 == 2: states = "\n" + states
530 for x in range(3 - (len(effects)/3)):
531 states = "\n" + states
532 states = "\n" + states
534 # blank space
535 flag = chr(38)
537 # shopping icon
538 if pc==portid+1:
539 if GemRB.GetStore()!=None:
540 flag = chr(37)
541 # talk icon
542 if GemRB.GameGetSelectedPCSingle(1)==portid+1:
543 flag = chr(37)
545 if CanLevelUp (portid+1):
546 states = flag+chr(238)+chr(39) + states
547 else:
548 states = flag+chr(238)+chr(238) + states
549 Button.SetText(states)
550 return
552 def PortraitButtonOnDrag ():
553 global DraggedPortrait
555 #they start from 1
556 DraggedPortrait = GemRB.GetVar ("PressedPortrait")
557 GemRB.DragItem (DraggedPortrait, -1, "")
558 return
560 def PortraitButtonOnPress ():
561 i = GemRB.GetVar ("PressedPortrait")
563 if not i:
564 return
566 if GemRB.GameControlGetTargetMode() != TARGET_MODE_NONE:
567 GemRB.ActOnPC (i)
568 return
570 if (not SelectionChangeHandler):
571 if GemRB.GameIsPCSelected (i):
572 GemRB.GameControlSetScreenFlags (SF_CENTERONACTOR, OP_OR)
573 GemRB.GameSelectPC (i, True, SELECT_REPLACE)
574 else:
575 GemRB.GameSelectPCSingle (i)
576 SelectionChanged ()
577 RunSelectionChangeHandler ()
578 return
580 def PortraitButtonOnShiftPress ():
581 i = GemRB.GetVar ("PressedPortrait")
583 if not i:
584 return
586 if (not SelectionChangeHandler):
587 sel = GemRB.GameIsPCSelected (i)
588 sel = not sel
589 GemRB.GameSelectPC (i, sel)
590 else:
591 GemRB.GameSelectPCSingle (i)
592 SelectionChanged ()
593 RunSelectionChangeHandler ()
594 return
596 # Run by Game class when selection was changed
597 def SelectionChanged ():
598 global PortraitWindow
600 GemRB.SetVar ("ActionLevel", 0)
601 if (not SelectionChangeHandler):
602 UpdateActionsWindow ()
603 for i in range (PARTY_SIZE):
604 Button = PortraitWindow.GetControl (i)
605 Button.EnableBorder (FRAME_PC_SELECTED, GemRB.GameIsPCSelected (i + 1))
606 else:
607 sel = GemRB.GameGetSelectedPCSingle ()
609 for i in range (PARTY_SIZE):
610 Button = PortraitWindow.GetControl (i)
611 Button.EnableBorder (FRAME_PC_SELECTED, i + 1 == sel)
612 return
614 def PortraitButtonOnMouseEnter ():
615 global DraggedPortrait
617 i = GemRB.GetVar ("PressedPortrait")
618 if GemRB.IsDraggingItem()==2:
619 if DraggedPortrait != None:
620 GemRB.SwapPCs (DraggedPortrait, i)
621 GemRB.SetVar ("PressedPortrait", DraggedPortrait)
622 DraggedPortrait = i
623 GemRB.SetTimedEventByName ("CheckDragging",1)
624 else:
625 OnDropPortraitToPC()
626 return
628 if GemRB.IsDraggingItem ():
629 Button = PortraitWindow.GetControl (i)
630 Button.EnableBorder (FRAME_PC_TARGET, 1)
631 return
633 def OnDropPortraitToPC ():
634 GemRB.SetVar ("PressedPortrait",0)
635 GemRB.DragItem (0, -1, "")
636 DraggedPortrait = None
637 return
639 def CheckDragging():
640 """Contains portrait dragging in case of mouse out-of-range."""
642 global DraggedPortrait
644 i = GemRB.GetVar ("PressedPortrait")
645 if not i:
646 GemRB.DragItem (0, -1, "")
648 if GemRB.IsDraggingItem()!=2:
649 DraggedPortrait = None
650 return
652 def PortraitButtonOnMouseLeave ():
653 i = GemRB.GetVar ("PressedPortrait")
654 if not i:
655 return
657 Button = PortraitWindow.GetControl (i-1)
658 Button.EnableBorder (FRAME_PC_TARGET, 0)
659 GemRB.SetVar ("PressedPortrait", 0)
660 GemRB.SetTimedEventByName ("CheckDragging",1)
661 return
663 def OpenWaitForDiscWindow ():
664 global DiscWindow
666 if DiscWindow:
667 GemRB.HideGUI ()
668 if DiscWindow:
669 DiscWindow.Unload ()
670 GemRB.SetVar ("OtherWindow", -1)
671 # ...LoadWindowPack()
672 EnableAnimatedWindows ()
673 DiscWindow = None
674 GemRB.UnhideGUI ()
675 return
677 try:
678 GemRB.HideGUI ()
679 except:
680 pass
682 GemRB.LoadWindowPack ("GUIID")
683 DiscWindow = Window = GemRB.LoadWindow (0)
684 GemRB.SetVar ("OtherWindow", Window.ID)
685 label = DiscWindow.GetControl (0)
687 disc_num = GemRB.GetVar ("WaitForDisc")
688 #disc_path = GemRB.GetVar ("WaitForDiscPath")
689 disc_path = 'XX:'
691 text = GemRB.GetString (31483) + " " + str (disc_num) + " " + GemRB.GetString (31569) + " " + disc_path + "\n" + GemRB.GetString (49152)
692 label.SetText (text)
693 DisableAnimatedWindows ()
694 # 31483 - Please place PS:T disc number
695 # 31568 - Please place the PS:T DVD
696 # 31569 - in drive
697 # 31570 - Wrong disc in drive
698 # 31571 - There is no disc in drive
699 # 31578 - No disc could be found in drive. Please place Disc 1 in drive.
700 # 49152 - To quit the game, press Alt-F4
702 try:
703 GemRB.UnhideGUI ()
704 except:
705 DiscWindow.SetVisible (WINDOW_VISIBLE)
707 def CheckLevelUp(pc):
708 GemRB.SetVar ("CheckLevelUp"+str(pc), CanLevelUp (pc))