Advertisement
Guest User

Untitled

a guest
Oct 18th, 2024
932
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.51 KB | None | 0 0
  1. #==============================================================================
  2. # Starter Selection Interface
  3. # Swdfm 2024-10-18
  4. # Used for "A Comprehensive Guide To Making A Custom UI" Tutorial
  5. # Call with "pbSelectStarter"
  6. #==============================================================================
  7. HOENN_STARTERS = [
  8. :TREECKO, :TORCHIC, :MUDKIP
  9. ]
  10.  
  11. class Starter_Selection
  12. def initialize
  13. # === Chapter 2 ===
  14. # Section 2.1
  15. @viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
  16. # Section 2.2
  17. @viewport.z = 99_999
  18. # === Chapter 3 ===
  19. # Section 3.1
  20. @sprites = {}
  21. # Section 3.2
  22. bg_exists = pbResolveBitmap("Graphics/UI/Trainer Card/bg_f")
  23. # Section 3.3
  24. if bg_exists
  25. addBackgroundPlane(@sprites, "bg", "Trainer Card/bg_f", @viewport)
  26. end
  27. # Section 3.4
  28. color = Color.new(0, 0, 0, 128)
  29. # Section 3.5
  30. @sprites["bg"] = ColoredPlane.new(color, @viewport)
  31. # === Chapter 4 ===
  32. # Section 4.1
  33. @sprites["overlay"] = BitmapSprite.new(Graphics.width, Graphics.height, @viewport)
  34. # Section 4.2
  35. pbSetSystemFont(@sprites["overlay"].bitmap)
  36. # Section 4.3
  37. @sprites["overlay"].z = @sprites["bg"].z + 1
  38. # Section 4.4
  39. @sprites["title"] = BitmapSprite.new(Graphics.width, Graphics.height / 4, @viewport)
  40. pbSetSystemFont(@sprites["title"].bitmap)
  41. @sprites["title"].z = @sprites["bg"].z + 1
  42. @sprites["title"].bitmap.font.size = 48
  43. # === Chapter 5 ===
  44. # Section 5.1
  45. @path = "Graphics/Pokemon/Front/"
  46. @path_icons = "Graphics/Pokemon/Icons/"
  47. @p_main_y = 48
  48. @icons_on_row = 3 # Amount of Pokemon Icons on one horizontal line
  49. @icon_first_y = @p_main_y + 200 # Y position of top row of Pokemon Icons
  50. @icon_gap_y = 64 # Space Between each Pokemon Icon (vertical)
  51. # Section 5.2
  52. pool = [
  53. :BULBASAUR, :CHARMANDER, :SQUIRTLE
  54. ]
  55. pool += HOENN_STARTERS
  56. @species = []
  57. for p in pool
  58. next unless GameData::Species.exists?(p)
  59. next unless pbResolveBitmap("#{@path}#{p}")
  60. next unless pbResolveBitmap("#{@path_icons}#{p}")
  61. @species.push(p)
  62. end
  63. # Section 5.3
  64. if @species.empty?
  65. 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!"
  66. end
  67. # First, we draw the icons
  68. # Section 5.4
  69. @species.each_with_index do |species, i|
  70. t_x = i % @icons_on_row # The "X co-ord" of that pokemon icon
  71. t_y = (i / @icons_on_row).floor # The "Y co-ord" of that pokemon icon
  72. # Section 5.5
  73. s = "icon_#{i}"
  74. # Section 5.6
  75. @sprites[s] = IconSprite.new(0, 0, @viewport)
  76. # Section 5.7
  77. @sprites[s].setBitmap(@path_icons + species.to_s)
  78. # Section 5.8
  79. @sprites[s].src_rect.width = @sprites[s].src_rect.width / 2
  80. # Section 5.9
  81. @sprites[s].x = (Graphics.width / (@icons_on_row + 1)).floor
  82. @sprites[s].x *= (t_x + 1)
  83. @sprites[s].x -= @sprites[s].width / 2
  84. @sprites[s].y = @icon_first_y + t_y * @icon_gap_y
  85. @sprites[s].z = @sprites["bg"].z + 2
  86. end
  87. # Section 5.10
  88. @index = rand(@species.length)
  89. # Then, we draw the big pokemon icon
  90. update_main_icon
  91. # === Chapter 6 ===
  92. do_text_pos = true
  93. # Section 6.1
  94. title = _INTL("Choose your starter!")
  95. overlay = @sprites["title"].bitmap
  96. title_x = Graphics.width / 2
  97. title_y = 8
  98. @baseColor = Color.new(224, 224, 224)
  99. @shadowColor = Color.new(48, 48, 48)
  100. if do_text_pos
  101. # Section 6.2
  102. text_pos = [
  103. [title, title_x, title_y, :center, @baseColor, @shadowColor]
  104. ]
  105. # Section 6.3
  106. pbDrawTextPositions(overlay, text_pos)
  107. else
  108. # Section 6.4
  109. drawTextEx(overlay, 0, title_y, Graphics.width, 1, title, @baseColor, @shadowColor)
  110. end
  111. change_pkmn_text
  112. # === Chapter 7 ===
  113. # Section 7.1
  114. @bg_colours = [
  115. Color.new(61, 102, 61), # Grass
  116. Color.new(127, 69, 63), # Fire
  117. Color.new(63, 92, 127) # Water
  118. ]
  119. # Section 7.2
  120. @sprites["arrow"] = AnimatedSprite.create("Graphics/UI/pause_arrow", 4, 3, @viewport)
  121. @sprites["arrow"].start
  122. @sprites["arrow"].z = @sprites["bg"].z + 3
  123. # === Chapter 8 ===
  124. refresh
  125. # Section 8.1
  126. pbFadeInAndShow(@sprites) { pbUpdate }
  127. loop do
  128. # Section 8.2
  129. Graphics.update
  130. Input.update
  131. pbUpdate
  132. # Section 8.3
  133. old_index = @index
  134. # Section 8.4
  135. if Input.trigger?(Input::USE)
  136. name = GameData::Species.get(@species[@index]).name
  137. if pbConfirmMessageSerious(_INTL("Are you sure that you wish to pick {1}?", name))
  138. # Section 8.5
  139. pbPlayDecisionSE
  140. # Section 8.6
  141. break
  142. else
  143. pbPlayCancelSE
  144. end
  145. # Section 8.7
  146. elsif Input.trigger?(Input::BACK)
  147. pbPlayBuzzerSE
  148. # Section 8.8
  149. elsif Input.trigger?(Input::LEFT)
  150. @index -= 1 unless @index % @icons_on_row == 0
  151. elsif Input.trigger?(Input::RIGHT)
  152. @index += 1 unless @index % @icons_on_row == @icons_on_row - 1
  153. elsif Input.trigger?(Input::UP)
  154. @index -= @icons_on_row unless @index < @icons_on_row
  155. elsif Input.trigger?(Input::DOWN)
  156. last_row = ((@species.length - 1) / @icons_on_row).floor * @icons_on_row
  157. @index += @icons_on_row if @index < last_row
  158. end
  159. # Section 8.9
  160. @index = @index.clamp(0, @species.length - 1)
  161. # Section 8.3
  162. if old_index != @index
  163. pbPlayCursorSE
  164. # Section 8.10
  165. refresh
  166. end
  167. end
  168. # Section 8.13
  169. pbFadeOutAndHide(@sprites)
  170. # Section 8.14
  171. pbDisposeSpriteHash(@sprites)
  172. @viewport.dispose
  173. end
  174.  
  175. # === Used in Chapters 5 and 8 ===
  176. def update_main_icon
  177. species = @species[@index]
  178. s = "poke"
  179. # Section 5.11
  180. @sprites[s].dispose if @sprites[s]
  181. @sprites[s] = IconSprite.new(0, @p_main_y, @viewport)
  182. @sprites[s].setBitmap("#{@path}#{species}")
  183. @sprites[s].x = Graphics.width / 2 - @sprites[s].width / 2
  184. end
  185.  
  186. # === Used in Chapters 6 and 8 ===
  187. def change_pkmn_text
  188. species = @species[@index]
  189. data = GameData::Species.get(species)
  190. text = data.name
  191. type = data.types[0]
  192. text_type = GameData::Type.get(type).name
  193. text_type = _INTL("{1} type", text_type)
  194. overlay = @sprites["overlay"].bitmap
  195. # Section 6.5
  196. overlay.clear
  197. t_x = Graphics.width / 2
  198. t_y = @sprites["poke"].y + @sprites["poke"].height - 32
  199. text_pos = [
  200. [text, t_x, t_y, :center, @baseColor, @shadowColor],
  201. [text_type, t_x, t_y + 32, :center, @baseColor, @shadowColor]
  202. ]
  203. pbDrawTextPositions(overlay, text_pos)
  204. end
  205.  
  206. # === Used in Chapter 8 ===
  207. def pbUpdate
  208. # Section 8.2
  209. pbUpdateSpriteHash(@sprites)
  210. end
  211.  
  212. # === Used in Chapter 8 ===
  213. def refresh
  214. update_main_icon
  215. change_pkmn_text
  216. # Moves Arrow
  217. # Section 8.11
  218. @sprites["arrow"].x = @sprites["icon_#{@index}"].x
  219. @sprites["arrow"].x += @sprites["icon_#{@index}"].width / 2
  220. @sprites["arrow"].x -= @sprites["arrow"].width / 2
  221. @sprites["arrow"].y = @sprites["icon_#{@index}"].y
  222. # Changes Background
  223. # Section 8.12
  224. c = @bg_colours[@index % @bg_colours.length]
  225. @sprites["bg"].set_plane_color(c)
  226. end
  227.  
  228. # === Chapter 9 ===
  229. def result
  230. # Section 9.1
  231. return @species[@index]
  232. end
  233. end
  234.  
  235. # Section 9.2
  236. def pbSelectStarter
  237. ret = Starter_Selection.new
  238. return ret.result
  239. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement