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

聊天窗口

parent 3d13036a
...@@ -9,4 +9,5 @@ ...@@ -9,4 +9,5 @@
/mycard.exe /mycard.exe
/7z.exe /7z.exe
/graphics/avatars/*_*.png /graphics/avatars/*_*.png
/error-程序出错请到论坛反馈.txt
Thumbs.db Thumbs.db
\ No newline at end of file
#encoding: UTF-8
require 'rubygems' require 'rubygems'
require 'rake' require 'rake'
require 'rake/clean' require 'rake/clean'
...@@ -45,4 +46,4 @@ Rake::RDocTask.new do |rdoc| ...@@ -45,4 +46,4 @@ Rake::RDocTask.new do |rdoc|
rdoc.options << '--line-numbers' rdoc.options << '--line-numbers'
end end
CLOBBER.include %w(log.log profile.log config.yml doc) + Dir.glob("{replay}/**/*") + Dir.glob("**/Thumbs.db") + Dir.glob("graphics/avatars/*_*.png") CLOBBER.include %w(error-程序出错请到论坛反馈.txt log.log profile.log config.yml doc) + Dir.glob("{replay}/**/*") + Dir.glob("**/Thumbs.db") + Dir.glob("graphics/avatars/*_*.png")
\ No newline at end of file \ No newline at end of file
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.
...@@ -92,7 +92,7 @@ class Action ...@@ -92,7 +92,7 @@ class Action
end end
end end
def run def run
#$log.debug('移动操作执行'){self.inspect} $log.debug('移动操作执行'){self.inspect}
from_field = parse_field(@from_pos) from_field = parse_field(@from_pos)
......
class ChatMessage
attr_accessor :user, :message, :channel, :time
def initialize(user,message,channel=:lobby,time=Time.now)
@user = user
@message = message
@channel = channel
@time = time
end
def name_visible?
case channel
when Symbol
true
when Room
!channel.include?(user)
when User
false
end
end
def name_color
if user == $game.user
[0,128,0]
else
[0,0,255]
end
end
def message_color
if name_visible?
[0,0,0]
elsif user == $game.user or ($game.room and !$game.room.include?($user) and user == $game.room.player1)
[0,128,0]
else
[255,0,0]
end
end
def self.channel_name(channel)
case channel
when Symbol
"##{channel}"
when Room
"[#{channel.name}]"
when User
"@#{channel.name}"
else
channel
end
end
def self.channel_color(channel)
case channel
when Symbol
[0x34,0x92,0xEA]
when Room
[0xF2,0x83,0xC4]
#[255,250,240]
when User
[0xFA,0x27,0x27]
else
[0,0,0]
end
end
end
...@@ -26,6 +26,8 @@ class Game ...@@ -26,6 +26,8 @@ class Game
end end
def action(action) def action(action)
end end
def chat(chatmessage)
end
def exit def exit
end end
def watching? def watching?
......
...@@ -73,12 +73,9 @@ class Game_Event ...@@ -73,12 +73,9 @@ class Game_Event
class Chat < Game_Event class Chat < Game_Event
attr_reader :user, :content, :channel attr_reader :chatmessage
def initialize(user, content, channel=:lobby) def initialize(chatmessage)
@user = user @chatmessage = chatmessage
@content = content
@channel = channel
@time = Time.now
end end
end end
......
...@@ -65,11 +65,13 @@ class Game_Event ...@@ -65,11 +65,13 @@ class Game_Event
templist = [] templist = []
else else
room = room.split(",") room = room.split(",")
templist << if empty room = if empty
Room.new(room[0].to_i, room[1], User.parse(room[2]), nil, room[3]=="1", Room::Color[room[4].to_i], nil, room[6]) Room.new(room[0].to_i, room[1], User.parse(room[2]), nil, room[3]=="1", Room::Color[room[4].to_i], nil, room[6])
else else
Room.new(room[0].to_i, room[3], User.parse(room[1]), User.parse(room[2]), false, Room::Color[room[5].to_i], room[3]) Room.new(room[0].to_i, room[3], User.parse(room[1]), User.parse(room[2]), false, Room::Color[room[5].to_i], room[3])
end end
room.name = room.name[1,room.name.size-1] #iduel服务器发来的消息中,房名前有一空格
templist << room
end end
end end
rooms = templist + rooms rooms = templist + rooms
...@@ -111,6 +113,7 @@ class Game_Event ...@@ -111,6 +113,7 @@ class Game_Event
room = Room.new(id.to_i) room = Room.new(id.to_i)
room.player1 = User.parse(player1) room.player1 = User.parse(player1)
room.player2 = User.parse(player2) room.player2 = User.parse(player2)
room.name = room.name[1,room.name.size-1] #iduel服务器发来的消息中,房名前有一空格
self.new room self.new room
end end
end end
...@@ -119,6 +122,7 @@ class Game_Event ...@@ -119,6 +122,7 @@ class Game_Event
class Watch class Watch
def self.parse(info) def self.parse(info)
id, name = info.split(",", 2) id, name = info.split(",", 2)
name = name[1,name.size-1] #iduel服务器发来的消息中,房名前有一空格
self.new Room.new(id.to_i, name) self.new Room.new(id.to_i, name)
end end
end end
...@@ -136,7 +140,8 @@ class Game_Event ...@@ -136,7 +140,8 @@ class Game_Event
def self.parse(info) def self.parse(info)
user, content = info.split(",", 2) user, content = info.split(",", 2)
user = user == "System" ? User.new(100000, "iDuel管理中心") : User.parse(user) user = user == "System" ? User.new(100000, "iDuel管理中心") : User.parse(user)
self.new(user, content.gsub('@@@@', ','), :lobby) content.gsub!('@@@@', ',')
self.new(ChatMessage.new(user, content, :lobby))
end end
end end
class Error class Error
...@@ -213,7 +218,8 @@ class Game_Event ...@@ -213,7 +218,8 @@ class Game_Event
def self.parse(info) def self.parse(info)
user, content = info.split(",", 2) user, content = info.split(",", 2)
user = User.parse(user) user = User.parse(user)
self.new(user, content.gsub('@@@@', ','), user) content.gsub!('@@@@', ',')
self.new(ChatMessage.new(user, content, user))
end end
end end
end end
\ No newline at end of file
...@@ -58,13 +58,11 @@ class Iduel < Game ...@@ -58,13 +58,11 @@ class Iduel < Game
@conn = nil @conn = nil
end end
end end
def recv(info) def recv(info)
if info.nil? if info.nil?
@conn.close @conn.close
@conn = nil @conn = nil
$log.error 'socket已中断'
Game_Event.push Game_Event::Error.parse(0) Game_Event.push Game_Event::Error.parse(0)
else else
info.chomp!(RS) info.chomp!(RS)
...@@ -77,13 +75,13 @@ class Iduel < Game ...@@ -77,13 +75,13 @@ class Iduel < Game
#def qroom(room) #def qroom(room)
# send(10, @key, room.id, checknum("QROOM", @session + room.id.to_s)) # send(10, @key, room.id, checknum("QROOM", @session + room.id.to_s))
#end #end
def chat(msg, channel=:lobby) def chat(chatmessage)
msg.gsub!(",", "@@@@") msg = chatmessage.message.gsub(",", "@@@@")
case channel case chatmessage.channel
when :lobby when :lobby
send(4, @key, msg, checknum("CHATP", @session)) send(4, @key, msg, checknum("CHATP", @session))
when User #私聊 when User #私聊
send(3, @key, "#{channel.name}(#{channel.id})", msg, checknum("CHATX", @session + "X" + "#{channel.name}(#{channel.id})")) send(3, @key, "#{chatmessage.channel.name}(#{chatmessage.channel.id})", msg, checknum("CHATX", @session + "X" + "#{chatmessage.channel.name}(#{chatmessage.channel.id})"))
end end
#4|241019,test,2368c6b89b3e2eedb92e1b624a2a157c #4|241019,test,2368c6b89b3e2eedb92e1b624a2a157c
......
...@@ -49,8 +49,7 @@ begin ...@@ -49,8 +49,7 @@ begin
log = STDOUT log = STDOUT
end end
$log = Logger.new(log) $log = Logger.new(log)
$log.info("main"){"初始化成功"}
#性能分析 #性能分析
if profile if profile
if profile == "STDOUT" if profile == "STDOUT"
...@@ -69,6 +68,8 @@ begin ...@@ -69,6 +68,8 @@ begin
#初始化标题场景 #初始化标题场景
require_relative 'scene_title' require_relative 'scene_title'
$scene = Scene_Title.new $scene = Scene_Title.new
$log.info("main"){"初始化成功"}
rescue Exception => exception rescue Exception => exception
open('error-程序出错请到论坛反馈.txt', 'w'){|f|f.write [exception.inspect, *exception.backtrace].join("\n")} open('error-程序出错请到论坛反馈.txt', 'w'){|f|f.write [exception.inspect, *exception.backtrace].join("\n")}
exit(1) exit(1)
......
#encoding: UTF-8 #encoding: UTF-8
require_relative 'cacheable' require_relative 'cacheable'
class Room class Room
Color = [[0,0,0], [255,0,0], [0,255,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
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)
......
...@@ -123,14 +123,14 @@ class Scene ...@@ -123,14 +123,14 @@ class Scene
self.windows.reverse.each do |window| self.windows.reverse.each do |window|
if window.include?(x, y) && window.visible if window.include?(x, y) && window.visible
if window != @active_window if window != @active_window
@active_window.lostfocus(window) if @active_window @active_window.lostfocus(window) if @active_window and !@active_window.destroyed?
@active_window = window @active_window = window
end end
@active_window.mousemoved(x, y) @active_window.mousemoved(x, y)
return @active_window return @active_window
end end
end end
if @active_window if @active_window and !@active_window.destroyed?
@active_window.lostfocus @active_window.lostfocus
@active_window = nil @active_window = nil
end end
......
...@@ -54,7 +54,7 @@ class Scene_Duel < Scene ...@@ -54,7 +54,7 @@ class Scene_Duel < Scene
def create_chat_window def create_chat_window
@background.fill_rect(@cardinfo_window.x, @cardinfo_window.height, 1024-@cardinfo_window.x, 768-@cardinfo_window.height,0xFFFFFFFF) @background.fill_rect(@cardinfo_window.x, @cardinfo_window.height, 1024-@cardinfo_window.x, 768-@cardinfo_window.height,0xFFFFFFFF)
@chat_window = Window_Chat.new(@cardinfo_window.x, @cardinfo_window.height, 1024-@cardinfo_window.x, 768-@cardinfo_window.height){|text|chat(text)} @chat_window = Window_Chat.new(@cardinfo_window.x, @cardinfo_window.height, 1024-@cardinfo_window.x, 768-@cardinfo_window.height){|text|chat(text)}
@chat_window.refresh @chat_window.channel = @room
end end
def chat(text) def chat(text)
action Action::Chat.new(true, text) action Action::Chat.new(true, text)
...@@ -125,6 +125,8 @@ class Scene_Duel < Scene ...@@ -125,6 +125,8 @@ class Scene_Duel < Scene
def handle_game(event) def handle_game(event)
case event case event
when Game_Event::Chat
@chat_window.add event.chatmessage
when Game_Event::Action when Game_Event::Action
if event.action.instance_of?(Action::Reset) and event.action.from_player if event.action.instance_of?(Action::Reset) and event.action.from_player
save_replay save_replay
...@@ -135,7 +137,12 @@ class Scene_Duel < Scene ...@@ -135,7 +137,12 @@ class Scene_Duel < Scene
if str =~ /^\[\d+\] (?:●|◎)→(.*)$/m if str =~ /^\[\d+\] (?:●|◎)→(.*)$/m
str = $1 str = $1
end end
@chat_window.add event.action.from_player, str user = if $game.room.player2 == $game.user
event.action.from_player ? $game.room.player2 : $game.room.player1
else
event.action.from_player ? $game.room.player1 : $game.room.player2
end
@chat_window.add ChatMessage.new(user, str, $game.room)
event.action.run event.action.run
refresh refresh
when Game_Event::Leave when Game_Event::Leave
......
...@@ -10,6 +10,8 @@ class Scene_Lobby < Scene ...@@ -10,6 +10,8 @@ class Scene_Lobby < Scene
require_relative 'window_userinfo' require_relative 'window_userinfo'
require_relative 'window_roomlist' require_relative 'window_roomlist'
require_relative 'window_chat' require_relative 'window_chat'
require_relative 'chatmessage'
attr_reader :chat_window
def start def start
$game.refresh $game.refresh
@background = Surface.load("graphics/lobby/background.png").display_format @background = Surface.load("graphics/lobby/background.png").display_format
...@@ -19,8 +21,7 @@ class Scene_Lobby < Scene ...@@ -19,8 +21,7 @@ class Scene_Lobby < Scene
@userinfo = Window_UserInfo.new(24,24, $game.user) @userinfo = Window_UserInfo.new(24,24, $game.user)
@active_window = @roomlist @active_window = @roomlist
@chat = Window_Chat.new(321,551,682,168){|text|$game.chat text; Game_Event.push Game_Event::Chat.new($game.user, text)} @chat_window = Window_Chat.new(313,543,698,212)
bgm = Mixer::Music.load("audio/bgm/lobby.ogg") bgm = Mixer::Music.load("audio/bgm/lobby.ogg")
Mixer.fade_in_music(bgm, -1, 800) Mixer.fade_in_music(bgm, -1, 800)
@bgm.destroy if @bgm @bgm.destroy if @bgm
...@@ -85,7 +86,7 @@ class Scene_Lobby < Scene ...@@ -85,7 +86,7 @@ class Scene_Lobby < Scene
require_relative 'scene_watch' require_relative 'scene_watch'
$scene = Scene_Watch.new(event.room) $scene = Scene_Watch.new(event.room)
when Game_Event::Chat when Game_Event::Chat
@chat.add event.user, event.content @chat_window.add event.chatmessage
else else
super super
end end
......
...@@ -29,7 +29,13 @@ class Window ...@@ -29,7 +29,13 @@ class Window
end end
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],
[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 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
...@@ -46,7 +52,9 @@ class Window ...@@ -46,7 +52,9 @@ class Window
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 $scene and $scene.background if @background
Surface.blit(@background,x,y,width,height,@contents,x,y)
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)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
class Window_CardInfo < Window class Window_CardInfo < Window
WLH = 20 WLH = 20
def initialize(x,y) def initialize(x,y)
super(x,y,1024-x,530,300) super(x,y,1024-x,524,300)
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 16) @font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 16)
self.card = nil self.card = nil
end end
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#  title #  title
#============================================================================== #==============================================================================
class Window_Chat < Window class Window_Chat < Window_List
WLH=16 WLH=16
require_relative 'widget_scrollbar' require_relative 'widget_scrollbar'
require_relative 'widget_inputbox' require_relative 'widget_inputbox'
...@@ -12,30 +12,84 @@ class Window_Chat < Window ...@@ -12,30 +12,84 @@ class Window_Chat < Window
Text_Color = [0,0,0] Text_Color = [0,0,0]
Player_Color = [0,0,0xFF] Player_Color = [0,0,0xFF]
Opponent_Color = [0xFF,0,0] Opponent_Color = [0xFF,0,0]
def initialize(x, y, width, height, &block) def initialize(x, y, width, height)
super(x,y,width,height-24) super(x,y,width,height)
@chat_input = Widget_InputBox.new(@x, @y+@height, @width, 24, &block) if @width > 600 #判断大厅还是房间,这个判据比较囧,待优化
@chat_background = Surface.load("graphics/system/chat.png").display_format
else
@chat_background = Surface.load("graphics/system/chat_room.png").display_format
end
@background = @contents.copy_rect(0,0,@contents.w,@contents.h) #new而已。。
@background.fill_rect(0,0,@background.w, @background.h, 0xFFb2cefe)
@background.put(@chat_background,0,31-4)
@tab = Surface.load "graphics/system/tab.png"
@chat_input = Widget_InputBox.new(@x+8, @y+@height-24-10, @width-14, 24) do |message|
chatmessage = ChatMessage.new($game.user, message, @channel)
$game.chat chatmessage
Game_Event.push Game_Event::Chat.new(chatmessage)
end
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 14) @font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 14)
@scroll = Widget_ScrollBar.new(self,@x+@width-20,@y,@height) @scroll = Widget_ScrollBar.new(self,@x+@width-20-8,@y+31+3,@height-68)
@list = [] @@list ||= {}
self.channel = :lobby
#self.items = [:lobby]#, User.new(1,"zh99997"), Room.new(1,"测试房间")]
end end
def add(user, content) def add(chatmessage)
@list << [user, content] @@list[chatmessage.channel] ||= []
self.items << chatmessage.channel unless self.items.include? chatmessage.channel
@@list[chatmessage.channel] << chatmessage
refresh refresh
end end
def mousemoved(x,y)
if y-@y < 31 and (x-@x) < @items.size * 100
self.index = (x-@x) / 100
else
self.index = nil
end
end
def clicked
self.channel = @items[@index] if @index
end
def channel=(channel)
self.items << channel unless self.items.include? channel
@channel = channel
refresh
end
def draw_item(index, status=0)
Surface.blit(@tab,0,@channel == @items[index] ? 0 : 31,100,31,@contents,index*100+3,0)
channel_name = ChatMessage.channel_name @items[index]
x = index*100+(100 - @font.text_size(channel_name)[0])/2
draw_stroked_text(channel_name,x,8,1,@font, [255,255,255], ChatMessage.channel_color(@items[index]))
end
def item_rect(index)
[index*100+3, 0, 100, 31]
end
lore.inject([0, 0, 0]) do |array, char|
text_size = src_bitmap.text_size char
args = array[0], array[1], text_size.width, text_size.height, char
src_bitmap.draw_text *args
if array[0] < 124
[array[0] + text_size.width, array[1], array[2]]
else
[0, array[1] + WLH, array[2] + 1]
end
end
def refresh def refresh
clear super
@list.last(@height/WLH).each_with_index do |chat, index| return unless @@list[@channel]
user, content = chat @@list[@channel].last((@height-68)/WLH).each_with_index do |chatmessage, index|
if user.is_a? User if chatmessage.name_visible?
@font.draw_blended_utf8(@contents, user.name+':', 0, index*WLH, *User_Color) @font.draw_blended_utf8(@contents, chatmessage.user.name+':', 8, index*WLH+31+3, *User_Color)
name_width = @font.text_size(user.name+':')[0] name_width = @font.text_size(chatmessage.user.name+':')[0]
color = Text_Color
else else
name_width = 0 name_width = 0
color = user ? Player_Color : Opponent_Color
end end
@font.draw_blended_utf8(@contents, content, name_width, index*WLH, *color) unless content.empty? @font.draw_blended_utf8(@contents, chatmessage.message, 8+name_width, index*WLH+31+3, *chatmessage.message_color) unless chatmessage.message.empty?
end end
end end
end end
\ No newline at end of file
#==============================================================================
# ■ Scene_Title
#------------------------------------------------------------------------------
#  title
#==============================================================================
class Window_Info < Sprite
def initialize(x, y, width, height, player, opponent)
super( Image.new(width, height) ){|sprite|
sprite.x = x
sprite.y = y
}
self.contents[0].blit(player.avatar(:small))
self.contents[0].blit(opponent.avatar(:small), width-48, 0)
self.player_lp = 8000
self.opponent_lp = 8000
yield self if block_given?
end
def player_lp=(lp)
lp = 8000 if lp > 8000
lp = 0 if lp < 0
width = (self.contents[0].width-48*2) * lp / 8000
self.contents[0].fill_rect(Color::Red, 48,0, width,48/2)
self.contents[0].fill_rect(Color::Red, 48+self.contents[0].width,0, self.contents[0].width - width,48/2)
end
def opponent_lp=(lp)
lp = 8000 if lp > 8000
lp = 0 if lp < 0
width = (self.contents[0].width-48*2) * lp / 8000
self.contents[0].fill_rect(Color::Red, 48,48/2, width,48/2)
self.contents[0].fill_rect(Color::Red, 48+self.contents[0].width,48/2, self.contents[0].width - width,48/2)
end
def card=(card)
card
end
#def player=(user)
# @user = user
# refresh
#end
def refresh
end
end
#<Iduel::User:0x46b6438 @id="201629", @name="zh99997", @credit="Level-1 (\u603B\u7ECF\u9A8C:183)">
\ No newline at end of file
...@@ -34,13 +34,6 @@ class Window_Login < Window ...@@ -34,13 +34,6 @@ class Window_Login < Window
@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,"记住密码")
refresh refresh
end 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 def refresh
clear clear
@items.each_pair{|index, rect|draw_item(index, rect)} @items.each_pair{|index, rect|draw_item(index, rect)}
......
...@@ -42,7 +42,7 @@ class Window_User < Window_List ...@@ -42,7 +42,7 @@ class Window_User < Window_List
def clicked def clicked
case index case index
when 0 when 0
#发送消息 $scene.chat_window.channel = @user
when 1 when 1
@user.space @user.space
when 2 when 2
...@@ -52,6 +52,7 @@ class Window_User < Window_List ...@@ -52,6 +52,7 @@ class Window_User < Window_List
$game.watch(@user.room) $game.watch(@user.room)
end end
end end
destroy
end end
def mousemoved(x,y) def mousemoved(x,y)
if x.between?(@x+172, @x+@width) and y.between?(@y+96, @y+96+@item_max*WLH) if x.between?(@x+172, @x+@width) and y.between?(@y+96, @y+96+@item_max*WLH)
......
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