Commit 68841d6b authored by 神楽坂玲奈's avatar 神楽坂玲奈

卡组编辑强化 增加导出OS格式卡组

parent 36a6f898
This diff was suppressed by a .gitattributes entry.
......@@ -2,6 +2,7 @@ module Dialog
#选择文件对话框
require 'win32api'
GetOpenFileName = Win32API.new("comdlg32.dll", "GetOpenFileNameW", "p", "i")
GetSaveFileName = Win32API.new("comdlg32.dll", "GetSaveFileNameW", "p", "i")
OFN_EXPLORER = 0x00080000
OFN_PATHMUSTEXIST = 0x00000800
OFN_FILEMUSTEXIST = 0x00001000
......@@ -13,7 +14,8 @@ module Dialog
Shell = WIN32OLE.new('Shell.Application')
module_function
def get_open_file(title="选择文件", filter = {"所有文件 (*.*)" => "*.*"})
def get_open_file(title="选择文件", filter = {"所有文件 (*.*)" => "*.*"}, save=nil)
szFile = (0.chr * 20481).encode("UTF-16LE")
szFileTitle = 0.chr * 2049
szTitle = (title+"\0").encode("UTF-16LE")
......@@ -43,13 +45,29 @@ module Dialog
0, # lpfnHook L
0 # lpTemplateName L
].pack("LLLPLLLPLPLPPLS2L4")
Dir.chdir{GetOpenFileName.call(ofn)}
Dir.chdir {
if save
GetSaveFileName.call(ofn)
else
GetOpenFileName.call(ofn)
end
}
szFile.delete!("\0".encode("UTF-16LE"))
szFile.encode("UTF-8")
result = szFile.encode("UTF-8")
if !result.empty? and save.is_a? Array
ext = save[ofn.unpack("LLLPLLLPLPLPPLS2L4")[6] - 1]
if result[-ext.size, ext.size].downcase != ext.downcase
result << ext
end
end
result
end
def web(url)
Shell.ShellExecute url
end
def uac(command, *args)
Shell.ShellExecute File.expand_path(command), args.join(' '), Dir.pwd, "runas"
end
......
......@@ -33,6 +33,8 @@ class Game
@room and @room.include? @user
end
def self.deck_edit
require_relative 'window_deck'
@deck_window = Window_Deck.new
end
def refresh_interval
5
......
class Window_Deck < Window
attr_reader :index
def initialize
@items = Dir.glob("ygocore/deck/*.ydk")[0, 10]
@background = Surface.load(@items.size > 4 ? 'graphics/lobby/host.png' : 'graphics/system/msgbox.png').display_format
super((1024-@background.w)/2, 230, @background.w, @background.h, 300)
@items_button = Surface.load("graphics/system/deck_buttons.png")
@items_buttons = {edit: "编辑", delete: "删除", export: "导出"}
button_y = @height - 36
@button = Surface.load("graphics/system/button.png")
@buttons = {import: "导入", edit: "编辑", close: "关闭"}
space = (@width - @buttons.size * @button.w / 3) / (@buttons.size + 1)
@buttons_pos = {}
@buttons.each_with_index do |button, index|
@buttons_pos[button[0]] = [(space+@button.w/3)*index+space, button_y, @button.w/3, @button.h]
end
@font = TTF.open("fonts/wqy-microhei.ttc", 16)
@title_color = [0xFF, 0xFF, 0xFF]
@color = [0x04, 0x47, 0x7c]
refresh
end
def refresh
clear
@font.draw_blended_utf8(@contents, "卡组编辑", (@width-@font.text_size("卡组编辑")[0])/2, 2, *@title_color)
@items = Dir.glob("ygocore/deck/*.ydk")[0, 10]
@background = Surface.load(@items.size > 4 ? 'graphics/lobby/host.png' : 'graphics/system/msgbox.png').display_format
@height = @background.h
@items.each_with_index do |deck, index|
@font.draw_blended_utf8(@contents, File.basename(deck, ".ydk"), 16, 28+WLH*index, *@color)
end
@items.size.times do |index|
@items_buttons.each_key do |key|
draw_item([index, key], self.index==[index, key] ? 1 : 0)
end
end
@buttons.each_key do |index|
draw_item(index, self.index==index ? 1 : 0)
end
end
def draw_item(index, status=0)
x, y=item_rect(index)
if index.is_a? Array
Surface.blit(@items_button, status*@items_button.w/3, @items_buttons.keys.index(index[1])*@items_button.h/3, @items_button.w/3, @items_button.h/3, @contents, x, y)
else
Surface.blit(@button, @button.w/3*status, 0, @button.w/3, @button.h, @contents, x, y)
text_size = @font.text_size(@buttons[index])
@font.draw_blended_utf8(@contents, @buttons[index], x+(@button.w/3-text_size[0])/2, y+(@button.h-text_size[1])/2, 0xFF, 0xFF, 0xFF)
end
end
def mousemoved(x, y)
new_index = nil
line = (y-@y-28)/WLH
if line.between?(0, @items.size-1)
i = (x - @x - (@width - @items_buttons.size * @items_button.w / 3)) / (@items_button.w/3)
if i >= 0
new_index = [line, @items_buttons.keys[i]]
end
else
@buttons_pos.each_key do |index|
if (x - @x).between?(@buttons_pos[index][0], @buttons_pos[index][0]+@buttons_pos[index][2]) and (y-@y).between?(@buttons_pos[index][1], @buttons_pos[index][1]+@buttons_pos[index][3])
new_index = index
break
end
end
end
self.index = new_index
end
def item_rect(index)
if index.is_a? Array
[
@width - (@items_button.w/3) * (@items_buttons.keys.reverse.index(index[1])+1),
28+WLH*index[0],
@items_button.w/3,
@items_button.h/3
]
else
@buttons_pos[index]
end
end
def index=(index)
return if index == @index
if @index
clear(*item_rect(@index))
draw_item(@index, 0)
end
@index = index
if @index
clear(*item_rect(@index))
draw_item(@index, 1)
end
end
def clicked
case self.index
when :import
import
refresh
when :edit
Ygocore.run_ygocore(:deck)
when :close
destroy
when Array
case index[1]
when :edit
Ygocore.run_ygocore(@items[index[0]])
when :delete
require_relative 'widget_msgbox'
Widget_Msgbox.new("删除卡组", "确定要删除卡组 #{File.basename(@items[index[0]], '.ydk')} 吗", buttons={ok: "确定", cancel: "取消"}) do |clicked|
if clicked == :ok
File.delete @items[index[0]]
refresh
end
end
when :export
export
end
end
end
def import
file = Dialog.get_open_file("导入卡组", "所有支持的卡组 (*.ydk;*.txt;*.deck)" => "*.ydk;*.txt;*.deck", "ygocore卡组 (*.ydk)" => "*.ydk", "OcgSoft卡组 (*.txt;*.deck)" => "*.txt;*.deck")
if !file.empty?
#fix for stdlib File.extname
file =~ /(\.deck|\.txt|\.ydk)$/i
extname = $1
Dir.mkdir "ygocore/deck" unless File.directory?("ygocore/deck")
open("ygocore/deck/#{File.basename(file, extname)+".ydk"}", 'w') do |dest|
if file =~ /(\.deck|\.txt)$/i
deck = Deck.load(file)
dest.puts("#main")
deck.main.each { |card| dest.puts card.number }
dest.puts("#extra")
deck.extra.each { |card| dest.puts card.number }
dest.puts("!side")
deck.side.each { |card| dest.puts card.number }
else
open(file) do |src|
dest.write src.read
end
end
end rescue ($log.error($!.inspect) { $!.backtrace.inspect }; Widget_Msgbox.new("导入卡组", "导入卡组失败", :ok => "确定"))
end
end
def export
require_relative 'dialog'
file = Dialog.get_open_file("导出卡组", {"ygocore卡组 (*.ydk)" => "*.ydk", "OcgSoft卡组 (*.txt)" => "*.txt"}, [".ydk", ".txt"])
if !file.empty?
@items[index[0]]
open(@items[index[0]]) do |src|
if file =~ /.txt$/i
main = []
extra = []
side = []
now_side = false
src.readlines.each do |line|
line.chomp!
if line[0, 1] == "#"
next
elsif line[0, 5] == "!side"
now_side = true
else
card = Card.find("number = '#{line.rjust(8, '0')}'")[0]
next if card.nil?
if now_side
side << card
elsif card.extra?
extra << card
else
main << card
end
end
end
open(file, 'w:GBK') do |dest|
main.each { |card| dest.puts "[#{card.name}]##" }
dest.puts "####"
side.each { |card| dest.puts "[#{card.name}]##" }
dest.puts "===="
extra.each { |card| dest.puts "[#{card.name}]##" }
end
else
open(file, 'w') do |dest|
dest.write src.read
end
end
end
end
end
end
\ No newline at end of file
......@@ -186,39 +186,6 @@ class Ygocore < Game
Widget_Msgbox.destroy rescue nil
end
def self.deck_edit
Widget_Msgbox.new("编辑卡组", "\"导入\"导入已有卡组,\"编辑\"启动ygocore", :import => "导入", :edit => "编辑") do |button|
case button
when :import
file = Dialog.get_open_file("导入卡组", "所有支持的卡组 (*.txt;*.deck;*.ydk)" => "*.ydk;*.txt;*.deck", "OcgSoft卡组 (*.txt;*.deck)" => "*.txt;*.deck", "ygocore卡组 (*.ydk)" => "*.ydk")
if !file.empty?
#fix for stdlib File.extname
file =~ /(\.deck|\.txt|\.ydk)$/i
extname = $1
Dir.mkdir "ygocore/deck" unless File.directory?("ygocore/deck")
open("ygocore/deck/#{File.basename(file, extname)+".ydk"}", 'w') do |dest|
if file =~ /(\.deck|\.txt)$/i
deck = Deck.load(file)
dest.puts("#main")
deck.main.each { |card| dest.puts card.number }
dest.puts("#extra")
deck.extra.each { |card| dest.puts card.number }
dest.pust("!side")
deck.side.each { |card| dest.puts card.number }
else
open(file) do |src|
dest.write src.read
end
end
end rescue Widget_Msgbox.new("导入卡组", "导入卡组失败", :ok => "确定")
Ygocore.run_ygocore(File.basename(file, extname))
end
when :edit
Ygocore.run_ygocore(:deck)
end
end
end
def self.replay(file, skip_image_downloading = false)
require 'fileutils'
FileUtils.mv Dir.glob('ygocore/replay/*.yrp'), 'replay/'
......
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