Advertisement
roninator2

Kid Friendly Basic Quest - Battle Message

Dec 13th, 2024
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 14.71 KB | None | 0 0
  1. # ╔═════════════════════════════════════╦════════════════════╗
  2. # ║ Title: KFBQ Battle Message Override ║  Version: 1.00     ║
  3. # ║ Author: Roninator2                  ║                    ║
  4. # ╠═════════════════════════════════════╬════════════════════╣
  5. # ║ Function:                           ║   Date Created     ║
  6. # ║                                     ╠════════════════════╣
  7. # ║   FFMQ Style Battle Messages        ║    12 Mar 2023     ║
  8. # ╚═════════════════════════════════════╩════════════════════╝
  9. # ╔══════════════════════════════════════════════════════════╗
  10. # ║ Instructions:                                            ║
  11. # ║                                                          ║
  12. # ║  none                                                    ║
  13. # ╚══════════════════════════════════════════════════════════╝
  14. # ╔══════════════════════════════════════════════════════════╗
  15. # ║ Terms of use:                                            ║
  16. # ║ Free for all uses in RPG Maker - Except nudity           ║
  17. # ╚══════════════════════════════════════════════════════════╝
  18.  
  19. #==============================================================================
  20. # ** BattleMessage
  21. #==============================================================================
  22.  
  23. class KFBQ_BattleMessage < Window_Base
  24.   #--------------------------------------------------------------------------
  25.   # * Object Initialization
  26.   #--------------------------------------------------------------------------
  27.   def initialize
  28.     @lines = 1
  29.     super(0, 0, window_width, window_height)
  30.     self.z = 200
  31.     self.openness = 0
  32.     create_back_bitmap
  33.     create_back_sprite
  34.     clear_instance_variables
  35.   end
  36.   #--------------------------------------------------------------------------
  37.   # * Get Window Width
  38.   #--------------------------------------------------------------------------
  39.   def window_width
  40.     Graphics.width
  41.   end
  42.   #--------------------------------------------------------------------------
  43.   # * Get Window Height
  44.   #--------------------------------------------------------------------------
  45.   def window_height
  46.     fitting_height(visible_line_number)
  47.   end
  48.   #--------------------------------------------------------------------------
  49.   # * Clear Instance Variables
  50.   #--------------------------------------------------------------------------
  51.   def clear_instance_variables
  52.     @fiber = nil                # Fiber
  53.     @background = 0             # Background type
  54.     @position = 2               # Display position
  55.     clear_flags
  56.   end
  57.   #--------------------------------------------------------------------------
  58.   # * Clear Flag
  59.   #--------------------------------------------------------------------------
  60.   def clear_flags
  61.     @show_fast = false          # Fast forward flag
  62.     @line_show_fast = false     # Fast forward by line flag
  63.     @pause_skip = false         # Input standby omission flag
  64.   end
  65.   #--------------------------------------------------------------------------
  66.   # * Get Number of Lines to Show
  67.   #--------------------------------------------------------------------------
  68.   def visible_line_number
  69.     return @lines
  70.   end
  71.   #--------------------------------------------------------------------------
  72.   # * Set Number of Lines to Show
  73.   #--------------------------------------------------------------------------
  74.   def set_visible_line_number(value = 1)
  75.     @lines = value
  76.   end
  77.   #--------------------------------------------------------------------------
  78.   # * Free
  79.   #--------------------------------------------------------------------------
  80.   def dispose
  81.     super
  82.     dispose_back_bitmap
  83.     dispose_back_sprite
  84.   end
  85.   #--------------------------------------------------------------------------
  86.   # * Frame Update
  87.   #--------------------------------------------------------------------------
  88.   def update
  89.     super
  90.     update_back_sprite
  91.     update_fiber
  92.   end
  93.   #--------------------------------------------------------------------------
  94.   # * Update Fiber
  95.   #--------------------------------------------------------------------------
  96.   def update_fiber
  97.     if @fiber
  98.       @fiber.resume
  99.     elsif $game_message.busy? && !$game_message.scroll_mode
  100.       @fiber = Fiber.new { fiber_main }
  101.       @fiber.resume
  102.     else
  103.       $game_message.visible = false
  104.     end
  105.   end
  106.   #--------------------------------------------------------------------------
  107.   # * Create Background Bitmap
  108.   #--------------------------------------------------------------------------
  109.   def create_back_bitmap
  110.     @back_bitmap = Bitmap.new(width, height)
  111.     rect1 = Rect.new(0, 0, width, 12)
  112.     rect2 = Rect.new(0, 12, width, height - 24)
  113.     rect3 = Rect.new(0, height - 12, width, 12)
  114.     @back_bitmap.gradient_fill_rect(rect1, back_color2, back_color1, true)
  115.     @back_bitmap.fill_rect(rect2, back_color1)
  116.     @back_bitmap.gradient_fill_rect(rect3, back_color1, back_color2, true)
  117.   end
  118.   #--------------------------------------------------------------------------
  119.   # * Get Background Color 1
  120.   #--------------------------------------------------------------------------
  121.   def back_color1
  122.     Color.new(0, 0, 0, 160)
  123.   end
  124.   #--------------------------------------------------------------------------
  125.   # * Get Background Color 2
  126.   #--------------------------------------------------------------------------
  127.   def back_color2
  128.     Color.new(0, 0, 0, 0)
  129.   end
  130.   #--------------------------------------------------------------------------
  131.   # * Create Background Sprite
  132.   #--------------------------------------------------------------------------
  133.   def create_back_sprite
  134.     @back_sprite = Sprite.new
  135.     @back_sprite.bitmap = @back_bitmap
  136.     @back_sprite.visible = false
  137.     @back_sprite.z = z - 1
  138.   end
  139.   #--------------------------------------------------------------------------
  140.   # * Free Background Bitmap
  141.   #--------------------------------------------------------------------------
  142.   def dispose_back_bitmap
  143.     @back_bitmap.dispose
  144.   end
  145.   #--------------------------------------------------------------------------
  146.   # * Free Background Sprite
  147.   #--------------------------------------------------------------------------
  148.   def dispose_back_sprite
  149.     @back_sprite.dispose
  150.   end
  151.   #--------------------------------------------------------------------------
  152.   # * Update Background Sprite
  153.   #--------------------------------------------------------------------------
  154.   def update_back_sprite
  155.     @back_sprite.visible = (@background == 1)
  156.     @back_sprite.y = y
  157.     @back_sprite.opacity = openness
  158.     @back_sprite.update
  159.   end
  160.   #--------------------------------------------------------------------------
  161.   # * Main Processing of Fiber
  162.   #--------------------------------------------------------------------------
  163.   def fiber_main
  164.     $game_message.visible = true
  165.     update_background
  166.     update_placement
  167.     loop do
  168.       process_all_text if $game_message.has_text?
  169.       process_input
  170.       $game_message.clear
  171.       Fiber.yield
  172.       break unless text_continue?
  173.     end
  174.     close_and_wait
  175.     $game_message.visible = false
  176.     @fiber = nil
  177.   end
  178.   #--------------------------------------------------------------------------
  179.   # * Update Window Background
  180.   #--------------------------------------------------------------------------
  181.   def update_background
  182.     @background = $game_message.background
  183.     self.opacity = @background == 0 ? 255 : 0
  184.   end
  185.   #--------------------------------------------------------------------------
  186.   # * Update Window Position
  187.   #--------------------------------------------------------------------------
  188.   def update_placement
  189.     self.y = (Graphics.height - height - 100)
  190.   end
  191.   #--------------------------------------------------------------------------
  192.   # * Process All Text
  193.   #--------------------------------------------------------------------------
  194.   def process_all_text
  195.     open_and_wait
  196.     text = convert_escape_characters($game_message.all_text)
  197.     pos = {}
  198.     new_page(text, pos)
  199.     process_character(text.slice!(0, 1), text, pos) until text.empty?
  200.   end
  201.   #--------------------------------------------------------------------------
  202.   # * Input Processing
  203.   #--------------------------------------------------------------------------
  204.   def process_input
  205.     input_pause unless @pause_skip
  206.   end
  207.   #--------------------------------------------------------------------------
  208.   # * Open Window and Wait for It to Fully Open
  209.   #--------------------------------------------------------------------------
  210.   def open_and_wait
  211.     open
  212.     Fiber.yield until open?
  213.   end
  214.   #--------------------------------------------------------------------------
  215.   # * Close Window and Wait for It to Fully Close
  216.   #--------------------------------------------------------------------------
  217.   def close_and_wait
  218.     close
  219.     Fiber.yield until all_close?
  220.   end
  221.   #--------------------------------------------------------------------------
  222.   # * Determine if All Windows Are Fully Closed
  223.   #--------------------------------------------------------------------------
  224.   def all_close?
  225.     close?
  226.   end
  227.   #--------------------------------------------------------------------------
  228.   # * Determine Whether to Continue Displaying Text
  229.   #--------------------------------------------------------------------------
  230.   def text_continue?
  231.     $game_message.has_text? && !settings_changed?
  232.   end
  233.   #--------------------------------------------------------------------------
  234.   # * Determine if Background and Position Changed
  235.   #--------------------------------------------------------------------------
  236.   def settings_changed?
  237.     @background != $game_message.background ||
  238.     @position != $game_message.position
  239.   end
  240.   #--------------------------------------------------------------------------
  241.   # * Wait
  242.   #--------------------------------------------------------------------------
  243.   def wait(duration)
  244.     duration.times { Fiber.yield }
  245.   end
  246.   #--------------------------------------------------------------------------
  247.   # * Update Fast Forward Flag
  248.   #--------------------------------------------------------------------------
  249.   def update_show_fast
  250.     @show_fast = true if Input.trigger?(:C)
  251.   end
  252.   #--------------------------------------------------------------------------
  253.   # * Wait After Output of One Character
  254.   #--------------------------------------------------------------------------
  255.   def wait_for_one_character
  256.     update_show_fast
  257.     Fiber.yield unless @show_fast || @line_show_fast
  258.   end
  259.   #--------------------------------------------------------------------------
  260.   # * New Page
  261.   #--------------------------------------------------------------------------
  262.   def new_page(text, pos)
  263.     contents.clear
  264.     draw_face($game_message.face_name, $game_message.face_index, 0, 0)
  265.     reset_font_settings
  266.     pos[:x] = new_line_x
  267.     pos[:y] = 0
  268.     pos[:new_x] = new_line_x
  269.     pos[:height] = calc_line_height(text)
  270.     clear_flags
  271.   end
  272.   #--------------------------------------------------------------------------
  273.   # * Get New Line Position
  274.   #--------------------------------------------------------------------------
  275.   def new_line_x
  276.     $game_message.face_name.empty? ? 0 : 112
  277.   end
  278.   #--------------------------------------------------------------------------
  279.   # * Normal Character Processing
  280.   #--------------------------------------------------------------------------
  281.   def process_normal_character(c, pos)
  282.     super
  283.     wait_for_one_character
  284.   end
  285.   #--------------------------------------------------------------------------
  286.   # * New Line Character Processing
  287.   #--------------------------------------------------------------------------
  288.   def process_new_line(text, pos)
  289.     @line_show_fast = false
  290.     super
  291.     if need_new_page?(text, pos)
  292.       input_pause
  293.       new_page(text, pos)
  294.     end
  295.   end
  296.   #--------------------------------------------------------------------------
  297.   # * Determine if New Page Is Needed
  298.   #--------------------------------------------------------------------------
  299.   def need_new_page?(text, pos)
  300.     pos[:y] + pos[:height] > contents.height && !text.empty?
  301.   end
  302.   #--------------------------------------------------------------------------
  303.   # * New Page Character Processing
  304.   #--------------------------------------------------------------------------
  305.   def process_new_page(text, pos)
  306.     text.slice!(/^\n/)
  307.     input_pause
  308.     new_page(text, pos)
  309.   end
  310.   #--------------------------------------------------------------------------
  311.   # * Icon Drawing Process by Control Characters
  312.   #--------------------------------------------------------------------------
  313.   def process_draw_icon(icon_index, pos)
  314.     super
  315.     wait_for_one_character
  316.   end
  317.   #--------------------------------------------------------------------------
  318.   # * Control Character Processing
  319.   #     code : the core of the control character
  320.   #            e.g. "C" in the case of the control character \C[1].
  321.   #     text : character string buffer in drawing processing (destructive)
  322.   #     pos  : draw position {:x, :y, :new_x, :height}
  323.   #--------------------------------------------------------------------------
  324.   def process_escape_character(code, text, pos)
  325.     case code.upcase
  326.     when '$'
  327.       @gold_window.open
  328.     when '.'
  329.       wait(15)
  330.     when '|'
  331.       wait(60)
  332.     when '!'
  333.       input_pause
  334.     when '>'
  335.       @line_show_fast = true
  336.     when '<'
  337.       @line_show_fast = false
  338.     when '^'
  339.       @pause_skip = true
  340.     else
  341.       super
  342.     end
  343.   end
  344.   #--------------------------------------------------------------------------
  345.   # * Input Pause Processing
  346.   #--------------------------------------------------------------------------
  347.   def input_pause
  348.     self.pause = true
  349.     wait(10)
  350.     Fiber.yield until Input.trigger?(:B) || Input.trigger?(:C)
  351.     Input.update
  352.     self.pause = false
  353.   end
  354. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement