mirror of
https://github.com/zhenyan121/SporeBG-Conid.git
synced 2026-04-10 06:14:08 +08:00
The calculation process has been modified, and now it is performed directly in the gameapplication class
This commit is contained in:
@@ -20,7 +20,7 @@ public:
|
||||
// 收集渲染数据
|
||||
virtual void CollectRenderData() = 0;
|
||||
|
||||
virtual void UpdateMousePositon(float x, float y) = 0;
|
||||
virtual void updateMousePositon(int logicalX, int logicalY) = 0;
|
||||
|
||||
protected:
|
||||
std::unordered_map<int, std::unique_ptr<Button>> m_buttons;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "GameUIManager.h"
|
||||
#include "utils/CoordinateTools.h"
|
||||
|
||||
GameUIManager::GameUIManager(SDL_Renderer* renderer, TextRenderer* textRenderer)
|
||||
{
|
||||
m_renderer = renderer;
|
||||
@@ -50,12 +50,11 @@ void GameUIManager::CollectRenderData() {
|
||||
}
|
||||
}
|
||||
|
||||
void GameUIManager::UpdateMousePositon(float x, float y) {
|
||||
void GameUIManager::updateMousePositon(int logicalX, int logicalY) {
|
||||
|
||||
auto logicalPos = physicalToLogical(static_cast<float>(x), static_cast<float>(y), m_renderer);
|
||||
int lx = logicalPos.first;
|
||||
int ly = logicalPos.second;
|
||||
std::string pos = std::to_string(lx) + " " + std::to_string(ly);
|
||||
|
||||
|
||||
std::string pos = std::to_string(logicalX) + " " + std::to_string(logicalY);
|
||||
|
||||
m_labels[makeHash("MousePositionLabel")]->setText(pos);
|
||||
}
|
||||
@@ -163,10 +162,9 @@ void GameUIManager::setupUIComponents() {
|
||||
}
|
||||
|
||||
|
||||
bool GameUIManager::handleClick(float x, float y) {
|
||||
auto logicalPos = physicalToLogical(static_cast<float>(x), static_cast<float>(y), m_renderer);
|
||||
int lx = logicalPos.first;
|
||||
int ly = logicalPos.second;
|
||||
bool GameUIManager::handleClick(int lx, int ly) {
|
||||
|
||||
|
||||
|
||||
// 遍历所有按钮,检查点击位置是否在按钮范围内
|
||||
for (auto& [id, button] : m_buttons) {
|
||||
|
||||
@@ -16,13 +16,13 @@ public:
|
||||
// 收集渲染数据
|
||||
void CollectRenderData();
|
||||
|
||||
void UpdateMousePositon(float x, float y);
|
||||
void updateMousePositon(int logicalX, int logicalY);
|
||||
|
||||
void updateActionType(ActionType type);
|
||||
|
||||
void updateGameState(GameState state);
|
||||
|
||||
bool handleClick(float x, float y);
|
||||
bool handleClick(int logicalX, int logicalY);
|
||||
private:
|
||||
std::function<void()> m_restartCallback;
|
||||
void setupUIComponents();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "MainMenuUIManager.h"
|
||||
#include "utils/CoordinateTools.h"
|
||||
|
||||
#include "ui/base/UIWidgetFactory.h"
|
||||
MainMenuUIManager::MainMenuUIManager(SDL_Renderer* renderer,
|
||||
TextRenderer* textRenderer,
|
||||
@@ -47,11 +47,10 @@ void MainMenuUIManager::CollectRenderData() {
|
||||
}
|
||||
}
|
||||
|
||||
void MainMenuUIManager::UpdateMousePositon(float x, float y) {
|
||||
auto logicalPos = physicalToLogical(static_cast<float>(x), static_cast<float>(y), m_renderer);
|
||||
int lx = logicalPos.first;
|
||||
int ly = logicalPos.second;
|
||||
std::string pos = std::to_string(lx) + " " + std::to_string(ly);
|
||||
void MainMenuUIManager::updateMousePositon(int logicalX, int logicalY) {
|
||||
|
||||
|
||||
std::string pos = std::to_string(logicalX) + " " + std::to_string(logicalY);
|
||||
|
||||
m_labels[makeHash("MousePositionLabel")]->setText(pos);
|
||||
}
|
||||
@@ -61,11 +60,11 @@ const UIRenderData& MainMenuUIManager::getUIRenderData() {
|
||||
return m_uiRenderData;
|
||||
}
|
||||
|
||||
void MainMenuUIManager::handleClick(float x, float y) {
|
||||
auto logicPos = physicalToLogical(x, y, m_renderer);
|
||||
void MainMenuUIManager::handleClick(int logicalX, int logicalY) {
|
||||
|
||||
for (auto& buttonPair : m_buttons) {
|
||||
SDL_Log("Handling click at logical position (%d, %d)\n", logicPos.first, logicPos.second);
|
||||
if (buttonPair.second->handleCilck(logicPos.first, logicPos.second)) {
|
||||
SDL_Log("Handling click at logical position (%d, %d)\n", logicalX, logicalY);
|
||||
if (buttonPair.second->handleCilck(logicalX, logicalY)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@ public:
|
||||
|
||||
void CollectRenderData() override;
|
||||
|
||||
void UpdateMousePositon(float x, float y) override;
|
||||
void updateMousePositon(int logicalX, int logicalY) override;
|
||||
|
||||
void handleClick(float x, float y);
|
||||
void handleClick(int logicalX, int logicalY);
|
||||
|
||||
private:
|
||||
SceneEventCallback m_eventCallback;
|
||||
|
||||
Reference in New Issue
Block a user