Advertisement
ForeverZer0

[RMXP] Journal 2.3

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