Compare commits

..

No commits in common. "aa9590e2f40c4ddf33302fe5c7d554dcf3d4512f" and "e799b4ec79e5e22778e1c6ab5b04da2ef7a39743" have entirely different histories.

4 changed files with 2 additions and 104 deletions

View File

@ -163,19 +163,7 @@
"hover": "resources/shoot_hover.png",
"pressed": "resources/shoot_pressed.png"
}
},
{
"type": "TextView",
"name": "velocityText",
"x": 10,
"y": 10,
"width": 200,
"height": 40,
"text": "Velocity: 0",
"fontSize": 24,
"color": [1.0, 1.0, 1.0, 1.0],
"centered": false
}
}
]
}
}

View File

@ -275,15 +275,6 @@ namespace ZL
loadGameplayUI = [this]() {
uiManager.loadFromFile("resources/config/ui.json", renderer, CONST_ZIP_FILE);
auto velocityTv = uiManager.findTextView("velocityText");
if (velocityTv) {
velocityTv->rect.x = 10.0f;
velocityTv->rect.y = static_cast<float>(Environment::height) - velocityTv->rect.h - 10.0f;
}
else {
std::cerr << "Failed to find velocityText in UI" << std::endl;
}
uiManager.startAnimationOnNode("backgroundNode", "bgScroll");
static bool isExitButtonAnimating = false;
uiManager.setAnimationCallback("settingsButton", "buttonsExit", [this]() {
@ -1215,15 +1206,6 @@ namespace ZL
}
}
// update velocity text
if (shipAlive && !gameOver) {
auto velocityTv = uiManager.findTextView("velocityText");
if (velocityTv) {
std::string velocityStr = "Velocity: " + std::to_string(static_cast<int>(Environment::shipState.velocity));
uiManager.setText("velocityText", velocityStr);
}
}
uiManager.update(static_cast<float>(delta));
lastTickCount = newTickCount;
}

View File

@ -1,6 +1,5 @@
#include "UiManager.h"
#include "utils/Utils.h"
#include "render/TextRenderer.h"
#include <fstream>
#include <iostream>
#include <algorithm>
@ -206,7 +205,6 @@ namespace ZL {
layoutNode(root);
buttons.clear();
sliders.clear();
textViews.clear();
collectButtonsAndSliders(root);
nodeActiveAnims.clear();
@ -329,29 +327,6 @@ namespace ZL {
}
}
if (node->type == "TextView") {
auto tv = std::make_shared<UiTextView>();
tv->name = node->name;
tv->rect = node->rect;
if (j.contains("text")) tv->text = j["text"].get<std::string>();
if (j.contains("fontPath")) tv->fontPath = j["fontPath"].get<std::string>();
if (j.contains("fontSize")) tv->fontSize = j["fontSize"].get<int>();
if (j.contains("color") && j["color"].is_array() && j["color"].size() == 4) {
for (int i = 0; i < 4; ++i) {
tv->color[i] = j["color"][i].get<float>();
}
}
if (j.contains("centered")) tv->centered = j["centered"].get<bool>();
tv->textRenderer = std::make_unique<TextRenderer>();
if (!tv->textRenderer->init(renderer, tv->fontPath, tv->fontSize)) {
std::cerr << "Failed to init TextRenderer for TextView: " << tv->name << std::endl;
}
node->textView = tv;
}
if (j.contains("children") && j["children"].is_array()) {
for (const auto& ch : j["children"]) {
node->children.push_back(parseNode(ch, renderer, zipFile));
@ -401,10 +376,7 @@ namespace ZL {
if (node->slider) {
sliders.push_back(node->slider);
}
if (node->textView) {
textViews.push_back(node->textView);
}
for (auto& c : node->children) collectButtonsAndSliders(c); // ìîæíî ïåðåèìåíîâàòü â collectControls
for (auto& c : node->children) collectButtonsAndSliders(c);
}
bool UiManager::setButtonCallback(const std::string& name, std::function<void(const std::string&)> cb) {
@ -560,9 +532,6 @@ namespace ZL {
for (const auto& s : sliders) {
s->draw(renderer);
}
for (const auto& tv : textViews) {
tv->draw(renderer);
}
renderer.PopMatrix();
renderer.PopProjectionMatrix();
@ -893,20 +862,4 @@ namespace ZL {
return true;
}
std::shared_ptr<UiTextView> UiManager::findTextView(const std::string& name) {
for (auto& tv : textViews) {
if (tv->name == name) return tv;
}
return nullptr;
}
bool UiManager::setText(const std::string& name, const std::string& newText) {
auto tv = findTextView(name);
if (!tv) {
return false;
}
tv->text = newText;
return true;
}
} // namespace ZL

View File

@ -2,7 +2,6 @@
#include "render/Renderer.h"
#include "render/TextureManager.h"
#include "render/TextRenderer.h"
#include "Environment.h"
#include "external/nlohmann/json.hpp"
#include <string>
@ -72,24 +71,6 @@ namespace ZL {
void draw(Renderer& renderer) const;
};
struct UiTextView {
std::string name;
UiRect rect;
std::string text = "";
std::string fontPath = "resources/fonts/DroidSans.ttf";
int fontSize = 32;
std::array<float, 4> color = { 1.f, 1.f, 1.f, 1.f }; // rgba
bool centered = true;
std::unique_ptr<TextRenderer> textRenderer;
void draw(Renderer& renderer) const {
if (textRenderer) {
textRenderer->drawText(text, rect.x + rect.w / 2, rect.y + rect.h / 2, 1.0f, centered, color);
}
}
};
struct UiNode {
std::string type;
UiRect rect;
@ -97,7 +78,6 @@ namespace ZL {
std::vector<std::shared_ptr<UiNode>> children;
std::shared_ptr<UiButton> button;
std::shared_ptr<UiSlider> slider;
std::shared_ptr<UiTextView> textView;
std::string orientation = "vertical";
float spacing = 0.0f;
@ -155,9 +135,6 @@ namespace ZL {
bool setSliderCallback(const std::string& name, std::function<void(const std::string&, float)> cb);
bool setSliderValue(const std::string& name, float value); // programmatic set (clamped 0..1)
std::shared_ptr<UiTextView> findTextView(const std::string& name);
bool setText(const std::string& name, const std::string& newText);
bool pushMenuFromFile(const std::string& path, Renderer& renderer, const std::string& zipFile = "");
bool popMenu();
void clearMenuStack();
@ -199,7 +176,6 @@ namespace ZL {
std::shared_ptr<UiNode> root;
std::vector<std::shared_ptr<UiButton>> buttons;
std::vector<std::shared_ptr<UiSlider>> sliders;
std::vector<std::shared_ptr<UiTextView>> textViews;
std::map<std::shared_ptr<UiNode>, std::vector<ActiveAnim>> nodeActiveAnims;
std::map<std::pair<std::string, std::string>, std::function<void()>> animCallbacks; // key: (nodeName, animName)
@ -218,7 +194,6 @@ namespace ZL {
};
std::vector<MenuState> menuStack;
};
} // namespace ZL