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

nbx初步,代码好乱,不能用

parent f07e6d72
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.
This diff was suppressed by a .gitattributes entry.
...@@ -30,15 +30,15 @@ class Iduel ...@@ -30,15 +30,15 @@ class Iduel
(@conn.write info) rescue Event.push Event::Error.new(0) (@conn.write info) rescue Event.push Event::Error.new(0)
end end
def recv(info) def recv(info)
Event.push begin if info.nil?
info.chomp!(RS)
info.encode! "UTF-8", :invalid => :replace, :undef => :replace
puts ">> #{info}"
Event.parse info
rescue IOError
@conn.close @conn.close
@conn = nil @conn = nil
Event::Error.new(0) Event::Error.new(0)
else
info.chomp!(RS)
info.encode! "UTF-8", :invalid => :replace, :undef => :replace
puts ">> #{info}"
Event.push Event.parse info
end end
end end
def close def close
......
#encoding: UTF-8
require_relative 'iduel'
class NBX < Iduel
Version = "20090622"
Port=2583
RS = "\xA1\xE9".force_encoding "GBK"
attr_accessor :user
def initialize
require 'socket'
require 'digest/md5'
require 'open-uri'
#require_relative 'iduel_action'
require_relative 'nbx_event'
require_relative 'nbx_user'
#require_relative 'iduel_room'
@conn_hall = UDPSocket.new
@conn_hall.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
@conn_hall.bind('0.0.0.0', Port)
@recv = Thread.new { recv *@conn_hall.recvfrom(1024) while @conn_hall }
Thread.abort_on_exception = true
end
def send(user, head, *args)
@conn_hall.send("#{head}|#{args.join(',')}", 0, user ? user.host : '<broadcast>', Port)
end
def login(username)
send(nil, 'USERONLINE', username)
@user = User.new(username, 'localhost')
end
def connect(server, port=Port)
#@conn = TCPSocket.open(server, port)
#@conn.set_encoding "GBK"
#@recv = Thread.new { recv @conn.gets(RS) while @conn }
end
def recv(info, addrinfo)
Socket.ip_address_list.each do |localhost_addrinfo|
if localhost_addrinfo.ip_address == addrinfo[3]
addrinfo[2] = 'localhost'
break
end
end
Event.push Event.parse(info, addrinfo[2])
end
end
#encoding: UTF-8
NBX::Event = Class.new #避开SDL::Event问题,所以没有用class NBX::Event::Event
class NBX::Event
@queue = []
def self.push(event)
@queue << event
end
def self.poll
@queue.shift
end
def self.parse(info, host)
info =~ /^([A-Z]*)\|(.*)$/m
case $1
when "USERONLINE"
NBX::Event::USERONLINE
end.new($2, host)
end
end
class NBX::Event::USERONLINE < NBX::Event
attr_reader :user#, :session
def initialize(info, host)
@user = NBX::User.new(info, host)
end
end
\ No newline at end of file
class NBX::User
attr_accessor :name, :host
@@all = []
class <<self
alias old_new new
def new(name, host)
user = @@all.find{|user| user.host == host }
if user
user.name = name
else
user = old_new(name, host)
@@all << user
end
user
end
end
def initialize(name, host)
@name = name
@host = host
end
def avatar(size)
Surface.new(SWSURFACE, 1, 1, 32, 0,0,0,0)
end
end
\ No newline at end of file
...@@ -54,17 +54,9 @@ class Scene ...@@ -54,17 +54,9 @@ class Scene
#@font.draw_blended_utf8(@fps.contents, @fpscount, 160, 12, 0x00,0x00,0x00) #@font.draw_blended_utf8(@fps.contents, @fpscount, 160, 12, 0x00,0x00,0x00)
#@fpscount += 1 #@fpscount += 1
$fpstimer.wait_frame do $fpstimer.wait_frame do
$screen.put(@background,0,0) $screen.put(@background,0,0) if @background
@windows.each do |window| @windows.each do |window|
if window.contents && window.visible && !window.destroyed? window.draw($screen)
if window.angle.zero?
Surface.blit(window.contents, *window.viewport, $screen, window.x, window.y)
else
contents = window.contents.transform_surface(0x66000000,180,1,1,0)
Surface.blit(contents, *window.viewport, $screen, window.x, window.y)
#Surface.transform_blit(window.contents,$screen,0,1,1,100,100,100,100,Surface::TRANSFORM_AA)#,0,0)
end
end
#$screen.put(window.contents, window.x, window.y) if window.contents && window.visible #$screen.put(window.contents, window.x, window.y) if window.contents && window.visible
end end
@font.draw_blended_utf8($screen, "%.1f" % $fpstimer.real_fps, 0, 0, 0xFF, 0xFF, 0xFF) @font.draw_blended_utf8($screen, "%.1f" % $fpstimer.real_fps, 0, 0, 0xFF, 0xFF, 0xFF)
......
#encoding: UTF-8
#==============================================================================
# Scene_Hall
#------------------------------------------------------------------------------
# 大厅
#==============================================================================
class Scene_Hall_NBX < Scene
require_relative 'window_playerlist'
require_relative 'window_userinfo'
require_relative 'window_roomlist'
require_relative 'window_chat'
require_relative 'nbx'
def start
$nbx = NBX.new
$nbx.login(ENV['username'])
@background = Surface.load "graphics/hall/background.png"
Surface.blit(@background,0,0,0,0,$screen,0,0)
@playerlist = Window_PlayerList.new(24,204)
@userinfo = Window_UserInfo.new(24,24, $nbx.user)
@roomlist = Window_RoomList.new(320,50)
@active_window = @roomlist
@chat = Window_Chat.new(321,551,682,168)
bgm = Mixer::Music.load("audio/bgm/hall.ogg")
Mixer.fade_in_music(bgm, 800, -1)
@bgm.destroy if @bgm
@bgm = bgm
@count = 0
super
end
def handle(event)
case event
when Event::MouseMotion
if @active_window and @active_window.visible && !@active_window.include?(event.x, event.y)
@active_window.lostfocus
@active_window = nil
end
self.windows.reverse.each do |window|
if window.include?(event.x, event.y) && window.visible
@active_window = window
@active_window.mousemoved(event.x, event.y)
break true
end
end
when Event::KeyDown
case event.sym
when Key::UP
@active_window.cursor_up
when Key::DOWN
@active_window.cursor_down
when Key::RETURN
@active_window.clicked
#when Key::F5
# if @roomlist.list and room = @roomlist.list.find{|room|room.player1 == $iduel.user or room.player2 == $iduel.user}
# $iduel.qroom room
# end
# $iduel.upinfo
#when Key::F12
# if @roomlist.list and room = @roomlist.list.find{|room|room.player1 == $iduel.user or room.player2 == $iduel.user}
#$iduel.qroom room
# end
#$iduel.close
$scene = Scene_Login.new
end
when Event::KeyUp
case event.sym
when Key::RETURN
determine
end
when Event::MouseButtonDown
case event.button
when Mouse::BUTTON_LEFT
if @active_window and !@active_window.include? event.x, event.y
@active_window.lostfocus
@active_window = nil
end
self.windows.reverse.each do |window|
if @active_window and @active_window.visible && !@active_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
@active_window.cursor_up
when 5
@active_window.cursor_down
end
when Event::MouseButtonUp
case event.button
when Mouse::BUTTON_LEFT
determine
end
else
super
end
end
def handle_nbx(event)
case event
when NBX::Event::USERONLINE
if !@playerlist.list.include? event.user
@playerlist.list << event.user
@playerlist.list = @playerlist.list #OMG...
else
@playerlist.refresh
end
#
#when Iduel::Event::OLIF
# @playerlist.list = event.users
#when Iduel::Event::RMIF
# @roomlist.list = event.rooms
#when Iduel::Event::JOINROOMOK
# require_relative 'scene_duel'
# $scene = Scene_Duel.new(event.room)
#when Iduel::Event::WATCHROOMSTART
# require_relative 'scene_watch'
# $scene = Scene_Watch.new(event.room)
#when Iduel::Event::PCHAT
# @chat.add event.user, event.content
#when Iduel::Event::Error
# Widget_Msgbox.new(event.title, event.message){$scene = Scene_Title.new}
#when Iduel::Event::QROOMOK
# @joinroom_msgbox.message = "读取房间信息" if @joinroom_msgbox && !@joinroom_msgbox.destroyed?
else
puts "---unhandled iduel event----"
p event
end
end
def update
super
while event = NBX::Event.poll
handle_nbx(event)
end
end
def determine
case @active_window
when @roomlist
return unless @roomlist.index and room = @roomlist.list[@roomlist.index]
if room.full?
#$iduel.watch room
@joinroom_msgbox = Widget_Msgbox.new("加入房间", "正在加入观战"){}
else
#$iduel.join room, "test"
@joinroom_msgbox = Widget_Msgbox.new("加入房间", "正在加入房间"){}
end
end
end
end
\ No newline at end of file
...@@ -5,39 +5,24 @@ ...@@ -5,39 +5,24 @@
#============================================================================== #==============================================================================
=begin =begin
class Scene_Single < Scene class Scene_Single < Scene
def start require_relative 'nbx'
@background = Sprite.new def start
@background.contents = Picture.new("title_0.jpg") $server = NBX.new
@command_window = Window.new(600,250,300,500) $server.login(ENV['username'])
@command_window.contents.color = [255,0,0] super
@command_window.contents.font.size = 32 end
@command_window.contents.blt(0,32*0, "duel") #def handle()
@command_window.contents.blt(0,32*1, "single mode") def update
@command_window.contents.blt(0,32*2, "deck edit") while event = NBX::Event.poll
@command_window.contents.blt(0,32*3, "config") handle_nbx(event)
@command_window.contents.blt(0,32*4, "quit") end
$screen.make_magic_hooks(Screen::MousePressed => proc { |owner, event| super
if event.pos[0].between?(@command_window.x, @command_window.x+ @command_window.width) && event.pos[1].between?(@command_window.y, @command_window.y+ @command_window.height) end
$scene = case (event.pos[1] - @command_window.y) / 32 def handle_nbx(event)
when 0 case event
Scene_Login.new when NBX::Event::USERONLINE
when 1 p event.user
Scene_Single.new end
when 2 end
Scene_DeckEdit.new
when 3
Scene_Config.new
when 4
nil
end
end
})
end
def update
end
end end
=end =end
\ No newline at end of file
...@@ -91,8 +91,8 @@ class Scene_Title < Scene ...@@ -91,8 +91,8 @@ class Scene_Title < Scene
require_relative 'scene_login' require_relative 'scene_login'
Scene_Login.new Scene_Login.new
when 1 when 1
require_relative 'scene_single' require_relative 'scene_hall_nbx'
Scene_Single.new Scene_Hall_NBX.new
when 2 when 2
require_relative 'scene_deck' require_relative 'scene_deck'
Scene_Deck.new Scene_Deck.new
......
# To change this template, choose Tools | Templates
# and open the template in the editor.
puts "Hello World"
#encoding: UTF-8 #encoding: UTF-8
class Widget_Msgbox < Window class Widget_Msgbox < Window
Title_Color = [0xFF, 0xFF, 0xFF]
Message_Color = [0x04, 0x47, 0x7c]
def initialize(title, message, buttons={:ok => "确定"}, &proc) def initialize(title, message, buttons={:ok => "确定"}, &proc)
#@background = Surface.load 'graphics/system/msgbox.png' #@background = Surface.load 'graphics/system/msgbox.png'
@contents = Surface.load 'graphics/system/msgbox.png' @contents = Surface.load 'graphics/system/msgbox.png'
...@@ -36,11 +38,9 @@ class Widget_Msgbox < Window ...@@ -36,11 +38,9 @@ class Widget_Msgbox < Window
end end
def refresh def refresh
@contents = Surface.load 'graphics/system/msgbox.png' @contents = Surface.load 'graphics/system/msgbox.png'
@font.draw_blended_utf8(@contents, @title, (@width-@font.text_size(@title)[0])/2, 2, 0xFF, 0xFF, 0xFF) @font.draw_blended_utf8(@contents, @title, (@width-@font.text_size(@title)[0])/2, 2, *Title_Color)
@font.draw_blended_utf8(@contents, @message, 2, 24+2, 0xFF, 0xFF, 0x66) @font.draw_blended_utf8(@contents, @message, 2, 24+2, *Message_Color)
@items.each_key do |index| @items.each_key {|index|draw_item(index, @index == index ? 1 : 0)}
draw_item(index, @index == index ? 1 : 0)
end
end end
def draw_item(index, status=0) def draw_item(index, status=0)
Surface.blit(@button,@button.w/3*status,0,@button.w/3,@button.h,@contents,@items[index][0],@items[index][1]) Surface.blit(@button,@button.w/3*status,0,@button.w/3,@button.h,@contents,@items[index][0],@items[index][1])
......
...@@ -10,19 +10,19 @@ class Window ...@@ -10,19 +10,19 @@ class Window
@visible = true @visible = true
@angle = 0 @angle = 0
@viewport = [0, 0, @width, @height] @viewport = [0, 0, @width, @height]
amask = 0xff000000 amask = 0xff000000
rmask = 0x00ff0000 rmask = 0x00ff0000
gmask = 0x0000ff00 gmask = 0x0000ff00
bmask = 0x000000ff bmask = 0x000000ff
unless @background unless @background
@background = Surface.new(SWSURFACE, @width, @height, 32, rmask, gmask, bmask, amask) @background = Surface.new(SWSURFACE, @width, @height, 32, rmask, gmask, bmask, amask)
@background.fill_rect(0,0,@width,@height,0x66000000) #@background.fill_rect(0,0,@width,@height,0x66000000)
end end
unless @contents unless @contents
@contents = Surface.new(SWSURFACE, @width, @height, 32, rmask, gmask, bmask, amask) @contents = Surface.new(SWSURFACE, @width, @height, 32, rmask, gmask, bmask, amask)
@contents.fill_rect(0,0,@width,@height,0x66000000) #@contents.fill_rect(0,0,@width,@height,0x66000000)
end end
#按Z坐标插入 #按Z坐标插入
unless $scene.windows.each_with_index do |window, index| unless $scene.windows.each_with_index do |window, index|
...@@ -47,8 +47,20 @@ class Window ...@@ -47,8 +47,20 @@ class Window
def destroyed? def destroyed?
@destroyed @destroyed
end end
def clear(x, y, width, height) def draw(screen)
Surface.blit(@background, x,y,width,height,@contents,x,y) if self.contents && self.visible && !self.destroyed?
if self.angle.zero?
Surface.blit(self.contents, *self.viewport, screen, self.x, self.y)
else
contents = self.contents.transform_surface(0x66000000,180,1,1,0)
Surface.blit(contents, *self.viewport, screen, self.x, self.y)
#Surface.transform_blit(window.contents,$screen,0,1,1,100,100,100,100,Surface::TRANSFORM_AA)#,0,0)
end
end
end
def clear(x=0, y=0, width=@width, height=@height)
#Surface.blit(@background, x,y,width,height,@contents,x,y)
contents.fill_rect(x,y,width,height,0x66000000)
end end
def update def update
#子类定义 #子类定义
......
...@@ -6,9 +6,16 @@ class Window_Action < Window_List ...@@ -6,9 +6,16 @@ class Window_Action < Window_List
Color_Disabled = [0x66,0x66,0x66] Color_Disabled = [0x66,0x66,0x66]
Color_Selected = [0x00,0x00,0xFF] Color_Selected = [0x00,0x00,0xFF]
def initialize#,list,list_available=Array.new(list.size, true)) def initialize#,list,list_available=Array.new(list.size, true))
super(0,0,96,20*WLH,300) super(0,0,123,20*WLH,300)
@background.fill_rect(0,0,@width, @height, 0xCC555500) #@skin = Surface.load 'graphics/field/action.png'
@contents.fill_rect(0,0,@width, @height, 0xCC555500) @up = Surface.load 'graphics/field/action_up.png'
@down = Surface.load 'graphics/field/action_down.png'
@middle = Surface.load 'graphics/field/action.png'
@up.set_alpha(RLEACCEL,255)
@middle.set_alpha(RLEACCEL,255)
@down.set_alpha(RLEACCEL,255)
@contents.fill_rect(0,0,@width, @height, 0x22555500)
@font = TTF.open('fonts/WenQuanYi Micro Hei.ttf', 16) @font = TTF.open('fonts/WenQuanYi Micro Hei.ttf', 16)
@visible = false @visible = false
end end
...@@ -16,13 +23,15 @@ class Window_Action < Window_List ...@@ -16,13 +23,15 @@ class Window_Action < Window_List
if list if list
@list = list.keys @list = list.keys
@list_available = list.values @list_available = list.values
@height = @viewport[3] = @list.size*WLH @height = @viewport[3] = @list.size*WLH+15*2
@contents.fill_rect(0,0,@width, @viewport[3], 0xCC555500)
@item_max = @list.size @item_max = @list.size
@index = @list_available.find_index(true) || 0 @index = @list_available.find_index(true) || 0
refresh
#p @index @contents.put(@up, 0, 0)
Surface.transform_draw(@middle,@contents,0,1,(@list.size*WLH).to_f/@middle.h,0,0,0,20,Surface::TRANSFORM_SAFE)
@contents.put(@down, 0, @height-15)
refresh
@visible = true @visible = true
else else
@visible = false @visible = false
......
...@@ -10,6 +10,7 @@ class Window_List < Window ...@@ -10,6 +10,7 @@ class Window_List < Window
attr_reader :index attr_reader :index
def initialize(x, y, width, height, z=200) def initialize(x, y, width, height, z=200)
super(x,y,width, height,z) super(x,y,width, height,z)
@list = [] unless @list
@o_index = 0 @o_index = 0
@item_max = 0 @item_max = 0
@column_max = 1 @column_max = 1
...@@ -37,6 +38,8 @@ class Window_List < Window ...@@ -37,6 +38,8 @@ class Window_List < Window
[0, @index*self.class::WLH, @width, self.class::WLH] [0, @index*self.class::WLH, @width, self.class::WLH]
end end
def refresh def refresh
clear
#@contents.fill_rect(0,0,@width,@height,0x66000000)
@item_max.times do |index| @item_max.times do |index|
draw_item(index, index==@index ? 1 : 0) draw_item(index, index==@index ? 1 : 0)
end end
......
...@@ -8,14 +8,16 @@ class Window_PlayerList < Window_List ...@@ -8,14 +8,16 @@ class Window_PlayerList < Window_List
attr_reader :x, :y, :width, :height attr_reader :x, :y, :width, :height
WLH = 20 WLH = 20
def initialize(x, y) def initialize(x, y)
@contents = Surface.load "graphics/hall/playerlist.png" #@contents = Surface.load "graphics/hall/playerlist.png"
#@background = Surface.load "graphics/hall/playerlist.png"
super(x,y,272,540) super(x,y,272,540)
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 16) @font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 16)
@color = [0x03, 0x11, 0x22] @color = [0x03, 0x11, 0x22]
@color_over = [0x03, 0x11, 0x22, 200,200,255] @color_over = [0x03, 0x11, 0x22, 200,200,255]
@color_click = [200,200,255, 0x03, 0x11, 0x22] @color_click = [200,200,255, 0x03, 0x11, 0x22]
@background = Surface.load "graphics/hall/playerlist.png" #p @contents.alpha
#@contents.fill_rect(0,0,0,0,0xFFFFFFFF) #@contents.set_alpha(RLEACCEL, 80)
@contents.fill_rect(0,0,@width,@height,0xFFFFFFFF)
refresh refresh
#@contents.f #@contents.f
end end
...@@ -29,6 +31,9 @@ class Window_PlayerList < Window_List ...@@ -29,6 +31,9 @@ class Window_PlayerList < Window_List
@font.draw_shaded_utf8(@contents, @list[index].name, 0, index*WLH, *@color_click) @font.draw_shaded_utf8(@contents, @list[index].name, 0, index*WLH, *@color_click)
end end
end end
#def clear(x=0, y=0, width=@width, height=@height)
# Surface.blit(x, )
#end
def item_rect(index) def item_rect(index)
[0, WLH*index, @width, WLH] [0, WLH*index, @width, WLH]
end end
......
...@@ -10,8 +10,9 @@ class Window_RoomList < Window_List ...@@ -10,8 +10,9 @@ class Window_RoomList < Window_List
WLH = 48 WLH = 48
def initialize(x, y) def initialize(x, y)
@button = Surface.load 'graphics/hall/room.png' @button = Surface.load 'graphics/hall/room.png'
@background = Surface.load 'graphics/hall/roomlist.png' @button.set_alpha(RLEACCEL, 255)
@contents = Surface.load 'graphics/hall/roomlist.png' #@background = Surface.load 'graphics/hall/roomlist.png'
#@contents = Surface.load 'graphics/hall/roomlist.png'
super(x,y,@button.w / 3, 48 * 10) super(x,y,@button.w / 3, 48 * 10)
@item_max = 0 @item_max = 0
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 16) @font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 16)
......
...@@ -24,9 +24,9 @@ class Window_UserInfo < Window ...@@ -24,9 +24,9 @@ class Window_UserInfo < Window
@font.draw_blended_utf8(@contents, @user.name, 160, 12, 0x00,0x00,0x00) @font.draw_blended_utf8(@contents, @user.name, 160, 12, 0x00,0x00,0x00)
@font.draw_blended_utf8(@contents, "id: #{@user.id}" , 160, 12+16*2, 0x00,0x00,0x00) #@font.draw_blended_utf8(@contents, "id: #{@user.id}" , 160, 12+16*2, 0x00,0x00,0x00)
@font.draw_blended_utf8(@contents, "Lv: #{@user.level}" , 160, 12+16*3, 0x00,0x00,0x00) #@font.draw_blended_utf8(@contents, "Lv: #{@user.level}" , 160, 12+16*3, 0x00,0x00,0x00)
@font.draw_blended_utf8(@contents, "经验: #{@user.exp}", 160, 12+16*4, 0x00,0x00,0x00) #@font.draw_blended_utf8(@contents, "经验: #{@user.exp}", 160, 12+16*4, 0x00,0x00,0x00)
end end
def dispose def dispose
@thread.exit @thread.exit
......
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