Class: UI::MiningGame::Tool_Buttons

Inherits:
SpriteStack show all
Defined in:
scripts/01450 Systems/08001 Mining Game/00030 UI_Mining_Game/00009 Tool_Buttons.rb

Overview

Class that describes the buttons that let the player choose his tool

Constant Summary collapse

COORD_Y_2_TOOLS =

Coordinates in no dynamite mode

[0, 80]
COORD_Y_3_TOOLS =

Coordinates in dynamite mode

[0, 64, 128]
TOOL_FILENAME =

Symbols of the tools

%w[pickaxe mace dynamite]

Constants inherited from SpriteStack

SpriteStack::NO_INITIAL_IMAGE

Instance Attribute Summary collapse

Attributes inherited from SpriteStack

#animated, #data, #moving, #stack, #viewport, #x, #y

Instance Method Summary collapse

Methods inherited from SpriteStack

#[], #add_background, #add_line, #add_text, #anime, #anime_delta_set, #dispose, #each, #execute_anime, #move, #move_to, #opacity, #opacity=, #push, #push_sprite, #set_origin, #set_position, #simple_mouse_in?, #size, #stop_animation, #translate_mouse_coords, #update, #update_animation, #update_position, #visible, #visible=, #with_cache, #with_font, #with_surface, #z, #z=

Constructor Details

#initialize(viewport) ⇒ Tool_Buttons

Create the tool buttons

Parameters:

  • viewport (Viewport)

    the viewport of the scene



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'scripts/01450 Systems/08001 Mining Game/00030 UI_Mining_Game/00009 Tool_Buttons.rb', line 21

def initialize(viewport)
  super(viewport, *initial_coordinates)
  @index = 0
  # @type [Yuki::Animation::ResolverObjectCommand]
  @animation = nil
  nb_tool = PFM.game_state.mining_game.dynamite_unlocked ? 3 : 2
  coord_y = PFM.game_state.mining_game.dynamite_unlocked ? COORD_Y_3_TOOLS : COORD_Y_2_TOOLS
  @buttons = []
  nb_tool.times { |i| buttons << add_sprite(0, coord_y[i], "mining_game/#{TOOL_FILENAME[i]}", 2, 1, type: SpriteSheet) }
  @button_click_anim = add_sprite(0, 0, 'mining_game/button_anim', 3, 3, type: SpriteSheet)
  @button_click_anim.visible = false
  button_state_change
end

Instance Attribute Details

#animationYuki::Animation::TimedAnimation

Returns the animation played when selecting a button.

Returns:

  • (Yuki::Animation::TimedAnimation)

    the animation played when selecting a button



17
18
19
# File 'scripts/01450 Systems/08001 Mining Game/00030 UI_Mining_Game/00009 Tool_Buttons.rb', line 17

def animation
  @animation
end

#buttonsArray<SpriteSheet>

Returns the array containing each button.

Returns:

  • (Array<SpriteSheet>)

    the array containing each button



15
16
17
# File 'scripts/01450 Systems/08001 Mining Game/00030 UI_Mining_Game/00009 Tool_Buttons.rb', line 15

def buttons
  @buttons
end

#indexInteger

Returns the currently selected button.

Returns:

  • (Integer)

    the currently selected button



13
14
15
# File 'scripts/01450 Systems/08001 Mining Game/00030 UI_Mining_Game/00009 Tool_Buttons.rb', line 13

def index
  @index
end

Instance Method Details

#change_buttons_state(index) ⇒ Symbol

Change the state of each button depending on the one that is hit

Parameters:

  • index (Integer)

    the index of the hitted button

Returns:

  • (Symbol)

    the symbol of the new tool to use



38
39
40
41
42
43
# File 'scripts/01450 Systems/08001 Mining Game/00030 UI_Mining_Game/00009 Tool_Buttons.rb', line 38

def change_buttons_state(index)
  @index = index
  button_state_change
  button_animation
  return TOOL_FILENAME[index].to_sym
end