#include "end_screen.hpp"
#include "godot_cpp/classes/button.hpp"
#include "godot_cpp/classes/global_constants.hpp"
#include "utils/game_root.hpp"
#include "utils/godot_macros.h"

namespace godot {
void EndScreen::_bind_methods() {
#define CLASSNAME EndScreen
    GDPROPERTY_HINTED(main_menu_scene, Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, "PackedScene");
    GDPROPERTY_HINTED(game_scene, Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, "PackedScene");
}

void EndScreen::_ready() { GDGAMEONLY();
    Button *restart_button = this->get_node<Button>("RestartButton");
    restart_button->connect("button_down", callable_mp(this, &EndScreen::restart));
    restart_button->grab_focus();
    Button *main_button = this->get_node<Button>("MainMenuButton");
    main_button->connect("button_down", callable_mp(this, &EndScreen::return_to_main));
}

void EndScreen::return_to_main() {
    GameRoot3D::get_singleton()->replace_levels(this->main_menu_scene);
}

void EndScreen::restart() {
    this->get_owner()->queue_free();
    GameRoot3D::get_singleton()->load_level(this->game_scene);
}

void EndScreen::set_main_menu_scene(Ref<PackedScene> scene) {
    this->main_menu_scene = scene;
}

Ref<PackedScene> EndScreen::get_main_menu_scene() const {
    return this->main_menu_scene;
}

void EndScreen::set_game_scene(Ref<PackedScene> scene) {
    this->game_scene = scene;
}

Ref<PackedScene> EndScreen::get_game_scene() const {
    return this->game_scene;
}
}
