Advertisement
DarkSoul144

Untitled

Oct 11th, 2019
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.85 KB | None | 0 0
  1.  
  2. module Mail_Core
  3.  
  4. end
  5.  
  6. class Scene_MailBox < Scene_MenuBase
  7. #--------------------------------------------------------------------------
  8. # * Create Background
  9. #--------------------------------------------------------------------------
  10. def create_background
  11. @background_sprite = Plane.new
  12. @background_sprite.bitmap = Cache.system("BGLoop3")
  13. end
  14. #--------------------------------------------------------------------------
  15. # * Start Processing
  16. #--------------------------------------------------------------------------
  17. def start
  18. super
  19. @mail_list_window = Window_MailList.new(0, 0)
  20. @mail_list_window.x = (Graphics.width - @mail_list_window.width) / 2
  21. @mail_list_window.y = (real_height - @mail_list_window.height) / 2
  22. @mail_list_window.unread_method = method(:refresh_unread_window)
  23. @mail_list_window.set_handler(:cancel, method(:return_scene))
  24. # Unread Window
  25. ww = @mail_list_window.width
  26. wh = @mail_list_window.fitting_height(1)
  27. wx = @mail_list_window.x
  28. wy = @mail_list_window.y + @mail_list_window.height + 12
  29. @unread_window = Window_Base.new(wx,wy,ww,wh)
  30. # Info Window
  31. ww = @mail_list_window.width + 100
  32. wh = @mail_list_window.height + @unread_window.height + 12
  33. wx = @mail_list_window.x + 12
  34. wy = @mail_list_window.y + 12
  35. @mail_info_window = Window_MailInfo.new(wx,wy,ww,wh)
  36. @mail_list_window.help_window = @mail_info_window
  37. # Relocate Windows
  38. total_width = @mail_list_window.width + 12 + @mail_info_window.width
  39. @mail_list_window.x = (Graphics.width - total_width) / 2
  40. @mail_info_window.x = @mail_list_window.x + @mail_list_window.width + 12
  41. @mail_info_window.y = @mail_list_window.y
  42. @unread_window.x = @mail_list_window.x
  43. #@unread_window.y = @mail_list_window.y + 12
  44. refresh_unread_window
  45. end
  46. #--------------------------------------------------------------------------
  47. # * Refresh Unread Window
  48. #--------------------------------------------------------------------------
  49. def refresh_unread_window
  50. unread_nums = $game_system.total_unread_mails()
  51. @unread_window.contents.clear
  52. cw = @unread_window.contents_width
  53. @unread_window.draw_text_ex(0,0,"\\c[5]#{unread_nums}\\c[0] Unread Mail(s)")
  54. end
  55. #--------------------------------------------------------------------------
  56. # * Update Processing
  57. #--------------------------------------------------------------------------
  58. def update
  59. super
  60. @background_sprite.ox += 1
  61. @background_sprite.oy += 1
  62. end
  63. #--------------------------------------------------------------------------
  64. # * Terminate Processing
  65. #--------------------------------------------------------------------------
  66. def terminate
  67. super
  68.  
  69. end
  70.  
  71. end # Scene_MailBox
  72.  
  73. class Window_MailList < Window_Command
  74. attr_accessor :unread_method
  75. #--------------------------------------------------------------------------
  76. # * Window Width
  77. #--------------------------------------------------------------------------
  78. def window_width
  79. return 260
  80. end
  81. #--------------------------------------------------------------------------
  82. # * Window Height
  83. #--------------------------------------------------------------------------
  84. def window_height
  85. return fitting_height(10)
  86. end
  87. #--------------------------------------------------------------------------
  88. # * Update Help Window
  89. #--------------------------------------------------------------------------
  90. def update_help
  91. @help_window.refresh(current_ext)
  92. end
  93. #--------------------------------------------------------------------------
  94. # * Set Cursor Position
  95. #--------------------------------------------------------------------------
  96. def index=(index)
  97. if @index != index
  98. # Mark Last Mail as read
  99. if @last_item && @last_item.is_a?(Mail_Data)
  100. @last_item.read!
  101. redraw_item(@index)
  102. @unread_method.call if @unread_method
  103. end
  104. end
  105. super(index)
  106. @last_item = current_ext
  107. end
  108. #--------------------------------------------------------------------------
  109. # * Make Command List
  110. #--------------------------------------------------------------------------
  111. def make_command_list
  112. for i in 0...$game_system.current_mails.size
  113. index = $game_system.current_mails.size - i - 1
  114. mail = $game_system.current_mails[index]
  115. add_command("Mail ##{index}", :ok, true, mail)
  116. end
  117. end
  118. #--------------------------------------------------------------------------
  119. # * Play OK Sound Effect
  120. # Added by dsiver144
  121. #--------------------------------------------------------------------------
  122. def play_ok_sound
  123. #Sound.play_ok
  124. end
  125. #--------------------------------------------------------------------------
  126. # * Draw Item
  127. #--------------------------------------------------------------------------
  128. def draw_item(index)
  129. mail_data = command_ext(index)
  130. change_color(normal_color, !mail_data.read)
  131. rect = item_rect_for_text(index)
  132. # Draw black bars
  133. if index % 2 == 0
  134. brect = rect.clone
  135. brect.y += 2
  136. brect.height -= 4
  137. contents.fill_rect(brect, Color.new(0,0,0,20))
  138. end
  139. id = sprintf("%2d.", index + 1)
  140. name = mail_data.title
  141. draw_text(rect, id, alignment)
  142. rect.x += 18
  143. icon_index = mail_data.read ? 353 : 352#mail_data.icon_index
  144. if icon_index
  145. draw_icon(icon_index, rect.x, rect.y)
  146. rect.x += 26
  147. end
  148. name += " *" if mail_data.has_reward?
  149. draw_text(rect, name, alignment)
  150. end
  151. #--------------------------------------------------------------------------
  152. # * Refresh
  153. #--------------------------------------------------------------------------
  154. def refresh
  155. super
  156. end
  157. end # Window_MailList
  158.  
  159. class Window_MailInfo < Window_Base
  160.  
  161. def refresh(mail_data)
  162. contents.clear
  163. cw = contents_width
  164. lh = line_height
  165. if mail_data.nil?
  166. draw_text(0,0,cw,contents_height,"- No data -",1)
  167. return
  168. end
  169. dx = 0
  170. dy = 0
  171. # Draw Mail Info
  172. contents.fill_rect(dx, dy + 1, cw, lh, Color.new(0,0,0,50))
  173. pos = draw_text_ex(dx + 3, dy + 3, "From: #{mail_data.author}")
  174.  
  175. begin
  176. width = pos[:x] - dx
  177. face_bitmap = Cache.minimap_npc(mail_data.author)
  178. fx = dx + width + 4 # dx + cw - face_bitmap.width - 3
  179. contents.blt(fx, dy + 2, face_bitmap, face_bitmap.rect)
  180. rescue
  181. p "Couldn't find face for NPC = #{mail_data.author}"
  182. end
  183. dy += lh
  184. draw_text_ex(dx + 3, dy + 3, "Contents:")
  185. dy += lh
  186. contents.fill_rect(dx, dy + 1, cw, lh * 5, Color.new(0,0,0,50))
  187. draw_text_ex(dx + 3, dy, mail_data.contents)
  188. dy += lh * 5
  189. draw_text_ex(dx + 3, dy + 3, "Attachments:")
  190. dy += lh
  191. if mail_data.reward
  192. mail_data.reward.each_with_index do |str, i|
  193. item_id, number = str.split("x")
  194. next if item_id == 0
  195. # Handle Gold Display
  196. if str =~ /(\d+)G/i
  197. item_id = 240
  198. number = $1.to_i
  199. end
  200. ry = dy + i * lh
  201. contents.fill_rect(dx, ry, cw, lh, Color.new(0,0,0,50))
  202. draw_text_ex(dx + 3, ry + 3, "\\ii[#{item_id}]")
  203. draw_text(dx + 3, ry + 3, cw, lh, number, 2)
  204. dy += 2
  205. end
  206. else
  207. contents.fill_rect(dx, dy, cw, contents_height - dy, Color.new(0,0,0,50))
  208. draw_text(dx, dy, cw, contents_height - dy, "No Attachment", 1)
  209. end
  210. end
  211.  
  212. def calc_line_height(text)
  213. return 16
  214. end
  215.  
  216. #--------------------------------------------------------------------------
  217. # * Draw Text with Control Characters
  218. #--------------------------------------------------------------------------
  219. def draw_text_ex(x, y, text)
  220. reset_font_settings
  221. text = convert_escape_characters(text)
  222. pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
  223. process_character(text.slice!(0, 1), text, pos) until text.empty?
  224. return pos
  225. end
  226.  
  227. end
  228.  
  229. class Game_Event
  230. #--------------------------------------------------------------------------
  231. # * new method: refresh_mail_box_event
  232. # This will be called in Move Route Of Mailbox Event
  233. #--------------------------------------------------------------------------
  234. def refresh_mail_box_event
  235. if $game_system.total_unread_mails > 0
  236. @bubble_icon_index = 352
  237. @bubble_icon_settings = [0, 16]
  238. end
  239. end
  240.  
  241. end
  242.  
  243. class Game_System
  244. attr_accessor :current_mails
  245. #--------------------------------------------------------------------------
  246. # * Add Mail To Your Mail Box
  247. #--------------------------------------------------------------------------
  248. def add_to_mailbox(title, name, text, reward = nil, icon_index = nil)
  249. mail_data = Mail_Data.new(title, name, text, reward, icon_index)
  250. current_mails << mail_data
  251. return mail_data
  252. end
  253. #--------------------------------------------------------------------------
  254. # * Remove A Mail From Your Mail Box
  255. #--------------------------------------------------------------------------
  256. def delete_a_mail(mail_data)
  257. current_mails.delete(mail_data)
  258. end
  259. #--------------------------------------------------------------------------
  260. # * Get All Mail Datas
  261. #--------------------------------------------------------------------------
  262. def current_mails
  263. return @current_mails ||= []
  264. end
  265. #--------------------------------------------------------------------------
  266. # * new method: total_unread_mails
  267. # Get the number of unread mails
  268. #--------------------------------------------------------------------------
  269. def total_unread_mails
  270. return current_mails.select {|mail| mail.read == false}.size
  271. end
  272. #--------------------------------------------------------------------------
  273. # * Before Update Sleep
  274. #--------------------------------------------------------------------------
  275. alias_method(:dsi_mail_system_before_update_sleep, :before_update_sleep)
  276. def before_update_sleep
  277. dsi_mail_system_before_update_sleep
  278. update_mail_system_everyday
  279. end
  280. #--------------------------------------------------------------------------
  281. # * new method: update_mail_system_everyday
  282. #--------------------------------------------------------------------------
  283. def update_mail_system_everyday
  284. all_mails = current_mails.clone
  285. all_mails.each do |mail|
  286. mail.process_delete
  287. end
  288. all_mails.clear
  289. end
  290.  
  291. end # Game_System
  292.  
  293. class Mail_Data
  294. attr_accessor :author
  295. attr_accessor :reward
  296. attr_accessor :title
  297. attr_accessor :read
  298. attr_accessor :claimed_reward
  299. attr_accessor :icon_index
  300. attr_accessor :delete_mode
  301. attr_accessor :contents
  302. #--------------------------------------------------------------------------
  303. # * Initialize
  304. #--------------------------------------------------------------------------
  305. def initialize(title, name, text, reward = nil, icon_index = nil)
  306. @title = title
  307. @author = name
  308. @contents = text
  309. @reward = reward
  310. @icon_index = icon_index
  311. @read = false
  312. @claimed_reward = false
  313. @delete_mode = :none
  314. end
  315. #--------------------------------------------------------------------------
  316. # * new method: has_reward?
  317. #--------------------------------------------------------------------------
  318. def has_reward?
  319. return @reward && !@claimed_reward
  320. end
  321. #--------------------------------------------------------------------------
  322. # * new method: read!
  323. #--------------------------------------------------------------------------
  324. def read!
  325. @read = true
  326. end
  327. #--------------------------------------------------------------------------
  328. # * new method: process_delete
  329. #--------------------------------------------------------------------------
  330. def process_delete
  331. if @delete_mode == :request_reward && @claimed_reward
  332. $game_system.delete_a_mail(self)
  333. end
  334. if @delete_mode == :read && @read
  335. $game_system.delete_a_mail(self)
  336. end
  337. end
  338. #--------------------------------------------------------------------------
  339. # * Get Reward From Mail
  340. #--------------------------------------------------------------------------
  341. def get_reward!
  342. p "Get Reward #{@reward}"
  343. end
  344. end # Mail_Data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement