mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-05-23 14:41:33 -04:00
Some more dual pane select work
This commit is contained in:
Vendored
+1
-1
Submodule extern/aurora updated: d950468064...702583583d
@@ -15,7 +15,7 @@ Rml::Element* createRoot(Rml::Element* parent, const Rml::String& tagName) {
|
||||
|
||||
} // namespace
|
||||
|
||||
Button::Button(Rml::Element* parent, ButtonProps props, const Rml::String& tagName)
|
||||
Button::Button(Rml::Element* parent, Props props, const Rml::String& tagName)
|
||||
: Component(createRoot(parent, tagName)) {
|
||||
update_props(std::move(props));
|
||||
}
|
||||
@@ -55,4 +55,11 @@ void Button::update_props(Props props) {
|
||||
mProps = std::move(props);
|
||||
}
|
||||
|
||||
void ControlledButton::update() {
|
||||
if (mIsSelected) {
|
||||
set_selected(mIsSelected());
|
||||
}
|
||||
Button::update();
|
||||
}
|
||||
|
||||
} // namespace dusk::ui
|
||||
+21
-6
@@ -6,14 +6,12 @@ namespace dusk::ui {
|
||||
|
||||
using ButtonCallback = std::function<void()>;
|
||||
|
||||
struct ButtonProps {
|
||||
Rml::String text;
|
||||
bool selected = false;
|
||||
};
|
||||
|
||||
class Button : public Component {
|
||||
public:
|
||||
using Props = ButtonProps;
|
||||
struct Props {
|
||||
Rml::String text;
|
||||
bool selected = false;
|
||||
};
|
||||
|
||||
Button(Rml::Element* parent, Props props, const Rml::String& tagName = "button");
|
||||
Button(Rml::Element* parent, Rml::String text, const Rml::String& tagName = "button")
|
||||
@@ -31,4 +29,21 @@ private:
|
||||
Props mProps;
|
||||
};
|
||||
|
||||
class ControlledButton : public Button {
|
||||
public:
|
||||
struct Props {
|
||||
Rml::String text;
|
||||
std::function<bool()> isSelected;
|
||||
};
|
||||
|
||||
ControlledButton(Rml::Element* parent, Props props, const Rml::String& tagName = "button")
|
||||
: Button(parent, Button::Props{std::move(props.text)}, tagName),
|
||||
mIsSelected(std::move(props.isSelected)) {}
|
||||
|
||||
void update() override;
|
||||
|
||||
private:
|
||||
std::function<bool()> mIsSelected;
|
||||
};
|
||||
|
||||
} // namespace dusk::ui
|
||||
+42
-3
@@ -4,6 +4,8 @@
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "button.hpp"
|
||||
#include "d/actor/d_a_player.h"
|
||||
#include "d/d_meter2_info.h"
|
||||
#include "number_button.hpp"
|
||||
#include "pane.hpp"
|
||||
#include "select_button.hpp"
|
||||
@@ -395,14 +397,23 @@ EditorWindow::EditorWindow() {
|
||||
leftPane
|
||||
.add_select_button({
|
||||
.key = label,
|
||||
.value = item_label_for_slot(selectItemData),
|
||||
.getValue = [&selectItemData] { return item_label_for_slot(selectItemData); },
|
||||
})
|
||||
.on_hover([&rightPane, &selectItemData](Rml::Event&) {
|
||||
rightPane.clear();
|
||||
rightPane.add_button("None", [&selectItemData] { selectItemData = 0xFF; });
|
||||
rightPane.add_button(
|
||||
{
|
||||
.text = "None",
|
||||
.isSelected = [&selectItemData] { return selectItemData == 0xFF; },
|
||||
},
|
||||
[&selectItemData] { selectItemData = 0xFF; });
|
||||
for (int i = 0; i < 24; i++) {
|
||||
rightPane.add_button(
|
||||
item_label_for_slot(i), [i, &selectItemData] { selectItemData = i; });
|
||||
{
|
||||
.text = item_label_for_slot(i),
|
||||
.isSelected = [i, &selectItemData] { return selectItemData == i; },
|
||||
},
|
||||
[i, &selectItemData] { selectItemData = i; });
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -410,6 +421,34 @@ EditorWindow::EditorWindow() {
|
||||
genSelectItemComboBox("Equip Y", get_player_status()->mSelectItem[1]);
|
||||
genSelectItemComboBox("Combo Equip X", get_player_status()->mMixItem[0]);
|
||||
genSelectItemComboBox("Combo Equip Y", get_player_status()->mMixItem[1]);
|
||||
|
||||
leftPane
|
||||
.add_select_button({
|
||||
.key = "Clothes",
|
||||
.getValue =
|
||||
[] {
|
||||
return itemMap.find(get_player_status()->mSelectEquip[0])->second.m_name;
|
||||
},
|
||||
})
|
||||
.on_hover([&rightPane](Rml::Event&) {
|
||||
rightPane.clear();
|
||||
const auto addOption = [&rightPane](const Rml::String& name, u8 id) {
|
||||
rightPane.add_button(
|
||||
{
|
||||
.text = name,
|
||||
.isSelected =
|
||||
[id] { return get_player_status()->mSelectEquip[0] == id; },
|
||||
},
|
||||
[id] {
|
||||
dMeter2Info_setCloth(id, false);
|
||||
daPy_getPlayerActorClass()->setClothesChange(0);
|
||||
});
|
||||
};
|
||||
addOption("Ordon Clothes", dItemNo_WEAR_CASUAL_e);
|
||||
addOption("Hero's Clothes", dItemNo_WEAR_KOKIRI_e);
|
||||
addOption("Zora Armor", dItemNo_WEAR_ZORA_e);
|
||||
addOption("Magic Armor", dItemNo_ARMOR_e);
|
||||
});
|
||||
});
|
||||
|
||||
add_tab("Location", [this](Rml::Element* content) {
|
||||
|
||||
@@ -19,14 +19,15 @@ public:
|
||||
void update() override;
|
||||
|
||||
Rml::Element* add_section(const Rml::String& text);
|
||||
Button& add_button(Button::Props props, ButtonCallback callback) {
|
||||
return add_child<Button>(std::move(props)).on_pressed(std::move(callback));
|
||||
ControlledButton& add_button(ControlledButton::Props props, ButtonCallback callback) {
|
||||
return static_cast<ControlledButton&>(
|
||||
add_child<ControlledButton>(std::move(props)).on_pressed(std::move(callback)));
|
||||
}
|
||||
Button& add_button(Rml::String text, ButtonCallback callback) {
|
||||
return add_child<Button>(std::move(text)).on_pressed(std::move(callback));
|
||||
}
|
||||
SelectButton& add_select_button(SelectButton::Props props) {
|
||||
return add_child<SelectButton>(std::move(props));
|
||||
ControlledSelectButton& add_select_button(ControlledSelectButton::Props props) {
|
||||
return add_child<ControlledSelectButton>(std::move(props));
|
||||
}
|
||||
Rml::Element* add_text(const Rml::String& text);
|
||||
Rml::Element* add_rml(const Rml::String& rml);
|
||||
|
||||
@@ -91,10 +91,24 @@ bool SelectButton::handle_nav_command(NavCommand cmd) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void ControlledSelectButton::update() {
|
||||
void BaseControlledSelectButton::update() {
|
||||
set_disabled(is_disabled());
|
||||
set_value_label(format_value());
|
||||
SelectButton::update();
|
||||
}
|
||||
|
||||
Rml::String ControlledSelectButton::format_value() {
|
||||
if (!mGetValue) {
|
||||
return "";
|
||||
}
|
||||
return mGetValue();
|
||||
}
|
||||
|
||||
bool ControlledSelectButton::is_disabled() {
|
||||
if (!mIsDisabled) {
|
||||
return false;
|
||||
}
|
||||
return mIsDisabled();
|
||||
}
|
||||
|
||||
} // namespace dusk::ui
|
||||
|
||||
@@ -34,9 +34,9 @@ protected:
|
||||
std::function<void()> mOnHover;
|
||||
};
|
||||
|
||||
class ControlledSelectButton : public SelectButton {
|
||||
class BaseControlledSelectButton : public SelectButton {
|
||||
public:
|
||||
ControlledSelectButton(Rml::Element* parent, Props props)
|
||||
BaseControlledSelectButton(Rml::Element* parent, Props props)
|
||||
: SelectButton(parent, std::move(props)) {}
|
||||
|
||||
void update() override;
|
||||
@@ -46,4 +46,29 @@ protected:
|
||||
virtual bool is_disabled() { return false; }
|
||||
};
|
||||
|
||||
class ControlledSelectButton : public BaseControlledSelectButton {
|
||||
public:
|
||||
struct Props {
|
||||
Rml::String key;
|
||||
std::function<Rml::String()> getValue;
|
||||
std::function<bool()> isDisabled;
|
||||
bool selected = false;
|
||||
};
|
||||
|
||||
ControlledSelectButton(Rml::Element* parent, Props props)
|
||||
: BaseControlledSelectButton(parent,
|
||||
BaseControlledSelectButton::Props{
|
||||
.key = std::move(props.key),
|
||||
.selected = props.selected,
|
||||
}),
|
||||
mGetValue(std::move(props.getValue)), mIsDisabled(std::move(props.isDisabled)) {}
|
||||
|
||||
protected:
|
||||
Rml::String format_value() override;
|
||||
bool is_disabled() override;
|
||||
|
||||
std::function<Rml::String()> mGetValue;
|
||||
std::function<bool()> mIsDisabled;
|
||||
};
|
||||
|
||||
} // namespace dusk::ui
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
namespace dusk::ui {
|
||||
|
||||
BaseStringButton::BaseStringButton(Rml::Element* parent, Props props)
|
||||
: ControlledSelectButton(parent, {std::move(props.key)}), mType(std::move(props.type)),
|
||||
: BaseControlledSelectButton(parent, {std::move(props.key)}), mType(std::move(props.type)),
|
||||
mMaxLength(props.maxLength) {
|
||||
mInputListeners.reserve(3);
|
||||
}
|
||||
@@ -20,7 +20,7 @@ void BaseStringButton::update() {
|
||||
focus_input();
|
||||
}
|
||||
}
|
||||
ControlledSelectButton::update();
|
||||
BaseControlledSelectButton::update();
|
||||
}
|
||||
|
||||
void BaseStringButton::start_editing() {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
namespace dusk::ui {
|
||||
|
||||
class BaseStringButton : public ControlledSelectButton {
|
||||
class BaseStringButton : public BaseControlledSelectButton {
|
||||
public:
|
||||
struct Props {
|
||||
Rml::String key;
|
||||
|
||||
Reference in New Issue
Block a user