TheoAllen

Theo - Event Notification

Jun 11th, 2013
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.65 KB | None | 0 0
  1. # =============================================================================
  2. # TheoAllen - Event Notification
  3. # Version : 1.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 - Basic Modules
  9. # =============================================================================
  10. ($imported ||= {})[:Theo_EventNotif] = true
  11. # =============================================================================
  12. # CHANGE LOGS:
  13. # -----------------------------------------------------------------------------
  14. # 2013.06.11 - Finished script
  15. # 2013.06.10 - Started script
  16. # =============================================================================
  17. =begin
  18.  
  19.   Perkenalan :
  20.   Script ini berfungsi untuk menampilkan event popup diatas player saat player
  21.   mendapat item atau mendapat gold. kamu juga bisa menyeting popupmu sendiri
  22.   dengan menggunakan teks.
  23.  
  24.   ----------------------------------------------------------------------------
  25.   Cara penggunaan :
  26.   Pasang dibawah material namun diatas main.
  27.  
  28.   untuk script call notifikasi, kamu bisa menuliskan
  29.   - evnotif_add("text")
  30.   - evnotif_add("text",color_id)
  31.   color_id adalah warna dari text color. Inputan adalah berupa angka dari
  32.   0 - 31
  33.  
  34.   untuk mendisable/enable change item / change gold, kamu bisa gunain
  35.   - evnotif_change_item(true/false)
  36.   - evnotif_change_gold(true/false)
  37.   pilih salah satu dari true atau false
  38.  
  39.   Edit konfigurasi kalo dirasa perlu
  40.  
  41.   ----------------------------------------------------------------------------
  42.   TERMS OF USE :
  43.   Credit gw, TheoAllen. Kalo semisal u bisa ngedit2 script gw trus jadi lebih
  44.   keren, terserah. Ane bebasin. Asal ngga ngeklaim aja. Kalo semisal mau
  45.   dipake buat komersil, jangan lupa, gw dibagi gratisannya.
  46.  
  47. =end
  48. # =============================================================================
  49. # Konfigurasi :
  50. # =============================================================================
  51. module THEO
  52.   module EVTNOTIF
  53.    
  54.     # ========================================================================
  55.       CHANGE_ITEM_NOTIF = true  # Jika kamu pengen nampilin change item
  56.       GAIN_ITEM_COLOR   = 24    # Default : 24
  57.       LOSE_ITEM_COLOR   = 25    # Default : 25
  58.     # ------------------------------------------------------------------------
  59.     # Konfigurasi untuk notifikasi change item. Color disana adalah text color
  60.     # yang bisa kamu pilih antara 0 - 31
  61.     # ========================================================================
  62.    
  63.     # ========================================================================
  64.       CHANGE_GOLD_NOTIF = true    # Jika kamu pengen nampilin change gold
  65.       GAIN_GOLD_COLOR   = 6       # Default : 6
  66.       LOSE_GOLD_COLOR   = 25      # Default : 25
  67.       GOLD_VOCAB        = "Gold"  # Vocab / currency untuk gold
  68.     # ------------------------------------------------------------------------
  69.     # Konfigurasi untuk notifikasi change gold. Color disana adalah text color
  70.     # yang bisa kamu pilih antara 0 - 31
  71.     # ========================================================================
  72.    
  73.     # ========================================================================
  74.       NOTIF_WIDTH   = 200  # Lebar maksimal notifikasi
  75.       DEFAULT_COLOR = 0    # Default : 0
  76.     # ------------------------------------------------------------------------
  77.     # Konfigurasi untuk notifikasinya
  78.     # ========================================================================
  79.    
  80.     # ========================================================================
  81.       FONT_DEFAULT  = ["Calibri"]   # Font untuk notifikasinya
  82.       FONT_SIZE     = 17            # Size huruf (default : 17)
  83.       FONT_BOLD     = true          # tulis true jika pengen bold
  84.     # ------------------------------------------------------------------------
  85.     # Konfigurasi untuk font dalam notifikasinya ~
  86.     # ========================================================================
  87.    
  88.     # ========================================================================
  89.       SHOW_TIME     = 60  # Total waktu notifikasi ditampilkan (default : 60)
  90.       FADEIN_TIME   = 10  # Total waktu notifikasi dimunculkan (default : 10)
  91.       FADEOUT_TIME  = 20  # Total waktu notifikasi dihilangkan (default : 20)
  92.     # ------------------------------------------------------------------------
  93.     # Konfiguasi untuk waktu menampilkannya. Angka tersebut adalah dalam
  94.     # satuan frame. Dimana 60 frame sama dengan 1 detik
  95.     # ========================================================================
  96.    
  97.   end
  98. end
  99. # =============================================================================
  100. # Akhir dari konfigurasi
  101. # =============================================================================
  102. class Game_System
  103.   attr_accessor :show_evnotif
  104.   attr_accessor :evnotif_gold
  105.   attr_accessor :notif_color
  106.  
  107.   alias pre_evnotif_init initialize
  108.   def initialize
  109.     pre_evnotif_init
  110.     init_evnotif_members
  111.   end
  112.  
  113.   def init_evnotif_members
  114.     @show_evnotif = THEO::EVTNOTIF::CHANGE_ITEM_NOTIF
  115.     @notif_color = THEO::EVTNOTIF::DEFAULT_COLOR
  116.     @evnotif_gold = THEO::EVTNOTIF::CHANGE_GOLD_NOTIF
  117.   end
  118.  
  119. end
  120.  
  121. class Game_Party < Game_Unit
  122.  
  123.   alias pre_evnotif_gain_item gain_item
  124.   def gain_item(item,amount,include_equip = false)
  125.     if item_container(item.class) && amount != 0 && $game_system.show_evnotif
  126.       last_number = item_number(item)
  127.       if amount > 0
  128.         new_number = last_number+amount
  129.         gained = [[new_number,0].max,max_item_number(item)].min
  130.         $game_temp.item_queue.push(Game_EventStruct.new(item,gained))
  131.       elsif amount < 0 && last_number > 0
  132.         loss = [amount,last_number*-1].max
  133.         $game_temp.item_queue.push(Game_EventStruct.new(item,loss))
  134.       end
  135.     end
  136.     pre_evnotif_gain_item(item,amount,include_equip)
  137.   end
  138.  
  139.   alias pre_evnotif_gain_gold gain_gold
  140.   def gain_gold(amount)
  141.     color = amount > 0 ? THEO::EVTNOTIF::GAIN_GOLD_COLOR :
  142.       THEO::EVTNOTIF::LOSE_GOLD_COLOR
  143.     text = THEO::EVTNOTIF::GOLD_VOCAB + (amount > 0 ? " +" : " ") + amount.to_s
  144.     $game_system.notif_color = color
  145.     $game_temp.item_queue.push(text) if $game_system.evnotif_gold
  146.     pre_evnotif_gain_gold(amount)
  147.   end
  148.  
  149. end
  150.  
  151. class Game_Interpreter
  152.  
  153.   def evnotif_add(text,color=THEO::EVTNOTIF::DEFAULT_COLOR)
  154.     unless $game_temp.item_queue.any? do |list|
  155.       if list.is_a?(String)
  156.         list == text
  157.       else
  158.         false
  159.       end
  160.     end
  161.     $game_system.notif_color = color
  162.     $game_temp.item_queue.push(text)
  163.     end
  164.   end
  165.  
  166.   def evnotif_change_item(bool)
  167.     $game_system.show_evnotif = bool
  168.   end
  169.  
  170.   def evnotif_change_gold(bool)
  171.     $game_system.evnotif_gold = bool
  172.   end
  173.  
  174. end
  175.  
  176. class Game_EventStruct
  177.   attr_accessor :item, :amount
  178.  
  179.   def initialize(item,amount)
  180.     @item = item
  181.     @amount = amount
  182.   end
  183.  
  184. end
  185.  
  186. class Game_Temp
  187.   attr_accessor :item_queue
  188.  
  189.   alias pre_evnotif_init initialize
  190.   def initialize
  191.     pre_evnotif_init
  192.     clear_item_queue
  193.   end
  194.  
  195.   def clear_item_queue
  196.     @item_queue = []
  197.   end
  198.  
  199.   def showing_notif?
  200.     !@item_queue.empty?
  201.   end
  202.  
  203. end
  204.  
  205. class Window_EventNotif < Window_Base
  206.  
  207.   include THEO::EVTNOTIF
  208.  
  209.   def initialize(width)
  210.     super(0,0,width,window_height)
  211.     self.opacity = 0
  212.     self.contents_opacity = 0
  213.     contents.font.name = FONT_DEFAULT
  214.     contents.font.size = FONT_SIZE
  215.     contents.font.bold = FONT_BOLD
  216.     @item = nil
  217.     @notif_flag = false
  218.     @count = 0
  219.   end
  220.  
  221.   def window_height
  222.     24 + standard_padding*2
  223.   end
  224.  
  225.   def item=(item)
  226.     @item = item
  227.     refresh
  228.     update_placement
  229.     self.contents_fade(255,FADEIN_TIME)
  230.     @notif_flag = true
  231.     @count = 0
  232.   end
  233.  
  234.   def refresh
  235.     contents.clear
  236.     if @item.is_a?(Game_EventStruct)
  237.       icon = @item.item.icon_index
  238.       amount = @item.amount
  239.       if amount > 0
  240.         change_color(text_color(GAIN_ITEM_COLOR))
  241.       else
  242.         change_color(text_color(LOSE_ITEM_COLOR))
  243.       end
  244.       text = @item.item.name + (amount > 0 ? " +" : " ") + amount.to_s
  245.       rect = text_size(text)
  246.       draw_icon(icon,[contents.width/2 - rect.width/2 - 24,0].max,0)
  247.       draw_text(15,0,contents.width-24,contents.height,text,1)
  248.     else
  249.       change_color(text_color($game_system.notif_color))
  250.       draw_text(0,0,contents.width,contents.height,@item,1)
  251.     end
  252.   end
  253.  
  254.   def update_placement
  255.     self.x = $game_player.screen_x - self.width/2
  256.     self.y = $game_player.screen_y - self.height - 24
  257.   end
  258.  
  259.   def update
  260.     super
  261.     update_placement
  262.     if @notif_flag
  263.       if @count > SHOW_TIME
  264.         @notif_flag = false
  265.         @count = 0
  266.         contents.clear
  267.         self.contents_opacity = 0
  268.         self.opacity = 0
  269.       end
  270.       self.contents_fade(0,FADEOUT_TIME) if @count == SHOW_TIME - FADEOUT_TIME
  271.       @count += 1
  272.     end
  273.   end
  274.  
  275.   def showing_notif?
  276.     @notif_flag
  277.   end
  278.  
  279. end
  280.  
  281. class Scene_Map < Scene_Base
  282.  
  283.   alias pre_evnotif_start start
  284.   def start
  285.     pre_evnotif_start
  286.     create_evnotif_window
  287.   end
  288.  
  289.   def create_evnotif_window
  290.     @evnotif_window = Window_EventNotif.new(THEO::EVTNOTIF::NOTIF_WIDTH)
  291.     @evnotif_window.viewport = @viewport
  292.   end
  293.  
  294.   alias pre_evnotif_update update
  295.   def update
  296.     pre_evnotif_update
  297.     update_evnotif_window
  298.   end
  299.  
  300.   def update_evnotif_window
  301.     if $game_temp.showing_notif? && !@evnotif_window.showing_notif?
  302.       @evnotif_window.item = $game_temp.item_queue.shift
  303.     end
  304.   end
  305.  
  306. end
Advertisement
Add Comment
Please, Sign In to add comment