blucalm

Hotkeys Update 30 Mar 2013

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