Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 19d4cef

Browse files
committed
Added MOSprite property IconFile which can be used to display a separate sprite in GUI elements.
1 parent 0330fe8 commit 19d4cef

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

Entities/MOSprite.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ void MOSprite::Clear()
3030
{
3131
m_SpriteFile.Reset();
3232
m_aSprite.clear();
33+
m_IconFile.Reset();
34+
m_GraphicalIcon = nullptr;
3335
m_FrameCount = 1;
3436
m_SpriteOffset.Reset();
3537
m_Frame = 0;
@@ -128,6 +130,8 @@ int MOSprite::Create(const MOSprite &reference)
128130
return -1;
129131

130132
m_SpriteFile = reference.m_SpriteFile;
133+
m_IconFile = reference.m_IconFile;
134+
m_GraphicalIcon = m_IconFile.GetAsBitmap();
131135

132136
m_FrameCount = reference.m_FrameCount;
133137
m_Frame = reference.m_Frame;
@@ -159,11 +163,13 @@ int MOSprite::Create(const MOSprite &reference)
159163
// is called. If the property isn't recognized by any of the base classes,
160164
// false is returned, and the reader's position is untouched.
161165

162-
int MOSprite::ReadProperty(const std::string_view &propName, Reader &reader)
163-
{
164-
if (propName == "SpriteFile")
165-
reader >> m_SpriteFile;
166-
else if (propName == "FrameCount") {
166+
int MOSprite::ReadProperty(const std::string_view &propName, Reader &reader) {
167+
if (propName == "SpriteFile") {
168+
reader >> m_SpriteFile;
169+
} else if (propName == "IconFile") {
170+
reader >> m_IconFile;
171+
m_GraphicalIcon = m_IconFile.GetAsBitmap();
172+
} else if (propName == "FrameCount") {
167173
reader >> m_FrameCount;
168174
m_aSprite.reserve(m_FrameCount);
169175
} else if (propName == "SpriteOffset")

Entities/MOSprite.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -387,16 +387,12 @@ class MOSprite : public MovableObject {
387387
void SetAngularVel(float newRotVel) override { m_AngularVel = newRotVel; }
388388

389389

390-
//////////////////////////////////////////////////////////////////////////////////////////
391-
// Method: GetGraphicalIcon
392-
//////////////////////////////////////////////////////////////////////////////////////////
393-
// Description: Gets a bitmap showing a good identifyable icon of this, for use in
394-
// GUI lists etc.
395-
// Arguments: None.
396-
// Return value: A good identifyable graphical representation of this in a BITMAP, if
397-
// available. If not, 0 is returned. Ownership is NOT TRANSFERRED!
390+
/// <summary>
391+
/// Gets the GUI representation of this MOSprite, either based on the first frame of its sprite or separately defined icon file.
392+
/// </summary>
393+
/// <returns>The graphical representation of this MOSprite as a BITMAP.</returns>
394+
BITMAP *GetGraphicalIcon() const override { return m_GraphicalIcon != nullptr ? m_GraphicalIcon : m_aSprite[0]; }
398395

399-
BITMAP * GetGraphicalIcon() const override { return m_aSprite[0]; }
400396

401397

402398
//////////////////////////////////////////////////////////////////////////////////////////
@@ -572,6 +568,8 @@ class MOSprite : public MovableObject {
572568
ContentFile m_SpriteFile;
573569
// Vector of pointers to BITMAPs representing the multiple frames of this sprite.
574570
std::vector<BITMAP *> m_aSprite;
571+
ContentFile m_IconFile; //!< The file containing the GUI icon.
572+
BITMAP *m_GraphicalIcon; //!< The GUI representation of this MOSprite as a BITMAP.
575573
// Number of frames, or elements in the m_aSprite array.
576574
unsigned int m_FrameCount;
577575
Vector m_SpriteOffset;

0 commit comments

Comments
 (0)