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

Commit c769c31

Browse files
committed
Lua capabilities for icons in the form of a Primitive function and width/height getters
1 parent effd887 commit c769c31

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

Entities/MOSprite.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,17 @@ class MOSprite : public MovableObject {
393393
/// <returns>The graphical representation of this MOSprite as a BITMAP.</returns>
394394
BITMAP *GetGraphicalIcon() const override { return m_GraphicalIcon != nullptr ? m_GraphicalIcon : m_aSprite[0]; }
395395

396+
/// <summary>
397+
/// Gets the width of this MOSprite's GUI icon.
398+
/// </summary>
399+
/// <returns>The width of the GUI icon bitmap.</returns>
400+
int GetIconWidth() const { return GetGraphicalIcon()->w; }
401+
402+
/// <summary>
403+
/// Gets the height of this MOSprite's GUI icon.
404+
/// </summary>
405+
/// <returns>The height of the GUI icon bitmap.</returns>
406+
int GetIconHeight() const { return GetGraphicalIcon()->h; }
396407

397408

398409
//////////////////////////////////////////////////////////////////////////////////////////

Lua/LuaBindingsEntities.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,8 @@ namespace RTE {
792792
.def("FacingAngle", &MOSprite::FacingAngle)
793793
.def("GetSpriteWidth", &MOSprite::GetSpriteWidth)
794794
.def("GetSpriteHeight", &MOSprite::GetSpriteHeight)
795+
.def("GetIconWidth", &MOSprite::GetIconWidth)
796+
.def("GetIconHeight", &MOSprite::GetIconHeight)
795797
.def("SetEntryWound", &MOSprite::SetEntryWound)
796798
.def("SetExitWound", &MOSprite::SetExitWound)
797799
.def("GetEntryWoundPresetName", &MOSprite::GetEntryWoundPresetName)

Lua/LuaBindingsManagers.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,9 @@ namespace RTE {
229229
.def("DrawBitmapPrimitive", (void (PrimitiveMan::*)(const Vector &start, Entity *entity, float rotAngle, int frame))&PrimitiveMan::DrawBitmapPrimitive)
230230
.def("DrawBitmapPrimitive", (void (PrimitiveMan::*)(const Vector &start, Entity *entity, float rotAngle, int frame, bool hFlipped, bool vFlipped))&PrimitiveMan::DrawBitmapPrimitive)
231231
.def("DrawBitmapPrimitive", (void (PrimitiveMan::*)(int player, const Vector &start, Entity *entity, float rotAngle, int frame))&PrimitiveMan::DrawBitmapPrimitive)
232-
.def("DrawBitmapPrimitive", (void (PrimitiveMan::*)(int player, const Vector &start, Entity *entity, float rotAngle, int frame, bool hFlipped, bool vFlipped))&PrimitiveMan::DrawBitmapPrimitive);
232+
.def("DrawBitmapPrimitive", (void (PrimitiveMan::*)(int player, const Vector &start, Entity *entity, float rotAngle, int frame, bool hFlipped, bool vFlipped))&PrimitiveMan::DrawBitmapPrimitive)
233+
.def("DrawIconPrimitive", (void (PrimitiveMan::*)(const Vector &start, Entity *entity))&PrimitiveMan::DrawIconPrimitive)
234+
.def("DrawIconPrimitive", (void (PrimitiveMan::*)(int player, const Vector &start, Entity *entity))&PrimitiveMan::DrawIconPrimitive);
233235
}
234236

235237
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Managers/PrimitiveMan.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ namespace RTE {
1414
}
1515
}
1616

17+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
18+
19+
void PrimitiveMan::DrawIconPrimitive(int player, const Vector &centerPos, Entity *entity) {
20+
if (const MOSprite *moSprite = dynamic_cast<MOSprite *>(entity)) { m_ScheduledPrimitives.push_back(std::make_unique<BitmapPrimitive>(player, centerPos, moSprite->GetGraphicalIcon(), 0, false, false)); }
21+
}
22+
1723
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1824

1925
void PrimitiveMan::DrawPrimitives(int player, BITMAP *targetBitmap, const Vector &targetPos) const {

Managers/PrimitiveMan.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,21 @@ namespace RTE {
364364
/// <param name="hFlipped">Whether to flip the sprite horizontally.</param>
365365
/// <param name="vFlipped">Whether to flip the sprite vertically.</param>
366366
void DrawBitmapPrimitive(int player, const Vector &centerPos, Entity *entity, float rotAngle, int frame, bool hFlipped, bool vFlipped);
367+
368+
/// <summary>
369+
/// Schedule to draw the GUI icon of an object.
370+
/// </summary>
371+
/// <param name="centerPos">Position of primitive's center in scene coordinates.</param>
372+
/// <param name="entity">An entity to draw sprite from.</param>
373+
void DrawIconPrimitive(const Vector &centerPos, Entity *entity) { DrawIconPrimitive(-1, centerPos, entity); }
374+
375+
/// <summary>
376+
/// Schedule to draw the GUI icon of an object, visible only to a specified player.
377+
/// </summary>
378+
/// <param name="player">Player screen to draw primitive on.</param>
379+
/// <param name="centerPos">Position of primitive's center in scene coordinates.</param>
380+
/// <param name="entity">An entity to draw sprite from.</param>
381+
void DrawIconPrimitive(int player, const Vector &centerPos, Entity *entity);
367382
#pragma endregion
368383

369384
protected:

0 commit comments

Comments
 (0)