-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathModificationExample.php
More file actions
161 lines (141 loc) · 5.47 KB
/
ModificationExample.php
File metadata and controls
161 lines (141 loc) · 5.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
namespace refaltor\roots;
use refaltor\ui\builders\Root;
use refaltor\ui\builders\RootBuild;
use refaltor\ui\components\Binding;
use refaltor\ui\components\Modification;
use refaltor\ui\elements\Label;
use refaltor\ui\elements\Panel;
use refaltor\ui\elements\Element;
/**
* ModificationExample - Demonstrates the Modification system.
*
* Shows: insert_back, insert_front, insert_after, insert_before,
* remove, replace, swap, move operations, and vanilla element modifications.
*/
class ModificationExample implements RootBuild
{
public function root(): Root
{
$root = Root::create();
// --- Element-level modifications ---
// A panel that modifies its controls array
$panel = Panel::create("modified_panel")
->setSizePercentage(100, 100)
->addModification(
Modification::insertBack(Modification::ARRAY_CONTROLS)
->setValue([
["injected_label@common.empty_panel" => []]
])
)
->addModification(
Modification::insertFront(Modification::ARRAY_CONTROLS)
->setValue([
["priority_label@common.empty_panel" => []]
])
);
// A panel demonstrating binding modifications
$bindingPanel = Panel::create("binding_modified_panel")
->setSize(200, 100)
->setAnchorFrom(Element::ANCHOR_CENTER)
->setAnchorTo(Element::ANCHOR_CENTER)
->addBinding(Binding::global("#title_text"))
->addModification(
Modification::insertBack(Modification::ARRAY_BINDINGS)
->setValue([
[
"binding_type" => "view",
"source_property_name" => "(not (#title_text = ''))",
"target_property_name" => "#visible",
]
])
);
// A panel demonstrating remove modification
$removePanel = Panel::create("cleanup_panel")
->setSize(100, 100)
->addModification(
Modification::remove(Modification::ARRAY_BINDINGS, [
"binding_name" => "#obsolete_binding"
])
);
// A panel demonstrating replace modification
$replacePanel = Panel::create("replace_panel")
->setSize(100, 100)
->addModification(
Modification::replace(Modification::ARRAY_BINDINGS, [
"binding_name" => "#old_binding"
])->setValue([
"binding_name" => "#new_binding",
"binding_type" => "global",
])
);
// A panel demonstrating swap modification
$swapPanel = Panel::create("swap_panel")
->setSize(100, 100)
->addModification(
Modification::swap(
Modification::ARRAY_BINDINGS,
["binding_name" => "#binding_a"],
["binding_name" => "#binding_b"]
)
);
// A panel demonstrating insert_after with control_name
$insertAfterPanel = Panel::create("ordered_panel")
->setSize(200, 200)
->addModification(
Modification::insertAfter("existing_control")
->setValue([
["new_control@common.empty_panel" => []]
])
);
// A panel demonstrating move operations
$movePanel = Panel::create("reorder_panel")
->setSize(200, 200)
->addModification(
Modification::moveFrontWhere(
Modification::ARRAY_BINDINGS,
["binding_name" => "#important_binding"]
)
);
$panel->addChilds([$bindingPanel, $removePanel, $replacePanel, $swapPanel, $insertAfterPanel, $movePanel]);
$root->addElement($panel);
// --- Vanilla element modifications (path syntax) ---
// Modify the HUD title text to hide when text equals a specific value
$root->modifyVanillaElement("hud_title_text/title_frame/title", [
Modification::insertBack(Modification::ARRAY_BINDINGS)
->setValue([
[
"binding_type" => "view",
"source_property_name" => "(not (#text = 'hidden_title'))",
"target_property_name" => "#visible",
]
]),
]);
// Add a custom control to the HUD
$root->modifyVanillaElement("hud_screen", [
Modification::insertBack(Modification::ARRAY_CONTROLS)
->setValue([
["custom_hud_element@" . $root->namespace . ".modified_panel" => []]
]),
]);
// Remove a binding from a vanilla element
$root->modifyVanillaElement("start_screen/play_button", [
Modification::remove(Modification::ARRAY_BINDINGS, [
"binding_name" => "#some_vanilla_binding"
]),
]);
return $root;
}
public function getNamespace(): string
{
return "modification_example";
}
public function getPathName(): string
{
return "./resources/pack_example/";
}
public function titleCondition(): string
{
return "MODIFICATION_EXAMPLE";
}
}