Advertisement
roninator2

TSDA Advanced Message System Mod

Dec 5th, 2024
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 23.18 KB | None | 0 0
  1. #===============================================================================
  2. # http://thiagodd.blogspot.com.br/
  3. # TSDA Advanced Message System
  4. #   by thiago_d_d
  5. #   Version 1.2.1
  6. # Mod by Roninator2
  7. # Any suggestions are apreciated, please make them here:
  8. # http://thiagodd.blogspot.com.br/
  9. #===============================================================================
  10. # Changelog of this version:
  11. #      - Fixed the bug with the y position of gold window.
  12. #      - Added an italic tag.
  13. #      - Added option to deactivate face window during game play. Now the face
  14. # window is activated by an switch, so if you don't want to use face outside
  15. # the window, deactivate that switch.
  16. #===============================================================================
  17. # Features
  18. #    - Created name window to show a name of your choice, only if you want.
  19. #    - The name window is customized, so you change color, etc.
  20. #    - Added support to hex colors.
  21. #    - Advanced letter by letter mode with advanced speed configuration.
  22. #    - You can choose if the player can skip the letter by letter mode
  23. #    - Added \Map tag, that shows the actual map name display
  24. #    - Added support to changes to the font name, size, and bold flag.
  25. #    - The face can be shown on a separate window.
  26. #    - The face can be shown on the right when separate window.
  27. #    - Message window position and size can now be customized.
  28. #    - Message window opacity can be customized.
  29. #    - Possibility to play an sound when letter by letter is on.
  30. #    - Everything is customized, you can change everything with tags during the
  31. #      text draw.
  32. #===============================================================================
  33. # Changing window size and position
  34. #===============================================================================
  35. # To change height, width, and x position -> go to TSDA module and configure
  36. # To change message window y position, execute a script, there are 4 options
  37. #
  38. # $game_message.real_position = desired_y
  39. #     changes the position to the desired y position in the screen
  40. #
  41. # $game_message.real_position = "event_id"
  42. #     changes the position based on the specified event coordinates, so the
  43. #     window will not be above the event
  44. #
  45. # $game_message.real_position = "player"
  46. #     changes the position based on the player coordinates, so the
  47. #     window will not be above the player
  48. #
  49. # $game_message.real_position = nil
  50. #     the message window position will be normal, like if there is not
  51. #     this script
  52. #===============================================================================
  53. # Playing sound letter by letter
  54. #===============================================================================
  55. # Configure the switch that activates that mode on the TSDA module.
  56. # To determine the sound that will be player, execute the script:
  57. #     $game_message.letter_sound = "Sound name"
  58. # Sound should be on the SE folder
  59. #===============================================================================
  60. # OLD TAGS
  61. #    These tags already exists, only listing them to make things easy for you.
  62. #===============================================================================
  63. # \V[ID] - Shows the value of the variable with the specified ID.
  64. # \N[ID] - Shows the name of the hero with the specified ID.
  65. # \C[ID] - Changes the color to that color index of the windowskin.
  66. # \P[n] - Shows the name of the hero in the team that has the specified position
  67. # \$ - Shows gold window.
  68. # \I[index] - Show the icon with the specified index.
  69. # \G - Shows the gold name.
  70. # \{ - Increases font size.
  71. # \} - Decreases font size.
  72. # \. - waits for 0.25 seconds.
  73. # \| - waits for 1 second.
  74. # \\ - draws the \ character.
  75. # \< - Shows the next text imediately.
  76. # \> - Stops to show the text imediately
  77. # \! - Pauses the window, waiting for input.
  78. # \^ - Closes the window.
  79. #===============================================================================
  80. # NEWS TAGS
  81. #    You can still use old tags, they work normally.
  82. #===============================================================================
  83. # \c[#000000]
  84. #      changes text color by the specified hex color.
  85. #---------------------------------------
  86. # \M
  87. #      activates the letter by letter mode if it is activated, or deactivate is
  88. #      if it is activated.
  89. #---------------------------------------
  90. # \Q[speed]
  91. #      changes letter by letter by letter mode speed delay.
  92. #---------------------------------------
  93. # \W
  94. #      activates the jump letter by letter function if it is deactivate, or
  95. #      deactivates it if it is activated.
  96. #---------------------------------------
  97. # \Map
  98. #      shows the actual map name.
  99. #---------------------------------------
  100. # \S[Text]
  101. #      shows the name window above the message window, with the specified text.
  102. #      You can use other tags inside the text
  103. #---------------------------------------
  104. # \R
  105. #      closes the name window
  106. #---------------------------------------
  107. # \I[color]
  108. #      changes the name window text color(supports hex)
  109. #---------------------------------------
  110. # \F[font name]
  111. #      changes the message window font
  112. #---------------------------------------
  113. # \L
  114. #      sets the font to bold, if it's not bold, or set it to normal,
  115. #      if it is bold
  116. #---------------------------------------
  117. # \H[size]
  118. #      sets the font size
  119. #---------------------------------------
  120. # \X
  121. #      sets the font to italic if it's not italic, or set it to normal, if it
  122. #      is italic
  123. #---------------------------------------
  124. #===============================================================================
  125. #===============================================================================
  126. # module TSDA
  127. #===============================================================================
  128. module TSDA
  129.   #ID of the switch that activates letter by letter mode
  130.   AMS_LETTER_BY_LETTER_SWITCH = 1
  131.   #ID of the switch that indicates if the player can jump letter by letter mode
  132.   AMS_JUMP_LBL_SWITCH = 2
  133.   #ID of the variable that indicates letter by letter mode speed delay.
  134.   AMS_SPEED_DELAY_LBL_VARIABLE = 1
  135.   #The font used in the name box
  136.   # format:
  137.   # ["name",size,bold]
  138.   NAME_BOX_FONT = ["Trebuchet MS",Font.default_size,false]
  139.   #Number of lines of the message window, determines the window height
  140.   #Width of the window and the x pos of the window
  141.   MESSAGE_WINDOW_LINES = 3
  142.   MESSAGE_WINDOW_WIDTH = 400
  143.   MESSAGE_WINDOW_XPOS = 30
  144.   #Face window opacity
  145.   NAME_WINDOW_OPACITY = 160
  146.   NAME_WINDOW_BACK_OPACITY = 160
  147.   #Use face window?
  148.   USE_MESSAGE_FACE_WINDOW_SWITCH = 4
  149.   # above switch must be on.
  150.   USE_MESSAGE_FACE_WINDOW_SWITCH_RIGHT = 5
  151.   #Face window opacity
  152.   FACE_WINDOW_OPACITY = 160
  153.   FACE_WINDOW_BACK_OPACITY = 160
  154.   #id of the switch that determinates if the letter sound will be played
  155.   LETTER_SOUND_SWITCH = 3
  156. end
  157. #===============================================================================
  158. # Game_Message
  159. #===============================================================================
  160. class Game_Message
  161.   attr_accessor         :real_position
  162.   attr_accessor         :letter_sound
  163. end
  164. #===============================================================================
  165. # Window_Message
  166. #===============================================================================
  167. class Window_Message
  168.   include TSDA
  169.   #-----------------------------------------------------------------------------
  170.   # initialize - overwritten method
  171.   #-----------------------------------------------------------------------------
  172.   def initialize
  173.     super(MESSAGE_WINDOW_XPOS, 0, MESSAGE_WINDOW_WIDTH, window_height)
  174.     self.z = 200
  175.     self.openness = 0
  176.     create_all_windows
  177.     create_back_bitmap
  178.     create_back_sprite
  179.     clear_instance_variables
  180.   end
  181.   #-----------------------------------------------------------------------------
  182.   # visible_line_number - overwritten method
  183.   #-----------------------------------------------------------------------------
  184.   def visible_line_number
  185.     return MESSAGE_WINDOW_LINES
  186.   end
  187.   #-----------------------------------------------------------------------------
  188.   # new_line_x - aliased method
  189.   #-----------------------------------------------------------------------------
  190.   alias ams_new_line_x new_line_x
  191.   def new_line_x
  192.     $game_switches[USE_MESSAGE_FACE_WINDOW_SWITCH] ? 0 : ams_new_line_x
  193.   end
  194.   #-----------------------------------------------------------------------------
  195.   # obtain_escape_code - overwritten method
  196.   #-----------------------------------------------------------------------------
  197.   def obtain_escape_code(text)
  198.     text.slice!(/^[\$\.\|\^!><\{\}\\]|^[A-Z]{1}/i)
  199.   end
  200.   #-----------------------------------------------------------------------------
  201.   # new_page - overwritten method
  202.   #-----------------------------------------------------------------------------
  203.   def new_page(text, pos)
  204.     contents.clear
  205.     if $game_switches[USE_MESSAGE_FACE_WINDOW_SWITCH]
  206.       if $game_switches[USE_MESSAGE_FACE_WINDOW_SWITCH_RIGHT]
  207.         @face_window.right_face(MESSAGE_WINDOW_XPOS + MESSAGE_WINDOW_WIDTH - 120)
  208.       end
  209.       @face_window.set_face(self,$game_message.face_name, $game_message.face_index)
  210.     else
  211.       @face_window.visible = false
  212.       draw_face($game_message.face_name, $game_message.face_index, 0, 0)
  213.     end
  214.     reset_font_settings
  215.     pos[:x] = new_line_x
  216.     pos[:y] = 0
  217.     pos[:new_x] = new_line_x
  218.     pos[:height] = calc_line_height(text)
  219.     clear_flags
  220.   end
  221.   #-----------------------------------------------------------------------------
  222.   # obtain_real_escape_param - new method
  223.   #-----------------------------------------------------------------------------
  224.   def obtain_real_escape_param(text,hex=true)
  225.     if hex
  226.       text.slice!(/^\[[0123456789ABCDEF#]+\]/)[/[0123456789ABCDEF#]+/] rescue nil
  227.     else
  228.       text.slice!(/^\[[\w\s]+\]/)[/[\w\s]+/] rescue nil
  229.     end
  230.   end
  231.   #-----------------------------------------------------------------------------
  232.   # convert_escape_characters - overwritten method
  233.   #-----------------------------------------------------------------------------
  234.   def convert_escape_characters(text)
  235.     result = text.to_s.clone
  236.     result.gsub!(/\\/)            { "\e" }
  237.     result.gsub!(/\e\e/)          { "\\" }
  238.     result.gsub!(/\eV\[(\d+)\]/i) { $game_variables[$1.to_i] }
  239.     result.gsub!(/\eN\[(\d+)\]/i) { actor_name($1.to_i) }
  240.     result.gsub!(/\eP\[(\d+)\]/i) { party_member_name($1.to_i) }
  241.     result.gsub!(/\eG/i)          { Vocab::currency_unit }
  242.     result.gsub!(/\eMap/i)        { $game_map.display_name }
  243.     result
  244.   end
  245.   #-----------------------------------------------------------------------------
  246.   # process_escape_character - aliased method
  247.   #-----------------------------------------------------------------------------
  248.   alias ams_process_escape_character process_escape_character
  249.   def process_escape_character(code, text, pos)
  250.     case code.upcase
  251.     when 'C'
  252.       param = obtain_real_escape_param(text)
  253.       if param[0,1] == "#" and param.size == 7
  254.         change_color(convert_to_hex(param[1,6]))
  255.       else
  256.         change_color(text_color(param.to_i))
  257.       end
  258.     when 'M'
  259.       sw = $game_switches[AMS_LETTER_BY_LETTER_SWITCH]
  260.       $game_switches[AMS_LETTER_BY_LETTER_SWITCH] = !sw
  261.       @letter_by_letter_mode = $game_switches[AMS_LETTER_BY_LETTER_SWITCH]
  262.     when 'Q'
  263.       param = obtain_escape_param(text)
  264.       $game_variables[AMS_SPEED_DELAY_LBL_VARIABLE] = param
  265.       @lbl_max = $game_variables[AMS_SPEED_DELAY_LBL_VARIABLE]
  266.     when 'W'
  267.       sw = $game_switches[AMS_JUMP_LBL_SWITCH]
  268.       $game_switches[AMS_JUMP_LBL_SWITCH] = !sw
  269.       @can_jump = $game_switches[AMS_JUMP_LBL_SWITCH]
  270.     when 'S'
  271.       param = obtain_real_escape_param(text,false)
  272.       @message_name_window.set_text(param,self)
  273.     when 'R'
  274.       @message_name_window.finish
  275.     when 'I'
  276.       param = obtain_real_escape_param(text)
  277.       if param[0,1] == "#" and param.size == 7
  278.         color = convert_to_hex(param[1,6])
  279.       else
  280.         color = text_color(param.to_i)
  281.       end
  282.       @message_name_window.font_color = color
  283.       @message_name_window.refresh
  284.     when 'F'
  285.       param = obtain_real_escape_param(text,false)
  286.       self.contents.font.name = param
  287.     when 'L'
  288.       self.contents.font.bold = !self.contents.font.bold
  289.     when 'H'
  290.       param = obtain_real_escape_param(text).to_i
  291.       self.contents.font.size = param
  292.     when 'X'
  293.       self.contents.font.italic = !self.contents.font.italic
  294.     else
  295.       ams_process_escape_character(code, text, pos)
  296.     end
  297.   end
  298.   #-----------------------------------------------------------------------------
  299.   # convert_to_hex - new method
  300.   #-----------------------------------------------------------------------------
  301.   def convert_to_hex(text)
  302.     return nil if text.size != 6
  303.     rgb = [0,0,0]
  304.     for index in 0...6
  305.       letter = text.slice!(/./m)
  306.       hex = hex_value(letter)
  307.       if index % 2 == 0
  308.         rgb[index / 2] += hex * 16
  309.       else
  310.         rgb[index / 2] += hex
  311.       end
  312.     end
  313.     return Color.new(rgb[0],rgb[1],rgb[2])
  314.   end
  315.   #-----------------------------------------------------------------------------
  316.   # hex_value - new method
  317.   #-----------------------------------------------------------------------------
  318.   def hex_value(text)
  319.     case text
  320.     when "0"
  321.       return 0
  322.     when "1"
  323.       return 1
  324.     when "2"
  325.       return 2
  326.     when "3"
  327.       return 3
  328.     when "4"
  329.       return 4
  330.     when "5"
  331.       return 5
  332.     when "6"
  333.       return 6
  334.     when "7"
  335.       return 7
  336.     when "8"
  337.       return 8
  338.     when "9"
  339.       return 9
  340.     when "A"
  341.       return 10
  342.     when "B"
  343.       return 11
  344.     when "C"
  345.       return 12
  346.     when "D"
  347.       return 13
  348.     when "E"
  349.       return 14
  350.     when "F"
  351.       return 15
  352.     end
  353.   end
  354.   #-----------------------------------------------------------------------------
  355.   # process_all_text - aliased method
  356.   #-----------------------------------------------------------------------------
  357.   alias ams_process_all_text process_all_text
  358.   def process_all_text
  359.     @letter_by_letter_mode = $game_switches[AMS_LETTER_BY_LETTER_SWITCH]
  360.     @lbl_max = $game_variables[AMS_SPEED_DELAY_LBL_VARIABLE]
  361.     @can_jump = $game_switches[AMS_JUMP_LBL_SWITCH]
  362.     ams_process_all_text
  363.   end
  364.   #-----------------------------------------------------------------------------
  365.   # wait_for_one_character - overwritten method
  366.   #-----------------------------------------------------------------------------
  367.   def wait_for_one_character
  368.     return if @show_fast
  369.     if @letter_by_letter_mode
  370.       if @can_jump
  371.         @show_fast = true if Input.press?(:B)
  372.         if Input.press?(:C)
  373.           if $game_variables[AMS_SPEED_DELAY_LBL_VARIABLE] > 1
  374.             @lbl_max = 1
  375.           else
  376.             @lbl_max = 0
  377.           end
  378.         else
  379.           @lbl_max = $game_variables[AMS_SPEED_DELAY_LBL_VARIABLE]
  380.         end
  381.       end
  382.       if @lbl_max > 0
  383.         play_sound = $game_switches[LETTER_SOUND_SWITCH]
  384.         Audio.se_play("Audio/SE/" + $game_message.letter_sound) if play_sound
  385.         for time in 0...@lbl_max
  386.           Fiber.yield
  387.         end
  388.       end
  389.     end
  390.   end
  391.   #-----------------------------------------------------------------------------
  392.   # update_placement - aliased method
  393.   #-----------------------------------------------------------------------------
  394.   alias ams_update_placement update_placement
  395.   def update_placement
  396.     @real_position = $game_message.real_position
  397.     @position = $game_message.position
  398.     if @real_position.nil?
  399.       self.y = @position * (Graphics.height - height) / 2
  400.     elsif @real_position.is_a?(Integer)
  401.       self.y = @real_position
  402.     elsif @real_position == "player"
  403.       y = $game_player.screen_y - 48
  404.       hei = calculate_total_component_height + 48
  405.       if y >= hei
  406.         self.y = $game_player.screen_y - height - 48
  407.       else
  408.         self.y = $game_player.screen_y
  409.       end
  410.     else
  411.       param = @real_position.to_i
  412.       event = $game_map.events[param]
  413.       y = event.screen_y - 48
  414.       hei = calculate_total_component_height + 48
  415.       if y >= hei
  416.         self.y = event.screen_y - height - 48
  417.       else
  418.         self.y = event.screen_y
  419.       end
  420.     end
  421.     @gold_window.y = ((self.y > @gold_window.height) ?
  422.       0 : Graphics.height - @gold_window.height)
  423.   end
  424.   #-----------------------------------------------------------------------------
  425.   # calculate_total_component_height - new method
  426.   #-----------------------------------------------------------------------------
  427.   def calculate_total_component_height
  428.     h = height + calculate_extra_component_height
  429.     h
  430.   end
  431.   #-----------------------------------------------------------------------------
  432.   # calculate_extra_component_height - new method
  433.   #-----------------------------------------------------------------------------
  434.   def calculate_extra_component_height
  435.     h = 0
  436.     if $game_switches[USE_MESSAGE_FACE_WINDOW_SWITCH] and !$game_message.face_name.empty?
  437.       h = 120
  438.     elsif @message_name_window.visible
  439.       h = @message_name_window.height
  440.     end
  441.     h
  442.   end
  443.   #-----------------------------------------------------------------------------
  444.   # settings_changed? - aliased method
  445.   #-----------------------------------------------------------------------------
  446.   alias ams_settings_changed? settings_changed?
  447.   def settings_changed?
  448.     return ams_settings_changed? ||
  449.       @real_position != $game_message.real_position
  450.   end
  451.   #-----------------------------------------------------------------------------
  452.   # create_all_windows - aliased method
  453.   #-----------------------------------------------------------------------------
  454.   alias ams_create_all_windows create_all_windows
  455.   def create_all_windows
  456.     ams_create_all_windows
  457.     @message_name_window = Window_MessageName.new
  458.     @face_window = Window_MessageFace.new
  459.   end
  460.   #-----------------------------------------------------------------------------
  461.   # dispose_all_windows - aliased method
  462.   #-----------------------------------------------------------------------------
  463.   alias ams_dispose_all_windows dispose_all_windows
  464.   def dispose_all_windows
  465.     ams_dispose_all_windows
  466.     @message_name_window.dispose
  467.     @face_window.dispose
  468.   end
  469.   #-----------------------------------------------------------------------------
  470.   # update_all_windows - aliased method
  471.   #-----------------------------------------------------------------------------
  472.   alias ams_update_all_windows update_all_windows
  473.   def update_all_windows
  474.     ams_update_all_windows
  475.     @message_name_window.update
  476.     @face_window.update
  477.   end
  478.   #-----------------------------------------------------------------------------
  479.   # close_and_wait - aliased method
  480.   #-----------------------------------------------------------------------------
  481.   alias ams_close_and_wait close_and_wait
  482.   def close_and_wait
  483.     @message_name_window.finish
  484.     @face_window.finish
  485.     ams_close_and_wait
  486.   end
  487. end
  488. #===============================================================================
  489. # Window_MessageName - new class
  490. #===============================================================================
  491. class Window_MessageName < Window_Base
  492.   include TSDA
  493.   #-----------------------------------------------------------------------------
  494.   attr_accessor          :font_color
  495.   #-----------------------------------------------------------------------------
  496.   # initialize - new method
  497.   #-----------------------------------------------------------------------------
  498.   def initialize
  499.     super(0,0,10,10)
  500.     self.visible = false
  501.     self.openness = 0
  502.     self.back_opacity = NAME_WINDOW_BACK_OPACITY
  503.     self.opacity = NAME_WINDOW_OPACITY
  504.     @font_color = text_color(0)
  505.   end
  506.   #-----------------------------------------------------------------------------
  507.   # set_text - new method
  508.   #-----------------------------------------------------------------------------
  509.   def set_text(text,window)
  510.     @text = text
  511.     bitmap = Bitmap.new(10,10)
  512.     bitmap.font.name = NAME_BOX_FONT[0]
  513.     bitmap.font.size = NAME_BOX_FONT[1]
  514.     bitmap.font.bold = NAME_BOX_FONT[2]
  515.     size = bitmap.text_size(text)
  516.     self.width = size.width + 24
  517.     self.height = size.height + 24
  518.     self.contents = Bitmap.new(size.width,size.height)
  519.     contents.font.name = NAME_BOX_FONT[0]
  520.     contents.font.size = NAME_BOX_FONT[1]
  521.     contents.font.bold = NAME_BOX_FONT[2]
  522.     h = window.calculate_extra_component_height
  523.     self.y = window.y > h ? window.y - height : window.y + window.height
  524.     self.x = ($game_message.face_name.empty? or !$game_switches[USE_MESSAGE_FACE_WINDOW_SWITCH]) ?
  525.       window.x : window.x + 120
  526.     self.visible = true
  527.     refresh
  528.     open
  529.     Fiber.yield until open?
  530.   end
  531.   #-----------------------------------------------------------------------------
  532.   # refresh - new method
  533.   #-----------------------------------------------------------------------------
  534.   def refresh
  535.     contents.clear
  536.     contents.font.color = @font_color
  537.     contents.draw_text(0,0,width - 24,height - 24,@text)
  538.   end
  539.   #-----------------------------------------------------------------------------
  540.   # finish - new method
  541.   #-----------------------------------------------------------------------------
  542.   def finish
  543.     close
  544.     until close?
  545.       update
  546.       Fiber.yield
  547.     end
  548.     self.openness = 0
  549.     self.visible = false
  550.   end
  551. end
  552. #===============================================================================
  553. # Window_MessageFace - new class
  554. #===============================================================================
  555. class Window_MessageFace < Window_Base
  556.   include TSDA
  557.   #---------------------------------------------------------------------------
  558.   # initialize - new method
  559.   #---------------------------------------------------------------------------
  560.   def initialize
  561.     super(0,0,120,120)
  562.     self.visible = false
  563.     self.openness = 0
  564.     self.back_opacity = FACE_WINDOW_BACK_OPACITY
  565.     self.opacity = FACE_WINDOW_OPACITY
  566.     @adjust = 0
  567.   end
  568.   #---------------------------------------------------------------------------
  569.   # set_face - new method
  570.   #---------------------------------------------------------------------------
  571.   def set_face(window,face_name,face_index)
  572.     self.y = window.y > 120 ? window.y - height : window.y + window.height
  573.     if $game_switches[USE_MESSAGE_FACE_WINDOW_SWITCH_RIGHT]
  574.       self.x = @adjust
  575.     else
  576.       self.x = window.x
  577.     end
  578.     self.visible = true
  579.     refresh
  580.     open
  581.     Fiber.yield until open?
  582.   end
  583.   def right_face(pos=0)
  584.     @adjust = pos
  585.   end
  586.   #---------------------------------------------------------------------------
  587.   # refresh - new method
  588.   #---------------------------------------------------------------------------
  589.   def refresh
  590.     contents.clear
  591.     draw_face($game_message.face_name, $game_message.face_index, 0, 0)
  592.   end
  593.   #---------------------------------------------------------------------------
  594.   # finish - new method
  595.   #---------------------------------------------------------------------------
  596.   def finish
  597.     close
  598.     until close?
  599.       update
  600.       Fiber.yield
  601.     end
  602.     self.openness = 0
  603.     self.visible = false
  604.   end
  605. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement