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

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

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Provides game selection utilities for the Lich GUI login system Implements accurate game selection with proper accessibility support

Constant Summary collapse

GAME_NAMES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

User-friendly display names for canonical game codes.

{
  'GS3' => 'GemStone IV',
  'GST' => 'GemStone IV Prime Test',
  'GSF' => 'GemStone IV Shattered',
  'DR'  => 'DragonRealms',
  'DRX' => 'DragonRealms Platinum',
  'DRT' => 'DragonRealms Prime Test',
  'DRF' => 'DragonRealms Fallen'
}.freeze
GAME_MAPPING =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Game code to display name mapping, derived from the canonical validator.

Authentication::LoginHelpers::VALID_GAME_CODES.to_h do |game_code|
  [game_code, GAME_NAMES.fetch(game_code)]
end.freeze
REVERSE_GAME_MAPPING =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates an accessible game selection combo box Builds a dropdown with all available games and proper accessibility support

Parameters:

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

    Currently selected game code (optional)

Returns:

  • (Gtk::ComboBoxText)

    Combo box with game options



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'documented/common/gui/game_selection.rb', line 42

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 Authentication::LoginHelpers.valid_game_code?(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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Gets the game name for a game code Converts an internal game code to its user-friendly display name

Parameters:

  • game_code (String)

    Game code

Returns:

  • (String)

    Display name for the game



88
89
90
91
92
# File 'documented/common/gui/game_selection.rb', line 88

def self.get_game_name(game_code)
  return 'Unknown' unless Authentication::LoginHelpers.valid_game_code?(game_code)

  GAME_MAPPING.fetch(game_code)
end

.get_selected_game_code(combo) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Gets the game code for the selected game in the combo box Converts the user-selected display name back to the internal game code

Parameters:

  • combo (Gtk::ComboBoxText)

    Game selection combo box

Returns:

  • (String)

    Game code for the selected game



75
76
77
78
79
80
81
# File 'documented/common/gui/game_selection.rb', line 75

def self.get_selected_game_code(combo)
  return nil unless combo

  selected_text = combo.active_text
  game_code = REVERSE_GAME_MAPPING[selected_text]
  Authentication::LoginHelpers.valid_game_code?(game_code) ? game_code : 'GS3'
end

.update_game_selection_combo(combo, current_selection = nil) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Updates an existing combo box with the current game options Refreshes the contents of an existing combo box with the latest game options

Parameters:

  • combo (Gtk::ComboBoxText)

    Existing game selection combo box

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

    Currently selected game code (optional)



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'documented/common/gui/game_selection.rb', line 100

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 Authentication::LoginHelpers.valid_game_code?(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