feat: defined game ui with a debug label
This commit is contained in:
parent
28d5fe0301
commit
00c30b4e9f
34
src/game_ui.cpp
Normal file
34
src/game_ui.cpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
#include "game_ui.hpp"
|
||||
#include "godot_cpp/classes/label.hpp"
|
||||
#include "godot_cpp/variant/utility_functions.hpp"
|
||||
#include "rally_rush_game_mode.hpp"
|
||||
#include "utils/game_root.hpp"
|
||||
#include "utils/godot_macros.h"
|
||||
|
||||
namespace godot {
|
||||
void GameUI::_bind_methods() {
|
||||
#define CLASSNAME GameUI
|
||||
}
|
||||
|
||||
void GameUI::_enter_tree() { GDGAMEONLY();
|
||||
Ref<RallyRushGameMode> game_mode{GameRoot3D::get_singleton()->get_game_mode()};
|
||||
game_mode->connect("key_found", callable_mp(this, &GameUI::on_key_found));
|
||||
game_mode->connect("all_keys_found", callable_mp(this, &GameUI::on_all_keys_found));
|
||||
this->debug_info_label = this->get_node<Label>("DebugInfo");
|
||||
if(this->debug_info_label == nullptr)
|
||||
UtilityFunctions::push_error("failed to find debuginfo");
|
||||
}
|
||||
|
||||
void GameUI::append_debug_info(String string) {
|
||||
String text = this->debug_info_label->get_text();
|
||||
this->debug_info_label->set_text(string + "\n" + text);
|
||||
}
|
||||
|
||||
void GameUI::on_key_found(int total_found) {
|
||||
this->append_debug_info(String("Total keys: ") + String::num(total_found));
|
||||
}
|
||||
|
||||
void GameUI::on_all_keys_found() {
|
||||
this->append_debug_info(String("all keys found!!"));
|
||||
}
|
||||
}
|
21
src/game_ui.hpp
Normal file
21
src/game_ui.hpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef GAME_UI_HPP
|
||||
#define GAME_UI_HPP
|
||||
|
||||
#include "godot_cpp/classes/canvas_layer.hpp"
|
||||
#include "godot_cpp/classes/label.hpp"
|
||||
namespace godot {
|
||||
class GameUI : public CanvasLayer {
|
||||
GDCLASS(GameUI, CanvasLayer);
|
||||
static void _bind_methods();
|
||||
public:
|
||||
virtual void _enter_tree() override;
|
||||
void append_debug_info(String string);
|
||||
protected:
|
||||
void on_key_found(int total_found);
|
||||
void on_all_keys_found();
|
||||
private:
|
||||
Label *debug_info_label{nullptr};
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !GAME_UI_HPP
|
Loading…
Reference in a new issue