neutale

OneEyedEagle - Event Command Skip

Nov 27th, 2020 (edited)
662
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================
  2. # ■ Event Command Skip by OneEyedEagle (http://oneeyedeagle.lofter.com/)
  3. # License - MIT License: http://opensource.org/licenses/mit-license.php
  4. #==============================================================================
  5. $imported ||= {}
  6. $imported["EAGLE-EventCommandSkip"] = true
  7. #==============================================================================
  8. # - 2020.7.26.19 Optimized
  9. #==============================================================================
  10. # - Script that makes use of labels and adds event command SKIP
  11. #--------------------------------------------------------------------------
  12. # - New label is added before the command to start skip | SKIP ,
  13. #   New label is added after the end of command to skip | SKIPEND ,
  14. #   When a key is pressed during a command the process between SKIP and SKIPEND,
  15. #   the commands can be skipped.
  16. #
  17. # - Example:
  18. #    |- Label:SKIP
  19. #    |- Show Text:Statement1
  20. #    |- Show Balloon Icon:Exclamation
  21. #    |- Show Text:Statement2
  22. #    |- Label:SKIPEND
  23. #    |- Show Text:Statement3
  24. #
  25. #    Show Text Statement1, Surprise, Text Statement2, and Text Statement3:
  26. #    If Shift key is pressed on statement 1, then command between is skipped.
  27. #    Text Statement3 is still shown.
  28. #
  29. # - Adds a label to SKIPTHEN in front of command when a skip is used.
  30. #   If skipped, the command between SKIPTHEN and SKIPEND are used.
  31. #   If not skipped, the instructions between are not executed.
  32. #
  33. # - Example:
  34. #    |- Label:SKIP
  35. #    |- Show Text:Statement1
  36. #    |- Show Text:Statement2
  37. #    |- Label:SKIPTHEN
  38. #    |- Show Text:Statement3
  39. #    |- Label:SKIPEND
  40. #    |- Show Text:Statement4
  41. #
  42. #    Show Text Statement 1, Statement 2, and Statement 4 are shown in order.
  43. #    If Shift key is pressed on statement 1.
  44. #    Skipped Statement2 however continues Statement3, and to Statement4.
  45. #
  46. #==============================================================================
  47.  
  48. module COMMAND_SKIP
  49.   #--------------------------------------------------------------------------
  50.   # ● 【Constant】 Skip label at the start (case sensitive)
  51.   #--------------------------------------------------------------------------
  52.   LABEL_SKIP = "SKIP"
  53.   #--------------------------------------------------------------------------
  54.   # ● 【Constant】 Label used when skipping contents to a point (case sensitive)
  55.   #--------------------------------------------------------------------------
  56.   LABEL_THEN = "SKIPTHEN"
  57.   #--------------------------------------------------------------------------
  58.   # ● 【Constant】 Skips to the end of the label if no SKIPTHEN (case sensitive)
  59.   #--------------------------------------------------------------------------
  60.   LABEL_END = "SKIPEND"
  61.   #--------------------------------------------------------------------------
  62.   # ● Key to skip
  63.   #--------------------------------------------------------------------------
  64.   def self.trigger?
  65.     Input.trigger?(:A) || @need_skip
  66.   end
  67.   #--------------------------------------------------------------------------
  68.   # ● Set up a text prompt
  69.   #--------------------------------------------------------------------------
  70.   def self.set_skip_hint(sprite)
  71.     text = "Press Shift to skip"
  72.     w = 16 * 9
  73.     sprite.bitmap = Bitmap.new(w, 18)
  74.     sprite.bitmap.font.size = 18
  75.     sprite.bitmap.fill_rect(0,17,w,1, Color.new(255,255,255,220))
  76.     sprite.bitmap.draw_text(0,1,sprite.width,sprite.height,text, 1)
  77.  
  78.     sprite.x = 15
  79.     sprite.y = 15
  80.   end
  81.   #--------------------------------------------------------------------------
  82.   # ● class self
  83.   #--------------------------------------------------------------------------
  84.   class << self
  85.     attr_reader :sprite_hint
  86.   end
  87.   def self.init_hint
  88.     if @hint_show_count.nil?
  89.       @sprite_hint.dispose if @sprite_hint
  90.       @sprite_hint = Sprite.new
  91.       set_skip_hint(@sprite_hint)
  92.       @sprite_hint.visible = false
  93.     end
  94.   end
  95.   def self.show_hint
  96.     @sprite_hint.visible = true
  97.     @need_skip = false
  98.   end
  99.   def self.hide_hint
  100.     @sprite_hint.visible = false
  101.     @need_skip = nil
  102.   end
  103.   #--------------------------------------------------------------------------
  104.   # ● Self skip?
  105.   #--------------------------------------------------------------------------
  106.   def self.skippable?
  107.     @need_skip != nil
  108.   end
  109.   #--------------------------------------------------------------------------
  110.   # ● Skip
  111.   #--------------------------------------------------------------------------
  112.   @need_skip = nil
  113.   def self.call
  114.     @need_skip = true
  115.   end
  116. end
  117. #=============================================================================
  118. # ○ Game_Interpreter
  119. #=============================================================================
  120. class Game_Interpreter
  121.   #--------------------------------------------------------------------------
  122.   # ● Skip run
  123.   #--------------------------------------------------------------------------
  124.   alias eagle_skip_run run
  125.   def run
  126.     COMMAND_SKIP.init_hint
  127.     @eagle_skip_begin_i = nil # Record command start position of skip label.
  128.     eagle_skip_run
  129.   end
  130.   #--------------------------------------------------------------------------
  131.   # ● Skip update
  132.   #--------------------------------------------------------------------------
  133.   alias eagle_skip_update update
  134.   def update
  135.     eagle_skip_update
  136.     eagle_process_skip if @eagle_skip_begin_i && COMMAND_SKIP.trigger?
  137.   end
  138.   #--------------------------------------------------------------------------
  139.   # ● Skip command
  140.   #--------------------------------------------------------------------------
  141.   alias eagle_skip_command_118 command_118
  142.   def command_118
  143.     if @params[0] == COMMAND_SKIP::LABEL_SKIP
  144.       COMMAND_SKIP.show_hint
  145.       @eagle_skip_begin_i = @index
  146.     elsif @eagle_skip_begin_i && @params[0] == COMMAND_SKIP::LABEL_THEN
  147.       eagle_goto_label(COMMAND_SKIP::LABEL_END)
  148.       COMMAND_SKIP.hide_hint
  149.       @eagle_skip_begin_i = nil
  150.     elsif @params[0] == COMMAND_SKIP::LABEL_END
  151.       COMMAND_SKIP.hide_hint
  152.     end
  153.     eagle_skip_command_118
  154.   end
  155.   #--------------------------------------------------------------------------
  156.   # ● Jump label
  157.   #--------------------------------------------------------------------------
  158.   def eagle_goto_label(label_name, i_begin = @index, i_end = @list.size-1)
  159.     i = i_begin
  160.     while i <= i_end
  161.       if @list[i].code == 118 && @list[i].parameters[0] == label_name
  162.         @index = i
  163.         return true
  164.       end
  165.       i += 1
  166.     end
  167.     return false
  168.   end
  169.   #--------------------------------------------------------------------------
  170.   # ● Process skip
  171.   #--------------------------------------------------------------------------
  172.   def eagle_process_skip
  173.     @eagle_skip_begin_i = nil
  174.     if !eagle_goto_label(COMMAND_SKIP::LABEL_THEN)
  175.       eagle_goto_label(COMMAND_SKIP::LABEL_END)
  176.     end
  177.     COMMAND_SKIP.hide_hint
  178.     if $imported["EAGLE-MessageEX"]
  179.       window = SceneManager.scene.message_window
  180.       window.force_close if window.open?
  181.     end
  182.     if $imported["EAGLE-AnimEX"]
  183.       ANIM_EX.all_chara_sprites.each { |s| s.stop_animation }
  184.       ANIM_EX.stop_all
  185.     end
  186.   end
  187. end
  188.  
RAW Paste Data