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

登陆,临时提交

parent b33ab42f
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
......@@ -4,7 +4,7 @@
begin
#读取配置文件
require 'yaml'
$config = YAML.load_file("config.yml") rescue YAML.load_file("data/config_default.yml")
$config = YAML.load_file("config.yml")
#初始化SDL
require 'sdl'
......
name: 局域网
\ No newline at end of file
......@@ -4,16 +4,20 @@
#------------------------------------------------------------------------------
#  login
#==============================================================================
require_relative 'window_gameselect'
require_relative 'window_login'
class Scene_Login < Scene
Vocab_Logging = "Logging"
def start
#@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 24)
if $config["autologin"]
@username = $config["username"]
@password = $config["password"]
login
end
#if $config["autologin"]
# @username = $config["username"]
# @password = $config["password"]
# login
#end
@background = Surface.load("graphics/login/background.png")
@gameselect_window = Window_GameSelect.new(117,269)
@login_window = Window_Login.new(316,316,$config["username"],$config["password"])
end
def login
#@font.draw_blended_utf8($screen, Vocab_Logging, 0,0,255,0,255)
......@@ -24,12 +28,12 @@ class Scene_Login < Scene
$game = Iduel.new
$game.login(@username, @password)
end
def update
while event = Game_Event.poll
handle_game(event)
end
super
end
#def update
#while event = Game_Event.poll
# handle_game(event)
#end
#super
#end
def handle_game(event)
case event
when Game_Event::Login
......
class Widget_InputBox < Window
attr_accessor :text, :proc
attr_reader :value, :proc
attr_accessor :type
require 'tk'
@@font = TkFont.new("family" => 'WenQuanYi Micro Hei',
"size" => 15) #这字号尼玛?!
@@root=TkRoot.new {
@@font = TkFont.new(
"family" => 'WenQuanYi Micro Hei',
"size" => 15 #这字号尼玛?!
)
@@root=TkRoot.new{
withdraw
overrideredirect true
attributes :topmost, true
......@@ -12,31 +15,40 @@ class Widget_InputBox < Window
@@entry = TkEntry.new(@@root){
font @@font
validate :focusout
validatecommand{@@active.text.replace(get);@@root.withdraw(true);@@active.refresh;true}
bind('Key-Return'){@@active.proc.call(get);delete(0, get.size);@@root.withdraw(true);true}
validatecommand{@@active.value=get;@@root.withdraw(true);@@active.refresh;true}
bind('Key-Return'){self.value="" if @@active.proc.call(get) if @@active.proc;true} #两个if的解释:当存在proc时,call那个proc,如果执行结果为真就清空value
pack
}
Thread.new{Tk.mainloop}
def initialize(x,y,width,height,z=300, &block)
super(x,y,width,height,z)
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 20)
@proc = block
@text = ""
@value = ""
@type = :text
end
def value=(value)
return if @value == value
@value = value
refresh
end
def refresh
@contents.fill_rect(0,0,@width,@height,0x66000000)
@font.draw_blended_utf8(@contents, @text, 0, 0, 0xFF, 0xFF, 0xFF) unless @text.empty?
clear
@font.draw_blended_utf8(@contents, @type == :password ? '*' * @value.size : @value, 0, 0, 0x00, 0x00, 0x00) unless @value.empty?
end
def mousemoved(x,y)
end
def clicked
@@active = self
@@root.geometry "#{@width}x#{@height}+#{@x+TkWinfo.pointerx(@@root)-Mouse.state[0]}+#{@y+TkWinfo.pointery(@@root)-Mouse.state[1]}"
@@entry.text @text
@@entry.width @width
@@root.deiconify
@@entry.value = @value
@@entry.show @type == :password ? '*' : nil
@@entry.focus :force
@@root.geometry "#{@width}x#{@height}+#{@x+TkWinfo.pointerx(@@root)-Mouse.state[0]}+#{@y+TkWinfo.pointery(@@root)-Mouse.state[1]}" #根据鼠标位置来确定游戏窗口的相对位置,点击的瞬间鼠标移动了的话会有误差
@@root.deiconify
@@active = self #TODO:存在线程安全问题
end
def clear(x=0, y=0, width=@width, height=@height)
@contents.fill_rect(x,y,width,height,0x66FFFFFF)
@contents.fill_rect(x+2,y+2,width-4,height-4,0xFFFFFFFF)
end
end
......@@ -52,8 +52,11 @@ class Window
end
end
def clear(x=0, y=0, width=@width, height=@height)
#Surface.blit(@background, x,y,width,height,@contents,x,y)
contents.fill_rect(x,y,width,height,0x66000000)
if $scene.background
Surface.blit($scene.background,@x+x,@y+y,width,height,@contents,x,y)
else
@contents.fill_rect(x,y,width,height,0xFF000000)
end
end
def update
#子类定义
......
#encoding: UTF-8
class Window_GameSelect < Window_List
WLH = 56
def initialize(x,y)
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 24)
@color = [255,255,255]
@game_color = [47,156,192]
@game_stroke_color = [0xFF,0xFF,0xFF]
@list = []
Dir.glob('lib/**/game.yml') do |file|
game = YAML.load_file(file)
if game.is_a?(Hash) && game["name"]
@list << game
else
$log.warn "#{game.inspect}读取失败(#{file})"
end
end
super(x,y,160,@list.size*WLH)
clear
@button = Surface.load("graphics/login/game_background.png")
#@button.set_alpha(RLEACCEL,255)
self.list = @list
end
def draw_item(index, status=0)
Surface.blit(@button, 0, 0, @button.w, @button.h, @contents, 0, WLH*index)
draw_stroked_text(@list[index]["name"], 24, WLH*index+14, 2)
end
def draw_stroked_text(text,x,y,size=1)
[[x-size,y-size], [x-size,y], [x-size,y+size],
[x,y-size], [x,y+size],
[x+size,y-size], [x+size,y], [x+size,y+size],
].each{|pos|@font.draw_blended_utf8(@contents, text, pos[0], pos[1], *@game_stroke_color)}
@font.draw_blended_utf8(@contents, text, x, y, *@game_color)
end
end
#encoding: UTF-8
require_relative 'widget_inputbox'
class Window_Login < Window
def initialize(x,y,username=nil, password=nil)
@username = username
@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.value = @username
@password_inputbox = Widget_InputBox.new(@x+192, @y+125, 165, WLH)
@password_inputbox.type = :password
@password_inputbox.value = @password
@color = [255,255,255]
@color_stroke = [0,0,0]
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 16)
@font_button = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 18)
draw_stroked_text("用户名", 105,80+2,1)
draw_stroked_text("密码", 105,125+2,1)
#@font.draw_blended_utf8(@contents, text, 105,80, *@game_color)
@items = {
#:username => [192,80,165,WLH],
#:password => [192,125,165,WLH],
:login => [192,200,80,36],
:register => [285,200,80,36]
}
@items_text = {
:login => "登陆",
:register => "注册"
}
self.index = nil
refresh
end
def draw_stroked_text(text,x,y,size=1,font=@font)
[[x-size,y-size], [x-size,y], [x-size,y+size],
[x,y-size], [x,y+size],
[x+size,y-size], [x+size,y], [x+size,y+size],
].each{|pos|font.draw_blended_utf8(@contents, text, pos[0], pos[1], *@color)}
font.draw_blended_utf8(@contents, text, x, y, *@color_stroke)
end
def refresh
clear
@items.each_pair{|index, rect|draw_item(index, rect)}
end
def draw_item(index, rect, status=0)
Surface.blit(@button,0,0,rect[2],rect[3],@contents,rect[0],rect[1])
draw_stroked_text(@items_text[index], rect[0]+20, rect[1]+9,1,@font_button)
end
def mousemoved(x,y)
@items.each_pair{|index, rect|
#p index, x >= rect[0] and x < rect[0]+rect[2] and y >= rect[1] and y < rect[1]+rect[3]
#p x,y,rect[0], rect[0]+rect[2], rect[1], rect[1]+rect[3]
p @x+x >= rect[0] and @x+x < rect[0]+rect[2] and @y+y >= rect[1] and @y+y < rect[1]+rect[3]
return self.index = index if true #@x+x >= rect[0] and @x+x < rect[0]+rect[2] and @y+y >= rect[1] and @y+y < rect[1]+rect[3]
}
end
def index=(index)
#return if @index == index
p index
@index = index
end
def clicked
case @index
when :login
$game = Iduel.new
$game.login(@username_inputbox.value, @password_inputbox.value)
when :register
require 'launchy'
Launchy.open("http://google.com")
end
end
end
File added
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