Код:
=begin
================================================================================
CDR - Show Variables 1.3
-------------------------------------------------------------------------------
Author: Ceodore
Mail: ceodore@email.com
https://ceodoremaker.wordpress.com
===============================Change log=======================================
04/04/2013 - 1.3 release. Bug fixes and new stuff
02/04/2013 - 1.2 release. Added font options.
01/04/2013 - 1.1 release. Fixed a minor bug.
01/04/2013 - 1.0 release.
===============================Description======================================
This implementation is meant to provide a way display any number of variables
on the map.
=================================License========================================
You may freely use and modify this script as long as you do not change the
original author information. If you use this on your game, include the author
on the credits.
===================================Use==========================================
Open a Script event command and follow the instructions:
Before showing a variable you need to define it's options. To do it, type
the command:
sv_options(n,x,y,icon,color,dir,icon_pos, lzeros)
Where n is the variable number and x and y are the value position on screen.
The other are optional, but it's nice to define, you only need to do it once
for each variable.
icon -> The icon index
color -> the color number
dir -> the text direction, wich can be:
:ltr (left to right)
:rtl (Right)
:mid (center)
icon_pos -> The icon position, can be :left or :right
lzeros -> The number of leading zeroes
show_variable(n)
Shows a variable on screen as specified in sv_options()
hide_variable(n)
Hides the variable n if it's being displayed on screen.
================================================================================
=end
module CDR_SV
# sub module containing default font options for the variable values
module FONT
NAME = ["Evolventa"]
SIZE = 25
BOLD = false
ITALIC = false
SHADOW = false
end
end
#==============================================================================
# DataManager
#==============================================================================
SuperDataManager = DataManager.dup
module DataManager
#--------------------------------------------------------------------------
# * intercept: clears the variable settings list
#--------------------------------------------------------------------------
def self.create_game_objects
Window_Variables.clear
SuperDataManager.create_game_objects
end
end
#==============================================================================
# Game_Interpreter
#==============================================================================
class Game_Interpreter
#--------------------------------------------------------------------------
# * new method: displays a variable on map screen
#--------------------------------------------------------------------------
def sv_options(n,x,y,icon=nil,color=1,dir=:ltr,icon_pos=:left, lzeros=0)
return unless SceneManager.scene.is_a?(Scene_Map)
sv_window = SceneManager.scene.variables_window
case dir
when :ltr
text_direction = 0
when :mid
text_direction = 1
when :rtl
text_direction = 2
end
sv_window.sv_options(n,x,y,icon,color,text_direction,icon_pos,lzeros)
end
#--------------------------------------------------------------------------
# * new method: displays a variable on map screen
#--------------------------------------------------------------------------
def show_variable(n)
return unless SceneManager.scene.is_a?(Scene_Map)
sv_window = SceneManager.scene.variables_window
sv_window.show_variable(n)
end
#--------------------------------------------------------------------------
# * new method: hides a displayed variable
#--------------------------------------------------------------------------
def hide_variable(n)
return unless SceneManager.scene.is_a?(Scene_Map)
sv_window = SceneManager.scene.variables_window
sv_window.hide_variable(n)
end
end
#==============================================================================
# SvOptions
#==============================================================================
class SvOptions
attr_accessor :id
attr_accessor :x
attr_accessor :y
attr_accessor :text_color
attr_accessor :x
attr_accessor :text_direction
attr_accessor :icon_index
attr_accessor :icon_position
attr_accessor :lzeros
attr_accessor :visible
#--------------------------------------------------------------------------
# * new method: initialize
#--------------------------------------------------------------------------
def initialize(id,x,y,icon,color,dir,icon_pos,lzeros,visible)
@id = id
@x = x
@y = y
@text_color = color
@text_direction = dir
@icon_index = icon
@icon_position = icon_pos
@lzeros = lzeros
@visible = visible
end
#--------------------------------------------------------------------------
# * new method: displays the variable on map screen
#--------------------------------------------------------------------------
def show
@visible = true
end
#--------------------------------------------------------------------------
# * new method: hides the variable from map screen
#--------------------------------------------------------------------------
def hide
@visible = false
end
end
#==============================================================================
# Window_Variables
#==============================================================================
class Window_Variables < Window_Base
@@items = {}
#--------------------------------------------------------------------------
# * new method: initialize
#--------------------------------------------------------------------------
def initialize
super(0, 0, window_width, window_height)
self.opacity = 0
self.visible = true
refresh
end
#--------------------------------------------------------------------------
# * new method: window_width
#--------------------------------------------------------------------------
def window_width
return Graphics.width
end
#--------------------------------------------------------------------------
# * new method: window_height
#--------------------------------------------------------------------------
def window_height
return Graphics.height
end
#--------------------------------------------------------------------------
# * new method: variable_width
#--------------------------------------------------------------------------
def variable_width
return 160
end
#--------------------------------------------------------------------------
# * new method: refresh
#--------------------------------------------------------------------------
def refresh
contents.clear
@@items.each{|k,vw| draw_item(vw) if vw.visible}
end
#--------------------------------------------------------------------------
# * new method: refresh
#--------------------------------------------------------------------------
def draw_item(item)
icon_x = draw_item_icon(item) unless item.icon_index.nil?
change_color(text_color(item.text_color))
cdr_sv_font
x_offset = item.icon_position == :left ? 28 : 0
text = $game_variables[item.id].to_s.rjust(item.lzeros, '0')
dir = item.text_direction
draw_text(item.x+x_offset, item.y, variable_width, line_height, text, dir)
reset_font_settings
change_color(normal_color)
end
#--------------------------------------------------------------------------
# * new method: draw_item_icon
#--------------------------------------------------------------------------
def draw_item_icon(item)
case item.icon_position
when :left
icon_x = item.x
when :right
icon_x = item.x+variable_width
end
draw_icon(item.icon_index, icon_x, item.y)
return icon_x
end
#--------------------------------------------------------------------------
# * new method: sets the font options as specified on CDR_SV::FONT module
#--------------------------------------------------------------------------
def cdr_sv_font
contents.font.name = CDR_SV::FONT::NAME
contents.font.size = CDR_SV::FONT::SIZE
contents.font.bold = CDR_SV::FONT::BOLD
contents.font.italic = CDR_SV::FONT::ITALIC
contents.font.shadow = CDR_SV::FONT::SHADOW
end
#--------------------------------------------------------------------------
# * new method: resets the font settings as in default font
#--------------------------------------------------------------------------
def reset_font_settings
contents.font.name = Font.default_name
contents.font.size = Font.default_size
contents.font.bold = Font.default_bold
contents.font.italic = Font.default_italic
contents.font.shadow = Font.default_shadow
end
#--------------------------------------------------------------------------
# * new method: adds a new variable_window
#--------------------------------------------------------------------------
def sv_options(n,x,y,icon,color,dir,icon_pos, lzeros, visible = false)
if !@@items.has_key?(n)
@@items[n] = SvOptions.new(n,x,y,icon,color,dir,icon_pos,lzeros,visible)
else
@@items[n].x = x
@@items[n].y = y
@@items[n].icon_index = icon
@@items[n].text_color = color
@@items[n].text_direction = dir
@@items[n].icon_position = icon_pos
@@items[n].lzeros = lzeros
@@items[n].visible = visible
end
end
#--------------------------------------------------------------------------
# * new method: adds a new variable_window
#--------------------------------------------------------------------------
def show_variable(n)
return if !@@items.has_key?(n)
@@items[n].show
end
#--------------------------------------------------------------------------
# * new method: removes a specific variable_window
#--------------------------------------------------------------------------
def hide_variable(n)
return if !@@items.has_key?(n)
@@items[n].hide
end
#--------------------------------------------------------------------------
# * new method: clears the variable options data
#--------------------------------------------------------------------------
def self.clear
@@items = {}
end
end
#==============================================================================
# Scene_map
#==============================================================================
class Scene_Map < Scene_Base
attr_accessor :variables_window
alias cdr_sv_start start
def start
cdr_sv_start
@variables_window = Window_Variables.new
end
#--------------------------------------------------------------------------
# * alias: updates each variable_window
#--------------------------------------------------------------------------
alias cdr_sv_update update
def update
cdr_sv_update
@variables_window.refresh
end
end
Социальные закладки