Код:
#sb:nap_ev_text [field]
=begin
#===============================================================================
Napoleons Event Text
Версия 1.03ru
Автор - Napoleon
Перевел strelokhalfer для rpg-maker.info
Описание:
- Отображает текст над событием
Инструкции:
- Расположите ниже "▼ Дополнения" или "▼ Материалы", но выше Main.
- Если у вас стоит скрипт от Khas "Character Render", расположите ниже его.
- В комментарии к событию напишите: <evtxt:Ваш текст>
- или вызовите скрипт(переводчик советует этот вариант):
- nap_ev_text(ev_id, text) # ev_id = номер события.
- nap_ev_erase_text(ev_id) - удалить текст над событием.
- ВНИМАНИЕ: НЕ РАБОТАЕТ НА ИГРОКЕ (event id == 0)
- пример настройки текста, через вызов скрипта (все настройки необязательны):
nap_ev_conf(1, {
:name => 'Arial',
:size => 20,
:bold => false,
:italic => false,
:outline => true,
:shadow => false,
:fg_color => Color.new(255, 0, 0, 0),
:out_color => Color.new(0, 255, 0, 0),
:bg_color => Color.new(128, 128, 128, 128),
})
- ВНИМАНИЕ: Не используйте в параллельном процессе. Используйте вместо
этого Автоматический запуск(или от нажатия), иначе
получите 'nil error message'.
- Другие примеры настроек чере комментарии.
<evtxt_font_name:'Verdana'> - Шрифт
<evtxt_font_size:40> - Размер шрифта
<evtxt_font_bold:true> - Полужиронсть
<evtxt_font_italic:false> - Курсив
<evtxt_font_outline:true> - Окаемка шрифта
<evtxt_font_shadow:false> - Тень
<evtxt_fg_color:128, 128, 128, 128> - цвет переднего фона
<evtxt_bg_color:128, 128, 128, 128> - цвет заднего фона
<evtxt_out_color:128, 128, 128, 128> - цвет окаемки
# ВНИМАНИЕ! Эти настройки нужно вызывать ДО установки текста через комментарий.
Так же, вы можете создать шаблон и вызвать его через <evtxt_preset:имя_шаблона>
Шаблон так же нужно вызывать до установки текста.
Требуется:
- RPG Maker VX Ace, внезапно, правда?
Условия использования:
- Attribution 3.0 Unported (CC BY 3.0)
http://creativecommons.org/licenses/by/3.0/
Что означает: вы можете использовать как в коммерческих,
так и бесплатных проектах, менять скрипт и адаптировать,
но вы обязаны упомянуть автора(Napoleon Dutch) в Благодарностях
История версий:
1.03ru (06 Февраля 2015)
- Русификация
1.03 (8 Июня 2014)
- Добавлена совместимость к освещению от Khas.
- анную правку помогал делать сам Khas.
- Удалены отладочные сообщения
1.02 (18 Мая 2014)
- Добавлены шаблоны.
1.01 (16 Января 2014)
- Добалены настройки Z-индекса.
1.00 (02 Января 2014)
- Первый релиз.
#===============================================================================
=end
$imported ||= {}
$imported[:nap_ev_text] = 1.03
#===============================================================================
# Секция настроек
#===============================================================================
module NAP_EV_TEXT_CONF
Z_INDEX = 99 # Напишите nil для использования
# Z-индекса из Sprite_Character.
# Внимание: Window_Base имеет Z-индекс = 100.
COMMENT_TAG = 'evtxt' # Не используйте '<' или '>'!
#Переводчик не рекомендует менять параметр выше.
DEFAULT_FONT_NAME = 'Arial' #Шрифт
DEFAULT_FONT_SIZE = 20 #Размер
DEFAULT_FONT_BOLD = true #Полужирность
DEFAULT_FONT_ITALIC = false #Курсив
DEFAULT_FONT_OUTLINE = false #Окаемка
DEFAULT_FONT_SHADOW = true #Тень
DEFAULT_FG_COLOR = Color.new(255, 255, 255, 255)#Стандартный передний фон.
DEFAULT_BG_COLOR = Color.new(0, 0, 0, 0) # Color.new(128,128,128,128) # для прозрачно-серого фона
DEFAULT_OUT_COLOR = Color.new(128, 0, 128, 255) #Цвет окаёмки
#ШАБЛОНЫ
PRESETS = {
:Sample => { # Все параметры необязательны.
:name => 'Times New Roman',
:size => 20,
:bold => false,
:outline => true,
:shadow => true,
:fg_color => Color.new(255, 255, 255, 255),
:bg_color => Color.new(0, 0, 0, 0),
:out_color => Color.new(64, 30, 96, 160)
},
:Sample2 => {
:name => 'Arial',
:size => 24,
:bold => true,
:outline => true,
:shadow => true,
:fg_color => Color.new(190, 255, 128, 255),
:bg_color => Color.new(0, 0, 0, 0),
:out_color => Color.new(128, 0, 128, 255)
},
:Halfer => {
:name => 'Arial',
:size => 24,
:bold => false,
:outline => false,
:shadow => false,
:fg_color => Color.new(255, 255, 255, 255),
:bg_color => Color.new(0, 0, 0, 0),
},
}
end
#===============================================================================
# Теперь скрипт не зависит от базового ядра
#===============================================================================
if !$imported[:nap_core] || $imported[:nap_core] < 1.05
# Global bitmap just for measuring text size
# DO NOT FORGET to change the font size and stuff before measuring!
$txt_measure_bmp = Bitmap.new(1,1)
class Game_CharacterBase
@@sprites = {}
def sprite
@@sprites[self]
end
def register_sprite(s)
@@sprites[self] = s
end
def detach_sprite
@@sprites.delete(self)
end
end
end
if $khas_graphics
class Texture_Character
alias init_mith_charref initialize
def initialize(*args)
init_mith_charref(*args)
@character.register_sprite(self) if @character
end
alias character_set_mith_charref character=
def character=(char)
@character.detach_sprite if @character
character_set_mith_charref(char)
@character.register_sprite(self) if @character
end
end # class Sprite_Character
elsif !$imported[:nap_core] || $imported[:nap_core] < 1.05
class Sprite_Character
alias init_mith_charref initialize
def initialize(*args)
init_mith_charref(*args)
@character.register_sprite(self) if @character
end
alias character_set_mith_charref character=
def character=(char)
@character.detach_sprite if @character
character_set_mith_charref(char)
@character.register_sprite(self) if @character
end
end # class Sprite_Character
end # if $khas_graphics
#===============================================================================
# Sprite/Texture Character
#===============================================================================
if $khas_graphics
class Texture_Character
attr_accessor :ev_text_sprite
attr_accessor :ev_text_options
attr_accessor :ev_text_text
alias nap_ev_text_initialize initialize
def initialize(*args)
nap_ev_text_initialize(*args)
nap_ev_text_reset_options
end
def nap_ev_text_reset_options
@ev_text_options = {
:name => NAP_EV_TEXT_CONF::DEFAULT_FONT_NAME,
:size => NAP_EV_TEXT_CONF::DEFAULT_FONT_SIZE,
:bold => NAP_EV_TEXT_CONF::DEFAULT_FONT_BOLD,
:italic => NAP_EV_TEXT_CONF::DEFAULT_FONT_ITALIC,
:outline => NAP_EV_TEXT_CONF::DEFAULT_FONT_OUTLINE,
:shadow => NAP_EV_TEXT_CONF::DEFAULT_FONT_SHADOW,
:fg_color => NAP_EV_TEXT_CONF::DEFAULT_FG_COLOR,
:bg_color => NAP_EV_TEXT_CONF::DEFAULT_BG_COLOR,
:out_color => NAP_EV_TEXT_CONF::DEFAULT_OUT_COLOR
}
end
def nap_ev_set_text(text)
@ev_text_text = text
nap_ev_refresh
end
def nap_ev_refresh
# If there already is a text in place then it will be overwritten.
@ev_text_sprite.dispose if @ev_text_sprite
# Do not create a (new) sprite if the text is nil (means that we want to erase it)
if @ev_text_text.nil?
@ev_text_sprite = nil
return
end
# Create sprite
@ev_text_sprite = Sprite.new
# Z-index
if NAP_EV_TEXT_CONF::Z_INDEX
@ev_text_sprite.z = NAP_EV_TEXT_CONF::Z_INDEX
else
@ev_text_sprite.z = @z
end
# Measure text size
nap_ev_text_apply_font($txt_measure_bmp)
txt_size = $txt_measure_bmp.text_size(@ev_text_text)
# Create & render on bitmap
@ev_text_sprite.bitmap = Bitmap.new(txt_size.width, txt_size.height)
nap_ev_text_apply_font(@ev_text_sprite.bitmap)
@ev_text_sprite.bitmap.fill_rect(0, 0, @ev_text_sprite.bitmap.width, @ev_text_sprite.bitmap.height, @ev_text_options[:bg_color])
@ev_text_sprite.bitmap.draw_text(0, 0, @ev_text_sprite.bitmap.width, @ev_text_sprite.bitmap.height, @ev_text_text, 1)
end
def nap_ev_text_apply_font(bitmap)
bitmap.font = Font.new(@ev_text_options[:name], @ev_text_options[:size])
bitmap.font.bold = @ev_text_options[:bold]
bitmap.font.italic = @ev_text_options[:italic]
bitmap.font.outline = @ev_text_options[:outline]
bitmap.font.shadow = @ev_text_options[:shadow]
bitmap.font.color = @ev_text_options[:fg_color]
bitmap.font.out_color = @ev_text_options[:out_color]
end
alias nap_ev_text_update update
def update
nap_ev_text_update
return if !@ev_text_sprite
nap_ev_text_update_location
end
def nap_ev_text_update_location
@ev_text_sprite.x = @x - @ev_text_sprite.width / 2
@ev_text_sprite.y = @y - @rh - @ev_text_sprite.height
end
alias nap_ev_text_dispose dispose
def dispose
@ev_text_sprite.dispose if @ev_text_sprite
nap_ev_text_dispose
end
end
else
class Sprite_Character < Sprite_Base
attr_accessor :ev_text_sprite
attr_accessor :ev_text_options
attr_accessor :ev_text_text
alias nap_ev_text_initialize initialize
def initialize(*args)
nap_ev_text_initialize(*args)
nap_ev_text_reset_options
end
def nap_ev_text_reset_options
@ev_text_options = {
:name => NAP_EV_TEXT_CONF::DEFAULT_FONT_NAME,
:size => NAP_EV_TEXT_CONF::DEFAULT_FONT_SIZE,
:bold => NAP_EV_TEXT_CONF::DEFAULT_FONT_BOLD,
:italic => NAP_EV_TEXT_CONF::DEFAULT_FONT_ITALIC,
:outline => NAP_EV_TEXT_CONF::DEFAULT_FONT_OUTLINE,
:shadow => NAP_EV_TEXT_CONF::DEFAULT_FONT_SHADOW,
:fg_color => NAP_EV_TEXT_CONF::DEFAULT_FG_COLOR,
:bg_color => NAP_EV_TEXT_CONF::DEFAULT_BG_COLOR,
:out_color => NAP_EV_TEXT_CONF::DEFAULT_OUT_COLOR
}
end
def nap_ev_set_text(text)
@ev_text_text = text
nap_ev_refresh
end
def nap_ev_refresh
# If there already is a text in place then it will be overwritten.
@ev_text_sprite.dispose if @ev_text_sprite
# Do not create a (new) sprite if the text is nil (means that we want to erase it)
if @ev_text_text.nil?
@ev_text_sprite = nil
return
end
# Create sprite
@ev_text_sprite = Sprite.new
# Z-index
if NAP_EV_TEXT_CONF::Z_INDEX
@ev_text_sprite.z = NAP_EV_TEXT_CONF::Z_INDEX
else
@ev_text_sprite.z = z
end
# Measure text size
nap_ev_text_apply_font($txt_measure_bmp)
txt_size = $txt_measure_bmp.text_size(@ev_text_text)
# Create & render on bitmap
@ev_text_sprite.bitmap = Bitmap.new(txt_size.width, txt_size.height)
nap_ev_text_apply_font(@ev_text_sprite.bitmap)
@ev_text_sprite.bitmap.fill_rect(0, 0, @ev_text_sprite.bitmap.width, @ev_text_sprite.bitmap.height, @ev_text_options[:bg_color])
@ev_text_sprite.bitmap.draw_text(0, 0, @ev_text_sprite.bitmap.width, @ev_text_sprite.bitmap.height, @ev_text_text, 1)
end
def nap_ev_text_apply_font(bitmap)
bitmap.font = Font.new(@ev_text_options[:name], @ev_text_options[:size])
bitmap.font.bold = @ev_text_options[:bold]
bitmap.font.italic = @ev_text_options[:italic]
bitmap.font.outline = @ev_text_options[:outline]
bitmap.font.shadow = @ev_text_options[:shadow]
bitmap.font.color = @ev_text_options[:fg_color]
bitmap.font.out_color = @ev_text_options[:out_color]
end
alias nap_ev_text_update update
def update
nap_ev_text_update
return if !@ev_text_sprite
nap_ev_text_update_location
end
def nap_ev_text_update_location
@ev_text_sprite.x = x - @ev_text_sprite.width / 2
@ev_text_sprite.y = y - height - @ev_text_sprite.height
end
alias nap_ev_text_dispose dispose
def dispose
@ev_text_sprite.dispose if @ev_text_sprite
nap_ev_text_dispose
end
end
end
#===============================================================================
# Game Event
#===============================================================================
class Game_Event < Game_Character
alias nap_ev_text_setup_page_settings setup_page_settings
def setup_page_settings
nap_ev_text_setup_page_settings
nap_ev_text_commenttag
end
def nap_ev_text_load_preset(preset_sym)
raise "Nap Event Text Error. Preset symbol: "#{preset_sym}" not found for event with id: "#{@id}" " if !NAP_EV_TEXT_CONF::PRESETS.has_key?(preset_sym)
self.sprite.nap_ev_text_reset_options
NAP_EV_TEXT_CONF::PRESETS[preset_sym].each { |k, v| self.sprite.ev_text_options[k] = NAP_EV_TEXT_CONF::PRESETS[preset_sym][k] }
end
def nap_ev_text_commenttag
return if self.list.nil?
sprite_character = self.sprite
return if !sprite_character
preset_found = false
for command in self.list
if command.code == 108
# set text
if command.parameters[0] =~ /<#{NAP_EV_TEXT_CONF::COMMENT_TAG}:(.*?)>/ix
sprite_character.nap_ev_set_text($1)
end
# Preset
if command.parameters[0] =~ /<evtxt_preset:(.*?)>/ix
nap_ev_text_load_preset($1.to_sym)
refresh = true
end
if !preset_found
# options
refresh = false
if command.parameters[0] =~ /<evtxt_name:(.*?)>/ix
sprite_character.ev_text_options[:name] = $1.strip
refresh = true
end
if command.parameters[0] =~ /<evtxt_font_size:(.*?)>/ix
sprite_character.ev_text_options[:size] = $1.strip.to_i
refresh = true
end
if command.parameters[0] =~ /<evtxt_bold:(.*?)>/ix
sprite_character.ev_text_options[:bold] = $1.strip.downcase == 'true'
refresh = true
end
if command.parameters[0] =~ /<evtxt_italic:(.*?)>/ix
sprite_character.ev_text_options[:italic] = $1.strip.downcase == 'true'
refresh = true
end
if command.parameters[0] =~ /<evtxt_outline:(.*?)>/ix
sprite_character.ev_text_options[:outline] = $1.strip.downcase == 'true'
refresh = true
end
if command.parameters[0] =~ /<evtxt_shadow:(.*?)>/ix
sprite_character.ev_text_options[:shadow] = $1.strip.downcase == 'true'
refresh = true
end
if command.parameters[0] =~ /<evtxt_fg_color:(.*?)>/ix
sprite_character.ev_text_options[:fg_color] = nap_ev_text_str2Color($1)
refresh = true
end
if command.parameters[0] =~ /<evtxt_bg_color:(.*?)>/ix
sprite_character.ev_text_options[:bg_color] = nap_ev_text_str2Color($1)
refresh = true
end
if command.parameters[0] =~ /<evtxt_out_color:(.*?)>/ix
sprite_character.ev_text_options[:out_color] = nap_ev_text_str2Color($1)
refresh = true
end
end
sprite_character.nap_ev_refresh if refresh
end
end
end # nap_ev_text_commenttag
def nap_ev_text_str2Color(str)
s = str.clone
s.delete!(' ')
s = s.split(',')
raise "ERROR: nap_ev_text_str2Color(#{str}) does not contain 4 integer values!" if s.length < 4
return Color.new(s[0].to_i, s[1].to_i, s[2].to_i, s[3].to_i)
end
end # class Game_Event < Game_Character
#===============================================================================
# Game Interpreter
# For: Adding commands
#===============================================================================
class Game_Interpreter
def nap_ev_text(ev_id, text)
return if !SceneManager.scene.is_a?(Scene_Map) || !SceneManager.scene.spriteset
$game_map.events[ev_id].sprite.nap_ev_set_text(text)
end
def nap_ev_erase_text(ev_id)
return if !SceneManager.scene.is_a?(Scene_Map) || !SceneManager.scene.spriteset
$game_map.events[ev_id].sprite.nap_ev_set_text(nil)
end
def nap_ev_conf(ev_id, hash)
$game_map.events[ev_id].sprite.ev_text_options[:name] = hash[:name] if hash.has_key?(:name)
$game_map.events[ev_id].sprite.ev_text_options[:size] = hash[:size] if hash.has_key?(:size)
$game_map.events[ev_id].sprite.ev_text_options[:bold] = hash[:bold] if hash.has_key?(:bold)
$game_map.events[ev_id].sprite.ev_text_options[:italic] = hash[:italic] if hash.has_key?(:italic)
$game_map.events[ev_id].sprite.ev_text_options[:outline] = hash[:outline] if hash.has_key?(:outline)
$game_map.events[ev_id].sprite.ev_text_options[:shadow] = hash[:shadow] if hash.has_key?(:shadow)
$game_map.events[ev_id].sprite.ev_text_options[:fg_color] = hash[:fg_color] if hash.has_key?(:fg_color)
$game_map.events[ev_id].sprite.ev_text_options[:out_color] = hash[:out_color] if hash.has_key?(:out_color)
$game_map.events[ev_id].sprite.ev_text_options[:bg_color] = hash[:bg_color] if hash.has_key?(:bg_color)
$game_map.events[ev_id].sprite.nap_ev_refresh
end
end
#===============================================================================
# Class Spriteset Map
# For: Showing the texts when the map starts. The initial setup_page_settings
# is called before the map-scene is activated (like if the player came from
# the title-scene or another map) and therefor could have the wrong or none
# Spriteset set.
#===============================================================================
class Spriteset_Map
alias nap_ev_text_create_characters create_characters
def create_characters
nap_ev_text_create_characters
$game_map.events.each{ |ev| ev[1].nap_ev_text_commenttag } # array note: [0] = id, [1] = event
end
end
#===============================================================================
Социальные закладки