Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # Starter Selection Interface
- # Swdfm 2024-10-18
- # Used for "A Comprehensive Guide To Making A Custom UI" Tutorial
- # Call with "pbSelectStarter"
- #==============================================================================
- HOENN_STARTERS = [
- :TREECKO, :TORCHIC, :MUDKIP
- ]
- class Starter_Selection
- def initialize
- # === Chapter 2 ===
- # Section 2.1
- @viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
- # Section 2.2
- @viewport.z = 99_999
- # === Chapter 3 ===
- # Section 3.1
- @sprites = {}
- # Section 3.2
- bg_exists = pbResolveBitmap("Graphics/UI/Trainer Card/bg_f")
- # Section 3.3
- if bg_exists
- addBackgroundPlane(@sprites, "bg", "Trainer Card/bg_f", @viewport)
- end
- # Section 3.4
- color = Color.new(0, 0, 0, 128)
- # Section 3.5
- @sprites["bg"] = ColoredPlane.new(color, @viewport)
- # === Chapter 4 ===
- # Section 4.1
- @sprites["overlay"] = BitmapSprite.new(Graphics.width, Graphics.height, @viewport)
- # Section 4.2
- pbSetSystemFont(@sprites["overlay"].bitmap)
- # Section 4.3
- @sprites["overlay"].z = @sprites["bg"].z + 1
- # Section 4.4
- @sprites["title"] = BitmapSprite.new(Graphics.width, Graphics.height / 4, @viewport)
- pbSetSystemFont(@sprites["title"].bitmap)
- @sprites["title"].z = @sprites["bg"].z + 1
- @sprites["title"].bitmap.font.size = 48
- # === Chapter 5 ===
- # Section 5.1
- @path = "Graphics/Pokemon/Front/"
- @path_icons = "Graphics/Pokemon/Icons/"
- @p_main_y = 48
- @icons_on_row = 3 # Amount of Pokemon Icons on one horizontal line
- @icon_first_y = @p_main_y + 200 # Y position of top row of Pokemon Icons
- @icon_gap_y = 64 # Space Between each Pokemon Icon (vertical)
- # Section 5.2
- pool = [
- :BULBASAUR, :CHARMANDER, :SQUIRTLE
- ]
- pool += HOENN_STARTERS
- @species = []
- for p in pool
- next unless GameData::Species.exists?(p)
- next unless pbResolveBitmap("#{@path}#{p}")
- next unless pbResolveBitmap("#{@path_icons}#{p}")
- @species.push(p)
- end
- # Section 5.3
- if @species.empty?
- raise "Oopsie! You either haven't defined the starters in the Pokemon PBS file, or do not have any pictures of them in the #{@path} and #{@path_icons} folders!"
- end
- # First, we draw the icons
- # Section 5.4
- @species.each_with_index do |species, i|
- t_x = i % @icons_on_row # The "X co-ord" of that pokemon icon
- t_y = (i / @icons_on_row).floor # The "Y co-ord" of that pokemon icon
- # Section 5.5
- s = "icon_#{i}"
- # Section 5.6
- @sprites[s] = IconSprite.new(0, 0, @viewport)
- # Section 5.7
- @sprites[s].setBitmap(@path_icons + species.to_s)
- # Section 5.8
- @sprites[s].src_rect.width = @sprites[s].src_rect.width / 2
- # Section 5.9
- @sprites[s].x = (Graphics.width / (@icons_on_row + 1)).floor
- @sprites[s].x *= (t_x + 1)
- @sprites[s].x -= @sprites[s].width / 2
- @sprites[s].y = @icon_first_y + t_y * @icon_gap_y
- @sprites[s].z = @sprites["bg"].z + 2
- end
- # Section 5.10
- @index = rand(@species.length)
- # Then, we draw the big pokemon icon
- update_main_icon
- # === Chapter 6 ===
- do_text_pos = true
- # Section 6.1
- title = _INTL("Choose your starter!")
- overlay = @sprites["title"].bitmap
- title_x = Graphics.width / 2
- title_y = 8
- @baseColor = Color.new(224, 224, 224)
- @shadowColor = Color.new(48, 48, 48)
- if do_text_pos
- # Section 6.2
- text_pos = [
- [title, title_x, title_y, :center, @baseColor, @shadowColor]
- ]
- # Section 6.3
- pbDrawTextPositions(overlay, text_pos)
- else
- # Section 6.4
- drawTextEx(overlay, 0, title_y, Graphics.width, 1, title, @baseColor, @shadowColor)
- end
- change_pkmn_text
- # === Chapter 7 ===
- # Section 7.1
- @bg_colours = [
- Color.new(61, 102, 61), # Grass
- Color.new(127, 69, 63), # Fire
- Color.new(63, 92, 127) # Water
- ]
- # Section 7.2
- @sprites["arrow"] = AnimatedSprite.create("Graphics/UI/pause_arrow", 4, 3, @viewport)
- @sprites["arrow"].start
- @sprites["arrow"].z = @sprites["bg"].z + 3
- # === Chapter 8 ===
- refresh
- # Section 8.1
- pbFadeInAndShow(@sprites) { pbUpdate }
- loop do
- # Section 8.2
- Graphics.update
- Input.update
- pbUpdate
- # Section 8.3
- old_index = @index
- # Section 8.4
- if Input.trigger?(Input::USE)
- name = GameData::Species.get(@species[@index]).name
- if pbConfirmMessageSerious(_INTL("Are you sure that you wish to pick {1}?", name))
- # Section 8.5
- pbPlayDecisionSE
- # Section 8.6
- break
- else
- pbPlayCancelSE
- end
- # Section 8.7
- elsif Input.trigger?(Input::BACK)
- pbPlayBuzzerSE
- # Section 8.8
- elsif Input.trigger?(Input::LEFT)
- @index -= 1 unless @index % @icons_on_row == 0
- elsif Input.trigger?(Input::RIGHT)
- @index += 1 unless @index % @icons_on_row == @icons_on_row - 1
- elsif Input.trigger?(Input::UP)
- @index -= @icons_on_row unless @index < @icons_on_row
- elsif Input.trigger?(Input::DOWN)
- last_row = ((@species.length - 1) / @icons_on_row).floor * @icons_on_row
- @index += @icons_on_row if @index < last_row
- end
- # Section 8.9
- @index = @index.clamp(0, @species.length - 1)
- # Section 8.3
- if old_index != @index
- pbPlayCursorSE
- # Section 8.10
- refresh
- end
- end
- # Section 8.13
- pbFadeOutAndHide(@sprites)
- # Section 8.14
- pbDisposeSpriteHash(@sprites)
- @viewport.dispose
- end
- # === Used in Chapters 5 and 8 ===
- def update_main_icon
- species = @species[@index]
- s = "poke"
- # Section 5.11
- @sprites[s].dispose if @sprites[s]
- @sprites[s] = IconSprite.new(0, @p_main_y, @viewport)
- @sprites[s].setBitmap("#{@path}#{species}")
- @sprites[s].x = Graphics.width / 2 - @sprites[s].width / 2
- end
- # === Used in Chapters 6 and 8 ===
- def change_pkmn_text
- species = @species[@index]
- data = GameData::Species.get(species)
- text = data.name
- type = data.types[0]
- text_type = GameData::Type.get(type).name
- text_type = _INTL("{1} type", text_type)
- overlay = @sprites["overlay"].bitmap
- # Section 6.5
- overlay.clear
- t_x = Graphics.width / 2
- t_y = @sprites["poke"].y + @sprites["poke"].height - 32
- text_pos = [
- [text, t_x, t_y, :center, @baseColor, @shadowColor],
- [text_type, t_x, t_y + 32, :center, @baseColor, @shadowColor]
- ]
- pbDrawTextPositions(overlay, text_pos)
- end
- # === Used in Chapter 8 ===
- def pbUpdate
- # Section 8.2
- pbUpdateSpriteHash(@sprites)
- end
- # === Used in Chapter 8 ===
- def refresh
- update_main_icon
- change_pkmn_text
- # Moves Arrow
- # Section 8.11
- @sprites["arrow"].x = @sprites["icon_#{@index}"].x
- @sprites["arrow"].x += @sprites["icon_#{@index}"].width / 2
- @sprites["arrow"].x -= @sprites["arrow"].width / 2
- @sprites["arrow"].y = @sprites["icon_#{@index}"].y
- # Changes Background
- # Section 8.12
- c = @bg_colours[@index % @bg_colours.length]
- @sprites["bg"].set_plane_color(c)
- end
- # === Chapter 9 ===
- def result
- # Section 9.1
- return @species[@index]
- end
- end
- # Section 9.2
- def pbSelectStarter
- ret = Starter_Selection.new
- return ret.result
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement