Commit cafaae12 authored by zh99998's avatar zh99998

滚动条

parent c89feb3c
...@@ -44,7 +44,7 @@ class FPSTimer ...@@ -44,7 +44,7 @@ class FPSTimer
private private
def wait(nxt) def wait(nxt)
print "-"# 加了这货tk输入框不卡,原因不明=.= #print "-"# 加了这货tk输入框不卡,原因不明=.=
sleeptime = nxt-get_ticks sleeptime = nxt-get_ticks
sleep(sleeptime) if sleeptime > 0 sleep(sleeptime) if sleeptime > 0
end end
......
...@@ -130,7 +130,8 @@ class Game_Event ...@@ -130,7 +130,8 @@ class Game_Event
@title = title @title = title
@message = message @message = message
@fatal = fatal @fatal = fatal
$log.error(@title){@message} $log.error(@fatal ? "致命错误" : "一般错误"){"#{@title}: #{@message}"}
$log.debug caller
end end
end end
class Unknown < Error class Unknown < Error
......
#!/usr/bin/env ruby #!/usr/bin/env ruby
#encoding: UTF-8 #encoding: UTF-8
GC.disable
begin begin
#读取配置文件 #读取配置文件
require 'yaml' require 'yaml'
...@@ -53,5 +53,6 @@ rescue Exception => exception ...@@ -53,5 +53,6 @@ rescue Exception => exception
$scene = Scene_Error.new $scene = Scene_Error.new
retry retry
ensure ensure
#(Thread.list-[Thread.main]).each{|t|t.exit} #消灭其他
$log.close $log.close
end end
\ No newline at end of file
...@@ -83,9 +83,9 @@ class Scene ...@@ -83,9 +83,9 @@ class Scene
update_active_window(event.x, event.y) update_active_window(event.x, event.y)
@active_window.clicked if @active_window @active_window.clicked if @active_window
when 4 when 4
@active_window.cursor_up if @active_window @active_window.scroll_up if @active_window
when 5 when 5
@active_window.cursor_down if @active_window @active_window.scroll_down if @active_window
end end
when Event::KeyDown when Event::KeyDown
case event.sym case event.sym
......
...@@ -80,17 +80,14 @@ class Scene_Duel < Scene ...@@ -80,17 +80,14 @@ class Scene_Duel < Scene
end end
def handle(event) def handle(event)
case event case event
when Event::MouseButtonUp when Event::MouseButtonDown
case event.button case event.button
when Mouse::BUTTON_LEFT
if @phases_window.include? event.x, event.y
@phases_window.mousemoved event.x, event.y
change_phase(Window_Phases::Phases[@phases_window.index])
end
when Mouse::BUTTON_RIGHT when Mouse::BUTTON_RIGHT
if @player_field_window.action_window if @player_field_window.action_window
@player_field_window.action_window.next @player_field_window.action_window.next
end end
else
super
end end
when Event::KeyDown when Event::KeyDown
case event.sym case event.sym
......
...@@ -46,12 +46,12 @@ class Scene_Hall < Scene ...@@ -46,12 +46,12 @@ class Scene_Hall < Scene
$game.join 'localhost' $game.join 'localhost'
@joinroom_msgbox = Widget_Msgbox.new("加入房间", "正在加入房间") @joinroom_msgbox = Widget_Msgbox.new("加入房间", "正在加入房间")
when Key::F5 when Key::F5
if @roomlist.list and room = @roomlist.list.find{|room|room.player1 == $game.user or room.player2 == $game.user} if @roomlist.items and room = @roomlist.items.find{|room|room.player1 == $game.user or room.player2 == $game.user}
$game.qroom room $game.qroom room
end end
$game.refresh $game.refresh
when Key::F12 when Key::F12
if @roomlist.list and room = @roomlist.list.find{|room|room.player1 == $game.user or room.player2 == $game.user} if @roomlist.items and room = @roomlist.items.find{|room|room.player1 == $game.user or room.player2 == $game.user}
$game.qroom room $game.qroom room
end end
$game.exit $game.exit
...@@ -75,9 +75,9 @@ class Scene_Hall < Scene ...@@ -75,9 +75,9 @@ class Scene_Hall < Scene
def handle_game(event) def handle_game(event)
case event case event
when Game_Event::AllUsers when Game_Event::AllUsers
@userlist.list = $game.users @userlist.items = $game.users
when Game_Event::AllRooms when Game_Event::AllRooms
@roomlist.list = $game.rooms @roomlist.items = $game.rooms
when Game_Event::Join when Game_Event::Join
require_relative 'scene_duel' require_relative 'scene_duel'
$scene = Scene_Duel.new(event.room, Deck.load("test1.TXT")) $scene = Scene_Duel.new(event.room, Deck.load("test1.TXT"))
...@@ -103,7 +103,7 @@ class Scene_Hall < Scene ...@@ -103,7 +103,7 @@ class Scene_Hall < Scene
def determine def determine
case @active_window case @active_window
when @roomlist when @roomlist
return unless @roomlist.index and room = @roomlist.list[@roomlist.index] return unless @roomlist.index and room = @roomlist.items[@roomlist.index]
if room.full? if room.full?
$game.watch room $game.watch room
@joinroom_msgbox = Widget_Msgbox.new("加入房间", "正在加入观战") @joinroom_msgbox = Widget_Msgbox.new("加入房间", "正在加入观战")
......
# To change this template, choose Tools | Templates
# and open the template in the editor.
class Widget_ScrollBar < Window class Widget_ScrollBar < Window
def initialize(x,y,height,max) attr_reader :scroll, :scroll_max
def initialize(parent_window,x,y,height)
super(x,y,20,height,400) super(x,y,20,height,400)
@max = max @parent_window = parent_window
@up_button = Surface.load('graphics/hall/scroll_up.png') @up_button = Surface.load('graphics/hall/scroll_up.png')
@down_button = Surface.load('graphics/hall/scroll_down.png') @down_button = Surface.load('graphics/hall/scroll_down.png')
@back = Surface.load('graphics/hall/scroll_background.png') @back = Surface.load('graphics/hall/scroll_background.png')
@bar = Surface.load('graphics/hall/scroll.png') @bar = Surface.load('graphics/hall/scroll.png')
@contents.fill_rect(0,0,@width, @height, 0xFFFFFFFF) @contents.fill_rect(0,0,@width, @height, 0xFFFFFFFF)
@scroll ||= 0
@scroll_max ||= 0
Surface.transform_draw(@back,@contents,0,1,@contents.h.to_f/@back.h,0,0,0,0,0) Surface.transform_draw(@back,@contents,0,1,@contents.h.to_f/@back.h,0,0,0,0,0)
refresh refresh
end end
...@@ -42,12 +42,14 @@ class Widget_ScrollBar < Window ...@@ -42,12 +42,14 @@ class Widget_ScrollBar < Window
when :up when :up
Surface.blit(@up_button,status*20,0,20,20,@contents,0,0) Surface.blit(@up_button,status*20,0,20,20,@contents,0,0)
when :scroll when :scroll
Surface.blit(@bar,status*20,0,20,24,@contents,0,20) return if @scroll_max.zero?
Surface.blit(@bar,status*20,0,20,24,@contents,0,20+(@height-40-24)*@scroll/(@scroll_max))
when :down when :down
Surface.blit(@down_button,status*20,0,20,20,@contents,0,@height-20) Surface.blit(@down_button,status*20,0,20,20,@contents,0,@height-20)
end end
end end
def refresh def refresh
clear
[:up, :scroll, :down].each do |index| [:up, :scroll, :down].each do |index|
draw_item(index, @index==index ? 1 : 0) draw_item(index, @index==index ? 1 : 0)
end end
...@@ -63,9 +65,24 @@ class Widget_ScrollBar < Window ...@@ -63,9 +65,24 @@ class Widget_ScrollBar < Window
end end
end end
def clicked def clicked
p @index case @index
#case index when :up
#when :up @parent_window.scroll -= 1
#end when :down
@parent_window.scroll += 1
end
end
def scroll=(scroll)
return unless scroll and scroll.between?(0,@scroll_max)
@scroll = scroll
refresh
end
def scroll_max=(scroll_max)
return unless scroll_max and scroll_max != @scroll_max and scroll_max >=0
@scroll_max = scroll_max
if @scroll >= @scroll_max
@scroll = @scroll_max
end
refresh
end end
end end
...@@ -74,10 +74,16 @@ class Window ...@@ -74,10 +74,16 @@ class Window
def lostfocus(active_window=nil) def lostfocus(active_window=nil)
#子类定义 #子类定义
end end
def cursor_up def cursor_up(wrap=false)
#子类定义 #子类定义
end end
def cursor_down def cursor_down(wrap=false)
#子类定义 #子类定义
end end
def scroll_up
cursor_up
end
def scroll_down
cursor_down
end
end end
\ No newline at end of file
...@@ -3,7 +3,7 @@ class Window_Action < Window_List ...@@ -3,7 +3,7 @@ class Window_Action < Window_List
Color = [0xFF,0xFF,0xFF] Color = [0xFF,0xFF,0xFF]
Color_Disabled = [0x66,0x66,0x66] Color_Disabled = [0x66,0x66,0x66]
Color_Selected = [0xFF,0xFF,0x00] Color_Selected = [0xFF,0xFF,0x00]
def initialize#,list,list_available=Array.new(list.size, true)) def initialize#,items,items_available=Array.new(items.size, true))
super(0,0,123,20*WLH,300) super(0,0,123,20*WLH,300)
#@skin = Surface.load 'graphics/field/action.png' #@skin = Surface.load 'graphics/field/action.png'
@up = Surface.load('graphics/field/action_up.png') @up = Surface.load('graphics/field/action_up.png')
...@@ -17,13 +17,13 @@ class Window_Action < Window_List ...@@ -17,13 +17,13 @@ class Window_Action < Window_List
@font = TTF.open('fonts/WenQuanYi Micro Hei.ttf', 16) @font = TTF.open('fonts/WenQuanYi Micro Hei.ttf', 16)
@visible = false @visible = false
end end
def list=(list) def items=(items)
if list if items
@list = list.keys @items = items.keys
@list_available = list.values @items_available = items.values
@height = @viewport[3] = @list.size*WLH+15*2 @height = @viewport[3] = @items.size*WLH+15*2
@item_max = @list.size @item_max = @items.size
@index = @list_available.find_index(true) || 0 @index = @items_available.find_index(true) || 0
refresh refresh
@visible = true @visible = true
else else
...@@ -32,7 +32,7 @@ class Window_Action < Window_List ...@@ -32,7 +32,7 @@ class Window_Action < Window_List
end end
def clear(x=0,y=0,width=@width,height=@height) def clear(x=0,y=0,width=@width,height=@height)
@contents.put(@up, 0, 0) @contents.put(@up, 0, 0)
Surface.transform_draw(@middle,@contents,0,1,(@list.size*WLH+20).to_f/@middle.h,0,0,0,15,Surface::TRANSFORM_SAFE) #+那里,我不知道为什么需要这么做,但是如果不+ 内容和底边会有一点空白 Surface.transform_draw(@middle,@contents,0,1,(@items.size*WLH+20).to_f/@middle.h,0,0,0,15,Surface::TRANSFORM_SAFE) #+那里,我不知道为什么需要这么做,但是如果不+ 内容和底边会有一点空白
@contents.put(@down, 0, @height-15) @contents.put(@down, 0, @height-15)
end end
def index=(index) def index=(index)
...@@ -44,19 +44,19 @@ class Window_Action < Window_List ...@@ -44,19 +44,19 @@ class Window_Action < Window_List
def draw_item(index, status=0) def draw_item(index, status=0)
case status case status
when 0 when 0
color = @list_available[index] ? Color : Color_Disabled color = @items_available[index] ? Color : Color_Disabled
@font.draw_blended_utf8(@contents, @list[index] , (@width-16*6)/2, index*WLH+15, *color) @font.draw_blended_utf8(@contents, @items[index] , (@width-16*6)/2, index*WLH+15, *color)
when 1 when 1
@font.draw_blended_utf8(@contents, @list[index] , (@width-16*6)/2, index*WLH+15, *Color_Selected) @font.draw_blended_utf8(@contents, @items[index] , (@width-16*6)/2, index*WLH+15, *Color_Selected)
end end
end end
def next def next
if index = @list_available[@index.next...@list.size].find_index(true) if index = @items_available[@index.next...@items.size].find_index(true)
self.index = index + @index.next self.index = index + @index.next
elsif index = @list_available[0..@index].find_index(true) elsif index = @items_available[0..@index].find_index(true)
self.index = index self.index = index
else else
self.index = (@index + 1) % @list.size self.index = (@index + 1) % @items.size
end end
end end
def mousemoved(x,y) def mousemoved(x,y)
......
...@@ -13,7 +13,7 @@ class Window_Chat < Window ...@@ -13,7 +13,7 @@ class Window_Chat < Window
super(x,y,width,height) super(x,y,width,height)
@chat_input = Widget_InputBox.new(416,723,586,24){|text|$game.chat text; add($game.user, text)} @chat_input = Widget_InputBox.new(416,723,586,24){|text|$game.chat text; add($game.user, text)}
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 16) @font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 16)
@scroll = Widget_ScrollBar.new(@x+@width-20,@y,@height,0) @scroll = Widget_ScrollBar.new(self,@x+@width-20,@y,@height)
@list = [] @list = []
end end
def add(user, content) def add(user, content)
......
...@@ -102,7 +102,7 @@ class Window_Field < Window ...@@ -102,7 +102,7 @@ class Window_Field < Window
end end
if index.nil? or !@items.has_key?(index) or (index == :deck and @field.deck.empty?) or (index == :removed and @field.removed.empty?) or (index == :extra and @field.extra.empty?) or (index == :graveyard and @field.graveyard.empty?) if index.nil? or !@items.has_key?(index) or (index == :deck and @field.deck.empty?) or (index == :removed and @field.removed.empty?) or (index == :extra and @field.extra.empty?) or (index == :graveyard and @field.graveyard.empty?)
@index = nil @index = nil
@action_window.list = nil if @action_window @action_window.items = nil if @action_window
else else
@index = index @index = index
draw_item(@index, 1) draw_item(@index, 1)
...@@ -185,7 +185,7 @@ class Window_Field < Window ...@@ -185,7 +185,7 @@ class Window_Field < Window
} }
end end
if @action_window if @action_window
@action_window.list = @action_names @action_window.items = @action_names
@action_window.x = @x + @items[@index][0] - (@action_window.width - @items[@index][2])/2 @action_window.x = @x + @items[@index][0] - (@action_window.width - @items[@index][2])/2
@action_window.y = @y + @items[@index][1] - @action_window.height @action_window.y = @y + @items[@index][1] - @action_window.height
end end
...@@ -206,10 +206,10 @@ class Window_Field < Window ...@@ -206,10 +206,10 @@ class Window_Field < Window
@action_window.cursor_down if @action_window @action_window.cursor_down if @action_window
end end
def cursor_left def cursor_left
#self.index = @index ? (@index - 1) % [@list.size, @item_max].min : 0 #self.index = @index ? (@index - 1) % [@items.size, @item_max].min : 0
end end
def cursor_right def cursor_right
#self.index = @index ? (@index + 1) % [@list.size, @item_max].min : 0 #self.index = @index ? (@index + 1) % [@items.size, @item_max].min : 0
end end
def lostfocus(active_window=nil) def lostfocus(active_window=nil)
if active_window != @action_window if active_window != @action_window
......
...@@ -6,29 +6,29 @@ class Window_GameSelect < Window_List ...@@ -6,29 +6,29 @@ class Window_GameSelect < Window_List
@color = [255,255,255] @color = [255,255,255]
@game_color = [47,156,192] @game_color = [47,156,192]
@game_stroke_color = [0xFF,0xFF,0xFF] @game_stroke_color = [0xFF,0xFF,0xFF]
@list = [] @items = []
Dir.glob('lib/**/game.yml') do |file| Dir.glob('lib/**/game.yml') do |file|
game = YAML.load_file(file) game = YAML.load_file(file)
if game.is_a?(Hash) && game["name"] if game.is_a?(Hash) && game["name"]
game['file'] ||= 'game.rb' game['file'] ||= 'game.rb'
game['file'] = File.expand_path(game['file'], File.dirname(file)) game['file'] = File.expand_path(game['file'], File.dirname(file))
@list << game @items << game
else else
$log.warn "#{game.inspect}读取失败(#{file})" $log.warn "#{game.inspect}读取失败(#{file})"
end end
end end
super(x,y,160,@list.size*WLH) super(x,y,160,@items.size*WLH)
clear clear
@button = Surface.load("graphics/login/game_background.png") @button = Surface.load("graphics/login/game_background.png")
#@button.set_alpha(RLEACCEL,255) #@button.set_alpha(RLEACCEL,255)
self.list = @list self.items = @items
self.index = @list.find_index{|game|game["name"] == game_name} || 0 self.index = @items.find_index{|game|game["name"] == game_name} || 0
clicked clicked
refresh refresh
end end
def draw_item(index, status=0) def draw_item(index, status=0)
Surface.blit(@button, @button.w/3*status, 0, @button.w/3, @button.h, @contents, 0, WLH*index) Surface.blit(@button, @button.w/3*status, 0, @button.w/3, @button.h, @contents, 0, WLH*index)
draw_stroked_text(@list[index]["name"], 24, WLH*index+14, 2) draw_stroked_text(@items[index]["name"], 24, WLH*index+14, 2)
end end
def item_rect(index) def item_rect(index)
[0, WLH*index, @button.w, @button.h] [0, WLH*index, @button.w, @button.h]
...@@ -54,7 +54,7 @@ class Window_GameSelect < Window_List ...@@ -54,7 +54,7 @@ class Window_GameSelect < Window_List
draw_item(@index, 1) draw_item(@index, 1)
end end
def clicked def clicked
load @list[@index]["file"] #TODO: load的这种架构微蛋疼,一时想不到更好的方案 load @items[@index]["file"] #TODO: load的这种架构微蛋疼,一时想不到更好的方案
@login_window.destroy if @login_window @login_window.destroy if @login_window
@login_window = Window_Login.new(316,316,$config["username"],$config["password"]) @login_window = Window_Login.new(316,316,$config["username"],$config["password"])
end end
......
#encoding: UTF-8 #encoding: UTF-8
#============================================================================== #==============================================================================
# ■ Window_RoomList # ■ Window_Roomitems
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
#  大厅内房间列表 #  大厅内房间列表
#============================================================================== #==============================================================================
require_relative 'window' require_relative 'window'
class Window_List < Window class Window_List < Window
attr_reader :list attr_reader :items
attr_reader :index attr_reader :index
def initialize(x, y, width, height, z=200) def initialize(x, y, width, height, z=200)
@list ||= [] @items ||= []
@index ||= nil @index ||= nil
super(x,y,width, height,z) super(x,y,width, height,z)
@o_index = 0
@item_max = 0
@column_max = 1
end end
def index=(index) def index=(index)
index = nil if index < 0 or index >= @item_max if index index = nil if index < 0 or index >= @items.size if index
return if index == @index return if index == @index
if @index if @index
clear(*item_rect(@index)) clear(*item_rect(@index))
draw_item(@index, 0) draw_item(@index, 0) if @items[@index]
end end
if index.nil? or index < 0 or index >= @item_max if index.nil? or index < 0 or index >= @items.size
@index = nil @index = nil
else else
@index = index @index = index
...@@ -37,30 +34,29 @@ class Window_List < Window ...@@ -37,30 +34,29 @@ class Window_List < Window
#子类定义 #子类定义
end end
def item_rect(index) def item_rect(index)
[0, @index*self.class::WLH, @width, self.class::WLH] [0, index*self.class::WLH, @width, self.class::WLH]
end end
def list=(list) def items=(items)
@list = list @items = items
@item_max = @list.size
refresh refresh
end end
def refresh def refresh
clear clear
@item_max.times {|index|draw_item(index, index==@index ? 1 : 0)} @items.each_index {|index|draw_item(index, index==@index ? 1 : 0)}
end end
def cursor_up def cursor_up(wrap=false)
self.index = @index ? (@index - @column_max) % [@list.size, @item_max].min : 0 self.index = @index ? (@index - @column_max) % [@items.size, @items.size].min : 0
end end
def cursor_down def cursor_down(wrap=false)
#if @index #if @index
self.index = @index ? ((@index + @column_max) % [@list.size, @item_max].min) : 0 self.index = @index ? ((@index + @column_max) % [@items.size, @items.size].min) : 0
#p @index, @index + @column_max, [@list.size, @item_max].min, (@index + @column_max) % [@list.size, @item_max].min, @index ? ((@index + @column_max) % [@list.size, @item_max].min) : 0 #p @index, @index + @column_max, [@items.size, @items.size].min, (@index + @column_max) % [@items.size, @items.size].min, @index ? ((@index + @column_max) % [@items.size, @items.size].min) : 0
end end
def cursor_left def cursor_left
self.index = @index ? (@index - 1) % [@list.size, @item_max].min : 0 self.index = @index ? (@index - 1) % [@items.size, @items.size].min : 0
end end
def cursor_right def cursor_right
self.index = @index ? (@index + 1) % [@list.size, @item_max].min : 0 self.index = @index ? (@index + 1) % [@items.size, @items.size].min : 0
end end
def mousemoved(x,y) def mousemoved(x,y)
#子类定义 #子类定义
......
class Window_Phases < Window_List class Window_Phases < Window_List
WLH = 81 #其实是列宽 WLH = 81 #其实是列宽
Phases = [:DP, :SP, :M1, :BP, :M2, :EP]
def initialize(x,y) def initialize(x,y)
@phases_player = Surface.load('graphics/system/phases_player.png') @phases_player = Surface.load('graphics/system/phases_player.png')
@phases_player.set_alpha(RLEACCEL,255) @phases_player.set_alpha(RLEACCEL,255)
@phases_opponent = Surface.load('graphics/system/phases_opponent.png') @phases_opponent = Surface.load('graphics/system/phases_opponent.png')
@phases_opponent.set_alpha(RLEACCEL,255) @phases_opponent.set_alpha(RLEACCEL,255)
super(x,y,5*WLH+@phases_player.w/3, @phases_player.h/6) super(x,y,5*WLH+@phases_player.w/3, @phases_player.h/6)
@column_max = @item_max = 6 @items = [:DP, :SP, :M1, :BP, :M2, :EP]
self.player = true self.player = true
end end
def player=(player) def player=(player)
...@@ -17,7 +16,7 @@ class Window_Phases < Window_List ...@@ -17,7 +16,7 @@ class Window_Phases < Window_List
refresh refresh
end end
def phase=(phase) def phase=(phase)
phase = Phases.index(phase) unless (0..5).include? phase phase = @items.index(phase) unless (0..5).include? phase
return if phase == @phase return if phase == @phase
@index = @phase @index = @phase
@phase = phase @phase = phase
...@@ -36,4 +35,7 @@ class Window_Phases < Window_List ...@@ -36,4 +35,7 @@ class Window_Phases < Window_List
def clear(x=0,y=0,width=@width,height=@height) def clear(x=0,y=0,width=@width,height=@height)
@contents.fill_rect(x,y,width, height, 0x00000000) @contents.fill_rect(x,y,width, height, 0x00000000)
end end
def clicked
$scene.change_phase(@items[@index])
end
end end
\ No newline at end of file
...@@ -18,7 +18,7 @@ class Window_RoomChat < Window ...@@ -18,7 +18,7 @@ class Window_RoomChat < Window
end end
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 14) @font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 14)
@contents.fill_rect(0,0,@width, @height, 0x99FFFFFF) @contents.fill_rect(0,0,@width, @height, 0x99FFFFFF)
@scroll = Widget_ScrollBar.new(@x+@width-20,@y,@height,0) @scroll = Widget_ScrollBar.new(self,@x+@width-20,@y,@height)
@list = [] @list = []
$chat_window = self $chat_window = self
end end
......
#encoding: UTF-8 #encoding: UTF-8
#============================================================================== #==============================================================================
# ■ Window_RoomList # ■ Window_Roomitems
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
#  大厅内房间列表 #  大厅内房间列表
#============================================================================== #==============================================================================
require_relative 'window_scrollable'
class Window_RoomList < Window_List class Window_RoomList < Window_Scrollable
attr_reader :list attr_reader :items
WLH = 48 WLH = 48
def initialize(x, y, list) def initialize(x, y, items)
@button = Surface.load('graphics/hall/room.png') @button = Surface.load('graphics/hall/room.png')
@button.set_alpha(RLEACCEL, 255) @button.set_alpha(RLEACCEL, 255)
#@background = Surface.load 'graphics/hall/roomlist.png' #@background = Surface.load 'graphics/hall/roomitems.png'
#@contents = Surface.load 'graphics/hall/roomlist.png' #@contents = Surface.load 'graphics/hall/roomitems.png'
super(x,y,@button.w / 3, 48 * 10) super(x,y,@button.w / 3, 48 * 10)
@item_max = 0 @item_max = 0
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 16) @font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 16)
@color = [0x03, 0x11, 0x22] @color = [0x03, 0x11, 0x22]
@scroll = Widget_ScrollBar.new(@x+@width,@y,@height,0) @scrolling = Widget_ScrollBar.new(self,@x+@width,@y,@height)
self.list = list self.items = items
@old_x = @old_y = -1
end end
def draw_item(index, status=0) def draw_item(index, status=0)
room = @list[index] y = item_rect(index)[1]
Surface.blit(@button, @width*status, room.full? ? WLH : 0, @width, WLH, @contents, 0, WLH*index) room = @items[index]
@font.draw_blended_utf8(@contents, "R-#{room.id}", 24, WLH*index+8, *@color) Surface.blit(@button, @width*status, room.full? ? WLH : 0, @width, WLH, @contents, 0, y)
@font.draw_blended_utf8(@contents, room.full? ? "【决斗中】" : room.private? ? "【私密房】" : "【等待中】", 8, WLH*index+24, *@color) @font.draw_blended_utf8(@contents, "R-#{room.id}", 24, y+8, *@color)
@font.draw_blended_utf8(@contents, room.name, 128, WLH*index+8, *room.color) @font.draw_blended_utf8(@contents, room.full? ? "【决斗中】" : room.private? ? "【私密房】" : "【等待中】", 8, y+24, *@color)
@font.draw_blended_utf8(@contents, room.player1.name, 128, WLH*index+24, *@color) @font.draw_blended_utf8(@contents, room.name, 128, y+8, *room.color)
@font.draw_blended_utf8(@contents, room.player2.name, 256, WLH*index+24, *@color) if room.full? @font.draw_blended_utf8(@contents, room.player1.name, 128, y+24, *@color)
@font.draw_blended_utf8(@contents, room.player2.name, 256, y+24, *@color) if room.full?
end end
def item_rect(index)
[@x, WLH*index, @width, WLH]
end
def mousemoved(x,y) def mousemoved(x,y)
return unless self.include?(x,y) return unless self.include?(x,y)
self.index = (y - @y) / WLH self.index = (y - @y) / WLH + @scroll
end end
end end
\ No newline at end of file
#encoding: UTF-8
require_relative 'window_list'
class Window_Scrollable < Window_List
attr_reader :scroll
attr_accessor :scrolling
def initialize(x, y, width, height, z=200)
super(x, y, width, height, z)
@page_size ||= @height / self.class::WLH
@scroll ||= 0
end
def cursor_up(wrap=false)
return unless wrap or @index.nil? or @index > 0
self.index = @index ? (@index - @scroll - 1) % @items.size + @scroll : @scroll
end
def cursor_down(wrap=false)
return unless wrap or @index.nil? or @index < @items.size-1
self.index = @index ? (@index - @scroll + 1) % @items.size + @scroll : @scroll
end
def scroll_up
cursor_up(false)
self.scroll -= 1
end
def scroll_down
cursor_down(false)
self.scroll += 1
end
def scroll=(scroll)
return unless scroll != @scroll and scroll and scroll >= 0 and scroll <= @items.size - @page_size
#有背景的不能这么用....
#if scroll > @scroll
# Surface.blit(@contents, 0, self.class::WLH * (scroll - @scroll), @width, (@page_size - (scroll - @scroll)) * self.class::WLH, @contents, 0, 0)
# clear(0, @page_size - (scroll - @scroll) * self.class::WLH, @width, self.class::WLH * (scroll - @scroll))
#else
# Surface.blit(@contents, 0, 0, @width, (@page_size - (scroll - @scroll)) * self.class::WLH, @contents, 0, self.class::WLH * (scroll - @scroll))
# clear(0, 0, @width, self.class::WLH * (scroll - @scroll))
#end
@scroll = scroll
@scrolling.scroll = @scroll if @scrolling
refresh
end
def refresh
clear
(@scroll...[(@scroll+@page_size), @items.size].min).each{|index|draw_item(index, @index == index ? 1 : 0)}
@scrolling.scroll_max = @items.size - @page_size if @scrolling
end
def item_rect(index)
[0, (index-@scroll)*self.class::WLH, @width, self.class::WLH]
end
end
...@@ -9,8 +9,7 @@ class Window_Title < Window_List ...@@ -9,8 +9,7 @@ class Window_Title < Window_List
@single_height = @button.h / Button_Count @single_height = @button.h / Button_Count
super(x,y,@button.w / 3,WLH * Button_Count - (WLH - @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'
@item_max = 6 self.items = [:决斗开始, :单人模式, :卡组编成, :选项设置, :退出游戏]
refresh
end end
def index=(index) def index=(index)
if index and @index != index if index and @index != index
......
...@@ -9,10 +9,10 @@ class Window_User < Window_List ...@@ -9,10 +9,10 @@ class Window_User < Window_List
@contents = Surface.load("graphics/hall/user.png").display_format #TODO:调用已经加载了的背景 @contents = Surface.load("graphics/hall/user.png").display_format #TODO:调用已经加载了的背景
@avatar_boarder = Surface.load("graphics/hall/avatar_boader.png") @avatar_boarder = Surface.load("graphics/hall/avatar_boader.png")
@list = ["发送消息", "查看资料"] @items = ["发送消息", "查看资料"]
@list << "加入游戏" if user.status == :waiting @items << "加入游戏" if user.status == :waiting
@list << "观战" if user.status == :dueling @items << "观战" if user.status == :dueling
@item_max = @list.size @item_max = @items.size
refresh refresh
end end
def refresh def refresh
...@@ -34,7 +34,7 @@ class Window_User < Window_List ...@@ -34,7 +34,7 @@ class Window_User < Window_List
end end
def draw_item(index, status=0) def draw_item(index, status=0)
@font.draw_blended_utf8(@contents, @list[index] , 172, 96+index*WLH, 0x00,0x00,0x00) @font.draw_blended_utf8(@contents, @items[index] , 172, 96+index*WLH, 0x00,0x00,0x00)
end end
def item_rect(index) def item_rect(index)
[172, 96+index*WLH, 128, WLH] [172, 96+index*WLH, 128, WLH]
......
...@@ -4,12 +4,13 @@ ...@@ -4,12 +4,13 @@
#  title #  title
#============================================================================== #==============================================================================
require_relative 'window_user' require_relative 'window_user'
class Window_UserList < Window_List require_relative 'window_scrollable'
class Window_UserList < Window_Scrollable
attr_reader :x, :y, :width, :height attr_reader :x, :y, :width, :height
WLH = 20 WLH = 20
def initialize(x, y, list) def initialize(x, y, items)
#@contents = Surface.load "graphics/hall/userlist.png" #@contents = Surface.load "graphics/hall/useritems.png"
#@background = Surface.load "graphics/hall/userlist.png" #@background = Surface.load "graphics/hall/useritems.png"
super(x,y,272,540) super(x,y,272,540)
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 16) @font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 16)
@color = [0x03, 0x11, 0x22] @color = [0x03, 0x11, 0x22]
...@@ -17,35 +18,33 @@ class Window_UserList < Window_List ...@@ -17,35 +18,33 @@ class Window_UserList < Window_List
@color_click = [200,200,255, 0x03, 0x11, 0x22] @color_click = [200,200,255, 0x03, 0x11, 0x22]
#@contents.set_alpha(RLEACCEL, 80) #@contents.set_alpha(RLEACCEL, 80)
@contents.fill_rect(0,0,@width,@height,0xFFFFFFFF) @contents.fill_rect(0,0,@width,@height,0xFFFFFFFF)
self.list = list self.items = items
#@contents.f #@contents.f
end end
def draw_item(index, status=0) def draw_item(index, status=0)
case status case status
when 0 when 0
@font.draw_blended_utf8(@contents, @list[index].name, 0, index*WLH, *@color) @font.draw_blended_utf8(@contents, @items[index].name, 0, item_rect(index)[1], *@color)
when 1 when 1
@font.draw_shaded_utf8(@contents, @list[index].name, 0, index*WLH, *@color_over) @font.draw_shaded_utf8(@contents, @items[index].name, 0, item_rect(index)[1], *@color_over)
when 2 when 2
@font.draw_shaded_utf8(@contents, @list[index].name, 0, index*WLH, *@color_click) @font.draw_shaded_utf8(@contents, @items[index].name, 0, item_rect(index)[1], *@color_click)
end end
end end
#def clear(x=0, y=0, width=@width, height=@height) #def clear(x=0, y=0, width=@width, height=@height)
# Surface.blit(x, ) # Surface.blit(x, )
#end #end
def item_rect(index)
[0, WLH*index, @width, WLH]
end
#def clear(x=0,y=0,width=@width,height=@height) #def clear(x=0,y=0,width=@width,height=@height)
# @contents.fill_rect(x,y,width,height,0x66FFFFFF) # @contents.fill_rect(x,y,width,height,0x66FFFFFF)
#end #end
def clicked def clicked
#$scene.refresh_rect(*item_rect(@index)){draw_item(@index, 2)} if @index #$scene.refresh_rect(*item_rect(@index)){draw_item(@index, 2)} if @index
return unless @index return unless @index
@userwindow = Window_User.new(100,100,@list[@index]) @userwindow = Window_User.new(100,100,@items[@index])
end end
def mousemoved(x,y) def mousemoved(x,y)
return unless include?(x,y) return unless include?(x,y)
self.index = (y - @y) / WLH self.index = (y - @y) / WLH + @scroll
end end
end end
\ No newline at end of file
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