SHARE
TWEET

Galv's Double Message

khanhdu Jun 11th, 2017 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #------------------------------------------------------------------------------#
  2. #  Galv's Double Message
  3. #------------------------------------------------------------------------------#
  4. #  For: RPGMAKER VX ACE
  5. #  Version 0.5
  6. #------------------------------------------------------------------------------#
  7. #  2012-11-30 - version 0.5 - incomplete release
  8. #------------------------------------------------------------------------------#
  9. #  This was an attempt at being able to show two messages at once. I couldn't
  10. #  work out how to do it how I wanted and decided to give up. It is usable in
  11. #  it's current state, though. The current problems are:
  12. #  - you cannot skip through the text while displaying the double message
  13. #  - you have to add double message text with script calls which is painful and
  14. #  could be hard for beginners.
  15. #------------------------------------------------------------------------------#
  16. #  INSTRUCTIONS:
  17. #  Put below materials, above main.
  18. #  To create a double message, use this SCRIPT CALL before a normal message:
  19. #
  20. #------------------------------------------------------------------------------#
  21. #  msg("Text goes in here","Face Name", face_position)
  22. #------------------------------------------------------------------------------#
  23. #
  24. #  - "Face Name" is the name of the faceset you want a face from, eg "Actor1"
  25. #  - face_position is where in that faceset the face you want is. 0 is first
  26. #  - "Test goes in here" - this is where it's painful as the script box is very
  27. #    small. Each new line in the script box is a new line in the message box
  28. #    unless you create multiple strings and add them together.
  29. #
  30. #------------------------------------------------------------------------------#
  31.  
  32. #------------------------------------------------------------------------------#
  33. #  EXAMPLE 1
  34. #------------------------------------------------------------------------------#
  35. #
  36. #  msg("This is the text that would appear
  37. #  in the script box. As the script box is
  38. #  small, it wraps, which will also make
  39. #  it wrap in the message window.",
  40. #  "Actor1", 0)
  41. #
  42. #-- Appears as ----------------------------------------------------------------#
  43. #   ________
  44. #  |        |   This is the text that would appear
  45. #  |  face  |   in the script box. As the script box is
  46. #  |        |   small, it wraps, which will also make
  47. #  |________|   it wrap in the message window.
  48. #
  49. #------------------------------------------------------------------------------#
  50.  
  51. #------------------------------------------------------------------------------#
  52. #  EXAMPLE 2  - multiple strings added together so line breaks aren't used
  53. #------------------------------------------------------------------------------#
  54. #  msg("This is the text that would appear" +
  55. #  "in the script box.
  56. #  As the script box is small, it wraps," +
  57. #  "which will also make
  58. #  it wrap in the message window.",
  59. #  "Actor1", 0)
  60. #
  61. #-- Appears as ----------------------------------------------------------------#
  62. #   ________
  63. #  |        |   This is the text that would appear in the script box.
  64. #  |  face  |   As the script box is small, it wraps, which will also make
  65. #  |        |   it wrap in the message window.
  66. #  |________|  
  67. #
  68. #------------------------------------------------------------------------------#
  69.  
  70. #------------------------------------------------------------------------------#
  71. #  MESSAGE CODES
  72. #------------------------------------------------------------------------------#
  73. #  Most normal message codes work, but in a scrip call you need to put 2 slashes
  74. #  eg. \\c[1]
  75. #  Also, \\n will create a new line the same as a return.
  76. #------------------------------------------------------------------------------#
  77.  
  78. #------------------------------------------------------------------------------#
  79. #  NOTES:
  80. #------------------------------------------------------------------------------#
  81. #  A double message will only ever appear when a real message is called.
  82. #  A double message will only disappear when a real message does. If you add
  83. #  wait of 10 between messages, you can remove the double message and add a new
  84. #  one if required. See demo for examples of this in use.
  85. #------------------------------------------------------------------------------#
  86. #  REMEMBER: This is not finished and I plan to come back to it later when I
  87. #  have possibly start to understand why the issues I was having were happening.
  88. #------------------------------------------------------------------------------#
  89.  
  90. ($imported ||= {})["Galvs_Double_Message"] = true
  91. module Galv_Msgs
  92.  
  93. #------------------------------------------------------------------------------#
  94. #  SCRIPT SETTINGS
  95. #------------------------------------------------------------------------------#  
  96.  
  97.   DISABLE_SKIP_SWITCH = 1   # Turn switch ON to disable skipping messages
  98.                             # skipping is always disabled when using 2 mesasges
  99.  
  100. #------------------------------------------------------------------------------#
  101. #  END SCRIPT SETTINGS
  102. #------------------------------------------------------------------------------#  
  103.  
  104. end # don't touch
  105.  
  106.  
  107. class Window_Message2 < Window_Base
  108.   def initialize
  109.     super(0, 0, window_width, window_height)
  110.     self.z = 200
  111.     self.openness = 0
  112.     clear_instance_variables
  113.   end
  114.  
  115.   def window_width
  116.     Graphics.width
  117.   end
  118.  
  119.   def window_height
  120.     fitting_height(visible_line_number)
  121.   end
  122.  
  123.   def clear_instance_variables
  124.     @fiber2 = nil
  125.     @background = 0
  126.     @position2 = 0
  127.   end
  128.  
  129.   def visible_line_number
  130.     return 4
  131.   end
  132.  
  133.   def update
  134.     super
  135.     update_close if !$game_message.visible
  136.     self.visible = false if $game_message.remove2 == true
  137.     update_fiber
  138.   end
  139.  
  140.   def update_close
  141.     return if self.openness <= 0
  142.     self.openness -= 48
  143.   end
  144.  
  145.   def update_fiber
  146.     if @fiber2
  147.       @fiber2.resume
  148.     elsif $game_message.visible && !$game_message.scroll_mode
  149.       @fiber2 = Fiber.new { fiber_main }
  150.       @fiber2.resume
  151.         else
  152.       $game_message.visible = false
  153.       $game_message.clear
  154.       $game_message.clear2
  155.     end
  156.   end
  157.  
  158.   def fiber_main
  159.     update_background
  160.     update_placement
  161.     loop do
  162.       process_all_text if $game_message.texts2 != ""
  163.       $game_message.clear2
  164.       Fiber.yield
  165.       break unless $game_message.busy?
  166.     end
  167.     close
  168.     Fiber.yield
  169.     @fiber2 = nil
  170.   end
  171.  
  172.   def update_background
  173.     @background = $game_message.background
  174.     self.opacity = @background == 0 ? 255 : 0
  175.   end
  176.  
  177.   def update_placement
  178.     case $game_message.position
  179.     when 2
  180.       @position2 = 0
  181.     when 0
  182.       @position2 = 2
  183.     end
  184.     self.y = @position2 * (Graphics.height - height) / 2
  185.   end
  186.  
  187.   def process_all_text
  188.     $game_message.disable_skip = true
  189.     open
  190.     text = convert_escape_characters($game_message.texts2)
  191.     pos = {}
  192.     new_page(text, pos)
  193.     process_character(text.slice!(0, 1), text, pos) until $game_message.texts2 == ""
  194.   end
  195.  
  196.   def text_continue?
  197.     $game_message.texts2 != ""
  198.   end
  199.  
  200.   def wait(duration)
  201.     duration.times { Fiber.yield }
  202.   end
  203.  
  204.   # Crash caused when show fast enabled. Disabled it.
  205.   #def update_show_fast
  206.   #  @show_fast = true if Input.trigger?(:C)
  207.   #end
  208.  
  209.   def wait_for_one_character
  210.     #update_show_fast
  211.     Fiber.yield #unless @show_fast
  212.   end
  213.  
  214.   def new_page(text, pos)
  215.     contents.clear
  216.     draw_face($game_message.face_name2, $game_message.face_index2, 0, 0)
  217.     reset_font_settings
  218.     pos[:x] = new_line_x
  219.     pos[:y] = 0
  220.     pos[:new_x] = new_line_x
  221.     pos[:height] = calc_line_height(text)
  222.   end
  223.  
  224.   def new_line_x
  225.     $game_message.face_name2 == "" ? 0 : 112
  226.   end
  227.  
  228.   def process_character(c, text, pos)
  229.     case c
  230.     when "\n"
  231.       process_new_line(text, pos)
  232.     when "\f"
  233.       process_new_page(text, pos)
  234.     when "\e"
  235.       process_escape_character(obtain_escape_code(text), text, pos)
  236.     else
  237.       process_normal_character(c, pos)
  238.     end
  239.   end
  240.  
  241.   def process_normal_character(c, pos)
  242.     text_width = text_size(c).width
  243.     draw_text(pos[:x], pos[:y], text_width * 2, pos[:height], c)
  244.     pos[:x] += text_width
  245.     wait_for_one_character
  246.   end
  247.  
  248.   def process_new_line(text, pos)
  249.     @line_show_fast = false
  250.     super
  251.     if need_new_page?(text, pos)
  252.       input_pause
  253.       new_page(text, pos)
  254.     end
  255.   end
  256.  
  257.   def need_new_page?(text, pos)
  258.     pos[:y] + pos[:height] > contents.height && !text.empty?
  259.   end
  260.  
  261.   def process_new_page(text, pos)
  262.     text.slice!(/^\n/)
  263.     input_pause
  264.     new_page(text, pos)
  265.   end
  266.  
  267.   def process_draw_icon(icon_index, pos)
  268.     super
  269.     wait_for_one_character
  270.   end
  271.  
  272.   def process_escape_character(code, text, pos)
  273.     case code.upcase
  274.     when '$'
  275.       @gold_window.open
  276.     when '.'
  277.       wait(15)
  278.     when '|'
  279.       wait(60)
  280.     when '!'
  281.       input_pause
  282.     when '>'
  283.       @line_show_fast = true
  284.     when '<'
  285.       @line_show_fast = false
  286.     when '^'
  287.       @pause_skip = true
  288.     else
  289.       super
  290.     end
  291.   end
  292.  
  293.   def input_pause
  294.     self.pause = true
  295.     wait(10)
  296.     #Fiber.yield until Input.trigger?(:B) || Input.trigger?(:C)
  297.     Fiber.yield until $game_message.btn_pressed
  298.     #Input.update
  299.     self.pause = false
  300.     $game_message.btn_pressed = false
  301.   end
  302.  
  303. end # Window_Message2 < Window_Base
  304.  
  305.  
  306. class Game_Message
  307.   attr_accessor :texts2
  308.   attr_accessor :face_name2
  309.   attr_accessor :face_index2
  310.   attr_accessor :remove2
  311.   attr_accessor :disable_skip
  312.   attr_accessor :btn_pressed
  313.  
  314.   alias galv_messages_message_initialize initialize
  315.   def initialize
  316.     galv_messages_message_initialize
  317.     @remove2 = false
  318.     clear2
  319.   end
  320.  
  321.   def clear2
  322.     @texts2 = ""
  323.     @face_name2 = ""
  324.     @face_index2 = 0
  325.     @disable_skip = false
  326.     @btn_pressed = false
  327.   end
  328. end # Game_Message
  329.  
  330.  
  331. class Game_Interpreter
  332.   def msg(texts, face_name, face_index)
  333.     $game_message.texts2 = texts
  334.     $game_message.face_name2 = face_name
  335.     $game_message.face_index2 = face_index
  336.   end
  337. end # Game_Interpreter
  338.  
  339.  
  340. class Scene_Map
  341.   alias galv_messages_map_create_message_window create_message_window
  342.   def create_message_window
  343.     galv_messages_map_create_message_window
  344.     @message_window2 = Window_Message2.new
  345.   end
  346. end # Scene_Map
  347.  
  348.  
  349. class Window_Message < Window_Base
  350.  
  351.   alias galv_messages_window_wait_for_one_character wait_for_one_character
  352.   def wait_for_one_character
  353.     return Fiber.yield if $game_message.disable_skip || $game_switches[Galv_Msgs::DISABLE_SKIP_SWITCH]
  354.     galv_messages_window_wait_for_one_character
  355.   end
  356.  
  357.   alias galv_messages_window_close_and_wait close_and_wait
  358.   def close_and_wait
  359.     $game_message.clear2
  360.     galv_messages_window_close_and_wait
  361.   end
  362.  
  363.   alias galv_messages_window_input_pause input_pause
  364.   def input_pause
  365.     galv_messages_window_input_pause
  366.     $game_message.btn_pressed = true
  367.   end
  368.  
  369. end # Window_Message < Window_Base
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top