#===============================================================================
# Mail Box System
# Author game_guy
# Version 1.1
#-------------------------------------------------------------------------------
# Intro:
# Small mail-box system. Have npc's send your players mail. Then have your
# Player read it. Sorta like the pokemon cellphone system. Where trainers
# would call you for a rematch.
#
# Features:
# Completely Customizable
# -Customize Text
# -Customize Color
# -Customize Opacity
# Easy to setup mail
# Easy to get mail
# Check to see if a mail has been read
#
# Instructions:
# Go down to config. Configure the variables there.
# Everythings self explanatory down below.
# Colors are setup like this.
# Color.new(red, green, blue)
#
# Script Calls:
# Use
# $scene = Scene_Mail.new to go to mail box
# Use
# $game_party.add_mail(mail_id) to add a new mail
# Use
# $game_party.take_mail(mail_id) to delete a mail
# Use
# $game_party.mark_read(mail_id) to mark a message read
# To see if a message has been read, use the script call in
# a conditional branch.
# $game_party.mail_read?(mail_id)
#
# Compatibility:
# Not tested with SDK.
#
# Credits:
# game_guy ~ For making it
# Darth Spy ~ Requesting it
#===============================================================================
module GGMail
#===================================================
# Config
#===================================================
#--------------------
# Mail Bag - Name of your mail holder.
# Example: Mail Box :O
#--------------------
Mail_Word = "Mail Bag"
#--------------------
# Action_Message - Text to show
# how to mark messages read.
#--------------------
Action_Message = "Press Space to Mark as Read"
#--------------------
# From_Text - Text displayed
# with the sender of the mail
# Example: Sender:
#--------------------
From_Text = "From: "
#--------------------
# Title_Text - Text displayed
# with the title of the mail.
#--------------------
Title_Text = "Title: "
#--------------------
# Message_Text - Text displayed
# with the message of the mail.
#--------------------
Message_Text = "Message: "
#--------------------
# Label_Color - Color of
# From, Title, and Message text
#--------------------
Label_Color = Color.new(192, 224, 255, 255)
#--------------------
# New_Color - Color of new
# unread mail
#--------------------
New_Color = Color.new(255, 255, 64, 255)
#--------------------
# Read_Color - Color of
# old already read mail
#--------------------
Read_Color = Color.new(255, 255, 255)
#--------------------
# Mail - Ignore this line
#--------------------
Mail = []
#--------------------
# Opacity - The transparency
# of the windows in the layout
#--------------------
Opacity = 128
#--------------------
# Background - The background
# that displays in the mail
# scene.
# 0 = blank
# 1 = map
# "quoted string" = picture
#--------------------
Background = 1
#--------------------
# Return_Scene - Scene
# that it goes to when exiting
# the mail
#--------------------
Return_Scene = Scene_Map
#===================================================
# Configure Mail
#---------------------------------------------------
# Add a new line
# Mail[id of mail] = ["title", "sender", "message"]
Mail[1] = ["How goes it?", "Granny", "Hey sonny. Was wondering how you were doing. Be safe and don't die!"]
Mail[2] = ["Help!", "Hooker", "Help me! I was working my corner and I was kidnapped!"]
#===================================================
# End Config
#===================================================
end
class Game_Party
attr_accessor :mail
attr_accessor :mread
alias gg_init_mail_party_lat initialize
def initialize
@mail = []
@mread = []
gg_init_mail_party_lat
end
def add_mail(id)
msg = GGMail::Mail[id]
return if msg == nil
unless @mail.include?(id)
@mail.push(id)
@mread[id] = false
end
end
def take_mail(id)
msg = GGMail::Mail[id]
return if msg == nil
if @mail.include?(id)
@mail.delete(id)
end
end
def mark_read(id)
return if id == nil
msg = GGMail::Mail[id]
return if msg == nil
if @mail.include?(id)
@mread[id] = true
end
end
def mail_read?(id)
return if id == nil
msg = GGMail::Mail[id]
return if msg == nil
return @mread[id]
end
end
class Window_Mail_Help < Window_Base
def initialize
super(16, 16, 576, 96)
self.back_opacity = GGMail::Opacity
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
def refresh
self.contents.draw_text(0, 0, 576, 32, GGMail::Mail_Word, 1)
self.contents.draw_text(0, 32, 576, 32, GGMail::Action_Message, 1)
end
end
class Bitmap
def format_text(text, width)
words = text.split(' ')
return words if words.size == 1
result, current_text = [], words.shift
words.each_index {|i|
if self.text_size("#{current_text} #{words[i]}").width > width
result.push(current_text)
current_text = words[i]
else
current_text = "#{current_text} #{words[i]}"
end
result.push(current_text) if i >= words.size - 1}
return result
end
end
class Window_Mail_Message < Window_Base
def initialize
super(192 + 16, 96 + 16, 416 - 32, 388 - 32)
self.back_opacity = GGMail::Opacity
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
def refresh
return if @mail_id == nil
msg = GGMail::Mail[@mail_id]
return if msg == nil
self.contents.clear
w = self.contents.text_size("Title: ").width
w2 = self.contents.text_size("From: ").width
self.contents.font.color = system_color
self.contents.draw_text(0, 0, self.width, 32, "Title: ")
self.contents.draw_text(0, 48, self.width, 32, "From: ")
self.contents.draw_text(0, 96, self.width, 32, "Message: ")
self.contents.font.color = normal_color
self.contents.draw_text(w + 8, 0, self.width, 32, msg[0])
self.contents.draw_text(w2 + 8, 48, self.width, 32, msg[1])
draw_msg(msg[2], 0, 128)
end
def draw_msg(msg, x, y)
text = self.contents.format_text(msg, 392)
text.each_index {|i|
self.contents.draw_text(x, y + i*32, 544, 32, text[i])}
end
def set_mail(id)
return if @mail_id == id
@mail_id = id
refresh
end
end
class Scene_Mail
def main
create_background
@mail = $game_party.mail
@messages = []
@mail.each {|i|
@messages.push(GGMail::Mail[i][0])}
@messages = [""] if @messages.size < 1
@mail_window = Window_Command.new(192, @messages)
@mail_window.x = 16
@mail_window.back_opacity = GGMail::Opacity
@mail_window.height = 388 - 32
@mail_window.y = 96 + 16
j = 0
@mail.each{|i|
if $game_party.mread[i] == false
@mail_window.draw_item(j, GGMail::New_Color)
end
j += 1}
@mail_help = Window_Mail_Help.new
@mail_info = Window_Mail_Message.new
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
@mail_window.dispose
@mail_help.dispose
@mail_info.dispose
if @back != nil
@back.dispose
end
end
def create_background
n = GGMail::Background
if GGMail::Background.is_a?(Integer)
if n == 1
@back = Spriteset_Map.new
end
else
@back = Sprite.new
@back.bitmap = RPG::Cache.picture(n)
end
end
def refresh_command
@messages = []
@mail_window.dispose
@mail_window = nil
@mail.each {|i|
@messages.push(GGMail::Mail[i][0])}
@messages = [""] if @messages.size < 1
@mail_window = Window_Command.new(192, @messages)
@mail_window.x = 16
@mail_window.height = 388 - 32
@mail_window.y = 96 + 16
@mail_window.back_opacity = GGMail::Opacity
j = 0
@mail.each{|i|
if $game_party.mread[i] == false
@mail_window.draw_item(j, GGMail::New_Color)
end
j += 1}
end
def update
@mail_window.update
@mail_help.update
@mail_info.update
@mail_info.set_mail(@mail[@mail_window.index])
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = GGMail::Return_Scene.new
return
elsif Input.trigger?(Input::C)
$game_system.se_play($data_system.decision_se)
$game_party.mark_read(@mail[@mail_window.index])
refresh_command
return
end
end
end