TheoAllen

Story Journal EX

Jan 14th, 2014
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.46 KB | None | 0 0
  1. # =============================================================================
  2. # TheoAllen - Story Journal
  3. # Version : 1.0
  4. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # (This script documentation is written in informal indonesian language)
  6. # =============================================================================
  7. ($imported ||={})[:Theo_StoryJournal] = true
  8. # =============================================================================
  9. # CHANGE LOGS:
  10. # -----------------------------------------------------------------------------
  11. # 2013.09.26 - Finished documentation
  12. # 2013.09.25 - Finished script
  13. # =============================================================================
  14. =begin
  15.  
  16.   Perkenalan :
  17.   Script ini ngebikin kamu bisa nambahin jurnal sederhana pada game untuk
  18.   keperluan cerita atau yang lain.
  19.  
  20.   ---------------------------------------------------------------------------
  21.   Cara penggunaan :
  22.   Pasang script ini dibawah material namun diatas main
  23.   Buat file dengan nama Journal.txt di dalam folder Data
  24.   Lalu tulis jurnal ceritanya disana. dengan format seperti berikut
  25.  
  26.   ---------------------
  27.   [Title] Judul cerita
  28.   Konten cerita Konten cerita Konten cerita Konten cerita Konten cerita
  29.   Konten cerita Konten cerita Konten cerita Konten cerita Konten cerita
  30.   Konten cerita Konten cerita Konten cerita Konten cerita Konten cerita
  31.   <P>Konten cerita Konten cerita Konten cerita Konten cerita Konten cerita
  32.   Konten cerita Konten cerita Konten cerita Konten cerita Konten cerita
  33.   Konten cerita Konten cerita Konten cerita Konten cerita Konten cerita
  34.  
  35.   Gunakan <P> ato [page] buat misahin konten cerita pada page yg berbeda.
  36.   Kamu juga bisa gunain escape character yang ada dalam message seperti
  37.   \C[1], \N[1], \V[1] dst ...
  38.  
  39.   Contoh :
  40.   ---------------------
  41.   [Title] Lipsum
  42.   Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean in ultrices
  43.   nulla, vel pharetra diam. Nunc faucibus pretium leo, a lacinia erat posuere
  44.   ut. Etiam porttitor enim et bibendum facilisis. Praesent eu elit ut metus
  45.   tempus aliquet. Cras tempor mauris sapien, ut laoreet quam condimentum ut.
  46.   <P>Aliquam aliquet ut quam vel sollicitudin. Fusce vestibulum semper sapien
  47.   nec luctus. Sed rhoncus, neque vitae
  48.  
  49.   ---------------------
  50.   Untuk menambahkan dan mengurangi isi jurnal tinggal panggil script call
  51.   berikut :
  52.   - add_journal("title")
  53.   - remove_journal("title")
  54.   - clear_journal
  55.  
  56.   Dimana title adalah judul dari konten cerita.
  57.   Untuk masuk ke dalam journal, bisa dengan menggunakan script call
  58.   - SceneManager.call(Story_Journal)
  59.  
  60.   ---------------------------------------------------------------------------
  61.   Terms of use :
  62.   Credit gw, TheoAllen. Kalo semisal u bisa ngedit2 script gw trus jadi lebih
  63.   keren, terserah. Ane bebasin. Asal ngga ngeklaim aja. Kalo semisal mau
  64.   dipake buat komersil, jangan lupa, gw dibagi gratisannya.
  65.  
  66. =end
  67. # =============================================================================
  68. # Konfigurasi :
  69. # =============================================================================
  70. module Theo
  71.   module Journal
  72.   # --------------------------------------------------------------------------
  73.   # Setting umum
  74.   # --------------------------------------------------------------------------
  75.     InstantRefresh  = true
  76.   # Jika false, maka untuk mengganti isi konten cerita, player harus nekan
  77.   # action button terlebih dahulu. Jika true, maka setiap ganti judul, konten
  78.   # akan langsung diganti (ga paham? eksperimen aja sendiri)
  79.    
  80.     MainMenu        = true
  81.   # Jika true, maka jurnal dapat dibuka di dalam main menu
  82.  
  83.     DisplayPage     = true
  84.   # Bagi kalian-kalian yang ngga pengen nampilin page dalam journal, kalian
  85.   # bisa ngisi ini dengan false
  86.  
  87.     ListWidth       = 200
  88.   # Lebar window untuk list judul
  89.  
  90.   # --------------------------------------------------------------------------
  91.   # Kosakata
  92.   # --------------------------------------------------------------------------
  93.     VocabPage     = "Page :"    # Kosakata untuk halaman
  94.     VocabCommand  = "Journal"   # Kosakata untuk command yang ada di main menu
  95.    
  96.   end
  97. end
  98. # =============================================================================
  99. # Akhir dari konfigurasi ~ !
  100. # =============================================================================
  101. class Game_Interpreter
  102.  
  103.   def add_journal(title)
  104.     return if $game_system.journal_keys.include?(title)
  105.     $game_system.journal_keys.push(title)
  106.   end
  107.  
  108.   def clear_journal
  109.     $game_system.journal_keys.clear
  110.   end
  111.  
  112.   def remove_journal(title)
  113.     $game_system.journal_keys.delete(title)
  114.   end
  115.  
  116. end
  117.  
  118. # -----------------------------------------------------------------------------
  119. # Updates version 1.1
  120. # Window content caches
  121. # -----------------------------------------------------------------------------
  122. class << Cache
  123.  
  124.   def journal_cache(key, bmp)
  125.     @journal ||= {}
  126.     @journal[key] = Bitmap.new(bmp.width, bmp.height)
  127.     @journal[key].blt(0,0,bmp,bmp.rect)
  128.   end
  129.  
  130.   def journal_bmp(key)
  131.     @journal ||= {}
  132.     @journal[key]
  133.   end
  134.  
  135. end
  136.  
  137. class << DataManager
  138.  
  139.   def load_journal_text
  140.     open_journal_text
  141.     $journal = load_data("Data/Journal.rvdata2")
  142.   end
  143.  
  144.   def open_journal_text
  145.     texts = {}
  146.     key = ""
  147.     File.open("Data/Journal.txt", "r:BOM|UTF-*") do |file|
  148.       file.readlines.each do |txt|
  149.         next if txt =~ /(^\s*(#|\/\/).*|^\s*$)/
  150.         if txt =~ /^\[Title\]\s*(.+)/i
  151.           key = $1.to_s
  152.           texts[key] = ""
  153.         else
  154.           txt.gsub!(/\[line\]/i) {"\n"}
  155.           txt.gsub!(/\[page\]/i) {"<P>"}
  156.           texts[key] += txt
  157.         end
  158.       end
  159.     end
  160.     File.open("Data/Journal.rvdata2", "w") do |file|
  161.       Marshal.dump(texts, file)
  162.     end
  163.   end
  164.  
  165.   alias theo_storyjournal_load_db load_database
  166.   def load_database
  167.     theo_storyjournal_load_db
  168.     load_journal_text if FileTest.exist?("Data/Journal.txt")
  169.   end
  170.  
  171. end
  172.  
  173. class Game_System
  174.   attr_accessor :journal_keys
  175.  
  176.   alias theo_storyjournal_init initialize
  177.   def initialize
  178.     theo_storyjournal_init
  179.     @journal_keys = []
  180.   end
  181. end
  182.  
  183. class Window_JournalList < Window_Selectable
  184.  
  185.   def initialize
  186.     super(0,0,window_width,window_height)
  187.     refresh
  188.     activate
  189.     select(0)
  190.   end
  191.  
  192.   def title_window=(window)
  193.     @title_window = window
  194.     update_help
  195.   end
  196.  
  197.   def window_width
  198.     return Theo::Journal::ListWidth
  199.   end
  200.  
  201.   def window_height
  202.     return Graphics.height
  203.   end
  204.  
  205.   def item_max
  206.     return [$game_system.journal_keys.size,1].max
  207.   end
  208.  
  209.   def draw_item(index)
  210.     rect = item_rect(index)
  211.     rect.x += 4
  212.     draw_text(rect, $game_system.journal_keys[index])
  213.   end
  214.  
  215.   def journal_contents
  216.     $journal[journal_title] || ""
  217.   end
  218.  
  219.   def journal_title
  220.     $game_system.journal_keys[index] || ""
  221.   end
  222.  
  223.   def update_help
  224.     return unless Theo::Journal::InstantRefresh
  225.     if @help_window
  226.       @help_window.set_title(journal_title)
  227.     end
  228.     @title_window.set_title(journal_title) if @title_window
  229.   end
  230.  
  231. end
  232.  
  233. class Window_JournalTitle < Window_Base
  234.  
  235.   def initialize(x)
  236.     super(x,0,Graphics.width - x,fitting_height(1))
  237.     set_title("")
  238.   end
  239.  
  240.   def set_title(str)
  241.     @title = str
  242.     refresh
  243.   end
  244.  
  245.   def refresh
  246.     contents.clear
  247.     draw_text(contents.rect,@title,1)
  248.   end
  249.  
  250. end
  251.  
  252. class Window_JournalContents < Window_Base
  253.  
  254.   def initialize(xpos,ypos)
  255.     super(xpos,ypos,Graphics.width - xpos, Graphics.height - ypos)
  256.     @page = 0
  257.     @texts = []
  258.     @title = ""
  259.   end
  260.  
  261.   def set_title(title)
  262.     @title = title
  263.     load_data(journal_contents)
  264.   end
  265.  
  266.   def journal_contents
  267.     $journal[@title] || ""
  268.   end
  269.  
  270.   def load_data(str)
  271.     @page = 0
  272.     @texts = str.split(/<P>/i)
  273.     refresh
  274.   end
  275.  
  276.   def get_cache
  277.     Cache.journal_bmp([@title, @page])
  278.   end
  279.  
  280.   def set_cache
  281.     Cache.journal_cache([@title, @page], contents)
  282.   end
  283.  
  284.   def refresh
  285.     contents.clear
  286.     if get_cache
  287.       draw_cached_bitmap
  288.     else
  289.       draw_contents
  290.       draw_current_page if Theo::Journal::DisplayPage
  291.       set_cache
  292.     end
  293.   end
  294.  
  295.   def draw_cached_bitmap
  296.     contents.blt(0,0,get_cache, get_cache.rect)
  297.   end
  298.  
  299.   def draw_contents
  300.     draw_text_ex(4,0,@texts[@page])
  301.   end
  302.  
  303.   def draw_current_page
  304.     reset_font_settings
  305.     ypos = contents.height - line_height
  306.     contents.fill_rect(0,ypos-2,contents.width,2,Color.new(255,255,255,128))
  307.     rect = Rect.new(4,ypos,contents.width-4,line_height)
  308.     pg = sprintf("%d / %d",@page+1,@texts.size)
  309.     draw_text(rect,Theo::Journal::VocabPage)
  310.     draw_text(rect,pg,2)
  311.   end
  312.  
  313.   def update
  314.     super
  315.     next_page if Input.trigger?(:RIGHT)
  316.     prev_page if Input.trigger?(:LEFT)
  317.   end
  318.  
  319.   def next_page
  320.     return if @page + 1 >= @texts.size
  321.     @page += 1
  322.     refresh
  323.   end
  324.  
  325.   def prev_page
  326.     return if @page + 1 <= 1
  327.     @page -= 1
  328.     refresh
  329.   end
  330.  
  331. end
  332.  
  333. class Window_MenuCommand < Window_Command
  334.  
  335.   alias theo_storyjournal_add_ori_cmd add_original_commands
  336.   def add_original_commands
  337.     theo_storyjournal_add_ori_cmd
  338.     return unless Theo::Journal::MainMenu
  339.     add_command(Theo::Journal::VocabCommand, :storyjournal)
  340.   end
  341.  
  342. end
  343.  
  344. class Scene_Menu < Scene_MenuBase
  345.  
  346.   alias theo_storyjournal_cmnd_window create_command_window
  347.   def create_command_window
  348.     theo_storyjournal_cmnd_window
  349.     @command_window.set_handler(:storyjournal, method(:enter_journal))
  350.   end
  351.  
  352.   def enter_journal
  353.     SceneManager.call(Story_Journal)
  354.   end
  355.  
  356. end
  357.  
  358. class Story_Journal < Scene_MenuBase
  359.  
  360.   def start
  361.     super
  362.     create_journal_list
  363.     create_journal_title
  364.     create_journal_contents
  365.   end
  366.  
  367.   def create_journal_list
  368.     @list = Window_JournalList.new
  369.     @list.set_handler(:ok, method(:on_journal_ok))
  370.     @list.set_handler(:cancel, method(:return_scene))
  371.   end
  372.  
  373.   def create_journal_title
  374.     @title = Window_JournalTitle.new(@list.width)
  375.     @title.set_title(@list.journal_title)
  376.   end
  377.  
  378.   def create_journal_contents
  379.     @contents = Window_JournalContents.new(@list.width,@title.height)
  380.     @contents.load_data(@list.journal_contents)
  381.     @list.help_window = @contents
  382.     @list.title_window = @title
  383.   end
  384.  
  385.   def on_journal_ok
  386.     @list.activate
  387.     return if Theo::Journal::InstantRefresh
  388.     @title.set_title(@list.journal_title)
  389.     @contents.load_data(@list.journal_contents)
  390.   end
  391.  
  392. end
Advertisement
Add Comment
Please, Sign In to add comment