Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==========================================================================
- # Iavra Item/Skill Discovery 1.0
- # -------------------------------------------------------------------------
- # Description:
- # Allows to hide the icon, name and description of items and skills until
- # they get used for the first time.
- # -------------------------------------------------------------------------
- # Prerequisites:
- # None
- # -------------------------------------------------------------------------
- # How to Use:
- # Place the following tags in the notebox of items/skills you want to hide:
- # <hide icon> Hides the icon. Optionally, an icon id can be supplied.
- # <hide name> Hides the name. Optionally, a string can be supplied.
- # <hide desc> Hides the description. Optionally, a string can be supplied.
- # Also, a small message can be shown every time a new item/skill is discovered.
- # -------------------------------------------------------------------------
- # Terms of Use:
- # Free to use for both commercial and non-commercial games. Please give credit.
- # -------------------------------------------------------------------------
- # Credits:
- # Iavra
- #==========================================================================
- module IAVRA
- module DISCOVER
- #==========================================================================
- # ■ ■ ■ ■ ■ CONFIGURATION ■ ■ ■ ■ ■
- #==========================================================================
- #==========================================================================
- # The default icon id to be used for hidden items/skills if no specific id
- # is supplied in the notetag. This can be done with <hide icon 1>.
- #==========================================================================
- DEFAULT_ICON = 1
- #==========================================================================
- # The default name to be used for hidden items/skills if no specific string
- # is supplied in the notetag. This can be done with <hide name "Text">
- #==========================================================================
- DEFAULT_NAME = "???"
- #==========================================================================
- # The default description to be used for hidden items/skills if no specific
- # string is supplied in the notetag. This can be done with <hide desc "Text">
- #==========================================================================
- DEFAULT_DESC = "???"
- #==========================================================================
- # If set to true, a popup window is shown in the bottom left corner whenever
- # a new iterm/skill is discovered.
- #==========================================================================
- SHOW_WINDOW = true
- #==========================================================================
- # The width of the popup window
- #==========================================================================
- WINDOW_WIDTH = 400
- #==========================================================================
- # The vertical space below each window. If a new item is discovered while
- # there is still a window on the screen, the old one(s) will be pushed
- # upwards depending on the new window's height and this value.
- #==========================================================================
- WINDOW_SPACING = 10
- #==========================================================================
- # If set to true, the icon of the discovered item/skill is shown in front
- # of the message.
- #==========================================================================
- WINDOW_ICON = false
- #==========================================================================
- # The text to be displayed. All message codes can be used.
- #==========================================================================
- WINDOW_TEXT = " \\C[2]%s\\C[0] discovered!"
- #==========================================================================
- # The delay (in frames) before the window starts to fade away and the rate
- # at which the window fades.
- #==========================================================================
- WINDOW_FADE_DELAY = 120
- WINDOW_FADE_RATE = 10
- #==========================================================================
- # The padding inside the window. X is horizontal, Y is vertical.
- #==========================================================================
- WINDOW_PADDING_X = 5
- WINDOW_PADDING_Y = 5
- #==========================================================================
- # The background of the window is drawn as a gradient between these colors.
- #==========================================================================
- WINDOW_COLOR_1 = Color.new(0, 0, 0, 255)
- WINDOW_COLOR_2 = Color.new(0, 0, 0, 0)
- #==========================================================================
- # ■ ■ ■ ■ ■ CONFIGURATION ■ ■ ■ ■ ■
- #==========================================================================
- REGEX_ICON = /^\s*<hide icon(\s+(\d+))?>/i
- REGEX_NAME = /^\s*<hide name(\s+"(.*)")?>/i
- REGEX_DESC = /^\s*<hide desc(\s+"(.*)")?>/i
- #==========================================================================
- # ▼ IAVRA::DISCOVER::Window_Discover
- #==========================================================================
- class Window_Discover < Window_Base
- #==========================================================================
- # Initializes the window, draws text etc.
- #==========================================================================
- def initialize(item)
- width = WINDOW_WIDTH + WINDOW_PADDING_X * 2
- height = fitting_height(1) + WINDOW_PADDING_Y * 2
- super(0, Graphics.height - height - WINDOW_SPACING, width, height)
- contents.gradient_fill_rect(contents.rect, WINDOW_COLOR_1, WINDOW_COLOR_2)
- draw_icon(item.icon_index, WINDOW_PADDING_X, WINDOW_PADDING_Y) if WINDOW_ICON
- offset = WINDOW_PADDING_X + (WINDOW_ICON ? 24 : 0)
- draw_text_ex(offset, WINDOW_PADDING_Y, sprintf(WINDOW_TEXT, item.name))
- self.windowskin = nil
- @delay = WINDOW_FADE_DELAY
- self.z = 1000
- end
- #==========================================================================
- # Count down delay and fade out. Dispose if opacity is 0.
- #==========================================================================
- def update
- super
- self.contents_opacity -= WINDOW_FADE_RATE if (@delay -= 1) <= 0
- dispose if self.contents_opacity == 0
- end
- #==========================================================================
- # Umm...yeah.
- #==========================================================================
- def standard_padding
- return 0
- end
- end
- end
- end
- #==========================================================================
- # ▼ DataManager
- #==========================================================================
- module DataManager
- class << self
- alias :iavra_discover_load_database :load_database
- end
- #==========================================================================
- # Loads our notetags from all skills and items.
- #==========================================================================
- def self.load_database
- iavra_discover_load_database
- ($data_items + $data_skills).compact.each{|item| item.iavra_discover_init}
- end
- end
- #==========================================================================
- # ▼ Game_System
- #==========================================================================
- class Game_System
- attr_reader :iavra_discover_discovered
- alias :iavra_discover_initialize :initialize
- #==========================================================================
- # Initializes our discovery hash.
- #==========================================================================
- def initialize(*args)
- iavra_discover_initialize(*args)
- @iavra_discover_discovered = {}
- end
- end
- #==========================================================================
- # ▼ RPG::UsableItem
- #==========================================================================
- class RPG::UsableItem < RPG::BaseItem
- #==========================================================================
- # Parses all notetags and stores the hidden values.
- #==========================================================================
- def iavra_discover_init
- self.note.split(/[\r\n]+/).each do |line|
- @iavra_discover_icon = $2.to_i || IAVRA::DISCOVER::DEFAULT_ICON if line[IAVRA::DISCOVER::REGEX_ICON]
- @iavra_discover_name = $2 || IAVRA::DISCOVER::DEFAULT_NAME if line[IAVRA::DISCOVER::REGEX_NAME]
- @iavra_discover_desc = $2 || IAVRA::DISCOVER::DEFAULT_DESC if line[IAVRA::DISCOVER::REGEX_DESC]
- end
- end
- #==========================================================================
- # Returns true if any part of the item/skill is still hidden.
- #==========================================================================
- def iavra_discover_discoverable?
- (@iavra_discover_icon || @iavra_discover_name || @iavra_discover_desc) &&
- $game_system.iavra_discover_discovered[[self.class, @id]].nil?
- end
- #==========================================================================
- # Returns our hidden icon index if the item/skill has not yet been used.
- #==========================================================================
- def icon_index
- return @icon_index if $game_system.iavra_discover_discovered[[self.class, @id]]
- return @iavra_discover_icon || @icon_index
- end
- #==========================================================================
- # Returns our hidden name if the skill/item has not yet been used.
- #==========================================================================
- def name
- return @name if $game_system.iavra_discover_discovered[[self.class, @id]]
- return @iavra_discover_name || @name
- end
- #==========================================================================
- # Returns our hidden description if the skill/item has not yet been used.
- #==========================================================================
- def description
- return @description if $game_system.iavra_discover_discovered[[self.class, @id]]
- return @iavra_discover_desc || @description
- end
- end
- #==========================================================================
- # ▼ Game_Actor
- #==========================================================================
- class Game_Actor < Game_Battler
- alias :iavra_discover_use_item :use_item
- #==========================================================================
- # Marks the skill/item as used.
- #==========================================================================
- def use_item(item)
- iavra_discover_use_item(item)
- if(item.iavra_discover_discoverable?)
- $game_system.iavra_discover_discovered[[item.class, item.id]] = true
- if(IAVRA::DISCOVER::SHOW_WINDOW)
- window = IAVRA::DISCOVER::Window_Discover.new(item)
- SceneManager.scene.iavra_discover_add_window(window)
- end
- end
- end
- end
- #==========================================================================
- # ▼ Scene_Base
- #==========================================================================
- class Scene_Base
- alias :iavra_discover_start :start
- alias :iavra_discover_update_all_windows :update_all_windows
- alias :iavra_discover_dispose_all_windows :dispose_all_windows
- #==========================================================================
- # Initialize our window array.
- #==========================================================================
- def start(*args)
- iavra_discover_start(*args)
- @iavra_discover_windows = []
- end
- #==========================================================================
- # Update all windows and remove disposed ones.
- #==========================================================================
- def update_all_windows
- iavra_discover_update_all_windows
- @iavra_discover_windows.reject!{|window| window.disposed?}
- @iavra_discover_windows.each{|window| window.update}
- end
- #==========================================================================
- # Cleanup on scene end.
- #==========================================================================
- def dispose_all_windows
- iavra_discover_dispose_all_windows
- @iavra_discover_windows.each{|window| window.dispose}
- end
- #==========================================================================
- # Add a new window, push older ones up to make space.
- #==========================================================================
- def iavra_discover_add_window(window)
- @iavra_discover_windows.each{|w| w.y -= (window.height + IAVRA::DISCOVER::WINDOW_SPACING)}
- @iavra_discover_windows << window
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement