TheoAllen

Theo - Event Notification v2

Oct 14th, 2013
518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 12.07 KB | None | 0 0
  1. # =============================================================================
  2. # TheoAllen - Event Notification
  3. # Version : 2.0
  4. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # (This script documentation is written in informal indonesian language)
  6. # -----------------------------------------------------------------------------
  7. # Requires :
  8. # >> Theo - Core Movement (Basic Modules)
  9. # >> Theo - Core Fade (Basic Modules)
  10. # =============================================================================
  11. ($imported ||= {})[:Theo_EventNotif] = true
  12. # =============================================================================
  13. # CHANGE LOGS:
  14. # -----------------------------------------------------------------------------
  15. # 2013.10.14 - Rewrite Script (v2.0)
  16. #            - Support multiple notification show
  17. #            - Add notification SE
  18. #            - Notification will only show up if item has changed by event
  19. #            - Add option to disable notification
  20. #            - Add slide up
  21. # 2013.06.11 - Finished script
  22. # 2013.06.10 - Started script
  23. # =============================================================================
  24. =begin
  25.  
  26.   Perkenalan :
  27.   Script ini berfungsi untuk menampilkan event popup diatas player saat player
  28.   mendapat item atau mendapat gold. kamu juga bisa menyeting popupmu sendiri
  29.   dengan menggunakan teks.
  30.  
  31.   Cara penggunaan :
  32.   Pasang script ini dibawah material namun diatas main.
  33.   Pastikan kamu setting $imported[:Theo_Movement] dan $imported[:Theo_CoreFade]
  34.   di Basic Modul gw true
  35.  
  36.   Untuk menghidupkan script ini, pastikan kamu menghidupkan switchnya terlebih
  37.   dahulu. Switch ID untuk mengaktifkan script ini bisa dilihat di konfigurasi
  38.  
  39.   Gunakan script call seperti berikut untuk nampilin notifikasi berupa teks
  40.   - show_notif(text)
  41.   - show_notif(text, icon)
  42.   - show_notif(text, icon, color)
  43.  
  44.   Dimana text adalah berupa tulisan / text yang dibungkus dalam kutip ("").
  45.   Icon adalah angka yang menunjukkan index icon dalam database (bisa diabaikan).
  46.   Color adalah kode angka untuk warna. Sama seperti \C[n] dalam message box.
  47.  
  48.   Terms of use :
  49.   Credit gw, TheoAllen. Kalo semisal u bisa ngedit2 script gw trus jadi lebih
  50.   keren, terserah. Ane bebasin. Asal ngga ngeklaim aja. Kalo semisal mau
  51.   dipake buat komersil, jangan lupa, gw dibagi gratisannya.  
  52.  
  53. =end
  54. # =============================================================================
  55. # Konfigurasi (Awas banyak) :
  56. # -----------------------------------------------------------------------------
  57. # Kalo semisal kamu pusing / ga paham soal settingan ini, lebih baik ngga usah
  58. # ngedit dan ikuti aja settingan default ini
  59. # =============================================================================
  60. module Theo
  61.   module EvNotif
  62.    
  63.   # ==========================================================================
  64.     Use_Notif_Switch  = 50  # Switch ID
  65.   # --------------------------------------------------------------------------
  66.   # Switch ID untuk menghidupkan script ini. Jika ON maka script ini akan
  67.   # dijalankan
  68.   # ==========================================================================  
  69.  
  70.  
  71.   # ==========================================================================
  72.     Use_Item_Sound    = true               # Gunain Sound Effect? (true/false)
  73.     Gain_Item_Sound   = ["Item1", 80, 100] # Gain Item SE
  74.     Lose_Item_Sound   = [ "Miss", 80, 100] # Lose Item SE
  75.   # --------------------------------------------------------------------------
  76.   # Sound Effect yang akan diplay saat notifikasi Change Item/Armor/Weapon
  77.   # ditampilkan. Isi dengan format ["Nama SE", Volume, Pitch]
  78.   # ==========================================================================
  79.     Gain_Item_Color   = 24  # Default : 24
  80.     Lose_Item_Color   = 25  # Default : 25
  81.   # --------------------------------------------------------------------------
  82.   # Untuk settingan warna gain item. Angka disana sama dengan kode \C[n] dalam
  83.   # message box. Kamu bisa memilih angkanya antara 0 - 31.
  84.   # ==========================================================================
  85.  
  86.  
  87.   # ==========================================================================
  88.     Use_Gold_Sound    = true               # Gunain Sound Effect? (true/false)
  89.     Gain_Gold_Sound   = ["Item1", 80, 100] # Gain Gold SE
  90.     Lose_Gold_Sound   = [ "Miss", 80, 100] # Lose Gold SE
  91.   # --------------------------------------------------------------------------
  92.   # Sound Effect yang akan diplay saat notifikasi Change Gold ditampilkan. Isi
  93.   # dengan format ["Nama SE", Volume, Pitch]
  94.   # ==========================================================================
  95.     Gain_Gold_Color   = 6       # Default : 6
  96.     Lose_Gold_Color   = 25      # Default : 25
  97.     Gold_Icon         = 245     # Icon untuk notifikasi Gold (Default : 245)
  98.     Gold_Vocab        = "Gold"  # Vocab untuk notifikasi Gold
  99.   # --------------------------------------------------------------------------
  100.   # Udah jelas wa rasa ~
  101.   # ==========================================================================
  102.  
  103.  
  104.   # ==========================================================================
  105.     FontName = ["Calibri"]  # Font yang digunakan
  106.     FontSize = 17           # Ukuran font yang digunakan
  107.     FontBold = true         # Mo ditebelin?
  108.   # --------------------------------------------------------------------------
  109.   # Setting untuk font. Untuk nama font, kamu bisa menggunakan multiple font
  110.   # seperti ["Times New Roman","Calibri","Arial"]. Jika nama font paling
  111.   # kiri tidak ada, maka akan dilanjutkan kanan.
  112.   # ==========================================================================
  113.  
  114.  
  115.   # ==========================================================================
  116.     Notif_TimeGap     = 40  # Default : 40 (note: 1)
  117.     Show_Time         = 40  # Default : 40 (note: 2)
  118.     Fadeout_Duration  = 30  # Default : 30 (note: 3)
  119.     SlideUp_Range     = 30  # Default : 30 (note: 4)
  120.     SlideUp_Duration  = 30  # Default : 30 (note: 5)
  121.   # --------------------------------------------------------------------------
  122.   # [Note: 1] => Jeda waktu antara notifikasi satu dengan notifikasi lainnya
  123.   #              Dalam hitungan frame (60 frame = 1 detik)
  124.   # [Note: 2] => Lama notifikasi dimunculkan dalam hitungan frame sebelum
  125.   #              akhirnya menghilang (fadeout)
  126.   # [Note: 3] => Durasi menghilang dalam hitungan frame.
  127.   # [Note: 4] => Jarak pergeseran keatas dalam hitungan pixel.
  128.   # [Note: 5] => Durasi bergerak keatas dalam hitungan frame.
  129.   # --------------------------------------------------------------------------
  130.   # Kalo masi ngga paham, coba aja isi make angka ekstrim. Misalnya 100, 999
  131.   # ato 1 :v
  132.   # ==========================================================================
  133.  
  134.   end
  135. end
  136. # =============================================================================
  137. # Akhir dari konfigurasi. Jangan sentuh apapun setelah line ini
  138. # =============================================================================
  139. class NotifStruct
  140.   attr_reader :color
  141.   attr_reader :text
  142.   attr_reader :icon
  143.   attr_reader :sound
  144.  
  145.   def initialize(text, icon, color, sound)
  146.     @color = color
  147.     @text = text
  148.     @icon = icon
  149.     @sound = sound
  150.   end
  151.  
  152.   def play
  153.     sound.play if sound
  154.   end
  155.  
  156. end
  157.  
  158. class Game_Temp
  159.   attr_reader :notif_queue
  160.  
  161.   alias theo_evnotif_init initialize
  162.   def initialize
  163.     theo_evnotif_init
  164.     @notif_queue = []
  165.   end
  166.  
  167.   def push_notif(text, icon = 0, color = 0, sound = nil)
  168.     notif_queue.push(NotifStruct.new(text, icon, color, sound))
  169.   end
  170.  
  171. end
  172.  
  173. class Game_Interpreter
  174.  
  175.   include Theo::EvNotif
  176.  
  177.   alias :theo_evnotif_125 :command_125
  178.   alias :theo_evnotif_126 :command_126
  179.   alias :theo_evnotif_127 :command_127
  180.   alias :theo_evnotif_128 :command_128
  181.  
  182.   def show_notif(text, icon = 0, color = 0, sound = nil)
  183.     $game_temp.push_notif(text, icon, color, sound)
  184.   end
  185.  
  186.   def command_125
  187.     theo_evnotif_125
  188.     return unless use_notif?
  189.     value = operate_value(@params[0], @params[1], @params[2])
  190.     fmt = (value > 0 ? "%s +%d" : "%s %d")
  191.     text = sprintf(fmt, Gold_Vocab, value)
  192.     $game_temp.push_notif(text, Gold_Icon, gold_color(value), gold_sound(value))
  193.   end
  194.  
  195.   def command_126
  196.     theo_evnotif_126
  197.     return unless use_notif?
  198.     value = operate_value(@params[1], @params[2], @params[3])
  199.     item_notif($data_items, value)
  200.   end
  201.  
  202.   def command_127
  203.     theo_evnotif_127
  204.     return unless use_notif?
  205.     value = operate_value(@params[1], @params[2], @params[3])
  206.     item_notif($data_weapons, value)
  207.   end
  208.  
  209.   def command_128
  210.     theo_evnotif_128
  211.     return unless use_notif?
  212.     value = operate_value(@params[1], @params[2], @params[3])
  213.     item_notif($data_armors, value)
  214.   end
  215.  
  216.   def item_notif(item, value)
  217.     fmt = (value > 0 ? "%s +%d" : "%s %d")
  218.     text = sprintf(fmt,item[@params[0]].name, value)
  219.     $game_temp.push_notif(text, item[@params[0]].icon_index, item_color(value),
  220.       item_sound(value))
  221.   end
  222.  
  223.   def gold_color(value)
  224.     value > 0 ? Gain_Gold_Color : Lose_Gold_Color
  225.   end
  226.  
  227.   def gold_sound(value)
  228.     return nil unless Use_Gold_Sound
  229.     args = (value > 0 ? Gain_Gold_Sound : Lose_Gold_Sound)
  230.     RPG::SE.new(*args)
  231.   end
  232.  
  233.   def item_color(value)
  234.     value > 0 ? Gain_Item_Color : Lose_Item_Color
  235.   end
  236.  
  237.   def item_sound(value)
  238.     return nil unless Use_Item_Sound
  239.     args = (value > 0 ? Gain_Item_Sound : Lose_Item_Sound)
  240.     RPG::SE.new(*args)
  241.   end
  242.  
  243.   def use_notif?
  244.     $game_switches[Use_Notif_Switch]
  245.   end
  246.  
  247. end
  248.  
  249. class EvNotives < Array
  250.  
  251.   include Theo::EvNotif
  252.  
  253.   def initialize
  254.     super
  255.     @count = 0
  256.   end
  257.  
  258.   def update
  259.     update_delete
  260.     update_new_notif
  261.     update_members
  262.   end
  263.  
  264.   def update_delete
  265.     delete_if {|ev| ev.disposed? }
  266.   end
  267.  
  268.   def update_new_notif
  269.     @count += 1
  270.     return if $game_temp.notif_queue.empty?
  271.     return if @count <= Notif_TimeGap
  272.     push(EvNotif.new($game_temp.notif_queue.shift))
  273.     @count = 0
  274.   end
  275.  
  276.   def update_members
  277.     each {|ev| ev.update }
  278.   end
  279.  
  280.   def dispose
  281.     each {|ev| ev.dispose }
  282.   end
  283.  
  284. end
  285.  
  286. class EvNotif < Window_Base
  287.  
  288.   include Theo::EvNotif
  289.  
  290.   def initialize(notif)
  291.     @notif = notif
  292.     super(0,0,1, fitting_height(1))
  293.     self.opacity = 0
  294.     @count = 0
  295.     resize_width
  296.     update_position
  297.     draw_notif
  298.     up(SlideUp_Range, SlideUp_Duration) # Taken from Theo - Basic Modules
  299.   end
  300.  
  301.   def width=(width)
  302.     super
  303.     create_contents
  304.   end
  305.  
  306.   def resize_width
  307.     self.width = calc_width
  308.     setup_font
  309.   end
  310.  
  311.   def line_height
  312.     [FontSize, super].max
  313.   end
  314.  
  315.   def calc_width
  316.     setup_font
  317.     result = text_size(@notif.text).width + standard_padding * 2 + 2
  318.     result += (icon? ? 24 : 0)
  319.     result
  320.   end
  321.  
  322.   def update_position
  323.     self.x = $game_player.screen_x - width/2
  324.     self.y = $game_player.screen_y - 48
  325.   end
  326.  
  327.   def icon?
  328.     @notif.icon > 0
  329.   end
  330.  
  331.   def draw_notif
  332.     color = @notif.color.is_a?(Color) ? @notif.color : text_color(@notif.color)
  333.     change_color(color)
  334.     draw_icon(@notif.icon, 0,0) if icon?
  335.     xpos = (icon? ? 24 : 0)
  336.     text_rect = Rect.new(xpos, 0, contents.width - xpos, contents.height)
  337.     draw_text(text_rect, @notif.text, 1)
  338.     @notif.play
  339.   end
  340.  
  341.   def setup_font
  342.     contents.font.name = FontName
  343.     contents.font.size = FontSize
  344.     contents.font.bold = FontBold
  345.   end
  346.  
  347.   def update
  348.     super
  349.     @count += 1
  350.     update_fadeout
  351.     update_dispose
  352.   end
  353.  
  354.   def update_fadeout
  355.     contents_fade(0, Fadeout_Duration) if @count == Show_Time
  356.   end
  357.  
  358.   def update_dispose
  359.     dispose if contents_opacity == 0
  360.   end
  361.  
  362. end
  363.  
  364. class Scene_Map < Scene_Base
  365.  
  366.   alias theo_evnotif_start start
  367.   def start
  368.     theo_evnotif_start
  369.     @evnotif = EvNotives.new
  370.   end
  371.  
  372.   alias theo_evnotif_update update
  373.   def update
  374.     theo_evnotif_update
  375.     @evnotif.update
  376.   end
  377.  
  378.   alias theo_evnotif_dispose_windows dispose_all_windows
  379.   def dispose_all_windows
  380.     theo_evnotif_dispose_windows
  381.     @evnotif.dispose
  382.   end
  383.  
  384. end
Advertisement
Add Comment
Please, Sign In to add comment