Commit 3d02ed93 authored by 神楽坂玲奈's avatar 神楽坂玲奈

用户信息初步,头像下载优化

parent 2342d619
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
...@@ -10,13 +10,15 @@ class Iduel ...@@ -10,13 +10,15 @@ class Iduel
attr_accessor :user attr_accessor :user
attr_accessor :room_id attr_accessor :room_id
attr_accessor :key attr_accessor :key
attr_accessor :rooms
def initialize def initialize
require 'socket' require 'socket'
require 'digest/md5' require 'digest/md5'
require 'open-uri' require 'open-uri'
require_relative 'iduel_action' require_relative 'iduel_action'
require_relative 'iduel_event' require_relative 'iduel_event'
require_relative 'iduel_user'
require_relative 'iduel_room'
@conn = TCPSocket.open(Server, Port) @conn = TCPSocket.open(Server, Port)
@conn.set_encoding "GBK" @conn.set_encoding "GBK"
Thread.abort_on_exception = true Thread.abort_on_exception = true
...@@ -70,78 +72,4 @@ class Iduel ...@@ -70,78 +72,4 @@ class Iduel
def quit def quit
send(11, @key, checknum("ULO", "#{@session}")) send(11, @key, checknum("ULO", "#{@session}"))
end end
end
class Iduel::User
@@all = []
attr_accessor :id, :name, :level, :exp
class << self
alias old_new new
def new(id, name = "", level = nil, exp = nil)
if id.is_a? String and id =~ /(.*)\((\d+)\)/
id = $2.to_i
name=$1
else
id = id.to_i
end
user = @@all.find{|user| user.id == id }
if user
user.name = name if name
user.level = level if level
user.exp = exp if exp
user
else
user = old_new(id, name, level, exp)
@@all << user
user
end
end
end
def initialize(id, name = "", level = nil, exp = nil)
@id = id
@name = name
@level = level
@exp = exp
end
def avatar(size = :small)
cache = "graphics/avatars/#{@id}_#{size}.png"
Thread.new do
open("http://www.duelcn.com/uc_server/avatar.php?uid=#{id-100000}&size=#{size}", 'rb') do |io|
open(cache, 'wb') {|c|c.write io.read}
end rescue Thread.exit
yield Surface.load cache
end rescue p("http://www.duelcn.com/uc_server/avatar.php?uid=#{id-100000}&size=#{size}") if block_given?
Surface.load cache rescue Surface.load "graphics/avatars/noavatar_#{size}.gif"
end
end
class Iduel::Room
@@all = []
attr_accessor :id, :name, :player1, :player2, :private, :color
class << self
alias old_new new
def new(id, *args)
id = id.to_i
room = @@all.find{|room| room.id == id }
if room
room
else
room = old_new(id, *args)
@@all << room
room
end
end
end
def initialize(id, name, player1, player2, private, color, session = nil, forbid = nil)
@id =id
@name = name
@player1 = player1
@player2 = player2
@private = private
@color = color
@forbid = forbid
@session = session
end
alias full? player2
alias private? private
end end
\ No newline at end of file
...@@ -80,6 +80,7 @@ class Iduel::Event::RMIF < Iduel::Event ...@@ -80,6 +80,7 @@ class Iduel::Event::RMIF < Iduel::Event
end end
end end
@rooms = templist + @rooms @rooms = templist + @rooms
$iduel.rooms = @rooms
end end
end end
class Iduel::Event::NOL < Iduel::Event class Iduel::Event::NOL < Iduel::Event
...@@ -119,6 +120,7 @@ class Iduel::Event::SingleRoomInfo < Iduel::Event ...@@ -119,6 +120,7 @@ class Iduel::Event::SingleRoomInfo < Iduel::Event
@room = Iduel::Room.new(id) @room = Iduel::Room.new(id)
@room.player1 = Iduel::User.new(player1) @room.player1 = Iduel::User.new(player1)
@room.player2 = Iduel::User.new(player2) @room.player2 = Iduel::User.new(player2)
$iduel.rooms << @room unless $iduel.rooms.include? @room
end end
end end
#"Q" #"Q"
......
class Iduel::Room
@@all = []
attr_accessor :id, :name, :player1, :player2, :private, :color
class << self
alias old_new new
def new(id, *args)
id = id.to_i
room = @@all.find{|room| room.id == id }
if room
room
else
room = old_new(id, *args)
@@all << room
room
end
end
end
def initialize(id, name, player1, player2, private, color, session = nil, forbid = nil)
@id =id
@name = name
@player1 = player1
@player2 = player2
@private = private
@color = color
@forbid = forbid
@session = session
end
alias full? player2
alias private? private
end
\ No newline at end of file
class Iduel::User
@@all = []
attr_accessor :id, :name, :level, :exp
class << self
alias old_new new
def new(id, name = "", level = nil, exp = nil)
if id.is_a? String and id =~ /(.*)\((\d+)\)/
id = $2.to_i
name=$1
else
id = id.to_i
end
user = @@all.find{|user| user.id == id }
if user
user.name = name if name
user.level = level if level
user.exp = exp if exp
user
else
user = old_new(id, name, level, exp)
@@all << user
user
end
end
end
def initialize(id, name = "", level = nil, exp = nil)
@id = id
@name = name
@level = level
@exp = exp
end
def avatar(size = :small)
cache = "graphics/avatars/#{@id}_#{size}.png"
result = Surface.load(cache) rescue Surface.load("graphics/avatars/loading_#{size}.gif")
if block_given?
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"
yield Surface.load cache
end
yield result
else
result
end
end
def status
room = $iduel.rooms.find{|room|room.player1 == @user or room.player2 == @user}
result = case
when room.nil?
"等待中"
when room.player2
"房间#{room.id}决斗中"
else
"房间#{room.id}等待中"
end
result
end
end
\ No newline at end of file
#encoding: UTF-8 #encoding: UTF-8
alias gbk_puts puts alias gbk_puts puts
def puts(*args) def puts(*args)
gbk_puts(*(args.collect{|item|item.encode "GBK"})) gbk_puts(*(args.collect{|item|item.encode "UTF-8"}))
end end
def p(*args) def p(*args)
print(args.collect{|item|item.inspect.encode "GBK"}.join("\n")+"\n") rescue print(args.join("\n")+"\n") print(args.collect{|item|item.inspect.encode "UTF-8"}.join("\n")+"\n") rescue print(args.join("\n")+"\n")
end end
require 'sdl' require 'sdl'
include SDL include SDL
...@@ -17,7 +17,7 @@ $config = YAML.load_file("config.yml") rescue YAML.load_file("data/config_defaul ...@@ -17,7 +17,7 @@ $config = YAML.load_file("config.yml") rescue YAML.load_file("data/config_defaul
SDL.init(INIT_VIDEO | INIT_AUDIO) SDL.init(INIT_VIDEO | INIT_AUDIO)
WM::set_caption("iDuel - 享受决斗", "graphics/system/iDuelPanel_32512.ico") WM::set_caption("iDuel - 享受决斗", "graphics/system/iDuelPanel_32512.ico")
WM::icon = Surface.load("graphics/system/iDuelPanel_32512.ico") #WM::icon = Surface.load("graphics/system/iDuelPanel_32512.ico")
style = HWSURFACE style = HWSURFACE
style |= FULLSCREEN if $config["fullscreen"] style |= FULLSCREEN if $config["fullscreen"]
$screen = Screen.open($config["width"], $config["height"], 0, style) $screen = Screen.open($config["width"], $config["height"], 0, style)
...@@ -28,7 +28,9 @@ SDL::Mixer.open(Mixer::DEFAULT_FREQUENCY,Mixer::DEFAULT_FORMAT,Mixer::DEFAULT_CH ...@@ -28,7 +28,9 @@ SDL::Mixer.open(Mixer::DEFAULT_FREQUENCY,Mixer::DEFAULT_FORMAT,Mixer::DEFAULT_CH
#SDL::Mixer.open #SDL::Mixer.open
require_relative 'scene' require_relative 'scene'
require_relative 'window'
require_relative 'window_list' require_relative 'window_list'
require_relative 'window_user'
require_relative 'scene_title' require_relative 'scene_title'
$scene = Scene_Title.new $scene = Scene_Title.new
......
...@@ -21,8 +21,8 @@ class Scene ...@@ -21,8 +21,8 @@ class Scene
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
def start def start
end end
def refresh_rect(x, y, width, height) def refresh_rect(x, y, width, height, background=@background, ox=0,oy=0)
Surface.blit(@background,x,y,width,height,$screen,x,y) Surface.blit(background,x+ox,y+oy,width,height,$screen,x,y)
yield yield
$screen.update_rect(x, y, width, height) $screen.update_rect(x, y, width, height)
end end
......
...@@ -32,7 +32,7 @@ class Scene_Hall < Scene ...@@ -32,7 +32,7 @@ class Scene_Hall < Scene
case event case event
when Event::MouseMotion when Event::MouseMotion
[@playerlist, @roomlist].each do |window| [@playerlist, @roomlist].each do |window|
if window .include? event.x, event.y if window.include? event.x, event.y
@active_window = window @active_window = window
@active_window.mousemoved(event.x, event.y) @active_window.mousemoved(event.x, event.y)
break break
......
...@@ -15,7 +15,7 @@ class Scene_Watch < Scene_Duel ...@@ -15,7 +15,7 @@ class Scene_Watch < Scene_Duel
Iduel::Event::DOL.callback do |event| Iduel::Event::DOL.callback do |event|
p event p event
end end
Iduel::Event::RMIF.callback do |event| Iduel::Event::RMIF.callback do |event|66
p event p event
end end
Iduel::Event::WMSG.callback do |event| Iduel::Event::WMSG.callback do |event|
......
class Window
attr_reader :x, :y, :width, :height
def initialize(x, y, width, height)
@x = x
@y = y
@width = width
@height = height
end
def refresh
end
def include?(x,y)
x > @x && x < @x + @width && y > @y && y < @y + @height
end
def dispose
$scene.refresh_rect(@x, @y, @width, @height)
end
end
\ No newline at end of file
...@@ -5,15 +5,11 @@ ...@@ -5,15 +5,11 @@
#  大厅内房间列表 #  大厅内房间列表
#============================================================================== #==============================================================================
class Window_List class Window_List < Window
attr_reader :x, :y, :width, :height
attr_reader :list attr_reader :list
attr_reader :index attr_reader :index
def initialize(x, y, width, height) def initialize(x, y, width, height)
@x = x super(x,y,width, height)
@y = y
@width = width
@height = height
@o_index = 0 @o_index = 0
@item_max = 0 @item_max = 0
@column_max = 1 @column_max = 1
...@@ -59,8 +55,6 @@ class Window_List ...@@ -59,8 +55,6 @@ class Window_List
def clicked def clicked
$scene.refresh_rect(*item_rect(@index)){draw_item(@index, 2)} if @index $scene.refresh_rect(*item_rect(@index)){draw_item(@index, 2)} if @index
end end
def include?(x,y)
x > @x && x < @x + @width && y > @y && y < @y + @height
end
end end
...@@ -11,9 +11,18 @@ class Window_PlayerList < Window_List ...@@ -11,9 +11,18 @@ class Window_PlayerList < Window_List
super(x,y,272,16*34) super(x,y,272,16*34)
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", WLH) @font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", WLH)
@color = [0x03, 0x11, 0x22] @color = [0x03, 0x11, 0x22]
@color_over = [0x03, 0x11, 0x22, 200,200,255]
@color_click = [200,200,255, 0x03, 0x11, 0x22]
end end
def draw_item(index, status=0) def draw_item(index, status=0)
@font.draw_blended_utf8($screen, @list[index].name, @x, @y+index*WLH, *@color) case status
when 0
@font.draw_blended_utf8($screen, @list[index].name, @x, @y+index*WLH, *@color)
when 1
@font.draw_shaded_utf8($screen, @list[index].name, @x, @y+index*WLH, *@color_over)
when 2
@font.draw_shaded_utf8($screen, @list[index].name, @x, @y+index*WLH, *@color_click)
end
end end
def item_rect(index) def item_rect(index)
[@x, @y+WLH*index, @width, WLH] [@x, @y+WLH*index, @width, WLH]
...@@ -24,8 +33,14 @@ class Window_PlayerList < Window_List ...@@ -24,8 +33,14 @@ class Window_PlayerList < Window_List
@height = @item_max * WLH @height = @item_max * WLH
refresh refresh
end end
def clicked
$scene.refresh_rect(*item_rect(@index)){draw_item(@index, 2)} if @index
@userwindow = Window_User.new(100,100,@list[@index])
end
def mousemoved(x,y) def mousemoved(x,y)
return unless include?(x,y) return unless include?(x,y)
self.index = (y - @y) / WLH if (y-@y) / 24 < @item_max
self.index = (y - @y) / WLH
end
end end
end end
\ No newline at end of file
class Window_User < Window
def initialize(x, y, user)
@background = Surface.load "graphics/hall/user.png"
@boarder = Surface.load "graphics/hall/avatar_boader.png"
super(x,y,@background.w,@background.h)
@font = TTF.open('fonts/WenQuanYi Micro Hei.ttf', 16)
@user = user
refresh
end
def refresh(x=@x, y=@y, width=@width, height=@height)
$scene.refresh_rect(@x, @y, @width, @height, @background, -@x, -@y) do
Surface.blit(@background, 0,0,0,0,$screen,@x,@y)
@thread = @user.avatar(:middle) do |avatar|
$scene.refresh_rect(@x+12, @y+12, @boarder.w, @boarder.h, @background, -@x, -@y) do
Surface.blit(avatar, 0,0,0,0,$screen,@x+24,@y+24)
Surface.blit(@boarder, 0,0,0,0,$screen,@x+12,@y+12)
end
end
@font.draw_blended_utf8($screen, @user.name, @x+172, @y+24, 0x00,0x00,0x00)
@font.draw_blended_utf8($screen, "id: #{@user.id}" , @x+172, @y+24+16*2, 0x00,0x00,0x00)
@font.draw_blended_utf8($screen, @user.status , @x+172, @y+24+16*3, 0x00,0x00,0x00)
@font.draw_blended_utf8($screen, "发送消息" , @x+172, @y+24+16*4+8, 0x00,0x00,0x00)
@font.draw_blended_utf8($screen, "查看资料" , @x+172, @y+24+16*5+8, 0x00,0x00,0x00)
@font.draw_blended_utf8($screen, "加为好友" , @x+172, @y+24+16*6+8, 0x00,0x00,0x00)
@font.draw_blended_utf8($screen, "加入游戏" , @x+172, @y+24+16*7+8, 0x00,0x00,0x00)
end
end
def clicked
end
def dispose
@thread.exit
super
end
end
\ No newline at end of file
...@@ -5,45 +5,31 @@ ...@@ -5,45 +5,31 @@
# 游戏大厅显示用户信息的类 # 游戏大厅显示用户信息的类
#============================================================================== #==============================================================================
class Window_UserInfo class Window_UserInfo < Window
def initialize(x, y, user) def initialize(x, y, user)
@boarder = Surface.load "graphics/hall/avatar_boader.png" @boarder = Surface.load "graphics/hall/avatar_boader.png"
@x = x super(x,y,240,@boarder.h)
@y = y
@width = 240
@height= @boarder.h
@font = TTF.open('fonts/WenQuanYi Micro Hei.ttf', 16) @font = TTF.open('fonts/WenQuanYi Micro Hei.ttf', 16)
@user = user
Surface.blit(user.avatar(:middle) do |newest_avatar| refresh
$scene.refresh_rect(@x, @y, @boarder.w, @boarder.h) do
if $scene.is_a? Scene_Hall
Surface.blit(newest_avatar, 0,0,0,0,$screen,@x+12,@y+12)
Surface.blit(@boarder, 0,0,0,0,$screen,@x,@y)
end
end
end, 0,0,0,0,$screen,@x+12,@y+12)
Surface.blit(@boarder, 0,0,0,0,$screen,@x,@y)
@font.draw_blended_utf8($screen, user.name, @x+160, @y+12, 0x00,0x00,0x00)
@font.draw_blended_utf8($screen, "Level: #{user.level}" , @x+160, @y+12+16*2, 0x00,0x00,0x00)
@font.draw_blended_utf8($screen, "总经验: #{user.exp}", @x+160, @y+12+16*3, 0x00,0x00,0x00)
end end
def refresh def refresh(x=@x, y=@y, width=@width, height=@height)
#p "-------------Read start-----------" @thread = @user.avatar(:middle) do |avatar|
#@user.avatar{|avatar| self.contents[1] = avatar; p "-------------read end-----------" } $scene.refresh_rect(@x, @y, @boarder.w, @boarder.h) do
#self. Surface.blit(avatar, 0,0,0,0,$screen,@x+12,@y+12)
#se Surface.blit(@boarder, 0,0,0,0,$screen,@x,@y)
#self.contents[1] = @user.avatar(:middle) end
end
#p @user
#contents[0].clear
#@list.each_with_index do |player, index| @font.draw_blended_utf8($screen, @user.name, @x+160, @y+12, 0x00,0x00,0x00)
#contents[0].draw_text(player.name, 0, 16*index) @font.draw_blended_utf8($screen, "id: #{@user.id}" , @x+160, @y+12+16*2, 0x00,0x00,0x00)
#end @font.draw_blended_utf8($screen, "Level: #{@user.level}" , @x+160, @y+12+16*3, 0x00,0x00,0x00)
@font.draw_blended_utf8($screen, "总经验: #{@user.exp}", @x+160, @y+12+16*4, 0x00,0x00,0x00)
end
def dispose
@thread.exit
super
end end
end end
#<Iduel::User:0x46b6438 @id="201629", @name="zh99997", @credit="Level-1 (\u603B\u7ECF\u9A8C:183)">
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1"> <project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.ruby.rubyproject</type> <type>org.netbeans.modules.ruby.rubyproject</type>
<configuration> <configuration>
<data xmlns="http://www.netbeans.org/ns/ruby-project/1"> <data xmlns="http://www.netbeans.org/ns/ruby-project/1">
<name>iduel</name> <name>iduel</name>
<source-roots> <source-roots>
<root id="src.dir"/> <root id="src.dir"/>
</source-roots> </source-roots>
<test-roots> <test-roots>
<root id="test.src.dir"/> <root id="test.src.dir"/>
<root id="spec.src.dir"/> <root id="spec.src.dir"/>
</test-roots> </test-roots>
</data> </data>
</configuration> </configuration>
</project> </project>
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