generated from Persson-dev/Godot-Xmake
Add main menu (#1)
Il est caché pour l'instant parce que c'est plus rapide à debug le reste pour le moment Reviewed-on: #1 Co-authored-by: Persson-dev <sim16.prib@gmail.com> Co-committed-by: Persson-dev <sim16.prib@gmail.com>
This commit is contained in:
47
src/MainMenu.cpp
Normal file
47
src/MainMenu.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "MainMenu.h"
|
||||
|
||||
#include <godot_cpp/classes/resource_loader.hpp>
|
||||
#include <godot_cpp/classes/scene_tree.hpp>
|
||||
|
||||
using namespace godot;
|
||||
|
||||
static constexpr char MainScenePath[] = "res://Scenes/Levels/world.tscn";
|
||||
|
||||
namespace blitz {
|
||||
|
||||
void MainMenu::_bind_methods() {}
|
||||
|
||||
MainMenu::MainMenu() {}
|
||||
|
||||
MainMenu::~MainMenu() {}
|
||||
|
||||
void MainMenu::_ready() {
|
||||
Node* container = find_child("Container");
|
||||
DEV_ASSERT(container);
|
||||
|
||||
m_JoinButton = Object::cast_to<Button>(container->find_child("JoinButton"));
|
||||
m_CreateButton = Object::cast_to<Button>(container->find_child("CreateButton"));
|
||||
m_QuitButton = Object::cast_to<Button>(container->find_child("QuitButton"));
|
||||
|
||||
DEV_ASSERT(m_JoinButton);
|
||||
DEV_ASSERT(m_CreateButton);
|
||||
DEV_ASSERT(m_QuitButton);
|
||||
|
||||
m_JoinButton->connect("pressed", callable_mp(this, &MainMenu::OnJoinPressed));
|
||||
m_CreateButton->connect("pressed", callable_mp(this, &MainMenu::OnCreatePressed));
|
||||
m_QuitButton->connect("pressed", callable_mp(this, &MainMenu::OnQuitPressed));
|
||||
}
|
||||
|
||||
void MainMenu::OnJoinPressed() {
|
||||
get_tree()->change_scene_to_file(MainScenePath);
|
||||
}
|
||||
|
||||
void MainMenu::OnCreatePressed() {
|
||||
get_tree()->change_scene_to_file(MainScenePath);
|
||||
}
|
||||
|
||||
void MainMenu::OnQuitPressed() {
|
||||
get_tree()->quit();
|
||||
}
|
||||
|
||||
} // namespace blitz
|
||||
30
src/MainMenu.h
Normal file
30
src/MainMenu.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <godot_cpp/classes/button.hpp>
|
||||
#include <godot_cpp/classes/control.hpp>
|
||||
|
||||
namespace blitz {
|
||||
|
||||
class MainMenu : public godot::Control {
|
||||
GDCLASS(MainMenu, godot::Control)
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
MainMenu();
|
||||
~MainMenu();
|
||||
|
||||
// Godot overrides
|
||||
void _ready() override;
|
||||
|
||||
private:
|
||||
godot::Button* m_JoinButton;
|
||||
godot::Button* m_CreateButton;
|
||||
godot::Button* m_QuitButton;
|
||||
|
||||
void OnJoinPressed();
|
||||
void OnCreatePressed();
|
||||
void OnQuitPressed();
|
||||
};
|
||||
|
||||
} // namespace blitz
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "FirstPersonPlayer.h"
|
||||
#include "Player.h"
|
||||
#include "SpringArmPivot.h"
|
||||
#include "MainMenu.h"
|
||||
|
||||
#include <gdextension_interface.h>
|
||||
#include <godot_cpp/core/defs.hpp>
|
||||
@@ -10,14 +11,19 @@
|
||||
|
||||
using namespace godot;
|
||||
|
||||
static void RegisterClasses() {
|
||||
ClassDB::register_class<blitz::Player>();
|
||||
ClassDB::register_class<blitz::SpringArmPivot>();
|
||||
ClassDB::register_class<blitz::FirstPersonPlayer>();
|
||||
ClassDB::register_class<blitz::MainMenu>();
|
||||
}
|
||||
|
||||
void initialize_example_module(ModuleInitializationLevel p_level) {
|
||||
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
|
||||
return;
|
||||
}
|
||||
|
||||
ClassDB::register_class<blitz::Player>();
|
||||
ClassDB::register_class<blitz::SpringArmPivot>();
|
||||
ClassDB::register_class<blitz::FirstPersonPlayer>();
|
||||
RegisterClasses();
|
||||
}
|
||||
|
||||
void uninitialize_example_module(ModuleInitializationLevel p_level) {
|
||||
|
||||
Reference in New Issue
Block a user