Advertisement
AngryPacman

PAC Item Scene

Jul 29th, 2011
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 14.76 KB | None | 0 0
  1. #===============================================================================
  2. #
  3. # Pacman Advanced Creative (PAC) Engine - Item Scene
  4. # 26/5/2011
  5. # Type: Menu
  6. # Installation: Optional stuff.
  7. # Level: Average
  8. # With: Cozziekuns (asissted by Modern Algebra)
  9. #
  10. #===============================================================================
  11. #
  12. # Description:
  13. # This is an inventory screen that sorts your items into categories and displays
  14. # them neatly. It's super sexy, I promise.
  15. #
  16. #===============================================================================
  17. #
  18. # Instructions
  19. # To install this script, open up your script editor and copy/paste this script
  20. # to an open slot below ? Materials but above ? Main. Remember to save.
  21. # Change the modules to your liking. The "hard" parts have instructions of their
  22. # own.
  23. #
  24. #===============================================================================
  25.  
  26. $imported = {} if $imported == nil
  27. $imported["PACItems"] = true
  28.  
  29. module PAC
  30.   module MENU
  31.     DISPLAY_TEXT = "Currently Displayed:"
  32.    
  33. #===============================================================================
  34. # Extra Item Categories (Inspired by Modern Algebra)
  35. # ------------------------------------------------------------------------------
  36. # How should I go about explaining something like this? Well, basically, each
  37. # item in the hash represents a certain category. For example, the first hash we
  38. # see here is:
  39. #
  40. # 0 => [144, "All", false]
  41. #
  42. # The syntax of this is:
  43. #
  44. # Category ID => [Icon Number, Text, Prime]
  45. #
  46. # Probably the most important part, the category ID is the number you want to
  47. # put into the notebox that the item contains. For example, if you wanted to
  48. # make the item "World Map" into a key item, simply add the text:
  49. #
  50. # \item_category[4]
  51. #
  52. # into the notebox. Note that numbers 0, 1, 2, and 3 are special. They're prime
  53. # categories. Sound special right? Not really, this just means you have to have
  54. # them in the inventory for this script to work. I could've gotten rid of them,
  55. # but that would've just given more work on your part (and mine), so bear with
  56. # them, please. Icon Numbers and Text are pretty self explanatory.
  57. #
  58. # Last, but not least, is the "Prime" function (inspired by Kyraiki). Setting
  59. # this to "true" means that anything in the prime category will not show up in
  60. # the item, weapon or armour categories. You can set if you want it to show up
  61. # in all.
  62. #===============================================================================
  63.  
  64.     ITEM_CATEGORIES = {
  65.    
  66.       0 => [144, "All", false],
  67.       1 => [64, "Items", false],
  68.       2 => [26, "Weapons", false],
  69.       3 => [40, "Armours", false],
  70.       4 => [80, "Key Items", true],
  71.       5 => [90, "Filler", false],
  72.       6 => [92, "Scrolling", false],
  73.       7 => [32, "Scrolling", false],
  74.     }
  75.    
  76.     ITEM_CATEGORY_WIDTH = 300 # How wide you want your text window.
  77.     KYRIAKI_ALL_CATEOGRY_PRIME = false # If you want prime key items to show up
  78.     # in the all window.
  79.     MAX_ITEM_ICONS = (544 - ITEM_CATEGORY_WIDTH) / 54 # The maximum
  80.     # number of icons that will fit.
  81.    
  82.   end
  83. end
  84.  
  85. #==============================================================================
  86. # ** RPG::BaseItem
  87. #------------------------------------------------------------------------------
  88. #  The superclass of all states.
  89. #==============================================================================
  90.  
  91. class RPG::BaseItem
  92.   #--------------------------------------------------------------------------
  93.   # * Cozziekuns Category Index
  94.   #--------------------------------------------------------------------------
  95.   def pac_inv_category_index
  96.     @pac_inv_category_index = 0
  97.     if self.note[/\\item_category\[(\d+)]/i] != nil
  98.       @pac_inv_category_index = $1.to_i
  99.     end
  100.   return @pac_inv_category_index
  101.   end
  102. end
  103.  
  104. #==============================================================================
  105. # ** Window_Item
  106. #------------------------------------------------------------------------------
  107. #  This window displays a list of inventory items for the item screen, etc.
  108. #==============================================================================
  109.  
  110. class Window_Item < Window_Selectable
  111.   #--------------------------------------------------------------------------
  112.   # * Refresh
  113.   #--------------------------------------------------------------------------
  114.   alias pac_inv_pis_refresh refresh
  115.   def refresh(sort_index = 0)
  116.    @sort_index = sort_index
  117.    pac_inv_pis_refresh
  118.  end
  119.   #--------------------------------------------------------------------------
  120.   # * Whether or not to include in item list
  121.   #     item : item
  122.   #--------------------------------------------------------------------------
  123.   alias pac_inv_pis_include? include?
  124.   def include?(item)
  125.     val = pac_inv_pis_include?(item)
  126.     return false if !val
  127.     return case @sort_index
  128.       when 0
  129.         unless PAC::MENU::KYRIAKI_ALL_CATEOGRY_PRIME
  130.           if PAC::MENU::ITEM_CATEGORIES[item.pac_inv_category_index][2]
  131.             return false
  132.           else
  133.             return true
  134.           end
  135.         else
  136.           return true
  137.         end
  138.       when 1
  139.         if PAC::MENU::ITEM_CATEGORIES[item.pac_inv_category_index][2]
  140.           return false
  141.         else
  142.           return item.is_a?(RPG::Item)
  143.         end
  144.       when 2
  145.         if PAC::MENU::ITEM_CATEGORIES[item.pac_inv_category_index][2]
  146.           return false
  147.         else
  148.           return item.is_a?(RPG::Weapon)
  149.         end
  150.       when 3
  151.         if PAC::MENU::ITEM_CATEGORIES[item.pac_inv_category_index][2]
  152.           return false
  153.         else
  154.           return item.is_a?(RPG::Armor)
  155.         end
  156.       when 4..999
  157.         return item.pac_inv_category_index == @sort_index
  158.       end
  159.     end
  160.   end
  161.  
  162. #==============================================================================
  163. # ** Window_ItemCategory
  164. #------------------------------------------------------------------------------
  165. #  This window displays what type of item is being displayed.
  166. #==============================================================================
  167.  
  168. class Window_ItemCategory < Window_Base
  169.   #--------------------------------------------------------------------------
  170.   # * Object Initialization
  171.   #     x : window X coordinate
  172.   #     y : window Y coordinate
  173.   #--------------------------------------------------------------------------
  174.   def initialize(x, y, width)
  175.     super(x, y, width, WLH + 32)
  176.     refresh
  177.   end
  178.   #--------------------------------------------------------------------------
  179.   # * Refresh
  180.   #--------------------------------------------------------------------------
  181.   def refresh(sort_index = 0)
  182.     @sort_index = sort_index
  183.     @item_categories = PAC::MENU::ITEM_CATEGORIES
  184.     @item_categories_width = PAC::MENU::ITEM_CATEGORY_WIDTH
  185.     @category_string = PAC::MENU::DISPLAY_TEXT
  186.     self.contents.clear
  187.     self.contents.font.color = system_color
  188.     self.contents.draw_text(4, 0, @item_categories_width - 40, WLH, @category_string, 0)
  189.     self.contents.font.color = normal_color
  190.     for i in 0...@item_categories.size
  191.       if @sort_index == i
  192.         self.contents.draw_text(4, 0, @item_categories_width - 40, WLH, @item_categories[i][1], 2)
  193.       end
  194.     end
  195.   end
  196. end
  197.  
  198. #==============================================================================
  199. # ** Window_ItemSort
  200. #------------------------------------------------------------------------------
  201. #  This window displays what type of item is being displayed.
  202. #==============================================================================
  203.  
  204. class Window_ItemSort < Window_Base
  205.   #--------------------------------------------------------------------------
  206.   # * Object Initialization
  207.   #     x : window X coordinate
  208.   #     y : window Y coordinate
  209.   #--------------------------------------------------------------------------
  210.   def initialize(x, y, width)
  211.     super(x, y, width, WLH + 32)
  212.     @ox = 0
  213.     if PAC::MENU::MAX_ITEM_ICONS < PAC::MENU::ITEM_CATEGORIES.size
  214.       self.contents = Bitmap.new(self.width - 32 + ((PAC::MENU::ITEM_CATEGORIES.size - PAC::MENU::MAX_ITEM_ICONS) * 54), self.height - 32)
  215.     end
  216.     refresh
  217.   end
  218.   #--------------------------------------------------------------------------
  219.   # * Refresh
  220.   #--------------------------------------------------------------------------
  221.   def refresh(sort_index = 0)
  222.     @sort_index = sort_index
  223.     @item_categories = PAC::MENU::ITEM_CATEGORIES
  224.     @item_categories_width = PAC::MENU::ITEM_CATEGORY_WIDTH
  225.     self.contents.clear
  226.     for i in 0...@item_categories.size
  227.       @icon_x = 0 + (i * ((544 - @item_categories_width) / @item_categories.size))
  228.       if @item_categories.size < PAC::MENU::MAX_ITEM_ICONS
  229.         draw_item(i)
  230.       else
  231.         draw_items(i)
  232.       end
  233.       if @sort_index == i
  234.         if @item_categories.size < PAC::MENU::MAX_ITEM_ICONS
  235.           draw_icon(@item_categories[i][0], @icon_x, 0, true)
  236.         else
  237.           draw_icon(@item_categories[i][0], i * 54, 0, true)
  238.         end
  239.       end
  240.     end
  241.   end
  242.   #--------------------------------------------------------------------------
  243.   # * Draw Item
  244.   #     index : item number
  245.   #--------------------------------------------------------------------------
  246.   def draw_item(index)
  247.     icons_x = (544 - @item_categories_width) / @item_categories.size
  248.     draw_icon(@item_categories[index][0], index * icons_x, 0, false)
  249.   end
  250.   #--------------------------------------------------------------------------
  251.   # * Draw Items
  252.   #     index : item number
  253.   #--------------------------------------------------------------------------
  254.   def draw_items(index)
  255.     draw_icon(@item_categories[index][0], index * 54, 0, false)
  256.   end
  257. end
  258.  
  259. #==============================================================================
  260. # ** Window_PACItemHelp
  261. #------------------------------------------------------------------------------
  262. #  This window shows skill and item explanations along with actor status and
  263. #  graphics fit for PAC scripts.
  264. #==============================================================================
  265.  
  266. class Window_PACItemHelp < Window_Base
  267.   def initialize
  268.     super(0, 56, 544, WLH + 32)
  269.   end
  270.   def set_text(text, align = 0)
  271.     if text != @text or align != @align
  272.       self.contents.clear
  273.       self.contents.font.color = normal_color
  274.       self.contents.draw_text(4, 0, self.width - 40, WLH, text, align)
  275.       @text = text
  276.       @align = align
  277.     end
  278.   end
  279. end
  280.  
  281. #==============================================================================
  282. # ** Scene_Item
  283. #------------------------------------------------------------------------------
  284. #  This class performs the item screen procepisng.
  285. #==============================================================================
  286.  
  287. class Scene_Item < Scene_Base
  288.   #--------------------------------------------------------------------------
  289.   # * Start procepisng
  290.   #--------------------------------------------------------------------------
  291.   def start
  292.     super
  293.     create_menu_background
  294.     @viewport = Viewport.new(0, 0, 544, 416)
  295.     @help_window = Window_PACItemHelp.new
  296.     @help_window.viewport = @viewport
  297.     @item_window = Window_Item.new(0, 112, 544, 304)
  298.     @item_window.viewport = @viewport
  299.     @item_window.help_window = @help_window
  300.     @item_window.active = false
  301.     @category_width = PAC::MENU::ITEM_CATEGORY_WIDTH
  302.     @category_window = Window_ItemCategory.new(544 - @category_width, 0, @category_width)
  303.     @sort_window = Window_ItemSort.new(0, 0, 544 - @category_width)
  304.     @target_window = Window_MenuStatus.new(0, 0)
  305.     @sort_index = 0
  306.     @item_categories = PAC::MENU::ITEM_CATEGORIES
  307.     hide_target_window
  308.   end
  309.   #--------------------------------------------------------------------------
  310.   # * Termination Procepisng
  311.   #--------------------------------------------------------------------------
  312.   alias pac_pis_terminate terminate
  313.   def terminate
  314.     super
  315.     pac_pis_terminate
  316.     @sort_window.dispose
  317.     @category_window.dispose
  318.   end
  319.   #--------------------------------------------------------------------------
  320.   # * Update Frame
  321.   #--------------------------------------------------------------------------
  322.   alias pac_pis_update update
  323.   def update
  324.     super
  325.     pac_pis_update
  326.     @sort_window.update
  327.     @category_window.update
  328.   end
  329.   #--------------------------------------------------------------------------
  330.   # * Update Item Selection
  331.   #--------------------------------------------------------------------------
  332.   def update_item_selection
  333.     if Input.trigger?(Input::B)
  334.       Sound.play_cancel
  335.       return_scene
  336.     elsif Input.trigger?(Input::C)
  337.       @item = @item_window.item
  338.       if @item != nil
  339.         $game_party.last_item_id = @item.id
  340.       end
  341.       if $game_party.item_can_use?(@item)
  342.         Sound.play_decision
  343.         determine_item
  344.       else
  345.         Sound.play_buzzer
  346.       end
  347.     elsif Input.trigger?(Input::X)
  348.       @sort_index -= 1
  349.       @sort_index %= @item_categories.size
  350.       if @sort_index + 1 == @item_categories.size
  351.         @sort_window.ox += 54 * (@item_categories.size - PAC::MENU::MAX_ITEM_ICONS)
  352.       else
  353.         if @item_categories.size > PAC::MENU::MAX_ITEM_ICONS and @sort_index > PAC::MENU::MAX_ITEM_ICONS - 2
  354.           @sort_window.ox -= 54
  355.         end
  356.       end
  357.       @category_window.refresh(@sort_index)
  358.       @sort_window.refresh(@sort_index)
  359.       @item_window.refresh(@sort_index)
  360.       @item_window.index = 0
  361.       Sound.play_cursor
  362.     elsif Input.trigger?(Input::Y)
  363.       @sort_index += 1
  364.       @sort_index %= @item_categories.size
  365.       if @sort_index != 0
  366.         if @item_categories.size > PAC::MENU::MAX_ITEM_ICONS and @sort_index > PAC::MENU::MAX_ITEM_ICONS - 1
  367.           @sort_window.ox += 54
  368.         end
  369.       else
  370.         @sort_window.ox = 0
  371.       end
  372.       @category_window.refresh(@sort_index)
  373.       @sort_window.refresh(@sort_index)
  374.       @item_window.refresh(@sort_index)
  375.       @item_window.index = 0
  376.       Sound.play_cursor
  377.     elsif Input.trigger?(Input::A)
  378.       @sort_index -= 1
  379.       @sort_index %= @item_categories.size
  380.       if @sort_index + 1 == @item_categories.size
  381.         @sort_window.ox += 54 * (@item_categories.size - PAC::MENU::MAX_ITEM_ICONS)
  382.       else
  383.         if @item_categories.size > PAC::MENU::MAX_ITEM_ICONS and @sort_index > PAC::MENU::MAX_ITEM_ICONS - 2
  384.           @sort_window.ox -= 54
  385.         end
  386.       end
  387.       @category_window.refresh(@sort_index)
  388.       @sort_window.refresh(@sort_index)
  389.       @item_window.refresh(@sort_index)
  390.       @item_window.index = 0
  391.       Sound.play_cursor
  392.     end
  393.   end
  394. end
  395.  
  396. #===============================================================================
  397. #
  398. # END OF SCRIPT
  399. #
  400. #=================================400 yay=======================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement