SHARE
TWEET

Popup Window

Vlue Apr 27th, 2014 (edited) 2,188 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Popup Window v1.2d
  2. #----------#
  3. #Features: Create a popup window for anything you want! How magical!
  4. #
  5. #Usage:    Script calls:
  6. #           (In Events:)
  7. #           pop_up(['text','text', ... ], timer(opt), x(opt), y(opt))
  8. #           (Anywhere else:)
  9. #           Popup.add(['text','text', ... ], timer(opt), x(opt), y(opt))
  10. #
  11. #          Examples:
  12. #           pop_up(['\i[5] Mage class unlocked!!'])
  13. #           pop_up(['\c[16] Class Change:\c[0]',
  14. #                   ' Speak to any mysterious hermit to change class!'],240)
  15. #
  16. #   Escape codes not working? You have two options... switch to '' singe quotes
  17. #    instead of "" double quotes, or double up on \\ slashes.
  18. #----------#
  19. #-- Script by: V.M of D.T
  20. #
  21. #- Questions or comments can be:
  22. #    given by email: sumptuaryspade@live.ca
  23. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  24. #   All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  25. #
  26. #- Free to use in any project with credit given, donations always welcome!
  27.  
  28. $imported = {} if $imported.nil?
  29. $imported[:Vlue_PopupWindow] = true
  30.  
  31. POPUP_DURATION = 180
  32.  
  33. class Popup_Window < Window_Base
  34.   def initialize(text,timer,x,y)
  35.     super(0,0,25,100)
  36.     text.each do |string|
  37.       temp_string = string.gsub(/\\[^invpgINVPG]\[\d{0,3}\]/) { "" }
  38.       temp_string = temp_string.gsub(/\\i\[\d{0,3}\]/) { icon_width }
  39.       temp_string = convert_escape_characters(temp_string)
  40.       self.width = [text_size(temp_string).width+standard_padding*2+12,self.width].max
  41.     end
  42.     self.height = text.size * line_height + line_height
  43.     if x.nil?
  44.       self.x = Graphics.width / 2 - self.width / 2
  45.     else
  46.       self.x = x
  47.     end
  48.     if y.nil?
  49.       self.y = Graphics.height / 2 - self.height / 2
  50.     else
  51.       self.y = y
  52.     end
  53.     @text = text
  54.     @timer = timer
  55.     create_contents
  56.     refresh
  57.     self.openness = 0
  58.     open
  59.   end
  60.   def icon_width
  61.     size = text_size(' ').width
  62.     ' ' * (24 / size)
  63.   end
  64.   def refresh
  65.     contents.clear
  66.     yy = 0
  67.     @text.each do |string|
  68.       draw_text_ex(0,yy,string)
  69.       yy += line_height
  70.     end
  71.   end
  72.   def update
  73.     super
  74.     @timer -= 1
  75.     close if @timer == 0
  76.   end
  77. end
  78.  
  79. module Popup
  80.   def self.init
  81.     @queue = []
  82.   end
  83.   def self.add(text, timer = POPUP_DURATION, x = nil, y = nil)
  84.     @queue.push([text,timer,x,y])
  85.   end
  86.   def self.queue
  87.     @queue
  88.   end
  89. end  
  90.  
  91. Popup.init
  92.  
  93. class Scene_Base
  94.   alias popupwin_preterminate pre_terminate
  95.   alias popupwin_update update
  96.   def update
  97.     popupwin_update
  98.     update_popup_window_text unless $popup.nil?
  99.     return if Popup.queue.empty?
  100.     if $popup.nil? or $popup.close?
  101.       text = Popup.queue.pop
  102.       $popup = Popup_Window.new(text[0], text[1], text[2], text[3])
  103.     end
  104.   end
  105.   def update_popup_window_text
  106.     $popup.update
  107.     $popup.close if Input.trigger?(:C)
  108.     if !$popup.disposed? and $popup.close?
  109.       $popup.dispose
  110.       $popup = nil
  111.     end
  112.   end
  113.   def pre_terminate
  114.     popupwin_preterminate
  115.     $popup.visible = false unless $popup.nil?
  116.   end
  117. end
  118.  
  119. class Game_Interpreter
  120.   alias popup_command_355 command_355
  121.   def pop_up(text, timer = POPUP_DURATION, x = nil, y = nil)
  122.     Popup.add(text, timer, x, y)
  123.   end
  124.   def command_355
  125.     popup_command_355
  126.     wait_for_popup #if SceneManager.scene.is_a?(Scene_Map)
  127.   end
  128.   def wait_for_popup
  129.     Fiber.yield while !Popup.queue.empty? || $popup
  130.   end
  131. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top