Commit 17ae1837 authored by 神楽坂玲奈's avatar 神楽坂玲奈

0.8.1

parent 1e26242c
...@@ -9,6 +9,9 @@ module Config ...@@ -9,6 +9,9 @@ module Config
config['bgm'] = true if config['bgm'].nil? config['bgm'] = true if config['bgm'].nil?
config['screen'] ||= {} config['screen'] ||= {}
config['screen']['width'], config['screen']['height'] = Resolution.default unless Resolution.all.include? [config['screen']['width'], config['screen']['height']] config['screen']['width'], config['screen']['height'] = Resolution.default unless Resolution.all.include? [config['screen']['width'], config['screen']['height']]
config['i18n'] ||= {}
config['i18n']['locale'] ||= "#{Locale.current.language}-#{Locale.current.region}"
I18n.locale = config['i18n']['locale']
config config
end end
def save(config=$config, file="config.yml") def save(config=$config, file="config.yml")
......
#游戏事件的抽象类 #游戏事件的抽象类
class Game_Event class Game_Event
@queue = [] @queue = []
def self.push(event) def self.push(event)
@queue << event @queue << event
end end
def self.poll def self.poll
@queue.shift @queue.shift
end end
def self.parse(info, *args) def self.parse(info, *args)
#适配器定义 #适配器定义
end end
...@@ -14,14 +17,16 @@ class Game_Event ...@@ -14,14 +17,16 @@ class Game_Event
class Login < Game_Event class Login < Game_Event
attr_reader :user attr_reader :user
def initialize(user) def initialize(user)
@user = user @user = user
$game.user = @user $game.user = @user
end end
end end
class AllUsers < Game_Event class AllUsers < Game_Event
attr_reader :users attr_reader :users
def initialize(users) def initialize(users)
@users = [] @users = []
users.each do |user| users.each do |user|
...@@ -34,9 +39,10 @@ class Game_Event ...@@ -34,9 +39,10 @@ class Game_Event
$game.users.replace @users $game.users.replace @users
end end
end end
class NewUser < AllUsers class NewUser < AllUsers
attr_reader :users attr_reader :users
def initialize(user) def initialize(user)
@user = user @user = user
unless $game.users.include? @user unless $game.users.include? @user
...@@ -51,6 +57,7 @@ class Game_Event ...@@ -51,6 +57,7 @@ class Game_Event
class MissingUser < AllUsers class MissingUser < AllUsers
attr_reader :users attr_reader :users
def initialize(user) def initialize(user)
@user = user @user = user
$game.users.delete @user $game.users.delete @user
...@@ -59,14 +66,27 @@ class Game_Event ...@@ -59,14 +66,27 @@ class Game_Event
class AllRooms < Game_Event class AllRooms < Game_Event
attr_reader :rooms attr_reader :rooms
def initialize(rooms) def initialize(rooms)
@rooms = rooms @rooms = rooms
$game.rooms.replace @rooms $game.rooms.replace @rooms
$game.rooms.sort_by! { |room| [room.status == :start ? 1 : 0, room.private ? 1 : 0, room.id] }
end
end
class RoomsUpdate < AllRooms
attr_reader :rooms
def initialize(rooms)
@rooms = rooms
$game.rooms.replace $game.rooms | @rooms
$game.rooms.delete_if { |room| room._deleted }
$game.rooms.sort_by! { |room| [room.status == :start ? 1 : 0, room.private ? 1 : 0, room.id] }
end end
end end
class NewRoom < AllRooms class NewRoom < AllRooms
attr_reader :room attr_reader :room
def initialize(room) def initialize(room)
@room = room @room = room
unless $game.rooms.include? @room unless $game.rooms.include? @room
...@@ -80,6 +100,7 @@ class Game_Event ...@@ -80,6 +100,7 @@ class Game_Event
end end
class MissingRoom < AllRooms class MissingRoom < AllRooms
attr_reader :room attr_reader :room
def initialize(room) def initialize(room)
@room = room @room = room
$game.rooms.delete @room $game.rooms.delete @room
...@@ -87,9 +108,9 @@ class Game_Event ...@@ -87,9 +108,9 @@ class Game_Event
end end
class Chat < Game_Event class Chat < Game_Event
attr_reader :chatmessage attr_reader :chatmessage
def initialize(chatmessage) def initialize(chatmessage)
@chatmessage = chatmessage @chatmessage = chatmessage
end end
...@@ -97,8 +118,9 @@ class Game_Event ...@@ -97,8 +118,9 @@ class Game_Event
class Join < Game_Event class Join < Game_Event
attr_reader :room attr_reader :room
def initialize(room) def initialize(room)
@room = room @room = room
$game.room = @room $game.room = @room
end end
end end
...@@ -106,8 +128,9 @@ class Game_Event ...@@ -106,8 +128,9 @@ class Game_Event
end end
class Watch < Game_Event class Watch < Game_Event
attr_reader :room attr_reader :room
def initialize(room) def initialize(room)
@room = room @room = room
$game.room = @room $game.room = @room
end end
end end
...@@ -117,8 +140,9 @@ class Game_Event ...@@ -117,8 +140,9 @@ class Game_Event
end end
class PlayerJoin < Game_Event class PlayerJoin < Game_Event
attr_reader :user attr_reader :user
def initialize(user) def initialize(user)
@user = user @user = user
$game.room.player2 = @user $game.room.player2 = @user
end end
end end
...@@ -130,20 +154,22 @@ class Game_Event ...@@ -130,20 +154,22 @@ class Game_Event
class Action < Game_Event class Action < Game_Event
attr_reader :action, :str attr_reader :action, :str
def initialize(action, str=action.escape) def initialize(action, str=action.escape)
@action = action @action = action
@str = str @str = str
end end
end end
class Error < Game_Event class Error < Game_Event
attr_reader :title, :message, :fatal attr_reader :title, :message, :fatal
def initialize(title, message, fatal=true) def initialize(title, message, fatal=true)
@title = title @title = title
@message = message @message = message
@fatal = fatal @fatal = fatal
$log.error(@fatal ? "致命错误" : "一般错误"){"#{@title}: #{@message} #{caller}"} $log.error(@fatal ? "致命错误" : "一般错误") { "#{@title}: #{@message} #{caller}" }
end end
end end
class Unknown < Error class Unknown < Error
......
...@@ -21,12 +21,12 @@ class User ...@@ -21,12 +21,12 @@ class User
end end
def avatar(size = :small) def avatar(size = :small)
cache = "graphics/avatars/#{@id}_#{size}.png" cache = "graphics/avatars/#{@id}_#{size}.png"
result = Surface.load(cache) rescue Surface.load("graphics/avatars/loading_#{size}.gif") result = Surface.load(cache) rescue Surface.load("graphics/avatars/loading_#{size}.png")
scene = $scene scene = $scene
if block_given? if block_given?
yield result yield result
Thread.new do Thread.new do
open("http://www.duelcn.com/uc_server/avatar.php?uid=#{id-100000}&size=#{size}", 'rb') {|io|open(cache, 'wb') {|c|c.write io.read}} rescue cache = "graphics/avatars/noavatar_#{size}.gif" open("http://www.duelcn.com/uc_server/avatar.php?uid=#{id-100000}&size=#{size}", 'rb') {|io|open(cache, 'wb') {|c|c.write io.read}} rescue cache = "graphics/avatars/error_#{size}.png"
(yield Surface.load(cache) if scene == $scene) rescue nil (yield Surface.load(cache) if scene == $scene) rescue nil
end end
else else
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
begin begin
Windows = RUBY_PLATFORM["win"] || RUBY_PLATFORM["ming"] Windows = RUBY_PLATFORM["win"] || RUBY_PLATFORM["ming"]
Dir.glob('post_update_*.rb').sort.each { |file| load file }
Thread.abort_on_exception = true Thread.abort_on_exception = true
require_relative 'resolution' require_relative 'resolution'
...@@ -9,30 +10,36 @@ begin ...@@ -9,30 +10,36 @@ begin
require_relative 'config' require_relative 'config'
require_relative 'association' require_relative 'association'
#i18n
require 'i18n'
require 'locale'
I18n.load_path += Dir['locales/*.yml']
I18n::Backend::Simple.include(I18n::Backend::Fallbacks)
#读取配置文件 #读取配置文件
$config = Config.load $config = Config.load
Config.save Config.save
#读取命令行参数 #读取命令行参数
log = "log.log" log = "log.log"
log_level = "INFO" log_level = "INFO"
profile = nil profile = nil
ARGV.each do |arg| ARGV.each do |arg|
arg = arg.dup.force_encoding("UTF-8") arg = arg.dup.force_encoding("UTF-8")
arg.force_encoding("GBK") unless arg.valid_encoding? arg.force_encoding("GBK") unless arg.valid_encoding?
case arg case arg
when /--log=(.*)/ when /--log=(.*)/
log.replace $1 log.replace $1
when /--log-level=(.*)/ when /--log-level=(.*)/
log_level.replace $1 log_level.replace $1
when /--profile=(.*)/ when /--profile=(.*)/
profile = $1 profile = $1
when /^mycard:.*|\.ydk$|\.yrp$|\.deck$/ when /^mycard:.*|\.ydk$|\.yrp$|\.deck$/
require_relative 'quickstart' require_relative 'quickstart'
$scene = false $scene = false
when /register_association/ when /register_association/
Association.register Association.register
$scene = false $scene = false
end end
end end
...@@ -51,7 +58,7 @@ begin ...@@ -51,7 +58,7 @@ begin
if log == "STDOUT" #调试用 if log == "STDOUT" #调试用
log = STDOUT log = STDOUT
end end
$log = Logger.new(log) $log = Logger.new(log)
$log.level = Logger.const_get log_level $log.level = Logger.const_get log_level
#性能分析 #性能分析
...@@ -63,7 +70,7 @@ begin ...@@ -63,7 +70,7 @@ begin
end end
require 'profiler' require 'profiler'
RubyVM::InstructionSequence.compile_option = { RubyVM::InstructionSequence.compile_option = {
:trace_instruction => true, :trace_instruction => true,
:specialized_instruction => false :specialized_instruction => false
} }
Profiler__::start_profile Profiler__::start_profile
...@@ -71,13 +78,13 @@ begin ...@@ -71,13 +78,13 @@ begin
SDL::Event::APPMOUSEFOCUS = 1 SDL::Event::APPMOUSEFOCUS = 1
SDL::Event::APPINPUTFOCUS = 2 SDL::Event::APPINPUTFOCUS = 2
SDL::Event::APPACTIVE = 4 SDL::Event::APPACTIVE = 4
SDL.putenv ("SDL_VIDEO_CENTERED=1"); SDL.putenv ("SDL_VIDEO_CENTERED=1");
SDL.init(INIT_VIDEO) SDL.init(INIT_VIDEO)
WM::set_caption("MyCard", "MyCard") WM::set_caption("MyCard", "MyCard")
WM::icon = Surface.load("graphics/system/icon.gif") WM::icon = Surface.load("graphics/system/icon.gif")
$screen = Screen.open($config['screen']['width'], $config['screen']['height'], 0, HWSURFACE | ($config['screen']['fullscreen'] ? FULLSCREEN : 0)) $screen = Screen.open($config['screen']['width'], $config['screen']['height'], 0, HWSURFACE | ($config['screen']['fullscreen'] ? FULLSCREEN : 0))
TTF.init TTF.init
#声音 #声音
......
...@@ -49,7 +49,9 @@ case file ...@@ -49,7 +49,9 @@ case file
require 'uri' require 'uri'
$game.user = User.new($1.to_sym, $1) if $1 $game.user = User.new($1.to_sym, $1) if $1
$game.password = $2 if $2 $game.password = $2 if $2
$game.server = $3 room = Room.new(0, $5)
$game.port = $4.to_i room.server_ip = $3
Ygocore.run_ygocore Room.new(0, $5), true room.server_port = $4.to_i
room.server_auth = true if $2
Ygocore.run_ygocore room, true
end end
\ No newline at end of file
...@@ -2,7 +2,7 @@ require_relative 'cacheable' ...@@ -2,7 +2,7 @@ require_relative 'cacheable'
class Room class Room
Color = [[0,0,0], [255,0,0], [0,128,0], [0,0,255], [255, 165, 0]] Color = [[0,0,0], [255,0,0], [0,128,0], [0,0,255], [255, 165, 0]]
extend Cacheable extend Cacheable
attr_accessor :id, :name, :player1, :player2, :private, :color, :forbid attr_accessor :id, :name, :player1, :player2, :private, :color, :forbid, :_deleted
attr_accessor :password attr_accessor :password
def initialize(id, name="等待更新", player1=nil, player2=nil, private=false, color=[0,0,0], session = nil, forbid = nil) def initialize(id, name="等待更新", player1=nil, player2=nil, private=false, color=[0,0,0], session = nil, forbid = nil)
@id = id @id = id
...@@ -30,6 +30,9 @@ class Room ...@@ -30,6 +30,9 @@ class Room
def extra def extra
{} {}
end end
def status
player2 ? :start : :wait
end
alias full? player2 alias full? player2
alias private? private alias private? private
end end
\ No newline at end of file
...@@ -2,7 +2,7 @@ require 'open-uri' ...@@ -2,7 +2,7 @@ require 'open-uri'
require "fileutils" require "fileutils"
require_relative 'card' require_relative 'card'
module Update module Update
Version = '0.7.4' Version = '0.8.1'
URL = "http://my-card.in/mycard/update.json?version=#{Version}" URL = "http://my-card.in/mycard/update.json?version=#{Version}"
class <<self class <<self
attr_reader :thumbnails, :images, :status attr_reader :thumbnails, :images, :status
......
...@@ -4,7 +4,7 @@ class Widget_Msgbox < Window ...@@ -4,7 +4,7 @@ class Widget_Msgbox < Window
class <<self class <<self
alias old_new new alias old_new new
def new(title, message, buttons={}, &proc) def new(title, message, buttons={}, &proc)
if instance = $scene.windows.find{|window|window.class == self and !window.destroyed?} if instance = $scene.windows.find{|window|window.class == self and !window.destroyed?} rescue nil
instance.set(title, message, buttons, &proc) instance.set(title, message, buttons, &proc)
instance instance
else else
......
...@@ -2,91 +2,111 @@ class Window ...@@ -2,91 +2,111 @@ class Window
WLH = 24 WLH = 24
attr_accessor :x, :y, :width, :height, :z, :contents, :visible, :viewport, :background attr_accessor :x, :y, :width, :height, :z, :contents, :visible, :viewport, :background
alias visible? visible alias visible? visible
def initialize(x, y, width, height, z=200) def initialize(x, y, width, height, z=200)
@x = x @x = x
@y = y @y = y
@z = z @z = z
@width = width @width = width
@height = height @height = height
@visible = true @visible = true
#@angle = 0 #@angle = 0
@viewport = [0, 0, @width, @height] @viewport = [0, 0, @width, @height]
@destroyed = false @destroyed = false
amask = 0xff000000 amask = 0xff000000
rmask = 0x00ff0000 rmask = 0x00ff0000
gmask = 0x0000ff00 gmask = 0x0000ff00
bmask = 0x000000ff bmask = 0x000000ff
#@background ||= Surface.new(SWSURFACE, @width, @height, 32, rmask, gmask, bmask, amask) #@background ||= Surface.new(SWSURFACE, @width, @height, 32, rmask, gmask, bmask, amask)
@contents ||= Surface.new(SWSURFACE, @width, @height, 32, rmask, gmask, bmask, amask) @contents ||= Surface.new(SWSURFACE, @width, @height, 32, rmask, gmask, bmask, amask)
#按Z坐标插入 #按Z坐标插入
unless $scene.windows.each_with_index do |window, index| unless $scene.windows.each_with_index do |window, index|
if window.z > @z if window.z > @z
$scene.windows.insert(index, self) $scene.windows.insert(index, self)
break true break true
end end
end == true end == true
$scene.windows << self $scene.windows << self
end end
end
def center_margin(text, width, font=@font)
(width - font.text_size(text)[0]) /2
end end
def draw_stroked_text(text,x,y,size=1,font=@font,color=@color,color_stroke=@color_stroke)
[[x-size,y-size], [x-size,y], [x-size,y+size], def draw_stroked_text(text, x, y, size=1, font=@font, color=@color, color_stroke=@color_stroke)
[x,y-size], [x,y+size], [[x-size, y-size], [x-size, y], [x-size, y+size],
[x+size,y-size], [x+size,y], [x+size,y+size], [x, y-size], [x, y+size],
].each{|pos|font.draw_blended_utf8(@contents, text, pos[0], pos[1], *color)} [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) font.draw_blended_utf8(@contents, text, x, y, *color_stroke)
end end
def include?(x,y)
def include?(x, y)
x >= @x && x < @x + @width && y >= @y && y < @y + @height x >= @x && x < @x + @width && y >= @y && y < @y + @height
end end
def destroy def destroy
@destroyed = true @destroyed = true
@contents.destroy if @contents @contents.destroy if @contents
$scene.windows.delete self if $scene $scene.windows.delete self if $scene
end end
def destroyed? def destroyed?
@destroyed @destroyed
end end
def draw(screen) def draw(screen)
return unless self.contents && self.visible? && !self.destroyed? return unless self.contents && self.visible? && !self.destroyed?
Surface.blit(self.contents, *self.viewport, screen, self.x, self.y) Surface.blit(self.contents, *self.viewport, screen, self.x, self.y)
end end
def clear(x=0, y=0, width=@width, height=@height) def clear(x=0, y=0, width=@width, height=@height)
if @background if @background
Surface.blit(@background,x,y,width,height,@contents,x,y) Surface.blit(@background, x, y, width, height, @contents, x, y)
elsif $scene and $scene.background elsif $scene and $scene.background
Surface.blit($scene.background,@x+x,@y+y,width,height,@contents,x,y) Surface.blit($scene.background, @x+x, @y+y, width, height, @contents, x, y)
else else
@contents.fill_rect(x,y,width,height,0xFF000000) @contents.fill_rect(x, y, width, height, 0xFF000000)
end end
end end
def update def update
#子类定义 #子类定义
end end
def refresh def refresh
#子类定义 #子类定义
end end
def mousemoved(x,y)
def mousemoved(x, y)
#子类定义 #子类定义
end end
def clicked def clicked
#子类定义 #子类定义
end end
def mouseleftbuttonup def mouseleftbuttonup
#子类定义 #子类定义
end end
def lostfocus(active_window=nil) def lostfocus(active_window=nil)
#子类定义 #子类定义
end end
def cursor_up(wrap=false) def cursor_up(wrap=false)
#子类定义 #子类定义
end end
def cursor_down(wrap=false) def cursor_down(wrap=false)
#子类定义 #子类定义
end end
def scroll_up def scroll_up
cursor_up cursor_up
end end
def scroll_down def scroll_down
cursor_down cursor_down
end end
......
...@@ -27,7 +27,7 @@ class Window_Chat < Window_Scrollable ...@@ -27,7 +27,7 @@ class Window_Chat < Window_Scrollable
if !@chat_input.value.empty? if !@chat_input.value.empty?
chatmessage = ChatMessage.new($game.user, @chat_input.value, @channel) chatmessage = ChatMessage.new($game.user, @chat_input.value, @channel)
$game.chat chatmessage $game.chat chatmessage
Game_Event.push Game_Event::Chat.new(chatmessage) if $game.show_chat_self Game_Event.push Game_Event::Chat.new(chatmessage)# if $game.show_chat_self
true true
end end
end end
......
...@@ -42,7 +42,7 @@ class Window_Config < Window ...@@ -42,7 +42,7 @@ class Window_Config < Window
when :avatar_cache when :avatar_cache
size = 0 size = 0
count = 0 count = 0
Dir.glob("graphics/avatars/*_*.png") do |file| Dir.glob("graphics/avatars/*").reject{|file|File.basename(file) =~ /(?:error|loading)_(?:small|middle|large)\.png/}.each do |file|
count += 1 count += 1
size += File.size(file) size += File.size(file)
end end
...@@ -105,7 +105,7 @@ class Window_Config < Window ...@@ -105,7 +105,7 @@ class Window_Config < Window
draw_item(@index, 1) draw_item(@index, 1)
when :avatar_cache when :avatar_cache
#clear(*item_rect(@index)) #clear(*item_rect(@index))
Dir.glob("graphics/avatars/*_*.png") do |file| Dir.glob("graphics/avatars/*").reject{|file|File.basename(file) =~ /(?:error|loading)_(?:small|middle|large)\.png/}.each do |file|
File.delete file File.delete file
end end
refresh refresh
......
require_relative 'window_host' require_relative 'window_host'
class Window_LobbyButtons < Window_List class Window_LobbyButtons < Window_List
def initialize(x, y) def initialize(x, y)
@items = ["常见问题", "卡组编辑", "建立房间"] @items = [I18n.t('lobby.faq'), I18n.t('lobby.editdeck'), I18n.t('lobby.newroom')]
@button = Surface.load("graphics/lobby/button.png") @button = Surface.load("graphics/lobby/button.png")
super(x, y, @items.size*@button.w/3+@items.size*4, 30) super(x, y, @items.size*@button.w/3+@items.size*4, 30)
@font = TTF.open("fonts/wqy-microhei.ttc", 15) @font = TTF.open("fonts/wqy-microhei.ttc", 15)
...@@ -9,9 +9,9 @@ class Window_LobbyButtons < Window_List ...@@ -9,9 +9,9 @@ class Window_LobbyButtons < Window_List
end end
def draw_item(index, status=0) def draw_item(index, status=0)
x, y=item_rect(index) x, y, width=item_rect(index)
Surface.blit(@button, status*@button.w/3, 0, @button.w/3, @button.h, @contents, x, y) Surface.blit(@button, status*@button.w/3, 0, @button.w/3, @button.h, @contents, x, y)
draw_stroked_text(@items[index], x+8, y+3, 2, @font, [0xdf, 0xf1, 0xff], [0x27, 0x43, 0x59]) draw_stroked_text(@items[index], x+center_margin(@items[index],width,@font), y+3, 2, @font, [0xdf, 0xf1, 0xff], [0x27, 0x43, 0x59])
end end
def item_rect(index) def item_rect(index)
......
...@@ -45,23 +45,23 @@ class Window_Login < Window ...@@ -45,23 +45,23 @@ class Window_Login < Window
:replay => [378,200,@button.w/3,@button.h] :replay => [378,200,@button.w/3,@button.h]
} }
@items_text = { @items_text = {
:login => "登录", :login => I18n.t("login.login"),
:register => "注册", :register => I18n.t("login.register"),
:replay => "录像" :replay => I18n.t("login.replay"),
} }
#self.index = nil #self.index = nil
@remember_password = Widget_Checkbox.new(self, 357+@x,80+@y,self.width-357,24,password,"记住密码") @remember_password = Widget_Checkbox.new(self, 357+@x,80+@y,self.width-357,24,password,I18n.t('login.remember'))
refresh refresh
end end
def refresh def refresh
clear clear
@items.each_pair{|index, rect|draw_item(index, rect)} @items.each_pair{|index, rect|draw_item(index, rect)}
draw_stroked_text("用户名", 105,80+2,1) draw_stroked_text(I18n.t('login.name'), 105,80+2,1)
draw_stroked_text("密码", 105,125+2,1) draw_stroked_text(I18n.t('login.password'), 105,125+2,1)
end end
def draw_item(index, rect, status=0) def draw_item(index, rect, status=0)
Surface.blit(@button,rect[2]*status,0,rect[2],rect[3],@contents,rect[0],rect[1]) Surface.blit(@button,rect[2]*status,0,rect[2],rect[3],@contents,rect[0],rect[1])
draw_stroked_text(@items_text[index], rect[0]+24, rect[1]+9,1,@font_button) draw_stroked_text(@items_text[index], rect[0] + center_margin(@items_text[index], rect[2], @font_button), rect[1]+9,1,@font_button)
end end
def mousemoved(x,y) def mousemoved(x,y)
self.index = @items.each_pair{|index, rect|break index if (x-@x >= rect[0] and x-@x < rect[0]+rect[2] and y-@y >= rect[1] and y-@y < rect[1]+rect[3])} self.index = @items.each_pair{|index, rect|break index if (x-@x >= rect[0] and x-@x < rect[0]+rect[2] and y-@y >= rect[1] and y-@y < rect[1]+rect[3])}
......
...@@ -26,10 +26,9 @@ class Window_RoomList < Window_Scrollable ...@@ -26,10 +26,9 @@ class Window_RoomList < Window_Scrollable
y = item_rect(index)[1] y = item_rect(index)[1]
room = @items[index] room = @items[index]
Surface.blit(@button, @width*status, room.full? ? WLH : 0, @width, WLH, @contents, 0, y) Surface.blit(@button, @width*status, room.full? ? WLH : 0, @width, WLH, @contents, 0, y)
@font.draw_blended_utf8(@contents, room.id.to_s, 24, y+8, *@color) @font.draw_blended_utf8(@contents, room.id.to_s, 24, y+8, *@color) unless room.id.to_s.empty?
@font.draw_blended_utf8(@contents, room.full? ? "【决斗中】" : room.private? ? "【私密房】" : "【等待中】", 8, y+24, *@color) @font.draw_blended_utf8(@contents, room.full? ? "【决斗中】" : room.private? ? "【私密房】" : "【等待中】", 8, y+24, *@color)
@font.draw_blended_utf8(@contents, room.name, 128, y+8, *room.color) unless room.name.empty? or room.name.size > 100 @font.draw_blended_utf8(@contents, room.name, 128, y+8, *room.color) unless room.name.nil? or room.name.empty? or room.name.size > 100
$log.error('标题过长') {room.name} if room.name.size > 100
@font.draw_blended_utf8(@contents, room.player1.name, 128, y+24, *room.player1.color) if room.player1 and !room.player1.name.empty? @font.draw_blended_utf8(@contents, room.player1.name, 128, y+24, *room.player1.color) if room.player1 and !room.player1.name.empty?
@font.draw_blended_utf8(@contents, room.player2.name, 320, y+24, *room.player2.color) if room.player2 and !room.player2.name.empty? @font.draw_blended_utf8(@contents, room.player2.name, 320, y+24, *room.player2.color) if room.player2 and !room.player2.name.empty?
room.extra.each_with_index do |extra, index| room.extra.each_with_index do |extra, index|
......
...@@ -7,20 +7,10 @@ class Game_Event ...@@ -7,20 +7,10 @@ class Game_Event
else else
Error.new('登录', '用户名或密码错误') Error.new('登录', '用户名或密码错误')
end end
#when :users
# AllUsers.new data.collect{|user|parse_user(user)}
when :rooms when :rooms
rooms_wait = [] AllRooms.new data.collect{|room|parse_room(room)}
rooms_start = [] when :rooms_update
data.each do |room| RoomsUpdate.new data.collect{|room|parse_room(room)}
room = parse_room(room)
if room.full?
rooms_start << room
else
rooms_wait << room
end
end
AllRooms.new rooms_wait + rooms_start
#when :newuser #when :newuser
#NewUser.new parse_user data #NewUser.new parse_user data
#when :missinguser #when :missinguser
...@@ -29,13 +19,13 @@ class Game_Event ...@@ -29,13 +19,13 @@ class Game_Event
NewRoom.new parse_room data NewRoom.new parse_room data
when :missingroom when :missingroom
MissingRoom.new parse_room data MissingRoom.new parse_room data
#when :chat when :chat
# case data[:channel] case data[:channel]
# when :lobby when :lobby
# Chat.new ChatMessage.new User.new(data[:from][:id],data[:from][:name]), data[:message], :lobby Chat.new ChatMessage.new User.new(data[:from][:id],data[:from][:name]), data[:message], :lobby
# else else
# Chat.new ChatMessage.new User.new(data[:from][:id],data[:from][:name]), data[:message], User.new(data[:channel]) Chat.new ChatMessage.new User.new(data[:from][:id],data[:from][:name]), data[:message], User.new(data[:channel])
# end end
end end
end end
def self.parse_room(room) def self.parse_room(room)
...@@ -49,6 +39,11 @@ class Game_Event ...@@ -49,6 +39,11 @@ class Game_Event
result.ot = room[:ot] result.ot = room[:ot]
result.status = room[:status] result.status = room[:status]
result.lp = room[:lp] result.lp = room[:lp]
result._deleted = room[:_deleted]
result.server_id = room[:server_id]
result.server_ip = room[:server_ip]
result.server_port = room[:server_port]
result.server_auth = room[:server_auth]
result result
end end
def self.parse_user(user) def self.parse_user(user)
......
This diff is collapsed.
...@@ -5,6 +5,7 @@ class Room ...@@ -5,6 +5,7 @@ class Room
attr_accessor :ot attr_accessor :ot
attr_accessor :lp attr_accessor :lp
attr_accessor :status attr_accessor :status
attr_accessor :server_id, :server_ip, :server_port, :server_auth
alias pvp? pvp alias pvp? pvp
alias match? match alias match? match
alias tag? tag alias tag? tag
......
register: http://my-card.in/register register: http://my-card.in/register
api: http://122.0.65.71:7922/ api: http://master.smdcn.net:7922/
index: http://my-card.in/ index: http://my-card.in/
server: 122.0.65.71 server: 122.0.65.70
port: 7911 port: 7911
\ No newline at end of file
...@@ -22,13 +22,13 @@ class User ...@@ -22,13 +22,13 @@ class User
end end
def avatar(size = :small) def avatar(size = :small)
cache = "graphics/avatars/mycard_#{@id}_#{size}.png" cache = "graphics/avatars/mycard_#{@id}_#{size}.png"
result = Surface.load(cache) rescue Surface.load("graphics/avatars/loading_#{size}.gif") result = Surface.load(cache) rescue Surface.load("graphics/avatars/loading_#{size}.png")
scene = $scene scene = $scene
if block_given? if block_given?
yield result yield result
Thread.new do Thread.new do
require 'cgi' require 'cgi'
open("http://my-card.in/users/#{CGI.escape @id.to_s}.png", 'rb') {|io|open(cache, 'wb') {|c|c.write io.read}} rescue cache = "graphics/avatars/noavatar_#{size}.gif" open("http://my-card.in/users/#{CGI.escape @id.to_s}.png", 'rb') {|io|open(cache, 'wb') {|c|c.write io.read}} rescue cache = "graphics/avatars/error_#{size}.png"
(yield Surface.load(cache) if scene == $scene) rescue nil (yield Surface.load(cache) if scene == $scene) rescue nil
end end
else else
......
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