Advertisement
Black_Mage

Game Log Script

Nov 3rd, 2018
738
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.38 KB | None | 0 0
  1. #==============================================================================
  2. # Don't remove this header!
  3. #==============================================================================
  4. # Game Log By Black Mage (Credit required to use)
  5. # Current Version : 1.1
  6. # https://burningwizard.wordpress.com/2018/11/04/game-log-script-rmvxa-rgss3/
  7. #
  8. # This script can store game log for you, and can display it too!
  9. # You can have separate log for your purposes.
  10. #
  11. # This script is licensed under CC BY 3.0
  12. # https://creativecommons.org/licenses/by/3.0/
  13. #==============================================================================
  14.  
  15. #==============================================================================
  16. # Changelog
  17. #==============================================================================
  18. #
  19. # Version 1.1
  20. #   - Enable line break on view_log feature.
  21. # Version 1.0
  22. #   - Initial version.
  23. #
  24. #==============================================================================
  25.  
  26. #==============================================================================
  27. # How to use the script
  28. #==============================================================================
  29. # Put this script on your project.
  30. #
  31. # Use any of these command on script call from event command:
  32. #
  33. # save_log(key, text)
  34. # Use this command to save the text on desired key. The new text added will be
  35. # placed in the bottom of the log corresponds to the key.
  36. #
  37. # get_log(key)
  38. # This command will return an array of log corresponds to the key.
  39. #
  40. # view_log(key, title)
  41. # Use this command to view the log corresponds to the key given. The title will
  42. # be displayed on top of the log window.
  43. #
  44. #==============================================================================
  45.  
  46. #------------------------------------------------------------------------------
  47. # * Beyond this is the sacred land of code. You need programming qualification
  48. #   to dwelve deeper, or it'll cause many unnecessary problems. Proceed on your
  49. #   own risk.
  50. #------------------------------------------------------------------------------
  51.  
  52. #==============================================================================
  53. # ** Log System
  54. #==============================================================================
  55. class Game_System
  56.   attr_accessor :save_log
  57.   attr_accessor :log_key
  58.   attr_accessor :log_title
  59.   alias black_initialize initialize
  60.   def initialize
  61.     black_initialize
  62.     @save_log = Hash.new
  63.   end
  64. end
  65.  
  66. class Game_Interpreter
  67.   #--------------------------------------------------------------------------
  68.   # new method: save log
  69.   #--------------------------------------------------------------------------
  70.   def save_log(key, text)
  71.     $game_system.save_log[key] = [] if !$game_system.save_log[key]
  72.     $game_system.save_log[key].push(text)
  73.   end
  74.   #--------------------------------------------------------------------------
  75.   # new method: get log
  76.   #--------------------------------------------------------------------------
  77.   def get_log(key)
  78.     return $game_system.save_log[key]
  79.   end
  80. end
  81. #_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  End of Log System
  82.  
  83.  
  84. #==============================================================================
  85. # ** Display Log System
  86. #==============================================================================
  87. class Game_Interpreter
  88.   #--------------------------------------------------------------------------
  89.   # new method: scene log, used to call log window.
  90.   #--------------------------------------------------------------------------
  91.   def view_log(key, title)
  92.     SceneManager.call(Scene_Log)
  93.     $game_system.log_key = key
  94.     $game_system.log_title = title
  95.   end
  96. end
  97.  
  98. class Scene_Log < Scene_MenuBase
  99.   def start
  100.     super
  101.     @title_window = Window_Title_Text.new(0,0,Graphics.width,48)
  102.     @title_window.set_text($game_system.log_title)
  103.     @text_window = Window_Char_Text.new(0, @title_window.height, Graphics.width, Graphics.height - @title_window.height)
  104.     @text_window.set_text($game_system.log_key)
  105.     @line_height = 24
  106.     @content_height = ($game_system.save_log[$game_system.log_key].size - 16) * 24
  107.   end
  108.    
  109.   def update
  110.     super
  111.     press_down if Input.repeat?(:DOWN)
  112.     press_up if Input.repeat?(:UP)
  113.     return return_scene if Input.trigger?(:B)
  114.   end
  115.  
  116.   def press_down
  117.     @text_window.oy += @line_height if @text_window.oy < [@content_height, 0].max
  118.   end
  119.  
  120.   def press_up
  121.     @text_window.oy -= @line_height if @text_window.oy > 0
  122.   end  
  123. end
  124.  
  125. class Window_Char_Text < Window_Base
  126.   def set_text(key)
  127.     text = $game_system.save_log[key]
  128.     return if !text
  129.     @line = 0
  130.     text.each do |text_line|
  131.       draw_text_ex(0, -24, text_line); @line += 1;
  132.     end
  133.     contents.clear
  134.     self.contents = Bitmap.new(width - 24, @line * 24)
  135.     @line = 0
  136.     text.each do |text_line|
  137.       draw_text_ex(0, @line*line_height, text_line)
  138.       @line += 1
  139.     end
  140.   end
  141.   def process_new_line(text, pos)
  142.     @line += 1 if @line.kind_of? Integer
  143.     pos[:x] = pos[:new_x]
  144.     pos[:y] += pos[:height]
  145.     pos[:height] = calc_line_height(text)
  146.   end
  147. end
  148.  
  149. class Window_Title_Text < Window_Base
  150.   def set_text(key)
  151.     contents.clear
  152.     self.contents = Bitmap.new(width - 24, 24)
  153.     draw_text(0, 0, contents.width, line_height, key)
  154.   end
  155. end
  156. #_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  End of Display Log System
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement