Advertisement
roninator2

Kid Friendly Basic Quest - Item Menu

Dec 14th, 2024
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 13.87 KB | None | 0 0
  1. # ╔═════════════════════════════════════╦════════════════════╗
  2. # ║ Title: KFBQ Item Menu Functions     ║  Version: 1.00     ║
  3. # ║ Author: Roninator2                  ║                    ║
  4. # ╠═════════════════════════════════════╬════════════════════╣
  5. # ║ Function:                           ║   Date Created     ║
  6. # ║                                     ╠════════════════════╣
  7. # ║   FFMQ Style Item Screens           ║    09 Mar 2023     ║
  8. # ╚═════════════════════════════════════╩════════════════════╝
  9. # ╔══════════════════════════════════════════════════════════╗
  10. # ║ Instructions:                                            ║
  11. # ║                                                          ║
  12. # ║  Set the Windows to look like FFMQ.                      ║
  13. # ║                                                          ║
  14. # ║  Due to the nature of how this script works, a note tag  ║
  15. # ║  is used to stop database entries from showing up in the ║
  16. # ║  menu. use note tag <kfbq exclude> to prevent an item    ║
  17. # ║  from showing in the item menu in game.                  ║
  18. # ║                                                          ║
  19. # ║  Use note tag <bomb> to indicate if a weapon is a bomb.  ║
  20. # ║  Then the item will be treated differently.              ║
  21. # ║  It will have a specified number of uses attached to it. ║
  22. # ║                                                          ║
  23. # ╚══════════════════════════════════════════════════════════╝
  24. # ╔══════════════════════════════════════════════════════════╗
  25. # ║ Terms of use:                                            ║
  26. # ║ Free for all uses in RPG Maker - Except nudity           ║
  27. # ╚══════════════════════════════════════════════════════════╝
  28.  
  29. #==============================================================================
  30. # ■ RPG::BaseItem
  31. #==============================================================================
  32. class RPG::BaseItem
  33.   def kfbq_exclude?
  34.     @note =~ /<kfbq exclude>/i
  35.   end
  36.   def bomb_item?
  37.     @note =~ /<bomb>/i
  38.   end
  39. end
  40.  
  41. #==============================================================================
  42. # ** Window_Help
  43. #==============================================================================
  44. class Window_ItemHelp < Window_Base
  45.   #--------------------------------------------------------------------------
  46.   # * Object Initialization
  47.   #--------------------------------------------------------------------------
  48.   def initialize(line_number = 1)
  49.     super(0, 0, Graphics.width / 2, fitting_height(line_number))
  50.   end
  51.   #--------------------------------------------------------------------------
  52.   # * Set Text
  53.   #--------------------------------------------------------------------------
  54.   def set_text(text)
  55.     if text != @text
  56.       @text = text
  57.       refresh
  58.     end
  59.   end
  60.   #--------------------------------------------------------------------------
  61.   # * Clear
  62.   #--------------------------------------------------------------------------
  63.   def clear
  64.     set_text("")
  65.   end
  66.   #--------------------------------------------------------------------------
  67.   # * Set Item
  68.   #     item : Skills and items etc.
  69.   #--------------------------------------------------------------------------
  70.   def set_item(item)
  71.     set_text(item ? item.name : "")
  72.   end
  73.   #--------------------------------------------------------------------------
  74.   # * Refresh
  75.   #--------------------------------------------------------------------------
  76.   def refresh
  77.     contents.clear
  78.     draw_text_ex(4, 0, @text)
  79.   end
  80. end
  81.  
  82. #==============================================================================
  83. # ** Window_Item_Command
  84. #==============================================================================
  85. class Window_Item_Command < Window_Base
  86.   #--------------------------------------------------------------------------
  87.   # initialize
  88.   #--------------------------------------------------------------------------
  89.   def initialize
  90.     super(Graphics.width / 2 + 60, 0, Graphics.width / 2 - 60, fitting_height(1))
  91.     refresh
  92.   end
  93.   #--------------------------------------------------------------------------
  94.   # dispose
  95.   #--------------------------------------------------------------------------
  96.   def dispose
  97.     contents.dispose unless disposed?
  98.     super unless disposed?
  99.   end
  100.   #--------------------------------------------------------------------------
  101.   # refresh
  102.   #--------------------------------------------------------------------------
  103.   def refresh
  104.     contents.clear
  105.     change_color(crisis_color)
  106.     name = "Items"
  107.     draw_text(4, 0, 200, line_height, name, 1)
  108.   end
  109. end
  110.  
  111. #==============================================================================
  112. # ** Window_ItemList
  113. #==============================================================================
  114. class Window_ItemList < Window_Selectable
  115.   #--------------------------------------------------------------------------
  116.   # * Object Initialization
  117.   #--------------------------------------------------------------------------
  118.   def initialize(x, y, width, height)
  119.     super
  120.     self.back_opacity = 255
  121.     @category = :none
  122.     @data = []
  123.   end
  124.   #--------------------------------------------------------------------------
  125.   # *  Column Maximum
  126.   #--------------------------------------------------------------------------
  127.   def col_max
  128.     return 4
  129.   end
  130.   #--------------------------------------------------------------------------
  131.   # * Get Item Height
  132.   #--------------------------------------------------------------------------
  133.   def item_height
  134.     return 60
  135.   end
  136.   #--------------------------------------------------------------------------
  137.   # * Get Activation State of Selection Item
  138.   #--------------------------------------------------------------------------
  139.   def current_item_enabled?
  140.     return true
  141.   end
  142.   #--------------------------------------------------------------------------
  143.   # * Include in Item List?
  144.   #--------------------------------------------------------------------------
  145.   def include?(item)
  146.     case @category
  147.     when :item
  148.       item.is_a?(RPG::Item) && !item.kfbq_exclude?
  149.     else
  150.       false
  151.     end
  152.   end
  153.   #--------------------------------------------------------------------------
  154.   # * Display in Enabled State?
  155.   #--------------------------------------------------------------------------
  156.   def enable?(item)
  157.     $game_party.usable?(item)
  158.   end
  159.   #--------------------------------------------------------------------------
  160.   # * Create Item List
  161.   #--------------------------------------------------------------------------
  162.   def make_item_list
  163.     @data = []
  164.     subtract = 0
  165.     for i in 1..$data_items.size - 1
  166.       item = $data_items[i]
  167.       if !item.kfbq_exclude?
  168.         @data[i-1] = nil unless !@data[i-1].nil?
  169.       else
  170.         subtract += 1
  171.         next
  172.       end
  173.       if $game_party.has_item?(item)
  174.         item.note.split(/[\r\n]+/).each { |line|
  175.           case line
  176.           when /<position:[-_ ](\d+)>/i
  177.             pos = $1.to_i
  178.             @data[pos-1-subtract] = item
  179.           end
  180.         }
  181.       end
  182.     end
  183.   end
  184.   #--------------------------------------------------------------------------
  185.   # * Draw Item
  186.   #--------------------------------------------------------------------------
  187.   def draw_item(index)
  188.     item = @data[index]
  189.     if item
  190.       rect = item_rect(index)
  191.       rect.width -= 4
  192.       draw_icon(item.icon_index, rect.x+3, rect.y+2, enable?(item))
  193.       draw_item_number(rect, item) unless item.key_item?
  194.     end
  195.   end
  196.   #--------------------------------------------------------------------------
  197.   # * Draw Number of Items
  198.   #--------------------------------------------------------------------------
  199.   def draw_item_number(rect, item)
  200.     make_font_bigger
  201.     rect.y -= 10
  202.     rect.x -= 10
  203.     draw_text(rect, sprintf("%2d", $game_party.item_number(item)),1) if $game_party.item_number(item) > 1
  204.     make_font_smaller
  205.   end
  206.   #--------------------------------------------------------------------------
  207.   # * Item Rect
  208.   #--------------------------------------------------------------------------
  209.   def item_rect(index)
  210.     rect = Rect.new
  211.     rect.width = 60
  212.     rect.height = 60
  213.     rect.x = index % col_max * (60)
  214.     rect.y = index / col_max * (60)
  215.     rect
  216.   end
  217.   #--------------------------------------------------------------------------
  218.   # * Update Help Text
  219.   #--------------------------------------------------------------------------
  220.   def update_help
  221.     @help_window.set_item(item)
  222.   end
  223.   #--------------------------------------------------------------------------
  224.   # * Refresh
  225.   #--------------------------------------------------------------------------
  226.   def refresh
  227.     @category = :item
  228.     make_item_list
  229.     create_contents
  230.     draw_all_items
  231.   end
  232. end
  233.  
  234. #==============================================================================
  235. # ** Scene_Item
  236. #==============================================================================
  237. class Scene_Item < Scene_ItemBase
  238.   #--------------------------------------------------------------------------
  239.   # * Start Processing
  240.   #--------------------------------------------------------------------------
  241.   def start
  242.     super
  243.     create_help_window
  244.     create_item_window
  245.     create_item_command
  246.     create_spell_window2
  247.     create_spell_count_window
  248.   end
  249.   #--------------------------------------------------------------------------
  250.   # * Create Help Window
  251.   #--------------------------------------------------------------------------
  252.   def create_help_window
  253.     @help_window = Window_ItemHelp.new
  254.     @help_window.viewport = @viewport
  255.   end
  256.   #--------------------------------------------------------------------------
  257.   # * Create Item Command Text Window
  258.   #--------------------------------------------------------------------------
  259.   def create_item_command
  260.     @command_window = Window_Item_Command.new
  261.     @command_window.viewport = @viewport
  262.   end
  263.   #--------------------------------------------------------------------------
  264.   # * Create Item Window
  265.   #--------------------------------------------------------------------------
  266.   def create_item_window
  267.     wh = Graphics.height - 148
  268.     @item_window = Window_ItemList.new(0, 48, Graphics.width / 2, wh)
  269.     @item_window.viewport = @viewport
  270.     @item_window.help_window = @help_window
  271.     @item_window.set_handler(:ok,     method(:on_item_ok))
  272.     @item_window.set_handler(:cancel, method(:return_scene))
  273.     @item_window.refresh
  274.     @item_window.activate
  275.     @item_window.select(0)
  276.   end
  277.   #--------------------------------------------------------------------------
  278.   # * Create Item Window2
  279.   #--------------------------------------------------------------------------
  280.   def create_spell_window2
  281.     ww = Graphics.width / 2
  282.     wh = Graphics.height - 208
  283.     @spell_window2 = Window_SpellList.new(ww, 48, ww, wh)
  284.     @spell_window2.actor = $game_party.members[1]
  285.     @spell_window2.viewport = @viewport
  286.     @spell_window2.help_window = @help_window
  287.     @spell_window2.actor = $game_party.members[1]
  288.     @spell_window2.set_handler(:ok,     method(:on_item_ok))
  289.     @spell_window2.set_handler(:cancel, method(:return_scene))
  290.   end
  291.   #--------------------------------------------------------------------------
  292.   # * Confirm Item
  293.   #--------------------------------------------------------------------------
  294.   def determine_item
  295.     if item.for_friend?
  296.       show_sub_window(@actor_window)
  297.       @actor_window.select_for_item(item)
  298.     else
  299.       use_item if SceneManager.scene_is?(Scene_Battle)
  300.       @item_window.refresh
  301.       activate_item_window
  302.     end
  303.   end
  304.   #--------------------------------------------------------------------------
  305.   # * Item [OK]
  306.   #--------------------------------------------------------------------------
  307.   def on_item_ok
  308.     @actor.last_skill.object = item
  309.     determine_item if !item.nil?
  310.     @item_window.refresh
  311.     activate_item_window
  312.   end
  313.   #--------------------------------------------------------------------------
  314.   # * Item [Cancel]
  315.   #--------------------------------------------------------------------------
  316.   def on_item_cancel
  317.     return_scene
  318.   end
  319.   #--------------------------------------------------------------------------
  320.   # * Play SE When Using Item
  321.   #--------------------------------------------------------------------------
  322.   def play_se_for_item
  323.     Sound.play_use_item
  324.   end
  325.   #--------------------------------------------------------------------------
  326.   # * Use Item
  327.   #--------------------------------------------------------------------------
  328.   def use_item
  329.     super
  330.     @item_window.redraw_current_item
  331.   end
  332.   #--------------------------------------------------------------------------
  333.   # * Create Spell Count Window
  334.   #--------------------------------------------------------------------------
  335.   def create_spell_count_window
  336.     @spell_count_window = Window_KFBQSpellCount.new(0, Graphics.height - 160, Graphics.width, 60)
  337.     @spell_count_window.z = 60
  338.   end
  339. end
  340.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement