2025-01-08 21:14:55 -03:00
|
|
|
#include "ui_mod_details_panel.h"
|
|
|
|
|
|
|
|
#include "librecomp/mods.hpp"
|
|
|
|
|
|
|
|
namespace recompui {
|
|
|
|
|
|
|
|
ModDetailsPanel::ModDetailsPanel(Element *parent) : Element(parent) {
|
|
|
|
set_flex(1.0f, 1.0f, 200.0f);
|
|
|
|
set_height(100.0f, Unit::Percent);
|
2025-01-16 23:53:10 -05:00
|
|
|
set_display(Display::Flex);
|
2025-01-08 21:14:55 -03:00
|
|
|
set_flex_direction(FlexDirection::Column);
|
|
|
|
set_border_bottom_right_radius(16.0f);
|
|
|
|
set_background_color(Color{ 190, 184, 219, 25 });
|
|
|
|
|
2025-01-18 20:09:03 -05:00
|
|
|
ContextId context = get_current_context();
|
|
|
|
|
|
|
|
header_container = context.create_element<Container>(FlexDirection::Row, JustifyContent::FlexStart, this);
|
2025-01-16 23:53:10 -05:00
|
|
|
header_container->set_flex(0.0f, 0.0f);
|
2025-01-08 21:14:55 -03:00
|
|
|
header_container->set_padding(16.0f);
|
2025-01-16 23:53:10 -05:00
|
|
|
header_container->set_gap(16.0f);
|
2025-01-08 21:14:55 -03:00
|
|
|
header_container->set_background_color(Color{ 0, 0, 0, 89 });
|
|
|
|
{
|
2025-01-18 20:09:03 -05:00
|
|
|
thumbnail_container = context.create_element<Container>(FlexDirection::Column, JustifyContent::SpaceEvenly, header_container);
|
2025-01-16 23:53:10 -05:00
|
|
|
thumbnail_container->set_flex(0.0f, 0.0f);
|
2025-01-08 21:14:55 -03:00
|
|
|
{
|
2025-01-18 20:09:03 -05:00
|
|
|
thumbnail_image = context.create_element<Image>(thumbnail_container);
|
2025-01-08 21:14:55 -03:00
|
|
|
thumbnail_image->set_width(100.0f);
|
|
|
|
thumbnail_image->set_height(100.0f);
|
|
|
|
thumbnail_image->set_background_color(Color{ 190, 184, 219, 25 });
|
|
|
|
}
|
|
|
|
|
2025-01-18 20:09:03 -05:00
|
|
|
header_details_container = context.create_element<Container>(FlexDirection::Column, JustifyContent::SpaceEvenly, header_container);
|
2025-01-16 23:53:10 -05:00
|
|
|
header_details_container->set_flex(1.0f, 1.0f);
|
|
|
|
header_details_container->set_flex_basis(100.0f, Unit::Percent);
|
|
|
|
header_details_container->set_text_align(TextAlign::Left);
|
2025-01-08 21:14:55 -03:00
|
|
|
{
|
2025-01-18 20:09:03 -05:00
|
|
|
title_label = context.create_element<Label>(LabelStyle::Large, header_details_container);
|
|
|
|
version_label = context.create_element<Label>(LabelStyle::Normal, header_details_container);
|
2025-01-08 21:14:55 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-18 20:09:03 -05:00
|
|
|
body_container = context.create_element<Container>(FlexDirection::Column, JustifyContent::FlexStart, this);
|
2025-01-16 23:53:10 -05:00
|
|
|
body_container->set_flex(0.0f, 0.0f);
|
|
|
|
body_container->set_text_align(TextAlign::Left);
|
|
|
|
body_container->set_padding(16.0f);
|
|
|
|
body_container->set_gap(16.0f);
|
2025-01-08 21:14:55 -03:00
|
|
|
{
|
2025-01-18 20:09:03 -05:00
|
|
|
description_label = context.create_element<Label>(LabelStyle::Normal, body_container);
|
|
|
|
authors_label = context.create_element<Label>(LabelStyle::Normal, body_container);
|
2025-01-16 23:53:10 -05:00
|
|
|
}
|
|
|
|
|
2025-01-18 20:09:03 -05:00
|
|
|
spacer_element = context.create_element<Element>(this);
|
2025-01-16 23:53:10 -05:00
|
|
|
spacer_element->set_flex(1.0f, 0.0f);
|
|
|
|
|
2025-01-18 20:09:03 -05:00
|
|
|
buttons_container = context.create_element<Container>(FlexDirection::Row, JustifyContent::SpaceAround, this);
|
2025-01-16 23:53:10 -05:00
|
|
|
buttons_container->set_flex(0.0f, 0.0f);
|
|
|
|
buttons_container->set_padding(16.0f);
|
|
|
|
{
|
2025-01-18 20:09:03 -05:00
|
|
|
enable_toggle = context.create_element<Toggle>(buttons_container);
|
2025-01-16 23:53:10 -05:00
|
|
|
enable_toggle->add_checked_callback(std::bind(&ModDetailsPanel::enable_toggle_checked, this, std::placeholders::_1));
|
2025-01-18 20:09:03 -05:00
|
|
|
configure_button = context.create_element<Button>("Configure", recompui::ButtonStyle::Secondary, buttons_container);
|
2025-01-18 13:02:19 -03:00
|
|
|
configure_button->add_pressed_callback(std::bind(&ModDetailsPanel::configure_button_pressed, this));
|
2025-01-18 20:09:03 -05:00
|
|
|
erase_button = context.create_element<Button>("Erase", recompui::ButtonStyle::Secondary, buttons_container);
|
2025-01-08 21:14:55 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ModDetailsPanel::~ModDetailsPanel() {
|
|
|
|
}
|
|
|
|
|
2025-01-16 22:34:47 -03:00
|
|
|
void ModDetailsPanel::set_mod_details(const recomp::mods::ModDetails& details, bool mod_enabled, bool toggle_enabled) {
|
2025-01-08 21:14:55 -03:00
|
|
|
cur_details = details;
|
|
|
|
|
|
|
|
title_label->set_text(cur_details.mod_id);
|
|
|
|
version_label->set_text(cur_details.version.to_string());
|
|
|
|
|
|
|
|
std::string authors_str = "<i>Authors</i>:";
|
|
|
|
bool first = true;
|
|
|
|
for (const std::string& author : details.authors) {
|
|
|
|
authors_str += (first ? " " : ", ") + author;
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
authors_label->set_text(authors_str);
|
|
|
|
description_label->set_text("Placeholder description. Some long text to make sure that wrapping is working correctly. Yet more text and so on.");
|
2025-01-16 22:34:47 -03:00
|
|
|
enable_toggle->set_checked(mod_enabled);
|
|
|
|
enable_toggle->set_enabled(toggle_enabled);
|
2025-01-16 21:02:13 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModDetailsPanel::set_mod_toggled_callback(std::function<void(bool)> callback) {
|
|
|
|
mod_toggled_callback = callback;
|
|
|
|
}
|
|
|
|
|
2025-01-18 13:02:19 -03:00
|
|
|
void ModDetailsPanel::set_mod_configure_pressed_callback(std::function<void()> callback) {
|
|
|
|
mod_configure_pressed_callback = callback;
|
|
|
|
}
|
|
|
|
|
2025-01-16 21:02:13 -03:00
|
|
|
void ModDetailsPanel::enable_toggle_checked(bool checked) {
|
|
|
|
if (mod_toggled_callback != nullptr) {
|
|
|
|
mod_toggled_callback(checked);
|
|
|
|
}
|
2025-01-08 21:14:55 -03:00
|
|
|
}
|
|
|
|
|
2025-01-18 13:02:19 -03:00
|
|
|
void ModDetailsPanel::configure_button_pressed() {
|
|
|
|
if (mod_configure_pressed_callback != nullptr) {
|
|
|
|
mod_configure_pressed_callback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-08 21:14:55 -03:00
|
|
|
} // namespace recompui
|