Commit 43a04a2a authored by 神楽坂玲奈's avatar 神楽坂玲奈

公告滚动

parent fa9b2490
class Announcement
attr_accessor :title
attr_accessor :url
attr_accessor :time
def initialize(title, url, time=nil)
@title = title
@url = url
@time = time
end
end
#encoding: UTF-8
class ChatMessage
attr_accessor :user, :message, :channel, :time
def initialize(user,message,channel=:lobby,time=Time.now)
......
......@@ -121,14 +121,19 @@ class Iduel < Game
(@conn.write info) rescue Game_Event.push Game_Event::Error.new($!.class.to_s, $!.message)
end
#公告
$config['iDuel']['announcements'] ||= {"正在读取公告..." => nil}
$config['iDuel']['announcements'] ||= [Announcement.new("正在读取公告...", nil, nil)]
Thread.new do
begin
open('http://www.duelcn.com/topic-Announce.html') do |file|
file.set_encoding "GBK"
announcements = {}
file.read.scan(/<li><em>.*?<\/em><a href="(.*?)" title="(.*?)" target="_blank">.*?<\/a><\/li>/).each do |url, title|
announcements[title.encode("UTF-8")] = "http://www.duelcn.com/#{url}"
announcements = []
file.read.scan(/<li><em>(.*?)<\/em><a href="(.*?)" title="(.*?)" target="_blank">.*?<\/a><\/li>/).each do |time, url, title|
if time =~ /(\d+)-(\d+)-(\d+)/
time = Time.new($1, $2, $3)
else
time = nil
end
announcements << Announcement.new(title.encode("UTF-8"), "http://www.duelcn.com/#{url}", time)
end
$config['iDuel']['announcements'].replace announcements
save_config
......
......@@ -14,6 +14,7 @@ begin
File.open(file,"w"){|file| YAML.dump($config, file)}
end
require_relative 'announcement'
#读取配置文件
load_config
save_config
......
class Window_Announcements < Window
def initialize(x,y,width,height)
super(x,y,width,height)
@index = 0
@count = 0
@items = $config[$config['game']]['announcements']
@last_item = @item = @items.first
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 18)
@color = [44,64,78]
@last_announcement = @items.first
@transforming = nil
refresh
end
def refresh
clear
@font.draw_blended_utf8(@contents, @items.first[0], 0, 0, *@color)
@index = 0 if !@items[@index]
if @transforming
@font.draw_blended_utf8(@contents, @last_item.title, 0, -@transforming, *@color)
@font.draw_blended_utf8(@contents, @item.title, 0, -@transforming+24, *@color)
else
@font.draw_blended_utf8(@contents, @item.title, 0, 0, *@color)
end
end
def update
if @items.first != @last_announcement
if @transforming
refresh
@last_announcement = @items.first
if @transforming >= 24
@transforming = nil
@last_item = @item
else
@transforming += 1
end
else
if @last_item != @item
@transforming = 0
end
end
if @item != @items[@index]
@index = 0
@count = 0
@item = @items[@index]
end
if @focus
@count = 0
else
@count += 1
end
if @count>= 120
@index = (@index + 1) % @items.size
@count = 0
@item = @items[@index]
end
super
end
def clicked
require 'launchy'
Launchy.open(@items.first[1]) if @items.first[1]
Launchy.open(@item.url) if @item.url
end
def mousemoved(x,y)
@focus = true
end
def lostfocus(active_window=nil)
@focus = false
end
end
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