Isle
Loading...
Searching...
No Matches
mxcontrolpresenter.cpp
Go to the documentation of this file.
2
3#include "define.h"
5#include "mxdsmultiaction.h"
6#include "mxmisc.h"
7#include "mxstillpresenter.h"
8#include "mxticklemanager.h"
9#include "mxtimer.h"
10#include "mxutilities.h"
11
12#include <assert.h>
13
15
16// FUNCTION: LEGO1 0x10043f50
18{
19 m_unk0x4c = 0;
20 m_unk0x4e = -1;
21 m_unk0x50 = FALSE;
22 m_unk0x52 = 0;
23 m_states = NULL;
24 m_unk0x54 = 0;
25}
26
27// FUNCTION: LEGO1 0x10044110
29{
30 if (m_states) {
31 delete m_states;
32 }
33}
34
35// FUNCTION: LEGO1 0x10044180
37{
38 m_unk0x4e = 0;
39 return SUCCESS;
40}
41
42// FUNCTION: LEGO1 0x10044190
44{
45 MxResult result = MxCompositePresenter::StartAction(p_controller, p_action);
46
48 ParseExtra();
49
50 MxS16 i = 0;
51 for (MxCompositePresenterList::iterator it = m_list.begin(); it != m_list.end(); it++) {
52 (*it)->Enable((m_unk0x4c != 3 || m_unk0x4e) && IsEnabled() ? m_unk0x4e == i : FALSE);
53 i++;
54 }
55
56 if (m_unk0x4c == 3) {
57 MxDSAction* action = (*m_list.begin())->GetAction();
58 action->SetFlags(action->GetFlags() | MxDSAction::c_bit11);
59 }
60
61 TickleManager()->RegisterClient(this, 200);
62
63 return result;
64}
65
66// FUNCTION: LEGO1 0x10044260
68{
69 if (m_action) {
70 m_unk0x50 = TRUE;
72 }
73}
74
75// FUNCTION: LEGO1 0x10044270
76// FUNCTION: BETA10 0x100eae68
78{
79 assert(p_presenter);
80 MxStillPresenter* presenter = (MxStillPresenter*) p_presenter;
81
82 if (m_unk0x4c == 3) {
84 assert(map && map->IsA("MxStillPresenter"));
85
86 if (presenter == map || map->GetDisplayZ() < presenter->GetDisplayZ()) {
87 if (map->VTable0x7c()) {
88 MxRect32 rect(0, 0, map->GetWidth() - 1, map->GetHeight() - 1);
89 rect += map->GetLocation();
90
91 if (rect.GetLeft() <= p_x && p_x < rect.GetRight() && rect.GetTop() <= p_y && p_y < rect.GetBottom()) {
92 // DECOMP: Beta uses GetBitmapStart() here, but that causes more diffs for retail.
93 MxU8* start = map->GetAlphaMask()
94 ? NULL
95 : map->GetBitmap()->GetStart(p_x - rect.GetLeft(), p_y - rect.GetTop());
96
97 m_unk0x56 = 0;
98 if (m_states) {
99 for (MxS16 i = 1; i <= *m_states; i++) {
100 // TODO: Can we match without the cast here?
101 if (m_states[i] == (MxS16) *start) {
102 m_unk0x56 = i;
103 break;
104 }
105 }
106 }
107 else {
108 if (*start != 0) {
109 m_unk0x56 = 1;
110 }
111 }
112
113 if (m_unk0x56) {
114 return TRUE;
115 }
116 }
117 }
118 }
119 }
120 else {
121 if (ContainsPresenter(m_list, presenter)) {
122 if (m_unk0x4c == 2) {
123 MxS32 width = presenter->GetWidth();
124 MxS32 height = presenter->GetHeight();
125
126 if (m_unk0x52 == 2 && m_unk0x54 == 2) {
127 if (p_x < presenter->GetX() + width / 2) {
128 m_unk0x56 = (p_y >= presenter->GetY() + height / 2) ? 3 : 1;
129 }
130 else {
131 m_unk0x56 = (p_y >= presenter->GetY() + height / 2) ? 4 : 2;
132 }
133 }
134 }
135 else {
136 m_unk0x56 = -1;
137 }
138
139 return TRUE;
140 }
141 }
142
143 return FALSE;
144}
145
146// FUNCTION: LEGO1 0x10044480
148{
149 if (IsEnabled()) {
150 switch (p_param->GetNotification()) {
152 if (m_unk0x4c == 0 || m_unk0x4c == 2 || m_unk0x4c == 3) {
155 VTable0x6c(0);
157 p_param->SetUnknown0x28(m_unk0x4e);
158 return TRUE;
159 }
160 break;
162 if (FUN_10044270(p_param->GetX(), p_param->GetY(), p_presenter)) {
165 VTable0x6c(m_unk0x56);
167 p_param->SetUnknown0x28(m_unk0x4e);
168 return TRUE;
169 }
170 break;
171 }
172 }
173
174 return FALSE;
175}
176
177// FUNCTION: LEGO1 0x10044540
179{
180 if (p_unk0x4e == -1) {
181 if ((MxS16) ((MxDSMultiAction*) m_action)->GetActionList()->GetNumElements() - m_unk0x4e == 1) {
182 m_unk0x4e = 0;
183 }
184 else {
185 m_unk0x4e++;
186 }
187 }
188 else {
189 m_unk0x4e = p_unk0x4e;
190 }
191
192 m_action->SetUnknown90(Timer()->GetTime());
193
194 MxS16 i = 0;
195 for (MxCompositePresenterList::iterator it = m_list.begin(); it != m_list.end(); it++) {
196 (*it)->Enable(((m_unk0x4c == 3 && m_unk0x4e == 0) || !IsEnabled()) ? FALSE : m_unk0x4e == i);
197 i++;
198 }
199}
200
201// FUNCTION: LEGO1 0x10044610
203{
207}
208
209// FUNCTION: LEGO1 0x10044640
210// FUNCTION: BETA10 0x100eb5e3
212{
213 MxU16 extraLength;
214 char* extraData;
215 m_action->GetExtra(extraLength, extraData);
216
217 if (extraLength) {
218 char extraCopy[256];
219 memcpy(extraCopy, extraData, extraLength);
220 extraCopy[extraLength] = '\0';
221
222 char output[256];
223 if (KeyValueStringParse(output, g_strSTYLE, extraCopy)) {
224 char* token = strtok(output, g_parseExtraTokens);
225
226 if (!strcmpi(token, g_strTOGGLE)) {
227 m_unk0x4c = 1;
228 }
229 else if (!strcmpi(token, g_strGRID)) {
230 m_unk0x4c = 2;
231 token = strtok(NULL, g_parseExtraTokens);
232 assert(token);
233 m_unk0x52 = atoi(token);
234
235 token = strtok(NULL, g_parseExtraTokens);
236 assert(token);
237 m_unk0x54 = atoi(token);
238 }
239 else if (!strcmpi(token, g_strMAP)) {
240 m_unk0x4c = 3;
241 token = strtok(NULL, g_parseExtraTokens);
242
243 if (token) {
244 MxS16 numStates = atoi(token);
245 m_states = new MxS16[numStates + 1];
246 assert(numStates);
247 *m_states = numStates;
248
249 for (MxS16 i = 1; i <= numStates; i++) {
250 token = strtok(NULL, g_parseExtraTokens);
251 assert(token);
252 m_states[i] = atoi(token);
253 }
254 }
255 }
256 else {
257 m_unk0x4c = 0;
258 }
259 }
260
261 if (KeyValueStringParse(output, g_strVISIBILITY, extraCopy)) {
262 if (!strcmpi(output, "FALSE")) {
263 Enable(FALSE);
264 }
265 }
266 }
267}
268
269// FUNCTION: LEGO1 0x10044820
271{
272 if (MxPresenter::IsEnabled() != p_enable) {
273 MxPresenter::Enable(p_enable);
274
275 MxS16 i = 0;
276 for (MxCompositePresenterList::iterator it = m_list.begin(); it != m_list.end(); it++) {
277 if (i == m_unk0x4e) {
278 (*it)->Enable((m_unk0x4c != 3 || i != 0) ? p_enable : 0);
279 break;
280 }
281
282 i++;
283 }
284
285 if (!p_enable) {
286 m_unk0x4e = 0;
287 }
288 }
289}
290
291// FUNCTION: LEGO1 0x100448a0
293{
294 MxCompositePresenterList::const_iterator it = m_list.begin();
295
296#ifdef COMPAT_MODE
297 advance(it, m_unk0x4e);
298#else
299 // Uses forward iterator logic instead of bidrectional for some reason.
300 _Advance(it, m_unk0x4e, forward_iterator_tag());
301#endif
302
303 return (*it)->HasTickleStatePassed(p_tickleState);
304}
[AI] Notification parameter for the LegoControlManager, used to propagate information about control e...
void SetClickedObjectId(MxS32 p_clickedObjectId)
[AI] Sets the object ID of the clicked control/presenter.
void SetUnknown0x28(MxS16 p_unk0x28)
[AI] Sets the value of the unknown field at offset 0x28.
void SetClickedAtom(const char *p_clickedAtom)
[AI] Sets the atom string that identifies the clicked control.
MxS32 GetY() const
Returns Y (vertical) coordinate for the event, usually screen-relative in pixels.
MxS32 GetX() const
Returns X (horizontal) coordinate for the event, usually screen-relative in pixels.
const char * GetInternal() const
[AI] Returns a pointer to the internal string, or nullptr if not set.
Definition: mxatom.h:194
void EndAction() override
[AI] Ends the composite action, terminating all child presenters and clearing action lists....
MxCompositePresenterList m_list
[AI] List of owned child presenters that are managed by this MxCompositePresenter....
MxResult StartAction(MxStreamController *p_controller, MxDSAction *p_action) override
[AI] Starts a composite action by creating child presenters for each action in a MxDSMultiAction list...
[AI] Presenter for UI controls, supporting toggles, grids, and "map" style controls with multiple int...
MxResult StartAction(MxStreamController *, MxDSAction *) override
[AI] Starts a new UI control action, configuring sub-presenters as required and enabling/disabling th...
void ReadyTickle() override
[AI] Handles transition into the 'ready' tickle state; disables tickling and advances state.
MxBool FUN_10044270(MxS32 p_x, MxS32 p_y, MxPresenter *p_presenter)
[AI] Tests if an input event at position (x, y) targets the supplied presenter's region as defined by...
void Enable(MxBool p_enable) override
[AI] Enables or disables the control; delegates enable to correct sub-presenter based on current stat...
MxResult AddToManager() override
[AI] Registers this presenter with the tickle manager and prepares for input handling.
~MxControlPresenter() override
[AI] Destructor, cleans up internal state memory.
virtual void VTable0x6c(MxS16 p_unk0x4e)
[AI] Selects a state/sub-control by index, or advances the currently selected state if -1 is provided...
MxBool HasTickleStatePassed(TickleState p_tickleState) override
[AI] Checks if a specific tickle state has passed for the currently active sub-presenter,...
void EndAction() override
[AI] Handles ending of a control's action; may fire notifications and update internal flags.
MxBool FUN_10044480(LegoControlManagerNotificationParam *p_param, MxPresenter *p_presenter)
[AI] Processes a notification param and presenter, reacting to input or click events; sets notificati...
void ParseExtra() override
[AI] Parses any configuration/customization provided in the extra data for the action,...
[AI] Represents an action deserialized from SI chunks, holding key animation or script parameters suc...
Definition: mxdsaction.h:17
MxU32 GetFlags()
[AI] Returns the flag field for this action (bitmask).
Definition: mxdsaction.h:177
void GetExtra(MxU16 &p_extraLength, char *&p_extraData)
[AI] Retrieves the extra data and its length for this action.
Definition: mxdsaction.h:168
virtual void SetUnknown90(MxLong p_unk0x90)
[AI] Set unknown value at offset 0x90, used as baseline in GetElapsedTime.
Definition: mxdsaction.cpp:60
void SetFlags(MxU32 p_flags)
[AI] Sets the flag bitmask controlling action logic (enabled, looping, etc).
Definition: mxdsaction.h:183
@ c_looping
[AI] Action or media should repeat in a loop [AI]
Definition: mxdsaction.h:21
@ c_world
[AI] Action is described in world-space coordinates [AI]
Definition: mxdsaction.h:27
@ c_bit11
[AI] Unknown - possibly reserved [AI]
Definition: mxdsaction.h:30
[AI] Represents a container for multiple MxDSAction objects, facilitating the grouping and management...
const MxAtomId & GetAtomId()
[AI] Returns a const-reference to the object's atom identifier.
Definition: mxdsobject.h:133
MxU32 GetObjectId()
[AI] Returns the object id numeric value.
Definition: mxdsobject.h:130
NotificationId GetNotification() const
[AI] Retrieves the current notification type of this parameter.
void SetNotification(NotificationId p_type)
[AI] Sets the notification type for this parameter object.
[AI] Abstract base class for all presenter types in the LEGO Island engine, responsible for managing ...
Definition: mxpresenter.h:20
virtual void ParseExtra()
[AI] Parses additional data from the associated action for configuration or world interaction.
Definition: mxpresenter.cpp:80
void ProgressTickleState(TickleState p_tickleState)
[AI] Helper for advancing the presenter's tickle state and updating transition history.
Definition: mxpresenter.h:72
virtual void Enable(MxBool p_enable)
[AI] Enables or disables this presenter (controls action flags accordingly).
MxBool IsEnabled()
[AI] Returns whether this presenter is logically enabled (based on the associated action's flags).
MxDSAction * m_action
[AI] The associated action currently being presented by this presenter.
Definition: mxpresenter.h:211
MxS32 GetX() const
[AI] Returns the X coordinate of screen location.
Definition: mxpresenter.h:166
MxS32 GetDisplayZ() const
[AI] Returns the display Z (depth) order.
Definition: mxpresenter.h:172
MxS32 GetY() const
[AI] Returns the Y coordinate of screen location.
Definition: mxpresenter.h:169
TickleState
[AI] Represents the state of the presenter's tickle (update) lifecycle.
Definition: mxpresenter.h:23
@ e_repeating
[AI] Presentation is repeating (e.g., looping media).
Definition: mxpresenter.h:28
MxDSAction * GetAction() const
[AI] Returns the current action being presented.
Definition: mxpresenter.h:175
[AI] Rectangle using 32-bit signed integer coordinates.
Definition: mxgeometry.h:706
T GetTop() const
[AI] Get the top edge.
Definition: mxgeometry.h:231
T GetRight() const
[AI] Get the right edge.
Definition: mxgeometry.h:241
T GetLeft() const
[AI] Get the left edge.
Definition: mxgeometry.h:221
T GetBottom() const
[AI] Get the bottom edge.
Definition: mxgeometry.h:251
[AI] Presenter for single still image/bitmap media sources in the game.
[AI] Controller for streaming and managing multimedia resources and actions during gameplay.
virtual void UnregisterClient(MxCore *p_client)
[AI] Unregisters (marks for destruction) a previously registered client.
virtual void RegisterClient(MxCore *p_client, MxTime p_interval)
[AI] Registers an MxCore object to receive periodic tickles.
virtual MxS32 GetHeight()
Returns the height of the current bitmap or alpha mask in pixels.
virtual MxS32 GetWidth()
Returns the width of the current bitmap or alpha mask in pixels.
#define TRUE
Definition: d3drmdef.h:28
#define FALSE
Definition: d3drmdef.h:27
#define DECOMP_SIZE_ASSERT(T, S)
Definition: decomp.h:19
const char * g_strMAP
[AI] Script or configuration keyword for defining or referencing a map entity.
Definition: define.cpp:37
const char * g_parseExtraTokens
[AI] Delimiter tokens for parsing extra parameters in scripts or command strings.
Definition: define.cpp:141
const char * g_strGRID
[AI] Used for identifying or interacting with grid-based maps or layouts.
Definition: define.cpp:33
const char * g_strSTYLE
[AI] String to specify styles, possibly for GUI, animation, or entity appearance.
Definition: define.cpp:29
const char * g_strTOGGLE
[AI] Used to toggle boolean states for properties or actions in scripting/config files.
Definition: define.cpp:41
const char * g_strVISIBILITY
[AI] Used when specifying visibility toggles or changes for objects/entities in scripting.
Definition: define.cpp:121
#define NULL
[AI] Null pointer value (C/C++ semantics).
Definition: legotypes.h:26
#define SUCCESS
[AI] Used to indicate a successful operation in result codes.
Definition: legotypes.h:30
MxTimer * Timer()
[AI] Returns the global simulation timer.
Definition: mxmisc.cpp:33
MxTickleManager * TickleManager()
[AI] Provides access to the global tickle manager.
Definition: mxmisc.cpp:25
@ c_notificationControl
[AI] UI control event [AI]
@ c_notificationButtonUp
[AI] Mouse/gamepad button release [AI]
@ c_notificationButtonDown
[AI] Mouse/gamepad button press [AI]
#define map
[AI] Macro alias for Map<K, T, Pr>, replacing std::map<T>.
Definition: mxstl.h:411
MxU8 MxBool
[AI]
Definition: mxtypes.h:124
MxLong MxResult
[AI]
Definition: mxtypes.h:106
signed short MxS16
[AI]
Definition: mxtypes.h:26
unsigned char MxU8
[AI]
Definition: mxtypes.h:8
signed int MxS32
[AI]
Definition: mxtypes.h:38
unsigned short MxU16
[AI]
Definition: mxtypes.h:20
MxBool KeyValueStringParse(char *, const char *, const char *)
Searches p_string for a key command and copies its associated value to p_output.
Definition: mxutilities.cpp:85
void FUN_100b7220(MxDSAction *p_action, MxU32 p_newFlags, MxBool p_setFlags)
Recursively sets or clears flags for an MxDSAction and all sub-actions if applicable.
MxBool ContainsPresenter(MxCompositePresenterList &p_presenterList, MxPresenter *p_presenter)
Determines if a presenter exists within a composite presenter hierarchy.