Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # -- Script : DSI State Viewer
- # -- Author : dsiver144
- # -- Last Updated : 01/06/2021
- #==============================================================================
- # > Script Calls:
- # ---------------------------------------------------------------------
- # 1. SceneManager.call(Scene_StateViewer) -> Open State Viewer Scene
- # 2. $game_system.unlock_state(state_id)
- # 3. $game_system.remove_state(state_id)
- # 4. $game_system.is_state_unlocked?(state_id)
- # -> Use this in conditional branches to check if a state is unlocked or not.
- # 5. $game_system.unlocked_states_percent
- # -> Use this in conditional branches to check the completed percentage.
- # ex: $game_system.unlocked_states_percent >= 100
- # This is check if you has completed the list or not.
- # ---------------------------------------------------------------------
- # > State Notetags:
- # ---------------------------------------------------------------------
- # 1. Custom Description
- # Use this
- # <desc>
- # Line 1
- # Line 2
- # Line 3
- # </desc>
- # 2. Reveal mode
- # Default mode will be all. It means if an actor or an enemy is inflicted by
- # the state, it will be unlocked.
- # <reveal mode: mode>
- # ex: <reveal mode: actor> or <reveal mode: all>
- # 3. Hide From List
- # Use this tag <hide>
- # !! The state that has EMPTY name will be excluded from the list.
- #==============================================================================
- module DSIVER144
- module STATE_VIEWER
- TEXTS = {}
- TEXTS["Title"] = "~ State Viewer ~"
- TEXTS["Locked"] = "? ? ? ? ? ? ? ? ?"
- TEXTS["None"] = "None"
- TEXTS["Description"] = "Description"
- TEXTS["Duration"] = "\\i[187]\\c[21] Duration"
- TEXTS["Treatment"] = "\\i[202]\\c[21] Treatment"
- TEXTS["Complete"] = "\\i[230] Completed"
- OPEN_KEY = :A # Press this key when you're in Status Menu
- end
- end
- module DataManager
- class << self
- alias_method(:dsi_sv_load_database, :load_database)
- end
- #--------------------------------------------------------------------------
- # * Load Database
- #--------------------------------------------------------------------------
- def self.load_database
- dsi_sv_load_database
- load_state_notetags
- end
- #--------------------------------------------------------------------------
- # * Load State Notetags
- #--------------------------------------------------------------------------
- def self.load_state_notetags
- $available_states = []
- $data_items.each do |item|
- next unless item
- item.effects.each do |effect|
- if effect.code == 22
- $data_states[effect.data_id].treat_items ||= []
- $data_states[effect.data_id].treat_items << item.id
- end
- end
- end
- $data_states.each do |state|
- next unless state
- state.hide_from_list = true if state.name.size == 0
- read_note = false
- state.reveal_mode = :all
- state.note.split(/[\r\n]+/i).each do |line|
- if line =~ /<desc>/i
- read_note = true
- state.custom_desc = ""
- next
- end
- if line =~ /<\/desc>/i
- read_note = false
- next
- end
- if read_note
- state.custom_desc += line + "\r\n"
- end
- if line =~ /<hide>/i
- state.hide_from_list = true
- end
- if line =~ /<reveal mode:\s*(actor|all)>/i
- state.reveal_mode = $1.to_sym
- end
- end
- $available_states << state unless state.hide_from_list
- end
- end
- end
- class RPG::State
- attr_accessor :custom_desc
- attr_accessor :hide_from_list
- attr_accessor :treat_items
- attr_accessor :reveal_mode
- end
- class Scene_StateViewer < Scene_MenuBase
- include DSIVER144::STATE_VIEWER
- #--------------------------------------------------------------------------
- # * Start
- #--------------------------------------------------------------------------
- def start
- super
- @title_window = Window_Base.new(0, 0, Graphics.width, 64)
- @title_window.draw_text(0, 0, @title_window.contents_width, @title_window.contents_height, TEXTS["Title"], 1)
- @list_window = Window_StatusList.new(0, 0)
- @list_window.refresh
- @list_window.y = @title_window.height
- @list_window.set_handler(:cancel, method(:return_scene))
- @help_window = Window_StateInfo.new(0, 0, Graphics.width - @list_window.width, @list_window.height - @list_window.fitting_height(1))
- @help_window.refresh(nil)
- @list_window.help_window = @help_window
- @help_window.x = @list_window.width
- @help_window.y = @title_window.height
- wx = @help_window.x
- wy = @help_window.y + @help_window.height
- ww = @help_window.width
- wh = Graphics.height - @help_window.height - @title_window.height
- @completed_window = Window_Base.new(wx, wy, ww, wh)
- @completed_window.draw_text_ex(0, 0, TEXTS["Complete"])
- @completed_window.draw_text(0, 0, @completed_window.contents_width, @completed_window.contents_height, "#{$game_system.unlocked_states_percent.round(2)}%", 2)
- @title_window.back_opacity = @help_window.back_opacity
- @completed_window.back_opacity = @help_window.back_opacity
- end
- end
- class Window_StatusList < Window_Command
- include DSIVER144::STATE_VIEWER
- #--------------------------------------------------------------------------
- # * Window Width
- #--------------------------------------------------------------------------
- def window_width
- return 230
- end
- #--------------------------------------------------------------------------
- # * Window Height
- #--------------------------------------------------------------------------
- def window_height
- return Graphics.height - 64
- end
- #--------------------------------------------------------------------------
- # * Update Help Window
- #--------------------------------------------------------------------------
- def update_help
- @help_window.refresh(current_ext)
- end
- #--------------------------------------------------------------------------
- # * Make Command List
- #--------------------------------------------------------------------------
- def make_command_list
- $available_states.each do |state|
- if $game_system.is_state_unlocked?(state.id)
- add_command(state.name, :ok, true, state)
- else
- add_command(TEXTS["Locked"], :ok, true, nil)
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Processing When OK Button Is Pressed
- #--------------------------------------------------------------------------
- def process_ok
- if current_item_enabled?
- Input.update
- deactivate
- call_ok_handler
- else
- Sound.play_buzzer
- end
- end
- #--------------------------------------------------------------------------
- # * Draw Item
- #--------------------------------------------------------------------------
- def draw_item(index)
- rect = item_rect(index)
- rect_text = item_rect_for_text(index)
- name = command_name(index)
- state = @list[index][:ext]
- cw = contents_width
- lh = line_height
- temp_rect = rect.clone
- temp_rect.y += 1
- temp_rect.height -= 2
- contents.fill_rect(temp_rect, Color.new(0, 0, 0, 50))
- change_color(system_color)
- draw_text(rect_text.x, rect_text.y, 32, lh, (index+1).to_s + ".", 2)
- change_color(text_color(0))
- if state
- draw_text_ex(rect_text.x + 32, rect_text.y, "\\i[#{state.icon_index}] #{state.name}")
- else
- draw_text_ex(rect_text.x + 32, rect_text.y, "\\c[7]" + name)
- end
- end
- end
- class Window_StateInfo < Window_Base
- include DSIVER144::STATE_VIEWER
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh(state)
- contents.clear
- cw = contents_width
- ch = contents_height
- lh = line_height
- if state.nil?
- draw_text(0, 0, cw, ch, TEXTS["None"], 1)
- return
- end
- dx = 0; dy = 0
- contents.font.bold = true
- change_color(system_color)
- draw_text(dx, dy, cw, lh, TEXTS["Description"], 1)
- contents.font.bold = false
- change_color(text_color(0))
- dy += lh + 4
- contents.fill_rect(dx, dy, cw, lh * 3, Color.new(0, 0, 0, 50))
- desc = state.custom_desc ? state.custom_desc : nil
- if desc
- draw_text_ex(dx + 4, dy, desc)
- else
- draw_text(dx, dy, cw, lh * 3, TEXTS["None"], 1)
- end
- dy += lh * 2 + 4
- change_color(system_color)
- draw_text(dx, dy, cw, lh, TEXTS["Info"], 1)
- contents.font.bold = false
- change_color(text_color(0))
- dy += lh + 4
- if true
- change_color(text_color(14))
- draw_text_ex(dx, dy,TEXTS["Duration"])
- change_color(text_color(0))
- turn_value = state.min_turns == state.max_turns ? "#{state.min_turns}" : "#{state.min_turns} ~ #{state.max_turns}"
- turn_text = state.auto_removal_timing > 0 ? "#{turn_value} Turn(s)" : " --- "
- dy += lh + 2
- contents.fill_rect(dx, dy, cw, lh, Color.new(0,0,0,50))
- draw_text(dx, dy, cw, lh, turn_text, 2)
- dy += lh + 2
- end
- if state.treat_items
- change_color(text_color(14))
- draw_text_ex(dx, dy, TEXTS["Treatment"])
- change_color(text_color(0))
- dy += lh + 2
- split = state.treat_items.size >= 4
- state.treat_items.each_with_index do |id, i|
- item = $data_items[id]
- cx = split && i % 2 != 0 ? cw / 2 : 0
- bar_w = split ? cw / 2 : cw
- contents.fill_rect(dx + cx, dy, bar_w, lh, Color.new(0,0,0,50))
- draw_text_ex(dx + cx, dy, "\\i[#{item.icon_index}]#{item.name}")
- dy += lh + 2 if split && i % 2 != 0
- end
- end
- end
- end
- class Game_System
- #--------------------------------------------------------------------------
- # * Get Unlocked States
- #--------------------------------------------------------------------------
- def unlocked_states
- @unlocked_states ||= {}
- end
- #--------------------------------------------------------------------------
- # * Unlock State Percent
- #--------------------------------------------------------------------------
- def unlocked_states_percent
- return unlocked_states.keys.size / $available_states.size.to_f * 100
- end
- #--------------------------------------------------------------------------
- # * Unlock State
- #--------------------------------------------------------------------------
- def unlock_state(state_id)
- @unlocked_states ||= {}
- @unlocked_states[state_id] = true
- end
- #--------------------------------------------------------------------------
- # * Is State Unlocked?
- #--------------------------------------------------------------------------
- def is_state_unlocked?(state_id)
- unlocked_states[state_id] == true
- end
- #--------------------------------------------------------------------------
- # * Remove State
- #--------------------------------------------------------------------------
- def remove_state(state_id)
- @unlocked_states ||= {}
- @unlocked_states.delete(state_id)
- end
- end
- class Game_Battler
- #--------------------------------------------------------------------------
- # * Add new state
- #--------------------------------------------------------------------------
- alias_method(:dsi_add_new_state_sv, :add_new_state)
- def add_new_state(state_id)
- state = $data_states[state_id]
- if !state.hide_from_list
- if state.reveal_mode == :all
- $game_system.unlock_state(state_id)
- else state.reveal_mode == :actor
- $game_system.unlock_state(state_id) if self.is_a?(Game_Actor)
- end
- end
- dsi_add_new_state_sv(state_id)
- end
- end
- class Scene_Status < Scene_MenuBase
- alias_method(:dsi_sv_scene_status_update, :update)
- #--------------------------------------------------------------------------
- # * Update
- #--------------------------------------------------------------------------
- def update
- dsi_sv_scene_status_update
- if Input.trigger?(DSIVER144::STATE_VIEWER::OPEN_KEY)
- open_status_viewer
- end
- end
- #--------------------------------------------------------------------------
- # * Open Status Viewer
- #--------------------------------------------------------------------------
- def open_status_viewer
- Sound.play_ok
- SceneManager.call(Scene_StateViewer)
- end
- end
Add Comment
Please, Sign In to add comment