#==============================================================================
# - Passwords Input Script - Beta 2
# Edited by Storm
#==============================================================================
module Password_Input
#--------------------------------------------------------------------------
# * Main Settings
#--------------------------------------------------------------------------
# Toggle script
SCRPT = true;
# Text viewed if script is disabled
SCTXT = "UNDER CONSTRUCTION!";
# Toggle passwords
CHACT = true;
#--------------------------------------------------------------------------
# * Window Settings
#--------------------------------------------------------------------------
# Input position for input window
IPOSX = 160;
IPOSY = 105;
# Input position for edit window
EPOSX = 160;
EPOSY = 23;
# Input back opacity for edit window
WINOP1 = 200;
# Input back opacity for input window
WINOP2 = 200;
# Input maximum characters limit (higher then 12 not supported)
# 1 character will be added automatically if the icon is disabled
MAXCH = 12;
# Show map on background
MAPBCK = true;
#--------------------------------------------------------------------------
# * Font & Text Settings
#--------------------------------------------------------------------------
# Input font settings for edit window
FNAME1 = "Arial";
FSIZE1 = 18;
FCLOR1 = 0;
# Input font settings for input window
FNAME2 = "Arial";
FSIZE2 = 18;
FCLOR2 = 0;
# Input font & text settings for [OK] button
BUTTN1 = "OK";
FNAME3 = "Arial";
FSIZE3 = 18;
FCLOR3 = 0;
SWITCH = 75; #DEFAULT SWITCH
#--------------------------------------------------------------------------
# * Icon Settings
#--------------------------------------------------------------------------
# Show icon in edit window
ICNNM = true;
# Input file name of the icon
CICON = "";
end
if Password_Input::SCRPT
#==============================================================================
# ** Scene_Password
#==============================================================================
class Scene_Password
def initialize(password,switch=Password_Input::SWITCH)
@password = password
@switch = switch
@ok = false
end
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
if Password_Input::MAPBCK
# Show map behind windows
@spriteset = Spriteset_Map.new
end
# Make windows
@edit_window = Window_PasswordEdit.new
@edit_window.x = Password_Input::EPOSX
@edit_window.y = Password_Input::EPOSY
@input_window = Window_PasswordInput.new
@input_window.x = Password_Input::IPOSX
@input_window.y = Password_Input::IPOSY
# Execute transition
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
# Abort loop if screen is changed
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
# Dispose of spriteset
@spriteset.dispose
# Dispose of windows
@edit_window.dispose
@input_window.dispose
if @password!="any"
if @ok
$game_switches[@switch] = true
else
$game_switches[@switch] = false
end
else
$game_variables[@switch] = @password_word
end
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update windows
@edit_window.update
@input_window.update
# If B button was pressed
if Input.repeat?(Input::B)
# If cursor position is at 0
if @edit_window.index == 0
return
end
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Delete text
@edit_window.back
return
end
if Password_Input::CHACT
# If C button was pressed
if Input.trigger?(Input::C)
# If cursor position is at [OK]
if @input_window.character == nil
@password_word = @edit_window.password
@password_downcase = @edit_window.password.downcase
# START EDITING //
#--------------------------------------------------------------------------
# * passwords
# Check example code.
#--------------------------------------------------------------------------
if @password_word == @password or @password == "any"
@ok = true
#$game_system.se_play($data_system.decision_se)
# STOP EDITING \\
else
# Play buzzer SE
#$game_system.se_play($data_system.buzzer_se)
end
# Switch to map screen
$scene = Scene_Map.new
return
end
# If text character is empty
if @input_window.character == ""
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Add text character
@edit_window.add(@input_window.character)
return
end
else
# If C button was pressed
if Input.trigger?(Input::C)
# If cursor position is at [OK]
if @input_window.character == nil
@password_word = @edit_window.password
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
# Switch to map screen
$scene = Scene_Map.new
return
end
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Add text character
@edit_window.add(@input_window.character)
return
end
end
end
end
#==============================================================================
# ** Window_Base
#==============================================================================
class Window_Base < Window
#--------------------------------------------------------------------------
# * Draw Graphic
# icon : icon
# x : draw spot x-coordinate
# y : draw spot y-coordinate
#--------------------------------------------------------------------------
def draw_icon_graphic(icon, x, y)
bitmap = RPG::Cache.icon(icon)
cw = bitmap.width
ch = bitmap.height
src_rect = Rect.new(0, 0, cw, ch)
self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
end
end
#==============================================================================
# ** Window_PasswordEdit
#==============================================================================
class Window_PasswordEdit < Window_Base
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader:password # password
attr_reader:index # cursor position
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 0, 320, 82)
self.contents = Bitmap.new(width - 32, height - 32)
self.back_opacity = Password_Input::WINOP1
if Password_Input::ICNNM
@max_char = Password_Input::MAXCH
else
@max_char = Password_Input::MAXCH + 1
end
@index = 0
@password = ""
refresh
update_cursor_rect
end
#--------------------------------------------------------------------------
# * Add Character
# character : text character to be added
#--------------------------------------------------------------------------
def add(character)
if @index < @max_char and character != ""
@password += character
@index += 1
refresh
update_cursor_rect
end
end
#--------------------------------------------------------------------------
# * Delete Character
#--------------------------------------------------------------------------
def back
if @index > 0
# Delete 1 text character
password_array = @password.split(//)
@password = ""
for i in 0...password_array.size-1
@password += password_array[i]
end
@index -= 1
refresh
update_cursor_rect
end
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
# Draw password
password_array = @password.split(//)
for i in 0...@max_char
c = password_array[i]
if c == nil
c = "-"
end
x = (i + 1) * 20
self.contents.font.name = Password_Input::FNAME1
self.contents.font.size = Password_Input::FSIZE1
self.contents.font.color = text_color(Password_Input::FCLOR1)
if Password_Input::ICNNM
self.contents.draw_text(x + 12, 14, 22, 24, c, 1)
else
self.contents.draw_text(x - 20, 14, 22, 24, c, 1)
end
end
# Draw graphic
if Password_Input::ICNNM
draw_icon_graphic(Password_Input::CICON, 16, 38)
end
end
#--------------------------------------------------------------------------
# * Cursor Rectangle Update
#--------------------------------------------------------------------------
def update_cursor_rect
x = (@index + 1) * 20
if Password_Input::ICNNM
self.cursor_rect.set(x + 12, 14, 22, 24)
else
self.cursor_rect.set(x - 20, 14, 22, 24)
end
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
update_cursor_rect
end
end
#==============================================================================
# ** Window_PasswordInput
#==============================================================================
class Window_PasswordInput < Window_Base
CHARACTER_TABLE =
[
"A","B","C","D","E",
"K","L","M","N","O",
"U","V","W","X","Y",
" "," "," "," "," ",
"a","b","c","d","e",
"k","l","m","n","o",
"u","v","w","x","y",
" "," "," "," "," ",
"1","2","3","4","5",
"F","G","H","I","J",
"P","Q","R","S","T",
"Z"," "," "," "," ",
" "," "," "," "," ",
"f","g","h","i","j",
"p","q","r","s","t",
"z"," "," "," "," ",
" "," "," "," "," ",
"6","7","8","9","0",
]
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 0, 320, 352)
self.contents = Bitmap.new(width - 32, height - 32)
self.back_opacity = Password_Input::WINOP2
@index = 0
refresh
update_cursor_rect
end
#--------------------------------------------------------------------------
# * Text Character Acquisition
#--------------------------------------------------------------------------
def character
return CHARACTER_TABLE[@index]
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
for i in 0...90
x = 10 + i / 5 / 9 * 130 + i % 5 * 26
y = i / 5 % 9 * 32
self.contents.font.name = Password_Input::FNAME2
self.contents.font.size = Password_Input::FSIZE2
self.contents.font.color = text_color(Password_Input::FCLOR2)
self.contents.draw_text(x, y, 24, 26, CHARACTER_TABLE[i], 1)
end
self.contents.font.name = Password_Input::FNAME3
self.contents.font.size = Password_Input::FSIZE3
self.contents.font.color = text_color(Password_Input::FCLOR3)
self.contents.draw_text(238, 9 * 32, 38, 24, Password_Input::BUTTN1, 1)
end
#--------------------------------------------------------------------------
# * Cursor Rectangle Update
#--------------------------------------------------------------------------
def update_cursor_rect
# If cursor is positioned on [OK]
if @index >= 90
self.cursor_rect.set(238, 9 * 32, 38, 24)
# If cursor is positioned on anything other than [OK]
else
x = 10 + @index / 5 / 9 * 130 + @index % 5 * 26
y = @index / 5 % 9 * 32
self.cursor_rect.set(x, y, 24, 26)
end
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
# If cursor is positioned on [OK]
if @index >= 90
# Cursor down
if Input.trigger?(Input::DOWN)
$game_system.se_play($data_system.cursor_se)
@index -= 90
end
# Cursor up
if Input.repeat?(Input::UP)
$game_system.se_play($data_system.cursor_se)
@index -= 90 - 40
end
if Input.trigger?(Input::C)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Switch to map screen
$scene = Scene_Map.new
return
end
# If cursor is positioned on anything other than [OK]
else
# If right directional button is pushed
if Input.repeat?(Input::RIGHT)
# If directional button pressed down is not a repeat, or
# cursor is not positioned on the right edge
if Input.trigger?(Input::RIGHT) or
@index / 45 < 3 or @index % 5 < 4
# Move cursor to right
$game_system.se_play($data_system.cursor_se)
if @index % 5 < 4
@index += 1
else
@index += 45 - 4
end
if @index >= 90
@index -= 90
end
end
end
# If left directional button is pushed
if Input.repeat?(Input::LEFT)
# If directional button pressed down is not a repeat, or
# cursor is not positioned on the left edge
if Input.trigger?(Input::LEFT) or
@index / 45 > 0 or @index % 5 > 0
# Move cursor to left
$game_system.se_play($data_system.cursor_se)
if @index % 5 > 0
@index -= 1
else
@index -= 45 - 4
end
if @index < 0
@index += 90
end
end
end
# If down directional button is pushed
if Input.repeat?(Input::DOWN)
# Move cursor down
$game_system.se_play($data_system.cursor_se)
if @index % 45 < 40
@index += 5
else
@index += 90 - 40
end
end
# If up directional button is pushed
if Input.repeat?(Input::UP)
# If directional button pressed down is not a repeat, or
# cursor is not positioned on the upper edge
if Input.trigger?(Input::UP) or @index % 45 >= 5
# Move cursor up
$game_system.se_play($data_system.cursor_se)
if @index % 45 >= 5
@index -= 5
else
@index += 90
end
end
end
# If L or R button was pressed
if Input.repeat?(Input::L) or Input.repeat?(Input::R)
# Move capital / small
$game_system.se_play($data_system.cursor_se)
if @index < 45
@index += 45
else
@index -= 45
end
end
end
update_cursor_rect
end
end
else
#==============================================================================
# ** Scene_Password
#==============================================================================
class Scene_Password
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Execute transition
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
# Abort loop if screen is changed
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Disabled message
$game_temp.message_text = Password_Input::SCTXT
$game_system.se_play($data_system.buzzer_se)
# Switch to map screen
$scene = Scene_Map.new
return
end
end
end
(password,switch)" to call it.
I added "SWITCH" as a default switch if the user didn't enter the "switch" in Password_Input.