properly implemented special race based action buttons
[gemrb.git] / gemrb / GUIScripts / iwd / GUICommonWindows.py
blobb922b3f08e08b7dfe27c8c983c2fafe0395cde72
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 import GUICommon
31 import LUCommon
33 import GUIJRNL
34 import GUIMA
35 import GUIMG
36 import GUIINV
37 import GUIOPT
38 import GUIPR
39 import GUIREC
41 FRAME_PC_SELECTED = 0
42 FRAME_PC_TARGET = 1
44 PortraitWindow = None
45 OptionsWindow = None
46 ActionsWindow = None
47 DraggedPortrait = None
49 def SetupMenuWindowControls (Window, Gears, ReturnToGame):
50 # FIXME: add "(key)" to tooltips!
52 # Return to Game
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)
60 # Map
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)
67 # Journal
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)
74 # Inventory
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)
81 # Records
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)
88 # Mage
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)
94 # Priest
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)
101 # Options
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)
108 # Party mgmt
109 Button = Window.GetControl (8)
110 Button.SetTooltip (16312)
111 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, None)
113 if Gears:
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)
127 return
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)
136 if Pressed:
137 Button = Pressed
138 else: # highlight return to game
139 Button = WindowIndex.GetControl (0)
141 Button.SetState (IE_GUI_BUTTON_PRESSED)
143 def AIPress ():
144 Button = PortraitWindow.GetControl (6)
145 AI = GemRB.GetMessageWindowSize () & GS_PARTYAI
146 if AI:
147 GemRB.GameSetScreenFlags (GS_PARTYAI, OP_NAND)
148 Button.SetTooltip (15918)
149 else:
150 GemRB.GameSetScreenFlags (GS_PARTYAI, OP_OR)
151 Button.SetTooltip (15917)
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 GemRB.GameSetFormation (GemRB.GetVar ("Value"), GemRB.GetVar ("Formation") )
167 GroupControls ()
168 return
170 def SetupFormation ():
171 global ActionsWindow
173 Window = ActionsWindow
174 for i in range (12):
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)
181 return
183 def GroupControls ():
184 global ActionsWindow
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 ())
203 for i in range (5):
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) )
215 return
217 def OpenActionsWindowControls (Window):
218 global ActionsWindow
220 ActionsWindow = Window
221 UpdateActionsWindow ()
222 return
224 def UpdateActionsWindow ():
225 """Redraws the actions section of the window."""
227 global ActionsWindow, PortraitWindow, OptionsWindow
228 global level, TopIndex
230 if ActionsWindow == -1:
231 return
233 if ActionsWindow == None:
234 return
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:
239 if PortraitWindow:
240 PortraitWindow.Invalidate ()
241 if OptionsWindow:
242 OptionsWindow.Invalidate ()
244 Selected = GemRB.GetSelectedSize()
246 #setting up the disabled button overlay (using the second border slot)
247 for i in range (12):
248 Button = ActionsWindow.GetControl (i)
249 Button.SetBorder (1, 0, 0, 0, 0, 50,30,10,120, 0, 1)
250 Button.SetFont ("NUMBER")
251 Button.SetText ("")
253 if Selected == 0:
254 EmptyControls ()
255 return
256 if Selected > 1:
257 GroupControls ()
258 return
259 #this is based on class
260 #we are sure there is only one actor selected
261 pc = 0
262 for i in range (PARTY_SIZE):
263 if GemRB.GameIsPCSelected (i+1):
264 pc = i+1
265 break
267 level = GemRB.GetVar ("ActionLevel")
268 TopIndex = GemRB.GetVar ("TopIndex")
269 if level == 0:
270 ActionsWindow.SetupControls (globals(), pc)
271 elif level == 1:
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)
279 return
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)
290 else:
291 GemRB.GameControlSetTargetMode (TARGET_MODE_NONE)
292 GemRB.SetEquippedQuickSlot (pc, which)
294 ActionsWindow.SetupControls (globals(), pc)
295 UpdateActionsWindow ()
296 return
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")
313 if TopIndex>10:
314 TopIndex -= 10
315 else:
316 TopIndex = 0
317 GemRB.SetVar ("TopIndex", TopIndex)
318 UpdateActionsWindow ()
319 return
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)
327 TopIndex += 10
328 if TopIndex > Max - 10:
329 if Max>10:
330 TopIndex = Max-10
331 else:
332 TopIndex = 0
334 GemRB.SetVar ("TopIndex", TopIndex)
335 UpdateActionsWindow ()
336 return
338 def ActionBardSongPressed ():
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 ActionQItemPressed (action):
378 pc = GemRB.GameGetFirstSelectedPC ()
379 #quick slot
380 GemRB.UseItem (pc, -2, action)
381 return
383 def ActionQItem1Pressed ():
384 ActionQItemPressed (ACT_QSLOT1)
385 return
387 def ActionQItem2Pressed ():
388 ActionQItemPressed (ACT_QSLOT2)
389 return
391 def ActionQItem3Pressed ():
392 ActionQItemPressed (ACT_QSLOT3)
393 return
395 def ActionQItem4Pressed ():
396 ActionQItemPressed (ACT_QSLOT4)
397 return
399 def ActionQItem5Pressed ():
400 ActionQItemPressed (ACT_QSLOT5)
401 return
403 def ActionInnatePressed ():
404 GemRB.SetVar ("TopIndex", 0)
405 GemRB.SetVar ("ActionLevel", 3)
406 UpdateActionsWindow ()
407 return
409 def SpellPressed ():
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 ()
418 return
420 def EquipmentPressed ():
421 pc = GemRB.GameGetFirstSelectedPC ()
423 GemRB.GameControlSetTargetMode (TARGET_MODE_CAST)
424 Item = GemRB.GetVar ("Equipment")
425 #equipment index
426 GemRB.UseItem (pc, -1, Item)
427 GemRB.SetVar ("ActionLevel", 0)
428 UpdateActionsWindow ()
429 return
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
438 # in nonwalking env
439 #if (not SelectionChangeHandler) and handler:
440 if (not SelectionChangeHandler) and handler and (not GUICommon.NextWindowFn):
441 sel = GemRB.GameGetFirstSelectedPC ()
442 if not sel:
443 sel = 1
444 GemRB.GameSelectPCSingle (sel)
446 SelectionChangeHandler = handler
448 # redraw selection on change main selection | single selection
449 SelectionChanged ()
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)
461 else:
462 PortraitWindow = Window = GemRB.LoadWindow (1)
464 if needcontrols:
465 if GUICommon.HasHOW():
466 # Rest (how)
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)
474 pos = pos - 37
475 Window.CreateButton (6, 6, pos, 27, 36)
476 # AI
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)
486 if GSFlags:
487 Button.SetTooltip (15917)
488 else:
489 Button.SetTooltip (15918)
491 #Select All
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():
499 # Rest (iwd)
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)
512 if (needcontrols):
513 Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, GUIINV.OpenInventoryWindowClick)
514 else:
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)
527 Button.SetText ("")
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 ()
537 SelectionChanged ()
538 return Window
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:
550 pic = None
552 if not pic:
553 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
554 Button.SetState (IE_GUI_BUTTON_DISABLED)
555 Button.SetText ("")
556 Button.SetTooltip ("")
557 continue
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)
572 states = ""
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
580 # blank space
581 # TODO: missing, maybe add another string tag to make glyphs 100% transparent?
582 flag = blank = chr(238)
584 # these two are missing too
585 ## shopping icon
586 #if pc==portid+1:
587 #if GemRB.GetStore()!=None:
588 #flag = chr(155)
589 ## talk icon
590 #if GemRB.GameGetSelectedPCSingle(1)==portid+1:
591 #flag = chr(154)
593 if LUCommon.CanLevelUp (portid+1):
594 states = flag+blank+chr(255) + states
595 else:
596 #states = flag+blank+blank + states
597 #states = "\n" + states
598 pass
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)
605 return
607 def PortraitButtonOnDrag ():
608 global DraggedPortrait
610 #they start from 1
611 DraggedPortrait = GemRB.GetVar ("PressedPortrait")
612 GemRB.DragItem (DraggedPortrait, -1, "")
613 return
615 def PortraitButtonOnPress ():
616 i = GemRB.GetVar ("PressedPortrait")
618 if not i:
619 return
621 if GemRB.GameControlGetTargetMode() != TARGET_MODE_NONE:
622 GemRB.ActOnPC (i)
623 return
625 if (not SelectionChangeHandler):
626 if GemRB.GameIsPCSelected (i):
627 GemRB.GameControlSetScreenFlags (SF_CENTERONACTOR, OP_OR)
628 GemRB.GameSelectPC (i, True, SELECT_REPLACE)
629 else:
630 GemRB.GameSelectPCSingle (i)
631 SelectionChanged ()
632 RunSelectionChangeHandler ()
633 return
635 def PortraitButtonOnShiftPress ():
636 i = GemRB.GetVar ("PressedPortrait")
638 if not i:
639 return
641 if (not SelectionChangeHandler):
642 sel = GemRB.GameIsPCSelected (i)
643 sel = not sel
644 GemRB.GameSelectPC (i, sel)
645 else:
646 GemRB.GameSelectPCSingle (i)
647 SelectionChanged ()
648 RunSelectionChangeHandler ()
649 return
651 # Run by Game class when selection was changed
652 def SelectionChanged ():
653 global PortraitWindow
655 if not PortraitWindow:
656 return
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))
665 else:
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)
670 import GUIWORLD
671 GUIWORLD.CloseContainerWindow()
672 return
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)
684 DraggedPortrait = i
685 GemRB.SetTimedEvent (CheckDragging, 1)
686 else:
687 OnDropPortraitToPC()
688 return
690 if GemRB.IsDraggingItem ():
691 Button = PortraitWindow.GetControl (i)
692 Button.EnableBorder (FRAME_PC_TARGET, 1)
693 return
695 def OnDropPortraitToPC ():
696 GemRB.SetVar ("PressedPortrait",0)
697 GemRB.DragItem (0, -1, "")
698 DraggedPortrait = None
699 return
701 def CheckDragging():
702 """Contains portrait dragging in case of mouse out-of-range."""
704 global DraggedPortrait
706 i = GemRB.GetVar ("PressedPortrait")
707 if not i:
708 GemRB.DragItem (0, -1, "")
710 if GemRB.IsDraggingItem()!=2:
711 DraggedPortrait = None
712 return
714 def PortraitButtonOnMouseLeave ():
715 i = GemRB.GetVar ("PressedPortrait")
716 if not i:
717 return
719 Button = PortraitWindow.GetControl (i-1)
720 Button.EnableBorder (FRAME_PC_TARGET, 0)
721 GemRB.SetVar ("PressedPortrait", 0)
722 GemRB.SetTimedEvent (CheckDragging, 1)
723 return
725 def ActionStopPressed ():
726 for i in range (PARTY_SIZE):
727 if GemRB.GameIsPCSelected (i + 1):
728 GemRB.ClearActions (i + 1)
729 return
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))