iwd: more gcw syncing with bg2 - actonpc and dragging
[gemrb.git] / gemrb / GUIScripts / iwd / GUICommonWindows.py
blob84ccf9a464025ec3e1cc7c09d4745899f63b9253
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 if pc == 0:
268 #summoned/charmed creature.
269 #TODO: some creatures have real actions window!!
270 GroupControls()
271 return
273 level = GemRB.GetVar ("ActionLevel")
274 TopIndex = GemRB.GetVar ("TopIndex")
275 if level == 0:
276 ActionsWindow.SetupControls (globals(), pc)
277 elif level == 1:
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)
285 return
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)
296 else:
297 GemRB.GameControlSetTargetMode (TARGET_MODE_NONE)
298 GemRB.SetEquippedQuickSlot (pc, which)
300 ActionsWindow.SetupControls (globals(), pc)
301 UpdateActionsWindow ()
302 return
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")
319 if TopIndex>10:
320 TopIndex -= 10
321 else:
322 TopIndex = 0
323 GemRB.SetVar ("TopIndex", TopIndex)
324 UpdateActionsWindow ()
325 return
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)
333 TopIndex += 10
334 if TopIndex > Max - 10:
335 if Max>10:
336 TopIndex = Max-10
337 else:
338 TopIndex = 0
340 GemRB.SetVar ("TopIndex", TopIndex)
341 UpdateActionsWindow ()
342 return
344 def ActionBardSongPressed ():
345 pc = GemRB.GameGetFirstSelectedPC ()
346 GemRB.SetModalState (pc, MS_BATTLESONG)
347 GemRB.PlaySound ("act_01")
348 UpdateActionsWindow ()
349 return
351 def ActionSearchPressed ():
352 pc = GemRB.GameGetFirstSelectedPC ()
353 GemRB.SetModalState (pc, MS_DETECTTRAPS)
354 UpdateActionsWindow ()
355 return
357 def ActionStealthPressed ():
358 pc = GemRB.GameGetFirstSelectedPC ()
359 GemRB.SetModalState (pc, MS_STEALTH)
360 GemRB.PlaySound ("act_07")
361 UpdateActionsWindow ()
362 return
364 def ActionTurnPressed ():
365 pc = GemRB.GameGetFirstSelectedPC ()
366 GemRB.SetModalState (pc, MS_TURNUNDEAD)
367 GemRB.PlaySound ("act_06")
368 UpdateActionsWindow ()
369 return
371 def ActionUseItemPressed ():
372 GemRB.SetVar ("TopIndex", 0)
373 GemRB.SetVar ("ActionLevel", 1)
374 UpdateActionsWindow ()
375 return
377 def ActionCastPressed ():
378 GemRB.SetVar ("TopIndex", 0)
379 GemRB.SetVar ("ActionLevel", 2)
380 UpdateActionsWindow ()
381 return
383 def ActionQItemPressed (action):
384 pc = GemRB.GameGetFirstSelectedPC ()
385 #quick slot
386 GemRB.UseItem (pc, -2, action)
387 return
389 def ActionQItem1Pressed ():
390 ActionQItemPressed (ACT_QSLOT1)
391 return
393 def ActionQItem2Pressed ():
394 ActionQItemPressed (ACT_QSLOT2)
395 return
397 def ActionQItem3Pressed ():
398 ActionQItemPressed (ACT_QSLOT3)
399 return
401 def ActionQItem4Pressed ():
402 ActionQItemPressed (ACT_QSLOT4)
403 return
405 def ActionQItem5Pressed ():
406 ActionQItemPressed (ACT_QSLOT5)
407 return
409 def ActionInnatePressed ():
410 GemRB.SetVar ("TopIndex", 0)
411 GemRB.SetVar ("ActionLevel", 3)
412 UpdateActionsWindow ()
413 return
415 def SpellPressed ():
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 ()
424 return
426 def EquipmentPressed ():
427 pc = GemRB.GameGetFirstSelectedPC ()
429 GemRB.GameControlSetTargetMode (TARGET_MODE_CAST)
430 Item = GemRB.GetVar ("Equipment")
431 #equipment index
432 GemRB.UseItem (pc, -1, Item)
433 GemRB.SetVar ("ActionLevel", 0)
434 UpdateActionsWindow ()
435 return
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
444 # in nonwalking env
445 if (not SelectionChangeHandler) and handler:
446 sel = GemRB.GameGetFirstSelectedPC ()
447 if not sel:
448 sel = 1
449 GemRB.GameSelectPCSingle (sel)
451 SelectionChangeHandler = handler
453 # redraw selection on change main selection | single selection
454 SelectionChanged ()
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)
466 else:
467 PortraitWindow = Window = GemRB.LoadWindow (1)
469 if needcontrols:
470 if GUICommon.HasHOW():
471 # Rest (how)
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)
479 pos = pos - 37
480 Window.CreateButton (6, 6, pos, 27, 36)
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, 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)
491 if GSFlags:
492 Button.SetTooltip (15917)
493 else:
494 Button.SetTooltip (15918)
496 #Select All
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():
504 # Rest (iwd)
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)
517 if (needcontrols):
518 Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, GUIINV.OpenInventoryWindowClick)
519 else:
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)
532 Button.SetText ("")
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 ()
542 SelectionChanged ()
543 return Window
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:
555 pic = None
557 if not pic:
558 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
559 Button.SetState (IE_GUI_BUTTON_DISABLED)
560 Button.SetText ("")
561 Button.SetTooltip ("")
562 continue
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)
576 if (hp_max<1):
577 ratio = 0.0
578 else:
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)
583 else:
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)
591 states = ""
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
599 # blank space
600 # TODO: missing, maybe add another string tag to make glyphs 100% transparent?
601 flag = blank = chr(238)
603 # these two are missing too
604 ## shopping icon
605 #if pc==portid+1:
606 #if GemRB.GetStore()!=None:
607 #flag = chr(155)
608 ## talk icon
609 #if GemRB.GameGetSelectedPCSingle(1)==portid+1:
610 #flag = chr(154)
612 if LUCommon.CanLevelUp (portid+1):
613 states = flag+blank+chr(255) + states
614 else:
615 #states = flag+blank+blank + states
616 #states = "\n" + states
617 pass
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)
624 return
626 def PortraitButtonOnDrag ():
627 global DraggedPortrait
629 #they start from 1
630 DraggedPortrait = GemRB.GetVar ("PressedPortrait")
631 GemRB.DragItem (DraggedPortrait, -1, "")
632 return
634 def PortraitButtonOnPress ():
635 i = GemRB.GetVar ("PressedPortrait")
637 if not i:
638 return
640 if GemRB.GameControlGetTargetMode() != TARGET_MODE_NONE:
641 GemRB.ActOnPC (i)
642 return
644 if (not SelectionChangeHandler):
645 if GemRB.GameIsPCSelected (i):
646 GemRB.GameControlSetScreenFlags (SF_CENTERONACTOR, OP_OR)
647 GemRB.GameSelectPC (i, True, SELECT_REPLACE)
648 else:
649 GemRB.GameSelectPCSingle (i)
650 SelectionChanged ()
651 RunSelectionChangeHandler ()
652 return
654 def PortraitButtonOnShiftPress ():
655 i = GemRB.GetVar ("PressedPortrait")
657 if not i:
658 return
660 if (not SelectionChangeHandler):
661 sel = GemRB.GameIsPCSelected (i)
662 sel = not sel
663 GemRB.GameSelectPC (i, sel)
664 else:
665 GemRB.GameSelectPCSingle (i)
666 SelectionChanged ()
667 RunSelectionChangeHandler ()
668 return
670 # Run by Game class when selection was changed
671 def SelectionChanged ():
672 global PortraitWindow
674 if not PortraitWindow:
675 return
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))
684 else:
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)
689 return
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)
701 DraggedPortrait = i
702 GemRB.SetTimedEvent (CheckDragging, 1)
703 else:
704 OnDropPortraitToPC()
705 return
707 if GemRB.IsDraggingItem ():
708 Button = PortraitWindow.GetControl (i)
709 Button.EnableBorder (FRAME_PC_TARGET, 1)
710 return
712 def OnDropPortraitToPC ():
713 GemRB.SetVar ("PressedPortrait",0)
714 GemRB.DragItem (0, -1, "")
715 DraggedPortrait = None
716 return
718 def CheckDragging():
719 """Contains portrait dragging in case of mouse out-of-range."""
721 global DraggedPortrait
723 i = GemRB.GetVar ("PressedPortrait")
724 if not i:
725 GemRB.DragItem (0, -1, "")
727 if GemRB.IsDraggingItem()!=2:
728 DraggedPortrait = None
729 return
731 def PortraitButtonOnMouseLeave ():
732 i = GemRB.GetVar ("PressedPortrait")
733 if not i:
734 return
736 Button = PortraitWindow.GetControl (i-1)
737 Button.EnableBorder (FRAME_PC_TARGET, 0)
738 GemRB.SetVar ("PressedPortrait", 0)
739 GemRB.SetTimedEvent (CheckDragging, 1)
740 return
742 def ActionStopPressed ():
743 for i in range (PARTY_SIZE):
744 if GemRB.GameIsPCSelected (i + 1):
745 GemRB.ClearActions (i + 1)
746 return
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))