#==============================================================================
# 悬停提示
# Version: 1.0.3
# Author: modern algebra (rmrk.net)
# Date: 4 November 2012
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Description:
#
# This script lets you display a graphic which hovers above any given event,
# player or follower. The primary virtue of the script is that it allows for
# a feature like in Diablo(暗黑破坏神), where characters that have something important to
# say have an exclamation(感叹) point or something above their heads. However, it
# is not limited to that: this script can show any picture, icon, text, or
# combination of icon & text above any character. (本脚本可以显示图片、图标
# 文字或者图标与文字混合)
#
# A secondary (and completely optional) feature is that you can set it up so
# that whenever gold, items, weapons, or armours are received through their
# respective event commands, a hover alert will float above the player's head
# with the icon, name, and amount of the item received before fading out.
# (可以在角色获得物品时于角色头顶显示 图标、物品名和数量)
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Instructions:
#
# Paste this script into its own slot in the Script Editor, above Main but
# below Materials.(将此脚本放到main上、素材下)
#
# I decided to try something new with this script, so this script operates
# through event comment commands. When the comment is the very first comment
# on an event's page, then the hover graphic set through that comment will
# automatically be generated as soon as that event page's conditions are met.
# If it is not, then it will only be run when that event is active and the
# Interpreter reaches it.
#
# The basic format for setting a hover graphic above the event in which the
# comment occurs is as follows, with any of the options between the curly
# brackets omitted if you are satisfied with the default setting:
# 使用注释: (下面是默认的格式)
# \hover_alert { name = ""; icon = 0; icon_hue = 0; time = -1;
# fontname = "Default"; fontsize = 20; colour = 0; bold = false;
# italic = false; effect = :none; effect_param = nil; se = nil;
# proximity = 0 }
#
# When setting any of the options, make sure it is concluded with either a
# semicolon or simply a new line. Each of the options is explained below, but
# I reiterate that you can exclude almost any of them if you are satisfied
# with the default value listed above:
#
# name - 设定显示的图片或文字, 如果在picture文件夹里有“name”文件,
# 图片会被显示. 否则将会显示“name”的文字。(你也可以空着,啥也不写)
#
# icon - 设定显示图标的index ID,将会显示在任何文字的左边
# 在“name”有同名图片文件时,图标不会显示
# 在“name”仅为文字或者是空白时,图标会显示
#
# icon_hue - 用来设定图标的色调,当然是在“icon”不为0的情况下。
#
# time - 设定悬停提示显示的时间(单位为帧,1秒=60帧)
#
# fontname - 设定显示文字的字体.
#
# fontsize - 设定显示文字的大小.
#
# colour - 设定显示文字的颜色. 它可以是“window”文件右下角调色盘的整数ID
# 或者是 an array of integers corresponding to [red, green, blue, alpha] (?)
#
# bold - 设定显示文字是否加粗。(加粗设为 “true”,不加粗设为“false”)
#
#
# italic - 设定显示文字是否为斜体。(斜体设为 “true”,不是斜体设为“false”)
#
# effect - 这是效果设定的标志
# 有三种显示提示的效果:
# :bounce - 悬停提示会弹跳一下;
# :fade_bounce - 悬停提示会淡入淡出
# :flash - 悬停提示会闪烁.
#
# 还有四种关闭提示的效果:
# :fade - 悬停提示会显示大概半秒,然后淡出;
# :rise_and_fade - 和“fade”差不多, 只是在消失前会微小上升;
# :disintegrate - 悬停提示会显示大概半秒,然后像素随机消除半秒;
# :rise_and_disintegrate - 和“disintegrate”差不多, 只是在消失前会微小上升;This will do the same as :disintegrate,
#
# effect_param - 设定闪烁的色调,只有你设定flash效果才有用(76行) ,可以设定为“window”
# 文件右下角调色盘的 ID 或者一个[r,g,b,a] 来更改闪烁的色调
#
# se - 设定悬停标志出现时播放的音效SE,(不设置也行).
# 必须为 ["文件名", 音量, 音调] 的格式
#
# proximity - 设定感应距离。角色在事件某一范围内才会显示悬停提示。Set this to any integer, and the hover graphic will only
# be visible if the player is within that many squares of the
# character over which the hover graphic is intended to appear.
#
# For any given hover alert, you only need to have either name or icon set
# directly. If you don't set those, then it will simply remove any existing
# hover graphic. If you exclude any other value, then I reiterate that it
# will just be set to the default value identified in the sample itself.
# You can set the default values for fontname, fontsize, colour, bold, italic
# and effect in the editable region starting at line 158.
#
# Now, the above code will only set a hover graphic on the event in which
# the comment appears. For auto-hover alerts in comments at the top of the
# page, you can only set it to that event, but for the interpreted comments
# that appear anywhere else you can set the hover graphic above a different
# event by adding the ID of the event in square brackets after \hover_alert,
# like so:
#
# \hover_alert[0] { ... }
#
# Now, if you set it to -1, then it will show above the player. If you set it
# to 0, it will show above the event in which the comment is. If you set it
# to any integer > 0, it will show above the event with that ID. If you want
# to set it above a follower, then you need to put an f before the ID, like
# so:
#
# \hover_alert[f1] { ... }
#
# where 1 is the first follower after the player, 2 is the second, etc. You
# can also set a hover alert above a vehicle by placing a v instead of an f:
#
# \hover_alert[v0] { ... }
#
# 0 is the boat, 1 is the ship, and 2 is the airship.
#
# Finally, I mention again that you can remove a hover alert graphic simply
# by not setting the name or icon within the {}. In other words, the
# following code would delete any hover graphic over Event 4:
#
# \hover_alert[4] { }
#``````````````````````````````````````````````````````````````````````````````
# Autogain Hover Alerts
#
# The autogain feature allows you to make it so that when gold and items are
# gained, a hover alert is created above the player showing what is received.
#
# If you want to use this feature, the value of AUTOGAIN_HOVERALERTS_SWITCH
# at line 182 must be set to a value greater than 0, and then the autogain
# alerts will only occur when the in-game switch with that ID is ON. You can
# also set a number of other autogain features starting at line 185. I
# direct you there for instructions about what each does.
#==============================================================================
$imported = {} unless $imported
$imported[:MA_HoverAlerts] = true
#==============================================================================
# *** MA_HoverAlert
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# This module holds configuration and data for the Hover Alerts script
#==============================================================================
module MA_HoverAlert
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
# * BEGIN Editable Region
#||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Text Option Defaults
#``````````````````````````````````````````````````````````````````````````
# These options mostly just change the way text is drawn by default, and
# are all subject to be overridden in any hover alert.
FONTNAME = Font.default_name # The font used when drawing text
FONTSIZE = Font.default_size # The size of text when drawing text
COLOUR = [255, 255, 255] # The default colour of text when drawing text.
# It can be either an [r, g, b, a] array or it
# can be an integer for the windowskin palette.
BOLD = Font.default_bold # Whether text is bolded. It can be set to
# either true or false
ITALIC = Font.default_italic # Whether text is italicized. It can be set to
# either true or false
EFFECT = :none # Default effect for regular hover alerts. It
# can be set to either :none, :bounce, :flash,
# :fade_bounce, or :rise_and_fade.
ANIMATE_FRAMES = 24 # If using an animated picture named with a
# %[x], then the number of frames to wait on
# each frame. There are 60 frames in 1 second.
#||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Autogain Options
#``````````````````````````````````````````````````````````````````````````
# These options affect the autogain feature, and none affect any other
# hover alert except those created when gaining items.
AUTOGAIN_HOVERALERTS_SWITCH = 19 # The ID of the switch used to turn the
# autogain feature on and off. If you never
# want to use it, set this to 0.
AUTOGAIN_GOLD_ICON = 262 # The icon for gold when autogaining
AUTOGAIN_NAME_FORMAT = "%s" # The format for the name of the item. The
# %s will be replaced with the item's name
# when autogaining.
AUTOGAIN_NUM_FORMAT = " %+d" # The format for the amount gained. The %+d
# is replaced by the number of items or gold
# gained.
AUTOGAIN_GAIN_SE = ["Chime2"] # The SE played when gaining items.
AUTOGAIN_LOSE_SE = ["Chime1"] # The SE played when losing items.
AUTOGAIN_EFFECT = :rise_and_fade# Effect when autogaining. It can be
# either :fade, :rise_and_fade, :disintegrate,
# or :rise_and_disintegrate.
#||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# * END Editable Region
#//////////////////////////////////////////////////////////////////////////
AUTOGAIN_GAIN_SE = RPG::SE.new(*AUTOGAIN_GAIN_SE) if AUTOGAIN_GAIN_SE.is_a?(Array)
AUTOGAIN_LOSE_SE = RPG::SE.new(*AUTOGAIN_LOSE_SE) if AUTOGAIN_LOSE_SE.is_a?(Array)
#==========================================================================
# ** HoverAlert
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# This class holds hoveralert data
#==========================================================================
class HoverAlert < Struct.new(:name, :icon_index, :icon_hue, :effect,
:effect_param, :se, :proximity, :fontname, :fontsize, :colour, :bold,
:italic, :time)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Object Initialization
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def initialize(*args)
defaults = MA_HoverAlert.maha_default_values
defaults[0, args.size] = args unless args.empty?
super(*defaults)
end
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Default Values
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def self.maha_default_values
["", 0, 0, MA_HoverAlert::EFFECT, 0, nil, 0, MA_HoverAlert::FONTNAME,
MA_HoverAlert::FONTSIZE, MA_HoverAlert::COLOUR, MA_HoverAlert::BOLD,
MA_HoverAlert::ITALIC, -1]
end
end
#==============================================================================
# ** Game_CharacterBase
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Summary of Changes:
# aliased methods
# new method - show_hover_alert
#==============================================================================
class Game_CharacterBase
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Public Instance Variables
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
attr_reader :hover_alert
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Initialize Private Members
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias maha_initprivmem_1cr0 init_private_members
def init_private_members(*args)
maha_initprivmem_1cr0(*args) # Call original method
clear_hover_alert
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Clear Hover Alert
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def clear_hover_alert
@hover_alert_queue = []
@hover_alert = nil
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Show Hover Alert
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def show_hover_alert(name = "", icon = 0, *args)
if (name.nil? || name.empty?) && (icon.nil? || icon == 0)
@hover_alert = @hover_alert_queue.empty? ? nil : @hover_alert_queue.shift
else
alert = MA_HoverAlert::HoverAlert.new(name, icon, *args)
@hover_alert ? @hover_alert_queue.push(alert) : @hover_alert = alert
end
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Replace Hover Alert
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def replace_hover_alert(*args)
clear_hover_alert
show_hover_alert(*args)
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Setup Hover Alert by Comment
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def interpret_hover_alert_comment(text)
if text[/\\HOVER_ALERT\[?.*?\]?\s*\{(.*?)\}/im]
name, icon, icon_hue, effect, effect_param, se, proximity, fontname,
fontsize, colour, bold, italic, time = *MA_HoverAlert.maha_default_values
color = nil # Initialize alternate spelling of color
eval($1)
colour = color if color
se = RPG::SE.new(*se) if se.is_a?(Array)
replace_hover_alert(name, icon, icon_hue, effect, effect_param, se,
proximity, fontname, fontsize, colour, bold, italic, time)
end
end
end
#==============================================================================
# ** Game_Event
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Summary of Changes:
# aliased methods - setup_page_settings; clear_page_settings
# new method - ma_collect_first_comment
#==============================================================================
class Game_Event
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Setup Page Settings
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias ma_stuppgsets_7sj5 setup_page_settings
def setup_page_settings(*args)
ma_stuppgsets_7sj5(*args) # Call original method
clear_hover_alert
interpret_hover_alert_comment(ma_collect_init_comment)
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Clear Page Settings
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias ma_clrpgsettings_5na5 clear_page_settings
def clear_page_settings(*args)
ma_clrpgsettings_5na5(*args) # Call original method
clear_hover_alert
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Collect First Comment
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def ma_collect_init_comment
comment, i = "", 0
while !@list[i].nil? && (@list[i].code == 108 || @list[i].code == 408)
comment += @list[i].parameters[0] + "\n"
i += 1
end
comment
end unless self.method_defined?(:ma_collect_init_comment)
end
#==============================================================================
# ** Game_Party
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Summary of Changes:
# new method - maha_item_number_plus_equips
#==============================================================================
class Game_Party
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Item Number and Equips
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def maha_item_number_plus_equips(item)
equip_num = 0
members.each { |actor| equip_num += actor.equips.count(item) }
item_number(item) + equip_num
end
end
#==============================================================================
# ** Game_Interpreter
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Summary of Changes:
# aliased method - command_108
#==============================================================================
class Game_Interpreter
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Command 108
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias maha_cmmndcomment_6cz9 command_108
def command_108(*args)
initial = (@index == 0)
maha_cmmndcomment_6cz9(*args) # Call original method
maha_interpret_hover_comment(@comments.join("\n")) unless initial
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Setup Hover Alert Comment
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def maha_interpret_hover_comment(text)
text2 = text.dup
loop do # Get evert hover alert code in the comment
match = text2.slice!(/\\HOVER[ _]ALERT\[?\s*([VF]?)(-?\d*)\s*\]?\s*\{.*?\}/im)
break if match.nil?
case $1.upcase
when '' # Empty
character = get_character($2.to_i)
when 'F' # Follower
character = $2.to_i == 0 ? $game_player : $game_player.followers[$2.to_i - 1]
return if !character || !character.visible?
when 'V' # Vehicle
character = $game_map.vehicles[$2.to_i]
return if !character || !character.transparent
end
character.interpret_hover_alert_comment(match) if character.is_a?(Game_CharacterBase)
end
end
if MA_HoverAlert::AUTOGAIN_HOVERALERTS_SWITCH >= 0
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Gain Gold
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias maha_command125_5fx9 command_125
def command_125(*args, &block)
old_value = $game_party.gold
maha_command125_5fx9(*args, &block) # Call Original Method
# Add to receipt if the possessed amount of gold has changed
if $game_party.gold != old_value && (MA_HoverAlert::AUTOGAIN_HOVERALERTS_SWITCH == 0 ||
$game_switches[MA_HoverAlert::AUTOGAIN_HOVERALERTS_SWITCH])
text = sprintf(MA_HoverAlert::AUTOGAIN_NUM_FORMAT, $game_party.gold - old_value)
se = $game_party.gold > old_value ? MA_HoverAlert::AUTOGAIN_GAIN_SE : MA_HoverAlert::AUTOGAIN_LOSE_SE
$game_player.show_hover_alert(text, MA_HoverAlert::AUTOGAIN_GOLD_ICON,
0, MA_HoverAlert::AUTOGAIN_EFFECT, 0, se)
end
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Gain Item
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias maha_comnd126_2vv9 command_126
def command_126(*args)
item = $data_items[@params[0]]
old_val = $game_party.maha_item_number_plus_equips(item)
maha_comnd126_2vv9(*args) # Call original method
autogain_item_hover_alert(item, $game_party.maha_item_number_plus_equips(item) - old_val)
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Gain Weapon
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias maha_commn127_3ar4 command_127
def command_127(*args)
item = $data_weapons[@params[0]]
old_val = $game_party.maha_item_number_plus_equips(item)
maha_commn127_3ar4(*args) # Call original method
autogain_item_hover_alert(item, $game_party.maha_item_number_plus_equips(item) - old_val)
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Gain Armor
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias maha_cnd128_1sp6 command_128
def command_128(*args)
item = $data_armors[@params[0]]
old_val = $game_party.maha_item_number_plus_equips(item)
maha_cnd128_1sp6(*args) # Call original method
autogain_item_hover_alert(item, $game_party.maha_item_number_plus_equips(item) - old_val)
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Autogain Hover Alert
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def autogain_item_hover_alert(item, n)
return if n == 0 || !(MA_HoverAlert::AUTOGAIN_HOVERALERTS_SWITCH == 0 ||
$game_switches[MA_HoverAlert::AUTOGAIN_HOVERALERTS_SWITCH])
text = sprintf(MA_HoverAlert::AUTOGAIN_NAME_FORMAT, item.name) +
sprintf(MA_HoverAlert::AUTOGAIN_NUM_FORMAT, n)
se = n > 0 ? MA_HoverAlert::AUTOGAIN_GAIN_SE : MA_HoverAlert::AUTOGAIN_LOSE_SE
icon_hue = $imported[:MAIcon_Hue] ? item.icon_hue : 0
$game_player.show_hover_alert(text, item.icon_index, icon_hue,
MA_HoverAlert::AUTOGAIN_EFFECT, 0, se)
end
end
end
#==============================================================================
# ** Sprite_HoverAlert
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# This class handles showing the hover sprite.
#==============================================================================
class Sprite_HoverAlert < Sprite_Base
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Object Initialization
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def initialize(viewport, character)
# Initialize variables
@char_x, @char_y = 0, 0
@effect_x, @effect_y = 0, 0
@effect, @effect_param, @effect_time = :none, 0, -1
@ap_time, @ap_max_time, @ap_width, @ap_frame_index, @ap_frame_num = -1, 0, 0, 0, 0
@time = 0
@disintegrate_array = []
super(viewport)
self.z = 200
@character = character
refresh
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Free
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def dispose(*args)
bitmap.dispose if bitmap && !bitmap.disposed?
super(*args)
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Update
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def update
super
refresh if @hover_alert != @character.hover_alert # if hover alert changed
if bitmap
if @hover_alert.proximity > 0
x = @character.distance_x_from($game_player.x).abs
y = @character.distance_y_from($game_player.y).abs
self.visible = Math.hypot(x, y) <= @hover_alert.proximity
end
if self.visible
maha_update_se # Update Sound Effect
maha_update_frame_animation # Update animation
maha_update_effect # Update the effect being played
# Adust position
self.x = @char_x + @effect_x
self.y = @char_y + @effect_y
end
if @hover_alert && @hover_alert.time > 0
if @time == @hover_alert.time
@character.show_hover_alert("", 0) # End Hover Alert
refresh
end
@time += 1
end
end
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Update SE
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def maha_update_se
if @hover_alert.se && !@se_played
@hover_alert.se.play
@se_played = true
end
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Update Frame Animation
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def maha_update_frame_animation
if @ap_time == 0 # If timer finished
# Switch frames
@ap_frame_index = (@ap_frame_index + 1) % @ap_frame_num
@ap_time = @ap_max_time
self.src_rect.x = @ap_frame_index*@ap_width
end
@ap_time -= 1 if @ap_time > 0 # Decrease timer until finished
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Adjust Character Position
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def adjust_character_position(x, y); @char_x, @char_y = x, y; end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Refresh
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def refresh
@se_played = false
@hover_alert = @character.hover_alert
bitmap.dispose if bitmap && !bitmap.disposed?
return unless @hover_alert
(!@hover_alert.name.empty? ? maha_draw_picture : maha_draw_text) rescue maha_draw_text
self.ox = @ap_width / 2
self.oy = bitmap.height
self.visible = true
maha_start_effect
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Reset Font Settings
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def maha_reset_font_settings
bitmap.font = Font.new(@hover_alert.fontname, @hover_alert.fontsize)
bitmap.font.bold = @hover_alert.bold
bitmap.font.italic = @hover_alert.italic
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Text Colour
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def text_color(n)
colour = case n
when Integer
# Extended Colour Palette compatibility
if $imported[:MA_ExtendedColourPalette] && n >= 32
n -= 32
Cache.system("Palette").get_pixel((n % 8) * 8, (n / 8) * 8)
else
Cache.system("Window").get_pixel(64 + (n % 8) * 8, 96 + (n / 8) * 8)
end
when Array then Color.new(*n)
else Color.new(255, 255, 255)
end
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Draw Picture
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def maha_draw_picture
# Use picture if it exists
self.bitmap = Cache.picture(@hover_alert.name).dup
@ap_width = bitmap.width
if @hover_alert.name[/%\[(\d+)[\s,;]*(\d*?)\]/] # If animated graphic
# Setup animated picture variables
@ap_frame_num = $1.to_i
@ap_width /= @ap_frame_num
@ap_max_time = $2.empty? ? MA_HoverAlert::ANIMATE_FRAMES : $2.to_i
@ap_frame_index = 0
@ap_time = @ap_max_time
self.src_rect = Rect.new(0, 0, @ap_width, bitmap.height)
else
@ap_time = -1
end
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Draw Text
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def maha_draw_text
# Else draw the word
x = 0
self.bitmap = Bitmap.new(24, 24)
if @hover_alert.name && !@hover_alert.name.empty?
maha_reset_font_settings
# Retrieve actual string
ts = bitmap.text_size(@hover_alert.name)
if @hover_alert.icon_index > 0
x = 28
ts.width += 28
ts.height = 24 if ts.height < 24
end
# Resize
bitmap.dispose
self.bitmap = Bitmap.new(ts.width + 4, ts.height + 4)
maha_reset_font_settings
bitmap.font.color = text_color(@hover_alert.colour)
# Draw text
bitmap.draw_text(x, 0, bitmap.width - x, bitmap.height, @hover_alert.name, 1)
end
# Draw Icon
@hover_alert.icon_hue == 0 ? maha_draw_icon(@hover_alert.icon_index, 0, (height - 24) / 2) :
maha_draw_icon_with_hue(@hover_alert.icon_index, @hover_alert.icon_hue, 0, (height - 24) / 2)
@ap_time = -1
@ap_width = bitmap.width
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Draw Icon
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def maha_draw_icon(icon_index, x, y)
bmp = Cache.system("Iconset")
rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
bitmap.blt(x, y, bmp, rect, 255)
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Draw Icon With Hue
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def maha_draw_icon_with_hue(icon_index, icon_hue, x, y)
bmp = Cache.system("Iconset")
rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
# Draw Icon onto small and independent bitmap
icon_bmp = Bitmap.new(24, 24)
icon_bmp.blt(0, 0, bmp, rect)
icon_bmp.hue_change(icon_hue) # Change hue of icon
rect.x, rect.y = 0, 0
bitmap.blt(x, y, icon_bmp, rect, 255)
icon_bmp.dispose # Dispose Icon Bitmap
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Start HoverAlert Effect
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def maha_start_effect
@effect = @hover_alert.effect
@effect_param = @hover_alert.effect_param
@effect_x, @effect_y = 0, 0
@disintegrate_array.clear
self.opacity = 255
case @effect
when :bounce, :fade_bounce then @effect_time = 32
when :flash
@effect_time = 32
flash(text_color(@effect_param), @effect_time)
when :rise_and_fade
@effect_time = 48
@effect_y = 18
when :fade then @effect_time = 48
when :disintegrate, :rise_and_disintegrate
@effect_y = 24 if @effect == :rise_and_disintegrate
@effect_time = 64
for i in 0...bitmap.width
for j in 0...bitmap.height
@disintegrate_array.push(i, j)
end
end
else
@effect_time = -1
end
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Update HoverAlert Effect
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def maha_update_effect
if @effect_time == 0
case @effect
when :bounce, :flash, :fade_bounce then maha_start_effect # Repeat
else maha_finish_effect # Close
end
elsif @effect_time > 0
case @effect
when :bounce then @effect_y += (@effect_time > 16 ? -0.5 : 0.5)
when :fade_bounce then self.opacity += (@effect_time > 16 ? -8 : 8)
# Temporary Effects
when :fade then self.opacity = 16*@effect_time if @effect_time < 16
when :rise_and_fade
@effect_y -= 0.5
self.opacity = 16*@effect_time if @effect_time < 16
when :disintegrate then maha_update_disintegrate_effect if @effect_time < 32
when :rise_and_disintegrate
@effect_y -= 0.5 if @effect_time > 32
maha_update_disintegrate_effect if @effect_time < 32
end
@effect_time -= 1
end
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Update Disintegrate Effect
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def maha_update_disintegrate_effect
col = Color.new(0, 0, 0, 0)
(bitmap.width*bitmap.height / 32).times do
i = (rand(@disintegrate_array.size / 2)*2)
x, y = *@disintegrate_array[i, 2]
bitmap.set_pixel(x, y, col)
@disintegrate_array.delete_at(i)
@disintegrate_array.delete_at(i + 1)
end
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Finish HoverAlert Effect
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def maha_finish_effect
@effect_x, @effect_y = 0, 0
@effect_time = -1
self.opacity = 255
@disintegrate_array.clear
# Set to next hover alert, if any
@character.show_hover_alert("", 0)
refresh
end
end
#==============================================================================
# ** Sprite_Character
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Summary of Changes:
# aliased methods - update; dispose
# new methods - update_maha_sprite; dispose_maha_sprite
#==============================================================================
class Sprite_Character
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Frame Update
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias maha_update_2hz0 update
def update(*args)
maha_update_2hz0(*args) # Call original method
update_maha_sprite
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Update Hover Alert
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def update_maha_sprite
if !@maha_sprite && @character.hover_alert # Create the HoverAlert sprite
@maha_sprite = Sprite_HoverAlert.new(viewport, @character)
end
if @maha_sprite
if @character.hover_alert.nil?
dispose_maha_sprite
else
# Pass position of sprite to the hover alert's sprite
@maha_sprite.adjust_character_position(self.x, self.y - self.oy)
@maha_sprite.update
end
end
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Dispose
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias maha_dispose_4cm6 dispose
def dispose(*args)
dispose_maha_sprite
maha_dispose_4cm6(*args) # Call original method
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Dispose Hover Alert Sprite
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def dispose_maha_sprite
@maha_sprite.dispose if @maha_sprite && !@maha_sprite.disposed?
@maha_sprite = nil
end
end