mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-05-10 04:26:42 +03:00
Move GameScriptDisplayString over to Scripting.
This commit is contained in:
parent
610b736572
commit
2889a62704
9 changed files with 12 additions and 12 deletions
82
Scripting/include/GameScriptDisplayString.h
Normal file
82
Scripting/include/GameScriptDisplayString.h
Normal file
|
@ -0,0 +1,82 @@
|
|||
#pragma once
|
||||
#include "GameScriptColor.h"
|
||||
|
||||
enum class DisplayStringOptions : size_t
|
||||
{
|
||||
CENTER,
|
||||
OUTLINE,
|
||||
NUM_OPTIONS
|
||||
};
|
||||
|
||||
static const std::unordered_map<std::string, DisplayStringOptions> kDisplayStringOptionNames
|
||||
{
|
||||
{"CENTER", DisplayStringOptions::CENTER},
|
||||
{"SHADOW", DisplayStringOptions::OUTLINE}
|
||||
};
|
||||
|
||||
using FlagArray = std::array<bool, static_cast<size_t>(DisplayStringOptions::NUM_OPTIONS)>;
|
||||
// Used to store data used to render the string.
|
||||
// This is separate from GameScriptDisplayString because the lifetimes
|
||||
// of the classes differ slightly.
|
||||
class UserDisplayString
|
||||
{
|
||||
public:
|
||||
UserDisplayString(std::string const& key, int x, int y, D3DCOLOR col, FlagArray const & flags, bool translated);
|
||||
|
||||
private:
|
||||
UserDisplayString() = default;
|
||||
std::string m_key{};
|
||||
D3DCOLOR m_color{ 0xFFFFFFFF };
|
||||
FlagArray m_flags{};
|
||||
int m_x{ 0 };
|
||||
int m_y{ 0 };
|
||||
bool m_deleteWhenZero{ false };
|
||||
|
||||
//seconds
|
||||
float m_timeRemaining{ 0.0f };
|
||||
bool m_isInfinite{ false };
|
||||
bool m_isTranslated{ false };
|
||||
friend class GameScript;
|
||||
friend class GameScriptDisplayString;
|
||||
};
|
||||
|
||||
using DisplayStringIDType = uintptr_t;
|
||||
using SetItemCallback = std::function<bool(DisplayStringIDType, UserDisplayString const&)>;
|
||||
using RemoveItemCallback = std::function<bool(DisplayStringIDType)>;
|
||||
using GetItemCallback = std::function<std::optional<std::reference_wrapper<UserDisplayString>>(DisplayStringIDType)>;
|
||||
|
||||
|
||||
class GameScriptDisplayString
|
||||
{
|
||||
private:
|
||||
DisplayStringIDType m_id{ 0 };
|
||||
public:
|
||||
GameScriptDisplayString();
|
||||
~GameScriptDisplayString();
|
||||
DisplayStringIDType GetID() const;
|
||||
static void Register(sol::state* state);
|
||||
|
||||
void SetPos(int x, int y);
|
||||
std::tuple<int, int> GetPos() const;
|
||||
|
||||
void SetCol(GameScriptColor const&);
|
||||
GameScriptColor GetCol();
|
||||
|
||||
void SetKey(std::string const&);
|
||||
std::string GetKey() const;
|
||||
|
||||
static SetItemCallback s_setItemCallback;
|
||||
static RemoveItemCallback s_removeItemCallback;
|
||||
static GetItemCallback s_getItemCallback;
|
||||
|
||||
// Creating a GameScriptDisplayString requires us to add an identifier
|
||||
// to a data structure. We use callbacks so this class doesn't have
|
||||
// to know about said data structure.
|
||||
static void SetCallbacks(SetItemCallback cba, RemoveItemCallback cbr, GetItemCallback cbg)
|
||||
{
|
||||
s_setItemCallback = cba;
|
||||
s_removeItemCallback = cbr;
|
||||
s_getItemCallback = cbg;
|
||||
}
|
||||
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue