Advertisement
roninator2

Notes and Letters

Dec 4th, 2024
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 22.77 KB | None | 0 0
  1. # ╔═══════════════════════════════════════════════╦════════════════════╗
  2. # ║ Title: Notes and Letters                      ║  Version: 1.04     ║
  3. # ║ Author: Roninator2                            ║                    ║
  4. # ╠═══════════════════════════════════════════════╬════════════════════╣
  5. # ║ Function:                                     ║   Date Created     ║
  6. # ║                                               ╠════════════════════╣
  7. # ║   Display a scene for notes and clues         ║    17 Jun 2024     ║
  8. # ╚═══════════════════════════════════════════════╩════════════════════╝
  9. # ╔════════════════════════════════════════════════════════════════════╗
  10. # ║ Requires: nil                                                      ║
  11. # ║                                                                    ║
  12. # ╚════════════════════════════════════════════════════════════════════╝
  13. # ╔════════════════════════════════════════════════════════════════════╗
  14. # ║ Brief Description:                                                 ║
  15. # ║      A new scene to show information from notes and letters        ║
  16. # ╚════════════════════════════════════════════════════════════════════╝
  17. # ╔════════════════════════════════════════════════════════════════════╗
  18. # ║ Instructions:                                                      ║
  19. # ║   Use note tag in note box to make the item a Note or Letter       ║
  20. # ║       <nal>                                                        ║
  21. # ║  Use note tag to specify the image that will be shown for the item ║
  22. # ║       <nal image: Image>                                           ║
  23. # ║  Call scene with SceneManager.call(Scene_NAL)                      ║
  24. # ║                                                                    ║
  25. # ║  Images go in the pictures folder                                  ║
  26. # ╚════════════════════════════════════════════════════════════════════╝
  27. # ╔════════════════════════════════════════════════════════════════════╗
  28. # ║ Updates:                                                           ║
  29. # ║ 1.00 - 17 Jun 2024 - Script finished                               ║
  30. # ║ 1.01 - 19 Jun 2024 - Make text full screen                         ║
  31. # ║ 1.02 - 21 Jun 2024 - Make requested adjustments                    ║
  32. # ║ 1.03 - 21 Jun 2024 - Added Sound and menu option                   ║
  33. # ║ 1.04 - 13 Jul 2024 - Converted to save data                        ║
  34. # ╚════════════════════════════════════════════════════════════════════╝
  35. # ╔════════════════════════════════════════════════════════════════════╗
  36. # ║ Credits and Thanks:                                                ║
  37. # ║   Roninator2                                                       ║
  38. # ║                                                                    ║
  39. # ╚════════════════════════════════════════════════════════════════════╝
  40. # ╔════════════════════════════════════════════════════════════════════╗
  41. # ║ Terms of use:                                                      ║
  42. # ║  Follow the original Authors terms of use where applicable         ║
  43. # ║    - When not made by me (Roninator2)                              ║
  44. # ║  Free for all uses in RPG Maker except nudity                      ║
  45. # ║  Anyone using this script in their project before these terms      ║
  46. # ║  were changed are allowed to use this script even if it conflicts  ║
  47. # ║  with these new terms. New terms effective 03 Apr 2024             ║
  48. # ║  No part of this code can be used with AI programs or tools        ║
  49. # ║  Credit must be given                                              ║
  50. # ╚════════════════════════════════════════════════════════════════════╝
  51.  
  52. module R2_NAL
  53.   # title text
  54.   TITLE = "Scene to view all Notes and Letters"
  55.   # set font settings
  56.   NAL_FONT = "VL Gothic"
  57.   NAL_FONT_SIZE = 24
  58.   NAL_FONT_BOLD = false
  59.   NAL_FONT_ITALIC = false
  60.   # text to show for returning
  61.   RETURN_TEXT = "\\I[19] Cancel"
  62.   # Variable to save data
  63.   NAL_VAR = 12
  64.   # NAL Text
  65.   NAL_TEXT = { # place the item text here
  66.             # Item ID => ["Item text line1", Item text line 2", ...]
  67.               17 => ["Put your text here. new lines",
  68.                       "go like this in the quotes",], # comma at the end
  69.   # carefull how much is placed in the line. too much and it will get cut off
  70.               18 => ["This is a basic item",
  71. "If your line is long you can move it back like this.",
  72. "Just so you can see it when you type it out.",
  73. "But the second line is the max length at 544 pixels.",],
  74.           # add more as needed
  75.  
  76.             } # do not touch
  77.   # Icon shown for when items have not been read
  78.   READ_ICON = 41
  79.   # open page sound
  80.   PAGE_READ = "Book2"
  81.   # Use the menu option
  82.   SHOW_IN_MENU = true
  83.   # Menu Command Text
  84.   MENU_COMMAND = "Notes Found"
  85. end
  86.  
  87. # ╔════════════════════════════════════════════════════════════════════╗
  88. # ║                      End of editable region                        ║
  89. # ╚════════════════════════════════════════════════════════════════════╝
  90.  
  91. module R2_NAL
  92.   # regex to match in item note box
  93.   NAL = /<nal>/i
  94.   NAL_IMAGE = /<nal image: (\w+(?:[, ]*\w*)*)>/i
  95. end
  96.  
  97. #==============================================================================
  98. # ■ DataManager
  99. #==============================================================================
  100.  
  101. module DataManager
  102.  
  103.   #--------------------------------------------------------------------------
  104.   # alias method: load_database
  105.   #--------------------------------------------------------------------------
  106.   class <<self; alias load_objects_nal create_game_objects; end
  107.   def self.create_game_objects
  108.     load_objects_nal
  109.     $game_variables[R2_NAL::NAL_VAR] = {}
  110.     load_notetags_nal
  111.   end
  112.  
  113.   #--------------------------------------------------------------------------
  114.   # load_notetags_nal
  115.   #--------------------------------------------------------------------------
  116.   def self.load_notetags_nal
  117.     for obj in $data_items
  118.       next if obj.nil?
  119.       obj.load_notetags_nal
  120.     end
  121.   end
  122.  
  123. end
  124.  
  125. #==============================================================================
  126. # ■ RPG::Item
  127. #==============================================================================
  128.  
  129. class RPG::Item
  130.  
  131.   #--------------------------------------------------------------------------
  132.   # load_notetags_nal
  133.   #--------------------------------------------------------------------------
  134.   def load_notetags_nal
  135.     nal = false
  136.     nal_image = ""
  137.     self.note.split(/[\r\n]+/).each { |line|
  138.       case line
  139.       when R2_NAL::NAL
  140.         nal = true
  141.       when R2_NAL::NAL_IMAGE
  142.         nal_image = $1.to_s
  143.       end
  144.     }
  145.     $game_variables[R2_NAL::NAL_VAR][self.id] = [nal, nal_image, false]
  146.   end
  147.  
  148. end
  149.  
  150. #==============================================================================
  151. # ■ Scene_Menu
  152. #==============================================================================
  153.  
  154. class Scene_Menu < Scene_MenuBase
  155.   alias r2_command_menu_nal_scene   create_command_window
  156.   #--------------------------------------------------------------------------
  157.   # * Create Command Window
  158.   #--------------------------------------------------------------------------
  159.   def create_command_window
  160.     r2_command_menu_nal_scene
  161.     @command_window.set_handler(:nal, method(:command_nal)) if R2_NAL::SHOW_IN_MENU
  162.   end
  163.   #--------------------------------------------------------------------------
  164.   # * [NAL] Command
  165.   #--------------------------------------------------------------------------
  166.   def command_nal
  167.     SceneManager.call(Scene_NAL)
  168.   end
  169. end
  170.  
  171. #==============================================================================
  172. # ■ Window_MenuCommand
  173. #==============================================================================
  174.  
  175. class Window_MenuCommand < Window_Command
  176.   alias r2_original_command_scene_nal   add_original_commands
  177.   #--------------------------------------------------------------------------
  178.   # * For Adding Original Commands
  179.   #--------------------------------------------------------------------------
  180.   def add_original_commands
  181.     r2_original_command_scene_nal
  182.     add_command(R2_NAL::MENU_COMMAND, :nal) if R2_NAL::SHOW_IN_MENU
  183.   end
  184. end
  185.  
  186. #==============================================================================
  187. # ■ Window NAL Item
  188. #==============================================================================
  189.  
  190. class Window_NAL_Title < Window_Base
  191.   #--------------------------------------------------------------------------
  192.   # * Object Initialization
  193.   #--------------------------------------------------------------------------
  194.   def initialize
  195.     super(0, 0, Graphics.width, fitting_height(1))
  196.     refresh
  197.   end
  198.   #--------------------------------------------------------------------------
  199.   # * Refresh
  200.   #--------------------------------------------------------------------------
  201.   def refresh
  202.     contents.clear
  203.     draw_text_ex(0,0,R2_NAL::TITLE)
  204.   end
  205. end
  206.  
  207. #==============================================================================
  208. # ■ Window Note List
  209. #==============================================================================
  210.  
  211. class Window_Note_List < Window_Selectable
  212.   #--------------------------------------------------------------------------
  213.   # * Object Initialization
  214.   #--------------------------------------------------------------------------
  215.   def initialize(x, y, width, height)
  216.     super(x, y, width, height)
  217.     @data = []
  218.     refresh
  219.     select(0)
  220.   end
  221.   #--------------------------------------------------------------------------
  222.   # * Get Digit Count
  223.   #--------------------------------------------------------------------------
  224.   def col_max
  225.     return 1
  226.   end
  227.   #--------------------------------------------------------------------------
  228.   # * Get Number of Items
  229.   #--------------------------------------------------------------------------
  230.   def item_max
  231.     @data ? @data.size : 1
  232.   end
  233.   #--------------------------------------------------------------------------
  234.   # * Get Item
  235.   #--------------------------------------------------------------------------
  236.   def item
  237.     @data && index >= 0 ? @data[index] : nil
  238.   end
  239.   #--------------------------------------------------------------------------
  240.   # * Include in Item List?
  241.   #--------------------------------------------------------------------------
  242.   def include?(item)
  243.     item.is_a?(RPG::Item) && $game_variables[R2_NAL::NAL_VAR][item.id][0] != false
  244.   end
  245.   #--------------------------------------------------------------------------
  246.   # * Create Item List
  247.   #--------------------------------------------------------------------------
  248.   def make_item_list
  249.     @data = $game_party.all_items.select {|item| include?(item) }
  250.     @data.push(nil) if include?(nil)
  251.   end
  252.   #--------------------------------------------------------------------------
  253.   # * Restore Previous Selection Position
  254.   #--------------------------------------------------------------------------
  255.   def select_last
  256.     select(@data.index($game_party.last_item.object) || 0)
  257.   end
  258.   #--------------------------------------------------------------------------
  259.   # * Draw Item
  260.   #--------------------------------------------------------------------------
  261.   def draw_item(index)
  262.     item = @data[index]
  263.     if item
  264.       rect = item_rect(index)
  265.       rect.width -= 4
  266.       draw_item_name(item, rect.x, rect.y)
  267.       draw_icon(R2_NAL::READ_ICON, rect.x, rect.y, true) if
  268.         $game_variables[R2_NAL::NAL_VAR][item.id][2] == false
  269.     end
  270.   end
  271.   #--------------------------------------------------------------------------
  272.   # * Draw Item Name
  273.   #     enabled : Enabled flag. When false, draw semi-transparently.
  274.   #--------------------------------------------------------------------------
  275.   def draw_item_name(item, x, y, enabled = true, width = 172)
  276.     return unless item
  277.     if $game_variables[R2_NAL::NAL_VAR][item.id][0] &&
  278.         $game_variables[R2_NAL::NAL_VAR][item.id][2] == false
  279.       # draw no icon
  280.     else
  281.       draw_icon(item.icon_index, x, y, enabled)
  282.     end
  283.     change_color(normal_color, enabled)
  284.     draw_text(x + 30, y, width, line_height, item.name)
  285.   end
  286.   #--------------------------------------------------------------------------
  287.   # * Image Window
  288.   #--------------------------------------------------------------------------
  289.   def image_window=(window)
  290.     @image_window = window
  291.   end
  292.   #--------------------------------------------------------------------------
  293.   # * Update
  294.   #--------------------------------------------------------------------------
  295.   def update
  296.     super
  297.     @image_window.set_item(item) if @image_window
  298.   end
  299.   #--------------------------------------------------------------------------
  300.   # * Refresh
  301.   #--------------------------------------------------------------------------
  302.   def refresh
  303.     make_item_list
  304.     create_contents
  305.     draw_all_items
  306.   end
  307. end
  308.  
  309. #==============================================================================
  310. # ■ Window NAL Image
  311. #==============================================================================
  312.  
  313. class Window_NAL_Image < Window_Base
  314.   #--------------------------------------------------------------------------
  315.   # * Object Initialization
  316.   #--------------------------------------------------------------------------
  317.   def initialize(x, y, width, height)
  318.     super(x, y, width, height)
  319.   end
  320.   #--------------------------------------------------------------------------
  321.   # * Set Text
  322.   #--------------------------------------------------------------------------
  323.   def set_image(image)
  324.     if image != @image
  325.       @image = image
  326.       refresh
  327.     end
  328.   end
  329.   #--------------------------------------------------------------------------
  330.   # * Clear
  331.   #--------------------------------------------------------------------------
  332.   def clear
  333.     set_image(nil)
  334.   end
  335.   #--------------------------------------------------------------------------
  336.   # * Set Item
  337.   #     item : Skills and items etc.
  338.   #--------------------------------------------------------------------------
  339.   def set_item(item)
  340.     set_image(item ? $game_variables[R2_NAL::NAL_VAR][item.id][1] ?
  341.       $game_variables[R2_NAL::NAL_VAR][item.id][1] : nil : nil)
  342.   end
  343.   #--------------------------------------------------------------------------
  344.   # * Refresh
  345.   #--------------------------------------------------------------------------
  346.   def refresh
  347.     contents.clear
  348.     bitmap = Cache.picture("#{@image}")
  349.     rect = Rect.new(0,0,self.width,self.height)
  350.     contents.blt(0, 0, bitmap, rect)
  351.     bitmap.dispose
  352.   end
  353. end
  354.  
  355. #==============================================================================
  356. # ■ Window NAL Text
  357. #==============================================================================
  358.  
  359. class Window_NAL_Text < Window_Base
  360.   #--------------------------------------------------------------------------
  361.   # * Object Initialization
  362.   #--------------------------------------------------------------------------
  363.   def initialize(x, y, width, height)
  364.     super(x, y, width, height)
  365.     self.opacity = 0
  366.     deactivate
  367.     hide
  368.     self.opacity = 255
  369.   end
  370.   #--------------------------------------------------------------------------
  371.   # * Set Text
  372.   #--------------------------------------------------------------------------
  373.   def set_text(text)
  374.     if text != @text
  375.       @text = text
  376.       refresh
  377.     end
  378.   end
  379.   #--------------------------------------------------------------------------
  380.   # * Clear
  381.   #--------------------------------------------------------------------------
  382.   def clear
  383.     set_text("")
  384.   end
  385.   #--------------------------------------------------------------------------
  386.   # * Set Item
  387.   #     item : Skills and items etc.
  388.   #--------------------------------------------------------------------------
  389.   def set_item(item)
  390.     RPG::SE.new(R2_NAL::PAGE_READ, 80, 0).play if R2_NAL::PAGE_READ != ""
  391.     set_text(item ? R2_NAL::NAL_TEXT[item.id] ? R2_NAL::NAL_TEXT[item.id] : [] : [])
  392.   end
  393.   #--------------------------------------------------------------------------
  394.   # * Refresh
  395.   #--------------------------------------------------------------------------
  396.   def refresh
  397.     contents.clear
  398.     y = 0
  399.     @text.each do |txt|
  400.       draw_text_ex(4, y, txt)
  401.       y += line_height
  402.     end
  403.     draw_text_ex(0, contents.height - 32, R2_NAL::RETURN_TEXT)
  404.   end
  405.   #--------------------------------------------------------------------------
  406.   # * Reset Font Settings
  407.   #--------------------------------------------------------------------------
  408.   def reset_font_settings
  409.     change_color(normal_color)
  410.     contents.font.name = R2_NAL::NAL_FONT
  411.     contents.font.size = R2_NAL::NAL_FONT_SIZE
  412.     contents.font.bold = R2_NAL::NAL_FONT_BOLD
  413.     contents.font.italic = R2_NAL::NAL_FONT_ITALIC
  414.   end
  415. end
  416.  
  417. #==============================================================================
  418. # ■ Scene NAL
  419. #==============================================================================
  420.  
  421. class Scene_NAL < Scene_MenuBase
  422.   #--------------------------------------------------------------------------
  423.   # * Start Processing
  424.   #--------------------------------------------------------------------------
  425.   def start
  426.     super
  427.     create_text_window
  428.     create_title_window
  429.     create_image_window
  430.     create_list_window
  431.   end
  432.   #--------------------------------------------------------------------------
  433.   # * Create Text Window
  434.   #--------------------------------------------------------------------------
  435.   def create_text_window
  436.     ww = Graphics.width
  437.     wh = Graphics.height
  438.     @text_window = Window_NAL_Text.new(0, 0, ww, wh)
  439.     @text_window.z = 200
  440.   end
  441.   #--------------------------------------------------------------------------
  442.   # * Create Title Window
  443.   #--------------------------------------------------------------------------
  444.   def create_title_window
  445.     @title_window = Window_NAL_Title.new
  446.   end
  447.   #--------------------------------------------------------------------------
  448.   # * Create Image Window
  449.   #--------------------------------------------------------------------------
  450.   def create_image_window
  451.     wx = 200
  452.     wy = @title_window.height
  453.     ww = Graphics.width - wx
  454.     wh = Graphics.height - wy
  455.     @image_window = Window_NAL_Image.new(wx, wy, ww, wh)
  456.   end
  457.   #--------------------------------------------------------------------------
  458.   # * Create List Window
  459.   #--------------------------------------------------------------------------
  460.   def create_list_window
  461.     wx = 0
  462.     wy = @title_window.height
  463.     ww = 200
  464.     wh = Graphics.height - wy
  465.     @list_window = Window_Note_List.new(wx, wy, ww, wh)
  466.     @list_window.set_handler(:ok,     method(:on_item_ok))
  467.     @list_window.set_handler(:cancel, method(:on_item_cancel))
  468.     @list_window.activate
  469.     @list_window.image_window = @image_window
  470.   end
  471.   #--------------------------------------------------------------------------
  472.   # * Item [OK]
  473.   #--------------------------------------------------------------------------
  474.   def on_item_ok
  475.     if @list_window.item == nil
  476.       Sound.play_buzzer
  477.       @list_window.activate
  478.       return
  479.     end
  480.     @list_window.deactivate
  481.     @text_window.activate
  482.     @text_window.show
  483.     @text_window.set_item(@list_window.item)
  484.     $game_variables[R2_NAL::NAL_VAR][@list_window.item.id][2] = true if
  485.       $game_variables[R2_NAL::NAL_VAR][@list_window.item.id][2] == false
  486.     @title_window.hide
  487.     @image_window.hide
  488.     @list_window.hide
  489.   end
  490.   #--------------------------------------------------------------------------
  491.   # * Item [Cancel]
  492.   #--------------------------------------------------------------------------
  493.   def on_item_cancel
  494.     return_scene
  495.   end
  496.   #--------------------------------------------------------------------------
  497.   # * Text Cancel
  498.   #--------------------------------------------------------------------------
  499.   def on_text_cancel
  500.     @text_window.deactivate
  501.     @text_window.hide
  502.     @title_window.show
  503.     @image_window.show
  504.     @list_window.show
  505.     @list_window.activate
  506.     @list_window.refresh
  507.     Sound.play_cancel
  508.   end
  509.   #--------------------------------------------------------------------------
  510.   # * Frame Update
  511.   #--------------------------------------------------------------------------
  512.   def update
  513.     super
  514.     on_text_cancel if Input.press?(:B) && @text_window.active
  515.   end
  516. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement