KDiurnalis ACE

KDiurnalis ACE
version 1.0.5
by Kyonides Arkanthes
​


Introduction

This is a Party's Journal Script!

Tweak this script's CONSTANTS in order to customize the Journal Menu's GUI.
You can find them under the KDiurnalis module.

There are two ways to open the Journal Menu.
SceneManager.call(KDiurnalis::Scene)
KDiurnalis.open!

To learn more about how to use my script please read the instructions embedded in it.

Notes:

The demo includes examples of how you can easily add entry lines to an existing date.
It will automatically create a new date entry if the current date is different from the previous one.

Now it features stuff like automatic substitutions of tags like \n[1] or \e[1]!

The Script

Ruby:
# * KDiurnalis ACE
#   Scripter : Kyonides Arkanthes
#   v 1.0.5 - 2022-06-16
# * Non Plug & Play Script * #

# The Party's Journal Script!

# Tweak this script's CONSTANTS in order to customize the Journal Menu's GUI.
# You can find them under the KDiurnalis module.

# * Overwritten Method * #
# Scene_Load#on_load_success

# * Script Calls * #

# - Open Journal Scene - 2 Options
# $scene = KDiurnalis::Scene.new
# KDiurnalis.open!

# - Add New Journal Page Steps - #

# -- Step 1
# Location: can be replaced with a "String" or :map for current map name.
# $game_party.add_journal_entry("Title", Location)

# -- Step 2
# Add as many Message Windows and lines of text as you wish!

# -- Step 3
# - Stop Using Message Windows as Journal Entry's Page Contents
# Simply stop adding any more message windows!

module KDiurnalis
  LOAD_OPENS_JOURNAL = true
  SHOW_DATES = nil
  # Place the Backdrop in the Titles1 directory.
  # Options: "Filename" or nil
  BACKDROP = "backdrop circles blue"
  TITLE = "%s's Journal"
  TITLE_ALIGN = 1
  NO_ENTRY = "No Entry Found"
  module Start
    TITLE = "My New Adventure"
    LOCATION = "Home"
    TEXT = []
    TEXT << "My history begins today."
    TEXT << "I am very excited indeed."
  end
  PAGES_FOUND = "%s Pages Found"
  PAGES_LABEL = "Page %s/%s"
  PAGES_LABEL_ALIGN = 2
  HELP_WIN_OPACITY = 160
  # Window's Coordinates = [X, Y, Width, Height, Opacity]
  LIST_WIN_COORD  = [8, 76, 160, 320, 160]
  DUMMY_WIN_COORD = [176, 76, 360, 84, 160]
  INFO_WIN_COORD  = [176, 76, 360, 320, 160]
  # * End of Setup * #
  extend self
  attr_accessor :use_message_window
  def open!() SceneManager.goto(Scene) end
  def after_load_scene
    LOAD_OPENS_JOURNAL ? open! : SceneManager.goto(Scene_Map)
  end
  def end_of_entry!() @use_message_window = nil end
  alias :end_of_message! :end_of_entry!

class KDJournal
  def initialize
    @dates = []
    date = KDDate.new
    entry = KDEntry.new(Start::TITLE.dup)
    entry.location = Start::LOCATION
    entry.texts = Start::TEXT.dup
    date.add_entry(entry)
    add_date(date)
  end

  def add_date(date)
    @dates.unshift(date)
    @last_date = date
  end
  def map(&blk) @dates.map(&blk) end
  def last() @dates[-1] end
  def [](pos) @dates[pos] end
  def empty?() @dates.empty? end
  def any?() @dates.any? end
  def size() @dates.size end
  attr_reader :dates, :last_date
end

class KDDate
  def initialize
    time = Time.now
    @year = time.year
    @month = time.month
    @month_name = time.strftime("%b")
    @day = time.mday
    @day_name = time.strftime("%a")
    @title = "#{@month_name} #{@day}, #{@year}"
    @entries = []
  end

  def same_date?(nyear, nmonth, nday)
    nyear == @year && nmonth == @month && nday == @day
  end

  def add_entry(entry)
    @entries << entry
    @last_entry = entry
  end
  attr_reader :year, :month, :month_name, :day, :day_name, :entries, :last_entry
  attr_accessor :title
end

class KDEntry
  def initialize(new_title)
    @title = new_title
    @location = ""
    @texts = []
  end
  attr_reader :title
  attr_accessor :texts, :location
end

class KDHelpWindow < Window_Base
  def initialize
    x, w = 80, Graphics.width
    super(x, 12, w - x * 2, 52)
  end

  def set_text(text, align=0)
    return if text == @text or align == @align
    @text = text
    @align = align
    refresh
  end

  def refresh
    contents.clear
    draw_text(0, 0, contents_width, 26, @text, @align)
  end
end

class KDListWindow < Window_Selectable
  def initialize(wx, wy, w, h)
    @data = []
    super
    @data = $game_party.journal_entries
    refresh
    select(0)
    activate
  end

  def draw_item(index)
    item = @data[index]
    rect = item_rect(index)
    rect.x += 4
    rect.width -= 8
    draw_text(rect, item.title)
  end

  def refresh
    create_contents
    item_max.times{|i| draw_item(i) }
  end
  def item_max() @data.any? ? @data.size : 1 end
  def item() @data[@index] end
  attr_writer :desc_window
end

class KDDummyWindow < Window_Base
  def initialize(wx, wy, w, h)
    super
    @index = 0
    refresh
  end

  def refresh
    contents.clear
    date = $game_party.journal_entries[@index]
    pages = sprintf(PAGES_FOUND, date.entries.size)
    draw_text(0, 0, contents_width, 24, pages)
  end

  def index=(pos)
    return if @index == pos
    @index = pos
    refresh
  end
end

class KDInfoWindow < Window_Base
  def show_entries(entry)
    self.visible = true
    @entries = entry
    @total = @entries.size
    @index = @total - 1
    @entry = @entries.last
    refresh
  end

  def refresh
    contents.clear
    w = contents_width
    f = contents.font
    f.bold = true
    draw_text(0, 0, w, 24, @entry.title, 1)
    draw_text(4, 32, w, 24, @entry.location)
    f.bold = false
    ly = 64
    @entry.texts.each do |text|
      draw_text(4, ly, w, 24, text)
      ly += 24
    end
    ly = height - 52
    pages = sprintf(PAGES_LABEL, @index + 1, @entries.size)
    draw_text(0, ly, w, 24, pages, PAGES_LABEL_ALIGN)
  end

  def update
    if Input.trigger?(:LEFT)
      return Sound.play_buzzer if @total == 1
      Sound.play_cursor
      @index = (@index - 1) % @total
      @entry = @entries[@index]
      refresh
      return
    elsif Input.trigger?(:RIGHT)
      return Sound.play_buzzer if @total == 1
      Sound.play_cursor
      @index = (@index + 1) % @total
      @entry = @entries[@index]
      refresh
    end
  end
  def clear() contents.clear end
end

class Scene < Scene_Base
  def start
    create_main_viewport
    @stage = SHOW_DATES ? :list : :info
    lx, ly, lw, lh, lbo = LIST_WIN_COORD
    dx, dy, dw, dh, dbo = DUMMY_WIN_COORD
    ix, iy, iw, ih, ibo = INFO_WIN_COORD
    @backdrop = Sprite.new
    if BACKDROP
      @backdrop.bitmap = Cache.title1(BACKDROP).dup
    else
      @backdrop.bitmap = SceneManager.background_bitmap
      @backdrop.color.set(16, 16, 16, 128)
    end
    @help_window = KDHelpWindow.new
    text = sprintf(TITLE, $game_party.name)
    @help_window.set_text(text, TITLE_ALIGN)
    @help_window.back_opacity = HELP_WIN_OPACITY
    @list_window = KDListWindow.new(lx, ly, lw, lh)
    @list_window.back_opacity = lbo
    @list_window.visible = SHOW_DATES
    @dummy_window = KDDummyWindow.new(dx, dy, dw, dh)
    @dummy_window.back_opacity = dbo
    @dummy_window.visible = SHOW_DATES
    @list_window.desc_window = @dummy_window
    @info_window = KDInfoWindow.new(ix, iy, iw, ih)
    @info_window.back_opacity = ibo
    @info_window.visible = !SHOW_DATES
    open_last_entry
  end

  def open_last_entry
    if SHOW_DATES
      date = @list_window.item
      @info_window.show_entries(date.entries)
    else
      entries = $game_party.journal_entries.map{|date| date.entries }
      entries = entries.flatten
      @info_window.show_entries(entries)
    end
    @stage = :info
  end

  def terminate
    super
    @backdrop.bitmap.dispose
    @backdrop.dispose
  end

  def update
    Graphics.update
    Input.update
    case @stage
    when :list
      update_list
    when :info
      update_info
    end
  end

  def update_list
    @list_window.update
    if Input.trigger?(:B)
      Sound.play_cancel
      SceneManager.call(Scene_Map)
      return
    elsif Input.trigger?(:C)
      Sound.play_ok
      @dummy_window.visible = false
      open_last_entry
    end
  end

  def update_info
    @info_window.update
    if Input.trigger?(:B)
      Sound.play_cancel
      unless SHOW_DATES
        SceneManager.call(Scene_Map)
        return
      end
      @info_window.visible = false
      @info_window.clear
      @dummy_window.visible = true
      @stage = :list
    end
  end
end

end

class Game_Party
  alias :kyon_diurnalis_gm_pty_init :initialize
  def initialize
    kyon_diurnalis_gm_pty_init
    @journal_entries = KDiurnalis::KDJournal.new
  end

  def add_journal_entry(title, place)
    place = $game_map.display_name if place == :map
    date = @journal_entries.last_date
    time = Time.now
    KDiurnalis.use_message_window = true
    entry = KDiurnalis::KDEntry.new(title)
    entry.location = place
    if date and date.same_date?(time.year, time.month, time.day)
      date.add_entry(entry)
    else
      date = KDiurnalis::KDDate.new
      date.add_entry(entry)
      @journal_entries.add_date(date)
    end
  end

  def total_journal_entries?(n)
    @journal_entries.size == n
  end

  def last_journal_entry_pages?(n)
    @journal_entries.last.entries.size == n
  end
  attr_reader :journal_entries
end

class Game_Event
  def name() @event.name end
  def name=(text) @event.name = text end
end

class Game_Interpreter
  alias :kyon_diurnalis_gm_int_comm_101 :command_101
  def process_journal_entries
    @index += 1
    date = $game_party.journal_entries.last_date
    entry = date.last_entry
    codes = [101, 401]
    command = @list[@index]
    while codes.include?(command.code)
      if command.code == 401
        line = command.parameters[0]
        line.gsub!(/\\N\[([0-9]+)\]/i) { $game_actors[$1.to_i].name }
        line.gsub!(/\\E\[([0-9]+)\]/i) { $game_map.events[$1.to_i].name }
        entry.texts << line
      end
      @index += 1
      command = @list[@index]
    end
    @index -= 1
    KDiurnalis.end_of_message!
    true
  end

  def command_101
    if KDiurnalis.use_message_window
      process_journal_entries
    else
      kyon_diurnalis_gm_int_comm_101
    end
  end
end

class Scene_Load
  def on_load_success
    Sound.play_load
    fadeout_all
    $game_system.on_after_load
    KDiurnalis.after_load_scene
  end
end



Terms & Conditions

Free as in beer for non commercial games.
Contact me if you want to go commercial. (There will be an inexpensive charge for this script only.)
This is very helpful! can i ask is there any option to have access from the menu too?
Note: I'm about to upload a new demo with the updated version of my script any time soon.

Let's say this is how you'd order the Main Menu commands if you're using the Non-Combat Menu script by mjshi:

Ruby:
module NonCombatMenu
  MENU = [
    ['Journal', :journal]
    ['Items',   :item],
    ['Status', :status],
    ['Save', :save],
    ['Load', :load],
    ['Exit', :shutdown],
  ]
# Several lines of code here

Then you can add this snippet at the end of my KDiurnalis script.

Ruby:
class Scene_End
  def command_journal() SceneManager.call(KDiurnalis::Scene) end
end
By the way, I have uploaded the latest iteration of my script.

Now you don't need leave any script call to end the processing of a given journal entry.
Simply stop adding message windows to your current event and that's it.

Please feel free to check out the demo to find out how you can setup your events and add new entries.
You did wonderfull job with the script!! and thanks for the demo!

Could i suggest some customization options? We could change the size of windows or to show only the text entrys without having to select the date? or opacity options?
I made some references.. Please ignore them if you don't like them..
3.png
4.png

6.png
7.png
Bulk Update!​

All ports of my simple script have been updated a while ago! 😀

Now it is possible to open the last entry of your journal by default.
Besides, you can make the date list window as invisible as a ninja as well.
It is easy to set the initial back opacity of all menu windows.
The latest version also allows you to show either a picture or the map as a backdrop.
Hello! The opacity applies only to the upper window and when i remove the backround image it doesn't show the game's curent map but it's black. check it if you want..

4.png
5.png
First of all, I want to make something clear. You didn't "fix" the window placement. You simply customized it as expected, which is a good thing.

Since the original configuration included a list of dates, I kept most of the window's coordinates intact and left a warning telling game developers that it is not a plug & play script. People are expected to customize the windows, just like you did.

Now let's take a look at your issues.

I think it's weird you get different back opacities for those windows, especially because you posted your customizations in your previous reply. There's only one way to change that opacity and both windows should change it for both of them call the back opacity method and never throw any error message.

I will be checking your no map issue and see if there's something missing.
You didn't "fix" the window placement. You simply customized it as expected
I am extremely sorry!! i didn't said it the right way! i will edit my post to correct it..
actually i will delete all of it (if you need the settings ask me and i will tell you)
Nah, just wait for my next post (or an edit of this one) regarding the missing map background snapshot.

By the way, does the map go missing right after loading a saved game or during gameplay?
In the XP port of my script I added a simple To Do List to my journal. L & R buttons let you switch between the journal and the to do list. Do VX Ace users find it useful as well? Should I include it in the next iteration of KDiurnalis ACE?

Note: Diurnalis means journal in old fashioned Latin.
The script works perfectly! Thank you very much, i loved it!

1.png

Original thread: https://forums.rpgmakerweb.com/threads/kdiurnalis-ace.148557/