Advertisement
eugene222

Mail System (German)

Sep 25th, 2014
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 38.26 KB | None | 0 0
  1. #==============================================================================
  2. # ** Mail System **
  3. #
  4. # Author:     Evgenij
  5. # Date:       28.09.2014
  6. # Version:    1.1a
  7. # ToF:        evgenij-scripts.org
  8. #
  9. # Thanks to: MHRob for requesting this script
  10. #==============================================================================
  11. #
  12. # Changelog:
  13. #
  14. # 28.09.2014 - V. 1.1a:
  15. #   - bugfixes
  16. #
  17. # 25.09.2014 - V. 1.1:
  18. #   - bugfixes
  19. #   - added gold to attachments
  20. #   - new feature: custom windowskin
  21. #   - new feature: run common_event when reading mail
  22. #   - new scriptcall: $game_system.attachments_claimed?(:symbol)
  23. #
  24. # 24.09.2014 - V. 1.0:
  25. #   - script created
  26. #
  27. #==============================================================================
  28. #
  29. # Beschreibung:
  30. #
  31. #   Dieses Script fügt eine Mail-Scene in euer Spiel ein.
  32. #   Näheres findet ihr im Script im Configbereich
  33. #
  34. # Script Calls:
  35. #
  36. # SceneManager.call(Scene_Mail)  # Die Scene öffnen
  37. #  
  38. # $game_system.add_email(:symbol)
  39. # $game_system.remove_email(:symbol)
  40. # $game_system.has_email?(:symbol)            # checkt ob spieler email hat
  41. # $game_system.attachments_claimed?(:symbol)  # checkt ob spieler die Anhänge
  42. #                                             # erhalten hat
  43. #
  44. #==============================================================================
  45. module EVG
  46.   module MAIL
  47.     #--------------------------------------------------------------------------
  48.     # Einige Escape Codes welche bei fast allen Texten im Configbereich genutzt
  49.     # werden können:
  50.     # \n           => neue Zeile
  51.     # \\c[index]   => Schriftfarbe ändern (Windowskin index verwenden)
  52.     # \\b          => Schaltet zwischen Fettgedruckt um, also an oder aus.
  53.     # \\i[index]   => Zeigt icon an
  54.     #--------------------------------------------------------------------------
  55.    
  56.     #--------------------------------------------------------------------------
  57.     # Cosmetic and Vocab Config:
  58.     #--------------------------------------------------------------------------
  59.     ALL_VOCAB = "Alle"
  60.     UNREAD_VOCAB = "Ungelesen"
  61.     READ_VOCAB = "Gelesen"
  62.     DELETED_VOCAB = "Gelöscht"
  63.    
  64.     ACTION_READ_VOCAB = "Lesen"
  65.     ACTION_MARK_READ_VOCAB = "Als gelesen markieren"
  66.     ACTION_MARK_UNREAD_VOCAB = "Als ungelesen markieren"
  67.     ACTION_DELETE_VOCAB = "Löschen"
  68.     ACTION_GET_ATTACHMENTS_VOCAB = "Anhänge erhalten"
  69.     # %s und %s werden im Script mit dem Sendernamen und der Senderaddresse ersetzt
  70.     HEADER_FROM_VOCAB = "\\b\\c[5]VON\\c[0]: \\c[6]%s <%s>\\b"
  71.    # %s wird im Script mit dem Mailnamen ersetzt
  72.    HEADER_SUBJECT_VOCAB = "\\b\\c[5]BETREFF\\c[0]: \\c[6]%s\\b"
  73.    ATTACHMENTS_VOCAB = "\\b\\c[13]Anhänge\\c[0]\\b"
  74.    CLAIMED_VOCAB = "Erhalten"
  75.  
  76.    # Nur Windowskin Farben möglich
  77.    CLAIMED_COLOR = 25
  78.    SENDER_COLOR = 2
  79.  
  80.    ATTACHMENT_ICON = 258
  81.    READ_ICON = 236
  82.    UNREAD_ICON = 235
  83.    NEW_MAIL_ICON = 235
  84.    GOLD_ICON = 361
  85.    
  86.    # Eigenen Windowskin für diese Scene verwenden, Die Datei muss in
  87.    # Graphics/System sein
  88.    # Wenn die Datei nicht existiert wird der Standartwindowskin genommen.
  89.    
  90.    WINDOWSKIN = "mailwindow"
  91.    WINDOWTONE = Tone.new(0, 0, 0, 0)
  92.    
  93.    #--------------------------------------------------------------------------
  94.    # Settings:
  95.    #--------------------------------------------------------------------------
  96.    GET_ATTACHMENTS_WHEN_MARKREAD = false
  97.    GET_ATTACHMENTS_WHEN_DELETE = true
  98.    SHOW_DELETED_CATEGORY = true
  99.    # Wenn es ungelese Email gibt, wird oben rechts die Anzahl eingeblendet.    
  100.    # Mit dem hier festgelegten Switch lässt sich das ganze ausschalten.
  101.    # Wenn der Switch an ist, wird keine Benachrichtigung angezeigt.
  102.    NOTIFICATION_ON_MAP_OFF_SWITCH = 5
  103.  
  104.    ADD_EMAIL_COMMMAND_TO_MENU = true
  105.    COMMAND_VOCAB = "View Mails"
  106.    COMMAND_SWITCH = 10   # Menu Command mit diesem Switch steuern
  107.  
  108.    #--------------------------------------------------------------------------
  109.    # Configure possible senders:
  110.    #--------------------------------------------------------------------------
  111.    SENDERS = { # Do not edit this line
  112.    #--------------------------------------------------------------------------
  113.      :eric => "eric@rpgmaker.rm",
  114.      :natalie => "natalie@rpgmaker.rm",
  115.      :me => "me@rpgmaker.rm",
  116.      
  117.    #--------------------------------------------------------------------------
  118.    } # Do not edit this line
  119.    #--------------------------------------------------------------------------
  120.    EMAILS = { # do not edit this line
  121.    #--------------------------------------------------------------------------
  122.    # Configure e-mails
  123.    # Template:
  124.    #
  125.    # :symbol => {  # Das Symbol muss mit doppelpunkt beginnen und einzigartig sein
  126.    #
  127.    #   :sender => :eric,  # Hier einen der oben definierten Sender verwenden.
  128.    #
  129.    #   :name   => "Email Name",
  130.    #
  131.    #   :text   => "Email Text",   # Hier sind die oben erwähnten escape codes möglich
  132.    #
  133.    #   :attachments => [w1, i12, g300],# Der Spieler würde im Anhang Waffe 1
  134.    #                                   # Item 12 und 300 Gold erhalten
  135.    #                                   # Anhänge sind optional
  136.    #
  137.    #   # Optional, hiermit kann man Common Events definieren.
  138.    #
  139.    #   :attach_ce => id,               # Wenn Anhänge erhalten werden, wird
  140.    #                                     das Common Event mit der id ausgeführt
  141.    #
  142.    #   :read_ce => id,                 # Wenn Email gelesen wird, wird das
  143.    #                                   # Common Event mit der Id ausgeführt
  144.    # },
  145.    #--------------------------------------------------------------------------
  146.  
  147.     :mail1 => {
  148.       :sender => :eric,
  149.       :name => "Hey whats up",
  150.       :text => "Blab\\c[2]albab\\c[0]la",
  151.     },
  152.    
  153.     :mail2 => {
  154.       :sender => :natalie,
  155.       :name => "Wilkommen",
  156.       :text => "Hallo, \n"+
  157.                "Ich möchte dich in unserer Gilde willkommen heißen.\n"+
  158.                "Wenn du fragen hast, kannst du dich an mich oder die\n"+
  159.                "anderen Gildenmitglieder wenden.\n\n"+
  160.                "Mit freundlichen Grüßen\n"+
  161.                "\\b\\c[10]Natalie\\c[0]\\b",
  162.  
  163.       :attachments => [:g30000, :w1, :i1, :a12],
  164.     },
  165.    
  166.     :mail3 => {
  167.       :sender => :me,
  168.       :name => "Some rewards for ya!",
  169.       :text => "Blabalbabla",
  170.       :attachments => [:w2, :i2, :a13, :i4, :i6],
  171.     },
  172.    
  173.    #--------------------------------------------------------------------------
  174.    } # Do not edit this line
  175.    #--------------------------------------------------------------------------
  176.    #============================================================================
  177.    # CONFIG END
  178.    #============================================================================
  179.    def initialize(*args)
  180.      super(*args)
  181.      skin = Cache.system(WINDOWSKIN) rescue nil
  182.      self.windowskin = skin if skin
  183.    end
  184.    def update_tone
  185.      self.tone.set(WINDOWTONE)
  186.    end
  187.  end
  188.  #============================================================================
  189.  class EMail
  190.    #--------------------------------------------------------------------------
  191.    attr_reader :symbol
  192.    attr_reader :name
  193.    attr_reader :address
  194.    attr_reader :title
  195.    attr_reader :text
  196.    attr_reader :sender
  197.    attr_reader :date
  198.    attr_reader :attachments
  199.    attr_reader :common_event_attach
  200.    attr_reader :common_event_read
  201.    attr_writer :read_ce
  202.    #--------------------------------------------------------------------------
  203.    def initialize(symbol, properties)
  204.      @symbol = symbol
  205.      @sender = properties[:sender].to_s.capitalize
  206.      @address = EVG::MAIL::SENDERS[properties[:sender]]
  207.      @name = properties[:name]
  208.      @text = properties[:text]
  209.      @attachments = properties[:attachments]
  210.      @title = properties[:title]
  211.      @common_event_attach = properties[:attach_ce]
  212.      @common_event_read   = properties[:read_ce]
  213.      @read_ce = false
  214.      @deleted = false
  215.      @date = Time.now
  216.      @state = :unread
  217.    end
  218.    #--------------------------------------------------------------------------
  219.    def all?
  220.      !deleted?
  221.    end
  222.    #--------------------------------------------------------------------------
  223.    def read
  224.      @state = :read
  225.      $game_system.calc_unread_mail_count
  226.      #@read_ce = true
  227.    end
  228.    #--------------------------------------------------------------------------
  229.    def read?
  230.      @state == :read
  231.    end
  232.    #--------------------------------------------------------------------------
  233.    def unread
  234.      @state = :unread
  235.      $game_system.calc_unread_mail_count
  236.    end
  237.    #--------------------------------------------------------------------------
  238.    def unread?
  239.      @state != :read
  240.    end
  241.    #--------------------------------------------------------------------------
  242.    def delete
  243.      @deleted = true
  244.      $game_system.calc_unread_mail_count
  245.    end
  246.    #--------------------------------------------------------------------------
  247.    def undelete
  248.      @deleted = false
  249.      $game_system.calc_unread_mail_count
  250.    end
  251.    #--------------------------------------------------------------------------
  252.    def deleted?
  253.      @deleted
  254.    end
  255.    #--------------------------------------------------------------------------
  256.    def attachments?
  257.      @attachments && !@attachments.empty?
  258.    end
  259.    #--------------------------------------------------------------------------
  260.    def claim_attachments
  261.      return if @attachments_claimed
  262.      @attachments_claimed = true
  263.    end
  264.    #--------------------------------------------------------------------------
  265.    def attachments_claimed?
  266.      @attachments_claimed || !attachments?
  267.    end
  268.    #--------------------------------------------------------------------------
  269.    def attach_common_event?
  270.      !@common_event_attach.nil? && @common_event_attach != 0
  271.    end
  272.    #--------------------------------------------------------------------------
  273.    def read_common_event?
  274.      !@common_event_read.nil? && @common_event_read != 0
  275.    end
  276.    #--------------------------------------------------------------------------
  277.    def read_common_event_ran?
  278.      return @read_ce
  279.    end
  280.  end
  281.  #--------------------------------------------------------------------------
  282.  module AttachmentManager
  283.    def self.get_item(code)
  284.      if /([a, w, i, g])(\d+)/i =~ code.to_s
  285.        case $1.upcase
  286.        when 'W'
  287.          $data_weapons[$2.to_i]
  288.        when 'A'
  289.          $data_armors[$2.to_i]
  290.        when 'I'
  291.          $data_items[$2.to_i]
  292.        when 'G'
  293.          $2.to_i
  294.        end    
  295.      end  
  296.    end
  297.  end
  298.  #--------------------------------------------------------------------------
  299. end
  300. #==============================================================================
  301. class Game_System
  302. #--------------------------------------------------------------------------
  303. attr_reader :mails
  304. attr_reader :unread_mails_count
  305. #--------------------------------------------------------------------------
  306. alias :evg_gs_initialze_mail    :initialize
  307. def initialize
  308.   evg_gs_initialze_mail
  309.   @mails = {}
  310.   @unread_mails_count = 0
  311. end
  312. #--------------------------------------------------------------------------
  313. def add_mail(symbol)
  314.   @mails ||= {}
  315.   return if @mails[symbol]
  316.   @mails[symbol] = EVG::EMail.new(symbol, EVG::MAIL::EMAILS[symbol])
  317.   @mails = Hash[@mails.sort_by{|sym, mail| mail.date}.reverse]
  318.   calc_unread_mail_count
  319. end
  320. #--------------------------------------------------------------------------
  321. def remove_mail(symbol)
  322.   @mails.delete(symbol)
  323.   calc_unread_mail_count
  324. end
  325. #--------------------------------------------------------------------------
  326. def has_email?(symbol)
  327.   !!@mails[symbol]
  328. end
  329. #--------------------------------------------------------------------------
  330. def attachments_claimed?(symbol)
  331.   @mails[symbol].attachments_claimed?
  332. end
  333. #--------------------------------------------------------------------------
  334. def calc_unread_mail_count
  335.   @unread_mails_count = @mails.select{|sym, mail| mail.unread?}.size
  336. end
  337. #--------------------------------------------------------------------------
  338. end
  339. #==============================================================================
  340. class Sprite_New_Mail < Sprite
  341. #--------------------------------------------------------------------------
  342. def initialize(viewport = nil, x, y)
  343.   super(viewport)
  344.   self.x = 4
  345.   self.y = y
  346.   reset_counter
  347.   create_bitmap
  348.   create_fiber
  349.   update
  350. end
  351. #--------------------------------------------------------------------------
  352. def max_time
  353.   return 60
  354. end
  355. #--------------------------------------------------------------------------
  356. def create_bitmap
  357.   self.bitmap = Bitmap.new(Graphics.width, 24)
  358.   draw_info
  359. end
  360. #--------------------------------------------------------------------------
  361. def draw_info
  362.   @old_count = $game_system.unread_mails_count
  363.   self.bitmap.clear
  364.   self.bitmap.draw_text(0, 0, Graphics.width - 32, 24, $game_system.unread_mails_count, 2)
  365.   draw_icon(EVG::MAIL::NEW_MAIL_ICON, Graphics.width - 32, 0)
  366. end
  367. #--------------------------------------------------------------------------
  368. def draw_icon(icon_index, x, y, enabled = true)
  369.   bitmap = Cache.system("Iconset")
  370.   rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  371.   self.bitmap.blt(x, y, bitmap, rect, enabled ? 255 : 128)
  372. end
  373. #--------------------------------------------------------------------------
  374. def create_fiber
  375.   @fiber = Fiber.new { fiber_main }
  376. end
  377. #--------------------------------------------------------------------------
  378. def fiber_main
  379.   loop do
  380.     update_visibility
  381.     @counter += 1
  382.     Fiber.yield
  383.     reset_counter if @counter >= max_time
  384.   end
  385.   @fiber = nil
  386. end
  387. #--------------------------------------------------------------------------
  388. def reset_counter
  389.   @counter = 0
  390. end
  391. #--------------------------------------------------------------------------
  392. def update_visibility
  393.   self.opacity = (-((@counter - 30.0)**2 * 0.28) + 255).to_i
  394. end
  395. #--------------------------------------------------------------------------
  396. def update
  397.   draw_info if @old_count != $game_system.unread_mails_count
  398.   self.visible = set_visible?
  399.   update_fiber if self.visible
  400. end
  401. #--------------------------------------------------------------------------
  402. def update_fiber
  403.   @fiber.resume if @fiber
  404. end
  405. #--------------------------------------------------------------------------
  406. def set_visible?
  407.   return false if $game_switches[EVG::MAIL::NOTIFICATION_ON_MAP_OFF_SWITCH]
  408.   return $game_system.unread_mails_count > 0
  409. end
  410. #--------------------------------------------------------------------------
  411. def dispose
  412.   self.bitmap.dispose if self.bitmap
  413.   self.bitmap = nil
  414.   super
  415. end
  416. #--------------------------------------------------------------------------
  417. end
  418. #==============================================================================
  419. class Spriteset_Map
  420. #--------------------------------------------------------------------------
  421. alias :evg_ssm_cp_mail    :create_pictures
  422. def create_pictures
  423.   evg_ssm_cp_mail
  424.   x = Graphics.width - 28
  425.   y = 4
  426.   @new_mail_sprite = Sprite_New_Mail.new(@viewport3, x, y)
  427. end
  428. #--------------------------------------------------------------------------
  429. alias :evg_ssm_dp_mail    :dispose_pictures
  430. def dispose_pictures
  431.   evg_ssm_dp_mail
  432.   @new_mail_sprite.dispose
  433.   @new_mail_sprite = nil
  434. end
  435. #--------------------------------------------------------------------------
  436. alias :evg_ssm_up_mail    :update_pictures
  437. def update_pictures
  438.   evg_ssm_up_mail
  439.   @new_mail_sprite.update
  440. end
  441. #--------------------------------------------------------------------------
  442. end
  443. #==============================================================================
  444. class Window_MailCategory < Window_HorzCommand
  445. #--------------------------------------------------------------------------
  446. include EVG::MAIL
  447. attr_reader   :selection_window
  448. #--------------------------------------------------------------------------
  449. def initialize(selection_window)
  450.   @selection_window = selection_window
  451.   super(window_x, window_y)
  452. end
  453. #--------------------------------------------------------------------------
  454. def window_x
  455.   @selection_window.window_x
  456. end
  457. #--------------------------------------------------------------------------
  458. def window_y
  459.   @selection_window.window_y - window_height
  460. end
  461. #--------------------------------------------------------------------------
  462. def window_width
  463.   @selection_window.window_width
  464. end
  465. #--------------------------------------------------------------------------
  466. def col_max
  467.   return 4
  468. end
  469. #--------------------------------------------------------------------------
  470. def update
  471.   super
  472.   @selection_window.category = current_symbol if @selection_window
  473. end
  474. #--------------------------------------------------------------------------
  475. def make_command_list
  476.   add_command(ALL_VOCAB,     :all)
  477.   add_command(UNREAD_VOCAB,  :unread)
  478.   add_command(READ_VOCAB,    :read)
  479.   add_command(DELETED_VOCAB, :deleted) if SHOW_DELETED_CATEGORY
  480. end
  481. #--------------------------------------------------------------------------
  482. def selection_window=(window)
  483.   @selection_window = window
  484.   update
  485. end
  486. #--------------------------------------------------------------------------
  487. end
  488. #==============================================================================
  489. class Window_MailSelection  < Window_Selectable
  490. #--------------------------------------------------------------------------
  491. include EVG::MAIL
  492. attr_reader :mails
  493. #--------------------------------------------------------------------------
  494. def initialize
  495.   create_mails
  496.   super(window_x, window_y, window_width, window_height)
  497.   refresh
  498. end
  499. #--------------------------------------------------------------------------
  500. def real_mails
  501.   $game_system.mails.values
  502. end
  503. #--------------------------------------------------------------------------
  504. def create_mails
  505.   @mails = case @category
  506.            when :read
  507.              real_mails.compact.select{|mail| mail.read? && !mail.deleted?}
  508.            when :unread
  509.              real_mails.compact.select{|mail| mail.unread? && !mail.deleted?}
  510.            when :deleted
  511.              real_mails.compact.select(&:deleted?)
  512.            else
  513.              real_mails.compact.select(&:all?)
  514.            end
  515. end
  516. #--------------------------------------------------------------------------
  517. def item_max
  518.   return @mails.size
  519. end
  520. #--------------------------------------------------------------------------
  521. def window_x
  522.   (Graphics.width - window_width) / 2
  523. end
  524. #--------------------------------------------------------------------------
  525. def window_y
  526.   (Graphics.height- window_height) / 2
  527. end
  528. #--------------------------------------------------------------------------
  529. def window_width
  530.   return 420
  531. end
  532. #--------------------------------------------------------------------------
  533. def window_height
  534.   fitting_height(10)
  535. end
  536. #--------------------------------------------------------------------------
  537. def sender_width
  538.   96
  539. end
  540. #--------------------------------------------------------------------------
  541. def name_width
  542.   contents.width - sender_width - 28 - 24
  543. end
  544. #--------------------------------------------------------------------------
  545. def category=(category)
  546.   return if @category == category
  547.   @category = category
  548.   refresh
  549.   self.oy = 0
  550. end
  551. #--------------------------------------------------------------------------
  552. def current_symbol
  553.   @mails[@index].symbol
  554. end
  555. #--------------------------------------------------------------------------
  556. def current_mail
  557.   @mails[@index]
  558. end
  559. #--------------------------------------------------------------------------
  560. def draw_item(index)
  561.   draw_mail_name(index)
  562. end
  563. #--------------------------------------------------------------------------
  564. def draw_mail_name(index)
  565.   mail = mails[index]
  566.   y = index * line_height
  567.   contents.font.size = 20
  568.   contents.font.bold = !mail.read?
  569.   change_color(sender_color(mail))
  570.   draw_read_unread_icon(mail, 2, y)
  571.   draw_text(26, y, sender_width, line_height, mail.sender)
  572.   change_color(text_color1(mail))
  573.   draw_text(sender_width + 26, y, name_width, line_height, mail.name)
  574.   draw_attachment_icon(mail, contents.width - 26, y) if mail.attachments?
  575. end
  576. #--------------------------------------------------------------------------
  577. def draw_read_unread_icon(mail, x, y)
  578.   icon_id = mail.read? ? READ_ICON : UNREAD_ICON
  579.   draw_icon(icon_id, x, y, !mail.read?)
  580. end
  581. #--------------------------------------------------------------------------
  582. def draw_attachment_icon(mail, x, y)
  583.   draw_icon(ATTACHMENT_ICON, x, y, !mail.attachments_claimed?)
  584. end
  585. #--------------------------------------------------------------------------
  586. def sender_color(mail)
  587.   color = Color.new.set(text_color(SENDER_COLOR))
  588.   color.set(color.red, color.green, color.blue, mail.read? ? 220 : color.alpha)
  589.   color
  590. end
  591. #--------------------------------------------------------------------------
  592. def text_color1(mail)
  593.   color = Color.new.set(normal_color)
  594.   color.set(color.red, color.green, color.blue, mail.read? ? 220 : color.alpha)
  595.   color
  596. end
  597. #--------------------------------------------------------------------------
  598. def refresh
  599.   create_mails
  600.   create_contents
  601.   draw_all_items
  602.   correct_index
  603. end
  604. #--------------------------------------------------------------------------
  605. def correct_index
  606.   if @index > @mails.size - 1 && @mails.size > 0
  607.     select(@mails.size - 1)
  608.   end
  609. end
  610. #--------------------------------------------------------------------------
  611. def current_item_enabled?
  612.   return @mails[@index]
  613. end
  614. #--------------------------------------------------------------------------
  615. end
  616. #==============================================================================
  617. class Window_MailConfirm < Window_Command
  618. #--------------------------------------------------------------------------
  619. include EVG::MAIL
  620. #--------------------------------------------------------------------------
  621. def initialize(selection_window)
  622.   @selection_window = selection_window
  623.   super(0, 0)
  624.   self.openness = 0
  625.   set_center
  626.   deactivate
  627. end
  628. #--------------------------------------------------------------------------
  629. def window_width
  630.   return 256
  631. end
  632. #--------------------------------------------------------------------------
  633. def make_command_list
  634.   add_command(ACTION_READ_VOCAB, :read)
  635.   add_command(ACTION_MARK_READ_VOCAB, :mark_read, read?)
  636.   add_command(ACTION_MARK_UNREAD_VOCAB, :mark_unread, mark_unread?)
  637.   add_command(ACTION_GET_ATTACHMENTS_VOCAB, :claim_attach, claim_attach?)
  638.   add_command(ACTION_DELETE_VOCAB, :delete, delete?)
  639. end
  640. #--------------------------------------------------------------------------
  641. def read?
  642.   @selection_window.current_mail && @selection_window.current_mail.unread?
  643. end
  644. #--------------------------------------------------------------------------
  645. def mark_unread?
  646.   @selection_window.current_mail && @selection_window.current_mail.read?
  647. end
  648. #--------------------------------------------------------------------------
  649. def claim_attach?
  650.   @selection_window.current_mail && !@selection_window.current_mail.attachments_claimed?
  651. end
  652. #--------------------------------------------------------------------------
  653. def delete?
  654.   @selection_window.current_mail && !@selection_window.current_mail.deleted?
  655. end
  656. #--------------------------------------------------------------------------
  657. def set_center
  658.   self.x = (Graphics.width - window_width) / 2
  659.   self.y = (Graphics.height - window_height) - 12
  660. end
  661. #--------------------------------------------------------------------------
  662. def open
  663.   refresh
  664.   select(0)
  665.   super
  666. end
  667. #--------------------------------------------------------------------------
  668. end
  669. #==============================================================================
  670. class Window_MailMessage < Window_Selectable
  671. #--------------------------------------------------------------------------
  672. include EVG::MAIL
  673. #--------------------------------------------------------------------------
  674. attr_reader :mail
  675. #--------------------------------------------------------------------------
  676. def initialize
  677.   super(window_x, window_y, window_width, window_height)
  678.   self.openness = 0
  679.   deactivate
  680. end
  681. #--------------------------------------------------------------------------
  682. def window_x
  683.   (Graphics.width - window_width) / 2
  684. end
  685. #--------------------------------------------------------------------------
  686. def window_y
  687.   (Graphics.height - window_height) / 2
  688. end
  689. #--------------------------------------------------------------------------
  690. def window_width
  691.   Graphics.width - 24
  692. end
  693. #--------------------------------------------------------------------------
  694. def window_height
  695.   ((Graphics.height - 24) / 24) * 24
  696. end
  697. #--------------------------------------------------------------------------
  698. def mail=(mail)
  699.   @mail = mail
  700.   refresh
  701. end
  702. #--------------------------------------------------------------------------
  703. def reset_font_settings
  704.   super
  705.   contents.font.size = 20
  706. end
  707. #--------------------------------------------------------------------------
  708. def refresh
  709.   contents.clear
  710.   select(-1)
  711.   draw_header
  712.   draw_text_ex(4, 48, mail.text)
  713.   draw_attachments(contents.height - line_height * 2) if mail.attachments?
  714. end
  715. #--------------------------------------------------------------------------
  716. def draw_header_frame(y, height = 22)
  717.   contents.fill_rect(0, y, contents.width, height, Color.new(0,0,0,255))
  718.   contents.clear_rect(1, y + 1, contents.width - 2, height - 2)
  719. end
  720. #--------------------------------------------------------------------------
  721. def draw_header
  722.   draw_header_frame(0)
  723.   draw_header_frame(24)    
  724.   draw_text_ex(4, 0, sprintf(HEADER_FROM_VOCAB, mail.sender, mail.address))
  725.   draw_text_ex(4, 24, sprintf(HEADER_SUBJECT_VOCAB, mail.name) )
  726. end
  727. #--------------------------------------------------------------------------
  728. def draw_attachments(y)
  729.   draw_header_frame(y, line_height * 2 - 2)
  730.   draw_text_ex(4, y - line_height * 0.5, ATTACHMENTS_VOCAB)
  731.   if !mail.attachments_claimed?
  732.     select(0)
  733.     draw_text(item_rect_for_text(0), ACTION_GET_ATTACHMENTS_VOCAB, 1)
  734.     draw_text_ex(4, y + line_height * 0.5, attachment_text)
  735.   else
  736.     change_color(text_color(EVG::MAIL::CLAIMED_COLOR))
  737.     contents.font.bold = true
  738.     draw_text(4, y + line_height * 0.5, contents.width - 8, line_height, CLAIMED_VOCAB, 1)
  739.     #draw_text(item_rect_for_text(0), "Claimed!", 2)
  740.     change_color(normal_color)
  741.     #contents.fill_rect(3, y + line_height, contents.width - 6, 1, Color.new(0, 0, 0, 255))
  742.   end
  743. end
  744. #--------------------------------------------------------------------------
  745. def draw_text_ex(x, y, text)
  746.   reset_font_settings
  747.   text = convert_escape_characters(text)
  748.   pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
  749.   process_character(text.slice!(0, 1), text, pos) until text.empty?
  750. end
  751. #--------------------------------------------------------------------------
  752. def process_escape_character(code, text, pos)
  753.   case code.upcase
  754.   when 'B'
  755.     contents.font.bold = !contents.font.bold
  756.   else
  757.     super
  758.   end
  759. end
  760. #--------------------------------------------------------------------------
  761. def attachment_text
  762.  mail.attachments.inject("") {|res, attach| "#{item_name(attach)} #{res}"}
  763.   end
  764.   #--------------------------------------------------------------------------
  765.   def item_name(code)
  766.     item = EVG::AttachmentManager.get_item(code)
  767.     return "Invalid itemcode" if item.nil?
  768.     if item.is_a?(Fixnum)
  769.       return "\\i[#{GOLD_ICON}]#{item}"
  770.     else
  771.       return "\\i[#{item.icon_index}]#{item.name}"
  772.     end
  773.    
  774.   end
  775.   #--------------------------------------------------------------------------
  776.   def item_rect(index)
  777.     rect = Rect.new
  778.     rect.width = 128
  779.     rect.height = line_height
  780.     rect.x = contents.width - 128 - 4
  781.     rect.y = contents.height - line_height * 2.5
  782.     rect
  783.   end
  784.   #--------------------------------------------------------------------------
  785.   def ok_enabled?
  786.     handle?(:ok) && @index == 0 && mail.attachments && !mail.attachments_claimed?
  787.   end
  788.   #--------------------------------------------------------------------------
  789. end
  790. #==============================================================================
  791. class Window_MailReward < Window_Base
  792.   #--------------------------------------------------------------------------
  793.   include EVG::MAIL
  794.   #--------------------------------------------------------------------------
  795.   def initialize
  796.     super(0,0,196,0)
  797.     @counter = 0
  798.     self.openness = 0
  799.   end
  800.   #--------------------------------------------------------------------------
  801.   def start(attachments)
  802.     @attachments = attachments
  803.     refresh
  804.     open
  805.     @counter = 60
  806.   end
  807.   #--------------------------------------------------------------------------
  808.   def update
  809.     super
  810.     if busy?
  811.       @counter -= 1
  812.     end
  813.     if @counter == 0 && open?
  814.       close
  815.     end
  816.   end
  817.   #--------------------------------------------------------------------------
  818.   def busy?
  819.     @counter > 0
  820.   end
  821.   #--------------------------------------------------------------------------
  822.   def refresh
  823.     recreate_window(fitting_height(@attachments.size + 1))
  824.     draw_text(0, 0, contents.width, line_height, "#{CLAIMED_VOCAB}:")
  825.     @attachments.each_with_index do |code, i|
  826.       y = line_height * (i+1)
  827.       item = EVG::AttachmentManager.get_item(code)
  828.       if item.is_a?(Fixnum)
  829.         draw_gold(item, 0, y)
  830.       else
  831.         draw_item_name(item, 0, y)
  832.       end
  833.     end
  834.   end
  835.  
  836.   def draw_gold(number, x, y)
  837.     draw_icon(GOLD_ICON, x, y)
  838.     draw_text(x + 26, y, contents.width - 26, line_height, number)
  839.   end
  840.   #--------------------------------------------------------------------------
  841.   def recreate_window(height)
  842.     self.height = height
  843.     self.x = (Graphics.width - self.width) / 2
  844.     self.y = (Graphics.height - self.height) / 2
  845.     create_contents
  846.   end
  847.   #--------------------------------------------------------------------------
  848. end
  849. #==============================================================================
  850. class Scene_Mail < Scene_MenuBase
  851.   #--------------------------------------------------------------------------
  852.   def start
  853.     super
  854.     create_selection_window
  855.     create_category_window
  856.     create_confirm_window
  857.     create_mail_window
  858.     create_reward_window
  859.     create_interpreter
  860.   end
  861.   #--------------------------------------------------------------------------
  862.   def create_selection_window
  863.     @selection_window = Window_MailSelection.new
  864.     @selection_window.set_handler(:ok, method(:on_selection_ok))
  865.     @selection_window.set_handler(:cancel, method(:on_selection_cancel))
  866.   end
  867.   #--------------------------------------------------------------------------
  868.   def create_category_window
  869.     @category_window = Window_MailCategory.new(@selection_window)
  870.     @category_window.set_handler(:ok, method(:on_category_ok))
  871.     @category_window.set_handler(:cancel, method(:return_scene))
  872.   end
  873.   #--------------------------------------------------------------------------
  874.   def create_confirm_window
  875.     @confirm_window = Window_MailConfirm.new(@selection_window)
  876.     @confirm_window.set_handler(:read, method(:read_mail))
  877.     @confirm_window.set_handler(:mark_read, method(:mark_mail_read))
  878.     @confirm_window.set_handler(:mark_unread, method(:mark_mail_unread))
  879.     @confirm_window.set_handler(:claim_attach, method(:claim_mail_attach))
  880.     @confirm_window.set_handler(:delete, method(:delete_mail))
  881.     @confirm_window.set_handler(:cancel, method(:on_confirm_cancel))
  882.   end
  883.   #--------------------------------------------------------------------------
  884.   def create_mail_window
  885.     @mail_window = Window_MailMessage.new
  886.     @mail_window.set_handler(:cancel, method(:on_mail_cancel))
  887.     @mail_window.set_handler(:ok, method(:on_mail_ok))
  888.   end
  889.   #--------------------------------------------------------------------------
  890.   def create_reward_window
  891.     @reward_window = Window_MailReward.new
  892.   end
  893.   #--------------------------------------------------------------------------
  894.   def on_category_ok
  895.     @category_window.deactivate
  896.     @selection_window.activate
  897.     @selection_window.select(0)
  898.   end
  899.   #--------------------------------------------------------------------------
  900.   def on_selection_ok
  901.     @selection_window.deactivate
  902.     @confirm_window.refresh
  903.     @confirm_window.open
  904.     @confirm_window.activate
  905.   end
  906.   #--------------------------------------------------------------------------
  907.   def on_selection_cancel
  908.     @selection_window.deactivate
  909.     @category_window.activate
  910.     @selection_window.unselect
  911.   end
  912.   #--------------------------------------------------------------------------
  913.   def read_mail
  914.     current_mail.read
  915.     @confirm_window.close
  916.     @confirm_window.deactivate
  917.     @category_window.close
  918.     @selection_window.close
  919.     @mail_window.mail = current_mail
  920.     @mail_window.activate
  921.     @mail_window.open
  922.     run_read_common_event
  923.     @selection_window.refresh
  924.   end
  925.   #--------------------------------------------------------------------------
  926.   def mark_mail_read
  927.     current_mail.read
  928.     if EVG::MAIL::GET_ATTACHMENTS_WHEN_MARKREAD
  929.       get_attachments
  930.     end
  931.     on_confirm_cancel
  932.     run_read_common_event
  933.     @selection_window.refresh
  934.   end
  935.   #--------------------------------------------------------------------------
  936.   def mark_mail_unread
  937.     current_mail.unread
  938.     @selection_window.refresh
  939.     on_confirm_cancel
  940.   end
  941.   #--------------------------------------------------------------------------
  942.   def claim_mail_attach
  943.     get_attachments
  944.     @selection_window.refresh
  945.     on_confirm_cancel
  946.   end
  947.   #--------------------------------------------------------------------------
  948.   def get_attachments
  949.     if !current_mail.attachments_claimed?
  950.       current_mail.claim_attachments
  951.       current_mail.attachments.each do |code|
  952.         item = EVG::AttachmentManager.get_item(code)
  953.         if item.is_a?(Fixnum)
  954.           $game_party.gain_gold(item)
  955.         else
  956.           $game_party.gain_item(item, 1)
  957.         end
  958.       end
  959.       @reward_window.start(current_mail.attachments)
  960.       if current_mail.attach_common_event?
  961.         run_common_event(current_mail.common_event_attach)
  962.       end
  963.     end
  964.   end
  965.   #--------------------------------------------------------------------------
  966.   def run_read_common_event
  967.     if !current_mail.read_common_event_ran? && current_mail.read_common_event?
  968.       run_common_event(current_mail.common_event_read)
  969.       current_mail.read_ce = true
  970.     end
  971.   end
  972.   #--------------------------------------------------------------------------
  973.   def delete_mail
  974.     current_mail.delete
  975.     if EVG::MAIL::GET_ATTACHMENTS_WHEN_DELETE
  976.       get_attachments
  977.     end
  978.     @selection_window.refresh
  979.     on_confirm_cancel
  980.   end
  981.   #--------------------------------------------------------------------------
  982.   def on_confirm_cancel
  983.     @confirm_window.close
  984.     @confirm_window.deactivate
  985.     @selection_window.activate
  986.   end
  987.   #--------------------------------------------------------------------------
  988.   def on_mail_ok
  989.     get_attachments
  990.     @mail_window.refresh
  991.     @mail_window.activate
  992.   end
  993.   #--------------------------------------------------------------------------
  994.   def on_mail_cancel
  995.     @mail_window.close
  996.     @mail_window.deactivate
  997.     @selection_window.refresh
  998.     @selection_window.activate
  999.     @selection_window.open
  1000.     @category_window.open
  1001.   end
  1002.   #--------------------------------------------------------------------------
  1003.   def current_mail
  1004.     $game_system.mails[@selection_window.current_symbol]
  1005.   end
  1006.   #--------------------------------------------------------------------------
  1007.   def create_interpreter
  1008.     @interpreter = Game_Interpreter.new
  1009.   end
  1010.   #--------------------------------------------------------------------------
  1011.   def run_common_event(event_id)
  1012.     $game_temp.reserve_common_event(event_id)
  1013.     @interpreter.setup_reserved_common_event
  1014.     update_interpreter while @interpreter.running?
  1015.   end
  1016.   #--------------------------------------------------------------------------
  1017.   def update_interpreter
  1018.     update_basic
  1019.     @interpreter.update
  1020.   end
  1021.   #--------------------------------------------------------------------------
  1022.   def update_basic
  1023.     Graphics.update
  1024.     Input.update
  1025.     @reward_window.update if @reward_window.busy?
  1026.     update_all_windows unless @reward_window.busy?
  1027.   end
  1028.   #--------------------------------------------------------------------------
  1029. end
  1030. #==============================================================================
  1031. class Scene_Menu
  1032.   #--------------------------------------------------------------------------
  1033.   alias :evg_sm_ccw_mail      :create_command_window
  1034.   def create_command_window
  1035.     evg_sm_ccw_mail
  1036.     @command_window.set_handler(:evg_mail, method(:command_evg_mail))
  1037.   end
  1038.   #--------------------------------------------------------------------------
  1039.   def command_evg_mail
  1040.     SceneManager.call(Scene_Mail)
  1041.   end
  1042.   #--------------------------------------------------------------------------
  1043. end
  1044. #==============================================================================
  1045. class Window_MenuCommand
  1046.   #--------------------------------------------------------------------------
  1047.   alias :evg_wmc_aoc_mail     :add_original_commands
  1048.   def add_original_commands
  1049.     evg_wmc_aoc_mail
  1050.     return unless EVG::MAIL::ADD_EMAIL_COMMMAND_TO_MENU
  1051.     add_command(EVG::MAIL::COMMAND_VOCAB, :evg_mail, evg_mail_command_enabled?)
  1052.   end
  1053.   #--------------------------------------------------------------------------
  1054.   def evg_mail_command_enabled?
  1055.     return $game_switches[EVG::MAIL::COMMAND_SWITCH]
  1056.   end
  1057.   #--------------------------------------------------------------------------
  1058. end
  1059. #==============================================================================
  1060. # SCRIPT END
  1061. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement