Class: Smagacor::GameSwitcher

Inherits:
FXSwitcher
  • Object
show all
Defined in:
lib/smagacor/smagacor-ui.rb

Overview

Game switcher widget. Used to display the different games in the space.

Instance Method Summary collapse

Instance Method Details

#initializer(p) ⇒ Object

Create a new switcher.



93
94
95
# File 'lib/smagacor/smagacor-ui.rb', line 93

def initializer( p )
  super( p, FRAME_SUNKEN|LAYOUT_FILL_X|LAYOUT_FILL_Y )
end

#select_game(game) ⇒ Object

Selects the specified game [GameInfo] for playing. If the game has been selected earlier, the widget only displays the game area. Otherwise the information in game is used for loading the necessary game files and for creating the game widget.



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/smagacor/smagacor-ui.rb', line 100

def select_game( game )
  game_index = 0
  children.each_with_index do |child, index|
    game_index = index if child.userData == game
  end
  if game_index == 0
    begin
      require File.join( game.directory, game.file )
      content = game.get_class_object.new( self, game )
      content.create
      content.userData = game
      game_index = children.length - 1
    rescue StandardError => e
      FXMessageBox.new( self, "Error loading game",
                        "Could not load the game #{game.name}\nError: #{e.message}\n#{e.backtrace.join("\n")}",
                        nil, MBOX_OK ).execute
    end
  end
  self.current = game_index
end