Module: Lich::Common::GUI::GameSelection

Defined in:
documented/common/gui/game_selection.rb

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

GAME_MAPPING.invert.freeze

Class Method Summary collapse

Class Method Details

.create_game_selection_combo(current_selection = nil) ⇒ Gtk::ComboBoxText

Creates a game selection combo box.

Examples:

Create a game selection combo

combo = Lich::Common::GUI::GameSelection.create_game_selection_combo("GS3")

Parameters:

  • current_selection (String, nil) (defaults to: nil)

    the currently selected game code, if any

Returns:

  • (Gtk::ComboBoxText)

    the combo box with game options



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'documented/common/gui/game_selection.rb', line 33

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

Retrieves the display name for a given game code.

Examples:

Get the game name

name = Lich::Common::GUI::GameSelection.get_game_name("GS3")

Parameters:

  • game_code (String)

    the internal game code

Returns:

  • (String)

    the user-friendly display name or 'Unknown' if not found



80
81
82
# File 'documented/common/gui/game_selection.rb', line 80

def self.get_game_name(game_code)
  GAME_MAPPING[game_code] || 'Unknown'
end

.get_selected_game_code(combo) ⇒ String

Retrieves the selected game code from the combo box.

Examples:

Get the selected game code

code = Lich::Common::GUI::GameSelection.get_selected_game_code(combo)

Parameters:

  • combo (Gtk::ComboBoxText)

    the combo box to retrieve the selection from

Returns:

  • (String)

    the selected game code or 'GS3' if not found



67
68
69
70
71
72
# File 'documented/common/gui/game_selection.rb', line 67

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 new options.

Examples:

Update the game selection combo

Lich::Common::GUI::GameSelection.update_game_selection_combo(combo, "GSX")

Parameters:

  • combo (Gtk::ComboBoxText)

    the combo box to update

  • current_selection (String, nil) (defaults to: nil)

    the currently selected game code, if any



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