Class: UI::SaveSign

Inherits:
SpriteStack show all
Defined in:
scripts/01450 Systems/00106 Save Load/00002 UI/00001 SaveSign.rb

Overview

UI element showing the save information

Constant Summary collapse

CORRUPTED_MESSAGE =

String shown when a save is corrupted

'Corrupted Save File'
SAVE_INDEX_MESSAGE =

String shown when a save is not corrupted and can be choosen

'Save %d'

Constants inherited from SpriteStack

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

Constructor Details

#initialize(viewport, visual_index) ⇒ SaveSign

Create a new save sign

Parameters:



19
20
21
22
23
24
# File 'scripts/01450 Systems/00106 Save Load/00002 UI/00001 SaveSign.rb', line 19

def initialize(viewport, visual_index)
  super(viewport, *coordinates(visual_index))
  create_sprites
  @save_index = 0
  @visual_index = visual_index
end

Instance Attribute Details

#save_indexInteger

Get the index of the save

Returns:



6
7
8
# File 'scripts/01450 Systems/00106 Save Load/00002 UI/00001 SaveSign.rb', line 6

def save_index
  @save_index
end

#visual_indexInteger

Get the visual index of the save sign

Returns:



9
10
11
# File 'scripts/01450 Systems/00106 Save Load/00002 UI/00001 SaveSign.rb', line 9

def visual_index
  @visual_index
end

Instance Method Details

#animate_cursor



71
72
73
74
75
76
77
78
79
80
# File 'scripts/01450 Systems/00106 Save Load/00002 UI/00001 SaveSign.rb', line 71

def animate_cursor
  @cursor.visible = true
  @animation = Yuki::Animation::TimedLoopAnimation.new(1)
  @animation.play_before(Yuki::Animation.wait(1))
  parallel = Yuki::Animation.send_command_to(@cursor, :sy=, 0)
  parallel.play_before(Yuki::Animation.wait(0.5))
  parallel.play_before(Yuki::Animation.send_command_to(@cursor, :sy=, 1))
  @animation.parallel_add(parallel)
  @animation.start
end

#coordinates(visual_index) ⇒ Array<Integer>

Get the coordinate of the element based on its coordinate

Parameters:

  • visual_index (Integer)

    visual index of the UI element

Returns:



85
86
87
# File 'scripts/01450 Systems/00106 Save Load/00002 UI/00001 SaveSign.rb', line 85

def coordinates(visual_index)
  return [base_x + visual_index * spacing_x, base_y + visual_index * spacing_y]
end

#data=(value)

Set the data of the SaveSign

Parameters:

  • value (PFM::GameState, Symbol)

    :new if new game, :corrupted if corrupted



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'scripts/01450 Systems/00106 Save Load/00002 UI/00001 SaveSign.rb', line 28

def data=(value)
  @data = value
  self.visible = true
  case value
  when :new
    show_new_game
  when :corrupted
    show_corrupted
  when :hidden
    self.visible = false
  else
    show_data(value)
  end
  @cursor&.visible = @visual_index == 0
end

#done?Boolean

Tell if the animation is done

Returns:

  • (Boolean)


52
53
54
55
56
# File 'scripts/01450 Systems/00106 Save Load/00002 UI/00001 SaveSign.rb', line 52

def done?
  return true unless @animation

  return @animation.done?
end

#move_to_visual_index(target_visual_index)

Start the animation of moving between index

Parameters:



60
61
62
63
64
65
66
67
68
69
# File 'scripts/01450 Systems/00106 Save Load/00002 UI/00001 SaveSign.rb', line 60

def move_to_visual_index(target_visual_index)
  real_visual_index = @visual_index == -1 && target_visual_index == 3 ? -2 : target_visual_index
  real_visual_index = @visual_index == 3 && real_visual_index == -1 ? 4 : real_visual_index
  @cursor.visible = false
  @animation = Yuki::Animation.move_discreet(0.1, self, *coordinates(@visual_index), *coordinates(real_visual_index))
  @animation.play_before(Yuki::Animation.send_command_to(self, :set_position, *coordinates(target_visual_index)))
  @animation.play_before(Yuki::Animation.send_command_to(self, :animate_cursor)) if target_visual_index == 0
  @animation.start
  @visual_index = target_visual_index
end

#update

Update the animation



45
46
47
48
# File 'scripts/01450 Systems/00106 Save Load/00002 UI/00001 SaveSign.rb', line 45

def update
  super
  @animation&.update
end