TheoAllen

Theo - Event Notif

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