Commit 4fbb42d5 authored by 神楽坂玲奈's avatar 神楽坂玲奈

resolution: 1024x640

parent f896c850
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.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
module Association
module_function
def register
if Windows
require 'win32/registry'
path, command, icon = paths
Win32::Registry::HKEY_CLASSES_ROOT.create('mycard') { |reg| reg['URL Protocol'] = path.ljust path.bytesize }
Win32::Registry::HKEY_CLASSES_ROOT.create('mycard\shell\open\command') { |reg| reg[nil] = command.ljust command.bytesize }
Win32::Registry::HKEY_CLASSES_ROOT.create('mycard\DefaultIcon') { |reg| reg[nil] = icon.ljust icon.bytesize }
Win32::Registry::HKEY_CLASSES_ROOT.create('.ydk') { |reg| reg[nil] = 'mycard' }
Win32::Registry::HKEY_CLASSES_ROOT.create('.yrp') { |reg| reg[nil] = 'mycard' }
Win32::Registry::HKEY_CLASSES_ROOT.create('.deck') { |reg| reg[nil] = 'mycard' }
end
end
def paths
pwd = Dir.pwd.gsub('/', '\\')
path = '"' + pwd + '\ruby\bin\rubyw.exe" -C"' + pwd + '" -KU lib/main.rb'
command = path + ' "%1"'
icon = '"' + pwd + '\mycard.exe", 0'
[path, command, icon]
end
def need?
return false unless Windows
return false if $config['no_assoc']
path, command, icon = paths
require 'win32/registry'
begin
Win32::Registry::HKEY_CLASSES_ROOT.open('mycard') { |reg| return true unless reg['URL Protocol'] == path }
Win32::Registry::HKEY_CLASSES_ROOT.open('mycard\shell\open\command') { |reg| return true unless reg[nil] == command }
Win32::Registry::HKEY_CLASSES_ROOT.open('mycard\DefaultIcon') { |reg| return true unless reg[nil] == icon }
Win32::Registry::HKEY_CLASSES_ROOT.open('.ydk') { |reg| return true unless reg[nil] == 'mycard' }
Win32::Registry::HKEY_CLASSES_ROOT.open('.yrp') { |reg| return true unless reg[nil] == 'mycard' }
Win32::Registry::HKEY_CLASSES_ROOT.open('.deck') { |reg| return true unless reg[nil] == 'mycard' }
rescue
return true
end
end
def request
require_relative 'widget_msgbox'
Widget_Msgbox.new("mycard", "即将进行文件关联, 弹出安全警告请点允许", ok: "确定", cancel: "取消") do |clicked|
if clicked == :ok
yield
else
Widget_Msgbox.new("mycard", "没有进行关联,要重新关联请删除config.yml")
$config['no_assoc'] = true
Config.save
end
end
end
def start
if need?
request do
register rescue Dialog.uac("ruby/bin/rubyw.exe", "-KU lib/main.rb register_association")
end
end
end
end
\ No newline at end of file
require 'yaml'
require_relative 'resolution'
Config = Module.new
module Config
module_function
def load(file="config.yml")
config = YAML.load_file(file) rescue {}
config = {} unless config.is_a? Hash
config['bgm'] = true if config['bgm'].nil?
config['screen'] ||= {}
config['screen']['width'], config['screen']['height'] = Resolution.default unless Resolution.all.include? [config['screen']['width'], config['screen']['height']]
config
end
def save(config=$config, file="config.yml")
File.open(file, "w") { |file| YAML.dump(config, file) }
end
end
\ No newline at end of file
module Graphics
module_function
Ext = ['.png', '.jpg', '.gif']
def load(directory, filename, alpha=true)
extname = File.extname(filename)
path = "graphics/#{directory}/#{File.dirname(filename)}/#{File.basename(filename, extname)}"
result = if extname.empty?
Ext.each do |ext|
result = load_file(path, ext)
break result if result
end
else
load_file(path, extname)
end
raise 'file not exist' if result.nil?
if alpha
result.display_format_alpha
else
result.display_format
end
end
def load_file(path, ext)
path_with_resolution = "#{path}-#{$config['screen']['width']}x#{$config['screen']['height']}#{ext}"
if File.file? path_with_resolution
Surface.load path_with_resolution
elsif File.file? path += ext
Surface.load path
end
end
end
\ No newline at end of file
......@@ -117,7 +117,7 @@ class Iduel < Game
User.new(id).friend = true
$config['iDuel']['friends'] << id
end
save_config
Config.save
end
rescue Exception => exception
$log.error('读取好友信息') {[exception.inspect, *exception.backtrace].collect{|str|str.encode("UTF-8")}.join("\n")}
......@@ -169,7 +169,7 @@ class Iduel < Game
announcements << Announcement.new(title.encode("UTF-8"), "http://www.duelcn.com/#{url}", nil)
end
$config['iDuel']['announcements'].replace announcements
save_config
Config.save
end
rescue Exception => exception
$log.error('公告') {[exception.inspect, *exception.backtrace].collect{|str|str.encode("UTF-8")}.join("\n")}
......
......@@ -8,7 +8,7 @@ class Window_Login
$game = Iduel.new
$config[$config['game']]['username'] = @username_inputbox.value
$config[$config['game']]['password'] = @remember_password.checked? ? @password_inputbox.value : nil
save_config
Config.save
$game.login(@username_inputbox.value, @password_inputbox.value)
@last_clicked = Time.now
when :register
......
#!/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
<<<<<<< HEAD
$config['screen']['height'] ||= 768
=======
$config['screen']['height'] ||= 640
>>>>>>> 8031a2a
end
def save_config(file="config.yml")
File.open(file, "w") { |file| YAML.dump($config, file) }
end
<<<<<<< HEAD
def register_url_protocol
if RUBY_PLATFORM["win"] || RUBY_PLATFORM["ming"]
require 'win32/registry'
path, command, icon = assoc_paths
Win32::Registry::HKEY_CLASSES_ROOT.create('mycard') { |reg| reg['URL Protocol'] = path.ljust path.bytesize }
Win32::Registry::HKEY_CLASSES_ROOT.create('mycard\shell\open\command') { |reg| reg[nil] = command.ljust command.bytesize }
Win32::Registry::HKEY_CLASSES_ROOT.create('mycard\DefaultIcon') { |reg| reg[nil] = icon.ljust icon.bytesize }
Win32::Registry::HKEY_CLASSES_ROOT.create('.ydk') { |reg| reg[nil] = 'mycard' }
Win32::Registry::HKEY_CLASSES_ROOT.create('.yrp') { |reg| reg[nil] = 'mycard' }
Win32::Registry::HKEY_CLASSES_ROOT.create('.deck') { |reg| reg[nil] = 'mycard' }
end
end
def assoc_paths
pwd = Dir.pwd.gsub('/', '\\')
path = '"' + pwd + '\ruby\bin\rubyw.exe" -C"' + pwd + '" -KU lib/main.rb'
command = path + ' "%1"'
icon = '"' + pwd + '\mycard.exe", 0'
[path, command, icon]
end
def assoc_need?
return false unless RUBY_PLATFORM["win"] || RUBY_PLATFORM["ming"]
return false if $config['no_assoc']
path, command, icon = assoc_paths
require 'win32/registry'
begin
Win32::Registry::HKEY_CLASSES_ROOT.open('mycard') { |reg| return true unless reg['URL Protocol'] == path }
Win32::Registry::HKEY_CLASSES_ROOT.open('mycard\shell\open\command') { |reg| return true unless reg[nil] == command }
Win32::Registry::HKEY_CLASSES_ROOT.open('mycard\DefaultIcon') { |reg| return true unless reg[nil] == icon }
Win32::Registry::HKEY_CLASSES_ROOT.open('.ydk') { |reg| return true unless reg[nil] == 'mycard' }
Win32::Registry::HKEY_CLASSES_ROOT.open('.yrp') { |reg| return true unless reg[nil] == 'mycard' }
Win32::Registry::HKEY_CLASSES_ROOT.open('.deck') { |reg| return true unless reg[nil] == 'mycard' }
rescue
return true
end
end
def request_assoc
require_relative 'widget_msgbox'
Widget_Msgbox.new("mycard", "即将进行文件关联, 弹出安全警告请点允许", ok: "确定", cancel: "取消") do |clicked|
if clicked == :ok
yield
else
Widget_Msgbox.new("mycard", "没有进行关联,要重新关联请删除config.yml")
$config['no_assoc'] = true
save_config
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) }
>>>>>>> 8031a2a
end
end
Windows = RUBY_PLATFORM["win"] || RUBY_PLATFORM["ming"]
Thread.abort_on_exception = true
require_relative 'resolution'
require_relative 'announcement'
require_relative 'config'
require_relative 'association'
#读取配置文件
load_config
save_config
$config = Config.load
Config.save
#读取命令行参数
log = "log.log"
log_level = "INFO"
......@@ -108,39 +30,30 @@ begin
when /^mycard:.*|\.ydk$|\.yrp$|\.deck$/
require_relative 'quickstart'
$scene = false
when /register_web_protocol/
<<<<<<< HEAD
$assoc_requested = true
=======
>>>>>>> 8031a2a
register_url_protocol
when /register_association/
Association.register
$scene = false
end
end
unless $scene == false
#初始化SDL
#加载文件
require 'logger'
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'
require_relative 'dialog'
require_relative 'graphics'
require_relative 'window'
require_relative 'widget_msgbox'
#日志
if log == "STDOUT" #调试用
log = STDOUT
end
$log = Logger.new(log)
$log.level = Logger.const_get log_level
#性能分析
if profile
if profile == "STDOUT"
......@@ -156,30 +69,38 @@ begin
Profiler__::start_profile
end
SDL::Event::APPMOUSEFOCUS = 1
SDL::Event::APPINPUTFOCUS = 2
SDL::Event::APPACTIVE = 4
SDL.putenv ("SDL_VIDEO_CENTERED=1");
SDL.init(INIT_VIDEO)
#初始化标题场景
WM::set_caption("MyCard", "MyCard")
$screen = Screen.open($config['screen']['width'], $config['screen']['height'], 0, HWSURFACE | ($config['screen']['fullscreen'] ? FULLSCREEN : 0))
TTF.init
#声音
begin
SDL.init(INIT_AUDIO)
Mixer.open(Mixer::DEFAULT_FREQUENCY, Mixer::DEFAULT_FORMAT, Mixer::DEFAULT_CHANNELS, 1536)
Mixer.set_volume_music(60)
rescue
nil
end
#标题场景
require_relative 'scene_title'
<<<<<<< HEAD
require_relative 'dialog'
=======
>>>>>>> 8031a2a
$scene = Scene_Title.new
#自动更新
#自动更新, 加载放到SDL前面会崩, 原因不明
require_relative 'update'
Update.start
WM::set_caption("MyCard v#{Update::Version}", "MyCard")
<<<<<<< HEAD
if assoc_need?
request_assoc do
register_url_protocol rescue Dialog.uac("ruby/bin/rubyw.exe", "-KU lib/main.rb register_web_protocol")
end
end
=======
require_relative 'dialog'
register_url_protocol rescue Dialog.uac("ruby/bin/rubyw.exe", "-KU lib/main.rb register_web_protocol")
>>>>>>> 8031a2a
#文件关联
Association.start
#初始化完毕
$log.info("main") { "初始化成功" }
end
rescue Exception => exception
......
module Resolution
module_function
def all
[
[1024, 768],
[1024, 640]
]
end
def system
return [1024, 768]
if Windows
require 'win32api'
get_system_metrics = Win32API.new "User32.dll", "GetSystemMetrics", ["L"], "L"
[get_system_metrics.call(0), get_system_metrics.call(1)]
else
`xrandr`.scan(/current (\d+) x (\d+)/).flatten.collect { |n| n.to_i }
end
end
def default
system_resolution = self.system
all.each do |width, height|
#p [width, height, system_resolution[0], system_resolution[1], (system_resolution[0] < width and system_resolution[1] < height)]
return [width, height] if system_resolution[0] > width and system_resolution[1] > height
end
all.last
end
end
\ No newline at end of file
......@@ -51,7 +51,7 @@ class Scene
# ● 开始处理
#--------------------------------------------------------------------------
def start
if $config['bgm'] and @@last_bgm != bgm and File.file? "audio/bgm/#{bgm}"
if $config['bgm'] and @@last_bgm != bgm and SDL.inited_system(INIT_AUDIO) != 0 and File.file? "audio/bgm/#{bgm}"
@@bgm.destroy if @@bgm
@@bgm = Mixer::Music.load "audio/bgm/#{bgm}"
Mixer.fade_in_music(@@bgm, -1, 800)
......@@ -130,7 +130,7 @@ class Scene
style = HWSURFACE
style |= FULLSCREEN if $config['screen']["fullscreen"]
$screen = Screen.open($config['screen']["width"], $config['screen']["height"], 0, style)
save_config
Config.save
end
when Key::F12
$scene = Scene_Title.new
......
......@@ -43,7 +43,7 @@ class Scene_Duel < Scene
@player_lp_window = Window_LP.new(0,0, @room.player1, true)
@opponent_lp_window = Window_LP.new(360,0, @room.player2, false)
@join_se = Mixer::Wave.load("audio/se/join.ogg")
@join_se = Mixer::Wave.load("audio/se/join.ogg") if SDL.inited_system(INIT_AUDIO) != 0
create_action_window
create_chat_window
......@@ -161,7 +161,7 @@ class Scene_Duel < Scene
player = $game.room.player1 == $game.user ? $game.room.player2 : $game.room.player1
if player
notify_send("对手加入房间", "#{player.name}(#{player.id})")
Mixer.play_channel(-1,@join_se,0)
Mixer.play_channel(-1,@join_se,0) if SDL.inited_system(INIT_AUDIO) != 0
else
notify_send("对手离开房间", "对手离开房间")
end
......@@ -175,7 +175,7 @@ class Scene_Duel < Scene
super
end
def refresh
@fieldback_window.card = $game.player_field.field[0] && $game.player_field.field[0].card_type == :场地魔法 && $game.player_field.field[0].position == :attack ? $game.player_field.field[0] : $game.opponent_field.field[0] && $game.opponent_field.field[0].card_type == :场地魔法 && $game.opponent_field.field[0].position == :attack ? $game.opponent_field.field[0] : nil
@fieldback_window.card = $game.player_field.field[0] && $game.player_field.field[0].card_type == :"场地魔法" && $game.player_field.field[0].position == :attack ? $game.player_field.field[0] : $game.opponent_field.field[0] && $game.opponent_field.field[0].card_type == :"场地魔法" && $game.opponent_field.field[0].position == :attack ? $game.opponent_field.field[0] : nil
@player_field_window.refresh
@opponent_field_window.refresh
@phases_window.player = $game.turn_player
......
......@@ -18,18 +18,14 @@ class Scene_Lobby < Scene
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
@background = Graphics.load('lobby', 'background', false)
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
<<<<<<< HEAD
@chat_window = Window_Chat.new(313,543,698,212)
=======
@chat_window = Window_Chat.new(313,$config['screen']['height'] - 225,698,212)
>>>>>>> 8031a2a
@count = 0
super
end
......
......@@ -12,7 +12,7 @@ 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
@background = Graphics.load('login', 'background', false)
#======================================================
# We'll pay fpr that soon or later.
#======================================================
......
#encoding: UTF-8
#==============================================================================
# Scene_Title
# Scene_Title
#------------------------------------------------------------------------------
# title
# title
#==============================================================================
require_relative 'scene'
require_relative 'widget_inputbox'
......@@ -15,8 +15,8 @@ class Scene_Title < Scene
title = title[rand(title.size)]
@background = Surface.load(title).display_format
Surface.blit(@background,0,0,0,0,$screen,0,0)
@command_window = Window_Title.new(title["left"] ? 200 : title["right"] ? 600 : 400, 300)
@decision_se = Mixer::Wave.load("audio/se/decision.ogg")
@command_window = Window_Title.new(title["left"] ? 200 : title["right"] ? 600 : 400, $config['screen']['height']/2-100)
@decision_se = Mixer::Wave.load("audio/se/decision.ogg") if SDL.inited_system(INIT_AUDIO) != 0
super
end
def clear(x,y,width,height)
......@@ -24,7 +24,7 @@ class Scene_Title < Scene
end
def determine
return unless @command_window.index
Mixer.play_channel(-1,@decision_se,0)
Mixer.play_channel(-1,@decision_se,0) if SDL.inited_system(INIT_AUDIO) != 0
case @command_window.index
when 0
require_relative 'scene_login'
......
......@@ -2,11 +2,7 @@ require 'open-uri'
require "fileutils"
require_relative 'card'
module Update
<<<<<<< HEAD
Version = '0.7.2'
=======
Version = '0.7.0'
>>>>>>> 8031a2a
Version = '0.7.3'
URL = "http://card.touhou.cc/mycard/update.json?version=#{Version}"
class <<self
attr_reader :thumbnails, :images, :status
......
......@@ -100,7 +100,7 @@ class Window_Config < Window
$scene = Scene_Config.new
else
$scene.last_bgm = nil
Mixer.fade_out_music(800)
Mixer.fade_out_music(800) if SDL.inited_system(INIT_AUDIO) != 0
end
draw_item(@index, 1)
when :avatar_cache
......@@ -113,7 +113,7 @@ class Window_Config < Window
when :return
$scene = Scene_Title.new
end
save_config
Config.save
end
def filesize_inspect(size)
case size
......
......@@ -14,11 +14,7 @@ class Window_RoomList < Window_Scrollable
@button.set_alpha(RLEACCEL, 255)
#@background = Surface.load 'graphics/lobby/roomitems.png'
#@contents = Surface.load 'graphics/lobby/roomitems.png'
<<<<<<< HEAD
super(x,y,@button.w / 3, 48 * 10)
=======
super(x,y,@button.w / 3, ($config['screen']['height'] - 288) / 48 * 48)
>>>>>>> 8031a2a
@item_max = 0
@font = TTF.open("fonts/wqy-microhei.ttc", 16)
@color = [0x03, 0x11, 0x22]
......
......@@ -8,12 +8,12 @@ class Window_Title < Window_List
@button.set_alpha(RLEACCEL,255)
@single_height = @button.h / Button_Count
super(x,y,@button.w / 3,WLH * Button_Count - (WLH - @button.h / Button_Count))
@cursor_se = Mixer::Wave.load 'audio/se/cursor.ogg'
@cursor_se = Mixer::Wave.load 'audio/se/cursor.ogg' if SDL.inited_system(INIT_AUDIO) != 0
self.items = [:决斗开始, :单人模式, :卡组编成, :选项设置, :退出游戏]
end
def index=(index)
if index and @index != index
Mixer.play_channel(-1,@cursor_se,0)
Mixer.play_channel(-1,@cursor_se,0) if SDL.inited_system(INIT_AUDIO) != 0
end
super
end
......
......@@ -208,7 +208,7 @@ class Ygocore < Game
announcements << Announcement.new(title, @@config['index'], nil)
end
$config['ygocore']['announcements'].replace announcements
save_config
Config.save
end
rescue Exception => exception
$log.error('公告读取失败') { [exception.inspect, *exception.backtrace].collect { |str| str.encode("UTF-8") }.join("\n") }
......
......@@ -8,7 +8,7 @@ class Window_Login
$game = Ygocore.new
$config[$config['game']]['username'] = @username_inputbox.value
$config[$config['game']]['password'] = @remember_password.checked? ? @password_inputbox.value : nil
save_config
Config.save
$game.login(@username_inputbox.value, @password_inputbox.value)
@last_clicked = Time.now
when :register
......
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.
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.
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.
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.
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