mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-07-08 20:24:47 -04:00
Improve disc selector
This commit is contained in:
+20
-14
@@ -11,9 +11,10 @@
|
||||
|
||||
namespace dusk::ui {
|
||||
|
||||
DiscState::DiscState(Rml::Element* parent, std::string_view id, std::string_view text, bool error,
|
||||
DiscState::DiscState(Rml::Element* parent, std::string_view id, std::string_view text,
|
||||
std::string_view statusText, bool statusIsError,
|
||||
std::function<void()> pressedCallback)
|
||||
: m_pressedCallback(std::move(pressedCallback)), m_error(error) {
|
||||
: m_pressedCallback(std::move(pressedCallback)), m_statusIsError(statusIsError) {
|
||||
using namespace theme;
|
||||
|
||||
m_element = append(parent, "button", id);
|
||||
@@ -39,11 +40,6 @@ DiscState::DiscState(Rml::Element* parent, std::string_view id, std::string_view
|
||||
|
||||
add_focus_border(m_element, BorderRadiusSmall);
|
||||
|
||||
m_label = add_label(m_element, error ? "Disc Error" : "Selected Disc", LabelStyle::Annotation);
|
||||
set_props(m_label, {
|
||||
{"pointer-events", "none"},
|
||||
});
|
||||
|
||||
m_value = add_label(m_element, text, LabelStyle::Body);
|
||||
set_props(m_value, {
|
||||
{"overflow", "hidden"},
|
||||
@@ -52,6 +48,14 @@ DiscState::DiscState(Rml::Element* parent, std::string_view id, std::string_view
|
||||
{"pointer-events", "none"},
|
||||
});
|
||||
|
||||
if (!statusText.empty()) {
|
||||
m_status = add_label(m_element, statusText, LabelStyle::Annotation);
|
||||
set_props(m_status, {
|
||||
{"pointer-events", "none"},
|
||||
{"white-space", "normal"},
|
||||
});
|
||||
}
|
||||
|
||||
m_element->AddEventListener(Rml::EventId::Click, this);
|
||||
m_element->AddEventListener(Rml::EventId::Focus, this);
|
||||
m_element->AddEventListener(Rml::EventId::Blur, this);
|
||||
@@ -117,16 +121,18 @@ void DiscState::apply_style() {
|
||||
}
|
||||
|
||||
const bool active = m_hovered || m_focused;
|
||||
const Color accent = m_error ? Danger : Primary;
|
||||
const Color accent = m_statusIsError ? Danger : Primary;
|
||||
|
||||
m_element->SetProperty("background-color", rgba(accent, active ? 52 : (m_error ? 32 : 20)));
|
||||
m_element->SetProperty("border-color", rgba(accent, active ? 220 : (m_error ? 190 : 120)));
|
||||
m_element->SetProperty("background-color",
|
||||
rgba(accent, active ? 52 : (m_statusIsError ? 32 : 20)));
|
||||
m_element->SetProperty("border-color",
|
||||
rgba(accent, active ? 220 : (m_statusIsError ? 190 : 120)));
|
||||
m_element->SetProperty("color", rgba(active ? TextActive : Text));
|
||||
|
||||
m_label->SetProperty("color", rgba(m_error ? Danger : (active ? TextActive : TextDim),
|
||||
m_error ? 220 : (active ? TextActive.a : TextDim.a)));
|
||||
m_value->SetProperty("color", rgba(m_error ? Danger : (active ? TextActive : Text),
|
||||
m_error ? 255 : (active ? TextActive.a : Text.a)));
|
||||
m_value->SetProperty("color", rgba(active ? TextActive : Text));
|
||||
if (m_status != nullptr) {
|
||||
m_status->SetProperty("color", rgba(m_statusIsError ? Danger : TextDim));
|
||||
}
|
||||
set_focus_border_visible(m_element, m_focused);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,8 @@ namespace dusk::ui {
|
||||
|
||||
class DiscState : public Rml::EventListener {
|
||||
public:
|
||||
DiscState(Rml::Element* parent, std::string_view id, std::string_view text, bool error,
|
||||
DiscState(Rml::Element* parent, std::string_view id, std::string_view text,
|
||||
std::string_view statusText, bool statusIsError,
|
||||
std::function<void()> pressedCallback);
|
||||
~DiscState() override;
|
||||
|
||||
@@ -28,10 +29,10 @@ public:
|
||||
|
||||
private:
|
||||
Rml::Element* m_element = nullptr;
|
||||
Rml::Element* m_label = nullptr;
|
||||
Rml::Element* m_value = nullptr;
|
||||
Rml::Element* m_status = nullptr;
|
||||
std::function<void()> m_pressedCallback;
|
||||
bool m_error = false;
|
||||
bool m_statusIsError = false;
|
||||
bool m_hovered = false;
|
||||
bool m_focused = false;
|
||||
|
||||
|
||||
@@ -68,17 +68,17 @@ std::string iso_validation_error_message(iso::ValidationError code) {
|
||||
case iso::ValidationError::InvalidImage:
|
||||
return "Unable to interpret selected file as a disc image";
|
||||
case iso::ValidationError::WrongGame:
|
||||
return "Selected disc is for a different game";
|
||||
return "Disc is for a different game";
|
||||
case iso::ValidationError::WrongVersion:
|
||||
return "Selected disc is for an unsupported version. Only NTSC & PAL GameCube are "
|
||||
return "Disc is for an unsupported version. Only NTSC & PAL GameCube are "
|
||||
"supported at this time";
|
||||
case iso::ValidationError::ExecutableMismatch:
|
||||
return "Selected disc image contains modified executable files.";
|
||||
return "Disc contains modified executable files";
|
||||
case iso::ValidationError::Success:
|
||||
return {};
|
||||
case iso::ValidationError::Unknown:
|
||||
default:
|
||||
return "Unknown disc image validation error";
|
||||
return "Unknown disc validation error";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -400,16 +400,22 @@ private:
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string disc_state_text() const {
|
||||
if (!m_errorString.empty()) {
|
||||
return m_errorString;
|
||||
}
|
||||
|
||||
if (is_selected_path_valid()) {
|
||||
std::string selected_disc_text() const {
|
||||
if (!m_selectedIsoPath.empty()) {
|
||||
return display_path(m_selectedIsoPath);
|
||||
}
|
||||
|
||||
return "No disc image selected";
|
||||
return "Select a disc...";
|
||||
}
|
||||
|
||||
std::string disc_status_text() const {
|
||||
if (!m_errorString.empty()) {
|
||||
return m_errorString;
|
||||
}
|
||||
if (is_selected_path_valid()) {
|
||||
return fmt::format("Disc region: {}", m_isPal ? "PAL" : "NTSC");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
bool should_use_compact_layout() const {
|
||||
@@ -472,9 +478,9 @@ private:
|
||||
void add_disc_control(Rml::Element* parent) {
|
||||
const std::string idString("select-disc");
|
||||
m_focusIds.push_back(idString);
|
||||
m_discState =
|
||||
std::make_unique<DiscState>(parent, idString, disc_state_text(), !m_errorString.empty(),
|
||||
[this, idString] { queue_activation(idString); });
|
||||
m_discState = std::make_unique<DiscState>(
|
||||
parent, idString, selected_disc_text(), disc_status_text(), !m_errorString.empty(),
|
||||
[this, idString] { queue_activation(idString); });
|
||||
}
|
||||
|
||||
void build_main(Rml::Element* screen) {
|
||||
|
||||
Reference in New Issue
Block a user