TheoAllen

Theo - Story Journal

Sep 24th, 2013
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.51 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. class << DataManager
  119.  
  120.   def load_journal_text
  121.     open_journal_text
  122.     $journal = load_data("Data/Journal.rvdata2")
  123.   end
  124.  
  125.   def open_journal_text
  126.     texts = {}
  127.     key = ""
  128.     File.open("Data/Journal.txt", "r:BOM|UTF-*") do |file|
  129.       file.readlines.each do |txt|
  130.         next if txt =~ /(^\s*(#|\/\/).*|^\s*$)/
  131.         if txt =~ /^\[Title\]\s*(.+)/i
  132.           key = $1.to_s
  133.           texts[key] = ""
  134.         else
  135.           txt.gsub!(/\[line\]/i) {"\n"}
  136.           txt.gsub!(/\[page\]/i) {"<P>"}
  137.           texts[key] += txt
  138.         end
  139.       end
  140.     end
  141.     File.open("Data/Journal.rvdata2", "w") do |file|
  142.       Marshal.dump(texts, file)
  143.     end
  144.   end
  145.  
  146.   alias theo_storyjournal_load_db load_database
  147.   def load_database
  148.     theo_storyjournal_load_db
  149.     load_journal_text if FileTest.exist?("Data/Journal.txt")
  150.   end
  151.  
  152. end
  153.  
  154. class Game_System
  155.   attr_accessor :journal_keys
  156.  
  157.   alias theo_storyjournal_init initialize
  158.   def initialize
  159.     theo_storyjournal_init
  160.     @journal_keys = []
  161.   end
  162. end
  163.  
  164. class Window_JournalList < Window_Selectable
  165.  
  166.   def initialize
  167.     super(0,0,window_width,window_height)
  168.     refresh
  169.     activate
  170.     select(0)
  171.   end
  172.  
  173.   def title_window=(window)
  174.     @title_window = window
  175.     update_help
  176.   end
  177.  
  178.   def window_width
  179.     return Theo::Journal::ListWidth
  180.   end
  181.  
  182.   def window_height
  183.     return Graphics.height
  184.   end
  185.  
  186.   def item_max
  187.     return [$game_system.journal_keys.size,1].max
  188.   end
  189.  
  190.   def draw_item(index)
  191.     rect = item_rect(index)
  192.     rect.x += 4
  193.     draw_text(rect, $game_system.journal_keys[index])
  194.   end
  195.  
  196.   def journal_contents
  197.     $journal[journal_title] || ""
  198.   end
  199.  
  200.   def journal_title
  201.     $game_system.journal_keys[index] || ""
  202.   end
  203.  
  204.   def update_help
  205.     return unless Theo::Journal::InstantRefresh
  206.     @help_window.load_data(journal_contents) if @help_window
  207.     @title_window.set_title(journal_title) if @title_window
  208.   end
  209.  
  210. end
  211.  
  212. class Window_JournalTitle < Window_Base
  213.  
  214.   def initialize(x)
  215.     super(x,0,Graphics.width - x,fitting_height(1))
  216.     set_title("")
  217.   end
  218.  
  219.   def set_title(str)
  220.     @title = str
  221.     refresh
  222.   end
  223.  
  224.   def refresh
  225.     contents.clear
  226.     draw_text(contents.rect,@title,1)
  227.   end
  228.  
  229. end
  230.  
  231. class Window_JournalContents < Window_Base
  232.  
  233.   def initialize(xpos,ypos)
  234.     super(xpos,ypos,Graphics.width - xpos, Graphics.height - ypos)
  235.     @page = 0
  236.     @texts = []
  237.   end
  238.  
  239.   def load_data(str)
  240.     @page = 0
  241.     @texts = str.split(/<P>/i)
  242.     refresh
  243.   end
  244.  
  245.   def refresh
  246.     contents.clear
  247.     draw_contents
  248.     draw_current_page if Theo::Journal::DisplayPage
  249.   end
  250.  
  251.   def draw_contents
  252.     draw_text_ex(4,0,@texts[@page])
  253.   end
  254.  
  255.   def draw_current_page
  256.     reset_font_settings
  257.     ypos = contents.height - line_height
  258.     contents.fill_rect(0,ypos-2,contents.width,2,Color.new(255,255,255,128))
  259.     rect = Rect.new(4,ypos,contents.width-4,line_height)
  260.     pg = sprintf("%d / %d",@page+1,@texts.size)
  261.     draw_text(rect,Theo::Journal::VocabPage)
  262.     draw_text(rect,pg,2)
  263.   end
  264.  
  265.   def update
  266.     super
  267.     next_page if Input.trigger?(:RIGHT)
  268.     prev_page if Input.trigger?(:LEFT)
  269.   end
  270.  
  271.   def next_page
  272.     return if @page + 1 >= @texts.size
  273.     @page += 1
  274.     refresh
  275.   end
  276.  
  277.   def prev_page
  278.     return if @page + 1 <= 1
  279.     @page -= 1
  280.     refresh
  281.   end
  282.  
  283. end
  284.  
  285. class Window_MenuCommand < Window_Command
  286.  
  287.   alias theo_storyjournal_add_ori_cmd add_original_commands
  288.   def add_original_commands
  289.     theo_storyjournal_add_ori_cmd
  290.     return unless Theo::Journal::MainMenu
  291.     add_command(Theo::Journal::VocabCommand, :storyjournal)
  292.   end
  293.  
  294. end
  295.  
  296. class Scene_Menu < Scene_MenuBase
  297.  
  298.   alias theo_storyjournal_cmnd_window create_command_window
  299.   def create_command_window
  300.     theo_storyjournal_cmnd_window
  301.     @command_window.set_handler(:storyjournal, method(:enter_journal))
  302.   end
  303.  
  304.   def enter_journal
  305.     SceneManager.call(Story_Journal)
  306.   end
  307.  
  308. end
  309.  
  310. class Story_Journal < Scene_MenuBase
  311.  
  312.   def start
  313.     super
  314.     create_journal_list
  315.     create_journal_title
  316.     create_journal_contents
  317.   end
  318.  
  319.   def create_journal_list
  320.     @list = Window_JournalList.new
  321.     @list.set_handler(:ok, method(:on_journal_ok))
  322.     @list.set_handler(:cancel, method(:return_scene))
  323.   end
  324.  
  325.   def create_journal_title
  326.     @title = Window_JournalTitle.new(@list.width)
  327.     @title.set_title(@list.journal_title)
  328.   end
  329.  
  330.   def create_journal_contents
  331.     @contents = Window_JournalContents.new(@list.width,@title.height)
  332.     @contents.load_data(@list.journal_contents)
  333.     @list.help_window = @contents
  334.     @list.title_window = @title
  335.   end
  336.  
  337.   def on_journal_ok
  338.     @list.activate
  339.     return if Theo::Journal::InstantRefresh
  340.     @title.set_title(@list.journal_title)
  341.     @contents.load_data(@list.journal_contents)
  342.   end
  343.  
  344. end
Advertisement
Add Comment
Please, Sign In to add comment