Class: RubyArmor::ChooseProfile

Inherits:
Fidgit::GuiState
  • Object
show all
Defined in:
lib/ruby_armor/states/choose_profile.rb

Instance Method Summary collapse

Instance Method Details

#finalizeObject



51
52
53
54
# File 'lib/ruby_armor/states/choose_profile.rb', line 51

def finalize
  super
  container.clear
end

#play(profile, config) ⇒ Object



56
57
58
59
# File 'lib/ruby_armor/states/choose_profile.rb', line 56

def play(profile, config)
  @game.instance_variable_set :@profile, profile
  push_game_state Play.new(@game, config)
end

#setupObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ruby_armor/states/choose_profile.rb', line 3

def setup
  super

  on_input :escape, :hide

  # Create the game.
  @game = RubyWarrior::Game.new

  warrior_sprites = SpriteSheet.new "warriors.png", DungeonView::SPRITE_WIDTH, DungeonView::SPRITE_HEIGHT, 4

  vertical align_h: :center, spacing: 30 do
    vertical align: :center, padding_top: 30, padding: 0 do
      label "ryanb's RubyWarrior is wearing Spooner's", align: :center, font_height: 12
      label "RubyArmor", align: :center, font_height: 80
    end

    # Use existing profile.
    vertical padding: 0, align_h: :center do
      scroll_window height: 250, width: 460 do
        @game.profiles.each do |profile|
          config = WarriorConfig.new profile

          name_of_level = profile.epic? ? "EPIC" : profile.level_number.to_s
          title = "#{profile.warrior_name.ljust(20)} #{profile.tower.name.rjust(12)}:#{name_of_level[0, 1]} #{profile.score.to_s.rjust(5)}"
          tip = "Play as #{profile.warrior_name} the #{config.warrior_class.capitalize} - #{profile.tower.name} - level #{name_of_level} - score #{profile.score}"

          # Can be disabled because of a bug in RubyWarrior paths.
          button title, width: 400, tip: tip, enabled: File.directory?(profile.tower_path),
                        icon: warrior_sprites[0, DungeonView::WARRIORS[config.warrior_class]], icon_options: { factor: 2 } do
            play profile, config
          end
        end
      end
    end

    # Option to create a new profile.
    horizontal align: :center do
      button "Create new profile", shortcut: :auto, shortcut_color: Play::SHORTCUT_COLOR do
        CreateProfile.new(@game, warrior_sprites).show
      end

      button "Exit", shortcut: :x, shortcut_color: Play::SHORTCUT_COLOR do
        exit!
      end
    end
  end
end