TheoAllen

Theo - Interact Hover Notification

Jul 24th, 2013
482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.90 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. # (This script documentation is written in informal indonesian language)
  6. # =============================================================================
  7. ($imported ||= {})[:Theo_InteractNotif] = true
  8. # =============================================================================
  9. # CHANGE LOGS:
  10. # -----------------------------------------------------------------------------
  11. # 2013.08.21 - Bugfix when changing map
  12. # 2013.08.04 - Bugfix at Event Page Condition
  13. # 2013.07.24 - Finished script
  14. # =============================================================================
  15. =begin
  16.  
  17.   Perkenalan :
  18.   Script ini berfungsi untuk nampilin notifikasi diatas event
  19.  
  20.   Cara penggunaan :
  21.   Pasang dibawah material namun diatas main
  22.   Gunakan comment pada event <interact: nama interaksi>
  23.  
  24.   Terms of Use :
  25.   Credit gw, TheoAllen. Kalo semisal u bisa ngedit2 script gw trus jadi lebih
  26.   keren, terserah. Ane bebasin. Asal ngga ngeklaim aja. Kalo semisal mau
  27.   dipake buat komersil, jangan lupa, gw dibagi gratisannya.  
  28.  
  29. =end
  30. # =============================================================================
  31. # Konfigurasi :
  32. # =============================================================================
  33. module THEO
  34.   module Interact
  35.    
  36.     # Tulisan default untuk event yg bisa diinteraksi. Bikin jadi "" kalo
  37.     # kamu ngga pengen setiap event muncul notifikasinya
  38.     DefaultNotif = "Interact"
  39.    
  40.     # Kecepatan muncul ilangnya.
  41.     FadeSpeed = 20
  42.    
  43.     # Makin besar, makin tinggi diatas event
  44.     Displacement = 15
  45.    
  46.     # Lebar maksimal
  47.     Width  = 300
  48.    
  49.     # Settingan Font
  50.     FontName = ["Calibri"]
  51.     FontSize = 18
  52.     FontBold = true
  53.     FontItalic = false
  54.    
  55.   end
  56. end
  57. # =============================================================================
  58. # Akhir dari konfigurasi
  59. # =============================================================================
  60. class Game_Event < Game_Character
  61.   attr_accessor :hover_notif
  62.  
  63.   alias theo_ihn_page_setting setup_page_settings
  64.   def setup_page_settings
  65.     theo_ihn_page_setting
  66.     setup_hover_notif
  67.   end  
  68.  
  69.   def setup_hover_notif
  70.     @hover_notif = THEO::Interact::DefaultNotif
  71.     @list.each do |command|
  72.       next unless command.code == 108 || command.code == 408
  73.       case command.parameters[0]
  74.       when /<(?:INTERACT|interact): (.*)>/i
  75.         @hover_notif = $1.to_s
  76.       end
  77.     end
  78.   end
  79.  
  80.   def list_is_empty?
  81.     list.all? do |command|
  82.       command.code == 0 ||
  83.       command.code == 108 ||
  84.       command.code == 408 ||
  85.       command.code == 118
  86.     end
  87.   end
  88.  
  89.   def trigger_is_possible?
  90.     return false if list_is_empty?
  91.     return false if trigger != 0
  92.     return true
  93.   end
  94.  
  95.   def meet_with_player?
  96.     return in_front_of_player? if normal_priority?
  97.     return below_or_above_player?
  98.   end
  99.  
  100.   def in_front_of_player?
  101.     self.x == $game_player.front_x && self.y == $game_player.front_y
  102.   end
  103.  
  104.   def below_or_above_player?
  105.     self.x == $game_player.x && self.y == $game_player.y
  106.   end
  107.  
  108.   def showing_hover_notif?
  109.     return false unless @hover_notif
  110.     return false if @hover_notif.empty?
  111.     return false if @erased
  112.     return false if $game_map.interpreter.running?
  113.     return trigger_is_possible? && meet_with_player?
  114.   end
  115.  
  116. end
  117.  
  118. class Game_Player < Game_Character
  119.  
  120.   def front_x
  121.     $game_map.round_x_with_direction(@x,@direction)
  122.   end
  123.  
  124.   def front_y
  125.     $game_map.round_y_with_direction(@y,@direction)
  126.   end
  127.  
  128. end
  129.  
  130. class Window_InteractNotif < Window_Base
  131.   include THEO::Interact
  132.  
  133.   def initialize(event)
  134.     super(0,0,Width,fitting_height(1))
  135.     self.opacity = 0
  136.     self.contents_opacity = 0
  137.     @event = event
  138.     setup_font
  139.     update_placement
  140.     refresh
  141.   end
  142.  
  143.   def setup_font
  144.     font = contents.font
  145.     font.size = FontSize
  146.     font.name = FontName
  147.     font.bold = FontBold
  148.     font.italic = FontItalic
  149.   end
  150.  
  151.   def refresh
  152.     contents.clear
  153.     @text = @event.hover_notif
  154.     draw_text(contents.rect,@text,1)
  155.   end
  156.  
  157.   def update
  158.     super
  159.     update_placement
  160.     update_opacity
  161.     refresh if need_refresh?
  162.   end
  163.  
  164.   def update_placement
  165.     self.x = @event.screen_x - self.width/2
  166.     self.y = @event.screen_y - self.height - Displacement
  167.   end
  168.  
  169.   def update_opacity
  170.     if @event.showing_hover_notif?
  171.       update_fadein
  172.     else
  173.       update_fadeout
  174.     end    
  175.   end
  176.  
  177.   def need_refresh?
  178.     @text != @event.hover_notif
  179.   end
  180.  
  181.   def line_height
  182.     FontSize
  183.   end
  184.  
  185.   def fade_speed
  186.     return FadeSpeed
  187.   end
  188.  
  189.   def update_fadein
  190.     self.contents_opacity += fade_speed
  191.   end
  192.  
  193.   def update_fadeout
  194.     self.contents_opacity -= fade_speed
  195.   end
  196.  
  197. end
  198.  
  199. class Scene_Map < Scene_Base
  200.  
  201.   alias theo_ihn_start start
  202.   def start
  203.     theo_ihn_start
  204.     create_hover_notif_window
  205.   end
  206.  
  207.   def create_hover_notif_window
  208.     @notif_windows = []
  209.     $game_map.events.values.each do |event|
  210.       @notif_windows.push(Window_InteractNotif.new(event))
  211.     end
  212.   end
  213.  
  214.   alias theo_ihn_update update
  215.   def update
  216.     theo_ihn_update
  217.     update_notif_windows
  218.   end
  219.  
  220.   def update_notif_windows
  221.     @notif_windows.each do |window|
  222.       window.update
  223.     end
  224.   end
  225.  
  226.   alias theo_ihn_dispose_all dispose_all_windows
  227.   def dispose_all_windows
  228.     theo_ihn_dispose_all
  229.     dispose_hover_notif
  230.   end
  231.  
  232.   def dispose_hover_notif
  233.     @notif_windows.each do |window|
  234.       window.dispose
  235.     end
  236.   end
  237.  
  238.   alias theo_ihn_pre_trans pre_transfer
  239.   def pre_transfer
  240.     theo_ihn_pre_trans
  241.     dispose_hover_notif
  242.   end
  243.  
  244.   alias theo_ihn_post_trans post_transfer
  245.   def post_transfer
  246.     create_hover_notif_window
  247.     theo_ihn_post_trans
  248.   end
  249.  
  250. end
Advertisement
Add Comment
Please, Sign In to add comment