Commit 8031a2a0 authored by 神楽坂玲奈's avatar 神楽坂玲奈

temp

parent 873082dc
#!/usr/bin/env ruby
begin
#定义全局方法
def load_config(file="config.yml")
require 'yaml'
$config = YAML.load_file("config.yml") rescue {}
$config = {} unless $config.is_a? Hash
$config['bgm'] = true if $config['bgm'].nil?
$config['screen'] ||= {}
$config['screen']['width'] ||= 1024
$config['screen']['height'] ||= 640
end
def save_config(file="config.yml")
File.open(file, "w") { |file| YAML.dump($config, file) }
end
def register_url_protocol
if RUBY_PLATFORM["win"] || RUBY_PLATFORM["ming"]
require 'win32/registry'
pwd = Dir.pwd.gsub('/', '\\')
path = '"' + pwd + '\ruby\bin\rubyw.exe" -C"' + pwd + '" -KU lib/main.rb'
command = path + ' "%1"'
icon = '"' + pwd + '\mycard.exe", 0'
Win32::Registry::HKEY_CLASSES_ROOT.create('mycard') { |reg| reg['URL Protocol'] = path.ljust path.bytesize unless (reg['URL Protocol'] == path rescue false) }
Win32::Registry::HKEY_CLASSES_ROOT.create('mycard\shell\open\command') { |reg| reg[nil] = command.ljust command.bytesize unless (reg[nil] == command rescue false) }
Win32::Registry::HKEY_CLASSES_ROOT.create('mycard\DefaultIcon') { |reg| reg[nil] = icon.ljust icon.bytesize unless (reg[nil] == icon rescue false) }
Win32::Registry::HKEY_CLASSES_ROOT.create('.ydk') { |reg| reg[nil] = 'mycard' unless (reg[nil] == 'mycard' rescue false) }
Win32::Registry::HKEY_CLASSES_ROOT.create('.yrp') { |reg| reg[nil] = 'mycard' unless (reg[nil] == 'mycard' rescue false) }
Win32::Registry::HKEY_CLASSES_ROOT.create('.deck') { |reg| reg[nil] = 'mycard' unless (reg[nil] == 'mycard' rescue false) }
end
end
Thread.abort_on_exception = true
require_relative 'announcement'
#读取配置文件
load_config
save_config
#读取命令行参数
log = "log.log"
log_level = "INFO"
profile = nil
ARGV.each do |arg|
arg = arg.dup.force_encoding("UTF-8")
arg.force_encoding("GBK") unless arg.valid_encoding?
case arg
when /--log=(.*)/
log.replace $1
when /--log-level=(.*)/
log_level.replace $1
when /--profile=(.*)/
profile = $1
when /^mycard:.*|\.ydk$|\.yrp$|\.deck$/
require_relative 'quickstart'
$scene = false
when /register_web_protocol/
register_url_protocol
$scene = false
end
end
unless $scene == false
#初始化SDL
require 'sdl'
include SDL
SDL::Event::APPMOUSEFOCUS = 1
SDL::Event::APPINPUTFOCUS = 2
SDL::Event::APPACTIVE = 4
SDL.putenv ("SDL_VIDEO_CENTERED=1");
SDL.init(INIT_VIDEO | INIT_AUDIO)
WM::set_caption("MyCard", "MyCard")
WM::icon = Surface.load("graphics/system/icon.gif")
$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, 1024)
Mixer.set_volume_music(60)
TTF.init
Thread.abort_on_exception = true
#初始化日志
require 'logger'
if log == "STDOUT" #调试用
log = STDOUT
end
$log = Logger.new(log)
$log.level = Logger.const_get log_level
#性能分析
if profile
if profile == "STDOUT"
profile = STDOUT
else
profile = open(profile, 'w')
end
require 'profiler'
RubyVM::InstructionSequence.compile_option = {
:trace_instruction => true,
:specialized_instruction => false
}
Profiler__::start_profile
end
#初始化标题场景
require_relative 'scene_title'
$scene = Scene_Title.new
#自动更新
require_relative 'update'
Update.start
WM::set_caption("MyCard v#{Update::Version}", "MyCard")
require_relative 'dialog'
register_url_protocol rescue Dialog.uac("ruby/bin/rubyw.exe", "-KU lib/main.rb register_web_protocol")
$log.info("main") { "初始化成功" }
end
rescue Exception => exception
open('error-程序出错请到论坛反馈.txt', 'w') { |f| f.write [exception.inspect, *exception.backtrace].join("\n") }
$scene = false
end
#主循环
begin
$scene.main while $scene
rescue Exception => exception
exception.backtrace.each { |backtrace| break if backtrace =~ /^(.*)\.rb:\d+:in `.*'"$/ } #由于脚本是从main.rb开始执行的,总会有个能匹配成功的文件
$log.fatal($1) { [exception.inspect, *exception.backtrace].collect { |str| str.force_encoding("UTF-8") }.join("\n") }
$game.exit if $game
require_relative 'scene_error'
$scene = Scene_Error.new
retry
ensure
if profile
Profiler__::print_profile(profile)
profile.close
end
$log.close rescue nil
#!/usr/bin/env ruby
begin
#定义全局方法
def load_config(file="config.yml")
require 'yaml'
$config = YAML.load_file("config.yml") rescue {}
$config = {} unless $config.is_a? Hash
$config['bgm'] = true if $config['bgm'].nil?
$config['screen'] ||= {}
$config['screen']['width'] ||= 1024
$config['screen']['height'] ||= 640
end
def save_config(file="config.yml")
File.open(file, "w") { |file| YAML.dump($config, file) }
end
def register_url_protocol
if RUBY_PLATFORM["win"] || RUBY_PLATFORM["ming"]
require 'win32/registry'
pwd = Dir.pwd.gsub('/', '\\')
path = '"' + pwd + '\ruby\bin\rubyw.exe" -C"' + pwd + '" -KU lib/main.rb'
command = path + ' "%1"'
icon = '"' + pwd + '\mycard.exe", 0'
Win32::Registry::HKEY_CLASSES_ROOT.create('mycard') { |reg| reg['URL Protocol'] = path.ljust path.bytesize unless (reg['URL Protocol'] == path rescue false) }
Win32::Registry::HKEY_CLASSES_ROOT.create('mycard\shell\open\command') { |reg| reg[nil] = command.ljust command.bytesize unless (reg[nil] == command rescue false) }
Win32::Registry::HKEY_CLASSES_ROOT.create('mycard\DefaultIcon') { |reg| reg[nil] = icon.ljust icon.bytesize unless (reg[nil] == icon rescue false) }
Win32::Registry::HKEY_CLASSES_ROOT.create('.ydk') { |reg| reg[nil] = 'mycard' unless (reg[nil] == 'mycard' rescue false) }
Win32::Registry::HKEY_CLASSES_ROOT.create('.yrp') { |reg| reg[nil] = 'mycard' unless (reg[nil] == 'mycard' rescue false) }
Win32::Registry::HKEY_CLASSES_ROOT.create('.deck') { |reg| reg[nil] = 'mycard' unless (reg[nil] == 'mycard' rescue false) }
end
end
Thread.abort_on_exception = true
require_relative 'announcement'
#读取配置文件
load_config
save_config
#读取命令行参数
log = "log.log"
log_level = "INFO"
profile = nil
ARGV.each do |arg|
arg = arg.dup.force_encoding("UTF-8")
arg.force_encoding("GBK") unless arg.valid_encoding?
case arg
when /--log=(.*)/
log.replace $1
when /--log-level=(.*)/
log_level.replace $1
when /--profile=(.*)/
profile = $1
when /^mycard:.*|\.ydk$|\.yrp$|\.deck$/
require_relative 'quickstart'
$scene = false
when /register_web_protocol/
register_url_protocol
$scene = false
end
end
unless $scene == false
#初始化SDL
require 'sdl'
include SDL
SDL::Event::APPMOUSEFOCUS = 1
SDL::Event::APPINPUTFOCUS = 2
SDL::Event::APPACTIVE = 4
SDL.putenv ("SDL_VIDEO_CENTERED=1");
SDL.init(INIT_VIDEO | INIT_AUDIO)
WM::set_caption("MyCard", "MyCard")
WM::icon = Surface.load("graphics/system/icon.gif")
$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, 1024)
Mixer.set_volume_music(60)
TTF.init
Thread.abort_on_exception = true
#初始化日志
require 'logger'
if log == "STDOUT" #调试用
log = STDOUT
end
$log = Logger.new(log)
$log.level = Logger.const_get log_level
#性能分析
if profile
if profile == "STDOUT"
profile = STDOUT
else
profile = open(profile, 'w')
end
require 'profiler'
RubyVM::InstructionSequence.compile_option = {
:trace_instruction => true,
:specialized_instruction => false
}
Profiler__::start_profile
end
#初始化标题场景
require_relative 'scene_title'
$scene = Scene_Title.new
#自动更新
require_relative 'update'
Update.start
WM::set_caption("MyCard v#{Update::Version}", "MyCard")
require_relative 'dialog'
register_url_protocol rescue Dialog.uac("ruby/bin/rubyw.exe", "-KU lib/main.rb register_web_protocol")
$log.info("main") { "初始化成功" }
end
rescue Exception => exception
open('error-程序出错请到论坛反馈.txt', 'w') { |f| f.write [exception.inspect, *exception.backtrace].join("\n") }
$scene = false
end
#主循环
begin
$scene.main while $scene
rescue Exception => exception
exception.backtrace.each { |backtrace| break if backtrace =~ /^(.*)\.rb:\d+:in `.*'"$/ } #由于脚本是从main.rb开始执行的,总会有个能匹配成功的文件
$log.fatal($1) { [exception.inspect, *exception.backtrace].collect { |str| str.force_encoding("UTF-8") }.join("\n") }
$game.exit if $game
require_relative 'scene_error'
$scene = Scene_Error.new
retry
ensure
if profile
Profiler__::print_profile(profile)
profile.close
end
$log.close rescue nil
end
\ No newline at end of file
#encoding: UTF-8
#==============================================================================
# Scene_Lobby
#------------------------------------------------------------------------------
# 大厅
#==============================================================================
class Scene_Lobby < Scene
require_relative 'window_userlist'
require_relative 'window_userinfo'
require_relative 'window_roomlist'
require_relative 'window_chat'
require_relative 'window_host'
require_relative 'window_lobbybuttons'
require_relative 'chatmessage'
require_relative 'scene_duel'
attr_reader :chat_window
def start
WM::set_caption("MyCard v#{Update::Version} - #{$config['game']} - #{$game.user.name}(#{$game.user.id})", "MyCard")
$game.refresh
@background = Surface.load("graphics/lobby/background.png").display_format
Surface.blit(@background,0,0,0,0,$screen,0,0)
@userlist = Window_UserList.new(24,204,$game.users)
@roomlist = Window_RoomList.new(320,50,$game.rooms)
@userinfo = Window_UserInfo.new(24,24, $game.user)
@host_window = Window_LobbyButtons.new(748,18)
@active_window = @roomlist
@chat_window = Window_Chat.new(313,$config['screen']['height'] - 225,698,212)
@count = 0
super
end
def bgm
"lobby.ogg"
end
def handle(event)
case event
when Event::KeyDown
case event.sym
when Key::UP
@active_window.cursor_up
when Key::DOWN
@active_window.cursor_down
when Key::F2
#@joinroom_msgbox = Widget_Msgbox.new("创建房间", "正在等待对手")
#$game.host Room.new(0, $game.user.name)
when Key::F3
#@joinroom_msgbox = Widget_Msgbox.new("加入房间", "正在加入房间")
#$game.join 'localhost'
when Key::F5
$game.refresh
when Key::F12
$game.exit
$scene = Scene_Login.new
end
else
super
end
end
def handle_game(event)
case event
when Game_Event::AllUsers
@userlist.items = $game.users
when Game_Event::AllRooms
@roomlist.items = $game.rooms
when Game_Event::Join
join(event.room)
when Game_Event::Watch
require_relative 'scene_watch'
$scene = Scene_Watch.new(event.room)
when Game_Event::Chat
@chat_window.add event.chatmessage
else
super
end
end
def join(room)
$scene = Scene_Duel.new(room)
end
def update
@chat_window.update
@host_window.update
@roomlist.update
if @count >= $game.refresh_interval*60
$game.refresh
@count = 0
end
@count += 1
super
end
def terminate
unless $scene.is_a? Scene_Lobby or $scene.is_a? Scene_Duel
$game.exit
end
end
#encoding: UTF-8
#==============================================================================
# Scene_Lobby
#------------------------------------------------------------------------------
# 大厅
#==============================================================================
class Scene_Lobby < Scene
require_relative 'window_userlist'
require_relative 'window_userinfo'
require_relative 'window_roomlist'
require_relative 'window_chat'
require_relative 'window_host'
require_relative 'window_lobbybuttons'
require_relative 'chatmessage'
require_relative 'scene_duel'
attr_reader :chat_window
def start
WM::set_caption("MyCard v#{Update::Version} - #{$config['game']} - #{$game.user.name}(#{$game.user.id})", "MyCard")
$game.refresh
@background = Surface.load("graphics/lobby/background.png").display_format
Surface.blit(@background,0,0,0,0,$screen,0,0)
@userlist = Window_UserList.new(24,204,$game.users)
@roomlist = Window_RoomList.new(320,50,$game.rooms)
@userinfo = Window_UserInfo.new(24,24, $game.user)
@host_window = Window_LobbyButtons.new(748,18)
@active_window = @roomlist
@chat_window = Window_Chat.new(313,$config['screen']['height'] - 225,698,212)
@count = 0
super
end
def bgm
"lobby.ogg"
end
def handle(event)
case event
when Event::KeyDown
case event.sym
when Key::UP
@active_window.cursor_up
when Key::DOWN
@active_window.cursor_down
when Key::F2
#@joinroom_msgbox = Widget_Msgbox.new("创建房间", "正在等待对手")
#$game.host Room.new(0, $game.user.name)
when Key::F3
#@joinroom_msgbox = Widget_Msgbox.new("加入房间", "正在加入房间")
#$game.join 'localhost'
when Key::F5
$game.refresh
when Key::F12
$game.exit
$scene = Scene_Login.new
end
else
super
end
end
def handle_game(event)
case event
when Game_Event::AllUsers
@userlist.items = $game.users
when Game_Event::AllRooms
@roomlist.items = $game.rooms
when Game_Event::Join
join(event.room)
when Game_Event::Watch
require_relative 'scene_watch'
$scene = Scene_Watch.new(event.room)
when Game_Event::Chat
@chat_window.add event.chatmessage
else
super
end
end
def join(room)
$scene = Scene_Duel.new(room)
end
def update
@chat_window.update
@host_window.update
@roomlist.update
if @count >= $game.refresh_interval*60
$game.refresh
@count = 0
end
@count += 1
super
end
def terminate
unless $scene.is_a? Scene_Lobby or $scene.is_a? Scene_Duel
$game.exit
end
end
end
\ No newline at end of file
#encoding: UTF-8
#==============================================================================
# ■ Scene_Login
#------------------------------------------------------------------------------
#  login
#==============================================================================
require_relative 'window_gameselect'
require_relative 'window_announcements'
require_relative 'window_login'
require_relative 'scene_replay'
require_relative 'scene_lobby'
class Scene_Login < Scene
def start
WM::set_caption("MyCard v#{Update::Version}", "MyCard")
@background = Surface.load("graphics/login/background.png").display_format
#======================================================
# We'll pay fpr that soon or later.
#======================================================
if $config['screen']['height'] == 768
@gameselect_window = Window_GameSelect.new(117,269)
elsif $config['screen']['height'] == 640
@gameselect_window = Window_GameSelect.new(117,134)
else
raise "无法分辨的分辨率"
end
#======================================================
# ENDS HERE
#======================================================
super
end
def update
@gameselect_window.update
super
end
def handle_game(event)
case event
when Game_Event::Login
require_relative 'scene_lobby'
$scene = Scene_Lobby.new
else
super
end
end
#def terminate
# @gameselect_window.destroy
#end
#encoding: UTF-8
#==============================================================================
# ■ Scene_Login
#------------------------------------------------------------------------------
#  login
#==============================================================================
require_relative 'window_gameselect'
require_relative 'window_announcements'
require_relative 'window_login'
require_relative 'scene_replay'
require_relative 'scene_lobby'
class Scene_Login < Scene
def start
WM::set_caption("MyCard v#{Update::Version}", "MyCard")
@background = Surface.load("graphics/login/background.png").display_format
#======================================================
# We'll pay fpr that soon or later.
#======================================================
if $config['screen']['height'] == 768
@gameselect_window = Window_GameSelect.new(117,269)
elsif $config['screen']['height'] == 640
@gameselect_window = Window_GameSelect.new(117,134)
else
raise "无法分辨的分辨率"
end
#======================================================
# ENDS HERE
#======================================================
super
end
def update
@gameselect_window.update
super
end
def handle_game(event)
case event
when Game_Event::Login
require_relative 'scene_lobby'
$scene = Scene_Lobby.new
else
super
end
end
#def terminate
# @gameselect_window.destroy
#end
end
\ No newline at end of file
require 'open-uri'
require "fileutils"
require_relative 'card'
module Update
Version = '0.7.0'
URL = "http://card.touhou.cc/mycard/update.json?version=#{Version}"
class <<self
attr_reader :thumbnails, :images, :status
def start
Dir.glob("mycard-update-*-*.zip") do |file|
file =~ /mycard-update-(.+?)-(.+?)\.zip/
if $1 <= Version and $2 > Version
$log.info('安装更新'){file}
WM::set_caption("MyCard - 正在更新 #{Version} -> #{$2}", "MyCard")
require 'zip/zip'
Zip::ZipFile::open(file) do |zip|
zip.each do |f|
if !File.directory?(f.name)
FileUtils.mkdir_p(File.dirname(f.name))
end
f.extract{true}
end
end rescue $log.error('安装更新出错'){file+$!.inspect+$!.backtrace.inspect}
Version.replace $2
File.delete file
@updated = true
end
end
if @updated
IO.popen('./mycard')
$scene = nil
end
@images = []
@thumbnails = []
@status = '正在检查更新'
@updated = false
Thread.new do
open(URL) do |file|
require 'json'
reply = file.read
$log.info('下载更新-服务器回传'){reply}
reply = JSON.parse(reply)
$log.info('下载更新-解析后'){reply.inspect}
reply.each do |fil|
name = File.basename fil
@status.replace "正在下载更新#{name}"
open(fil, 'rb') do |fi|
$log.info('下载完毕'){name}
@updated = true
open(name, 'wb') do |f|
f.write fi.read
end
end rescue $log.error('下载更新'){'下载更新失败'}
end
end rescue $log.error('检查更新'){'检查更新失败'}
if @updated
require_relative 'widget_msgbox'
Widget_Msgbox.new('mycard', '下载更新完毕,点击确定重新运行mycard并安装更新', :ok => "确定"){IO.popen('./mycard'); $scene = nil}
end
if File.file? "ygocore/cards.cdb"
require 'sqlite3'
db = SQLite3::Database.new( "ygocore/cards.cdb" )
db.execute( "select id from datas" ) do |row|
@thumbnails << row[0]
end
@images.replace @thumbnails
if !File.directory?('ygocore/pics/thumbnail')
FileUtils.mkdir_p('ygocore/pics/thumbnail')
end
existed_thumbnails = []
Dir.foreach("ygocore/pics/thumbnail") do |file|
if file =~ /(\d+)\.jpg/
existed_thumbnails << $1.to_i
end
end
@thumbnails -= existed_thumbnails
existed_images = []
Dir.foreach("ygocore/pics") do |file|
if file =~ /(\d+)\.jpg/
existed_images << $1.to_i
end
end
@images -= existed_images
existed_images = []
if (!@images.empty? or !@thumbnails.empty?) and File.file?("#{Card::PicPath}/1.jpg")
db_mycard = SQLite3::Database.new( "data/data.sqlite" )
db_mycard.execute( "select id, number from `yu-gi-oh` where number in (#{(@images+@thumbnails).uniq.collect{|number|"'%08d'" % number}.join(',')})" ) do |row|
id = row[0]
number = row[1].to_i
src = "#{Card::PicPath}/#{id}.jpg"
dest = "ygocore/pics/#{number}.jpg"
dest_thumb = "ygocore/pics/thumbnail/#{number}.jpg"
if File.file?(src)
@status.replace "检测到存在iDuel卡图 正在导入 #{id}.jpg"
existed_images << number
if !File.exist?(dest)
FileUtils.copy_file(src, dest)
FileUtils.copy_file(src, dest_thumb)
end
end
end
end
@images -= existed_images
@thumbnails -= existed_images
@thumbnails = (@thumbnails & @images) + (@thumbnails - @images)
unless @thumbnails.empty? and @images.empty?
$log.info('待下载的完整卡图'){@images.inspect}
$log.info('待下载的缩略卡图'){@thumbnails.inspect}
threads = 5.times.collect do
thread = Thread.new do
while number = @thumbnails.pop
@status.replace "正在下载缩略卡图 (剩余#{@thumbnails.size}张)"
open("http://card.touhou.cc/images/cards/ygocore/thumbnail/#{number}.jpg", 'rb') do |remote|
next if File.file? "ygocore/pics/thumbnail/#{number}.jpg"
#$log.debug('下载缩略卡图'){"http://card.touhou.cc/images/cards/ygocore/thumbnail/#{number}.jpg 到 ygocore/pics/thumbnail/#{number}.jpg" }
open("ygocore/pics/thumbnail/#{number}.jpg", 'wb') do |local|
local.write remote.read
end
end rescue $log.error('下载缩略出错'){"http://card.touhou.cc/images/cards/ygocore/thumbnail/#{number}.jpg 到 ygocore/pics/thumbnail/#{number}.jpg" }
end
while number = @images.pop
@status.replace "正在下载完整卡图 (剩余#{@images.size}张)"
#$log.debug('下载完整卡图'){"http://card.touhou.cc/images/cards/ygocore/#{number}.jpg 到 ygocore/pics/#{number}.jpg" }
open("http://card.touhou.cc/images/cards/ygocore/#{number}.jpg", 'rb') do |remote|
next if File.file? "ygocore/pics/#{number}.jpg"
open("ygocore/pics/#{number}.jpg", 'wb') do |local|
local.write remote.read
end
end rescue $log.error('下载完整卡图出错'){"http://card.touhou.cc/images/cards/ygocore/#{number}.jpg 到 ygocore/pics/#{number}.jpg" }
end
end
thread.priority = -1
thread
end
threads.each{|thread|thread.join}
end
end rescue $log.error('卡图更新'){'找不到ygocore卡片数据库'}
@status = nil
end.priority = -1
end
end
end
require 'open-uri'
require "fileutils"
require_relative 'card'
module Update
Version = '0.7.0'
URL = "http://card.touhou.cc/mycard/update.json?version=#{Version}"
class <<self
attr_reader :thumbnails, :images, :status
def start
Dir.glob("mycard-update-*-*.zip") do |file|
file =~ /mycard-update-(.+?)-(.+?)\.zip/
if $1 <= Version and $2 > Version
$log.info('安装更新'){file}
WM::set_caption("MyCard - 正在更新 #{Version} -> #{$2}", "MyCard")
require 'zip/zip'
Zip::ZipFile::open(file) do |zip|
zip.each do |f|
if !File.directory?(f.name)
FileUtils.mkdir_p(File.dirname(f.name))
end
f.extract{true}
end
end rescue $log.error('安装更新出错'){file+$!.inspect+$!.backtrace.inspect}
Version.replace $2
File.delete file
@updated = true
end
end
if @updated
IO.popen('./mycard')
$scene = nil
end
@images = []
@thumbnails = []
@status = '正在检查更新'
@updated = false
Thread.new do
open(URL) do |file|
require 'json'
reply = file.read
$log.info('下载更新-服务器回传'){reply}
reply = JSON.parse(reply)
$log.info('下载更新-解析后'){reply.inspect}
reply.each do |fil|
name = File.basename fil
@status.replace "正在下载更新#{name}"
open(fil, 'rb') do |fi|
$log.info('下载完毕'){name}
@updated = true
open(name, 'wb') do |f|
f.write fi.read
end
end rescue $log.error('下载更新'){'下载更新失败'}
end
end rescue $log.error('检查更新'){'检查更新失败'}
if @updated
require_relative 'widget_msgbox'
Widget_Msgbox.new('mycard', '下载更新完毕,点击确定重新运行mycard并安装更新', :ok => "确定"){IO.popen('./mycard'); $scene = nil}
end
if File.file? "ygocore/cards.cdb"
require 'sqlite3'
db = SQLite3::Database.new( "ygocore/cards.cdb" )
db.execute( "select id from datas" ) do |row|
@thumbnails << row[0]
end
@images.replace @thumbnails
if !File.directory?('ygocore/pics/thumbnail')
FileUtils.mkdir_p('ygocore/pics/thumbnail')
end
existed_thumbnails = []
Dir.foreach("ygocore/pics/thumbnail") do |file|
if file =~ /(\d+)\.jpg/
existed_thumbnails << $1.to_i
end
end
@thumbnails -= existed_thumbnails
existed_images = []
Dir.foreach("ygocore/pics") do |file|
if file =~ /(\d+)\.jpg/
existed_images << $1.to_i
end
end
@images -= existed_images
existed_images = []
if (!@images.empty? or !@thumbnails.empty?) and File.file?("#{Card::PicPath}/1.jpg")
db_mycard = SQLite3::Database.new( "data/data.sqlite" )
db_mycard.execute( "select id, number from `yu-gi-oh` where number in (#{(@images+@thumbnails).uniq.collect{|number|"'%08d'" % number}.join(',')})" ) do |row|
id = row[0]
number = row[1].to_i
src = "#{Card::PicPath}/#{id}.jpg"
dest = "ygocore/pics/#{number}.jpg"
dest_thumb = "ygocore/pics/thumbnail/#{number}.jpg"
if File.file?(src)
@status.replace "检测到存在iDuel卡图 正在导入 #{id}.jpg"
existed_images << number
if !File.exist?(dest)
FileUtils.copy_file(src, dest)
FileUtils.copy_file(src, dest_thumb)
end
end
end
end
@images -= existed_images
@thumbnails -= existed_images
@thumbnails = (@thumbnails & @images) + (@thumbnails - @images)
unless @thumbnails.empty? and @images.empty?
$log.info('待下载的完整卡图'){@images.inspect}
$log.info('待下载的缩略卡图'){@thumbnails.inspect}
threads = 5.times.collect do
thread = Thread.new do
while number = @thumbnails.pop
@status.replace "正在下载缩略卡图 (剩余#{@thumbnails.size}张)"
open("http://card.touhou.cc/images/cards/ygocore/thumbnail/#{number}.jpg", 'rb') do |remote|
next if File.file? "ygocore/pics/thumbnail/#{number}.jpg"
#$log.debug('下载缩略卡图'){"http://card.touhou.cc/images/cards/ygocore/thumbnail/#{number}.jpg 到 ygocore/pics/thumbnail/#{number}.jpg" }
open("ygocore/pics/thumbnail/#{number}.jpg", 'wb') do |local|
local.write remote.read
end
end rescue $log.error('下载缩略出错'){"http://card.touhou.cc/images/cards/ygocore/thumbnail/#{number}.jpg 到 ygocore/pics/thumbnail/#{number}.jpg" }
end
while number = @images.pop
@status.replace "正在下载完整卡图 (剩余#{@images.size}张)"
#$log.debug('下载完整卡图'){"http://card.touhou.cc/images/cards/ygocore/#{number}.jpg 到 ygocore/pics/#{number}.jpg" }
open("http://card.touhou.cc/images/cards/ygocore/#{number}.jpg", 'rb') do |remote|
next if File.file? "ygocore/pics/#{number}.jpg"
open("ygocore/pics/#{number}.jpg", 'wb') do |local|
local.write remote.read
end
end rescue $log.error('下载完整卡图出错'){"http://card.touhou.cc/images/cards/ygocore/#{number}.jpg 到 ygocore/pics/#{number}.jpg" }
end
end
thread.priority = -1
thread
end
threads.each{|thread|thread.join}
end
end rescue $log.error('卡图更新'){'找不到ygocore卡片数据库'}
@status = nil
end.priority = -1
end
end
end
class Window_GameSelect < Window_List
WLH = 56
def initialize(x,y)
@font = TTF.open("fonts/wqy-microhei.ttc", 24)
@color = [255,255,255]
@game_color = [47,156,192]
@game_stroke_color = [0xFF,0xFF,0xFF]
@items = []
Dir.glob('lib/**/game.yml') do |file|
game = YAML.load_file(file)
if game.is_a?(Hash) && game["name"]
game['file'] ||= 'game.rb'
game['file'] = File.expand_path(game['file'], File.dirname(file))
$config[game['name']] ||= {}
@items << game
else
$log.error "#{game.inspect}读取失败(#{file})"
end
end
super(x,y,160,@items.size*WLH)
clear
@button = Surface.load("graphics/login/game_background.png")
#@button.set_alpha(RLEACCEL,255)
self.items = @items
self.index = @items.find_index{|game|game["name"] == $config['game']} || 0
clicked
#======================================================
# We'll pay fpr that soon or later.
#======================================================
if $config['screen']['height'] == 768
@announcements_window = Window_Announcements.new(313,265,600,24)
elsif $config['screen']['height'] == 640
@announcements_window = Window_Announcements.new(313,130,600,24)
else
raise "无法分辨的分辨率"
end
#======================================================
# ENDS HERE
#======================================================
refresh
end
def draw_item(index, status=0)
Surface.blit(@button, @button.w/3*status, @game == index ? @button.h/2 : 0, @button.w/3, @button.h/2, @contents, 0, WLH*index)
draw_stroked_text(@items[index]["name"], 24, WLH*index+14, 2)
end
def item_rect(index)
return [0,0,0,0] unless index
[0, WLH*index, @button.w/3, @button.h/2]
end
def draw_stroked_text(text,x,y,size=1)
[[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], *@game_stroke_color)}
@font.draw_blended_utf8(@contents, text, x, y, *@game_color)
end
def mousemoved(x,y)
self.index = (y-@y) / WLH
end
def index=(index)
return if @index == index# or index.nil?
if @index
clear(*item_rect(@index))
draw_item(@index, 0)
end
@index = index
clear(*item_rect(@index))
draw_item(@index, 1) if @index
end
def clicked
return unless @index
load @items[@index]["file"].encode("GBK") #TODO: load的这种架构微蛋疼,一时想不到更好的方案
$config['game'] = @items[@index]['name']
@login_window.destroy if @login_window
#======================================================
# We'll pay fpr that soon or later.
#======================================================
if $config['screen']['height'] == 768
@login_window = Window_Login.new(316,316,$config[$config['game']]["username"],$config[$config['game']]["password"])
elsif $config['screen']['height'] == 640
@login_window = Window_Login.new(316,183,$config[$config['game']]["username"],$config[$config['game']]["password"])
else
raise "无法分辨的分辨率"
end
#======================================================
# ENDS HERE
#======================================================
@announcements_window.refresh if @announcements_window
@game = @index
refresh
end
def update
@login_window.update if @login_window
@announcements_window.update if @announcements_window
end
#def lostfocus
# self.index = nil
#end
#def destroy
# @login_window.destroy if @login_window
# super
#end
end
class Window_GameSelect < Window_List
WLH = 56
def initialize(x,y)
@font = TTF.open("fonts/wqy-microhei.ttc", 24)
@color = [255,255,255]
@game_color = [47,156,192]
@game_stroke_color = [0xFF,0xFF,0xFF]
@items = []
Dir.glob('lib/**/game.yml') do |file|
game = YAML.load_file(file)
if game.is_a?(Hash) && game["name"]
game['file'] ||= 'game.rb'
game['file'] = File.expand_path(game['file'], File.dirname(file))
$config[game['name']] ||= {}
@items << game
else
$log.error "#{game.inspect}读取失败(#{file})"
end
end
super(x,y,160,@items.size*WLH)
clear
@button = Surface.load("graphics/login/game_background.png")
#@button.set_alpha(RLEACCEL,255)
self.items = @items
self.index = @items.find_index{|game|game["name"] == $config['game']} || 0
clicked
#======================================================
# We'll pay fpr that soon or later.
#======================================================
if $config['screen']['height'] == 768
@announcements_window = Window_Announcements.new(313,265,600,24)
elsif $config['screen']['height'] == 640
@announcements_window = Window_Announcements.new(313,130,600,24)
else
raise "无法分辨的分辨率"
end
#======================================================
# ENDS HERE
#======================================================
refresh
end
def draw_item(index, status=0)
Surface.blit(@button, @button.w/3*status, @game == index ? @button.h/2 : 0, @button.w/3, @button.h/2, @contents, 0, WLH*index)
draw_stroked_text(@items[index]["name"], 24, WLH*index+14, 2)
end
def item_rect(index)
return [0,0,0,0] unless index
[0, WLH*index, @button.w/3, @button.h/2]
end
def draw_stroked_text(text,x,y,size=1)
[[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], *@game_stroke_color)}
@font.draw_blended_utf8(@contents, text, x, y, *@game_color)
end
def mousemoved(x,y)
self.index = (y-@y) / WLH
end
def index=(index)
return if @index == index# or index.nil?
if @index
clear(*item_rect(@index))
draw_item(@index, 0)
end
@index = index
clear(*item_rect(@index))
draw_item(@index, 1) if @index
end
def clicked
return unless @index
load @items[@index]["file"].encode("GBK") #TODO: load的这种架构微蛋疼,一时想不到更好的方案
$config['game'] = @items[@index]['name']
@login_window.destroy if @login_window
#======================================================
# We'll pay fpr that soon or later.
#======================================================
if $config['screen']['height'] == 768
@login_window = Window_Login.new(316,316,$config[$config['game']]["username"],$config[$config['game']]["password"])
elsif $config['screen']['height'] == 640
@login_window = Window_Login.new(316,183,$config[$config['game']]["username"],$config[$config['game']]["password"])
else
raise "无法分辨的分辨率"
end
#======================================================
# ENDS HERE
#======================================================
@announcements_window.refresh if @announcements_window
@game = @index
refresh
end
def update
@login_window.update if @login_window
@announcements_window.update if @announcements_window
end
#def lostfocus
# self.index = nil
#end
#def destroy
# @login_window.destroy if @login_window
# super
#end
end
#encoding: UTF-8
#==============================================================================
# ■ Window_Roomitems
#------------------------------------------------------------------------------
#  大厅内房间列表
#==============================================================================
require_relative 'window_scrollable'
require_relative 'window_join'
class Window_RoomList < Window_Scrollable
attr_reader :items
WLH = 48
def initialize(x, y, items)
@button = Surface.load('graphics/lobby/room.png')
@button.set_alpha(RLEACCEL, 255)
#@background = Surface.load 'graphics/lobby/roomitems.png'
#@contents = Surface.load 'graphics/lobby/roomitems.png'
super(x,y,@button.w / 3, ($config['screen']['height'] - 288) / 48 * 48)
@item_max = 0
@font = TTF.open("fonts/wqy-microhei.ttc", 16)
@color = [0x03, 0x11, 0x22]
@scrollbar = Widget_ScrollBar.new(self,@x+@width,@y,@height)
self.items = items
end
def draw_item(index, status=0)
y = item_rect(index)[1]
room = @items[index]
Surface.blit(@button, @width*status, room.full? ? WLH : 0, @width, WLH, @contents, 0, y)
@font.draw_blended_utf8(@contents, room.id.to_s, 24, y+8, *@color)
@font.draw_blended_utf8(@contents, room.full? ? "【决斗中】" : room.private? ? "【私密房】" : "【等待中】", 8, y+24, *@color)
@font.draw_blended_utf8(@contents, room.name, 128, y+8, *room.color) unless room.name.empty? or room.name.size > 100
$log.error('标题过长') {room.name} if room.name.size > 100
@font.draw_blended_utf8(@contents, room.player1.name, 128, y+24, *room.player1.color) if room.player1 and !room.player1.name.empty?
@font.draw_blended_utf8(@contents, room.player2.name, 320, y+24, *room.player2.color) if room.player2 and !room.player2.name.empty?
room.extra.each_with_index do |extra, index|
str, color = extra
@font.draw_blended_utf8(@contents, str, 300+index*96, y+8, *color)
end
end
def update
@join_window.update if @join_window and !@join_window.destroyed?
end
def mousemoved(x,y)
return unless self.include?(x,y)
self.index = (y - @y) / WLH + @scroll
end
def clicked
return unless @index and room = @items[@index]
if room.full?
@joinroom_msgbox = Widget_Msgbox.new("加入房间", "正在加入观战")
$game.watch room
else
if room.private
@join_window = Window_Join.new(0,0,room)
else
@joinroom_msgbox = Widget_Msgbox.new("加入房间", "正在加入房间")
$game.join room
end
end
end
#encoding: UTF-8
#==============================================================================
# ■ Window_Roomitems
#------------------------------------------------------------------------------
#  大厅内房间列表
#==============================================================================
require_relative 'window_scrollable'
require_relative 'window_join'
class Window_RoomList < Window_Scrollable
attr_reader :items
WLH = 48
def initialize(x, y, items)
@button = Surface.load('graphics/lobby/room.png')
@button.set_alpha(RLEACCEL, 255)
#@background = Surface.load 'graphics/lobby/roomitems.png'
#@contents = Surface.load 'graphics/lobby/roomitems.png'
super(x,y,@button.w / 3, ($config['screen']['height'] - 288) / 48 * 48)
@item_max = 0
@font = TTF.open("fonts/wqy-microhei.ttc", 16)
@color = [0x03, 0x11, 0x22]
@scrollbar = Widget_ScrollBar.new(self,@x+@width,@y,@height)
self.items = items
end
def draw_item(index, status=0)
y = item_rect(index)[1]
room = @items[index]
Surface.blit(@button, @width*status, room.full? ? WLH : 0, @width, WLH, @contents, 0, y)
@font.draw_blended_utf8(@contents, room.id.to_s, 24, y+8, *@color)
@font.draw_blended_utf8(@contents, room.full? ? "【决斗中】" : room.private? ? "【私密房】" : "【等待中】", 8, y+24, *@color)
@font.draw_blended_utf8(@contents, room.name, 128, y+8, *room.color) unless room.name.empty? or room.name.size > 100
$log.error('标题过长') {room.name} if room.name.size > 100
@font.draw_blended_utf8(@contents, room.player1.name, 128, y+24, *room.player1.color) if room.player1 and !room.player1.name.empty?
@font.draw_blended_utf8(@contents, room.player2.name, 320, y+24, *room.player2.color) if room.player2 and !room.player2.name.empty?
room.extra.each_with_index do |extra, index|
str, color = extra
@font.draw_blended_utf8(@contents, str, 300+index*96, y+8, *color)
end
end
def update
@join_window.update if @join_window and !@join_window.destroyed?
end
def mousemoved(x,y)
return unless self.include?(x,y)
self.index = (y - @y) / WLH + @scroll
end
def clicked
return unless @index and room = @items[@index]
if room.full?
@joinroom_msgbox = Widget_Msgbox.new("加入房间", "正在加入观战")
$game.watch room
else
if room.private
@join_window = Window_Join.new(0,0,room)
else
@joinroom_msgbox = Widget_Msgbox.new("加入房间", "正在加入房间")
$game.join room
end
end
end
end
\ No newline at end of file
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