You need to sign in or sign up before continuing.
Commit 6790eed8 authored by 神楽坂玲奈's avatar 神楽坂玲奈

BGM显示标题

parent 0d173898
No preview for this file type
No preview for this file type
No preview for this file type
# $Id$
# = Description
#
# ruby-ogginfo gives you access to low level information on ogg files
# (bitrate, length, samplerate, encoder, etc... ), as well as tag.
# It is written in pure ruby.
#
#
# = Download
#
#
# http://rubyforge.org/projects/ruby-ogginfo/
#
#
# = Generate documentation
#
# rdoc --template=kilmer ogginfo.rb
#
#
# = Changelog
#
# [0.1 20/06/2004]
#
# * first public version
#
#
# License:: Ruby
# Author:: Guillaume Pierronnet (mailto:moumar_AT__rubyforge_DOT_org)
# Website:: http://ruby-ogginfo.rubyforge.org/
#
# see http://www.xiph.org/ogg/vorbis/docs.html for documentation on vorbis format
# http://www.xiph.org/ogg/vorbis/doc/v-comment.html
require "iconv"
# Raised on any kind of error related to ruby-ogginfo
class OggInfoError < StandardError ; end
class OggInfo
=begin
FIELDS_MAPPING = {
"title" => "songname",
"artist" => "artist",
"album" => "album",
"date" => "year",
"description" => "comment",
"tracknumber" => "tracknum",
"genre" => "genre"
}
=end
attr_reader :channels, :samplerate, :bitrate, :tag, :length
def initialize(filename, charset = "iso-8859-1")
begin
@file = File.new(filename, "rb")
find_page()
extract_infos()
find_page()
extract_tag(charset)
extract_end()
ensure
close
end
end
# "block version" of ::new()
def self.open(filename)
m = self.new(filename)
ret = nil
if block_given?
begin
ret = yield(m)
ensure
m.close
end
else
ret = m
end
ret
end
def close
@file.close if @file and not @file.closed?
end
def hastag?
not @tag.empty?
end
def to_s
"channels #{@channels} samplerate #{@samplerate} bitrate #{@bitrate} length #{@length}"
end
private
def find_page
header = 'OggS' # 0xf4 . 0x67 . 0x 67 . 0x53
bytes = @file.read(4)
bytes_read = 4
while header != bytes
#raise OggInfoError if bytes_read > 4096 or @file.eof? #bytes.nil?
raise OggInfoError if @file.eof? #bytes.nil?
bytes.slice!(0)
char = @file.read(1)
bytes_read += 1
bytes << char
end
end
def extract_infos
# @bitrate = {}
@file.seek(35, IO::SEEK_CUR) # seek after "vorbis"
# @channels, @samplerate, @bitrate["upper"], @bitrate["nominal"], @bitrate["lower"] =
@channels, @samplerate, up_br, br, down_br =
@file.read(17).unpack("CV4")
@bitrate =
if br == 0
if up == 2**32 - 1 or down == 2**32 - 1
0
else
(up_br + down_br)/2
end
else
br
end
end
def extract_tag(charset)
@tag = {}
@file.seek(22, IO::SEEK_CUR)
segs = @file.read(1).unpack("C")[0]
@file.seek(segs + 7, IO::SEEK_CUR)
size = @file.read(4).unpack("V")[0]
@file.seek(size, IO::SEEK_CUR)
tag_size = @file.read(4).unpack("V")[0]
#ic = Iconv.new(charset, "utf8")
tag_size.times do |i|
size = @file.read(4).unpack("V")[0]
com = @file.read(size)
comment = com
comment.force_encoding "UTF-8"
# begin
# comment = ic.iconv( com )
# rescue Iconv::IllegalSequence, Iconv::InvalidCharacter
# comment = com
# end
key, val = comment.split(/=/)
@tag[key.downcase] = val
end
#ic.close
end
def extract_end
begin #Errno::EINVAL
@file.seek(-5000, IO::SEEK_END) #FIXME size of seeking
find_page
pos = @file.read(6).unpack("x2 V")[0] #FIXME pos is int64
@length = pos.to_f / @samplerate
rescue Errno::EINVAL
@length = 0
end
end
end
if $0 == __FILE__
while filename = ARGV.shift
puts "Getting info from #{filename}"
begin
ogg = OggInfo.new(filename)
rescue OggInfoError
puts "error: doesn't appear to be an ogg file"
else
puts ogg
ogg.tag.each { |key, value|
puts "#{key} => #{value}"
}
end
puts
end
end
\ No newline at end of file
......@@ -6,10 +6,13 @@
#==============================================================================
require_relative 'fpstimer'
require_relative 'game'
require_relative 'window_bgm'
require_relative 'ogginfo'
class Scene
attr_reader :windows
attr_reader :background
@@fpstimer = FPSTimer.new
@@last_bgm = @@bgm = nil
#--------------------------------------------------------------------------
# ● 主处理
#--------------------------------------------------------------------------
......@@ -43,7 +46,13 @@ class Scene
# ● 开始处理
#--------------------------------------------------------------------------
def start
if @@last_bgm != self.class::BGM
@@bgm.destroy if @@bgm
@@bgm = Mixer::Music.load "audio/bgm/#{self.class::BGM}"
Mixer.fade_in_music(@@bgm, -1, 800)
@bgm_window = Window_BGM.new OggInfo.new("audio/bgm/#{self.class::BGM}", "UTF-8").tag["title"]
@@last_bgm = self.class::BGM
end
end
def refresh_rect(x, y, width, height, background=@background, ox=0,oy=0)
Surface.blit(background,x+ox,y+oy,width,height,$screen,x,y)
......@@ -65,6 +74,7 @@ class Scene
# ● 更新画面
#--------------------------------------------------------------------------
def update
@bgm_window.update if @bgm_window and !@bgm_window.destroyed?
while event = Event.poll
handle(event)
end
......
......@@ -21,6 +21,7 @@ class Scene_Duel < Scene
attr_reader :player_field_window
attr_reader :opponent_field_window
attr_reader :fieldback_window
BGM = "audio/bgm/duel.ogg"
def initialize(room, deck=nil)
super()
@room = room
......@@ -28,8 +29,6 @@ class Scene_Duel < Scene
end
def start
WM::set_caption("MyCard - #{$config['game']} - #{$game.user.name}(#{$game.user.id}) - #{@room.name}(#{@room.id})", "MyCard")
@bgm = Mixer::Music.load "audio/bgm/duel.ogg"
Mixer.fade_in_music(@bgm, -1, 800)
@background = Surface.load("graphics/field/main.png").display_format
Surface.blit(@background, 0, 0, 0, 0, $screen, 0, 0)
......
......@@ -13,6 +13,7 @@ class Scene_Lobby < Scene
require_relative 'chatmessage'
require_relative 'scene_duel'
attr_reader :chat_window
BGM = "lobby.ogg"
def start
WM::set_caption("MyCard - #{$config['game']} - #{$game.user.name}(#{$game.user.id})", "MyCard")
$game.refresh
......@@ -24,10 +25,6 @@ class Scene_Lobby < Scene
@active_window = @roomlist
@chat_window = Window_Chat.new(313,543,698,212)
bgm = Mixer::Music.load("audio/bgm/lobby.ogg")
Mixer.fade_in_music(bgm, -1, 800)
@bgm.destroy if @bgm
@bgm = bgm
@count = 0
super
end
......
......@@ -8,6 +8,7 @@ require_relative 'window_gameselect'
require_relative 'window_announcements'
require_relative 'window_login'
require_relative 'scene_replay'
BGM = "title.ogg"
class Scene_Login < Scene
def start
WM::set_caption("MyCard", "MyCard")
......@@ -15,6 +16,7 @@ class Scene_Login < Scene
$config['game'] = 'iDuel' #临时修补点击过一次局域网之后无限进入局域网的问题
@gameselect_window = Window_GameSelect.new(117,269)
@announcements_window = Window_Announcements.new(313,265,600,24)
super
end
def update
@announcements_window.update
......
......@@ -6,6 +6,7 @@
#==============================================================================
require_relative 'scene'
require_relative 'window_title'
BGM = 'title.ogg'
class Scene_Title < Scene
def start
WM::set_caption("MyCard", "MyCard")
......@@ -18,9 +19,7 @@ class Scene_Title < Scene
#@logo_window = Window.new(@command_window.x-(logo.w-@command_window.width)/2,150,logo.w,logo.h)
#@logo_window.contents = logo
#$screen.update_rect(0,0,0,0)
@bgm = Mixer::Music.load 'audio/bgm/title.ogg'
@decision_se = Mixer::Wave.load("audio/se/decision.ogg")
Mixer.fade_in_music @bgm, -1, 800
super
end
......
require_relative 'window'
class Window_BGM < Window
def initialize(bgm_name)
@bgm_name = bgm_name
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 18)
width = @font.text_size("♪#{@bgm_name}")[0]
@count = 0
@contents = @font.render_blended_utf8("♪#{@bgm_name}" , 255,255,255)
super($config['screen']['width'], 0, width, 24,999)
end
def update
if @count >= 180
if @x >= $config['screen']['width']
self.destroy
else
self.x += 1.5
end
elsif $config['screen']['width'] - @x < @width
self.x -= 1.5
else
@count += 1
end
end
end
\ No newline at end of file
......@@ -4,7 +4,7 @@ class Window_CardInfo < Window
def initialize(x,y)
super(x,y,1024-x,524,300)
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 16)
self.card = Game_Card.new Card.find('name' => :mycard, 'number' => :"000000", 'lore' => "提示:\n快捷键:\nF10退出房间\nF12 返回主界面", 'card_type' => :" ", 'stats' => "", 'archettypes' => "", "mediums" => "", "tokens" => 0)
self.card = Game_Card.new Card.find('name' => :mycard, 'number' => :"000000", 'lore' => "提示:\n快捷键:\nF10 退出房间\nF12 返回主界面", 'card_type' => :" ", 'stats' => "", 'archettypes' => "", "mediums" => "", "tokens" => 0)
end
def card=(card)
return if card.nil? or card == @card or !card.known?
......
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