载入中...
搜索中...
未找到
PcgColorPreviewSync.cpp
浏览该文件的文档.
2#include <algorithm>
3#include <cmath>
4#include <simplesquirrel/simplesquirrel.hpp>
9
10// PcgColorPreviewSync.cpp
11namespace eve::ui {
12Result<void> PcgColorPreviewSync::sync(float r, float g, float b, float a) {
13 if (!std::isfinite(r) || !std::isfinite(g) || !std::isfinite(b) || !std::isfinite(a))
15 "ui.pcgColorPreview.sync"));
16 if (r == 0.f && g == 0.f && b == 0.f) {
17 red_ = green_ = blue_ = 0.5f;
18 alpha_ = 1.f;
19 } else {
20 red_ = r * 2.5f;
21 green_ = g * 2.5f;
22 blue_ = b * 2.5f;
23 alpha_ = a * 2.5f;
24 }
25 return Result<void>::success();
26}
27void exposePcgColorPreviewSyncBindings(ssq::Table& table) {
28 auto cls = table.addClass("PcgColorPreviewSync", ssq::Class::Ctor<PcgColorPreviewSync()>());
29 auto vm = table.getHandle();
30 cls.addFunc("sync", [vm](PcgColorPreviewSync* self, float r, float g, float b, float a) {
31 return eve::script::projectResult(vm, self->sync(r, g, b, a));
32 });
33 cls.addFunc("getRed", [](const PcgColorPreviewSync* self) { return self->getRed(); });
34 cls.addFunc("getGreen", [](const PcgColorPreviewSync* self) { return self->getGreen(); });
35 cls.addFunc("getBlue", [](const PcgColorPreviewSync* self) { return self->getBlue(); });
36 cls.addFunc("getAlpha", [](const PcgColorPreviewSync* self) { return self->getAlpha(); });
37}
38} // namespace eve::ui
39
40// PcgControllerSelection.cpp
41namespace eve::ui {
42namespace {}
43Result<void> PcgControllerSelection::add(const std::string& name, int type, const std::string& id) {
44 if (name.empty() || id.empty())
46 "controller name and widget id are required",
47 "ui.pcgControllerSelection"));
48 rows_.push_back({name, id, type, false});
49 return Result<void>::success();
50}
52 int found = -1;
53 for (size_t i = 0; i < rows_.size(); ++i)
54 if (rows_[i].controllerType == current) {
55 found = int(i);
56 break;
57 }
58 if (found < 0) return Result<bool>::success(false);
59 for (size_t i = 0; i < rows_.size(); ++i) rows_[i].visible = int(i) == found;
60 selected_ = found;
61 return Result<bool>::success(true);
62}
64 if (i < 0 || i >= int(rows_.size()))
66 DiagnosticCode::InvalidArgument, "controller row index is out of range", "ui.pcgControllerSelection"));
67 return Result<bool>::success(rows_[size_t(i)].visible);
68}
70 if (i < 0 || i >= int(rows_.size()))
72 DiagnosticCode::InvalidArgument, "controller row index is out of range", "ui.pcgControllerSelection"));
73 return Result<std::string>::success(rows_[size_t(i)].widgetId);
74}
76 auto c = t.addClass("PcgControllerSelection", ssq::Class::Ctor<PcgControllerSelection()>());
77 auto vm = t.getHandle();
78 c.addFunc("add", [vm](PcgControllerSelection* s, const std::string& n, int type, const std::string& id) {
79 return eve::script::projectResult(vm, s->add(n, type, id));
80 });
81 c.addFunc("refresh", [vm](PcgControllerSelection* s, int type) {
82 return eve::script::projectResult(vm, s->refresh(type), [](bool v) { return v; });
83 });
84 c.addFunc("getCount", [](const PcgControllerSelection* s) { return s->getCount(); });
85 c.addFunc("getSelectedIndex", [](const PcgControllerSelection* s) { return s->getSelectedIndex(); });
86 c.addFunc("getVisible", [vm](const PcgControllerSelection* s, int i) {
87 return eve::script::projectResult(vm, s->getVisible(i), [](bool v) { return v; });
88 });
89 c.addFunc("getWidgetId", [vm](const PcgControllerSelection* s, int i) {
90 return eve::script::projectResult(vm, s->getWidgetId(i), [](std::string v) { return v; });
91 });
92}
93} // namespace eve::ui
94
95// PcgLoadingScreen.cpp
96namespace eve::ui {
97namespace {
98
99bool validName(const std::string& value) { return !value.empty() && value.find('\0') == std::string::npos; }
100} // namespace
101
103 if (!std::isfinite(fadeOutSpeed) || fadeOutSpeed < 0.f)
105 "fade-out speed must be finite and non-negative", {}, {},
106 "ui.pcgLoadingScreen"));
107 fadeOutSpeed_ = fadeOutSpeed;
108 return Result<void>::success();
109}
110
112 canvasVisible_ = true;
113 backgroundAlpha_ = 1.f;
114 progress_ = 0.f;
115}
116
118 if (!std::isfinite(progress))
119 return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, "load progress must be finite",
120 {}, {}, "ui.pcgLoadingScreen"));
121 canvasVisible_ = true;
122 progress_ = progress;
123 if (progress >= 1.f) onLoadProgressEnded();
124 return Result<void>::success();
125}
126
128 fading_ = true;
129 progressVisible_ = false;
130 textVisible_ = false;
131}
132
134 timeoutOpen_ = true;
135 pendingMissingScenes_.clear();
136}
137
138Result<int> PcgLoadingScreen::addMissingScene(const std::string& terrainName, const std::string& impostorName) {
139 if (!timeoutOpen_)
141 "beginTimeout must be called before adding a missing scene", {},
142 {}, "ui.pcgLoadingScreen"));
143 if ((!terrainName.empty() && !validName(terrainName)) || (!impostorName.empty() && !validName(impostorName)))
145 "missing-scene names must not contain null characters", {}, {},
146 "ui.pcgLoadingScreen"));
147 pendingMissingScenes_.push_back({terrainName, impostorName, {}, {}});
148 return Result<int>::success(static_cast<int>(pendingMissingScenes_.size() - 1));
149}
150
151Result<void> PcgLoadingScreen::addReference(int sceneIndex, const std::string& objectName, bool impostor) {
152 if (!timeoutOpen_ || sceneIndex < 0 || static_cast<size_t>(sceneIndex) >= pendingMissingScenes_.size() ||
153 !validName(objectName))
155 DiagnosticCode::InvalidArgument, "an open timeout, valid scene index and nonempty object name are required",
156 {}, {}, "ui.pcgLoadingScreen"));
157 auto& scene = pendingMissingScenes_[static_cast<size_t>(sceneIndex)];
158 (impostor ? scene.impostorReferences : scene.regularReferences).push_back(objectName);
159 return Result<void>::success();
160}
161
162Result<void> PcgLoadingScreen::addRegularReference(int sceneIndex, const std::string& objectName) {
163 return addReference(sceneIndex, objectName, false);
164}
165
166Result<void> PcgLoadingScreen::addImpostorReference(int sceneIndex, const std::string& objectName) {
167 return addReference(sceneIndex, objectName, true);
168}
169
171 if (!timeoutOpen_)
173 "beginTimeout must be called before endTimeout", {}, {},
174 "ui.pcgLoadingScreen"));
175 std::string message = "Pcg Loading Screen Timeout, closing down loading screen.\r\n";
176 message +=
177 "If you feel that there is no error but the terrain loading simply needs more time, try to increase the "
178 "Timeout value in the Terrain Loader Manager.\r\n";
179 message += "The following scenes are still not loaded:\r\n";
180 for (const auto& scene : pendingMissingScenes_) {
181 if (!scene.regularReferences.empty()) {
182 message += "\r\n " + scene.terrainName + "\r\n Referencing Objects:\r\n";
183 for (const auto& name : scene.regularReferences) message += name + ", ";
184 }
185 if (!scene.impostorReferences.empty()) {
186 message += "\r\n " + scene.impostorName + "\r\n Referencing Objects:\r\n";
187 for (const auto& name : scene.impostorReferences) message += name + ", ";
188 }
189 message += "\r\n";
190 }
191 timeoutMessage_ = std::move(message);
192 pendingMissingScenes_.clear();
193 timeoutOpen_ = false;
195 return Result<void>::success();
196}
197
199 if (!std::isfinite(deltaTime) || deltaTime < 0.f)
201 "frame delta time must be finite and non-negative", {}, {},
202 "ui.pcgLoadingScreen"));
203 if (fading_) {
204 backgroundAlpha_ -= deltaTime * fadeOutSpeed_;
205 if (backgroundAlpha_ <= 0.f) {
206 backgroundAlpha_ = 0.f;
207 canvasVisible_ = false;
208 fading_ = false;
209 }
210 }
211 return Result<void>::success();
212}
213
214void exposePcgLoadingScreenBindings(ssq::Table& table) {
215 auto c = table.addClass("PcgLoadingScreen", ssq::Class::Ctor<PcgLoadingScreen()>());
216 const auto vm = table.getHandle();
217 c.addFunc("configure", [vm](PcgLoadingScreen* self, float speed) {
218 return eve::script::projectResult(vm, self->configure(speed));
219 });
220 c.addFunc("onLoadProgressStarted", [](PcgLoadingScreen* self) { self->onLoadProgressStarted(); });
221 c.addFunc("onLoadProgressUpdated", [vm](PcgLoadingScreen* self, float progress) {
222 return eve::script::projectResult(vm, self->onLoadProgressUpdated(progress));
223 });
224 c.addFunc("onLoadProgressEnded", [](PcgLoadingScreen* self) { self->onLoadProgressEnded(); });
225 c.addFunc("beginTimeout", [](PcgLoadingScreen* self) { self->beginTimeout(); });
226 c.addFunc("addMissingScene", [vm](PcgLoadingScreen* self, const std::string& terrain, const std::string& impostor) {
227 return eve::script::projectResult(vm, self->addMissingScene(terrain, impostor),
228 [](int value) { return eve::Value(value); });
229 });
230 c.addFunc("addRegularReference", [vm](PcgLoadingScreen* self, int index, const std::string& name) {
232 });
233 c.addFunc("addImpostorReference", [vm](PcgLoadingScreen* self, int index, const std::string& name) {
235 });
236 c.addFunc("endTimeout",
237 [vm](PcgLoadingScreen* self) { return eve::script::projectResult(vm, self->endTimeout()); });
238 c.addFunc("tick",
239 [vm](PcgLoadingScreen* self, float dt) { return eve::script::projectResult(vm, self->tick(dt)); });
240 c.addFunc("getCanvasVisible", [](const PcgLoadingScreen* self) { return self->getCanvasVisible(); });
241 c.addFunc("getProgressVisible", [](const PcgLoadingScreen* self) { return self->getProgressVisible(); });
242 c.addFunc("getTextVisible", [](const PcgLoadingScreen* self) { return self->getTextVisible(); });
243 c.addFunc("getFading", [](const PcgLoadingScreen* self) { return self->getFading(); });
244 c.addFunc("getProgress", [](const PcgLoadingScreen* self) { return self->getProgress(); });
245 c.addFunc("getBackgroundAlpha", [](const PcgLoadingScreen* self) { return self->getBackgroundAlpha(); });
246 c.addFunc("getTimeoutMessage", [](const PcgLoadingScreen* self) { return self->getTimeoutMessage(); });
247}
248
249} // namespace eve::ui
250
251// PcgPhotoModeColorPicker.cpp
252namespace eve::ui {
253namespace {
254bool finite4(float a, float b, float c, float d) {
255 return std::isfinite(a) && std::isfinite(b) && std::isfinite(c) && std::isfinite(d);
256}
257} // namespace
258bool PcgPhotoModeColorPicker::hdrActive() const noexcept { return hdr_ && (a_ > 1.f || a_ < 0.f); }
259Result<void> PcgPhotoModeColorPicker::open(float r, float g, float b, float a, bool hdr) {
260 if (!finite4(r, g, b, a))
262 Diagnostic::error(DiagnosticCode::InvalidArgument, "color must be finite", "ui.pcgPhotoModeColorPicker"));
263 float nr = r, ng = g, nb = b;
264 if (hdr && (a > 1.f || a < 0.f)) {
265 nr *= a;
266 ng *= a;
267 nb *= a;
268 }
269 r_ = nr;
270 g_ = ng;
271 b_ = nb;
272 a_ = a;
273 hdr_ = hdr;
274 open_ = true;
275 front_ = true;
276 return Result<void>::success();
277}
278Result<void> PcgPhotoModeColorPicker::setLast(float r, float g, float b, float a) {
279 if (!finite4(r, g, b, a))
281 Diagnostic::error(DiagnosticCode::InvalidArgument, "color must be finite", "ui.pcgPhotoModeColorPicker"));
282 lastR_ = r;
283 lastG_ = g;
284 lastB_ = b;
285 lastA_ = a;
286 return Result<void>::success();
287}
288Result<void> PcgPhotoModeColorPicker::setChannel(float& dst, float v) {
289 if (!std::isfinite(v))
291 Diagnostic::error(DiagnosticCode::InvalidArgument, "color must be finite", "ui.pcgPhotoModeColorPicker"));
292 dst = v;
293 ++revision_;
294 return Result<void>::success();
295}
296Result<void> PcgPhotoModeColorPicker::setRed(float v) { return setChannel(r_, v); }
297Result<void> PcgPhotoModeColorPicker::setGreen(float v) { return setChannel(g_, v); }
298Result<void> PcgPhotoModeColorPicker::setBlue(float v) { return setChannel(b_, v); }
299Result<void> PcgPhotoModeColorPicker::setHdr(float v) { return setChannel(a_, v); }
301 r_ = lastR_;
302 g_ = lastG_;
303 b_ = lastB_;
304 a_ = lastA_;
305 revision_ += 5;
306}
307float PcgPhotoModeColorPicker::getPreviewRed() const noexcept { return r_ * (hdrActive() ? a_ : 1.f); }
308float PcgPhotoModeColorPicker::getPreviewGreen() const noexcept { return g_ * (hdrActive() ? a_ : 1.f); }
309float PcgPhotoModeColorPicker::getPreviewBlue() const noexcept { return b_ * (hdrActive() ? a_ : 1.f); }
310float PcgPhotoModeColorPicker::getHdrSwatch() const noexcept { return std::clamp((a_ + 5.f) / 10.f, 0.f, 1.f); }
317 auto c = t.addClass("PcgPhotoModeColorPicker", ssq::Class::Ctor<PcgPhotoModeColorPicker()>());
318 auto vm = t.getHandle();
319 c.addFunc("open", [vm](PcgPhotoModeColorPicker* s, float r, float g, float b, float a, bool h) {
320 return eve::script::projectResult(vm, s->open(r, g, b, a, h));
321 });
322 c.addFunc("setLast", [vm](PcgPhotoModeColorPicker* s, float r, float g, float b, float a) {
323 return eve::script::projectResult(vm, s->setLast(r, g, b, a));
324 });
325 c.addFunc("setFocusedName", &PcgPhotoModeColorPicker::setFocusedName);
326 c.addFunc("close", [](PcgPhotoModeColorPicker* s) { s->close(); });
327 c.addFunc("setRed",
328 [vm](PcgPhotoModeColorPicker* s, float v) { return eve::script::projectResult(vm, s->setRed(v)); });
329 c.addFunc("setGreen",
330 [vm](PcgPhotoModeColorPicker* s, float v) { return eve::script::projectResult(vm, s->setGreen(v)); });
331 c.addFunc("setBlue",
332 [vm](PcgPhotoModeColorPicker* s, float v) { return eve::script::projectResult(vm, s->setBlue(v)); });
333 c.addFunc("setHdr",
334 [vm](PcgPhotoModeColorPicker* s, float v) { return eve::script::projectResult(vm, s->setHdr(v)); });
335 c.addFunc("reset", [](PcgPhotoModeColorPicker* s) { s->reset(); });
336 c.addFunc("getRed", [](const PcgPhotoModeColorPicker* s) { return s->getRed(); });
337 c.addFunc("getGreen", [](const PcgPhotoModeColorPicker* s) { return s->getGreen(); });
338 c.addFunc("getBlue", [](const PcgPhotoModeColorPicker* s) { return s->getBlue(); });
339 c.addFunc("getAlpha", [](const PcgPhotoModeColorPicker* s) { return s->getAlpha(); });
340 c.addFunc("getPreviewRed", [](const PcgPhotoModeColorPicker* s) { return s->getPreviewRed(); });
341 c.addFunc("getPreviewGreen", [](const PcgPhotoModeColorPicker* s) { return s->getPreviewGreen(); });
342 c.addFunc("getPreviewBlue", [](const PcgPhotoModeColorPicker* s) { return s->getPreviewBlue(); });
343 c.addFunc("getHdrSwatch", [](const PcgPhotoModeColorPicker* s) { return s->getHdrSwatch(); });
344 c.addFunc("getHdrEnabled", [](const PcgPhotoModeColorPicker* s) { return s->getHdrEnabled(); });
345 c.addFunc("getOpen", [](const PcgPhotoModeColorPicker* s) { return s->getOpen(); });
346 c.addFunc("getFocusedName", [](const PcgPhotoModeColorPicker* s) { return s->getFocusedName(); });
347 c.addFunc("getChangeRevision", [](const PcgPhotoModeColorPicker* s) { return s->getChangeRevision(); });
348 c.addFunc("consumeBringToFront",
349 [](PcgPhotoModeColorPicker* s) { return s->consumeBringToFront() == PcgUiRequestStatus::Requested; });
350}
351} // namespace eve::ui
std::string terrain
const std::string & s
HSQUIRRELVM vm
Definition ECS.cpp:38
HSQOBJECT cls
Definition ECS.cpp:39
std::string name
Definition ECS.cpp:154
std::string message
tensor::Graph g
Definition GpuGraph.cpp:7
glm::vec3 n
Definition Grass.cpp:63
double r
float v
std::int32_t c
int h
std::string id
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
double dt
std::weak_ptr< PrimitiveScene > scene
Object::Ptr value
float d
float t
bool found
double current
The single Squirrel projection for common Result, Status and Value.
bool visible
uint32_t index
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
Caller-owned highlighted-color snapshot ported from Pcg ColorPreviewSync.
float getBlue() const noexcept
Return highlighted blue.
float getRed() const noexcept
Return highlighted red.
float getAlpha() const noexcept
Return highlighted alpha.
float getGreen() const noexcept
Return highlighted green.
Result< void > sync(float red, float green, float blue, float alpha)
Synchronize from the source image color exactly as Pcg does on enable.
Caller-owned visibility selection ported from Pcg UIControllerSelection.
Result< bool > refresh(int currentController)
Select first matching type; no match preserves the previous visibility snapshot.
Result< bool > getVisible(int index) const
Return row visibility.
Result< void > add(const std::string &name, int controllerType, const std::string &widgetId)
Append one controller type and its stable UI widget id.
Result< std::string > getWidgetId(int index) const
Return stable widget id.
Caller-owned loading-screen state driven by Pcg terrain load-progress events.
Result< void > tick(float deltaTime)
Advance background fade using explicit frame delta time.
void beginTimeout() noexcept
Start a transactional missing-scene diagnostic.
Result< void > endTimeout()
Publish the timeout warning and begin fade-out.
Result< int > addMissingScene(const std::string &terrainName, const std::string &impostorName)
Append one missing terrain scene and return its stable index in the pending diagnostic.
void onLoadProgressStarted() noexcept
Reset canvas, background alpha and progress when load tracking starts.
float getProgress() const noexcept
Return current progress without clamping Pcg's event value.
const std::string & getTimeoutMessage() const noexcept
Return the most recently published timeout warning.
void onLoadProgressEnded() noexcept
Hide progress/text and begin fading the background.
bool getTextVisible() const noexcept
Return whether the loading text is enabled.
Result< void > onLoadProgressUpdated(float progress)
Publish progress; values at least one automatically begin fade-out.
Result< void > addRegularReference(int sceneIndex, const std::string &objectName)
Append a regular referencing object name to a pending scene.
Result< void > configure(float fadeOutSpeed)
Set the alpha units removed per second.
Result< void > addImpostorReference(int sceneIndex, const std::string &objectName)
Append an impostor referencing object name to a pending scene.
bool getFading() const noexcept
Return whether fade-out is running.
float getBackgroundAlpha() const noexcept
Return current background alpha.
bool getCanvasVisible() const noexcept
Return whether the loading canvas is enabled.
bool getProgressVisible() const noexcept
Return whether the progress bar is active.
Caller-owned runtime model of Pcg PhotoModeColorPicker.
Result< void > open(float r, float g, float b, float a, bool hdr)
Open with a source color and preserve Pcg's HDR preprocessing.
Result< void > setHdr(float v)
Set HDR alpha and publish one change.
void setFocusedName(const std::string &name)
Set the focused display name, exposed with Pcg parentheses.
Result< void > setGreen(float v)
Set one raw channel and publish one change.
float getPreviewRed() const noexcept
Return displayed/applied RGB after optional HDR multiplication.
PcgUiRequestStatus consumeBringToFront() noexcept
Return and clear the SetAsLastSibling request.
float getHdrSwatch() const noexcept
Return HDR slider grayscale swatch.
void reset() noexcept
Restore last RGBA and reproduce four slider events plus explicit callback.
Result< void > setRed(float v)
Set one raw channel and publish one change.
Result< void > setLast(float r, float g, float b, float a)
Store the color restored by reset.
Result< void > setBlue(float v)
Set one raw channel and publish one change.
ssq::Table projectResult(HSQUIRRELVM vm, Result< void > &&result)
Consume and project a void native Result using the common schema.
void exposePcgColorPreviewSyncBindings(ssq::Table &table)
Register Pcg color-preview bindings.
void exposePcgLoadingScreenBindings(ssq::Table &table)
Register Pcg loading-screen bindings.
void exposePcgPhotoModeColorPickerBindings(ssq::Table &t)
Register Pcg photo-mode color-picker bindings.
PcgUiRequestStatus
Explicit status returned when consuming a one-shot Pcg UI request.
Definition PcgUiStatus.h:4
void exposePcgControllerSelectionBindings(ssq::Table &t)
Register Pcg controller-selection bindings.