Advertisement
Guest User

Simple Journal

a guest
Dec 29th, 2011
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 13.43 KB | None | 0 0
  1. #==============================================================================
  2. #   Simple Journal
  3. #   Author: Nicke
  4. #   Created: 08/13/2011
  5. #   Edited: 08/16/2011
  6. #   Version: 1.0b
  7. #==============================================================================
  8. # Instructions
  9. # -----------------------------------------------------------------------------
  10. # To install this script, open up your script editor and copy/paste this script
  11. # to an open slot below ▼ Materials but above ▼ Main. Remember to save.
  12. # -----------------------------------------------------------------------------
  13. #
  14. # To open Simple Journal use: $scene = Scene_Simple_Journal.new <- In your menu.
  15. #
  16. # Use the call script function to add, remove or complete a quest.
  17. #   Quick example:
  18. #   add_quest(id,type)
  19. #
  20. #   add_quest(1,:main)
  21. #   add_quest(0,:side)
  22. #   complete_quest(0,:side)
  23. #   fail_quest(1,:main)
  24. #
  25. #   Note:
  26. #   In Main quests you should only add 1 quest each time as it is
  27. #   designed that way. However, to make main quest act like side quest page
  28. #   simply set SCROLL_MAIN_QUESTS to true.
  29. #   Every quest stores a variable if it is being completed or failed which then
  30. #   can be used as you want.
  31. #  
  32. #==============================================================================
  33. ($imported ||= {})["NICKE-SIMPLE-JOURNAL"] = true
  34.  
  35. module NICKE
  36.   module JOURNAL_SYSTEM
  37.    
  38.     # --------------------------------------------------------------------------
  39.     # General settings.
  40.     WIDTH = Graphics.width                # Change the width of the journal window.
  41.     HEIGHT = Graphics.height              # Change the height of the journal window.
  42.     FONT_TYPE = ["Rockwell", "Arial"]     # Font type.
  43.     TITLE = "Journal"                     # Journal title text.
  44.     FOOTER = "Use Left/Right to change page." # Footer text.
  45.     NO_ENTRIES = "No entries added..."    # If no quest added show this text.
  46.     COMPLETE_QUEST_VAR = 1                # Variable to store completed quests
  47.     FAILED_QUEST_VAR = 2                  # Variable to store failed quests.
  48.     SCROLL_MAIN_QUESTS = false            # Scroll at Main Quests too?
  49.     # Note: If true, footer will be hidden.
  50.      
  51.     BUTTON_LEFT_PAGE = Input::LEFT        # Button to change page to the left.
  52.     BUTTON_RIGHT_PAGE =  Input::RIGHT     # Button to change page to the right.
  53.    
  54.     BACKGROUND_IMAGE_ACTIVE = false       # Use a background image?
  55.     BACKGROUND_IMAGE = "journal"          # Background image file name.
  56.     # Note: You might need to tweak the height and the position of the window
  57.     # in order for it to be working smoothly with the slider.
  58.    
  59.     RETURN_TO_MAP = false                 # On terminate, go back to map instead?
  60.     # --------------------------------------------------------------------------
  61.     # Color, size and shadow.
  62.     T_FONT_SIZE = 26                                # Title font size.
  63.     T_FONT_COLOR = Color.new(223,255,80)            # Title font color.
  64.     T_FONT_SHADOW = true                            # Title font shadow.
  65.        
  66.     QUEST_HEADER_SIZE = 20                          # Quest Header font size.
  67.     QUEST_HEADER_COLOR = Color.new(135,206,250)     # Quest Header font color.
  68.     QUEST_HEADER_SHADOW = true                      # Quest Header font shadow.
  69.    
  70.     QUEST_DETAILS_SIZE = 16                         # Quest Details font size.
  71.     QUEST_DETAILS_COLOR = Color.new(245,245,245)    # Quest Details font color.
  72.     QUEST_DETAILS_SHADOW = true                     # Quest Details font shadow.
  73.    
  74.     H_FONT_SIZE = 20                                # Header font size.
  75.     H_FONT_COLOR = Color.new(223,255,80)            # Header font color.
  76.     H_FONT_SHADOW = true                            # Header font shadow.
  77.    
  78.     F_FONT_SIZE = 18                                # Footer font size.
  79.     F_FONT_COLOR = Color.new(223,255,80)            # Footer font color.
  80.     F_FONT_SHADOW = true                            # Footer font shadow.
  81.    
  82.     NO_E_FONT_SIZE = 18                             # No entries font size.
  83.     NO_E_FONT_COLOR = Color.new(235,235,160)        # No entries font color.
  84.     NO_E_FONT_SHADOW = true                         # No entries font shadow.  
  85.     # --------------------------------------------------------------------------
  86.     # MAIN QUESTS.
  87.     # Main Quest[Index] = [Icon, "Title", "Details"]
  88.     MAIN_Q_HEADER = "Main Quests"         # Header text for Main quests.
  89.     MAIN_QUESTS = []                      # Don't touch it!
  90.     MAIN_QUESTS[0] = [15, "The Terror in Townsil", "Travel to Townsil and talk to captain awesome."]
  91.     MAIN_QUESTS[1] = [15, "The Terror in Townsil", "Search the town for clues."]
  92.     MAIN_QUESTS[2] = [15, "The Terror in Townsil", "Go back to captain awesome and explain that the situation is crucial."]
  93.     # --------------------------------------------------------------------------
  94.     # SIDE QUESTS.
  95.     # SIDE Quest[Index] = [Icon, "Title", "Details"]
  96.     SIDE_Q_HEADER = "Side Quests"         # Header text for Side quests.
  97.     SIDE_QUESTS = []                      # Don't touch it!
  98.     SIDE_QUESTS[0] = [12, 'Kill the Orcs.', 'Hunt down ten orcs and kill them.']
  99.     SIDE_QUESTS[1] = [75, 'Aid the doctor.', 'Help the doctor by finding the missing herbs.']
  100.     SIDE_QUESTS[2] = [138, 'Find the forgotten girl.', 'Locate the missing girl in the woods.']
  101.     SIDE_QUESTS[3] = [44, 'Armour Reparing.', 'Talk to the local blacksmith to get the armour fixed.']
  102.     SIDE_QUESTS[4] = [151, 'Special Delivery.', 'Take the box filled with unique materials to the mayor in town.']
  103.     SIDE_QUESTS[5] = [64, 'Brew a potion.', 'Gather the missing ingrediens for the health potion.']
  104.     SIDE_QUESTS[6] = [22, 'Solve the bandit problem.', 'Track down and get rid of the bandits that lurks within the deep forest.']
  105.     # --------------------------------------------------------------------------
  106.  
  107.   end
  108. end
  109. # *** Don't edit below unless you know what you are doing. ***
  110. class Game_System
  111.  
  112.   attr_accessor :main_quests
  113.   attr_accessor :side_quests
  114.   attr_accessor :completed_quests
  115.   attr_accessor :failed_quests
  116.  
  117.   alias nicke_quest_initialize initialize unless $@
  118.   def initialize(*args, &block)
  119.     nicke_quest_initialize(*args, &block)
  120.     @main_quests = []
  121.     @side_quests = []
  122.     @completed_quests = [] # Going to be used later on.
  123.     @failed_quests = [] # Going to be used later on.
  124.   end
  125.  
  126. end
  127.  
  128. class Game_Interpreter
  129.  
  130.   include NICKE::JOURNAL_SYSTEM
  131.  
  132.   def add_quest(id, type)
  133.     # Method to add a quest.  
  134.     case type
  135.     when :main # Main quests.
  136.       unless $game_system.main_quests.include?(MAIN_QUESTS[id])
  137.         $game_system.main_quests.push(MAIN_QUESTS[id])
  138.       end unless MAIN_QUESTS[id].nil?
  139.     when :side # Side quests.
  140.       unless $game_system.side_quests.include?(SIDE_QUESTS[id])
  141.         $game_system.side_quests.push(SIDE_QUESTS[id])
  142.       end unless SIDE_QUESTS[id].nil?
  143.     end
  144.   end
  145.  
  146.   def complete_quest(id, type)
  147.     # Method to complete a quest.
  148.     case type
  149.     when :main # Main quests.
  150.       if $game_system.main_quests.include?(MAIN_QUESTS[id])
  151.         $game_system.main_quests.delete(MAIN_QUESTS[id])
  152.         $game_system.completed_quests.push(MAIN_QUESTS[id])      
  153.         $game_variables[COMPLETE_QUEST_VAR] += 1
  154.       end
  155.     when :side # Side quests.
  156.       if $game_system.side_quests.include?(SIDE_QUESTS[id])
  157.         $game_system.side_quests.delete(SIDE_QUESTS[id])
  158.         $game_system.completed_quests.push(SIDE_QUESTS[id])
  159.         $game_variables[COMPLETE_QUEST_VAR] += 1
  160.       end
  161.     end
  162.   end
  163.  
  164.   def fail_quest(id, type)
  165.     # Method for quest failed.
  166.     case type
  167.     when :main # Main quests.
  168.       unless MAIN_QUESTS[id].nil?
  169.         $game_system.main_quests.delete(MAIN_QUESTS[id])
  170.         $game_system.failed_quests.push(MAIN_QUESTS[id])
  171.         $game_variables[FAILED_QUEST_VAR] += 1
  172.       end
  173.     when :side # Side quests.
  174.       unless SIDE_QUESTS[id].nil?
  175.         $game_system.side_quests.delete(SIDE_QUESTS[id])
  176.         $game_system.failed_quests.push(SIDE_QUESTS[id])
  177.         $game_variables[FAILED_QUEST_VAR] += 1
  178.       end
  179.     end
  180.   end
  181.  
  182. end
  183.  
  184. class Scene_Simple_Journal < Scene_Base
  185.  
  186.   include NICKE::JOURNAL_SYSTEM
  187.  
  188.   def start
  189.     # Create the bg if true and make a new instance of Window_Simple_Journal.
  190.     super()
  191.     @journal_window = Window_Simple_Journal.new(true)
  192.     if BACKGROUND_IMAGE_ACTIVE == true
  193.       create_bg
  194.       @journal_window.opacity = 0
  195.     end
  196.   end
  197.  
  198.   def create_bg
  199.     # Method for creating the background image.
  200.     @bg = Sprite.new
  201.     @bg.bitmap = Cache.picture(BACKGROUND_IMAGE)
  202.   end
  203.  
  204.   def update
  205.     super
  206.     # Method for checking input triggers.
  207.     if Input.trigger?(Input::B)
  208.       Sound.play_cancel
  209.       if RETURN_TO_MAP == true
  210.         $scene = Scene_Map.new
  211.       else
  212.         $scene = Scene_Menu.new(0)
  213.       end
  214.     elsif Input.trigger?(BUTTON_LEFT_PAGE) || Input.trigger?(BUTTON_RIGHT_PAGE)
  215.       Sound.play_decision
  216.       main = @journal_window.main
  217.       @journal_window.dispose
  218.       @journal_window = Window_Simple_Journal.new(!main)
  219.     elsif Input.trigger?(Input::UP)
  220.       y = @journal_window.oy
  221.       @journal_window.oy = [y - 52, 0].max
  222.     elsif Input.trigger?(Input::DOWN)
  223.       return if @journal_window.contents.height < @journal_window.height
  224.       y = @journal_window.oy
  225.       @journal_window.oy = [y + 52, @journal_window.height - y + 16].min
  226.     end
  227.     @journal_window.opacity = 0 if BACKGROUND_IMAGE_ACTIVE == true
  228.   end
  229.  
  230.   def terminate(*args, &block)
  231.     # Method for disposing the bg and the journal window.
  232.     super
  233.     @journal_window.dispose
  234.     @bg.dispose if BACKGROUND_IMAGE_ACTIVE == true
  235.   end
  236.  
  237. end
  238.  
  239. class Window_Simple_Journal < Window_Base
  240.  
  241.   include NICKE::JOURNAL_SYSTEM
  242.  
  243.   attr_reader :main
  244.  
  245.   def initialize(main = true)
  246.     super(0,0,WIDTH, HEIGHT)
  247.     @main = main
  248.     # This will allow scrolling if there are too many items.
  249.     if !@main
  250.         self.contents = Bitmap.new(self.width - 32, HEIGHT - 56 + ($game_system.side_quests.size - 1) * WLH)
  251.     else
  252.         self.contents = Bitmap.new(self.width - 32, HEIGHT - 56 + ($game_system.main_quests.size - 1) * WLH) unless SCROLL_MAIN_QUESTS != true
  253.     end
  254.     refresh
  255.   end
  256.  
  257.   def refresh
  258.     self.contents.clear
  259.     # Add Graphics.
  260.     addGraphics
  261.     # Add Quests.
  262.     addQuests
  263.   end
  264.  
  265.   def self_rect
  266.     # Return the value of contents rect.
  267.     return self.contents.rect
  268.   end
  269.  
  270.   def draw_text(x, y, text, align)
  271.     # Method for drawing the text.
  272.     title = self_rect
  273.     title.x = x
  274.     title.y = y
  275.     title.height = 28
  276.     self.contents.draw_text(title,text,align)
  277.   end
  278.  
  279.   def draw_line(x, y)
  280.     # Create two lines actually, one is acting like the shadow.
  281.     line = self_rect
  282.     line.height = 1
  283.     line.width -= 10
  284.     line.x = x
  285.     line.y = y
  286.     self.contents.fill_rect(line,normal_color)
  287.     line.y += 1
  288.     color = Color.new(0,0,0,200)
  289.     self.contents.fill_rect(line,color)
  290.   end
  291.  
  292.   def addQuests
  293.     if @main
  294.       # Fill it with the current main quest data.
  295.       quests = $game_system.main_quests
  296.     else
  297.       # Fill it with the current side quest data.
  298.       quests = $game_system.side_quests
  299.     end
  300.     # If no quests have been added show no entries instead.
  301.     if quests.empty?
  302.       contents.font.name = FONT_TYPE
  303.       contents.font.size = NO_E_FONT_SIZE
  304.       contents.font.color = NO_E_FONT_COLOR
  305.       contents.font.shadow = NO_E_FONT_SHADOW
  306.       draw_text(0, 160, NO_ENTRIES, 1)
  307.       return  
  308.     end
  309.     yoff = WLH * 2
  310.     quests.each_with_index { |q, i|
  311.       draw_icon( q[0], 0, i * yoff + 84) ;
  312.       # Font, size, color & shadow.
  313.       contents.font.name = FONT_TYPE
  314.       contents.font.size = QUEST_HEADER_SIZE
  315.       contents.font.color = QUEST_HEADER_COLOR
  316.       contents.font.shadow = QUEST_HEADER_SHADOW
  317.       self.contents.draw_text(10, 68 + i * yoff, self.contents.width - 16, WLH, q[1], 1)
  318.       contents.font.name = FONT_TYPE
  319.       contents.font.size = QUEST_DETAILS_SIZE
  320.       contents.font.color = QUEST_DETAILS_COLOR
  321.       contents.font.shadow = QUEST_DETAILS_SHADOW
  322.       self.contents.draw_text(27, 60 + (i * yoff)+WLH, self.contents.width - 16, WLH, q[2])
  323.     }
  324.   end
  325.  
  326.   def addGraphics
  327.       # Method for drawing the graphics and some headers.
  328.       self.contents.font.name = FONT_TYPE
  329.       self.contents.font.size = T_FONT_SIZE
  330.       self.contents.font.color = T_FONT_COLOR
  331.       self.contents.font.shadow = T_FONT_SHADOW
  332.       draw_text(0, 0, TITLE, 1) if BACKGROUND_IMAGE_ACTIVE != true
  333.       self.contents.font.name = FONT_TYPE
  334.       self.contents.font.size = H_FONT_SIZE
  335.       self.contents.font.color = H_FONT_COLOR
  336.       self.contents.font.shadow = H_FONT_SHADOW
  337.       if @main
  338.         draw_text(0, 42, MAIN_Q_HEADER, 1)
  339.         self.contents.font.name = FONT_TYPE
  340.         self.contents.font.size = F_FONT_SIZE
  341.         self.contents.font.color = F_FONT_COLOR
  342.         self.contents.font.shadow = F_FONT_SHADOW
  343.         draw_text(0,360, FOOTER, 1) unless SCROLL_MAIN_QUESTS == true
  344.         draw_line(5,356)            unless SCROLL_MAIN_QUESTS == true
  345.       else
  346.         draw_text(0, 42, SIDE_Q_HEADER, 1)
  347.       end
  348.       draw_line(5,36) if BACKGROUND_IMAGE_ACTIVE != true
  349.   end
  350.  
  351. end # END OF FILE
  352.  
  353. #=*==========================================================================*=#
  354. # ** END OF FILE
  355. #=*==========================================================================*=#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement