summaryrefslogtreecommitdiff
path: root/lib/nes
diff options
context:
space:
mode:
Diffstat (limited to 'lib/nes')
-rw-r--r--lib/nes/app/application.cc4
-rw-r--r--lib/nes/app/application.hh2
-rw-r--r--lib/nes/app/ui/screen-help.cc110
-rw-r--r--lib/nes/app/ui/screen-help.hh23
4 files changed, 138 insertions, 1 deletions
diff --git a/lib/nes/app/application.cc b/lib/nes/app/application.cc
index 622fdf7..2637d19 100644
--- a/lib/nes/app/application.cc
+++ b/lib/nes/app/application.cc
@@ -1,5 +1,6 @@
#include "nes/app/application.hh"
#include "nes/app/input/input-device-keyboard.hh"
+#include "nes/app/input/input-device-controller.hh"
#include "nes/app/ui/screen.hh"
#include "nes/app/graphics/renderer.hh"
#include "nes/app/action.hh"
@@ -53,6 +54,7 @@ namespace nes::app
, screen_title_{ keyboard }
, screen_browser_{ keyboard, file_browser }
, screen_settings_{ input_manager_, preferences_ }
+ , screen_help_{ input_manager_ }
, screen_error_{ keyboard }
, screen_confirm_quit_{ keyboard }
, screen_prompt_key_{ keyboard }
@@ -142,7 +144,7 @@ namespace nes::app
}
case action::type::go_to_help:
{
- // TODO
+ go_to_screen(&screen_help_);
break;
}
case action::type::close_popup:
diff --git a/lib/nes/app/application.hh b/lib/nes/app/application.hh
index cee99ed..2c1d304 100644
--- a/lib/nes/app/application.hh
+++ b/lib/nes/app/application.hh
@@ -4,6 +4,7 @@
#include "nes/app/ui/screen-title.hh"
#include "nes/app/ui/screen-browser.hh"
#include "nes/app/ui/screen-settings.hh"
+#include "nes/app/ui/screen-help.hh"
#include "nes/app/ui/screen-freeze.hh"
#include "nes/app/ui/screen-error.hh"
#include "nes/app/ui/screen-confirm-quit.hh"
@@ -63,6 +64,7 @@ namespace nes::app
screen_title screen_title_;
screen_browser screen_browser_;
screen_settings screen_settings_;
+ screen_help screen_help_;
screen_freeze screen_freeze_;
screen_error screen_error_;
screen_confirm_quit screen_confirm_quit_;
diff --git a/lib/nes/app/ui/screen-help.cc b/lib/nes/app/ui/screen-help.cc
new file mode 100644
index 0000000..55d7b86
--- /dev/null
+++ b/lib/nes/app/ui/screen-help.cc
@@ -0,0 +1,110 @@
+#include "nes/app/ui/screen-help.hh"
+#include "nes/app/input/input-manager.hh"
+#include "nes/app/preferences.hh"
+
+namespace
+{
+
+
+}
+
+namespace nes::app
+{
+ screen_help::screen_help(input_manager& input_manager)
+ : input_manager_{ input_manager }
+ { }
+
+ auto screen_help::render(renderer& renderer) -> void
+ {
+ renderer.render_fill(color::background_primary);
+ renderer.render_rect(0, 0, 32, 3, color::background_secondary);
+
+ renderer.render_text(
+ 2, 1, "Key Bindings", color::foreground_primary,
+ text_attributes{}.set_max_width(26).set_ellipsize_mode(ellipsize_mode::middle));
+
+ auto render_list_item = [&](unsigned& y, string_view name, string_view value, bool fullline = true, bool left = true) -> void
+ {
+ unsigned x_offset = 2;
+ unsigned container_width = renderer::width - 2 * x_offset;
+ if (!fullline)
+ {
+ container_width -= x_offset; // offset between columns
+ container_width /= 2;
+ }
+
+ unsigned column_offset = 0;
+ if (!fullline && !left)
+ {
+ column_offset = container_width + 2 * x_offset;
+ }
+ else
+ {
+ column_offset = x_offset;
+ }
+
+ unsigned max_val_width = (container_width - x_offset) / 2;
+ unsigned value_width = value.get_length();
+ if (value_width > max_val_width)
+ {
+ value_width = max_val_width;
+ }
+
+ unsigned name_width = container_width - value_width - x_offset;
+
+ renderer.render_text(
+ column_offset, y, name, color::foreground_primary,
+ text_attributes{}.set_max_width(name_width).set_ellipsize_mode(ellipsize_mode::middle));
+
+ renderer.render_text(
+ column_offset + container_width, y, value, color::foreground_secondary,
+ text_attributes{}.set_alignment(text_alignment::right).set_max_width(value_width).set_ellipsize_mode(ellipsize_mode::middle));
+
+ if (fullline || !left)
+ {
+ y += 2;
+ }
+ };
+
+ auto render_title = [&](unsigned& y, string_view title) -> void
+ {
+ renderer.render_text(
+ 14 + 2, y, title, color::accent_primary,
+ text_attributes{}.set_alignment(nes::app::text_alignment::center).set_max_width(28).set_ellipsize_mode(ellipsize_mode::middle));
+ y += 2;
+ };
+
+ unsigned y_offset = 5;
+
+ render_title(y_offset, "> Launcher <");
+
+ render_list_item(y_offset, "Select", "<Enter>");
+ render_list_item(y_offset, "Navigation", "<Arrow Keys>");
+ render_list_item(y_offset, "Go Back", "<Backspace>");
+
+ y_offset += 1;
+ render_title(y_offset, "> Games <");
+
+ render_list_item(y_offset, "Up", "W", false, true);
+ render_list_item(y_offset, "Left", "A", false, false);
+ render_list_item(y_offset, "Down", "S", false, true);
+ render_list_item(y_offset, "Right", "D", false, false);
+ render_list_item(y_offset, "Action B", "K", false, true);
+ render_list_item(y_offset, "Action A", "L", false, false);
+ render_list_item(y_offset, "Start", "<Enter>");
+ render_list_item(y_offset, "Select", "<Space>");
+ }
+
+ auto screen_help::process_events() -> action
+ {
+ while (auto const event = input_manager_.get_keyboard().poll_event())
+ {
+ if (event == input_event::key_down(key::backspace))
+ {
+ return action::go_to_title();
+ }
+ }
+
+ return action{};
+ }
+} // namespace nes::app \ No newline at end of file
diff --git a/lib/nes/app/ui/screen-help.hh b/lib/nes/app/ui/screen-help.hh
new file mode 100644
index 0000000..882772b
--- /dev/null
+++ b/lib/nes/app/ui/screen-help.hh
@@ -0,0 +1,23 @@
+#pragma once
+
+#include "nes/app/ui/screen.hh"
+#include "nes/app/ui/selection.hh"
+
+namespace nes::app
+{
+ class input_manager;
+
+ /// Screen used to configure various emulator options.
+ class screen_help final : public screen
+ {
+ static constexpr auto page_size = u32{ 8 };
+
+ input_manager& input_manager_;
+
+ public:
+ explicit screen_help(input_manager&);
+
+ auto render(renderer&) -> void override;
+ auto process_events() -> action override;
+ };
+} // namespace nes::app \ No newline at end of file