#=============================================================================== # Event Pop-Up Windows # By Jet10985 (Jet) # Requested by: ZeroManArmy #=============================================================================== # This snippet lets you have a textbox above an event that closes/opens # automatically afer a certain amount of frames. # This script has: 4 customization options. #=============================================================================== # Overwritten Methods: # None #------------------------------------------------------------------------------- # Aliased methods: # Game_Event: initialize, refresh, update # Scene_Map: terminate #=============================================================================== =begin To make a pop-up window, and configure it: Pop-up windows are created via comments, as to avoid odd parallel processing. If you want a custom opening time, closing time, opacity or you need to adjust the y coordinate of the window, you must configure them first by using the following in an event comment: Custom opening timed: POPUP OPEN = 60 Custom closing timed: POPUP CLOSE = 60 Custom Window Opacity: POPUP OPACITY = 60 Adjust Y Coordinate: POPUP Y = 10 For the opening and closing, the number represent frames. 60 frames = 1 second. For the y coordinate, the number will be how many pixels down the window is moved from the default position Note: The config below has options for a default time for opening time, closing time and opacity, so you don't need to use these comments every time. To make the actual pop-up window, use this comment after any config you do: POPUP = Hey, what's up? There are no quotes required. =end module PopUpEventWindows # This switch will hide all popup windows if it is on. TURN_POPUP_WINDOWS_OFF = 100 # This is the default amount of frames a popup will be open for. # If you never want windows to close, make this value -1 DEFAULT_OPEN_FOR = 120 # This is the default amount of frames a popup will be closed for. DEFAULT_CLOSED_FOR = 60 # This is how transperant the window is. # 255 is completely solid, 0 is completely see-through POPUP_OPACITY = 200 end #=============================================================================== # DON'T EDIT FURTHER UNLESS YOU KNOW WHAT TO DO. #=============================================================================== class Window_EventPopUp < Window_Base include PopUpEventWindows def initialize(x, y, width, height, text, time_up, time_down, opacity, event, add_y) super(x, y, width, height) self.opacity = opacity @text = text @limit = time_up @orig_limit = time_up @down_limit = time_down @orig_down_limit = time_down @event = event @add_y = add_y refresh end def refresh self.contents.clear self.contents.draw_text(0, 0, self.width, 24, @text) end def update @limit -= 1 unless @limit == 0 @down_limit -= 1 unless @limit > 0 if self.x != @event.screen_x - (self.width / 2) self.x = @event.screen_x - (self.width / 2) end if self.y != @event.screen_y - 88 + @add_y self.y = @event.screen_y - 88 + @add_y end if $game_message.visible || $game_switches[TURN_POPUP_WINDOWS_OFF] || @text.length == 0 self.visible = false else self.visible = true unless self.visible end if @limit == 0 && self.openness != 0 self.openness -= 17 unless self.openness == 0 @down_limit = @orig_down_limit elsif @down_limit == 0 && self.openness != 255 self.openness += 17 unless self.openness == 255 @limit = @orig_limit end if !$scene.is_a?(Scene_Map) self.dispose end end end class Game_Event include PopUpEventWindows attr_accessor :popup_window, :popup_window_open_for, :popup_window_closed_for alias jet6821_initialize initialize unless $@ def initialize(*args, &block) @popup_window = false jet6821_initialize(*args, &block) end def check_for_popup @popup_window.dispose unless [true, false].include?(@popup_window) @popup_window = true additional_y = 0 for item in @list if item.code == 108 or item.code == 408 if [nil, DEFAULT_OPEN_FOR].include?(@popup_window_open_for) if !item.parameters[0][/(?:POPUP OPEN)[ ]*=[ ]*(\d+)/i].nil? @popup_window_open_for = $1.gsub(/\n|\r/i) {|p| "" }.to_i else @popup_window_open_for = DEFAULT_OPEN_FOR end end if [nil, DEFAULT_CLOSED_FOR].include?(@popup_window_closed_for) if !item.parameters[0][/(?:POPUP CLOSE)[ ]*=[ ]*(\d+)/i].nil? @popup_window_closed_for = $1.gsub(/\n|\r/i) {|p| "" }.to_i else @popup_window_closed_for = DEFAULT_CLOSED_FOR end end if [nil, POPUP_OPACITY].include?(@popup_window_opa) if !item.parameters[0][/(?:POPUP OPACITY)[ ]*=[ ]*(\d+)/i].nil? @popup_window_opa = $1.gsub(/\n|\r/i) {|p| "" }.to_i else @popup_window_opa = POPUP_OPACITY end end if !item.parameters[0][/(?:POPUP Y)[ ]*=[ ]*(\d+)/i].nil? additional_y += $1.gsub(/\n|\r/i) {|p| "" }.to_i end if !item.parameters[0][/(?:POPUP)[ ]*=[ ]*(.+)/i].nil? t = $1.gsub(/\n|\r/i) {|p| "" } text = convert_special_characters(t) temp = Bitmap.new(1, 1) width = temp.text_size(text).width + 32 temp.dispose x = self.screen_x - (width / 2) y = self.screen_y - 88 + additional_y @popup_window = Window_EventPopUp.new(x, y, width, 56, text, @popup_window_open_for, @popup_window_closed_for, @popup_window_opa, self, additional_y) end end end @popup_window_open_for = nil @popup_window_closed_for = nil @popup_window_opa = nil end def convert_special_characters(text) text.gsub!(/\\V\[([0-9]+)\]/i) { $game_variables[$1.to_i] } text.gsub!(/\\N\[([0-9]+)\]/i) { $game_actors[$1.to_i].name } return text end alias jet6789_refresh refresh unless $@ def refresh(*args, &block) jet_old_page = @page jet6789_refresh(*args, &block) if jet_old_page != @page check_for_popup end end alias jet9821_update update unless $@ def update(*args, &block) jet9821_update(*args, &block) if ![true, false].include?(@popup_window) && @popup_window.disposed? @popup_window = false end check_for_popup if @popup_window == false @popup_window.update unless @popup_window == true end end class Scene_Base alias jet6811_terminate terminate unless $@ def terminate(*args, &block) if !self.is_a?(Scene_Title) for event in $game_map.events.values next if [false, true].include?(event.popup_window) || event.popup_window.disposed? event.popup_window.update unless event.popup_window == true end end jet6811_terminate(*args, &block) end end