Black_Mage icon

Game Log Script

Black_Mage | PRO | 11/03/18 10:52:13 PM UTC | 0 ⭐ | 7819 👁️ | Never ⏰ | []
Ruby |

5.38 KB

|

None

|

0 👍

/

0 👎

#==============================================================================
# Don't remove this header!
#==============================================================================
# Game Log By Black Mage (Credit required to use)
# Current Version : 1.1
# https://burningwizard.wordpress.com/2018/11/04/game-log-script-rmvxa-rgss3/
#
# This script can store game log for you, and can display it too!
# You can have separate log for your purposes.
#
# This script is licensed under CC BY 3.0
# https://creativecommons.org/licenses/by/3.0/
#==============================================================================
 
#==============================================================================
# Changelog
#==============================================================================
#
# Version 1.1
#   - Enable line break on view_log feature.
# Version 1.0
#   - Initial version.
#
#==============================================================================
 
#==============================================================================
# How to use the script
#==============================================================================
# Put this script on your project.
#
# Use any of these command on script call from event command:
#
# save_log(key, text)
# Use this command to save the text on desired key. The new text added will be
# placed in the bottom of the log corresponds to the key.
#
# get_log(key)
# This command will return an array of log corresponds to the key.
#
# view_log(key, title)
# Use this command to view the log corresponds to the key given. The title will
# be displayed on top of the log window.
#
#==============================================================================
 
#------------------------------------------------------------------------------
# * Beyond this is the sacred land of code. You need programming qualification
#   to dwelve deeper, or it'll cause many unnecessary problems. Proceed on your
#   own risk.
#------------------------------------------------------------------------------
 
#==============================================================================
# ** Log System
#==============================================================================
class Game_System
  attr_accessor :save_log
  attr_accessor :log_key
  attr_accessor :log_title
  alias black_initialize initialize
  def initialize
    black_initialize
    @save_log = Hash.new
  end
end
 
class Game_Interpreter
  #--------------------------------------------------------------------------
  # new method: save log
  #--------------------------------------------------------------------------
  def save_log(key, text)
    $game_system.save_log[key] = [] if !$game_system.save_log[key]
    $game_system.save_log[key].push(text)
  end
  #--------------------------------------------------------------------------
  # new method: get log
  #--------------------------------------------------------------------------
  def get_log(key)
    return $game_system.save_log[key]
  end
end
#_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  End of Log System
 
 
#==============================================================================
# ** Display Log System
#==============================================================================
class Game_Interpreter
  #--------------------------------------------------------------------------
  # new method: scene log, used to call log window.
  #--------------------------------------------------------------------------
  def view_log(key, title)
    SceneManager.call(Scene_Log)
    $game_system.log_key = key
    $game_system.log_title = title
  end
end
 
class Scene_Log < Scene_MenuBase
  def start
    super
    @title_window = Window_Title_Text.new(0,0,Graphics.width,48)
    @title_window.set_text($game_system.log_title)
    @text_window = Window_Char_Text.new(0, @title_window.height, Graphics.width, Graphics.height - @title_window.height)
    @text_window.set_text($game_system.log_key)
    @line_height = 24
    @content_height = ($game_system.save_log[$game_system.log_key].size - 16) * 24
  end
    
  def update
    super
    press_down if Input.repeat?(:DOWN)
    press_up if Input.repeat?(:UP)
    return return_scene if Input.trigger?(:B)
  end
  
  def press_down
    @text_window.oy += @line_height if @text_window.oy < [@content_height, 0].max
  end
  
  def press_up
    @text_window.oy -= @line_height if @text_window.oy > 0
  end  
end
 
class Window_Char_Text < Window_Base
  def set_text(key)
    text = $game_system.save_log[key]
    return if !text
    @line = 0
    text.each do |text_line|
      draw_text_ex(0, -24, text_line); @line += 1;
    end
    contents.clear
    self.contents = Bitmap.new(width - 24, @line * 24)
    @line = 0
    text.each do |text_line|
      draw_text_ex(0, @line*line_height, text_line)
      @line += 1
    end
  end
  def process_new_line(text, pos)
    @line += 1 if @line.kind_of? Integer
    pos[:x] = pos[:new_x]
    pos[:y] += pos[:height]
    pos[:height] = calc_line_height(text)
  end
end
 
class Window_Title_Text < Window_Base
  def set_text(key)
    contents.clear
    self.contents = Bitmap.new(width - 24, 24)
    draw_text(0, 0, contents.width, line_height, key)
  end
end
#_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  End of Display Log System

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎