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

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

parent 36a6f898
This diff was suppressed by a .gitattributes entry.
module Dialog module Dialog
#选择文件对话框 #选择文件对话框
require 'win32api' require 'win32api'
GetOpenFileName = Win32API.new("comdlg32.dll", "GetOpenFileNameW", "p", "i") GetOpenFileName = Win32API.new("comdlg32.dll", "GetOpenFileNameW", "p", "i")
OFN_EXPLORER = 0x00080000 GetSaveFileName = Win32API.new("comdlg32.dll", "GetSaveFileNameW", "p", "i")
OFN_PATHMUSTEXIST = 0x00000800 OFN_EXPLORER = 0x00080000
OFN_FILEMUSTEXIST = 0x00001000 OFN_PATHMUSTEXIST = 0x00000800
OFN_ALLOWMULTISELECT = 0x00000200 OFN_FILEMUSTEXIST = 0x00001000
OFN_FLAGS = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT = 0x00000200
OFN_ALLOWMULTISELECT OFN_FLAGS = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST |
#打开网页 OFN_ALLOWMULTISELECT
require 'win32ole' #打开网页
Shell = WIN32OLE.new('Shell.Application') require 'win32ole'
Shell = WIN32OLE.new('Shell.Application')
module_function
def get_open_file(title="选择文件", filter = {"所有文件 (*.*)" => "*.*"}) module_function
szFile = (0.chr * 20481).encode("UTF-16LE")
szFileTitle = 0.chr * 2049 def get_open_file(title="选择文件", filter = {"所有文件 (*.*)" => "*.*"}, save=nil)
szTitle = (title+"\0").encode("UTF-16LE") szFile = (0.chr * 20481).encode("UTF-16LE")
szFilter = (filter.flatten.join("\0")+"\0\0").encode("UTF-16LE") szFileTitle = 0.chr * 2049
szInitialDir = "\0" szTitle = (title+"\0").encode("UTF-16LE")
szFilter = (filter.flatten.join("\0")+"\0\0").encode("UTF-16LE")
ofn = szInitialDir = "\0"
[
76, # lStructSize L ofn =
0, # hwndOwner L [
0, # hInstance L 76, # lStructSize L
szFilter, # lpstrFilter L 0, # hwndOwner L
0, # lpstrCustomFilter L 0, # hInstance L
0, # nMaxCustFilter L szFilter, # lpstrFilter L
1, # nFilterIndex L 0, # lpstrCustomFilter L
szFile, # lpstrFile L 0, # nMaxCustFilter L
szFile.size - 1, # nMaxFile L 1, # nFilterIndex L
szFileTitle, # lpstrFileTitle L szFile, # lpstrFile L
szFileTitle.size - 1, # nMaxFileTitle L szFile.size - 1, # nMaxFile L
szInitialDir, # lpstrInitialDir L szFileTitle, # lpstrFileTitle L
szTitle, # lpstrTitle L szFileTitle.size - 1, # nMaxFileTitle L
OFN_FLAGS, # Flags L szInitialDir, # lpstrInitialDir L
0, # nFileOffset S szTitle, # lpstrTitle L
0, # nFileExtension S OFN_FLAGS, # Flags L
0, # lpstrDefExt L 0, # nFileOffset S
0, # lCustData L 0, # nFileExtension S
0, # lpfnHook L 0, # lpstrDefExt L
0 # lpTemplateName L 0, # lCustData L
].pack("LLLPLLLPLPLPPLS2L4") 0, # lpfnHook L
Dir.chdir{GetOpenFileName.call(ofn)} 0 # lpTemplateName L
szFile.delete!("\0".encode("UTF-16LE")) ].pack("LLLPLLLPLPLPPLS2L4")
szFile.encode("UTF-8") Dir.chdir {
end if save
def web(url) GetSaveFileName.call(ofn)
Shell.ShellExecute url else
end GetOpenFileName.call(ofn)
def uac(command, *args)
Shell.ShellExecute File.expand_path(command), args.join(' '), Dir.pwd, "runas" end
end }
szFile.delete!("\0".encode("UTF-16LE"))
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
end end
\ No newline at end of file
#游戏适配器的抽象类 #游戏适配器的抽象类
require_relative 'game_event' require_relative 'game_event'
require_relative 'action' require_relative 'action'
require_relative 'user' require_relative 'user'
require_relative 'room' require_relative 'room'
class Game class Game
attr_reader :users, :rooms attr_reader :users, :rooms
attr_accessor :user, :room, :player_field, :opponent_field, :turn, :turn_player, :phase attr_accessor :user, :room, :player_field, :opponent_field, :turn, :turn_player, :phase
def initialize def initialize
@users = [] @users = []
@rooms = [] @rooms = []
end end
def login(username, password=nil) def login(username, password=nil)
end end
def refresh def refresh
end end
def host(room_name, room_config) def host(room_name, room_config)
end end
def join(room) def join(room)
end end
def watch(room) def watch(room)
end end
def leave def leave
end end
def action(action) def action(action)
end end
def chat(chatmessage) def chat(chatmessage)
end end
def exit def exit
$scene = Scene_Login.new if $scene $scene = Scene_Login.new if $scene
end end
def watching? def watching?
@room and @room.include? @user @room and @room.include? @user
end end
def self.deck_edit def self.deck_edit
end require_relative 'window_deck'
def refresh_interval @deck_window = Window_Deck.new
5 end
end def refresh_interval
end 5
end
end
class Window class Window
WLH = 24 WLH = 24
attr_accessor :x, :y, :width, :height, :z, :contents, :visible, :viewport, :background attr_accessor :x, :y, :width, :height, :z, :contents, :visible, :viewport, :background
alias visible? visible alias visible? visible
def initialize(x, y, width, height, z=200) def initialize(x, y, width, height, z=200)
@x = x @x = x
@y = y @y = y
@z = z @z = z
@width = width @width = width
@height = height @height = height
@visible = true @visible = true
#@angle = 0 #@angle = 0
@viewport = [0, 0, @width, @height] @viewport = [0, 0, @width, @height]
@destroyed = false @destroyed = false
amask = 0xff000000 amask = 0xff000000
rmask = 0x00ff0000 rmask = 0x00ff0000
gmask = 0x0000ff00 gmask = 0x0000ff00
bmask = 0x000000ff bmask = 0x000000ff
#@background ||= Surface.new(SWSURFACE, @width, @height, 32, rmask, gmask, bmask, amask) #@background ||= Surface.new(SWSURFACE, @width, @height, 32, rmask, gmask, bmask, amask)
@contents ||= Surface.new(SWSURFACE, @width, @height, 32, rmask, gmask, bmask, amask) @contents ||= Surface.new(SWSURFACE, @width, @height, 32, rmask, gmask, bmask, amask)
#按Z坐标插入 #按Z坐标插入
unless $scene.windows.each_with_index do |window, index| unless $scene.windows.each_with_index do |window, index|
if window.z > @z if window.z > @z
$scene.windows.insert(index, self) $scene.windows.insert(index, self)
break true break true
end end
end == true end == true
$scene.windows << self $scene.windows << self
end end
end end
def draw_stroked_text(text,x,y,size=1,font=@font,color=@color,color_stroke=@color_stroke) def draw_stroked_text(text,x,y,size=1,font=@font,color=@color,color_stroke=@color_stroke)
[[x-size,y-size], [x-size,y], [x-size,y+size], [[x-size,y-size], [x-size,y], [x-size,y+size],
[x,y-size], [x,y+size], [x,y-size], [x,y+size],
[x+size,y-size], [x+size,y], [x+size,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], *color)} ].each{|pos|font.draw_blended_utf8(@contents, text, pos[0], pos[1], *color)}
font.draw_blended_utf8(@contents, text, x, y, *color_stroke) font.draw_blended_utf8(@contents, text, x, y, *color_stroke)
end end
def include?(x,y) def include?(x,y)
x >= @x && x < @x + @width && y >= @y && y < @y + @height x >= @x && x < @x + @width && y >= @y && y < @y + @height
end end
def destroy def destroy
@destroyed = true @destroyed = true
@contents.destroy if @contents @contents.destroy if @contents
$scene.windows.delete self if $scene $scene.windows.delete self if $scene
end end
def destroyed? def destroyed?
@destroyed @destroyed
end end
def draw(screen) def draw(screen)
return unless self.contents && self.visible? && !self.destroyed? return unless self.contents && self.visible? && !self.destroyed?
Surface.blit(self.contents, *self.viewport, screen, self.x, self.y) Surface.blit(self.contents, *self.viewport, screen, self.x, self.y)
end end
def clear(x=0, y=0, width=@width, height=@height) def clear(x=0, y=0, width=@width, height=@height)
if @background if @background
Surface.blit(@background,x,y,width,height,@contents,x,y) Surface.blit(@background,x,y,width,height,@contents,x,y)
elsif $scene and $scene.background elsif $scene and $scene.background
Surface.blit($scene.background,@x+x,@y+y,width,height,@contents,x,y) Surface.blit($scene.background,@x+x,@y+y,width,height,@contents,x,y)
else else
@contents.fill_rect(x,y,width,height,0xFF000000) @contents.fill_rect(x,y,width,height,0xFF000000)
end end
end end
def update def update
#子类定义 #子类定义
end end
def refresh def refresh
#子类定义 #子类定义
end end
def mousemoved(x,y) def mousemoved(x,y)
#子类定义 #子类定义
end end
def clicked def clicked
#子类定义 #子类定义
end end
def mouseleftbuttonup def mouseleftbuttonup
#子类定义 #子类定义
end end
def lostfocus(active_window=nil) def lostfocus(active_window=nil)
#子类定义 #子类定义
end end
def cursor_up(wrap=false) def cursor_up(wrap=false)
#子类定义 #子类定义
end end
def cursor_down(wrap=false) def cursor_down(wrap=false)
#子类定义 #子类定义
end end
def scroll_up def scroll_up
cursor_up cursor_up
end end
def scroll_down def scroll_down
cursor_down cursor_down
end end
end end
\ No newline at end of file
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 ...@@ -186,39 +186,6 @@ class Ygocore < Game
Widget_Msgbox.destroy rescue nil Widget_Msgbox.destroy rescue nil
end 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) def self.replay(file, skip_image_downloading = false)
require 'fileutils' require 'fileutils'
FileUtils.mv Dir.glob('ygocore/replay/*.yrp'), 'replay/' 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