TheoAllen

Theo - Pause Anywhere at Anytime (ENG)

May 18th, 2014
644
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.13 KB | None | 0 0
  1. # =============================================================================
  2. # TheoAllen - Pause anywhere at anytime
  3. # Version : 1.0
  4. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # (English Documentation)
  6. # =============================================================================
  7. ($imported ||= {})[:Theo_Pause] = true
  8. # =============================================================================
  9. # Change Logs:
  10. # -----------------------------------------------------------------------------
  11. # 2014.01.16 - Finished script
  12. # =============================================================================
  13. =begin
  14.  
  15.   Introduction :
  16.   This script allow you to pause anywhere at anytime
  17.  
  18.   How to use :
  19.   Put this script below material but above main
  20.   Edit the config if necessary
  21.  
  22.   Terms of Use :
  23.   Credit me, TheoAllen. You are free to edit this script by your own. As long
  24.   as you don't claim it yours. For commercial purpose, don't forget to give me
  25.   a free copy of the game.
  26.  
  27. =end
  28. # =============================================================================
  29. # Configuration
  30. # =============================================================================
  31. module Theo
  32.   module Pause
  33.   # --------------------------------------------------------------------------
  34.     Color         = Color.new(0,0,0,150)
  35.   # Background color. Fill in this format : Color.new(red,green,blue,alpha)
  36.     Text          = "Pause"
  37.   # Text which will be displayed in pause
  38.   # --------------------------------------------------------------------------
  39.     FontName      = ["Calibri"] # Used font
  40.     FontSize      = 72          # Font size
  41.     FontBold      = true        # Bold?
  42.     FontItalic    = true        # Italic?
  43.   # --------------------------------------------------------------------------
  44.     DisplayPause  = true  # Display pause text?
  45.   # Why is this necessary? It's actually for my own good. I need to screenshot
  46.   # an awesome action. So I need to freeze the screen for a brief time. Just
  47.   # to make sure my timing is right
  48.     Button        = :ALT  # Button to trigger pause or unpause
  49.   # --------------------------------------------------------------------------
  50.   end
  51. end
  52. # =============================================================================
  53. # End of configuration
  54. # =============================================================================
  55. class Sprite_Screen < Sprite
  56.  
  57.   def initialize(viewport = nil)
  58.     super(viewport)
  59.     self.bitmap = Bitmap.new(Graphics.width,Graphics.height)
  60.   end
  61.  
  62.   def dispose
  63.     self.bitmap.dispose
  64.     super
  65.   end
  66.  
  67. end
  68.  
  69. class Bitmap
  70.  
  71.   def entire_fill(color = Color.new(0,0,0,150))
  72.     fill_rect(self.rect,color)
  73.   end
  74.  
  75. end
  76.  
  77. class Scene_Base
  78.  
  79.   alias scene_start start
  80.   def start
  81.     @pause_flag = false
  82.     scene_start
  83.     @pause_viewport = Viewport.new
  84.     @pause_viewport.z = 999
  85.     @pause_sprite = Sprite_Screen.new
  86.     @pause_sprite.viewport = @pause_viewport
  87.     @pause_sprite.bitmap.entire_fill(Theo::Pause::Color)
  88.     @pause_sprite.bitmap.font.name = Theo::Pause::FontName
  89.     @pause_sprite.bitmap.font.size = Theo::Pause::FontSize
  90.     @pause_sprite.bitmap.font.bold = Theo::Pause::FontBold
  91.     @pause_sprite.bitmap.font.italic = Theo::Pause::FontItalic
  92.     @pause_sprite.bitmap.draw_text(@pause_sprite.bitmap.rect,
  93.       Theo::Pause::Text, 1)
  94.     @pause_sprite.visible = false
  95.   end
  96.  
  97.   alias pause_update update_basic
  98.   def update_basic
  99.     pause_update
  100.     if Input.trigger?(Theo::Pause::Button)
  101.       @pause_flag = true
  102.       @pause_sprite.visible = true if Theo::Pause::DisplayPause
  103.       @saved_framecount = Graphics.frame_count
  104.       while @pause_flag
  105.         update_for_pause
  106.       end
  107.     end
  108.   end
  109.  
  110.   def update_for_pause
  111.     Graphics.update
  112.     Input.update
  113.     if Input.trigger?(Theo::Pause::Button)
  114.       @pause_flag = false
  115.       Graphics.frame_count = @saved_framecount
  116.       @pause_sprite.visible = false
  117.       Input.update
  118.     end
  119.   end
  120.  
  121.   alias scene_terminate terminate
  122.   def terminate
  123.     scene_terminate
  124.     @pause_viewport.dispose
  125.     @pause_sprite.dispose
  126.   end
  127.  
  128. end
Advertisement
Add Comment
Please, Sign In to add comment