Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # Hotkeys v2.0
- # Author Eshra
- # First Version Finished 10 Aug 2015
- #------------------------------------------------------------------------------
- #
- # Usage:
- #
- # Requires Era Module v0.2 available at
- # https://rascripts.wordpress.com/2015/08/10/era-module-v0-2/
- #
- # Install by copying and pasting this script under the "Materials" Section of the
- # Script Editor below 'Era Module'.
- #
- # Adds an option for setting hotkeys to the main menu. Hotkeys allow items and
- # skills to be used while on the map. The hotkeys you've set are displayed on
- # an action bar. The action bar can be hidden from the new "options" menu.
- #
- # Important notes:
- # Items that are set to hotkeys must NOT be set as 'only usable in battle' if
- # you intend to use a hotkey with that item.
- #
- # The required extended Input module (by by Cidiomar R Dias Jr) is included
- # below. No additional setup is necessary.
- #------------------------------------------------------------------------------
- #==============================================================================
- #------------------------------------------------------------------------------
- # ** Input
- #------------------------------------------------------------------------------
- # Created By Cidiomar R. Dias JĂșnior
- # Originally posted at http://rgss3help.cidiomar.com/?p=145
- #
- # Terms of Use: http://rgss3help.cidiomar.com/?page_id=159
- #------------------------------------------------------------------------------
- # A module that handles input data from a gamepad or keyboard.
- # Managed by symbols rather than button numbers in RGSS3.
- #==============================================================================
- module Input
- #--------------------------------------------------------------------------
- # * Keymap in symbols
- # To get a key from the keymap, you can use Input.key(sym) or Input:KEYMAP[sym]
- # Or if you want to use a symbol in a input function, just pass the symbol
- # as argument.
- #--------------------------------------------------------------------------
- KEYMAP = {
- LBUTTON: 0x01, RBUTTON: 0x02,
- CANCEL: 0x03, MBUTTON: 0x04,
- XBUTTON1: 0x05, XBUTTON2: 0x06,
- BACK: 0x08, TAB: 0x09,
- CLEAR: 0x0c, RETURN: 0x0d,
- SHIFT: 0x10, CONTROL: 0x11,
- MENU: 0x12, PAUSE: 0x13,
- CAPITAL: 0x14, KANA: 0x15,
- KANA: 0x15, KANA: 0x15,
- JUNJA: 0x17, FINAL: 0x18,
- HANJA: 0x19, HANJA: 0x19,
- ESCAPE: 0x1b, CONVERT: 0x1c,
- NONCONVERT: 0x1d, ACCEPT: 0x1e,
- MODECHANGE: 0x1f, SPACE: 0x20,
- PRIOR: 0x21, NEXT: 0x22,
- END: 0x23, HOME: 0x24,
- LEFT: 0x25, UP: 0x26,
- RIGHT: 0x27, DOWN: 0x28,
- SELECT: 0x29, PRINT: 0x2a,
- EXECUTE: 0x2b, SNAPSHOT: 0x2c,
- INSERT: 0x2d, DELETE: 0x2e,
- HELP: 0x2f, N0: 0x30,
- KEY_1: 0x31, KEY_2: 0x32,
- KEY_3: 0x33, KEY_4: 0x34,
- KEY_5: 0x35, KEY_6: 0x36,
- KEY_7: 0x37, KEY_8: 0x38,
- KEY_9: 0x39, colon: 0x3a,
- semicolon: 0x3b, less: 0x3c,
- equal: 0x3d, greater: 0x3e,
- question: 0x3f, at: 0x40,
- LETTER_A: 0x41, LETTER_B: 0x42,
- LETTER_C: 0x43, LETTER_D: 0x44,
- LETTER_E: 0x45, LETTER_F: 0x46,
- LETTER_G: 0x47, LETTER_H: 0x48,
- LETTER_I: 0x49, LETTER_J: 0x4a,
- LETTER_K: 0x4b, LETTER_L: 0x4c,
- LETTER_M: 0x4d, LETTER_N: 0x4e,
- LETTER_O: 0x4f, LETTER_P: 0x50,
- LETTER_Q: 0x51, LETTER_R: 0x52,
- LETTER_S: 0x53, LETTER_T: 0x54,
- LETTER_U: 0x55, LETTER_V: 0x56,
- LETTER_W: 0x57, LETTER_X: 0x58,
- LETTER_Y: 0x59, LETTER_Z: 0x5a,
- LWIN: 0x5b, RWIN: 0x5c,
- APPS: 0x5d, asciicircum: 0x5e,
- SLEEP: 0x5f, NUMPAD0: 0x60,
- NUMPAD1: 0x61, NUMPAD2: 0x62,
- NUMPAD3: 0x63, NUMPAD4: 0x64,
- NUMPAD5: 0x65, NUMPAD6: 0x66,
- NUMPAD7: 0x67, NUMPAD8: 0x68,
- NUMPAD9: 0x69, MULTIPLY: 0x6a,
- ADD: 0x6b, SEPARATOR: 0x6c,
- SUBTRACT: 0x6d, DECIMAL: 0x6e,
- DIVIDE: 0x6f, F1: 0x70,
- F2: 0x71, F3: 0x72,
- F4: 0x73, F5: 0x74,
- F6: 0x75, F7: 0x76,
- F8: 0x77, F9: 0x78,
- F10: 0x79, F11: 0x7a,
- F12: 0x7b, F13: 0x7c,
- F14: 0x7d, F15: 0x7e,
- F16: 0x7f, F17: 0x80,
- F18: 0x81, F19: 0x82,
- F20: 0x83, F21: 0x84,
- F22: 0x85, F23: 0x86,
- F24: 0x87, NUMLOCK: 0x90,
- SCROLL: 0x91, LSHIFT: 0xa0,
- RSHIFT: 0xa1, LCONTROL: 0xa2,
- RCONTROL: 0xa3, LMENU: 0xa4,
- RMENU: 0xa5, BROWSER_BACK: 0xa6,
- BROWSER_FORWARD: 0xa7, BROWSER_REFRESH: 0xa8,
- BROWSER_STOP: 0xa9, BROWSER_SEARCH: 0xaa,
- BROWSER_FAVORITES: 0xab, BROWSER_HOME: 0xac,
- VOLUME_MUTE: 0xad, VOLUME_DOWN: 0xae,
- VOLUME_UP: 0xaf, MEDIA_NEXT_TRACK: 0xb0,
- MEDIA_PREV_TRACK: 0xb1, MEDIA_STOP: 0xb2,
- MEDIA_PLAY_PAUSE: 0xb3, LAUNCH_MAIL: 0xb4,
- LAUNCH_MEDIA_SELECT: 0xb5, LAUNCH_APP1: 0xb6,
- LAUNCH_APP2: 0xb7, cedilla: 0xb8,
- onesuperior: 0xb9, masculine: 0xba,
- guillemotright: 0xbb, onequarter: 0xbc,
- onehalf: 0xbd, threequarters: 0xbe,
- questiondown: 0xbf, Agrave: 0xc0,
- Aacute: 0xc1, Acircumflex: 0xc2,
- Atilde: 0xc3, Adiaeresis: 0xc4,
- Aring: 0xc5, AE: 0xc6,
- Ccedilla: 0xc7, Egrave: 0xc8,
- Eacute: 0xc9, Ecircumflex: 0xca,
- Ediaeresis: 0xcb, Igrave: 0xcc,
- Iacute: 0xcd, Icircumflex: 0xce,
- Idiaeresis: 0xcf, ETH: 0xd0,
- Ntilde: 0xd1, Ograve: 0xd2,
- Oacute: 0xd3, Ocircumflex: 0xd4,
- Otilde: 0xd5, Odiaeresis: 0xd6,
- multiply: 0xd7, Oslash: 0xd8,
- Ugrave: 0xd9, Uacute: 0xda,
- Ucircumflex: 0xdb, Udiaeresis: 0xdc,
- Yacute: 0xdd, THORN: 0xde,
- ssharp: 0xdf, agrave: 0xe0,
- aacute: 0xe1, acircumflex: 0xe2,
- atilde: 0xe3, adiaeresis: 0xe4,
- PROCESSKEY: 0xe5, ae: 0xe6,
- PACKET: 0xe7, egrave: 0xe8,
- eacute: 0xe9, ecircumflex: 0xea,
- ediaeresis: 0xeb, igrave: 0xec,
- iacute: 0xed, icircumflex: 0xee,
- idiaeresis: 0xef, eth: 0xf0,
- ntilde: 0xf1, ograve: 0xf2,
- oacute: 0xf3, ocircumflex: 0xf4,
- otilde: 0xf5, ATTN: 0xf6,
- CRSEL: 0xf7, EXSEL: 0xf8,
- EREOF: 0xf9, PLAY: 0xfa,
- ZOOM: 0xfb, NONAME: 0xfc,
- PA1: 0xfd, thorn: 0xfe,
- ydiaeresis: 0xff
- }
- KEYMAP[:WIN] = [KEYMAP[:LWIN], KEYMAP[:RWIN]]
- #--------------------------------------------------------------------------
- # * Default Keys, you can configure here instead of by pressing F1.
- #--------------------------------------------------------------------------
- #UP = [KEYMAP[:UP]]
- #DOWN = [KEYMAP[:DOWN]]
- #LEFT = [KEYMAP[:LEFT]]
- #RIGHT = [KEYMAP[:RIGHT]]
- #A = [KEYMAP[:SHIFT]]
- #B = [KEYMAP[:LETTER_X]]
- #C = [KEYMAP[:LETTER_Z]]
- #X = [KEYMAP[:LETTER_B]]
- #Y = []
- #Z = []
- #L = [KEYMAP[:PRIOR]]
- #R = [KEYMAP[:NEXT]]
- #F5 = [KEYMAP[:F5]]
- #F6 = [KEYMAP[:F6]]
- #F7 = [KEYMAP[:F7]]
- #F8 = [KEYMAP[:F8]]
- #F9 = [KEYMAP[:F9]]
- #SHIFT = [KEYMAP[:SHIFT]]
- #CTRL = [KEYMAP[:CONTROL]]
- #ALT = [KEYMAP[:MENU]]
- #I = [KEYMAP[:LETTER_I]]
- #E = [KEYMAP[:LETTER_E]]
- #S = [KEYMAP[:LETTER_S]]
- #T = [KEYMAP[:LETTER_T]]
- UP = [KEYMAP[:UP]]
- DOWN = [KEYMAP[:DOWN]]
- LEFT = [KEYMAP[:LEFT]]
- RIGHT = [KEYMAP[:RIGHT]]
- A = [KEYMAP[:SHIFT]]
- B = [KEYMAP[:LETTER_X]]
- C = [KEYMAP[:LETTER_Z]]
- X = [KEYMAP[:LETTER_B]]
- Y = []
- Z = []
- L = [KEYMAP[:PRIOR]]
- R = [KEYMAP[:NEXT]]
- F5 = [KEYMAP[:F5]]
- F6 = [KEYMAP[:F6]]
- F7 = [KEYMAP[:F7]]
- F8 = [KEYMAP[:F8]]
- F9 = [KEYMAP[:F9]]
- SHIFT = [KEYMAP[:SHIFT]]
- CTRL = [KEYMAP[:CONTROL]]
- ALT = [KEYMAP[:MENU]]
- I = [KEYMAP[:LETTER_I]]
- E = [KEYMAP[:LETTER_E]]
- S = [KEYMAP[:LETTER_S]]
- T = [KEYMAP[:LETTER_T]]
- #--------------------------------------------------------------------------
- # * Symbol version of default keys.
- #--------------------------------------------------------------------------
- SYM_KEYS = {
- :UP => UP,
- :LEFT => LEFT,
- :DOWN => DOWN,
- :RIGHT => RIGHT,
- :A => A,
- :B => B,
- :C => C,
- :X => X,
- :Y => Y,
- :Z => Z,
- :L => L,
- :R => R,
- :F5 => F5,
- :F6 => F6,
- :F7 => F7,
- :F8 => F8,
- :F9 => F9,
- :SHIFT => SHIFT,
- :CTRL => CTRL,
- :ALT => ALT,
- :I => I,
- :E => E,
- :S => S,
- :T => T
- }
- #--------------------------------------------------------------------------
- # * Key Codes Used in Events Conditional Branchs
- #--------------------------------------------------------------------------
- EventsKeyCodes = {
- 2 => :DOWN,
- 4 => :LEFT,
- 6 => :RIGHT,
- 8 => :UP,
- 11 => :A,
- 12 => :B,
- 13 => :C,
- 14 => :X,
- 15 => :Y,
- 16 => :Z,
- 17 => :L,
- 18 => :R
- }
- #--------------------------------------------------------------------------
- # * Internal APIs to handle keyboard functions
- #--------------------------------------------------------------------------
- GetKeyboardState = Win32API.new('user32.dll', 'GetKeyboardState', 'I', 'I')
- MapVirtualKeyEx = Win32API.new('user32.dll', 'MapVirtualKeyEx', 'IIL', 'I')
- ToUnicodeEx = Win32API.new('user32.dll', 'ToUnicodeEx', 'LLPPILL', 'L')
- #----------
- @language_layout = Win32API.new('user32.dll', 'GetKeyboardLayout', 'L', 'L').call(0)
- DOWN_STATE_MASK = (0x8 << 0x04)
- DEAD_KEY_MASK = (0x8 << 0x1C)
- #-----
- UNICODE_TO_UTF8 = Encoding::Converter.new(Encoding.list[2], Encoding.list[1])
- #--------------------------------------------------------------------------
- # * States of keys
- #--------------------------------------------------------------------------
- @state = DL::CPtr.new(DL.malloc(256), 256)
- @triggered = Array.new(256, false)
- @pressed = Array.new(256, false)
- @released = Array.new(256, false)
- @repeated = Array.new(256, 0)
- #--------------------------------------------------------------------------
- # * Singleton attrs of states
- #--------------------------------------------------------------------------
- class << self
- attr_reader :triggered, :pressed, :released, :repeated, :state
- end
- #--------------------------------------------------------------------------
- # * Get a key code by simbol
- #--------------------------------------------------------------------------
- def self.key(sym)
- KEYMAP[sym] || 0
- end
- #--------------------------------------------------------------------------
- # * Updates input data.
- # As a general rule, this method is called once per frame.
- #--------------------------------------------------------------------------
- def self.update
- GetKeyboardState.call(@state.to_i)
- #-----
- 0.upto(255) do |key|
- if @state[key] & DOWN_STATE_MASK == DOWN_STATE_MASK
- @released[key] = false
- @pressed[key] = true if (@triggered[key] = !@pressed[key])
- @repeated[key] < 17 ? @repeated[key] += 1 : @repeated[key] = 15
- elsif !@released[key] and @pressed[key]
- @triggered[key] = false
- @pressed[key] = false
- @repeated[key] = 0
- @released[key] = true
- else
- @released[key] = false
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Checks the status of the directional buttons, translates the data into
- # a specialized 4-direction input format, and returns the number pad
- # equivalent (2, 4, 6, 8).
- #
- # If no directional buttons are being pressed (or the equivalent), returns 0.
- #--------------------------------------------------------------------------
- def self.dir4
- return 2 if self.press?(DOWN)
- return 4 if self.press?(LEFT)
- return 6 if self.press?(RIGHT)
- return 8 if self.press?(UP)
- return 0
- end
- #--------------------------------------------------------------------------
- # * Checks the status of the directional buttons, translates the data into
- # a specialized 8-direction input format, and returns the number pad
- # equivalent (1, 2, 3, 4, 6, 7, 8, 9).
- #
- #If no directional buttons are being pressed (or the equivalent), returns 0.
- #--------------------------------------------------------------------------
- def self.dir8
- down = self.press?(DOWN)
- left = self.press?(LEFT)
- return 1 if down and left
- right = self.press?(RIGHT)
- return 3 if down and right
- up = self.press?(UP)
- return 7 if up and left
- return 9 if up and right
- return 2 if down
- return 4 if left
- return 6 if right
- return 8 if up
- return 0
- end
- #--------------------------------------------------------------------------
- # * Determines whether the button corresponding to the symbol sym is
- # currently being pressed.
- #
- # If the button is being pressed, returns TRUE. If not, returns FALSE.
- #
- # if Input.press?(:C)
- # do_something
- # end
- #--------------------------------------------------------------------------
- def self.press?(keys)
- if keys.is_a?(Numeric)
- k = keys.to_i
- return (@pressed[k] and !@triggered[k])
- elsif keys.is_a?(Array)
- return keys.any? {|key| self.press?(key) }
- elsif keys.is_a?(Symbol)
- if SYM_KEYS.key?(keys)
- return SYM_KEYS[keys].any? {|key| (@pressed[key] and !@triggered[key]) }
- elsif (KEYMAP.key?(keys))
- k = KEYMAP[keys]
- return (@pressed[k] and !@triggered[k])
- else
- return false
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Determines whether the button corresponding to the symbol sym is
- # currently being pressed again.
- # "Pressed again" is seen as time having passed between the button being
- # not pressed and being pressed.
- #
- # If the button is being pressed, returns TRUE. If not, returns FALSE.
- #--------------------------------------------------------------------------
- def self.trigger?(keys)
- if keys.is_a?(Numeric)
- return @triggered[keys.to_i]
- elsif keys.is_a?(Array)
- return keys.any? {|key| @triggered[key]}
- elsif keys.is_a?(Symbol)
- if SYM_KEYS.key?(keys)
- return SYM_KEYS[keys].any? {|key| @triggered[key]}
- elsif KEYMAP.key?(keys)
- return @triggered[KEYMAP[keys]]
- else
- return false
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Determines whether the button corresponding to the symbol sym is
- # currently being pressed again.
- # Unlike trigger?, takes into account the repeated input of a button being
- # held down continuously.
- #
- # If the button is being pressed, returns TRUE. If not, returns FALSE.
- #--------------------------------------------------------------------------
- def self.repeat?(keys)
- if keys.is_a?(Numeric)
- key = keys.to_i
- return @repeated[key] == 1 || @repeated[key] == 16
- elsif keys.is_a?(Array)
- return keys.any? {|key| @repeated[key] == 1 || @repeated[key] == 16}
- elsif keys.is_a?(Symbol)
- if SYM_KEYS.key?(keys)
- return SYM_KEYS[keys].any? {|key| @repeated[key] == 1 || @repeated[key] == 16}
- elsif KEYMAP.key?(keys)
- return @repeated[KEYMAP[keys]] == 1 || @repeated[KEYMAP[keys]] == 16
- else
- return false
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Determines whether the button corresponding to the symbol sym
- # was released.
- #
- # If the button was released, returns TRUE. If not, returns FALSE.
- #--------------------------------------------------------------------------
- def self.release?(keys)
- if keys.is_a?(Numeric)
- return @released[keys.to_i]
- elsif keys.is_a?(Array)
- return keys.any? {|key| @released[key]}
- elsif keys.is_a?(Symbol)
- if SYM_KEYS.key?(keys)
- return SYM_KEYS[keys].any? {|key| @released[key]}
- elsif KEYMAP.key?(keys)
- return @released[KEYMAP[keys]]
- else
- return false
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Gets the character that correspond to vk using the keyboard layout
- #--------------------------------------------------------------------------
- def self.get_character(vk)
- c = MapVirtualKeyEx.call(vk, 2, @language_layout)
- return '' if c < 32 && (c & DEAD_KEY_MASK != DEAD_KEY_MASK)
- #-----
- result = "\0" * 2
- length = ToUnicodeEx.call(vk, MapVirtualKeyEx.call(vk, 0, @language_layout),
- @state, result, 2, 0, @language_layout)
- #-----
- return (length == 0 ? '' : result)
- end
- #--------------------------------------------------------------------------
- # * Accents Table, to bo used in conversion from ASCII to UTF8
- #--------------------------------------------------------------------------
- AccentsCharsConv = {
- 'A' => ['Ă', 'Ă', 'Ă', 'Ă', 'Ă'],
- 'E' => ['Ă', 'Ă', 'Ă', 0, 'Ă'],
- 'I' => ['Ă', 'Ă', 'Ă', 0, 'Ă'],
- 'O' => ['Ă', 'Ă', 'Ă', 'Ă', 'Ă'],
- 'U' => ['Ă', 'Ă', 'Ă', 0, 'Ă'],
- 'C' => [ 0 , 'Ă', 0 , 0, 0 ],
- 'N' => [ 0 , 0, 0 , 'Ă', 0 ],
- 'Y' => [ 0 , 'Ă', 0 , 0, 'Ćž'],
- 'a' => ['Ă ', 'ĂĄ', 'Ăą', 'ĂŁ', 'Ă€'],
- 'e' => ['Ăš', 'Ă©', 'ĂȘ', 0 , 'Ă«'],
- 'i' => ['ĂŹ', 'Ă', 'Ăź', 0 , 'ĂŻ'],
- 'o' => ['ĂČ', 'Ăł', 'ĂŽ', 'Ă”', 'ö'],
- 'u' => ['Ăč', 'Ăș', 'Ă»', 0 , 'ĂŒ'],
- 'c' => [ 0 , 'ç', 0 , 0 , 0 ],
- 'n' => [ 0 , 0 , 0 , 'ñ', 0 ],
- 'y' => [ 0 , 'Ăœ', 0 , 0 , 'Ăż'],
- }
- # Letters that can have accent
- PssbLetters = 'AEIOUCNYaeioucny'
- # Accents, in ASCII, configured at runtime to avoid encoding troubles
- Accents = [96.chr, 180.chr, 94.chr, 126.chr, 168.chr].join
- NonCompatChars = [180, 168]
- @last_accent = nil
- #--------------------------------------------------------------------------
- # * Get inputed string transcoded to UTF8
- #--------------------------------------------------------------------------
- def self.UTF8String
- result = ''
- 31.upto(255) {|key|
- if self.repeat?(key)
- c = self.get_character(key)
- if (cc = c.unpack('C')[0]) and NonCompatChars.include?(cc)
- result += cc.chr
- else
- result += UNICODE_TO_UTF8.convert(c) if c != ''
- end
- end
- }
- return '' if result == ''
- #-----
- if @last_accent
- result = @last_accent + result
- @last_accent = nil
- end
- f_result = ''
- jump = false
- for i in 0 ... result.length
- c = result[i]
- if jump
- jump = false
- next
- end
- #-----
- if Accents.include?(c)
- if (nc = result[i+1]) != nil
- if PssbLetters.include?(nc)
- if (ac = AccentsCharsConv[nc][Accents.index(c)]) != 0
- f_result << ac
- jump = true
- else
- f_result << c
- f_result << nc
- jump = true
- end
- elsif Accents.include?(nc)
- f_result << c
- f_result << nc
- jump = true
- else
- f_result << c
- f_result << nc
- jump = true
- end
- else
- @last_accent = c
- end
- else
- f_result << c
- end
- end
- #-----
- return f_result
- end
- #----------
- end
- #
- # Game_Interpreter
- # def command_111 modification to work properly with my Input System
- #
- class Game_Interpreter
- #--------------------------------------------------------------------------
- # * Conditional Branch
- #--------------------------------------------------------------------------
- def command_111
- result = false
- case @params[0]
- when 0 # Switch
- result = ($game_switches[@params[1]] == (@params[2] == 0))
- when 1 # Variable
- value1 = $game_variables[@params[1]]
- if @params[2] == 0
- value2 = @params[3]
- else
- value2 = $game_variables[@params[3]]
- end
- case @params[4]
- when 0 # value1 is equal to value2
- result = (value1 == value2)
- when 1 # value1 is greater than or equal to value2
- result = (value1 >= value2)
- when 2 # value1 is less than or equal to value2
- result = (value1 <= value2)
- when 3 # value1 is greater than value2
- result = (value1 > value2)
- when 4 # value1 is less than value2
- result = (value1 < value2)
- when 5 # value1 is not equal to value2
- result = (value1 != value2)
- end
- when 2 # Self switch
- if @event_id > 0
- key = [@map_id, @event_id, @params[1]]
- result = ($game_self_switches[key] == (@params[2] == 0))
- end
- when 3 # Timer
- if $game_timer.working?
- if @params[2] == 0
- result = ($game_timer.sec >= @params[1])
- else
- result = ($game_timer.sec <= @params[1])
- end
- end
- when 4 # Actor
- actor = $game_actors[@params[1]]
- if actor
- case @params[2]
- when 0 # in party
- result = ($game_party.members.include?(actor))
- when 1 # name
- result = (actor.name == @params[3])
- when 2 # Class
- result = (actor.class_id == @params[3])
- when 3 # Skills
- result = (actor.skill_learn?($data_skills[@params[3]]))
- when 4 # Weapons
- result = (actor.weapons.include?($data_weapons[@params[3]]))
- when 5 # Armors
- result = (actor.armors.include?($data_armors[@params[3]]))
- when 6 # States
- result = (actor.state?(@params[3]))
- end
- end
- when 5 # Enemy
- enemy = $game_troop.members[@params[1]]
- if enemy
- case @params[2]
- when 0 # appear
- result = (enemy.alive?)
- when 1 # state
- result = (enemy.state?(@params[3]))
- end
- end
- when 6 # Character
- character = get_character(@params[1])
- if character
- result = (character.direction == @params[2])
- end
- when 7 # Gold
- case @params[2]
- when 0 # Greater than or equal to
- result = ($game_party.gold >= @params[1])
- when 1 # Less than or equal to
- result = ($game_party.gold <= @params[1])
- when 2 # Less than
- result = ($game_party.gold < @params[1])
- end
- when 8 # Item
- result = $game_party.has_item?($data_items[@params[1]])
- when 9 # Weapon
- result = $game_party.has_item?($data_weapons[@params[1]], @params[2])
- when 10 # Armor
- result = $game_party.has_item?($data_armors[@params[1]], @params[2])
- when 11 # Button
- key = Input::EventsKeyCodes[@params[1]]
- result = Input.press?(key) if key
- when 12 # Script
- result = eval(@params[1])
- when 13 # Vehicle
- result = ($game_player.vehicle == $game_map.vehicles[@params[1]])
- end
- @branch[@indent] = result
- command_skip if !@branch[@indent]
- end
- end
- #==============================================================================
- # Hotkeys v2.0
- #
- # *Usage above
- #------------------------------------------------------------------------------
- raise "requires updated Era module" if ($imported ||= {})["Era Module"] < 0.2
- $imported[:Era_Hotkeys] = 2.0
- class Game_Player < Game_Character
- alias hkey_update_rq update
- def update
- hkey_update_rq
- check_hotkeys
- end
- def check_hotkeys
- $game_system.game_hotkeys.each do |v|
- v.try_skill if Input.trigger?(v.key)
- end
- end
- end
- class Game_System
- def game_hotkeys; era_obj.game_hotkeys; end
- def bind_hotkey(id, sym, usr, ksym)
- game_hotkeys.bind_key(id, sym, usr, ksym)
- end
- def bind_or_remove_hotkey(id, sym, usr, ksym)
- game_hotkeys.bind_or_remove_hotkey(id, sym, usr, ksym)
- end
- end
- class CEra
- alias pub_mems_alias_hkeys init_public_mems
- def init_public_mems(opts = {})
- pub_mems_alias_hkeys(opts)
- init_hkeys
- end
- def init_hkeys; @game_hotkeys = Game_Hotkeys.new; end
- def game_hotkeys; @game_hotkeys; end
- end
- class Game_Hotkeys
- attr_reader :hotkeys
- def initialize
- @hotkeys = {}
- @visible = true
- end
- def bind_or_remove_hotkey(id, sym, usr, ksym)
- fkey = find_hotkey(db_arr(sym)[id])
- if fkey == ksym
- remove_hotkey_h(ksym)#(db_arr(sym)[id])
- else
- bind_key(id, sym, usr, ksym)
- end
- end
- def db_arr(sym); sym == :item ? $data_items : $data_skills; end
- # removes hotkey based on key sym, potentially much faster
- def remove_hotkey_h(ksym); @hotkeys.delete(ksym); end
- # params Example (2,:skill, $game_party.members[0], :Z)
- def bind_key(id, sym, battler, keysym)
- remove_hotkey(db_arr(sym)[id])
- @hotkeys[keysym] = Hotkey_Binding.new(id, sym, battler, keysym)
- end
- def each
- @hotkeys.keys.each{ |k| yield @hotkeys[k] }
- end
- def size
- @hotkeys.keys.size
- end
- # finds associated hotkey for item, returns nil if none found
- def find_hotkey(item)
- sym = item.is_a?(RPG::Skill) ? :skill : :item
- each{|v| return v.key if v.skill_id == item.id && sym == v.item_type_sym}
- nil
- end
- def remove_hotkey(item)
- sym = item.is_a?(RPG::Skill) ? :skill : :item
- @hotkeys.keys.inject(false) do |r,k|
- next unless sym = (v = @hotkeys[k]).item_type_sym
- @hotkeys.delete(k) if (tmp = v.skill_id == item.id)
- r = r || tmp
- end
- end
- def toggle_visibility
- @visible ? @visible = false : @visible = true
- end
- def visible; @visible; end
- end
- class Hotkey_Binding
- attr_reader :user # battler that is using the skill
- attr_reader :key # key to press to activate the skill
- attr_reader :skill_id
- attr_reader :item_type_sym
- def initialize(skill_id, item_type_sym, battler, keysym)
- @user = battler
- @key = keysym
- @skill_id = skill_id
- @item_type_sym = item_type_sym
- end
- def can_use?
- return false if !user.usable?(item)
- return false if item.scope == 11 && !user.item_test(user, item)
- return true
- end
- def try_skill
- (item.scope<=6 || item.scope==11 ? use_skill : friend_selection) if can_use?
- end
- def friend_selection
- SceneManager.call(Scene_HkeyActorSelect)
- scene = SceneManager.scene
- scene.item = item
- scene.item_user = @user
- end
- # Before the item is used need to access:
- # battler.item_test(user, item)
- def use_skill
- Sound.play_use_item
- @user.use_item(item)
- use_item_on_targets
- check_gameover
- end
- def check_gameover
- SceneManager.goto(Scene_Gameover) if $game_party.all_dead?
- end
- def use_item_on_targets
- item_targets.each do |target|
- item.repeats.times { target.item_apply(@user, item) }
- end
- end
- def item
- case @item_type_sym
- when :skill; $data_skills[@skill_id];
- when :item; $data_items[@skill_id];
- end
- end
- def item_targets
- if !item.for_friend?
- []
- elsif item.for_all?
- $game_party.members
- else
- [$game_party.members[0]]
- end
- end
- def actor_win_index
- scene = SceneManager.scene
- scene.is_a?(Scene_Map) ? scene.actor_window_index : -1
- end
- def to_s
- "user #{@user}, #{@item_type_sym.to_s} #{@skill_id}, Key: #{@key}"
- end
- end
- class Scene_HkeyActorSelect < Scene_ItemBase
- def start
- super
- @actor_window.show
- @actor_window.activate
- @actor_window.select_last
- end
- def user; @user; end
- def item_user=(actor); @user = actor; end
- def item; @hkey_item; end
- def item=(itm); @hkey_item = itm; end
- def on_actor_cancel; return_scene; end
- def play_se_for_item; Sound.play_use_item; end
- def on_actor_ok
- if item_usable?
- use_item
- return_scene
- else
- Sound.play_buzzer
- end
- end
- end # Scene_HkeyActorSelect
- class Window_MenuCommand < Window_Command
- alias add_orig_coms_hkeys add_main_commands#add_original_commands
- def add_main_commands#add_original_commands
- add_command("Hotkeys", :hot_keys, main_commands_enabled)
- add_orig_coms_hkeys
- add_command("Options", :hkey_options, main_commands_enabled)
- end
- end
- class Window_HkeyCategory < Window_HorzCommand
- attr_reader :hkeyselect_win
- def initialize(x,y); super(x, y); end
- def window_width; Graphics.width; end
- def col_max; return 2; end
- def update
- super
- @hkeyselect_win.category = current_symbol if @hkeyselect_win
- end
- def make_command_list
- add_command(Vocab::item, :item)
- add_command(Vocab::skill, :skill)
- end
- def hkeyselect_win=(window)
- @hkeyselect_win = window
- update
- end
- end
- # Allows hotkeys to be set
- class Window_HkeySelection < Window_Selectable
- def initialize(x,y,w,h)
- super(x,y,w,h)
- @data = []
- @category = nil
- @last_selection = 0
- end
- def user; $game_party.menu_actor; end
- def deactivate
- @last_selection = @index
- super
- end
- def category=(cat); @category = cat; end
- def select_last
- select(@data.size > @last_selection ? @last_selection || 0 : 0)
- end
- def make_item_list
- case @category
- when :skill
- @data = user ? user.skills : []#.select {|skill| include?(skill) } : []
- when :item
- @data = $game_party.all_items
- end
- end
- def activate
- super
- refresh
- end
- def refresh
- make_item_list
- create_contents
- draw_all_items
- end
- def draw_item(index)
- skill = @data[index]
- if skill
- rect = item_rect(index)
- rect.width -= 4
- draw_item_name(skill, rect.x, rect.y, true)
- end
- end
- def draw_item_name(item, x, y, enabled = true, width = 172)
- return unless item
- draw_icon(item.icon_index, x, y, enabled)
- change_color(normal_color, enabled)
- draw_text(x + 24, y, width, line_height, item.name + " " + hkeystr(item))
- end
- def item_max
- @data ? @data.size : 1
- end
- def col_max
- return 2
- end
- def hkeystr(skill)
- str = $game_system.game_hotkeys.find_hotkey(skill).to_s.gsub(/key_|letter_/i,'')
- (str.eql?("") ? "" : " :" + str)
- end
- def update
- super
- validkeys = Input::KEYMAP
- validkeys.keys.each do |k|
- item = @data[@index]
- next if k == :UP || k==:DOWN || k==:LEFT || k==:RIGHT || !item
- if Input.trigger?(validkeys[k])
- tsym = item.is_a?(RPG::Skill) ? :skill : :item
- $game_system.bind_or_remove_hotkey(item.id, tsym, user, k)#id, sym, usr, ksym
- refresh
- break
- end
- end
- end # update
- end
- class Window_HkeyToggle < Window_Selectable
- def item_max; 1; end
- def draw_item(index)
- r = item_rect(index)
- is_on = $game_system.game_hotkeys.visible
- draw_text(r.x,r.y,145,line_height,"Hotkey Bar: " +
- (is_on ? "On " : "Off"))
- end
- end
- class Scene_Menu < Scene_MenuBase
- alias start_hkey_scm start
- def start
- start_hkey_scm
- create_hkey_toggle_win
- end
- def create_hkey_toggle_win
- @hkey_toggle_window = Window_HkeyToggle.new(
- 0,@command_window.height,@command_window.width,60)
- @hkey_toggle_window.set_handler(:ok, method(:toggle_hkey_visible))
- @hkey_toggle_window.set_handler(:cancel, method(:hkey_toggle_window_hide))
- @hkey_toggle_window.hide
- end
- def toggle_hkey_visible
- $game_system.game_hotkeys.toggle_visibility
- @hkey_toggle_window.refresh
- @hkey_toggle_window.activate
- @hkey_toggle_window.select(0)
- end
- def hkey_toggle_window_hide
- @hkey_toggle_window.deactivate
- @hkey_toggle_window.hide
- @command_window.activate
- end
- alias create_com_win_hkeys create_command_window
- def create_command_window
- create_com_win_hkeys
- @command_window.set_handler(:hot_keys, method(:command_personal))
- @command_window.set_handler(:hkey_options, method(:command_hkey_opts))
- end
- def command_hkey_opts
- @hkey_toggle_window.activate
- @hkey_toggle_window.show
- @hkey_toggle_window.refresh
- @command_window.deactivate
- end
- alias on_persok_hkeys on_personal_ok
- def on_personal_ok
- on_persok_hkeys
- SceneManager.call(Scene_Hkey) if @command_window.current_symbol == :hot_keys
- end
- end
- # Scene which allows hotkeys to be setup
- class Scene_Hkey < Scene_MenuBase
- def start
- super
- create_help_window
- create_hkey_category_win
- create_hkey_select_win
- end
- def create_help_window
- super
- @help_window.set_text "Hot Key Setup"
- end
- def create_hkey_category_win
- @category_window = Window_HkeyCategory.new(0,@help_window.height)
- @category_window.set_handler(:ok, method(:on_category_ok))
- @category_window.set_handler(:cancel, method(:return_scene))
- @category_window.activate
- end
- def on_category_ok
- @hkey_select_window.activate
- @hkey_select_window.select_last
- @help_window.set_text "Press a key to set it as a hotkey for any " +
- "#{@category_window.current_symbol.to_s}"
- end
- def create_hkey_select_win
- wy = @category_window.y+@category_window.height
- @hkey_select_window = Window_HkeySelection.new(
- 0, wy, Graphics.width,Graphics.height-wy)
- @hkey_select_window.set_handler(:cancel, method(:on_hkey_select_cancel))
- @category_window.hkeyselect_win = @hkey_select_window
- end
- def on_hkey_select_cancel
- @hkey_select_window.deactivate
- @category_window.activate
- @help_window.set_text "Hot Key Setup"
- end
- end
- class Scene_Map < Scene_Base
- alias create_wins_hkeys create_all_windows
- def create_all_windows
- create_wins_hkeys
- create_hkey_display
- end
- def create_hkey_display
- @hotkey_window = Window_Hotkeys.new
- @hotkey_window.refresh
- check_display_hkey_window
- end
- alias upd_scne_map update
- def update
- upd_scne_map
- check_display_hkey_window
- end
- alias perform_trans_hkeys perform_transition
- def perform_transition
- perform_trans_hkeys
- check_display_hkey_window
- end
- def check_display_hkey_window
- hide_hkey_window? ? @hotkey_window.hide : @hotkey_window.show
- end
- def hide_hkey_window?
- !$game_system.game_hotkeys.visible || $game_message.visible || @hotkey_window.amt_shown <= 0
- end
- end
- class Window_Hotkeys < Window_Base
- def initialize
- w = Graphics.width-40
- visible = false
- super((Graphics.width-w)/2,Graphics.height - 70,w,50)
- self.arrows_visible = false
- end
- def amt_shown
- [$game_system.game_hotkeys.size, max_shown].min
- end
- def max_shown; 12; end
- def draw_each_hotkey
- ind = 0
- amt = amt_shown
- $game_system.game_hotkeys.each do |v|
- draw_icon(v.item.icon_index, ind, 0, v.can_use?)
- draw_text(ind+16, 0, 12,20, v.key.to_s.gsub!(/key_|letter_/i,''))
- ind += contents.width/max_shown
- end
- end
- def activate
- super
- show
- refresh
- end
- def max_width
- Graphics.width-40
- end
- def refresh
- contents.clear
- bsize = max_width/max_shown
- self.width = [(bsize * amt_shown),max_width].min
- self.width += standard_padding/2 if self.width > 0
- self.x = (Graphics.width - self.width)/2
- draw_each_hotkey
- end
- end #eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement