Advertisement
roninator2

Crazyninjaguy Item Menu Use Command - mod

Dec 15th, 2024
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 19.16 KB | None | 0 0
  1. #===============================================================================
  2. # * SEE - Item Menu ACE
  3. # * By Crazyninjaguy
  4. # * Requested by BizarreMonkey
  5. # * Modified by Roniunator2
  6. # * http://www.stormxstudios.co.uk
  7. # * 11/11/2021 - V1.04.2
  8. # * If you like my scripts, please show your appreciation by checking out
  9. #   my friendly, helpful Game Development Community, StormCross Studios.
  10. #  ---------------------------------------------------------------------------
  11. # * Aliased Methods
  12. #    - start (Scene_Item)
  13. #    - update_item_selection (Scene_Item)
  14. #    - terminate (Scene_Item)
  15. #  ---------------------------------------------------------------------------
  16. # * This script adds a new item description window with support for four text
  17. #   text lines and a 96 x 96 picture in Graphics/Pictures.
  18. # * To add a picture for your item, add this into the notebox of that item in
  19. #   the database
  20. # * <picture potionpicture>
  21. # * Replacing potionpicture for your image filename.
  22. #===============================================================================
  23.  
  24. #===============================================================================
  25. # !!!!!!!If using Yanfly Item Menu, it must be placed above this script.!!!!!!!
  26. #===============================================================================
  27.  
  28. $imported = {} if $imported == nil
  29. $imported["SEE - Item Menu Ace"] = true
  30.  
  31. #===============================================================================
  32. # * Main StormCross Engine Evolution Configuration Module
  33. #===============================================================================
  34. module SEE
  35.  #=============================================================================
  36.  # * Item Menu Configuration Module
  37.  #=============================================================================
  38.   module Item
  39.   ITEMS = []
  40. #===========================================================================
  41. # * The number at the beginning of the ITEMS[1] is the item id in the
  42. #   database.
  43. # * Each line of text in quotes is a seperate line in the window.
  44. #   Seperate each with a comma
  45. #===========================================================================
  46.   ITEMS[1] = ["This is a potion.", "It's very nice and restores 500hp.", "Costs 50 Gil in a shop.", "Has a purplish glow."]
  47.   ITEMS[2] = ["This is a high potion.", "It's very nice and restores 2500hp.", "Costs 150 Gil in a shop.", "Has a purplish glow."]
  48.  
  49.   WEAPONS = []
  50.   WEAPONS[1] = ["Derp", "", "", ""]
  51.  
  52.   ARMORS = []
  53.   ARMORS[1] = ["", "", "", ""]
  54.  
  55.   ITEM_COLOURS = []
  56. #===========================================================================
  57. # * As with the previous, the number at the beginning of COLOURS[1] is the
  58. #   item id in the database.
  59. # * The numbers in the array correspond to the text_color() argument of
  60. #   window base. 0 is white. You can find these by looking at the
  61. #   Window.png graphic. Seperate each value with a comma.
  62. #===========================================================================
  63.   ITEM_COLOURS[1] = [0, 1, 2, 3]
  64.  
  65.   WEAPON_COLOURS = []
  66.   WEAPON_COLOURS[1] = [0, 1, 2, 3]
  67.  
  68.   ARMOR_COLOURS = []
  69.   ARMOR_COLOURS[1] = [0, 1, 2, 3]
  70.  
  71.   # Show Commands
  72.   Use       = true
  73.   Discard   = false
  74.   Details   = false
  75.   Rename    = true  # requires Bubs Rename anything script line 91
  76.                     # to look like this
  77.                     # $imported["BubsRenameAnything"] = true
  78.     Rename_Size = 20
  79.   Cancel    = true
  80.  
  81.   end # Item
  82. end # SEE
  83.  
  84. module ReadNote
  85.   def read_note(note, tag, position = 1)
  86.     note2 = note.dup
  87.     lines = note2.scan(/<.+>/)
  88.     for line in lines
  89.       words = line.split(/[ <>]/)
  90.       words.delete("")
  91.       for word in words
  92.         if word == tag
  93.           result = words[words.index(word) + position]
  94.           return true if result == nil
  95.           return result
  96.         end
  97.       end
  98.     end
  99.     return false
  100.   end
  101. end
  102.  
  103. #==============================================================================
  104. # ** Window_SubItemCategory
  105. #------------------------------------------------------------------------------
  106. #  This window is for selecting a category of normal items and equipment
  107. # on the item screen or shop screen.
  108. #==============================================================================
  109.  
  110. class Window_SubItemCategory < Window_Command
  111.   attr_reader :item_window
  112.   #--------------------------------------------------------------------------
  113.   # * Object Initialization
  114.   #--------------------------------------------------------------------------
  115.   def initialize(x, y)
  116.     super(x, y)
  117.     @category = :none
  118.     self.back_opacity = 255
  119.     clear_command_list
  120.     make_command_list
  121.   end
  122.   #--------------------------------------------------------------------------
  123.   # * Get Window Width
  124.   #--------------------------------------------------------------------------
  125.   def window_width
  126.     return 120
  127.   end
  128.   #--------------------------------------------------------------------------
  129.   # * Get Window Height
  130.   #--------------------------------------------------------------------------
  131.   def window_height
  132.     fitting_height(visible_line_number)
  133.   end
  134.   #--------------------------------------------------------------------------
  135.   # * Create Command List
  136.   #--------------------------------------------------------------------------
  137.   def make_command_list
  138.     add_command("Use", :use, @category == :item) if SEE::Item::Use == true
  139.     add_command("Discard", :discard) if SEE::Item::Discard == true
  140.     add_command("Details", :details) if SEE::Item::Details == true
  141.     add_command("Rename", :rename) if SEE::Item::Rename == true && $imported["BubsRenameAnything"]
  142.     add_command("Cancel", :cancel) if SEE::Item::Cancel == true
  143.   end
  144.   def category=(category)
  145.     return if @category == category
  146.     @category = category
  147.     refresh
  148.   end
  149.   def category(category)
  150.     @category = category
  151.     refresh
  152.   end
  153.   def update
  154.     super
  155.     @category = @item_window.current_symbol if @subitem_window
  156.   end
  157. end
  158.  
  159.  
  160. class Scene_Item < Scene_ItemBase
  161.   attr_accessor :item_window
  162.   alias r2_start_item_for_yanfly    start
  163.   def start
  164.     r2_start_item_for_yanfly
  165.     create_description_window
  166.     create_sub_item_window
  167.     create_number_window
  168.     @description_index = 0
  169.   end
  170.   def create_description_window
  171.     @description = Window_ItemDescribe.new
  172.     @description.hide
  173.     @description.viewport = @viewport
  174.     @description.set_handler(:cancel, method(:details_cancel))
  175.   end
  176.   def create_item_window
  177.     wy = @category_window.y + @category_window.height
  178.     wh = Graphics.height - wy
  179.     @item_window = Window_ItemList.new(0, wy, Graphics.width, wh)
  180.     @item_window.help_window = @help_window
  181.     @item_window.set_handler(:ok,     method(:on_sub_item_ok))
  182.     @item_window.set_handler(:cancel, method(:on_item_cancel))
  183.     @category_window.item_window = @item_window
  184.     @item_window.viewport = @viewport
  185.   end
  186.   def create_sub_item_window
  187.     wy = @category_window.y + @category_window.height
  188.     @subitem_window = Window_SubItemCategory.new(200, wy + 50)
  189.     @subitem_window.set_handler(:use,     method(:on_item_ok))
  190.     @subitem_window.set_handler(:discard,     method(:on_item_discard))
  191.     @subitem_window.set_handler(:details,     method(:on_item_details))
  192.     @subitem_window.set_handler(:rename,     method(:on_item_rename))
  193.     @subitem_window.set_handler(:cancel, method(:on_sub_item_cancel))
  194.     @category_window.item_window = @item_window
  195.     @subitem_window.viewport = @viewport
  196.     @subitem_window.hide
  197.   end
  198.   def create_number_window
  199.     wy = @category_window.y + @category_window.height
  200.     wh = 48
  201.     @number_window = Window_DiscardNumber.new(100, wy + 50, wh)
  202.     @number_window.viewport = @viewport
  203.     @number_window.hide
  204.     @number_window.set_handler(:ok,     method(:on_number_ok))
  205.     @number_window.set_handler(:cancel, method(:on_number_cancel))
  206.   end
  207.   def activate_item_window
  208.     @item_window.refresh
  209.     @subitem_window.refresh
  210.     @subitem_window.activate
  211.   end
  212.   def on_item_discard
  213.     @subitem_window.deactivate
  214.     @subitem_window.hide
  215.     @number_window.set(item, $game_party.item_number(item))
  216.     @number_window.activate
  217.     @number_window.show
  218.   end
  219.   if $imported["YEA-ItemMenu"] == true
  220.     def open_types
  221.       @category_window.x = Graphics.width
  222.       @types_window.x = 0
  223.       @types_window.reveal(@category_window.current_symbol)
  224.       @subitem_window.category(@category_window.current_symbol)
  225.     end
  226.   end
  227.   alias r2_item_nil_count on_item_ok
  228.   def on_item_ok
  229.     if item == nil
  230.       Sound.play_buzzer
  231.       on_sub_item_cancel
  232.       return
  233.     end
  234.     r2_item_nil_count
  235.   end
  236.   def on_sub_item_ok
  237.     if @item_window.item == nil
  238.       Sound.play_buzzer
  239.       on_sub_item_cancel
  240.     else
  241.       @category_window.item_window = @subitem_window
  242.       @subitem_window.activate
  243.       @subitem_window.select(0)
  244.       @subitem_window.show
  245.       @item_window.deactivate
  246.     end
  247.   end
  248.   def on_item_rename
  249.     if @item_window.item == nil
  250.       Sound.play_buzzer
  251.       on_sub_item_cancel
  252.     else
  253.       item = @item_window.item
  254.       case item
  255.       when RPG::Item
  256.         obj = $data_items[item.id]
  257.         symbol = :item
  258.       when RPG::Armor
  259.         obj = $data_armors[item.id]
  260.         symbol = :armor
  261.       when RPG::Weapon
  262.         obj = $data_weapons[item.id]
  263.         symbol = :weapon
  264.       else
  265.         Sound.play_buzzer
  266.         on_sub_item_cancel
  267.       end
  268.       if obj
  269.         SceneManager.call(Scene_RenameAnything)
  270.         SceneManager.scene.prepare(obj, SEE::Item::Rename_Size, symbol)
  271.       end
  272.     end
  273.   end
  274.   def on_item_details
  275.     @description.show
  276.     @description.activate
  277.     @description.z = 1000
  278.     @subitem_window.deactivate
  279.     @subitem_window.hide
  280.     @item_window.deactivate
  281.     update
  282.   end
  283.   def on_sub_item_cancel
  284.     @subitem_window.deactivate
  285.     @subitem_window.hide
  286.     @item_window.activate
  287.     @category_window.item_window = @item_window
  288.   end
  289.   def details_cancel
  290.     @description.deactivate
  291.     @description.hide
  292.     @subitem_window.activate
  293.     @subitem_window.show
  294.     @subitem_window.select(0)
  295.   end
  296.   def on_number_ok
  297.     discard(@number_window.number)
  298.     play_se_for_item
  299.     @number_window.hide
  300.     @item_window.refresh
  301.     on_sub_item_cancel
  302.   end
  303.   def discard(number)
  304.     $game_party.lose_item(item, number)
  305.   end
  306.   def on_number_cancel
  307.     Sound.play_cancel
  308.     @number_window.hide
  309.     on_sub_item_cancel
  310.   end
  311.   def update
  312.     super
  313.     if @description_index != @item_window.index
  314.       @description.details(@item_window.item)
  315.       @description_index = @item_window.index
  316.     end
  317.   end
  318. end
  319.  
  320. class Window_ItemList < Window_Selectable
  321.   def enable?(item)
  322.     return true
  323.   end
  324. end
  325.  
  326. class Window_ItemDescribe < Window_Selectable
  327.   include ReadNote
  328.   include SEE::Item
  329.   def initialize(item = nil)
  330.     super(0, 0, window_width, window_height)
  331.     self.back_opacity = 255
  332.     details(item)
  333.   end # initialize
  334.   def window_width
  335.     Graphics.width
  336.   end
  337.   def window_height
  338.     Graphics.height
  339.   end
  340.   def details(item)
  341.     self.contents.clear
  342.     if item != nil
  343.       if item.is_a?(RPG::Item)
  344.         picture = read_note($data_items[item.id].note, "picture")
  345.       elsif item.is_a?(RPG::Weapon)
  346.         picture = read_note($data_weapons[item.id].note, "picture")
  347.       elsif item.is_a?(RPG::Armor)
  348.         picture = read_note($data_armors[item.id].note, "picture")
  349.       end
  350.       if picture != false
  351.         bitmap = Cache.picture(picture)
  352.         rect = Rect.new(0, 0, 96, 96)
  353.         self.contents.blt(0, 0, bitmap, rect)
  354.       end
  355.       if item.is_a?(RPG::Item)
  356.         if ITEMS[item.id] != nil
  357.           if ITEM_COLOURS[item.id] != nil
  358.             self.contents.font.color = text_color(ITEM_COLOURS[item.id][0])
  359.             self.contents.draw_text(96, 0, width - 128, 24, ITEMS[item.id][0])
  360.             self.contents.font.color = text_color(ITEM_COLOURS[item.id][1])
  361.             self.contents.draw_text(96, 24, width - 128, 24, ITEMS[item.id][1])
  362.             self.contents.font.color = text_color(ITEM_COLOURS[item.id][2])
  363.             self.contents.draw_text(96, 48, width - 128, 24, ITEMS[item.id][2])
  364.             self.contents.font.color = text_color(ITEM_COLOURS[item.id][3])
  365.             self.contents.draw_text(96, 72, width - 128, 24, ITEMS[item.id][3])
  366.             self.contents.font.color = text_color(0)
  367.           else
  368.             self.contents.draw_text(96, 0, width - 128, 24, ITEMS[item.id][0])
  369.             self.contents.draw_text(96, 24, width - 128, 24, ITEMS[item.id][1])
  370.             self.contents.draw_text(96, 48, width - 128, 24, ITEMS[item.id][2])
  371.             self.contents.draw_text(96, 72, width - 128, 24, ITEMS[item.id][3])
  372.           end
  373.         end
  374.       elsif item.is_a?(RPG::Weapon)
  375.         if WEAPONS[item.id] != nil
  376.           if WEAPON_COLOURS[item.id] != nil
  377.             self.contents.font.color = text_color(WEAPON_COLOURS[item.id][0])
  378.             self.contents.draw_text(96, 0, width - 128, 24, WEAPONS[item.id][0])
  379.             self.contents.font.color = text_color(WEAPON_COLOURS[item.id][1])
  380.             self.contents.draw_text(96, 24, width - 128, 24, WEAPONS[item.id][1])
  381.             self.contents.font.color = text_color(WEAPON_COLOURS[item.id][2])
  382.             self.contents.draw_text(96, 48, width - 128, 24, WEAPONS[item.id][2])
  383.             self.contents.font.color = text_color(WEAPON_COLOURS[item.id][3])
  384.             self.contents.draw_text(96, 72, width - 128, 24, WEAPONS[item.id][3])
  385.             self.contents.font.color = text_color(0)
  386.           else
  387.             self.contents.draw_text(96, 0, width - 128, 24, WEAPONS[item.id][0])
  388.             self.contents.draw_text(96, 24, width - 128, 24, WEAPONS[item.id][1])
  389.             self.contents.draw_text(96, 48, width - 128, 24, WEAPONS[item.id][2])
  390.             self.contents.draw_text(96, 72, width - 128, 24, WEAPONS[item.id][3])
  391.           end
  392.         end
  393.       elsif item.is_a?(RPG::Armor)
  394.         if ARMORS[item.id] != nil
  395.           if ARMOR_COLOURS[item.id] != nil
  396.             self.contents.font.color = text_color(ARMOR_COLOURS[item.id][0])
  397.             self.contents.draw_text(96, 0, width - 128, 24, ARMORS[item.id][0])
  398.             self.contents.font.color = text_color(ARMOR_COLOURS[item.id][1])
  399.             self.contents.draw_text(96, 24, width - 128, 24, ARMORS[item.id][1])
  400.             self.contents.font.color = text_color(ARMOR_COLOURS[item.id][2])
  401.             self.contents.draw_text(96, 48, width - 128, 24, ARMORS[item.id][2])
  402.             self.contents.font.color = text_color(ARMOR_COLOURS[item.id][3])
  403.             self.contents.draw_text(96, 72, width - 128, 24, ARMORS[item.id][3])
  404.             self.contents.font.color = text_color(0)
  405.           else
  406.             self.contents.draw_text(96, 0, width - 128, 24, ARMORS[item.id][0])
  407.             self.contents.draw_text(96, 24, width - 128, 24, ARMORS[item.id][1])
  408.             self.contents.draw_text(96, 48, width - 128, 24, ARMORS[item.id][2])
  409.             self.contents.draw_text(96, 72, width - 128, 24, ARMORS[item.id][3])
  410.           end
  411.         end
  412.       end
  413.     end
  414.   end # refresh
  415. end # Window_ItemDescription
  416.  
  417. #==============================================================================
  418. # ** Window_DiscardNumber
  419. #------------------------------------------------------------------------------
  420. #  This window is for inputting quantity of items to buy or sell on the shop
  421. # screen.
  422. #==============================================================================
  423.  
  424. class Window_DiscardNumber < Window_Selectable
  425.   #--------------------------------------------------------------------------
  426.   # * Public Instance Variables
  427.   #--------------------------------------------------------------------------
  428.   attr_reader   :number                   # quantity entered
  429.   #--------------------------------------------------------------------------
  430.   # * Object Initialization
  431.   #--------------------------------------------------------------------------
  432.   def initialize(x, y, height)
  433.     super(x, y, window_width, height)
  434.     @item = nil
  435.     @max = 1
  436.     @number = 1
  437.   end
  438.   #--------------------------------------------------------------------------
  439.   # * Get Window Width
  440.   #--------------------------------------------------------------------------
  441.   def window_width
  442.     return 304
  443.   end
  444.   #--------------------------------------------------------------------------
  445.   # * Set Item, Max Quantity, Price, and Currency Unit
  446.   #--------------------------------------------------------------------------
  447.   def set(item, max)
  448.     @item = item
  449.     @max = max
  450.     @number = 1
  451.     refresh
  452.   end
  453.   #--------------------------------------------------------------------------
  454.   # * Refresh
  455.   #--------------------------------------------------------------------------
  456.   def refresh
  457.     contents.clear
  458.     draw_item_name(@item, 0, 0)
  459.     draw_number
  460.   end
  461.   #--------------------------------------------------------------------------
  462.   # * Draw Quantity
  463.   #--------------------------------------------------------------------------
  464.   def draw_number
  465.     change_color(normal_color)
  466.     draw_text(cursor_x - 28, 0, 22, line_height, "×")
  467.     draw_text(cursor_x, 0, cursor_width - 4, line_height, @number, 2)
  468.   end
  469.   #--------------------------------------------------------------------------
  470.   # * Get Cursor Width
  471.   #--------------------------------------------------------------------------
  472.   def cursor_width
  473.     figures * 10 + 12
  474.   end
  475.   #--------------------------------------------------------------------------
  476.   # * Get X Coordinate of Cursor
  477.   #--------------------------------------------------------------------------
  478.   def cursor_x
  479.     contents_width - cursor_width - 4
  480.   end
  481.   #--------------------------------------------------------------------------
  482.   # * Get Maximum Number of Digits for Quantity Display
  483.   #--------------------------------------------------------------------------
  484.   def figures
  485.     return 2
  486.   end
  487.   #--------------------------------------------------------------------------
  488.   # * Frame Update
  489.   #--------------------------------------------------------------------------
  490.   def update
  491.     super
  492.     if active
  493.       last_number = @number
  494.       update_number
  495.       if @number != last_number
  496.         Sound.play_cursor
  497.         refresh
  498.       end
  499.     end
  500.   end
  501.   #--------------------------------------------------------------------------
  502.   # * Update Quantity
  503.   #--------------------------------------------------------------------------
  504.   def update_number
  505.     change_number(1)   if Input.repeat?(:RIGHT)
  506.     change_number(-1)  if Input.repeat?(:LEFT)
  507.     change_number(10)  if Input.repeat?(:UP)
  508.     change_number(-10) if Input.repeat?(:DOWN)
  509.   end
  510.   #--------------------------------------------------------------------------
  511.   # * Change Quantity
  512.   #--------------------------------------------------------------------------
  513.   def change_number(amount)
  514.     @number = [[@number + amount, @max].min, 1].max
  515.   end
  516.   #--------------------------------------------------------------------------
  517.   # * Update Cursor
  518.   #--------------------------------------------------------------------------
  519.   def update_cursor
  520.     cursor_rect.set(cursor_x, 0, cursor_width, line_height)
  521.   end
  522. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement