Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================================================
- # * [ACE] Font EX
- #===============================================================================
- # * Made by: Sixth (www.rpgmakervxace.net, www.forums.rpgmakerweb.com)
- # * Version: 1.3
- # * Updated: 25/10/2018
- # * Requires: -------
- #-------------------------------------------------------------------------------
- # * < Change Log >
- #-------------------------------------------------------------------------------
- # * Version 1.0 (27/11/2017)
- # - Initial release.
- # * Version 1.1 (18/03/2018)
- # - Fixed a specific issue with automatic line breaks and manual line breaks.
- # This issue happened only if the line which triggered the auto line break
- # is a single "word", and if the previous line had a manual line break
- # before a space (going backwards).
- # - Fixed some horizontal and vertical spacing issues. A lot of them.
- # - Added an option to enable the horizontal justified alignment type for
- # lines which consist of a single long word. If you enable it, the spacing
- # between the letters on these specific lines will be set to the same value,
- # or at least close to that (can't break down pixels to float values, so
- # there can be some inconsistency in the spacing, but that can only be seen
- # when your letters are kinda big compared to the reserved width of these
- # lines).
- # * Version 1.2 (10/10/2018)
- # - Changed the setting area for the preload feature. You can now specify
- # which character images to preload for each font style separately.
- # * Version 1.3 (25/10/2018)
- # - Added hue change option.
- # - Changed the cache clearing method to support clearing different hue
- # variants of character images.
- # - Added an option to display the text drawing area for individual texts for
- # easier debugging.
- # - Fixed a typo in the script call details. Opps!
- #-------------------------------------------------------------------------------
- # * < Description >
- #-------------------------------------------------------------------------------
- # * This is a scripter's tool, so it won't do anything by itself!
- # * With this script, you can display text using images on any bitmap object.
- # * The default text drawing method won't let you make fancy styles for your
- # fonts, it won't let you control the spacing between each characters, and
- # it can also be kinda slow. These were the main reasons I wrote this script.
- # * The new text drawing method has the following features:
- # - Automatic line-breaks.
- # - Separate alignment options horizontally and vertically (with automatic
- # line-breaks!).
- # Available alignment options:
- # ~ Left (horizontal) / Top (vertical)
- # ~ Middle
- # ~ Right (horizontal) / Bottom (vertical)
- # ~ Justified
- # - Full control over the horizontal spacing between each characters.
- # You can make default spacing settings and specific spacing settings which
- # will only trigger between the 2 specified characters.
- # - Full control over the speed of the character drawing.
- # You can setup a wait time for character drawing and make it wait that
- # many frames before the next character is drawn.
- # - Message sound effects.
- # Setup an SE for the character drawing. Use randomized effects or static
- # ones, play the effect after each characters or after several characters
- # periodically.
- # - Setup speed up keys for your messages.
- # In case your message's wait time is greater than 1 frame, you can
- # designate a key which when pressed will speed up the character drawing.
- # - Setup skip keys for your messages.
- # In case your message is not an instant one, you can designate a key which
- # when pressed will draw the remaining text instantly.
- # - Setup "wait for key input" pauses in your messages.
- # If you want to display your text periodically, with breaks between each
- # section, you can do by assigning break points in your text.
- # - Setup automatic position and width changes for each lines.
- # Sometimes we can't predict the exact line number where some words or
- # characters will end up, but we want to make sure that out text is
- # displayed in a well structured manner. And guess what? We are so lazy, we
- # want it to be done automatically whatever we may write in our messages! :D
- # Well, that is now possible, just setup the starting position and width of
- # each specific lines, and it's done!
- # - Setup automatic height changes for each lines.
- # The same principle as for the previous feature. Being lazy enough, we
- # surely don't want to format our text manually. What would be the point
- # of automatic line-breaks that way, right? So, if you want to, you can
- # setup the height of each specific lines in advance, and forget about it,
- # the drawing will do the rest for you automatically.
- # - Built-in text replacing message codes.
- # Just some basic stuffs here, such as:
- # ~ Variable value display.
- # ~ Actor name display (based on actor ID or party position).
- # ~ Actor's class name display (based on actor ID or party position).
- # ~ Skill, item, weapon, armor name display.
- # - Built-in special message codes:
- # ~ Drawing position modifier codes for moving the next character
- # left/right or moving the next line up/down.
- # ~ Wait time modifier code to change the wait time from the next character.
- # ~ Style changing code to change the font style used during the drawing.
- # ~ Break point code to stop the text drawing until a key is pressed.
- # - And of course, image based text drawing. Not the static one with static
- # character spacing, but the dynamic one with many customization options
- # right off the bat! The drawing method also uses the cache to speed up the
- # drawing, so it will most probably be much faster than the default text
- # drawing method.
- # - Ohh, and it works on ANY bitmap, so you can use it on ANY sprites/planes!
- #-------------------------------------------------------------------------------
- # * < Image Setup >
- #-------------------------------------------------------------------------------
- # * First thing first, you must setup your character images before you can
- # actually use this text drawing method, obviously.
- # I won't lie, this can be a pretty boring job, but once it's done, you can
- # use the completed character set any time you want in the future.
- # * Each font style used by this script must be in it's own separate folder!
- # You can setup the folder used for each font style separately in the script
- # settings, so you have full control over this too.
- # * You must have an image for each characters you use in your texts, even if
- # they are only used once during a 120 hours game (which is highly unlikely,
- # but still :D)! However, if you are sure that a character will not appear in
- # a given font style ever during your game, it is safe to leave that character
- # out from that font style's folder.
- # * The character images themselves must all have the same height in the same
- # style! This is to let you adjust the vertical positions of your characters
- # manually, since doing this automatically would lead to a pretty convoluted
- # setting area, which is not what most of us want, right?
- # This means that the height of your characters will always be the height
- # between the top of the tallest character and the bottom of the smallest
- # character. Well, this is the only way I can explain it, but if it's not
- # enough, you can check the PSD files in each font style folder, and check the
- # "Guide Lines" layer folder to see what I mean. I marked the important
- # vertical positioning lines there, so that I always know the vertical
- # positioning of my characters. Note that those layers are only there as a
- # guide, they do not affect anything in this script, nor are they needed for
- # this script to work!
- # * There can be no empty pixels on the left or right side on your character
- # images! The automatic character width calculation is based on the width of
- # the character images, that's why there should be no useless empty pixels
- # on the sides. The spacing between the characters itself can be setup for
- # each font styles separately in the script settings, so this part is not on
- # your character images at all.
- # * You can have whatever drawn on your character images. This script is meant
- # to be used for text drawing, but that is not the only thing you can draw
- # with it, it all depends on what you have on your character images.
- #-------------------------------------------------------------------------------
- # * < Usage Information >
- #-------------------------------------------------------------------------------
- # * No surprise, but you will need scripting knowledge to use this script.
- # For that reason, I will explain this part in a way that assumes that the
- # reader has sufficient knowledge about the relevant classes and scripting
- # in general.
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # * Here is the method call to trigger the new text drawing method:
- #
- # draw_text_fex_a( * options go here * )
- #
- # This method must be called on a Bitmap object!
- #
- # You have several named options you can use as arguments. All of them are
- # optional except the :txt argument, obviously. If you omit them, a default
- # value will be loaded for them automatically. The default values will be
- # noted for each options below.
- #
- # Here are all the options you can use:
- #
- # :x => value, # Default value: 0
- # :y => value, # Default value: 0
- # :w => value, # Default value: the bitmap's width
- # :h => value, # Default value: the bitmap's height
- # These will setup the drawing area on the bitmap. The drawing area plays a
- # huge part in text positioning along with the used alignment options.
- # All of them can be a single integer number representing pixels.
- # Aside from setting up a single value for them, you can also setup automatic
- # drawing area changes based on line numbers. This option is available for the
- # :x and :w arguments. To set them up this way, you will have to use a hash
- # with the following options:
- # :default => value,
- # This sets the default value. If a line does not have a custom value set up,
- # this value will be used automatically.
- # [line_num1,line_num2,...] => value,
- # This sets up custom values for the specified line numbers.
- # For example, setting up the :x argument like this:
- # :x => { :default => 4, [*4..7] => 82, [*12..16] => 46 },
- # Will make the starting X position for line 4 to 7 set to 82, and for line
- # 12 to 16 it will be set to 46. Any other lines will use 4 automatically.
- # Naturally, this would only make sense if you also change the :w argument
- # the same way, since otherwise you might get some text cut down on some
- # lines, or end up with a weirdly formatted text layout.
- # Using these options along with the alignment options you are able to format
- # your text layout in very specific ways.
- #
- # :vs => value, # Default value: loaded from the 'VertSp' settings
- # This will setup a custom vertical spacing between the lines.
- # In case you want to use a custom vertical spacing between your lines for
- # different texts, you can do so with this option.
- # Note that the vertical spacing is just the extra pixels added after each
- # lines, so it doesn't include the line's height! The line's height is
- # calculated automatically based on the height of your character images.
- # You can use a single integer value for this argument, or you can use a hash
- # to setup the vertical spacing for each lines separately, just like you can
- # with the :x and :w options.
- #
- # :ah => value, # Default value: 0
- # :av => value, # Default value: 0
- # These are the text alignment types used for the text drawing.
- # You can setup the horizontal (:ah) and vertical (:av) alignments separately
- # for more control over the text layout.
- # It's important to note that the alignment options will work even for
- # automatic line breaks! No other drawing methods I saw so far can do this.
- # Both of them can take 4 values, so you have 4 options for each of them.
- # 0 - Left (horizontal) / Top (vertical)
- # 1 - Middle (both)
- # 2 - Right (horizontal) / Bottom (vertical)
- # 3 - Justified (both)
- # Most of these alignment types are pretty self-explanatory.
- # Just to note an important fact:
- # The horizontal alignment will affect the horizontal placement of the text
- # together with your :x and :w options.
- # The vertical alignment will affect the vertical placement of the text
- # together with your :y and :h options.
- # The mentioned options are closely related, never forget this!
- # And a little extra not for the justified alignment options:
- # In case you don't know, this alignment type means that the spacing between
- # words (for horizontal alignment) and/or the spacing between lines (for
- # vertical alignment) will be the exact same for each line.
- # This will make each line have the exact same width (with 1 pixel difference
- # at most) in the case of horizontal alignment, and it will make the text use
- # up all of the available height for line-breaks in the case of vertical
- # alignment. This alignment type is mostly used in newspapers, where each
- # column of text has the same amount of width and the text columns have sharp
- # "edges" to clearly divide the columns from each other.
- # In the case of horizontal alignment, the lines will only trigger the
- # justified version if the line-break itself was made automatically! Manual
- # line breaks will simply apply the left side alignment for the line.
- # Well, if you want to know more about this alignment type, feel free to use
- # the almighty google, or just check it in a text editor program you use.
- #
- # :style => value, # Default value: 'default'
- # This option will setup the font style used for the text drawing.
- # Must be a string value, and a valid setting key from the 'Types' setting
- # found in the script!
- #
- # :opa => value, # Default value: 255
- # This will be the opacity of the text. Valid values: 0 - 255.
- # Note that the opacity will also be influenced by the opacity of the
- # sprite/plane the bitmap is assigned to.
- #
- # :hue => value, # Default value: 0
- # The hue of the character images. Valid values: 0 - 360.
- # In case you have a red character image set, and you don't want to make a
- # new image set for a blue one with the same font style, you can change the
- # hue value to make it blue without using a new image set.
- # Note that each character image with different hue values will be loaded
- # separately, so if you want to preload a style with multiple hue values, you
- # will have to add the hue values in the 'Preload' settings, otherwise they
- # won't be preloaded.
- #
- # :wait => value, # Default value: 0
- # This will setup the wait time between each character drawing.
- # Setting the value to 0 will make the text instant, while using positive
- # numbers will make the text drawn character by character.
- # Note that text sound effects can not be played for instant texts for pretty
- # obviosu reasons.
- # The wait time can be skipped and/or sped up by the player during the game if
- # you also use the :skip_key and/or :spd_key arguments for the text.
- #
- # :se => [file,volume,pitch,freq], # Default value: nil
- # This will setup a sound effect which will play after each character or after
- # each set of characters.
- # The file, volume and pitch options can take single values or an array with
- # multiple values. If you use an array for them, a random value will be
- # selected from the array each time the sound effect is triggered.
- # The values for the file option must be strings, and they must be valid
- # sound effect file names.
- # The values for the volume option must be integer numbers from 0 to 100.
- # The values for the pitch option must be integer numbers from 0 to 150.
- # Although I am not sure what is the highest value the pitch option can really
- # take, so that maximum value I noted above might be off.
- # The freq option must be an positive integer number! If you use 1, the sound
- # effect will be played after each character. If you use some higher values,
- # the sound effect will only play after that many characters.
- # If you don't use the :se option, there will be no sound effects played for
- # the text. Instant texts can not play sound effects for obvious reasons.
- #
- # :spd_key => value, # Default value: nil
- # If you use this option, and if the :wait option is set to something higher
- # than 1, the player can speed up the text drawing by holding down the
- # specified key.
- # The value must be a valid key symbol. If you use a custom input script, you
- # can use the key identifiers used from that script as well, as long as the
- # custom input script uses the default Input check methods for checking key
- # presses.
- # If you don't use this option, the player won't be able to speed up the text
- # display.
- #
- # :skip_key => value, # Default value: nil
- # If you use this option, and if the text is not an instant one, the player
- # can press a key to display the text instantly.
- # It takes the same values as the previous argument option.
- # Note that if the text got some break points set up with the provided
- # message code for it, the text will only be displayed to the next break
- # point! The player must pass the break point by pressing the specified key
- # set up for it in the message code in order to be able to use the skip
- # message key set up with this option again.
- # If you don't use this option, the player won't be able to skip the text
- # display.
- #
- # :txt => "text", # Default value: ""
- # And finally, maybe the most important option, the text you want to display.
- # Needless to say, this must be a string value.
- # While it has a default value set up, using that wouldn't make any sense, so
- # this option is kinda mandatory to use.
- #
- # :debug => true,
- # Using this option, you can enable the debug background for displaying the
- # drawing area of the text. The color of the drawing area will be the same as
- # the color you have setup in the 'Debug' settings.
- # This option got no editable parts. You use it if you want to enable the
- # debug background for the text, and you omit it if you don't want to display
- # that background.
- #
- # Quite a lot of options for a seemingly simple text drawing method, right?
- # Well, options are always nice to have, so never hold back with them. :P
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # * Here is the method call to update the new text drawing method:
- #
- # update_font_ex
- #
- # This method must be called on each frame on any bitmaps where you want to
- # display non-instant texts! Instant texts will be displayed even without
- # updating the bitmap with this method.
- # I added an option in the script which enables auto-updates for all bitmap
- # objects, but if you would like to manually decide which bitmaps should
- # update texts, you can simply disable that option and call this method on
- # your bitmap manually.
- #
- # What's the point of calling it manually if there is an automatic way to do
- # so? Well, even though not by much, doing it only on bitmaps with actual text
- # drawing (so only if you need it) is better performance-wise.
- # The only thing running on bitmaps without actual text drawing is the check
- # for text data, so it really shouldn't slow down anything, but for
- # perfectionists, I decided to allow the disabling of the automatic update
- # method.
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # * Here is the method to clear the font cache:
- #
- # Cache.clear_font_ex('style_key', ['style_key',hue], ...)
- #
- # The new text drawing method uses the cache to speed up the text drawing.
- # The first time you draw a text with a font style, you might experience a
- # small lag spike. That is when the character images are loaded into the
- # cache. You can try to pre-load your character images to avoid this
- # completely, in fact, I recommend you do so.
- #
- # While I do not recommend clearing the font cache at all during the game, you
- # can do it with this method.
- # This method accepts any amount of arguments, so you can clear any amount of
- # font styles with it from the cache.
- #
- # You can use 2 types of arguments:
- #
- # 1. A simple 'style_key' from the 'Types' setting area.
- # This one will clear the character images used for the specified font style.
- # If you use this type of argument, the code will assume that the hue value of
- # the images needed to be cleared is 0 (which is the default hue value).
- #
- # 2. An array of 2 elements: 'style_key' and hue value, in this order.
- # With this argument type, you can specify the hue value of the style you want
- # to clear. Each hue value will have it's own character image stored in the
- # cache, so if you want to get rid of them for real, you will have to clear
- # all used hue variants as well.
- #
- # You can combine the 2 argument types if needed.
- # All characters from the specified font styles and hue values (if specified)
- # will be cleared from the cache after this script call.
- #
- # Leaving the character images in the cache should not consume much RAM, but
- # it really depends on the file size of your character images, so I can't
- # guarantee that it is impossible to overload the RAM with it. Although, doing
- # that would require quite big file sizes, so the chance of that happening is
- # very low.
- #-------------------------------------------------------------------------------
- # * < Built-in Text Message Codes >
- #-------------------------------------------------------------------------------
- # * I added several commonly used message codes which will automatically replace
- # themselves with the specified data.
- # Here is a list of these message codes:
- #
- # <VAR: ID> # Displays the value of the variable.
- # <ANAME: ID> # Displays the name of the actor based on actor ID.
- # <MNAME: ID> # Displays the name of the actor based on party position.
- # <ACLASS: ID> # Displays the class of the actor based on actor ID.
- # <MCLASS: ID> # Displays the class of the actor based on party position.
- # <ANICK: ID> # Displays the nickname of the actor based on actor ID.
- # <MNICK: ID> # Displays the nickname of the actor based on party position.
- # <ITEM: ID> # Displays the name of the item.
- # <WEAPON: ID> # Displays the name of the weapon.
- # <ARMOR: ID> # Displays the name of the armor.
- # <SKILL: ID> # Displays the name of the skill.
- # <STATE: ID> # Displays the name of the state.
- # <CLASS: ID> # Displays the name of the class.
- #
- # The message code identifiers (VAR, ACTOR, etc) are not case-sensitive, so if
- # you prefer lower-case letters, you can write them that way too.
- #
- # The variable display will be replaced first, so, in theory, you can display
- # all other message codes based on a variable as well by using the variable
- # message code as their ID. But I never tested this, so don't yell on me if
- # this doesn't actually work. :P
- #
- # If you want to add your own message codes, feel free to do so. Since this
- # scriptt requires scripting knowledge, I won't explain how to do it. It is
- # pretty easy to find these message codes in the code, so adding new ones
- # should not be a problem for anyone.
- #-------------------------------------------------------------------------------
- # * < Built-in Function Message Codes >
- #-------------------------------------------------------------------------------
- # * These are message codes which will add some new features for your text
- # drawing, or change some aspects of it during the drawing itself.
- # Here is a list of available message codes in this section:
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # <S: FONT_STYLE>
- #
- # Changes the font style.
- # The new font style is loaded for the next normal character after this
- # message code.
- # You must replace the FONT_STYLE part with a valid setting key from the
- # 'Types' settings found in this script.
- #
- # Note that if there are multiple font styles on the same line, the Y position
- # of the characters will be the same, aligned to the bottom of the line height
- # line. This means that in this case, some font styles might not look good if
- # combined with other font styles if they got different heights. This all
- # depends on how you position your characters on your images vertically, so if
- # you plan your fonts well, they might not have any visual awkwardness at all.
- #
- # Also, if there are multiple font styles on the same lines, the line height
- # will be taken from the tallest font style to keep enough space for all
- # characters.
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # <H: VALUE>
- #
- # Changes the hue for the following characters.
- # Replace VALUE with an integer number between 0 and 360.
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # <X: VALUE>
- #
- # Moves the rest of the line to the left or right.
- # The X position added this way will be reset on each new lines!
- # The VALUE must be a positive or negative integer number.
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # <Y: VALUE>
- #
- # Moves the next line this many pixels downwards.
- # The rest of the lines below the first affected one will get their Y position
- # corrected automatically.
- # You can only use positive integer numbers for the VALUE here.
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # <W: VALUE>
- #
- # Sets up a new wait time between characters.
- # The VALUE must be an integer number, positive or 0 (0 = instant text).
- # Can be good to use if you want to display some parts of the text slower or
- # quicker.
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # <K: KEY>
- #
- # Sets up a break point in the text.
- # What is a break point? Well, it is a point where the text will stop
- # advancing until the player presses a key.
- # These break points can NOT be skipped with the :skip_key option used in the
- # draw_text_fex script call, they can only be skipped by pressing the
- # designated key you specified in this message code.
- # The KEY must be replaced with a valid key identifier. If you use a custom
- # input script, you can use the key identifiers from that script as well, as
- # long as that custom input script uses the default Input check methods.
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # * Note for scripters:
- # All of the function message codes operate by recording the character
- # positions they are placed in the text. This means that ALL of them must be
- # obtained, processed and replaced with a single swoop, otherwise the recorded
- # positions WILL get messed up. You are free to add in your own function codes
- # if you want, just be aware that you can't simply do a .gsub! on the text
- # because that will get you wrong position recordings. Check how this part of
- # the code is written, you should be able to figure out the rest from there.
- #
- # As a last note, your message codes must NOT contain any > signs aside from
- # the message code closure point! The regex I used will break the message
- # code at the first > sign found, so if you would add that sign in the key or
- # in the parameter of the message code, your message code will most probably
- # NOT function at all.
- #-------------------------------------------------------------------------------
- # * < Installation >
- #-------------------------------------------------------------------------------
- # * Place this script below Materials but above Main!
- #-------------------------------------------------------------------------------
- # * < Compatibility Info >
- #-------------------------------------------------------------------------------
- # * No known incompatibilities.
- #-------------------------------------------------------------------------------
- # * < Known Issues >
- #-------------------------------------------------------------------------------
- # * No known issues.
- #-------------------------------------------------------------------------------
- # * < Terms of Use >
- #-------------------------------------------------------------------------------
- # * Free to use for whatever purposes you want.
- # * Credit me (Sixth) in your game, pretty please! :P
- # * Posting modified versions of this script is allowed as long as you notice me
- # about it with a link to it!
- #===============================================================================
- $imported = {} if $imported.nil?
- $imported["SixthFontEX"] = true
- #===============================================================================
- # Settings:
- #===============================================================================
- module FontEX
- #-----------------------------------------------------------------------------
- # Character Settings:
- #-----------------------------------------------------------------------------
- # This is where you will setup the character list and their image names.
- # Each character you want to use in any font style must be specified here.
- #
- # Format:
- #
- # 'character' => 'filename',
- #
- # The character can be any valid character, really.
- # Although, sadly, the font type used in this editor does not support some
- # (well, a lot of) extra character symbols, so you won't be able to set those
- # up here.
- #
- # There are some extra characters which are normally not displayed, but you
- # can still specify a filename for them and use them in your texts.
- # One of them, for example, is the "\t" character, which denotes the paragraph
- # character when the TAB key is pressed.
- # The only special character which is processed automatically is the "\n"
- # character which denotes a line-break. That won't be displayed at all, it
- # will just start a new line, like it would normally.
- #
- # And this is a good place to state that you can insert a manual line-break
- # with the "\n" character in your texts.
- #
- # The list I made contains most of the basic characters (letters, numbers,
- # signs, etc) and some extra ones as well, but it is far from including all
- # of the displayable characters, so feel free to add your own character
- # settings here.
- #
- # The character images must be named the same way in all of your font style
- # folders!
- #
- # I have noted some of the settings here with a "No image file setup!" line.
- # That means that these characters don't have a character image for any font
- # style I made, so they are unusable in your texts until you make an image
- # for them.
- #-----------------------------------------------------------------------------
- Chs = {
- # Spaces:
- ' ' => 'space',
- "\t" => 'tab',
- # Lowercase letters:
- 'a' => 'a_lc',
- 'b' => 'b_lc',
- 'c' => 'c_lc',
- 'd' => 'd_lc',
- 'e' => 'e_lc',
- 'f' => 'f_lc',
- 'g' => 'g_lc',
- 'h' => 'h_lc',
- 'i' => 'i_lc',
- 'j' => 'j_lc',
- 'k' => 'k_lc',
- 'l' => 'l_lc',
- 'm' => 'm_lc',
- 'n' => 'n_lc',
- 'o' => 'o_lc',
- 'p' => 'p_lc',
- 'q' => 'q_lc',
- 'r' => 'r_lc',
- 's' => 's_lc',
- 't' => 't_lc',
- 'u' => 'u_lc',
- 'v' => 'v_lc',
- 'w' => 'w_lc',
- 'x' => 'x_lc',
- 'y' => 'y_lc',
- 'z' => 'z_lc',
- # Uppercase letters:
- 'A' => 'a_uc',
- 'B' => 'b_uc',
- 'C' => 'c_uc',
- 'D' => 'd_uc',
- 'E' => 'e_uc',
- 'F' => 'f_uc',
- 'G' => 'g_uc',
- 'H' => 'h_uc',
- 'I' => 'i_uc',
- 'J' => 'j_uc',
- 'K' => 'k_uc',
- 'L' => 'l_uc',
- 'M' => 'm_uc',
- 'N' => 'n_uc',
- 'O' => 'o_uc',
- 'P' => 'p_uc',
- 'Q' => 'q_uc',
- 'R' => 'r_uc',
- 'S' => 's_uc',
- 'T' => 't_uc',
- 'U' => 'u_uc',
- 'V' => 'v_uc',
- 'W' => 'w_uc',
- 'X' => 'x_uc',
- 'Y' => 'y_uc',
- 'Z' => 'z_uc',
- # Numbers:
- '0' => '0',
- '1' => '1',
- '2' => '2',
- '3' => '3',
- '4' => '4',
- '5' => '5',
- '6' => '6',
- '7' => '7',
- '8' => '8',
- '9' => '9',
- # Signs:
- '.' => 'point',
- ',' => 'comma',
- ';' => 'semicolon',
- ':' => 'doublepoint',
- '!' => 'exclamation',
- '?' => 'question',
- '_' => 'underscore',
- "'" => 'apostrophe1',
- '`' => 'apostrophe2',
- #'’' => 'apostrophe3', # No image file setup!
- '"' => 'quote',
- #'“' => 'quote1', # No image file setup!
- #'”' => 'quote2', # No image file setup!
- '@' => 'at',
- '#' => 'numero',
- '$' => 'dollar',
- '€' => 'euro',
- '£' => 'pound',
- "\\" => 'lbrace',
- '/' => 'rbrace',
- # Math:
- '+' => 'plus',
- '-' => 'minus',
- '*' => 'multiply',
- '÷' => 'divide',
- '=' => 'equal',
- '~' => 'approx',
- '%' => 'percent',
- '^' => 'on_square',
- '&' => 'and',
- '|' => 'or',
- '(' => 'lbracket_normal',
- ')' => 'rbracket_normal',
- '[' => 'lbracket_square',
- ']' => 'rbracket_square',
- '{' => 'lbracket_curly',
- '}' => 'rbracket_curly',
- '<' => 'smaller',
- '>' => 'higher',
- # <-- Add more character settings here if needed!
- }
- #-----------------------------------------------------------------------------
- # Font Style Settings:
- #-----------------------------------------------------------------------------
- # This is the place where you can setup the identifiers and folders used for
- # your different font styles.
- # You will use the setting keys from this setting in all font style related
- # things in the provided script calls and message codes.
- #
- # Format:
- #
- # 'style_key' => "folder_path/",
- #
- # You can make as many font style settings as you want.
- #
- # If you don't setup a :style argument for the text drawing script call,
- # the 'default' font style will be used automatically.
- #-----------------------------------------------------------------------------
- Types = {
- 'default' => "Graphics/FontEX/Microsoft Himalaya/s23_white_gray_grad/",
- 'mod_up' => "Graphics/FontEX/Microsoft Himalaya/s23_green_grad/",
- 'card_name' => "Graphics/FontEX/MatrixBoldSmallCaps/s23_black_white/",
- 'card_desc' => "Graphics/FontEX/Tw Cen MT Condensed/s15_white/",
- 'card_desc2' => "Graphics/FontEX/Tw Cen MT Condensed/s16_white_small_caps/",
- 'card_desc3' => "Graphics/FontEX/Tw Cen MT Condensed/s16_black_small_caps/",
- 'check_value' => "Graphics/FontEX/Tw Cen MT Condensed/s20_white_small_caps/",
- 'hp_value' => "Graphics/FontEX/WST_Engl/s21_green_grad/",
- 'ap_value' => "Graphics/FontEX/WST_Engl/s21_yellow_grad/",
- 'lvl_value' => "Graphics/FontEX/WST_Engl/s21_blue_grad/",
- 'xp_value' => "Graphics/FontEX/WST_Engl/s20_blue_grad/",
- 'icons' => "Graphics/FontEX/Icons/",
- # <-- Add more font style settings here if needed!
- }
- #-----------------------------------------------------------------------------
- # Horizontal Spacing Settings:
- #-----------------------------------------------------------------------------
- # This is where you will setup the horizontal spacing between the characters
- # for your font styles.
- #
- # You have multiple ways to set these up. I will list them now...
- #
- # 'rescue' => value,
- # If the 'rescue' key is used, that means that this setting will be loaded for
- # any characters which got no custom spacing setting set up.
- # The very first setting here is a default spacing setting for ALL of your
- # font styles. In case a font style got no setting at all here, or if a
- # character got no spacing setting in a font style and the font style got no
- # separate 'rescue' setting, this first 'rescue' setting will be used instead.
- # You can have a 'rescue' setting for each of your font styles.
- #
- # 'character' => value,
- # This one will setup the spacing used after the specified character. This
- # spacing is only used for the specified character.
- #
- # 'character1character2' => value,
- # And this one is the most specific spacing setting you can use.
- # This will setup the spacing used between the 2 characters used in the
- # setting key. This setting type will only be triggered if the character after
- # 'character1' is 'character2'!
- #
- # So, by using the above setting options, you can setup a custom spacing
- # setting group for each of your font styles. Just follow this format:
- #
- # 'style_key' => {
- # 'setting1' => value,
- # 'setting2' => value,
- # ...
- # },
- #
- # The 'style_key' must be a valid setting key used in the 'Types' setting
- # area found above.
- # You can add as many settings in these setting groups as you want, and you
- # can make as many font style group settings as you want too.
- #-----------------------------------------------------------------------------
- HorzSp = {
- 'rescue' => 0, # Default spacing for all characters for all font styles
- 'default' => {
- 'rescue' => 0, # Default spacing for all characters for this style only
- 'av' => -2, # Spacing between lower-case a and v
- 'Av' => -1, # Spacing between upper-case A and lower-case v
- 'AV' => -1, # Spacing between upper-case A and V
- 'ly' => -1, # Spacing between lower-case l and y
- 'rv' => -1,
- },
- 'mod_up' => {
- 'rescue' => -2, # Default spacing for all characters for this style only
- 'av' => -4, # Spacing between lower-case a and v
- 'Av' => -3, # Spacing between upper-case A and lower-case v
- 'AV' => -3, # Spacing between upper-case A and V
- 'ly' => -3, # Spacing between lower-case l and y
- },
- 'card_name' => {
- 'rescue' => -1, # Default spacing for all characters for this style only
- },
- 'card_desc' => {
- 'rescue' => 1, # Default spacing for all characters for this style only
- },
- 'card_desc2' => {
- 'rescue' => 1, # Default spacing for all characters for this style only
- },
- 'card_desc3' => {
- 'rescue' => 1, # Default spacing for all characters for this style only
- },
- 'check_value' => {
- 'rescue' => 1, # Default spacing for all characters for this style only
- },
- 'icons' => {
- 'rescue' => 2,
- },
- # <-- Add more horizontal spacing settings here if needed!
- }
- #-----------------------------------------------------------------------------
- # Vertical Spacing Settings:
- #-----------------------------------------------------------------------------
- # This is where you will setup the extra vertical spacing between the lines.
- #
- # The line height will be automatically calculated based on the character
- # images' height. The vertical spacing value will be added to the line height,
- # and the result will decide the Y position of the next line after a
- # line-break.
- #
- # Format:
- #
- # 'style_key' => value,
- #
- # The 'style_key' must be a valid setting key used in the 'Types' setting
- # area found above.
- # The value is the amount of pixels to add to the line height (or in other
- # words, the amount of pixels between each lines).
- #
- # Note that these are just the default values your font styles will use.
- # You can use a custom vertical spacing value with the draw_text_fex method's
- # :vs option if you want.
- #
- # The 'rescue' setting will be used automatically if there is no setting made
- # for a font style and if no custom vertical spacing has been set up with the
- # above mentioned :vs option.
- #-----------------------------------------------------------------------------
- VertSp = {
- 'rescue' => 1, # Default for all font styles.
- 'default' => 2,
- 'mod_up' => 1,
- 'card_name' => 2,
- 'card_desc' => 4,
- 'card_desc2' => 1,
- 'card_desc3' => 1,
- 'check_value' => 2,
- 'icons' => 2,
- # <-- Add more vertical spacing settings here if needed!
- }
- #-----------------------------------------------------------------------------
- # Preload Font Styles Settings:
- #-----------------------------------------------------------------------------
- # You can choose the font styles you want to be preloaded on game startup.
- # Doing this will prevent the lag-spike which would happen otherwise the first
- # time you use a font style with an instant text drawing.
- # I recommend loading every commonly used font styles here, but it is your
- # choice to do so at the end, it is not mandatory for this script to work.
- #
- # You have several ways of preloading your font styles here.
- #
- # 1. Load all characters for a font style:
- # To do this, simply enter a setting that looks like this:
- # 'style_key' => {},
- # Replace the 'style_key' with a valid setting key from the 'Types' setting
- # area found above.
- # This will load the images for all of the characters you made in the 'Chs'
- # setting area.
- # If you use certain font styles for displaying numbers only, you shouldn't
- # load all characters for them, obviously, only the numbers, for example.
- #
- # 2. Load specific characters only:
- # To do this, enter a setting that looks like this:
- # 'style_key' => {
- # :load => ['ch1', 'ch2', ..., 'chN'],
- # },
- # The 'style_key' is the same as in the above setting type.
- # The 'ch1', 'ch2', and so on, must be valid setting keys from the 'Chs'
- # setting area. Only the images for the entered characters will be
- # preloaded. The rest of the characters will only be loaded on demand, so
- # only if you use them during the game at any point.
- # You can enter as many character keys as you want in the array.
- # If you only use numbers from a font style, for example, this is the
- # setting type you should use for it. Same if you only have Russian letters
- # made for a font style and want to preload them, you will have to use this
- # type of setting in that case too.
- #
- # 3. Skip specific characters, load all others:
- # To do this, enter a setting that looks like this:
- # 'style_key' => {
- # :skip => ['ch1', 'ch2', ..., 'chN'],
- # },
- # The editable parts are the same as in the previous setting type, but this
- # time, instead of specifying which ones to preload, you specifiy which ones
- # NOT to preload, in other words, which ones to skip.
- # All of the characters you enter into the array will be skipped, so they
- # won't be preloaded on startup, and all of the characters you DON'T enter
- # will be preloaded.
- #
- # These are the 3 ways you can setup the preload behaviour for your font
- # styles.
- #
- # Additionally, you can mix the last 2 setting types if you want, but the use
- # of that setting type is pretty limited, so I won't go into details on that.
- #
- # If you don't enter any settings for a font style here, the character images
- # for that font type will NOT be preloaded at all. You can still use them in
- # the game, of course, but they will only be loaded on demand and not on game
- # startup.
- #
- # From v1.3, you can also enter preload settings for different hue values.
- # You can do that by adding a setting option like this:
- # 'style_key' => {
- # :hue => {
- # hue_value1 => { * :load or :skip setting here if needed * },
- # hue_value2 => { * :load or :skip setting here if needed * },
- # ...
- # },
- # },
- # As you can see, you can add as many hue values as you want.
- # Replace the hue_valueX parts with integer numbers between 0 and 360.
- # Although using 0 is not necessary if you have setup the preload settings
- # for the font style outside the :hue option, since those settings will load
- # the default hue version of the character set, and the default hue is 0.
- # And the :load/:skip settings are the same like in the "hue-less" setting
- # options, so you can use them the same way.
- # If you use a hue changed character set without preloading them, they will
- # be loaded on demand only, just like the regular, not preloaded character
- # images.
- #-----------------------------------------------------------------------------
- Preload = [
- #'default' => {}, # Preload all letters
- #'rus_1' => {
- # :load => [ # Load only these letters
- # 'А','Б','В','Г','Д','Е','Ж','З','И','Й','К','Л','М','Н','О','П',
- # 'Р','С','Т','У','Ф','Х','Ц','Ч','Ш','Щ','Ъ','Ы','Ь','Э','Ю','Я',
- # ],
- #},
- ]
- #-----------------------------------------------------------------------------
- # Auto Update Settings:
- #-----------------------------------------------------------------------------
- # The bitmaps with non-instant text drawings must be updated in each frames.
- # This script can do that automatically or you can do it manually yourself in
- # your own code.
- # Setting the below options to true will enable the automatic text drawing
- # update for all bitmaps assigned for the specified objects.
- # Set them to false to disable this feature for them.
- #-----------------------------------------------------------------------------
- Auto = {
- :sprite => true,
- :window => true,
- }
- #-----------------------------------------------------------------------------
- # Debug Settings:
- #-----------------------------------------------------------------------------
- # Sometimes it is annoying to guess the drawing area for the texts.
- # Okay, it's always annoying...
- # For that reason, I added a debug feature which will paint the specified
- # drawing area for the texts drawn with this script.
- #
- # The setting options here should be self-explanatory.
- #-----------------------------------------------------------------------------
- Debug = {
- :enable => false, # Set it to true to enable or false to disable.
- :color => Color.new(255,100,100,220), # The color of the drawing area.
- }
- #-----------------------------------------------------------------------------
- # Miscellaneous Settings:
- #-----------------------------------------------------------------------------
- # Any other settings not fitting into the other setting areas will go here.
- # For now, there is only one lonely option here...
- #
- # :single => true/false,
- # This is an experimental feature, and quite honestly, not very useful for
- # most people. I explained what this option does in the update logs, so check
- # for the details there.
- # Setting this option to true will enable this feature, while setting it to
- # false will disable it.
- #-----------------------------------------------------------------------------
- Misc = {
- :single => false,
- }
- end
- #===============================================================================
- # End of settings! O.o
- #===============================================================================
- module Cache
- @font_ex_cache = {}
- def self.font_ex(fname,folder,hue=0)
- fky = [folder,hue]
- @font_ex_cache[fky] = [] if @font_ex_cache[fky].nil?
- @font_ex_cache[fky] << fname unless @font_ex_cache[fky].include?(fname)
- load_bitmap(folder,fname,hue)
- end
- def self.clear_font_ex(*styles)
- styles.each do |style|
- case style
- when Array
- folder = FontEX::Types[style[0]]
- fky = [folder,style[1]]
- else
- folder = FontEX::Types[style]
- fky = [folder,0]
- end
- next unless @font_ex_cache[fky]
- @font_ex_cache[fky].each do |img|
- if fky[1] == 0 # No hue change
- ky = folder + img
- else # Custom hue
- ky = [folder + img,fky[1]]
- end
- @cache[ky].dispose
- @cache.delete(ky)
- end
- @font_ex_cache.delete(fky)
- end
- end
- def self.preload_styles(styles)
- styles.each do |style,sdt|
- # Load normal characters, no hue change
- letters = (sdt[:load] || FontEX::Chs.keys).clone
- letters -= sdt[:skip] if sdt[:skip]
- letters.each {|ch| Cache.font_ex(FontEX::Chs[ch],FontEX::Types[style],0) }
- if sdt[:hue] # Load custom hue types if there is any
- sdt[:hue].each do |hue,hdt|
- letters = (hdt[:load] || FontEX::Chs.keys).clone
- letters -= hdt[:skip] if hdt[:skip]
- letters.each {|ch| Cache.font_ex(FontEX::Chs[ch],FontEX::Types[style],hue) }
- end
- end
- end
- end
- end
- Cache.preload_styles(FontEX::Preload)
- class Bitmap
- attr_accessor :fex
- def char_horz_sp(char,style,nchar=nil)
- if nchar
- ky = char + nchar
- if FontEX::HorzSp[style] && FontEX::HorzSp[style][ky]
- return FontEX::HorzSp[style][ky]
- end
- end
- if FontEX::HorzSp[style] && FontEX::HorzSp[style][char]
- return FontEX::HorzSp[style][char] # There is a set value for the char
- elsif FontEX::HorzSp[style] && FontEX::HorzSp[style]['rescue']
- return FontEX::HorzSp[style]['rescue'] # There is a set value for the font style
- else
- return FontEX::HorzSp['rescue'] # Load default spacing value
- end
- end
- def char_vert_sp(vsp,style,lnum)
- if vsp.is_a?(Hash)
- sv = vsp.find {|lnums,nh| lnums.is_a?(Array) && lnums.include?(lnum) }
- vh = sv ? sv[1] : vsp[:default]
- vh = (FontEX::VertSp[style] || FontEX::VertSp['rescue']) if vh == :style
- return vh
- else
- return vsp
- end
- end
- def debug_back_paint(xx,yy,ww,hh)
- if xx.is_a?(Hash)
- mx = xx.values.min_by {|val| val }
- else
- mx = xx
- end
- if ww.is_a?(Hash)
- mw = ww.values.max_by {|val| val }
- else
- mw = ww
- end
- fill_rect(mx,yy,mw,hh,FontEX::Debug[:color])
- end
- def draw_text_fex_a(args={})
- if @fex.nil?
- @fex = []
- else
- @fex.reject! {|fdt| fdt[:done] }
- end
- # Setting up all the data for the text
- dt = {
- :x => 0, :y => 0, :w => self.width, :h => self.height, :wait => 0, :hue => 0,
- :ah => 0, :av => 0, :opa => 255, :style => 'default', :lines => {}, :debug => false,
- :mods => {'s' => {}, 'x' => {}, 'y' => {}, 'w' => {}, 'k' => {}, 'h' => {}},
- :done => false, :spd_key => nil, :skip_key => nil, :se => nil, :txt => "",
- }.merge(args)
- dt[:wait] -= 1
- dt[:num] = dt[:wait]
- dt[:vs] = (FontEX::VertSp[dt[:style]] || FontEX::VertSp['rescue']) if dt[:vs].nil?
- @fex << dt
- dt[:txt] = process_text_fex(dt[:txt])
- ori_font = dt[:style].clone
- ori_hue = dt[:hue]
- debug_back_paint(dt[:x],dt[:y],dt[:w],dt[:h]) if FontEX::Debug[:enable] || dt[:debug]
- ax = 0 # Stores the X value added after the last character
- ay = char_vert_sp(dt[:vs],dt[:style],0) # Vertical spacing
- tw = 0 # Total width
- ch_h = 0
- ci = 0
- hsp = 0
- ch_w = []
- r_h = [] # Records previous line height values
- rym = 0
- spaces = 0
- last = 0
- loop do
- ch = dt[:txt][ci,1] # Current character
- break if ch.nil? || ch == ""
- if dt[:mods]['s'][ci] # Style change found!
- dt[:style] = dt[:mods]['s'][ci]
- vsp = char_vert_sp(dt[:vs],dt[:style],dt[:lines].size)
- ay = vsp if ay < vsp
- end
- if dt[:mods]['h'][ci] # Hue change found!
- dt[:hue] = dt[:mods]['h'][ci]
- end
- if ch == "\n" || ch == "\r\n"
- lw = tw
- pch = dt[:txt][ci-1,1]
- lw -= char_horz_sp(pch,dt[:style]) if pch && pch != ""
- if spaces > 0
- clw = lwidth(dt[:w],dt[:lines].size)
- sp = (clw - lw)/spaces.to_f
- else
- clw = lwidth(dt[:w],dt[:lines].size)
- sp = clw - lw
- end
- dt[:lines][ci] = {:w => lw, :ch => ch_h, :vs => ay, :ry => rym, :sp => 0.0}
- tw = 0
- ay = char_vert_sp(dt[:vs],dt[:style],dt[:lines].size)
- ch_h = 0
- spaces = 0
- rym = 0
- ci += 1
- next
- end
- if dt[:mods]['x'][ci]
- tw += dt[:mods]['x'][ci].to_i
- end
- if dt[:mods]['y'][ci]
- rym += dt[:mods]['y'][ci].to_i
- end
- img = Cache.font_ex(FontEX::Chs[ch],FontEX::Types[dt[:style]],dt[:hue])
- ch_h = img.height if ch_h < img.height
- ry = ch_h - img.height
- rym = ry if rym < ry
- r_h[ci] = [ch_h,rym,ay]
- nch = dt[:txt][ci+1,1]
- hsp = char_horz_sp(ch,dt[:style],nch) # Horizontal spacing
- ax = img.width + hsp # Added x after the character
- ch_w[ci] = [img.width,hsp,ch_h,rym] if ch_w[ci].nil? # Stores the width of the char
- tw += img.width
- spaces += 1 if ch == ' '
- if break_line?(tw,dt[:w],dt[:lines].size) # Line-break needed
- if ch == ' ' # The character is a space
- phsp = char_horz_sp(dt[:txt][ci-1,1],dt[:style],ch)
- lw = tw - img.width - phsp
- spaces -= 1
- if spaces > 0
- clw = lwidth(dt[:w],dt[:lines].size)
- sp = (clw - lw)/spaces.to_f
- else
- clw = lwidth(dt[:w],dt[:lines].size)
- sp = clw - lw.to_f
- end
- last = ci + 1
- # Starts a new line and leaves the space char on the prev line
- dt[:lines][ci+1] = {:w => lw, :ch => ch_h, :vs => ay, :ry => rym, :sp => sp}
- else
- oci = ci
- ostyle = dt[:style]
- #pstyle = dt[:style]
- orym = rym
- och_h = ch_h
- oay = ay
- subw = -hsp
- until [" ","\t","\n","\r\n"].include?(dt[:txt][ci]) || ci == last
- if dt[:mods]['s'][ci] # Style change found!
- pstyle = dt[:mods]['s'].find {|cid,dt| cid < ci }
- if pstyle # Previous style change found
- dt[:style] = pstyle[1]
- else # No other style change found, load original style
- dt[:style] = ori_font
- end
- vsp = char_vert_sp(dt[:vs],dt[:style],dt[:lines].size)
- ay = vsp if ay < vsp
- end
- if dt[:mods]['h'][ci] # Hue change found!
- phue = dt[:mods]['h'].find {|cid,dt| cid < ci }
- if phue # Previous hue change found
- dt[:hue] = phue[1]
- else # No other hue change found, load original hue
- dt[:hue] = ori_hue
- end
- end
- # Space found or reached the start
- if ch_w[ci]
- subw += ch_w[ci][0] + ch_w[ci][1]
- end
- ci -= 1
- if r_h[ci]
- ch_h = r_h[ci][0]
- rym = r_h[ci][1]
- ay = r_h[ci][2]
- end
- end
- if ["\n","\r\n"].include?(dt[:txt][ci,1]) || ci == last
- dt[:style] = ostyle
- phsp = char_horz_sp(dt[:txt][oci-1,1],dt[:style],ch)
- lw = tw - img.width - phsp
- cnum = oci - 1 - ci
- clw = lwidth(dt[:w],dt[:lines].size)
- sp = (clw - lw) / cnum.to_f
- ch_h = och_h
- rym = orym
- ay = oay
- vsp = char_vert_sp(dt[:vs],dt[:style],dt[:lines].size)
- ay = vsp if ay < vsp
- dt[:lines][oci] = {:w => lw, :ch => ch_h, :vs => ay, :ry => rym, :sp => sp, :single => true}
- last = oci
- ci = oci-1 # Reset the char counter
- else
- subw += ch_w[ci-1][1] if ch_w[ci-1]
- simg = Cache.font_ex(FontEX::Chs[" "],FontEX::Types[dt[:style]],dt[:hue])
- lw = tw - (subw + simg.width + char_horz_sp(" ",dt[:style],dt[:txt][ci,1]))
- spaces -= 1
- if spaces > 0
- clw = lwidth(dt[:w],dt[:lines].size)
- sp = (clw - lw)/spaces.to_f
- else
- clw = lwidth(dt[:w],dt[:lines].size)
- sp = clw - lw.to_f
- end
- last = ci
- # Just make a line break
- dt[:lines][ci] = {:w => lw, :ch => ch_h, :vs => ay, :ry => rym, :sp => sp}
- end
- end
- tw = 0
- spaces = 0
- ay = char_vert_sp(dt[:vs],dt[:style],dt[:lines].size)
- ch_h = 0
- rym = 0
- else
- tw += hsp
- end
- ci += 1
- end
- if spaces > 0
- clw = lwidth(dt[:w],dt[:lines].size)
- sp = (clw-(tw-hsp))/spaces.to_f
- else
- clw = lwidth(dt[:w],dt[:lines].size)
- sp = clw-(tw-hsp)
- end
- # The width of the last line
- dt[:lines][:last] = {:w => tw-hsp, :ch => ch_h, :vs => ay, :ry => rym, :sp => 0}
- dt[:style] = ori_font
- dt[:hue] = ori_hue
- dt[:ci] = 0
- dt[:lnum] = 0 # Current line number
- dt[:cline] = dt[:lines].values[0]
- dt[:cw] = dt[:cline][:w] # Current line width
- dt[:th] = dt[:lines].values.inject(0) {|r,ldt| r += ldt[:ch] + ldt[:vs] + ldt[:ry] }
- dt[:th] -= ay + rym
- dt[:vsp] = (dt[:h] - dt[:th].to_f) / (dt[:lines].size - 1)
- dt[:cx] = font_ex_align_h(dt[:x],dt[:w],dt[:cw],dt[:ah],0)
- dt[:cy] = font_ex_align_v(dt[:y],dt[:h],dt[:th],dt[:av])
- dt[:rym] = 0
- # Kept for future debugging
- #ii = 0
- #dt[:lines].each do |ci,line|
- # p "line #{ii}: #{line}"
- # ii += 1
- #end
- #p "total height: #{dt[:th]}"
- update_fex(dt,@fex.size - 1) if dt[:wait] < 0
- end
- def lwidth(tw,lnum)
- if tw.is_a?(Hash)
- sw = tw.find {|lnums,nw| lnums.is_a?(Array) && lnums.include?(lnum) }
- lw = sw ? sw[1] : tw[:default]
- return lw
- else
- return tw
- end
- end
- def break_line?(cw,tw,lnum)
- if tw.is_a?(Hash)
- sw = tw.find {|lnums,nw| lnums.is_a?(Array) && lnums.include?(lnum) }
- lw = sw ? sw[1] : tw[:default]
- return cw > lw
- else
- return cw > tw
- end
- end
- def update_font_ex
- return unless @fex
- @fex.each_with_index do |dt,i|
- update_fex(dt,i)
- end
- end
- def update_fex(dt,fi)
- return if dt[:done]
- if dt[:skip_key] && !dt[:skip]
- dt[:skip] = true if Input.trigger?(dt[:skip_key])
- end
- if dt[:num] >= dt[:wait] || dt[:spd_key] && Input.press?(dt[:spd_key])
- loop do
- ch = dt[:txt][dt[:ci]]
- if ch.nil? || ch == "" # No more char!
- dt[:done] = true
- break
- end
- if dt[:mods]['k'][dt[:ci]]
- unless Input.trigger?(dt[:mods]['k'][dt[:ci]].to_sym)
- dt[:skip] = false if dt[:skip]
- return
- end
- end
- if dt[:mods]['s'][dt[:ci]]
- dt[:style] = dt[:mods]['s'][dt[:ci]]
- end
- if dt[:mods]['h'][dt[:ci]]
- dt[:hue] = dt[:mods]['h'][dt[:ci]]
- end
- if dt[:mods]['w'][dt[:ci]]
- dt[:wait] = dt[:mods]['w'][dt[:ci]].to_i - 1
- end
- if dt[:lines][dt[:ci]] # Do a linebreak here
- dt[:cy] += dt[:cline][:ch] + dt[:cline][:vs] # Start new line
- dt[:cy] += dt[:vsp] if dt[:av] == 3
- dt[:lnum] += 1
- dt[:cline] = dt[:lines].values[dt[:lnum]]
- dt[:cw] = dt[:cline][:w] # Current line width
- dt[:cx] = font_ex_align_h(dt[:x],dt[:w],dt[:cw],dt[:ah],dt[:lnum]) # Reset X pos
- dt[:rym] = 0
- if ch == " " || ch == "\n" || ch == "\r\n"
- dt[:ci] += 1
- if dt[:wait] >= 0 && !dt[:skip]
- dt[:num] = 0
- break
- else
- next
- end
- end
- end
- if dt[:mods]['x'][dt[:ci]]
- dt[:cx] += dt[:mods]['x'][dt[:ci]].to_i
- end
- if dt[:mods]['y'][dt[:ci]]
- dt[:rym] += dt[:mods]['y'][dt[:ci]].to_i
- end
- if ch == ' ' || (FontEX::Misc[:single] && dt[:cline][:single])
- dt[:cx] += dt[:lines].values[dt[:lnum]][:sp] if dt[:ah] == 3
- end
- img = Cache.font_ex(FontEX::Chs[ch],FontEX::Types[dt[:style]],dt[:hue])
- rct = Rect.new(0,0,img.width,img.height)
- play_fex_se(dt[:ci],dt[:se]) if dt[:se] && !dt[:skip] && dt[:wait] >= 0
- ry = dt[:cline][:ch] - img.height
- dt[:rym] = ry if dt[:rym] < ry
- blt(dt[:cx], dt[:cy]+ry, img, rct, dt[:opa]) # Draw the char
- # Added x after the character
- ax = img.width + char_horz_sp(ch,dt[:style],dt[:txt][dt[:ci]+1])
- dt[:cx] += ax
- dt[:ci] += 1
- break if dt[:wait] >= 0 && !dt[:skip]
- end
- dt[:num] = 0
- else
- dt[:num] += 1
- end
- end
- def font_ex_align_h(xx,ww,cw,al=0,lnum)
- if xx.is_a?(Hash)
- sx = xx.find {|lnums,nx| lnums.is_a?(Array) && lnums.include?(lnum) }
- nx = sx ? sx[1] : xx[:default]
- else
- nx = xx
- end
- if ww.is_a?(Hash)
- sw = ww.find {|lnums,nw| lnums.is_a?(Array) && lnums.include?(lnum) }
- tw = sw ? sw[1] : ww[:default]
- else
- tw = ww
- end
- case al
- when 0, 3; return nx # Current X pos
- when 1; return nx + (tw - cw) / 2 # Current X pos
- when 2; return nx + tw - cw # Current X pos
- end
- end
- def font_ex_align_v(yy,hh,th,al=0)
- case al
- when 0, 3; return yy # Current Y pos
- when 1; return yy + (hh - th) / 2 # Current Y pos
- when 2; return yy + hh - th # Current Y pos
- end
- end
- def play_fex_se(ci,dt)
- return unless ci % dt[3] == 0
- se = dt[0].is_a?(Array) ? dt[0].sample : dt[0]
- vol = dt[1].is_a?(Array) ? dt[1].sample : dt[1]
- pitch = dt[2].is_a?(Array) ? dt[2].sample : dt[2]
- RPG::SE.new(se,vol,pitch).play
- end
- def process_text_fex(txt) # Text message codes
- ctxt = txt.dup
- ctxt.gsub!(/<VAR:(?:\s*)(\d+)>/i) { $game_variables[$1.to_i].to_s }
- ctxt.gsub!(/<VAR:(?:\s*)(\d+)>/i) { $game_variables[$1.to_i].to_s }
- ctxt.gsub!(/<ANAME:(?:\s*)(\d+)>/i) { actor_name($1.to_i) }
- ctxt.gsub!(/<MNAME:(?:\s*)(\d+)>/i) { member_name($1.to_i) }
- ctxt.gsub!(/<ACLASS:(?:\s*)(\d+)>/i) { actor_class_name($1.to_i) }
- ctxt.gsub!(/<MCLASS:(?:\s*)(\d+)>/i) { member_class_name($1.to_i) }
- ctxt.gsub!(/<ANICK:(?:\s*)(\d+)>/i) { actor_nickname($1.to_i) }
- ctxt.gsub!(/<MNICK:(?:\s*)(\d+)>/i) { member_nickname($1.to_i) }
- ctxt.gsub!(/<ITEM:(?:\s*)(\d+)>/i) { obj_name($data_items[$1.to_i]) }
- ctxt.gsub!(/<ARMOR:(?:\s*)(\d+)>/i) { obj_name($data_armors[$1.to_i]) }
- ctxt.gsub!(/<WEAPON:(?:\s*)(\d+)>/i) { obj_name($data_weapons[$1.to_i]) }
- ctxt.gsub!(/<SKILL:(?:\s*)(\d+)>/i) { obj_name($data_skills[$1.to_i]) }
- ctxt.gsub!(/<CLASS:(?:\s*)(\d+)>/i) { obj_name($data_classes[$1.to_i]) }
- ctxt.gsub!(/<STATE:(?:\s*)(\d+)>/i) { obj_name($data_states[$1.to_i]) }
- return post_process_text_fex(ctxt)
- end
- def post_process_text_fex(ctxt) # Functional message codes
- pos = 0
- while ctxt =~ /<(S|X|Y|W|K|H):(?:\s*)([^>]*)>/i
- tp = $1
- mod = $2
- pos = ctxt.index(/<(S|X|Y|W|K|H):(?:\s*)([^>]*)>/i,pos)
- @fex[-1][:mods][tp.downcase][pos] = mod
- ctxt.sub!(/<(S|X|Y|W|K|H):(?:\s*)([^>]*)>/i,"")
- end
- return ctxt
- end
- def obj_name(obj)
- return obj ? obj.name : ""
- end
- def actor_name(id)
- act = $game_actors[id]
- return act ? act.name : ""
- end
- def member_name(id)
- act = $game_party.members[id]
- return act ? act.name : ""
- end
- def actor_nickname(id)
- act = $game_actors[id]
- return act ? act.nickname : ""
- end
- def member_nickname(id)
- act = $game_party.members[id]
- return act ? act.nickname : ""
- end
- def actor_class_name(id)
- act = $game_actors[id]
- return act ? act.class.name : ""
- end
- def member_class_name(id)
- act = $game_party.members[id]
- return act ? act.class.name : ""
- end
- alias clear_fex9927 dispose
- def dispose
- @fex = nil
- clear_fex9927
- end
- end
- if FontEX::Auto[:sprite]
- class Sprite
- alias add_fex_update9971 update
- def update
- add_fex_update9971
- bitmap.update_font_ex if !self.disposed? && bitmap
- end
- end
- end
- if FontEX::Auto[:window]
- class Window
- alias add_fex_update9973 update
- def update
- add_fex_update9973
- self.contents.update_font_ex if !self.disposed? && self.contents
- end
- end
- end
- #==============================================================================
- # !!END OF SCRIPT - OHH, NOES!!
- #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement