TheoAllen

Theo - Interact Hover Notif (ENG)

May 31st, 2014
915
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.08 KB | None | 0 0
  1. # =============================================================================
  2. # TheoAllen - Interact Hover Notification
  3. # Version : 1.1
  4. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # (English Documentation)
  6. # =============================================================================
  7. ($imported ||= {})[:Theo_InteractNotif] = true
  8. # =============================================================================
  9. # Change Logs:
  10. # -----------------------------------------------------------------------------
  11. # 2014.05.30 - Change notetag to be more reasonable
  12. # 2013.08.21 - Bugfix when changing map
  13. # 2013.08.04 - Bugfix at Event Page Condition
  14. # 2013.07.24 - Finished script
  15. # =============================================================================
  16. =begin
  17.  
  18.   Introduction :
  19.   This script displays notification text over event. Only event with action
  20.   button as trigger and not an empty event will be displaying the text
  21.  
  22.   How to use :
  23.   Put this script below material but above main
  24.   Put comments in event in this format <interact: notif>
  25.   So, it will display the notification text
  26.  
  27.   Terms of Use :
  28.   Credit me, TheoAllen. You are free to edit this script by your own. As long
  29.   as you don't claim it yours. For commercial purpose, don't forget to give me
  30.   a free copy of the game.
  31.  
  32. =end
  33. # =============================================================================
  34. # Configuration :
  35. # =============================================================================
  36. module THEO
  37.   module Interact
  38.    
  39.     # Default text of hover notif. Set it to "" if you don't want to each
  40.     # event displays notification
  41.     DefaultNotif = ""
  42.    
  43.     # Opacity change per frame (not frame duration, remember)
  44.     FadeSpeed = 20
  45.    
  46.     # Higher value means, higher place over event
  47.     Displacement = 15
  48.    
  49.     # Maximum width of notification
  50.     Width  = 300
  51.    
  52.     # Font settings
  53.     FontName = ["Calibri"]
  54.     FontSize = 18
  55.     FontBold = true
  56.     FontItalic = false
  57.    
  58.   end
  59. end
  60. # =============================================================================
  61. # End of config. Unless you're a mighty scripting god, do not touch anything
  62. # pass this line.
  63. # =============================================================================
  64. class Game_Event < Game_Character
  65.   attr_accessor :hover_notif
  66.  
  67.   alias theo_ihn_page_setting setup_page_settings
  68.   def setup_page_settings
  69.     theo_ihn_page_setting
  70.     setup_hover_notif
  71.   end  
  72.  
  73.   def setup_hover_notif
  74.     @hover_notif = THEO::Interact::DefaultNotif
  75.     @list.each do |command|
  76.       next unless command.code == 108 || command.code == 408
  77.       if command.parameters[0] =~ /<interact\s*:\s+(.*)>/i
  78.         @hover_notif = $1.to_s
  79.       end
  80.     end
  81.   end
  82.  
  83.   def list_is_empty?
  84.     list.all? do |command|
  85.       command.code == 0 ||
  86.       command.code == 108 ||
  87.       command.code == 408 ||
  88.       command.code == 118
  89.     end
  90.   end
  91.  
  92.   def trigger_is_possible?
  93.     return false if list_is_empty?
  94.     return false if trigger != 0
  95.     return true
  96.   end
  97.  
  98.   def meet_with_player?
  99.     return in_front_of_player? if normal_priority?
  100.     return below_or_above_player?
  101.   end
  102.  
  103.   def in_front_of_player?
  104.     self.x == $game_player.front_x && self.y == $game_player.front_y
  105.   end
  106.  
  107.   def below_or_above_player?
  108.     self.x == $game_player.x && self.y == $game_player.y
  109.   end
  110.  
  111.   def showing_hover_notif?
  112.     return false unless @hover_notif
  113.     return false if @hover_notif.empty?
  114.     return false if @erased
  115.     return false if $game_map.interpreter.running?
  116.     return trigger_is_possible? && meet_with_player?
  117.   end
  118.  
  119. end
  120.  
  121. class Game_Player < Game_Character
  122.  
  123.   def front_x
  124.     $game_map.round_x_with_direction(@x,@direction)
  125.   end
  126.  
  127.   def front_y
  128.     $game_map.round_y_with_direction(@y,@direction)
  129.   end
  130.  
  131. end
  132.  
  133. class Window_InteractNotif < Window_Base
  134.   include THEO::Interact
  135.  
  136.   def initialize(event)
  137.     super(0,0,Width,fitting_height(1))
  138.     self.opacity = 0
  139.     self.contents_opacity = 0
  140.     @event = event
  141.     setup_font
  142.     update_placement
  143.     refresh
  144.   end
  145.  
  146.   def setup_font
  147.     font = contents.font
  148.     font.size = FontSize
  149.     font.name = FontName
  150.     font.bold = FontBold
  151.     font.italic = FontItalic
  152.   end
  153.  
  154.   def refresh
  155.     contents.clear
  156.     @text = @event.hover_notif
  157.     draw_text(contents.rect,@text,1)
  158.   end
  159.  
  160.   def update
  161.     super
  162.     update_placement
  163.     update_opacity
  164.     refresh if need_refresh?
  165.   end
  166.  
  167.   def update_placement
  168.     self.x = @event.screen_x - self.width/2
  169.     self.y = @event.screen_y - self.height - Displacement
  170.   end
  171.  
  172.   def update_opacity
  173.     if @event.showing_hover_notif?
  174.       update_fadein
  175.     else
  176.       update_fadeout
  177.     end    
  178.   end
  179.  
  180.   def need_refresh?
  181.     @text != @event.hover_notif
  182.   end
  183.  
  184.   def line_height
  185.     FontSize
  186.   end
  187.  
  188.   def fade_speed
  189.     return FadeSpeed
  190.   end
  191.  
  192.   def update_fadein
  193.     self.contents_opacity += fade_speed
  194.   end
  195.  
  196.   def update_fadeout
  197.     self.contents_opacity -= fade_speed
  198.   end
  199.  
  200. end
  201.  
  202. class Scene_Map < Scene_Base
  203.  
  204.   alias theo_ihn_start start
  205.   def start
  206.     theo_ihn_start
  207.     create_hover_notif_window
  208.   end
  209.  
  210.   def create_hover_notif_window
  211.     @notif_windows = []
  212.     $game_map.events.values.each do |event|
  213.       @notif_windows.push(Window_InteractNotif.new(event))
  214.     end
  215.   end
  216.  
  217.   alias theo_ihn_update update
  218.   def update
  219.     theo_ihn_update
  220.     update_notif_windows
  221.   end
  222.  
  223.   def update_notif_windows
  224.     @notif_windows.each do |window|
  225.       window.update
  226.     end
  227.   end
  228.  
  229.   alias theo_ihn_dispose_all dispose_all_windows
  230.   def dispose_all_windows
  231.     theo_ihn_dispose_all
  232.     dispose_hover_notif
  233.   end
  234.  
  235.   def dispose_hover_notif
  236.     @notif_windows.each do |window|
  237.       window.dispose
  238.     end
  239.   end
  240.  
  241.   alias theo_ihn_pre_trans pre_transfer
  242.   def pre_transfer
  243.     theo_ihn_pre_trans
  244.     dispose_hover_notif
  245.   end
  246.  
  247.   alias theo_ihn_post_trans post_transfer
  248.   def post_transfer
  249.     create_hover_notif_window
  250.     theo_ihn_post_trans
  251.   end
  252.  
  253. end
Advertisement
Add Comment
Please, Sign In to add comment