/*
* Copyright (C) 2023 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see .
*/
#include "game/states/controls-menu-state.hpp"
#include "game/states/keyboard-config-menu-state.hpp"
#include "game/states/gamepad-config-menu-state.hpp"
#include "game/states/options-menu-state.hpp"
#include "game/controls.hpp"
#include
#include
#include "game/menu.hpp"
#include "game/strings.hpp"
#include
using namespace hash::literals;
controls_menu_state::controls_menu_state(::game& ctx):
game_state(ctx)
{
debug::log_trace("Entering controls menu state...");
// Construct menu item texts
keyboard_text = std::make_unique();
gamepad_text = std::make_unique();
back_text = std::make_unique();
// Build list of menu item texts
ctx.menu_item_texts.push_back({keyboard_text.get(), nullptr});
ctx.menu_item_texts.push_back({gamepad_text.get(), nullptr});
ctx.menu_item_texts.push_back({back_text.get(), nullptr});
// Set content of menu item texts
keyboard_text->set_content(get_string(ctx, "controls_menu_keyboard"));
gamepad_text->set_content(get_string(ctx, "controls_menu_gamepad"));
back_text->set_content(get_string(ctx, "back"));
// Init menu item index
::menu::init_menu_item_index(ctx, "controls");
::menu::update_text_color(ctx);
::menu::update_text_font(ctx);
::menu::align_text(ctx, true);
::menu::add_text_to_ui(ctx);
::menu::setup_animations(ctx);
// Construct menu item callbacks
auto select_keyboard_callback = [&ctx]()
{
// Disable menu controls
ctx.function_queue.push(std::bind(::disable_menu_controls, std::ref(ctx)));
::menu::fade_out
(
ctx,
[&ctx]()
{
// Queue change to keyboard config menu state
ctx.function_queue.push
(
[&ctx]()
{
ctx.state_machine.pop();
ctx.state_machine.emplace(std::make_unique(ctx));
}
);
}
);
};
auto select_gamepad_callback = [&ctx]()
{
// Disable menu controls
ctx.function_queue.push(std::bind(::disable_menu_controls, std::ref(ctx)));
::menu::fade_out
(
ctx,
[&ctx]()
{
// Queue change to gamepad config menu state
ctx.function_queue.push
(
[&ctx]()
{
ctx.state_machine.pop();
ctx.state_machine.emplace(std::make_unique(ctx));
}
);
}
);
};
auto select_back_callback = [&ctx]()
{
// Disable menu controls
ctx.function_queue.push(std::bind(::disable_menu_controls, std::ref(ctx)));
::menu::fade_out
(
ctx,
[&ctx]()
{
// Queue change to options menu state
ctx.function_queue.push
(
[&ctx]()
{
ctx.state_machine.pop();
ctx.state_machine.emplace(std::make_unique(ctx));
}
);
}
);
};
// Build list of menu select callbacks
ctx.menu_select_callbacks.push_back(select_keyboard_callback);
ctx.menu_select_callbacks.push_back(select_gamepad_callback);
ctx.menu_select_callbacks.push_back(select_back_callback);
// Build list of menu left callbacks
ctx.menu_left_callbacks.push_back(nullptr);
ctx.menu_left_callbacks.push_back(nullptr);
ctx.menu_left_callbacks.push_back(nullptr);
// Build list of menu right callbacks
ctx.menu_right_callbacks.push_back(nullptr);
ctx.menu_right_callbacks.push_back(nullptr);
ctx.menu_right_callbacks.push_back(nullptr);
// Set menu back callback
ctx.menu_back_callback = select_back_callback;
// Queue menu control setup
ctx.function_queue.push(std::bind(::enable_menu_controls, std::ref(ctx)));
// Fade in menu
::menu::fade_in(ctx, nullptr);
debug::log_trace("Entered controls menu state");
}
controls_menu_state::~controls_menu_state()
{
debug::log_trace("Exiting options menu state...");
// Destruct menu
::disable_menu_controls(ctx);
::menu::clear_callbacks(ctx);
::menu::delete_animations(ctx);
::menu::remove_text_from_ui(ctx);
::menu::delete_text(ctx);
debug::log_trace("Exited controls menu state");
}