Jump to content
Sign in to follow this  
Victor Sant

VE - SFonts

Recommended Posts

Victor Engine - SFonts

 

sfont.PNG

 

 

This script allows the use of SFonts. SFonts is a image file that replaces the normal font.

What are SFonts? (from http://rubygame.org/docs/)

SFont is a type of bitmapped font, which is loaded from an image file with a meaningful top row of pixels, and the font itself below that. The top row provides information about what parts of the lower area contains font data, and which parts are empty. The image file should contain all of the glyphs on one row, with the “skip†color at the top-left pixel.

 

Download:

Victor Engine - SFonts

 

 

Credits:

Author: Victor Sant

 

Terms of Use

Edited by Victor Sant

Share this post


Link to post
Share on other sites
And i put those defs in another script below Material... maybe i put them wrong, can you give an example of how it should look?
how exactly you're doing?

 

if you want more speficif colors, you can go directily on the script and add the "text_color(n)" directly on the part you want do change the colors.

 

Example: I added this on Window_Gold:

def normal_color;	  text_color(4);   end;

And the white color (normal_color) was replaced with yellow. wich was the fifth font on the default list.

 

Using the default fonts i set and adding the following code on the material section changed the font fine

class Window_Base < Window
 #--------------------------------------------------------------------------
 # * Overwite methods: colors
 #--------------------------------------------------------------------------
 def normal_color;	 text_color(0);   end;
 def system_color;	 text_color(2);   end;
 def crisis_color;	 text_color(4);   end;
 def knockout_color;	text_color(1);  end;
 def mp_cost_color;	 text_color(3);  end;
 def power_up_color;	text_color(3);  end;
 def power_down_color;  text_color(5);  end;
 def tp_cost_color;	 text_color(4);  end;
end

Edited by Victor Sant

Share this post


Link to post
Share on other sites
And i put those defs in another script below Material... maybe i put them wrong, can you give an example of how it should look?
how exactly you're doing?

 

if you want more speficif colors, you can go directily on the script and add the "text_color(n)" directly on the part you want do change the colors.

 

Example: I added this on Window_Gold:

def normal_color;	  text_color(4);   end;

And the white color (normal_color) was replaced with yellow. wich was the fifth font on the default list.

 

Using the default fonts i set and adding the following code on the material section changed the font fine

class Window_Base < Window
 #--------------------------------------------------------------------------
 # * Overwite methods: colors
 #--------------------------------------------------------------------------
 def normal_color;	 text_color(0);   end;
 def system_color;	 text_color(2);   end;
 def crisis_color;	 text_color(4);   end;
 def knockout_color;	text_color(1);  end;
 def mp_cost_color;	 text_color(3);  end;
 def power_up_color;	text_color(3);  end;
 def power_down_color;  text_color(5);  end;
 def tp_cost_color;	 text_color(4);  end;
end

 

 

Well, i add your script, i add the fonts as well, and i even add the extra thing you said to add for the colors, but for some reason, the only font it seems to want to use is the white one.

Please don't take this the wrong way, i'm not trying to be a jerk, but some times your instructions can be a little hard to figure out.

 

When the english version comes out and you can make a demo, that might help.

Edited by Michael Ponder Jr

Share this post


Link to post
Share on other sites

@Michael Ponder Jr

Post here your settings (the one insde the Module Victor_Engine) and the script you changed. If i see what exactly you did, i might figure out what is happening.

Share this post


Link to post
Share on other sites

I placed the script with your core script, where it needs to go.

Then i placed those defs in a small script above the sfont script, all i get is the white font that comes into use.

I remembered to have the folder for it as well, so i'm not sure what's going on with it, i just kind of figure i'm forgetting or leaving something out.

Share this post


Link to post
Share on other sites

That's the thing, i did not make any changes, i put it in as you said to put it in, there is nothing to show really.

#==============================================================================
# ** Victor Engine - SFont
#------------------------------------------------------------------------------
# Author : Victor Sant
#
# Aditional Credit :
#   - RubyGame  (Original Concept)
#   - Trickster (RubyGame SFont conversion to RPG Maker)
#
# Version History:
#  v 1.00 - 2011.12.21 - First relase
#------------------------------------------------------------------------------
#  This script allows the use of SFonts. SFonts is a image file that replaces
# the normal font.
#
# What are SFonts? (from http://rubygame.org/docs/)
# SFont is a type of bitmapped font, which is loaded from an image file with
# a meaningful top row of pixels, and the font itself below that. The top row
# provides information about what parts of of the lower area contains font
# data, and which parts are empty. The image file should contain all of the
# glyphs on one row, with the colorkey color at the bottom-left pixel and the
# "skip" color at the top-left pixel.
#
#------------------------------------------------------------------------------
# Compatibility
#   Requires the script 'Victor Engine - Basic Module'
#
# * Overwrite methods
#   None
#
# * Alias methods
#   class Bitmap
#	 def draw_text
#	 def text_size(str)
#
#   class << DataManager
#	 def create_game_objects
#
#   class Sprite_Timer < Sprite
#	 def create_bitmap
#
#   class Window_Base < Window
#	 def create_contents
#	 def text_color(n)
#
#------------------------------------------------------------------------------
# Instructions:
#  To instal the script, open you script editor and paste this script on
#  a new section on bellow the Materials section. This script must also
#  be bellow the script 'Victor Engine - Basic'
#  The SFonts must be placed on the folder "Graphics/SFonts". Create a folder
#  named "SFonts" on the Graphics folder.
#
#------------------------------------------------------------------------------
# Additional instructions:
#
#   On the SFont, the first pixel on the top left corner is considered the
#   "skip color", so, anywhere that this color appears on the first row
#   the part will be skiped, so use it to define the limit from each
#   character. At first it might be hard to get how it work.
#
#   If the constant ALL_SFONT is true, all fonts in all windows will be
#   replaced with SFonts, if false, you will need to add them manually
#   in the code (not recomended for begginers).
#
#   The method "text_color(n)" from Window_Base can be used to change
#   the SFont, where n is the SFont index on the SFONT_NAMES array.
#   (Remember that indexes starts at 0, not at 1)
#   Text on independent bitmaps (outside windows) will need to be changed
#   manually on the code.
#
#   The system colors can be changed on the Window_Base class, on the
#   following methods. Replace the number in text_color(x) with the index
#   of the color SFont on the SFONT_NAMES array.
#	def normal_color;	  text_color(0);   end;
#	def system_color;	  text_color(16);  end;
#	def crisis_color;	  text_color(17);  end;
#	def knockout_color;	text_color(18);  end;
#	def gauge_back_color;  text_color(19);  end;
#	def hp_gauge_color1;   text_color(20);  end;
#	def hp_gauge_color2;   text_color(21);  end;
#	def mp_gauge_color2;   text_color(23);  end;
#	def mp_gauge_color1;   text_color(22);  end;
#	def mp_cost_color;	 text_color(23);  end;
#	def power_up_color;	text_color(24);  end;
#	def power_down_color;  text_color(25);  end;
#	def tp_gauge_color1;   text_color(28);  end;
#	def tp_gauge_color2;   text_color(29);  end;
#	def tp_cost_color;	 text_color(29);  end;
#   If you don't feel like changing the default scripts just create a new
#   script on the Materials section for the class Window_Base and add these
#   medthods.
#
#==============================================================================

#==============================================================================
# ** Victor Engine
#------------------------------------------------------------------------------
#   Setting module for the Victor Engine
#==============================================================================

module Victor_Engine
 #--------------------------------------------------------------------------
 # * Set the use of SFonts for all windows
 #	If true all windows will use SFonts automatically, if false
 #	you must set them manually
 #--------------------------------------------------------------------------
 VE_ALL_SFONT = true
 #--------------------------------------------------------------------------
 # * Set SFonts
 #	Set here the name of the SFonts that will be used, add how many
 #	SFont names you want. Refer to the SFont bitmap with $sfont[index]
 #--------------------------------------------------------------------------
 VE_SFONT_NAMES = ["Arial White", "Arial Red", "Arial Blue", "Arial Green",
"Arial Yellow", "Arial Gray"]
 #--------------------------------------------------------------------------
 # * Set the digit list
 #	The order of the digits here define the order of of the digits on
 #	the image file, make sure to follow the same order or the text
 #	in game might be totally screwed.
 #	You can add how many characters you want, even complex character.
 #	the character here doesn't need to be exactly the same from the
 #	image file so you can use special characters to show icons and such.
 #--------------------------------------------------------------------------
 VE_SFONT_DIGITS = ["!",'"',"#","$","%","&","'","(",")","*","+",",","-",".",
 "/","0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?","@","A",
 "B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T",
 "U","V","W","X","Y","Z","[","\\","]","^","_","`","a","b","c","d","e","f","g",
 "h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
 "{","|","}","~"]
end

$imported[:ve_sfonts] = true

#==============================================================================
# ** Cache
#------------------------------------------------------------------------------
#  This module loads each of graphics, creates a Bitmap object, and retains it.
# To speed up load times and conserve memory, this module holds the created
# Bitmap object in the internal hash, allowing the program to return
# preexisting objects when the same bitmap is requested again.
#==============================================================================

module Cache
 #--------------------------------------------------------------------------
 # * New method: sfont
 #--------------------------------------------------------------------------
 def self.sfont(filename, hue = 0)
self.load_bitmap("Graphics/SFonts/", filename, hue)
 end
end

#==============================================================================
# ** Bitmap
#------------------------------------------------------------------------------
#  This class handles and draws the bitmaps
#==============================================================================

class Bitmap
 #--------------------------------------------------------------------------
 # * Public Instance Variables
 #--------------------------------------------------------------------------
 attr_accessor :sfont
 #--------------------------------------------------------------------------
 # * Alias method: draw_text
 #--------------------------------------------------------------------------
 alias :draw_text_ve_sfont :draw_text
 def draw_text(*args)
sfont ? draw_sfont_text(*args) : draw_text_ve_sfont(*args)
 end
 #--------------------------------------------------------------------------
 # * Alias method: draw_sfont_text
 #--------------------------------------------------------------------------
 def draw_sfont_text(*args)
is_rect = args[0].is_a?(Rect)
x	  = is_rect ? args[0].x	  : args[0]
y	  = is_rect ? args[0].y	  : args[1]
width  = is_rect ? args[0].width  : args[2]
height = is_rect ? args[0].height : args[3]
text   = is_rect ? args[1].to_s   : args[4].to_s
align  = is_rect ? args[2]		: args[5]
bitmap = sfont.draw_text(text)
x += width - bitmap.width	   if align == 2
x += (width - bitmap.width) / 2 if align == 1
y += (height - bitmap.height) / 2 - 4
blt(x, y, bitmap, bitmap.rect)
 end
 #--------------------------------------------------------------------------
 # * Alias method: text_size
 #--------------------------------------------------------------------------
 alias :text_size_ve_sfont :text_size
 def text_size(text)
sfont ? sfont.text_size(text) : text_size_ve_sfont(text)
 end
end

#==============================================================================
# ** DataManager
#------------------------------------------------------------------------------
#  This module handles the game and database objects used in game.
# Almost all global variables are initialized on this module
#==============================================================================

class << DataManager
 #--------------------------------------------------------------------------
 # * Alias method: create_game_objects
 #--------------------------------------------------------------------------
 alias :create_game_objects_ve_sfont :create_game_objects
 def create_game_objects
create_game_objects_ve_sfont
create_sfonts
 end
 #--------------------------------------------------------------------------
 # * New method: create_sfonts
 #--------------------------------------------------------------------------
 def create_sfonts
$sfont = VE_SFONT_NAMES.collect {|name| SFont.new(name)}
 end
end

#==============================================================================
# ** Sprite_Timer
#------------------------------------------------------------------------------
#  This sprite is used to display the timer. It observes the $game_system
# and automatically changes sprite conditions.
#==============================================================================

class Sprite_Timer < Sprite
 #--------------------------------------------------------------------------
 # * Alias method: create_bitmap
 #--------------------------------------------------------------------------
 alias :create_bitmap_ve_sfont :create_bitmap
 def create_bitmap
create_bitmap_ve_sfont
self.bitmap.sfont = $sfont[0] if VE_ALL_SFONT
 end
end

#==============================================================================
# ** Window_Base
#------------------------------------------------------------------------------
#  This is a superclass of all windows in the game.
#==============================================================================

class Window_Base < Window
 #--------------------------------------------------------------------------
 # * Alias method: create_contents
 #--------------------------------------------------------------------------
 alias :create_contents_ve_sfont :create_contents
 def create_contents
create_contents_ve_sfont
contents.sfont = $sfont[0] if VE_ALL_SFONT
 end
 #--------------------------------------------------------------------------
 # * Alias method: text_color
 #--------------------------------------------------------------------------
 alias :text_color_ve_sfont :text_color
 def text_color(n)
sfont(n)
text_color_ve_sfont(n)
 end
 #--------------------------------------------------------------------------
 # * Alias method: change_color
 #--------------------------------------------------------------------------
 alias :change_color_ve_sfont :change_color
 def change_color(color, enabled = true)
change_color_ve_sfont(color, enabled)
contents.sfont.alpha = enabled ? 255 : translucent_alpha
 end
 #--------------------------------------------------------------------------
 # * New method: sfont
 #--------------------------------------------------------------------------
 def sfont(n)
return if !contents.sfont
contents.sfont = $sfont[n] ? $sfont[n] : $sfont[0]
 end
end

#==============================================================================
# ** SFont
#------------------------------------------------------------------------------
#  This class handles the SFonts
#==============================================================================

class SFont
 #--------------------------------------------------------------------------
 # * Public Instance Variables
 #--------------------------------------------------------------------------
 attr_reader   :bitmap
 attr_accessor :alpha
 #--------------------------------------------------------------------------
 # * initialize
 #--------------------------------------------------------------------------
 def initialize(name)
@bitmap = Cache.sfont(name)
@height = @bitmap.height + 4
@skip   = @bitmap.get_pixel(0, 0)
@digits = VE_SFONT_DIGITS
@alpha  = 255
@values = {}
@values[" "] = Rect.new(-12, 0, 12, @height)
setup_digits
@values.default = @values[" "]
 end
 #--------------------------------------------------------------------------
 # * setup_digits
 #--------------------------------------------------------------------------
 def setup_digits
x1 = x2 = 0
@digits.each do |digit|
  x1 += 1 while @bitmap.get_pixel(x1, 0) == @skip && x1 < @bitmap.width
  x2 = x1	
  x2 += 1 while @bitmap.get_pixel(x2, 0) != @skip && x2 < @bitmap.width
  @values[digit] = Rect.new(x1, 0, x2 - x1, @height)
  x1 = x2
end
 end
 #--------------------------------------------------------------------------
 # * text_size
 #--------------------------------------------------------------------------
 def text_size(text)
size = 0
text.split("").each {|i| size += @values[i].width}
rect = Rect.new(0, 0, size, @height)
rect
 end
 #--------------------------------------------------------------------------
 # * draw_text
 #--------------------------------------------------------------------------
 def draw_text(text)
width = [text_size(text).width, 1].max
bitmap = Bitmap.new(width, @height)
x = 0
text.split("").each do |i|
  bitmap.blt(x, 4, @bitmap, @values[i], @alpha)
  x += @values[i].width
end
bitmap
 end
 #--------------------------------------------------------------------------
 # * dispose
 #--------------------------------------------------------------------------
 def dispose
return if !@bitmap || @bitmap.disposed?
@bitmap.dispose
 end
end

 

I put that in, then i put another script above it...

 

def normal_color;	  text_color(0);   end;
def system_color;	  text_color(16);  end;
def crisis_color;	  text_color(17);  end;
def knockout_color;	text_color(18);  end;
def gauge_back_color;  text_color(19);  end;
def hp_gauge_color1;   text_color(20);  end;
def hp_gauge_color2;   text_color(21);  end;
def mp_gauge_color2;   text_color(23);  end;
def mp_gauge_color1;   text_color(22);  end;
def mp_cost_color;	 text_color(23);  end;
def power_up_color;	text_color(24);  end;
def power_down_color;  text_color(25);  end;
def tp_gauge_color1;   text_color(28);  end;
def tp_gauge_color2;   text_color(29);  end;
def tp_cost_color;	 text_color(29);  end;

 

I put that in a script above it...

 

And the only font that's showing up is Arial White, everything is showing up with this font.

 

I'm trying to figure out why..... and what you are doing specifically..

Edited by Michael Ponder Jr

Share this post


Link to post
Share on other sites

@Michael Ponder Jr

 

# The system colors can be changed on the Window_Base class, on the

# following methods. Replace the number in text_color(x) with the index

# of the color SFont on the SFONT_NAMES array.

# def normal_color; text_color(0); end;

# def system_color; text_color(16); end;

# def crisis_color; text_color(17); end;

# def knockout_color; text_color(18); end;

# def mp_cost_color; text_color(23); end;

# def power_up_color; text_color(24); end;

# def power_down_color; text_color(25); end;

# def tp_cost_color; text_color(29); end;

# If you don't feel like changing the default scripts just create a new

# script on the Materials section for the class Window_Base and add these

# medthods.

 

 

Did you do the part in red, replace the numbers with the color index?

Share this post


Link to post
Share on other sites

That was the part i was misinterpreting, i did not know i had to change anything, just slap that list into script above the SFont script...

It was not clear to me exactly what i had to do, i figure it was a little more plug and use >_< sorry..

Share this post


Link to post
Share on other sites
# The method "text_color(n)" from Window_Base can be used to change

# the SFont, where n is the SFont index on the SFONT_NAMES array.

# (Remember that indexes starts at 0, not at 1)

So if you want the "system color" to be the blue color make

def system_color; text_color(2); end;

Why 2? As stated, index starts at 0

 

#                   index 0        index 1      index 2        index 3      index 4         index 5
VE_SFONT_NAMES = ["Arial White", "Arial Red", "Arial Blue", "Arial Green","Arial Yellow", "Arial Gray"]


Maybe i should make it a hash...

Edited by Victor Sant

Share this post


Link to post
Share on other sites

Yeah, that might help people like me who don't pick things up very well lol.. i'm not sure that would work too well, i'm not sure how far over a hash can go, and some people tend to over do it, they might have all kinds of fonts and colors going way over to the side.

 

I wonder if it still reads what's typed out that's WAY over to the side.

Share this post


Link to post
Share on other sites

I updated the script to work with hashes.

 

With a hash, instead of:

VE_SFONT_NAMES = ["Arial White", "Arial Red", "Arial Blue", "Arial Green","Arial Yellow", "Arial Gray"]

it will be:

VE_SFONT_NAMES = { 1 => "Arial White", 2 => "Arial Red", 3 => "Arial Blue", 4 => "Arial Green", 5 => "Arial Yellow", 6 => "Arial Gray"}

If someone can't get that they must use the number on the text_color(n) to get the font they want... they really should quit using this script.

Share this post


Link to post
Share on other sites

Awesome!

And thanks for all the hard work, you're awesome.

 

 

 

How would i use a separate set of fonts for the message box than what the menus use?

Was just an idea i had..

I like using a separate font style for the message boxes than what the menu and such uses.

 

Has anyone figured out how to set SFonts manually yet?

Edited by Michael Ponder Jr

Share this post


Link to post
Share on other sites

How did you get the colors to seperate like that?

 

Like how the menu is red..

 

The name is green...

 

The "0"/(maxhealth) is red...

 

Help me out please.

Share this post


Link to post
Share on other sites

With this script, if I want different sized fonts, or fonts in italics or bold, does each size and style require its own bitmap image?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
Top ArrowTop Arrow Highlighted