#==============================================================================
# 顯示NPC名
#------------------------------------------------------------------------------
# 跟原版一樣,EV開頭的不顯示,逗號後加顏色代碼
# 修改某事件名的方法:
# set_npc_name("新名", 事件ID, 地圖ID, 是否永久生效)
# 範例 set_npc_name("123",nil,nil,true)
# 事件ID 為空時表示當前事件
# 地圖ID 為空時表示當前地圖
# 是否永久生效 默認永久,否則只允許修改當前地圖
#==============================================================================
# 參數設定
#==============================================================================
module NPC
NAME_FONT = "蒼藍字體"
NAME_SIZE = 24 #NPC名大小
NAME_SHADOW = true
NAME_WIDTH = 200
end
#==============================================================================
# 重定事件名
#==============================================================================
def set_npc_name(name, event_id = nil, map_id = nil, forever = true)
# 處理事件 ID
if event_id == nil
event_id = $game_map.interpreter.event_id
end
# 處理地圖 ID
if map_id == nil
$game_map.events[event_id].name = name
map_id = $game_map.map_id
else
map_id = map_id
end
return unless forever
data = load_data(sprintf("Data/Map%03d.rvdata", map_id))
# 更改名
data.events[event_id].name = name
save_data(data, sprintf("Data/Map%03d.rvdata", map_id))
end
#==============================================================================
# ■ Game_Character
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
# ◎ 定義實例變量
#--------------------------------------------------------------------------
attr_accessor :name # 名稱
#--------------------------------------------------------------------------
# ◎ 初始化對象
#--------------------------------------------------------------------------
alias character_ini initialize
def initialize
character_ini
@name = ""
end
end
#==============================================================================
# ■ Game_Event
#==============================================================================
class Game_Event < Game_Character
#--------------------------------------------------------------------------
# ◎ 定義實例變量
#--------------------------------------------------------------------------
attr_reader :erased
#--------------------------------------------------------------------------
# ◎ 初始化對像
# map_id : 地圖 ID
# event : 事件 (RPG::Event)
#--------------------------------------------------------------------------
alias event_ini initialize
def initialize(map_id, event)
event_ini(map_id, event)
@name = @event.name
end
end
#==============================================================================
# ■ Game_Player
#==============================================================================
#~ class Game_Player < Game_Character
#--------------------------------------------------------------------------
# ◎ 顯示主角名字
#--------------------------------------------------------------------------
#~ def name
#~ return $game_party.members[0].name
#~ end
#~ end
#==============================================================================
# ■ Game_Interpreter
#==============================================================================
class Game_Interpreter
#--------------------------------------------------------------------------
# ◎ 定義實例變量
#--------------------------------------------------------------------------
attr_reader :event_id
end
#==============================================================================
# ■ Sprite_Character
#==============================================================================
class Sprite_Character < Sprite_Base
#--------------------------------------------------------------------------
# ◎ 初始化對象
# viewport : 視區
# character : 角色 (Game_Character)
#--------------------------------------------------------------------------
def initialize(viewport, character = nil)
super(viewport)
@character = character
@balloon_duration = 0
## 名稱
@name = @character.name
set_name_sprite
update
end
#--------------------------------------------------------------------------
# ◎ 釋放
#--------------------------------------------------------------------------
def dispose
dispose_balloon
super
##
return if @name_sprite == nil
@name_sprite.bitmap.dispose
@name_sprite.dispose
end
#--------------------------------------------------------------------------
# ● 更新畫面
#--------------------------------------------------------------------------
def update
super
update_bitmap
self.visible = (not @character.transparent)
update_src_rect
self.x = @character.screen_x
self.y = @character.screen_y
self.z = @character.screen_z
self.opacity = @character.opacity
self.blend_type = @character.blend_type
self.bush_depth = @character.bush_depth
update_balloon
if @character.animation_id != 0
animation = $data_animations[@character.animation_id]
start_animation(animation)
@character.animation_id = 0
end
if @character.balloon_id != 0
@balloon_id = @character.balloon_id
start_balloon
@character.balloon_id = 0
end
## 名稱可視和跟隨
unless @name_sprite == nil or @name_sprite.disposed?
if @character.is_a?(Game_Event) and @character.erased
@name_sprite.visible = false
return
else
@name_sprite.visible = true
end
if @character.is_a?(Game_Player) and @character.in_vehicle?
@name_sprite.visible = false
return
else
@name_sprite.visible = true
end
if @name != @character.name
@name = @character.name
refresh_name_sprite
end
#████████████████████████████████████████████████████████████████████████
#████████████████████████████████████████████████████████████████████████
@name_sprite.x = self.x - 250 #原版
@name_sprite.y = self.y - self.height - NPC::NAME_SIZE+2
#~ @name_sprite.x = (self.x - 250) * 2 - 80 #放大兩倍
#~ @name_sprite.y = (self.y - self.height - NPC::NAME_SIZE+2) * 2 - 250 #放大兩倍
#████████████████████████████████████████████████████████████████████████
#████████████████████████████████████████████████████████████████████████
#~ @name_sprite.z = self.z+1
@name_sprite.z = self.z-60 #優先度++++++
end
end
#--------------------------------------------------------------------------
# ○ 設定 NPC 名稱
#--------------------------------------------------------------------------
def set_name_sprite
return if @character.name[0, 2] == "EV"
return if @character.name == ""
return if @character.character_name == ""
return if @character.is_a?(Game_Event) and @character.erased
@color_board = Window_Base.new(0,0,33,33)
@color_board.visible = false
@name_sprite = Sprite.new
@name_sprite.bitmap = Bitmap.new(NPC::NAME_WIDTH, NPC::NAME_SIZE+2)
@name_sprite.bitmap.font.name = NPC::NAME_FONT
@name_sprite.bitmap.font.size = NPC::NAME_SIZE
@name_sprite.bitmap.font.shadow = NPC::NAME_SHADOW
refresh_name_sprite
end
#--------------------------------------------------------------------------
# ○ 更新 NPC 名稱
#--------------------------------------------------------------------------
def refresh_name_sprite
name,color_index = @name.split(/,/)
color_index = 0 if color_index == ""
@name_sprite.bitmap.font.color = @color_board.text_color(color_index.to_i) #原有
#██████████████████████████████████████████████████████████████████████████
#~ @name_sprite.bitmap.font.color = Color.new(0,200,150) #NPC名稱顏色
@name_sprite.bitmap.clear
@name_sprite.bitmap.draw_text(0,0,200,NPC::NAME_SIZE+2,name,1)#置中對齊
#██████████████████████████████████████████████████████████████████████████
end
end