DDraceNetwork Docs
quick_action.h
Go to the documentation of this file.
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
13{
14private:
15 const char *m_pLabel;
16 const char *m_pDescription;
17
22
23 const char m_ActionButtonId = 0;
24
25public:
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(m_pLabel, ": ");
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
Definition: quick_action.h:13
const char * m_pLabel
Definition: quick_action.h:15
const char * Description() const
Definition: quick_action.h:68
bool Active()
Definition: quick_action.h:50
const char * m_pDescription
Definition: quick_action.h:16
FButtonActiveCallback m_pfnActiveCallback
Definition: quick_action.h:20
CQuickAction(const char *pLabel, const char *pDescription, FButtonClickCallback pfnCallback, FButtonDisabledCallback pfnDisabledCallback, FButtonActiveCallback pfnActiveCallback, FButtonColorCallback pfnColorCallback)
Definition: quick_action.h:26
const void * ActionButtonId() const
Definition: quick_action.h:70
FButtonDisabledCallback m_pfnDisabledCallback
Definition: quick_action.h:19
const char * Label() const
Definition: quick_action.h:56
const char m_ActionButtonId
Definition: quick_action.h:23
FButtonColorCallback m_pfnColorCallback
Definition: quick_action.h:21
int Color()
Definition: quick_action.h:54
FButtonClickCallback m_pfnCallback
Definition: quick_action.h:18
const char * LabelShort() const
Definition: quick_action.h:60
void Call() const
Definition: quick_action.h:43
bool Disabled()
Definition: quick_action.h:46
std::function< bool()> FButtonActiveCallback
Definition: quick_action.h:9
std::function< void()> FButtonClickCallback
Definition: quick_action.h:7
std::function< int()> FButtonColorCallback
Definition: quick_action.h:10
std::function< bool()> FButtonDisabledCallback
Definition: quick_action.h:8
const char * str_find(const char *haystack, const char *needle)
Definition: system.cpp:3146