#==============================================================================
# 〓 地图显示变量 〓 Author:芯☆淡茹水
#==============================================================================
=begin
#==============================================================================
◆ 说明 ◆
#==============================================================================
#------------------------------------------------------------------------------
1,变量的命名
变量命名格式为 => 变量名^图标序号
未写 图标序号 的变量,不会显示图标。
#------------------------------------------------------------------------------
2,游戏中添加变量显示 => 事件-脚本:show_map_val(id, x, y, w, s, c1, c2)
id :变量ID
x :变量窗口显示的X坐标
y :变量窗口显示的Y坐标
w :变量窗口宽(可省略,省略后为设置的默认值)
s :字体大小(可省略,省略后为设置的默认值)
c1 :变量名文字色号(可省略,省略后为设置的默认值)
c2 :变量值文字色号(可省略,省略后为设置的默认值)
※ 如果对应的变量已经在显示中,此条命令无效 ※
※ 地图上显示的变量个数无限制,理论上可显示无数个变量 ※
#------------------------------------------------------------------------------
3,游戏中删除变量显示 => 事件-脚本:delete_map_val(id)
id :变量ID
※ 如果对应的变量未在显示中,此条命令无效 ※
#------------------------------------------------------------------------------
4,移动变量窗口 => 事件-脚本:move_val_window(id, direction, duration, speed)
id :变量ID
direction :移动的方向(2:下;4:左;6:右;8:上)
duration :移动时持续的帧数
speed :移动时每一帧移动的像素值
※ 如果对应的变量未在显示中或变量窗口正在移动中,此条命令无效 ※
#------------------------------------------------------------------------------
=end
#==============================================================================
module XdRs_Show_Val_Set
#==============================================================================
# ◆ 设置 ◆
#==============================================================================
#--------------------------------------------------------------------------
# 窗口边宽
Standard_padding = 8
#--------------------------------------------------------------------------
# 窗口不透明度
Opacity = 255
#--------------------------------------------------------------------------
# 默认窗口宽度
Default_window_width = 180
#--------------------------------------------------------------------------
# 默认窗口字体大小
Default_font_size = 20
#--------------------------------------------------------------------------
# 默认变量名字体颜色号
Default_val_name_color = 0
#--------------------------------------------------------------------------
# 默认变量值字体颜色号
Default_val_num_color = 0
#--------------------------------------------------------------------------
# 初始显示的变量。
# 格式:变量ID => [X坐标, Y坐标, 窗口宽, 字体大小, 变量名色号, 变量值色号]
# 其中 窗口宽, 字体大小, 变量名色号, 变量值色号 可省略, 省略后为默认值。
Initial_vals = {
11 => [0, 0],
12 => [10, 40],
13 => [20, 80, 240, 18, 3, 2]
}
end
#==============================================================================
class XdRs_Val_Data
#--------------------------------------------------------------------------
attr_reader :id, :x, :y
attr_reader :font_size
attr_reader :window_width
attr_reader :window_height
attr_reader :name_color
attr_reader :num_color
#--------------------------------------------------------------------------
def initialize(id, x, y, w=nil, s=nil, c1=nil, c2=nil)
@id = id
@x = x || 0
@y = y || 0
@font_size = s || XdRs_Show_Val_Set::Default_font_size
@window_width = w || XdRs_Show_Val_Set::Default_window_width
@window_height = XdRs_Show_Val_Set::Standard_padding * 2 + [@font_size, 24].max
@name_color = c1 || XdRs_Show_Val_Set::Default_val_name_color
@num_color = c2 || XdRs_Show_Val_Set::Default_val_num_color
clear_move_data
end
#--------------------------------------------------------------------------
def clear_move_data
@speed = 0
@move_direction = 0
@move_duration = 0
end
#--------------------------------------------------------------------------
def name
text = $data_system.variables[@id]
return text.split(/\^/)[0] || ""
end
#--------------------------------------------------------------------------
def icon_index
text = $data_system.variables[@id]
return (text.split(/\^/)[1] || "0").to_i
end
#--------------------------------------------------------------------------
def start_move(direction, duration, speed)
return if is_moving?
@move_direction = direction
@move_duration = duration
@speed = speed
end
#--------------------------------------------------------------------------
def is_moving?
return false if ![2,4,6,8].include?(@move_direction)
return @speed > 0 && @move_duration > 0
end
#--------------------------------------------------------------------------
def update_move
return if @move_duration == 0
@move_duration -= 1
is_moving? && apply_move
@move_duration == 0 && clear_move_data
end
#--------------------------------------------------------------------------
def apply_move
@x += @move_direction == 6 ? @speed : (@move_direction == 4 ? -@speed : 0)
@y += @move_direction == 2 ? @speed : (@move_direction == 8 ? -@speed : 0)
end
end
#==============================================================================
class Game_System
#--------------------------------------------------------------------------
attr_accessor :additive_val, :deleted_val
#--------------------------------------------------------------------------
alias xr_show_val_initialize initialize
def initialize
xr_show_val_initialize
setup_initial_vals
end
#--------------------------------------------------------------------------
def setup_initial_vals
@xr_map_vals = []
vals = XdRs_Show_Val_Set::Initial_vals
vals.keys.each do |id|
data = vals[id]
show_map_val(id,data[0],data[1],data[2],data[3],data[4],data[5])
end
@additive_val = nil
end
#--------------------------------------------------------------------------
def map_vals
return @xr_map_vals.map{|d| d.id }
end
#--------------------------------------------------------------------------
def get_map_val_data(id)
return @xr_map_vals.find{|d| d.id == id }
end
#--------------------------------------------------------------------------
def has_map_val(id)
return @xr_map_vals.any?{|d| d.id == id}
end
#--------------------------------------------------------------------------
def show_map_val(id, x, y, w=nil, s=nil, c1=nil, c2=nil)
return if has_map_val(id) || id == 0
@xr_map_vals.push(XdRs_Val_Data.new(id,x,y,w,s,c1,c2))
@additive_val = id
end
#--------------------------------------------------------------------------
def delete_map_val(id)
return if !has_map_val(id)
@xr_map_vals.delete(get_map_val_data(id))
@deleted_val = id
end
#--------------------------------------------------------------------------
def move_map_val_window(id, drc, drt, speed)
has_map_val(id) && get_map_val_data(id).start_move(drc, drt, speed)
end
end
#==============================================================================
class Game_Interpreter
#--------------------------------------------------------------------------
def show_map_val(id, x, y, w=nil, s=nil, c1=nil, c2=nil)
$game_system.show_map_val(id, x, y, w, s, c1, c2)
end
#--------------------------------------------------------------------------
def delete_map_val(id)
$game_system.delete_map_val(id)
end
#--------------------------------------------------------------------------
def move_val_window(id, direction, duration, speed)
$game_system.move_map_val_window(id, direction, duration, speed)
end
end
#==============================================================================
class Window_Map_Val < Window_Base
#--------------------------------------------------------------------------
def initialize(data)
@data = data
super(@data.x, @data.y, @data.window_width, @data.window_height)
self.opacity = XdRs_Show_Val_Set::Opacity
self.z = 9999
refresh
end
#--------------------------------------------------------------------------
def line_height
return [@data.font_size, 24].max
end
#--------------------------------------------------------------------------
def standard_padding
return XdRs_Show_Val_Set::Standard_padding
end
#--------------------------------------------------------------------------
def refresh
contents.clear
contents.font.size = @data.font_size
@last_num = $game_variables[@data.id]
draw_val_name(draw_val_icon(0))
draw_val_num
end
#--------------------------------------------------------------------------
def draw_val_icon(x)
return x if @data.icon_index == 0
y = (line_height - 24) / 2
draw_icon(@data.icon_index, x, y)
return x + 28
end
#--------------------------------------------------------------------------
def draw_val_name(x)
change_color(text_color(@data.name_color))
tw = text_size(@data.name).width + 4
y = (line_height - @data.font_size) / 2
draw_text(x, y, tw, @data.font_size, @data.name)
end
#--------------------------------------------------------------------------
def draw_val_num
change_color(text_color(@data.num_color))
y = (line_height - @data.font_size) / 2
draw_text(0, y, contents_width, @data.font_size, @last_num.to_s, 2)
end
#--------------------------------------------------------------------------
def is_val_changed?
return @last_num != $game_variables[@data.id]
end
#--------------------------------------------------------------------------
def update
super
@data.update_move
update_state
update_location
end
#--------------------------------------------------------------------------
def update_state
is_val_changed? && refresh
end
#--------------------------------------------------------------------------
def update_location
self.x = @data.x
self.y = @data.y
end
end
#==============================================================================
class Scene_Map
#--------------------------------------------------------------------------
def create_xr_val_window(id)
$game_system.additive_val = nil
window_name = "@xr_val_window#{id}"
data = $game_system.get_map_val_data(id)
window = instance_variable_get(window_name)
return if !!window && !window.disposed? || !data
instance_variable_set(window_name, Window_Map_Val.new(data))
end
#--------------------------------------------------------------------------
def dispose_xr_val_window(id)
$game_system.deleted_val = nil
window_name = "@xr_val_window#{id}"
return if !instance_variable_get(window_name)
instance_variable_get(window_name).dispose
instance_variable_set(window_name, nil)
end
#--------------------------------------------------------------------------
alias xr_map_val_create_all_windows create_all_windows
def create_all_windows
xr_map_val_create_all_windows
$game_system.map_vals.each{|id| create_xr_val_window(id) }
end
#--------------------------------------------------------------------------
alias xr_map_val_update update
def update
xr_map_val_update
update_xr_map_val
end
#--------------------------------------------------------------------------
def update_xr_map_val
$game_system.additive_val && create_xr_val_window($game_system.additive_val)
$game_system.deleted_val && dispose_xr_val_window($game_system.deleted_val)
end
end
#==============================================================================