Isle
Loading...
Searching...
No Matches
legometerpresenter.cpp
Go to the documentation of this file.
2
3#include "decomp.h"
4#include "define.h"
5#include "mxbitmap.h"
6#include "mxdsaction.h"
7#include "mxmisc.h"
8#include "mxutilities.h"
9#include "mxvariabletable.h"
10
11#include <assert.h>
12
14
15// FUNCTION: LEGO1 0x10043430
16// FUNCTION: BETA10 0x10097570
18{
19 m_meterPixels = NULL;
20 m_fillColor = 1;
21 m_curPercent = 0;
22 m_layout = e_leftToRight;
23 m_flags.m_bit1 = FALSE;
24}
25
26// FUNCTION: LEGO1 0x10043780
27// FUNCTION: BETA10 0x1009764a
29{
30 delete m_meterPixels;
31}
32
33// FUNCTION: LEGO1 0x10043800
34// FUNCTION: BETA10 0x100976ec
36{
38
39 MxU16 extraLength;
40 char* extraData;
41 m_action->GetExtra(extraLength, extraData);
42
43 if (extraLength) {
44 char extraCopy[256];
45 memcpy(extraCopy, extraData, extraLength);
46 extraCopy[extraLength] = '\0';
47
48 char output[256];
49 if (KeyValueStringParse(output, g_strTYPE, extraCopy)) {
50 if (!strcmpi(output, g_strLEFT_TO_RIGHT)) {
51 m_layout = e_leftToRight;
52 }
53 else if (!strcmpi(output, g_strRIGHT_TO_LEFT)) {
54 m_layout = e_rightToLeft;
55 }
56 else if (!strcmpi(output, g_strBOTTOM_TO_TOP)) {
57 m_layout = e_bottomToTop;
58 }
59 else if (!strcmpi(output, g_strTOP_TO_BOTTOM)) {
60 m_layout = e_topToBottom;
61 }
62 }
63
64 if (KeyValueStringParse(output, g_strFILLER_INDEX, extraCopy)) {
65 m_fillColor = atoi(output);
66 }
67
68 if (KeyValueStringParse(output, g_strVARIABLE, extraCopy)) {
69 m_variable = output;
70 }
71 else {
72 assert(0);
73 EndAction();
74 }
75 }
76 else {
77 EndAction();
78 }
79}
80
81// FUNCTION: LEGO1 0x10043990
82// FUNCTION: BETA10 0x10097917
84{
86
87 m_meterPixels = new MxU8[m_frameBitmap->GetDataSize()];
88 if (m_meterPixels == NULL) {
89 assert(0);
90 EndAction();
91 }
92
93 memcpy(m_meterPixels, m_frameBitmap->GetImage(), m_frameBitmap->GetDataSize());
94
95 m_meterRect.SetLeft(0);
96 m_meterRect.SetTop(0);
97 m_meterRect.SetRight(m_frameBitmap->GetBmiWidth() - 1);
98 m_meterRect.SetBottom(m_frameBitmap->GetBmiHeightAbs() - 1);
99}
100
101// FUNCTION: LEGO1 0x10043a30
102// FUNCTION: BETA10 0x10097a1a
104{
105 DrawMeter();
107}
108
109// FUNCTION: LEGO1 0x10043a50
110// FUNCTION: BETA10 0x10097a40
111void LegoMeterPresenter::DrawMeter()
112{
113 const char* strval = VariableTable()->GetVariable(m_variable.GetData());
114 MxFloat percent = atof(strval);
115 MxS16 row, leftRightCol, bottomTopCol, leftRightEnd, bottomTopEnd;
116
117 if (strval != NULL && m_curPercent != percent) {
118 m_curPercent = percent;
119
120 // DECOMP: This clamp is retail only
121 if (percent > 0.99) {
122 m_curPercent = 0.99f;
123 }
124 else if (percent < 0.0) {
125 m_curPercent = 0.0f;
126 }
127
128 // Copy the previously drawn meter back into the bitmap
129 memcpy(m_frameBitmap->GetImage(), m_meterPixels, m_frameBitmap->GetDataSize());
130
131 switch (m_layout) {
132 case e_leftToRight:
133 leftRightEnd = m_meterRect.GetWidth() * m_curPercent;
134
135 for (row = m_meterRect.GetTop(); row < m_meterRect.GetBottom(); row++) {
136 MxU8* line = m_frameBitmap->GetStart(m_meterRect.GetLeft(), row);
137
138 for (leftRightCol = 0; leftRightCol < leftRightEnd; leftRightCol++, line++) {
139 if (*line) {
140 *line = m_fillColor;
141 }
142 }
143 }
144 break;
145 case e_bottomToTop:
146 bottomTopEnd = m_meterRect.GetBottom() - (MxS16) (m_meterRect.GetHeight() * m_curPercent);
147
148 for (row = m_meterRect.GetBottom(); row > bottomTopEnd; row--) {
149 MxU8* line = m_frameBitmap->GetStart(m_meterRect.GetLeft(), row);
150
151 for (bottomTopCol = 0; bottomTopCol < m_meterRect.GetWidth(); bottomTopCol++, line++) {
152 if (*line) {
153 *line = m_fillColor;
154 }
155 }
156 }
157 // break;
158 default:
159 // The other two fill options are not implemented.
160 break;
161 }
162 }
163}
Presenter class for displaying and updating a graphical meter element, such as a progress bar or heal...
~LegoMeterPresenter() override
Destructor for LegoMeterPresenter.
void ParseExtra() override
[AI] Parses the "extra" data chunk attached to this presenter for dynamic meter configuration.
void RepeatingTickle() override
[AI] Called every frame in the 'repeating' tickle phase, updates and redraws the meter based on curre...
void StreamingTickle() override
[AI] Performs initialization of the meter on first streaming update, copying original bitmap data and...
MxLong GetBmiHeightAbs() const
[AI] Returns the absolute value of the bitmap's height.
Definition: mxbitmap.h:242
MxU8 * GetStart(MxS32 p_left, MxS32 p_top) const
[AI] Returns a pointer to the starting address of the pixel data at the specified coordinates.
Definition: mxbitmap.h:288
MxLong GetDataSize() const
[AI] Computes the total size in bytes for the bitmap's pixel data buffer.
Definition: mxbitmap.h:260
MxLong GetBmiWidth() const
[AI] Fetches the width (in pixels) encoded in this bitmap's header.
Definition: mxbitmap.h:224
MxU8 * GetImage() const
[AI] Retrieves the pointer to the image pixel data.
Definition: mxbitmap.h:248
void GetExtra(MxU16 &p_extraLength, char *&p_extraData)
[AI] Retrieves the extra data and its length for this action.
Definition: mxdsaction.h:168
MxDSAction * m_action
[AI] The associated action currently being presented by this presenter.
Definition: mxpresenter.h:211
void SetLeft(T p_left)
[AI] Set the left edge.
Definition: mxgeometry.h:226
T GetTop() const
[AI] Get the top edge.
Definition: mxgeometry.h:231
T GetWidth() const
[AI] Get the rectangle's width.
Definition: mxgeometry.h:262
void SetBottom(T p_bottom)
[AI] Set the bottom edge.
Definition: mxgeometry.h:256
T GetHeight() const
[AI] Get the rectangle's height.
Definition: mxgeometry.h:268
T GetLeft() const
[AI] Get the left edge.
Definition: mxgeometry.h:221
void SetTop(T p_top)
[AI] Set the top edge.
Definition: mxgeometry.h:236
T GetBottom() const
[AI] Get the bottom edge.
Definition: mxgeometry.h:251
void SetRight(T p_right)
[AI] Set the right edge.
Definition: mxgeometry.h:246
void ParseExtra() override
[AI] Parses extra action data for bitmap configuration, such as visibility or image mapping,...
void RepeatingTickle() override
[AI] Repetition tickle logic—handles repeated action/time-based state changes.
void StreamingTickle() override
[AI] Main frame advancing logic, loads the next frame if the elapsed time is appropriate.
char * GetData() const
Returns a pointer to the internal character buffer.
Definition: mxstring.h:110
const char * GetVariable(const char *p_key)
Returns the value for the variable with a given key, or an empty string if not found.
MxBitmap * m_frameBitmap
Bitmap for current video frame. [AI].
void EndAction() override
Signals the end of the current playback action.
#define FALSE
Definition: d3drmdef.h:27
#define DECOMP_SIZE_ASSERT(T, S)
Definition: decomp.h:19
const char * g_strTOP_TO_BOTTOM
[AI] Used when referencing objects laid out or animated from top to bottom.
Definition: define.cpp:109
const char * g_strRIGHT_TO_LEFT
[AI] Used when referencing objects laid out or animated from right to left.
Definition: define.cpp:89
const char * g_strLEFT_TO_RIGHT
[AI] Used when referencing objects laid out or animated from left to right.
Definition: define.cpp:61
const char * g_strTYPE
[AI] Used to denote the type or class of an object/action in scripts or data files.
Definition: define.cpp:65
const char * g_strVARIABLE
[AI] Used for referencing variable assignment or lookup in script commands or tables.
Definition: define.cpp:117
const char * g_strBOTTOM_TO_TOP
[AI] Used when referencing objects laid out or animated from bottom to top.
Definition: define.cpp:21
const char * g_strFILLER_INDEX
[AI] Identifier string for special "filler" entity or material indices in definition files.
Definition: define.cpp:49
#define NULL
[AI] Null pointer value (C/C++ semantics).
Definition: legotypes.h:26
MxVariableTable * VariableTable()
[AI] Returns the variable table used for script variables and global key/value state.
Definition: mxmisc.cpp:73
signed short MxS16
[AI]
Definition: mxtypes.h:26
float MxFloat
[AI]
Definition: mxtypes.h:68
unsigned char MxU8
[AI]
Definition: mxtypes.h:8
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