#==============================================================================
# ■ Scene_Login
#------------------------------------------------------------------------------
# 处理用户登录的类。
#==============================================================================
class Scene_Login
#--------------------------------------------------------------------------
# ● 初始化对像
#--------------------------------------------------------------------------
def initialize
@mouse_press_register = false # 注册按钮
@mouse_press_login = false # 登录按钮
@focus_index = 1 #焦点
@get_focus = false #获得焦点
@textcursor_count = 0 # 用来控制光标闪烁
@textcursor_index = 0 # 用来控制光标位置
@text_index = 0 # 字符计数
# 在文件不存在的情况下创建默认的测试帐号
filename = "Data/Message.log"
unless FileTest.exist?(filename)
newuser = {"test"=>["gm","gm","gm"]}
file = File.open(filename, "wb")
Marshal.dump(newuser, file)
file.close
end
end
#--------------------------------------------------------------------------
# ● 主处理
#--------------------------------------------------------------------------
def main
# 载入数据库
$data_actors = load_data("Data/Actors.rxdata")
$data_classes = load_data("Data/Classes.rxdata")
$data_skills = load_data("Data/Skills.rxdata")
$data_items = load_data("Data/Items.rxdata")
$data_weapons = load_data("Data/Weapons.rxdata")
$data_armors = load_data("Data/Armors.rxdata")
$data_enemies = load_data("Data/Enemies.rxdata")
$data_troops = load_data("Data/Troops.rxdata")
$data_states = load_data("Data/States.rxdata")
$data_animations = load_data("Data/Animations.rxdata")
$data_tilesets = load_data("Data/Tilesets.rxdata")
$data_common_events = load_data("Data/CommonEvents.rxdata")
$data_system = load_data("Data/System.rxdata")
# 生成系统对像
$game_system = Game_System.new
# 生成背景图形
@sprite_back = Sprite.new
@sprite_back.bitmap = RPG::Cache.picture("用户登录.png")
# 生成登录按钮
@sprite_login = Sprite.new
@sprite_login.bitmap = RPG::Cache.picture("登录1.png")
@sprite_login.x = 320
@sprite_login.y = 300
# 生成注册按钮
@sprite_register = Sprite.new
@sprite_register.bitmap = RPG::Cache.picture("注册1.png")
@sprite_register.x = 400
@sprite_register.y = 300
# 生成文本光标
@sprite_textcursor = Sprite.new
@sprite_textcursor.bitmap = RPG::Cache.picture("文本光标.png")
@sprite_textcursor.x = 247
@sprite_textcursor.y = 200
@sprite_textcursor.opacity = 0
@login_window = Window_Login.new
# 执行过渡
Graphics.transition
# 主循环
loop do
# 刷新游戏画面
Graphics.update
# 刷新输入情报
Mouse.update
# 刷新画面
update
# 如果画面切换的话就中断循环
if $scene != self
break
end
end
# 准备过渡
Graphics.freeze
# 释放窗口
@sprite_back.dispose
@sprite_back.bitmap.dispose
@sprite_login.dispose
@sprite_login.bitmap.dispose
@sprite_register.dispose
@sprite_register.bitmap.dispose
@sprite_textcursor.dispose
@sprite_textcursor.bitmap.dispose
@login_window.dispose
end
#--------------------------------------------------------------------------
# ● 刷新画面
#--------------------------------------------------------------------------
def update
# 在获得焦点的情况下监听键盘输入
if @get_focus == true
listen_keyboard_input
# 按TAB键切换光标位置
if Kboard.keyboard($R_Key_TAB)
case @focus_index
when 1
@focus_index = 2
@textcursor_index = $password.length
@text_index = $password.length
when 2
@focus_index = 1
@textcursor_index = $username.length
@text_index = $username.length
end
end
end
if @get_focus == true # 在获得焦点的情况下刷新文本光标
if @textcursor_count%40 < 20 # 每秒钟刷新一次
@sprite_textcursor.opacity = 0
else
@sprite_textcursor.opacity = 255
end
# 刷新光标位置,因为背景图片的文本框没有对齐,所以设置比较麻烦
@sprite_textcursor.x = 247 + @textcursor_index * 10 # 8为每个字符的间距
case @focus_index
when 1
@sprite_textcursor.y = 200
when 2
@sprite_textcursor.y = 200 + 53
end
@textcursor_count += 1
else
@sprite_textcursor.opacity = 0
end
mouse_x,mouse_y = Mouse.get_mouse_pos
Mouse.click_lock
# 用户登录
if (mouse_x > @sprite_login.x) and (mouse_y > @sprite_login.y) and
(mouse_x < @sprite_login.x + @sprite_login.bitmap.width) and
(mouse_y < @sprite_login.y + @sprite_login.bitmap.height)
Mouse.click_unlock
@sprite_login.bitmap = RPG::Cache.picture("登录2.png")
if Mouse.press?(Mouse::LEFT)
@sprite_login.bitmap = RPG::Cache.picture("登录3.png")
@mouse_press_login = true
return
end
if Input.trigger?(Input::C)
@sprite_login.bitmap = RPG::Cache.picture("登录3.png")
@mouse_press_login = true
return
end
if @mouse_press_login
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
# 读取数据库
filename = "Data/Message.log"
file = File.open(filename, "r")
user_info = Marshal.load(file)
file.close
if $username.length <= 0 #如果用户名为空
p "请输入用户名"
@mouse_press_login = false
return
end
if $password.length <= 0 #如果密码为空
p "请输入密码"
@mouse_press_login = false
return
end
if user_info.include?($username.to_s)
if $password.to_s == user_info[$username.to_s][0]
$scene = Scene_Title.new
else
p "密码错误"
end
else
p "用户名不存在"
end
# 移动场景
$game_temp.player_transferring = true
$game_temp.player_new_map_id = (23)
$game_temp.player_new_x = (10)
$game_temp.player_new_y = (7)
$game_temp.player_new_direction = 0
@mouse_press_login = false
end
else
Mouse.click_lock
@sprite_login.bitmap = RPG::Cache.picture("登录1.png")
@mouse_press_login = false
end
# 用户名注册
if (mouse_x > @sprite_register.x) and (mouse_y > @sprite_register.y) and
(mouse_x < @sprite_register.x + @sprite_register.bitmap.width) and
(mouse_y < @sprite_register.y + @sprite_register.bitmap.height)
Mouse.click_unlock
@sprite_register.bitmap = RPG::Cache.picture("注册2.png")
if Mouse.press?(Mouse::LEFT)
@sprite_register.bitmap = RPG::Cache.picture("注册3.png")
@mouse_press_register = true
return
end
if @mouse_press_register
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
$scene = Scene_Register.new
@mouse_press_register = false
end
else
Mouse.click_lock
@sprite_register.bitmap = RPG::Cache.picture("注册1.png")
@mouse_press_register = false
end
# 用户名文本框区域
if (mouse_x > 248 - 5) and (mouse_y > 202 - 10) and
(mouse_x < 475 + 5) and (mouse_y < 220)
Mouse.click_unlock
$mouse_tag = "text"
if Mouse.trigger?(Mouse::LEFT)
@get_focus = true
@focus_index = 1
@textcursor_index = $username.length
@text_index = $username.length
end
return
else
Mouse.click_lock
$mouse_tag = nil
end
# 密码文本框区域
if (mouse_x > 248 - 5) and (mouse_y > 255 - 10) and
(mouse_x < 475 + 5) and (mouse_y < 272)
Mouse.click_unlock
$mouse_tag = "text"
if Mouse.trigger?(Mouse::LEFT)
@get_focus = true
@focus_index = 2
@textcursor_index = $password.length
@text_index = $password.length
end
return
else
Mouse.click_lock
$mouse_tag = nil
end
end
############################################################################
# 监听键盘输入
def listen_keyboard_input
case @focus_index
when 1
# 字母A
if Kboard.keyboard($R_Key_A)
if $username.length >= 15
return
end
$username[@text_index] = "a"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母B
if Kboard.keyboard($R_Key_B)
if $username.length >= 15
return
end
$username[@text_index] = "b"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母C
if Kboard.keyboard($R_Key_C)
if $username.length >= 15
return
end
$username[@text_index] = "c"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母D
if Kboard.keyboard($R_Key_D)
if $username.length >= 15
return
end
$username[@text_index] = "d"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母E
if Kboard.keyboard($R_Key_E)
if $username.length >= 15
return
end
$username[@text_index] = "e"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母F
if Kboard.keyboard($R_Key_F)
if $username.length >= 15
return
end
$username[@text_index] = "f"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母G
if Kboard.keyboard($R_Key_G)
if $username.length >= 15
return
end
$username[@text_index] = "g"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母H
if Kboard.keyboard($R_Key_H)
if $username.length >= 15
return
end
$username[@text_index] = "h"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母I
if Kboard.keyboard($R_Key_I)
if $username.length >= 15
return
end
$username[@text_index] = "i"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母J
if Kboard.keyboard($R_Key_J)
if $username.length >= 15
return
end
$username[@text_index] = "j"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母K
if Kboard.keyboard($R_Key_K)
if $username.length >= 15
return
end
$username[@text_index] = "k"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母L
if Kboard.keyboard($R_Key_L)
if $username.length >= 15
return
end
$username[@text_index] = "l"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母M
if Kboard.keyboard($R_Key_M)
if $username.length >= 15
return
end
$username[@text_index] = "m"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母N
if Kboard.keyboard($R_Key_N)
if $username.length >= 15
return
end
$username[@text_index] = "n"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母O
if Kboard.keyboard($R_Key_O)
if $username.length >= 15
return
end
$username[@text_index] = "o"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母P
if Kboard.keyboard($R_Key_P)
if $username.length >= 15
return
end
$username[@text_index] = "p"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母Q
if Kboard.keyboard($R_Key_Q)
if $username.length >= 15
return
end
$username[@text_index] = "q"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母R
if Kboard.keyboard($R_Key_R)
if $username.length >= 15
return
end
$username[@text_index] = "r"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母S
if Kboard.keyboard($R_Key_S)
if $username.length >= 15
return
end
$username[@text_index] = "s"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母T
if Kboard.keyboard($R_Key_T)
if $username.length >= 15
return
end
$username[@text_index] = "t"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母U
if Kboard.keyboard($R_Key_U)
if $username.length >= 15
return
end
$username[@text_index] = "u"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母V
if Kboard.keyboard($R_Key_V)
if $username.length >= 15
return
end
$username[@text_index] = "v"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母W
if Kboard.keyboard($R_Key_W)
if $username.length >= 15
return
end
$username[@text_index] = "w"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母X
if Kboard.keyboard($R_Key_X)
if $username.length >= 15
return
end
$username[@text_index] = "x"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母Y
if Kboard.keyboard($R_Key_Y)
if $username.length >= 15
return
end
$username[@text_index] = "y"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母Z
if Kboard.keyboard($R_Key_Z)
if $username.length >= 15
return
end
$username[@text_index] = "z"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 数字0
if Kboard.keyboard($R_Key_0) or Kboard.keyboard($R_Key_NUMPAD0)
if $username.length >= 15
return
end
$username[@text_index] = "0"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 数字1
if Kboard.keyboard($R_Key_1) or Kboard.keyboard($R_Key_NUMPAD1)
if $username.length >= 15
return
end
$username[@text_index] = "1"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 数字2
if Kboard.keyboard($R_Key_2) or Kboard.keyboard($R_Key_NUMPAD2)
if $username.length >= 15
return
end
$username[@text_index] = "2"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 数字3
if Kboard.keyboard($R_Key_3) or Kboard.keyboard($R_Key_NUMPAD3)
if $username.length >= 15
return
end
$username[@text_index] = "3"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 数字4
if Kboard.keyboard($R_Key_4) or Kboard.keyboard($R_Key_NUMPAD4)
if $username.length >= 15
return
end
$username[@text_index] = "4"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 数字5
if Kboard.keyboard($R_Key_5) or Kboard.keyboard($R_Key_NUMPAD5)
if $username.length >= 15
return
end
$username[@text_index] = "5"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 数字6
if Kboard.keyboard($R_Key_6) or Kboard.keyboard($R_Key_NUMPAD6)
if $username.length >= 15
return
end
$username[@text_index] = "6"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 数字7
if Kboard.keyboard($R_Key_7) or Kboard.keyboard($R_Key_NUMPAD7)
if $username.length >= 15
return
end
$username[@text_index] = "7"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 数字8
if Kboard.keyboard($R_Key_8) or Kboard.keyboard($R_Key_NUMPAD8)
if $username.length >= 15
return
end
$username[@text_index] = "8"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 数字9
if Kboard.keyboard($R_Key_9) or Kboard.keyboard($R_Key_NUMPAD9)
if $username.length >= 15
return
end
$username[@text_index] = "9"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 删除键
if Kboard.keyboard($R_Key_BACK)
if $username.length > 0
$username.pop
@textcursor_index -= 1
@text_index -= 1
@login_window.refresh
end
end
when 2
# 字母A
if Kboard.keyboard($R_Key_A)
if $password.length >= 15
return
end
$password[@text_index] = "a"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母B
if Kboard.keyboard($R_Key_B)
if $password.length >= 15
return
end
$password[@text_index] = "b"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母C
if Kboard.keyboard($R_Key_C)
if $password.length >= 15
return
end
$password[@text_index] = "c"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母D
if Kboard.keyboard($R_Key_D)
if $password.length >= 15
return
end
$password[@text_index] = "d"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母E
if Kboard.keyboard($R_Key_E)
if $password.length >= 15
return
end
$password[@text_index] = "e"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母F
if Kboard.keyboard($R_Key_F)
if $password.length >= 15
return
end
$password[@text_index] = "f"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母G
if Kboard.keyboard($R_Key_G)
if $password.length >= 15
return
end
$password[@text_index] = "g"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母H
if Kboard.keyboard($R_Key_H)
if $password.length >= 15
return
end
$password[@text_index] = "h"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母I
if Kboard.keyboard($R_Key_I)
if $password.length >= 15
return
end
$password[@text_index] = "i"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母J
if Kboard.keyboard($R_Key_J)
if $password.length >= 15
return
end
$password[@text_index] = "j"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母K
if Kboard.keyboard($R_Key_K)
if $password.length >= 15
return
end
$password[@text_index] = "k"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母L
if Kboard.keyboard($R_Key_L)
if $password.length >= 15
return
end
$password[@text_index] = "l"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母M
if Kboard.keyboard($R_Key_M)
if $password.length >= 15
return
end
$password[@text_index] = "m"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母N
if Kboard.keyboard($R_Key_N)
if $password.length >= 15
return
end
$password[@text_index] = "n"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母O
if Kboard.keyboard($R_Key_O)
if $password.length >= 15
return
end
$password[@text_index] = "o"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母P
if Kboard.keyboard($R_Key_P)
if $password.length >= 15
return
end
$password[@text_index] = "p"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母Q
if Kboard.keyboard($R_Key_Q)
if $password.length >= 15
return
end
$password[@text_index] = "q"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母R
if Kboard.keyboard($R_Key_R)
if $password.length >= 15
return
end
$password[@text_index] = "r"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母S
if Kboard.keyboard($R_Key_S)
if $password.length >= 15
return
end
$password[@text_index] = "s"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母T
if Kboard.keyboard($R_Key_T)
if $password.length >= 15
return
end
$password[@text_index] = "t"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母U
if Kboard.keyboard($R_Key_U)
if $password.length >= 15
return
end
$password[@text_index] = "u"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母V
if Kboard.keyboard($R_Key_V)
if $password.length >= 15
return
end
$password[@text_index] = "v"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母W
if Kboard.keyboard($R_Key_W)
if $password.length >= 15
return
end
$password[@text_index] = "w"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母X
if Kboard.keyboard($R_Key_X)
if $password.length >= 15
return
end
$password[@text_index] = "x"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母Y
if Kboard.keyboard($R_Key_Y)
if $password.length >= 15
return
end
$password[@text_index] = "y"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 字母Z
if Kboard.keyboard($R_Key_Z)
if $password.length >= 15
return
end
$password[@text_index] = "z"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 数字0
if Kboard.keyboard($R_Key_0) or Kboard.keyboard($R_Key_NUMPAD0)
if $password.length >= 15
return
end
$password[@text_index] = "0"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 数字1
if Kboard.keyboard($R_Key_1) or Kboard.keyboard($R_Key_NUMPAD1)
if $password.length >= 15
return
end
$password[@text_index] = "1"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 数字2
if Kboard.keyboard($R_Key_2) or Kboard.keyboard($R_Key_NUMPAD2)
if $password.length >= 15
return
end
$password[@text_index] = "2"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 数字3
if Kboard.keyboard($R_Key_3) or Kboard.keyboard($R_Key_NUMPAD3)
if $password.length >= 15
return
end
$password[@text_index] = "3"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 数字4
if Kboard.keyboard($R_Key_4) or Kboard.keyboard($R_Key_NUMPAD4)
if $password.length >= 15
return
end
$password[@text_index] = "4"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 数字5
if Kboard.keyboard($R_Key_5) or Kboard.keyboard($R_Key_NUMPAD5)
if $password.length >= 15
return
end
$password[@text_index] = "5"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 数字6
if Kboard.keyboard($R_Key_6) or Kboard.keyboard($R_Key_NUMPAD6)
if $password.length >= 15
return
end
$password[@text_index] = "6"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 数字7
if Kboard.keyboard($R_Key_7) or Kboard.keyboard($R_Key_NUMPAD7)
if $password.length >= 15
return
end
$password[@text_index] = "7"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 数字8
if Kboard.keyboard($R_Key_8) or Kboard.keyboard($R_Key_NUMPAD8)
if $password.length >= 15
return
end
$password[@text_index] = "8"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 数字9
if Kboard.keyboard($R_Key_9) or Kboard.keyboard($R_Key_NUMPAD9)
if $password.length >= 15
return
end
$password[@text_index] = "9"
@textcursor_index += 1
@text_index += 1
@login_window.refresh
end
# 删除键
if Kboard.keyboard($R_Key_BACK)
if $password.length > 0
$password.pop
@textcursor_index -= 1
@text_index -= 1
@login_window.refresh
end
end
end
end
end