2023-11-05 20:34:20 +01:00
|
|
|
#ifndef __RECOMP_UI__
|
|
|
|
#define __RECOMP_UI__
|
|
|
|
|
2023-11-11 23:42:07 +01:00
|
|
|
#include <memory>
|
2024-01-02 04:36:06 +01:00
|
|
|
#include <string>
|
2023-11-11 23:42:07 +01:00
|
|
|
|
2023-11-05 20:34:20 +01:00
|
|
|
#include "SDL.h"
|
2024-04-20 20:25:46 +02:00
|
|
|
#include "RmlUi/Core.h"
|
2023-11-05 20:34:20 +01:00
|
|
|
|
2023-11-11 23:42:07 +01:00
|
|
|
namespace Rml {
|
|
|
|
class ElementDocument;
|
|
|
|
class EventListenerInstancer;
|
2024-01-01 06:09:14 +01:00
|
|
|
class Context;
|
2024-01-02 04:36:06 +01:00
|
|
|
class Event;
|
2023-11-11 23:42:07 +01:00
|
|
|
}
|
|
|
|
|
2024-06-05 01:12:43 +02:00
|
|
|
namespace recompui {
|
2024-01-02 04:36:06 +01:00
|
|
|
class UiEventListenerInstancer;
|
|
|
|
|
|
|
|
class MenuController {
|
|
|
|
public:
|
|
|
|
virtual ~MenuController() {}
|
|
|
|
virtual Rml::ElementDocument* load_document(Rml::Context* context) = 0;
|
|
|
|
virtual void register_events(UiEventListenerInstancer& listener) = 0;
|
|
|
|
virtual void make_bindings(Rml::Context* context) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::unique_ptr<MenuController> create_launcher_menu();
|
|
|
|
std::unique_ptr<MenuController> create_config_menu();
|
|
|
|
|
2024-01-07 08:03:12 +01:00
|
|
|
using event_handler_t = void(const std::string& param, Rml::Event&);
|
2023-11-24 23:10:21 +01:00
|
|
|
|
|
|
|
void queue_event(const SDL_Event& event);
|
|
|
|
bool try_deque_event(SDL_Event& out);
|
2023-11-11 23:42:07 +01:00
|
|
|
|
2024-01-02 04:36:06 +01:00
|
|
|
std::unique_ptr<UiEventListenerInstancer> make_event_listener_instancer();
|
|
|
|
void register_event(UiEventListenerInstancer& listener, const std::string& name, event_handler_t* handler);
|
2023-11-11 23:42:07 +01:00
|
|
|
|
2023-11-24 23:10:21 +01:00
|
|
|
enum class Menu {
|
|
|
|
Launcher,
|
2023-12-29 22:49:26 +01:00
|
|
|
Config,
|
2023-11-24 23:10:21 +01:00
|
|
|
None
|
|
|
|
};
|
|
|
|
|
|
|
|
void set_current_menu(Menu menu);
|
2024-01-08 09:38:05 +01:00
|
|
|
Menu get_current_menu();
|
2024-01-08 07:28:50 +01:00
|
|
|
|
|
|
|
enum class ConfigSubmenu {
|
2024-03-15 17:13:29 +01:00
|
|
|
General,
|
2024-01-08 07:28:50 +01:00
|
|
|
Controls,
|
2024-03-15 17:13:29 +01:00
|
|
|
Graphics,
|
2024-01-08 07:28:50 +01:00
|
|
|
Audio,
|
2024-03-15 17:13:29 +01:00
|
|
|
Debug,
|
2024-01-08 07:28:50 +01:00
|
|
|
Count
|
|
|
|
};
|
|
|
|
|
2024-04-21 22:55:45 +02:00
|
|
|
enum class ButtonVariant {
|
|
|
|
Primary,
|
|
|
|
Secondary,
|
|
|
|
Tertiary,
|
|
|
|
Success,
|
|
|
|
Error,
|
|
|
|
Warning,
|
|
|
|
NumVariants,
|
|
|
|
};
|
|
|
|
|
2024-01-08 07:28:50 +01:00
|
|
|
void set_config_submenu(ConfigSubmenu submenu);
|
|
|
|
|
2023-11-24 23:10:21 +01:00
|
|
|
void destroy_ui();
|
2024-01-06 22:08:15 +01:00
|
|
|
void apply_color_hack();
|
2024-02-18 04:12:23 +01:00
|
|
|
void get_window_size(int& width, int& height);
|
2024-03-12 05:27:20 +01:00
|
|
|
void set_cursor_visible(bool visible);
|
2024-04-01 09:19:16 +02:00
|
|
|
void update_supported_options();
|
|
|
|
void toggle_fullscreen();
|
2024-04-22 15:11:13 +02:00
|
|
|
void update_rml_display_refresh_rate();
|
2024-04-20 20:25:46 +02:00
|
|
|
|
2024-04-21 22:55:45 +02:00
|
|
|
extern const std::unordered_map<ButtonVariant, std::string> button_variants;
|
|
|
|
|
2024-04-20 20:25:46 +02:00
|
|
|
struct PromptContext {
|
|
|
|
Rml::DataModelHandle model_handle;
|
|
|
|
std::string header = "";
|
|
|
|
std::string content = "";
|
|
|
|
std::string confirmLabel = "Confirm";
|
|
|
|
std::string cancelLabel = "Cancel";
|
2024-04-21 22:55:45 +02:00
|
|
|
ButtonVariant confirmVariant = ButtonVariant::Success;
|
|
|
|
ButtonVariant cancelVariant = ButtonVariant::Error;
|
2024-04-20 20:25:46 +02:00
|
|
|
std::function<void()> onConfirm;
|
|
|
|
std::function<void()> onCancel;
|
|
|
|
|
2024-04-21 22:55:45 +02:00
|
|
|
std::string returnElementId = "";
|
|
|
|
|
2024-04-20 20:25:46 +02:00
|
|
|
bool open = false;
|
|
|
|
bool shouldFocus = false;
|
|
|
|
bool focusOnCancel = true;
|
|
|
|
|
|
|
|
PromptContext() = default;
|
|
|
|
|
|
|
|
void close_prompt();
|
|
|
|
void open_prompt(
|
|
|
|
const std::string& headerText,
|
|
|
|
const std::string& contentText,
|
|
|
|
const std::string& confirmLabelText,
|
|
|
|
const std::string& cancelLabelText,
|
|
|
|
std::function<void()> confirmCb,
|
|
|
|
std::function<void()> cancelCb,
|
2024-04-21 22:55:45 +02:00
|
|
|
ButtonVariant _confirmVariant = ButtonVariant::Success,
|
|
|
|
ButtonVariant _cancelVariant = ButtonVariant::Error,
|
|
|
|
bool _focusOnCancel = true,
|
|
|
|
const std::string& _returnElementId = ""
|
2024-04-20 20:25:46 +02:00
|
|
|
);
|
|
|
|
void on_confirm(void);
|
|
|
|
void on_cancel(void);
|
|
|
|
void on_click(Rml::DataModelHandle model_handle, Rml::Event& event, const Rml::VariantList& inputs);
|
|
|
|
};
|
|
|
|
|
|
|
|
PromptContext *get_prompt_context(void);
|
2024-04-30 16:41:22 +02:00
|
|
|
|
|
|
|
bool get_cont_active(void);
|
2024-05-02 07:51:09 +02:00
|
|
|
void set_cont_active(bool active);
|
|
|
|
void activate_mouse();
|
2024-06-05 01:12:43 +02:00
|
|
|
|
2024-06-12 09:40:14 +02:00
|
|
|
void message_box(const char* msg);
|
|
|
|
|
|
|
|
void set_render_hooks();
|
2024-06-28 16:36:40 +02:00
|
|
|
|
|
|
|
Rml::ElementPtr create_custom_element(Rml::Element* parent, std::string tag);
|
2023-11-24 23:10:21 +01:00
|
|
|
}
|
2023-11-11 23:42:07 +01:00
|
|
|
|
2023-11-05 20:34:20 +01:00
|
|
|
#endif
|