TheoAllen

Theo - VX Choice (ENG)

May 15th, 2014
956
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.88 KB | None | 0 0
  1. # =============================================================================
  2. # TheoAllen - VX Style Choices
  3. # Version : 1.1
  4. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # (English Documentation)
  6. # =============================================================================
  7. ($imported ||= {})[:Theo_VXStyleChoices] = true
  8. # =============================================================================
  9. # Change Logs :
  10. # -----------------------------------------------------------------------------
  11. # 2013.11.14 - Compatibility patch with my choice help
  12. #            - Bugfix. Face graphic erased when clearing message box
  13. # 2013.10.14 - Bugfix. Choice isn't displayed if it isn't followed by texts
  14. # 2013.10.12 - Finished script
  15. # =============================================================================
  16. =begin
  17.  
  18.   Introduction :
  19.   This script allow you to display choices as VX has
  20.  
  21.   How to use :
  22.   Put this script below material but above main
  23.   Use these script calls to activate VX style choice
  24.  
  25.   vx_choice(true)   << to activate
  26.   vx_choice(false)  << to deacitave
  27.  
  28.   Terms of use :
  29.   Credit me, TheoAllen. You are free to edit this script by your own. As long
  30.   as you don't claim it yours. For commercial purpose, don't forget to give me
  31.   a free copy of the game.
  32.  
  33. =end
  34. # =============================================================================
  35. # No configuration. Just dont edit below this line
  36. # =============================================================================
  37. class Game_Interpreter
  38.  
  39.   def vx_choice(bool)
  40.     $game_message.vx_choice = bool
  41.   end
  42.  
  43. end
  44.  
  45. class Game_Message
  46.   attr_accessor :vx_choice
  47.  
  48.   alias theo_vxchoice_init initialize
  49.   def initialize
  50.     theo_vxchoice_init
  51.     @vx_choice = false
  52.   end
  53.  
  54. end
  55.  
  56. class Window_Message < Window_Base
  57.  
  58.   alias theo_vxchoice_init initialize
  59.   def initialize
  60.     theo_vxchoice_init
  61.     init_vxchoice_member
  62.   end
  63.  
  64.   def init_vxchoice_member
  65.     @need_clear = false
  66.     @choice_index = 0
  67.     @choice_y = 0
  68.   end
  69.  
  70.   alias theo_vxchoice_input input_choice
  71.   def input_choice
  72.     return start_vx_choice if $game_message.vx_choice
  73.     return theo_vxchoice_input
  74.   end
  75.  
  76.   alias theo_vxchoice_new_page new_page
  77.   def new_page(text, pos)
  78.     theo_vxchoice_new_page(text, pos)
  79.     @need_clear = ($game_message.texts.size + $game_message.choices.size) >
  80.       visible_line_number
  81.   end
  82.  
  83.   alias theo_vxchoice_new_line process_new_line
  84.   def process_new_line(text, pos)
  85.     theo_vxchoice_new_line(text, pos)
  86.     @choice_y = pos[:y]
  87.   end
  88.  
  89.   def start_vx_choice
  90.     open_and_wait unless open?
  91.     if @need_clear
  92.       input_need_clear
  93.     end
  94.     @choice_index  = 0
  95.     ypos = 0
  96.     $game_message.choices.each do |choice|
  97.       draw_text_ex(new_line_x + padding_x, @choice_y + ypos, choice)
  98.       ypos += line_height
  99.     end
  100.     update_vx_choice(@choice_y)
  101.   end
  102.  
  103.   def padding_x
  104.     return 16
  105.   end
  106.  
  107.   def input_need_clear
  108.     input_pause
  109.     contents.clear
  110.     draw_face($game_message.face_name, $game_message.face_index, 0, 0)
  111.     @choice_y = 0
  112.     @need_clear = false
  113.   end
  114.  
  115.   def update_vx_choice(ypos)
  116.     rect_width = contents.width - new_line_x - rface
  117.     cursor_rect.set(new_line_x, ypos, rect_width, line_height)
  118.     if choice_help?
  119.       @choice_help.open
  120.       update_choice_help
  121.     end
  122.     wait(10)
  123.     until Input.trigger?(:C) || (Input.trigger?(:B) && cancel_enabled?)
  124.       update_choice_cursor
  125.       Fiber.yield
  126.     end
  127.     cursor_rect.empty
  128.     execute_choice
  129.     Input.update
  130.   end
  131.  
  132.   def rface
  133.     ($imported[:Theo_RightSideFace] && !$game_message.face_name.empty? &&
  134.       $game_message.rface) ? 100 : 0
  135.   end
  136.  
  137.   def cancel_enabled?
  138.     $game_message.choice_cancel_type > 0
  139.   end
  140.  
  141.   def update_choice_cursor
  142.     cursor_rect.y = @choice_y + @choice_index * line_height
  143.     change_choice_index(1) if Input.repeat?(:DOWN)
  144.     change_choice_index(-1) if Input.repeat?(:UP)
  145.   end
  146.  
  147.   def change_choice_index(amount)
  148.     Sound.play_cursor
  149.     @choice_index += amount
  150.     wrap_index
  151.     update_choice_help if choice_help?
  152.   end
  153.  
  154.   def wrap_index
  155.     @choice_index = 0 if @choice_index > $game_message.choices.size - 1
  156.     @choice_index = $game_message.choices.size - 1 if @choice_index < 0
  157.   end
  158.  
  159.   def execute_choice
  160.     call_ok_handler if Input.trigger?(:C)
  161.     call_cancel_handler if Input.trigger?(:B)
  162.     if choice_help?
  163.       @choice_help.close
  164.     end
  165.   end
  166.  
  167.   def choice_help?
  168.     $imported[:Theo_ChoiceHelp]
  169.   end
  170.  
  171.   def update_choice_help
  172.     @choice_help.set_text($game_message.choice_helps[@choice_index])
  173.   end
  174.  
  175.   def call_ok_handler
  176.     Sound.play_ok
  177.     $game_message.choice_proc.call(@choice_index)
  178.   end
  179.  
  180.   def call_cancel_handler
  181.     Sound.play_cancel
  182.     $game_message.choice_proc.call($game_message.choice_cancel_type - 1)
  183.   end
  184.  
  185. end
Advertisement
Add Comment
Please, Sign In to add comment