Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
- # ** Hotkeys
- # Author: Eshra
- # Release Date: 20 Aug. 2012
- # Compatibility: RPG Maker VX Ace
- # Dependencies: None
- #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
- #
- # About:
- #
- # This script allows skills and items to be linked to hotkeys from a new menu
- # inside of the main menu. It also creates an actionbar that can be turned on
- # or off.
- #
- # The hotkeys can be used while the current Scene is Scene_Map. The update
- # method of Scene_Map is now listens for key presses.
- #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
- #
- #------------------------------------------------------------------------------
- # * How to Use
- #------------------------------------------------------------------------------
- #
- # To use this script, insert it as new script in the script editor under
- # the materials section.
- #
- # It's a very simple plug and play script, you can adjust which skills or items
- # are used by which hotkeys from the main menu in game.
- #
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # Author Notes:
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- #
- # Aliased Methods:
- # Scene_Map:
- # update
- # Scene_Map
- # update
- #
- # Window_MenuCommand
- # add_original_commands
- #
- # Scene_Menu
- # create_command_window
- # on_personal_ok
- #
- # I used several global variables and they were not encapsulated inside
- # Game_Temp or anything so there may potentially be some namespace pollution
- # problems.
- #
- # Hotkeys are retained when using f12 to reset. I honestly don't know if I care
- # enough to write the code to fix this. It's so trivial.
- #
- # This was one of the first scrips I ever wrote for rpg maker so I likely made
- # a lot of mistakes in terms of coding practices etc.
- #
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # Original Release Date: 20 Aug. 2012
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # Update Log:
- # 3 Dec. 2012 - Can see item amounts. The script didn't actually work for skills...
- # fixed now. Can assign turning the action bar on and off to a hotkey
- # now. Hotkeys only show up on the menu once. Items being used on friends
- # are no longer used when canceling before selecting a party member.
- # 6 Nov. 2012 - Added check to see if item was usable.
- #
- # 20 Aug. 2012 - First Version Finished
- #
- #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
- # Terms of Use
- #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
- # Free to use as you please. Please respect the header though so the dates can
- # be preserved.
- #------------------------------------------------------------------------------
- ($imported||={})["(~^_^)~Hotkeys"] = 0.1
- # Below are the settings that can be adjusted when using this script
- module HOTKEY
- module ACTIONBAR
- HEIGHT = 47 # Height of the action bar
- FONTSIZE = 13.5 # Size of the font in the action bar
- MAX = 12 # This value should be greater than 0 and less than or equal to 12
- # it is the number of hotkeys the player can use
- LOCATION = [183, 205] # Numerator mod, Denominator
- VISIBLE = true # Switch this to false to hide the action bar.
- WIDTH_OFFSET = 100
- CD_VISIBLE = true
- ORDER = { # The hotkey associated with 1 is the leftmost, 12 is rightmost.
- 1 => :F5, # The symbols associatated with each number can be mixed and
- 2 => :F6, # matched around. For example to display hotkey A as the
- 3 => :F7, # leftmost hotkey instead of F5. Swamp :A with :F5 in the hash
- 4 => :F8, # such that 1 => :A and 5 => :F5.
- 5 => :A,
- 6 => :B,
- 7 => :C,
- 8 => :X,
- 9 => :Y,
- 10 => :Z,
- 11 => :L,
- 12 => :R
- }
- end
- module COOLDOWN_GAUGE
- COLOR1 = Color.new(120, 80, 0, 250)
- COLOR2 = Color.new(200, 250, 0, 250)
- end
- end
- #===============================================================
- # Game_Map:
- # New variables are added to hold hotkey information
- #
- #===============================================================
- class Game_Map
- $hotkey_data = {} #maps symbols to item icons
- @@game_hotkeys = {}
- def self.game_hotkeys
- @@game_hotkeys
- end
- end # End - Game_Map
- #===============================================================
- # Window_Base:
- # Change the update so it handles the case where the window
- # has been disposed of.
- #===============================================================
- class Window_Base < Window
- alias hotkey_update_alias_meth_9092 update
- def update
- return if disposed?
- hotkey_update_alias_meth_9092
- end # - End update
- end # - End Window_Base
- #===============================================================
- # Scene_Map:
- # The update method listens for keyboard input.
- #===============================================================
- class Scene_Map < Scene_Base
- $hkey_user = nil
- $hkey_target = nil
- @@show_actionbar = HOTKEY::ACTIONBAR::VISIBLE
- alias hotkey_sc_map_start_meth_add_var start
- def start
- hotkey_sc_map_start_meth_add_var
- end # End - start
- def self.hide_actionbar
- @@show_actionbar = false
- end
- def self.show_action_bar
- @@show_actionbar = true
- end
- alias hotkey_update_alias_9090 update
- def update
- hotkey_update_alias_9090
- if Input.trigger?(:F5)
- evalute_hotkey(:F5)
- elsif Input.trigger?(:F6)
- evalute_hotkey(:F6)
- elsif Input.trigger?(:F7)
- evalute_hotkey(:F7)
- elsif Input.trigger?(:F8)
- evalute_hotkey(:F8)
- elsif Input.trigger?(:A)
- evalute_hotkey(:A)
- elsif Input.trigger?(:B)
- evalute_hotkey(:B)
- elsif Input.trigger?(:C)
- evalute_hotkey(:C)
- elsif Input.trigger?(:X)
- evalute_hotkey(:X)
- elsif Input.trigger?(:Y)
- evalute_hotkey(:Y)
- elsif Input.trigger?(:Z)
- evalute_hotkey(:Z)
- elsif Input.trigger?(:R)
- evalute_hotkey(:R)
- elsif Input.trigger?(:L)
- evalute_hotkey(:L)
- end # - End trigger cases
- update_actionbar
- update_cool_downs
- end # - End update
- def update_actionbar
- # hide action bar if game_message is being shown
- hide_ab_when_showing_message
- if @@show_actionbar
- if @actionbar == nil || @actionbar.disposed?
- create_actionbar
- end # - End actionbar check
- @actionbar.update unless @actionbar.disposed?
- else
- @actionbar.dispose unless @actionbar == nil
- end # End - if @@show_actionbar
- end
- def hide_ab_when_showing_message
- if $game_message.visible
- @temp_hide_abar = true if @@show_actionbar
- Scene_Map.hide_actionbar
- else
- Scene_Map.show_action_bar if @temp_hide_abar
- end
- end
- def update_cool_downs
- return unless $imported["(~^_^)~Cooldowns"]
- if @@show_actionbar && HOTKEY::ACTIONBAR::CD_VISIBLE
- if @cooldown_imgs == nil || @cooldown_imgs.disposed?
- create_cooldown_images
- end # - End actionbar check
- @cooldown_imgs.contents.clear
- draw_cooldown_imgs_contents(@cooldown_imgs)
- @cooldown_imgs.update unless @cooldown_imgs.disposed?
- end
- end
- def create_cooldown_images
- wy = HOTKEY::ACTIONBAR::LOCATION[0]*Graphics.height/HOTKEY::ACTIONBAR::LOCATION[1]
- wh = HOTKEY::ACTIONBAR::HEIGHT
- ww = Graphics.width - HOTKEY::ACTIONBAR::WIDTH_OFFSET
- @cooldown_imgs = Window_Base.new(HOTKEY::ACTIONBAR::WIDTH_OFFSET/2, wy, ww, wh)
- @cooldown_imgs.viewport = @viewport
- @cooldown_imgs.opacity = 0
- draw_cooldown_imgs_contents(@cooldown_imgs)
- end
- def draw_cooldown_imgs_contents(window)
- width = Graphics.width-HOTKEY::ACTIONBAR::WIDTH_OFFSET
- font_size = HOTKEY::ACTIONBAR::FONTSIZE
- max = HOTKEY::ACTIONBAR::MAX
- (1..max).each{ |key|
- used_cd = 0
- used_cd_base = 0
- bar_length = 0
- item_cd = 0
- item_cd_base = 0
- sym = HOTKEY::ACTIONBAR::ORDER[key]
- item = Game_Map.game_hotkeys[sym]
- item = item[1] unless item == nil
- next if item == nil
- gcd = $game_map.gcd_val #global cooldown amt
- item_cd = item.cooldown_timer
- used_cd = 0#(gcd > item_cd) gcd : item_cd
- used_cd_base = -1
- if gcd > item_cd
- used_cd = $game_map.gcd_val
- used_cd_base = $game_map.gcd_base
- else
- used_cd = item_cd
- used_cd_base = item.base_cooldown
- end
- if used_cd_base <= 0
- used_cd_base = 1
- end
- bar_length = used_cd * (width/max) / used_cd_base
- if bar_length > 0
- window.draw_gauge((key-1)*width/max,0,bar_length,1.01,HOTKEY::COOLDOWN_GAUGE::COLOR1,HOTKEY::COOLDOWN_GAUGE::COLOR2)
- end
- }
- end # - End draw_actionbar_contents
- def create_cd_bar
- @cd_bar = Bitmap.new(50,50)
- @cd_bar.fill_rect(0,0,50,50, Color.new(0, 0, 0, 160))
- end
- def create_actionbar
- wy = HOTKEY::ACTIONBAR::LOCATION[0]*Graphics.height/HOTKEY::ACTIONBAR::LOCATION[1]
- wh = HOTKEY::ACTIONBAR::HEIGHT
- ww = Graphics.width - HOTKEY::ACTIONBAR::WIDTH_OFFSET
- @actionbar = Window_Base.new(HOTKEY::ACTIONBAR::WIDTH_OFFSET/2, wy, ww, wh)
- @actionbar.viewport = @viewport
- draw_actionbar_contents(@actionbar)
- end # - End create_actionbar
- def draw_actionbar_contents(window)
- width = Graphics.width-HOTKEY::ACTIONBAR::WIDTH_OFFSET
- font_size = HOTKEY::ACTIONBAR::FONTSIZE
- max = HOTKEY::ACTIONBAR::MAX
- (1..max).each{ |key|
- sym = HOTKEY::ACTIONBAR::ORDER[key]
- ind = $hotkey_data[sym]
- if ind && ind.to_s.to_sym == :action_bar_on_off
- window.contents.font.size = font_size
- window.contents.draw_text((key-1)*width/max,0,width,22,sym.to_s)
- window.contents.draw_text((key-1)*width/max+6,8,width,22,"OFF")
- next
- end
- window.draw_icon(ind, (key-1)*width/max, 0) unless ind == nil
- window.contents.font.size = font_size
- window.contents.draw_text((key-1)*width/max,0,width,22,sym.to_s)
- hkey = Game_Map.game_hotkeys[sym]
- next unless hkey
- # item = Game_Map.game_hotkeys[sym][1].id
- id = hkey[1].id
- amt = hkey[2] == :item ? $game_party.item_number($data_items[id]) : nil
- window.contents.draw_text((key-1)*width/max + 8,8,width,22,"x#{amt.to_s}") if amt
- }
- end # - End draw_actionbar_contents
- def refresh_actionbar
- draw_actionbar_contents(@actionbar)
- end
- def evalute_hotkey(symbol)
- if $hotkey_data[symbol] == :action_bar_on_off
- @@show_actionbar ? Scene_Map.hide_actionbar : Scene_Map.show_action_bar
- update_actionbar
- return
- end
- return if !(hkey = Game_Map.game_hotkeys[symbol])
- id = hkey[1].id
- $hkey_item = item = hkey[2] == :skill ? $data_skills[id] : $data_items[id] # $data_items[hkey[1].id]
- $hkey_user = actor = $game_actors[hkey[0].id]
- if actor.usable?(item) && !item.nil? && !actor.nil?
- use_item_to_actors if item.for_friend?
- if @hkey_use_itm_ok && item.for_friend?
- actor.use_item(item)
- @hkey_use_itm_ok = false
- end
- check_gameover
- Sound.play_use_item
- else
- Sound.play_buzzer
- end
- refresh_actionbar
- end # - End evalute_hotkey
- def check_gameover
- SceneManager.goto(Scene_Gameover) if $game_party.all_dead?
- end # - End check_gameover
- def use_item_to_actors
- item, user = $hkey_item, $hkey_user
- array = item_target_actors
- return if !array
- array.each do |target|
- @hkey_use_itm_ok = true
- item.repeats.times {
- target.item_apply(user, item)
- }
- end
- end # - End use_item_to_actors
- def item_target_actors
- item = $hkey_item
- if !item.for_friend?
- []
- elsif item.for_all?
- $game_party.members
- else
- SceneManager.call(Scene_HotkeyActorSelection)
- []
- end
- end # - End item_target_actors
- end # - End Scene_Map
- #===============================================================
- # Scene_HotkeyActorSelection:
- # This class handles party member selection for hotkeys linked
- # to items/skills with a single target.
- #===============================================================
- class Scene_HotkeyActorSelection < Scene_ItemBase
- def start
- super
- create_actor_window
- show_sub_window(@actor_window)
- @user = $hkey_user
- @item = $hkey_item
- @actor_window.select(0)
- end # - End start
- #--------------------------------------------------------------------------
- # * Window to select the target of a skill or item
- #--------------------------------------------------------------------------
- def create_actor_window
- @actor_window = Window_MenuActor.new
- @actor_window.set_handler(:ok, method(:on_actor_ok))
- @actor_window.set_handler(:cancel, method(:on_actor_cancel))
- end # - End create_actor_window
- #--------------------------------------------------------------------------
- # * Use Item on Actor
- #--------------------------------------------------------------------------
- def use_item_to_actors
- item_target_actors.each do |target|
- item.repeats.times { target.item_apply(user, item) }
- end
- end # - End use_item_to_actors
- def user
- @user
- end
- def item
- @item
- end
- def play_se_for_item
- Sound.play_use_item
- end
- #--------------------------------------------------------------------------
- # * Actor [Cancel]
- #--------------------------------------------------------------------------
- def on_actor_cancel
- hide_sub_window(@actor_window)
- end
- #--------------------------------------------------------------------------
- # * Show Subwindow
- #--------------------------------------------------------------------------
- def show_sub_window(window)
- width_remain = Graphics.width - window.width
- window.x = 0
- @viewport.rect.x = @viewport.ox = window.width
- @viewport.rect.width = width_remain
- window.show.activate
- end # - End show_sub_window
- #--------------------------------------------------------------------------
- # * Hide Subwindow
- #--------------------------------------------------------------------------
- def hide_sub_window(window)
- @viewport.rect.x = @viewport.ox = 0
- @viewport.rect.width = Graphics.width
- window.hide.deactivate
- return_scene
- end # - End hide_sub_window
- #--------------------------------------------------------------------------
- # * Determine if Item Is Effective
- #--------------------------------------------------------------------------
- def item_effects_valid?
- item_target_actors.any? do |target|
- target.item_test($hkey_user, $hkey_item)
- end
- end # - End item_effects_valid?
- #--------------------------------------------------------------------------
- # * Determine item targets
- #--------------------------------------------------------------------------
- def item_target_actors
- if !$hkey_item.for_friend?
- []
- elsif $hkey_item.for_all?
- $game_party.members
- else
- [$game_party.members[@actor_window.index]]
- end
- end # - End item_target_actors
- end # - End Scene_HotkeyActorSelection
- #===============================================================
- # Window_MenuCommand:
- # Adds a new command option called "Hot Keys" to the main menu
- #===============================================================
- class Window_MenuCommand < Window_Command
- alias al_alias_method_m_make_com_l_ch_98384 make_command_list
- def make_command_list
- add_command("Hot Keys", :hotkey, true)
- al_alias_method_m_make_com_l_ch_98384
- end
- alias hotkey_add_orig_com_alias_9089 add_original_commands
- def add_original_commands
- hotkey_add_orig_com_alias_9089
- end # - End add_original_commands
- end # - End Window_MenuCommand
- #Scene_Menu class
- class Scene_Menu < Scene_MenuBase
- #--------------------------------------------------------------------------
- # * Create Command Window
- #--------------------------------------------------------------------------
- alias hotkey_create_com_win_alias_9088 create_command_window
- def create_command_window
- hotkey_create_com_win_alias_9088
- @command_window.set_handler(:hotkey, method(:command_personal))
- end # - End create_command_window
- # * Alias on_personal_ok
- alias hotkey_on_pers_ok_alias_meth on_personal_ok
- def on_personal_ok
- hotkey_on_pers_ok_alias_meth
- case @command_window.current_symbol
- when :hotkey
- SceneManager.call(Scene_Hotkey)
- end # - End case block
- end # - End on_personal_ok
- end # - End Scene_Menu
- #==============================================================================
- # ** Window_HotkeyCommand
- #------------------------------------------------------------------------------
- # This command window appears on the menu screen.
- #==============================================================================
- class Window_HotkeyCommand < Window_Command
- attr_accessor :list
- #--------------------------------------------------------------------------
- # * Initialize Command Selection Position (Class Method)
- #--------------------------------------------------------------------------
- @@last_command_symbol = nil
- @@command_names ||= {
- :F5 => "F5",
- :F6 => "F6",
- :F7 => "F7",
- :F8 => "F8",
- :A => ":A",
- :B => ":B",
- :C => ":C",
- :X => ":X",
- :Y => ":Y",
- :Z => ":Z",
- :L => ":L",
- :R => ":R"
- }
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(x,y)
- super(x, y)
- select_last
- @actor = nil
- end
- #--------------------------------------------------------------------------
- # * Get Window Width
- #--------------------------------------------------------------------------
- def window_width
- return 160
- end
- #--------------------------------------------------------------------------
- # * Get Number of Lines to Show
- #--------------------------------------------------------------------------
- def visible_line_number
- item_max
- end
- #--------------------------------------------------------------------------
- # * Create Command List
- #--------------------------------------------------------------------------
- def make_command_list
- add_main_commands
- end
- #--------------------------------------------------------------------------
- # * Add Main Commands to List
- #--------------------------------------------------------------------------
- def add_main_commands
- pos_hash = HOTKEY::ACTIONBAR::ORDER
- (1..HOTKEY::ACTIONBAR::MAX).each{ |key|
- sym = pos_hash[key]
- add_command(@@command_names[sym], sym)
- }
- end
- #--------------------------------------------------------------------------
- # * Processing When OK Button Is Pressed
- #--------------------------------------------------------------------------
- def process_ok
- @@last_command_symbol = current_symbol
- super
- end
- #--------------------------------------------------------------------------
- # * Restore Previous Selection Position
- #--------------------------------------------------------------------------
- def select_last
- select_symbol(@@last_command_symbol)
- end
- def self.last_command_symbol
- @@last_command_symbol
- end
- def actor=(actor)
- return if @actor == actor
- @actor = actor
- refresh
- select_last
- end
- #--------------------------------------------------------------------------
- # * Changes the name of the command on the menu
- #--------------------------------------------------------------------------
- def change_command_name(index, symbol, name)
- @list[index][:name] = name
- @@command_names[symbol] = name
- end
- end # - End Window_HotKeyCommand
- #==============================================================================
- # ** Window_HotkeyCategory
- #------------------------------------------------------------------------------
- # This window displays the categories Item and Skill when choosing which
- # hotkeys to associate with what.
- #==============================================================================
- class Window_HotkeyCategory < Window_HorzCommand
- attr_reader :item_window
- def initialize(x,y,width)
- @widow_width = width
- super(x,y)
- end # - End initialize
- #--------------------------------------------------------------------------
- # * Get Window Width
- #--------------------------------------------------------------------------
- def window_width
- @widow_width
- end # - End window_width
- #--------------------------------------------------------------------------
- # * Get Digit Count
- #--------------------------------------------------------------------------
- def col_max
- return 4
- end # - End col_max
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- super
- @item_window.category = current_symbol if @item_window
- end # - End update
- #--------------------------------------------------------------------------
- # * Create Command List
- #--------------------------------------------------------------------------
- def make_command_list
- add_command(Vocab::item, :item)
- add_command(Vocab::skill, :skill)
- add_command("On/Off", :on_off)
- add_command("Clear", :clear)
- end # - End make_command_list
- #--------------------------------------------------------------------------
- # * Set Item Window
- #--------------------------------------------------------------------------
- def item_window=(item_window)
- @item_window = item_window
- update
- end # - End item_window
- end # - End Window_HotkeyCategory
- #==============================================================================
- # ** Window_HotkeyItem
- #------------------------------------------------------------------------------
- # This window displays a list of items that can be associated with hotkeys.
- #==============================================================================
- class Window_HotkeyItem < Window_Selectable
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(x, y, width, height)
- super
- @category = :none
- @data = []
- end
- #--------------------------------------------------------------------------
- # * Set Category
- #--------------------------------------------------------------------------
- def category=(category)
- return if @category == category
- @category = category
- refresh
- self.oy = 0
- end
- #--------------------------------------------------------------------------
- # * Get Digit Count
- #--------------------------------------------------------------------------
- def col_max
- return 2
- end
- #--------------------------------------------------------------------------
- # * Get Number of Items
- #--------------------------------------------------------------------------
- def item_max
- @data ? @data.size : 1
- end
- #--------------------------------------------------------------------------
- # * Get Item
- #--------------------------------------------------------------------------
- def item
- @data && index >= 0 ? @data[index] : nil
- end
- #--------------------------------------------------------------------------
- # * Get Activation State of Selection Item
- #--------------------------------------------------------------------------
- def current_item_enabled?
- enable?(@data[index])
- end
- #--------------------------------------------------------------------------
- # * Include in Item List?
- #--------------------------------------------------------------------------
- def include?(item)
- return item.is_a?(RPG::Item)# && !item.key_item?
- end
- #--------------------------------------------------------------------------
- # * Display in Enabled State?
- #--------------------------------------------------------------------------
- def enable?(item)
- $game_party.usable?(item)
- end
- #--------------------------------------------------------------------------
- # * Create Item List
- #--------------------------------------------------------------------------
- def make_item_list
- @data = $game_party.all_items.select { |item|
- include?(item) && enable?(item)
- }
- @data.push(nil) if include?(nil)
- end
- #--------------------------------------------------------------------------
- # * Restore Previous Selection Position
- #--------------------------------------------------------------------------
- def select_last
- select(@data.index($game_party.last_item.object) || 0)
- end
- #--------------------------------------------------------------------------
- # * Draw Item
- #--------------------------------------------------------------------------
- def draw_item(index)
- item = @data[index]
- if item
- rect = item_rect(index)
- rect.width -= 4
- draw_item_name(item, rect.x, rect.y, enable?(item))
- draw_item_number(rect, item)
- end
- end
- #--------------------------------------------------------------------------
- # * Draw Number of Items
- #--------------------------------------------------------------------------
- def draw_item_number(rect, item)
- draw_text(rect, sprintf(":%2d", $game_party.item_number(item)), 2)
- end
- #--------------------------------------------------------------------------
- # * Update Help Text
- #--------------------------------------------------------------------------
- def update_help
- @help_window.set_item(item)
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- make_item_list
- create_contents
- draw_all_items
- end
- end # - End Window_HotkeyItem
- #==============================================================================
- # ** Window_HotkeySkillList
- #------------------------------------------------------------------------------
- # This window is for displaying skills which can be associated with a hotkey
- #==============================================================================
- class Window_HotkeySkillList < Window_Selectable
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(x, y, width, height)
- super
- @actor = nil
- @stype_id = 0
- @data = []
- #self.visible = false
- end
- #--------------------------------------------------------------------------
- # * Set Actor
- #--------------------------------------------------------------------------
- def actor=(actor)
- return if @actor == actor
- @actor = actor
- refresh
- self.oy = 0
- end
- #--------------------------------------------------------------------------
- # * Set Skill Type ID
- #--------------------------------------------------------------------------
- def stype_id=(stype_id)
- return if @stype_id == stype_id
- @stype_id = stype_id
- refresh
- self.oy = 0
- end
- #--------------------------------------------------------------------------
- # * Get Digit Count
- #--------------------------------------------------------------------------
- def col_max
- return 2
- end
- #--------------------------------------------------------------------------
- # * Get Number of Items
- #--------------------------------------------------------------------------
- def item_max
- @data ? @data.size : 1
- end
- #--------------------------------------------------------------------------
- # * Get Skill
- #--------------------------------------------------------------------------
- def item
- @data && index >= 0 ? @data[index] : nil
- end
- #--------------------------------------------------------------------------
- # * Get Activation State of Selection Item
- #--------------------------------------------------------------------------
- def current_item_enabled?
- enable?(@data[index])
- end
- #--------------------------------------------------------------------------
- # * Include in Skill List?
- #--------------------------------------------------------------------------
- def include?(item)
- item
- end
- #--------------------------------------------------------------------------
- # * Display Skill in Active State?
- #--------------------------------------------------------------------------
- def enable?(item)
- true#@actor && @actor.usable?(item)
- end
- #--------------------------------------------------------------------------
- # * Create Skill List
- #--------------------------------------------------------------------------
- def make_item_list
- @data = @actor ? @actor.skills.select {|skill| include?(skill) } : []
- end
- #--------------------------------------------------------------------------
- # * Restore Previous Selection Position
- #--------------------------------------------------------------------------
- def select_last
- select(@data.index(@actor.last_skill.object) || 0)
- end
- #--------------------------------------------------------------------------
- # * Draw Item
- #--------------------------------------------------------------------------
- def draw_item(index)
- skill = @data[index]
- if skill
- rect = item_rect(index)
- rect.width -= 4
- draw_item_name(skill, rect.x, rect.y, enable?(skill))
- draw_skill_cost(rect, skill)
- end
- end
- #--------------------------------------------------------------------------
- # * Draw Skill Use Cost
- #--------------------------------------------------------------------------
- def draw_skill_cost(rect, skill)
- if @actor.skill_tp_cost(skill) > 0
- change_color(tp_cost_color, enable?(skill))
- draw_text(rect, @actor.skill_tp_cost(skill), 2)
- elsif @actor.skill_mp_cost(skill) > 0
- change_color(mp_cost_color, enable?(skill))
- draw_text(rect, @actor.skill_mp_cost(skill), 2)
- end
- end
- #--------------------------------------------------------------------------
- # * Update Help Text
- #--------------------------------------------------------------------------
- def update_help
- @help_window.set_item(item)
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- make_item_list
- create_contents
- draw_all_items
- end
- end # - End Window_HotkeySkillList
- #==============================================================================
- # * Easy Option for turning hotkey on/off
- #==============================================================================
- class Window_HkeyOnOff < Window_Selectable
- #--------------------------------------------------------------------------
- # * Draw Item
- #--------------------------------------------------------------------------
- def draw_item(index)
- draw_text(5,0,180,22, "Action Bar On/Off")
- end
- def item_max
- return 1
- end
- end # Window_HkeyOnOFf
- #==============================================================================
- # ** Scene_Hotkey
- #------------------------------------------------------------------------------
- # This class performs the hotkey screen processing.
- #==============================================================================
- class Scene_Hotkey < Scene_ItemBase
- #--------------------------------------------------------------------------
- # * Start Processing
- #--------------------------------------------------------------------------
- def start
- super
- create_help_window
- create_command_window
- create_category_window
- create_dummy_window
- create_skill_window
- create_item_window
- create_hkey_on_off_window
- @skill_window.hide
- @item_window.hide
- @category_window.unselect
- @category_window.deactivate
- @hkey_on_off_window.hide
- end # - End start
- #--------------------------------------------------------------------------
- # * Create Command Window
- # * This windows has commands representing keys to use as hotkeys
- #--------------------------------------------------------------------------
- def create_command_window
- wx = 0
- wy = @help_window.height
- @command_window = Window_HotkeyCommand.new(wx, wy)
- @command_window.viewport = @viewport
- @command_window.help_window = @help_window
- @command_window.actor = @actor
- @command_window.set_handler(:ok, method(:on_hotkey_select))
- @command_window.set_handler(:cancel, method(:return_scene))
- end # - End create_command_window
- #--------------------------------------------------------------------------
- # * Create Skill Window
- #--------------------------------------------------------------------------
- def create_skill_window
- wx = @command_window.width
- wy = @category_window.y + @category_window.height
- ww = Graphics.width - @command_window.width
- wh = Graphics.height - wy
- @skill_window = Window_HotkeySkillList.new(wx, wy, ww, wh)
- @skill_window.actor = @actor
- @skill_window.viewport = @viewport
- @skill_window.help_window = @help_window
- @skill_window.set_handler(:ok, method(:on_skill_ok))
- @skill_window.set_handler(:cancel, method(:on_item_cancel))
- end # - End create_skill_window
- #--------------------------------------------------------------------------
- # * Create Item Window
- #--------------------------------------------------------------------------
- def create_item_window
- wy = @category_window.y + @category_window.height
- wh = Graphics.height - wy
- ww = Graphics.width-@command_window.width
- @item_window = Window_HotkeyItem.new(@command_window.width, wy, ww, wh)
- @item_window.viewport = @viewport
- @item_window.help_window = @help_window
- @item_window.set_handler(:ok, method(:on_item_ok))
- @item_window.set_handler(:cancel, method(:on_item_cancel))
- @category_window.item_window = @item_window
- end # - End create_item_window
- def create_hkey_on_off_window
- wy = @category_window.y + @category_window.height
- wh = Graphics.height - wy
- ww = Graphics.width-@command_window.width
- @hkey_on_off_window = Window_HkeyOnOff.new(@command_window.width, wy,ww,wh)
- @hkey_on_off_window.viewport = @viewport
- @hkey_on_off_window.set_handler(:ok, method(:on_off_ok))
- @hkey_on_off_window.set_handler(:cancel, method(:on_item_cancel))
- end
- #def item_usable?
- # $hkey_user.usable?($hkey_item) && item_effects_valid?
- #end
- #--------------------------------------------------------------------------
- # * Create Category Window
- #--------------------------------------------------------------------------
- def create_category_window
- x = @command_window.width
- y = @help_window.height
- width = Graphics.width - @command_window.width
- @category_window = Window_HotkeyCategory.new(x,y, width)
- @category_window.viewport = @viewport
- @category_window.help_window = @help_window
- @category_window.y = @help_window.height
- @category_window.set_handler(:ok, method(:on_category_ok))
- @category_window.set_handler(:cancel, method(:on_hotkey_cancel))
- end # - End create_category_window
- #--------------------------------------------------------------------------
- # * Create Dummy Window
- # * This window is used just for looks, it sits in the background
- #--------------------------------------------------------------------------
- def create_dummy_window
- wy = @category_window.y + @category_window.height
- wh = Graphics.height - wy
- ww = Graphics.width - @command_window.width
- @dummy_window = Window_Base.new(@command_window.width, wy, ww, wh)
- @dummy_window.viewport = @viewport
- end # - End create_dummy_window
- #--------------------------------------------------------------------------
- # * Get the user this hotkey is associated with
- #--------------------------------------------------------------------------
- #def user
- # @actor
- #end
- #--------------------------------------------------------------------------
- # * Category [OK]
- #--------------------------------------------------------------------------
- def on_category_ok
- @dummy_window.hide
- if @category_window.index == 0 #category item
- @item_window.activate
- @item_window.select_last
- @skill_window.hide
- @hkey_on_off_window.hide
- @item_window.show
- @skill_window.refresh
- @item_window.refresh
- elsif @category_window.index == 1 #category skill
- @skill_window.activate
- @skill_window.select_last
- @skill_window.show
- @item_window.hide
- @hkey_on_off_window.hide
- @skill_window.refresh
- @item_window.refresh
- elsif @category_window.index == 2 # action bar on/off
- @hkey_on_off_window.activate
- @hkey_on_off_window.select(0)
- @hkey_on_off_window.show
- @hkey_on_off_window.refresh
- @item_window.hide
- @skill_window.hide
- else #category clear
- @dummy_window.show
- Game_Map.game_hotkeys[Window_HotkeyCommand.last_command_symbol] = nil
- sym = @command_window.current_symbol
- $hotkey_data[sym] = nil
- update_command_window_text(sym, nil)
- @category_window.refresh
- @category_window.activate
- end
- end # - End on_category_ok
- #--------------------------------------------------------------------------
- # * Item [OK]
- #--------------------------------------------------------------------------
- def on_item_ok
- new_hotkey(@item_window)
- end # - End on_item_ok
- #--------------------------------------------------------------------------
- # * Skill [OK]
- #--------------------------------------------------------------------------
- def on_skill_ok
- new_hotkey(@skill_window)
- end # - End on_skill_ok
- #--------------------------------------------------------------------------
- # * Action bar on/off category
- #--------------------------------------------------------------------------
- def on_off_ok
- add_on_off_hkey
- @command_window.activate
- end
- def add_on_off_hkey
- sym = @command_window.current_symbol
- $hotkey_data[sym] = :action_bar_on_off
- update_command_window_text(sym, :action_bar_on_off)
- end
- #--------------------------------------------------------------------------
- # * Update $hotkey_data with the new hotkey.
- #--------------------------------------------------------------------------
- def new_hotkey(window)
- $game_party.last_item.object = item
- Game_Map.game_hotkeys[Window_HotkeyCommand.last_command_symbol] = [@actor, (item = window.item), window.item.is_a?(RPG::Skill) ? :skill : :item]
- sym = @command_window.current_symbol
- $hotkey_data[sym] = item.icon_index
- update_command_window_text(sym, item)
- @command_window.activate
- end # - End new_hotkey
- def update_command_window_text(sym, item)
- colon = get_colon(sym)
- name = !item ? "" : nil
- name = (item &&!item.is_a?(RPG::UsableItem)) ? "->On/Off" : ("->" + item.name) if name.nil?
- @command_window.change_command_name(@command_window.index, sym, colon+sym.to_s + name)
- @command_window.refresh
- end
- def get_colon(sym)
- colon = ":"
- case sym.to_s
- when "F5"
- colon = ""
- when "F6"
- colon = ""
- when "F7"
- colon = ""
- when "F8"
- colon = ""
- end
- return colon
- end
- #--------------------------------------------------------------------------
- # * Item [Cancel]
- #--------------------------------------------------------------------------
- def on_item_cancel
- @item_window.hide
- @skill_window.hide
- @hkey_on_off_window.hide
- @dummy_window.show
- @category_window.activate
- end # - End on_item_cancel
- #--------------------------------------------------------------------------
- # * Play SE When Using Item
- #--------------------------------------------------------------------------
- def play_se_for_item
- Sound.play_use_item
- end
- #--------------------------------------------------------------------------
- # * Cancels selection on the category window and moves back to the command
- # window.
- #--------------------------------------------------------------------------
- def on_hotkey_cancel
- @command_window.activate
- @category_window.unselect
- end # - End on_hotkey_cancel
- #--------------------------------------------------------------------------
- # * Handles processing after a hotkey has been selected from the command
- # window.
- #--------------------------------------------------------------------------
- def on_hotkey_select
- @category_window.activate
- @category_window.select(0)
- end
- end # - End Scene_Hotkey
- #=================================END OF FILE===================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement