Class: UI::SpriteStack
- Defined in:
- scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb
Overview
Class that helps to define a single object constitued of various sprites. With this class you can move the sprites as a single sprite, change the data that generate the sprites and some other cool stuff
Direct Known Subclasses
BattleUI::AbilityBar, BattleUI::ExpDistribution, BattleUI::ExpDistribution::PokemonInfo, BattleUI::ExpDistribution::Statistics, BattleUI::GenericChoice, BattleUI::InfoBar, BattleUI::PlayerChoice::ItemInfo, BattleUI::PlayerChoice::SpecialButton, BattleUI::PlayerChoice::SubChoice, BattleUI::SkillChoice::MoveButton, BattleUI::SkillChoice::MoveDescription, BattleUI::SkillChoice::MoveInfo, BattleUI::SkillChoice::SpecialButton, BattleUI::SkillChoice::SubChoice, BattleUI::TargetSelection, BattleUI::TargetSelection::Button, BattleUI::TrainerPartyBalls, GTS::Button, GTS::LoadingScreen, Bag::ButtonList::ItemButton, Bag::InfoCompact, Bag::InfoWide, Bag::PocketList, Bag::ScrollBar, Bag::SearchBar, Bag::WinPocket, Casino::NumberDisplay, DexButton, DexSeenGot, DexWinInfo, DexWinMap, DexWinSprite, GenericBase, GenericBase::ControlButton, Hall_of_Fame::Congratulation_Text_Box, Hall_of_Fame::Dead_Pokemon_Text, Hall_of_Fame::End_Stars_Animation, Hall_of_Fame::Graveyard_Animation_Stack, Hall_of_Fame::League_Champion_Text_Box, Hall_of_Fame::Party_Battler_Stack, Hall_of_Fame::Pokemon_Battler_Stack, Hall_of_Fame::Pokemon_Stars_Animation, Hall_of_Fame::Pokemon_Text_Box, Hall_of_Fame::Trainer_Infos_Text_Box, Hall_of_Fame::Type_Background, InputNumber, KeyBindingViewer, MapPanel, MiningGame::Diggable_Stack, MiningGame::Hit_Counter_Stack, MiningGame::Tiles_Stack, MiningGame::Tool_Buttons, MoveTeaching::BaseBackground, MoveTeaching::NewSkill, MoveTeaching::PokemonInfos, MoveTeaching::Skill, MoveTeaching::SkillDescription, Options::Button, Options::Description, PSDKMenuButton, Quest::CategoryDisplay, Quest::Composition, Quest::ObjectiveList, Quest::QuestButton, Quest::QuestList, Quest::RewardButton, Quest::RewardScreen, Quest::ScrollBar, QuestInformer, SaveSign, UI::Shop::ItemDesc, UI::Shop::ItemList::ListButton, UI::Shop::MoneyWindow, UI::Shop::PkmDesc, UI::Shop::PkmList::ListButtonPkm, UI::Shop::PkmScrollBar, UI::Shop::ScrollBar, ShortcutElement, UI::Storage::BoxStack, UI::Storage::Composition, UI::Storage::DetailedSearch, UI::Storage::PartyStack, UI::Storage::RapidSearch, UI::Storage::Summary, Summary_Memo, Summary_Skill, Summary_Skills, Summary_Stat, Summary_Top, TeamButton, TextScroller, TitleControls, VoltorbFlip::Animation, VoltorbFlip::BoardCounter, VoltorbFlip::BoardTile, VoltorbFlip::Texts
Constant Summary collapse
- NO_INITIAL_IMAGE =
Constant specifiying the sprite will have no image during initialization
nil
Instance Attribute Summary collapse
-
#animated ⇒ Boolean
>>> Section from Yuki::Sprite <<< If the sprite has a self animation.
-
#data
Data used by the sprites of the sprite stack to generate themself.
-
#moving ⇒ Boolean
If the sprite is moving.
-
#stack
readonly
Get the stack.
-
#viewport ⇒ Viewport
readonly
Get the viewport.
-
#x ⇒ Numeric
X coordinate of the sprite stack.
-
#y ⇒ Numeric
Y coordinate of the sprite stack.
Instance Method Summary collapse
-
#[](index) ⇒ Sprite, Text
Return an element of the stack.
-
#add_background(filename, type: Sprite, rect: nil) ⇒ Sprite
(also: #add_foreground)
Push a background image.
-
#add_line(line_index, str, align = 0, outlinesize = Text::Util::DEFAULT_OUTLINE_SIZE, type: Text, color: nil, dx: 0) ⇒ Text
Add a text inside the stack using metrics given by with_surface.
-
#add_text(x, y, width, height, str, align = 0, outlinesize = Text::Util::DEFAULT_OUTLINE_SIZE, type: Text, color: nil, sizeid: nil) ⇒ Text
Add a text inside the stack, the offset x/y will be adjusted.
-
#anime(arr, delta = 1)
Start an animation.
-
#anime_delta_set(v)
Change the time to wait between each animation message.
-
#dispose
Dispose each sprite of the sprite stack and clear the stack.
-
#each(&block)
yield a block on each sprite.
-
#execute_anime(n)
Force the execution of the n next animation message.
-
#initialize(viewport, x = 0, y = 0, default_cache: :interface) ⇒ SpriteStack
constructor
Create a new Sprite stack.
-
#move(delta_x, delta_y) ⇒ self
Move the sprite stack.
-
#move_to(x, y, nb_frame)
Move the sprite to a specific coordinate in a certain amount of frame.
-
#opacity ⇒ Integer
Gets the opacity of the SpriteStack.
-
#opacity=(value)
Sets the opacity of the SpriteStack.
-
#push(x, y, bmp, *args, rect: nil, type: Sprite, ox: 0, oy: 0) ⇒ Sprite
(also: #add_sprite)
Push a sprite to the stack.
-
#push_sprite(sprite) ⇒ sprite
(also: #add_custom_sprite)
Push a sprite object to the stack.
-
#set_origin(_ox, _oy)
Set the origin (does nothing).
-
#set_position(x, y) ⇒ self
Change the x and y coordinate of the sprite stack.
-
#simple_mouse_in?(mx = Mouse.x, my = Mouse.y) ⇒ Boolean
Detect if the mouse is in the first sprite of the stack.
-
#size ⇒ Integer
(also: #length)
Return the size of the stack.
-
#stop_animation
Stop the animation.
-
#translate_mouse_coords(mx = Mouse.x, my = Mouse.y) ⇒ Array(Numeric, Numeric)
Translate the mouse coordinate to mouse position inside the first sprite of the stack.
-
#update
Update sprite (+move & animation).
-
#update_animation(no_delta)
Update the animation.
-
#update_position
Update the movement.
-
#visible ⇒ Boolean
If the sprite stack is visible.
-
#visible=(value)
Change the visible property of each sprites.
-
#with_cache(cache)
Execute push operations with an alternative cache.
-
#with_font(font_id)
Execute add_text operation with an alternative font.
-
#with_surface(x, y, unit_width, size_id = 0, offset_width = 2)
Execute add_line with specific metrics info.
-
#z ⇒ Numeric
Gets the z of the SpriteStack.
-
#z=(value)
Sets the z of the SpriteStack.
Constructor Details
#initialize(viewport, x = 0, y = 0, default_cache: :interface) ⇒ SpriteStack
Create a new Sprite stack
27 28 29 30 31 32 33 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 27 def initialize(, x = 0, y = 0, default_cache: :interface) @viewport = @stack = [] @x = x @y = y @default_cache = default_cache end |
Instance Attribute Details
#animated ⇒ Boolean
>>> Section from Yuki::Sprite <<< If the sprite has a self animation
290 291 292 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 290 def animated @animated end |
#data
Data used by the sprites of the sprite stack to generate themself
15 16 17 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 15 def data @data end |
#moving ⇒ Boolean
If the sprite is moving
293 294 295 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 293 def moving @moving end |
#stack (readonly)
Get the stack
17 18 19 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 17 def stack @stack end |
#viewport ⇒ Viewport (readonly)
Get the viewport
20 21 22 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 20 def @viewport end |
#x ⇒ Numeric
X coordinate of the sprite stack
10 11 12 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 10 def x @x end |
#y ⇒ Numeric
Y coordinate of the sprite stack
13 14 15 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 13 def y @y end |
Instance Method Details
#[](index) ⇒ Sprite, Text
Return an element of the stack
177 178 179 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 177 def [](index) @stack[index] end |
#add_background(filename, type: Sprite, rect: nil) ⇒ Sprite Also known as: add_foreground
Push a background image
78 79 80 81 82 83 84 85 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 78 def add_background(filename, type: Sprite, rect: nil) sprite = type.new(@viewport) sprite.set_position(@x, @y) sprite.set_bitmap(filename, @default_cache) sprite.src_rect.set(*rect) if rect.is_a?(Array) sprite.src_rect = rect if rect.is_a?(Rect) return push_sprite(sprite) end |
#add_line(line_index, str, align = 0, outlinesize = Text::Util::DEFAULT_OUTLINE_SIZE, type: Text, color: nil, dx: 0) ⇒ Text
Add a text inside the stack using metrics given by with_surface
165 166 167 168 169 170 171 172 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 165 def add_line(line_index, str, align = 0, outlinesize = Text::Util::DEFAULT_OUTLINE_SIZE, type: Text, color: nil, dx: 0) x = @surface_x + dx * (@surface_width + @surface_offset_width) y = @surface_y + line_index * (height = Fonts.line_height(@surface_size_id || @font_id.to_i)) text = type.new(@font_id.to_i, @viewport, x + @x, y - Text::Util::FOY + @y, @surface_width, height, str, align, outlinesize, color, @surface_size_id) text.draw_shadow = outlinesize.nil? @stack << text return text end |
#add_text(x, y, width, height, str, align = 0, outlinesize = Text::Util::DEFAULT_OUTLINE_SIZE, type: Text, color: nil, sizeid: nil) ⇒ Text
Add a text inside the stack, the offset x/y will be adjusted
65 66 67 68 69 70 71 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 65 def add_text(x, y, width, height, str, align = 0, outlinesize = Text::Util::DEFAULT_OUTLINE_SIZE, type: Text, color: nil, sizeid: nil) height ||= Fonts.line_height(sizeid || @font_id.to_i) text = type.new(@font_id.to_i, @viewport, x + @x, y - Text::Util::FOY + @y, width, height, str, align, outlinesize, color, sizeid) text.draw_shadow = outlinesize.nil? @stack << text return text end |
#anime(arr, delta = 1)
Start an animation
328 329 330 331 332 333 334 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 328 def anime(arr, delta = 1) @animated = true @animation = arr @anime_pos = 0 @anime_delta = delta @anime_count = 0 end |
#anime_delta_set(v)
Change the time to wait between each animation message
370 371 372 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 370 def anime_delta_set(v) @anime_delta = v end |
#dispose
Dispose each sprite of the sprite stack and clear the stack
282 283 284 285 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 282 def dispose @stack.each(&:dispose) @stack.clear end |
#each(&block)
yield a block on each sprite
276 277 278 279 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 276 def each(&block) return @stack.each unless block @stack.each(&block) end |
#execute_anime(n)
this method is used in animation message Array
Force the execution of the n next animation message
353 354 355 356 357 358 359 360 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 353 def execute_anime(n) @anime_pos += 1 @anime_pos = 0 if @anime_pos >= @animation.size n.times do update_animation(true) end @anime_pos -= 1 end |
#move(delta_x, delta_y) ⇒ self
Move the sprite stack
218 219 220 221 222 223 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 218 def move(delta_x, delta_y) @x += delta_x @y += delta_y @stack.each { |sprite| sprite.set_position(sprite.x + delta_x, sprite.y + delta_y) } return self end |
#move_to(x, y, nb_frame)
Move the sprite to a specific coordinate in a certain amount of frame
305 306 307 308 309 310 311 312 313 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 305 def move_to(x, y, nb_frame) @moving = true @move_frame = nb_frame @move_total = nb_frame @new_x = x @new_y = y @del_x = self.x - x @del_y = self.y - y end |
#opacity ⇒ Integer
Gets the opacity of the SpriteStack
376 377 378 379 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 376 def opacity return 0 unless (sprite = @stack.first) return sprite.opacity end |
#opacity=(value)
Sets the opacity of the SpriteStack
383 384 385 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 383 def opacity=(value) @stack.each { |sprite| sprite.opacity = value if sprite.respond_to?(:opacity=) } end |
#push(x, y, bmp, *args, rect: nil, type: Sprite, ox: 0, oy: 0) ⇒ Sprite Also known as: add_sprite
Push a sprite to the stack
44 45 46 47 48 49 50 51 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 44 def push(x, y, bmp, *args, rect: nil, type: Sprite, ox: 0, oy: 0) sprite = type.new(@viewport, *args) sprite.set_position(@x + x, @y + y).set_origin(ox, oy) sprite.set_bitmap(bmp, @default_cache) if bmp sprite.src_rect.set(*rect) if rect.is_a?(Array) sprite.src_rect = rect if rect.is_a?(Rect) return push_sprite(sprite) end |
#push_sprite(sprite) ⇒ sprite Also known as: add_custom_sprite
Push a sprite object to the stack
91 92 93 94 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 91 def push_sprite(sprite) @stack << sprite return sprite end |
#set_origin(_ox, _oy)
this function is only for compatibility, it does nothing
Set the origin (does nothing)
229 230 231 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 229 def set_origin(_ox, _oy) # Does nothing end |
#set_position(x, y) ⇒ self
Change the x and y coordinate of the sprite stack
208 209 210 211 212 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 208 def set_position(x, y) delta_x = x - @x delta_y = y - @y return move(delta_x, delta_y) end |
#simple_mouse_in?(mx = Mouse.x, my = Mouse.y) ⇒ Boolean
Detect if the mouse is in the first sprite of the stack
251 252 253 254 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 251 def simple_mouse_in?(mx = Mouse.x, my = Mouse.y) return false if @stack.empty? return @stack.first.simple_mouse_in?(mx, my) end |
#size ⇒ Integer Also known as: length
Return the size of the stack
183 184 185 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 183 def size @stack.size end |
#stop_animation
this method is used in the animation message Array (because animation loops)
Stop the animation
364 365 366 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 364 def stop_animation @animated = false end |
#translate_mouse_coords(mx = Mouse.x, my = Mouse.y) ⇒ Array(Numeric, Numeric)
Translate the mouse coordinate to mouse position inside the first sprite of the stack
260 261 262 263 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 260 def translate_mouse_coords(mx = Mouse.x, my = Mouse.y) return 0,0 if @stack.empty? return @stack.first.translate_mouse_coords(mx, my) end |
#update
Update sprite (+move & animation)
295 296 297 298 299 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 295 def update update_animation(false) if @animated update_position if @moving @stack.each { |sprite| sprite.update if sprite.respond_to?(:update) } end |
#update_animation(no_delta)
Update the animation
338 339 340 341 342 343 344 345 346 347 348 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 338 def update_animation(no_delta) unless no_delta @anime_count += 1 return if @anime_delta > @anime_count @anime_count = 0 end anim = @animation[@anime_pos] send(*anim) if anim[0] != :send && anim[0].class == Symbol @anime_pos += 1 @anime_pos = 0 if @anime_pos >= @animation.size end |
#update_position
Update the movement
316 317 318 319 320 321 322 323 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 316 def update_position @move_frame -= 1 @moving = false if @move_frame == 0 set_position( @new_x + (@del_x * @move_frame) / @move_total, @new_y + (@del_y * @move_frame) / @move_total ) end |
#visible ⇒ Boolean
Return the visible property of the first sprite
If the sprite stack is visible
236 237 238 239 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 236 def visible return false if @stack.empty? return @stack.first.visible end |
#visible=(value)
Change the visible property of each sprites
243 244 245 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 243 def visible=(value) @stack.each { |sprite| sprite.visible = value } end |
#with_cache(cache)
Execute push operations with an alternative cache
102 103 104 105 106 107 108 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 102 def with_cache(cache) last_cache = @default_cache @default_cache = cache yield ensure @default_cache = last_cache end |
#with_font(font_id)
Execute add_text operation with an alternative font
115 116 117 118 119 120 121 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 115 def with_font(font_id) last_font = @font_id @font_id = font_id yield ensure @font_id = last_font end |
#with_surface(x, y, unit_width, size_id = 0, offset_width = 2)
Execute add_line with specific metrics info
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 136 def with_surface(x, y, unit_width, size_id = 0, offset_width = 2) last_surface_x = @surface_x last_surface_y = @surface_y last_unit_width = @surface_width last_size_id = @surface_size_id last_offset_width = @surface_offset_width @surface_x = x @surface_y = y @surface_width = unit_width @surface_size_id = size_id @surface_offset_width = offset_width yield ensure @surface_x = last_surface_x @surface_y = last_surface_y @surface_width = last_unit_width @surface_size_id = last_size_id @surface_offset_width = last_offset_width end |
#z ⇒ Numeric
Gets the z of the SpriteStack
389 390 391 392 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 389 def z return 0 unless (sprite = @stack.first) return sprite.z end |
#z=(value)
Sets the z of the SpriteStack
395 396 397 |
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00100 SpriteStack.rb', line 395 def z=(value) @stack.each { |sprite| sprite.z = value } end |