载入中...
搜索中...
未找到
PcgScreenshotSavedNotice.cpp
浏览该文件的文档.
2#include <cmath>
3#include <simplesquirrel/simplesquirrel.hpp>
5#include "ui/PcgTooltip.h"
6
7// PcgScreenshotSavedNotice.cpp
8namespace eve::ui {
10 if (!std::isfinite(seconds) || seconds < 0)
12 "show duration must be finite and non-negative",
13 "ui.pcgScreenshotSavedNotice"));
14 enabled_ = enabled;
15 duration_ = seconds;
16 if (!enabled_) {
17 visible_ = false;
18 pending_ = false;
19 }
20 return Result<void>::success();
21}
23 if (path.find('\0') != std::string::npos)
25 DiagnosticCode::InvalidArgument, "saved path contains a null character", "ui.pcgScreenshotSavedNotice"));
26 visible_ = false;
27 pending_ = false;
28 if (!enabled_) return Result<void>::success();
29 path_ = path;
30 pending_ = true;
31 return Result<void>::success();
32}
34 if (!std::isfinite(now) || now < 0)
36 DiagnosticCode::InvalidArgument, "time must be finite and non-negative", "ui.pcgScreenshotSavedNotice"));
37 if (pending_ && enabled_) {
38 pending_ = false;
39 visible_ = true;
40 hideAt_ = now + duration_;
41 }
42 return Result<void>::success();
43}
45 if (!std::isfinite(now) || now < 0)
47 DiagnosticCode::InvalidArgument, "time must be finite and non-negative", "ui.pcgScreenshotSavedNotice"));
48 if (visible_ && now >= hideAt_) visible_ = false;
49 return Result<void>::success();
50}
52 auto c = t.addClass("PcgScreenshotSavedNotice", ssq::Class::Ctor<PcgScreenshotSavedNotice()>());
53 auto vm = t.getHandle();
54 c.addFunc("configure", [vm](PcgScreenshotSavedNotice* s, bool e, float d) {
55 return eve::script::projectResult(vm, s->configure(e, d));
56 });
57 c.addFunc("request", [vm](PcgScreenshotSavedNotice* s, const std::string& p) {
58 return eve::script::projectResult(vm, s->request(p));
59 });
60 c.addFunc("endFrame",
61 [vm](PcgScreenshotSavedNotice* s, float n) { return eve::script::projectResult(vm, s->endFrame(n)); });
62 c.addFunc("tick",
63 [vm](PcgScreenshotSavedNotice* s, float n) { return eve::script::projectResult(vm, s->tick(n)); });
64 c.addFunc("getVisible", [](const PcgScreenshotSavedNotice* s) { return s->getVisible(); });
65 c.addFunc("getPathVisible", [](const PcgScreenshotSavedNotice* s) { return s->getPathVisible(); });
66 c.addFunc("getPath", [](const PcgScreenshotSavedNotice* s) { return s->getPath(); });
67 c.addFunc("getPending", [](const PcgScreenshotSavedNotice* s) { return s->getPending(); });
68}
69} // namespace eve::ui
70
71// PcgTooltip.cpp
72namespace eve::ui {
73namespace {}
74Result<void> PcgTooltipManager::configure(int mode, int theme, float delay, float bottom, float top, int wrap) {
75 if (mode < 0 || mode > 2 || theme < 0 || theme > 1 || !std::isfinite(delay) || !std::isfinite(bottom) ||
76 !std::isfinite(top) || delay < 0 || bottom < 0 || top < 0 || wrap < 0)
78 Diagnostic::error(DiagnosticCode::InvalidArgument, "invalid tooltip configuration", "ui.pcgTooltip"));
79 mode_ = mode;
80 theme_ = theme;
81 delay_ = delay;
82 bottomOffset_ = bottom;
83 topOffset_ = top;
84 wrapLimit_ = wrap;
85 hide();
86 return Result<void>::success();
87}
88Result<void> PcgTooltipManager::addTooltip(const std::string& id, const std::string& header, const std::string& text) {
89 if (id.empty())
91 Diagnostic::error(DiagnosticCode::InvalidArgument, "tooltip id must not be empty", "ui.pcgTooltip"));
92 entries_.push_back({id, header, text});
93 return Result<void>::success();
94}
96 if (q.empty())
98 Diagnostic::error(DiagnosticCode::InvalidArgument, "tooltip query must not be empty", "ui.pcgTooltip"));
99 for (auto it = entries_.begin(); it != entries_.end(); ++it)
100 if (it->id.find(q) != std::string::npos) {
101 entries_.erase(it);
102 return Result<bool>::success(true);
103 }
104 return Result<bool>::success(false);
105}
106bool PcgTooltipManager::accepts(int source) const noexcept {
107 return source >= 0 && source <= 1 && (mode_ == 2 || mode_ == source);
108}
109Result<bool> PcgTooltipManager::enter(int source, const std::string& q, float now) {
110 if (!std::isfinite(now) || now < 0 || q.empty() || source < 0 || source > 1)
112 Diagnostic::error(DiagnosticCode::InvalidArgument, "invalid tooltip enter request", "ui.pcgTooltip"));
113 pending_ = false;
114 if (!accepts(source)) return Result<bool>::success(false);
115 for (const auto& e : entries_)
116 if (e.id.find(q) != std::string::npos) {
117 source_ = source;
118 header_ = e.header;
119 text_ = e.text;
120 showAt_ = now + delay_;
121 pending_ = true;
122 return Result<bool>::success(true);
123 }
124 return Result<bool>::success(false);
125}
126Result<void> PcgTooltipManager::enterText(int source, const std::string& content, const std::string& header,
127 float now) {
128 if (!std::isfinite(now) || now < 0 || source < 0 || source > 1)
130 Diagnostic::error(DiagnosticCode::InvalidArgument, "invalid tooltip enter request", "ui.pcgTooltip"));
131 pending_ = false;
132 if (!accepts(source)) return Result<void>::success();
133 source_ = source;
134 header_ = header;
135 text_ = content;
136 showAt_ = now + delay_;
137 pending_ = true;
138 return Result<void>::success();
139}
141 if (source < 0 || source > 1)
143 Diagnostic::error(DiagnosticCode::InvalidArgument, "tooltip source must be UI or scene", "ui.pcgTooltip"));
144 if (accepts(source)) {
145 pending_ = false;
146 visible_ = false;
147 }
148 return Result<void>::success();
149}
150Result<void> PcgTooltipManager::tick(float now, float x, float y, float sw, float sh, bool input) {
151 if (!std::isfinite(now) || !std::isfinite(x) || !std::isfinite(y) || !std::isfinite(sw) || !std::isfinite(sh) ||
152 now < 0 || sw <= 0 || sh <= 0)
154 Diagnostic::error(DiagnosticCode::InvalidArgument, "invalid tooltip frame input", "ui.pcgTooltip"));
155 pivotX_ = x / sw;
156 float normalized = y / sh;
157 pivotY_ = normalized * (y <= sh * .5f ? bottomOffset_ : topOffset_);
158 if (input) {
159 hide();
160 return Result<void>::success();
161 }
162 if (pending_ && now >= showAt_) {
163 pending_ = false;
164 visible_ = true;
165 }
166 return Result<void>::success();
167}
168void exposePcgTooltipBindings(ssq::Table& t) {
169 auto c = t.addClass("PcgTooltipManager", ssq::Class::Ctor<PcgTooltipManager()>());
170 auto vm = t.getHandle();
171 c.addFunc("configure", [vm](PcgTooltipManager* s, int m, int th, float d, float b, float top, int w) {
172 return eve::script::projectResult(vm, s->configure(m, th, d, b, top, w));
173 });
174 c.addFunc("addTooltip",
175 [vm](PcgTooltipManager* s, const std::string& i, const std::string& h, const std::string& x) {
176 return eve::script::projectResult(vm, s->addTooltip(i, h, x));
177 });
178 c.addFunc("removeTooltip", [vm](PcgTooltipManager* s, const std::string& q) {
179 return eve::script::projectResult(vm, s->removeTooltip(q), [](bool v) { return v; });
180 });
181 c.addFunc("enter", [vm](PcgTooltipManager* s, int src, const std::string& q, float n) {
182 return eve::script::projectResult(vm, s->enter(src, q, n), [](bool v) { return v; });
183 });
184 c.addFunc("enterText",
185 [vm](PcgTooltipManager* s, int src, const std::string& text, const std::string& header, float n) {
186 return eve::script::projectResult(vm, s->enterText(src, text, header, n));
187 });
188 c.addFunc("exit", [vm](PcgTooltipManager* s, int src) { return eve::script::projectResult(vm, s->exit(src)); });
189 c.addFunc("tick", [vm](PcgTooltipManager* s, float n, float x, float y, float w, float h, bool i) {
190 return eve::script::projectResult(vm, s->tick(n, x, y, w, h, i));
191 });
192 c.addFunc("hide", [](PcgTooltipManager* s) { s->hide(); });
193 c.addFunc("getVisible", [](const PcgTooltipManager* s) { return s->getVisible(); });
194 c.addFunc("getPending", [](const PcgTooltipManager* s) { return s->getPending(); });
195 c.addFunc("getHeader", [](const PcgTooltipManager* s) { return s->getHeader(); });
196 c.addFunc("getText", [](const PcgTooltipManager* s) { return s->getText(); });
197 c.addFunc("getHeaderVisible", [](const PcgTooltipManager* s) { return s->getHeaderVisible(); });
198 c.addFunc("getWrapEnabled", [](const PcgTooltipManager* s) { return s->getWrapEnabled(); });
199 c.addFunc("getPivotX", [](const PcgTooltipManager* s) { return s->getPivotX(); });
200 c.addFunc("getPivotY", [](const PcgTooltipManager* s) { return s->getPivotY(); });
201 c.addFunc("getBackgroundR", [](const PcgTooltipManager* s) { return s->getBackgroundR(); });
202 c.addFunc("getForeground", [](const PcgTooltipManager* s) { return s->getForeground(); });
203 c.addFunc("getCount", [](const PcgTooltipManager* s) { return s->getCount(); });
204}
205} // namespace eve::ui
double y
double m[16]
double x
float w
Definition AnimClip.cpp:738
const std::string & s
glm::vec4 p[6]
HSQUIRRELVM vm
Definition ECS.cpp:38
EvpackChunkInput input
Definition Evpack.cpp:170
glm::vec3 n
Definition Grass.cpp:63
std::array< double, 10 > q
float v
std::int32_t c
int h
std::string id
MeleePoint3 b
Definition MeleeHit.cpp:41
const std::string * accepts
std::string path
Definition PlayHost.cpp:111
float d
float t
std::string text
std::string_view source
The single Squirrel projection for common Result, Status and Value.
float bottom
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 notification state ported from Pcg ScreenshotSavedManager.
Result< void > configure(bool enabled, float showSeconds)
Configure enable state and visible duration atomically.
Result< void > tick(float unscaledNow)
Advance expiration using explicit unscaled time.
Result< void > endFrame(float unscaledNow)
Publish a pending notice after rendering this frame.
Result< void > request(const std::string &savedPath)
Cancel an old notice and schedule a new one for the next end-of-frame.
Caller-owned runtime model of Pcg Tooltip, TooltipManager, Profile and Trigger.
Definition PcgTooltip.h:12
Result< bool > removeTooltip(const std::string &query)
Remove first entry whose id contains the query.
Result< void > tick(float now, float mouseX, float mouseY, float screenWidth, float screenHeight, bool anyInput)
Update mouse placement, delayed visibility, and input dismissal.
Result< void > exit(int source)
Cancel matching hover and hide tooltip.
Result< bool > enter(int source, const std::string &query, float now)
Schedule the first profile entry whose id contains query. source is 0 UI or 1 scene.
Result< void > addTooltip(const std::string &id, const std::string &header, const std::string &text)
Append a tooltip profile entry.
void hide() noexcept
Hide and cancel all pending tooltip work.
Definition PcgTooltip.h:21
Result< void > enterText(int source, const std::string &content, const std::string &header, float now)
Schedule direct trigger content, matching TooltipTrigger.
Result< void > configure(int interactionMode, int theme, float delay, float bottomOffset, float topOffset, int wrapLimit)
Configure interaction mode (0 UI, 1 scene, 2 both), theme (0 light, 1 dark), delay and layout.
SQInteger top
Definition Snapshot.cpp:115
ssq::Table projectResult(HSQUIRRELVM vm, Result< void > &&result)
Consume and project a void native Result using the common schema.
void exposePcgScreenshotSavedNoticeBindings(ssq::Table &t)
Register Pcg screenshot-notice bindings.
void exposePcgTooltipBindings(ssq::Table &t)
Register Pcg tooltip bindings.
bool enabled
Object::Ptr theme