Black_Mage

Extra Setting for Choice RMVXA Script

Jul 6th, 2017 (edited)
672
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 15.65 KB | None | 0 0
  1. #==============================================================================
  2. # Extra Settings for Choices Script By Black Mage (Credit required to use)
  3. # Version : 1.2
  4. #
  5. # https://burningwizard.wordpress.com/2017/12/29/extra-settings-for-choices-script-rmvxa-rgss3/
  6. #==============================================================================
  7.  
  8. #==============================================================================
  9. # Changelog
  10. #==============================================================================
  11. # Version 1.2
  12. #   - Separate centered choices text with centered choices window position.
  13. #   - Add custom position for choices window.
  14. #
  15. # Version 1.1
  16. #   - Add Button Customize setting.
  17. #   - Add Centered Choices setting.
  18. #
  19. # Version 1.0
  20. #   - Initial version.
  21. #==============================================================================
  22.  
  23. #==============================================================================
  24. # This script have several function regarding choices command.
  25. #
  26. # 1. Scrolling Choices
  27. #    You can make the choices cursor scrolling from top to the bottom by using
  28. #    this script call:
  29. #
  30. #    choice_scroll(boolean, delay)
  31. #
  32. #    where boolean value is true or false. When boolean is false, nothing is
  33. #    happened, and you can put delay value whatever you like. If the boolean
  34. #    is true, however, then the choices will start to scrolling from top to the
  35. #    bottom of available choices. The speed of the scrolling is depends on the
  36. #    value of delay. The smaller the delay value, means the scrolling speed
  37. #    will be faster.
  38. #
  39. # 2. Arrow Lock
  40. #    You can lock the directional button during choice selection, leaving
  41. #    player to have access only on confirm and cancel button, by using this
  42. #    script call:
  43. #
  44. #    choice_arrow_lock(value)
  45. #
  46. #    where the value is true or false. Set the value on true to disable the
  47. #    directional button, and set it on false to enable the directional button.
  48. #
  49. # 3. Forced Choices
  50. #    This setting will make the choice cursor will always return to a specified
  51. #    index, no matter where the player move the cursor. The cursor will return
  52. #    to the specified index after several delay. You can use it by calling this
  53. #    script call:
  54. #
  55. #    choice_forced(boolean, index, delay)
  56. #
  57. #    where boolean is either true or false, determining wether the setting is
  58. #    used or not. index is where the choice cursor will return at. And delay is
  59. #    how many frame passed before the cursor return to the specified index.
  60. #
  61. # 4. Timed Choices
  62. #    This will make the choice have an invisible timer on it. When the timer
  63. #    reaches 0, the highlited choice will be selected, or it will trigger
  64. #    another event depending on the setting. You can use it by using this script
  65. #    call:
  66. #
  67. #    choice_timer(boolean1, boolean2, duration, common_event)
  68. #
  69. #    where boolean1 stands for determining wether the setting is in effect or
  70. #    not. Set it to false so you don't need to worry about the other arguments
  71. #    value, just put whatever on them.
  72. #
  73. #    boolean2 stands for wether when the time is running out, a specific common
  74. #    event will be played or it will choos the highlighted choice. When this
  75. #    value is false, the highlighted choice will be selected. When this is true,
  76. #    a common event will be played depending on common_event value.
  77. #
  78. #    duration is how many frames will passed before Boolean2 setting took effect.
  79. #
  80. #    common_event is an ID for which common event get executed if boolean2 value
  81. #    is true. If boolean2 value is false, you can put whatever on it's value.
  82. #
  83. #    You can check how many frames left on the timer on this variable:
  84. #    
  85. #    $game_system.choice_remaining_time
  86. #
  87. # 5. Button Customize
  88. #    You can customize the button used to move the choices by using this script
  89. #    call:
  90. #
  91. #    choice_button(down, up)
  92. #
  93. #    where down and up are the button that will make the choices go down and up
  94. #    respectively. Ex: choice_button(:LEFT, :RIGHT) will make the left arrow to
  95. #    move the choice cursor up, and the right arrow will move the choice cursor
  96. #    down.
  97. #    
  98. #    Default available button:
  99. #    down arrow         :DOWN
  100. #    up arrow           :UP
  101. #    left arrow         :LEFT
  102. #    right arrow        :RIGHT
  103. #
  104. #    You can add more button by using some script that enable another button to
  105. #    be used in your game.
  106. #
  107. # 6. Centered Choices
  108. #    I hate the default positioning of choices in RMVXA, and some script out
  109. #    there aren't suited for my needs. So here's a function to have the choices
  110. #    got centered.
  111. #
  112. #    choice_centered(boolean)
  113. #
  114. #    where boolean are set to true if you want the choices to be centered.
  115. #
  116. # 7. Centered choices text
  117. #    This initially come together with the Centered Choices feature. I decided
  118. #    to have them separated.
  119. #
  120. #    choice_text_centered(boolean)
  121. #
  122. #    Set the boolean to true to have this feature enabled.
  123. #
  124. # 8. Custom Choice Window Position
  125. #    This feature was added by request due to script with same function as this
  126. #    can't be used for certain reason.
  127. #    
  128. #    choice_window_pos_custom(boolean)
  129. #    choice_window_position_x(int)
  130. #    choice_window_position_y(int)
  131. #
  132. #    Set the boolean into true to enable this feature. Set the int to your
  133. #    desired value.
  134. #==============================================================================
  135.  
  136. #==============================================================================
  137. # * Initial Settings. Can left them untouched.
  138. #==============================================================================
  139. module BLACK_CHOICES
  140.   SCROLL        = [false, 0]  # Setting, delay
  141.   TIMER         = [false, false, 0, 0]  # Setting, event on, duration, common event]
  142.   ARROW_LOCK    = false
  143.   FORCED        = [false,0,0] # Setting, index, delay
  144.   BUTTON        = [:DOWN, :UP]
  145.   CENTERED      = false
  146.   TEXT_CENTERED = false
  147.   ENABLE_CUSTOM_CHOICE_WINDOW_POSITION = false
  148.   CUSTOM_CHOICE_WINDOW_POSITION = [0,0]
  149. end
  150. #==============================================================================
  151.  
  152. #------------------------------------------------------------------------------
  153. # * Beyond this is the sacred land of code. You need programming qualification
  154. #   to dwelve deeper, or it'll cause many unnecessary problems. Proceed on your
  155. #   own risk.
  156. #------------------------------------------------------------------------------
  157.  
  158. #==============================================================================
  159. # ■ Game_System
  160. #==============================================================================
  161. class Game_System
  162.   attr_accessor :choice_scroll
  163.   attr_accessor :choice_timer
  164.   attr_accessor :choice_arrow_lock
  165.   attr_accessor :choice_remaining_time
  166.   attr_accessor :choice_forced
  167.   attr_accessor :choice_button
  168.   attr_accessor :choice_centered
  169.   attr_accessor :choice_text_centered
  170.   attr_accessor :choice_window_pos_custom
  171.   attr_accessor :choice_window_position_x
  172.   attr_accessor :choice_window_position_y
  173.  
  174.   alias black_initialize initialize
  175.   def initialize
  176.     @choice_scroll        = [BLACK_CHOICES::SCROLL[0], BLACK_CHOICES::SCROLL[1]]
  177.     @choice_timer         = [BLACK_CHOICES::TIMER[0], BLACK_CHOICES::TIMER[1], BLACK_CHOICES::TIMER[2]]
  178.     @choice_arrow_lock    = BLACK_CHOICES::ARROW_LOCK
  179.     @choice_forced        = [BLACK_CHOICES::FORCED[0], BLACK_CHOICES::FORCED[1], BLACK_CHOICES::FORCED[2]]
  180.     @choice_button        = [BLACK_CHOICES::BUTTON[0], BLACK_CHOICES::BUTTON[1]]
  181.     @choice_centered      = BLACK_CHOICES::CENTERED
  182.     @choice_text_centered = BLACK_CHOICES::TEXT_CENTERED
  183.     @choice_window_pos_custom = BLACK_CHOICES::ENABLE_CUSTOM_CHOICE_WINDOW_POSITION
  184.     @choice_window_position_x = BLACK_CHOICES::CUSTOM_CHOICE_WINDOW_POSITION[0]
  185.     @choice_window_position_y = BLACK_CHOICES::CUSTOM_CHOICE_WINDOW_POSITION[1]
  186.     black_initialize
  187.   end
  188. end
  189. #==============================================================================
  190.  
  191. #==============================================================================
  192. # * Game Interpreter
  193. #==============================================================================
  194. class Game_Interpreter
  195.   #----------------------------------------------------------------------------
  196.   # * Choice scroll setting
  197.   #----------------------------------------------------------------------------        
  198.   def choice_scroll(boolean, delay)
  199.     $game_system.choice_scroll = [boolean, delay]
  200.   end
  201.  
  202.   #----------------------------------------------------------------------------
  203.   # * Choice timer
  204.   #----------------------------------------------------------------------------        
  205.   def choice_timer(boolean1, boolean2, timer, common_event)
  206.     $game_system.choice_timer = [boolean1, boolean2, timer, common_event]
  207.   end
  208.  
  209.   #----------------------------------------------------------------------------
  210.   # * Arrow lock
  211.   #----------------------------------------------------------------------------        
  212.   def choice_arrow_lock(value); $game_system.choice_arrow_lock = value; end
  213.  
  214.   #----------------------------------------------------------------------------
  215.   # * Choice forced.
  216.   #----------------------------------------------------------------------------        
  217.   def choice_forced(boolean, index, delay)
  218.     $game_system.choice_forced = [boolean, index, delay]
  219.   end
  220.  
  221.   #----------------------------------------------------------------------------
  222.   # * Choice reverse.
  223.   #----------------------------------------------------------------------------        
  224.   def choice_button(down, up); $game_system.choice_button = [down, up]; end
  225.  
  226.   #----------------------------------------------------------------------------
  227.   # * Choice centered.
  228.   #----------------------------------------------------------------------------        
  229.   def choice_centered(boolean); $game_system.choice_centered = boolean; end
  230.  
  231.   #----------------------------------------------------------------------------
  232.   # * Choice text centered.
  233.   #----------------------------------------------------------------------------        
  234.   def choice_text_centered(boolean)
  235.     $game_system.choice_text_centered = boolean
  236.   end
  237.  
  238.   #----------------------------------------------------------------------------
  239.   # * Enable custom choice window position.
  240.   #----------------------------------------------------------------------------        
  241.   def choice_window_pos_custom(boolean)
  242.     $game_system.choice_window_pos_custom = boolean
  243.   end
  244.  
  245.   #----------------------------------------------------------------------------
  246.   # * Custom choice window position.
  247.   #----------------------------------------------------------------------------        
  248.   def choice_window_position_x(int)
  249.     $game_system.choice_window_position_x = int
  250.   end
  251.   def choice_window_position_y(int)
  252.     $game_system.choice_window_position_y = int
  253.   end
  254. end
  255.  
  256. class Window_ChoiceList < Window_Command
  257.   #----------------------------------------------------------------------------
  258.   # * Update
  259.   #----------------------------------------------------------------------------
  260.   def update
  261.     super
  262.     scrolling_choices if $game_system.choice_scroll[0] == true
  263.     countdown_timer if $game_system.choice_timer[0] == true
  264.     forced_choices if $game_system.choice_forced[0] == true
  265.   end
  266.  
  267.   #----------------------------------------------------------------------------
  268.   # * Method for scrolling choices
  269.   #----------------------------------------------------------------------------
  270.   def scrolling_choices
  271.     @speed = 0 if @speed == nil
  272.     @speed += 1
  273.     @speed = 0 if @speed >= $game_system.choice_scroll[1]
  274.     if self.active and @speed == 0
  275.       if @index == ($game_message.choices.size - 1)
  276.         @index = 0
  277.       else
  278.         @index += 1
  279.       end
  280.       update_cursor
  281.     end
  282.   end
  283.  
  284.   #----------------------------------------------------------------------------
  285.   # * Method for timed choices
  286.   #----------------------------------------------------------------------------
  287.   def countdown_timer
  288.     $game_system.choice_remaining_time = $game_system.choice_timer[2] if @timer == nil
  289.     @timer = true; $game_system.choice_remaining_time -= 1
  290.     if $game_system.choice_remaining_time <= 0 and @timer != nil
  291.       if $game_system.choice_timer[1]
  292.         deactivate; close; black_reset
  293.         $game_temp.reserve_common_event($game_system.choice_timer[3])
  294.       else
  295.         process_ok
  296.       end
  297.     end
  298.   end  
  299.  
  300.   #----------------------------------------------------------------------------
  301.   # * Method for forced choices
  302.   #----------------------------------------------------------------------------
  303.   def forced_choices
  304.     @delay = $game_system.choice_forced[2] if @delay == nil
  305.     @delay -= 1
  306.     if @delay <= 0
  307.       @delay = nil; select($game_system.choice_forced[1])
  308.     end
  309.   end
  310.  
  311.   #----------------------------------------------------------------------------
  312.   # * Call OK Handler
  313.   #----------------------------------------------------------------------------
  314.   alias black_call_ok_handler call_ok_handler
  315.   def call_ok_handler; black_reset; black_call_ok_handler; end
  316.  
  317.   #----------------------------------------------------------------------------
  318.   # * Call Cancel Handler
  319.   #----------------------------------------------------------------------------
  320.   alias black_call_cancel_handler call_cancel_handler
  321.   def call_cancel_handler; black_reset; black_call_cancel_handler; end
  322.  
  323.   #----------------------------------------------------------------------------
  324.   # * Reset setting
  325.   #----------------------------------------------------------------------------
  326.   def black_reset
  327.     @timer = nil; @delay = nil
  328.     $game_system.choice_forced[0] = false
  329.     $game_system.choice_timer[0] = false
  330.   end
  331.  
  332.   #----------------------------------------------------------------------------
  333.   # * Arrow lock
  334.   #----------------------------------------------------------------------------
  335.   def cursor_movable?; super if !$game_system.choice_arrow_lock; end
  336.  
  337.   #----------------------------------------------------------------------------
  338.   # * Cursor Movement Processing
  339.   #----------------------------------------------------------------------------
  340.   def process_cursor_move
  341.     return unless cursor_movable?
  342.     last_index = @index
  343.     down  = $game_system.choice_button[0]
  344.     up    = $game_system.choice_button[1]
  345.     cursor_down (true)  if Input.repeat?(down)
  346.     cursor_up   (true)  if Input.repeat?(up)
  347.     Sound.play_cursor if @index != last_index
  348.   end
  349. end
  350.  
  351. #==============================================================================
  352. # * Centered Choices Script.
  353. #==============================================================================
  354. class Window_ChoiceList < Window_Command
  355.   alias center_item_rect_for_text item_rect_for_text
  356.   def item_rect_for_text(index)
  357.     return center_item_rect_for_text(index) if !$game_system.choice_text_centered
  358.     rect = item_rect(index)
  359.     max_chc_wdth = $game_message.choices.collect {|s| text_size(s).width }[index]
  360.     center = (self.width - max_chc_wdth - (padding * 2)) / 2
  361.     rect.x = center; rect.width -= 8; rect
  362.   end    
  363.   alias black_update_placement update_placement
  364.   def update_placement
  365.     black_update_placement
  366.     if $game_system.choice_centered
  367.       self.width = [width, 144].max
  368.       self.x = (Graphics.width - width)/2
  369.       self.y = self.y - 2
  370.     elsif $game_system.choice_window_pos_custom
  371.       self.width = [width, 144].max
  372.       self.x = $game_system.choice_window_position_x
  373.       self.y = $game_system.choice_window_position_y
  374.     end
  375.   end
  376. end
  377. #==============================================================================
Add Comment
Please, Sign In to add comment