09-09-2016, 03:43 AM 
(This post was last modified: 10-08-2017, 04:46 PM by DerVVulfman.)
	
	
	DerVV's Simple Popup System
Version: 1.2
Version: 1.2
Introduction
Seriously, this is a simple popup screen that can be used to generate windows that popup on the screen witn important texts. But I posted it as a skeleton for would-be script users to show how to make pop-up windows for their own systems.
Script
 The Script
  			Code:
#==============================================================================
# ** DerVV's Simple Popup System
#------------------------------------------------------------------------------
#    by DerVVulfman
#    version 1.2
#    10-08-2017 (mmddyy)
#    RGSS / RPGMaker XP
#------------------------------------------------------------------------------
#  Seriously, this is a simple popup screen that can be used to generate
#  windows that popup on the screen witn important texts.   But I posted
#  it as a skeleton for would-be script users to show how to make pop-up
#  windows for their own systems.
#
#  This version includes a module  so you can position  the popup window
#  where you want on the screen and decide if the popup freezes the map.
#
#  Also, it includes a feature so you can use a timer system to make the
#  popup automatically vanish instead of relying upon player input.   It
#  is based on seconds passed.   If the Timer value  is set to any value
#  than 0, then the popup will stay on the screen for the number of sec-
#  onds indicated.  But if set to 0, then it will rely on button input.
#
#
#==============================================================================
module Popup
  # HEIGHT POSITION & CENTERED WIDTH
  #
    Y_Pos     = 50      # Height of window
    Width     = 250     # Window Width
  
  # POP FUNCTIONS
  #
    Timer     = 0       # if 0, uses button.  Otherwise it is seconds passed
    Button    = "OK"    # Button text
    Interrupt = false   # Does map freeze when pop is on (recommended true)
  
end
#==============================================================================
# ** Window_Popup
#------------------------------------------------------------------------------
#  This window generates a pop-up window.
#==============================================================================
class Window_Popup < Window_Selectable
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    # Compute window height from command quantity
    super(0, 0, Popup::Width, 32 + 32)
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #     text_lines : text string array
  #--------------------------------------------------------------------------
  def refresh(text_lines)
    # Get number of lines of text for window size
    @item_max       = text_lines.size
    # If we have no timer, using button
    if Popup::Timer == 0
      # Set window height and contents bitmap with extra 'button' line
      self.height     = 32 * (@item_max + 2)
      self.contents   = Bitmap.new(width - 32, (@item_max + 1) * 32)    
    # Otherwise, if timer is used
    else
      # Set window height and contents bitmap without extra line
      self.height     = 32 * (@item_max + 1)
      self.contents   = Bitmap.new(width - 32, @item_max * 32)    
    end
    # Clear contents
    self.contents.clear
    # Cycle through and draw the text
    for i in 0...@item_max
      draw_item(i, text_lines[i], normal_color)
    end
    # Draw Button text if timer is 0
    if Popup::Timer == 0
      draw_item(@item_max, Popup::Button, normal_color)
    end
    # Set index position depending on timer or not
    self.index = (Popup::Timer == 0) ?  @item_max : 0
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #     text  : rendered text
  #     color : text color
  #--------------------------------------------------------------------------
  def draw_item(index, text, color)
    self.contents.font.color = color
    rect = Rect.new(4, 32 * index, self.contents.width - 8, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(rect, text)
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    return if Input.repeat?(Input::UP)
    return if Input.repeat?(Input::DOWN)
    super
  end
  #--------------------------------------------------------------------------
  # * Update Cursor Rectangle
  #--------------------------------------------------------------------------
  def update_cursor_rect
    # Don't draw cursor rect if using a timer
    return unless Popup::Timer == 0
    # Otherwise, draw cursor rect on button
    super()
  end
end
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  This class performs map screen processing.
#==============================================================================
class Scene_Map
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias scene_map_pop_main main
  alias scene_map_pop_update update
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Setup the popup window
    @pop_window         = Window_Popup.new
    @pop_window.visible = false
    @pop_window.active  = false
    @pop_window.x       = (640-Popup::Width)/2
    @pop_window.y       = Popup::Y_Pos
    @pop_window.z       = 1500
    # Perform the original call
    scene_map_pop_main
    # Dispose of the window
    @pop_window.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update 
    # Update the Hotkey Popup Window if active
    @pop_window.update if @pop_window.active == true
    # If popup interrupts actions
    if Popup::Interrupt == true
      # Exit the Hotkey Popup Window if active
      return update_pop if @pop_window.active == true &&
        !$game_temp.message_window_showing
    end
    # The original call
    scene_map_pop_update
    # If popup doesn't interrupt
    if Popup::Interrupt == false
      # Exit the Hotkey Popup Window if active
      return update_pop if @pop_window.active == true
    end
  end  
  #--------------------------------------------------------------------------
  # * Frame Update Testing Popup Condition
  #--------------------------------------------------------------------------
  def update_pop
    # If using timer
    return update_timer unless Popup::Timer == 0
    # Otherwise, must be keyed
    return update_button
  end  
  #--------------------------------------------------------------------------
  # * Frame Update Popup Timer Testing
  #--------------------------------------------------------------------------
  def update_timer
    # If waiting
    if @pwait_count > 0
      # Decrease wait count
      @pwait_count -= 1
      # End Method
      return
    end    
    # Hide Hotkey Popup
    @pop_window.active = @pop_window.visible = false
  end
  #--------------------------------------------------------------------------
  # * Frame Update Popup Key Testing
  #--------------------------------------------------------------------------
  def update_button
    # Return if Enter isn't pressed
    return if !Input.trigger?(Input::C)
    # Play decision
    $game_system.se_play($data_system.decision_se)
    # Hide Hotkey Popup
    @pop_window.active = @pop_window.visible = false
  end
  #--------------------------------------------------------------------------
  # * Passed call
  #     added_text : text string array
  #--------------------------------------------------------------------------
  def begin_pop(added_text=nil)
    # Set the wait count to seconds (value * game frame rate)
    @pwait_count = (Popup::Timer).abs * Graphics.frame_rate 
    # Ensure no invalid text.  Must be string (even empty) if set to nil.
    added_text = [""] if added_text.nil?
    # Refresh pop window with new text
    @pop_window.refresh(added_text)
    # Make pop window visible and active
    @pop_window.active = @pop_window.visible = true
  end
endInstructions
Basically paste it below Scene_Debug and above Main.
When you want to run it, make a script call of $scene.begin_pop. The syntax is:
$scene.begin_pop( array_of_text )
where an array of text could be like [ "One line of text here.", "Another line of text" ]
The window will close either by player input or will close by itself if the timer setting is put to use.
Compatibility
Just for RPGMaker XP, though principles would work in other engines.
Terms and Conditions
Oh, this is a simple skeleton script. Nothing needed by me for its use. Heck, other people probably figured this routine out in no time.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)
	  Above are clickable links

 
 
 DerVV's Simple Popup System
 DerVV's Simple Popup System
 
 
![[Image: QrnbKlx.jpg]](https://i.imgur.com/QrnbKlx.jpg)
![[Image: sGz1ErF.png]](https://i.imgur.com/sGz1ErF.png)
![[Image: liM4ikn.png]](https://i.imgur.com/liM4ikn.png)
![[Image: fdzKgZA.png]](https://i.imgur.com/fdzKgZA.png)
![[Image: sj0H81z.png]](https://i.imgur.com/sj0H81z.png)
![[Image: QL7oRau.png]](https://i.imgur.com/QL7oRau.png)
![[Image: uSqjY09.png]](https://i.imgur.com/uSqjY09.png)
![[Image: GAA3qE9.png]](https://i.imgur.com/GAA3qE9.png)
![[Image: 2Hmnx1G.png]](https://i.imgur.com/2Hmnx1G.png)
![[Image: BwtNdKw.png%5B]](https://i.imgur.com/BwtNdKw.png%5B)


 
