Class: UI::Storage::Composition

Inherits:
UI::SpriteStack show all
Defined in:
scripts/01450 Systems/00010 Storage/00002 UI_Storage/00100 Composition.rb

Overview

Stack responsive of showing the full PC UI

Constant Summary

Constants inherited from UI::SpriteStack

UI::SpriteStack::NO_INITIAL_IMAGE

Instance Attribute Summary collapse

Attributes inherited from UI::SpriteStack

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

Instance Method Summary collapse

Methods inherited from UI::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_animation, #update_position, #visible, #visible=, #with_cache, #with_font, #with_surface, #z, #z=

Constructor Details

#initialize(viewport, mode, selection_mode) ⇒ Composition

Create a new Composition

Parameters:

  • viewport (Viewport)

    viewport used to display the sprites

  • mode (Symbol)

    :pokemon, :item, :battle or :box

  • selection_mode (Symbol)

    :detailed, :fast or :grouped



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'scripts/01450 Systems/00010 Storage/00002 UI_Storage/00100 Composition.rb', line 30

def initialize(viewport, mode, selection_mode)
  super(viewport)
  @mode_handler = ModeHandler.new(mode, selection_mode)
  @selection_handler = SelectionHandler.new(@mode_handler)
  # @type [Yuki::Animation::TimedAnimation]
  @animation = nil
  # @type [PFM::Storage]
  @storage = nil
  @party = nil
  @box_index = 0
  create_stack
  @selection_handler.cursor = @cursor_handler
end

Instance Attribute Details

#box_indexInteger (readonly)

Get the current box index

Returns:



16
17
18
# File 'scripts/01450 Systems/00010 Storage/00002 UI_Storage/00100 Composition.rb', line 16

def box_index
  @box_index
end

#cursor_handlerCursorHandler (readonly)

Get the cursor object

Returns:



22
23
24
# File 'scripts/01450 Systems/00010 Storage/00002 UI_Storage/00100 Composition.rb', line 22

def cursor_handler
  @cursor_handler
end

#mode_handlerModeHandler (readonly)

Get the mode handler

Returns:



7
8
9
# File 'scripts/01450 Systems/00010 Storage/00002 UI_Storage/00100 Composition.rb', line 7

def mode_handler
  @mode_handler
end

#partyArray<PFM::Pokemon>

Get the party

Returns:



10
11
12
# File 'scripts/01450 Systems/00010 Storage/00002 UI_Storage/00100 Composition.rb', line 10

def party
  @party
end

#selection_handlerSelectionHandler (readonly)

Get the selection handler

Returns:



25
26
27
# File 'scripts/01450 Systems/00010 Storage/00002 UI_Storage/00100 Composition.rb', line 25

def selection_handler
  @selection_handler
end

#storagePFM::Storage

Get the storage object

Returns:



13
14
15
# File 'scripts/01450 Systems/00010 Storage/00002 UI_Storage/00100 Composition.rb', line 13

def storage
  @storage
end

#summarySummary (readonly)

Get the summary object

Returns:



19
20
21
# File 'scripts/01450 Systems/00010 Storage/00002 UI_Storage/00100 Composition.rb', line 19

def summary
  @summary
end

Instance Method Details

#animate_left_arrow(middle_animation = nil)

Start animation for left arrow

Parameters:



72
73
74
75
76
77
78
# File 'scripts/01450 Systems/00010 Storage/00002 UI_Storage/00100 Composition.rb', line 72

def animate_left_arrow(middle_animation = nil)
  arrow = @arrow_left
  @animation = Yuki::Animation::ScalarAnimation.new(0.05, arrow, :x=, arrow.x, arrow.x - 2)
  @animation.play_before(middle_animation) if middle_animation
  @animation.play_before(Yuki::Animation::ScalarAnimation.new(0.05, arrow, :x=, arrow.x - 2, arrow.x))
  @animation.start
end

#animate_right_arrow(middle_animation = nil)

Start animation for right arrow

Parameters:



62
63
64
65
66
67
68
# File 'scripts/01450 Systems/00010 Storage/00002 UI_Storage/00100 Composition.rb', line 62

def animate_right_arrow(middle_animation = nil)
  arrow = @arrow_right
  @animation = Yuki::Animation::ScalarAnimation.new(0.05, arrow, :x=, arrow.x, arrow.x + 2)
  @animation.play_before(middle_animation) if middle_animation
  @animation.play_before(Yuki::Animation::ScalarAnimation.new(0.05, arrow, :x=, arrow.x + 2, arrow.x))
  @animation.start
end

#done?boolean

Tell if the animation is done

Returns:

  • (boolean)


55
56
57
58
# File 'scripts/01450 Systems/00010 Storage/00002 UI_Storage/00100 Composition.rb', line 55

def done?
  all_done = @summary.done? && @cursor.done?
  return @animation ? all_done && @animation.done? : all_done
end

#hovering_box_option?Boolean

Tell if the box option is hovered

Returns:

  • (Boolean)


133
134
135
136
137
138
139
140
# File 'scripts/01450 Systems/00010 Storage/00002 UI_Storage/00100 Composition.rb', line 133

def hovering_box_option?
  if @box_stack.box_option_hovered?
    @cursor.select_box = true
    return true
  else
    return false
  end
end

#hovering_left_arrow?Boolean

Tell if the left arrow is hovered

Returns:

  • (Boolean)


150
151
152
# File 'scripts/01450 Systems/00010 Storage/00002 UI_Storage/00100 Composition.rb', line 150

def hovering_left_arrow?
  return @arrow_left.simple_mouse_in?
end

#hovering_mode_indicator?Boolean

Tell if the mouse hover the mode indicator

Returns:

  • (Boolean)


121
122
123
# File 'scripts/01450 Systems/00010 Storage/00002 UI_Storage/00100 Composition.rb', line 121

def hovering_mode_indicator?
  return @mode_indicator.simple_mouse_in?
end

#hovering_party_left_arrow?Boolean

Tell if the left arrow of party stack is hovered

Returns:

  • (Boolean)


162
163
164
# File 'scripts/01450 Systems/00010 Storage/00002 UI_Storage/00100 Composition.rb', line 162

def hovering_party_left_arrow?
  return @party_stack.hovering_left_arrow?
end

#hovering_party_right_arrow?Boolean

Tell if the right arrow of party stack is hovered

Returns:

  • (Boolean)


156
157
158
# File 'scripts/01450 Systems/00010 Storage/00002 UI_Storage/00100 Composition.rb', line 156

def hovering_party_right_arrow?
  return @party_stack.hovering_right_arrow?
end

#hovering_pokemon_sprite?Boolean

Tell if the mouse is hovering a pokemon sprite & update cursor index in consequence

Returns:

  • (Boolean)


100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'scripts/01450 Systems/00010 Storage/00002 UI_Storage/00100 Composition.rb', line 100

def hovering_pokemon_sprite?
  if @cursor.inbox
    return true if @box_stack.pokemon_sprites[@cursor.index].simple_mouse_in?
  elsif !@cursor.select_box
    return true if @party_stack.pokemon_sprites[@cursor.index].simple_mouse_in?
  end
  index = @party_stack.pokemon_sprites.index(&:simple_mouse_in?)
  if index
    @cursor.force_index(false, index)
    return true
  end
  index = @box_stack.pokemon_sprites.index(&:simple_mouse_in?)
  if index
    @cursor.force_index(true, index)
    return true
  end
  return false
end

#hovering_right_arrow?Boolean

Tell if the right arrow is hovered

Returns:

  • (Boolean)


144
145
146
# File 'scripts/01450 Systems/00010 Storage/00002 UI_Storage/00100 Composition.rb', line 144

def hovering_right_arrow?
  return @arrow_right.simple_mouse_in?
end

#hovering_selection_mode_indicator?Boolean

Tell if the mouse hover the selection mode indicator

Returns:

  • (Boolean)


127
128
129
# File 'scripts/01450 Systems/00010 Storage/00002 UI_Storage/00100 Composition.rb', line 127

def hovering_selection_mode_indicator?
  return @selection_mode_indicator.simple_mouse_in?
end

#update

Update the composition state



45
46
47
48
49
50
51
# File 'scripts/01450 Systems/00010 Storage/00002 UI_Storage/00100 Composition.rb', line 45

def update
  @summary.update
  @cursor.update
  return if !@animation || @animation.done?

  @animation.update
end