Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================================
- # - Eshra HOT KEYS -
- #===============================================================
- # To use this script, insert it as new script in the script editor under
- # the materials section.
- # 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.
- # Aliased Methods:
- # Scene_Map:
- # update
- # Scene_Map
- # update
- # Window_MenuCommand
- # add_original_commands
- # Scene_Menu
- # create_command_window
- # on_personal_ok
- # 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
- # Skill/Item cooldowns. While thae cooldown timer is greater than 0 they cannot
- # be used.
- $imported = {} if $imported.nil?
- $imported["Eshra-SCENE_MAP_COOLDOWNS"] = true
- module COOLDOWNS
- module USE_FAILED
- SOUND = 3 # Default Buzzer
- end
- module REGEXP
- TAG = /<!cooldown (\d+)>/i
- GLOBAL = /<!global cool (\d+)>/i
- end
- end
- module DURATION
- module REGEXP
- TAG = /<!duration (\d+)>/i
- end
- module NAME
- TAG = /<!ts-name = (\w+)(?:\s|)\[T(\d+)\]>/i
- end
- end
- module DataManager
- #--------------------------------------------------------------------------
- # alias method: load_database
- #--------------------------------------------------------------------------
- class <<self; alias load_dtbase_mp_cd_ntags load_database; end
- def self.load_database
- load_dtbase_mp_cd_ntags
- load_map_cd_notetags
- end
- #--------------------------------------------------------------------------
- # new method: load_notetags_abe
- #--------------------------------------------------------------------------
- def self.load_map_cd_notetags
- groups = [$data_armors, $data_weapons, $data_items, $data_skills]
- for group in groups
- for obj in group
- next if obj.nil?
- obj.load_sc_map_cd_notetags
- end
- end
- end
- end # DataManager
- class RPG::UsableItem < RPG::BaseItem
- attr_accessor :cooldown_timer
- attr_accessor :base_cooldown
- attr_accessor :duration_timer
- attr_accessor :base_duration
- attr_accessor :global_cooldown
- def load_sc_map_cd_notetags
- @cooldown_timer = 0
- @base_cooldown = 0
- @duration_timer = 0
- @base_duration = 0
- @global_cooldown = 0
- self.note.split(/[\r\n]+/).each { |line|
- next unless line != nil
- case line
- when COOLDOWNS::REGEXP::TAG
- @base_cooldown = $1.to_i
- when DURATION::REGEXP::TAG
- @base_duration = $1.to_i
- when COOLDOWNS::REGEXP::GLOBAL
- @global_cooldown = $1.to_i
- print "loaded global cool = #{@global_cooldown}\n"
- end # End - case line
- } # End - self.note.split
- end # End - load_sc_map_cd_notetagss
- end # End - RPG::UsableItem
- #
- # RPG::BaseItem - Add an accessor for name
- #
- class RPG::BaseItem
- attr_accessor :name
- end
- class RPG::EquipItem < RPG::BaseItem
- attr_accessor :cooldown_timer
- attr_accessor :base_cooldown
- attr_accessor :duration_timer
- attr_accessor :base_duration
- attr_accessor :global_cooldown
- def load_sc_map_cd_notetags
- @cooldown_timer = 0
- @base_cooldown = 0
- @duration_timer = 0
- @base_duration = 0
- @global_cooldown = 0
- self.note.split(/[\r\n]+/).each { |line|
- next unless line != nil
- case line
- when COOLDOWNS::REGEXP::TAG
- @base_cooldown = $1.to_i
- when DURATION::REGEXP::TAG
- @base_duration = $1.to_i
- when COOLDOWNS::REGEXP::GLOBAL
- @global_cooldown = $1.to_i
- end # End - case line
- } # End - self.note.split
- end # End - load_sc_map_cd_notetagss
- end # End - RPG::EquipItem
- class Game_Map
- attr_accessor :cooldown_queue # Items on cd are placed here
- attr_accessor :duration_queue # Items that last over time are place here
- attr_accessor :global_cooldown
- attr_accessor :global_cooldown_base
- #
- # ** Alias method initialize
- #
- alias gme_map_cool_down_ch_initialize initialize
- def initialize
- gme_map_cool_down_ch_initialize
- @cooldown_queue = []
- @duration_queue = []
- @global_cooldown = 0
- end # End - initialize
- #
- # ** Alias method update
- #
- alias gme_map_cool_down_ch_update_9817 update
- def update(*arg)
- gme_map_cool_down_ch_update_9817(*arg)
- @global_cooldown -= 1 if @global_cooldown > 0
- print "global_cooldown remaining: #{global_cooldown}\n"
- print "cooldown_queue = #{@cooldown_queue.inspect}\n"
- @cooldown_queue.each{ |item|
- item.cooldown_timer-=1
- print "cooldown left on #{item}: #{item.cooldown_timer}\n"
- if(item.cooldown_timer <= 0)
- @cooldown_queue.delete(item)
- end
- } # End - @cooldown_queue.each
- @duration_queue.each{ |item|
- item.duration_timer-=1
- print "duration left on #{item}: #{item.duration_timer}\n"
- if(item.duration_timer <= 0)
- @duration_queue.delete(item)
- end
- } # End - @duration_queue.each
- end # End - update
- # Store all the cooldown data for the item.
- def init_cooldown_timers(item)
- item.cooldown_timer = item.base_cooldown
- item.duration_timer = item.base_duration
- print "init cooldown_timer, item gcd = #{item.global_cooldown}\n"
- if @global_cooldown < item.global_cooldown
- @global_cooldown = item.global_cooldown
- @global_cooldown_base = item.global_cooldown
- end
- @cooldown_queue.push(item) unless @cooldown_queue.include?(item)
- @duration_queue.push(item) unless @duration_queue.include?(item)
- end
- def game_timer_skills
- @@game_timer_skills
- end
- # Check if there is a global cooldown
- def all_cd?
- print "on gcd = ", @global_cooldown > 0, "\n"
- return @global_cooldown > 0
- end
- def gcd_val(mod = 0)
- @global_cooldown + mod
- end
- def gcd_base(mod = 0)
- @global_cooldown_base + mod
- end
- end # End - Scene_Map
- #
- # ** Aliased use_item methods in various classes: **
- #
- class Scene_ItemBase < Scene_MenuBase
- alias item_usable_check_for_cd_4289_use_item use_item
- def use_item
- if item.cooldown_timer > 0 || $game_map.all_cd?
- Sound.play_system_sound(COOLDOWNS::USE_FAILED::SOUND)
- return
- end
- print "on global cooldown? #{$game_map.all_cd?}\n"
- item_usable_check_for_cd_4289_use_item
- $game_map.init_cooldown_timers(item)
- end # End - use_item
- end # End - Scene_ItemBase
- #class Scene_Battle < Scene_Base
- # alias item_usable_check_for_cd_4288_use_item use_item
- # def use_item
- # if item.cooldown_timer != 0 && item.cooldown_timer != nil && $game_map.all_cd?
- # Sound.play_system_sound(COOLDOWNS::USE_FAILED::SOUND)
- # return
- # item_usable_check_for_cd_4288_use_item
- # $game_map.init_cooldown_timers(item)
- # end # End - use_item
- #end # End - Scene_Battle
- #class Scene_Item < Scene_ItemBase
- # alias item_usable_check_for_cd_4287_use_item use_item
- # def use_item
- # if item.cooldown_timer != 0 && item.cooldown_timer != nil && $game_map.all_cd?
- # Sound.play_system_sound(COOLDOWNS::USE_FAILED::SOUND)
- # return
- # end
- # item_usable_check_for_cd_4287_use_item
- # $game_map.init_cooldown_timers(item)
- # end # End - use_item
- #end # End - Scene_Item
- #class Scene_Skill < Scene_ItemBase
- # alias item_usable_check_for_cd_4286_use_item use_item
- # def use_item
- # if item.cooldown_timer != 0 && item.cooldown_timer != nil && $game_map.all_cd?
- # Sound.play_system_sound(COOLDOWNS::USE_FAILED::SOUND)
- # return
- # end
- # item_usable_check_for_cd_4286_use_item
- # $game_map.init_cooldown_timers(item)
- # end # End - use_item
- #end # End - Scene_Skill
- class Game_Battler < Game_BattlerBase
- alias item_usable_check_for_cd_4285_use_item use_item
- def use_item(item)
- print "cooldown_timer: #{item.cooldown_timer}"
- if item.cooldown_timer > 0 || $game_map.all_cd?
- Sound.play_system_sound(COOLDOWNS::USE_FAILED::SOUND)
- return
- end
- item_usable_check_for_cd_4285_use_item(item)
- $game_map.init_cooldown_timers(item)
- end # End - use_item
- end # End - Game_Battler
- #===============================================================
- # 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
- #===============================================================
- # 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
- 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
- if HOTKEY::ACTIONBAR::VISIBLE
- if @actionbar == nil || @actionbar.disposed?
- create_actionbar
- end # - End actionbar check
- @actionbar.update unless @actionbar.disposed?
- end
- end
- def update_cool_downs
- return unless $imported["Eshra-SCENE_MAP_COOLDOWNS"]
- if HOTKEY::ACTIONBAR::VISIBLE && 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|
- # sym = HOTKEY::ACTIONBAR::ORDER[key]
- # ind = $hotkey_data[sym]
- # 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)
- #}
- #window.draw_text(0,0,width,22,"Cool Downs")
- (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
- if item == nil
- #print "item was nil\n"
- end
- next if item == nil
- #print "~~~~~~~~~~~~~~~~~~~~~item wasn't nil\n~~~~~~~~~~~~~~~~~~~~~~~\n"
- 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
- print "item.cooldown_timer = #{item.cooldown_timer}\n"
- print "item.base_cooldown = #{item.base_cooldown}\n"
- if used_cd_base <= 0
- used_cd_base = 1
- end
- bar_length = used_cd * (width/max) / used_cd_base
- print "used_cd_base = #{used_cd_base}\n"
- print "used_cd= #{used_cd}\n"
- print "((key)*width/max) = #{(width/max)}\n"
- print "bar_length = #{bar_length}\n"
- 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
- #window.draw_gauge(0,0,500,165,HOTKEY::COOLDOWN_GAUGE::COLOR1,HOTKEY::COOLDOWN_GAUGE::COLOR2)
- }
- #window.draw_gauge(0,0,500,165,HOTKEY::COOLDOWN_GAUGE::COLOR1,HOTKEY::COOLDOWN_GAUGE::COLOR2)
- #window.draw_gauge(0,0,500,165,Color.new(120, 80, 0, 100),Color.new(200, 150, 0, 100))
- 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]
- 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)
- }
- end # - End draw_actionbar_contents
- def evalute_hotkey(symbol)
- return if !(hkey = Game_Map.game_hotkeys[symbol])
- $hkey_item = item = hkey[1]
- $hkey_user = actor = hkey[0]
- return if item == nil || actor == nil
- actor.use_item(item)
- use_item_to_actors if item.for_friend?
- check_gameover
- Sound.play_use_item
- 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 == nil
- array.each do |target|
- 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 usable
- #--------------------------------------------------------------------------
- #def item_usable?
- # $hkey_user.usable?($hkey_item) && item_effects_valid?
- #end # - End item_usable?
- #--------------------------------------------------------------------------
- # * 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
- #add_game_end_command #I commented out this line (I added this code)
- end
- alias hotkey_add_orig_com_alias_9089 add_original_commands
- def add_original_commands
- hotkey_add_orig_com_alias_9089
- add_command("Hot Keys", :hotkey, true)
- 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 3
- 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("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) }
- @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
- #==============================================================================
- # ** 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
- @skill_window.hide
- @item_window.hide
- @category_window.unselect
- @category_window.deactivate
- 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_ItemList.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 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
- @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
- @skill_window.refresh
- @item_window.refresh
- 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
- update_hotkey(@item_window)
- end # - End on_item_ok
- #--------------------------------------------------------------------------
- # * Skill [OK]
- #--------------------------------------------------------------------------
- def on_skill_ok
- update_hotkey(@skill_window)
- end # - End on_skill_ok
- #--------------------------------------------------------------------------
- # * Update $hotkey_data with the new hotkey.
- #--------------------------------------------------------------------------
- def update_hotkey(window)
- $game_party.last_item.object = item
- Game_Map.game_hotkeys[Window_HotkeyCommand.last_command_symbol] = [@actor, (item = window.item)]
- sym = @command_window.current_symbol
- $hotkey_data[sym] = item.icon_index
- update_command_window_text(sym, item)
- @command_window.activate
- end # - End update_hotkey
- def update_command_window_text(sym, item)
- colon = get_colon(sym)
- name = (!item) ? "" : ("->" + item.name)
- @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
- @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