mirror of
https://github.com/Mr-Wiseguy/Zelda64Recomp.git
synced 2025-02-15 19:19:19 +01:00
Mod menu progress.
This commit is contained in:
parent
2ab4d7dfac
commit
dd6fbceaf7
@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
namespace recompui {
|
namespace recompui {
|
||||||
|
|
||||||
static const std::string hover_state = "hover";
|
static const std::string_view hover_state = "hover";
|
||||||
static const std::string disabled_state = "disabled";
|
static const std::string_view disabled_state = "disabled";
|
||||||
|
|
||||||
Button::Button(const std::string &text, ButtonStyle style, Element *parent) : Element(parent, Events(EventType::Click, EventType::Hover, EventType::Enable), "button") {
|
Button::Button(const std::string &text, ButtonStyle style, Element *parent) : Element(parent, Events(EventType::Click, EventType::Hover, EventType::Enable), "button") {
|
||||||
this->style = style;
|
this->style = style;
|
||||||
|
@ -52,11 +52,13 @@ void Element::add_child(Element *child) {
|
|||||||
void Element::set_property(Rml::PropertyId property_id, const Rml::Property &property, Animation animation) {
|
void Element::set_property(Rml::PropertyId property_id, const Rml::Property &property, Animation animation) {
|
||||||
assert(base != nullptr);
|
assert(base != nullptr);
|
||||||
|
|
||||||
if (animation.type == AnimationType::None) {
|
if (animation.type == AnimationType::None || animation.type == AnimationType::Set) {
|
||||||
base->SetProperty(property_id, property);
|
base->SetProperty(property_id, property);
|
||||||
|
|
||||||
// Only non-animated properties should be stored as part of the style.
|
if (animation.type == AnimationType::None) {
|
||||||
Style::set_property(property_id, property, animation);
|
// Only non-animated properties should be stored as part of the style.
|
||||||
|
Style::set_property(property_id, property, animation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const Rml::String property_name = Rml::StyleSheetSpecification::GetPropertyName(property_id);
|
const Rml::String property_name = Rml::StyleSheetSpecification::GetPropertyName(property_id);
|
||||||
@ -184,6 +186,10 @@ void Element::set_enabled(bool enabled) {
|
|||||||
propagate_disabled(disabled_from_parent);
|
propagate_disabled(disabled_from_parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Element::is_enabled() const {
|
||||||
|
return enabled && !disabled_from_parent;
|
||||||
|
}
|
||||||
|
|
||||||
void Element::set_text(const std::string &text) {
|
void Element::set_text(const std::string &text) {
|
||||||
base->SetInnerRML(text);
|
base->SetInnerRML(text);
|
||||||
}
|
}
|
||||||
|
@ -9,10 +9,18 @@ namespace recompui {
|
|||||||
class Element : public Style, public Rml::EventListener {
|
class Element : public Style, public Rml::EventListener {
|
||||||
friend class Element;
|
friend class Element;
|
||||||
private:
|
private:
|
||||||
|
Rml::Element *base = nullptr;
|
||||||
|
uint32_t events_enabled = 0;
|
||||||
std::vector<Style *> styles;
|
std::vector<Style *> styles;
|
||||||
std::vector<uint32_t> styles_counter;
|
std::vector<uint32_t> styles_counter;
|
||||||
std::unordered_set<std::string_view> style_active_set;
|
std::unordered_set<std::string_view> style_active_set;
|
||||||
std::unordered_multimap<std::string_view, uint32_t> style_name_index_map;
|
std::unordered_multimap<std::string_view, uint32_t> style_name_index_map;
|
||||||
|
std::vector<std::unique_ptr<Element>> children;
|
||||||
|
bool owner = false;
|
||||||
|
bool orphaned = false;
|
||||||
|
bool enabled = true;
|
||||||
|
bool disabled_attribute = false;
|
||||||
|
bool disabled_from_parent = false;
|
||||||
|
|
||||||
void add_child(Element *child);
|
void add_child(Element *child);
|
||||||
void register_event_listeners(uint32_t events_enabled);
|
void register_event_listeners(uint32_t events_enabled);
|
||||||
@ -26,15 +34,6 @@ private:
|
|||||||
// Rml::EventListener overrides.
|
// Rml::EventListener overrides.
|
||||||
virtual void ProcessEvent(Rml::Event &event) override;
|
virtual void ProcessEvent(Rml::Event &event) override;
|
||||||
protected:
|
protected:
|
||||||
Rml::Element *base = nullptr;
|
|
||||||
std::vector<std::unique_ptr<Element>> children;
|
|
||||||
uint32_t events_enabled = 0;
|
|
||||||
bool owner = false;
|
|
||||||
bool orphaned = false;
|
|
||||||
bool enabled = true;
|
|
||||||
bool disabled_attribute = false;
|
|
||||||
bool disabled_from_parent = false;
|
|
||||||
|
|
||||||
virtual void process_event(const Event &e);
|
virtual void process_event(const Event &e);
|
||||||
public:
|
public:
|
||||||
// Used for backwards compatibility with legacy UI elements.
|
// Used for backwards compatibility with legacy UI elements.
|
||||||
@ -47,6 +46,7 @@ public:
|
|||||||
void add_style(Style *style, const std::string_view style_name);
|
void add_style(Style *style, const std::string_view style_name);
|
||||||
void add_style(Style *style, const std::initializer_list<std::string_view> &style_names);
|
void add_style(Style *style, const std::initializer_list<std::string_view> &style_names);
|
||||||
void set_enabled(bool enabled);
|
void set_enabled(bool enabled);
|
||||||
|
bool is_enabled() const;
|
||||||
void set_text(const std::string &text);
|
void set_text(const std::string &text);
|
||||||
void set_style_enabled(const std::string_view &style_name, bool enabled);
|
void set_style_enabled(const std::string_view &style_name, bool enabled);
|
||||||
};
|
};
|
||||||
|
@ -343,8 +343,8 @@ namespace recompui {
|
|||||||
set_property(Rml::PropertyId::FlexBasis, Rml::Property(Rml::Style::FlexBasis::Type::Auto, Rml::Unit::KEYWORD), Animation());
|
set_property(Rml::PropertyId::FlexBasis, Rml::Property(Rml::Style::FlexBasis::Type::Auto, Rml::Unit::KEYWORD), Animation());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Style::set_flex_basis_percentage(float basis, Animation animation) {
|
void Style::set_flex_basis(float basis, Unit unit, Animation animation) {
|
||||||
set_property(Rml::PropertyId::FlexBasis, Rml::Property(basis, Rml::Unit::PERCENT), animation);
|
set_property(Rml::PropertyId::FlexBasis, Rml::Property(basis, to_rml(unit)), animation);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Style::set_flex(float grow, float shrink, Animation animation) {
|
void Style::set_flex(float grow, float shrink, Animation animation) {
|
||||||
@ -353,10 +353,10 @@ namespace recompui {
|
|||||||
set_flex_basis_auto();
|
set_flex_basis_auto();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Style::set_flex(float grow, float shrink, float basis_percentage, Animation animation) {
|
void Style::set_flex(float grow, float shrink, float basis, Unit basis_unit, Animation animation) {
|
||||||
set_flex_grow(grow, animation);
|
set_flex_grow(grow, animation);
|
||||||
set_flex_shrink(shrink, animation);
|
set_flex_shrink(shrink, animation);
|
||||||
set_flex_basis_percentage(basis_percentage, animation);
|
set_flex_basis(basis, basis_unit, animation);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Style::set_flex_direction(FlexDirection flex_direction) {
|
void Style::set_flex_direction(FlexDirection flex_direction) {
|
||||||
|
@ -63,9 +63,9 @@ namespace recompui {
|
|||||||
void set_flex_grow(float grow, Animation animation = Animation());
|
void set_flex_grow(float grow, Animation animation = Animation());
|
||||||
void set_flex_shrink(float shrink, Animation animation = Animation());
|
void set_flex_shrink(float shrink, Animation animation = Animation());
|
||||||
void set_flex_basis_auto();
|
void set_flex_basis_auto();
|
||||||
void set_flex_basis_percentage(float basis_percentage, Animation animation = Animation());
|
void set_flex_basis(float basis, Unit unit = Unit::Percent, Animation animation = Animation());
|
||||||
void set_flex(float grow, float shrink, Animation animation = Animation());
|
void set_flex(float grow, float shrink, Animation animation = Animation());
|
||||||
void set_flex(float grow, float shrink, float basis_percentage, Animation animation = Animation());
|
void set_flex(float grow, float shrink, float basis, Unit basis_unit = Unit::Percent, Animation animation = Animation());
|
||||||
void set_flex_direction(FlexDirection flex_direction);
|
void set_flex_direction(FlexDirection flex_direction);
|
||||||
void set_align_items(AlignItems align_items);
|
void set_align_items(AlignItems align_items);
|
||||||
void set_overflow(Overflow overflow);
|
void set_overflow(Overflow overflow);
|
||||||
|
@ -4,13 +4,31 @@
|
|||||||
|
|
||||||
namespace recompui {
|
namespace recompui {
|
||||||
|
|
||||||
Toggle::Toggle(Element *parent) : Element(parent, Events(EventType::Click, EventType::Hover), "button") {
|
static const std::string_view checked_state = "checked";
|
||||||
|
static const std::string_view hover_state = "hover";
|
||||||
|
static const std::string_view disabled_state = "disabled";
|
||||||
|
|
||||||
|
Toggle::Toggle(Element *parent) : Element(parent, Events(EventType::Click, EventType::Hover, EventType::Enable), "button") {
|
||||||
set_width(162.0f);
|
set_width(162.0f);
|
||||||
set_height(72.0f);
|
set_height(72.0f);
|
||||||
set_border_radius(36.0f);
|
set_border_radius(36.0f);
|
||||||
set_opacity(0.9f);
|
set_opacity(0.9f);
|
||||||
set_cursor(Cursor::Pointer);
|
set_cursor(Cursor::Pointer);
|
||||||
set_border_width(2.0f);
|
set_border_width(2.0f);
|
||||||
|
set_border_color(Color{ 177, 76, 34, 255 });
|
||||||
|
set_background_color(Color{ 0, 0, 0, 0 });
|
||||||
|
checked_style.set_border_color(Color{ 34, 177, 76, 255 });
|
||||||
|
hover_style.set_border_color(Color{ 177, 76, 34, 255 });
|
||||||
|
hover_style.set_background_color(Color{ 206, 120, 68, 76 });
|
||||||
|
checked_hover_style.set_border_color(Color{ 34, 177, 76, 255 });
|
||||||
|
checked_hover_style.set_background_color(Color{ 68, 206, 120, 76 });
|
||||||
|
disabled_style.set_border_color(Color{ 177, 76, 34, 128 });
|
||||||
|
checked_disabled_style.set_border_color(Color{ 34, 177, 76, 128 });
|
||||||
|
add_style(&checked_style, checked_state);
|
||||||
|
add_style(&hover_style, hover_state);
|
||||||
|
add_style(&checked_hover_style, { checked_state, hover_state });
|
||||||
|
add_style(&disabled_style, disabled_state);
|
||||||
|
add_style(&checked_disabled_style, { checked_state, disabled_state });
|
||||||
|
|
||||||
floater = new Element(this);
|
floater = new Element(this);
|
||||||
floater->set_position(Position::Relative);
|
floater->set_position(Position::Relative);
|
||||||
@ -18,37 +36,34 @@ namespace recompui {
|
|||||||
floater->set_width(80.0f);
|
floater->set_width(80.0f);
|
||||||
floater->set_height(64.0f);
|
floater->set_height(64.0f);
|
||||||
floater->set_border_radius(32.0f);
|
floater->set_border_radius(32.0f);
|
||||||
|
floater->set_background_color(Color{ 177, 76, 34, 255 });
|
||||||
|
floater_checked_style.set_background_color(Color{ 34, 177, 76, 255 });
|
||||||
|
floater_disabled_style.set_background_color(Color{ 177, 76, 34, 128 });
|
||||||
|
floater_disabled_checked_style.set_background_color(Color{ 34, 177, 76, 128 });
|
||||||
|
floater->add_style(&floater_checked_style, checked_state);
|
||||||
|
floater->add_style(&floater_disabled_style, disabled_state);
|
||||||
|
floater->add_style(&floater_disabled_checked_style, { checked_state, disabled_state });
|
||||||
|
|
||||||
set_checked_internal(false, false, true);
|
set_checked_internal(false, false, true);
|
||||||
update_properties();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Toggle::set_checked_internal(bool checked, bool animate, bool setup) {
|
void Toggle::set_checked_internal(bool checked, bool animate, bool setup) {
|
||||||
if (this->checked != checked || setup) {
|
if (this->checked != checked || setup) {
|
||||||
this->checked = checked;
|
this->checked = checked;
|
||||||
|
|
||||||
floater->set_left(floater_left_target(), Unit::Dp, animate ? Animation::tween(0.1f) : Animation());
|
floater->set_left(floater_left_target(), Unit::Dp, animate ? Animation::tween(0.1f) : Animation::set());
|
||||||
|
|
||||||
if (!setup) {
|
if (!setup) {
|
||||||
update_properties();
|
|
||||||
|
|
||||||
for (const auto &function : checked_callbacks) {
|
for (const auto &function : checked_callbacks) {
|
||||||
function(checked);
|
function(checked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_style_enabled(checked_state, checked);
|
||||||
|
floater->set_style_enabled(checked_state, checked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Toggle::update_properties() {
|
|
||||||
Color border_color = checked ? Color{ 34, 177, 76, 255 } : Color{ 177, 76, 34, 255 };
|
|
||||||
Color main_color = checked ? Color{ 68, 206, 120, 255 } : Color{ 206, 120, 68, 255 };
|
|
||||||
main_color.a = hovered ? 76 : 0;
|
|
||||||
|
|
||||||
set_border_color(border_color);
|
|
||||||
set_background_color(main_color);
|
|
||||||
floater->set_background_color(border_color);
|
|
||||||
}
|
|
||||||
|
|
||||||
float Toggle::floater_left_target() const {
|
float Toggle::floater_left_target() const {
|
||||||
return checked ? 4.0f : 78.0f;
|
return checked ? 4.0f : 78.0f;
|
||||||
}
|
}
|
||||||
@ -56,11 +71,18 @@ namespace recompui {
|
|||||||
void Toggle::process_event(const Event &e) {
|
void Toggle::process_event(const Event &e) {
|
||||||
switch (e.type) {
|
switch (e.type) {
|
||||||
case EventType::Click:
|
case EventType::Click:
|
||||||
set_checked_internal(!checked, true, false);
|
if (is_enabled()) {
|
||||||
|
set_checked_internal(!checked, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case EventType::Hover:
|
case EventType::Hover:
|
||||||
hovered = e.hover.active;
|
set_style_enabled(hover_state, e.hover.active);
|
||||||
update_properties();
|
floater->set_style_enabled(hover_state, e.hover.active);
|
||||||
|
break;
|
||||||
|
case EventType::Enable:
|
||||||
|
set_style_enabled(disabled_state, !e.enable.enable);
|
||||||
|
floater->set_style_enabled(disabled_state, !e.enable.enable);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(false && "Unknown event type.");
|
assert(false && "Unknown event type.");
|
||||||
|
@ -8,11 +8,17 @@ namespace recompui {
|
|||||||
protected:
|
protected:
|
||||||
Element *floater;
|
Element *floater;
|
||||||
std::list<std::function<void(bool)>> checked_callbacks;
|
std::list<std::function<void(bool)>> checked_callbacks;
|
||||||
|
Style checked_style;
|
||||||
|
Style hover_style;
|
||||||
|
Style checked_hover_style;
|
||||||
|
Style disabled_style;
|
||||||
|
Style checked_disabled_style;
|
||||||
|
Style floater_checked_style;
|
||||||
|
Style floater_disabled_style;
|
||||||
|
Style floater_disabled_checked_style;
|
||||||
bool checked = false;
|
bool checked = false;
|
||||||
bool hovered = false;
|
|
||||||
|
|
||||||
void set_checked_internal(bool checked, bool animate, bool setup);
|
void set_checked_internal(bool checked, bool animate, bool setup);
|
||||||
void update_properties();
|
|
||||||
float floater_left_target() const;
|
float floater_left_target() const;
|
||||||
|
|
||||||
// Element overrides.
|
// Element overrides.
|
||||||
|
@ -138,6 +138,7 @@ namespace recompui {
|
|||||||
|
|
||||||
enum class AnimationType {
|
enum class AnimationType {
|
||||||
None,
|
None,
|
||||||
|
Set,
|
||||||
Tween
|
Tween
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -157,6 +158,12 @@ namespace recompui {
|
|||||||
AnimationType type = AnimationType::None;
|
AnimationType type = AnimationType::None;
|
||||||
float duration = 0.0f;
|
float duration = 0.0f;
|
||||||
|
|
||||||
|
static Animation set() {
|
||||||
|
Animation a;
|
||||||
|
a.type = AnimationType::Set;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
static Animation tween(float duration) {
|
static Animation tween(float duration) {
|
||||||
Animation a;
|
Animation a;
|
||||||
a.type = AnimationType::Tween;
|
a.type = AnimationType::Tween;
|
||||||
|
@ -39,6 +39,7 @@ ModDetailsPanel::ModDetailsPanel(Element *parent) : Element(parent) {
|
|||||||
{
|
{
|
||||||
description_label = new Label(LabelStyle::Normal, body_container);
|
description_label = new Label(LabelStyle::Normal, body_container);
|
||||||
authors_label = new Label(LabelStyle::Normal, body_container);
|
authors_label = new Label(LabelStyle::Normal, body_container);
|
||||||
|
spacer_element = new Element(body_container);
|
||||||
buttons_container = new Container(FlexDirection::Row, JustifyContent::SpaceAround, body_container);
|
buttons_container = new Container(FlexDirection::Row, JustifyContent::SpaceAround, body_container);
|
||||||
buttons_container->set_padding_left(16.0f);
|
buttons_container->set_padding_left(16.0f);
|
||||||
{
|
{
|
||||||
@ -53,7 +54,7 @@ ModDetailsPanel::ModDetailsPanel(Element *parent) : Element(parent) {
|
|||||||
ModDetailsPanel::~ModDetailsPanel() {
|
ModDetailsPanel::~ModDetailsPanel() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModDetailsPanel::set_mod_details(const recomp::mods::ModDetails& details, bool enabled) {
|
void ModDetailsPanel::set_mod_details(const recomp::mods::ModDetails& details, bool mod_enabled, bool toggle_enabled) {
|
||||||
cur_details = details;
|
cur_details = details;
|
||||||
|
|
||||||
title_label->set_text(cur_details.mod_id);
|
title_label->set_text(cur_details.mod_id);
|
||||||
@ -68,7 +69,8 @@ void ModDetailsPanel::set_mod_details(const recomp::mods::ModDetails& details, b
|
|||||||
|
|
||||||
authors_label->set_text(authors_str);
|
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.");
|
description_label->set_text("Placeholder description. Some long text to make sure that wrapping is working correctly. Yet more text and so on.");
|
||||||
enable_toggle->set_checked(enabled);
|
enable_toggle->set_checked(mod_enabled);
|
||||||
|
enable_toggle->set_enabled(toggle_enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModDetailsPanel::set_mod_toggled_callback(std::function<void(bool)> callback) {
|
void ModDetailsPanel::set_mod_toggled_callback(std::function<void(bool)> callback) {
|
||||||
|
@ -14,7 +14,7 @@ class ModDetailsPanel : public Element {
|
|||||||
public:
|
public:
|
||||||
ModDetailsPanel(Element *parent);
|
ModDetailsPanel(Element *parent);
|
||||||
virtual ~ModDetailsPanel();
|
virtual ~ModDetailsPanel();
|
||||||
void set_mod_details(const recomp::mods::ModDetails& details, bool enabled);
|
void set_mod_details(const recomp::mods::ModDetails& details, bool mod_enabled, bool toggle_enabled);
|
||||||
void set_mod_toggled_callback(std::function<void(bool)> callback);
|
void set_mod_toggled_callback(std::function<void(bool)> callback);
|
||||||
private:
|
private:
|
||||||
recomp::mods::ModDetails cur_details;
|
recomp::mods::ModDetails cur_details;
|
||||||
@ -27,6 +27,7 @@ private:
|
|||||||
Container *body_container = nullptr;
|
Container *body_container = nullptr;
|
||||||
Label *description_label = nullptr;
|
Label *description_label = nullptr;
|
||||||
Label *authors_label = nullptr;
|
Label *authors_label = nullptr;
|
||||||
|
Element *spacer_element = nullptr;
|
||||||
Container *buttons_container = nullptr;
|
Container *buttons_container = nullptr;
|
||||||
Toggle *enable_toggle = nullptr;
|
Toggle *enable_toggle = nullptr;
|
||||||
Button *configure_button = nullptr;
|
Button *configure_button = nullptr;
|
||||||
|
@ -73,7 +73,9 @@ void ModMenu::set_active_mod(int32_t mod_index) {
|
|||||||
active_mod_index = mod_index;
|
active_mod_index = mod_index;
|
||||||
if (active_mod_index >= 0) {
|
if (active_mod_index >= 0) {
|
||||||
bool mod_enabled = recomp::mods::is_mod_enabled(mod_details[mod_index].mod_id);
|
bool mod_enabled = recomp::mods::is_mod_enabled(mod_details[mod_index].mod_id);
|
||||||
mod_details_panel->set_mod_details(mod_details[mod_index], mod_enabled);
|
bool auto_enabled = recomp::mods::is_mod_auto_enabled(mod_details[mod_index].mod_id);
|
||||||
|
bool toggle_enabled = !auto_enabled && (mod_details[mod_index].runtime_toggleable || !ultramodern::is_game_started());
|
||||||
|
mod_details_panel->set_mod_details(mod_details[mod_index], mod_enabled, toggle_enabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +123,7 @@ ModMenu::ModMenu(Element *parent) : Element(parent) {
|
|||||||
{
|
{
|
||||||
list_container = new Container(FlexDirection::Column, JustifyContent::Center, body_container);
|
list_container = new Container(FlexDirection::Column, JustifyContent::Center, body_container);
|
||||||
list_container->set_display(Display::Block);
|
list_container->set_display(Display::Block);
|
||||||
list_container->set_flex_basis_percentage(100.0f);
|
list_container->set_flex_basis(100.0f);
|
||||||
list_container->set_align_items(AlignItems::Center);
|
list_container->set_align_items(AlignItems::Center);
|
||||||
list_container->set_height(100.0f, Unit::Percent);
|
list_container->set_height(100.0f, Unit::Percent);
|
||||||
list_container->set_background_color(Color{ 0, 0, 0, 89 });
|
list_container->set_background_color(Color{ 0, 0, 0, 89 });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user