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

临时提交

parent 3fcc87f9
...@@ -28,6 +28,9 @@ class Game ...@@ -28,6 +28,9 @@ class Game
end end
def exit def exit
end end
def watching?
@room and @room.include? @user
end
end end
...@@ -21,6 +21,8 @@ class Game_Event ...@@ -21,6 +21,8 @@ class Game_Event
WatchAction WatchAction
when "M" when "M"
Leave Leave
when 'N'
PrivateChat
when "O" when "O"
Chat Chat
when "P" when "P"
...@@ -134,7 +136,7 @@ class Game_Event ...@@ -134,7 +136,7 @@ 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, :hall) self.new(user, content.gsub('@@@@', ','), :hall)
end end
end end
class Error class Error
...@@ -207,4 +209,11 @@ class Game_Event ...@@ -207,4 +209,11 @@ class Game_Event
def self.parse(info) def self.parse(info)
end end
end end
class PrivateChat < Chat
def self.parse(info)
user, content = info.split(",", 2)
user = User.parse(user)
self.new(user, content.gsub('@@@@', ','), user)
end
end
end end
\ No newline at end of file
...@@ -50,7 +50,7 @@ class Iduel < Game ...@@ -50,7 +50,7 @@ class Iduel < Game
send(2, "#{checknum("RMSG", @session)}@#{@key}", "#{action.escape}▊▊▊mycard") #消息校验字串,为了防止由于mycard开源造成外挂泛滥扰乱正常iduel秩序,这里不模仿iduel计算校验字串,直接发送mycard供iduel识别 send(2, "#{checknum("RMSG", @session)}@#{@key}", "#{action.escape}▊▊▊mycard") #消息校验字串,为了防止由于mycard开源造成外挂泛滥扰乱正常iduel秩序,这里不模仿iduel计算校验字串,直接发送mycard供iduel识别
end end
def exit def exit
@recv.exit @recv.exit if @recv
if @conn if @conn
leave leave
send(11, @key, checknum("ULO", "#{@session}")) send(11, @key, checknum("ULO", "#{@session}"))
...@@ -65,7 +65,7 @@ class Iduel < Game ...@@ -65,7 +65,7 @@ class Iduel < Game
if info.nil? if info.nil?
@conn.close @conn.close
@conn = nil @conn = nil
Game_Event::Error.parse(0) Game_Event.push Game_Event::Error.parse(0)
else else
info.chomp!(RS) info.chomp!(RS)
info.delete!("\r") info.delete!("\r")
...@@ -77,8 +77,15 @@ class Iduel < Game ...@@ -77,8 +77,15 @@ 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) def chat(msg, channel=:hall)
send(4, @key, msg, checknum("CHATP", @session)) msg.gsub!(",", "@@@@")
case channel
when :hall
send(4, @key, msg, checknum("CHATP", @session))
when User #私聊
send(3, @key, "#{channel.name}(#{channel.id})", msg, checknum("CHATX", @session + "X" + "#{channel.name}(#{channel.id})"))
end
#4|241019,test,2368c6b89b3e2eedb92e1b624a2a157c #4|241019,test,2368c6b89b3e2eedb92e1b624a2a157c
end end
private private
......
...@@ -2,12 +2,21 @@ ...@@ -2,12 +2,21 @@
#encoding: UTF-8 #encoding: UTF-8
begin begin
#定义全局方法
def load_config(file="config.yml")
require 'yaml'
$config = YAML.load_file("config.yml") rescue {}
$config['screen'] ||= {}
$config['screen']['width'] ||= 1024
$config['screen']['height'] ||= 768
end
def save_config(file="config.yml")
File.open(file,"w"){|file| YAML.dump($config, file)}
end
#读取配置文件 #读取配置文件
require 'yaml' load_config
$config = YAML.load_file("config.yml") rescue {} save_config
$config['width'] ||= 1024
$config['height'] ||= 768
File.open("config.yml","w"){|config| YAML.dump($config, config)}
#读取命令行参数 #读取命令行参数
log = "log.log" log = "log.log"
...@@ -27,7 +36,7 @@ begin ...@@ -27,7 +36,7 @@ begin
SDL.init(INIT_VIDEO | INIT_AUDIO) SDL.init(INIT_VIDEO | INIT_AUDIO)
WM::set_caption("MyCard", "graphics/system/icon.gif") WM::set_caption("MyCard", "graphics/system/icon.gif")
WM::icon = Surface.load("graphics/system/icon.gif") WM::icon = Surface.load("graphics/system/icon.gif")
$screen = Screen.open($config["width"], $config["height"], 0, HWSURFACE | ($config["fullscreen"] ? FULLSCREEN : 0)) $screen = Screen.open($config['screen']['width'], $config['screen']['height'], 0, HWSURFACE | ($config['screen']['fullscreen'] ? FULLSCREEN : 0))
Mixer.open(Mixer::DEFAULT_FREQUENCY,Mixer::DEFAULT_FORMAT,Mixer::DEFAULT_CHANNELS,512) Mixer.open(Mixer::DEFAULT_FREQUENCY,Mixer::DEFAULT_FORMAT,Mixer::DEFAULT_CHANNELS,512)
TTF.init TTF.init
......
...@@ -106,7 +106,7 @@ class Scene ...@@ -106,7 +106,7 @@ class Scene
$game.exit if $game $game.exit if $game
Widget_Msgbox.new(event.title, event.message, :ok => "确定"){$scene = Scene_Title.new if event.fatal} Widget_Msgbox.new(event.title, event.message, :ok => "确定"){$scene = Scene_Title.new if event.fatal}
else else
$log.debug event $log.debug('未处理的游戏事件'){event.inspect}
end end
end end
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
......
...@@ -16,7 +16,7 @@ class Scene_Duel < Scene ...@@ -16,7 +16,7 @@ class Scene_Duel < Scene
require_relative 'replay' require_relative 'replay'
require_relative 'game_card' require_relative 'game_card'
require_relative 'game_field' require_relative 'game_field'
require_relative 'window_roomchat' require_relative 'window_chat'
attr_reader :cardinfo_window attr_reader :cardinfo_window
attr_reader :player_field_window attr_reader :player_field_window
attr_reader :opponent_field_window attr_reader :opponent_field_window
...@@ -44,17 +44,21 @@ class Scene_Duel < Scene ...@@ -44,17 +44,21 @@ class Scene_Duel < Scene
@player_lp_window = Window_LP.new(0,0, @room.player1, true) @player_lp_window = Window_LP.new(0,0, @room.player1, true)
@opponent_lp_window = Window_LP.new(360,0, @room.player2, false) @opponent_lp_window = Window_LP.new(360,0, @room.player2, false)
@chat_window = Window_RoomChat.new(@cardinfo_window.x, @cardinfo_window.height, 1024-@cardinfo_window.x, 768-@cardinfo_window.height)
create_action_window create_action_window
Card.find(:方程式同调士) create_chat_window
Card.find(:异星的最终战士)
super super
end end
def create_action_window def create_action_window
@player_field_window.action_window = Window_Action.new @player_field_window.action_window = Window_Action.new
end end
def create_chat_window
@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.refresh
end
def chat(text)
action Action::Chat.new(true, text)
end
def init_replay def init_replay
@replay = Replay.new @replay = Replay.new
end end
...@@ -131,7 +135,7 @@ class Scene_Duel < Scene ...@@ -131,7 +135,7 @@ 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 @chat_window.add event.action.from_player, str
event.action.run event.action.run
refresh refresh
when Game_Event::Leave when Game_Event::Leave
......
...@@ -19,7 +19,7 @@ class Scene_Hall < Scene ...@@ -19,7 +19,7 @@ class Scene_Hall < 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) @chat = Window_Chat.new(321,551,682,168){|text|$game.chat text; Game_Event.push Game_Event::Chat.new($game.user, text)}
bgm = Mixer::Music.load("audio/bgm/hall.ogg") bgm = Mixer::Music.load("audio/bgm/hall.ogg")
Mixer.fade_in_music(bgm, -1, 800) Mixer.fade_in_music(bgm, -1, 800)
......
...@@ -8,29 +8,18 @@ require_relative 'scene_duel' ...@@ -8,29 +8,18 @@ require_relative 'scene_duel'
class Scene_Watch < Scene_Duel class Scene_Watch < Scene_Duel
def create_action_window def create_action_window
end end
def chat(text)
$game.chat text, $game.room
Game_Event.push Game_Event::Action.new(Action::Chat.new(true, text), "#{$game.user}:#{text}")
end
def action(action) def action(action)
end end
def start def start
super super
action = Action::Chat.new(true, "#{$game.user.name}(#{$game.user.id})进入了观战") #$game.chat "#{$game.user.name}(#{$game.user.id})进入了观战", @room
action.id = :观战
$game.action action
end end
def handle(event) def terminate
case event #$game.chat "#{$game.user.name}(#{$game.user.id})离开了观战", @room
when Event::KeyDown
case event.sym
when Key::F10
action = Action::Chat.new(true, "#{$game.user.name}(#{$game.user.id})离开了观战")
action.id = :观战
$game.action action
$game.leave
else
super
end
else
super
end
end end
def handle_game(event) def handle_game(event)
case event case event
......
...@@ -5,14 +5,17 @@ ...@@ -5,14 +5,17 @@
#============================================================================== #==============================================================================
class Window_Chat < Window class Window_Chat < Window
WLH=16
require_relative 'widget_scrollbar' require_relative 'widget_scrollbar'
require_relative 'widget_inputbox' require_relative 'widget_inputbox'
User_Color = [0,0,0xFF] User_Color = [0,0,0xFF]
Text_Color = [0,0,0] Text_Color = [0,0,0]
def initialize(x, y, width, height) Player_Color = [0,0,0xFF]
super(x,y,width,height) Opponent_Color = [0xFF,0,0]
@chat_input = Widget_InputBox.new(416,723,586,24){|text|$game.chat text; add($game.user, text)} def initialize(x, y, width, height, &block)
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 16) super(x,y,width,height-24)
@chat_input = Widget_InputBox.new(@x, @y+@height, @width, 24, &block)
@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,@y,@height)
@list = [] @list = []
end end
...@@ -22,12 +25,17 @@ class Window_Chat < Window ...@@ -22,12 +25,17 @@ class Window_Chat < Window
end end
def refresh def refresh
clear clear
@list.last(7).each_with_index do |chat, index| @list.last(@height/WLH).each_with_index do |chat, index|
user, content = *chat user, content = chat
@font.draw_blended_utf8(@contents, user.name, 0, index*WLH, *User_Color) if user.is_a? User
name_width = @font.text_size(user.name)[0] @font.draw_blended_utf8(@contents, user.name+':', 0, index*WLH, *User_Color)
@font.draw_blended_utf8(@contents, ':'+content, name_width, index*WLH, *Text_Color) name_width = @font.text_size(user.name+':')[0]
color = Text_Color
else
name_width = 0
color = user ? Player_Color : Opponent_Color
end
@font.draw_blended_utf8(@contents, content, name_width, index*WLH, *color) unless content.empty?
end end
end end
end end
\ No newline at end of file
...@@ -12,9 +12,10 @@ class Window_GameSelect < Window_List ...@@ -12,9 +12,10 @@ class Window_GameSelect < Window_List
if game.is_a?(Hash) && game["name"] if game.is_a?(Hash) && game["name"]
game['file'] ||= 'game.rb' game['file'] ||= 'game.rb'
game['file'] = File.expand_path(game['file'], File.dirname(file)) game['file'] = File.expand_path(game['file'], File.dirname(file))
$config[game['name']] = {}
@items << game @items << game
else else
$log.warn "#{game.inspect}读取失败(#{file})" $log.error "#{game.inspect}读取失败(#{file})"
end end
end end
super(x,y,160,@items.size*WLH) super(x,y,160,@items.size*WLH)
...@@ -56,6 +57,7 @@ class Window_GameSelect < Window_List ...@@ -56,6 +57,7 @@ class Window_GameSelect < Window_List
def clicked def clicked
load @items[@index]["file"] #TODO: load的这种架构微蛋疼,一时想不到更好的方案 load @items[@index]["file"] #TODO: load的这种架构微蛋疼,一时想不到更好的方案
@login_window.destroy if @login_window @login_window.destroy if @login_window
@login_window = Window_Login.new(316,316,$config["username"],$config["password"]) p @items, @index, $config
@login_window = Window_Login.new(316,316,$config[[@items][@index]['name']]["username"],$config[[@items][@index]['name']]["password"])
end end
end end
...@@ -13,8 +13,8 @@ class Window_LP < Window ...@@ -13,8 +13,8 @@ class Window_LP < Window
@player = player @player = player
if @player if @player
@player.avatar do |avatar| @player.avatar do |avatar|
clear(@position ? 0 : @width-Avatar_Size, 24, Avatar_Size, Avatar_Size) clear(@position ? 0 : @width-Avatar_Size, 0, Avatar_Size, Avatar_Size)
@contents.put avatar, @position ? 0 : @width-Avatar_Size, 24 @contents.put avatar, @position ? 0 : @width-Avatar_Size, 0
end end
if @position if @position
@font.draw_solid_utf8(@contents, @player.name, Avatar_Size, 24, *@color) @font.draw_solid_utf8(@contents, @player.name, Avatar_Size, 24, *@color)
......
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