Commit f7ebe964 authored by 神楽坂玲奈's avatar 神楽坂玲奈

滚动条

parent 13a0b92e
...@@ -97,6 +97,12 @@ class Scene ...@@ -97,6 +97,12 @@ class Scene
when 5 when 5
@active_window.scroll_down if @active_window @active_window.scroll_down if @active_window
end end
when Event::MouseButtonUp
case event.button
when Mouse::BUTTON_LEFT
update_active_window(event.x, event.y)
@active_window.mouseleftbuttonup if @active_window
end
when Event::KeyDown when Event::KeyDown
case event.sym case event.sym
when Key::F12 when Key::F12
......
...@@ -57,16 +57,6 @@ class Scene_Lobby < Scene ...@@ -57,16 +57,6 @@ class Scene_Lobby < Scene
$game.exit $game.exit
$scene = Scene_Login.new $scene = Scene_Login.new
end end
when Event::KeyUp
case event.sym
when Key::RETURN
determine
end
when Event::MouseButtonUp
case event.button
when Mouse::BUTTON_LEFT
determine
end
else else
super super
end end
...@@ -98,20 +88,6 @@ class Scene_Lobby < Scene ...@@ -98,20 +88,6 @@ class Scene_Lobby < Scene
@count += 1 @count += 1
super super
end end
def determine
case @active_window
when @roomlist
return unless @roomlist.index and room = @roomlist.items[@roomlist.index]
if room.full?
$game.watch room
@joinroom_msgbox = Widget_Msgbox.new("加入房间", "正在加入观战")
else
$game.join room, "test"
@joinroom_msgbox = Widget_Msgbox.new("加入房间", "正在加入房间")
end
end
end
def terminate def terminate
unless $scene.is_a? Scene_Lobby or $scene.is_a? Scene_Duel unless $scene.is_a? Scene_Lobby or $scene.is_a? Scene_Duel
$game.exit $game.exit
......
...@@ -10,6 +10,7 @@ class Widget_ScrollBar < Window ...@@ -10,6 +10,7 @@ class Widget_ScrollBar < Window
@contents.fill_rect(0,0,@width, @height, 0xFFFFFFFF) @contents.fill_rect(0,0,@width, @height, 0xFFFFFFFF)
@scroll ||= 0 @scroll ||= 0
@scroll_max ||= 0 @scroll_max ||= 0
@scrolling = nil
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
...@@ -55,6 +56,9 @@ class Widget_ScrollBar < Window ...@@ -55,6 +56,9 @@ class Widget_ScrollBar < Window
end end
end end
def mousemoved(x,y) def mousemoved(x,y)
if Mouse.state[2] and @scrolling and @scroll_max > 0
@parent_window.scroll = [[0, (y - @y - @scrolling) / ((@height-40-24)/@scroll_max)].max, @scroll_max].min
end
case y-@y case y-@y
when 0...20 #上按钮 when 0...20 #上按钮
self.index = :up self.index = :up
...@@ -70,8 +74,21 @@ class Widget_ScrollBar < Window ...@@ -70,8 +74,21 @@ class Widget_ScrollBar < Window
scroll_up scroll_up
when :down when :down
scroll_down scroll_down
when :scroll
y = (@height-40-24)*@scroll/(@scroll_max)
case Mouse.state[1] - @y - 20
when 0...y
scroll_up
when y..(y+24)
@scrolling = Mouse.state[1] - @y - y
else
scroll_down
end
end end
end end
def mouseleftbuttonup
@scrolling = nil
end
def scroll_up def scroll_up
@parent_window.scroll_up @parent_window.scroll_up
end end
......
...@@ -72,6 +72,9 @@ class Window ...@@ -72,6 +72,9 @@ class Window
def clicked def clicked
#子类定义 #子类定义
end end
def mouseleftbuttonup
#子类定义
end
def lostfocus(active_window=nil) def lostfocus(active_window=nil)
#子类定义 #子类定义
end end
......
...@@ -27,7 +27,7 @@ class Window_Chat < Window_Scrollable ...@@ -27,7 +27,7 @@ class Window_Chat < Window_Scrollable
Game_Event.push Game_Event::Chat.new(chatmessage) Game_Event.push Game_Event::Chat.new(chatmessage)
end end
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 14) @font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 14)
@scrolling = Widget_ScrollBar.new(self,@x+@width-20-8,@y+31+3,@height-68) @scrollbar = Widget_ScrollBar.new(self,@x+@width-20-8,@y+31+3,@height-68)
@page_size = (@height-68)/WLH @page_size = (@height-68)/WLH
@@list ||= {} @@list ||= {}
@list_splited = {} @list_splited = {}
...@@ -121,7 +121,7 @@ class Window_Chat < Window_Scrollable ...@@ -121,7 +121,7 @@ class Window_Chat < Window_Scrollable
@font.draw_blended_utf8(@contents, chatmessage.user.name+':', x, y, *chatmessage.name_color) if chatmessage.name_visible? @font.draw_blended_utf8(@contents, chatmessage.user.name+':', x, y, *chatmessage.name_color) if chatmessage.name_visible?
@font.draw_blended_utf8(@contents, message, x+name_width(chatmessage), y, *chatmessage.message_color) unless chatmessage.message.empty? @font.draw_blended_utf8(@contents, message, x+name_width(chatmessage), y, *chatmessage.message_color) unless chatmessage.message.empty?
else else
@font.draw_blended_utf8(@contents, message, x, y, *chatmessage) @font.draw_blended_utf8(@contents, message, x, y, *chatmessage) unless message.empty?
end end
end end
def item_rect(index) def item_rect(index)
......
...@@ -17,7 +17,7 @@ class Window_RoomList < Window_Scrollable ...@@ -17,7 +17,7 @@ class Window_RoomList < Window_Scrollable
@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]
@scrolling = Widget_ScrollBar.new(self,@x+@width,@y,@height) @scrollbar = Widget_ScrollBar.new(self,@x+@width,@y,@height)
self.items = items self.items = items
end end
...@@ -36,4 +36,14 @@ class Window_RoomList < Window_Scrollable ...@@ -36,4 +36,14 @@ class Window_RoomList < Window_Scrollable
return unless self.include?(x,y) return unless self.include?(x,y)
self.index = (y - @y) / WLH + @scroll self.index = (y - @y) / WLH + @scroll
end end
def clicked
return unless @index and room = @items[@index]
if room.full?
$game.watch room
@joinroom_msgbox = Widget_Msgbox.new("加入房间", "正在加入观战")
else
$game.join room, "test"
@joinroom_msgbox = Widget_Msgbox.new("加入房间", "正在加入房间")
end
end
end end
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require_relative 'window_list' require_relative 'window_list'
class Window_Scrollable < Window_List class Window_Scrollable < Window_List
attr_reader :scroll attr_reader :scroll
attr_accessor :scrolling attr_accessor :scrollbar
def initialize(x, y, width, height, z=200) def initialize(x, y, width, height, z=200)
super(x, y, width, height, z) super(x, y, width, height, z)
@page_size ||= @height / self.class::WLH @page_size ||= @height / self.class::WLH
...@@ -40,8 +40,10 @@ class Window_Scrollable < Window_List ...@@ -40,8 +40,10 @@ class Window_Scrollable < Window_List
def refresh def refresh
clear clear
(@scroll...[(@scroll+@page_size), @items.size].min).each{|index|draw_item(index, @index == index ? 1 : 0)} (@scroll...[(@scroll+@page_size), @items.size].min).each{|index|draw_item(index, @index == index ? 1 : 0)}
@scrolling.scroll_max = [@items.size - @page_size, 0].max if @scrolling if @scrollbar
@scrolling.scroll = @scroll if @scrolling @scrollbar.scroll_max = [@items.size - @page_size, 0].max
@scrollbar.scroll = @scroll
end
end end
def item_rect(index) def item_rect(index)
[0, (index-@scroll)*self.class::WLH, @width, self.class::WLH] [0, (index-@scroll)*self.class::WLH, @width, self.class::WLH]
......
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