Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # -- Script Name: DSI Secret Discovery Scene
- # -- Author: dsiver144
- # -- Last Updated: July 20th 2019
- # --------------------------------------------------------------------------
- # >> Script Call:
- # --------------------------------------------------------------------------
- # Open Scene: SceneManager.call(Scene_Discovery)
- # $game_system.unlock_secret(secret_key)
- # -> Use this to unlock a secret base on its secret key
- # ex: $game_system.unlock_secret(:secret1)
- # $game_system.lock_secret(secret_key)
- # -> Just in case you want to lock a secret.
- # ex: $game_system.lock_secret(:secret2)
- # $game_system.secret_unlocked?(secret_key)
- # -> Use in Conditional Branches to check if you have unlocked a secret or not.
- # ex: $game_system.secret_unlocked?(:secret1)
- #==============================================================================
- module DSIVER144
- module DISCOVERY
- # If this is set to true whenever you try to unlock an unknown secret key
- # A message will be shown to alert you about it.
- DEBUG_UNLOCK_WRONG_KEY = true
- MENU_COMMAND_NAME = "Discoveries"
- ENABLE_SWITCH_ID = 15 # Turn this switch ON to show the command in Menu.
- Title_Text_Color_Code = 14
- Scene_Title_Text = "Discoveries"
- Secrets = {} # Don't remove this line.
- # Setup Zone
- #Secrets[secret_key] = {}
- Secrets[:secret1] = {}
- Secrets[:secret1][:name] = "Secret #1"
- Secrets[:secret1][:icon_index] = 18
- Secrets[:secret1][:bgm] = ["Theme4",80,100]
- Secrets[:secret1][:contents] = {}
- Secrets[:secret1][:contents][0] = "This is description about secret 1."
- # Use this below format when you need to add a picture.
- # Picture(name) where name is the picture name located in Graphics/Pictures
- Secrets[:secret1][:contents][1] = "Picture(Book)"
- Secrets[:secret1][:contents][2] = "More description..."
- Secrets[:secret1][:contents][3] = "You can use \\c[7]Message Code\\c[0] too."
- Secrets[:secret1][:contents][4] = "I have nothing to say... \\i[124]"
- Secrets[:secret2] = {}
- Secrets[:secret2][:name] = "Secret #2"
- Secrets[:secret2][:icon_index] = 20
- Secrets[:secret2][:bgm] = nil
- Secrets[:secret2][:contents] = {}
- Secrets[:secret2][:contents][0] = "This is description about secret 2."
- Secrets[:secret2][:contents][1] = "Picture(Book)"
- Secrets[:secret2][:contents][2] = "This is a exmaple of the secret that"
- Secrets[:secret2][:contents][3] = "dont use BGM."
- Secrets[:secret2][:contents][4] = "New Line..."
- Secrets[:secret2][:contents][5] = "New Line..."
- Secrets[:secret2][:contents][6] = "New Line..."
- Secrets[:secret2][:contents][7] = "New Line..."
- Secrets[:secret2][:contents][8] = "New Line..."
- Secrets[:secret2][:contents][9] = "New Line..."
- end # DISCOVERY
- end # DSIVER144
- class Window_MenuCommand < Window_Command
- include DSIVER144::DISCOVERY
- alias_method(:dsi_discovery_add_original_commands, :add_original_commands)
- def add_original_commands
- dsi_discovery_add_original_commands
- if $game_switches[ENABLE_SWITCH_ID]
- add_command(MENU_COMMAND_NAME, :discovery)
- end
- end
- end
- class Scene_Menu
- include DSIVER144::DISCOVERY
- alias_method(:dsi_discovery_create_command_window, :create_command_window)
- def create_command_window
- dsi_discovery_create_command_window
- @command_window.set_handler(:discovery, method(:command_discovery))
- end
- #--------------------------------------------------------------------------
- # * new method: command_discovery
- #--------------------------------------------------------------------------
- def command_discovery
- SceneManager.call(Scene_Discovery)
- end
- end
- class Scene_Discovery < Scene_MenuBase
- include DSIVER144::DISCOVERY
- #--------------------------------------------------------------------------
- # * Start Processing
- #--------------------------------------------------------------------------
- def start
- super
- $game_system.save_bgm
- ww = Graphics.width
- wh = 46
- @window_title = Window_Base.new(0, 0, ww, wh)
- title_text = Scene_Title_Text
- @window_title.draw_text(0, 0, @window_title.contents_width, @window_title.contents_height, title_text, 1)
- wy = @window_title.height
- @window_list = Window_SecretList.new(0,wy)
- @window_list.height = Graphics.height - @window_title.height
- @window_list.create_contents
- @window_list.refresh
- @window_list.set_handler(:secret, method(:on_secret_ok))
- @window_list.set_handler(:cancel, method(:on_secret_cancel))
- wx = @window_list.width
- wy = @window_list.y
- ww = Graphics.width - @window_list.width
- wh = @window_list.height
- @data_window = Window_SecretData.new(wx, wy, ww, wh)
- @data_window.deactivate
- @window_list.help_window = @data_window
- end
- #--------------------------------------------------------------------------
- # * On Secret [OK]
- #--------------------------------------------------------------------------
- def on_secret_ok
- @data_window.activate
- end
- #--------------------------------------------------------------------------
- # * on_secret_cancel
- #--------------------------------------------------------------------------
- def on_secret_cancel
- return_scene
- end
- #--------------------------------------------------------------------------
- # * Update
- #--------------------------------------------------------------------------
- def update
- super
- if @data_window.active
- if Input.trigger?(:B)
- Sound.play_cancel
- @data_window.deactivate
- @window_list.activate
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Terminate
- #--------------------------------------------------------------------------
- def terminate
- super
- $game_system.replay_bgm
- end
- end
- class Window_SecretData < Window_Base
- include DSIVER144::DISCOVERY
- attr_accessor :current_secret
- #--------------------------------------------------------------------------
- # * Clear
- #--------------------------------------------------------------------------
- def clear
- contents.clear
- end
- #--------------------------------------------------------------------------
- # * Update
- #--------------------------------------------------------------------------
- def update
- super
- if self.active
- if Input.repeat?(:DOWN) && can_scroll_down?
- Sound.play_cursor
- self.oy += line_height
- set_item(@current_secret)
- end
- if Input.repeat?(:UP)
- Sound.play_cursor
- self.oy -= line_height
- if self.oy < 0
- self.oy = 0
- end
- set_item(@current_secret)
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Can Scroll Down ?
- #--------------------------------------------------------------------------
- def can_scroll_down?
- return self.oy + contents_height < contents.height
- end
- #--------------------------------------------------------------------------
- # * Set Item
- #--------------------------------------------------------------------------
- def set_item(secret)
- contents.clear
- #@sprite_background = Sprite.new
- if secret.nil?
- self.oy = 0
- draw_text(0, 0, contents_width, contents_height, "- No Data -", 1)
- @current_secret = nil
- else
- @current_secret = secret
- cw = contents_width
- lh = line_height
- dx = 0
- dy = 0
- # Draw BG
- if secret[:background]
- background = Cache.picture(secret[:background])
- rect = contents.rect.clone
- rect.y = self.oy
- #rect.height = rect.height + rect.y
- contents.blt(dx, dy + self.oy, background, background.rect)
- end
- if secret[:bgm]
- RPG::BGM.new(*secret[:bgm]).play
- else
- $game_system.replay_bgm
- end
- # Draw Secret Name
- contents.font.size += 5
- change_color(text_color(Title_Text_Color_Code))
- draw_text(dx, dy, cw, lh, secret[:name], 1)
- contents.fill_rect(0, lh, cw, 2, Color.new(255,255,255,200))
- contents.font.size -= 5
- change_color(text_color(0))
- dy += lh
- secret[:contents].values.each_with_index do |line, index|
- if line.match(/Picture\((.+)\)/i)
- picture = Cache.picture($1)
- contents.blt(dx, dy, picture, picture.rect)
- dy += picture.rect.height
- else
- draw_text_ex(dx, dy, line)
- dy += lh
- end
- end
- end
- end
- end
- class Window_SecretList < Window_Command
- include DSIVER144::DISCOVERY
- #--------------------------------------------------------------------------
- # * Get Command Ext
- #--------------------------------------------------------------------------
- def window_width
- return 300
- end
- #--------------------------------------------------------------------------
- # * Get Command Ext
- #--------------------------------------------------------------------------
- def command_ext(index)
- @list[index][:ext]
- end
- #--------------------------------------------------------------------------
- # * Update Help Window
- #--------------------------------------------------------------------------
- def update_help
- @help_window.set_item(current_ext)
- end
- #--------------------------------------------------------------------------
- # * Add Command
- #--------------------------------------------------------------------------
- def make_command_list
- Secrets.each_pair do |key, secret|
- next unless $game_system.secret_unlocked?(key)
- add_command(secret[:name], :secret, true, secret)
- end
- end
- #--------------------------------------------------------------------------
- # * Draw Item
- #--------------------------------------------------------------------------
- def draw_item(index)
- change_color(normal_color, command_enabled?(index))
- rect = item_rect_for_text(index)
- secret = command_ext(index)
- p secret
- if secret
- if secret[:icon_index]
- draw_icon(secret[:icon_index], rect.x, rect.y)
- rect.x += 26
- rect.width -= 26
- end
- draw_text(rect, command_name(index), alignment)
- end
- end
- end
- class Game_System
- include DSIVER144::DISCOVERY
- attr_accessor :unlocked_secrets
- #--------------------------------------------------------------------------
- # * Unlock Secrets
- #--------------------------------------------------------------------------
- def unlocked_secrets
- @unlocked_secrets ||= {}
- return @unlocked_secrets
- end
- #--------------------------------------------------------------------------
- # * Secret Unlocked?
- #--------------------------------------------------------------------------
- def secret_unlocked?(secret_key)
- return unlocked_secrets.has_key?(secret_key)
- end
- #--------------------------------------------------------------------------
- # * Unlock Secret
- #--------------------------------------------------------------------------
- def unlock_secret(secret_key)
- msgbox_p("You entered wrong key.") if $TEST && DEBUG_UNLOCK_WRONG_KEY && Secrets.has_key?(secret_key) == false
- unlocked_secrets[secret_key] = true
- end
- #--------------------------------------------------------------------------
- # * Lock Secret
- #--------------------------------------------------------------------------
- def lock_secret(secret_key)
- msgbox_p("You entered wrong key.") if $TEST && DEBUG_UNLOCK_WRONG_KEY && Secrets.has_key?(secret_key) == false
- unlocked_secrets.delete(secret_key)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement