Debian Codegraph @

include/ui/ientityinspector.h

raw
1 #pragma once
2
3 #include "imodule.h"
4
5 class Entity;
6 class wxPanel;
7 class wxWindow;
8 class IEntitySelection; // defined in ientity.h
9
10 namespace ui
11 {
12
13 /**
14 * greebo: Some entity property editors may implement this interface,
15 * to allow modules to call their dialog windows directly.
16 */
17 class IPropertyEditorDialog
18 {
19 public:
20 using Ptr = std::shared_ptr<IPropertyEditorDialog>;
21 using CreationFunc = std::function<Ptr()>;
22
23 virtual ~IPropertyEditorDialog() {}
24
25 /**
26 * greebo: Run the dialog, returning the new value for the named property.
27 */
28 virtual std::string runDialog(Entity* entity, const std::string& key) = 0;
29 };
30
31 /**
32 * Represents the key selection in the entity inspector.
33 * This can be the direct key like "model" or it can be a proxy setter,
34 * in the form of "set <key> on <attachment>" which are propagating
35 * key values to attached entities at spawn time.
36 */
37 class ITargetKey
38 {
39 public:
40 using Ptr = std::shared_ptr<ITargetKey>;
41
42 virtual ~ITargetKey() {}
43
44 // Returns the full string representation of this key, e.g. "classname" or "set _color on flame"
45 virtual std::string getFullKey() const = 0;
46
47 // The key this is affecting, either on this entity or an attachment
48 // ("set X on Y" style keys will return key part X).
49 virtual const std::string& getAffectedKey() const = 0;
50
51 // Modify the key this setter is affecting.
52 // Passing an empty key will throw an std::invalid_argument exception.
53 virtual void setAffectedKey(const std::string&) = 0;
54
55 // Returns true whether this is a "set X on Y" style key, or false if this a regular key
56 virtual bool isTargetingAttachment() const = 0;
57
58 // In case this a "set x on y" style key, this method returns the name of the attachment y
59 virtual const std::string& getAttachmentName() const = 0;
60
61 // Set the name of the attachment to modify. Assigning a non-empty name will
62 // make this key a "set x on y" setter, assigning an name will
63 // convert this to a regular entity key.
64 virtual void setAttachmentName(const std::string& name) = 0;
65
66 // Returns a new copy of this instance
67 virtual Ptr clone() const = 0;
68 };
69
70 /**
71 * Abstract base for a PropertyEditor which provides
72 * a user interface for editing spawnargs (entity keyvalues).
73 */
74 class IPropertyEditor
75 {
76 public:
77 using Ptr = std::shared_ptr<IPropertyEditor>;
78
79 /**
80 * Construction function object. This callable returns the new PropertyEditor instance.
81 *
82 * @param parent
83 * The parent window, needed by the code to pack the widgets of this editor.
84 *
85 * @param entities
86 * The Entity Set to interact with.
87 *
88 * @param key
89 * The key name which this PropertyEditor is displaying.
90 */
91 using CreationFunc = std::function<Ptr(wxWindow*, IEntitySelection&, const ITargetKey::Ptr& key)>;
92
93 virtual ~IPropertyEditor() {}
94
95 /**
96 * greebo: Retrieve the widget for packing this into a parent container.
97 */
98 virtual wxPanel* getWidget() = 0;
99
100 /**
101 * Instructs the editor to update its widgets from the edited entity's key values.
102 */
103 virtual void updateFromEntities() = 0;
104
105 /**
106 * A signal that is emitted when a key value has been applied to one or more selected entities.
107 * (This is used as a feedback channel for the EntityInspector UI to get notified when
108 * a value has been set, such that the text entry boxes can follow along.)
109 */
110 virtual sigc::signal<void(const std::string&, const std::string&)>& signal_keyValueApplied() = 0;
111 };
112
113 class IEntityInspectorModule :
114 public RegisterableModule
115 {
116 public:
117 /**
118 * Registers the given property editor and associates it with the given entity key.
119 * (The string key is interpreted as regular expression.)
120 */
121 virtual void registerPropertyEditor(const std::string& key, const IPropertyEditor::CreationFunc& create) = 0;
122
123 /**
124 * Removes the property editor for the given key.
125 */
126 virtual void unregisterPropertyEditor(const std::string& key) = 0;
127
128 // Dialog Handling
129
130 virtual void registerPropertyEditorDialog(const std::string& key, const IPropertyEditorDialog::CreationFunc& create) = 0;
131 virtual IPropertyEditorDialog::Ptr createDialog(const std::string& key) = 0;
132 virtual void unregisterPropertyEditorDialog(const std::string& key) = 0;
133 };
134
135 } // namespace ui
136
137 constexpr const char* const MODULE_ENTITYINSPECTOR("EntityInspector");
138
139 inline ui::IEntityInspectorModule& GlobalEntityInspector()
140 {
141 static module::InstanceReference<ui::IEntityInspectorModule> _reference(MODULE_ENTITYINSPECTOR);
142 return _reference;
143 }