generated from Persson-dev/Godot-Xmake
add basic main menu
All checks were successful
Linux arm64 / Build (pull_request) Successful in 1m7s
All checks were successful
Linux arm64 / Build (pull_request) Successful in 1m7s
This commit is contained in:
41
godot/Scenes/Menus/mainmenu.tscn
Normal file
41
godot/Scenes/Menus/mainmenu.tscn
Normal file
@@ -0,0 +1,41 @@
|
||||
[gd_scene format=3 uid="uid://bqfqg7xwwlxd8"]
|
||||
|
||||
[node name="Main Menu" type="MainMenu"]
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 4
|
||||
|
||||
[node name="Container" type="VBoxContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -228.512
|
||||
offset_top = -89.5
|
||||
offset_right = 228.512
|
||||
offset_bottom = 89.5
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="JoinButton" type="Button" parent="Container"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 35
|
||||
text = "Join Game"
|
||||
|
||||
[node name="CreateButton" type="Button" parent="Container"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 35
|
||||
text = "Create Game"
|
||||
|
||||
[node name="QuitButton" type="Button" parent="Container"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 35
|
||||
text = "Quit"
|
||||
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