I need a little help with ccoas UMS for VX.
I get some really annoying bugs with the textbox... :(
Look:
As you see, the textbox moves out of the screen. oO (2nd picture)
Can somebody please fix that? =(
Eternal thanks is granted to the one who finishes this task! :)
Maybe you can make it, that both, the face and the name box can be displayed, too?^^
Oh, here's the UMS:
Script
Code:
# *****************************************************************************
# * Universal Message System for VX
# * v0.3.0
# * by Ccoa
# *****************************************************************************
# Usage:
=begin
IN MESSAGE CODES
\b - toggle bold on and off
\c[i] - change to color i
\c[#IIIIII] - change the text color to the hex code
\e[i] - center over event i (0 is player)
\fl - change face justification to left
\font[name] - change the window font to font name
\fr - change face justification to right
\g - show the gold window
\height[i] - permanenty set the window height to i (NORMAL_MODE only)
\i - toggle italics on and off
\ic[i] - draw icon at index i
\jc - justify the window to the center (ignored if centered over event)
\jl - justify the window to the left (ignored if centered over event)
\jr - justify the window to the right (ignored if centered over event)
\m - toggle between FIT_WINDOW_TO_TEXT and NORMAL_MODE
\mf - mirror (flip) the face being displayed
\nm["name"] - display "name" in the name window
\n[i] - show actor i's name
\np[i] - show the actor at position i's name
\oa[i] - display the icon and name of armor i
\oi[i] - display the icon and name of item i
\os[i] - display the icon and name of skill i
\ow[i] - display the icon and name of weapon i
\p[i] - pause for i frames before writing the next character
\skip - toggle text skip on and off
\t1 - show talk1 icon
\t2 - show talk2 icon
\th - show thought icon
\v[i] - show variable i
\w[i] - wait i frames before closing window automatically (MUST be last!)
\width[i] - permanenty set the window width to i (NORMAL_MODE only)
\. - wait 1/4 sec before continuing
\| - wait 1 sec before closing
\! - wait for button input
\> - display rest of characters all at once
\^ - close window automatically after text is displayed
\\ - print the \ character
OUT OF MESSAGE CODES (use in a Script event command)
$game_system.face_graphic_justification = LEFT - the face graphic is on the left side
$game_system.face_graphic_justification = RIGHT - the face graphic is on the right side
$game_system.face_graphic_position = TOP - face graphic appears on top of window
$game_system.face_graphic_position = CENTER - face graphic appears centered in window
$game_system.face_graphic_position = BOTTOM - face graphic appears on the bottom of window
$game_system.message_event = i (0 = player, -1 = no event)
$game_system.name = "name" - name to display in name window
$game_system.name = "" - display no name in the name window
$game_system.name_window = true - show window behind name
$game_system.name_window = false - don't show window behind name
$game_system.ums_mode = NORMAL_MODE - switch to normal mode
$game_system.ums_mode = FIT_WINDOW_TO_TEXT - switch to fit window mode
$game_system.comic_enabled = false - turn off comic thingy
$game_system.comic_enabled = true - turn on comic thingy (only works with message_event not -1)
$game_system.comic_style = TALK1 - use the talk1.png comic thingy
$game_system.comic_style = TALK2 - use the talk2.png comic thingy
$game_system.comic_style = THOUGHT - use the thought.png comic thingy
$game_system.face_graphic_justification = LEFT - the face graphic is on the left side
$game_system.face_graphic_justification = RIGHT - the face graphic is on the right side
$game_system.sound_effect = "" - turn off sound effect per letter
$game_system.sound_effect = "SE name" - play the given SE with each letter
$game_system.text_skip = true - turn text skip on
$game_system.text_skip = false - turn text skip off
$game_system.write_speed = i - change the output to 1 char/i frames (must be integer greater than 0)
$game_system.window_height = i - change the window height to i
$game_system.window_width = i - change the window width to i
$game_system.window_justification = RIGHT - make the window right justified
$game_system.window_justification = LEFT - make the window left justified
$game_system.window_justification = CENTER - make the window center justified
$game_system.font = "name" - change the font to name
$game_system.font = "" - return the font to the default
=end
# modes
NORMAL_MODE = 0
FIT_WINDOW_TO_TEXT = 1
# comic styles
TALK1 = 0
TALK2 = 1
THOUGHT = 2
# justifications
RIGHT = 4
CENTER = 0
LEFT = 6
# positions for extra objects (face graphics, choice box, etc)
ABOVE = 0 # place the object above the top of the message box
CENTER = 1 # center the object vertically inside the message box
BOTTOM = 2 # place the bottom of the object on the bottom of the message box
SIDE = 3 # to the side of the message box (which side depends on justification)
class Game_System
attr_accessor :ums_mode # what mode the UMS is in
attr_accessor :message_event # what event to center over
attr_accessor :name # name to display in name window
attr_accessor :name_window # should the name window be visible?
attr_accessor :comic_enabled # show comic-thingy?
attr_accessor :comic_style # TALK1, TALK2, or THOUGHT
attr_accessor :write_speed # how fast to write the text
attr_accessor :text_skip # text skip on?
attr_accessor :face_graphic_justification # LEFT or RIGHT
attr_accessor :face_graphic_position # TOP, BOTTOM, or CENTER
attr_accessor :sound_effect # SE to play with each character
attr_accessor :window_height # height of message window
attr_accessor :window_width # width of message window
attr_accessor :window_justification # LEFT, RIGHT, or CENTER
attr_accessor :font # special font to use in messages
def add_shortcut(shortcut, code)
text = shortcut.downcase
if !@used_codes.include?(text)
@shortcuts[shortcut] = code
end
end
end
#==============================================================================
# ** Window_Message
#------------------------------------------------------------------------------
# This message window is used to display text.
#==============================================================================
class Window_Message < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 288, $game_system.window_width, $game_system.window_height)
if $game_system.font != ""
self.contents.font.name = $game_system.font
else
self.contents.font.name = Font.default_name
end
self.z = 200
self.active = false
self.index = -1
self.openness = 0
@opening = false # WIndow opening flag
@closing = false # Window closing flag
@text = nil # Remaining text to be displayed
@contents_x = 0 # X coordinate for drawing next character
@contents_y = 0 # Y coordinate for drawing next character
@line_count = 0 # Line count drawn up until now
@wait_count = 0 # Wait count
@background = 0 # Background type
@position = 2 # Display position
@show_fast = false # Fast forward flag
@line_show_fast = false # Fast forward by line flag
@pause_skip = false # Input standby omission flag
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias ums_update update
def update
if @opening
if $game_system.comic_enabled
@comic.opacity += 48
end
if !$game_message.face_name.empty?
@face.opacity += 48
end
elsif @closing
if $game_system.comic_enabled
@comic.opacity -= 48
end
if !$game_message.face_name.empty?
@face.opacity -= 48
end
end
set_window_position
ums_update
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
alias ums_dispose dispose
def dispose
ums_dispose
dispose_name_window
dispose_comic_icon
dispose_face_graphic
end
#--------------------------------------------------------------------------
# * Dispose name window
#--------------------------------------------------------------------------
def dispose_name_window
@name_window.dispose
end
def dispose_comic_icon
@comic.dispose
end
def dispose_face_graphic
if @face.bitmap != nil
@face.bitmap.dispose
end
@face.dispose
end
#--------------------------------------------------------------------------
# * End Message
#--------------------------------------------------------------------------
alias ums_terminate_message terminate_message
def terminate_message
ums_terminate_message
@name_window.visible = false
@face.opacity = 0
@face.mirror = false
end
#--------------------------------------------------------------------------
# * Convert Special Characters
#--------------------------------------------------------------------------
def convert_special_characters
# replace shortcuts with original code
$game_system.shortcuts.each { |shortcut, code|
@text.gsub!(shortcut, code)
}
# face
@text.gsub!(/\\[Ff][Ll]/) do
$game_system.face_graphic_justification = LEFT
""
end
@text.gsub!(/\\[Ff][Rr]/) do
$game_system.face_graphic_justification = RIGHT
""
end
@text.gsub!(/\\[Mm][Ff]/) do
@face.mirror = true
""
end
# toggle mode
@text.gsub!(/\\[Mm]/) do
if $game_system.ums_mode == NORMAL_MODE
$game_system.ums_mode = FIT_WINDOW_TO_TEXT
else
$game_system.ums_mode = NORMAL_MODE
end
""
end
# message event
@text.gsub!(/\\[Ee]\[([0-9]+)\]/) do
$game_system.message_event = $1.to_i
if $game_system.comic_enabled
@comic.visible = true
end
""
end
@text.gsub!(/\\[Ee]\[\-1\]/) do
$game_system.message_event = -1
@comic.visible = false
""
end
# comic stuff
@text.gsub!(/\\[Tt]1/) do
$game_system.comic_style = TALK1
""
end
@text.gsub!(/\\[Tt]2/) do
$game_system.comic_style = TALK2
""
end
@text.gsub!(/\\[Tt][Hh]/) do
$game_system.comic_style = THOUGHT
""
end
# text skip
@text.gsub!(/\\[Ss][Kk][Ii][Pp]/) do
$game_system.text_skip = !$game_system.text_skip
""
end
# height, width, and justification
@text.gsub!(/\\[Hh][Ee][Ii][Gg][Hh][Tt]\[([0-9]+)\]/) do
$game_system.window_height = $1.to_i
""
end
@text.gsub!(/\\[Ww][Ii][Dd][Tt][Hh]\[([0-9]+)\]/) do
$game_system.window_width = $1.to_i
""
end
@text.gsub!(/\\[Jj][Rr]/) do
$game_system.window_justification = RIGHT
reset_window
""
end
@text.gsub!(/\\[Jj][Cc]/) do
$game_system.window_justification = CENTER
reset_window
""
end
@text.gsub!(/\\[Jj][Ll]/) do
$game_system.window_justification = LEFT
reset_window
""
end
# item, weapon, armor, skill names and icons
@text.gsub!(/\\[Oo][Ii]\[([0-9]+)\]/) do
item = $data_items[$1.to_i]
if item != nil
"\x14[" + item.icon_index.to_s + "] " + item.name
else
""
end
end
@text.gsub!(/\\[Oo][Aa]\[([0-9]+)\]/) do
item = $data_armors[$1.to_i]
if item != nil
"\x14[" + item.icon_index.to_s + "] " + item.name
else
""
end
end
@text.gsub!(/\\[Oo][Ww]\[([0-9]+)\]/) do
item = $data_weapons[$1.to_i]
if item != nil
"\x14[" + item.icon_index.to_s + "] " + item.name
else
""
end
end
@text.gsub!(/\\[Oo][Ss]\[([0-9]+)\]/) do
skill = $data_skills[$1.to_i]
if skill != nil
"\x14[" + skill.icon_index.to_s + "] " + skill.name
else
""
end
end
@text.gsub!(/\\[Nn][Pp]\[([0-9]+)\]/i) {
i = $1.to_i - 1
if $game_party.members[i] == nil
""
else
$game_party.members[i].name
end
}
# name window
@text.gsub!(/\\[Nn][Mm]\[(.*?)\]/) do
$game_system.name = $1.to_s
if $game_system.name == ""
@name_window.visible = false
else
@name_window.set_name($game_system.name)
end
""
end
end
#--------------------------------------------------------------------------
# * Set Window Background and Position
#--------------------------------------------------------------------------
def reset_window
@background = $game_message.background
@position = $game_message.position
if @background == 0 # Normal window
self.opacity = 255
else # Dim Background and Make it Transparent
self.opacity = 0
end
# check mode
if $game_system.ums_mode == FIT_WINDOW_TO_TEXT
width = 1
text = @text.split("\x00")
height = 0
i = 0
for line in text
width = [width, self.contents.text_size(line).width].max
delta = self.contents.text_size(line).height
height += delta + (delta * 0.2).to_i
end
self.width = width + 32
self.height = height + 32
create_contents
else
self.width = $game_system.window_width
self.height = $game_system.window_height
create_contents
end
set_window_position
if $game_system.name != ""
@name_window.visible = true
end
end
def set_window_position
# x and y
if $game_system.message_event == -1
if $game_system.window_justification == LEFT
self.x = 0
elsif $game_system.window_justification == RIGHT
self.x = Graphics.width - self.width
else # CENTER
self.x = (Graphics.width - self.width) / 2
end
case @position
when 0 # Top
self.y = 0
@gold_window.y = 360
when 1 # Middle
self.y = (Graphics.height - self.height) / 2
@gold_window.y = 0
when 2 # Bottom
self.y = Graphics.height - self.height
@gold_window.y = 0
end
else
if $game_system.message_event > 0
# center on event
event_x = $game_map.events[$game_system.message_event].screen_x
self.y = $game_map.events[$game_system.message_event].screen_y - self.height - 48
else
# center on player
event_x = $game_player.screen_x
self.y = $game_player.screen_y - self.height - 48
end
self.x = event_x - self.width / 2
end
# name window
if $game_system.name != ""
@name_window.x = self.x
@name_window.y = self.y - 36
end
# comic icon
if $game_system.comic_enabled
if $game_system.comic_style == TALK1
@comic.bitmap = Cache.system("talk1")
elsif $game_system.comic_style == TALK2
@comic.bitmap = Cache.system("talk2")
else # thought
@comic.bitmap = Cache.system("thought")
end
end
@comic.x = self.x + (self.width / 2) + 4
@comic.y = self.y + self.height - 2
# double check for good values
if self.y < 0 + ($game_system.name == "" ? 0 : 16)
if $game_system.comic_enabled
if $game_system.message_event == 0 or $game_map.events[$game_system.message_event] == nil
self.y = $game_player.screen_y - 16
else
self.y = $game_map.events[$game_system.message_event].screen_y - 16
end
@comic.angle = 180
@comic.y = self.y + 2
@comic.x = self.x + (self.width / 2) - 4
else
self.y = 0 + ($game_system.name == "" ? 0 : 16)
end
elsif self.y > 480 - self.height
self.y = 480 - self.height
end
if self.x < 0
self.x = 0
elsif self.x > 680 - self.width - 48
self.x = 640 - self.width
end
# face image
# x coord
if $game_system.face_graphic_justification == LEFT
@face.x = self.x + 6
else # RIGHT
@face.x = self.x + self.width - @face.width - 6
end
# y coord
if $game_system.face_graphic_position == CENTER
if self.height > @face.height
delta = (self.height - @face.height) / 2
else
delta = 6
end
@face.y = self.y + self.height - @face.height - delta
elsif $game_system.face_graphic_position == BOTTOM
@face.y = self.y + self.height - @face.height - 6
else # ABOVE
@face.y = self.y - @face.height
end
end
if !$game_message.face_name.include?("$")
index = $game_message.face_index
rect = Rect.new(0, 0, 0, 0)
h = @face.bitmap.height / 2
w = @face.bitmap.width / 4
rect.x = index % 4 * w
rect.y = index / 4 * h
rect.width = w
rect.height = h
@face.src_rect = rect
if $game_system.face_graphic_justification == LEFT and $game_system.face_graphic_position != ABOVE
@contents_x = w + 16
else
@contents_x = 0
end
end
if $game_system.face_graphic_justification == LEFT and $game_system.face_graphic_position != ABOVE
@contents_x = @face.width + 16
else
@contents_x = 0
end
end
@contents_y = 0
@line_count = 0
@show_fast = false
@line_show_fast = false
@pause_skip = false
contents.font.color = text_color(0)
end
#--------------------------------------------------------------------------
# * New Line
#--------------------------------------------------------------------------
def new_line
if $game_message.face_name.empty?
@contents_x = 0
elsif $game_system.face_graphic_justification == RIGHT or $game_system.face_graphic_position == ABOVE
@contents_x = 0
else # left justified and in box
@contents_x = @face.width + 12
end
@contents_y += WLH
@line_count += 1
@line_show_fast = false
end
#--------------------------------------------------------------------------
# * Update Message
#--------------------------------------------------------------------------
def update_message
if !(Graphics.frame_count % $game_system.write_speed == 0)
return
end
loop do
c = @text.slice!(/./m) # Get next text character
case c
when nil # There is no text that must be drawn
finish_message # Finish update
break
when "\x00" # New line
new_line
if @line_count >= MAX_LINE # If line count is maximum
unless @text.empty? # If there is more
self.pause = true # Insert number input
break
end
end
when "\x01" # \C[n] (text character color change)
@text.sub!(/\[([0-9]+)\]/, "")
contents.font.color = text_color($1.to_i)
next
when "\x02" # \G (gold display)
@gold_window.refresh
@gold_window.open
when "\x03" # \. (wait 1/4 second)
@wait_count = 15
break
when "\x04" # \| (wait 1 second)
@wait_count = 60
break
when "\x05" # \! (Wait for input)
self.pause = true
break
when "\x06" # \> (Fast display ON)
@line_show_fast = true
when "\x07" # \< (Fast display OFF)
@line_show_fast = false
when "\x08" # \^ (No wait for input)
@pause_skip = true
when "\x09"
contents.font.bold = !contents.font.bold # toggle bold
when "\x10"
contents.font.italic = !contents.font.italic # toggle italic
when "\x11" #\p[i] (pause i frames)
@text.sub!(/\[([0-9]+)\]/, "")
@wait_count = $1.to_i
when "\x12" # hex color change
# convert hex color to RGB
@text.sub!(/\[([0123456789abcdef]+)\]/, "")
hex_code = $1.to_s
red = ("0x" + hex_code.slice(0..1)).hex
blue = ("0x" + hex_code.slice(2..3)).hex
green = ("0x" + hex_code.slice(4..5)).hex
self.contents.font.color = Color.new(red, blue, green)
next
when "\x13" # change write speed
@text.sub!(/\[([0-9]+)\]/, "")
$game_system.write_speed = $1.to_i
break
when "\x14" # draw icon
@text.sub!(/\[([0-9]+)\]/, "")
draw_icon($1.to_i, @contents_x, @contents_y)
@contents_x += 24
when "\x15" # change font
@text.sub!(/\[(.*?)\]/, "")
$game_system.font = $1.to_s
if $game_system.font != ""
self.contents.font.name = $game_system.font
else
self.contents.font.name = Font.default_name
end
next
else # Normal text character
if $game_system.sound_effect != ""
Audio.se_play('Audio/SE/' + $game_system.sound_effect, 80, 100)
end
contents.draw_text(@contents_x, @contents_y, 40, WLH, c)
c_width = contents.text_size(c).width
@contents_x += c_width
end
break unless @show_fast or @line_show_fast
end
end
#--------------------------------------------------------------------------
# * Update Fast Forward Flag
#--------------------------------------------------------------------------
def update_show_fast
if self.pause or self.openness < 255 or !$game_system.text_skip
@show_fast = false
elsif Input.trigger?(Input::C) and @wait_count < 2
@show_fast = true
elsif not Input.press?(Input::C)
@show_fast = false
end
if @show_fast and @wait_count > 0
@wait_count -= 1
end
end
end
#==============================================================================
# ** Window_Name
#------------------------------------------------------------------------------
# This window shows the name above the message window
#==============================================================================
I see you're using VX so you probably didn't read the XP version thread. It was already discussed and somewhat answered already. Take a look: ccoa's UMS XP