1#ifndef GAME_EDITOR_QUICK_ACTION_H
2#define GAME_EDITOR_QUICK_ACTION_H
3
4#include <functional>
5#include <utility>
6
7typedef std::function<void()> FButtonClickCallback;
8typedef std::function<bool()> FButtonDisabledCallback;
9typedef std::function<bool()> FButtonActiveCallback;
10typedef std::function<int()> FButtonColorCallback;
11
12class CQuickAction
13{
14private:
15 const char *m_pLabel;
16 const char *m_pDescription;
17
18 FButtonClickCallback m_pfnCallback;
19 FButtonDisabledCallback m_pfnDisabledCallback;
20 FButtonActiveCallback m_pfnActiveCallback;
21 FButtonColorCallback m_pfnColorCallback;
22
23 const char m_ActionButtonId = 0;
24
25public:
26 CQuickAction(
27 const char *pLabel,
28 const char *pDescription,
29 FButtonClickCallback pfnCallback,
30 FButtonDisabledCallback pfnDisabledCallback,
31 FButtonActiveCallback pfnActiveCallback,
32 FButtonColorCallback pfnColorCallback) :
33 m_pLabel(pLabel),
34 m_pDescription(pDescription),
35 m_pfnCallback(std::move(pfnCallback)),
36 m_pfnDisabledCallback(std::move(pfnDisabledCallback)),
37 m_pfnActiveCallback(std::move(pfnActiveCallback)),
38 m_pfnColorCallback(std::move(pfnColorCallback))
39 {
40 }
41
42 // code to run when the action is triggered
43 void Call() const { m_pfnCallback(); }
44
45 // bool that indicates if the action can be performed not or not
46 bool Disabled() { return m_pfnDisabledCallback(); }
47
48 // bool that indicates if the action is currently running
49 // only applies to actions that can be turned on or off like proof borders
50 bool Active() { return m_pfnActiveCallback(); }
51
52 // color "enum" that represents the state of the quick actions button
53 // used as Checked argument for DoButton_Editor()
54 int Color() { return m_pfnColorCallback(); }
55
56 const char *Label() const { return m_pLabel; }
57
58 // skips to the part of the label after the first colon
59 // useful for buttons that only show the state
60 const char *LabelShort() const
61 {
62 const char *pShort = str_find(haystack: m_pLabel, needle: ": ");
63 if(!pShort)
64 return m_pLabel;
65 return pShort + 2;
66 }
67
68 const char *Description() const { return m_pDescription; }
69
70 const void *ActionButtonId() const { return &m_ActionButtonId; }
71};
72
73#endif
74