Working on tutorial refactoring
This commit is contained in:
1 parent
ea8f64c940
commit
9fa120d4ad
82 files changed
+1877
-7563
No files matched your search
+16
-2
@@ -5,6 +5,7 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <unordered_set>
|
||||
#include "GameConstants.h"
|
||||
|
||||
namespace FRG {
|
||||
@@ -1535,6 +1536,14 @@ namespace FRG {
|
||||
renderer.PopProjectionMatrix();
|
||||
}
|
||||
|
||||
// Buttons under a hidden node (the node itself or any ancestor) must not react to touches.
|
||||
static void collectVisibleInteractives(const std::shared_ptr<UiNode>& node, std::unordered_set<const void*>& out) {
|
||||
if (!node || !node->visible) return;
|
||||
if (node->button) out.insert(node->button.get());
|
||||
if (node->textButton) out.insert(node->textButton.get());
|
||||
for (auto& c : node->children) collectVisibleInteractives(c, out);
|
||||
}
|
||||
|
||||
static std::shared_ptr<UiNode> findNodeByName(const std::shared_ptr<UiNode>& node, const std::string& name) {
|
||||
if (!node) return nullptr;
|
||||
if (!name.empty() && node->name == name) return node;
|
||||
@@ -1847,11 +1856,13 @@ namespace FRG {
|
||||
void UiManager::onTouchDown(int64_t fingerId, int x, int y) {
|
||||
// Iterate allInteractives in reverse DFS order: later-declared elements have higher priority.
|
||||
// At most one button or textButton is pressed per touch.
|
||||
std::unordered_set<const void*> visibleInteractives;
|
||||
collectVisibleInteractives(root, visibleInteractives);
|
||||
for (auto it = allInteractives.rbegin(); it != allInteractives.rend(); ++it) {
|
||||
if (std::holds_alternative<std::shared_ptr<UiButton>>(*it)) {
|
||||
auto& b = std::get<std::shared_ptr<UiButton>>(*it);
|
||||
//logger() << "onTouchDown found the button: " << b->name << std::endl;
|
||||
if (b->state != ButtonState::Disabled &&
|
||||
if (visibleInteractives.count(b.get()) && b->state != ButtonState::Disabled &&
|
||||
b->getClickZoneRect().containsConsideringBorder((float)x, (float)y, b->border)) {
|
||||
b->state = ButtonState::Pressed;
|
||||
pressedButtons[fingerId] = b;
|
||||
@@ -1861,7 +1872,7 @@ namespace FRG {
|
||||
}
|
||||
} else {
|
||||
auto& tb = std::get<std::shared_ptr<UiTextButton>>(*it);
|
||||
if (tb->state != ButtonState::Disabled &&
|
||||
if (visibleInteractives.count(tb.get()) && tb->state != ButtonState::Disabled &&
|
||||
tb->getClickZoneRect().containsConsideringBorder((float)x, (float)y, tb->border)) {
|
||||
tb->state = ButtonState::Pressed;
|
||||
pressedTextButtons[fingerId] = tb;
|
||||
@@ -2197,6 +2208,9 @@ namespace FRG {
|
||||
if (!root) return false;
|
||||
auto node = findNodeByName(root, nodeName);
|
||||
if (!node) return false;
|
||||
// Replay the fade-in when a hidden image is revealed, as if its screen was just shown.
|
||||
if (visible && !node->visible && node->staticImage && node->staticImage->fadeInEnabled)
|
||||
node->staticImage->fadeInElapsedMs = 0.0f;
|
||||
node->visible = visible;
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user