Commit e9c3391f authored by 神楽坂玲奈's avatar 神楽坂玲奈

登陆界面输入框响应enter

parent 15b9ddaf
#encoding: UTF-8
class Replay
User_Filter = /(.+?)\((\d+)\)(?:\(\d+:\d+:\d+\))?(?::|:) */
User_Filter = /(.+?)(?:\((\d+)\))?(?:\(\d+:\d+:\d+\))?(?::|:) */
Delimiter = /^#{User_Filter}\n ?/
Player_Filter = /#{Delimiter}\[\d+\] ◎→/
Opponent_Filter =/#{Delimiter}\[\d+\] ●→/
......@@ -27,8 +27,8 @@ class Replay
require 'cgi'
contents = CGI.unescape_html(contents)
else
result.player1 = User.new($2.to_i, $1) if contents =~ Player_Filter
result.player2 = User.new($2.to_i, $1) if contents =~ Opponent_Filter
result.player1 = User.new($2 ? $2.to_i : :player, $1) if contents =~ Player_Filter
result.player2 = User.new($2 ? $2.to_i : :opponent, $1) if contents =~ Opponent_Filter
from_players = contents.scan(Delimiter).collect do |matched|
id = matched[1].to_i
name = matched[0]
......@@ -52,6 +52,10 @@ class Replay
result.player2 ||= User.new(1, "对手")
lines = contents.split(Delimiter)
lines.shift #split后,在第一个操作之前会多出一个空白元素
if from_players.empty?
Game_Event.push Game_Event::Error.new("播放战报", "战报无法识别")
return []
end
lines = lines.each_slice(lines.size/from_players.size).collect{|a|a.last.strip}
from_players = from_players.to_enum
result.actions = lines.collect do |action_str|
......
......@@ -39,7 +39,6 @@ begin
$screen = Screen.open($config['screen']['width'], $config['screen']['height'], 0, HWSURFACE | ($config['screen']['fullscreen'] ? FULLSCREEN : 0))
Mixer.open(Mixer::DEFAULT_FREQUENCY,Mixer::DEFAULT_FORMAT,Mixer::DEFAULT_CHANNELS,512)
TTF.init
#设置标准输出编码(windows)
STDOUT.set_encoding "GBK", "UTF-8", :invalid => :replace, :undef => :replace if RUBY_PLATFORM["win"] || RUBY_PLATFORM["ming"]
......
......@@ -104,7 +104,7 @@ class Scene
case event
when Game_Event::Error
$game.exit if $game
Widget_Msgbox.new(event.title, event.message, :ok => "确定"){$scene = Scene_Title.new if event.fatal}
Widget_Msgbox.new(event.title, event.message, :ok => "确定"){$scene = Scene_Login.new if event.fatal}
else
$log.debug('未处理的游戏事件'){event.inspect}
end
......
......@@ -27,6 +27,7 @@ class Scene_Duel < Scene
@deck = deck
end
def start
WM::set_caption("MyCard - #{$config['game']} - #{$game.user.name}(#{$game.user.id}) - #{@room.name}(#{@room.id})", "MyCard")
@bgm = Mixer::Music.load "audio/bgm/duel.ogg"
Mixer.fade_in_music(@bgm, -1, 800)
@background = Surface.load("graphics/field/main.png").display_format
......
......@@ -13,6 +13,7 @@ class Scene_Lobby < Scene
require_relative 'chatmessage'
attr_reader :chat_window
def start
WM::set_caption("MyCard - #{$config['game']} - #{$game.user.name}(#{$game.user.id})", "MyCard")
$game.refresh
@background = Surface.load("graphics/lobby/background.png").display_format
Surface.blit(@background,0,0,0,0,$screen,0,0)
......@@ -93,7 +94,7 @@ class Scene_Lobby < Scene
end
def update
if @count >= 300
if @count >= 600
$game.refresh
@count = 0
end
......
......@@ -9,6 +9,7 @@ require_relative 'window_login'
require_relative 'scene_replay'
class Scene_Login < Scene
def start
WM::set_caption("MyCard", "MyCard")
@background = Surface.load("graphics/login/background.png").display_format
@gameselect_window = Window_GameSelect.new(117,269,$config["game"])
end
......@@ -27,4 +28,7 @@ class Scene_Login < Scene
super
end
end
#def terminate
# @gameselect_window.destroy
#end
end
\ No newline at end of file
......@@ -8,6 +8,7 @@ require_relative 'scene'
require_relative 'window_title'
class Scene_Title < Scene
def start
WM::set_caption("MyCard", "MyCard")
title = Dir.glob("graphics/titles/title_*.*")
title = title[rand(title.size)]
@background = Surface.load(title).display_format
......
......@@ -16,16 +16,16 @@ class Widget_InputBox < Window
@@entry = TkEntry.new(@@root){
font @@font
validate :focusout
validatecommand{@@active.value=get.encode("UTF-8");@@root.withdraw(true);@@active.refresh;true}
validatecommand {Widget_InputBox.determine}
bind('Key-Return'){self.value="" if @@active.proc.call(get.encode("UTF-8")) if @@active.proc;true} #两个if的解释:当存在proc时,call那个proc,如果执行结果为真就清空value
pack
}
Thread.new{Tk.mainloop}
def initialize(x,y,width,height,z=300, &block)
def initialize(x,y,width,height,z=300, &proc)
super(x,y,width,height,z)
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 20)
@proc = block
@proc = proc
@value = ""
@type = :text
end
......@@ -36,7 +36,7 @@ class Widget_InputBox < Window
end
def refresh
clear
@font.draw_blended_utf8(@contents, @type == :password ? '*' * @value.size : @value, 0, 0, 0x00, 0x00, 0x00) unless @value.empty?
@font.draw_blended_utf8(@contents, @type == :password ? '*' * @value.size : @value, 2, 0, 0x00, 0x00, 0x00) unless @value.empty?
end
def clicked
@@entry.value = @value
......@@ -51,4 +51,7 @@ class Widget_InputBox < Window
@contents.fill_rect(x,y,width,height,0x66FFFFFF)
@contents.fill_rect(x+2,y+2,width-4,height-4,0xFFFFFFFF)
end
def self.determine
@@active.value=@@entry.get.encode("UTF-8");@@root.withdraw(true);@@active.refresh;true
end
end
......@@ -4,7 +4,7 @@ class Window_CardInfo < Window
def initialize(x,y)
super(x,y,1024-x,524,300)
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 16)
self.card = nil
self.card = Game_Card.new Card.find(1)#new 'name' => :test, 'number' => :"000000", 'lore' => "test2", 'card_type' => :通常魔法, 'stats' => "", 'archettypes' => "", "mediums" => "", "tokens" => ""
end
def card=(card)
return if card.nil? or card == @card or !card.known?
......
......@@ -3,11 +3,11 @@
#------------------------------------------------------------------------------
#  title
#==============================================================================
require_relative 'widget_scrollbar'
require_relative 'widget_inputbox'
require_relative 'chatmessage'
class Window_Chat < Window_List
WLH=16
require_relative 'widget_scrollbar'
require_relative 'widget_inputbox'
User_Color = [0,0,0xFF]
Text_Color = [0,0,0]
Player_Color = [0,0,0xFF]
......
......@@ -60,4 +60,8 @@ class Window_GameSelect < Window_List
@login_window.destroy if @login_window
@login_window = Window_Login.new(316,316,$config[$config['game']]["username"],$config[$config['game']]["password"])
end
#def destroy
# @login_window.destroy if @login_window
# super
#end
end
......@@ -8,9 +8,9 @@ class Window_Login < Window
@password = password
@button = Surface.load("graphics/login/button.png")
super(x,y,597,338)
@username_inputbox = Widget_InputBox.new(@x+192, @y+80, 165, WLH)
@username_inputbox = Widget_InputBox.new(@x+192, @y+80, 165, WLH){@password_inputbox.clicked;false}
@username ? @username_inputbox.value = @username : @username_inputbox.refresh
@password_inputbox = Widget_InputBox.new(@x+192, @y+125, 165, WLH)
@password_inputbox = Widget_InputBox.new(@x+192, @y+125, 165, WLH){Widget_InputBox.determine;self.index=:login;clicked;false}
@password_inputbox.type = :password
@password ? @password_inputbox.value = @password : @password_inputbox.refresh
@color = [255,255,255]
......@@ -66,4 +66,9 @@ class Window_Login < Window
draw_item(@index, item_rect(@index), 1)
end
end
#def destroy
# @username_inputbox.destroy
# @password_inputbox.destroy
# super
#end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment