Advertisement
Guest User

DSI Secret Discovery Scene

a guest
Jul 19th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.22 KB | None | 0 0
  1. #==============================================================================
  2. # -- Script Name: DSI Secret Discovery Scene
  3. # -- Author: dsiver144
  4. # -- Last Updated: July 20th 2019
  5. # --------------------------------------------------------------------------
  6. # >> Script Call:
  7. # --------------------------------------------------------------------------
  8. # $game_system.unlock_secret(secret_key)
  9. # -> Use this to unlock a secret base on its secret key
  10. # ex: $game_system.unlock_secret(:secret1)
  11. # $game_system.lock_secret(secret_key)
  12. # -> Just in case you want to lock a secret.
  13. # ex: $game_system.lock_secret(:secret2)
  14. # $game_system.secret_unlocked?(secret_key)
  15. # -> Use in Conditional Branches to check if you have unlocked a secret or not.
  16. # ex: $game_system.secret_unlocked?(:secret1)
  17. #==============================================================================
  18. module DSIVER144
  19. module DISCOVERY
  20. # If this is set to true whenever you try to unlock an unknown secret key
  21. # A message will be shown to alert you about it.
  22. DEBUG_UNLOCK_WRONG_KEY = true
  23.  
  24. Title_Text_Color_Code = 14
  25. Scene_Title_Text = "Discoveries"
  26.  
  27. Secrets = {} # Don't remove this line.
  28. # Setup Zone
  29. #Secrets[secret_key] = {}
  30. Secrets[:secret1] = {}
  31. Secrets[:secret1][:name] = "Secret #1"
  32. Secrets[:secret1][:icon_index] = 18
  33. Secrets[:secret1][:bgm] = ["Theme4",80,100]
  34. Secrets[:secret1][:contents] = {}
  35. Secrets[:secret1][:contents][0] = "This is description about secret 1."
  36. # Use this below format when you need to add a picture.
  37. # Picture(name) where name is the picture name located in Graphics/Pictures
  38. Secrets[:secret1][:contents][1] = "Picture(Book)"
  39. Secrets[:secret1][:contents][2] = "More description..."
  40. Secrets[:secret1][:contents][3] = "You can use \\c[7]Message Code\\c[0] too."
  41. Secrets[:secret1][:contents][4] = "I have nothing to say... \\i[124]"
  42.  
  43. Secrets[:secret2] = {}
  44. Secrets[:secret2][:name] = "Secret #2"
  45. Secrets[:secret2][:icon_index] = 20
  46. Secrets[:secret2][:bgm] = nil
  47. Secrets[:secret2][:contents] = {}
  48. Secrets[:secret2][:contents][0] = "This is description about secret 2."
  49. Secrets[:secret2][:contents][1] = "Picture(Book)"
  50. Secrets[:secret2][:contents][2] = "This is a exmaple of the secret that"
  51. Secrets[:secret2][:contents][3] = "dont use BGM."
  52. Secrets[:secret2][:contents][4] = "New Line..."
  53. Secrets[:secret2][:contents][5] = "New Line..."
  54. Secrets[:secret2][:contents][6] = "New Line..."
  55. Secrets[:secret2][:contents][7] = "New Line..."
  56. Secrets[:secret2][:contents][8] = "New Line..."
  57. Secrets[:secret2][:contents][9] = "New Line..."
  58.  
  59. end # DISCOVERY
  60. end # DSIVER144
  61.  
  62. class Scene_Discovery < Scene_MenuBase
  63. include DSIVER144::DISCOVERY
  64. #--------------------------------------------------------------------------
  65. # * Start Processing
  66. #--------------------------------------------------------------------------
  67. def start
  68. super
  69. $game_system.save_bgm
  70.  
  71. ww = Graphics.width
  72. wh = 46
  73. @window_title = Window_Base.new(0, 0, ww, wh)
  74. title_text = Scene_Title_Text
  75. @window_title.draw_text(0, 0, @window_title.contents_width, @window_title.contents_height, title_text, 1)
  76. wy = @window_title.height
  77.  
  78. @window_list = Window_SecretList.new(0,wy)
  79. @window_list.height = Graphics.height - @window_title.height
  80. @window_list.create_contents
  81. @window_list.refresh
  82.  
  83. @window_list.set_handler(:secret, method(:on_secret_ok))
  84. @window_list.set_handler(:cancel, method(:on_secret_cancel))
  85.  
  86. wx = @window_list.width
  87. wy = @window_list.y
  88. ww = Graphics.width - @window_list.width
  89. wh = @window_list.height
  90. @data_window = Window_SecretData.new(wx, wy, ww, wh)
  91. @data_window.deactivate
  92.  
  93. @window_list.help_window = @data_window
  94. end
  95. #--------------------------------------------------------------------------
  96. # * On Secret [OK]
  97. #--------------------------------------------------------------------------
  98. def on_secret_ok
  99. @data_window.activate
  100. end
  101. #--------------------------------------------------------------------------
  102. # * on_secret_cancel
  103. #--------------------------------------------------------------------------
  104. def on_secret_cancel
  105. return_scene
  106. end
  107. #--------------------------------------------------------------------------
  108. # * Update
  109. #--------------------------------------------------------------------------
  110. def update
  111. super
  112. if @data_window.active
  113. if Input.trigger?(:B)
  114. Sound.play_cancel
  115. @data_window.deactivate
  116. @window_list.activate
  117. end
  118. end
  119. end
  120. #--------------------------------------------------------------------------
  121. # * Terminate
  122. #--------------------------------------------------------------------------
  123. def terminate
  124. super
  125. $game_system.replay_bgm
  126. end
  127.  
  128. end
  129.  
  130. class Window_SecretData < Window_Base
  131. include DSIVER144::DISCOVERY
  132. attr_accessor :current_secret
  133. #--------------------------------------------------------------------------
  134. # * Clear
  135. #--------------------------------------------------------------------------
  136. def clear
  137. contents.clear
  138. end
  139. #--------------------------------------------------------------------------
  140. # * Update
  141. #--------------------------------------------------------------------------
  142. def update
  143. super
  144. if self.active
  145. if Input.repeat?(:DOWN) && can_scroll_down?
  146. Sound.play_cursor
  147. self.oy += line_height
  148. set_item(@current_secret)
  149. end
  150. if Input.repeat?(:UP)
  151. Sound.play_cursor
  152. self.oy -= line_height
  153. if self.oy < 0
  154. self.oy = 0
  155. end
  156. set_item(@current_secret)
  157. end
  158. end
  159. end
  160. #--------------------------------------------------------------------------
  161. # * Can Scroll Down ?
  162. #--------------------------------------------------------------------------
  163. def can_scroll_down?
  164. return self.oy + contents_height < contents.height
  165. end
  166. #--------------------------------------------------------------------------
  167. # * Set Item
  168. #--------------------------------------------------------------------------
  169. def set_item(secret)
  170. contents.clear
  171. #@sprite_background = Sprite.new
  172. if secret.nil?
  173. self.oy = 0
  174. draw_text(0, 0, contents_width, contents_height, "- No Data -", 1)
  175. @current_secret = nil
  176. else
  177. @current_secret = secret
  178. cw = contents_width
  179. lh = line_height
  180. dx = 0
  181. dy = 0
  182. # Draw BG
  183. if secret[:background]
  184. background = Cache.picture(secret[:background])
  185. rect = contents.rect.clone
  186. rect.y = self.oy
  187. #rect.height = rect.height + rect.y
  188. contents.blt(dx, dy + self.oy, background, background.rect)
  189. end
  190. if secret[:bgm]
  191. RPG::BGM.new(*secret[:bgm]).play
  192. else
  193. $game_system.replay_bgm
  194. end
  195. # Draw Secret Name
  196. contents.font.size += 5
  197. change_color(text_color(Title_Text_Color_Code))
  198. draw_text(dx, dy, cw, lh, secret[:name], 1)
  199. contents.fill_rect(0, lh, cw, 2, Color.new(255,255,255,200))
  200. contents.font.size -= 5
  201. change_color(text_color(0))
  202. dy += lh
  203. secret[:contents].values.each_with_index do |line, index|
  204. if line.match(/Picture\((.+)\)/i)
  205. picture = Cache.picture($1)
  206. contents.blt(dx, dy, picture, picture.rect)
  207. dy += picture.rect.height
  208. else
  209. draw_text_ex(dx, dy, line)
  210. dy += lh
  211. end
  212. end
  213. end
  214. end
  215. end
  216.  
  217. class Window_SecretList < Window_Command
  218. include DSIVER144::DISCOVERY
  219. #--------------------------------------------------------------------------
  220. # * Get Command Ext
  221. #--------------------------------------------------------------------------
  222. def window_width
  223. return 300
  224. end
  225. #--------------------------------------------------------------------------
  226. # * Get Command Ext
  227. #--------------------------------------------------------------------------
  228. def command_ext(index)
  229. @list[index][:ext]
  230. end
  231. #--------------------------------------------------------------------------
  232. # * Update Help Window
  233. #--------------------------------------------------------------------------
  234. def update_help
  235. @help_window.set_item(current_ext)
  236. end
  237. #--------------------------------------------------------------------------
  238. # * Add Command
  239. #--------------------------------------------------------------------------
  240. def make_command_list
  241. Secrets.each_pair do |key, secret|
  242. next unless $game_system.secret_unlocked?(key)
  243. add_command(secret[:name], :secret, true, secret)
  244. end
  245. end
  246. #--------------------------------------------------------------------------
  247. # * Draw Item
  248. #--------------------------------------------------------------------------
  249. def draw_item(index)
  250. change_color(normal_color, command_enabled?(index))
  251. rect = item_rect_for_text(index)
  252. secret = command_ext(index)
  253. p secret
  254. if secret
  255. if secret[:icon_index]
  256. draw_icon(secret[:icon_index], rect.x, rect.y)
  257. rect.x += 26
  258. rect.width -= 26
  259. end
  260. draw_text(rect, command_name(index), alignment)
  261. end
  262. end
  263.  
  264. end
  265.  
  266. class Game_System
  267. include DSIVER144::DISCOVERY
  268. attr_accessor :unlocked_secrets
  269. #--------------------------------------------------------------------------
  270. # * Unlock Secrets
  271. #--------------------------------------------------------------------------
  272. def unlocked_secrets
  273. @unlocked_secrets ||= {}
  274. return @unlocked_secrets
  275. end
  276. #--------------------------------------------------------------------------
  277. # * Secret Unlocked?
  278. #--------------------------------------------------------------------------
  279. def secret_unlocked?(secret_key)
  280. return unlocked_secrets.has_key?(secret_key)
  281. end
  282. #--------------------------------------------------------------------------
  283. # * Unlock Secret
  284. #--------------------------------------------------------------------------
  285. def unlock_secret(secret_key)
  286. msgbox_p("You entered wrong key.") if $TEST && DEBUG_UNLOCK_WRONG_KEY && Secrets.has_key?(secret_key) == false
  287. unlocked_secrets[secret_key] = true
  288. end
  289. #--------------------------------------------------------------------------
  290. # * Lock Secret
  291. #--------------------------------------------------------------------------
  292. def lock_secret(secret_key)
  293. msgbox_p("You entered wrong key.") if $TEST && DEBUG_UNLOCK_WRONG_KEY && Secrets.has_key?(secret_key) == false
  294. unlocked_secrets.delete(secret_key)
  295. end
  296.  
  297. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement