O TEMA DO FÓRUM ESTÁ EM MANUTENÇÃO. FEEDBACKS AQUI: ACESSAR

Inserir nome utilizando o teclado

Iniciado por Raizen, 14/06/2013 às 18:56

Inserir nome do herói com o teclado
por lasso

Introdução

Tem as mesmas funções do "Inserir nome do herói", porém usa o teclado.

Screenshots



Como usar

Coloque acima de Main.

Vá à 3ª aba dos comandos do evento, cloque "Chamar Script" e chame isso
$scene = Scene_NameInput.new(id, caracteres)

sendo id o id do personagem e caracteres o numero de caracteres
nao tem limite pro numero de caracteres

Comparibilidade:VX

Demo

Não é necessária.

Script
################################################################################
# Inserir nome do herói com o teclado                                          #
################################################################################
#--------------------------------Créditos--------------------------------------#
################################################################################
# Por: Lasso.                                                                  #
################################################################################
#-----------------------------Características----------------------------------#
################################################################################
# Tem as mesmas funções do "Inserir nome do herói", porém usa o teclado.       #
################################################################################
#--------------------------------Intruções-------------------------------------#
################################################################################
# Coloque acima de Main.                                                       #
#                                                                              #
# Vá à 3ª aba dos comandos do evento, cloque "Chamar Script" e chame isso      #
# $scene = Scene_NameInput.new(id, caracteres)                                 #
# sendo id o id do personagem e caracteres o numero de caracteres              #
# nao tem limite pro numero de caracteres                                      #
################################################################################
module Keys
  @getAsyncKeyState = Win32API.new('user32', 'GetAsyncKeyState', 'i', 'i')
  @last_array = Array.new(256, false)
  @trigger = Array.new(256, false)
  @press = Array.new(256, false)
  def self.update
    @trigger = Array.new(256, false)
    @press = Array.new(256, false)
    for i in 0..255
      @press[i] = (@getAsyncKeyState.call(i) == 0)? false : true
      if @last_array[i] == false and @press[i] == true
        @trigger[i] = true
      end
    end
    @last_array = @press
  end
  def self.trigger?(i)
    return @trigger[i]
  end
  def self.press?(i)
    return @press[i]
  end
end
module Input
  class << self
    alias keys_update update
  end
  def self.update
    self.keys_update
    Keys.update
  end
end
class Window_Name < Window_Base
  attr_reader   :name
  attr_reader   :index
  attr_reader   :max_char
  def initialize(actor_id, max_char)
    super(0, 0, 544, 128)
    @actor = $game_actors[actor_id]
    @name = @actor.name
    @max_char = max_char
    @default_name = @name
    @index = @name.size
    self.active = false
    refresh
    update_cursor
  end
  def restore_default
    @name = @default_name
    @index = @name.size
    refresh
    update_cursor
  end
  def add(character)
    if @index < @max_char and character != ''
      @name += character
      @index += 1
      refresh
      update_cursor
    end
  end
  def back
    if @index > 0
      name_array = @name.split(//)
      @name = ""
      for i in 0...name_array.size-1
        @name += name_array[i]
      end
      @index -= 1
      refresh
      update_cursor
    end
  end
  def item_rect(index)
    rect = Rect.new(0, 0, 0, 0)
    rect.x = 220 - (@max_char + 1) * 12 + index * 24
    rect.y = 36
    rect.width = 24
    rect.height = WLH
    return rect
  end
  def refresh
    self.contents.clear
    draw_actor_face(@actor, 0, 0)
    name_array = @name.split(//)
    for i in 0...@max_char
      c = name_array[i]
      c = '_' if c == nil
      self.contents.draw_text(item_rect(i), c, 1)
    end
  end
  def update_cursor
    self.cursor_rect = item_rect(@index)
  end
  def update
    super
    update_cursor
  end
end
class Scene_NameInput < Scene_Base
  CHARACTERS = [[65,'a'],[66,'b'],[67,'c'],[68,'d'],[69,'e'],[70,'f'],[71,'g'],[72,'h'],[73,'i'],[74,'j'],[75,'k'],[76,'l'],[77,'m'],[78,'n'],[79,'o'],[80,'p'],[81,'q'],[82,'r'],[83,'s'],[84,'t'],[85,'u'],[86,'v'],[87,'w'],[88,'x'],[89,'y'],[90,'z'],[48,'0'],[49,'1'],[50,'2'],[51,'3'],[52,'4'],[53,'5'],[54,'6'],[55,'7'],[56,'8'],[57,'9'],[32,' '],[96,'0'],[97,'1'],[98,'2'],[99,'3'],[100,'4'],[101,'5'],[102,'6'],[103,'7'],[104,'8'],[105,'9']]
  ENTER = 13
  BACKSPACE = 8
  LEFT_SHIFT = 160
  RIGHT_SHIFT = 161
  def initialize(actor_id, max_char)
    @actor = $game_actors[actor_id]
    @edit_window = Window_Name.new(actor_id, max_char)
    start
  end
  def start
    create_menu_background
  end
  def terminate
    super
    dispose_menu_background
    @edit_window.dispose
  end
  def return_scene
    $scene = Scene_Map.new
  end
  def update
    super
    update_menu_background
    @edit_window.update
    if Keys.trigger?(BACKSPACE)
      if @edit_window.index > 0
        Sound.play_cancel
        @edit_window.back
      end
    elsif Keys.trigger?(ENTER)
      if @edit_window.name == ''
        @edit_window.restore_default
        if @edit_window.name == ''
          Sound.play_buzzer
        else
          Sound.play_decision
        end
      else
        Sound.play_decision
        @actor.name = @edit_window.name
        return_scene
      end
    end
    for i in CHARACTERS
      if Keys.trigger?(i[0])
        if @edit_window.index == @edit_window.max_char
          Sound.play_buzzer
        else
          Sound.play_decision
          case shift?
          when true
            @edit_window.add(i[1].upcase)
          when false
            @edit_window.add(i[1])
          end
        end
      end
    end
  end
  def shift?
    return (Keys.press?(LEFT_SHIFT) or Keys.press?(RIGHT_SHIFT))
  end
end



Créditos e Agradecimentos

  • Criado por lasso.

  Esse é bem simples, mas eu prefiro o do Rafidelis.  Mas vou guardar aqui, vai que rola. ;D

  Ótima contribuição, carinha-que-usa-avatar-de-menina.

Aff que zuado man U.U
Spoiler
Eu nem chego perto kkkkkkkkkkkkkkk Parabéns mano ta muito manerissimo, vou até usar quando tiver chance *0*
[close]

--------------------------------------------

TY Misty :3
My Gift *0* Thank u Vash