roninator2

SEE - Item Menu ACE - rename anything

Nov 20th, 2024
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 18.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.03
  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   = true
  74.   Details   = true
  75.   Cancel    = true
  76.  
  77.   end # Item
  78. end # SEE
  79.  
  80. module ReadNote
  81.   def read_note(note, tag, position = 1)
  82.     note2 = note.dup
  83.     lines = note2.scan(/<.+>/)
  84.     for line in lines
  85.       words = line.split(/[ <>]/)
  86.       words.delete("")
  87.       for word in words
  88.         if word == tag
  89.           result = words[words.index(word) + position]
  90.           return true if result == nil
  91.           return result
  92.         end
  93.       end
  94.     end
  95.     return false
  96.   end
  97. end
  98.  
  99. #==============================================================================
  100. # ** Window_SubItemCategory
  101. #------------------------------------------------------------------------------
  102. #  This window is for selecting a category of normal items and equipment
  103. # on the item screen or shop screen.
  104. #==============================================================================
  105.  
  106. class Window_SubItemCategory < Window_Command
  107.   attr_reader :item_window
  108.   #--------------------------------------------------------------------------
  109.   # * Object Initialization
  110.   #--------------------------------------------------------------------------
  111.   def initialize(x, y)
  112.     super(x, y)
  113.     @category = :none
  114.     self.back_opacity = 255
  115.     clear_command_list
  116.     make_command_list
  117.   end
  118.   #--------------------------------------------------------------------------
  119.   # * Get Window Width
  120.   #--------------------------------------------------------------------------
  121.   def window_width
  122.     return 120
  123.   end
  124.   #--------------------------------------------------------------------------
  125.   # * Get Window Height
  126.   #--------------------------------------------------------------------------
  127.   def window_height
  128.     fitting_height(visible_line_number)
  129.   end
  130.   #--------------------------------------------------------------------------
  131.   # * Create Command List
  132.   #--------------------------------------------------------------------------
  133.   def make_command_list
  134.     add_command("Use", :use, @category == :item) if SEE::Item::Use == true
  135.     add_command("Discard", :discard) if SEE::Item::Discard == true
  136.     add_command("Details", :details) if SEE::Item::Details == true
  137.     add_command("Cancel", :cancel) if SEE::Item::Cancel == true
  138.   end
  139.   def category=(category)
  140.     return if @category == category
  141.     @category = category
  142.     refresh
  143.   end
  144.   def category(category)
  145.     @category = category
  146.     refresh
  147.   end
  148.   def update
  149.     super
  150.     @category = @item_window.current_symbol if @subitem_window
  151.   end
  152. end
  153.  
  154.  
  155. class Scene_Item < Scene_ItemBase
  156.   attr_accessor :item_window
  157.   alias r2_start_item_for_yanfly    start
  158.   def start
  159.     r2_start_item_for_yanfly
  160.     create_description_window
  161.     create_sub_item_window
  162.     create_number_window
  163.     @description_index = 0
  164.   end
  165.   def create_description_window
  166.     @description = Window_ItemDescription.new
  167.     @description.hide
  168.     @description.viewport = @viewport
  169.     @description.set_handler(:cancel, method(:details_cancel))
  170.   end
  171.   def create_item_window
  172.     wy = @category_window.y + @category_window.height
  173.     wh = Graphics.height - wy
  174.     @item_window = Window_ItemList.new(0, wy, Graphics.width, wh)
  175.     @item_window.help_window = @help_window
  176.     @item_window.set_handler(:ok,     method(:on_sub_item_ok))
  177.     @item_window.set_handler(:cancel, method(:on_item_cancel))
  178.     @category_window.item_window = @item_window
  179.     @item_window.viewport = @viewport
  180.   end
  181.   def create_sub_item_window
  182.     wy = @category_window.y + @category_window.height
  183.     @subitem_window = Window_SubItemCategory.new(200, wy + 50)
  184.     @subitem_window.set_handler(:use,     method(:on_item_ok))
  185.     @subitem_window.set_handler(:discard,     method(:on_item_discard))
  186.     @subitem_window.set_handler(:details,     method(:on_item_details))
  187.     @subitem_window.set_handler(:cancel, method(:on_sub_item_cancel))
  188.     @category_window.item_window = @item_window
  189.     @subitem_window.viewport = @viewport
  190.     @subitem_window.hide
  191.   end
  192.   def create_number_window
  193.     wy = @category_window.y + @category_window.height
  194.     wh = 48
  195.     @number_window = Window_DiscardNumber.new(100, wy + 50, wh)
  196.     @number_window.viewport = @viewport
  197.     @number_window.hide
  198.     @number_window.set_handler(:ok,     method(:on_number_ok))
  199.     @number_window.set_handler(:cancel, method(:on_number_cancel))
  200.   end
  201.   def activate_item_window
  202.     @item_window.refresh
  203.     @subitem_window.refresh
  204.     @subitem_window.activate
  205.   end
  206.   def on_item_discard
  207.     @subitem_window.deactivate
  208.     @subitem_window.hide
  209.     @number_window.set(item, $game_party.item_number(item))
  210.     @number_window.activate
  211.     @number_window.show
  212.   end
  213.   if $imported["YEA-ItemMenu"] == true
  214.     def open_types
  215.       @category_window.x = Graphics.width
  216.       @types_window.x = 0
  217.       @types_window.reveal(@category_window.current_symbol)
  218.       @subitem_window.category(@category_window.current_symbol)
  219.     end
  220.   end
  221.   alias r2_item_nil_count on_item_ok
  222.   def on_item_ok
  223.     if item == nil
  224.       Sound.play_buzzer
  225.       on_sub_item_cancel
  226.       return
  227.     end
  228.     r2_item_nil_count
  229.   end
  230.   def on_sub_item_ok
  231.     if @item_window.item == nil
  232.       Sound.play_buzzer
  233.       on_sub_item_cancel
  234.     else
  235.       @category_window.item_window = @subitem_window
  236.       @subitem_window.activate
  237.       @subitem_window.select(0)
  238.       @subitem_window.show
  239.       @item_window.deactivate
  240.     end
  241.   end
  242.   def on_item_details
  243.     @description.show
  244.     @description.activate
  245.     @description.z = 1000
  246.     @subitem_window.deactivate
  247.     @subitem_window.hide
  248.     @item_window.deactivate
  249.     update
  250.   end
  251.   def on_sub_item_cancel
  252.     @subitem_window.deactivate
  253.     @subitem_window.hide
  254.     @item_window.activate
  255.     @category_window.item_window = @item_window
  256.   end
  257.   def details_cancel
  258.     @description.deactivate
  259.     @description.hide
  260.     @subitem_window.activate
  261.     @subitem_window.show
  262.     @subitem_window.select(0)
  263.   end
  264.   def on_number_ok
  265.     discard(@number_window.number)
  266.     play_se_for_item
  267.     @number_window.hide
  268.     @item_window.refresh
  269.     on_sub_item_cancel
  270.   end
  271.   def discard(number)
  272.     $game_party.lose_item(item, number)
  273.   end
  274.   def on_number_cancel
  275.     Sound.play_cancel
  276.     @number_window.hide
  277.     on_sub_item_cancel
  278.   end
  279.   def update
  280.     super
  281.     if @description_index != @item_window.index
  282.       @description.details(@item_window.item)
  283.       @description_index = @item_window.index
  284.     end
  285.   end
  286. end
  287.  
  288. class Window_ItemList < Window_Selectable
  289.   def enable?(item)
  290.     return true
  291.   end
  292. end
  293.  
  294. class Window_ItemDescription < Window_Selectable
  295.   include ReadNote
  296.   include SEE::Item
  297.   def initialize(item = nil)
  298.     super(0, 0, window_width, window_height)
  299.     self.back_opacity = 255
  300.     details(item)
  301.   end # initialize
  302.   def window_width
  303.     Graphics.width
  304.   end
  305.   def window_height
  306.     Graphics.height
  307.   end
  308.   def details(item)
  309.     self.contents.clear
  310.     if item != nil
  311.       if item.is_a?(RPG::Item)
  312.         picture = read_note($data_items[item.id].note, "picture")
  313.       elsif item.is_a?(RPG::Weapon)
  314.         picture = read_note($data_weapons[item.id].note, "picture")
  315.       elsif item.is_a?(RPG::Armor)
  316.         picture = read_note($data_armors[item.id].note, "picture")
  317.       end
  318.       if picture != false
  319.         bitmap = Cache.picture(picture)
  320.         rect = Rect.new(0, 0, 96, 96)
  321.         self.contents.blt(0, 0, bitmap, rect)
  322.       end
  323.       if item.is_a?(RPG::Item)
  324.         if ITEMS[item.id] != nil
  325.           if ITEM_COLOURS[item.id] != nil
  326.             self.contents.font.color = text_color(ITEM_COLOURS[item.id][0])
  327.             self.contents.draw_text(96, 0, width - 128, 24, ITEMS[item.id][0])
  328.             self.contents.font.color = text_color(ITEM_COLOURS[item.id][1])
  329.             self.contents.draw_text(96, 24, width - 128, 24, ITEMS[item.id][1])
  330.             self.contents.font.color = text_color(ITEM_COLOURS[item.id][2])
  331.             self.contents.draw_text(96, 48, width - 128, 24, ITEMS[item.id][2])
  332.             self.contents.font.color = text_color(ITEM_COLOURS[item.id][3])
  333.             self.contents.draw_text(96, 72, width - 128, 24, ITEMS[item.id][3])
  334.             self.contents.font.color = text_color(0)
  335.           else
  336.             self.contents.draw_text(96, 0, width - 128, 24, ITEMS[item.id][0])
  337.             self.contents.draw_text(96, 24, width - 128, 24, ITEMS[item.id][1])
  338.             self.contents.draw_text(96, 48, width - 128, 24, ITEMS[item.id][2])
  339.             self.contents.draw_text(96, 72, width - 128, 24, ITEMS[item.id][3])
  340.           end
  341.         end
  342.       elsif item.is_a?(RPG::Weapon)
  343.         if WEAPONS[item.id] != nil
  344.           if WEAPON_COLOURS[item.id] != nil
  345.             self.contents.font.color = text_color(WEAPON_COLOURS[item.id][0])
  346.             self.contents.draw_text(96, 0, width - 128, 24, WEAPONS[item.id][0])
  347.             self.contents.font.color = text_color(WEAPON_COLOURS[item.id][1])
  348.             self.contents.draw_text(96, 24, width - 128, 24, WEAPONS[item.id][1])
  349.             self.contents.font.color = text_color(WEAPON_COLOURS[item.id][2])
  350.             self.contents.draw_text(96, 48, width - 128, 24, WEAPONS[item.id][2])
  351.             self.contents.font.color = text_color(WEAPON_COLOURS[item.id][3])
  352.             self.contents.draw_text(96, 72, width - 128, 24, WEAPONS[item.id][3])
  353.             self.contents.font.color = text_color(0)
  354.           else
  355.             self.contents.draw_text(96, 0, width - 128, 24, WEAPONS[item.id][0])
  356.             self.contents.draw_text(96, 24, width - 128, 24, WEAPONS[item.id][1])
  357.             self.contents.draw_text(96, 48, width - 128, 24, WEAPONS[item.id][2])
  358.             self.contents.draw_text(96, 72, width - 128, 24, WEAPONS[item.id][3])
  359.           end
  360.         end
  361.       elsif item.is_a?(RPG::Armor)
  362.         if ARMORS[item.id] != nil
  363.           if ARMOR_COLOURS[item.id] != nil
  364.             self.contents.font.color = text_color(ARMOR_COLOURS[item.id][0])
  365.             self.contents.draw_text(96, 0, width - 128, 24, ARMORS[item.id][0])
  366.             self.contents.font.color = text_color(ARMOR_COLOURS[item.id][1])
  367.             self.contents.draw_text(96, 24, width - 128, 24, ARMORS[item.id][1])
  368.             self.contents.font.color = text_color(ARMOR_COLOURS[item.id][2])
  369.             self.contents.draw_text(96, 48, width - 128, 24, ARMORS[item.id][2])
  370.             self.contents.font.color = text_color(ARMOR_COLOURS[item.id][3])
  371.             self.contents.draw_text(96, 72, width - 128, 24, ARMORS[item.id][3])
  372.             self.contents.font.color = text_color(0)
  373.           else
  374.             self.contents.draw_text(96, 0, width - 128, 24, ARMORS[item.id][0])
  375.             self.contents.draw_text(96, 24, width - 128, 24, ARMORS[item.id][1])
  376.             self.contents.draw_text(96, 48, width - 128, 24, ARMORS[item.id][2])
  377.             self.contents.draw_text(96, 72, width - 128, 24, ARMORS[item.id][3])
  378.           end
  379.         end
  380.       end
  381.     end
  382.   end # refresh
  383. end # Window_ItemDescription
  384.  
  385. #==============================================================================
  386. # ** Window_DiscardNumber
  387. #------------------------------------------------------------------------------
  388. #  This window is for inputting quantity of items to buy or sell on the shop
  389. # screen.
  390. #==============================================================================
  391.  
  392. class Window_DiscardNumber < Window_Selectable
  393.   #--------------------------------------------------------------------------
  394.   # * Public Instance Variables
  395.   #--------------------------------------------------------------------------
  396.   attr_reader   :number                   # quantity entered
  397.   #--------------------------------------------------------------------------
  398.   # * Object Initialization
  399.   #--------------------------------------------------------------------------
  400.   def initialize(x, y, height)
  401.     super(x, y, window_width, height)
  402.     @item = nil
  403.     @max = 1
  404.     @number = 1
  405.   end
  406.   #--------------------------------------------------------------------------
  407.   # * Get Window Width
  408.   #--------------------------------------------------------------------------
  409.   def window_width
  410.     return 304
  411.   end
  412.   #--------------------------------------------------------------------------
  413.   # * Set Item, Max Quantity, Price, and Currency Unit
  414.   #--------------------------------------------------------------------------
  415.   def set(item, max)
  416.     @item = item
  417.     @max = max
  418.     @number = 1
  419.     refresh
  420.   end
  421.   #--------------------------------------------------------------------------
  422.   # * Refresh
  423.   #--------------------------------------------------------------------------
  424.   def refresh
  425.     contents.clear
  426.     draw_item_name(@item, 0, 0)
  427.     draw_number
  428.   end
  429.   #--------------------------------------------------------------------------
  430.   # * Draw Quantity
  431.   #--------------------------------------------------------------------------
  432.   def draw_number
  433.     change_color(normal_color)
  434.     draw_text(cursor_x - 28, 0, 22, line_height, "×")
  435.     draw_text(cursor_x, 0, cursor_width - 4, line_height, @number, 2)
  436.   end
  437.   #--------------------------------------------------------------------------
  438.   # * Get Cursor Width
  439.   #--------------------------------------------------------------------------
  440.   def cursor_width
  441.     figures * 10 + 12
  442.   end
  443.   #--------------------------------------------------------------------------
  444.   # * Get X Coordinate of Cursor
  445.   #--------------------------------------------------------------------------
  446.   def cursor_x
  447.     contents_width - cursor_width - 4
  448.   end
  449.   #--------------------------------------------------------------------------
  450.   # * Get Maximum Number of Digits for Quantity Display
  451.   #--------------------------------------------------------------------------
  452.   def figures
  453.     return 2
  454.   end
  455.   #--------------------------------------------------------------------------
  456.   # * Frame Update
  457.   #--------------------------------------------------------------------------
  458.   def update
  459.     super
  460.     if active
  461.       last_number = @number
  462.       update_number
  463.       if @number != last_number
  464.         Sound.play_cursor
  465.         refresh
  466.       end
  467.     end
  468.   end
  469.   #--------------------------------------------------------------------------
  470.   # * Update Quantity
  471.   #--------------------------------------------------------------------------
  472.   def update_number
  473.     change_number(1)   if Input.repeat?(:RIGHT)
  474.     change_number(-1)  if Input.repeat?(:LEFT)
  475.     change_number(10)  if Input.repeat?(:UP)
  476.     change_number(-10) if Input.repeat?(:DOWN)
  477.   end
  478.   #--------------------------------------------------------------------------
  479.   # * Change Quantity
  480.   #--------------------------------------------------------------------------
  481.   def change_number(amount)
  482.     @number = [[@number + amount, @max].min, 1].max
  483.   end
  484.   #--------------------------------------------------------------------------
  485.   # * Update Cursor
  486.   #--------------------------------------------------------------------------
  487.   def update_cursor
  488.     cursor_rect.set(cursor_x, 0, cursor_width, line_height)
  489.   end
  490. end
Add Comment
Please, Sign In to add comment