Advertisement
Kakakadafi

[Overwrite] Input options menu Key/Con

Oct 21st, 2017
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.78 KB | None | 0 0
  1. module YIN
  2.   # Name of the confirm button in the button config
  3.   Confirm = "Confirm"
  4.   # Name of the cancel button in the button config
  5.   Cancel = "Menu/Cancel"
  6.   # Name of the dash button in the button config
  7.   Dash = "Accessory"
  8.   # Name of the attack button in the button config
  9.   # NOTE - For some reason the word Attack causes the text to show in the
  10.   # correct spot.
  11.   # I actually think it might be trying to draw an icon through Blackmorning's
  12.   # icons script.
  13.   Attack = "Weapon"
  14.   # Name of the attack button in the button config
  15.   Skill = "Magic"
  16.   # Name of the weapon skill button in the button config
  17.   WeaponSkill = "Skill"
  18.   # Name of the move button in the button config
  19.   Move_Up = "Move Up"
  20.   Move_Down = "Move Down"
  21.   Move_Left = "Move Left"
  22.   Move_Right = "Move Right"
  23.   # Name of the menu button in the button config
  24.   Menu = "Menu"
  25.   # Name of the pageup button in the button config
  26.   Page_Up = "Accessory"
  27.   # Name of the pagedown button in the button config
  28.   Page_Down = "Switch"
  29. end
  30.  
  31. class Window_CurrentButtons < Window_Selectable
  32.   #--------------------------------------------------------------------------
  33.   # * Object Initialization
  34.   #--------------------------------------------------------------------------
  35.   def initialize(x, y, width, height)
  36.     make_item_list
  37.     height = window_height
  38.     super
  39.     @buttons = []
  40.     refresh
  41.   end
  42.   #--------------------------------------------------------------------------
  43.   # * Get Digit Count
  44.   #--------------------------------------------------------------------------
  45.   def col_max
  46.     return 1
  47.   end
  48.   #--------------------------------------------------------------------------
  49.   # * Get Number of Items
  50.   #--------------------------------------------------------------------------
  51.   def item_max
  52.     @buttons ? @buttons.size : 1
  53.   end
  54.   #--------------------------------------------------------------------------
  55.   # * Get Window Height
  56.   #--------------------------------------------------------------------------
  57.   def window_height
  58.     fitting_height(item_max)
  59.   end
  60.   #--------------------------------------------------------------------------
  61.   # * Get Item
  62.   #--------------------------------------------------------------------------
  63.   def item
  64.     @buttons && index >= 0 ? @buttons[index] : nil
  65.   end
  66.   #--------------------------------------------------------------------------
  67.   # * Create Item List
  68.   #--------------------------------------------------------------------------
  69.   def make_item_list
  70.     inputs = {
  71.       :Confirm            => PadConfig.confirm,
  72.       :Cancel             => PadConfig.cancel,
  73.       :Dash               => PadConfig.dash,
  74.       :Attack             => PadConfig.attack,
  75.       :Skill              => PadConfig.skill,
  76.       :Skill2             => PadConfig.skill2,
  77.       :Move_Up            => PadConfig.move_up,
  78.       :Move_Down          => PadConfig.move_down,
  79.       :Move_Left          => PadConfig.move_left,
  80.       :Move_Right         => PadConfig.move_right
  81. #~       :Page_Up            => PadConfig.page_up,
  82. #~       :Page_Down          => PadConfig.page_down
  83.     }
  84.     @buttons = []
  85.     inputs.each{|key,val|
  86.       @buttons << [key,val]
  87.     }
  88.   end
  89.   #--------------------------------------------------------------------------
  90.   # * Draw Item
  91.   #--------------------------------------------------------------------------
  92.   def draw_item(index)
  93.     item = @buttons[index]
  94.     if item
  95.       rect = item_rect(index)
  96.       rect.width -= 4
  97.       button = item[1].to_s.gsub(/_/, ' ').strip.capitalize
  98.       case item[0]
  99.       when :Confirm
  100.         button_name = YIN::Confirm
  101.       when :Cancel
  102.         button_name = YIN::Cancel
  103.       when :Dash
  104.         button_name = YIN::Dash
  105.       when :Attack
  106.         button_name = YIN::Attack
  107.       when :Skill
  108.         button_name = YIN::Skill
  109.       when :Skill2
  110.         button_name = YIN::WeaponSkill #Nama Skill menu
  111.       when :Move_Up
  112.         button_name = YIN::Move_Up
  113.       when :Move_Down
  114.         button_name = YIN::Move_Down
  115.       when :Move_Left
  116.         button_name = YIN::Move_Left
  117.       when :Move_Right
  118.         button_name = YIN::Move_Right
  119.       when :Page_Up
  120.         button_name = YIN::Page_Up
  121.       when :Page_Down
  122.         button_name = YIN::Page_Down
  123.       end
  124.       draw_text(rect.x, rect.y, rect.width, rect.height, button_name.strip)
  125.       draw_text(rect.x, rect.y, rect.width, rect.height, button, 2)
  126.     end
  127.   end
  128.   #--------------------------------------------------------------------------
  129.   # * Update Help Text
  130.   #--------------------------------------------------------------------------
  131.   def update_help
  132.   end
  133.    
  134.   def process_cursor_move
  135.     super
  136.     if @help_window
  137.       @help_window.refresh_input_config("Change button configuration")
  138.     end
  139.   end
  140.   #--------------------------------------------------------------------------
  141.   # * Refresh
  142.   #--------------------------------------------------------------------------
  143.   def refresh
  144.     make_item_list
  145.     create_contents
  146.     draw_all_items
  147.   end
  148. end
  149.  
  150. class Window_Help < Window_Base
  151.   def refresh_input_config(text)
  152.     contents.clear
  153.     draw_text(4, 0, contents.width, contents.height, text, 1)
  154.   end
  155. end
  156.  
  157. #==============================================================================
  158. # ** Scene_ButtonConfig
  159. #------------------------------------------------------------------------------
  160. #  This class performs basic processing related to the menu screen.
  161. #==============================================================================
  162.  
  163. class Scene_ButtonConfig < Scene_MenuBase
  164.   include Zale::Keyboard_Manager
  165.   #--------------------------------------------------------------------------
  166.   # * Start Processing
  167.   #--------------------------------------------------------------------------
  168.   def start
  169.     super
  170.     @change_current = nil
  171.     @waiting = false
  172.     @counter = 10
  173.     create_current_window
  174.     create_help_window
  175.   end
  176.   #--------------------------------------------------------------------------
  177.   # * Termination Processing
  178.   #--------------------------------------------------------------------------
  179.   def terminate
  180.     super
  181.     dispose_background
  182.   end
  183.   #--------------------------------------------------------------------------
  184.   # * Create Background
  185.   #--------------------------------------------------------------------------
  186.   def create_background
  187.     @background_sprite = Sprite.new
  188.     @background_sprite.bitmap = SceneManager.background_bitmap
  189.     @background_sprite.color.set(16, 16, 16, 128)
  190.   end
  191.   #--------------------------------------------------------------------------
  192.   # * Free Background
  193.   #--------------------------------------------------------------------------
  194.   def dispose_background
  195.     @background_sprite.dispose
  196.   end
  197.   #--------------------------------------------------------------------------
  198.   # * Create Help Window
  199.   #--------------------------------------------------------------------------
  200.   def create_help_window
  201.     @help_window = Window_Help.new
  202.     @help_window.viewport = @viewport
  203.     if WolfPad.plugged_in?
  204.       @help_window.refresh_input_config("Using Game Controller. Change button configuration")
  205.     else
  206.       @help_window.refresh_input_config("Using Keyboard. Change button configuration")
  207.     end
  208.   end
  209.    
  210.   def create_current_window
  211.     @current_window = Window_CurrentButtons.new((Graphics.width - 192) / 2, (Graphics.height - 192) / 2, 192, 216)
  212.     @current_window.viewport = @viewport
  213.     @current_window.help_window = @help_window
  214.     @current_window.set_handler(:ok,     method(:on_current_ok))
  215.     @current_window.set_handler(:cancel, method(:on_current_cancel))
  216.     @current_window.activate
  217.     @current_window.select(0)
  218.   end
  219.    
  220.   def on_current_ok
  221.     @change_current = @current_window.item
  222.     case @change_current[0]
  223.       when :Confirm
  224.         button_name = YIN::Confirm
  225.       when :Cancel
  226.         button_name = YIN::Cancel
  227.       when :Dash
  228.         button_name = YIN::Dash
  229.       when :Attack
  230.         button_name = YIN::Attack
  231.       when :Skill
  232.         button_name = YIN::Skill
  233.       when :Skill2
  234.         button_name = YIN::WeaponSkill #Nama Skill menu
  235.       when :Move_Up
  236.         button_name = YIN::Move_Up
  237.       when :Move_Down
  238.         button_name = YIN::Move_Down
  239.       when :Move_Left
  240.         button_name = YIN::Move_Left
  241.       when :Move_Right
  242.         button_name = YIN::Move_Right
  243.       when :Page_Up
  244.         button_name = YIN::Page_Up
  245.       when :Page_Down
  246.         button_name = YIN::Page_Down
  247.     end
  248.     @waiting = true
  249.     @help_window.refresh_input_config("Press the button you want to change '#{button_name}' to.")
  250.   end
  251.    
  252.   def on_current_cancel
  253.     if @waiting == true ; return; end
  254.     SceneManager.return
  255.   end
  256.    
  257.   def wait_for_input
  258.     @counter -= 1 if @counter > 0
  259.     if @counter > 0 ; return ; end
  260.     if WolfPad.trigger?(:A); assign(@change_current, :A); end
  261.     if WolfPad.trigger?(:B); assign(@change_current, :B); end
  262.     if WolfPad.trigger?(:X); assign(@change_current, :X); end
  263.     if WolfPad.trigger?(:Y); assign(@change_current, :Y); end
  264.        
  265.     if WolfPad.trigger?(:L1); assign(@change_current, :L1); end
  266.     if WolfPad.trigger?(:L2); assign(@change_current, :L2); end
  267.     if WolfPad.trigger?(:R1); assign(@change_current, :R1); end
  268.     if WolfPad.trigger?(:R2); assign(@change_current, :R2); end
  269.        
  270.     if WolfPad.trigger?(:SELECT); assign(@change_current, :SELECT); end
  271.     if WolfPad.trigger?(:START); assign(@change_current, :START); end
  272.  
  273.     if WolfPad.trigger?(:L3); assign(@change_current, :L3); end
  274.     if WolfPad.trigger?(:R3); assign(@change_current, :R3); end
  275.                
  276.     if WolfPad.trigger?(:R_UP); assign(@change_current, :R_UP); end
  277.     if WolfPad.trigger?(:R_DOWN); assign(@change_current, :R_DOWN); end
  278.     if WolfPad.trigger?(:R_LEFT); assign(@change_current, :R_LEFT); end
  279.     if WolfPad.trigger?(:R_RIGHT); assign(@change_current, :R_RIGHT); end
  280.      
  281.     if Input.get_key[1] === true;
  282.       assign(@change_current, Input.get_key[0][0])
  283.     end
  284.   end
  285.    
  286.   def check_button_assignment(new)
  287.     controls = WolfPad.plugged_in? ? $game_options.game_controls[:controller] : $game_options.game_controls[:keyboard]
  288.     controls.any? {|key| key[1] == new}
  289.   end
  290.    
  291.   def assign(current, new)
  292.     cur = @current_window.item[0]
  293.     if cur != :Move_Up && cur != :Move_Down && cur != :Move_Left && cur != :Move_Right
  294.       if new == :_left || new == :_right || new == :_up || new == :_down
  295.         @waiting = false
  296.         Sound.play_buzzer
  297.         button = new.to_s.gsub(/_/, ' ').strip.capitalize
  298.         @help_window.refresh_input_config("Cannot assign directional buttons to action functions!")
  299.         @current_window.activate
  300.         @current_window.refresh
  301.         @counter = 10
  302.         return
  303.       end
  304.     end
  305.     if check_button_assignment(new)
  306.       @waiting = false
  307.       Sound.play_buzzer
  308.       button = new.to_s.gsub(/_/, ' ').strip.capitalize
  309.       @help_window.refresh_input_config("Button #{button} is already assigned to a function!")
  310.       @current_window.activate
  311.       @current_window.refresh
  312.       @counter = 10
  313.       return
  314.     end
  315.     Sound.play_ok
  316.     @counter = 10
  317.     controls = WolfPad.plugged_in? ? $game_options.game_controls[:controller] : $game_options.game_controls[:keyboard]
  318.     controls[@change_current[0]] = new
  319.     @waiting = false
  320.     @current_window.activate
  321.     @current_window.refresh
  322.   end
  323.    
  324.   def update
  325.     super
  326.     if @change_current != @current_window.item
  327.       if WolfPad.plugged_in?
  328.         @help_window.refresh_input_config("Using Game Controller. Change button configuration")
  329.       else
  330.         @help_window.refresh_input_config("Using Keyboard. Change button configuration")
  331.       end
  332.     end
  333.     if @waiting == true
  334.       wait_for_input
  335.     end
  336.   end
  337. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement