# http://www.hbgames.org/forums/viewtopic.php?f=11&t=72241
#==============================================================================
# Picture Text Command
# By gerkrt/gerrtunk
# Version: 2.2
# License: GPL, credits
#==============================================================================
=begin
NOTE: Requested by Heretic and edited by ThallionDarkshine on chaos-prject.com
to remove MACL requirements for all features. This edit of the script
does NOT requre MACL to access all features due to MACL having similar
problems to the SDK where a lot of stuff does not work as a result.
Version 2.1 by gerkrt/gerrtunk
Version 2.2 by ThallionDarkshine
----------------------------------
Instalation and compatiility
----------------------------------
-Put this script before main.
-To use advance effects install MACL. Here: http://etheon.net/public/dl/macl_complete.txt
Here the forum thread: viewtopic.php?f=11&t=9417
-To install read the instructions. Anyway, you have to put before main but after
this script.
----------------------------------
Instructions
----------------------------------
This script can show pictures based on a text line. The image will be treated like
a normal picture loaded with the show picture event command. It have the same
rules and can be moved, changue tone, erased, etc...
A call script example:
@m = Message.new
@m.bold = false
@m.size = 22
@m.font = "Arial"
@m.italic = false
@m.color = Color.new(255,255,255,255)
@m.t"Text to show"
Then you need to put a command show picture with any image(its not used) and the
values that you will put in a normal event command show picture. The script then creates
creates a bitmap based on your text and options and loading a event picture with it.
You have to use this structure of call script+show picture to use this new command.
----------------------------------
Options and meanings
----------------------------------
Basic options. Description before #:
@m = Message.new # Dont changue or remove this. Always the first thing.
@m.bold = false # Bold letter
@m.size = 22 # Size of the font
@m.font = "Arial" # Fontname
@m.italic = false # Cursive italic
@m.color = Color.new(255,255,255,255) # Text basic color.
@m.t"Wep" # Text to write in the brackets "".
Advanced options. Only with MACL.
@m.shadow = true # Shadowed font
@m.s_color = Color.new(134,176,188,154) # Shadow color
@m.outline = true # Shows a outline
@m.o_color = Color.new(134,176,188,154) # Outline color
@m.horiz_grad = true # Horizontal gradient with two colors
@m.vert_grad = true # Vertical gradient with two colors
@m.g1_color = Color.new(134,176,188,154) # Gradiet Starting color
@m.g2_color = Color.new(1,255,188,154) # Gradiet Endig color
-The only fixed option is @m = Message.new. If you only put this will chargue
a picture based only in your predefenided values.
-Then you have to compose your call scripts adding a option in a new line every time
This a example:
Show message "Noooooo", size 16 and horizontal gradient with defined colors:
@m = Message.new
@m.t"Nooooooooooooooooo"
@m.size = 16
@m.horiz_grad = true
@m.g1_color = Color.new(134,176,188,154)
@m.g2_color = Color.new(1,255,188,154)
-The order dont care. The only rule is to put the @m = Message.new first.
-The two gradients use the same colors values.
-Incompatible effects: the two gradients, shadow/outline.
-Remember to quit the #'s.
-You can make a large call script in two call scripts, simply continue writting
in the next. The other option is:
@m.size = 16 ; @m.horiz_grad = true
The ; is a ruby line internal separator. Its like they are in different lines.
-Some advice about the values:
Color.new(134,176,188,154) Red,Green,Blue+alpha Only changue the numbers. 0-255.
"Texts": You must use the "" and the text inside of them.
true/false: It means Active or Inactive. For example to write bold: @m.bold = true
If the sucker call script gives you strange errors this is what you can try:
-Recolocate the larger scripts lines: spaces,intros,etc
-Add a new option at the end, event if its inactive one.
--------------------------------------------
Advices to write the text
--------------------------------------------
-To only write a event variable value :
@m.t$game_variables[variable_id].to_s
-Complex phrases:
@m.t"HP:"+$game_variables[variable_id].to_s+" "+"Z"
It writes HP:var Z.
-In ruby the + concatenate words to make larger ones.
-Use " " if you need some spaces or aligns
-Respect the "" word delimitators.
-The $game_variables[variable_id].to_s dont use "", but internslly its treated like a word
-variable_id: The number ID of a event variable
----------------------------------
Long lines
----------------------------------
Call script command suck for these. This a example of what you have to do:
@m.t"HP:"+$game_variables[variable_id].to_s
@m.t" MP:"+$game_variables[variable_id2].to_s
@m.t" Limit: "+$game_variables[variable_id3].to_s
The script automatically concatenates all. Just write it in order.
------------------------
Default values
------------------------
If you need this, you can make your predefenided values for all the options.
With this, the command can be shorter, removing the lines you dont need.
The constants names are Def_font_+ the option of the @ that you alreadyknow.
=end
module Wep
Def_font_name = "Arial"
Def_font_text = "Wep"
Def_font_size = 24
Def_font_bold = false
Def_font_italic = false
Def_font_color = Color.new(255, 255, 255, 255) # The normal color
Def_font_outline = false
Def_font_shadow = false
Def_font_s_color = Color.new(0, 0, 0, 100)
Def_font_o_color = Color.new(0, 0, 0)
Def_font_o_size = 1
Def_font_s_ox = 4
Def_font_s_oy = 4
#Def_font_g1_color = Color.new(255, 45, 255)
#Def_font_g2_color = Color.new(12, 128, 128)
end
#==============================================================================
class Message
attr_accessor :text
attr_accessor :font
attr_accessor :size
attr_accessor :bold
attr_accessor :italic
attr_accessor :color
attr_accessor :horiz_grad
attr_accessor :vert_grad
attr_accessor :shadow
attr_accessor :outline
attr_accessor :s_color
attr_accessor :o_color
attr_accessor :o_size
attr_accessor :s_ox
attr_accessor :s_oy
def initialize(text=Wep::Def_font_text,font=Wep::Def_font_name,size=Wep::Def_font_size,bold=Wep::Def_font_bold,italic=Wep::Def_font_italic, color=Wep::Def_font_color, outline=Wep::Def_font_outline,shadow=Wep::Def_font_shadow, s_color=Wep::Def_font_s_color, o_color=Wep::Def_font_o_color, o_size = Wep::Def_font_o_size, s_ox = Wep::Def_font_s_ox, s_oy = Wep::Def_font_s_oy) @text = text
@font = font
@size = size
@bold = bold
@italic = italic
@color = color
@s_color = s_color
@o_color = o_color
@shadow = shadow
@o_size = o_size
@s_ox = s_ox
@s_oy = s_oy
@text = ""
@text = text
@outline = outline
@first_concat = true
end
#--------------------------------------------------------------------------
# *t This metod concatenates the text string.
# Optimitzed to be very short.
#--------------------------------------------------------------------------
def t(text)
# Check if the text is the predefined and its the first time to add
# and clears it
if Wep::Def_font_text == @text and @first_concat
@text = ""
end
@first_concat = false
@text += text
end
end
class Sprite_Picture
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
# If picture file name is different from current one and have a message
if @picture_name != @picture.name and @picture.message
# Remember file name to instance variables
@picture_name = @picture.name
#if @picture_name != ""
# Get picture graphic
#end
# Use the testing bitmap to know text size
testing_bitmap = Bitmap.new(1,1)
testing_bitmap.font.name = @picture.message.font
testing_bitmap.font.size = @picture.message.size
testing_bitmap.font.bold = @picture.message.bold
testing_bitmap.font.italic = @picture.message.italic
line = @picture.message.text
needed_rect = testing_bitmap.text_size(line)
# Changue basic font options
self.bitmap = Bitmap.new(needed_rect.width, needed_rect.height)
self.bitmap.font.name = @picture.message.font
self.bitmap.font.size = @picture.message.size
self.bitmap.font.bold = @picture.message.bold
self.bitmap.font.italic = @picture.message.italic
self.bitmap.font.color = @picture.message.color
self.bitmap.font.outline_color = @picture.message.o_color
self.bitmap.font.outline = @picture.message.outline
self.bitmap.font.outline_distance = @picture.message.o_size
self.bitmap.font.shadow = @picture.message.shadow
self.bitmap.font.shadow_color = @picture.message.s_color
self.bitmap.font.shadow_ox = @picture.message.s_ox
self.bitmap.font.shadow_oy = @picture.message.s_oy
self.bitmap.draw_text(0, 0, needed_rect.width, needed_rect.height, line)
end
# If picture file name is different from current one
if @picture_name != @picture.name and @picture.message == nil
# Remember file name to instance variables
@picture_name = @picture.name
# If file name is not empty
if @picture_name != ""
# Get picture graphic
self.bitmap = RPG::Cache.picture(@picture_name)
end
end
# If file name is empty
if @picture_name == ""
# Set sprite to invisible
self.visible = false
return
end
# Set sprite to visible
self.visible = true
# Set transfer starting point
if @picture.origin == 0
self.ox = 0
self.oy = 0
else
self.ox = self.bitmap.width / 2
self.oy = self.bitmap.height / 2
end
# Set sprite coordinates
self.x = @picture.x
self.y = @picture.y
self.z = @picture.number
# Set zoom rate, opacity level, and blend method
self.zoom_x = @picture.zoom_x / 100.0
self.zoom_y = @picture.zoom_y / 100.0
self.opacity = @picture.opacity
self.blend_type = @picture.blend_type
# Set rotation angle and color tone
self.angle = @picture.angle
self.tone = @picture.tone
end
end
class Game_Picture
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :message # text
#--------------------------------------------------------------------------
# * Object Initialization
# number : picture number
#--------------------------------------------------------------------------
alias gp_init initialize
def initialize(number)
gp_init(number)
@message = nil
end
alias gp_show show
def show(name, origin, x, y, zoom_x, zoom_y, opacity, blend_type, message=nil)
gp_show(name, origin, x, y, zoom_x, zoom_y, opacity, blend_type)
@message = message
end
alias gp_erase erase
def erase
gp_erase
@message = nil
end
end
class Interpreter
#--------------------------------------------------------------------------
# * Show Picture
#--------------------------------------------------------------------------
def command_231
# Get picture number
number = @parameters[0] + ($game_temp.in_battle ? 50 : 0)
# If appointment method is [direct appointment]
if @parameters[3] == 0
x = @parameters[4]
y = @parameters[5]
# If appointment method is [appoint with variables]
else
x = $game_variables[@parameters[4]]
y = $game_variables[@parameters[5]]
end
# Show picture
# If message is written
if @m != nil
$game_screen.pictures[number].show(@parameters[1], @parameters[2],
x, y, @parameters[6], @parameters[7], @parameters[8], @parameters[9], @m)
# Format m for other calls
@m = nil
else
$game_screen.pictures[number].show(@parameters[1], @parameters[2],
x, y, @parameters[6], @parameters[7], @parameters[8], @parameters[9])
end
# Continue
return true
end
end
=begin
addons to remove macl dependency by ThallionDarkshine
=end
class Font
attr_accessor :underline, :overline, :strikethrough
attr_accessor :outline, :outline_color, :outline_distance
attr_accessor :shadow, :shadow_color, :shadow_ox, :shadow_oy
# F12 No Crash Fix for already defined
unless $text_picture_version
alias tdks_message_init initialize
def initialize(*args)
tdks_message_init(*args)
@underline = false
@overline = false
@strikethrough = false
@outline, @outline_color, @outline_distance = false, Color.new(0, 0, 0), 0
@shadow, @shadow_color, @shadow_ox, @shadow_oy = false, Color.new(127, 127, 127, 170), 2, 2
end
end
end
class Bitmap
# F12 No Crash Fix for already defined
unless $text_picture_version
alias tdks_txt2pic_draw_text draw_text
def draw_text(*args)
unless args[0].is_a?(Rect)
args[0..3] = Rect.new(*args[0..3])
end
args[2] = 0 if args[2].nil?
args[3] = 1 if args[3].nil?
case args[3]
when 0
args[0].height = text_size(args[1]).height
when 1
h = text_size(args[1]).height
args[0].y += (args[0].height - h) / 2
args[0].height = h
when 2
h = text_size(args[1]).height
args[0].y += args[0].height
args[0].height = h
end
text = args[1].clone
text = text.split(/[\n\r]/)
rect = args[0].clone
case args[3]
when 1
amnt = (text.length / 2.0).floor
text[0...amnt].each { |ln| rect.y -= text_size(ln).height } if amnt > 0
rect.y += text_size(text[0]).height / 2 if amnt % 2 == 1
when 2
text.each { |ln| rect.y -= text_size(ln).height }
end
text.each { |ln|
orig_x = rect.x
size = text_size(ln)
case args[2]
when 1
rect.x += (rect.width - size.width) / 2
when 2
rect.x += rect.width - size.width
end
if font.shadow
prev_color = font.color.clone
font.color = font.shadow_color
tdks_txt2pic_draw_text(rect.x + font.shadow_ox, rect.y + font.shadow_oy, rect.width, rect.height, ln)
font.color = prev_color
end
if font.outline
prev_color = font.color.clone
font.color = font.outline_color
(-font.outline_distance..font.outline_distance).each { |ox|
(-font.outline_distance..font.outline_distance).each { |oy|
next if ox == 0 and oy == 0
tdks_txt2pic_draw_text(rect.x + ox, rect.y + oy, rect.width, rect.height, ln)
}
}
font.color = prev_color
end
tdks_txt2pic_draw_text(rect, ln)
if font.overline
fill_rect(rect.x, rect.y + (size.height / 15.0).ceil, size.width, (size.height / 15.0).ceil, font.color)
end
if font.strikethrough
fill_rect(rect.x, rect.y + size.height / 2, size.width, (size.height / 15.0).ceil, font.color)
end
rect.y += size.height
if font.underline
fill_rect(rect.x, rect.y - (2 * size.height / 15.0).ceil, size.width, (size.height / 15.0).ceil, font.color)
end
rect.x = orig_x
}
end
def draw_gradient_text(c1, c2, *args)
unless args[0].is_a?(Rect)
args[0..3] = Rect.new(*args[0..3])
end
rect = args[0]
tmp = Bitmap.new(rect.width, rect.height)
tmp.draw_text(tmp.rect, *args[1...args.length])
overlay_grad = Win32API.new('overlay_grad.dll', 'overlay_grad', 'liiiiiiiiii', 'b')
overlay_grad.call(tmp.__id__, args[0].x, args[0].y, args[0].width, args[0].height, c1.red, c1.green, c1.blue, c2.red, c2.green, c2.blue)
blt(rect.x, rect.y, tmp, tmp.rect)
end
end
end
$text_picture_version = 2.2