Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Mail_Core
- end
- class Scene_MailBox < Scene_MenuBase
- #--------------------------------------------------------------------------
- # * Create Background
- #--------------------------------------------------------------------------
- def create_background
- @background_sprite = Plane.new
- @background_sprite.bitmap = Cache.system("BGLoop3")
- end
- #--------------------------------------------------------------------------
- # * Start Processing
- #--------------------------------------------------------------------------
- def start
- super
- @mail_list_window = Window_MailList.new(0, 0)
- @mail_list_window.x = (Graphics.width - @mail_list_window.width) / 2
- @mail_list_window.y = (real_height - @mail_list_window.height) / 2
- @mail_list_window.unread_method = method(:refresh_unread_window)
- @mail_list_window.set_handler(:cancel, method(:return_scene))
- # Unread Window
- ww = @mail_list_window.width
- wh = @mail_list_window.fitting_height(1)
- wx = @mail_list_window.x
- wy = @mail_list_window.y + @mail_list_window.height + 12
- @unread_window = Window_Base.new(wx,wy,ww,wh)
- # Info Window
- ww = @mail_list_window.width + 100
- wh = @mail_list_window.height + @unread_window.height + 12
- wx = @mail_list_window.x + 12
- wy = @mail_list_window.y + 12
- @mail_info_window = Window_MailInfo.new(wx,wy,ww,wh)
- @mail_list_window.help_window = @mail_info_window
- # Relocate Windows
- total_width = @mail_list_window.width + 12 + @mail_info_window.width
- @mail_list_window.x = (Graphics.width - total_width) / 2
- @mail_info_window.x = @mail_list_window.x + @mail_list_window.width + 12
- @mail_info_window.y = @mail_list_window.y
- @unread_window.x = @mail_list_window.x
- #@unread_window.y = @mail_list_window.y + 12
- refresh_unread_window
- end
- #--------------------------------------------------------------------------
- # * Refresh Unread Window
- #--------------------------------------------------------------------------
- def refresh_unread_window
- unread_nums = $game_system.total_unread_mails()
- @unread_window.contents.clear
- cw = @unread_window.contents_width
- @unread_window.draw_text_ex(0,0,"\\c[5]#{unread_nums}\\c[0] Unread Mail(s)")
- end
- #--------------------------------------------------------------------------
- # * Update Processing
- #--------------------------------------------------------------------------
- def update
- super
- @background_sprite.ox += 1
- @background_sprite.oy += 1
- end
- #--------------------------------------------------------------------------
- # * Terminate Processing
- #--------------------------------------------------------------------------
- def terminate
- super
- end
- end # Scene_MailBox
- class Window_MailList < Window_Command
- attr_accessor :unread_method
- #--------------------------------------------------------------------------
- # * Window Width
- #--------------------------------------------------------------------------
- def window_width
- return 260
- end
- #--------------------------------------------------------------------------
- # * Window Height
- #--------------------------------------------------------------------------
- def window_height
- return fitting_height(10)
- end
- #--------------------------------------------------------------------------
- # * Update Help Window
- #--------------------------------------------------------------------------
- def update_help
- @help_window.refresh(current_ext)
- end
- #--------------------------------------------------------------------------
- # * Set Cursor Position
- #--------------------------------------------------------------------------
- def index=(index)
- if @index != index
- # Mark Last Mail as read
- if @last_item && @last_item.is_a?(Mail_Data)
- @last_item.read!
- redraw_item(@index)
- @unread_method.call if @unread_method
- end
- end
- super(index)
- @last_item = current_ext
- end
- #--------------------------------------------------------------------------
- # * Make Command List
- #--------------------------------------------------------------------------
- def make_command_list
- for i in 0...$game_system.current_mails.size
- index = $game_system.current_mails.size - i - 1
- mail = $game_system.current_mails[index]
- add_command("Mail ##{index}", :ok, true, mail)
- end
- end
- #--------------------------------------------------------------------------
- # * Play OK Sound Effect
- # Added by dsiver144
- #--------------------------------------------------------------------------
- def play_ok_sound
- #Sound.play_ok
- end
- #--------------------------------------------------------------------------
- # * Draw Item
- #--------------------------------------------------------------------------
- def draw_item(index)
- mail_data = command_ext(index)
- change_color(normal_color, !mail_data.read)
- rect = item_rect_for_text(index)
- # Draw black bars
- if index % 2 == 0
- brect = rect.clone
- brect.y += 2
- brect.height -= 4
- contents.fill_rect(brect, Color.new(0,0,0,20))
- end
- id = sprintf("%2d.", index + 1)
- name = mail_data.title
- draw_text(rect, id, alignment)
- rect.x += 18
- icon_index = mail_data.read ? 353 : 352#mail_data.icon_index
- if icon_index
- draw_icon(icon_index, rect.x, rect.y)
- rect.x += 26
- end
- name += " *" if mail_data.has_reward?
- draw_text(rect, name, alignment)
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- super
- end
- end # Window_MailList
- class Window_MailInfo < Window_Base
- def refresh(mail_data)
- contents.clear
- cw = contents_width
- lh = line_height
- if mail_data.nil?
- draw_text(0,0,cw,contents_height,"- No data -",1)
- return
- end
- dx = 0
- dy = 0
- # Draw Mail Info
- contents.fill_rect(dx, dy + 1, cw, lh, Color.new(0,0,0,50))
- pos = draw_text_ex(dx + 3, dy + 3, "From: #{mail_data.author}")
- begin
- width = pos[:x] - dx
- face_bitmap = Cache.minimap_npc(mail_data.author)
- fx = dx + width + 4 # dx + cw - face_bitmap.width - 3
- contents.blt(fx, dy + 2, face_bitmap, face_bitmap.rect)
- rescue
- p "Couldn't find face for NPC = #{mail_data.author}"
- end
- dy += lh
- draw_text_ex(dx + 3, dy + 3, "Contents:")
- dy += lh
- contents.fill_rect(dx, dy + 1, cw, lh * 5, Color.new(0,0,0,50))
- draw_text_ex(dx + 3, dy, mail_data.contents)
- dy += lh * 5
- draw_text_ex(dx + 3, dy + 3, "Attachments:")
- dy += lh
- if mail_data.reward
- mail_data.reward.each_with_index do |str, i|
- item_id, number = str.split("x")
- next if item_id == 0
- # Handle Gold Display
- if str =~ /(\d+)G/i
- item_id = 240
- number = $1.to_i
- end
- ry = dy + i * lh
- contents.fill_rect(dx, ry, cw, lh, Color.new(0,0,0,50))
- draw_text_ex(dx + 3, ry + 3, "\\ii[#{item_id}]")
- draw_text(dx + 3, ry + 3, cw, lh, number, 2)
- dy += 2
- end
- else
- contents.fill_rect(dx, dy, cw, contents_height - dy, Color.new(0,0,0,50))
- draw_text(dx, dy, cw, contents_height - dy, "No Attachment", 1)
- end
- end
- def calc_line_height(text)
- return 16
- end
- #--------------------------------------------------------------------------
- # * Draw Text with Control Characters
- #--------------------------------------------------------------------------
- def draw_text_ex(x, y, text)
- reset_font_settings
- text = convert_escape_characters(text)
- pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
- process_character(text.slice!(0, 1), text, pos) until text.empty?
- return pos
- end
- end
- class Game_Event
- #--------------------------------------------------------------------------
- # * new method: refresh_mail_box_event
- # This will be called in Move Route Of Mailbox Event
- #--------------------------------------------------------------------------
- def refresh_mail_box_event
- if $game_system.total_unread_mails > 0
- @bubble_icon_index = 352
- @bubble_icon_settings = [0, 16]
- end
- end
- end
- class Game_System
- attr_accessor :current_mails
- #--------------------------------------------------------------------------
- # * Add Mail To Your Mail Box
- #--------------------------------------------------------------------------
- def add_to_mailbox(title, name, text, reward = nil, icon_index = nil)
- mail_data = Mail_Data.new(title, name, text, reward, icon_index)
- current_mails << mail_data
- return mail_data
- end
- #--------------------------------------------------------------------------
- # * Remove A Mail From Your Mail Box
- #--------------------------------------------------------------------------
- def delete_a_mail(mail_data)
- current_mails.delete(mail_data)
- end
- #--------------------------------------------------------------------------
- # * Get All Mail Datas
- #--------------------------------------------------------------------------
- def current_mails
- return @current_mails ||= []
- end
- #--------------------------------------------------------------------------
- # * new method: total_unread_mails
- # Get the number of unread mails
- #--------------------------------------------------------------------------
- def total_unread_mails
- return current_mails.select {|mail| mail.read == false}.size
- end
- #--------------------------------------------------------------------------
- # * Before Update Sleep
- #--------------------------------------------------------------------------
- alias_method(:dsi_mail_system_before_update_sleep, :before_update_sleep)
- def before_update_sleep
- dsi_mail_system_before_update_sleep
- update_mail_system_everyday
- end
- #--------------------------------------------------------------------------
- # * new method: update_mail_system_everyday
- #--------------------------------------------------------------------------
- def update_mail_system_everyday
- all_mails = current_mails.clone
- all_mails.each do |mail|
- mail.process_delete
- end
- all_mails.clear
- end
- end # Game_System
- class Mail_Data
- attr_accessor :author
- attr_accessor :reward
- attr_accessor :title
- attr_accessor :read
- attr_accessor :claimed_reward
- attr_accessor :icon_index
- attr_accessor :delete_mode
- attr_accessor :contents
- #--------------------------------------------------------------------------
- # * Initialize
- #--------------------------------------------------------------------------
- def initialize(title, name, text, reward = nil, icon_index = nil)
- @title = title
- @author = name
- @contents = text
- @reward = reward
- @icon_index = icon_index
- @read = false
- @claimed_reward = false
- @delete_mode = :none
- end
- #--------------------------------------------------------------------------
- # * new method: has_reward?
- #--------------------------------------------------------------------------
- def has_reward?
- return @reward && !@claimed_reward
- end
- #--------------------------------------------------------------------------
- # * new method: read!
- #--------------------------------------------------------------------------
- def read!
- @read = true
- end
- #--------------------------------------------------------------------------
- # * new method: process_delete
- #--------------------------------------------------------------------------
- def process_delete
- if @delete_mode == :request_reward && @claimed_reward
- $game_system.delete_a_mail(self)
- end
- if @delete_mode == :read && @read
- $game_system.delete_a_mail(self)
- end
- end
- #--------------------------------------------------------------------------
- # * Get Reward From Mail
- #--------------------------------------------------------------------------
- def get_reward!
- p "Get Reward #{@reward}"
- end
- end # Mail_Data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement