-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathVariableExample.php
More file actions
183 lines (163 loc) · 6.18 KB
/
VariableExample.php
File metadata and controls
183 lines (163 loc) · 6.18 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
namespace refaltor\roots;
use refaltor\ui\builders\Root;
use refaltor\ui\builders\RootBuild;
use refaltor\ui\colors\BasicColor;
use refaltor\ui\components\Variable;
use refaltor\ui\elements\Element;
use refaltor\ui\elements\Image;
use refaltor\ui\elements\Label;
use refaltor\ui\elements\Panel;
use refaltor\ui\elements\StackPanel;
use refaltor\ui\helpers\OrientationHelper;
/**
* VariableExample - Demonstrates the Variable (conditional) system.
*
* Shows: conditional variables, platform-specific sizing,
* gamepad vs touch vs keyboard layouts, multiple variables.
*/
class VariableExample implements RootBuild
{
public function root(): Root
{
$root = Root::create();
$mainPanel = Panel::create("variable_container")
->setSizePercentage(100, 100);
// Background
$bg = Image::create("variable_bg", "textures/ui/dialog_background_opaque")
->setSizePercentage(100, 100)
->setNinesliceSize(4)
->setLayer(-1);
$mainPanel->addChild($bg);
// Title
$title = Label::create("variable_title", "Variable Examples")
->setFontSize(Label::FONT_EXTRA_LARGE)
->setShadow()
->setColor(BasicColor::yellow())
->setAnchorFrom(Element::ANCHOR_TOP_MIDDLE)
->setAnchorTo(Element::ANCHOR_TOP_MIDDLE)
->setOffset(0, 10);
$mainPanel->addChild($title);
$stack = StackPanel::create("variable_stack")
->setOrientation(OrientationHelper::VERTICAL)
->setSize(300, 250)
->setAnchorFrom(Element::ANCHOR_CENTER)
->setAnchorTo(Element::ANCHOR_CENTER);
// Panel with platform-dependent size using variables
$platformPanel = Panel::create("platform_panel")
->setCustomSize(['$panel_width', '$panel_height'])
->addVariable(
Variable::when("$is_holographic", [
'$panel_width' => 400,
'$panel_height' => 300,
])
)
->addVariable(
Variable::when("$pocket_screen", [
'$panel_width' => 200,
'$panel_height' => 150,
])
)
->addVariable(
Variable::when("(not $is_holographic and not $pocket_screen)", [
'$panel_width' => 300,
'$panel_height' => 200,
])
);
$platformLabel = Label::create("platform_label", "Size adapts to platform!")
->setFontSize(Label::FONT_NORMAL)
->setColor(BasicColor::cyan())
->setShadow()
->setAnchorFrom(Element::ANCHOR_CENTER)
->setAnchorTo(Element::ANCHOR_CENTER);
$platformPanel->addChild($platformLabel);
$stack->addChild($platformPanel);
// Input-mode dependent text using variables
$inputPanel = Panel::create("input_mode_panel")
->setSize(280, 40)
->addVariable(
Variable::when("$is_using_gamepad", [
'$action_text' => "Press A to continue",
'$text_color' => BasicColor::green(),
])
)
->addVariable(
Variable::when("$touch", [
'$action_text' => "Tap to continue",
'$text_color' => BasicColor::cyan(),
])
)
->addVariable(
Variable::when("(not $is_using_gamepad and not $touch)", [
'$action_text' => "Click to continue",
'$text_color' => BasicColor::white(),
])
);
$inputLabel = Label::create("input_label", '$action_text')
->setFontSize(Label::FONT_LARGE)
->setShadow()
->setAnchorFrom(Element::ANCHOR_CENTER)
->setAnchorTo(Element::ANCHOR_CENTER);
$inputPanel->addChild($inputLabel);
$stack->addChild($inputPanel);
// Panel visible only on certain screen size
$widePanel = Panel::create("wide_screen_only")
->setSize(280, 30)
->addVariable(
Variable::when("$desktop_screen", [
'$show_extra_info' => true,
])
)
->addVariable(
Variable::when("(not $desktop_screen)", [
'$show_extra_info' => false,
])
);
$wideLabel = Label::create("wide_label", "Desktop-only extra info panel")
->setFontSize(Label::FONT_SMALL)
->setColor(BasicColor::rgb(0.8, 0.8, 0.3))
->setShadow()
->setAnchorFrom(Element::ANCHOR_CENTER)
->setAnchorTo(Element::ANCHOR_CENTER);
$widePanel->addChild($wideLabel);
$stack->addChild($widePanel);
// Multiple variables on one element (stacked conditions)
$multiVarPanel = Panel::create("multi_var_panel")
->setCustomSize(['$mv_width', '$mv_height'])
->addVariables([
Variable::when('$trial_screen', [
'$mv_width' => 150,
'$mv_height' => 80,
'$mv_text' => "Trial Mode",
]),
Variable::when('(not $trial_screen)', [
'$mv_width' => 250,
'$mv_height' => 60,
'$mv_text' => "Full Version",
]),
]);
$multiVarLabel = Label::create("multi_var_label", '$mv_text')
->setFontSize(Label::FONT_NORMAL)
->setColor(BasicColor::magenta())
->setShadow()
->setAnchorFrom(Element::ANCHOR_CENTER)
->setAnchorTo(Element::ANCHOR_CENTER);
$multiVarPanel->addChild($multiVarLabel);
$stack->addChild($multiVarPanel);
$mainPanel->addChild($stack);
$root->addElement($mainPanel);
return $root;
}
public function getNamespace(): string
{
return "variable_example";
}
public function getPathName(): string
{
return "./resources/pack_example/";
}
public function titleCondition(): string
{
return "VARIABLE_EXAMPLE";
}
}