From 0cbe013a11f5c5ef72d437643fb81ba3e8042973 Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Mon, 4 Mar 2024 20:57:13 -0600 Subject: [PATCH] Use new menu and menu_item elements instead of custom extension, improved styling of list_box menus in game settings --- lib/gui_state_ext.rb | 52 ---------------------- lib/page.rb | 4 -- lib/pages/games.rb | 46 +++++++++++-------- lib/states/dialogs/game_settings_dialog.rb | 22 +++++---- lib/theme.rb | 10 +++++ w3d_hub_linux_launcher.rb | 2 - 6 files changed, 51 insertions(+), 85 deletions(-) delete mode 100644 lib/gui_state_ext.rb diff --git a/lib/gui_state_ext.rb b/lib/gui_state_ext.rb deleted file mode 100644 index 2fa7c7d..0000000 --- a/lib/gui_state_ext.rb +++ /dev/null @@ -1,52 +0,0 @@ -module CyberarmEngine - class GuiState < CyberarmEngine::GameState - def menu(host_element, items:, width: 200) - container = CyberarmEngine::Element::Stack.new( - parent: host_element.parent, - width: width, - theme: W3DHub::THEME, - border_color: 0xff_000000, - border_thickness: 1 - ) - - container.instance_variable_set(:"@__menu", host_element) - - container.define_singleton_method(:recalculate_menu) do - @x = @__menu.x - @y = @__menu.y + @__menu.height - - @y = @__menu.y - height if @y + height > window.height - end - - def container.recalculate - super - - recalculate_menu - end - - items.each do |item| - btn = CyberarmEngine::Element::Button.new( - item[:label], - { - parent: container, - width: 1.0, - text_align: :left, - theme: W3DHub::THEME, - border_thickness: 0, - margin: 0 - }, - proc do - item[:block]&.call - end - ) - container.add(btn) - end - - container.recalculate - container.recalculate - container.recalculate - - show_menu(container) - end - end -end diff --git a/lib/page.rb b/lib/page.rb index 0025336..13cd42d 100644 --- a/lib/page.rb +++ b/lib/page.rb @@ -47,9 +47,5 @@ class W3DHub def button_up(id) end - - def menu(host_element, items:) - @host.menu(host_element, items: items) - end end end \ No newline at end of file diff --git a/lib/pages/games.rb b/lib/pages/games.rb index 08357aa..a3482db 100644 --- a/lib/pages/games.rb +++ b/lib/pages/games.rb @@ -187,26 +187,36 @@ class W3DHub end button get_image("#{GAME_ROOT_PATH}/media/ui_icons/gear.png"), tip: I18n.t(:"games.game_options"), image_height: 32, margin_left: 0 do |btn| - items = [] - - items << { label: I18n.t(:"games.game_settings"), block: proc do - if game.uses_engine_cfg? - push_state(States::GameSettingsDialog, app_id: game.id, channel: channel.id) - else - Store.application_manager.wwconfig(game.id, channel.id) + menu(parent: btn) do + menu_item(I18n.t(:"games.game_settings")) do + if game.uses_engine_cfg? + push_state(States::GameSettingsDialog, app_id: game.id, channel: channel.id) + else + Store.application_manager.wwconfig(game.id, channel.id) + end end - end} - # items << { label: I18n.t(:"games.game_settings"), block: proc { Store.application_manager.settings(game.id, channel.id) } } - items << { label: I18n.t(:"games.wine_configuration"), block: proc { Store.application_manager.wine_configuration(game.id, channel.id) } } if W3DHub.unix? - items << { label: I18n.t(:"games.game_modifications"), block: proc { populate_game_modifications(game, channel) } } unless Store.offline_mode - if game.id != "ren" - items << { label: I18n.t(:"games.repair_installation"), block: proc { Store.application_manager.repair(game.id, channel.id) } } unless Store.offline_mode - items << { label: I18n.t(:"games.uninstall_game"), block: proc { Store.application_manager.uninstall(game.id, channel.id) } } unless Store.offline_mode - end - # From gui_state_ext.rb - # TODO: Implement in engine proper - menu(btn, items: items) + if W3DHub.unix? + menu_item(I18n.t(:"games.wine_configuration")) do + Store.application_manager.wine_configuration(game.id, channel.id) + end + end + + unless Store.offline_mode + menu_item(I18n.t(:"games.game_modifications")) do + populate_game_modifications(game, channel) + end + + if game.id != "ren" + menu_item(I18n.t(:"games.repair_installation")) do + Store.application_manager.repair(game.id, channel.id) + end + menu_item(I18n.t(:"games.uninstall_game")) do + Store.application_manager.uninstall(game.id, channel.id) + end + end + end + end.show end else diff --git a/lib/states/dialogs/game_settings_dialog.rb b/lib/states/dialogs/game_settings_dialog.rb index dc954eb..e8b17e9 100644 --- a/lib/states/dialogs/game_settings_dialog.rb +++ b/lib/states/dialogs/game_settings_dialog.rb @@ -2,6 +2,10 @@ class W3DHub class States class GameSettingsDialog < Dialog BUTTON_STYLE = { text_size: 18, padding_top: 3, padding_bottom: 3, padding_left: 3, padding_right: 3, height: 18 } + LIST_ITEM_THEME = Marshal.load(Marshal.dump(THEME)) + BUTTON_STYLE.each do |key, value| + LIST_ITEM_THEME[:Button][key] = value + end def setup window.show_cursor = true @@ -88,7 +92,7 @@ class W3DHub current_res = "#{@game_settings.get_value(:resolution_width)}x#{@game_settings.get_value(:resolution_height)}" para "Resolution", fill: true, text_wrap: :none - list_box items: res_options, choose: current_res, width: 172, **BUTTON_STYLE do |value| + list_box items: res_options, choose: current_res, width: 172, theme: LIST_ITEM_THEME, **BUTTON_STYLE do |value| w, h = value.split("x", 2) @game_settings.set_value(:resolution_width, w.to_i) @@ -98,7 +102,7 @@ class W3DHub flow(width: 1.0, height: 28, margin: 4, margin_left: 10) do para "Windowed Mode", fill: true, text_wrap: :none - list_box items: @game_settings.get(:windowed_mode).options.map { |v| v[0] }, choose: @game_settings.get_value(:windowed_mode), width: 172, **BUTTON_STYLE do |value| + list_box items: @game_settings.get(:windowed_mode).options.map { |v| v[0] }, choose: @game_settings.get_value(:windowed_mode), width: 172, theme: LIST_ITEM_THEME, **BUTTON_STYLE do |value| @game_settings.set_value(:windowed_mode, value) end end @@ -112,7 +116,7 @@ class W3DHub flow(width: 1.0, height: 28, margin: 4, margin_left: 10) do para "Anti-aliasing", fill: true, text_wrap: :none - list_box items: @game_settings.get(:anti_aliasing).options.map { |v| v[0] }, choose: @game_settings.get_value(:anti_aliasing), width: 72, **BUTTON_STYLE do |value| + list_box items: @game_settings.get(:anti_aliasing).options.map { |v| v[0] }, choose: @game_settings.get_value(:anti_aliasing), width: 72, theme: LIST_ITEM_THEME, **BUTTON_STYLE do |value| @game_settings.set_value(:anti_aliasing, value) end end @@ -191,35 +195,35 @@ class W3DHub flow(width: 1.0, height: 28, margin: 4, margin_left: 10) do para "Texture Detail", fill: true, text_wrap: :none - list_box items: @game_settings.get(:texture_detail).options.map { |v| v[0] }, choose: @game_settings.get_value(:texture_detail), width: 172, **BUTTON_STYLE do |value| + list_box items: @game_settings.get(:texture_detail).options.map { |v| v[0] }, choose: @game_settings.get_value(:texture_detail), width: 172, theme: LIST_ITEM_THEME, **BUTTON_STYLE do |value| @game_settings.set_value(:texture_detail, value) end end flow(width: 1.0, height: 28, margin: 4, margin_left: 10) do para "Texture Filtering", fill: true, text_wrap: :none - list_box items: @game_settings.get(:texture_filtering).options.map { |v| v[0] }, choose: @game_settings.get_value(:texture_filtering), width: 172, **BUTTON_STYLE do |value| + list_box items: @game_settings.get(:texture_filtering).options.map { |v| v[0] }, choose: @game_settings.get_value(:texture_filtering), width: 172, theme: LIST_ITEM_THEME, **BUTTON_STYLE do |value| @game_settings.set_value(:texture_filtering, value) end end # flow(width: 1.0, height: 28, margin: 4, margin_left: 10) do # para "Shader Detail", fill: true - # list_box items: @game_settings.get(:texture_filtering).options.map { |v| v[0] }, choose: @game_settings.get_value(:texture_filtering), width: 172, **BUTTON_STYLE do |value| + # list_box items: @game_settings.get(:texture_filtering).options.map { |v| v[0] }, choose: @game_settings.get_value(:texture_filtering), width: 172, theme: LIST_ITEM_THEME, **BUTTON_STYLE do |value| # @game_settings.set_value(:texture_filtering, value) # end # end # flow(width: 1.0, height: 28, margin: 4, margin_left: 10) do # para "Post Processing Detail", fill: true - # list_box items: @game_settings.get(:texture_filtering).options.map { |v| v[0] }, choose: @game_settings.get_value(:texture_filtering), width: 172, **BUTTON_STYLE do |value| + # list_box items: @game_settings.get(:texture_filtering).options.map { |v| v[0] }, choose: @game_settings.get_value(:texture_filtering), width: 172, theme: LIST_ITEM_THEME, **BUTTON_STYLE do |value| # @game_settings.set_value(:texture_filtering, value) # end # end flow(width: 1.0, height: 28, margin: 4, margin_left: 10) do para "Shadow Resolution", fill: true, text_wrap: :none - list_box items: @game_settings.get(:shadow_resolution).options.map { |v| v[0] }, choose: @game_settings.get_value(:shadow_resolution), width: 172, **BUTTON_STYLE do |value| + list_box items: @game_settings.get(:shadow_resolution).options.map { |v| v[0] }, choose: @game_settings.get_value(:shadow_resolution), width: 172, theme: LIST_ITEM_THEME, **BUTTON_STYLE do |value| @game_settings.set_value(:shadow_resolution, value) end end @@ -233,7 +237,7 @@ class W3DHub flow(width: 1.0, height: 28, margin: 4, margin_left: 10) do para "FPS Limit", fill: true, text_wrap: :none - list_box items: @game_settings.get(:fps).options.map { |v| v[0] }, choose: @game_settings.get_value(:fps), width: 172, **BUTTON_STYLE do |value| + list_box items: @game_settings.get(:fps).options.map { |v| v[0] }, choose: @game_settings.get_value(:fps), width: 172, theme: LIST_ITEM_THEME, **BUTTON_STYLE do |value| @game_settings.set_value(:fps, value.to_i) end end diff --git a/lib/theme.rb b/lib/theme.rb index a957b21..f542b00 100644 --- a/lib/theme.rb +++ b/lib/theme.rb @@ -142,6 +142,16 @@ class W3DHub active: { background: 0xff_005aad } + }, + Menu: { + width: 200, + border_color: 0xaa_efefef, + border_thickness: 1 + }, + MenuItem: { + width: 1.0, + text_left: :left, + margin: 0 } } end diff --git a/w3d_hub_linux_launcher.rb b/w3d_hub_linux_launcher.rb index acf581d..626634a 100644 --- a/w3d_hub_linux_launcher.rb +++ b/w3d_hub_linux_launcher.rb @@ -85,8 +85,6 @@ I18n.load_path << Dir["#{W3DHub::GAME_ROOT_PATH}/locales/*.yml"] I18n.default_locale = :en # GUI_DEBUG = true -require_relative "lib/gui_state_ext" - require_relative "lib/win32_stub" unless Gem.win_platform? require_relative "lib/version"