Module: Lich::Common::GUI::GameSelection
- Defined in:
- documented/common/gui/game_selection.rb
Overview
Module for game selection GUI functionality Provides methods to create and manage game selection interfaces.
Constant Summary collapse
- GAME_MAPPING =
Game code to display name mapping Maps internal game codes to user-friendly display names Game code to display name mapping Maps internal game codes to user-friendly display names.
{ 'GS3' => 'GemStone IV', 'GSX' => 'GemStone IV Platinum', 'GST' => 'GemStone IV Prime Test', 'GSF' => 'GemStone IV Shattered', 'DR' => 'DragonRealms', 'DRX' => 'DragonRealms Platinum', 'DRT' => 'DragonRealms Prime Test', 'DRF' => 'DragonRealms Fallen' }.freeze
- REVERSE_GAME_MAPPING =
Display name to game code mapping (reverse of GAME_MAPPING) Used for converting user-selected display names back to game codes Display name to game code mapping (reverse of GAME_MAPPING) Used for converting user-selected display names back to game codes.
GAME_MAPPING.invert.freeze
Class Method Summary collapse
-
.create_game_selection_combo(current_selection = nil) ⇒ Gtk::ComboBoxText
Creates a combo box for game selection.
-
.get_game_name(game_code) ⇒ String
Gets the display name for a given game code.
-
.get_selected_game_code(combo) ⇒ String?
Retrieves the game code corresponding to the selected game name in the combo box.
-
.update_game_selection_combo(combo, current_selection = nil) ⇒ void
Updates the game selection combo box with the current game options.
Class Method Details
.create_game_selection_combo(current_selection = nil) ⇒ Gtk::ComboBoxText
Creates a combo box for game selection.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'documented/common/gui/game_selection.rb', line 36 def self.create_game_selection_combo(current_selection = nil) combo = Gtk::ComboBoxText.new # Add all game options GAME_MAPPING.each do |_code, name| combo.append_text(name) end # Set default selection if current_selection && GAME_MAPPING.key?(current_selection) # Set to the provided game code index = GAME_MAPPING.keys.index(current_selection) combo.active = index if index else # Default to GS Prime combo.active = GAME_MAPPING.keys.index('GS3') || 0 end # Add accessibility properties Accessibility.make_combo_accessible( combo, "Game Selection", "Select the game for this character" ) combo end |
.get_game_name(game_code) ⇒ String
Gets the display name for a given game code.
81 82 83 |
# File 'documented/common/gui/game_selection.rb', line 81 def self.get_game_name(game_code) GAME_MAPPING[game_code] || 'Unknown' end |
.get_selected_game_code(combo) ⇒ String?
Retrieves the game code corresponding to the selected game name in the combo box.
69 70 71 72 73 74 |
# File 'documented/common/gui/game_selection.rb', line 69 def self.get_selected_game_code(combo) return nil unless combo selected_text = combo.active_text REVERSE_GAME_MAPPING[selected_text] || 'GS3' # Default to GS3 if not found end |
.update_game_selection_combo(combo, current_selection = nil) ⇒ void
This method returns an undefined value.
Updates the game selection combo box with the current game options.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'documented/common/gui/game_selection.rb', line 91 def self.update_game_selection_combo(combo, current_selection = nil) return unless combo # Clear existing options while combo.remove_text(0) # Keep removing until empty end # Add all game options GAME_MAPPING.each do |_code, name| combo.append_text(name) end # Set selection if current_selection && GAME_MAPPING.key?(current_selection) # Set to the provided game code index = GAME_MAPPING.keys.index(current_selection) combo.active = index if index else # Default to GS Prime combo.active = GAME_MAPPING.keys.index('GS3') || 0 end end |