10-15-2008, 01:00 PM
(This post was last modified: 06-10-2017, 04:08 AM by DerVVulfman.)
Keyboard Name Input
by vinardo
Version: 1.0 (15.10.08)
Introduction
You can edit hero namy by keyboard!
Demo:
KeyboardNameInputbyVinardo.rar (Size: 192.17 KB / Downloads: 4)
Script:
You need the SDK by SephirothSpawn, and:
Credits
Thanks to SephirothSpawn for SDK and Keyboard Input Module
Author's Notes
Here can be errors...
Sorry for my english lang. - I'm from Poland...
by vinardo
Version: 1.0 (15.10.08)
This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.
No support is given. If you are the owner of the thread, please contact administration.
Introduction
You can edit hero namy by keyboard!
Demo:
KeyboardNameInputbyVinardo.rar (Size: 192.17 KB / Downloads: 4)
Script:
You need the SDK by SephirothSpawn, and:
Keyboard Input Module by SephirothSpawn
Code:
module Input
#--------------------------------------------------------------------------
Back = 8
Shift = 16
Ctrl = 17
Alt = 18
Esc = 27
Space = 32
Numberpad = (33..40).to_a + [12, 45]
Numbers = (48..57).to_a
Letters = (65..90).to_a
FKeys = (112..123).to_a
Collon = 186
Equal = 187
Comma = 188
Underscore = 189
Dot = 190
Backslash = 191
LB = 219
RB = 221
Enter = 13
Quote = 222
#--------------------------------------------------------------------------
def Input.getstate(key)
unless Win32API.new("user32","GetKeyState",['i'],'i').call(key).between?(0, 1)
return true
end
return false
end
#--------------------------------------------------------------------------
def Input.get_direction
for key in Numberpad
if Input.getstate(key)
case key
when 45; return "0" # Same As Insert
when 33; return "9" # Same As Page Up
when 34; return "3" # Same As Page Down
when 35; return "1" # Same As Page End
when 36; return "7" # Same As Page Home
when 37; return "4" # Same As Left
when 38; return "8" # Same As Up
when 39; return "6" # Same As Right
when 40; return "2" # Same As Down
when 12; return "5"
end
end
end
end
#--------------------------------------------------------------------------
def Input.get_function
if Input.getstate(Back)
return 'Back'
elsif Input.getstate(Backslash)
return '/'
elsif Input.getstate(Esc)
return 'Esc'
elsif Input.getstate(Ctrl)
return 'Ctrl'
elsif Input.getstate(Alt)
return 'Alt'
elsif Input.getstate(Enter)
return 'Enter'
end
for key in FKeys
if Input.getstate(key)
num = key - 111
return 'F' + num.to_s
end
end
return nil
end
#--------------------------------------------------------------------------
def Input.get_letters
for key in Letters
if Input.getstate(key)
return (Input.getstate(Shift) ? key.chr.upcase : key.chr.downcase)
end
end
return nil
end
#--------------------------------------------------------------------------
def Input.get_numbers
return nil if Input.getstate(Shift)
for key in Numbers
if Input.getstate(key)
return key.chr
end
end
return nil
end
#--------------------------------------------------------------------------
def Input.get_key
if Input.getstate(Space)
return ' '
elsif Input.getstate(Backslash) and Input.getstate(Shift)
return '?'
elsif Input.getstate(LB)
return (Input.getstate(Shift) ? '{' : '[')
elsif Input.getstate(RB)
return (Input.getstate(Shift) ? '}' : ']')
elsif Input.getstate(Comma)
return (Input.getstate(Shift) ? '<' : ',')
elsif Input.getstate(Dot)
return (Input.getstate(Shift) ? '>' : '.')
elsif Input.getstate(Collon)
return (Input.getstate(Shift) ? ':' : ';')
elsif Input.getstate(Equal)
return (Input.getstate(Shift) ? '+' : '=')
elsif Input.getstate(Underscore)
return (Input.getstate(Shift) ? '_' : '-')
elsif Input.getstate(Quote)
return (Input.getstate(Shift) ? "\"" : "'")
end
for key in Numbers
if Input.getstate(key) and Input.getstate(Shift)
case key
when 48; return ')'
when 49; return '!'
when 50; return '@'
when 51; return '#'
when 52; return '$'
when 53; return '%'
when 54; return '^'
when 55; return '&'
when 56; return '*'
when 57; return '('
end
end
end
return nil
end
end
Class_Name
Code:
######################################################################
# Keyboard Name Input Script #
# by Vinardo #
######################################################################
# You can Enter Hero Name by your Keyboard! #
# #
# Thanks to SephirothSpawn for Keyboard Input Module and SDK #
######################################################################
# Sorry for my english- I'm from Poland #
######################################################################
class Scene_Name
def main
@actor = $game_actors[$game_temp.name_actor_id]
@waiting = 0
@edit_window = Window_NameEdit.new(@actor, $game_temp.name_max_char)
@spriteset = Spriteset_Map.new
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@edit_window.dispose
@spriteset.dispose
end
def update
@edit_window.update
letter = Input.get_letters
number = Input.get_numbers
key = Input.get_key
if @waiting == 0
unless letter.nil?
$game_system.se_play($data_system.decision_se)
@edit_window.add(Input.get_letters)
@waiting = 6
end
unless number.nil?
$game_system.se_play($data_system.decision_se)
@edit_window.add(Input.get_numbers)
@waiting = 6
end
unless key.nil?
$game_system.se_play($data_system.decision_se)
@edit_window.add(Input.get_key)
@waiting = 6
end
if Input.get_function == 'Back'
$game_system.se_play($data_system.cancel_se)
@edit_window.back
@waiting = 6
end
if Input.get_function == 'Esc'
@edit_window.restore_default
$game_system.se_play($data_system.buzzer_se)
@waiting = 6
end
else
@waiting -= 1 if @waiting > 0
end
if Input.get_function == 'Enter'
@actor.name = @edit_window.name
$game_system.se_play($data_system.decision_se)
$scene = Scene_Map.new
end
end
end
Window_NameEdit
Code:
#==============================================================================
# ** Window_NameEdit
#------------------------------------------------------------------------------
# This window is used to edit your name on the input name screen.
#==============================================================================
class Window_NameEdit < Window_Base
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :name # name
attr_reader :index # cursor position
#--------------------------------------------------------------------------
# * Object Initialization
# actor : actor
# max_char : maximum number of characters
#--------------------------------------------------------------------------
def initialize(actor, max_char)
super(20, 80, 600, 128)
self.contents = Bitmap.new(width - 32, height - 32)
@actor = actor
@name = actor.name
@max_char = max_char
# Fit name within maximum number of characters
name_array = @name.split(//)[0...@max_char]
@name = ""
for i in 0...name_array.size
@name += name_array[i]
end
@default_name = @name
@index = name_array.size
refresh
update_cursor_rect
end
#--------------------------------------------------------------------------
# * Return to Default Name
#--------------------------------------------------------------------------
def restore_default
@name = @default_name
@index = @name.split(//).size
refresh
update_cursor_rect
end
#--------------------------------------------------------------------------
# * Add Character
# character : text character to be added
#--------------------------------------------------------------------------
def add(character)
if @index < @max_char and character != ""
@name += character
@index += 1
refresh
update_cursor_rect
end
end
#--------------------------------------------------------------------------
# * Delete Character
#--------------------------------------------------------------------------
def back
if @index > 0
# Delete 1 text character
name_array = @name.split(//)
@name = ""
for i in 0...name_array.size-1
@name += name_array[i]
end
@index -= 1
refresh
update_cursor_rect
end
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
# Draw name
name_array = @name.split(//)
for i in 0...@max_char
c = name_array[i]
if c == nil
c = "_"
end
x = 320 - @max_char * 14 + i * 28
self.contents.draw_text(x, 32, 28, 32, c, 1)
end
# Draw graphic
draw_actor_graphic(@actor, 320 - @max_char * 14 - 40, 80)
end
#--------------------------------------------------------------------------
# * Cursor Rectangle Update
#--------------------------------------------------------------------------
def update_cursor_rect
x = 320 - @max_char * 14 + @index * 28
self.cursor_rect.set(x, 32, 28, 32)
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
update_cursor_rect
end
end
Credits
Thanks to SephirothSpawn for SDK and Keyboard Input Module
Author's Notes
Here can be errors...
Sorry for my english lang. - I'm from Poland...