Commit 031d85f2 authored by 神楽坂玲奈's avatar 神楽坂玲奈

对话框换行&滚动

parent a4d41f1c
File added
...@@ -83,6 +83,15 @@ class Iduel < Game ...@@ -83,6 +83,15 @@ class Iduel < Game
send(4, @key, msg, checknum("CHATP", @session)) send(4, @key, msg, checknum("CHATP", @session))
when User #私聊 when User #私聊
send(3, @key, "#{chatmessage.channel.name}(#{chatmessage.channel.id})", msg, checknum("CHATX", @session + "X" + "#{chatmessage.channel.name}(#{chatmessage.channel.id})")) send(3, @key, "#{chatmessage.channel.name}(#{chatmessage.channel.id})", msg, checknum("CHATX", @session + "X" + "#{chatmessage.channel.name}(#{chatmessage.channel.id})"))
when Room #房间消息:向双方分别私聊
channel = chatmessage.channel
chatmessage.channel = channel.player1
chat chatmessage
if channel.player2
chatmessage.channel = channel.player2
chat chatmessage
end
chatmessage.channel = channel
end end
#4|241019,test,2368c6b89b3e2eedb92e1b624a2a157c #4|241019,test,2368c6b89b3e2eedb92e1b624a2a157c
......
...@@ -134,7 +134,10 @@ class Scene_Duel < Scene ...@@ -134,7 +134,10 @@ class Scene_Duel < Scene
end end
@replay.add event.str @replay.add event.str
str = event.str str = event.str
if str =~ /^\[\d+\] (?:●|◎)→(.*)$/m if str =~ /^\[\d+\] (.*)$/m
str = $1
end
if str =~ /^(?:●|◎)→(.*)$/m
str = $1 str = $1
end end
user = if $game.room.player2 == $game.user user = if $game.room.player2 == $game.user
......
...@@ -20,6 +20,7 @@ class Scene_Login < Scene ...@@ -20,6 +20,7 @@ class Scene_Login < Scene
end end
def update def update
@announcements_window.update @announcements_window.update
#@gameselect_window.update
super super
end end
def handle_game(event) def handle_game(event)
......
...@@ -51,6 +51,9 @@ class Widget_InputBox < Window ...@@ -51,6 +51,9 @@ class Widget_InputBox < Window
@contents.fill_rect(x,y,width,height,0x66FFFFFF) @contents.fill_rect(x,y,width,height,0x66FFFFFF)
@contents.fill_rect(x+2,y+2,width-4,height-4,0xFFFFFFFF) @contents.fill_rect(x+2,y+2,width-4,height-4,0xFFFFFFFF)
end end
def update
#puts "UPDATE:" + self.to_s
end
def self.determine def self.determine
@@active.value=@@entry.get.encode("UTF-8");@@root.withdraw(true);@@active.refresh;true @@active.value=@@entry.get.encode("UTF-8");@@root.withdraw(true);@@active.refresh;true
end end
......
...@@ -86,7 +86,7 @@ class Widget_ScrollBar < Window ...@@ -86,7 +86,7 @@ class Widget_ScrollBar < Window
def scroll_max=(scroll_max) def scroll_max=(scroll_max)
return unless scroll_max and scroll_max != @scroll_max and scroll_max >=0 return unless scroll_max and scroll_max != @scroll_max and scroll_max >=0
@scroll_max = scroll_max @scroll_max = scroll_max
if @scroll >= @scroll_max if @scroll > @scroll_max
@scroll = @scroll_max @scroll = @scroll_max
end end
refresh refresh
......
...@@ -4,7 +4,8 @@ class Window_CardInfo < Window ...@@ -4,7 +4,8 @@ class Window_CardInfo < Window
def initialize(x,y) def initialize(x,y)
super(x,y,1024-x,524,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 = Game_Card.new Card.find('name' => :mycard, 'number' => :"000000", 'lore' => "提示:\n快捷键:\nF10 退出房间\nF12 返回主界面", 'card_type' => :" ", 'stats' => "", 'archettypes' => "", "mediums" => "", "tokens" => 0) self.card = Game_Card.new Card.find('name' => :mycard, 'number' => :"000000", 'lore' => "提示:\n快捷键:\nF10 退出房间\nF12 返回主界面", 'card_type' => :"通常魔法", 'stats' => "", 'archettypes' => "", "mediums" => "", "tokens" => 0)
@card.card.instance_eval { @image = Card::CardBack; @image_small = Card::CardBack_Small }
end end
def card=(card) def card=(card)
return if card.nil? or card == @card or !card.known? return if card.nil? or card == @card or !card.known?
......
...@@ -6,12 +6,9 @@ ...@@ -6,12 +6,9 @@
require_relative 'widget_scrollbar' require_relative 'widget_scrollbar'
require_relative 'widget_inputbox' require_relative 'widget_inputbox'
require_relative 'chatmessage' require_relative 'chatmessage'
class Window_Chat < Window_List require_relative 'window_scrollable'
class Window_Chat < Window_Scrollable
WLH=16 WLH=16
User_Color = [0,0,0xFF]
Text_Color = [0,0,0]
Player_Color = [0,0,0xFF]
Opponent_Color = [0xFF,0,0]
def initialize(x, y, width, height) def initialize(x, y, width, height)
super(x,y,width,height) super(x,y,width,height)
if @width > 600 #判断大厅还是房间,这个判据比较囧,待优化 if @width > 600 #判断大厅还是房间,这个判据比较囧,待优化
...@@ -30,53 +27,138 @@ class Window_Chat < Window_List ...@@ -30,53 +27,138 @@ class Window_Chat < Window_List
Game_Event.push Game_Event::Chat.new(chatmessage) Game_Event.push Game_Event::Chat.new(chatmessage)
end 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-8,@y+31+3,@height-68) @scrolling = Widget_ScrollBar.new(self,@x+@width-20-8,@y+31+3,@height-68)
@page_size = (@height-68)/WLH
@@list ||= {} @@list ||= {}
@list_splited = {}
@@list.each_pair do |channel, chatmessages|
chatmessages.each do |chatmessage|
add_split(chatmessage)
end
end
@channels = []
self.channel = :lobby self.channel = :lobby
#self.items = [:lobby]#, User.new(1,"zh99997"), Room.new(1,"测试房间")]
end end
def add(chatmessage) def add(chatmessage)
@@list[chatmessage.channel] ||= [] @@list[chatmessage.channel] ||= []
self.items << chatmessage.channel unless self.items.include? chatmessage.channel @channels << chatmessage.channel unless @channels.include? chatmessage.channel
@@list[chatmessage.channel] << chatmessage @@list[chatmessage.channel] << chatmessage
scroll_bottom = @items.size - self.scroll <= @page_size
add_split(chatmessage)
if chatmessage.channel == @channel
@scroll = [@items.size - @page_size, 0].max if scroll_bottom
refresh refresh
end end
end
def add_split(chatmessage)
@list_splited[chatmessage.channel] ||= []
@list_splited[chatmessage.channel] << [chatmessage, ""]
width = name_width(chatmessage)
line = 0
chatmessage.message.each_char do |char|
if char == "\n"
line += 1
width = 0
@list_splited[chatmessage.channel] << [chatmessage.message_color, ""]
else
char_width = @font.text_size(char)[0]
if char_width + width > @width-14-20
line += 1
width = char_width
@list_splited[chatmessage.channel] << [chatmessage.message_color, char]
else
@list_splited[chatmessage.channel].last[1] << char
width += char_width
end
end
end
end
def mousemoved(x,y) def mousemoved(x,y)
if y-@y < 31 and (x-@x) < @items.size * 100 if y-@y < 31 and (x-@x) < @channels.size * 100
self.index = (x-@x) / 100 #p '**********',@channels, (x-@x) / 100
self.index = @channels[(x-@x) / 100]
else else
self.index = nil self.index = nil
end end
end end
def clicked def clicked
self.channel = @items[@index] if @index case @index
when nil
when Integer
else
self.channel = @index
end
end end
def channel=(channel) def channel=(channel)
self.items << channel unless self.items.include? channel return if @channel == channel
@channel = channel @channel = channel
@channels << channel unless @channels.include? channel
@list_splited[channel] ||= []
@items = @list_splited[channel]
@scroll = [@items.size - @page_size, 0].max
refresh refresh
end end
def draw_item(index, status=0) def draw_item(index, status=0)
Surface.blit(@tab,0,@channel == @items[index] ? 0 : 31,100,31,@contents,index*100+3,0) case index
channel_name = ChatMessage.channel_name @items[index] when nil
when Integer #描绘聊天消息
draw_item_chatmessage(index, status)
else #描绘频道标签
draw_item_channel(index, status)
end
end
def draw_item_channel(channel, status)
index = @channels.index(channel)
Surface.blit(@tab,0,@channel == channel ? 0 : 31,100,31,@contents,index*100+3,0)
channel_name = ChatMessage.channel_name channel
x = index*100+(100 - @font.text_size(channel_name)[0])/2 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])) draw_stroked_text(channel_name,x,8,1,@font, [255,255,255], ChatMessage.channel_color(channel))
end
def draw_item_chatmessage(index, status)
x,y = item_rect_chatmessage(index)
chatmessage, message = @items[index]
if chatmessage.is_a? ChatMessage
@font.draw_blended_utf8(@contents, chatmessage.user.name+':', x, y, *chatmessage.name_color) if chatmessage.name_visible?
@font.draw_blended_utf8(@contents, message, x+name_width(chatmessage), y, *chatmessage.message_color) unless chatmessage.message.empty?
else
@font.draw_blended_utf8(@contents, message, x, y, *chatmessage)
end
end end
def item_rect(index) def item_rect(index)
[index*100+3, 0, 100, 31] case index
when nil
when Integer #描绘聊天消息
item_rect_chatmessage(index)
else #描绘频道标签
item_rect_channel(index)
end
end
def item_rect_channel(channel)
[@channels.index(channel)*100+3, 0, 100, 31]
end
def item_rect_chatmessage(index)
[8, (index-@scroll)*WLH+31+3, @width, self.class::WLH]
end end
def refresh def refresh
super super
return unless @@list[@channel] @channels.each {|channel|draw_item_channel(channel, @index==channel)}
@@list[@channel].last((@height-68)/WLH).each_with_index do |chatmessage, index| end
if chatmessage.name_visible? def name_width(chatmessage)
@font.draw_blended_utf8(@contents, chatmessage.user.name+':', 8, index*WLH+31+3, *User_Color) chatmessage.name_visible? ? @font.text_size(chatmessage.user.name+':')[0] : 0
name_width = @font.text_size(chatmessage.user.name+':')[0] end
def index_legal?(index)
case index
when nil,Integer
super
else else
name_width = 0 @channels.include? index
end
end end
@font.draw_blended_utf8(@contents, chatmessage.message, 8+name_width, index*WLH+31+3, *chatmessage.message_color) unless chatmessage.message.empty? def scroll_up
self.scroll -= 1
end end
def scroll_down
self.scroll += 1
end end
end end
\ No newline at end of file
...@@ -60,6 +60,9 @@ class Window_GameSelect < Window_List ...@@ -60,6 +60,9 @@ class Window_GameSelect < Window_List
@login_window.destroy if @login_window @login_window.destroy if @login_window
@login_window = Window_Login.new(316,316,$config[$config['game']]["username"],$config[$config['game']]["password"]) @login_window = Window_Login.new(316,316,$config[$config['game']]["username"],$config[$config['game']]["password"])
end end
def update
@login_window.update if @login_window
end
#def destroy #def destroy
# @login_window.destroy if @login_window # @login_window.destroy if @login_window
# super # super
......
...@@ -14,14 +14,14 @@ class Window_List < Window ...@@ -14,14 +14,14 @@ class Window_List < Window
super(x,y,width, height,z) super(x,y,width, height,z)
end end
def index=(index) def index=(index)
index = nil if index < 0 or index >= @items.size if index index = nil unless index_legal?(index)
return if index == @index return if index == @index
if @index if @index
clear(*item_rect(@index)) clear(*item_rect(@index))
draw_item(@index, 0) if @items[@index] draw_item(@index, 0) if index_legal?(@index)
end end
if index.nil? or index < 0 or index >= @items.size if index.nil?
@index = nil @index = nil
else else
@index = index @index = index
...@@ -69,6 +69,8 @@ class Window_List < Window ...@@ -69,6 +69,8 @@ class Window_List < Window
def clicked def clicked
#子类定义 #子类定义
end end
def index_legal?(index)
index.nil? or (index >= 0 and index < @items.size)
end
end end
...@@ -66,6 +66,10 @@ class Window_Login < Window ...@@ -66,6 +66,10 @@ class Window_Login < Window
draw_item(@index, item_rect(@index), 1) draw_item(@index, item_rect(@index), 1)
end end
end end
def update
@username_inputbox.update
@password_inputbox.update
end
#def destroy #def destroy
# @username_inputbox.destroy # @username_inputbox.destroy
# @password_inputbox.destroy # @password_inputbox.destroy
......
#encoding: UTF-8
require_relative 'scene_watch'
class Window_RoomChat < Window
WLH=16
require_relative 'widget_scrollbar'
Player_Color = [0,0,0xFF]
Opponent_Color = [0,0x66,0]
def initialize(x, y, width, height)
super(x,y,width,height-24)
@chat_input = Widget_InputBox.new(@x,@y+@height,@width,24) do |text|
action = Action::Chat.new(true, text)
if $scene.is_a?(Scene_Watch)
action.id = :观战
$game.action action
else
$scene.action action
end
end
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 14)
@contents.fill_rect(0,0,@width, @height, 0x99FFFFFF)
@scroll = Widget_ScrollBar.new(self,@x+@width-20,@y,@height)
@list = []
$chat_window = self
end
def add(player, content)
@list << [player, content]
refresh
end
def refresh
@contents.fill_rect(0,0,@width, @height, 0x99FFFFFF)
@list.last(7).each_with_index do |chat, index|
player, content = chat
@font.draw_blended_utf8(@contents, content.empty? ? " " : content, 0, index*WLH, *(player ? Player_Color : Opponent_Color))
end
end
end
...@@ -35,13 +35,13 @@ class Window_Scrollable < Window_List ...@@ -35,13 +35,13 @@ class Window_Scrollable < Window_List
# clear(0, 0, @width, self.class::WLH * (scroll - @scroll)) # clear(0, 0, @width, self.class::WLH * (scroll - @scroll))
#end #end
@scroll = scroll @scroll = scroll
@scrolling.scroll = @scroll if @scrolling
refresh refresh
end end
def refresh def refresh
clear clear
(@scroll...[(@scroll+@page_size), @items.size].min).each{|index|draw_item(index, @index == index ? 1 : 0)} (@scroll...[(@scroll+@page_size), @items.size].min).each{|index|draw_item(index, @index == index ? 1 : 0)}
@scrolling.scroll_max = @items.size - @page_size if @scrolling @scrolling.scroll_max = [@items.size - @page_size, 0].max if @scrolling
@scrolling.scroll = @scroll if @scrolling
end end
def item_rect(index) def item_rect(index)
[0, (index-@scroll)*self.class::WLH, @width, self.class::WLH] [0, (index-@scroll)*self.class::WLH, @width, self.class::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