Class: UI::Shop::ItemList

Inherits:
Array
  • Object
show all
Defined in:
scripts/01450 Systems/00203 Shop/00002 ItemShop UI/00030 ItemList.rb

Defined Under Namespace

Classes: ListButton

Constant Summary collapse

AMOUNT =

Number of button in the list

3
BUTTON_OFFSET =

Offset between each button

38
ACTIVE_OFFSET =

Offset between active button & inative button

-14
# Base X coordinate
BASE_X =

Base X coordinate

128
BASE_Y =

Base Y coordinate

30

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(viewport) ⇒ ItemList

Create a new ButtonList

Parameters:

  • viewport (Viewport)

    viewport in which the SpriteStack will be displayed



18
19
20
21
22
23
24
25
26
# File 'scripts/01450 Systems/00203 Shop/00002 ItemShop UI/00030 ItemList.rb', line 18

def initialize(viewport)
  super(AMOUNT) do |i|
    ListButton.new(viewport, i)
  end
  @item_list = []
  @name_list = []
  @price_list = []
  @index = 0
end

Instance Attribute Details

#indexInteger

Returns index of the current active item.

Returns:

  • (Integer)

    index of the current active item



15
16
17
# File 'scripts/01450 Systems/00203 Shop/00002 ItemShop UI/00030 ItemList.rb', line 15

def index
  @index
end

Instance Method Details

#done?Boolean

Test if the animation is done

Returns:

  • (Boolean)


38
39
40
# File 'scripts/01450 Systems/00203 Shop/00002 ItemShop UI/00030 ItemList.rb', line 38

def done?
  @animation.nil?
end

#item_list=(list)

Set the item list

Parameters:



65
66
67
68
# File 'scripts/01450 Systems/00203 Shop/00002 ItemShop UI/00030 ItemList.rb', line 65

def item_list=(list)
  @item_list = list
  @name_list = @item_list.collect { |id| data_item(id).exact_name }
end

#item_price=(list)

Set the price list

Parameters:



72
73
74
# File 'scripts/01450 Systems/00203 Shop/00002 ItemShop UI/00030 ItemList.rb', line 72

def item_price=(list)
  @price_list = list
end

#mouse_delta_indexInteger

Return the delta index with mouse position

Returns:



78
79
80
81
82
83
84
# File 'scripts/01450 Systems/00203 Shop/00002 ItemShop UI/00030 ItemList.rb', line 78

def mouse_delta_index
  mouse_index = find_index(&:simple_mouse_in?)
  return 0 unless mouse_index

  active_index = find_index(&:active?) || 0
  return mouse_index - active_index
end

#move_down

Move all the buttons down



58
59
60
61
# File 'scripts/01450 Systems/00203 Shop/00002 ItemShop UI/00030 ItemList.rb', line 58

def move_down
  @animation = :move_down_animation
  @counter = 0
end

#move_up

Move all the buttons up



52
53
54
55
# File 'scripts/01450 Systems/00203 Shop/00002 ItemShop UI/00030 ItemList.rb', line 52

def move_up
  @animation = :move_up_animation
  @counter = 0
end

#update

Update the animation



29
30
31
32
33
34
# File 'scripts/01450 Systems/00203 Shop/00002 ItemShop UI/00030 ItemList.rb', line 29

def update
  return unless @animation

  send(@animation)
  @counter += 1
end