Advertisement
Guest User

Untitled

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