体会一下?
class Window_Popup < Window_Selectable def initialize super 0, 0, 0, 0 self.openness = 0 end def set_text text width, height = measure text self.width = width + standard_padding * 2 self.height = height + standard_padding * 2 create_contents draw_text_ex 0, 0, text end def measure text width = text.lines.map { |e| (contents.text_size e.chomp).width }.max height = text.lines.to_a.size * line_height return width, height end end class Window_ItemList < Window_Selectable def process_handling super return unless open? && active && @data[index] process_popup if handle?(:popup) && Input.trigger?(:X) end def process_popup if handle?(:popup) Sound.play_ok Input.update deactivate call_handler(:popup) else Sound.play_buzzer end end end class Scene_Item < Scene_ItemBase alias _start_without_popup start def start _start_without_popup create_popup_window end alias _create_item_window_without_popup create_item_window def create_item_window _create_item_window_without_popup @item_window.set_handler(:popup, method(:on_item_popup)) end def create_popup_window @popup_window = Window_Popup.new @popup_window.viewport = @viewport @popup_window.set_handler(:ok, method(:on_popup_ok)) @popup_window.set_handler(:cancel, method(:on_popup_ok)) end def on_item_popup rect = @item_window.item_rect @item_window.index @popup_window.x = @item_window.x + @item_window.padding + rect.x @popup_window.y = @item_window.y + @item_window.padding + rect.y + rect.height @popup_window.set_text "You selected #{@item_window.item.name}" @popup_window.show.activate.open end def on_popup_ok @popup_window.close update until @popup_window.close? @popup_window.hide.deactivate activate_item_window end end
class Window_Popup < Window_Selectable
def initialize
super 0, 0, 0, 0
self.openness = 0
end
def set_text text
width, height = measure text
self.width = width + standard_padding * 2
self.height = height + standard_padding * 2
create_contents
draw_text_ex 0, 0, text
end
def measure text
width = text.lines.map { |e| (contents.text_size e.chomp).width }.max
height = text.lines.to_a.size * line_height
return width, height
end
end
class Window_ItemList < Window_Selectable
def process_handling
super
return unless open? && active && @data[index]
process_popup if handle?(:popup) && Input.trigger?(:X)
end
def process_popup
if handle?(:popup)
Sound.play_ok
Input.update
deactivate
call_handler(:popup)
else
Sound.play_buzzer
end
end
end
class Scene_Item < Scene_ItemBase
alias _start_without_popup start
def start
_start_without_popup
create_popup_window
end
alias _create_item_window_without_popup create_item_window
def create_item_window
_create_item_window_without_popup
@item_window.set_handler(:popup, method(:on_item_popup))
end
def create_popup_window
@popup_window = Window_Popup.new
@popup_window.viewport = @viewport
@popup_window.set_handler(:ok, method(:on_popup_ok))
@popup_window.set_handler(:cancel, method(:on_popup_ok))
end
def on_item_popup
rect = @item_window.item_rect @item_window.index
@popup_window.x = @item_window.x + @item_window.padding + rect.x
@popup_window.y = @item_window.y + @item_window.padding + rect.y + rect.height
@popup_window.set_text "You selected #{@item_window.item.name}"
@popup_window.show.activate.open
end
def on_popup_ok
@popup_window.close
update until @popup_window.close?
@popup_window.hide.deactivate
activate_item_window
end
end
|