blucalm

Hotkey - Update 26 April 2013 Bugfix

Apr 26th, 2013
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 47.26 KB | None | 0 0
  1.    
  2.  
  3.     #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  4.     # ** Hotkeys
  5.     #    Author: Eshra
  6.     #    Release Date: 20 Aug. 2012
  7.     #    Compatibility: RPG Maker VX Ace
  8.     #    Dependencies: None
  9.     #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  10.     #
  11.     #   About:
  12.     #
  13.     #   This script allows skills and items to be linked to hotkeys from a new menu
  14.     #   inside of the main menu. It also creates an actionbar that can be turned on
  15.     #   or off.
  16.     #
  17.     #   The hotkeys can be used while the current Scene is Scene_Map. The update
  18.     #   method of Scene_Map is now listens for key presses.
  19.     #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  20.     #
  21.     #------------------------------------------------------------------------------
  22.     # * How to Use
  23.     #------------------------------------------------------------------------------
  24.     #
  25.     # To use this script, insert it as new script in the script editor under
  26.     # the materials section.
  27.     #
  28.     # It's a very simple plug and play script, you can adjust which skills or items
  29.     # are used by which hotkeys from the main menu in game.
  30.     #
  31.     #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  32.     # Author Notes:
  33.     #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  34.     #
  35.     # Aliased Methods:
  36.     # Scene_Map:
  37.     #     update
  38.     # Scene_Map
  39.     #   update
  40.     #
  41.     # Window_MenuCommand
  42.     #   add_original_commands
  43.     #
  44.     # Scene_Menu
  45.     #   create_command_window
  46.     #   on_personal_ok
  47.     #
  48.     # I used several global variables and they were not encapsulated inside
  49.     # Game_Temp or anything so there may potentially be some namespace pollution
  50.     # problems.
  51.     #
  52.     # Hotkeys are retained when using f12 to reset. I honestly don't know if I care
  53.     # enough to write the code to fix this. It's so trivial.
  54.     #
  55.     # This was one of the first scrips I ever wrote for rpg maker so I likely made
  56.     # a lot of mistakes in terms of coding practices etc.
  57.     #
  58.     #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  59.     # Original Release Date: 20 Aug. 2012
  60.     #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  61.     # Update Log:
  62.     # 26 April 2013 - Fixed Bug allowing items to be used even if none in inv
  63.     # 30 Mar. 2013 - Fixed Bug causing crash after hiding actionbar and then viewing
  64.     #                and closing the menu. Fixed bug preventing actionbar from being
  65.     #                able to be hidden after a game message was shown.
  66.     # 5 Dec. 2012 - Cooldowns are now hidden properly when actionbar is hidden.
  67.     #               Cooldowns now stay infront of the action bar when it is hidden
  68.     #               then shown again.
  69.     # 3 Dec. 2012 - Can see item amounts. The script didn't actually work for skills...
  70.     #               fixed now. Can assign turning the action bar on and off to a hotkey
  71.     #               now. Hotkeys only show up on the menu once. Items being used on friends
  72.     #               are no longer used when canceling before selecting a party member.
  73.     # 6 Nov. 2012 - Added check to see if item was usable.
  74.     #
  75.     # 20 Aug. 2012 - First Version Finished
  76.     #
  77.     #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  78.     # Terms of Use
  79.     #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  80.     # Free to use as you please. Please respect the header though so the dates can
  81.     # be preserved.
  82.     #------------------------------------------------------------------------------
  83.     ($imported||={})["(~^_^)~Hotkeys"] = 0.3
  84.      
  85.     # Below are the settings that can be adjusted when using this script
  86.     module HOTKEY
  87.       module ACTIONBAR
  88.         HEIGHT = 47 # Height of the action bar
  89.        
  90.         FONTSIZE = 13.5 # Size of the font in the action bar
  91.        
  92.         MAX = 7    # This value should be greater than 0 and less than or equal to 12
  93.                       # it is the number of hotkeys the player can use
  94.                      
  95.         LOCATION = [183, 205] # Numerator mod, Denominator
  96.        
  97.         VISIBLE = true # Switch this to false to hide the action bar.
  98.        
  99.         WIDTH_OFFSET = 100
  100.        
  101.         CD_VISIBLE = true
  102.         ORDER = {     # The hotkey associated with 1 is the leftmost, 12 is rightmost.
  103.           1 => :F5,   # The symbols associatated with each number can be mixed and
  104.           2 => :F6,   # matched around. For example to display hotkey A as the
  105.           3 => :F7,   # leftmost hotkey instead of F5. Swamp :A with :F5 in the hash
  106.           4 => :F8,   # such that 1 => :A and 5 => :F5.
  107.           5 => :A,
  108.           6 => :B,
  109.           7 => :C,
  110.           8 => :X,
  111.           9 => :Y,
  112.           10 => :Z,
  113.           11 => :L,
  114.           12 => :R
  115.         }
  116.       end
  117.      
  118.       module COOLDOWN_GAUGE
  119.         COLOR1 = Color.new(120, 80, 0, 250)
  120.         COLOR2 = Color.new(200, 250, 0, 250)
  121.       end
  122.     end
  123.      
  124.     #===============================================================
  125.     # Game_Map:
  126.     #   New variables are added to hold hotkey information
  127.     #    
  128.     #===============================================================
  129.      
  130.     class Game_Map
  131.      
  132.       $hotkey_data = {}   #maps symbols to item icons
  133.       @@game_hotkeys = {}
  134.      
  135.       def self.game_hotkeys
  136.         @@game_hotkeys
  137.       end
  138.     end # End - Game_Map
  139.     #===============================================================
  140.     # Window_Base:
  141.     #   Change the update so it handles the case where the window
  142.     #     has been disposed of.
  143.     #===============================================================
  144.     class Window_Base < Window
  145.       alias hotkey_update_alias_meth_9092 update
  146.       def update
  147.         return if disposed?
  148.         hotkey_update_alias_meth_9092
  149.       end # - End update
  150.     end # - End Window_Base
  151.      
  152.     #===============================================================
  153.     # Scene_Map:
  154.     #   The update method listens for keyboard input.
  155.     #===============================================================
  156.     class Scene_Map < Scene_Base
  157.      
  158.       $hkey_user = nil
  159.       $hkey_target = nil
  160.      
  161.       @@show_actionbar = HOTKEY::ACTIONBAR::VISIBLE
  162.      
  163.       alias hotkey_sc_map_start_meth_add_var start
  164.       def start
  165.         hotkey_sc_map_start_meth_add_var
  166.         @cooldown_viewport ||= Viewport.new
  167.         @cooldown_viewport.z = 300
  168.       end # End - start
  169.      
  170.       def self.hide_actionbar
  171.         @@show_actionbar = false
  172.         @cooldown_imgs.hide unless !@cooldown_imgs
  173.         print "hide_actionbar, @@show_actionbar = #{@@show_actionbar}\n"
  174.       end
  175.      
  176.       def self.show_action_bar
  177.         @@show_actionbar = true
  178.         @cooldown_imgs.show unless !@cooldown_imgs
  179.       end
  180.      
  181.       alias hotkey_update_alias_9090 update
  182.       def update
  183.         hotkey_update_alias_9090
  184.         if Input.trigger?(:F5)
  185.           evalute_hotkey(:F5)
  186.         elsif Input.trigger?(:F6)
  187.           evalute_hotkey(:F6)
  188.         elsif Input.trigger?(:F7)
  189.           evalute_hotkey(:F7)
  190.         elsif Input.trigger?(:F8)
  191.           evalute_hotkey(:F8)
  192.         elsif Input.trigger?(:A)
  193.           evalute_hotkey(:A)
  194.         elsif Input.trigger?(:B)
  195.           evalute_hotkey(:B)
  196.         elsif Input.trigger?(:C)
  197.           evalute_hotkey(:C)
  198.         elsif Input.trigger?(:X)
  199.           evalute_hotkey(:X)
  200.         elsif Input.trigger?(:Y)
  201.           evalute_hotkey(:Y)
  202.         elsif Input.trigger?(:Z)
  203.           evalute_hotkey(:Z)
  204.         elsif Input.trigger?(:R)
  205.           evalute_hotkey(:R)
  206.         elsif Input.trigger?(:L)
  207.           evalute_hotkey(:L)
  208.         end # - End trigger cases
  209.        
  210.        
  211.         update_actionbar
  212.         update_cool_downs
  213.      
  214.       end # - End update
  215.      
  216.       def update_actionbar
  217.         # hide action bar if game_message is being shown
  218.         hide_ab_when_showing_message
  219.        
  220.         if @@show_actionbar
  221.           if @actionbar == nil || @actionbar.disposed?
  222.             create_actionbar
  223.           end # - End actionbar check
  224.           @actionbar.update unless @actionbar.disposed?
  225.         else
  226.           @actionbar.dispose unless !@actionbar
  227.         end # End - if @@show_actionbar
  228.       end
  229.      
  230.       def hide_ab_when_showing_message
  231.         if $game_message.visible
  232.           @temp_hide_abar = true if @@show_actionbar
  233.           Scene_Map.hide_actionbar
  234.         else
  235.           Scene_Map.show_action_bar if @temp_hide_abar
  236.           @temp_hide_abar = false
  237.         end
  238.       end
  239.      
  240.       def update_cool_downs
  241.         return unless $imported["(~^_^)~Cooldowns"]
  242.        
  243.         if @@show_actionbar && HOTKEY::ACTIONBAR::CD_VISIBLE
  244.           if @cooldown_imgs == nil || @cooldown_imgs.disposed?
  245.             create_cooldown_images
  246.           end # - End actionbar check
  247.           @cooldown_imgs.contents.clear
  248.           draw_cooldown_imgs_contents(@cooldown_imgs)
  249.           @cooldown_imgs.update unless @cooldown_imgs.disposed?
  250.         else
  251.           @cooldown_imgs.contents.clear unless @cooldown_imgs.disposed?
  252.         end
  253.        
  254.       end
  255.      
  256.       def create_cooldown_images
  257.         wy = HOTKEY::ACTIONBAR::LOCATION[0]*Graphics.height/HOTKEY::ACTIONBAR::LOCATION[1]
  258.         wh = HOTKEY::ACTIONBAR::HEIGHT
  259.         ww = Graphics.width - HOTKEY::ACTIONBAR::WIDTH_OFFSET
  260.         @cooldown_imgs = Window_Base.new(HOTKEY::ACTIONBAR::WIDTH_OFFSET/2, wy, ww, wh)
  261.         @cooldown_imgs.viewport = @cooldown_viewport
  262.         @cooldown_imgs.opacity = 0
  263.         draw_cooldown_imgs_contents(@cooldown_imgs)
  264.       end
  265.      
  266.       def draw_cooldown_imgs_contents(window)
  267.         width = Graphics.width-HOTKEY::ACTIONBAR::WIDTH_OFFSET
  268.         font_size = HOTKEY::ACTIONBAR::FONTSIZE
  269.         max = HOTKEY::ACTIONBAR::MAX
  270.        
  271.         (1..max).each{ |key|
  272.           used_cd = 0
  273.           used_cd_base = 0
  274.           bar_length = 0
  275.           item_cd = 0
  276.           item_cd_base = 0
  277.          
  278.           sym = HOTKEY::ACTIONBAR::ORDER[key]
  279.           item = Game_Map.game_hotkeys[sym]
  280.           item = item[1] unless item == nil
  281.           next if item == nil
  282.          
  283.           gcd = $game_map.gcd_val     #global cooldown amt
  284.           item_cd = item.cooldown_timer
  285.           used_cd = 0#(gcd > item_cd) gcd : item_cd
  286.           used_cd_base = -1
  287.           if gcd > item_cd
  288.             used_cd = $game_map.gcd_val
  289.             used_cd_base = $game_map.gcd_base
  290.           else
  291.             used_cd = item_cd
  292.             used_cd_base = item.base_cooldown
  293.           end
  294.            
  295.           if used_cd_base <= 0
  296.             used_cd_base = 1
  297.           end
  298.           bar_length = used_cd * (width/max) / used_cd_base
  299.           if bar_length > 0
  300.             window.draw_gauge((key-1)*width/max,0,bar_length,1.01,HOTKEY::COOLDOWN_GAUGE::COLOR1,HOTKEY::COOLDOWN_GAUGE::COLOR2)
  301.           end
  302.         }
  303.       end # - End draw_actionbar_contents
  304.      
  305.       def create_cd_bar
  306.         @cd_bar = Bitmap.new(50,50)
  307.         @cd_bar.fill_rect(0,0,50,50, Color.new(0, 0, 0, 160))
  308.       end
  309.      
  310.       def create_actionbar
  311.         wy = HOTKEY::ACTIONBAR::LOCATION[0]*Graphics.height/HOTKEY::ACTIONBAR::LOCATION[1]
  312.         wh = HOTKEY::ACTIONBAR::HEIGHT
  313.         ww = Graphics.width - HOTKEY::ACTIONBAR::WIDTH_OFFSET
  314.         @actionbar = Window_Base.new(HOTKEY::ACTIONBAR::WIDTH_OFFSET/2, wy, ww, wh)
  315.         @actionbar.viewport = @viewport
  316.         draw_actionbar_contents(@actionbar)
  317.       end # - End create_actionbar
  318.      
  319.       def draw_actionbar_contents(window)
  320.         width = Graphics.width-HOTKEY::ACTIONBAR::WIDTH_OFFSET
  321.         font_size = HOTKEY::ACTIONBAR::FONTSIZE
  322.         max = HOTKEY::ACTIONBAR::MAX
  323.        
  324.         (1..max).each{ |key|
  325.           sym = HOTKEY::ACTIONBAR::ORDER[key]
  326.           ind = $hotkey_data[sym]
  327.          
  328.           if ind && ind.to_s.to_sym == :action_bar_on_off
  329.             window.contents.font.size = font_size
  330.             window.contents.draw_text((key-1)*width/max,0,width,22,sym.to_s)
  331.             window.contents.draw_text((key-1)*width/max+6,8,width,22,"OFF")
  332.             next
  333.           end
  334.          
  335.           window.draw_icon(ind, (key-1)*width/max, 0) unless ind == nil
  336.           window.contents.font.size = font_size
  337.           window.contents.draw_text((key-1)*width/max,0,width,22,sym.to_s)
  338.          
  339.           hkey = Game_Map.game_hotkeys[sym]
  340.          
  341.           next unless hkey
  342.           # item = Game_Map.game_hotkeys[sym][1].id
  343.           id = hkey[1].id
  344.          
  345.           amt = hkey[2] == :item ? $game_party.item_number($data_items[id]) : nil
  346.          
  347.           window.contents.draw_text((key-1)*width/max + 8,8,width,22,"x#{amt.to_s}") if amt
  348.          
  349.         }
  350.       end # - End draw_actionbar_contents
  351.      
  352.       def refresh_actionbar
  353.         draw_actionbar_contents(@actionbar)
  354.       end
  355.      
  356.       def evalute_hotkey(symbol)
  357.        
  358.         if $hotkey_data[symbol] == :action_bar_on_off
  359.           @@show_actionbar ? Scene_Map.hide_actionbar : Scene_Map.show_action_bar
  360.           update_actionbar
  361.           return
  362.         end
  363.        
  364.         return if !(hkey = Game_Map.game_hotkeys[symbol])
  365.        
  366.         id = hkey[1].id
  367.         $hkey_item = item = hkey[2] == :skill ? $data_skills[id] : $data_items[id] # $data_items[hkey[1].id]
  368.         $hkey_user = actor = $game_actors[hkey[0].id]
  369.        
  370.         amtcheck = true
  371.         if item.is_a?(RPG::Item)
  372.           amtcheck = $game_party.item_number(item) > 0
  373.         end
  374.        
  375.         if actor.usable?(item) && !item.nil? && !actor.nil? && amtcheck
  376.           use_item_to_actors if item.for_friend?
  377.           if @hkey_use_itm_ok && item.for_friend?
  378.             actor.use_item(item)
  379.             @hkey_use_itm_ok = false
  380.           elsif !item.for_friend?
  381.             actor.use_item(item)
  382.           end
  383.           check_gameover
  384.           Sound.play_use_item
  385.         else
  386.           Sound.play_buzzer
  387.         end
  388.         refresh_actionbar
  389.       end # - End evalute_hotkey
  390.      
  391.       def check_gameover
  392.         SceneManager.goto(Scene_Gameover) if $game_party.all_dead?
  393.       end # - End check_gameover
  394.      
  395.       def use_item_to_actors
  396.         item, user = $hkey_item, $hkey_user
  397.         array = item_target_actors
  398.         return if !array
  399.         array.each do |target|
  400.           @hkey_use_itm_ok = true
  401.           item.repeats.times {
  402.             target.item_apply(user, item)
  403.           }
  404.         end
  405.       end # - End use_item_to_actors
  406.          
  407.       def item_target_actors
  408.         item = $hkey_item
  409.         if !item.for_friend?
  410.           []
  411.         elsif item.for_all?
  412.           $game_party.members
  413.         else
  414.           SceneManager.call(Scene_HotkeyActorSelection)
  415.           []
  416.         end
  417.       end # - End item_target_actors
  418.      
  419.     end # - End Scene_Map
  420.      
  421.     #===============================================================
  422.     # Scene_HotkeyActorSelection:
  423.     #   This class handles party member selection for hotkeys linked
  424.     #   to items/skills with a single target.
  425.     #===============================================================
  426.      
  427.     class Scene_HotkeyActorSelection < Scene_ItemBase
  428.       def start
  429.         super
  430.         create_actor_window
  431.         show_sub_window(@actor_window)
  432.         @user = $hkey_user
  433.         @item = $hkey_item
  434.         @actor_window.select(0)
  435.       end # - End start
  436.      
  437.       #--------------------------------------------------------------------------
  438.       # * Window to select the target of a skill or item
  439.       #--------------------------------------------------------------------------
  440.       def create_actor_window
  441.         @actor_window = Window_MenuActor.new
  442.         @actor_window.set_handler(:ok,     method(:on_actor_ok))
  443.         @actor_window.set_handler(:cancel, method(:on_actor_cancel))
  444.       end # - End create_actor_window
  445.      
  446.       #--------------------------------------------------------------------------
  447.       # * Use Item on Actor
  448.       #--------------------------------------------------------------------------
  449.       def use_item_to_actors
  450.         item_target_actors.each do |target|
  451.           item.repeats.times { target.item_apply(user, item) }
  452.         end
  453.       end # - End use_item_to_actors
  454.      
  455.       def user
  456.         @user
  457.       end
  458.      
  459.       def item
  460.         @item
  461.       end
  462.      
  463.       def play_se_for_item
  464.         Sound.play_use_item
  465.       end
  466.      
  467.       #--------------------------------------------------------------------------
  468.       # * Actor [Cancel]
  469.       #--------------------------------------------------------------------------
  470.       def on_actor_cancel
  471.         hide_sub_window(@actor_window)
  472.       end
  473.      
  474.       #--------------------------------------------------------------------------
  475.       # * Show Subwindow
  476.       #--------------------------------------------------------------------------
  477.       def show_sub_window(window)
  478.         width_remain = Graphics.width - window.width
  479.         window.x = 0
  480.         @viewport.rect.x = @viewport.ox = window.width
  481.         @viewport.rect.width = width_remain
  482.         window.show.activate
  483.       end # - End show_sub_window
  484.      
  485.       #--------------------------------------------------------------------------
  486.       # * Hide Subwindow
  487.       #--------------------------------------------------------------------------
  488.       def hide_sub_window(window)
  489.         @viewport.rect.x = @viewport.ox = 0
  490.         @viewport.rect.width = Graphics.width
  491.         window.hide.deactivate
  492.         return_scene
  493.       end # - End hide_sub_window
  494.      
  495.       #--------------------------------------------------------------------------
  496.       # * Determine if Item Is Effective
  497.       #--------------------------------------------------------------------------
  498.       def item_effects_valid?
  499.         item_target_actors.any? do |target|
  500.           target.item_test($hkey_user, $hkey_item)
  501.         end
  502.       end # - End item_effects_valid?
  503.      
  504.       #--------------------------------------------------------------------------
  505.       # * Determine item targets
  506.       #--------------------------------------------------------------------------
  507.       def item_target_actors
  508.         if !$hkey_item.for_friend?
  509.           []
  510.         elsif $hkey_item.for_all?
  511.           $game_party.members
  512.         else
  513.           [$game_party.members[@actor_window.index]]
  514.         end
  515.       end # - End item_target_actors
  516.      
  517.     end # - End Scene_HotkeyActorSelection
  518.      
  519.     #===============================================================
  520.     # Window_MenuCommand:
  521.     #   Adds a new command option called "Hot Keys" to the main menu
  522.     #===============================================================
  523.     class Window_MenuCommand < Window_Command
  524.      
  525.       alias al_alias_method_m_make_com_l_ch_98384 make_command_list
  526.       def make_command_list
  527.         add_command("Hot Keys", :hotkey, true)
  528.         al_alias_method_m_make_com_l_ch_98384
  529.       end
  530.      
  531.       alias hotkey_add_orig_com_alias_9089 add_original_commands
  532.       def add_original_commands
  533.         hotkey_add_orig_com_alias_9089
  534.       end # - End add_original_commands
  535.      
  536.     end # - End Window_MenuCommand
  537.      
  538.     #Scene_Menu class
  539.     class Scene_Menu < Scene_MenuBase
  540.       #--------------------------------------------------------------------------
  541.       # * Create Command Window
  542.       #--------------------------------------------------------------------------
  543.       alias hotkey_create_com_win_alias_9088 create_command_window
  544.       def create_command_window
  545.         hotkey_create_com_win_alias_9088
  546.         @command_window.set_handler(:hotkey,    method(:command_personal))
  547.       end  # - End create_command_window
  548.      
  549.       # * Alias on_personal_ok
  550.       alias hotkey_on_pers_ok_alias_meth on_personal_ok
  551.       def on_personal_ok
  552.         hotkey_on_pers_ok_alias_meth
  553.         case @command_window.current_symbol
  554.         when :hotkey
  555.           SceneManager.call(Scene_Hotkey)
  556.         end # - End case block
  557.       end # - End on_personal_ok
  558.     end # - End Scene_Menu
  559.      
  560.     #==============================================================================
  561.     # ** Window_HotkeyCommand
  562.     #------------------------------------------------------------------------------
  563.     #  This command window appears on the menu screen.
  564.     #==============================================================================
  565.      
  566.     class Window_HotkeyCommand < Window_Command
  567.      
  568.       attr_accessor :list
  569.      
  570.       #--------------------------------------------------------------------------
  571.       # * Initialize Command Selection Position (Class Method)
  572.       #--------------------------------------------------------------------------
  573.       @@last_command_symbol = nil
  574.      
  575.       @@command_names ||= {
  576.         :F5 => "F5",
  577.         :F6 => "F6",
  578.         :F7 => "F7",
  579.         :F8 => "F8",
  580.         :A => ":A",
  581.         :B => ":B",
  582.         :C => ":C",
  583.         :X => ":X",
  584.         :Y => ":Y",
  585.         :Z => ":Z",
  586.         :L => ":L",
  587.         :R => ":R"
  588.       }
  589.      
  590.       #--------------------------------------------------------------------------
  591.       # * Object Initialization
  592.       #--------------------------------------------------------------------------
  593.       def initialize(x,y)
  594.         super(x, y)
  595.         select_last
  596.         @actor = nil
  597.       end
  598.      
  599.       #--------------------------------------------------------------------------
  600.       # * Get Window Width
  601.       #--------------------------------------------------------------------------
  602.       def window_width
  603.         return 160
  604.       end
  605.       #--------------------------------------------------------------------------
  606.       # * Get Number of Lines to Show
  607.       #--------------------------------------------------------------------------
  608.       def visible_line_number
  609.         item_max
  610.       end
  611.       #--------------------------------------------------------------------------
  612.       # * Create Command List
  613.       #--------------------------------------------------------------------------
  614.       def make_command_list
  615.         add_main_commands
  616.       end
  617.       #--------------------------------------------------------------------------
  618.       # * Add Main Commands to List
  619.       #--------------------------------------------------------------------------
  620.       def add_main_commands
  621.         pos_hash = HOTKEY::ACTIONBAR::ORDER
  622.         (1..HOTKEY::ACTIONBAR::MAX).each{ |key|
  623.           sym = pos_hash[key]
  624.           add_command(@@command_names[sym], sym)
  625.         }
  626.       end
  627.       #--------------------------------------------------------------------------
  628.       # * Processing When OK Button Is Pressed
  629.       #--------------------------------------------------------------------------
  630.       def process_ok
  631.         @@last_command_symbol = current_symbol
  632.         super
  633.       end
  634.       #--------------------------------------------------------------------------
  635.       # * Restore Previous Selection Position
  636.       #--------------------------------------------------------------------------
  637.       def select_last
  638.         select_symbol(@@last_command_symbol)
  639.       end
  640.      
  641.       def self.last_command_symbol
  642.         @@last_command_symbol
  643.       end
  644.      
  645.       def actor=(actor)
  646.         return if @actor == actor
  647.         @actor = actor
  648.         refresh
  649.         select_last
  650.       end
  651.      
  652.       #--------------------------------------------------------------------------
  653.       # * Changes the name of the command on the menu
  654.       #--------------------------------------------------------------------------
  655.       def change_command_name(index, symbol, name)
  656.         @list[index][:name] = name
  657.         @@command_names[symbol] = name
  658.       end
  659.      
  660.     end # - End Window_HotKeyCommand
  661.      
  662.     #==============================================================================
  663.     # ** Window_HotkeyCategory
  664.     #------------------------------------------------------------------------------
  665.     #  This window displays the categories Item and Skill when choosing which
  666.     #     hotkeys to associate with what.
  667.     #==============================================================================
  668.     class Window_HotkeyCategory < Window_HorzCommand
  669.       attr_reader :item_window
  670.      
  671.       def initialize(x,y,width)
  672.         @widow_width = width
  673.         super(x,y)
  674.        
  675.       end  # - End initialize
  676.       #--------------------------------------------------------------------------
  677.       # * Get Window Width
  678.       #--------------------------------------------------------------------------
  679.       def window_width
  680.         @widow_width
  681.       end # - End window_width
  682.       #--------------------------------------------------------------------------
  683.       # * Get Digit Count
  684.       #--------------------------------------------------------------------------
  685.       def col_max
  686.         return 4
  687.       end # - End col_max
  688.       #--------------------------------------------------------------------------
  689.       # * Frame Update
  690.       #--------------------------------------------------------------------------
  691.       def update
  692.         super
  693.         @item_window.category = current_symbol if @item_window
  694.       end # - End update
  695.       #--------------------------------------------------------------------------
  696.       # * Create Command List
  697.       #--------------------------------------------------------------------------
  698.       def make_command_list
  699.         add_command(Vocab::item,     :item)
  700.         add_command(Vocab::skill,   :skill)
  701.         add_command("On/Off",   :on_off)
  702.         add_command("Clear",   :clear)
  703.       end # - End make_command_list
  704.       #--------------------------------------------------------------------------
  705.       # * Set Item Window
  706.       #--------------------------------------------------------------------------
  707.       def item_window=(item_window)
  708.         @item_window = item_window
  709.         update
  710.       end # - End item_window
  711.      
  712.     end # - End Window_HotkeyCategory
  713.      
  714.     #==============================================================================
  715.     # ** Window_HotkeyItem
  716.     #------------------------------------------------------------------------------
  717.     #  This window displays a list of items that can be associated with hotkeys.
  718.     #==============================================================================
  719.      
  720.     class Window_HotkeyItem < Window_Selectable
  721.       #--------------------------------------------------------------------------
  722.       # * Object Initialization
  723.       #--------------------------------------------------------------------------
  724.       def initialize(x, y, width, height)
  725.         super
  726.         @category = :none
  727.         @data = []
  728.       end
  729.       #--------------------------------------------------------------------------
  730.       # * Set Category
  731.       #--------------------------------------------------------------------------
  732.       def category=(category)
  733.         return if @category == category
  734.         @category = category
  735.         refresh
  736.         self.oy = 0
  737.       end
  738.       #--------------------------------------------------------------------------
  739.       # * Get Digit Count
  740.       #--------------------------------------------------------------------------
  741.       def col_max
  742.         return 2
  743.       end
  744.       #--------------------------------------------------------------------------
  745.       # * Get Number of Items
  746.       #--------------------------------------------------------------------------
  747.       def item_max
  748.         @data ? @data.size : 1
  749.       end
  750.       #--------------------------------------------------------------------------
  751.       # * Get Item
  752.       #--------------------------------------------------------------------------
  753.       def item
  754.         @data && index >= 0 ? @data[index] : nil
  755.       end
  756.       #--------------------------------------------------------------------------
  757.       # * Get Activation State of Selection Item
  758.       #--------------------------------------------------------------------------
  759.       def current_item_enabled?
  760.         enable?(@data[index])
  761.       end
  762.       #--------------------------------------------------------------------------
  763.       # * Include in Item List?
  764.       #--------------------------------------------------------------------------
  765.       def include?(item)
  766.         return item.is_a?(RPG::Item)# && !item.key_item?
  767.       end
  768.       #--------------------------------------------------------------------------
  769.       # * Display in Enabled State?
  770.       #--------------------------------------------------------------------------
  771.       def enable?(item)
  772.         $game_party.usable?(item)
  773.       end
  774.       #--------------------------------------------------------------------------
  775.       # * Create Item List
  776.       #--------------------------------------------------------------------------
  777.       def make_item_list
  778.         @data = $game_party.all_items.select { |item|
  779.           include?(item) && enable?(item)
  780.         }
  781.         @data.push(nil) if include?(nil)
  782.       end
  783.       #--------------------------------------------------------------------------
  784.       # * Restore Previous Selection Position
  785.       #--------------------------------------------------------------------------
  786.       def select_last
  787.         select(@data.index($game_party.last_item.object) || 0)
  788.       end
  789.       #--------------------------------------------------------------------------
  790.       # * Draw Item
  791.       #--------------------------------------------------------------------------
  792.       def draw_item(index)
  793.         item = @data[index]
  794.         if item
  795.           rect = item_rect(index)
  796.           rect.width -= 4
  797.           draw_item_name(item, rect.x, rect.y, enable?(item))
  798.           draw_item_number(rect, item)
  799.         end
  800.       end
  801.       #--------------------------------------------------------------------------
  802.       # * Draw Number of Items
  803.       #--------------------------------------------------------------------------
  804.       def draw_item_number(rect, item)
  805.         draw_text(rect, sprintf(":%2d", $game_party.item_number(item)), 2)
  806.       end
  807.       #--------------------------------------------------------------------------
  808.       # * Update Help Text
  809.       #--------------------------------------------------------------------------
  810.       def update_help
  811.         @help_window.set_item(item)
  812.       end
  813.       #--------------------------------------------------------------------------
  814.       # * Refresh
  815.       #--------------------------------------------------------------------------
  816.       def refresh
  817.         make_item_list
  818.         create_contents
  819.         draw_all_items
  820.       end
  821.      
  822.     end # - End Window_HotkeyItem
  823.      
  824.      
  825.     #==============================================================================
  826.     # ** Window_HotkeySkillList
  827.     #------------------------------------------------------------------------------
  828.     #  This window is for displaying skills which can be associated with a hotkey
  829.     #==============================================================================
  830.      
  831.     class Window_HotkeySkillList < Window_Selectable
  832.       #--------------------------------------------------------------------------
  833.       # * Object Initialization
  834.       #--------------------------------------------------------------------------
  835.       def initialize(x, y, width, height)
  836.         super
  837.         @actor = nil
  838.         @stype_id = 0
  839.         @data = []
  840.         #self.visible = false
  841.       end
  842.       #--------------------------------------------------------------------------
  843.       # * Set Actor
  844.       #--------------------------------------------------------------------------
  845.       def actor=(actor)
  846.         return if @actor == actor
  847.         @actor = actor
  848.         refresh
  849.         self.oy = 0
  850.       end
  851.       #--------------------------------------------------------------------------
  852.       # * Set Skill Type ID
  853.       #--------------------------------------------------------------------------
  854.       def stype_id=(stype_id)
  855.         return if @stype_id == stype_id
  856.         @stype_id = stype_id
  857.         refresh
  858.         self.oy = 0
  859.       end
  860.       #--------------------------------------------------------------------------
  861.       # * Get Digit Count
  862.       #--------------------------------------------------------------------------
  863.       def col_max
  864.         return 2
  865.       end
  866.       #--------------------------------------------------------------------------
  867.       # * Get Number of Items
  868.       #--------------------------------------------------------------------------
  869.       def item_max
  870.         @data ? @data.size : 1
  871.       end
  872.       #--------------------------------------------------------------------------
  873.       # * Get Skill
  874.       #--------------------------------------------------------------------------
  875.       def item
  876.         @data && index >= 0 ? @data[index] : nil
  877.       end
  878.       #--------------------------------------------------------------------------
  879.       # * Get Activation State of Selection Item
  880.       #--------------------------------------------------------------------------
  881.       def current_item_enabled?
  882.         enable?(@data[index])
  883.       end
  884.       #--------------------------------------------------------------------------
  885.       # * Include in Skill List?
  886.       #--------------------------------------------------------------------------
  887.       def include?(item)
  888.         item
  889.       end
  890.       #--------------------------------------------------------------------------
  891.       # * Display Skill in Active State?
  892.       #--------------------------------------------------------------------------
  893.       def enable?(item)
  894.         true#@actor && @actor.usable?(item)
  895.       end
  896.       #--------------------------------------------------------------------------
  897.       # * Create Skill List
  898.       #--------------------------------------------------------------------------
  899.       def make_item_list
  900.         @data = @actor ? @actor.skills.select {|skill| include?(skill) } : []
  901.       end
  902.       #--------------------------------------------------------------------------
  903.       # * Restore Previous Selection Position
  904.       #--------------------------------------------------------------------------
  905.       def select_last
  906.         select(@data.index(@actor.last_skill.object) || 0)
  907.       end
  908.       #--------------------------------------------------------------------------
  909.       # * Draw Item
  910.       #--------------------------------------------------------------------------
  911.       def draw_item(index)
  912.         skill = @data[index]
  913.         if skill
  914.           rect = item_rect(index)
  915.           rect.width -= 4
  916.           draw_item_name(skill, rect.x, rect.y, enable?(skill))
  917.           draw_skill_cost(rect, skill)
  918.         end
  919.       end
  920.       #--------------------------------------------------------------------------
  921.       # * Draw Skill Use Cost
  922.       #--------------------------------------------------------------------------
  923.       def draw_skill_cost(rect, skill)
  924.         if @actor.skill_tp_cost(skill) > 0
  925.           change_color(tp_cost_color, enable?(skill))
  926.           draw_text(rect, @actor.skill_tp_cost(skill), 2)
  927.         elsif @actor.skill_mp_cost(skill) > 0
  928.           change_color(mp_cost_color, enable?(skill))
  929.           draw_text(rect, @actor.skill_mp_cost(skill), 2)
  930.         end
  931.       end
  932.       #--------------------------------------------------------------------------
  933.       # * Update Help Text
  934.       #--------------------------------------------------------------------------
  935.       def update_help
  936.         @help_window.set_item(item)
  937.       end
  938.       #--------------------------------------------------------------------------
  939.       # * Refresh
  940.       #--------------------------------------------------------------------------
  941.       def refresh
  942.         make_item_list
  943.         create_contents
  944.         draw_all_items
  945.       end
  946.      
  947.     end # - End Window_HotkeySkillList
  948.      
  949.     #==============================================================================
  950.     # * Easy Option for turning hotkey on/off
  951.     #==============================================================================
  952.     class Window_HkeyOnOff < Window_Selectable
  953.       #--------------------------------------------------------------------------
  954.       # * Draw Item
  955.       #--------------------------------------------------------------------------
  956.       def draw_item(index)
  957.         draw_text(5,0,180,22, "Action Bar On/Off")
  958.       end
  959.      
  960.       def item_max
  961.         return 1
  962.       end
  963.     end # Window_HkeyOnOFf
  964.      
  965.     #==============================================================================
  966.     # ** Scene_Hotkey
  967.     #------------------------------------------------------------------------------
  968.     #  This class performs the hotkey screen processing.
  969.     #==============================================================================
  970.     class Scene_Hotkey < Scene_ItemBase
  971.       #--------------------------------------------------------------------------
  972.       # * Start Processing
  973.       #--------------------------------------------------------------------------
  974.       def start
  975.         super
  976.         create_help_window
  977.         create_command_window
  978.         create_category_window
  979.         create_dummy_window
  980.         create_skill_window
  981.         create_item_window
  982.         create_hkey_on_off_window
  983.        
  984.         @skill_window.hide
  985.         @item_window.hide
  986.         @category_window.unselect
  987.         @category_window.deactivate
  988.         @hkey_on_off_window.hide
  989.       end # - End start
  990.      
  991.       #--------------------------------------------------------------------------
  992.       # * Create Command Window
  993.       #     * This windows has commands representing keys to use as hotkeys
  994.       #--------------------------------------------------------------------------
  995.       def create_command_window
  996.         wx = 0
  997.         wy = @help_window.height
  998.         @command_window = Window_HotkeyCommand.new(wx, wy)
  999.         @command_window.viewport = @viewport
  1000.         @command_window.help_window = @help_window
  1001.         @command_window.actor = @actor
  1002.         @command_window.set_handler(:ok, method(:on_hotkey_select))
  1003.         @command_window.set_handler(:cancel, method(:return_scene))
  1004.       end # - End create_command_window
  1005.      
  1006.       #--------------------------------------------------------------------------
  1007.       # * Create Skill Window
  1008.       #--------------------------------------------------------------------------
  1009.       def create_skill_window
  1010.         wx = @command_window.width
  1011.         wy = @category_window.y + @category_window.height
  1012.         ww = Graphics.width - @command_window.width
  1013.         wh = Graphics.height - wy
  1014.         @skill_window = Window_HotkeySkillList.new(wx, wy, ww, wh)
  1015.         @skill_window.actor = @actor
  1016.         @skill_window.viewport = @viewport
  1017.         @skill_window.help_window = @help_window
  1018.         @skill_window.set_handler(:ok,     method(:on_skill_ok))
  1019.         @skill_window.set_handler(:cancel, method(:on_item_cancel))
  1020.       end # - End create_skill_window
  1021.      
  1022.       #--------------------------------------------------------------------------
  1023.       # * Create Item Window
  1024.       #--------------------------------------------------------------------------
  1025.       def create_item_window
  1026.         wy = @category_window.y + @category_window.height
  1027.         wh = Graphics.height - wy
  1028.         ww = Graphics.width-@command_window.width
  1029.         @item_window = Window_HotkeyItem.new(@command_window.width, wy, ww, wh)
  1030.         @item_window.viewport = @viewport
  1031.         @item_window.help_window = @help_window
  1032.         @item_window.set_handler(:ok,     method(:on_item_ok))
  1033.         @item_window.set_handler(:cancel, method(:on_item_cancel))
  1034.         @category_window.item_window = @item_window
  1035.       end # - End create_item_window
  1036.      
  1037.       def create_hkey_on_off_window
  1038.         wy = @category_window.y + @category_window.height
  1039.         wh = Graphics.height - wy
  1040.         ww = Graphics.width-@command_window.width
  1041.         @hkey_on_off_window = Window_HkeyOnOff.new(@command_window.width, wy,ww,wh)
  1042.         @hkey_on_off_window.viewport = @viewport
  1043.         @hkey_on_off_window.set_handler(:ok,     method(:on_off_ok))
  1044.         @hkey_on_off_window.set_handler(:cancel, method(:on_item_cancel))
  1045.       end
  1046.      
  1047.       #def item_usable?
  1048.       #  $hkey_user.usable?($hkey_item) && item_effects_valid?
  1049.       #end
  1050.      
  1051.       #--------------------------------------------------------------------------
  1052.       # * Create Category Window
  1053.       #--------------------------------------------------------------------------
  1054.       def create_category_window
  1055.         x = @command_window.width
  1056.         y = @help_window.height
  1057.         width = Graphics.width - @command_window.width
  1058.         @category_window = Window_HotkeyCategory.new(x,y, width)
  1059.         @category_window.viewport = @viewport
  1060.         @category_window.help_window = @help_window
  1061.         @category_window.y = @help_window.height
  1062.         @category_window.set_handler(:ok,     method(:on_category_ok))
  1063.         @category_window.set_handler(:cancel, method(:on_hotkey_cancel))
  1064.       end # - End create_category_window
  1065.      
  1066.       #--------------------------------------------------------------------------
  1067.       # * Create Dummy Window
  1068.       #     * This window is used just for looks, it sits in the background
  1069.       #--------------------------------------------------------------------------
  1070.       def create_dummy_window
  1071.         wy = @category_window.y + @category_window.height
  1072.         wh = Graphics.height - wy
  1073.         ww = Graphics.width - @command_window.width
  1074.         @dummy_window = Window_Base.new(@command_window.width, wy, ww, wh)
  1075.         @dummy_window.viewport = @viewport
  1076.       end # - End create_dummy_window
  1077.      
  1078.       #--------------------------------------------------------------------------
  1079.       # * Get the user this hotkey is associated with
  1080.       #--------------------------------------------------------------------------
  1081.       #def user
  1082.       #  @actor
  1083.       #end
  1084.      
  1085.       #--------------------------------------------------------------------------
  1086.       # * Category [OK]
  1087.       #--------------------------------------------------------------------------
  1088.       def on_category_ok
  1089.         @dummy_window.hide
  1090.         if @category_window.index == 0 #category item
  1091.           @item_window.activate
  1092.           @item_window.select_last
  1093.           @skill_window.hide
  1094.           @hkey_on_off_window.hide
  1095.           @item_window.show
  1096.           @skill_window.refresh
  1097.           @item_window.refresh
  1098.         elsif @category_window.index == 1 #category skill
  1099.           @skill_window.activate
  1100.           @skill_window.select_last
  1101.           @skill_window.show
  1102.           @item_window.hide
  1103.           @hkey_on_off_window.hide
  1104.           @skill_window.refresh
  1105.           @item_window.refresh
  1106.         elsif @category_window.index == 2 # action bar on/off
  1107.           @hkey_on_off_window.activate
  1108.           @hkey_on_off_window.select(0)
  1109.           @hkey_on_off_window.show
  1110.           @hkey_on_off_window.refresh
  1111.           @item_window.hide
  1112.           @skill_window.hide
  1113.         else                               #category clear
  1114.           @dummy_window.show
  1115.           Game_Map.game_hotkeys[Window_HotkeyCommand.last_command_symbol] = nil
  1116.           sym = @command_window.current_symbol
  1117.           $hotkey_data[sym] = nil
  1118.           update_command_window_text(sym, nil)
  1119.           @category_window.refresh
  1120.           @category_window.activate
  1121.         end
  1122.       end # - End on_category_ok
  1123.      
  1124.       #--------------------------------------------------------------------------
  1125.       # * Item [OK]
  1126.       #--------------------------------------------------------------------------
  1127.       def on_item_ok
  1128.         new_hotkey(@item_window)
  1129.       end # - End on_item_ok
  1130.      
  1131.       #--------------------------------------------------------------------------
  1132.       # * Skill [OK]
  1133.       #--------------------------------------------------------------------------
  1134.       def on_skill_ok
  1135.         new_hotkey(@skill_window)
  1136.       end # - End on_skill_ok
  1137.      
  1138.       #--------------------------------------------------------------------------
  1139.       # * Action bar on/off category
  1140.       #--------------------------------------------------------------------------
  1141.       def on_off_ok
  1142.         add_on_off_hkey
  1143.         @command_window.activate
  1144.       end
  1145.      
  1146.       def add_on_off_hkey
  1147.         sym = @command_window.current_symbol
  1148.         $hotkey_data[sym] = :action_bar_on_off
  1149.         update_command_window_text(sym, :action_bar_on_off)
  1150.       end
  1151.       #--------------------------------------------------------------------------
  1152.       # * Update $hotkey_data with the new hotkey.
  1153.       #--------------------------------------------------------------------------
  1154.       def new_hotkey(window)
  1155.         $game_party.last_item.object = item
  1156.         Game_Map.game_hotkeys[Window_HotkeyCommand.last_command_symbol] = [@actor, (item = window.item), window.item.is_a?(RPG::Skill) ? :skill : :item]
  1157.         sym = @command_window.current_symbol
  1158.         $hotkey_data[sym] = item.icon_index
  1159.         update_command_window_text(sym, item)
  1160.         @command_window.activate
  1161.       end # - End new_hotkey
  1162.      
  1163.       def update_command_window_text(sym, item)
  1164.         colon = get_colon(sym)
  1165.         name = !item ? "" : nil
  1166.         name = (item &&!item.is_a?(RPG::UsableItem)) ? "->On/Off" : ("->" + item.name) if name.nil?
  1167.        
  1168.        
  1169.         @command_window.change_command_name(@command_window.index, sym, colon+sym.to_s + name)
  1170.         @command_window.refresh
  1171.       end
  1172.      
  1173.       def get_colon(sym)
  1174.         colon = ":"
  1175.         case sym.to_s
  1176.         when "F5"
  1177.           colon = ""
  1178.         when "F6"
  1179.           colon = ""
  1180.         when "F7"
  1181.           colon = ""
  1182.         when "F8"
  1183.           colon = ""
  1184.         end
  1185.         return colon
  1186.       end
  1187.       #--------------------------------------------------------------------------
  1188.       # * Item [Cancel]
  1189.       #--------------------------------------------------------------------------
  1190.       def on_item_cancel
  1191.         @item_window.hide
  1192.         @skill_window.hide
  1193.         @hkey_on_off_window.hide
  1194.         @dummy_window.show
  1195.         @category_window.activate
  1196.       end # - End on_item_cancel
  1197.      
  1198.       #--------------------------------------------------------------------------
  1199.       # * Play SE When Using Item
  1200.       #--------------------------------------------------------------------------
  1201.       def play_se_for_item
  1202.         Sound.play_use_item
  1203.       end
  1204.      
  1205.       #--------------------------------------------------------------------------
  1206.       # * Cancels selection on the category window and moves back to the command
  1207.       #     window.
  1208.       #--------------------------------------------------------------------------
  1209.       def on_hotkey_cancel
  1210.         @command_window.activate
  1211.         @category_window.unselect
  1212.       end # - End on_hotkey_cancel
  1213.      
  1214.       #--------------------------------------------------------------------------
  1215.       # * Handles processing after a hotkey has been selected from the command
  1216.       #     window.
  1217.       #--------------------------------------------------------------------------
  1218.       def on_hotkey_select
  1219.         @category_window.activate
  1220.         @category_window.select(0)
  1221.       end
  1222.     end # - End Scene_Hotkey
  1223.     #=================================END OF FILE===================================
Advertisement
Add Comment
Please, Sign In to add comment