Class: Core::States::OptionMenu

Inherits:
State show all
Includes:
Core, GUI
Defined in:
lib/states/menus/options.rb

Constant Summary

Constants included from Core

CURSOR_Z, DEFAULT_CONFIG, DEFAULT_FONT, FOG_Z, GUI_Z, HOME_PATH, LIBRARY_PATH, MAPOBJECT_Z, MAP_Z, PARTICLE_Z, RELEASE, Core::SAVE_DIR, VERSION

Instance Attribute Summary

Attributes inherited from State

#window, #x, #y

Instance Method Summary collapse

Methods included from Core

anim, animations, animations=, between?, config, exit, font, inside?, load_game, mouse_inside?, multiline, particles, particles=, save_game, silently, sprite, tiles, window, window=

Methods inherited from State

#draw_cursor, #finish, #update_cursor

Constructor Details

#initialize(window) ⇒ OptionMenu

Returns a new instance of OptionMenu.



7
8
9
10
11
12
13
14
15
# File 'lib/states/menus/options.rb', line 7

def initialize(window)
  super(window)
  @background = Core.sprite("menu/ingame_background")
  @restart = false
  @w = Core::GUI::Window.new(0, 0, 1024, 768, Trans.menu(:options))
  @w.add(:details, Window.new(288, 56, 704, 128, Trans.menu(:options_details), false, "gui/options_details"))
  @w.add(:language, Button.new(32, 32, 224, 32, Trans.menu(:language), lambda {swap(:language)}, true, :left))
  @w.add(:volume, Button.new(32, 80, 224, 32, Trans.menu(:volume), lambda {swap(:volume)}, true, :left))
end

Instance Method Details

#drawObject



47
48
49
50
51
# File 'lib/states/menus/options.rb', line 47

def draw
  @background.draw(0, 0, 0)
  @w.draw
  draw_cursor
end

#language(sym) ⇒ Object



28
29
30
31
32
# File 'lib/states/menus/options.rb', line 28

def language(sym)
  Core.config[:language] = sym.to_s
  swap(:language)
  @restart = true
end

#swap(sym) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/states/menus/options.rb', line 16

def swap(sym)
  detail = @w[:details]
  detail.empty
  case sym
  when :language
    detail.add(:en, Button.new(16, 16, 96, 24, Trans.menu(:lang_english), lambda {language(:en)}, true, :left))
    detail.add(:de, Button.new(16, 48, 96, 24, Trans.menu(:lang_german), lambda {language(:de)}, true, :left))
    detail[Core.config[:language].to_sym].disable
  when :volume
    detail.add(:slider, Slider.new(16, 16, 128, 32))
  end
end

#updateObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/states/menus/options.rb', line 33

def update
  if @window.pressed?(Gosu::KbEscape) or @w.remove?
    if @restart
      Core.exit(0)
    else
      Core.window.advance(StartMenu.new(Core.window))
    end
  end
  @w.update
  if @restart and !@w[:details].include?(:warning)
    @w[:details].add(:warning, Textfield.new(384, 16, 320, 96, Trans.menu(:restart_warning)))
  end
  update_cursor
end