Help with ForeverZero's Journal Script

Hopefully a simple change / addition.

  1. #+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
  2. # Journal
  3. # Author: ForeverZer0
  4. # Version: 2.4
  5. # Data: 12.30.2010
  6. #+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
  7. #
  8. # Introduction:
  9. #   I wrote this script after seeing a request here on CP for something similar.
  10. #   It basically just allows the player to view a Journal that show the player
  11. #   information about people they have encountered and places they have visited.
  12. #   Can also log weapons, armors, and items.
  13. #  
  14. # Features:
  15. #   - Easy to use/configure
  16. #   - Nice simple interface
  17. #   - Will log people, places, weapons, armors, and items seperately
  18. #   - Configurable what type of entries you would like to log.
  19. #   - Configurable layout
  20. #   - Option to use pictures
  21. #   - Fully compatible "stats" you want the system to display.
  22. #
  23. # Instructions:
  24. #   - Place script in the usual place.
  25. #   - All configuration is below, and explained in each section.
  26. #   - All pictures must be in folder labeled "Journal" within your game's
  27. #     Picture folder.
  28. #   - All you have to do is assign arbitrary "ids" to each person and location
  29. #     respectively. After you have completed configuration, when you want the
  30. #     person/place to be added to the Journal, use these script calls:
  31. #
  32. #       Journal.add_character(ID)
  33. #       Journal.add_location(ID)
  34. #       Journal.add_weapon(ID)
  35. #       Journal.add_armor(ID)
  36. #       Journal.add_item(ID)
  37. #
  38. #       You can also delete entries in the same way:
  39. #
  40. #       Journal.delete_character(id)
  41. #       Journal.delete_location(id)
  42. #       Journal.delete_weapon(id)
  43. #       Journal.delete_armor(id)
  44. #       Journal.delete_item(id)
  45. #
  46. #     Where the "ID" is the number you assigned to each.
  47. #   - To call the scene, use this script call:
  48. #
  49. #       $scene = Scene_Journal.new
  50. #
  51. #   - The script comes with a fix for those who like to use smaller text sizes
  52. #     (like myself), which will allow for more information to be displayed on
  53. #     the screen at once.
  54. #   - If you would like to change the look up a little bit, just change around
  55. #     the X and Y values in Window_Journal.
  56. #
  57. # Credits/Thanks:
  58. #   - ForeverZer0, for the script.
  59. #
  60. #=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
  61. #                           BEGIN CONFIGURATION
  62. #=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
  63.  
  64. module Journal
  65.  
  66.   # If true, a line height of 20 pixels will be used, which looks better with
  67.   # smaller font sizes.
  68.   SMALL_TEXT = true
  69.   # The width of the entry list used for Scene_Journal. The other windows will
  70.   # automatically adjust to this width.
  71.   LIST_WIDTH = 192
  72.  
  73.   # Define what aspects of the journal you would like to use. Choose from the
  74.   # values listed below and add them to the array. DO NOT change the values.
  75.   # Omit values for types you do not want to use.
  76.   #        'People' - 'Places' - 'Weapons' - 'Armors' - 'Items'
  77.   LIST_ORDER = ['People', 'Places', 'Weapons', 'Armors', 'Items']
  78.  
  79.   # Configure if you would like for items, weapons, and armors to be unlocked
  80.   # automatically when they are first aquired by the player. If using this
  81.   # options, IDs MUST match the IDs used in the Database. You will also need to
  82.   # manually add anything the player begins with at game start.
  83.   AUTO_WEAPONS = true
  84.   AUTO_ARMORS = true
  85.   AUTO_ITEMS = true
  86.  
  87. #-------------------------------------------------------------------------------
  88.   CHARACTER_STATS = ['Name:', 'Race:', 'Age:', 'Height:', 'Weight:']
  89.  
  90.   # Configure the values used for the above array for each character. Just make
  91.   # sure the value that corresponds to each stat is at the same index in the [].
  92.   # Just make sure that the first stat is the name, it will be used on the menu
  93.   # to select which character/location will be viewed.
  94.   def self.character_info(id)
  95.     info = case id
  96.     when 1 then ['Aluxes', 'Human', '19', '5'10"', '165 lbs.']
  97.     when 2 then ['Hilda', 'Human', '20', '5'5"', '113']
  98.     when 3 then ['Basil', 'Human', '24', '6'0"', '187 lbs.']
  99.     end
  100.     return info != nil ? info : []
  101.   end
  102.  
  103.   # Short paragraph/description of character. Uses Blizzard's slice_text method
  104.   # to automatically break to next line when needed, so do not concern yourself
  105.   # with that.
  106.   def self.character_bio(id)
  107.     text = case id
  108.     when 1
  109.       'Our everyday hero, that seems to make an appearance in every demo.'
  110.     when 2
  111.       'Random witch girl.'
  112.     when 3
  113.       'Another RPGXP character.'
  114.     end
  115.     return text != nil ? text : ''
  116.   end
  117. #-------------------------------------------------------------------------------
  118.   LOCATION_STATS = ['Name:', 'Country:']
  119.  
  120.   # Configure the values used for the above array for each location. Just make
  121.   # sure the value that corresponds to each stat is at the same index in the [].
  122.   # Just make sure that the first stat is the name, it will be used on the menu
  123.   # to select which character/location will be viewed.
  124.   def self.location_info(id)
  125.     info = case id
  126.     when 1 then ['New York', 'USA']
  127.     when 2 then ['Ohio', 'USA']
  128.     when 3 then ['Iowa', 'Who cares...']
  129.     end
  130.     return info != nil ? info : []
  131.   end
  132.  
  133.   # Short paragraph/description of location. Uses Blizzard's slice_text method
  134.   # to automatically break to next line when needed, so do not concern yourself
  135.   # with that.
  136.   def self.location_bio(id)
  137.     return case id
  138.     when 1
  139.       'The state north of Pennsylvania.'
  140.     when 2
  141.       'The state west of Pennsylvania.'
  142.     when 3
  143.       'A boring state.'
  144.     else
  145.       ''
  146.     end
  147.   end
  148. #-------------------------------------------------------------------------------
  149.   WEAPON_STATS = ['Name:', 'Origin:']
  150.    
  151.   def self.weapon_info(id)
  152.     text = case id
  153.     when 1 then ['Bronze Sword', 'Everywhere.']
  154.     when 2 then ['Iron Sword', 'Right here.']
  155.     when 3 then ['Mythril Sword', 'Blah blah.']
  156.     end
  157.   end
  158.  
  159.   def self.weapon_bio(id)
  160.     return case id
  161.     when 1
  162.       'Simple sword. Seems to be the standard that all RPG games have the hero start with.'
  163.     when 2
  164.       'Slighly better than the Bronze sword.'
  165.     when 3
  166.       'Yet another sword that is in almost every RPG.'
  167.     else
  168.       ''
  169.     end
  170.   end
  171. #-------------------------------------------------------------------------------
  172.   ARMOR_STATS = ['Name:', 'Origin:']
  173.    
  174.   def self.armor_info(id)
  175.     text = case id
  176.     when 1 then ['', '']
  177.     when 2 then ['', '']
  178.     when 3 then ['', '']
  179.     end
  180.   end
  181.  
  182.   def self.armor_bio(id)
  183.     return case id
  184.     when 1
  185.       ''
  186.     when 2
  187.       ''
  188.     when 3
  189.       ''
  190.     else
  191.       ''
  192.     end
  193.   end
  194. #-------------------------------------------------------------------------------
  195.   ITEM_STATS = ['Name:', 'Origin:']
  196.  
  197.   def self.item_info(id)
  198.     text = case id
  199.     when 1 then ['', '']
  200.     when 2 then ['', '']
  201.     when 3 then ['', '']
  202.     end
  203.   end
  204.  
  205.   def self.item_bio(id)
  206.     return case id
  207.     when 1
  208.       ''
  209.     when 2
  210.       ''
  211.     when 3
  212.       ''
  213.     else
  214.       ''
  215.     end
  216.   end
  217. #-------------------------------------------------------------------------------
  218.  
  219.   # Set the following to true if you would loke pictures to be displayed for
  220.   # the respective type of Journal entries. They will be defined below.
  221.   CHARACTER_PIC = true
  222.   LOCATION_PIC = true
  223.   WEAPON_PIC = true
  224.   ARMOR_PIC = true
  225.   ITEM_PIC = true
  226.  
  227.   # Filenames of character pictures.
  228.   def self.character_pic(id)
  229.     file = case id
  230.     when 1 then 'Aluxes'
  231.     when 2 then 'Hilda'
  232.     when 3 then 'Basil'
  233.     end
  234.     return file != nil ? RPG::Cache.picture("Journal/#{file}") : Bitmap.new(1,1)
  235.   end
  236.  
  237.   # Filenames of location pictures.
  238.   def self.location_pic(id)
  239.     file = case id
  240.     when 1 then ''
  241.     when 2 then ''
  242.     when 3 then ''
  243.     end
  244.     return file != nil ? RPG::Cache.picture("Journal/#{file}") : Bitmap.new(1,1)
  245.   end  
  246.  
  247.   # Filename of weapon pictures.
  248.   def self.weapon_pic(id)
  249.     file = case id
  250.     when 1 then ''
  251.     when 2 then ''
  252.     when 3 then ''
  253.     end
  254.     return file != nil ? RPG::Cache.picture("Journal/#{file}") : Bitmap.new(1,1)
  255.   end
  256.  
  257.   # Filename of weapon pictures.
  258.   def self.armor_pic(id)
  259.     file = case id
  260.     when 1 then ''
  261.     when 2 then ''
  262.     when 3 then ''
  263.     end
  264.     return file != nil ? RPG::Cache.picture("Journal/#{file}") : Bitmap.new(1,1)
  265.   end
  266.  
  267.   # Filenames of item pictures.
  268.   def self.item_pic(id)
  269.     file = case id
  270.     when 1 then ''
  271.     when 2 then ''
  272.     when 3 then ''
  273.     end
  274.     return file != nil ? RPG::Cache.picture("Journal/#{file}") : Bitmap.new(1,1)
  275.   end
  276.  
  277. #=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
  278. #                           END CONFIGURATION
  279. #=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
  280.  
  281.   def self.add_character(id)
  282.     unless $game_system.journal['People'].include?(id)
  283.       $game_system.journal['People'].push(id)
  284.       $game_system.journal['People'].sort!
  285.     end
  286.   end
  287.  
  288.   def self.add_location(id)
  289.     unless $game_system.journal['Places'].include?(id)
  290.       $game_system.journal['Places'].push(id)
  291.       $game_system.journal['Places'].sort!
  292.     end
  293.   end
  294.  
  295.   def self.add_weapon(id)
  296.     unless $game_system.journal['Weapons'].include?(id)
  297.       $game_system.journal['Weapons'].push(id)
  298.       $game_system.journal['Weapons'].sort!
  299.     end
  300.   end
  301.  
  302.   def self.add_armor(id)
  303.     unless $game_system.journal['Armors'].include?(id)
  304.       $game_system.journal['Armors'].push(id)
  305.       $game_system.journal['Armors'].sort!
  306.     end
  307.   end
  308.  
  309.   def self.add_item(id)
  310.     unless $game_system.journal['Items'].include?(id)
  311.       $game_system.journal['Items'].push(id)
  312.       $game_system.journal['Items'].sort!
  313.     end
  314.   end
  315.  
  316.   def self.delete_character(id)
  317.     $game_system.journal['People'].delete(id)
  318.     $game_system.journal['People'].sort!
  319.   end
  320.  
  321.   def self.delete_location(id)
  322.     $game_system.journal['Places'].delete(id)
  323.     $game_system.journal['Places'].sort!
  324.   end
  325.  
  326.   def self.delete_weapon(id)
  327.     $game_system.journal['Weapons'].delete(id)
  328.     $game_system.journal['Weapons'].sort!
  329.   end
  330.  
  331.   def self.delete_armor(id)
  332.     $game_system.journal['Armors'].delete(id)
  333.     $game_system.journal['Armors'].sort!
  334.   end
  335.  
  336.   def self.delete_item(id)
  337.     $game_system.journal['Items'].delete(id)
  338.     $game_system.journal['Items'].sort!
  339.   end
  340. end
  341.  
  342. #===============================================================================
  343. # ** Game_System
  344. #===============================================================================
  345.  
  346. class Game_System
  347.  
  348.   attr_accessor :journal
  349.  
  350.   alias zer0_journal_init initialize
  351.   def initialize
  352.     zer0_journal_init
  353.     @journal = {}
  354.     Journal::LIST_ORDER.each {|key| @journal[key] = [] }
  355.   end
  356.  
  357.   def journal_entries(type)
  358.     entries = []
  359.     case type
  360.     when 'People'
  361.       @journal[type].each {|id| entries.push(Journal.character_info(id)[0]) }
  362.     when 'Places'
  363.       @journal[type].each {|id| entries.push(Journal.location_info(id)[0]) }
  364.     when 'Weapons'
  365.       @journal[type].each {|id| entries.push(Journal.weapon_info(id)[0]) }
  366.     when 'Armors'
  367.       @journal[type].each {|id| entries.push(Journal.armor_info(id)[0]) }
  368.     when 'Items'
  369.       @journal[type].each {|id| entries.push(Journal.item_info(id)[0]) }
  370.     end
  371.     return entries.empty? ? ['None'] : entries
  372.   end
  373. end
  374.  
  375. #===============================================================================
  376. # ** Game_Party
  377. #===============================================================================
  378.  
  379. class Game_Party
  380.  
  381.   alias zer0_auto_add_weapon gain_weapon
  382.   def gain_weapon(weapon_id, n)
  383.     # Unlock weapon ID if recieved.
  384.     if Journal::AUTO_WEAPONS& ![nil, 0].include?(weapon_id)
  385.       Journal.add_weapon(weapon_id)
  386.     end
  387.     zer0_auto_add_weapon(weapon_id, n)
  388.   end
  389.  
  390.   alias zer0_auto_add_armor gain_armor
  391.   def gain_armor(armor_id, n)
  392.     # Unlock armor ID if recieved.
  393.     if Journal::AUTO_ARMORS && ![nil, 0].include?(armor_id)
  394.       Journal.add_armor(armor_id)
  395.     end
  396.     zer0_auto_add_armor(armor_id, n)
  397.   end
  398.  
  399.   alias zer0_auto_add_item gain_item
  400.   def gain_item(item_id, n)
  401.     # Unlock item ID if recieved.
  402.      if Journal::AUTO_ITEMS && ![nil, 0].include?(item_id)
  403.       Journal.add_item(item_id)
  404.     end
  405.     zer0_auto_add_item(item_id, n)
  406.   end
  407. end
  408.  
  409. #===============================================================================
  410. # ** Bitmap (slice_text method by Blizzard)
  411. #===============================================================================
  412.  
  413. class Bitmap
  414.  
  415.   def slice_text(text, width)
  416.     words = text.split(' ')
  417.     return words if words.size == 1
  418.     result, current_text = [], words.shift
  419.     words.each_index {|i|
  420.     if self.text_size("#{current_text} #{words[i]}").width > width
  421.       result.push(current_text)
  422.       current_text = words[i]
  423.     else
  424.       current_text = "#{current_text} #{words[i]}"
  425.     end
  426.     result.push(current_text) if i >= words.size - 1}
  427.     return result
  428.   end
  429. end
  430.  
  431. #===============================================================================
  432. # ** Window_Journal
  433. #===============================================================================
  434.  
  435. class Window_Journal < Window_Base
  436.  
  437.   attr_accessor :type
  438.  
  439.   def initialize
  440.     super(Journal::LIST_WIDTH, 0, 640 - Journal::LIST_WIDTH, 480)
  441.     self.contents = Bitmap.new(width - 32, height - 32)
  442.     self.visible = false
  443.     @type = ''
  444.   end
  445.  
  446.   def id=(id)
  447.     @id = id
  448.     refresh
  449.   end
  450.  
  451.   def refresh
  452.     self.contents.clear
  453.     return if @id == nil
  454.     # Set local variables, branching by what type is being viewed.
  455.     case @type
  456.     when 'People'
  457.       stats = Journal::CHARACTER_STATS
  458.       info = Journal.character_info(@id)
  459.       bio = Journal.character_bio(@id)
  460.       pic = Journal::CHARACTER_PIC ? Journal.character_pic(@id) : nil
  461.     when 'Places'
  462.       stats = Journal::LOCATION_STATS
  463.       info = Journal.location_info(@id)
  464.       bio = Journal.location_bio(@id)
  465.       pic = Journal::LOCATION_PIC ? Journal.location_pic(@id) : nil
  466.     when 'Weapons'
  467.       stats = Journal::WEAPON_STATS
  468.       info = Journal.weapon_info(@id)
  469.       bio = Journal.weapon_bio(@id)
  470.       pic = Journal::WEAPON_PIC ? Journal.weapon_pic(@id) : nil
  471.     when 'Armors'
  472.       stats = Journal::ARMOR_STATS
  473.       info = Journal.armor_info(@id)
  474.       bio = Journal.armor_bio(@id)
  475.       pic = Journal::ARMOR_PIC ? Journal.armor_pic(@id) : nil
  476.     when 'Items'
  477.       stats = Journal::ITEM_STATS
  478.       info = Journal.item_info(@id)
  479.       bio = Journal.item_bio(@id)
  480.       pic = Journal::ITEM_PIC ? Journal.item_pic(@id) : nil
  481.     end
  482.     width = 640 - Journal::LIST_WIDTH - 40
  483.     bio = self.contents.slice_text(bio, width)
  484.     if pic != nil
  485.       rect = Rect.new(0, 0, pic.width, pic.height)
  486.       self.contents.blt(self.width-pic.width-64, 32, pic, rect)
  487.     end
  488.     # Draw the values on the window's bitmap.
  489.     self.contents.font.color = system_color
  490.     y = Journal::SMALL_TEXT ? 20 : 32
  491.     stats.each_index {|i| self.contents.draw_text(0, i*(y*2), 128, y, stats[i])}
  492.     self.contents.draw_text(0, 320, 128, y, 'Description:')
  493.     self.contents.font.color = normal_color
  494.     info.each_index {|i| self.contents.draw_text(8, y+i*(y*2), 128, y, info[i])}
  495.     bio.each_index {|i| self.contents.draw_text(8, (320+y)+i*y, width, y, bio[i])}  
  496.   end
  497. end
  498.  
  499. #===============================================================================
  500. # ** Scene_Journal
  501. #===============================================================================
  502.  
  503. class Scene_Journal
  504. #-------------------------------------------------------------------------------
  505.   def main
  506.     # Create lists of the entries for each Journal content type.
  507.     @entry_lists, @index = [], 0
  508.     # Create list of entry titles.
  509.     Journal::LIST_ORDER.each {|key|
  510.       next unless $game_system.journal.has_key?(key)
  511.       window = Window_Command.new(Journal::LIST_WIDTH, $game_system.journal_entries(key))
  512.       window.visible = window.active = false
  513.       window.height = 480
  514.       @entry_lists.push(window)
  515.     }
  516.     # Create main command window.
  517.     @command_window = Window_Command.new(Journal::LIST_WIDTH, Journal::LIST_ORDER)
  518.     @command_window.height = 480
  519.     # Create main window for viewing information and dummy window.
  520.     @dummy_window = Window_Base.new(Journal::LIST_WIDTH, 0, 640 - Journal::LIST_WIDTH, 480)
  521.     @journal_window = Window_Journal.new
  522.     @windows = @entry_lists + [@journal_window, @command_window, @dummy_window]
  523.     # Transition and start main loop for the scene.
  524.     Graphics.transition
  525.     loop {Graphics.update; Input.update; update; break if $scene != self}
  526.     # Dispose all windows and prepare for transition.
  527.     Graphics.freeze
  528.     @windows.each {|window| window.dispose}
  529.   end
  530. #-------------------------------------------------------------------------------
  531.   def update
  532.     # Update all the windows.
  533.     @windows.each {|window| window.update }
  534.     # Branch update method depending on what window is active.
  535.     @command_window.active ? update_command : update_entry_selection
  536.   end
  537. #-------------------------------------------------------------------------------
  538.   def update_command
  539.     if Input.trigger?(Input::B)
  540.       $game_system.se_play($data_system.cancel_se)
  541.       $scene = Scene_Map.new
  542.     elsif Input.trigger?(Input::C)
  543.       # Deactivate command window and make selected entry list active.
  544.       @index = @command_window.index
  545.       @command_window.active = @command_window.visible = false
  546.       @entry_lists[@index].active = @entry_lists[@index].visible = true
  547.     end
  548.   end
  549. #-------------------------------------------------------------------------------
  550.   def update_entry_selection
  551.     if Input.trigger?(Input::B)
  552.       $game_system.se_play($data_system.cancel_se)
  553.       # Deactivate entry list and make command window active.
  554.       @command_window.active = @command_window.visible = true
  555.       @entry_lists[@index].active = @entry_lists[@index].visible = false
  556.       @journal_window.visible = false
  557.     elsif Input.trigger?(Input::C)
  558.       @journal_window.visible = true
  559.       $game_system.se_play($data_system.decision_se)
  560.       type = Journal::LIST_ORDER[@index]
  561.       # Set the type and id variables for the journal window and refresh.
  562.       @journal_window.type = type
  563.       @journal_window.id = $game_system.journal[type][@entry_lists[@index].index]
  564.     end
  565.   end
  566. end
Expand to see the code.



This script is a journal script which puts different entries under different banners. What I want to do is when new information is added have the entry name display in a different colour in the index until the player reads the entry, to flag it up as new information.

Any pointers on how I can go about doing this?

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=75663