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

filter

parent 6abbb711
This diff was suppressed by a .gitattributes entry.
......@@ -3,12 +3,15 @@ require_relative 'game_event'
require_relative 'action'
require_relative 'user'
require_relative 'room'
require_relative 'server'
class Game
attr_reader :users, :rooms
attr_reader :users, :rooms, :servers, :filter
attr_accessor :user, :room, :player_field, :opponent_field, :turn, :turn_player, :phase
def initialize
@users = []
@rooms = []
@servers = []
@filter = {servers: [], waiting_only: false, normal_only: false}
end
def login(username, password=nil)
end
......
......@@ -40,6 +40,13 @@ class Game_Event
end
end
class AllServers < Game_Event
attr_reader :servers
def initialize(servers)
$game.servers.replace servers
end
end
class NewUser < AllUsers
attr_reader :users
......
......@@ -11,6 +11,7 @@ class Scene_Lobby < Scene
require_relative 'window_roomlist'
require_relative 'window_chat'
require_relative 'window_host'
require_relative 'window_filter'
require_relative 'window_lobbybuttons'
require_relative 'chatmessage'
require_relative 'scene_duel'
......@@ -62,7 +63,9 @@ class Scene_Lobby < Scene
when Game_Event::AllUsers
@userlist.items = $game.users
when Game_Event::AllRooms
@roomlist.items = $game.rooms
@roomlist.items = $game.rooms.find_all{|room|$game.filter[:servers].collect{|server|server.id}.include?(room.server_id)}
when Game_Event::AllServers
@roomlist.items = $game.rooms.find_all{|room|$game.filter[:servers].collect{|server|server.id}.include?(room.server_id)}
when Game_Event::Join
join(event.room)
when Game_Event::Watch
......
require_relative 'cacheable'
class Server
attr_accessor :id, :name, :ip, :port, :auth
extend Cacheable
def initialize(id, name="", ip="", port=0, auth=false)
@id = id
@name = name
@ip = ip
@port = port
@auth = auth
end
def set(id, name=:keep, ip=:keep, port=:keep, auth=:keep)
@id = id
@name = name unless name == :keep
@ip = ip unless ip == :keep
@port = name unless port == :keep
@auth = name unless auth == :keep
end
end
\ No newline at end of file
......@@ -2,137 +2,41 @@ class Window_Filter < Window
attr_reader :index
def initialize(x,y)
@background = Surface.load('graphics/lobby/filter.png').display_format
super((1024-@background.w)/2, 230, @background.w, @background.h)
super(x,y, @background.w, @background.h)
@font = TTF.open("fonts/wqy-microhei.ttc", 16)
@color = [0x04, 0x47, 0x7c]
@title_color = [0xFF, 0xFF, 0xFF]
[]
@pvp = Widget_Checkbox.new(self, 33+@x,@y+41+WLH*2,120,24,false,"竞技场") {|checked|(@ocg.checked = true; @tcg.checked = @tag.checked = false; @lp_inputbox.value = "8000") if checked}
@pvp.background = @background.copy_rect(33,70,120,24)
@match = Widget_Checkbox.new(self, 120+@x,@y+41+WLH*2,120,24,true,"三回决斗"){|checked|@tag.checked = false if checked}
@match.background = @background.copy_rect(120,70,120,24)
@tag = Widget_Checkbox.new(self, 33+@x,@y+41+WLH*4+4,120,24,false,"TAG双打"){|checked|@pvp.checked = @match.checked = false if checked}
@tag.background = @background.copy_rect(120,70,120,24)
@ocg = Widget_Checkbox.new(self, 33+@x,@y+41+WLH*5+4,120,24,true,"OCG"){|checked|@tcg.checked = true if !checked}
@ocg.background = @background.copy_rect(120,70,120,24)
@tcg = Widget_Checkbox.new(self, 120+@x,@y+41+WLH*5+4,120,24,false,"TCG"){|checked|@pvp.checked = false if checked; @ocg.checked = true if !checked}
@tcg.background = @background.copy_rect(120,70,120,24)
@roomname_inputbox.value = rand(1000).to_s
@lp_inputbox.value = 8000.to_s
@password_inputbox.refresh
@pvp.refresh
@match.refresh
@tag.refresh
@ocg.refresh
@tcg.refresh
@servers = $game.servers.each_with_index.collect do |server, index|
result = Widget_Checkbox.new(self, 4+@x,@y+WLH+WLH*index,@width-8,24,true,server.name){|checked|checked ? $game.filter[:servers].push(server) : $game.filter[:servers].delete(server) ; Game_Event.push(Game_Event::AllRooms.new($game.rooms))}
result.background = @background.copy_rect(4,WLH+WLH*index,@width-8,24)
result.refresh
result
end
@waiting_only = Widget_Checkbox.new(self, 4+@x,@y+WLH*7-4,@width-8,24,true, I18n.t('lobby.waiting_only')){|checked|$game.filter[:waiting_only] = checked; Game_Event.push(Game_Event::AllRooms.new($game.rooms))}
@waiting_only.background = @background.copy_rect(4,WLH*7-4,@width-8,24)
@waiting_only.checked = false
@waiting_only.refresh
@normal_only = Widget_Checkbox.new(self, 4+@x,@y+WLH*7+WLH-4,120,24,true,I18n.t('lobby.normal_only')){|checked|$game.filter[:normal_only] = checked; Game_Event.push(Game_Event::AllRooms.new($game.rooms))}
@normal_only.background = @background.copy_rect(4,WLH*7+WLH-4,120,24)
@normal_only.checked = false
@normal_only.refresh
refresh
end
def refresh
clear
@font.draw_blended_utf8(@contents, "建立房间", (@width-@font.text_size("建立房间")[0])/2, 2, *@title_color)
@font.draw_blended_utf8(@contents, "房间名", 33,43, *@color)
@font.draw_blended_utf8(@contents, "房间密码", 33,43+WLH, *@color)
@contents.fill_rect(4,43+WLH*3,@contents.w-8, 2, 0xAA0A7AC5)
@font.draw_blended_utf8(@contents, "自定义模式", 20,43+WLH*3+4, *@color)
@font.draw_blended_utf8(@contents, "初始LP", 33,44+WLH*6+4, *@color)
@items.each_key do |index|
draw_item(index, self.index==index ? 1 : 0)
end
end
def draw_item(index, status=0)
Surface.blit(@button,@button.w/3*status,0,@button.w/3,@button.h,@contents,@items[index][0],@items[index][1])
text_size = @font.text_size(@buttons[index])
@font.draw_blended_utf8(@contents, @buttons[index], @items[index][0]+(@button.w/3-text_size[0])/2, @items[index][1]+(@button.h-text_size[1])/2, 0xFF, 0xFF, 0xFF)
end
def mousemoved(x,y)
new_index = nil
@items.each_key do |index|
if (x - @x).between?(@items[index][0], @items[index][0]+@items[index][2]) and (y-@y).between?(@items[index][1], @items[index][1]+@items[index][3])
new_index = index
break
end
end
self.index = new_index
end
def item_rect(index)
@items[index]
end
def index=(index)
return if index == @index
if @index
clear(*item_rect(@index))
draw_item(@index, 0)
end
if index.nil? or !@items.include? index
@index = nil
else
@index = index
draw_item(@index, 1)
end
end
def clicked
case self.index
when :ok
if @roomname_inputbox.value.empty?
Widget_Msgbox.new("建立房间", "请输入房间名", ok: "确定" )
elsif !name_check
Widget_Msgbox.new("建立房间", "房间名/房间密码超过长度上限", ok: "确定")
elsif @lp_inputbox.value.to_i >= 99999
Widget_Msgbox.new("建立房间", "初始LP超过上限", ok: "确定")
else
Widget_Msgbox.new("建立房间", "正在建立房间")
destroy
$game.host(@roomname_inputbox.value, password: @password_inputbox.value, pvp: @pvp.checked?, match: @match.checked?, tag: @tag.checked?, ot: @tcg.checked? ? @ocg.checked? ? 2 : 1 : 0, lp: @lp_inputbox.value.to_i)
end
when :cancel
destroy
end
@font.draw_blended_utf8(@contents, "服务器", 4, 4, *@color)
@contents.fill_rect(4,WLH,@contents.w-8, 2, 0xAA0A7AC5)
@font.draw_blended_utf8(@contents, "房间属性", 4, WLH*6+4-4, *@color)
@contents.fill_rect(4,WLH*7-4,@contents.w-8, 2, 0xAA0A7AC5)
end
def destroy
@roomname_inputbox.destroy
@password_inputbox.destroy
@lp_inputbox.destroy
@pvp.destroy
@match.destroy
@tag.destroy
@ocg.destroy
@tcg.destroy
@servers.each{|server|server.destroy}
@normal_only.destroy
@waiting_only.destroy
super
end
def update
@roomname_inputbox.update
@password_inputbox.update
@lp_inputbox.update
end
def name_check
name = @roomname_inputbox.value
# P#/PM#/M#/T# 的总房名长度允许为13
# 其他情况下如果全英文,那么上限19,否则上限20
# TCG代码自定义房占15个字符
# 一个汉字两个字符,密码算在内
if @tcg.checked #代码自定义房
max = 5
max -= 1 if name.ascii_only?
elsif @pvp.checked or @match.checked or @tag.checked
# 去掉那个#占用的
max = 12
max -= 1 if @pvp.checked
max -= 1 if @match.checked
max -= 1 if @tag.checked
else
max = 20
max -= 1 if name.ascii_only?
end
max -= @lp_inputbox.value.size - 4
if !@password_inputbox.value.empty?
max -= 1
max -= @password_inputbox.value.encode("GBK").bytesize
end
max -= name.encode("GBK").bytesize
return max >= 0
end
end
end
\ No newline at end of file
......@@ -36,7 +36,11 @@ class Window_LobbyButtons < Window_List
require_relative 'dialog'
Dialog.web "http://my-card.in/login?user[name]=#{CGI.escape $game.user.name}&user[password]=#{CGI.escape $game.password}&continue=/topics/1453"
when 1 #房间筛选
if @filter_window and !@filter_window.destroyed?
@filter_window.destroy
else
@filter_window = Window_Filter.new(678, 44)
end
when 2 #卡组编辑
require_relative 'deck'
$game.class.deck_edit
......
......@@ -11,6 +11,10 @@ class Game_Event
AllRooms.new data.collect{|room|parse_room(room)}
when :rooms_update
RoomsUpdate.new data.collect{|room|parse_room(room)}
when :servers
servers = data.collect{|server|parse_server(server)}
$game.filter[:servers].concat (servers - $game.servers)
AllServers.new servers
#when :newuser
#NewUser.new parse_user data
#when :missinguser
......@@ -49,4 +53,7 @@ class Game_Event
def self.parse_user(user)
User.new(user[:id], user[:name], user[:certified])
end
def self.parse_server(server)
Server.new(server[:id], server[:name], server[:ip], server[:port], server[:auth])
end
end
......@@ -77,7 +77,7 @@ class Ygocore < Game
def connect
@recv = Thread.new do
EventMachine::run {
EventMachine::connect "mycard-server.my-card.in", 9997, Client
EventMachine::connect "localhost", 9997, Client
}
end
end
......@@ -137,9 +137,10 @@ class Ygocore < Game
room.password = room_config[:password]
room.ot = room_config[:ot]
room.lp = room_config[:lp]
room.server_ip = $game.server
room.server_port = $game.port
room.server_auth = true
server = @filter[:servers].sample || Server.new(nil, "", $game.server, $game.port, true)
room.server_ip = server.ip
room.server_port = server.port
room.server_auth = server.auth
if $game.rooms.any? { |game_room| game_room.name == room_name }
Widget_Msgbox.new("建立房间", "房间名已存在", :ok => "确定")
else
......
......@@ -16,4 +16,7 @@ en:
newroom: "建立房间"
lobby: "大厅"
filter: "房间筛选"
waiting_only: "仅等待中"
normal_only: "仅标准房"
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