Code: |
#=begin #=============================================================================== # *** Advanced Input #------------------------------------------------------------------------------- # Auteur : Åvygeil #------------------------------------------------------------------------------- # Ce script permet de gérer facilement les touches du clavier. #=============================================================================== #=============================================================================== # ** Keyboard #------------------------------------------------------------------------------- # Ce module contient les constantes correspondant aux touches du clavier. #=============================================================================== module Keyboard #============================================================================= # ** Key #----------------------------------------------------------------------------- # Cette classe modélise une combinaison de touches du clavier. #============================================================================= class Key attr_reader :code # le code de la combinaison de touche #=========================================================================== # * initialize # code : le code de la touche #=========================================================================== def initialize(code) @code = code end #=========================================================================== # * & # key : une autre combinaison de touches #--------------------------------------------------------------------------- # Renvoie une combinaison de touches qui correspond # à la touche self ET la touche key. #=========================================================================== def &(key) code = @code + key.code return Key.new(code) end #=========================================================================== # * | # key : une autre combinaison de touches #--------------------------------------------------------------------------- # Renvoie une combinaison de touches qui correspond # à la touche self OU la touche key. #=========================================================================== def |(key) code = [] for c1 in @code for c2 in key.code code << c1+c2 end end return Key.new(code) end end #----------------------------------------------------------------------------- # Définition des touches #----------------------------------------------------------------------------- BACK = Key.new([[0x08]]) TAB = Key.new([[0x09]]) ENTER = Key.new([[0x0D]]) SHIFT = Key.new([[0x10]]) ALT_GR = Key.new([[0x11]]) PAUSE = Key.new([[0x13]]) CAPS_LOCK = Key.new([[0x14]]) ESCAPE = Key.new([[0x1B]]) SPACE = Key.new([[0x20]]) PAGE_UP = Key.new([[0x21]]) PAGE_DOWN = Key.new([[0x22]]) PAGE_END = Key.new([[0x23]]) HOME = Key.new([[0x24]]) LEFT = Key.new([[0x25]]) UP = Key.new([[0x26]]) RIGHT = Key.new([[0x27]]) DOWN = Key.new([[0x28]]) PRINT_SCREEN = Key.new([[0x2C]]) INSERT = Key.new([[0x2D]]) DELETE = Key.new([[0x2E]]) A_GRAVE = Key.new([[0x30]]) AMPERSAND = Key.new([[0x31]]) E_ACUTE = Key.new([[0x32]]) DOUBLE_QUOTE = Key.new([[0x33]]) SIMPLE_QUOTE = Key.new([[0x34]]) OPENING_PARENTHESIS = Key.new([[0x35]]) DASH = Key.new([[0x36]]) E_GRAVE = Key.new([[0x37]]) UNDERSCORE = Key.new([[0x38]]) C_CEDIL = Key.new([[0x39]]) A = Key.new([[0x41]]) B = Key.new([[0x42]]) C = Key.new([[0x43]]) D = Key.new([[0x44]]) E = Key.new([[0x45]]) F = Key.new([[0x46]]) G = Key.new([[0x47]]) H = Key.new([[0x48]]) I = Key.new([[0x49]]) J = Key.new([[0x4A]]) K = Key.new([[0x4B]]) L = Key.new([[0x4C]]) M = Key.new([[0x4D]]) N = Key.new([[0x4E]]) O = Key.new([[0x4F]]) P = Key.new([[0x50]]) Q = Key.new([[0x51]]) R = Key.new([[0x52]]) S = Key.new([[0x53]]) T = Key.new([[0x54]]) U = Key.new([[0x55]]) V = Key.new([[0x56]]) W = Key.new([[0x57]]) X = Key.new([[0x58]]) Y = Key.new([[0x59]]) Z = Key.new([[0x5A]]) WINDOWS = Key.new([[0x5B]]) F1 = Key.new([[0x70]]) F2 = Key.new([[0x71]]) F3 = Key.new([[0x72]]) F4 = Key.new([[0x73]]) F5 = Key.new([[0x74]]) F6 = Key.new([[0x75]]) F7 = Key.new([[0x76]]) F8 = Key.new([[0x77]]) F9 = Key.new([[0x78]]) F10 = Key.new([[0x79]]) F11 = Key.new([[0x7A]]) F12 = Key.new([[0x7B]]) LEFT_SHIFT = Key.new([[0xA0]]) RIGHT_SHIFT = Key.new([[0xA0]]) CTRL = Key.new([[0xA2]]) ALT = Key.new([[0xA4]]) DOLLAR = Key.new([[0xBA]]) COMMA = Key.new([[0xBC]]) EQUAL = Key.new([[0xBB]]) SEMICOLON = Key.new([[0xBE]]) COLON = Key.new([[0xBF]]) U_GRAVE = Key.new([[0xC0]]) CLOSING_PARENTHESIS = Key.new([[0xDB]]) ASTERISK = Key.new([[0xDC]]) CIRCUMFLEX = Key.new([[0xDD]]) SQUARE = Key.new([[0xDE]]) EXCLAMATION_MARK = Key.new([[0xDF]]) LESS_THAN = Key.new([[0xE2]]) NUM_LOCK = Key.new([[0x90]]) ZERO = Key.new([[0x60]]) ONE = Key.new([[0x61]]) TWO = Key.new([[0x62]]) THREE = Key.new([[0x63]]) FOUR = Key.new([[0x64]]) FIVE = Key.new([[0x65]]) SIX = Key.new([[0x66]]) SEVEN = Key.new([[0x67]]) EIGHT = Key.new([[0x68]]) NINE = Key.new([[0x69]]) PLUS = Key.new([[0x6B]]) MINUS = Key.new([[0x6D]]) TIMES = Key.new([[0x6A]]) DIVIDE = Key.new([[0x6F]]) DECIMAL = Key.new([[0x6E]]) #============================================================================= # * self.update #----------------------------------------------------------------------------- # Mise à jour de l'état du clavier. #============================================================================= def self.update if not @keyboard_init @caps_lock = false @num_lock = true @grave = false @trema = false @circumflex = false @keyboard_init = true end if Input.trigger?(CAPS_LOCK) @caps_lock = !@caps_lock end if Input.trigger?(NUM_LOCK) @num_lock = !@num_lock end if Input.trigger?(E_GRAVE) and alt_gr? @grave = true end if Input.trigger?(CIRCUMFLEX) caps? ? @trema = true : @circumflex = true end end #============================================================================= # * self.caps? #----------------------------------------------------------------------------- # Renvoie si le mode majuscule est enclenché. #============================================================================= def self.caps? return Input.press?(SHIFT) ? !@caps_lock : @caps_lock end #============================================================================= # * self.num_lock? #----------------------------------------------------------------------------- # Renvoie si le mode majuscule est enclenché. #============================================================================= def self.num_lock? return @num_lock end #============================================================================= # * self.alt_gr? #----------------------------------------------------------------------------- # Renvoie si le mode alternate graphics est enclenché. #============================================================================= def self.alt_gr? return Input.press?(ALT_GR) end #============================================================================= # * self.number #----------------------------------------------------------------------------- # Renvoie le chiffre pressé. #============================================================================= def self.number if (caps? and Input.trigger?(A_GRAVE)) or (num_lock? and Input.trigger?(ZERO)) return "0" end if (caps? and Input.trigger?(AMPERSAND)) or (num_lock? and Input.trigger?(ONE)) return "1" end if (caps? and Input.trigger?(E_ACUTE)) or (num_lock? and Input.trigger?(TWO)) return "2" end if (caps? and Input.trigger?(DOUBLE_QUOTE)) or (num_lock? and Input.trigger?(THREE)) return "3" end if (caps? and Input.trigger?(SIMPLE_QUOTE)) or (num_lock? and Input.trigger?(FOUR)) return "4" end if (caps? and Input.trigger?(OPENING_PARENTHESIS)) or (num_lock? and Input.trigger?(FIVE)) return "5" end if (caps? and Input.trigger?(DASH)) or (num_lock? and Input.trigger?(SIX)) return "6" end if (caps? and Input.trigger?(E_GRAVE)) or (num_lock? and Input.trigger?(SEVEN)) return "7" end if (caps? and Input.trigger?(UNDERSCORE)) or (num_lock? and Input.trigger?(EIGHT)) return "8" end if (caps? and Input.trigger?(C_CEDIL)) or (num_lock? and Input.trigger?(NINE)) return "9" end if (not caps? and Input.trigger?(DASH)) or (num_lock? and Input.trigger?(MINUS)) return "-" end return "" end #============================================================================= # * self.letter #----------------------------------------------------------------------------- # Renvoie la lettre pressée. #============================================================================= def self.letter if Input.trigger?(TAB) return "" if alt_gr? return " " end if Input.trigger?(SPACE) return "" if alt_gr? return " " end if Input.trigger?(A_GRAVE) return "@" if alt_gr? return "0" if caps? return "à" end if Input.trigger?(AMPERSAND) return "" if alt_gr? return "1" if caps? return "&" end if Input.trigger?(E_ACUTE) return "" if alt_gr? return "2" if caps? return "é" end if Input.trigger?(DOUBLE_QUOTE) return "#" if alt_gr? return "3" if caps? return "\"" end if Input.trigger?(SIMPLE_QUOTE) return "{" if alt_gr? return "4" if caps? return "'" end if Input.trigger?(OPENING_PARENTHESIS) return "[" if alt_gr? return "5" if caps? return "(" end if Input.trigger?(DASH) return "|" if alt_gr? return "6" if caps? return "-" end if Input.trigger?(E_GRAVE) return "" if alt_gr? return "7" if caps? return "è" end if Input.trigger?(UNDERSCORE) return "\\" if alt_gr? return "8" if caps? return "_" end if Input.trigger?(C_CEDIL) return "^" if alt_gr? return "9" if caps? return "ç" end if Input.trigger?(A) return "" if alt_gr? return "A" if caps? if @grave @grave = false return "à" end if @trema @trema = false return "ä" end if @circumflex @circumflex = false return "â" end return "a" end if Input.trigger?(B) return "" if alt_gr? return "B" if caps? return "b" end if Input.trigger?(C) return "" if alt_gr? return "C" if caps? return "c" end if Input.trigger?(D) return "" if alt_gr? return "D" if caps? return "d" end if Input.trigger?(E) return "€" if alt_gr? return "E" if caps? if @grave @grave = false return "è" end if @trema @trema = false return "ë" end if @circumflex @circumflex = false return "ê" end return "e" end if Input.trigger?(F) return "" if alt_gr? return "F" if caps? return "f" end if Input.trigger?(G) return "" if alt_gr? return "G" if caps? return "g" end if Input.trigger?(H) return "" if alt_gr? return "H" if caps? return "h" end if Input.trigger?(I) return "" if alt_gr? return "I" if caps? if @grave @grave = false return "ì" end if @trema @trema = false return "ï" end if @circumflex @circumflex = false return "î" end return "i" end if Input.trigger?(J) return "" if alt_gr? return "J" if caps? return "j" end if Input.trigger?(K) return "" if alt_gr? return "K" if caps? return "k" end if Input.trigger?(L) return "" if alt_gr? return "L" if caps? return "l" end if Input.trigger?(M) return "" if alt_gr? return "M" if caps? return "m" end if Input.trigger?(N) return "" if alt_gr? return "N" if caps? return "n" end if Input.trigger?(O) return "" if alt_gr? return "O" if caps? if @grave @grave = false return "ò" end if @trema @trema = false return "ö" end if @circumflex @circumflex = false return "ô" end return "o" end if Input.trigger?(P) return "" if alt_gr? return "P" if caps? return "p" end if Input.trigger?(Q) return "" if alt_gr? return "Q" if caps? return "q" end if Input.trigger?(R) return "" if alt_gr? return "R" if caps? return "r" end if Input.trigger?(S) return "" if alt_gr? return "S" if caps? return "s" end if Input.trigger?(T) return "" if alt_gr? return "T" if caps? return "t" end if Input.trigger?(U) return "" if alt_gr? return "U" if caps? if @grave @grave = false return "ù" end if @trema @trema = false return "ü" end if @circumflex @circumflex = false return "û" end return "u" end if Input.trigger?(V) return "" if alt_gr? return "V" if caps? return "v" end if Input.trigger?(W) return "" if alt_gr? return "W" if caps? return "w" end if Input.trigger?(X) return "" if alt_gr? return "X" if caps? return "x" end if Input.trigger?(Y) return "" if alt_gr? return "Y" if caps? return "y" end if Input.trigger?(Z) return "" if alt_gr? return "Z" if caps? return "z" end if Input.trigger?(DOLLAR) return "¤" if alt_gr? return "£" if caps? return "$" end if Input.trigger?(COMMA) return "" if alt_gr? return "?" if caps? return "," end if Input.trigger?(EQUAL) return "}" if alt_gr? return "+" if caps? return "=" end if Input.trigger?(SEMICOLON) return "" if alt_gr? return "." if caps? return ";" end if Input.trigger?(COLON) return "" if alt_gr? return "/" if caps? return ":" end if Input.trigger?(U_GRAVE) return "" if alt_gr? return "%" if caps? return "ù" end if Input.trigger?(CLOSING_PARENTHESIS) return "]" if alt_gr? return "°" if caps? return ")" end if Input.trigger?(ASTERISK) return "" if alt_gr? return "µ" if caps? return "*" end if Input.trigger?(SQUARE) return "" if alt_gr? return "" if caps? return "²" end if Input.trigger?(EXCLAMATION_MARK) return "" if alt_gr? return "§" if caps? return "!" end if Input.trigger?(LESS_THAN) return "" if alt_gr? return ">" if caps? return "<" end if num_lock? if Input.trigger?(ZERO) return "0" end if Input.trigger?(ONE) return "1" end if Input.trigger?(TWO) return "2" end if Input.trigger?(THREE) return "3" end if Input.trigger?(FOUR) return "4" end if Input.trigger?(FIVE) return "5" end if Input.trigger?(SIX) return "6" end if Input.trigger?(SEVEN) return "7" end if Input.trigger?(EIGHT) return "8" end if Input.trigger?(NINE) return "9" end if Input.trigger?(PLUS) return "+" end if Input.trigger?(MINUS) return "-" end if Input.trigger?(TIMES) return "*" end if Input.trigger?(DIVIDE) return "/" end if Input.trigger?(DECIMAL) return "." end end return "" end end #=============================================================================== # ** Input #------------------------------------------------------------------------------- # On redéfinit entièrement le module Input en se servant de la Win32API. #=============================================================================== module Input #----------------------------------------------------------------------------- # Utilisation de la Win32API pour gérer les touches #----------------------------------------------------------------------------- @@GetKeyboardState = Win32API.new("user32","GetKeyboardState", ['p'],'i') @@keyboard_state = Array.new(256, 0) @@old_keyboard_state = Array.new(256, 0) #============================================================================= # * self.update #----------------------------------------------------------------------------- # Mise à jour de l'état des entrées #============================================================================= def self.update for i in 0...@@keyboard_state.size @@old_keyboard_state[i] = @@keyboard_state[i] end buf = 0.chr * 256 @@GetKeyboardState.call(buf) @@keyboard_state = buf.unpack("C256") Keyboard.update end #============================================================================= # * self.trigger? # key : touche #----------------------------------------------------------------------------- # Teste si on appuie une fois sur une touche #============================================================================= def self.trigger?(key) if key.is_a?(Integer) # Conversion des demandes par code en clef (pour les appel avant ce script) return trigger_code_to_key(key) end for c1 in key.code b2 = false for c2 in c1 if (@@keyboard_state[c2] & 0b10000000 != 0 and @@old_keyboard_state[c2] & 0b10000000 == 0) b2 = true end end if b2 == false return false end end return true end #============================================================================= # * self.press? # key : touche #----------------------------------------------------------------------------- # Teste si on appuie sur une touche de manière continue #============================================================================= def self.press?(key) if key.is_a?(Integer) # Conversion des demandes par code en clef (pour les appel avant ce script) return press_code_to_key(key) end for c1 in key.code b2 = false for c2 in c1 if (@@keyboard_state[c2] & 0b10000000 != 0) b2 = true end end if b2 == false return false end end return true end #============================================================================= # * self.repeat? # key : touche #----------------------------------------------------------------------------- # Teste si on appuie sur une touche de manière répétée #============================================================================= def self.repeat?(key) if key.is_a?(Integer) # Conversion des demandes par code en clef (pour les appel avant ce script) return repeat_code_to_key(key) end if self.trigger?(key) @@count = 0 return true end if self.press?(key) @@count = (@@count+1)%Graphics.frame_rate return @@count == 0 end return false end @@count = 0 #============================================================================= # * self.dir4 #----------------------------------------------------------------------------- # Teste 4 touches directionnelles #============================================================================= def self.dir4 return 2 if press?(Input::DOWN) return 4 if press?(Input::LEFT) return 6 if press?(Input::RIGHT) return 8 if press?(Input::UP) return 0 end #============================================================================= # * self.dir8 #----------------------------------------------------------------------------- # Teste 8 touches directionnelles #============================================================================= def self.dir8 return 1 if press?(Input::DOWN) and press?(Input::LEFT) return 3 if press?(Input::DOWN) and press?(Input::RIGHT) return 7 if press?(Input::UP) and press?(Input::LEFT) return 9 if press?(Input::UP) and press?(Input::RIGHT) return dir4 end #============================================================================= # * self.basic_keys #----------------------------------------------------------------------------- # Renvoie un objet Hash qui associe un code de touche utilisé par RMXP # à un objet Key standard défini dans le module Input #============================================================================= def self.basic_keys { 2 => Input::DOWN, 4 => Input::LEFT, 6 => Input::RIGHT, 8 => Input::UP, 11 => Input::A, 12 => Input::B, 13 => Input::C, 14 => Input::X, 15 => Input::Y, 16 => Input::Z, 17 => Input::L, 18 => Input::R, 21 => Input::SHIFT, 22 => Input::CTRL, 23 => Input::ALT, 25 => Input::F5, 26 => Input::F6, 27 => Input::F7, 28 => Input::F8, 29 => Input::F9 } end #============================================================================= # * self.trigger_code_to_key # keycode : int, code de la clef #----------------------------------------------------------------------------- # Renvoie le résultat de trigger? pour les valeur de Input originales. #============================================================================= def self.trigger_code_to_key(keycode) case keycode when 2 then trigger?(Keyboard::DOWN) # DOWN when 4 then trigger?(Keyboard::LEFT) # LEFT when 6 then trigger?(Keyboard::RIGHT)# RIGHT when 8 then trigger?(Keyboard::UP) # UP when 11 then trigger?(Keyboard::SHIFT) or trigger?(Keyboard::Z) # A when 12 then trigger?(Keyboard::ZERO) or trigger?(Keyboard::ESCAPE) or trigger?(Keyboard::X) # B when 13 then trigger?(Keyboard::C) or trigger?(Keyboard::SPACE) or trigger?(Keyboard::ENTER) # C when 14 then trigger?(Keyboard::A) # X when 15 then trigger?(Keyboard::S) # Y when 16 then trigger?(Keyboard::D) # Z when 17 then trigger?(Keyboard::Q) # L when 18 then trigger?(Keyboard::W) # R when 21 then trigger?(Keyboard::A) # SHIFT when 22 then trigger?(Keyboard::CTRL) # CTRL when 23 then trigger?(Keyboard::ALT) # ALT when 25 then trigger?(Keyboard::F5) # F5 when 26 then trigger?(Keyboard::F6) # F6 when 27 then trigger?(Keyboard::F7) # F7 when 28 then trigger?(Keyboard::F8) # F8 when 29 then trigger?(Keyboard::F9) # F9 else print("ERREUR : Input.trigger_code_to_key(#{keycode})\nLe code spécifié n'est pas valide.") end end #============================================================================= # * self.press_code_to_key # keycode : int, code de la clef #----------------------------------------------------------------------------- # Renvoie le résultat de press? pour les valeur de Input originales. #============================================================================= def self.press_code_to_key(keycode) case keycode when 2 then press?(Keyboard::DOWN) # DOWN when 4 then press?(Keyboard::LEFT) # LEFT when 6 then press?(Keyboard::RIGHT)# RIGHT when 8 then press?(Keyboard::UP) # UP when 11 then press?(Keyboard::SHIFT) or press?(Keyboard::Z) # A when 12 then press?(Keyboard::ZERO) or press?(Keyboard::ESCAPE) or press?(Keyboard::X) # B when 13 then press?(Keyboard::C) or press?(Keyboard::SPACE) or press?(Keyboard::ENTER) # C when 14 then press?(Keyboard::A) # X when 15 then press?(Keyboard::S) # Y when 16 then press?(Keyboard::D) # Z when 17 then press?(Keyboard::Q) # L when 18 then press?(Keyboard::W) # R when 21 then press?(Keyboard::A) # SHIFT when 22 then press?(Keyboard::CTRL) # CTRL when 23 then press?(Keyboard::ALT) # ALT when 25 then press?(Keyboard::F5) # F5 when 26 then press?(Keyboard::F6) # F6 when 27 then press?(Keyboard::F7) # F7 when 28 then press?(Keyboard::F8) # F8 when 29 then press?(Keyboard::F9) # F9 else print("ERREUR : Input.press_code_to_key(#{keycode})\nLe code spécifié n'est pas valide.") end end #============================================================================= # * self.press_code_to_key # keycode : int, code de la clef #----------------------------------------------------------------------------- # Renvoie le résultat de repeat? pour les valeur de Input originales. #============================================================================= def self.repeat_code_to_key(keycode) case keycode when 2 then repeat?(Keyboard::DOWN) # DOWN when 4 then repeat?(Keyboard::LEFT) # LEFT when 6 then repeat?(Keyboard::RIGHT)# RIGHT when 8 then repeat?(Keyboard::UP) # UP when 11 then repeat?(Keyboard::SHIFT) or repeat?(Keyboard::Z) # A when 12 then repeat?(Keyboard::ZERO) or repeat?(Keyboard::ESCAPE) or repeat?(Keyboard::X) # B when 13 then repeat?(Keyboard::C) or repeat?(Keyboard::SPACE) or repeat?(Keyboard::ENTER) # C when 14 then repeat?(Keyboard::A) # X when 15 then repeat?(Keyboard::S) # Y when 16 then repeat?(Keyboard::D) # Z when 17 then repeat?(Keyboard::Q) # L when 18 then repeat?(Keyboard::W) # R when 21 then repeat?(Keyboard::A) # SHIFT when 22 then repeat?(Keyboard::CTRL) # CTRL when 23 then repeat?(Keyboard::ALT) # ALT when 25 then repeat?(Keyboard::F5) # F5 when 26 then repeat?(Keyboard::F6) # F6 when 27 then repeat?(Keyboard::F7) # F7 when 28 then repeat?(Keyboard::F8) # F8 when 29 then repeat?(Keyboard::F9) # F9 else print("ERREUR : Input.repeat_code_to_key(#{keycode})\nLe code spécifié n'est pas valide.") end end end #=============================================================================== # ** Interpreter #------------------------------------------------------------------------------- # On redéfinit les méthodes de gestion du clavier # pour les commandes d'évènements #=============================================================================== class Interpreter #============================================================================= # * input_button #============================================================================= def input_button n = 0 Input.basic_keys.each do |code, key| if Input.trigger?(key) n = code end end if n > 0 $game_variables[@button_input_variable_id] = n $game_map.need_refresh = true @button_input_variable_id = 0 end end #============================================================================= # * command_111 #============================================================================= def command_111 result = false case @parameters[0] when 0 result = ($game_switches[@parameters[1]] == (@parameters[2] == 0)) when 1 value1 = $game_variables[@parameters[1]] if @parameters[2] == 0 value2 = @parameters[3] else value2 = $game_variables[@parameters[3]] end case @parameters[4] when 0 result = (value1 == value2) when 1 result = (value1 >= value2) when 2 result = (value1 <= value2) when 3 result = (value1 > value2) when 4 result = (value1 < value2) when 5 result = (value1 != value2) end when 2 if @event_id > 0 key = [$game_map.map_id, @event_id, @parameters[1]] if @parameters[2] == 0 result = ($game_self_switches[key] == true) else result = ($game_self_switches[key] != true) end end when 3 if $game_system.timer_working sec = $game_system.timer / Graphics.frame_rate if @parameters[2] == 0 result = (sec >= @parameters[1]) else result = (sec <= @parameters[1]) end end when 4 actor = $game_actors[@parameters[1]] if actor != nil case @parameters[2] when 0 result = ($game_party.actors.include?(actor)) when 1 result = (actor.name == @parameters[3]) when 2 result = (actor.skill_learn?(@parameters[3])) when 3 result = (actor.weapon_id == @parameters[3]) when 4 result = (actor.armor1_id == @parameters[3] or actor.armor2_id == @parameters[3] or actor.armor3_id == @parameters[3]) when 5 result = (actor.state?(@parameters[3])) end end when 5 enemy = $game_troop.enemies[@parameters[1]] if enemy != nil case @parameters[2] when 0 result = (enemy.exist?) when 1 result = (enemy.state?(@parameters[3])) end end when 6 character = get_character(@parameters[1]) if character != nil result = (character.direction == @parameters[2]) end when 7 if @parameters[2] == 0 result = ($game_party.gold >= @parameters[1]) else result = ($game_party.gold <= @parameters[1]) end when 8 result = ($game_party.item_number(@parameters[1]) > 0) when 9 result = ($game_party.weapon_number(@parameters[1]) > 0) when 10 result = ($game_party.armor_number(@parameters[1]) > 0) when 11 result = (Input.press?(Input.basic_keys[@parameters[1]])) when 12 result = eval(@parameters[1]) end @branch[@list[@index].indent] = result if @branch[@list[@index].indent] == true @branch.delete(@list[@index].indent) return true end return command_skip end end #=end |
Code: |
module Kurei #============================================================================================================================================================ # *** UScene_Console #------------------------------------------------------------------------------------------------------------------------------------------------------------ # Scene Secondaire de la console, ouvre une fenêtre tout en conservant la scene principale. # Permet à l'utilisateur de taper des commandes d'interpreter et de l'executer. #============================================================================================================================================================ class UScene_Console #=========================================================================== # * main #--------------------------------------------------------------------------- # Méthode principale de la scene secondaire #=========================================================================== def main @window_console = Kurei::Window_Console.new @text_area = @window_console.text_area @old_text_choosen = 0 @target = $game_player @interpreter = Interpreter.new # Interpreter ou s'éxécuteront les commandes d'interpreter # Affichage de la fenêtre d'aide @help_window = Window_Console_Help.new @help_window.visible = false @help_window.active = false # Chargement des données de la dernière ouverture de la console if $console_memory != nil @window_console.old_texts = $console_memory @window_console.refresh end @window_console.description = target_description(@target) # Curseur @map_cursor = CursorMap.new $scene.spriteset.add_character_sprite(@map_cursor) @map_cursor.moveto(@target.x, @target.y) $game_map.center(@map_cursor.x, @map_cursor.y, Game_Player::CENTER_X, Game_Player::CENTER_Y) Graphics.update Input.update loop do update Graphics.update Input.update if Input.trigger?(Keyboard::SQUARE) break end end $console_memory = @window_console.old_texts $scene.spriteset.remove_sprite_of_event(@map_cursor) $game_player.center($game_player.x, $game_player.y) @window_console.dispose @help_window.dispose end #=========================================================================== # * update #--------------------------------------------------------------------------- # Mise à jour de la scene secondaire #=========================================================================== def update $scene.spriteset.update @window_console.update if @window_console.active update_console else update_cursor end end #=========================================================================== # * update_console #--------------------------------------------------------------------------- # Mise à jour des valeurs de console #=========================================================================== def update_console command = nil if Input.trigger?(Keyboard::BACK) or Input.repeat?(Keyboard::BACK) @text_area.action_backspace elsif Input.trigger?(Keyboard::DELETE) or Input.repeat?(Keyboard::DELETE) @text_area.action_delete elsif Input.trigger?(Keyboard::LEFT) or Input.repeat?(Keyboard::LEFT) @text_area.action_move_left elsif Input.trigger?(Keyboard::RIGHT) or Input.repeat?(Keyboard::RIGHT) @text_area.action_move_right elsif Input.trigger?(Keyboard::UP) t = @window_console.old_texts[@old_text_choosen] if t != nil t = t.split(" --- ")[0] @text_area.set_text(t) @old_text_choosen = [@old_text_choosen+1, @window_console.old_texts.size-1].min end elsif Input.trigger?(Keyboard::DOWN) t = @window_console.old_texts[@old_text_choosen] if t != nil t = t.split(" --- ")[0] @text_area.set_text(t) @old_text_choosen = [@old_text_choosen-1, 0].max end elsif Input.trigger?(Keyboard::ENTER) command = @text_area.text @window_console.valid_current_text elsif Input.trigger?(Keyboard::TAB) @help_window.visible = false @window_console.visible = false @window_console.active = false else l = Keyboard.letter @text_area.action_add_letter(l) if l != "" end # Gestion de la commande if command != nil res = "" if command[0..4] == "-help" @help_window.visible = !@help_window.visible res = (@help_window.visible ? "ON" : "OFF") elsif command == "-select" @help_window.visible = false @window_console.visible = false @window_console.active = false else res = execute_command(command) end @window_console.old_texts[0] += " --- #{res}" if res != "" @window_console.description = target_description(@target) end end #=========================================================================== # * update_cursor #--------------------------------------------------------------------------- # Mise à jour du curseur #=========================================================================== def update_cursor x = @map_cursor.x y = @map_cursor.y id = $game_map.check_event(x, y) if id == nil and x == $game_player.x and y == $game_player.y e = $game_player else e = $game_map.events[id] end if e == nil @window_console.description = "" else @window_console.description = target_description(e) end @window_console.refresh if Input.trigger?(Keyboard::SPACE) if e != nil @target = e @window_console.visible = true @window_console.active = true end elsif Input.trigger?(Keyboard::TAB) @window_console.visible = true @window_console.active = true @map_cursor.moveto($game_player.x, $game_player.y) $game_map.center(@map_cursor.x, @map_cursor.y, Game_Player::CENTER_X, Game_Player::CENTER_Y) @window_console.description = target_description($game_player) @window_console.refresh elsif Input.dir4 != 0 if Input.trigger?(Keyboard::DOWN) y += 1 elsif Input.trigger?(Keyboard::LEFT) x -= 1 elsif Input.trigger?(Keyboard::RIGHT) x += 1 elsif Input.trigger?(Keyboard::UP) y -= 1 end if $game_map.valid?(x, y) @map_cursor.moveto(x, y) $game_map.center(@map_cursor.x, @map_cursor.y, Game_Player::CENTER_X, Game_Player::CENTER_Y) end end end #=========================================================================== # * execute_command(command) # command : string, command à exécuter #--------------------------------------------------------------------------- # Execution de la commande. Les instructions de commandes sont séparées par # des points-virgules #=========================================================================== def execute_command(command) if command == "" return "" end command_list = command.split(";") res = "DONE" # Détermination de l'indice if command_list.size > 1 indice = command_list[0] command = command_list[1] else indice = nil command = command_list[0] end if command == "help" return "" end begin case indice when "T" # Target command = "@target.#{command}" res += " : #{eval(command).inspect}" else # Interpreter ecom = RPG::EventCommand.new(355, 0, [command]) ecom_2 = RPG::EventCommand.new(0,0,[]) @interpreter.setup([ecom, ecom_2], @target.id) res += " : #{@interpreter.execute_command}" end rescue res = "ERREUR : Entrez \"-help\" pour l'aide" ensure return res end end #=========================================================================== # * target_description(target) # target : Game_Character, événement décrit #--------------------------------------------------------------------------- # Construit une chaine de caractère décrivant rapidement l'événement #=========================================================================== def target_description(target) if target == $game_player return "JOUEUR" end d = "" d += sprintf("EV%03d ", target.id) d += "\"#{target.event.name}\"" d += " (#{target.x}, #{target.y})" for intloc in ["A", "B", "C", "D"] d+= " #{intloc}:#{$game_self_switches[[target.map_id, target.id, intloc]]}" end return d end end #============================================================================================================================================================ # *** CursorMap < Game_Player #------------------------------------------------------------------------------------------------------------------------------------------------------------ # Classe contenant l'événement du curseur de map #============================================================================================================================================================ class CursorMap < Game_Event def initialize super($game_map.map_id, RPG::Event.new($game_player.x, $game_player.y)) @character_name = "MAP" moveto($game_player.x, $game_player.y) end def screen_z(height = 0) return 890 end end end class Scene_Map attr_accessor :spriteset end class Spriteset_Map attr_accessor :tilemap attr_accessor :character_sprites # Retire le sprite correspondant au Character # event : Game_Event, event à retirer def remove_sprite_of_event(event) for s in @character_sprites if s.character == event s.dispose @character_sprites.delete(s) end end end # Ajoute le sprite au spriteset # event : Game_Event (Game_Character), event à ajouter def add_character_sprite(event, z = nil) sprite = Sprite_Character.new(@viewport1, event) sprite.bitmap = RPG::Cache.character(event.character_name, event.character_hue) @character_sprites.push(sprite) end end module Kurei #============================================================================================================================================================ # *** Window_Text < Window_Base #------------------------------------------------------------------------------------------------------------------------------------------------------------ # Fenêtre où l'utilisateur peut taper du texte #============================================================================================================================================================ class Window_Text_Area < Window_Base TEXT_BAR_SILENCE = 20 CURSOR = '|' #=========================================================================== # * initialize(x, y, width, height, has_skin = true) # x, y : int, coordonnées d'apparition de la fenêtre # width, height : int, dimensions de la fenêtre # has_skin : bool, indique si la fenêtre à une apparence ou si elle # n'en a pas. Peut-être utile pour en faire un simple # champs dans une autre fenêtre plus complexe #--------------------------------------------------------------------------- # Créer la fenêtre de texte #=========================================================================== def initialize(x, y, width, height, has_skin = true) super(x, y, width, height) @text = "" @text += CURSOR @text_bar_index = @text.length - 1 @text_bar_counter = 0 self.windowskin = nil if not has_skin # Création du sprite texte @spr_text = Sprite.new @spr_text.x = self.x + 14 @spr_text.y = self.y + 2 @spr_text.z = 905 @spr_text.bitmap = Bitmap.new(width, height) @spr_text.bitmap.font.name = $fontface @spr_text.bitmap.font.size = 20 @spr_text.bitmap.font.color = normal_color refresh end #=========================================================================== # * refresh #--------------------------------------------------------------------------- # Met le texte et les images à jours #=========================================================================== def refresh # Affichage du texte @spr_text.bitmap.clear @spr_text.bitmap.draw_text(0,0, @spr_text.bitmap.width, @spr_text.bitmap.height, @text) end #=========================================================================== # * update #--------------------------------------------------------------------------- # Mise à jour des données de la fenêtre #=========================================================================== def update super @text_bar_counter += 1 if @text_bar_counter >= TEXT_BAR_SILENCE if @text[@text_bar_index] == 124 hide_text_bar else draw_text_bar end refresh @text_bar_counter = 0 end end #=========================================================================== # * dispose #--------------------------------------------------------------------------- # Efface la fenêtre et ses composants #=========================================================================== def dispose super @spr_text.bitmap.dispose @spr_text.dispose end #====================================================================================================================== #====================================================================================================================== # ** Methodes d'action sur le texte #=========================================================================== # * change_text_bar_index(value) # value : int, index où il faut placer la barre #--------------------------------------------------------------------------- # Change le curseur de place #=========================================================================== def change_text_bar_index(value) if value == @text_bar_index return end if value < 0 or value >= @text.length return end @text[@text_bar_index] = "" @text_bar_index = value @text.insert(@text_bar_index, CURSOR) @text_bar_counter = 0 refresh end #=========================================================================== # * action_add_letter(letter) # letter : string, lettre à ajouter #--------------------------------------------------------------------------- # Ajoute une lettre au texte, ajoute à l'emplacement du curseur #=========================================================================== def action_add_letter(letter) @text.insert(@text_bar_index, letter) @text_bar_index+=1 @text_bar_counter = 0 refresh end #=========================================================================== # * action_backspace #--------------------------------------------------------------------------- # Efface la lettre à gauche du curseur (Touche <--) #=========================================================================== def action_backspace if @text_bar_index == 0 return end @text[@text_bar_index-1] = "" @text_bar_index -= 1 @text_bar_counter = 0 refresh end #=========================================================================== # * action_delete #--------------------------------------------------------------------------- # Efface la lettre à droite du curseur (Touche Suppr.) #=========================================================================== def action_delete if @text_bar_index == @text.length-1 return end @text[@text_bar_index+1] = "" @text_bar_counter = 0 refresh end #=========================================================================== # * action_move_left #--------------------------------------------------------------------------- # Déplace le curseur vers la gauche. #=========================================================================== def action_move_left change_text_bar_index(@text_bar_index - 1) end #=========================================================================== # * action_move_right #--------------------------------------------------------------------------- # Déplace le curseur vers la droite. #=========================================================================== def action_move_right change_text_bar_index(@text_bar_index + 1) end #====================================================================================================================== #====================================================================================================================== # ** Methodes sur les attributs privés #=========================================================================== # * delete_text_bar #--------------------------------------------------------------------------- # Efface le curseur #=========================================================================== def delete_text_bar @text[@text_bar_index] = '' end #=========================================================================== # * hide_text_bar #--------------------------------------------------------------------------- # Remplace le curseur par un espace #=========================================================================== def hide_text_bar @text[@text_bar_index] = ' ' end #=========================================================================== # * draw_text_bar #--------------------------------------------------------------------------- # Dessine le curseur #=========================================================================== def draw_text_bar if @text[@text_bar_index] == 32 @text[@text_bar_index] = CURSOR else @text.insert(@text_bar_index, CURSOR) end end #====================================================================================================================== #====================================================================================================================== # ** Accesseurs #=========================================================================== # * draw_text_bar #--------------------------------------------------------------------------- # Dessine le curseur #=========================================================================== def text t = @text.clone t[@text_bar_index] = "" return t end #=========================================================================== # * clear_text_bar #--------------------------------------------------------------------------- # Efface le texte et réinitialise le curseur #=========================================================================== def clear_text set_text("") end #=========================================================================== # * set_text(valeur) # valeur : string, texte remplaçant #--------------------------------------------------------------------------- # Remplace le texte actuel par celui donné #=========================================================================== def set_text(valeur) @text = valeur @text += CURSOR @text_bar_index = @text.length - 1 @text_bar_counter = 0 refresh end #=========================================================================== # * visible=(value) # value : bool, nouvel état de la visibilité #--------------------------------------------------------------------------- # Change la visibilité de la fenêtre et de ses composants #=========================================================================== def visible=(value) super(value) @spr_text.visible = value end end end module Kurei #============================================================================================================================================================ # *** Window_Console < Window_Base #------------------------------------------------------------------------------------------------------------------------------------------------------------ # Fenêtre de la console. #============================================================================================================================================================ class Window_Console < Window_Base WIDTH = 500 TEXT_AREA_HEIGHT = 40 MAX_DRAW_OLD_TEXTS = 4 attr_reader :text_area # Zone de texte de la fenêtre attr_accessor :old_texts # Textes déjà validés #=========================================================================== # * initialize #--------------------------------------------------------------------------- # Créer la fenêtre #=========================================================================== def initialize height = TEXT_AREA_HEIGHT * 2 + MAX_DRAW_OLD_TEXTS*20 + 14 super(320 - WIDTH/2, 480-height, WIDTH, height) self.z = 900 @description = "" # Textes déjà validés @old_texts = [] # Liste des textes déjà validé @spr_old_texts = Sprite.new @spr_old_texts.x = self.x + 14 @spr_old_texts.y = self.y @spr_old_texts.z = 905 @spr_old_texts.bitmap = Bitmap.new(width, height) @spr_old_texts.bitmap.font.name = $fontface @spr_old_texts.bitmap.font.size = 20 @spr_old_texts.bitmap.font.color = normal_color # Zone de texte de l'utilisateur @text_area = Window_Text_Area.new(self.x, 480 - TEXT_AREA_HEIGHT, self.width, TEXT_AREA_HEIGHT) @text_area.z = 905 # Affichage du nom de la cible @target_area = Window_Base.new(self.x, self.y, self.width, TEXT_AREA_HEIGHT) @target_area.z = 905 @spr_target = Sprite.new @spr_target.x = self.x + 14 @spr_target.y = self.y @spr_target.z = 906 @spr_target.bitmap = Bitmap.new(width, TEXT_AREA_HEIGHT) @spr_target.bitmap.font.name = $fontface @spr_target.bitmap.font.size = 20 @spr_target.bitmap.font.color = normal_color refresh end #=========================================================================== # * refresh #--------------------------------------------------------------------------- # Met le texte et les images à jours #=========================================================================== def refresh @text_area.refresh @spr_target.bitmap.clear @spr_target.bitmap.draw_text(0,0,@spr_target.bitmap.width, @spr_target.bitmap.height, @description) @spr_old_texts.bitmap.clear oy = @text_area.y - self.y for i in 0...[@old_texts.size, MAX_DRAW_OLD_TEXTS].min oy -= 20 @spr_old_texts.bitmap.draw_text(0, oy, self.width, 20, @old_texts[i]) end end #=========================================================================== # * update #--------------------------------------------------------------------------- # Mise à jour des données de la fenêtre #=========================================================================== def update super @text_area.update end #=========================================================================== # * dispose #--------------------------------------------------------------------------- # Efface la fenêtre et ses composants #=========================================================================== def dispose super @text_area.dispose @spr_old_texts.bitmap.dispose @spr_old_texts.dispose @spr_target.bitmap.dispose @spr_target.dispose @target_area.dispose end #=========================================================================== # * action_valid_current_text #--------------------------------------------------------------------------- # Valide le texte courant et vide la zone de texte #=========================================================================== def valid_current_text if @text_area.text == "" return end @old_texts.insert(0, @text_area.text) @text_area.clear_text refresh end #=========================================================================== # * description=(value) # value : string, description à afficher #--------------------------------------------------------------------------- # Modifie la description de l'événement #=========================================================================== def description=(value) @description = value refresh end #=========================================================================== # * visible=(value) # value : bool, nouvel état de la visibilité #--------------------------------------------------------------------------- # Change la visibilité de la fenêtre et de ses composants #=========================================================================== def visible=(value) super(value) @spr_old_texts.visible = value @text_area.visible = value end end end module Kurei #============================================================================================================================================================ # *** Window_Console_Help < Window_Base #------------------------------------------------------------------------------------------------------------------------------------------------------------ # Fenêtre d'aide. #============================================================================================================================================================ class Window_Console_Help < Window_Base def initialize super(0,0,640,250) self.z = 910 @spr_texts = Sprite.new @spr_texts.x = self.x + 14 @spr_texts.y = self.y @spr_texts.z = 911 @spr_texts.bitmap = Bitmap.new(640, height) @spr_texts.bitmap.font.name = $fontface @spr_texts.bitmap.font.size = 20 @spr_texts.bitmap.font.color = normal_color aides = [ "AIDE CONSOLE", "Commandes", " \"-help\" - Ouvre/Ferme la fenêtre d'aide", " \"-select\" - Lance la sélection d'un évent, raccourci : touche TAB", "Indice de commande, se met au début de la commande, si aucun indice n'est indiqué, alors ce", "sera comme une commande de script employé par l'événement", " \"T;\" - indique que la commande s'appliquera à l'événement sélectionné", " exemple : T;moveto(10,10) changera la position de l'événement sélectionné" ] for i in 0...aides.size text = aides[i] @spr_texts.bitmap.draw_text(0, 14 + 20 * i, 640, 20, text) end end def dispose super @spr_texts.bitmap.dispose @spr_texts.dispose end def visible=(value) super(value) @spr_texts.visible = value end end end |
Code: |
s = Kurei::UScene_Console.new s.main |
Code: |
if Input.trigger?(Keyboard::SQUARE) s = Kurei::UScene_Console.new s.main |
Code: |
if Input.trigger?(Keyboard::SQUARE) Kurei::UScene_Console.new.main end |
Code: |
if Input.trigger?(Input::B) unless $game_system.map_interpreter.running? or $game_system.menu_disabled $game_temp.menu_calling = true $game_temp.menu_beep = true end end if $DEBUG and Input.press?(Input::F9) $game_temp.debug_calling = true end # ---> ICI <--- (mais là c'est déjà installé) if Input.trigger?(Keyboard::SQUARE) s = Kurei::UScene_Console.new s.main end |
Code: |
Kurei::Window_Text_Area.new(fond=true) |
Yuri a écrit: |
Je m'attendais à un AllocConsole ou qcch dans le genre x) Enfin, script intéressant mais faut faire gaffe à ne pas utiliser ce module Input pour son jeu car il fait beaucoup trop de traitements inutiles... |
TouzaxA a écrit: |
C'est chouette ce script, ça manquait. Félicitations pour tout ce travail ! |