eugene222

Mail System

Sep 24th, 2014
847
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.20 KB | None | 0 0
  1. #==============================================================================
  2. # ** Mail System **
  3. #
  4. # Author: Evgenij
  5. # Date: 30.09.2014
  6. # Version: 1.1b
  7. # ToF: evgenij-scripts.org
  8. #
  9. # Thanks to: MHRob for requesting this script
  10. #==============================================================================
  11. #
  12. # Changelog:
  13. # 30.09.2014 - V. 1.1b:
  14. # - bugfix
  15. # - new format for SENDER Configuration
  16. #
  17. # 28.09.2014 - V. 1.1a:
  18. # - bugfixes
  19. #
  20. # 25.09.2014 - V. 1.1:
  21. # - bugfixes
  22. # - added gold to attachments
  23. # - new feature: custom windowskin
  24. # - new feature: run common_event when reading mail
  25. # - new scriptcall: $game_system.attachments_claimed?(:symbol)
  26. #
  27. # 24.09.2014 - V. 1.0:
  28. # - script created
  29. #
  30. #==============================================================================
  31. #
  32. # Description:
  33. #
  34. # This script adds an email scene to your game, you need to predefine senders
  35. # and emails in the script and after that you can send them to the player via
  36. # a script call.
  37. #
  38. # Script Calls:
  39. #
  40. # SceneManager.call(Scene_Mail) # to call the scene
  41. #
  42. # $game_system.add_email(:symbol)
  43. # $game_system.remove_email(:symbol)
  44. # $game_system.has_email?(:symbol) # checks if player has email
  45. # $game_system.attachments_claimed?(:symbol) # checks if the attachments were
  46. # # claimed
  47. #
  48. #==============================================================================
  49. module EVG
  50. module MAIL
  51. #--------------------------------------------------------------------------
  52. # Some Escape Codes which can be used almost everywhere:
  53. # \n => new line
  54. # \\c[index] => change color (windowskin index)
  55. # \\b => toogle bold on or off
  56. # \\i[index] => show icon
  57. #--------------------------------------------------------------------------
  58.  
  59. #--------------------------------------------------------------------------
  60. # Cosmetic and Vocab Config:
  61. #--------------------------------------------------------------------------
  62. ALL_VOCAB = "ALL"
  63. UNREAD_VOCAB = "Unread"
  64. READ_VOCAB = "Read"
  65. DELETED_VOCAB = "Deleted"
  66.  
  67. ACTION_READ_VOCAB = "Read"
  68. ACTION_MARK_READ_VOCAB = "Mark read"
  69. ACTION_MARK_UNREAD_VOCAB = "Mark unread"
  70. ACTION_DELETE_VOCAB = "Delete"
  71. ACTION_GET_ATTACHMENTS_VOCAB = "Get Attach."
  72. # %s and %s get replaced by the sender name and the sender address
  73. HEADER_FROM_VOCAB = "\\b\\c[5]FROM\\c[0]: \\c[6]%s <%s>\\b"
  74. # %s gets replaced by the mail name
  75. HEADER_SUBJECT_VOCAB = "\\b\\c[5]SUBJECT\\c[0]: \\c[6]%s\\b"
  76. ATTACHMENTS_VOCAB = "\\b\\c[13]Attachments\\c[0]\\b"
  77. CLAIMED_VOCAB = "Claimed"
  78.  
  79. # Use windowskin colors only
  80. CLAIMED_COLOR = 25
  81. SENDER_COLOR = 2
  82.  
  83. ATTACHMENT_ICON = 258
  84. READ_ICON = 236
  85. UNREAD_ICON = 235
  86. NEW_MAIL_ICON = 235
  87. GOLD_ICON = 361
  88.  
  89. # You can use custom windowskin, put the file in Graphics/System
  90. # if the file dont exist, the window skin wont change, you also get no
  91. # error.
  92. WINDOWSKIN = "mailwindow"
  93. WINDOWTONE = Tone.new(0, 0, 0, 0)
  94.  
  95. #--------------------------------------------------------------------------
  96. # Settings:
  97. #--------------------------------------------------------------------------
  98. GET_ATTACHMENTS_WHEN_MARKREAD = true
  99. GET_ATTACHMENTS_WHEN_DELETE = true
  100. SHOW_DELETED_CATEGORY = true
  101. # If this switch will be on, no notification will be shown when the player
  102. # is on map and have unread emails
  103. NOTIFICATION_ON_MAP_OFF_SWITCH = 5
  104.  
  105. ADD_EMAIL_COMMMAND_TO_MENU = true
  106. COMMAND_VOCAB = "View Mails"
  107. COMMAND_SWITCH = 10 # For enabling or disabling the command in menu
  108.  
  109. #--------------------------------------------------------------------------
  110. # Configure possible senders:
  111. #--------------------------------------------------------------------------
  112. SENDERS = { # Do not edit this line
  113. #--------------------------------------------------------------------------
  114. :eric => {:name => "Eric", :address => "[email protected]"},
  115. :natalie => {:name => "Natalie", :address => "[email protected]"},
  116. :me => {:name => "Me, the king", :address => "[email protected]"},
  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 => { # the symbol has to be unique
  126. #
  127. # :sender => :eric, # take a sender from above SENDERS
  128. #
  129. # :name => "Email Name",
  130. #
  131. # :text => "Email Text", # You can use escape codes
  132. #
  133. # :attachments => [w1, i12, a13], # would give the player weapon 1, item 12
  134. # # and armor 13 as attachment.
  135. # # attachments are optional
  136. #
  137. # # Optional you can run common events when the player claims an attachment
  138. # # or reads the mail:
  139. #
  140. # :attach_ce => id, # only works when attachments are used
  141. # # starts the common event with id when
  142. # # attachments are claimed, also optional
  143. # :read_ce => id, # starts common event with id when email
  144. # gets read
  145. # },
  146. #--------------------------------------------------------------------------
  147.  
  148. :mail1 => {
  149. :sender => :eric,
  150. :name => "Hey whats up",
  151. :text => "Blab\\c[2]albab\\c[0]la",
  152. },
  153.  
  154. :mail2 => {
  155. :sender => :natalie,
  156. :name => "Welcome",
  157. :text => "Hello, \n"+
  158. "I want to welcome you in our guild. If you have questions\n"+
  159. "feel free to ask me or another member.\n\n"+
  160. "Best Regards!\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 = EVG::MAIL::SENDERS[properties[:sender]][:name]
  206. @address = EVG::MAIL::SENDERS[properties[:sender]][:address]
  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 && [email protected]?
  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 attachments_claimed?(symbol)
  327. @mails[symbol].attachments_claimed?
  328. end
  329. #--------------------------------------------------------------------------
  330. def has_email?(symbol)
  331. !!@mails[symbol]
  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 make_command_list
  630. add_command(ACTION_READ_VOCAB, :read)
  631. add_command(ACTION_MARK_READ_VOCAB, :mark_read, read?)
  632. add_command(ACTION_MARK_UNREAD_VOCAB, :mark_unread, mark_unread?)
  633. add_command(ACTION_GET_ATTACHMENTS_VOCAB, :claim_attach, claim_attach?)
  634. add_command(ACTION_DELETE_VOCAB, :delete, delete?)
  635. end
  636. #--------------------------------------------------------------------------
  637. def read?
  638. @selection_window.current_mail && @selection_window.current_mail.unread?
  639. end
  640. #--------------------------------------------------------------------------
  641. def mark_unread?
  642. @selection_window.current_mail && @selection_window.current_mail.read?
  643. end
  644. #--------------------------------------------------------------------------
  645. def claim_attach?
  646. @selection_window.current_mail && !@selection_window.current_mail.attachments_claimed?
  647. end
  648. #--------------------------------------------------------------------------
  649. def delete?
  650. @selection_window.current_mail && !@selection_window.current_mail.deleted?
  651. end
  652. #--------------------------------------------------------------------------
  653. def set_center
  654. self.x = (Graphics.width - window_width) / 2
  655. self.y = (Graphics.height - window_height) - 12
  656. end
  657. #--------------------------------------------------------------------------
  658. def open
  659. refresh
  660. select(0)
  661. super
  662. end
  663. #--------------------------------------------------------------------------
  664. end
  665. #==============================================================================
  666. class Window_MailMessage < Window_Selectable
  667. #--------------------------------------------------------------------------
  668. include EVG::MAIL
  669. #--------------------------------------------------------------------------
  670. attr_reader :mail
  671. #--------------------------------------------------------------------------
  672. def initialize
  673. super(window_x, window_y, window_width, window_height)
  674. self.openness = 0
  675. deactivate
  676. end
  677. #--------------------------------------------------------------------------
  678. def window_x
  679. (Graphics.width - window_width) / 2
  680. end
  681. #--------------------------------------------------------------------------
  682. def window_y
  683. (Graphics.height - window_height) / 2
  684. end
  685. #--------------------------------------------------------------------------
  686. def window_width
  687. Graphics.width - 24
  688. end
  689. #--------------------------------------------------------------------------
  690. def window_height
  691. ((Graphics.height - 24) / 24) * 24
  692. end
  693. #--------------------------------------------------------------------------
  694. def mail=(mail)
  695. @mail = mail
  696. refresh
  697. end
  698. #--------------------------------------------------------------------------
  699. def reset_font_settings
  700. super
  701. contents.font.size = 20
  702. end
  703. #--------------------------------------------------------------------------
  704. def refresh
  705. contents.clear
  706. select(-1)
  707. draw_header
  708. draw_text_ex(4, 48, mail.text)
  709. draw_attachments(contents.height - line_height * 2) if mail.attachments?
  710. end
  711. #--------------------------------------------------------------------------
  712. def draw_header_frame(y, height = 22)
  713. contents.fill_rect(0, y, contents.width, height, Color.new(0,0,0,255))
  714. contents.clear_rect(1, y + 1, contents.width - 2, height - 2)
  715. end
  716. #--------------------------------------------------------------------------
  717. def draw_header
  718. draw_header_frame(0)
  719. draw_header_frame(24)
  720. draw_text_ex(4, 0, sprintf(HEADER_FROM_VOCAB, mail.sender, mail.address))
  721. draw_text_ex(4, 24, sprintf(HEADER_SUBJECT_VOCAB, mail.name) )
  722. end
  723. #--------------------------------------------------------------------------
  724. def draw_attachments(y)
  725. draw_header_frame(y, line_height * 2 - 2)
  726. draw_text_ex(4, y - line_height * 0.5, ATTACHMENTS_VOCAB)
  727. if !mail.attachments_claimed?
  728. select(0)
  729. draw_text(item_rect_for_text(0), ACTION_GET_ATTACHMENTS_VOCAB, 1)
  730. draw_text_ex(4, y + line_height * 0.5, attachment_text)
  731. else
  732. change_color(text_color(EVG::MAIL::CLAIMED_COLOR))
  733. contents.font.bold = true
  734. draw_text(4, y + line_height * 0.5, contents.width - 8, line_height, CLAIMED_VOCAB, 1)
  735. #draw_text(item_rect_for_text(0), "Claimed!", 2)
  736. change_color(normal_color)
  737. #contents.fill_rect(3, y + line_height, contents.width - 6, 1, Color.new(0, 0, 0, 255))
  738. end
  739. end
  740. #--------------------------------------------------------------------------
  741. def draw_text_ex(x, y, text)
  742. reset_font_settings
  743. text = convert_escape_characters(text)
  744. pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
  745. process_character(text.slice!(0, 1), text, pos) until text.empty?
  746. end
  747. #--------------------------------------------------------------------------
  748. def process_escape_character(code, text, pos)
  749. case code.upcase
  750. when 'B'
  751. contents.font.bold = !contents.font.bold
  752. else
  753. super
  754. end
  755. end
  756. #--------------------------------------------------------------------------
  757. def attachment_text
  758. mail.attachments.inject("") {|res, attach| "#{item_name(attach)} #{res}"}
  759. end
  760. #--------------------------------------------------------------------------
  761. def item_name(code)
  762. item = EVG::AttachmentManager.get_item(code)
  763. return "Invalid itemcode" if item.nil?
  764. if item.is_a?(Fixnum)
  765. return "\\i[#{GOLD_ICON}]#{item}"
  766. else
  767. return "\\i[#{item.icon_index}]#{item.name}"
  768. end
  769.  
  770. end
  771. #--------------------------------------------------------------------------
  772. def item_rect(index)
  773. rect = Rect.new
  774. rect.width = 128
  775. rect.height = line_height
  776. rect.x = contents.width - 128 - 4
  777. rect.y = contents.height - line_height * 2.5
  778. rect
  779. end
  780. #--------------------------------------------------------------------------
  781. def ok_enabled?
  782. handle?(:ok) && @index == 0 && mail.attachments && !mail.attachments_claimed?
  783. end
  784. #--------------------------------------------------------------------------
  785. end
  786. #==============================================================================
  787. class Window_MailReward < Window_Base
  788. #--------------------------------------------------------------------------
  789. include EVG::MAIL
  790. #--------------------------------------------------------------------------
  791. def initialize
  792. super(0,0,196,0)
  793. @counter = 0
  794. self.openness = 0
  795. end
  796. #--------------------------------------------------------------------------
  797. def start(attachments)
  798. @attachments = attachments
  799. refresh
  800. open
  801. @counter = 60
  802. end
  803. #--------------------------------------------------------------------------
  804. def update
  805. super
  806. if busy?
  807. @counter -= 1
  808. end
  809. if @counter == 0 && open?
  810. close
  811. end
  812. end
  813. #--------------------------------------------------------------------------
  814. def busy?
  815. @counter > 0
  816. end
  817. #--------------------------------------------------------------------------
  818. def refresh
  819. recreate_window(fitting_height(@attachments.size + 1))
  820. draw_text(0, 0, contents.width, line_height, "#{CLAIMED_VOCAB}:")
  821. @attachments.each_with_index do |code, i|
  822. y = line_height * (i+1)
  823. item = EVG::AttachmentManager.get_item(code)
  824. if item.is_a?(Fixnum)
  825. draw_gold(item, 0, y)
  826. else
  827. draw_item_name(item, 0, y)
  828. end
  829. end
  830. end
  831.  
  832. def draw_gold(number, x, y)
  833. draw_icon(GOLD_ICON, x, y)
  834. draw_text(x + 26, y, contents.width - 26, line_height, number)
  835. end
  836. #--------------------------------------------------------------------------
  837. def recreate_window(height)
  838. self.height = height
  839. self.x = (Graphics.width - self.width) / 2
  840. self.y = (Graphics.height - self.height) / 2
  841. create_contents
  842. end
  843. #--------------------------------------------------------------------------
  844. end
  845. #==============================================================================
  846. class Scene_Mail < Scene_MenuBase
  847. #--------------------------------------------------------------------------
  848. def start
  849. super
  850. create_selection_window
  851. create_category_window
  852. create_confirm_window
  853. create_mail_window
  854. create_reward_window
  855. create_interpreter
  856. end
  857. #--------------------------------------------------------------------------
  858. def create_selection_window
  859. @selection_window = Window_MailSelection.new
  860. @selection_window.set_handler(:ok, method(:on_selection_ok))
  861. @selection_window.set_handler(:cancel, method(:on_selection_cancel))
  862. end
  863. #--------------------------------------------------------------------------
  864. def create_category_window
  865. @category_window = Window_MailCategory.new(@selection_window)
  866. @category_window.set_handler(:ok, method(:on_category_ok))
  867. @category_window.set_handler(:cancel, method(:return_scene))
  868. end
  869. #--------------------------------------------------------------------------
  870. def create_confirm_window
  871. @confirm_window = Window_MailConfirm.new(@selection_window)
  872. @confirm_window.set_handler(:read, method(:read_mail))
  873. @confirm_window.set_handler(:mark_read, method(:mark_mail_read))
  874. @confirm_window.set_handler(:mark_unread, method(:mark_mail_unread))
  875. @confirm_window.set_handler(:claim_attach, method(:claim_mail_attach))
  876. @confirm_window.set_handler(:delete, method(:delete_mail))
  877. @confirm_window.set_handler(:cancel, method(:on_confirm_cancel))
  878. end
  879. #--------------------------------------------------------------------------
  880. def create_mail_window
  881. @mail_window = Window_MailMessage.new
  882. @mail_window.set_handler(:cancel, method(:on_mail_cancel))
  883. @mail_window.set_handler(:ok, method(:on_mail_ok))
  884. end
  885. #--------------------------------------------------------------------------
  886. def create_reward_window
  887. @reward_window = Window_MailReward.new
  888. end
  889. #--------------------------------------------------------------------------
  890. def on_category_ok
  891. @category_window.deactivate
  892. @selection_window.activate
  893. @selection_window.select(0)
  894. end
  895. #--------------------------------------------------------------------------
  896. def on_selection_ok
  897. @selection_window.deactivate
  898. @confirm_window.refresh
  899. @confirm_window.open
  900. @confirm_window.activate
  901. end
  902. #--------------------------------------------------------------------------
  903. def on_selection_cancel
  904. @selection_window.deactivate
  905. @category_window.activate
  906. @selection_window.unselect
  907. end
  908. #--------------------------------------------------------------------------
  909. def read_mail
  910. @confirm_window.close
  911. @confirm_window.deactivate
  912. @category_window.close
  913. @selection_window.close
  914. @mail_window.mail = current_mail
  915. @mail_window.activate
  916. @mail_window.open
  917. end
  918. #--------------------------------------------------------------------------
  919. def mark_mail_read
  920. current_mail.read
  921. if EVG::MAIL::GET_ATTACHMENTS_WHEN_MARKREAD
  922. get_attachments
  923. end
  924. on_confirm_cancel
  925. run_read_common_event
  926. @selection_window.refresh
  927. end
  928. #--------------------------------------------------------------------------
  929. def mark_mail_unread
  930. current_mail.unread
  931. @selection_window.refresh
  932. on_confirm_cancel
  933. end
  934. #--------------------------------------------------------------------------
  935. def claim_mail_attach
  936. get_attachments
  937. @selection_window.refresh
  938. on_confirm_cancel
  939. end
  940. #--------------------------------------------------------------------------
  941. def get_attachments
  942. if !current_mail.attachments_claimed?
  943. current_mail.claim_attachments
  944. current_mail.attachments.each do |code|
  945. item = EVG::AttachmentManager.get_item(code)
  946. if item.is_a?(Fixnum)
  947. $game_party.gain_gold(item)
  948. else
  949. $game_party.gain_item(item, 1)
  950. end
  951. end
  952. @reward_window.start(current_mail.attachments)
  953. if current_mail.attach_common_event?
  954. run_common_event(current_mail.common_event_attach)
  955. end
  956. end
  957. end
  958. #--------------------------------------------------------------------------
  959. def run_read_common_event
  960. if !current_mail.read_common_event_ran? && current_mail.read_common_event?
  961. run_common_event(current_mail.common_event_read)
  962. current_mail.read_ce = true
  963. end
  964. end
  965. #--------------------------------------------------------------------------
  966. def delete_mail
  967. current_mail.delete
  968. if EVG::MAIL::GET_ATTACHMENTS_WHEN_DELETE
  969. get_attachments
  970. end
  971. @selection_window.refresh
  972. on_confirm_cancel
  973. end
  974. #--------------------------------------------------------------------------
  975. def on_confirm_cancel
  976. @confirm_window.close
  977. @confirm_window.deactivate
  978. @selection_window.activate
  979. end
  980. #--------------------------------------------------------------------------
  981. def on_mail_ok
  982. get_attachments
  983. @mail_window.refresh
  984. @mail_window.activate
  985. end
  986. #--------------------------------------------------------------------------
  987. def on_mail_cancel
  988. current_mail.read
  989. run_read_common_event
  990. @mail_window.close
  991. @mail_window.deactivate
  992. @selection_window.refresh
  993. @selection_window.activate
  994. @selection_window.open
  995. @category_window.open
  996. end
  997. #--------------------------------------------------------------------------
  998. def current_mail
  999. $game_system.mails[@selection_window.current_symbol]
  1000. end
  1001. #--------------------------------------------------------------------------
  1002. def create_interpreter
  1003. @interpreter = Game_Interpreter.new
  1004. end
  1005. #--------------------------------------------------------------------------
  1006. def run_common_event(event_id)
  1007. $game_temp.reserve_common_event(event_id)
  1008. @interpreter.setup_reserved_common_event
  1009. update_interpreter while @interpreter.running?
  1010. end
  1011. #--------------------------------------------------------------------------
  1012. def update_interpreter
  1013. update_basic
  1014. @interpreter.update
  1015. end
  1016. #--------------------------------------------------------------------------
  1017. def update_basic
  1018. Graphics.update
  1019. Input.update
  1020. @reward_window.update if @reward_window.busy?
  1021. update_all_windows unless @reward_window.busy?
  1022. end
  1023. #--------------------------------------------------------------------------
  1024. end
  1025. #==============================================================================
  1026. class Scene_Menu
  1027. #--------------------------------------------------------------------------
  1028. alias :evg_sm_ccw_mail :create_command_window
  1029. def create_command_window
  1030. evg_sm_ccw_mail
  1031. @command_window.set_handler(:evg_mail, method(:command_evg_mail))
  1032. end
  1033. #--------------------------------------------------------------------------
  1034. def command_evg_mail
  1035. SceneManager.call(Scene_Mail)
  1036. end
  1037. #--------------------------------------------------------------------------
  1038. end
  1039. #==============================================================================
  1040. class Window_MenuCommand
  1041. #--------------------------------------------------------------------------
  1042. alias :evg_wmc_aoc_mail :add_original_commands
  1043. def add_original_commands
  1044. evg_wmc_aoc_mail
  1045. return unless EVG::MAIL::ADD_EMAIL_COMMMAND_TO_MENU
  1046. add_command(EVG::MAIL::COMMAND_VOCAB, :evg_mail, evg_mail_command_enabled?)
  1047. end
  1048. #--------------------------------------------------------------------------
  1049. def evg_mail_command_enabled?
  1050. return $game_switches[EVG::MAIL::COMMAND_SWITCH]
  1051. end
  1052. #--------------------------------------------------------------------------
  1053. end
  1054. #==============================================================================
  1055. # SCRIPT END
  1056. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment