Advertisement
TheSixth

Letter Animations

Jan 8th, 2019
750
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 32.83 KB | None | 0 0
  1. #===============================================================================
  2. # * [ACE] Letter Animations
  3. #===============================================================================
  4. # * Made by: Sixth (www.rpgmakervxace.net, www.forums.rpgmakerweb.com)
  5. # * Version: 1.0
  6. # * Updated: 06/01/2019
  7. # * Requires: -------
  8. #-------------------------------------------------------------------------------
  9. # * < Change Log >
  10. #-------------------------------------------------------------------------------
  11. # * Version 1.0 (06/01/2019)
  12. #   - Initial release.
  13. #-------------------------------------------------------------------------------
  14. # * < Description >
  15. #-------------------------------------------------------------------------------
  16. # * This script will let you use image-sheets for the letters in the message
  17. #   window. The letters can be animated using these image-sheets.
  18. #-------------------------------------------------------------------------------
  19. # * < Script Calls >
  20. #-------------------------------------------------------------------------------
  21. # * To change the message box's letter style, use this script call BEFORE the
  22. #   "Show Message" event command:
  23. #
  24. #     set_msg_win_style('style_key', hue)
  25. #
  26. #   Replace the 'style_key' with a valid setting key from the 'Styles' setting
  27. #   area found in this script!
  28. #   You can also use nil here, in which case this script will be disabled until
  29. #   you use this script call again with a valid setting key instead of nil.
  30. #
  31. #   Replace the hue with an integer number between 0 and 360.
  32. #   This will set the hue of the letter images.
  33. #   You can omit this argument, in which case 0 will be used automatically.
  34. #
  35. #   Note that the effect of this script call is saved! Once you use this, the
  36. #   message box letter style will remain on the values you used the last time
  37. #   in this script call, even after loading a saved game!
  38. #
  39. #   Examples:
  40. #
  41. #     set_msg_win_style('default')
  42. #     set_msg_win_style('yellow')
  43. #     set_msg_win_style('curly_blue',126)
  44. #     set_msg_win_style('edgy_yellow_red',80)
  45. #
  46. #-------------------------------------------------------------------------------
  47. # * < Image Setup >
  48. #-------------------------------------------------------------------------------
  49. # * First thing first, you must setup your character images before you can use
  50. #   this script.
  51. #   I won't lie, this can be a pretty boring job, but once it's done, you can
  52. #   use the completed character set any time you want in the future.
  53. # * Each letter style used by this script must be in it's own separate folder!
  54. #   You can setup the folder used for each letter style separately in the script
  55. #   settings, so you have full control over this too.
  56. # * You must have an image for each characters you use in your texts, even if
  57. #   they are only used once during a 120 hours game (which is highly unlikely,
  58. #   but still :D)! However, if you are sure that a character will not appear in
  59. #   a given letter style ever during your game, it is safe to leave that
  60. #   character out from that letter style's folder.
  61. # * The letter image-sheets can have any size (width x height) and the image
  62. #   frames on them can be formatted in any way (rows x columns), but each
  63. #   image frame must have the same width and height!
  64. #   All image frames used in the drawing AND in the idle animation must be on
  65. #   the SAME image-sheet! You can select which image frames to use for which
  66. #   animation, so don't worry about that.
  67. # * The image frames are "numbered" in a specific (and logical) way.
  68. #   The numbering starts from 0 (from the top-leftmost frame) and goes to
  69. #   infinity (to the bottom-rightmost frame).
  70. #   For example:
  71. #
  72. #     -----------------
  73. #     | 0 | 1 | 2 | 3 |
  74. #     -----------------
  75. #     | 4 | 5 | 6 | 7 |
  76. #     -----------------
  77. #
  78. #   You will use these index numbers in the :frames animation settings.
  79. # * The image frames themselves must all have the same height in the same
  80. #   style! This is to let you adjust the vertical positions of your characters
  81. #   manually, since doing this automatically would lead to a pretty convoluted
  82. #   setting area, which is not what most of us want, right?
  83. #   This means that the height of your characters will always be the height
  84. #   between the top of the tallest character and the bottom of the smallest
  85. #   character. Well, this is the only way I can explain it, but if it's not
  86. #   enough, you can check the PSD files in each letter style folder, and check
  87. #   the "Guide Lines" layer folder to see what I mean. I marked the important
  88. #   vertical positioning lines there, so that I always know the vertical
  89. #   positioning of my characters. Note that those layers are only there as a
  90. #   guide, they do not affect anything in this script, nor are they needed for
  91. #   this script to work!
  92. #   Hahh! Got you! This is a copy/paste paragraph from another script of mine,
  93. #   I never really made sample images for this script, sorry! :P
  94. # * There can be no empty pixels on the left or right side on your character
  95. #   images! The automatic character width calculation is based on the width of
  96. #   the character image frames, that's why there should be no useless empty
  97. #   pixels on the sides. The spacing between the characters itself can be setup
  98. #   for each letter styles separately in the script settings, so this part is
  99. #   not on your character images at all.
  100. #   Actually, you can have empty pixels on the image frames used in the drawing
  101. #   animation, since those are most probably incomplete letters until they are
  102. #   fully "drawn" anyway, but make sure that the image frames used in the idle
  103. #   animation don't have empty pixels on the sides!
  104. #   If you can't make the image frames this way, you can still adjust the
  105. #   spacing after specific letters and even between specific letters, so you can
  106. #   still use those images, but you will have a lot more to setup that way.
  107. # * You can have whatever drawn on your character images. This script is meant
  108. #   to be used for text drawing, but that is not the only thing you can draw
  109. #   with it, it all depends on what you have on your character images.
  110. #-------------------------------------------------------------------------------
  111. # * < Installation >
  112. #-------------------------------------------------------------------------------
  113. # * Place this script below Materials but above Main!
  114. # * If you are using my Control Configuration System script, place this script
  115. #   above those scripts!
  116. #-------------------------------------------------------------------------------
  117. # * < Compatibility Info >
  118. #-------------------------------------------------------------------------------
  119. # * No known incompatibilities.
  120. # * There is no word-wrap feature in this script! There won't be one either,
  121. #   unless someone (othar than me) is willing to make an addon for that.
  122. #   This probably means that this script will not work well with word-wrap
  123. #   scripts.
  124. #-------------------------------------------------------------------------------
  125. # * < Known Issues >
  126. #-------------------------------------------------------------------------------
  127. # * No known issues.
  128. #-------------------------------------------------------------------------------
  129. # * < Terms of Use >
  130. #-------------------------------------------------------------------------------
  131. # * Free to use for whatever purposes you want.
  132. # * Credit me (Sixth) in your game, pretty please! :P
  133. # * Posting modified versions of this script is allowed as long as you notice me
  134. #   about it with a link to it!
  135. #===============================================================================
  136. $imported = {} if $imported.nil?
  137. $imported["SixthLetterEX"] = true
  138. #===============================================================================
  139. # Settings:
  140. #===============================================================================
  141. module MsgLtrEX
  142.   #-----------------------------------------------------------------------------
  143.   # Letter Image Settings:
  144.   #-----------------------------------------------------------------------------
  145.   # This is where you will setup the character list and their image names.
  146.   # Each character you want to use in any letter style must be specified here.
  147.   #
  148.   # Format:
  149.   #
  150.   #   'character' => 'filename',
  151.   #
  152.   # The character can be any valid character, really.
  153.   # Although, sadly, the font type used in this editor does not support some
  154.   # (well, a lot of) extra character symbols, so you won't be able to set those
  155.   # up here.
  156.   #
  157.   # There are some extra characters which are normally not displayed, but you
  158.   # can still specify a filename for them and use them in your texts.
  159.   # One of them, for example, is the "\t" character, which denotes the paragraph
  160.   # character when the TAB key is pressed.
  161.   # The only special character which is processed automatically is the "\n"
  162.   # character which denotes a line-break. That won't be displayed at all, it
  163.   # will just start a new line, like it would normally.
  164.   #
  165.   # And this is a good place to state that you can insert a manual line-break
  166.   # with the "\n" character in your texts.
  167.   #
  168.   # The list I made contains most of the basic characters (letters, numbers,
  169.   # signs, etc) and some extra ones as well, but it is far from including all
  170.   # of the displayable characters, so feel free to add your own character
  171.   # settings here.
  172.   #
  173.   # The character image filenames you setup here are the default ones for all of
  174.   # your letter styles. You can change the filename for each character in your
  175.   # letter style setting area with the :img option if needed.
  176.   #
  177.   # I have noted some of the settings here with a "No image file setup!" line.
  178.   # That means that these characters don't have a character image for any letter
  179.   # style I made, so they are unusable in your texts until you make an image
  180.   # for them.
  181.   #-----------------------------------------------------------------------------
  182.   Letters = {
  183.     # Spaces:
  184.     ' '  => 'space',
  185.     "\t" => 'tab',
  186.     # Lowercase letters:
  187.     'a' => 'a_lc', 'b' => 'b_lc', 'c' => 'c_lc', 'd' => 'd_lc', 'e' => 'e_lc',
  188.     'f' => 'f_lc', 'g' => 'g_lc', 'h' => 'h_lc', 'i' => 'i_lc', 'j' => 'j_lc',
  189.     'k' => 'k_lc', 'l' => 'l_lc', 'm' => 'm_lc', 'n' => 'n_lc', 'o' => 'o_lc',
  190.     'p' => 'p_lc', 'q' => 'q_lc', 'r' => 'r_lc', 's' => 's_lc', 't' => 't_lc',
  191.     'u' => 'u_lc', 'v' => 'v_lc', 'w' => 'w_lc', 'x' => 'x_lc', 'y' => 'y_lc',
  192.     'z' => 'z_lc',
  193.     # Uppercase letters:
  194.     'A' => 'a_uc', 'B' => 'b_uc', 'C' => 'c_uc', 'D' => 'd_uc', 'E' => 'e_uc',
  195.     'F' => 'f_uc', 'G' => 'g_uc', 'H' => 'h_uc', 'I' => 'i_uc', 'J' => 'j_uc',
  196.     'K' => 'k_uc', 'L' => 'l_uc', 'M' => 'm_uc', 'N' => 'n_uc', 'O' => 'o_uc',
  197.     'P' => 'p_uc', 'Q' => 'q_uc', 'R' => 'r_uc', 'S' => 's_uc', 'T' => 't_uc',
  198.     'U' => 'u_uc', 'V' => 'v_uc', 'W' => 'w_uc', 'X' => 'x_uc', 'Y' => 'y_uc',
  199.     'Z' => 'z_uc',
  200.     # Numbers:
  201.     '0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4',
  202.     '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9',
  203.     # Signs:
  204.     '.' => 'point',
  205.     ',' => 'comma',
  206.     ';' => 'semicolon',
  207.     ':' => 'doublepoint',
  208.     '!' => 'exclamation',
  209.     '?' => 'question',
  210.     '_' => 'underscore',
  211.     "'" => 'apostrophe1',
  212.     '`' => 'apostrophe2',
  213.     #'’' => 'apostrophe3', # No image file setup!
  214.     '"' => 'quote',
  215.     #'“' => 'quote1', # No image file setup!
  216.     #'”' => 'quote2', # No image file setup!
  217.     '@' => 'at',
  218.     '#' => 'numero',
  219.     '$' => 'dollar',
  220.     '€' => 'euro',
  221.     '£' => 'pound',
  222.     "\\" => 'lbrace',
  223.     '/' => 'rbrace',
  224.     # Math:
  225.     '+' => 'plus',
  226.     '-' => 'minus',
  227.     '*' => 'multiply',
  228.     '÷' => 'divide',
  229.     '=' => 'equal',
  230.     '~' => 'approx',
  231.     '%' => 'percent',
  232.     '^' => 'on_square',
  233.     '&' => 'and',
  234.     '|' => 'or',
  235.     '(' => 'lbracket_normal',
  236.     ')' => 'rbracket_normal',
  237.     '[' => 'lbracket_square',
  238.     ']' => 'rbracket_square',
  239.     '{' => 'lbracket_curly',
  240.     '}' => 'rbracket_curly',
  241.     '<' => 'smaller',
  242.     '>' => 'higher',
  243.     # <-- Add more character settings here if needed!
  244.   }
  245.  
  246.   #-----------------------------------------------------------------------------
  247.   # Letter Style Settings:
  248.   #-----------------------------------------------------------------------------
  249.   # This is the place where you can setup the identifiers, folder, spacing and
  250.   # animation settings for your letter styles.
  251.   # You will use the setting keys from this setting in all letter style related
  252.   # things in the provided script call.
  253.   #
  254.   # Format:
  255.   #
  256.   #   'style_key' => {
  257.   #     :folder => "folder_path/",
  258.   #     :spacing => {
  259.   #       :horz => value,
  260.   #       :vert => value,
  261.   #       'char' => value,
  262.   #       'char1char2' => value,
  263.   #       ...
  264.   #     },
  265.   #     :draw => {
  266.   #       :cols => amount,
  267.   #       :rows => amount,
  268.   #       :frames => [index1, index2, ...],
  269.   #       :wait => value,
  270.   #       :repeat => amount,
  271.   #     },
  272.   #     :idle => {
  273.   #       :cols => amount,
  274.   #       :rows => amount,
  275.   #       :frames => [index1, index2, ...],
  276.   #       :wait => value,
  277.   #       :repeat => amount,
  278.   #     },
  279.   #     'char1' => {
  280.   #       :img => "filename",
  281.   #       :draw => { * draw_animation_settings_here * },
  282.   #       :idle => { * idle_animation_settings_here * },
  283.   #     },
  284.   #     ...
  285.   #   },
  286.   #
  287.   # You can make as many letter style settings as you want.
  288.   # The 'default' letter style setting must contain ALL setting options
  289.   # (excluding the character specific ones - those are optional even there)!
  290.   # The :folder option is the only one that is mandatory for ALL other letter
  291.   # style settings. If a letter style is missing some other setting options,
  292.   # those will be loaded from the 'default' letter style automatically.
  293.   # For this reason, you should never remove or rename the setting key for the
  294.   # 'default' letter style settings!
  295.   #
  296.   # If you don't use a 'style' argument for the letter style changing script
  297.   # call, the 'default' letter style will be used automatically.
  298.   #
  299.   # Okay, so that's all for the basics...
  300.   # Now lets see the details...
  301.   # I will break this into multiple sections for easier readability.
  302.   #
  303.   #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  304.   # 1. Folder settings:
  305.   #
  306.   #   :folder => "folder_path/",
  307.   #
  308.   # A simple option for start.
  309.   # You just enter the path of the folder containing all character images for
  310.   # the letter style here.
  311.   # Don't forget the "/" sign at the end, that is needed!
  312.   #
  313.   # Because there can be no files named the same in the same folder, you must
  314.   # set this up for ALL of your letter style settings!
  315.   #
  316.   #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  317.   # 2. Spacing settings:
  318.   #
  319.   #   :spacing => {
  320.   #     :horz => value,
  321.   #     :vert => value,
  322.   #     'char' => value,
  323.   #     'char1char2' => value,
  324.   #     ...
  325.   #   },
  326.   #
  327.   # This one seems a bit longer, but it's still simple enough...
  328.   #
  329.   # First, you have 2 static options:
  330.   # :horz - The default horizontal spacing between the letter images.
  331.   # :vert - The vertical spacing between each line drawn.
  332.   #
  333.   # And than you can add unlimited amount of custom horizontal spacing settings.
  334.   # You can do this 2 different ways:
  335.   #
  336.   # - Use this format: 'char' => value,
  337.   # You must replace the 'char' with a valid setting key from the
  338.   # 'Letters' setting area (found above this setting area).
  339.   # This will make the draw method use the spacing value you specify here AFTER
  340.   # the specified character.
  341.   # Example: 'a' => 1, '!' => 0,
  342.   #
  343.   # - Use this format: 'char1char2' => value,
  344.   # Here you must replace the 'char1char2' part with 2 valid setting keys from
  345.   # the 'Letters' setting area (found above this setting area).
  346.   # This will make the draw method use the spacing value you specify here
  347.   # BETWEEN the 2 specified characters.
  348.   # Example: 'av' => 0, 'BY' => 2,
  349.   #
  350.   # If none of the above 2 custom, letter specific horizontal spacing settings
  351.   # are set, the default value will be loaded automatically instead (from the
  352.   # :horz setting option).
  353.   #
  354.   # The value must be an integer number and it is measured in pixels!
  355.   #
  356.   #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  357.   # 3. Animation settings:
  358.   #
  359.   #   :draw/:idle => {
  360.   #     :cols => amount,
  361.   #     :rows => amount,
  362.   #     :frames => [index1, index2, ...],
  363.   #     :wait => value,
  364.   #     :repeat => amount,
  365.   #   },
  366.   #
  367.   # Another bigger setting group.
  368.   # This one will setup the default drawing/idle animation for your letters.
  369.   # Both animation setting groups (:draw and :idle) got the same setting options
  370.   # and layout, so I will just merge the details on them here.
  371.   #
  372.   # When the letter is drawn, it will start out with the :draw animation
  373.   # settings. This will let you make a drawing animation for each of your
  374.   # letters.
  375.   # When this draw animation is finished, the letter will switch to the :idle
  376.   # animation settings. This will let you make a separate animation for the
  377.   # letters when they are "finished the drawing", or you can just simply use it
  378.   # for stopping the animation, and let the letter be static for the rest of the
  379.   # day.
  380.   # The letters will keep appearing one after the other, each waiting for the
  381.   # previous letter's :draw animation to finish. For that reason, you may want
  382.   # to consider using short draw animations with only a few frames or a very
  383.   # quick one with more frames (the latter will definitely look smoother),
  384.   # otherwise the player will get bored of it, or even worse, will get annoyed
  385.   # by it.
  386.   # Note that when the player presses the "skip" or "fast-forward" button, the
  387.   # :draw animation ends immediately for all letters and the whole text will be
  388.   # displayed at once (all letters also switch to their :idle animation).
  389.   #
  390.   # The animation is made by using image-sheets for your letters.
  391.   # This image sheet can be formatted in any way, and can be any size.
  392.   # The :cols and :rows options will setup the formatting of the image-sheet.
  393.   # For example, if you have an image-sheet containing 8 image frames in a
  394.   # 2 x 4 format, you will have to set the :rows setting to 2 and the :cols
  395.   # setting to 4.
  396.   # You don't have to use all image frames from the image-sheet, you have the
  397.   # option to select exactly which frames you want to use and in which order
  398.   # with the next setting option.
  399.   #
  400.   # The :frames setting option will let you setup which image frames you want
  401.   # to use from the image-sheet, how many times you want to use them in the
  402.   # animation cycle and in which order you want to use them.
  403.   # For more information about getting the correct image frame indexes for this
  404.   # setting, head to the "Image Setup" details found in the header of this
  405.   # script.
  406.   # You must enter at least one image frame into this setting array!
  407.   # You can use unlimited amount of image frames here, and you can re-use the
  408.   # same image frame index multiple times as well if needed.
  409.   #
  410.   # The :wait setting option will let you control the speed of the animation
  411.   # cycle. This must be an integer number, 0 or higher!
  412.   # The higher the value you set here, the slower the animation gets!
  413.   #
  414.   # The :repeat option will let you setup how many times the animation cycle
  415.   # repeats before stopping the animation. The animation will stop on the last
  416.   # image frame from the :frames setting option.
  417.   # If you set this to 0, the animation will be blocked completely (so, the
  418.   # drawn letter images will NOT be animated at all), and if you set it to -1,
  419.   # the animation cycle will repeat endlessly.
  420.   # If you set it to 1 or higher, the animation cycle will stop after that many
  421.   # repeats.
  422.   #
  423.   # You may want to setup static (not animated) letters, especially for the
  424.   # :idle animation settings. You can do so by setting the :repeat option to 0,
  425.   # and by entering only 1 frame index into the :frames setting array.
  426.   # The :wait setting is irrelevant in this case, but you must setup a valid
  427.   # value for it still!
  428.   # The rest of the settings must be setup properly, even if you don't want to
  429.   # animate the letter (:cols and :rows).
  430.   #
  431.   #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  432.   # 4. Character specific settings:
  433.   #
  434.   #   'char1' => {
  435.   #     :img => "filename",
  436.   #     :draw => { * draw_animation_settings_here * },
  437.   #     :idle => { * idle_animation_settings_here * },
  438.   #   },
  439.   #
  440.   # These setting groups are optional only!
  441.   # With these, you can setup a custom image-sheet name, and animation settings
  442.   # for each of your letters in a letter style.
  443.   #
  444.   # The 'char1' setting key must be replaced by a valid setting key used in the
  445.   # 'Letters' setting area (found above this setting area). The settings in the
  446.   # character specific setting groups will apply to the specified character
  447.   # only!
  448.   #
  449.   # The :img setting option will let you setup a custom image-sheet filename
  450.   # for the letter. I don't recommend using this option. It is much better to
  451.   # just stick with the same filenames for all of your letter styles, since the
  452.   # letter images must be in different folders for each letters styles anyway.
  453.   #
  454.   # The :draw and :idle setting options will setup a custom drawing/idle
  455.   # animation for the letter. This can come in handy, since a drawing animation
  456.   # for the 'M' letter could have more animation frames than, for example, the
  457.   # '!' sign has.
  458.   #
  459.   # All setting options here are optional, so you can leave out the ones you
  460.   # don't want to modify for the letter (they will use the default ones instead
  461.   # that way).
  462.   # But keep in mind that if you use the :draw or the :idle setting groups here,
  463.   # you must setup ALL setting options for those groups (:rows, :cols, :frames,
  464.   # :wait and :repeat)!
  465.   #
  466.   # You can enter unlimited amount of character specific settings here!
  467.   #
  468.   #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  469.   # And this would be it.
  470.   #
  471.   #-----------------------------------------------------------------------------
  472.   Styles = {
  473.   #-----------------------------------------------------------------------------
  474.     'default' => {
  475.       # Folder for the letter images
  476.       :folder => "Graphics/FontEX/Microsoft Himalaya/s23_white_gray_grad/",
  477.       # Spacing settings:
  478.       :spacing => {
  479.         :horz => 1, :vert => 2,
  480.       },
  481.       # Default drawing animation settings
  482.       :draw => {
  483.         :rows => 1, :cols => 1, :wait => 6, :repeat => 0,
  484.         :frames => [0],
  485.       },
  486.       # Default idle animation settings
  487.       :idle => {
  488.         :rows => 1, :cols => 1, :wait => 6, :repeat => 0,
  489.         :frames => [0],
  490.       },
  491.       # Letter image settings:
  492.       # Add custom animation settings for your letters here if needed.
  493.       # Format:
  494.       #   'letter' => {:draw => {*settings*}, :idle => {*settings*}},
  495.       #
  496.      
  497.     },
  498.   #-----------------------------------------------------------------------------
  499.     'yellow' => {
  500.       :folder => "Graphics/FontEX/WST_Engl/s21_yellow_grad/",
  501.       :spacing => {
  502.         :horz => 1, :vert => -2,
  503.       },
  504.     },
  505.   #-----------------------------------------------------------------------------
  506.   # <-- Add more letter style setting here!
  507.   }
  508.  
  509. #===============================================================================
  510. # End of settings! O.o
  511. #===============================================================================
  512.  
  513.   def self.get_data(sky,opt,*edt)
  514.     dt = Styles['default'].merge(Styles[sky] || {})
  515.     case opt
  516.     when :img # edt = char
  517.       if dt[edt[0]] && dt[edt[0]][:img]
  518.         return dt[edt[0]][:img]
  519.       else
  520.         return Letters[edt[0]]
  521.       end
  522.     when :spacing # edt = [:horz/:vert,char1,char2]
  523.       case edt[0]
  524.       when :horz
  525.         if edt[2]
  526.           ky = edt[1] + edt[2]
  527.           return dt[:spacing][ky] if dt[:spacing][ky]
  528.         end
  529.         return dt[:spacing][edt[1]] || dt[:spacing][:horz]
  530.       when :vert
  531.         return dt[:spacing][:vert]
  532.       end
  533.     when :draw, :idle # edt = [char]
  534.       if dt[edt[0]] && dt[edt[0]][opt]
  535.         return dt[edt[0]][opt]
  536.       else
  537.         return dt[opt]
  538.       end
  539.     else
  540.       return dt[opt]
  541.     end
  542.   end
  543.  
  544. end
  545.  
  546. module Cache
  547.    
  548.   @ltr_ex_cache = {}
  549.  
  550.   def self.letter_ex(fname,folder,hue=0)
  551.     fky = [folder,hue]
  552.     @ltr_ex_cache[fky] = [] if @ltr_ex_cache[fky].nil?
  553.     @ltr_ex_cache[fky] << fname unless @ltr_ex_cache[fky].include?(fname)
  554.     load_bitmap(folder,fname,hue)
  555.   end
  556.    
  557.   def self.clear_letter_ex(*styles)
  558.     styles.each do |style|
  559.       case style
  560.       when Array
  561.         dt = MsgLtrEX::Styles['default'].merge(MsgLtrEX::Styles[style[0]] || {})
  562.         folder = dt[:folder]
  563.         fky = [folder,style[1]]
  564.       else
  565.         dt = MsgLtrEX::Styles['default'].merge(MsgLtrEX::Styles[style] || {})
  566.         folder = dt[:folder]
  567.         fky = [folder,0]
  568.       end
  569.       next unless @ltr_ex_cache[fky]
  570.       @ltr_ex_cache[fky].each do |img|
  571.         if fky[1] == 0 # No hue change
  572.           ky = folder + img
  573.         else # Custom hue
  574.           ky = [folder + img,fky[1]]
  575.         end
  576.         @cache[ky].dispose
  577.         @cache.delete(ky)
  578.       end
  579.       @ltr_ex_cache.delete(fky)
  580.     end
  581.   end
  582.  
  583.   def self.preload_letter_ex(styles)
  584.     styles.each do |style,sdt|
  585.       # Load normal characters, no hue change
  586.       letters = (sdt[:load] || MsgLtrEX::Letters.keys).clone
  587.       letters -= sdt[:skip] if sdt[:skip]
  588.       fold = MsgLtrEX.get_data(style,:folder)
  589.       letters.each do |ch|
  590.         Cache.letter_ex(MsgLtrEX.get_data(style,:img,ch),fold,0)
  591.       end
  592.       if sdt[:hue] # Load custom hue types if there is any
  593.         sdt[:hue].each do |hue,hdt|
  594.           letters = (hdt[:load] || MsgLtrEX::Letters.keys).clone
  595.           letters -= hdt[:skip] if hdt[:skip]
  596.           letters.each do |ch|
  597.             Cache.letter_ex(MsgLtrEX.get_data(style,:img,ch),fold,hue)
  598.           end
  599.         end
  600.       end
  601.     end
  602.   end
  603.  
  604. end
  605.  
  606. class AnImgEX6 < Sprite
  607.    
  608.   attr_accessor :data, :pause
  609.  
  610.   def initialize(data,view=nil,fold="Graphics/Pictures/")
  611.     @data = data; @view = view
  612.     @folder = fold unless @folder
  613.     @counter = @data[:wait]
  614.     @repeat = @data[:repeat] || -1
  615.     @pattern = @cmd_y = 0
  616.     @cols = @data[:cols] || 1
  617.     @rows = @data[:rows] || 1
  618.     super(view)
  619.     setup_sprite
  620.     reset_frames
  621.   end
  622.  
  623.   def setup_sprite
  624.     self.bitmap = Cache.custom(@data[:img],@folder).clone
  625.     self.opacity = @data[:opacity] if @data[:opacity]
  626.     self.z = @data[:z] if @data[:z]
  627.     self.src_rect.width = self.bitmap.width/@cols
  628.     self.src_rect.height = self.bitmap.height/@rows
  629.     self.ox = self.src_rect.width/2
  630.     self.oy = self.src_rect.height/2
  631.   end
  632.      
  633.   def change_image_data(data)
  634.     @data = data
  635.     @cols = @data[:cols] || 1
  636.     @rows = @data[:rows] || 1
  637.     self.bitmap.dispose if self.bitmap && !self.bitmap.disposed?
  638.     setup_sprite
  639.     if @data[:frames][@pattern].nil?
  640.       reset_frames
  641.     else
  642.       reset_frames(@pattern)
  643.     end
  644.   end
  645.    
  646.   def reset_frames(ptrn=0)
  647.     @counter = @data[:wait]
  648.     @pattern = ptrn
  649.     frm = @data[:idle] || @data[:frames][@pattern]
  650.     if @cols > 1
  651.       self.src_rect.x = (frm % @cols) * self.src_rect.width
  652.     else
  653.       self.src_rect.x = 0
  654.     end
  655.     if @rows > 1
  656.       self.src_rect.y = (frm / @cols) * self.src_rect.height
  657.     else
  658.       self.src_rect.y = 0
  659.     end
  660.   end
  661.  
  662.   def update
  663.     super
  664.     update_sprite_frames unless @pause
  665.   end
  666.    
  667.   def update_sprite_frames
  668.     return if @repeat == 0
  669.     if @counter > 0
  670.       @counter -= 1
  671.     else
  672.       @counter = @data[:wait]
  673.       @pattern += 1
  674.       if @pattern >= @data[:frames].size
  675.         @pattern = 0
  676.         @repeat -= 1 if @repeat > 0
  677.       end
  678.       if @cols > 1
  679.         mx = @data[:frames][@pattern] % @cols
  680.         self.src_rect.x = mx * self.src_rect.width
  681.       end
  682.       if @rows > 1
  683.         my = @data[:frames][@pattern] / @cols
  684.         self.src_rect.y = my * self.src_rect.height
  685.       end
  686.     end
  687.   end
  688.      
  689. end
  690.  
  691. class LetterEX < AnImgEX6
  692.  
  693.   attr_accessor :letter, :nletter, :pattern
  694.  
  695.   def initialize(letter,nletter,lhue,data,view=nil,fold="Graphics/Pictures/")
  696.     @letter = letter
  697.     @nletter = nletter
  698.     @lhue = lhue
  699.     super(data,view,fold)
  700.   end
  701.  
  702.   def setup_sprite
  703.     self.bitmap = Cache.letter_ex(@data[:img],@folder,@lhue).clone
  704.     self.opacity = @data[:opacity] if @data[:opacity]
  705.     self.z = @data[:z] if @data[:z]
  706.     self.src_rect.width = self.bitmap.width/@cols
  707.     self.src_rect.height = self.bitmap.height/@rows
  708.     self.ox = self.src_rect.width/2
  709.     self.oy = self.src_rect.height/2
  710.   end
  711.  
  712. end
  713.  
  714. class Window_Base < Window
  715.  
  716.   attr_accessor :letters, :ltr_style
  717.  
  718.   alias add_ltr_vars8815 initialize
  719.   def initialize(x, y, width, height)
  720.     init_ltr_vars
  721.     add_ltr_vars8815(x, y, width, height)
  722.   end
  723.    
  724.   def init_ltr_vars
  725.     @letters = []
  726.   end
  727.  
  728.   def setup_ltr_vars(sky='default',hue=0)
  729.     @ltr_style = sky
  730.     @ltr_hue = hue
  731.     return unless sky
  732.     @ltr_folder = MsgLtrEX.get_data(sky,:folder)
  733.   end
  734.  
  735.   def draw_text_ex(x, y, text)
  736.     reset_font_settings
  737.     text = convert_escape_characters(text)
  738.     pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
  739.     pos[:text] = text
  740.     process_character(text.slice!(0, 1), text, pos) until text.empty?
  741.   end
  742.  
  743.   alias add_ltr_proc8861 process_normal_character
  744.   def process_normal_character(c, pos)
  745.     if @ltr_style
  746.       process_letter_ex(c, pos)
  747.     else
  748.       add_ltr_proc8861(c, pos)
  749.     end
  750.   end
  751.  
  752.   def process_letter_ex(c, pos)
  753.     fname = MsgLtrEX.get_data(@ltr_style,:img,c)
  754.     nc = pos[:text][0]
  755.     hsp = MsgLtrEX.get_data(@ltr_style,:spacing,:horz,c,nc)
  756.     ddt = MsgLtrEX.get_data(@ltr_style,:draw,c)
  757.     ldt = ddt.clone
  758.     ldt[:img] = fname
  759.     ldt[:opacity] = self.contents_opacity
  760.     ldt[:z] = self.z
  761.     ltr = LetterEX.new(c,nc,@ltr_hue,ldt,self.viewport,@ltr_folder)
  762.     @letters << ltr
  763.     ltr.x = self.x + standard_padding + ltr.ox + pos[:x]
  764.     ltr.y = self.y + standard_padding + ltr.oy + pos[:y]
  765.     tw = ltr.src_rect.width + hsp
  766.     pos[:x] += tw
  767.   end
  768.  
  769.   alias add_nline_ex8876 process_new_line
  770.   def process_new_line(text, pos)
  771.     if @ltr_style
  772.       process_new_line_ltr_ex(text, pos)
  773.     else
  774.       add_nline_ex8876(text, pos)
  775.     end
  776.   end
  777.  
  778.   def process_new_line_ltr_ex(text, pos)
  779.     pos[:x] = pos[:new_x]
  780.     if @letters[-1]
  781.       pos[:height] = @letters[-1].src_rect.height
  782.     else
  783.       pos[:height] = calc_line_height(text)
  784.     end
  785.     pos[:y] += pos[:height] + MsgLtrEX.get_data(@ltr_style,:spacing,:vert)
  786.   end
  787.  
  788.   alias upd_letter_ex9926 update_tone
  789.   def update_tone
  790.     upd_letter_ex9926
  791.     @letters.each {|ltr| ltr.update }
  792.   end
  793.  
  794.   def dispose_letters
  795.     @letters.each {|ltr| ltr.dispose }
  796.     @letters = []
  797.   end
  798.  
  799.   def dispose
  800.     dispose_letters
  801.     super
  802.   end
  803.  
  804. end
  805.  
  806. class Window_Message < Window_Base
  807.  
  808.   alias restart_opa9974 update_background
  809.   def update_background
  810.     restart_opa9974
  811.     self.contents_opacity = 255
  812.     @ltr_style = $game_system.ltr_style
  813.     @ltr_hue = $game_system.ltr_hue
  814.     return unless @ltr_style
  815.     @ltr_folder = MsgLtrEX.get_data(@ltr_style,:folder)
  816.   end
  817.      
  818.   alias add_txt_ltr_ex7541 new_page
  819.   def new_page(text, pos)
  820.     add_txt_ltr_ex7541(text, pos)
  821.     pos[:text] = text
  822.     dispose_letters
  823.   end
  824.    
  825.   def close
  826.     if @ltr_style
  827.       until @letters.all? {|ltr| ltr.opacity == 0 }
  828.         @letters.each {|ltr| ltr.opacity -= 28 }
  829.         self.contents_opacity -= 28
  830.         Fiber.yield
  831.       end
  832.       dispose_letters
  833.     end
  834.     super
  835.   end
  836.    
  837.   alias wait_ltr_ex7751 wait_for_one_character
  838.   def wait_for_one_character
  839.     if @ltr_style
  840.       wait_for_ltr_ex
  841.     else
  842.       wait_ltr_ex7751
  843.     end
  844.   end
  845.  
  846.   def wait_for_ltr_ex
  847.     if @letters[-1]
  848.       dt = @letters[-1].data
  849.       wtime = [dt[:frames].size * dt[:wait] * dt[:repeat],1].max
  850.       wtime.times do
  851.         update_show_fast
  852.         break if @show_fast || @line_show_fast
  853.         Fiber.yield
  854.       end
  855.       ddt = MsgLtrEX.get_data(@ltr_style,:idle,@letters[-1].letter)
  856.       ldt = ddt.clone
  857.       ldt[:img] = dt[:img]
  858.       ldt[:opacity] = dt[:opacity]
  859.       ldt[:z] = dt[:z]
  860.       @letters[-1].change_image_data(ldt)
  861.     end
  862.   end
  863.  
  864. end
  865.  
  866. class Game_System
  867.  
  868.   attr_accessor :ltr_style, :ltr_hue
  869.  
  870. end
  871.  
  872. class Scene_Base
  873.  
  874.   attr_accessor :message_window
  875.    
  876. end
  877.  
  878. class Game_Interpreter
  879.  
  880.   def set_msg_win_style(sky='default',hue=0)
  881.     $game_system.ltr_style = sky
  882.     $game_system.ltr_hue = hue
  883.   end
  884.  
  885. end
  886. #==============================================================================
  887. # !!END OF SCRIPT - OHH, NOES!!
  888. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement