DarkSoul144

DSI State Viewer

Jun 1st, 2021 (edited)
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.45 KB | None | 0 0
  1. #==============================================================================
  2. # -- Script : DSI State Viewer
  3. # -- Author : dsiver144
  4. # -- Last Updated : 01/06/2021
  5. #==============================================================================
  6. # > Script Calls:
  7. # ---------------------------------------------------------------------
  8. # 1. SceneManager.call(Scene_StateViewer) -> Open State Viewer Scene
  9. # 2. $game_system.unlock_state(state_id)
  10. # 3. $game_system.remove_state(state_id)
  11. # 4. $game_system.is_state_unlocked?(state_id)
  12. # -> Use this in conditional branches to check if a state is unlocked or not.
  13. # 5. $game_system.unlocked_states_percent
  14. # -> Use this in conditional branches to check the completed percentage.
  15. # ex: $game_system.unlocked_states_percent >= 100
  16. # This is check if you has completed the list or not.
  17. # ---------------------------------------------------------------------
  18. # > State Notetags:
  19. # ---------------------------------------------------------------------
  20. # 1. Custom Description
  21. # Use this
  22. # <desc>
  23. # Line 1
  24. # Line 2
  25. # Line 3
  26. # </desc>
  27. # 2. Reveal mode
  28. # Default mode will be all. It means if an actor or an enemy is inflicted by
  29. # the state, it will be unlocked.
  30. # <reveal mode: mode>
  31. # ex: <reveal mode: actor> or <reveal mode: all>
  32. # 3. Hide From List
  33. # Use this tag <hide>
  34. # !! The state that has EMPTY name will be excluded from the list.
  35. #==============================================================================
  36.  
  37. module DSIVER144
  38. module STATE_VIEWER
  39. TEXTS = {}
  40. TEXTS["Title"] = "~ State Viewer ~"
  41. TEXTS["Locked"] = "? ? ? ? ? ? ? ? ?"
  42. TEXTS["None"] = "None"
  43. TEXTS["Description"] = "Description"
  44. TEXTS["Duration"] = "\\i[187]\\c[21] Duration"
  45. TEXTS["Treatment"] = "\\i[202]\\c[21] Treatment"
  46. TEXTS["Complete"] = "\\i[230] Completed"
  47.  
  48. OPEN_KEY = :A # Press this key when you're in Status Menu
  49.  
  50. end
  51. end
  52.  
  53. module DataManager
  54. class << self
  55. alias_method(:dsi_sv_load_database, :load_database)
  56. end
  57. #--------------------------------------------------------------------------
  58. # * Load Database
  59. #--------------------------------------------------------------------------
  60. def self.load_database
  61. dsi_sv_load_database
  62. load_state_notetags
  63. end
  64. #--------------------------------------------------------------------------
  65. # * Load State Notetags
  66. #--------------------------------------------------------------------------
  67. def self.load_state_notetags
  68. $available_states = []
  69. $data_items.each do |item|
  70. next unless item
  71. item.effects.each do |effect|
  72. if effect.code == 22
  73. $data_states[effect.data_id].treat_items ||= []
  74. $data_states[effect.data_id].treat_items << item.id
  75. end
  76. end
  77. end
  78. $data_states.each do |state|
  79. next unless state
  80. state.hide_from_list = true if state.name.size == 0
  81. read_note = false
  82. state.reveal_mode = :all
  83. state.note.split(/[\r\n]+/i).each do |line|
  84. if line =~ /<desc>/i
  85. read_note = true
  86. state.custom_desc = ""
  87. next
  88. end
  89. if line =~ /<\/desc>/i
  90. read_note = false
  91. next
  92. end
  93. if read_note
  94. state.custom_desc += line + "\r\n"
  95. end
  96. if line =~ /<hide>/i
  97. state.hide_from_list = true
  98. end
  99. if line =~ /<reveal mode:\s*(actor|all)>/i
  100. state.reveal_mode = $1.to_sym
  101. end
  102. end
  103. $available_states << state unless state.hide_from_list
  104. end
  105. end
  106. end
  107.  
  108. class RPG::State
  109. attr_accessor :custom_desc
  110. attr_accessor :hide_from_list
  111. attr_accessor :treat_items
  112. attr_accessor :reveal_mode
  113. end
  114.  
  115. class Scene_StateViewer < Scene_MenuBase
  116. include DSIVER144::STATE_VIEWER
  117. #--------------------------------------------------------------------------
  118. # * Start
  119. #--------------------------------------------------------------------------
  120. def start
  121. super
  122. @title_window = Window_Base.new(0, 0, Graphics.width, 64)
  123. @title_window.draw_text(0, 0, @title_window.contents_width, @title_window.contents_height, TEXTS["Title"], 1)
  124.  
  125. @list_window = Window_StatusList.new(0, 0)
  126. @list_window.refresh
  127. @list_window.y = @title_window.height
  128. @list_window.set_handler(:cancel, method(:return_scene))
  129.  
  130. @help_window = Window_StateInfo.new(0, 0, Graphics.width - @list_window.width, @list_window.height - @list_window.fitting_height(1))
  131. @help_window.refresh(nil)
  132. @list_window.help_window = @help_window
  133. @help_window.x = @list_window.width
  134. @help_window.y = @title_window.height
  135.  
  136. wx = @help_window.x
  137. wy = @help_window.y + @help_window.height
  138. ww = @help_window.width
  139. wh = Graphics.height - @help_window.height - @title_window.height
  140. @completed_window = Window_Base.new(wx, wy, ww, wh)
  141. @completed_window.draw_text_ex(0, 0, TEXTS["Complete"])
  142. @completed_window.draw_text(0, 0, @completed_window.contents_width, @completed_window.contents_height, "#{$game_system.unlocked_states_percent.round(2)}%", 2)
  143.  
  144. @title_window.back_opacity = @help_window.back_opacity
  145. @completed_window.back_opacity = @help_window.back_opacity
  146. end
  147. end
  148.  
  149. class Window_StatusList < Window_Command
  150. include DSIVER144::STATE_VIEWER
  151. #--------------------------------------------------------------------------
  152. # * Window Width
  153. #--------------------------------------------------------------------------
  154. def window_width
  155. return 230
  156. end
  157. #--------------------------------------------------------------------------
  158. # * Window Height
  159. #--------------------------------------------------------------------------
  160. def window_height
  161. return Graphics.height - 64
  162. end
  163. #--------------------------------------------------------------------------
  164. # * Update Help Window
  165. #--------------------------------------------------------------------------
  166. def update_help
  167. @help_window.refresh(current_ext)
  168. end
  169. #--------------------------------------------------------------------------
  170. # * Make Command List
  171. #--------------------------------------------------------------------------
  172. def make_command_list
  173. $available_states.each do |state|
  174. if $game_system.is_state_unlocked?(state.id)
  175. add_command(state.name, :ok, true, state)
  176. else
  177. add_command(TEXTS["Locked"], :ok, true, nil)
  178. end
  179. end
  180. end
  181. #--------------------------------------------------------------------------
  182. # * Processing When OK Button Is Pressed
  183. #--------------------------------------------------------------------------
  184. def process_ok
  185. if current_item_enabled?
  186. Input.update
  187. deactivate
  188. call_ok_handler
  189. else
  190. Sound.play_buzzer
  191. end
  192. end
  193. #--------------------------------------------------------------------------
  194. # * Draw Item
  195. #--------------------------------------------------------------------------
  196. def draw_item(index)
  197. rect = item_rect(index)
  198. rect_text = item_rect_for_text(index)
  199. name = command_name(index)
  200. state = @list[index][:ext]
  201. cw = contents_width
  202. lh = line_height
  203.  
  204. temp_rect = rect.clone
  205. temp_rect.y += 1
  206. temp_rect.height -= 2
  207. contents.fill_rect(temp_rect, Color.new(0, 0, 0, 50))
  208. change_color(system_color)
  209. draw_text(rect_text.x, rect_text.y, 32, lh, (index+1).to_s + ".", 2)
  210. change_color(text_color(0))
  211. if state
  212. draw_text_ex(rect_text.x + 32, rect_text.y, "\\i[#{state.icon_index}] #{state.name}")
  213. else
  214. draw_text_ex(rect_text.x + 32, rect_text.y, "\\c[7]" + name)
  215. end
  216.  
  217. end
  218.  
  219. end
  220.  
  221. class Window_StateInfo < Window_Base
  222. include DSIVER144::STATE_VIEWER
  223. #--------------------------------------------------------------------------
  224. # * Refresh
  225. #--------------------------------------------------------------------------
  226. def refresh(state)
  227. contents.clear
  228. cw = contents_width
  229. ch = contents_height
  230. lh = line_height
  231. if state.nil?
  232. draw_text(0, 0, cw, ch, TEXTS["None"], 1)
  233. return
  234. end
  235. dx = 0; dy = 0
  236. contents.font.bold = true
  237. change_color(system_color)
  238. draw_text(dx, dy, cw, lh, TEXTS["Description"], 1)
  239. contents.font.bold = false
  240. change_color(text_color(0))
  241. dy += lh + 4
  242. contents.fill_rect(dx, dy, cw, lh * 3, Color.new(0, 0, 0, 50))
  243. desc = state.custom_desc ? state.custom_desc : nil
  244. if desc
  245. draw_text_ex(dx + 4, dy, desc)
  246. else
  247. draw_text(dx, dy, cw, lh * 3, TEXTS["None"], 1)
  248. end
  249. dy += lh * 2 + 4
  250. change_color(system_color)
  251. draw_text(dx, dy, cw, lh, TEXTS["Info"], 1)
  252. contents.font.bold = false
  253. change_color(text_color(0))
  254. dy += lh + 4
  255. if true
  256. change_color(text_color(14))
  257. draw_text_ex(dx, dy,TEXTS["Duration"])
  258. change_color(text_color(0))
  259. turn_value = state.min_turns == state.max_turns ? "#{state.min_turns}" : "#{state.min_turns} ~ #{state.max_turns}"
  260. turn_text = state.auto_removal_timing > 0 ? "#{turn_value} Turn(s)" : " --- "
  261. dy += lh + 2
  262. contents.fill_rect(dx, dy, cw, lh, Color.new(0,0,0,50))
  263. draw_text(dx, dy, cw, lh, turn_text, 2)
  264. dy += lh + 2
  265. end
  266. if state.treat_items
  267. change_color(text_color(14))
  268. draw_text_ex(dx, dy, TEXTS["Treatment"])
  269. change_color(text_color(0))
  270. dy += lh + 2
  271. split = state.treat_items.size >= 4
  272. state.treat_items.each_with_index do |id, i|
  273. item = $data_items[id]
  274. cx = split && i % 2 != 0 ? cw / 2 : 0
  275. bar_w = split ? cw / 2 : cw
  276. contents.fill_rect(dx + cx, dy, bar_w, lh, Color.new(0,0,0,50))
  277. draw_text_ex(dx + cx, dy, "\\i[#{item.icon_index}]#{item.name}")
  278. dy += lh + 2 if split && i % 2 != 0
  279. end
  280. end
  281. end
  282.  
  283. end
  284.  
  285. class Game_System
  286. #--------------------------------------------------------------------------
  287. # * Get Unlocked States
  288. #--------------------------------------------------------------------------
  289. def unlocked_states
  290. @unlocked_states ||= {}
  291. end
  292. #--------------------------------------------------------------------------
  293. # * Unlock State Percent
  294. #--------------------------------------------------------------------------
  295. def unlocked_states_percent
  296. return unlocked_states.keys.size / $available_states.size.to_f * 100
  297. end
  298. #--------------------------------------------------------------------------
  299. # * Unlock State
  300. #--------------------------------------------------------------------------
  301. def unlock_state(state_id)
  302. @unlocked_states ||= {}
  303. @unlocked_states[state_id] = true
  304. end
  305. #--------------------------------------------------------------------------
  306. # * Is State Unlocked?
  307. #--------------------------------------------------------------------------
  308. def is_state_unlocked?(state_id)
  309. unlocked_states[state_id] == true
  310. end
  311. #--------------------------------------------------------------------------
  312. # * Remove State
  313. #--------------------------------------------------------------------------
  314. def remove_state(state_id)
  315. @unlocked_states ||= {}
  316. @unlocked_states.delete(state_id)
  317. end
  318.  
  319. end
  320.  
  321. class Game_Battler
  322. #--------------------------------------------------------------------------
  323. # * Add new state
  324. #--------------------------------------------------------------------------
  325. alias_method(:dsi_add_new_state_sv, :add_new_state)
  326. def add_new_state(state_id)
  327. state = $data_states[state_id]
  328. if !state.hide_from_list
  329. if state.reveal_mode == :all
  330. $game_system.unlock_state(state_id)
  331. else state.reveal_mode == :actor
  332. $game_system.unlock_state(state_id) if self.is_a?(Game_Actor)
  333. end
  334. end
  335. dsi_add_new_state_sv(state_id)
  336. end
  337. end
  338.  
  339. class Scene_Status < Scene_MenuBase
  340.  
  341. alias_method(:dsi_sv_scene_status_update, :update)
  342. #--------------------------------------------------------------------------
  343. # * Update
  344. #--------------------------------------------------------------------------
  345. def update
  346. dsi_sv_scene_status_update
  347. if Input.trigger?(DSIVER144::STATE_VIEWER::OPEN_KEY)
  348. open_status_viewer
  349. end
  350. end
  351. #--------------------------------------------------------------------------
  352. # * Open Status Viewer
  353. #--------------------------------------------------------------------------
  354. def open_status_viewer
  355. Sound.play_ok
  356. SceneManager.call(Scene_StateViewer)
  357. end
  358. end
Add Comment
Please, Sign In to add comment