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.

Examples:

Using the GameSelection module

combo = Lich::Common::GUI::GameSelection.create_game_selection_combo

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

Class Method Details

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

Creates a combo box for game selection.

Examples:

Creating a game selection combo

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

Parameters:

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

    The game code to set as the default selection.

Returns:

  • (Gtk::ComboBoxText)

    The combo box populated with game options.



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.

Examples:

Getting a 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 for the game, or ‘Unknown’ if not found.



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.

Examples:

Getting the selected game code

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

Parameters:

  • combo (Gtk::ComboBoxText)

    The combo box from which to get the selected game.

Returns:

  • (String, nil)

    The game code of the selected game, or ‘GS3’ if not found.



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.

Examples:

Updating the game selection combo

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

Parameters:

  • combo (Gtk::ComboBoxText)

    The combo box to update.

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

    The game code to set as the default selection.



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