Commit 2719711f authored by 神楽坂玲奈's avatar 神楽坂玲奈

聊天

parent f554109f
...@@ -61,7 +61,7 @@ class Iduel ...@@ -61,7 +61,7 @@ class Iduel
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 action(action) def action(action)
send(2, "#{checknum("RMSG", @session)}@#{@key}", "#{action.escape}▊▊▊000000") #TODO send(2, "#{checknum("RMSG", @session)}@#{@key}", "#{action.escape}▊▊▊000000") #TODO:iduel校验字串
end end
def host(name, password="", lv=0, color = 0) def host(name, password="", lv=0, color = 0)
send(6, @key, name, password, checknum("JOINROOMMSG", @session + name + password + "0"), 0, color, lv, 0, nil, nil) #TODO:v.ak, v.al send(6, @key, name, password, checknum("JOINROOMMSG", @session + name + password + "0"), 0, color, lv, 0, nil, nil) #TODO:v.ak, v.al
...@@ -69,6 +69,10 @@ class Iduel ...@@ -69,6 +69,10 @@ class Iduel
def watch(room, password="") def watch(room, password="")
send(5, @key, room.id, password, checknum("WATCHROOMMSG", "#{@session}#{room.id}#{password}")) send(5, @key, room.id, password, checknum("WATCHROOMMSG", "#{@session}#{room.id}#{password}"))
end end
def chat(msg)
send(4, @key, msg, checknum("CHATP", @session))
#4|241019,test,2368c6b89b3e2eedb92e1b624a2a157c
end
def quitwatchroom def quitwatchroom
send("QUITWATCHROOM", @key, checknum("QUITWATCHROOM", @session)) send("QUITWATCHROOM", @key, checknum("QUITWATCHROOM", @session))
end end
......
...@@ -104,7 +104,7 @@ class Iduel::Event::PCHAT < Iduel::Event ...@@ -104,7 +104,7 @@ class Iduel::Event::PCHAT < Iduel::Event
attr_reader :user, :content attr_reader :user, :content
def initialize(info) def initialize(info)
user, @content = info.split(",", 2) user, @content = info.split(",", 2)
@user = Iduel::User.new user @user = user == "System" ? Iduel::User.new(100000, "iDuel管理中心") : Iduel::User.new(user)
end end
end end
class Iduel::Event::JOINROOMOK < Iduel::Event class Iduel::Event::JOINROOMOK < Iduel::Event
......
...@@ -14,7 +14,7 @@ class Scene ...@@ -14,7 +14,7 @@ class Scene
start start
while $scene == self while $scene == self
update update
#sleep 0.01 sleep 0.01
end end
terminate terminate
end end
......
...@@ -73,6 +73,7 @@ class Scene_Duel < Scene ...@@ -73,6 +73,7 @@ class Scene_Duel < Scene
when Event::MouseMotion when Event::MouseMotion
if @active_window and !@active_window.include? event.x, event.y if @active_window and !@active_window.include? event.x, event.y
@active_window.lostfocus @active_window.lostfocus
@active_window = nil
end end
self.windows.reverse.each do |window| self.windows.reverse.each do |window|
if window.include? event.x, event.y if window.include? event.x, event.y
...@@ -84,8 +85,18 @@ class Scene_Duel < Scene ...@@ -84,8 +85,18 @@ class Scene_Duel < Scene
when Event::MouseButtonDown when Event::MouseButtonDown
case event.button case event.button
when Mouse::BUTTON_LEFT when Mouse::BUTTON_LEFT
@active_window.mousemoved(event.x, event.y) if @active_window and !@active_window.include? event.x, event.y
@active_window.clicked @active_window.lostfocus
@active_window = nil
end
self.windows.reverse.each do |window|
if window.include? event.x, event.y
@active_window = window
@active_window.mousemoved(event.x, event.y)
break true
end
end
@active_window.clicked if @active_window
when 4 when 4
@active_window.cursor_up @active_window.cursor_up
when 5 when 5
...@@ -102,7 +113,7 @@ class Scene_Duel < Scene ...@@ -102,7 +113,7 @@ class Scene_Duel < Scene
@phases_window.index = @phase @phases_window.index = @phase
end end
end end
when Mouse::BUTTON_RIGHT when Mouse::BUTTON_RIGHT
if @action_window if @action_window
@action_window.next @action_window.next
end end
......
...@@ -8,18 +8,16 @@ class Scene_Hall < Scene ...@@ -8,18 +8,16 @@ class Scene_Hall < Scene
require_relative 'window_playerlist' require_relative 'window_playerlist'
require_relative 'window_userinfo' require_relative 'window_userinfo'
require_relative 'window_roomlist' require_relative 'window_roomlist'
require_relative 'window_chat'
#require_relative 'window_chat'
def start def start
$iduel.upinfo $iduel.upinfo
@background = Surface.load "graphics/hall/background.png" @background = Surface.load "graphics/hall/background.png"
Surface.blit(@background,0,0,0,0,$screen,0,0) Surface.blit(@background,0,0,0,0,$screen,0,0)
@playerlist = Window_PlayerList.new(24,204) @playerlist = Window_PlayerList.new(24,204)
@userinfo = Window_UserInfo.new(24,24, $iduel.user) @userinfo = Window_UserInfo.new(24,24, $iduel.user)
@roomlist = Window_RoomList.new(320,51) @roomlist = Window_RoomList.new(320,51)
@active_window = @roomlist @active_window = @roomlist
#@chat = Window_Chat.new(320,550) @chat = Window_Chat.new(320,550,680,168)
$screen.update_rect(0,0,0,0) $screen.update_rect(0,0,0,0)
bgm = Mixer::Music.load("audio/bgm/hall.ogg") bgm = Mixer::Music.load("audio/bgm/hall.ogg")
...@@ -31,11 +29,15 @@ class Scene_Hall < Scene ...@@ -31,11 +29,15 @@ class Scene_Hall < Scene
def handle(event) def handle(event)
case event case event
when Event::MouseMotion when Event::MouseMotion
if @active_window and !@active_window.include? event.x, event.y
@active_window.lostfocus
@active_window = nil
end
self.windows.reverse.each do |window| self.windows.reverse.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 true
end end
end end
when Event::KeyDown when Event::KeyDown
...@@ -66,8 +68,18 @@ class Scene_Hall < Scene ...@@ -66,8 +68,18 @@ class Scene_Hall < Scene
when Event::MouseButtonDown when Event::MouseButtonDown
case event.button case event.button
when Mouse::BUTTON_LEFT when Mouse::BUTTON_LEFT
@active_window.mousemoved(event.x, event.y) if @active_window and !@active_window.include? event.x, event.y
@active_window.clicked @active_window.lostfocus
@active_window = nil
end
self.windows.reverse.each do |window|
if window.include? event.x, event.y
@active_window = window
@active_window.mousemoved(event.x, event.y)
break
end
end
@active_window.clicked if @active_window
when 4 when 4
@active_window.cursor_up @active_window.cursor_up
when 5 when 5
...@@ -94,6 +106,8 @@ class Scene_Hall < Scene ...@@ -94,6 +106,8 @@ class Scene_Hall < Scene
when Iduel::Event::WATCHROOMSTART when Iduel::Event::WATCHROOMSTART
require_relative 'scene_watch' require_relative 'scene_watch'
$scene = Scene_Watch.new(event.room) $scene = Scene_Watch.new(event.room)
when Iduel::Event::PCHAT
@chat.add event.user, event.content
else else
puts "---unhandled iduel event----" puts "---unhandled iduel event----"
p event p event
......
...@@ -21,6 +21,8 @@ class Scene_Title < Scene ...@@ -21,6 +21,8 @@ class Scene_Title < Scene
@bgm = Mixer::Music.load 'audio/bgm/title.ogg' @bgm = Mixer::Music.load 'audio/bgm/title.ogg'
@decision_se = Mixer::Wave.load("audio/se/decision.ogg") @decision_se = Mixer::Wave.load("audio/se/decision.ogg")
Mixer.fade_in_music @bgm, -1, 800 Mixer.fade_in_music @bgm, -1, 800
end end
def clear(x,y,width,height) def clear(x,y,width,height)
Surface.blit(@background,x,y,width,height,$screen,x,y) Surface.blit(@background,x,y,width,height,$screen,x,y)
...@@ -39,13 +41,11 @@ class Scene_Title < Scene ...@@ -39,13 +41,11 @@ class Scene_Title < Scene
case event.button case event.button
when Mouse::BUTTON_LEFT when Mouse::BUTTON_LEFT
Widget_InputBox.show(0,0){|text, finished|p text, finished}
if @command_window.include?(event.x, event.y) if @command_window.include?(event.x, event.y)
@command_window.click((event.y - @command_window.y) / @command_window.class::Button_Height) @command_window.click((event.y - @command_window.y) / @command_window.class::Button_Height)
end end
when Mouse::BUTTON_RIGHT when Mouse::BUTTON_RIGHT
Widget_InputBox.right
when 4 #scrool_up when 4 #scrool_up
@command_window.index = @index ? (@index-1) % Buttons.size : 0 @command_window.index = @index ? (@index-1) % Buttons.size : 0
when 5 when 5
......
class Widget_InputBox class Widget_InputBox < Window
attr_accessor :text, :proc
require 'tk' require 'tk'
@@font = TkFont.new("family" => 'WenQuanYi Micro Hei',
"size" => 15) #这字号尼玛?!
@@root=TkRoot.new { @@root=TkRoot.new {
withdraw withdraw
overrideredirect true overrideredirect true
attributes :topmost, true attributes :topmost, true
} }
@@entry = TkEntry.new(@@root){ @@entry = TkEntry.new(@@root){
takefocus 1 font @@font
validate :focusout validate :focusout
validatecommand{@@root.withdraw;@@proc.call(get, false);true} validatecommand{@@active.text.replace(get);@@root.withdraw(true);@@active.refresh;true}
bind('Key-Return'){@@root.withdraw;@@proc.call(get, true);true} bind('Key-Return'){@@active.proc.call(get);delete(0, get.size);@@root.withdraw(true);true}
pack pack
} }
def self.show(x,y,text=nil, &proc) Thread.new{Tk.mainloop}
@@root.geometry "+#{x+TkWinfo.pointerx(@@root)-Mouse.state[0]}+#{y+TkWinfo.pointery(@@root)-Mouse.state[1]}" 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 = ""
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?
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 @@root.deiconify
@@entry.text text if text
@@proc = proc
@@entry.focus :force @@entry.focus :force
end end
Thread.new{Tk.mainloop}
end end
...@@ -4,28 +4,28 @@ ...@@ -4,28 +4,28 @@
#  title #  title
#============================================================================== #==============================================================================
class Window_Chat < Sprite class Window_Chat < Window
User_Color = [0,0,0xFF]
Text_Color = [0,0,0]
def initialize(x, y, width, height) def initialize(x, y, width, height)
super( Image.new(width, height) ){|sprite| super(x,y,width,height)
sprite.x = x @chat_input = Widget_InputBox.new(416,723,586,24){|text|$iduel.chat text; add($iduel.user, text)}
sprite.y = y @font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 16)
sprite.width = width @contents.fill_rect(0,0,@width, @height, 0xFFFFFFFF)
sprite.height = height @list = []
sprite.contents[0].font.size = 16
sprite.contents[0].font.color = Color.new(0x031122)
sprite.contents[0].font.smooth = true
@font_bold = sprite.contents[0].font.dup
@font_bold.bold = true
}
yield self if block_given?
end end
def add(user, content) def add(user, content)
contents[0].blit(contents[0], 0, 0, 0, 24, contents[0].width, contents[0].height-16) #滚动条泥煤啊 @list << [user, content]
contents[0].fill_rect(Color::White, 0, contents[0].height-16, contents[0].width, 16) refresh
name = user.name+": "
name_width = @font_bold.text_size(name)[0]
contents[0].draw_text(name, 0, contents[0].height-16, @font_bold)
contents[0].draw_text(content, name_width, contents[0].height-16)
end end
def refresh
@contents.fill_rect(0,0,@width, @height, 0xFFFFFFFF)
@list.last(7).each_with_index do |chat, index|
user, content = *chat
@font.draw_blended_utf8(@contents, user.name, 0, index*WLH, *User_Color)
name_width = @font.text_size(user.name)[0]
@font.draw_blended_utf8(@contents, ':'+content, name_width, index*WLH, *Text_Color)
end
end
end end
...@@ -54,7 +54,7 @@ class Window_Config < Window ...@@ -54,7 +54,7 @@ class Window_Config < Window
clear(*item_rect(@index)) clear(*item_rect(@index))
draw_item(@index, 0) draw_item(@index, 0)
end end
if index.nil? or index.is_a?(Emulator) if index.nil? or !@items.include? index
@index = nil @index = nil
else else
@index = index @index = index
......
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