Advertisement
neonblack

TA and FC V2.1 (vx)

Mar 21st, 2012
628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 37.99 KB | None | 0 0
  1. ###--------------------------------------------------------------------------###
  2. #  Text Alignment and Face Flip script                                         #
  3. #  Version 2.1                                                                 #
  4. #                                                                              #
  5. #      Credits:                                                                #
  6. #  Original code by: Neon Black                                                #
  7. #  Modified by:                                                                #
  8. #                                                                              #
  9. #  This work is licensed under the Creative Commons Attribution-NonCommercial  #
  10. #  3.0 Unported License. To view a copy of this license, visit                 #
  11. #  http://creativecommons.org/licenses/by-nc/3.0/.                             #
  12. #  Permissions beyond the scope of this license are available at               #
  13. #  http://cphouseset.wordpress.com/liscense-and-terms-of-use/.                 #
  14. #                                                                              #
  15. #      Contact:                                                                #
  16. #  NeonBlack - neonblack23@live.com (e-mail) or "neonblack23" on skype         #
  17. ###--------------------------------------------------------------------------###
  18.  
  19. ###--------------------------------------------------------------------------###
  20. #      Revision information:                                                   #
  21. #  V2.1 - 10.15.2012                                                           #
  22. #   General script cleanup                                                     #
  23. #  V2.0 - 3.17.2012                                                            #
  24. #   Added Advanced Mode                                                        #
  25. #   Modified several old commands                                              #
  26. #   Added "short" commands                                                     #
  27. #   Fixed an error related to alignment                                        #
  28. #  V1.1 - 10.24.2011                                                           #
  29. #   Fixed an error related to choice boxes                                     #
  30. #   Fixed an error related to battle messages                                  #
  31. #   Added the \trans[x] command                                                #
  32. #   Added the \keep command                                                    #
  33. #   Did general code cleanup                                                   #
  34. #  V1.0 - 10.1.2011                                                            #
  35. #   Wrote and debugged main script                                             #
  36. ###--------------------------------------------------------------------------###
  37.  
  38. ###--------------------------------------------------------------------------###
  39. #      Compatibility:                                                          #
  40. #  Alias       - Window_Message: initialize                                    #
  41. #  Overwrites  - Window_Message: update, start_message, new_page, new_line,    #
  42. #                                start_number_input, update_cursor             #
  43. #  New Objects - Window_Base: draw_message_face, get_facebox                   #
  44. #                Window_Message: get_face_flip, get_alignment, align_my_text,  #
  45. #                                check_lbl, check_lbl2, get_line_speed,        #
  46. #                                ghost_face_check, check_face_trans,           #
  47. #                                dispose_keep                                  #
  48. #      Advanced Mode Compatibility:                                            #
  49. #  Alias       - Bitmap: draw_text                                             #
  50. #  Overwrites  - Window_Base: draw_face                                        #
  51. #                Window_Message: convert_special_characters, update_message    #
  52. #                                                                              #
  53. #  If you are using any Yanfly Engine Custom Message System, play this script  #
  54. #  ABOVE the Yanfly CMS or the Yanfly script will not work properly.  This     #
  55. #  script will not work with any Yanfly CMS if Advanced Mode is enabled.       #
  56. ###--------------------------------------------------------------------------###
  57.  
  58. ###--------------------------------------------------------------------------###
  59. #      Instructions:                                                           #
  60. #  Place this script in the "Materials" section of the scripts above main.     #
  61. #  This script is pretty much plug and play with a few options available to    #
  62. #  change below.  Several additional text commands have become available and   #
  63. #  are described below in detail.  Each configuration option is described in   #
  64. #  detail where it is to be defined.                                           #
  65. #                                                                              #
  66. #  A new feature added in version 2.0 is that the text box can use larger and  #
  67. #  smaller face sets than what are normally allowed.  Face sets must still     #
  68. #  contain 8 faces (4 horizontally and 2 vertically) but they can now be any   #
  69. #  size.  Alternatively, you can use a single graphic for face sets by adding  #
  70. #  a "$" to the file name.                                                     #
  71. #                                                                              #
  72. #      Commands: (All the following commands must be LOWERCASE to work.)       #
  73. #      Box Alignment Codes:                                                    #
  74. #                Place these codes anywhere in a message to change the         #
  75. #                 alignment of the entire box.  If more than one is present    #
  76. #                 the higher code on the list takes higher priority.  These    #
  77. #                 codes will work with the Line Alignment Code.                #
  78. #                                                                              #
  79. # long      short                                                              #
  80. #  \alil     \al -   Aligns all text to the left of the box.                   #
  81. #  \alic     \ac -   Aligns all text to the center of the box.                 #
  82. #  \alir     \ar -   Aligns all text to the right of the box.                  #
  83. #                                                                              #
  84. #      Line Alignment Code:                                                    #
  85. #                Place this code anywhere in a message to change the           #
  86. #                 alignment of a designated line.  You may use this code as    #
  87. #                 many times as you need to align each line.  This code will   #
  88. #                 work with the Box Alignment Codes.                           #
  89. #                                                                              #
  90. #  \pos[x:y] -   Aligns line "x" to alignment "y".                             #
  91. #                 X: May be any value from 1 to 4.                             #
  92. #                 Y: 0 - Left align, 1 - Center align, 2 - Right align.        #
  93. #                 Example: "\ali[2:3]" aligns line 2 to the right.             #
  94. #                                                                              #
  95. #      Face Position Codes:                                                    #
  96. #                Place these codes anywhere in your message to change the      #
  97. #                 position and mirroring of the message face in a text box.    #
  98. #                 If more than one code is present the higher code on the      #
  99. #                 list takes priority.  These work with all alignment codes.   #
  100. #                 "Swap" and "Flip" codes are made to work together.           #
  101. #                                                                              #
  102. # long      short                                                              #
  103. #  \keep     \k    -   Saves face for next message or choice.                  #
  104. #  \trans[x] \t[x] -   Sets face transparency to value "x".                    #
  105. #  \swap     \s>   -   Place the face on the right side of the textbox.        #
  106. #  \uswap    \s<   -   Place the face on the left side of the textbox.         #
  107. #  \flip     \f>   -   Mirrors the face in the textbox.                        #
  108. #  \uflip    \f<   -   Unmirrors the face's direction in the textbox.          #
  109. #  \right    \r    -   Places the face on the right side and flips it.         #
  110. #  \left     \l    -   Places the face on the left side and un-flips it.       #
  111. #                                                                              #
  112. ###-----                                                                -----###
  113. #      Advanced Section                                                        #
  114. #  The advanced section contains some additional commands and features not     #
  115. #  used by standard.  It is important to note that if you choose to use the    #
  116. #  advanced commands and options, this message system loses some of it's       #
  117. #  compatibility.  This script will no longer be compatible with scripts such  #
  118. #  as Yanfly's CMS which it had previously been compatible with, but it gains  #
  119. #  several commands that it did not previously have.  In order for any of the  #
  120. #  advanced commands to work, advanced mode must be set to TRUE in the config  #
  121. #  section of this script.                                                     #
  122. #                                                                              #
  123. #      Features:                                                               #
  124. #  Here is a list of additional features that become available when using      #
  125. #  advanced mode.                                                              #
  126. #      Faceset Upgrades:                                                       #
  127. #  Advanced mode will overwrite how faces are displayed by the "draw_face"     #
  128. #  scripting command.  This allows you to use facesets of different sizes.     #
  129. #  Please remember that a faceset must still contain 8 faces, 4 horizontal     #
  130. #  and 2 vertical.  You may, however, now use single face graphics simply by   #
  131. #  adding a "$" to the graphic name.  This will cause the entire graphic to    #
  132. #  be used as a single face.                                                   #
  133. #      Text Draw Upgrades:                                                     #
  134. #  Modified how text is drawn on screen.  You can now change the shadows       #
  135. #  under text to be in different positions and different colors.  You can      #
  136. #  also choose for text to be outlined rather than shadowed.  This option can  #
  137. #  be turned off if you do not want to alter how text is drawn.                #
  138. #      More Text Commands:                                                     #
  139. #  Several new text commands were added that only become available with        #
  140. #  advanced mode turned on.  This also fixes a "text insensative" glitch with  #
  141. #  the "\G" command.  All these commands will work both uppercase and          #
  142. #  lowercase.                                                                  #
  143. #                                                                              #
  144. #  \icon[x]  \ICON[x] - Display icon "x" in the message box.                   #
  145. #  \b        \B       - Toggle bold text.  DOES NOT ALIGN PROPERLY!            #
  146. #  \i        \I       - Toggle italic text.                                    #
  147. #  \fi[x]    \FI[x]   - Changes the face displayed to face "x" in the current  #
  148. #                        faceset where "x" is a value from 0-7.  Does nothing  #
  149. #                        when using facesets with "$".  Useful when you want   #
  150. #                        to change a character's emotion mid sentence.         #
  151. ###--------------------------------------------------------------------------###
  152.  
  153. ###--------------------------------------------------------------------------###
  154. #      Config:                                                                 #
  155. #  These are the default values used by several of the functions in the        #
  156. #  script.  You may change these values as you find your game requires in      #
  157. #  order to give the player a better playing experience based on your game.    #
  158. #                                                                              #
  159. module CP   # Do not edit                                                      #
  160. module CMS  #  these two lines.                                                #
  161. #                                                                              #
  162. ###-----                                                                -----###
  163. # The default alignment to use for game windows.  Using higher or lower        #
  164. # values than designated may have undesired results.                           #
  165. # 0 = Left, 1 = Center, 2 = Right                                              #
  166. DEFAULT_ALIGNMENT = 0 # Default = 0                                            #
  167. #                                                                              #
  168. # A fix for the messages that appear at the start and end of battle.  Use a    #
  169. # text command here to control the alignment of battle message text if you do  #
  170. # not want it to display with the default alignment.                           #
  171. BATTLE_MESSAGE_FIX = "\al" # Default = "\al"                                   #
  172. #                                                                              #
  173. # Sets if you want the text to type out (default) or display instantly.        #
  174. # false = type out, true = display instantly                                   #
  175. TEXT_TYPE_OR_SKIP = false # Default = false                                    #
  176. #                                                                              #
  177. # Sets the face position and flipping of the face by default.  Swapping is     #
  178. # left and right position in the textbox while flipping mirrors the face in    #
  179. # the textbox.                                                                 #
  180. # SWAPPING: false = left side, true = right side                               #
  181. # FLIPPING: false = normal, true = flip face                                   #
  182. DEFAULT_SWAPPING = false # Default = false                                     #
  183. DEFAULT_FLIPPING = false # Default = false                                     #
  184. #                                                                              #
  185. # Offset used by the CMS when facesets larger than 96x96 are used.  It's       #
  186. # important to note that facesets will use the bottom left corner as the       #
  187. # point of origin so POSITIVE Y values move the image UP.  X value is          #
  188. # automatically recalculated for "swapped" faces.                              #
  189. X_OFFSET = 0 # Default = 0                                                     #
  190. Y_OFFSET = 0 # Default = 0                                                     #
  191. #                                                                              #
  192. # The X offset for text when a face is displayed.  Can be used to correct      #
  193. # text placement when large facesets are used.  When the DEFAULT_FACE_LAY is   #
  194. # set to false, this much of the text box is trimmed off.                      #
  195. TEXT_OFFSET = 0 # Default = 0                                                  #
  196. #                                                                              #
  197. # Places the displayed face over the textbox.  Changing this value to false    #
  198. # will cause the face to display UNDER the textbox.  This is useful when       #
  199. # large portrait type faces.                                                   #
  200. DEFAULT_FACE_LAY = true # Default = true                                       #
  201. #                                                                              #
  202. ###-----                                                                -----###
  203. #      Advanced Mode:                                                          #
  204. #  Advanced mode options.  These options are only in effect if advanced mode   #
  205. #  is enabled.  See the instructions above for the changes this has.           #
  206. #                                                                              #
  207. # Turns advanced mode on an off.  No other advanced options will have any      #
  208. # effect if this is set to false.                                              #
  209. ADVANCED_MODE = false # Default = false                                        #
  210. #                                                                              #
  211. # Enable or disable the face set upgrade.  See above to read on what it does.  #
  212. # Big facesets are available in message boxes even if this is turned off.      #
  213. # This can be disabled in case of compatibility errors.                        #
  214. FACE_MOD = true # Default = true                                               #
  215. #                                                                              #
  216. # Enable or disable the additional text commands.  See above to read on what   #
  217. # commands were added.  Alignment and other simple codes will work even with   #
  218. # this set to disabled.  This can be disabled in case of compatibility         #
  219. # errors.                                                                      #
  220. TEXT_MOD = true # Default = true                                               #
  221. #                                                                              #
  222. # Modifies how text shadows are drawn.  Shadows can be moved around or text    #
  223. # can be outlined.  Any values other than those below will prevnt any shadow   #
  224. # from being drawn.                                                            #
  225. # 0 = standard shadows, 1 = modified shadow, 2 = outlined                      #
  226. TEXT_STYLE = 0 # Default = 0                                                   #
  227. #                                                                              #
  228. # The X and Y offset used when drawing a shadow.  Changing these moves the     #
  229. # position of the shadow.                                                      #
  230. SHADOW_X = 1 # Default = 1                                                     #
  231. SHADOW_Y = 1 # Default = 1                                                     #
  232. #                                                                              #
  233. # The color used for the shadow.  These values represent the red, green, and   #
  234. # blue values used by the shadow.  Alpha level is determined by default.       #
  235. SHADOW_COLOR = [0, 0, 0] # Default = [0, 0, 0]                                 #
  236. #                                                                              #
  237. #                                                                              #
  238. end # Don't edit                                                               #
  239. end #  either of these.                                                        #
  240. ###--------------------------------------------------------------------------###
  241.  
  242.  
  243. ###--------------------------------------------------------------------------###
  244. #  The following lines are the actual core code of the script.  While you are  #
  245. #  certainly invited to look, modifying it may result in undesirable results.  #
  246. #  Modify at your own risk!                                                    #
  247. ###--------------------------------------------------------------------------###
  248.  
  249.  
  250. $imported = {} if $imported == nil
  251. $imported["CP_TAAFF"] = true
  252.  
  253. module Vocab  # May add an additional mode of customization, so saving this.
  254.   # Basic Battle Messages
  255.   Emerge          += CP::CMS::BATTLE_MESSAGE_FIX
  256.   Preemptive      += CP::CMS::BATTLE_MESSAGE_FIX
  257.   Surprise        += CP::CMS::BATTLE_MESSAGE_FIX
  258.   EscapeStart     += CP::CMS::BATTLE_MESSAGE_FIX
  259.   EscapeFailure   += CP::CMS::BATTLE_MESSAGE_FIX
  260.  
  261.   # Battle Ending Messages
  262.   Victory         += CP::CMS::BATTLE_MESSAGE_FIX
  263.   Defeat          += CP::CMS::BATTLE_MESSAGE_FIX
  264.   ObtainExp       += CP::CMS::BATTLE_MESSAGE_FIX
  265.   ObtainGold      += CP::CMS::BATTLE_MESSAGE_FIX
  266.   ObtainItem      += CP::CMS::BATTLE_MESSAGE_FIX
  267.   LevelUp         += CP::CMS::BATTLE_MESSAGE_FIX
  268.   ObtainSkill     += CP::CMS::BATTLE_MESSAGE_FIX
  269. end
  270.  
  271. if CP::CMS::ADVANCED_MODE && CP::CMS::TEXT_MOD && CP::CMS::TEXT_STYLE != 0
  272. class Bitmap
  273.   alias cp_cms_draw_text draw_text unless $@
  274.   def draw_text(*args)
  275.     unless self.font.shadow
  276.       cp_cms_draw_text(*args)
  277.     else
  278.       case args.size
  279.       when 2, 3
  280.         rect = args[0]
  281.         text = args[1]
  282.         align = args[2] ? args[2] : 0
  283.       else
  284.         rect = Rect.new(args[0], args[1], args[2], args[3])
  285.         text = args[4]
  286.         align = args[5] ? args[5] : 0
  287.       end
  288.       fcolor = self.font.color.clone
  289.       trans = self.font.color.alpha
  290.       self.font.shadow = false
  291.       sc = CP::CMS::SHADOW_COLOR
  292.       self.font.color = Color.new(sc[0], sc[1], sc[2], trans)
  293.       if CP::CMS::TEXT_STYLE == 1
  294.         xo = CP::CMS::SHADOW_X
  295.         yo = CP::CMS::SHADOW_Y
  296.         cp_cms_draw_text(rect.x+xo,rect.y+yo,rect.width,rect.height,text,align)
  297.       elsif CP::CMS::TEXT_STYLE == 2
  298.         cp_cms_draw_text(rect.x+1,rect.y+1,rect.width,rect.height,text,align)
  299.         cp_cms_draw_text(rect.x-1,rect.y-1,rect.width,rect.height,text,align)
  300.         cp_cms_draw_text(rect.x-1,rect.y+1,rect.width,rect.height,text,align)
  301.         cp_cms_draw_text(rect.x+1,rect.y-1,rect.width,rect.height,text,align)
  302.       end
  303.       self.font.color = fcolor
  304.       cp_cms_draw_text(rect, text, align)
  305.       self.font.shadow = true
  306.     end
  307.   end
  308. end
  309. end
  310.  
  311. class Window_Base < Window
  312.  
  313.   # New object  -  Called by the "new_page" object.  Used instead of the
  314.   #                "draw_face" object to draw a sprite as the face.
  315.   def draw_message_face(face_name, face_index, x, y, opacity = 255,
  316.                         facesw = false, flipf = false)
  317.     @face_sprite.z = CP::CMS::DEFAULT_FACE_LAY ? 211 : 199
  318.     @face_sprite.bitmap = Cache.face(face_name)
  319.     rect = Rect.new(0, 0, 0, 0)
  320.     sign = face_name[/^[\$]./]
  321.     if sign != nil and sign.include?('$')
  322.       fsizex = @face_sprite.bitmap.width
  323.       fsizey = @face_sprite.bitmap.height
  324.       rect.x = 0
  325.       rect.y = 0
  326.     else
  327.       fsizex = @face_sprite.bitmap.width / 4
  328.       fsizey = @face_sprite.bitmap.height / 2
  329.       rect.x = face_index % 4 * fsizex
  330.       rect.y = face_index / 4 * fsizey
  331.     end
  332.     rect.width = fsizex
  333.     rect.height = fsizey
  334.    
  335.     xo = (fsizex < 96) ? ((96 - fsizex) / 2) : 0
  336.     yo = (fsizey < 96) ? ((96 - fsizey) / 2) : 0
  337.     xs = CP::CMS::X_OFFSET
  338.     ys = CP::CMS::Y_OFFSET
  339.     mp = $game_message.position * ((Graphics.height-128)/2)
  340.    
  341.     @face_sprite.x = x + 16 + xo + xs
  342.     @face_sprite.x = Graphics.width - 16 - rect.width - xo - xs if facesw
  343.     @face_sprite.y = y + 112 + mp - rect.height - yo - ys
  344.    
  345.     @face_sprite.opacity = opacity
  346.     @face_sprite.src_rect = rect
  347.     @face_sprite.mirror = flipf
  348.     @face_sprite.visible = false if self.openness < 255
  349.     ot = CP::CMS::TEXT_OFFSET
  350.     rvalue = CP::CMS::DEFAULT_FACE_LAY ? (16 + rect.width + xs + xo + ot) : 0
  351.     return rvalue
  352.   end
  353.  
  354.   #####------
  355.   ## Overwrites "draw_face" to improve how facesets are handled.  
  356.   if CP::CMS::ADVANCED_MODE
  357.   def draw_face(face_name, face_index, x, y, size = nil)
  358.     bitmap = Cache.face(face_name)
  359.     rect = Rect.new(0, 0, 0, 0)
  360.     sign = face_name[/^[\$]./]
  361.     if sign != nil and sign.include?('$')
  362.       fsizex = bitmap.width
  363.       fsizey = bitmap.height
  364.       sizex = get_facebox(fsizex, size)
  365.       sizey = get_facebox(fsizey, size)
  366.       rect.x = 0 + (fsizex - sizex) / 2
  367.       rect.y = 0 + (fsizey - sizey) / 2
  368.     else
  369.       fsizex = bitmap.width / 4
  370.       fsizey = bitmap.height / 2
  371.       sizex = get_facebox(fsizex, size)
  372.       sizey = get_facebox(fsizey, size)
  373.       rect.x = face_index % 4 * fsizex + (fsizex - sizex) / 2
  374.       rect.y = face_index / 4 * fsizey + (fsizey - sizey) / 2
  375.     end
  376.     rect.width = sizex
  377.     rect.height = sizey
  378.     mx = x + (size - sizex) / 2
  379.     my = y + (size - sizey) / 2
  380.     self.contents.blt(mx, my, bitmap, rect)
  381.   end
  382.   end #advanced
  383.  
  384.   def get_facebox(fsize, size)
  385.     return fsize if size == nil
  386.     if size > fsize
  387.       rsize = fsize
  388.     else
  389.       rsize = fsize - (fsize - size)
  390.     end
  391.     return rsize
  392.   end
  393. end
  394.  
  395. class Window_Message < Window_Selectable
  396.  
  397.   alias flip_face_init initialize unless $@  # Alias initialize
  398.   def initialize
  399.     flip_face_init
  400.     @face_sprite = Sprite.new
  401.     @face_offset = 0
  402.     unless CP::CMS::DEFAULT_FACE_LAY
  403.       self.width = Graphics.width - CP::CMS::TEXT_OFFSET
  404.       self.x = CP::CMS::TEXT_OFFSET
  405.       create_contents
  406.     end
  407.   end
  408.  
  409.   def update  # Overwrite update
  410.     super
  411.     update_gold_window
  412.     update_number_input_window
  413.     update_back_sprite
  414.     update_show_fast
  415.     unless @opening or @closing
  416.       @face_sprite.visible = true if !@face_sprite.visible
  417.       if @wait_count > 0
  418.         @wait_count -= 1
  419.       elsif self.pause
  420.         input_pause
  421.       elsif self.active
  422.         input_choice
  423.       elsif @number_input_window.visible
  424.         input_number
  425.       elsif @text
  426.         update_message
  427.       elsif continue?
  428.         start_message
  429.         open
  430.         $game_message.visible = true
  431.       else
  432.         close           # Next line removes the displayed face
  433.         @face_sprite.bitmap.dispose if @face_sprite.bitmap
  434.         dispose_keep
  435.         $game_message.visible = @closing
  436.       end
  437.     else
  438.       @face_sprite.visible = false if @face_sprite.visible
  439.     end
  440.   end
  441.  
  442.   # New object  -  Called during the "update" object.  Clears out the keep
  443.   #                variables at the end of use.
  444.   def dispose_keep
  445.     @savename = nil
  446.     @saveindex = nil
  447.     @saveghost = nil
  448.     @saveswap = nil
  449.     @saveflip = nil
  450.   end
  451.  
  452.   def start_message  # Overwrite start_message
  453.     @text = ""
  454.     @clone = []
  455.     for i in 0...$game_message.texts.size
  456.       @text += "    " if i >= $game_message.choice_start
  457.       @text += $game_message.texts[i].clone
  458.       @text += "    " if i >= $game_message.choice_start
  459.       @text += "\x00"
  460.       @clone[i] = ""
  461.       @clone[i] += "    " if i >= $game_message.choice_start
  462.       @clone[i] += $game_message.texts[i].clone
  463.       @clone[i] += "    " if i >= $game_message.choice_start
  464.     end
  465.     @item_max = $game_message.choice_max
  466.     convert_special_characters
  467.     reset_window
  468.     get_alignment
  469.     check_lbl
  470.     new_page
  471.   end
  472.  
  473.   def new_page  # Overwrite new_page
  474.     contents.clear
  475.     ghost_face_check
  476.     get_face_flip
  477.     if $game_message.face_name.empty?
  478.       @contents_x = 0
  479.       @face_sprite.bitmap.dispose if @face_sprite.bitmap != nil
  480.     else
  481.       name = $game_message.face_name
  482.       index = $game_message.face_index
  483.       @face_offset = draw_message_face(name,index,0,0,@ghostme,@swapme,@flipme)
  484.       @contents_x = @face_offset
  485.       unless CP::CMS::DEFAULT_FACE_LAY
  486.         self.width = Graphics.width - CP::CMS::TEXT_OFFSET
  487.         self.x = CP::CMS::TEXT_OFFSET
  488.         self.x = 0 if @swapme
  489.       end
  490.     end
  491.     @contents_y = 0
  492.     @line_count = 0
  493.     contents.font.bold = false
  494.     contents.font.italic = false
  495.     align_my_text
  496.     @show_fast = false
  497.     get_line_speed
  498.     @pause_skip = false
  499.     contents.font.color = text_color(0)
  500.   end
  501.  
  502.   def new_line  # Overwrite new_line
  503.     if $game_message.face_name.empty?
  504.       @contents_x = 0
  505.       @face_sprite.bitmap.dispose if @face_sprite.bitmap != nil
  506.     else
  507.       @contents_x = @face_offset
  508.     end
  509.     @contents_y += WLH
  510.     @line_count += 1
  511.     align_my_text
  512.     get_line_speed
  513.   end
  514.  
  515.   if CP::CMS::ADVANCED_MODE and CP::CMS::TEXT_MOD
  516.   def convert_special_characters # Overwrite convert_special_characters
  517.     @text.gsub!(/\\V\[([0-9]+)\]/i) { $game_variables[$1.to_i] }
  518.     @text.gsub!(/\\V\[([0-9]+)\]/i) { $game_variables[$1.to_i] }
  519.     @text.gsub!(/\\N\[([0-9]+)\]/i) { $game_actors[$1.to_i].name }
  520.     @text.gsub!(/\\C\[([0-9]+)\]/i) { "\x01[#{$1}]" }
  521.     @text.gsub!(/\\G/i)             { "\x02" }
  522.     @text.gsub!(/\\\./)             { "\x03" }
  523.     @text.gsub!(/\\\|/)             { "\x04" }
  524.     @text.gsub!(/\\!/)              { "\x05" }
  525.     @text.gsub!(/\\>/)              { "\x06" }
  526.     @text.gsub!(/\\</)              { "\x07" }
  527.     @text.gsub!(/\\\^/)             { "\x08" }
  528.     @text.gsub!(/\\\\/)             { "\\" }
  529.     @text.gsub!(/\\IC\[([0-9]+)\]/i){ "\x09[#{$1}]" }
  530.     @text.gsub!(/\\B/i)             { "\x10" }
  531.     @text.gsub!(/\\I/i)             { "\x11" }
  532.     @text.gsub!(/\\FI\[([0-9]+)\]/i){ "\x12[#{$1}]" }
  533.   end
  534.  
  535.   def update_message # Overwrite update_message statement
  536.     loop do
  537.       c = @text.slice!(/./m)            # Get next text character
  538.       case c
  539.       when nil                          # There is no text that must be drawn
  540.         finish_message                  # Finish update
  541.         break
  542.       when "\x00"                       # New line
  543.         new_line
  544.         if @line_count >= MAX_LINE      # If line count is maximum
  545.           unless @text.empty?           # If there is more
  546.             self.pause = true           # Insert number input
  547.             break
  548.           end
  549.         end
  550.       when "\x01"                       # \C[n]  (text character color change)
  551.         @text.sub!(/\[([0-9]+)\]/, "")
  552.         contents.font.color = text_color($1.to_i)
  553.         next
  554.       when "\x02"                       # \G  (gold display)
  555.         @gold_window.refresh
  556.         @gold_window.open
  557.       when "\x03"                       # \.  (wait 1/4 second)
  558.         @wait_count = 15
  559.         break
  560.       when "\x04"                       # \|  (wait 1 second)
  561.         @wait_count = 60
  562.         break
  563.       when "\x05"                       # \!  (Wait for input)
  564.         self.pause = true
  565.         break
  566.       when "\x06"                       # \>  (Fast display ON)
  567.         @line_show_fast = true
  568.       when "\x07"                       # \<  (Fast display OFF)
  569.         @line_show_fast = false
  570.       when "\x08"                       # \^  (No wait for input)
  571.         @pause_skip = true
  572.       when "\x09"                       # \Icon[n]  (Displays an icon)
  573.         @text.sub!(/\[([0-9]+)\]/, "")
  574.         icon_index_num = $1.to_i
  575.         @contents_x += 2
  576.         draw_icon(icon_index_num, @contents_x, @contents_y)
  577.         @contents_x += 26
  578.       when "\x10"                       # \B  (toggles bold display)
  579.         contents.font.bold = !contents.font.bold
  580.       when "\x11"                       # \I  (toggles italic display)
  581.         contents.font.italic = !contents.font.italic
  582.       when "\x12"
  583.         @text.sub!(/\[([0-9]+)\]/, "")
  584.         findex = $1.to_i
  585.         fname = $game_message.face_name
  586.         draw_message_face(fname,findex,0,0,@ghostme,@swapme,@flipme)
  587.       else                              # Normal text character
  588.         contents.draw_text(@contents_x, @contents_y, 40, WLH, c)
  589.         c_width = contents.text_size(c).width
  590.         @contents_x += c_width
  591.       end
  592.       break unless @show_fast or @line_show_fast
  593.     end
  594.   end
  595.   end # Advanced Mode
  596.  
  597.   def start_number_input  # Overwrite start_number_input
  598.     digits_max = $game_message.num_input_digits_max
  599.     number = $game_variables[$game_message.num_input_variable_id]
  600.     @number_input_window.digits_max = digits_max
  601.     @number_input_window.number = number
  602.     @number_input_window.x = ($game_message.face_name.empty? || @swapme) ? x : x + @face_offset
  603.     @number_input_window.y = y + @contents_y
  604.     @number_input_window.active = true
  605.     @number_input_window.visible = true
  606.     @number_input_window.update
  607.   end
  608.  
  609.   def update_cursor  # Overwrite update_cursor
  610.     if @index >= 0
  611.       x = ($game_message.face_name.empty? || @swapme) ? 0 : @face_offset
  612.       y = ($game_message.choice_start + @index) * WLH
  613.       minussize = @swapme ? @face_offset : 0
  614.       self.cursor_rect.set(x, y, contents.width - x - minussize, WLH)
  615.     else
  616.       self.cursor_rect.empty
  617.     end
  618.   end
  619.  
  620.  
  621.   # New object  -  Called during the "new_page" object.  Used to check if there
  622.   #                are any codes that modify the position of the face.
  623.   def get_face_flip
  624.     @swapme = CP::CMS::DEFAULT_SWAPPING              # Sets swapping to default
  625.     @flipme = CP::CMS::DEFAULT_FLIPPING              # Sets flipping to default
  626.     @swapme = @saveswap if @saveswap != nil
  627.     @flipme = @saveflip if @saveflip != nil
  628.     @text.gsub!(/\\(?:right|r)/){"\\swap\\flip"}     # Single code for one side
  629.     @text.gsub!(/\\(?:left|l)/){"\\uswap\\uflip"}
  630.     @text.gsub!(/\\f</){"\\uflip"}                   # Substitutes new codes
  631.     @text.gsub!(/\\s</){"\\uswap"}
  632.     @text.gsub!(/\\f>/){"\\flip"}
  633.     @text.gsub!(/\\s>/){"\\swap"}
  634.     @swapme = false if @text.include?("\\uswap")     # Unsets swapping if true
  635.     @flipme = false if @text.include?("\\uflip")     # Unsets flipping if true
  636.     @swapme = true if @text.include?("\\swap")       # Sets swapping if true
  637.     @flipme = true if @text.include?("\\flip")       # Sets flipping if true
  638.     @text.gsub!(/\\swap/) {""}                       # Clears swapping modifiers
  639.     @text.gsub!(/\\uswap/) {""}                        
  640.     @text.gsub!(/\\flip/) {""}                       # Clears flipping modifiers
  641.     @text.gsub!(/\\uflip/) {""}                            
  642.     @saveswap = @keepme ? @swapme : nil              # Keep me variables
  643.     @saveflip = @keepme ? @flipme : nil
  644.   end
  645.  
  646.   # New object  -  Called during the "new_page" object.  Checks to see if any
  647.   #                alignment modifier codes are present in the text and sets the
  648.   #                new alignment accordingly.
  649.   def get_alignment
  650.     @halign = CP::CMS::DEFAULT_ALIGNMENT            # Sets alignment to default
  651.     @halign = 2 if @text.include?("\\alir")         # Sets alignment to right
  652.     @halign = 2 if @text.include?("\\ar")
  653.     @halign = 1 if @text.include?("\\alic")         # Sets alignment to center
  654.     @halign = 1 if @text.include?("\\ac")
  655.     @halign = 0 if @text.include?("\\alil")         # Sets alignment to left
  656.     @halign = 0 if @text.include?("\\al")
  657.     @text.gsub!(/\\(?:alil|alic|alir|ar|ac|al)/){""}# Clears alignment modifiers
  658.   end
  659.  
  660.   # New object  -  Called during the "new_page" object.  Sets the opacity to
  661.   #                255 and then checks if it should be changed.
  662.   def ghost_face_check
  663.     @ghostme = 255
  664.     @ghostme = @saveghost if @saveghost != nil
  665.     @keepme = false
  666.     if $game_message.face_name.empty?
  667.       $game_message.face_name = @savename if @savename != nil
  668.       $game_message.face_index = @saveindex if @saveindex != nil
  669.     end
  670.     @keepme = true if @text.include?("\\keep")       # Sets keeping if true
  671.     @keepme = true if @text.include?("\\k")
  672.     @text.gsub!(/\\keep/) {""}                       # Clears keeping modifiers
  673.     @text.gsub!(/\\k/) {""}
  674.     @savename = @keepme ? $game_message.face_name : nil  # Keep me variables
  675.     @saveindex = @keepme ? $game_message.face_index : nil
  676.     @text.gsub!(/\\(?:trans|t)\[(\d+)\]/i) {         # Sets transparency
  677.       check_face_trans($1.to_i) }
  678.     @saveghost = @keepme ? @ghostme : nil
  679.   end
  680.  
  681.   # New object  -  Called curing the "new_page" and "new_line" objects.  Sets
  682.   #                the X position of the text based on the alignment defined in
  683.   #                the "get_alignment" object.
  684.   def align_my_text
  685.     unless @clone[@line_count].nil?
  686.       @clone[@line_count].gsub!(/\\V\[([0-9]+)\]/i) { $game_variables[$1.to_i] }
  687.       @clone[@line_count].gsub!(/\\V\[([0-9]+)\]/i) { $game_variables[$1.to_i] }
  688.       @clone[@line_count].gsub!(/\\N\[([0-9]+)\]/i) { $game_actors[$1.to_i].name }
  689.       @clone[@line_count].gsub!(/\\(?:alil|alic|alir|ar|ac|al)/){""}
  690.       @clone[@line_count].gsub!(/\\(?:keep|k|trans|t)/){""}
  691.       @clone[@line_count].gsub!(/\\(?:swap|uswap|flip|uflip|right|left)/){""}
  692.       @clone[@line_count].gsub!(/\\(?:s>|s<|f>|f<|f|l)/){""}
  693.       @clone[@line_count].gsub!(/\\IC\[([0-9]+)\]/i){"[..]"}
  694.       @clone[@line_count].gsub!(/\\(?:C|FI)\[([0-9]+)\]/i){""}
  695.       @clone[@line_count].gsub!(/\\(?:G|B|I)/i){""}
  696.       @clone[@line_count].gsub!(/\\(?:>|<|\.|\\|\^|\||!)/){""}
  697.       @clone[@line_count].gsub!(/\\pos\[(\d+):(\d+)\]/i){""}
  698.       linewidth = Graphics.width - 32 - @contents_x  # Sets the width of a line
  699.       textwidth = contents.text_size(@clone[@line_count]).width# Gets text width
  700.     else
  701.       linewidth = Graphics.width - 32 - @contents_x
  702.       textwidth = contents.text_size(@text).width
  703.     end
  704.    
  705.     if @lineali[@line_count]                  # Gets space for alignment
  706.       newwidth = (linewidth - textwidth) / 2 * @lineali[@line_count]
  707.     else
  708.       newwidth = (linewidth - textwidth) / 2 * @halign
  709.     end
  710.    
  711.     if @swapme                                       # Sets the new alignment
  712.       @contents_x = newwidth
  713.     else
  714.       @contents_x += newwidth    
  715.     end
  716.   end
  717.  
  718.   # New object  -  Called during the "start_message" object.  Checks for any
  719.   #                "line by line" alignment modifying codes.
  720.   def check_lbl
  721.     @lineali = []
  722.     @text.gsub!(/\\pos\[(\d+):(\d+)\]/i) {
  723.       check_lbl_2($1.to_i, $2.to_i) }
  724.   end
  725.  
  726.   # New object  -  Called during the "check_lbl" object.  Sets any available
  727.   #                alignments and then returns a null text.
  728.   def check_lbl_2(linen, align)
  729.     case linen
  730.     when 1, 2, 3, 4
  731.       @lineali[linen-1] = align
  732.     end
  733.     retme = ""
  734.     return retme
  735.   end
  736.  
  737.   # New object  -  Called during the "ghost_face_check" object.  Checks if a
  738.   #                new transparencty is called for the face.
  739.   def check_face_trans(ghostme)
  740.     @ghostme = ghostme
  741.     retme = ""
  742.     return retme
  743.   end
  744.   # New object  -  Called during the "new_page" and "new_line" objects.  Checks
  745.   #                what the line speed is currently set to.  May change this in
  746.   #                the future so saving this for space.
  747.   def get_line_speed
  748.     @line_show_fast = CP::CMS::TEXT_TYPE_OR_SKIP
  749.   end
  750. end
  751.  
  752.  
  753. ###--------------------------------------------------------------------------###
  754. #  End of script.                                                              #
  755. ###--------------------------------------------------------------------------###
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement