Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. # Some Popup v 2.8
  2. # VX Ace version
  3. # by mikb89
  4.  
  5. # Details:
  6. #  Show some popup text when facing an event.
  7. #  Text can be placed in center of screen, over the player or over the event.
  8. #  Write [pop] in a comment to assign the popup to an event and write in the
  9. #   next comment the text that will be shown.
  10. # NOTE: [pop] is by default, but you can change it in the settings.
  11. #  Text can be also grayed, to indicate a non-available something. To do so,
  12. #   write [npop] instead of [pop].
  13. #  You can also show a picture instead of text. In order to do this, the first
  14. #   comment must be [ppop] and the second will contain the name of the Picture.
  15. #  It is possible to play a sound/music effect for each event. Just write in a
  16. #   third comment these lines:
  17. #    SE (or ME or BGM or BGS)
  18. #    Audio filename
  19. #    Volume (1-100)
  20. #    Pitch (50-150)
  21. #    You can omit the two last lines, and they will be set by default:
  22. #    Volume 80 for BGS and SE, 100 for BGM and ME
  23. #    Pitch 100
  24. # ATTENTION: comments have to be the first two (or three) commands of the event.
  25. #
  26. #  You can also call a script with:
  27. #    $game_player.remove_town_sprite
  28. #   in it to remove the sprite. For example if you put the sprite on an event
  29. #   which you'll speak, with this code you can remove the popup.
  30.  
  31. # Configurations:
  32. module SPOP
  33.   ID = "pop" # set "loc" for old version compatibility.
  34.    # What you have to write on a event to be identified as popup one.
  35.    # If the value here is for example "pop" you'll have to write:
  36.    #  - [pop] for the common text popup;
  37.    #  - [npop] for the grayed out popup;
  38.    #  - [ppop] for the picture popup.
  39.   AUTO_REMOVE_AT_TRANSFER = true
  40.    # Test to understand what I mean.
  41.    #  true - gives the same effect as the one in Chrono Trigger towns.
  42.    #  false - let the popup be visible after the teleport. Will fade out at the
  43.    #          first player movement.
  44.   GRAYED_COLOR = Color.new(255,245,255,175)
  45.    # Value of grey color. Red, green, blue, alpha. From 0 to 255.
  46.   WALK_8_DIR = true
  47.    # You don't have to include the 8dir script. Just set true this.
  48.   POPUP_TRANSITION = 9
  49.    # The effect of the popup appearing/disappearing.
  50.    #  0: no effect
  51.    #  1: fading in/out
  52.    #  2: movement up/down
  53.    #  3: movement & fading
  54.    #  4: reduced movement
  55.    #  5: reduced movement & fading
  56.    #  6: zoom in/out
  57.    #  7: zoom & fading
  58.    #  8: zoom & movement
  59.    #  9: zoom, movement, fading
  60.    # 10: zoom & reduced movement
  61.    # 11: zoom, reduced movement, fading
  62.   POPUP_SOUND = ["SE", "Book1", 80, 100]
  63.    # Play something on popup.
  64.    # 4 parameters:
  65.    #  1. Sound kind ("SE", "ME", "BGS", "BGM");
  66.    #  2. Name of the file;
  67.    #  3. Volume (0-100);
  68.    #  4. Pitch (50-150 (or 15-453 if you want MAXIMUM values)).
  69.    # To deactivate sound just set "" the 2. or set 0 to 3. Examples:
  70.    #  POPUP_SOUND = ["SE", "", 80, 100]
  71.    #  POPUP_SOUND = ["SE", "Book1", 0, 100]
  72.    # Won't be played.
  73.    # Eventual BGM or BGS playing will fade as the graphic fade/zoom/move and
  74.    #  will start after the popup close. Obviously not valid if using SE/ME.
  75.  
  76.    # Examples with ME, BGM, BGS:
  77.    #  POPUP_SOUND = ["ME", "Item", 100, 100]
  78.    #  POPUP_SOUND = ["BGM", "Town1", 100, 100]
  79.    #  POPUP_SOUND = ["BGS", "Clock", 100, 100]
  80.   POPUP_BINDING = 2
  81.    # Where the popup should be binded.
  82.    #  0: center of the screen
  83.    #  1: over the player
  84.    #  2: over the event
  85. end
  86.  
  87. # Others:
  88. #  You'll see 'town' everywhere in the script. This is because of the SECOND
  89. #   name given to this script: "Popup town name".
  90. #  The FIRST original name was "Location system", from this the [loc] to add in
  91. #   event comments. By the way I never publicated the version with this name, so
  92. #   you won't find anything.
  93.  
  94. #Codename: spop
  95.  
  96. ($imported ||= {})[:mikb89_spop] = true
  97.  
  98. # License:
  99. # - You can ask me to include support for other scripts as long as these scripts
  100. #   use the $imported[script] = true;
  101. # - You can modify and even repost my scripts, after having received a response
  102. #   by me. For reposting it, anyway, you must have done heavy edit or porting,
  103. #   you can't do a post with the script as is;
  104. # - You can use my scripts for whatever you want, from free to open to
  105. #   commercial games. I'd appreciate by the way if you let me know about what
  106. #   you're doing;
  107. # - You must credit me, if you use this script or part of it.
  108.  
  109. class Game_Player < Game_Character
  110.   #--------------------------------------------------------------------------
  111.   # * Object Initialization
  112.   #--------------------------------------------------------------------------
  113.   alias_method(:initGP_b4_spop, :initialize) unless method_defined?(:initGP_b4_spop)
  114. #class Game_Player#def initialize() <- aliased
  115.   def initialize
  116.     initGP_b4_spop
  117.     @town_sprite = nil
  118.     @town_text = ""
  119.     reset_audio
  120.     @town_ex_audio = nil
  121.     @sync_event = nil
  122.   end
  123.   #--------------------------------------------------------------------------
  124.   # * Frame Update
  125.   #--------------------------------------------------------------------------
  126.   alias_method(:updateGP_b4_spop, :update) unless method_defined?(:updateGP_b4_spop)
  127. #class Game_Player#def update() <- aliased
  128.   def update
  129.     updateGP_b4_spop
  130.     if @town_sprite != nil
  131.       case SPOP::POPUP_BINDING
  132.       when 1
  133.         @town_sprite.x = $game_player.screen_x
  134.         if @town_sprite.y != $game_player.screen_y && $game_player.screen_y != @sync_y
  135.           @town_sprite.y = $game_player.screen_y - (@town_sprite.y - @sync_y).abs
  136.           @sync_y = $game_player.screen_y
  137.         end
  138.       when 2
  139.         if @sync_event != nil
  140.           @town_sprite.x = @sync_event.screen_x
  141.           if @town_sprite.y != @sync_event.screen_y && @sync_event.screen_y != @sync_y
  142.             @town_sprite.y = @sync_event.screen_y - (@town_sprite.y - @sync_y).abs
  143.             @sync_y = @sync_event.screen_y
  144.           end
  145.           remove_town_sprite if Math.hypot(@sync_event.distance_x_from($game_player.x), @sync_event.distance_y_from($game_player.y)) > 2
  146.         end
  147.       end
  148.       rem = false
  149.       @town_sprite.visible = SceneManager.scene_is?(Scene_Map)
  150.       @town_sprite.update
  151.       if [1,3,5,7,9,11].include?(SPOP::POPUP_TRANSITION)
  152.         @town_sprite.opacity -= 15 if @town_sprite.z == 5 && @town_sprite.opacity > 0
  153.         @town_sprite.opacity += 15 if @town_sprite.z == 10 && @town_sprite.opacity < 255
  154.         rem = true if @town_sprite.opacity <= 0
  155.       end
  156.       if [2,3,4,5,8,9,10,11].include?(SPOP::POPUP_TRANSITION)
  157.         mov = [4,5,10,11].include?(SPOP::POPUP_TRANSITION) ? 32 : 64
  158.         val = mov/16
  159.         t = @town_sprite.y
  160.         @town_sprite.y += val if @town_sprite.z == 5 && @toadd > -mov
  161.         @town_sprite.y -= val if @town_sprite.z == 10 && @toadd > 0
  162.         @toadd -= val if t != @town_sprite.y
  163.         rem = true if @toadd <= -mov
  164.       end
  165.       if [6,7,8,9,10,11].include?(SPOP::POPUP_TRANSITION)
  166.         if @town_sprite.z == 5 && @town_sprite.zoom_x > 0
  167.           @town_sprite.zoom_x -= 0.25
  168.           @town_sprite.zoom_y -= 0.25
  169.         end
  170.         if @town_sprite.z == 10 && @town_sprite.zoom_x < 1
  171.           @town_sprite.zoom_x += 0.25
  172.           @town_sprite.zoom_y += 0.25
  173.         end
  174.         rem = true if @town_sprite.zoom_x <= 0
  175.       end
  176.       if @town_ex_audio != nil
  177.         if @audiowait > 0
  178.           @audiowait -= 1
  179.         elsif @audiowait == 0
  180.           if @town_audio != nil
  181.             @town_audio.play
  182.             if @town_ex_audio.class != @town_audio.class
  183.               @town_ex_audio.replay
  184.               @town_ex_audio = nil
  185.             end
  186.             reset_audio if @town_audio.name != SPOP::POPUP_SOUND[1]
  187.           end
  188.           @audiowait = -1
  189.         end
  190.       end
  191.       remove_town_sprite(true) if rem
  192.     end
  193.   end
  194.   #--------------------------------------------------------------------------
  195.   # * Removing of town sprite when changing map
  196.   #--------------------------------------------------------------------------
  197.   alias_method(:perform_transfer_b4_spop, :perform_transfer) unless method_defined?(:perform_transfer_b4_spop)
  198. #class Game_Player#def perform_transfer() <- aliased
  199.   def perform_transfer
  200.     remove_town_sprite(true, false) if SPOP::AUTO_REMOVE_AT_TRANSFER
  201.     perform_transfer_b4_spop
  202.   end
  203.   #--------------------------------------------------------------------------
  204.   # * Processing of Movement via input from the Directional Buttons
  205.   #--------------------------------------------------------------------------
  206. #class Game_Player#def move_by_input() <- rewritten
  207.   def move_by_input
  208.     return unless movable?
  209.     return if $game_map.interpreter.running?
  210.     x, y = self.x, self.y
  211.     case SPOP::WALK_8_DIR ? Input.dir8 : Input.dir4
  212.     when 1
  213.       move_diagonal(4,2)#lower_left
  214.       if !@move_succeed
  215.         check_town(x-1, y+1)
  216.       else
  217.         check_town(x-2, y+2)
  218.       end
  219.     when 2
  220.       move_straight(2)#down
  221.       if !@move_succeed
  222.         check_town(x, y+1)
  223.       else
  224.         check_town(x, y+2)
  225.       end
  226.     when 3
  227.       move_diagonal(6,2)#lower_right
  228.       if !@move_succeed
  229.         check_town(x+1, y+1)
  230.       else
  231.         check_town(x+2, y+2)
  232.       end
  233.     when 4
  234.       move_straight(4)#left
  235.       if !@move_succeed
  236.         check_town(x-1, y)
  237.       else
  238.         check_town(x-2, y)
  239.       end
  240.     when 6
  241.       move_straight(6)#right
  242.       if !@move_succeed
  243.         check_town(x+1, y)
  244.       else
  245.         check_town(x+2, y)
  246.       end
  247.     when 7
  248.       move_diagonal(4,8)#upper_left
  249.       if !@move_succeed
  250.         check_town(x-1, y-1)
  251.       else
  252.         check_town(x-2, y-2)
  253.       end
  254.     when 8
  255.       move_straight(8)#up
  256.       if !@move_succeed
  257.         check_town(x, y-1)
  258.       else
  259.         check_town(x, y-2)
  260.       end
  261.     when 9
  262.       move_diagonal(6,8)#upper_right
  263.       if !@move_succeed
  264.         check_town(x+1, y-1)
  265.       else
  266.         check_town(x+2, y-2)
  267.       end
  268.     end
  269.   end
  270.   #--------------------------------------------------------------------------
  271.   # * Operations for sprite removal and audio stopping
  272.   #--------------------------------------------------------------------------
  273. #class Game_Player#def remove_town_sprite(instant, audio)
  274.   def remove_town_sprite(instant=false, audio=true)
  275.     if @town_sprite != nil
  276.       if instant || SPOP::POPUP_TRANSITION == 0
  277.         if audio
  278.           @town_audio.class.stop if @town_audio != nil
  279.           @town_ex_audio.replay if @town_ex_audio != nil
  280.         end
  281.         @town_ex_audio = nil
  282.         @town_sprite.dispose
  283.         @town_sprite = nil
  284.         @sync_event = nil
  285.       else
  286.         @town_sprite.z = 5
  287.         unless @town_audio.is_a?(RPG::SE)
  288.           @town_audio.class.fade(4) if @town_audio != nil
  289.         end
  290.       end
  291.     end
  292.   end
  293.   #--------------------------------------------------------------------------
  294.   # * Set the audio as the one specified in SPOP or passed
  295.   #--------------------------------------------------------------------------
  296. #class Game_Player#def reset_audio(spn)
  297.   def reset_audio(spn = SPOP::POPUP_SOUND)
  298.     @town_audio = (spn[1] == "" ||
  299.                   spn[2] <= 0) ? nil :
  300.                     case spn[0]
  301.                     when "BGM"; RPG::BGM.new(spn[1], spn[2], spn[3])
  302.                     when "BGS"; RPG::BGS.new(spn[1], spn[2], spn[3])
  303.                     when "ME"; RPG::ME.new(spn[1], spn[2], spn[3])
  304.                     when "SE"; RPG::SE.new(spn[1], spn[2], spn[3])
  305.                     end
  306.   end
  307.   #--------------------------------------------------------------------------
  308.   # * Check if there is a town event in front of the player
  309.   #--------------------------------------------------------------------------
  310. #class Game_Player#def check_town(x, y)
  311.   def check_town(x, y)
  312.     return false if $game_map.interpreter.running?
  313.     result = false
  314.     for event in $game_map.events_xy(x, y)
  315.       unless [1,2].include?(event.trigger) and event.priority_type == 1
  316.         if event.list != nil
  317.           if event.list[0].code == 108 and
  318.             ["[#{SPOP::ID}]", "[n#{SPOP::ID}]", "[p#{SPOP::ID}]"].include?(event.list[0].parameters[0])
  319.             result = true
  320.             next if @town_sprite != nil && @town_sprite.z == 10 && @town_text == event.list[1].parameters[0]
  321.             remove_town_sprite(true)
  322.             @town_sprite = Sprite.new
  323.             @town_sprite.z = 10
  324.             if [6,7,8,9,10,11].include?(SPOP::POPUP_TRANSITION)
  325.               @town_sprite.zoom_x = @town_sprite.zoom_y = 0.0
  326.             end
  327.             @town_sprite.opacity = 15 if [1,3,5,7,9,11].include?(SPOP::POPUP_TRANSITION)
  328.             if event.list[0].parameters[0] != "[p#{SPOP::ID}]"
  329.               @town_sprite.bitmap ||= Bitmap.new(1,1)
  330.               siz = @town_sprite.bitmap.text_size(event.list[1].parameters[0])
  331.               h = siz.height
  332.               s = siz.width
  333.               @town_sprite.bitmap.dispose
  334.               @town_sprite.bitmap = Bitmap.new(s, 24)
  335.               if event.list[0].parameters[0] == "[n#{SPOP::ID}]"
  336.                 ex = @town_sprite.bitmap.font.color
  337.                 @town_sprite.bitmap.font.color = SPOP::GRAYED_COLOR
  338.               end
  339.               @town_sprite.bitmap.draw_text(0,2,s,22,event.list[1].parameters[0],1)
  340.               @town_sprite.bitmap.font.color = ex if event.list[0].parameters[0] == "[n#{SPOP::ID}]"
  341.             else
  342.               @town_sprite.bitmap = Cache.picture(event.list[1].parameters[0])
  343.               s = @town_sprite.bitmap.width
  344.               h = @town_sprite.bitmap.height
  345.             end
  346.             @town_text = event.list[1].parameters[0]
  347.             @town_sprite.ox = s/2
  348.             @town_sprite.oy = h/2
  349.             case SPOP::POPUP_BINDING
  350.             when 1
  351.               @town_sprite.x = $game_player.screen_x#*32+16
  352.               @town_sprite.y = @sync_y = $game_player.screen_y#*32+16
  353.             when 2
  354.               @town_sprite.x = event.screen_x#*32+16
  355.               @town_sprite.y = @sync_y = event.screen_y#*32+16
  356.               @sync_event = event
  357.             else
  358.               @town_sprite.x = 544/2# - s/2
  359.               @town_sprite.y = 416/2# - h/2
  360.             end
  361.             @town_sprite.y -= 64 if [0,1,6,7].include?(SPOP::POPUP_TRANSITION)
  362.             @town_sprite.y -= 32 if [4,5,10,11].include?(SPOP::POPUP_TRANSITION)
  363.             @toadd = [2,3,4,5,8,9,10,11].include?(SPOP::POPUP_TRANSITION) ? 64 : 0
  364.             @toadd -= 32 if [4,5,10,11].include?(SPOP::POPUP_TRANSITION)
  365.             if @town_audio != nil || event.list[2].code == 108
  366.               if ["BGM", "ME", "BGS", "SE"].include?(event.list[2].parameters[0]) &&
  367.                 event.list[3].code == 408
  368.                 arr = []
  369.                 arr.push(event.list[2].parameters[0])
  370.                 arr.push(event.list[3].parameters[0])
  371.                 if event.list[4].code == 408
  372.                   arr.push(event.list[4].parameters[0].to_i)
  373.                   arr.push(event.list[5].parameters[0].to_i) if event.list[5].code == 408
  374.                 else
  375.                   arr.push(["BGS", "SE"].include?(event.list[2].parameters[0]) ? 80 : 100)
  376.                 end
  377.                 arr.push(100) if arr.size < 4
  378.                 reset_audio(arr)
  379.               end
  380.               @town_ex_audio = @town_audio.class.last if [RPG::BGM, RPG::BGS].include?(@town_audio.class)
  381.               if @town_ex_audio != nil
  382.                 @town_ex_audio.class.fade(4)
  383.                 @audiowait = 4
  384.               else
  385.                 @town_audio.play
  386.                 reset_audio if arr != nil
  387.               end
  388.             end
  389.           end
  390.         end
  391.       end
  392.     end
  393.     remove_town_sprite unless result
  394.     return result
  395.   end
  396. end
  397.  
  398. #--------------------------------------------------------------------------
  399. # * Sprite removal at Save (can't save a Sprite) and End
  400. #--------------------------------------------------------------------------
  401. class Scene_Save < Scene_File
  402.   if method_defined?(:start)
  403.     alias_method(:start_SSav_b4_spop, :start) unless method_defined?(:start_SSav_b4_spop)
  404.   end
  405. #class Scene_Save#def start() <- aliased/added
  406.   def start
  407.     if respond_to?(:start_SSav_b4_spop)
  408.       start_SSav_b4_spop
  409.     else
  410.       super
  411.     end
  412.     $game_player.remove_town_sprite(true)
  413.   end
  414. end
  415.  
  416. class Scene_End < Scene_MenuBase
  417.   alias_method(:start_SEnd_b4_spop, :start) unless method_defined?(:start_SEnd_b4_spop)
  418. #class Scene_End#def start() <- aliased
  419.   def start
  420.     start_SEnd_b4_spop
  421.     $game_player.remove_town_sprite(true)
  422.   end
  423. end