#=============================================================================== # Minimalist Name Input Interface (v1.1) # Author: jetpackgone # Compatible with RPG Maker VX Ace # Last updated: October 10, 2014 # # Feel free to use and share, but please credit me if you choose to use # or adapt this script in any way. #=============================================================================== # Features: # - Reduces Name Input Processing window to minimalist form with only capital # letters. # - Useful for implementing short passwords of up to 10 letters in length. # - See demo for example. #=============================================================================== # Version # 1.0 - Original # 1.1 - Fixed window width for demo #=============================================================================== #============================================================================== # ** Window_NameEdit #------------------------------------------------------------------------------ # This window is used to edit an actor's name on the name input screen. #============================================================================== class Window_NameEdit < Window_Base #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_reader :name # name attr_reader :index # cursor position attr_reader :max_char # maximum number of characters #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize(actor, max_char) x = (Graphics.width - 360 / 2) / 2 y = (Graphics.height - (fitting_height(3) + fitting_height(6) + 8)) / 2 super(x, y, 360 / 2 + 4, fitting_height(3)) @actor = actor @max_char = max_char @default_name = @name = actor.name[0, @max_char] @index = @name.size deactivate refresh end #-------------------------------------------------------------------------- # * Get Width of Face Graphic #-------------------------------------------------------------------------- def face_width return 0 end #-------------------------------------------------------------------------- # * Get Character Width #-------------------------------------------------------------------------- def char_width text_size($game_system.japanese? ? "あ" : "A").width + 4 end #-------------------------------------------------------------------------- # * Get Rectangle for Displaying Item #-------------------------------------------------------------------------- def item_rect(index) Rect.new(left + index * char_width, 36, char_width, line_height) end #-------------------------------------------------------------------------- # * Get Left Coordinate of Name #-------------------------------------------------------------------------- def left name_center = (contents_width + face_width) / 2 name_width = (@max_char + 1) * char_width return [name_center - name_width / 2, contents_width - name_width].min end #-------------------------------------------------------------------------- # * Get Underline Rectangle #-------------------------------------------------------------------------- def underline_rect(index) rect = item_rect(index) rect.x += 1 rect.y += rect.height - 4 rect.width -= 2 rect.height = 2 rect end #-------------------------------------------------------------------------- # * Get Underline Color #-------------------------------------------------------------------------- def underline_color color = normal_color color.alpha = 48 color end #-------------------------------------------------------------------------- # * Draw Text #-------------------------------------------------------------------------- def draw_char(index) rect = item_rect(index) rect.x -= -3 rect.width += 4 change_color(normal_color) draw_text(rect, @name[index] || "") end end #============================================================================== # ** Window_NameInput #------------------------------------------------------------------------------ # This window is used to select text characters on the name input screen. #============================================================================== class Window_NameInput < Window_Selectable #-------------------------------------------------------------------------- # * Character Tables (Latin) #-------------------------------------------------------------------------- LATIN3 = [ 'A','B','C','D','E', 'F','G','H','I','J', 'K','L','M','N','O', 'P','Q','R','S','T', 'U','V','W','X','Y', 'Z', '', '', '', 'OK' ] #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize(edit_window) super(edit_window.x, edit_window.y+edit_window.height, edit_window.width, fitting_height(6)) @edit_window = edit_window @page = 0 @index = 0 refresh update_cursor activate end #-------------------------------------------------------------------------- # * Get Text Table #-------------------------------------------------------------------------- def table return [LATIN3] end #-------------------------------------------------------------------------- # * Get Text Character #-------------------------------------------------------------------------- def character @index < 28 ? table[@page][@index] : "" end #-------------------------------------------------------------------------- # * Determine Cursor Location: Confirmation #-------------------------------------------------------------------------- def is_ok? @index == 29 end #-------------------------------------------------------------------------- # * Get Rectangle for Displaying Item #-------------------------------------------------------------------------- def item_rect(index) rect = Rect.new rect.x = index % 5 * 32 + index % 5 / 5 * 16 rect.y = index / 5 * line_height rect.width = 32 rect.height = line_height rect end #-------------------------------------------------------------------------- # * Refresh #-------------------------------------------------------------------------- def refresh contents.clear change_color(normal_color) 30.times {|i| draw_text(item_rect(i), table[@page][i], 1) } end #-------------------------------------------------------------------------- # * Move Cursor Down # wrap : Wraparound allowed #-------------------------------------------------------------------------- def cursor_down(wrap) if @index < 25 or wrap @index = (index + 5) % 30 end end #-------------------------------------------------------------------------- # * Move Cursor Up # wrap : Wraparound allowed #-------------------------------------------------------------------------- def cursor_up(wrap) if @index >= 5 or wrap @index = (index + 25) % 30 end end #-------------------------------------------------------------------------- # * Move Cursor Right # wrap : Wraparound allowed #-------------------------------------------------------------------------- def cursor_right(wrap) if @index % 5 < 4 @index += 1 elsif wrap @index -= 4 end end #-------------------------------------------------------------------------- # * Move Cursor Left # wrap : Wraparound allowed #-------------------------------------------------------------------------- def cursor_left(wrap) if @index % 5 > 0 @index -= 1 elsif wrap @index += 4 end end #-------------------------------------------------------------------------- # * Jump to OK #-------------------------------------------------------------------------- def process_jump if @index != 29 @index = 29 Sound.play_cursor end end end