alai/src/Main.cpp

94 lines
1.9 KiB
C++
Raw Normal View History

2022-04-05 14:51:59 -04:00
#include "Main.h"
#include <SceneTree.hpp>
using namespace godot;
using namespace main;
2022-04-05 14:51:59 -04:00
void Main::_register_methods()
{
register_method("_ready", &Main::_ready);
register_method("_physics_process", &Main::_physics_process);
register_property<Main, bool>("full_screen", &Main::set_full_screen, &Main::get_full_screen, main::full_screen);
register_property<Main, Vector2>("window_size", &Main::set_window_size, &Main::get_window_size, main::window_size);
register_property<Main, int8_t>("launch_screen", &Main::set_launch_screen, &Main::get_launch_screen, main::launch_screen);
2022-04-05 14:51:59 -04:00
}
Main::Main()
{
}
Main::~Main()
{
}
void Main::_init()
{
_os = OS::get_singleton();
_input = Input::get_singleton();
full_screen = main::full_screen;
window_size = main::window_size;
launch_screen = main::launch_screen;
2022-04-05 14:51:59 -04:00
}
void Main::_ready()
{
if (get_full_screen())
{
_os->set_window_fullscreen(true);
}
else
{
_os->set_window_size(window_size);
_os->set_window_position(
_os->get_screen_position(get_launch_screen()) + _os->get_screen_size() * 0.5 - _os->get_window_size() * 0.5
);
}
}
void Main::_physics_process(float delta)
{
if (_input->is_action_just_pressed("ui_cancel"))
{
get_tree()->quit();
}
}
2022-04-12 11:33:22 -04:00
void Main::set_full_screen(bool full_screen)
2022-04-05 14:51:59 -04:00
{
2022-04-12 11:33:22 -04:00
this->full_screen = full_screen;
2022-04-05 14:51:59 -04:00
}
bool Main::get_full_screen()
{
2022-04-12 11:33:22 -04:00
return this->full_screen;
2022-04-05 14:51:59 -04:00
}
2022-04-12 11:33:22 -04:00
void Main::set_window_size(Vector2 window_size)
2022-04-05 14:51:59 -04:00
{
2022-04-12 11:33:22 -04:00
this-> window_size = window_size;
2022-04-05 14:51:59 -04:00
}
Vector2 Main::get_window_size()
{
2022-04-12 11:33:22 -04:00
return this->window_size;
2022-04-05 14:51:59 -04:00
}
2022-04-12 11:33:22 -04:00
void Main::set_launch_screen(int8_t launch_screen)
2022-04-05 14:51:59 -04:00
{
2022-04-12 11:33:22 -04:00
this->launch_screen = launch_screen;
2022-04-05 14:51:59 -04:00
}
int8_t Main::get_launch_screen()
{
2022-04-12 11:33:22 -04:00
if (this->launch_screen == -1)
2022-04-05 14:51:59 -04:00
{
return _os->get_current_screen();
}
else
{
2022-04-12 11:33:22 -04:00
return this->launch_screen;
2022-04-05 14:51:59 -04:00
}
}