1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 The GemRB Project
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * Declares GameControl widget which is responsible for displaying areas,
23 * interacting with PCs, NPCs and the rest of the game world.
24 * @author The GemRB Project
34 #include "Interface.h"
40 #define DF_IN_DIALOG 1
41 #define DF_TALKCOUNT 2
42 #define DF_UNBREAKABLE 4
43 #define DF_FREEZE_SCRIPTS 8
44 #define DF_INTERACT 16
45 #define DF_IN_CONTAINER 32
46 #define DF_OPENCONTINUEWINDOW 64
47 #define DF_OPENENDWINDOW 128
50 // !!! Keep these synchronized with GUIDefines.py !!!
51 #define SF_DISABLEMOUSE 1 //no mouse cursor
52 #define SF_CENTERONACTOR 2 //
53 #define SF_ALWAYSCENTER 4
54 #define SF_GUIENABLED 8 //
55 #define SF_LOCKSCROLL 16 //don't scroll
56 #define SF_CUTSCENE 32 //don't push new actions onto the action queue
57 #define SF_TRACKING 64 //draw blue arrows on the edge for creatures
59 // target modes and types
60 // !!! Keep these synchronized with GUIDefines.py !!!
61 #define TARGET_MODE_NONE 0
62 #define TARGET_MODE_TALK 1
63 #define TARGET_MODE_ATTACK 2
64 #define TARGET_MODE_CAST 3
65 #define TARGET_MODE_DEFEND 4
66 #define TARGET_MODE_PICK 5
69 #define TARGET_SELECT 16
70 #define TARGET_NO_DEAD 32
71 #define TARGET_POINT 64
72 #define TARGET_NO_HIDDEN 128
73 #define TARGET_TYPE_NONE 0x000
74 #define TARGET_NO_ALLY 0x100 //0x100
75 #define TARGET_NO_ENEMY 0x200 //0x200
76 #define TARGET_NO_NEUTRAL 0x400
77 #define TARGET_NO_SELF 0x800
78 #define TARGET_TYPE_ALL 0 //(TARGET_TYPE_ALLY | TARGET_TYPE_ENEMY | TARGET_TYPE_NEUTRAL)
83 * Widget displaying areas, where most of the game 'happens'.
84 * It allows for interacting with PCs, NPCs and the rest of the world.
85 * It's also a very core part of GemRB, as some processes are driven from it.
86 * It's always assigned Control index 0.
89 class GEM_EXPORT GameControl
: public Control
{
94 /** Draws the Control on the Output Display */
95 void Draw(unsigned short x
, unsigned short y
);
96 /** Sets the Text of the current control */
97 int SetText(const char* string
, int pos
= 0);
98 /** Sets multiple quicksaves flag*/
99 static void MultipleQuickSaves(int arg
);
100 void SetTracker(Actor
*actor
, ieDword dist
);
103 //using global ID which is safer
106 ieDword distance
; //tracking distance
107 std::vector
< Actor
*> highlighted
;
108 bool DrawSelectionRect
;
111 Region SelectionRect
;
112 short StartX
, StartY
;
116 Container
* overContainer
;
117 InfoPoint
* overInfoPoint
;
119 // currently selected targetting type, such as talk, attack, cast, ...
121 // allow targetting allies, enemies and/or neutrals (bitmask)
125 unsigned char lastCursor
;
129 unsigned short lastMouseX
, lastMouseY
;
133 unsigned long AIUpdateCounter
;
137 unsigned int DisplayTextTime
;
139 /** Key Press Event */
140 void OnKeyPress(unsigned char Key
, unsigned short Mod
);
141 /** Key Release Event */
142 void OnKeyRelease(unsigned char Key
, unsigned short Mod
);
143 /** Mouse Over Event */
144 void OnMouseOver(unsigned short x
, unsigned short y
);
145 /** Global Mouse Move Event */
146 void OnGlobalMouseMove(unsigned short x
, unsigned short y
);
147 /** Mouse Button Down */
148 void OnMouseDown(unsigned short x
, unsigned short y
, unsigned short Button
,
150 /** Mouse Button Up */
151 void OnMouseUp(unsigned short x
, unsigned short y
, unsigned short Button
,
153 /** Special Key Press */
154 void OnSpecialKeyPress(unsigned char Key
);
155 void DisplayTooltip();
156 void UpdateScrolling();
157 void SetScreenFlags(int value
, int mode
);
158 void SetDialogueFlags(int value
, int mode
);
159 int GetScreenFlags() { return ScreenFlags
; }
160 int GetDialogueFlags() { return DialogueFlags
; }
161 /** this function is called from the area when autosave is needed */
163 void SetDisplayText(char *text
, unsigned int time
);
164 void SetDisplayText(ieStrRef text
, unsigned int time
);
166 /** this function is called when the user presses 'q' (or equivalent) */
168 /** this function safely retrieves an Actor by ID */
169 Actor
*GetActorByGlobalID(ieWord ID
);
170 void CalculateSelection(const Point
&p
);
171 void ResizeDel(Window
* win
, int type
);
172 void ResizeAdd(Window
* win
, int type
);
173 void HandleWindowHide(const char *WindowName
, const char *WindowPosition
);
174 void HandleWindowReveal(const char *WindowName
, const char *WindowPosition
);
175 void ReadFormations();
176 /** Draws an arrow on the edge of the screen based on the point (points at offscreen actors) */
177 void DrawArrowMarker(const Region
&screen
, Point p
, const Region
&viewport
);
180 unsigned char LeftCount
, BottomCount
, RightCount
, TopCount
;
183 Actor
*user
; //the user of item or spell
187 ieWord originalTargetID
;
188 //no idea if this is viable
189 Scriptable
*targetOB
;
190 //using spell or item
191 int spellOrItem
; // -1 = item, otherwise the spell type
192 //the user of spell or item
194 int spellSlot
, spellIndex
; //or inventorySlot/itemHeader
195 int spellCount
; //multiple targeting
199 /** Selects one or all PC */
200 void SelectActor(int whom
, int type
= -1);
201 void SetCutSceneMode(bool active
);
204 void TryToAttack(Actor
*source
, Actor
*target
);
205 void TryToBash(Actor
*source
, Scriptable
*tgt
);
206 void TryToCast(Actor
*source
, const Point
&p
);
207 void TryToCast(Actor
*source
, Actor
*target
);
208 void TryToDefend(Actor
*source
, Actor
*target
);
209 void TryToTalk(Actor
*source
, Actor
*target
);
210 void TryToPick(Actor
*source
, Actor
*tgt
);
211 void TryToPick(Actor
*source
, Door
*tgt
);
212 void TryToPick(Actor
*source
, Container
*tgt
);
213 void TryToDisarm(Actor
*source
, InfoPoint
*tgt
);
214 void PerformActionOn(Actor
*actor
);
217 int GetCursorOverContainer(Container
*overContainer
);
218 void HandleContainer(Container
*container
, Actor
*actor
);
220 int GetCursorOverDoor(Door
*overDoor
);
221 void HandleDoor(Door
*door
, Actor
*actor
);
223 int GetCursorOverInfoPoint(InfoPoint
*overInfoPoint
);
224 bool HandleActiveRegion(InfoPoint
*trap
, Actor
*actor
, Point
&p
);
226 Point
GetFormationOffset(ieDword formation
, ieDword pos
);
227 void MoveToPointFormation(Actor
*actor
, unsigned int pos
, Point src
, Point p
);
228 /** calls MoveToPoint or RunToPoint */
229 void CreateMovement(Actor
*actor
, const Point
&p
);
230 int InitDialog(Scriptable
* speaker
, Scriptable
* target
, const char* dlgref
);
231 void EndDialog(bool try_to_break
=false);
232 void DialogChoose(unsigned int choose
);
233 /** Displays a string over an object */
234 void DisplayString(Scriptable
* target
);
235 /** Displays a string on screen */
236 void DisplayString(const Point
&p
, const char *Text
);
237 Actor
*GetLastActor();
238 /** changes map to the current PC */
239 void ChangeMap(Actor
*pc
, bool forced
);
240 /** Returns game screenshot, with or without GUI controls */
241 Sprite2D
* GetScreenshot( bool show_gui
= 0 );
242 /** Returns current area preview for saving a game */
243 Sprite2D
* GetPreview();
244 /** Returns PC portrait for a currently running game */
245 Sprite2D
* GetPortraitPreview(int pcslot
);
246 /** Sets up targeting with spells or items */
247 void SetupItemUse(int slot
, int header
, Actor
*actor
, int targettype
, int cnt
);
248 /** Page is the spell type + spell level info */
249 void SetupCasting(int type
, int level
, int slot
, Actor
*actor
, int targettype
, int cnt
);
250 bool SetEvent(int eventType
, const char *handler
);