TheoAllen

Theo - VX Style Choice

Oct 13th, 2013
741
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.43 KB | None | 0 0
  1. # =============================================================================
  2. # TheoAllen - VX Style Choices
  3. # Version : 1.0b
  4. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # (This script documentation is written in informal indonesian language)
  6. # =============================================================================
  7. ($imported ||= {})[:Theo_VXStyleChoices] = true
  8. # =============================================================================
  9. # CHANGE LOGS:
  10. # -----------------------------------------------------------------------------
  11. # 2013.10.14 - Bugfix. Choice isn't displayed if it isn't followed by texts
  12. # 2013.10.12 - Finished script
  13. # =============================================================================
  14. =begin
  15.  
  16.   Perkenalan :
  17.   Script ini ngebikin kamu bisa gunain style choice kek VX
  18.  
  19.   Cara penggunaan :
  20.   Pasang script ini dibawah material namun diatas main.
  21.   Gunakan script call sebagai berikut buat nampilin choice model VX.
  22.  
  23.   vx_choice(true)   << buat ngehidupin
  24.   vx_choice(false)  << buat ngematiin
  25.  
  26.   Terms of use :
  27.   Credit gw, TheoAllen. Kalo semisal u bisa ngedit2 script gw trus jadi lebih
  28.   keren, terserah. Ane bebasin. Asal ngga ngeklaim aja. Kalo semisal mau
  29.   dipake buat komersil, jangan lupa, gw dibagi gratisannya.
  30.  
  31. =end
  32. # =============================================================================
  33. # Tidak ada konfigurasi
  34. # =============================================================================
  35. class Game_Interpreter
  36.  
  37.   def vx_choice(bool)
  38.     $game_message.vx_choice = bool
  39.   end
  40.  
  41. end
  42.  
  43. class Game_Message
  44.   attr_accessor :vx_choice
  45.  
  46.   alias theo_vxchoice_init initialize
  47.   def initialize
  48.     theo_vxchoice_init
  49.     @vx_choice = true
  50.   end
  51.  
  52. end
  53.  
  54. class Window_Message < Window_Base
  55.  
  56.   alias theo_vxchoice_init initialize
  57.   def initialize
  58.     theo_vxchoice_init
  59.     init_vxchoice_member
  60.   end
  61.  
  62.   def init_vxchoice_member
  63.     @need_clear = false
  64.     @choice_index = 0
  65.     @choice_y = 0
  66.   end
  67.  
  68.   alias theo_vxchoice_input input_choice
  69.   def input_choice
  70.     return start_vx_choice if $game_message.vx_choice
  71.     return theo_vxchoice_input
  72.   end
  73.  
  74.   alias theo_vxchoice_new_page new_page
  75.   def new_page(text, pos)
  76.     theo_vxchoice_new_page(text, pos)
  77.     @need_clear = ($game_message.texts.size + $game_message.choices.size) >
  78.       visible_line_number
  79.   end
  80.  
  81.   alias theo_vxchoice_new_line process_new_line
  82.   def process_new_line(text, pos)
  83.     theo_vxchoice_new_line(text, pos)
  84.     @choice_y = pos[:y]
  85.   end
  86.  
  87.   def start_vx_choice
  88.     open_and_wait unless open?
  89.     if @need_clear
  90.       input_need_clear
  91.     end
  92.     @choice_index  = 0
  93.     ypos = 0
  94.     $game_message.choices.each do |choice|
  95.       draw_text_ex(new_line_x + padding_x, @choice_y + ypos, choice)
  96.       ypos += line_height
  97.     end
  98.     update_vx_choice(@choice_y)
  99.   end
  100.  
  101.   def padding_x
  102.     return 16
  103.   end
  104.  
  105.   def input_need_clear
  106.     input_pause
  107.     contents.clear
  108.     @choice_y = 0
  109.     @need_clear = false
  110.   end
  111.  
  112.   def update_vx_choice(ypos)
  113.     rect_width = contents.width - new_line_x - rface
  114.     cursor_rect.set(new_line_x, ypos, rect_width, line_height)
  115.     wait(10)
  116.     until Input.trigger?(:C) || (Input.trigger?(:B) && cancel_enabled?)
  117.       update_choice_cursor
  118.       Fiber.yield
  119.     end
  120.     cursor_rect.empty
  121.     execute_choice
  122.     Input.update
  123.   end
  124.  
  125.   def rface
  126.     ($imported[:Theo_RightSideFace] && !$game_message.face_name.empty? &&
  127.       $game_message.rface) ? 100 : 0
  128.   end
  129.  
  130.   def cancel_enabled?
  131.     $game_message.choice_cancel_type > 0
  132.   end
  133.  
  134.   def update_choice_cursor
  135.     cursor_rect.y = @choice_y + @choice_index * line_height
  136.     change_choice_index(1) if Input.repeat?(:DOWN)
  137.     change_choice_index(-1) if Input.repeat?(:UP)
  138.   end
  139.  
  140.   def change_choice_index(amount)
  141.     Sound.play_cursor
  142.     @choice_index += amount
  143.     wrap_index
  144.   end
  145.  
  146.   def wrap_index
  147.     @choice_index = 0 if @choice_index > $game_message.choices.size - 1
  148.     @choice_index = $game_message.choices.size - 1 if @choice_index < 0
  149.   end
  150.  
  151.   def execute_choice
  152.     call_ok_handler if Input.trigger?(:C)
  153.     call_cancel_handler if Input.trigger?(:B)
  154.   end
  155.  
  156.   def call_ok_handler
  157.     Sound.play_ok
  158.     $game_message.choice_proc.call(@choice_index)
  159.   end
  160.  
  161.   def call_cancel_handler
  162.     Sound.play_cancel
  163.     $game_message.choice_proc.call($game_message.choice_cancel_type - 1)
  164.   end
  165.  
  166. end
Advertisement
Add Comment
Please, Sign In to add comment