#=============================================================================== # Note Input # Original RMVX By Jet10985 (Jet) # Input Script by: OriginalWij and Yanfly # Converted to RMVX Ace by Raizen #=============================================================================== # This script will allow the player to freely type notes inside a notebook using # the keyboard. # This script has: 5 customization options. #=============================================================================== # Overwritten Methods: # None #------------------------------------------------------------------------------- # Aliased methods: # None #=============================================================================== =begin The player can turn the page using the Right and Left Arrow keys They press the Up key to make a new page. They press the Down key to delete a page. They press the ESC key to exit the note input scene. -------------------------------------------------------------------------------- To call the Note Input Screen, use this in an Event "Script..." command: SceneManager.call(Scene_NoteInput) =end module NoteInput # What text should be shown at the top of the note input scene? NOTE_INPUT_TEXT = "Notebook" # What font will notes be written in? NOTE_FONT = ["Verdana", "Arial", "Courier New"] # What size will the note's font be? NOTE_SIZE = 20 # What color will the note font be? NOTE_COLOR = Color.new(255, 255, 255) # This is how much space is between each line height-wise. # I recommend making it 4 bigger than the NOTE_SIZE. NOTE_WLH = 24 end #=============================================================================== # DON'T EDIT FURTHER UNLESS YOU KNOW WHAT TO DO. #=============================================================================== class String def each_word array = self.split(" ") if block_given? array.each {|a| yield a } else return array end end def lines line_array = [] each_line {|line| line_array.push(line.gsub(/[\r\n]/i, "")) } return line_array end def each_letter; return self.split(//i); end end class Game_System attr_accessor :note_input_texts alias jet1139_initialize initialize unless $@ def initialize(*args, &block) jet1139_initialize(*args, &block) @note_input_texts = [""] end end module NoteInput include Input LETTERS = {} LETTERS['A'] = 65; LETTERS['B'] = 66; LETTERS['C'] = 67; LETTERS['D'] = 68 LETTERS['E'] = 69; LETTERS['F'] = 70; LETTERS['G'] = 71; LETTERS['H'] = 72 LETTERS['I'] = 73; LETTERS['J'] = 74; LETTERS['K'] = 75; LETTERS['L'] = 76 LETTERS['M'] = 77; LETTERS['N'] = 78; LETTERS['O'] = 79; LETTERS['P'] = 80 LETTERS['Q'] = 81; LETTERS['R'] = 82; LETTERS['S'] = 83; LETTERS['T'] = 84 LETTERS['U'] = 85; LETTERS['V'] = 86; LETTERS['W'] = 87; LETTERS['X'] = 88 LETTERS['Y'] = 89; LETTERS['Z'] = 90 NUMBERS = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57] NUMPAD = [96, 97, 98, 99, 100, 101, 102, 103, 104, 105] BACK = 138; ENTER = 143; SPACE = 32; SCOLON = 186; ESC = 157 QUOTE = 222; EQUALS = 187; COMMA = 188; USCORE = 189; PERIOD = 190 SLASH = 191; LBRACE = 219; RBRACE = 221; BSLASH = 220; TILDE = 192 F10 = 121; F11 = 122; CAPS = 20; NMUL = 106; NPLUS = 107 NSEP = 108; NMINUS = 109; NDECI = 110; NDIV = 111; Extras = [USCORE, EQUALS, LBRACE, RBRACE, BSLASH, SCOLON, QUOTE, COMMA, PERIOD, SLASH, NMUL, NPLUS, NSEP, NMINUS, NDECI, NDIV] GetKeyState = Win32API.new("user32", "GetAsyncKeyState", "i", "i") GetCapState = Win32API.new("user32", "GetKeyState", "i", "i") KeyRepeatCounter = {} module_function def update for key in KeyRepeatCounter.keys if (GetKeyState.call(key).abs & 0x8000 == 0x8000) KeyRepeatCounter[key] += 1 else KeyRepeatCounter.delete(key) end end end def press?(key) adjusted_key = adjust_key(key) return true unless KeyRepeatCounter[adjusted_key].nil? return key_pressed?(adjusted_key) end def trigger?(key) adjusted_key = adjust_key(key) count = KeyRepeatCounter[adjusted_key] return ((count == 0) or (count.nil? ? key_pressed?(adjusted_key) : false)) end def repeat?(key) adjusted_key = adjust_key(key) count = KeyRepeatCounter[adjusted_key] return true if count == 0 if count.nil? return key_pressed?(adjusted_key) else return (count >= 23 and (count - 23) % 6 == 0) end end def adjust_key(key) key -= 130 if key.between?(130, 158) return key end def key_pressed?(key) if (GetKeyState.call(key).abs & 0x8000 == 0x8000) KeyRepeatCounter[key] = 0 return true end return false end def typing? return true if repeat?(SPACE) for i in 'A'..'Z' return true if repeat?(LETTERS[i]) end for i in 0...NUMBERS.size return true if repeat?(NUMBERS[i]) return true if repeat?(NUMPAD[i]) end for key in Extras return true if repeat?(key) end return false end def key_type return " " if repeat?(SPACE) for i in 'A'..'Z' next unless repeat?(LETTERS[i]) return upcase? ? i.upcase : i.downcase end for i in 0...NUMBERS.size return i.to_s if repeat?(NUMPAD[i]) if !Input.press?(SHIFT) return i.to_s if repeat?(NUMBERS[i]) elsif repeat?(NUMBERS[i]) case i when 1; return "!" when 2; return "@" when 3; return "#" when 4; return "$" when 5; return "%" when 6; return "^" when 7; return "&" when 8; return "*" when 9; return "(" when 0; return ")" end end end for key in Extras next unless repeat?(key) case key when USCORE; return Input.press?(SHIFT) ? "_" : "-" when EQUALS; return Input.press?(SHIFT) ? "+" : "=" when LBRACE; return Input.press?(SHIFT) ? "{" : "[" when RBRACE; return Input.press?(SHIFT) ? "}" : "]" when BSLASH; return Input.press?(SHIFT) ? "|" : "\\" when SCOLON; return Input.press?(SHIFT) ? ":" : ";" when QUOTE; return Input.press?(SHIFT) ? '"' : "'" when COMMA; return Input.press?(SHIFT) ? "<" : "," when PERIOD; return Input.press?(SHIFT) ? ">" : "." when SLASH; return Input.press?(SHIFT) ? "?" : "/" when NMUL; return "*" when NPLUS; return "+" when NSEP; return "," when NMINUS; return "-" when NDECI; return "." when NDIV; return "/" end end return "" end def upcase? return !Input.press?(SHIFT) if GetCapState.call(CAPS) == 1 return true if Input.press?(SHIFT) return false end end class Window_NoteInput < Window_Base attr_reader :text include NoteInput def initialize(x, y, width, height) super(x, y, width, height) self.contents.font.name = NOTE_FONT self.contents.font.size = NOTE_SIZE self.contents.font.color = NOTE_COLOR @wait_count = 0 @text = 0 @ref_text = "" @clear_or_draw = false refresh end def refresh self.contents.clear space_taken = 0 new_text = "" $game_system.note_input_texts[@text].each_word {|word| space_taken += self.contents.text_size("#{word} ").width if word == "\x00" new_text.concat(" ") space_taken += self.contents.text_size(" ").width elsif word == "\x01" new_text.concat("\r\n") space_taken = 0 elsif space_taken > self.contents.width space_taken = 0 new_text.concat("\r\n#{word}") space_taken += self.contents.text_size("#{word} ").width else new_text.concat(" #{word}") end } i = 0 new_text.each_line {|line| self.contents.draw_text(0, i * NOTE_WLH, self.contents.width, NOTE_WLH, line.gsub(/[\r\n]/i, "")) i += 1 } @ref_text = new_text update(true) end def update(bypass = false) @wait_count -= 1 unless @wait_count == 0 return unless bypass || @wait_count == 0 @wait_count = 30 ny = (@ref_text.lines.size - 1) * NOTE_WLH if @ref_text.lines[@ref_text.lines.size - 1].nil? nx = 0 else nx = self.contents.text_size(@ref_text.lines[ @ref_text.lines.size - 1].gsub(/[\r\n]/i, "")).width end index_line = self.contents.text_size("|") if @clear_or_draw self.contents.clear_rect(nx, ny, index_line.width, index_line.height) else self.contents.draw_text(nx, ny, index_line.width, index_line.height, "|") end @clear_or_draw = !@clear_or_draw end def add_key(letter) return if letter == "" i = @ref_text.lines.size i -= 1 unless i == 0 if i != 0 and self.contents.text_size( @ref_text.lines[i] + letter).width > self.contents.width || " \x01 " == letter if @ref_text.lines.size * NOTE_WLH + NOTE_WLH > self.contents.height Sound.play_buzzer return end end $game_system.note_input_texts[@text].concat(letter) refresh end def remove_key f = $game_system.note_input_texts[@text].each_letter if ["\x00", "\x01"].include?(f[f.size - 2]) f.pop f.pop end f.pop f.push("") if f.empty? $game_system.note_input_texts[@text] = f.inject {|a, b| a + b } refresh end def text=(t) @text = t if @text < 0 @text = $game_system.note_input_texts.size - 1 elsif @text == $game_system.note_input_texts.size @text = 0 end refresh end end class Scene_NoteInput < Scene_Base def initialize @return_scene = $scene.class end def start super create_background @help_window = Window_Help.new @help_window.set_text(NoteInput::NOTE_INPUT_TEXT) @note_window = Window_NoteInput.new(0, 56, Graphics.width, Graphics.height - 56) @note_window.text = 0 @index = 0 @command_win = Window_Canc_Command.new(160, 0) @command_win.set_handler(:cancel, method(:command_cancel)) @command_win.x = Graphics.width / 2 - 80 @command_win.y = Graphics.height / 2 - @command_win.height / 2 @command_win.refresh @command_win.deactivate @command_win.close end #-------------------------------------------------------------------------- # * Criação do plano de fundo #-------------------------------------------------------------------------- def create_background @command_win = false @background_sprite = Sprite.new @background_sprite.bitmap = SceneManager.background_bitmap @background_sprite.color.set(16, 16, 16, 128) end def update super return unless @note_window.active NoteInput.update if NoteInput.trigger?(NoteInput::ESC) SceneManager.return return end if Input.trigger?(Input::UP) $game_system.note_input_texts.push("") @note_window.text = $game_system.note_input_texts.size - 1 elsif Input.trigger?(Input::DOWN) @command_win.open @command_win.activate @note_window.deactivate elsif Input.trigger?(Input::LEFT) @note_window.text -= 1 elsif Input.trigger?(Input::RIGHT) @note_window.text += 1 elsif NoteInput.trigger?(NoteInput::BACK) @note_window.remove_key elsif NoteInput.trigger?(NoteInput::SPACE) @note_window.add_key(" \x00 ") elsif NoteInput.trigger?(NoteInput::ENTER) @note_window.add_key(" \x01 ") else @note_window.add_key(NoteInput.key_type) end @note_window.update end def command_cancel p "aeee" $game_system.note_input_texts.delete_at(@note_window.text) if $game_system.note_input_texts.empty? $game_system.note_input_texts.push("") end @note_window.text -= 1 @command_win.deactivate @note_window.activate @command_win.close end def terminate super dispose_background @note_window.dispose @help_window.dispose @command_win.dispose end #-------------------------------------------------------------------------- # * Disposição do plano de fundo #-------------------------------------------------------------------------- def dispose_background @background_sprite.dispose end end #============================================================================== # ** Window_HorzCommand #------------------------------------------------------------------------------ # Esta janela lida com seleção geral de comandos ns horizontal. #============================================================================== class Window_Canc_Command < Window_Command #-------------------------------------------------------------------------- # * Criação da lista de comandos #-------------------------------------------------------------------------- def make_command_list add_command('Delete', :cancel) end end