Advertisement
roninator2

Theoallen Simply Upgrade your Weapon addon - View Sockets

Dec 10th, 2024
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 21.59 KB | None | 0 0
  1. # ╔═══════════════════════════════════════════════╦════════════════════╗
  2. # ║ Title: Socket View Scene                      ║  Version: 1.01     ║
  3. # ║ Author: Roninator2                            ║                    ║
  4. # ╠═══════════════════════════════════════════════╬════════════════════╣
  5. # ║ Function:                                     ║   Date Created     ║
  6. # ║                                               ╠════════════════════╣
  7. # ║   View Socket Item Data                       ║    28 Jan 2024     ║
  8. # ╚═══════════════════════════════════════════════╩════════════════════╝
  9. # ╔════════════════════════════════════════════════════════════════════╗
  10. # ║ Requires:  Weapon Upgrade - Sockets                                ║
  11. # ╚════════════════════════════════════════════════════════════════════╝
  12. # ╔════════════════════════════════════════════════════════════════════╗
  13. # ║ Brief Description:                                                 ║
  14. # ║ Simply view socket item data                                       ║
  15. # ╚════════════════════════════════════════════════════════════════════╝
  16. # ╔════════════════════════════════════════════════════════════════════╗
  17. # ║ Instructions:                                                      ║
  18. # ║   Call scene                                                       ║
  19. # ║     SceneManager.call(Scene_Socket_Data)                           ║
  20. # ╚════════════════════════════════════════════════════════════════════╝
  21. # ╔════════════════════════════════════════════════════════════════════╗
  22. # ║ Updates:                                                           ║
  23. # ║ 1.00 - 28 Jan 2024 - Script finished                               ║
  24. # ║ 1.01 - 07 Feb 2024 - Added vertical line x position                ║
  25. # ╚════════════════════════════════════════════════════════════════════╝
  26. # ╔════════════════════════════════════════════════════════════════════╗
  27. # ║ Credits and Thanks:                                                ║
  28. # ║   Roninator2                                                       ║
  29. # ║                                                                    ║
  30. # ╚════════════════════════════════════════════════════════════════════╝
  31. # ╔════════════════════════════════════════════════════════════════════╗
  32. # ║ Terms of use:                                                      ║
  33. # ║  Follow the original Authors terms of use where applicable         ║
  34. # ║    - When not made by me (Roninator2)                              ║
  35. # ║  Free for all uses in RPG Maker except nudity                      ║
  36. # ║  Anyone using this script in their project before these terms      ║
  37. # ║  were changed are allowed to use this script even if it conflicts  ║
  38. # ║  with these new terms. New terms effective 03 Apr 2024             ║
  39. # ║  No part of this code can be used with AI programs or tools        ║
  40. # ║  Credit must be given                                              ║
  41. # ╚════════════════════════════════════════════════════════════════════╝
  42.  
  43. module Vocab
  44.   # Socket menu text
  45.   Socket_Data = "Socket Info"
  46. end
  47.  
  48. module R2_Socket_Config
  49.   # If true will show command in item menu to view sockets items
  50.   # if false will include items in item menu as key items
  51.   Use_Item_Command  = false
  52.  
  53.   # position for the Vertical line
  54.   Vertical_Line_View_X = 260
  55. end
  56.  
  57. # ╔════════════════════════════════════════════════════════════════════╗
  58. # ║                      End of editable region                        ║
  59. # ╚════════════════════════════════════════════════════════════════════╝
  60.  
  61. #==============================================================================
  62. # ** Window_SocketItemData
  63. #------------------------------------------------------------------------------
  64. #  This window shows the socket item information.
  65. #==============================================================================
  66. if R2_Socket_Config::Use_Item_Command
  67. class Window_ItemCategory < Window_HorzCommand
  68.   #--------------------------------------------------------------------------
  69.   # * Alias method: make_command_list
  70.   #--------------------------------------------------------------------------
  71.   alias :make_command_list_r2_socket_system :make_command_list
  72.   def make_command_list
  73.     make_command_list_r2_socket_system
  74.     add_command(Vocab::Socket_Data, :socket_data, $game_party.socket_items != [])
  75.   end
  76. end
  77.  
  78. class Scene_Item < Scene_ItemBase
  79.   #--------------------------------------------------------------------------
  80.   # * Alias method: create_category_window
  81.   #--------------------------------------------------------------------------
  82.   alias :socket_system_create_category_window :create_category_window
  83.   #--------------------------------------------------------------------------
  84.   # * Create Category Window
  85.   #--------------------------------------------------------------------------
  86.   def create_category_window
  87.     socket_system_create_category_window
  88.     @category_window.set_handler(:socket_data,   method(:socket_info))
  89.   end
  90.   #--------------------------------------------------------------------------
  91.   # * socket_info
  92.   #--------------------------------------------------------------------------
  93.   def socket_info
  94.     SceneManager.call(Scene_Socket_Data)
  95.   end
  96. end
  97. else
  98. class Window_ItemList < Window_Selectable
  99.   alias :r2_key_item_socket_list  :make_item_list
  100.   #--------------------------------------------------------------------------
  101.   # * Create Item List
  102.   #--------------------------------------------------------------------------
  103.   def make_item_list
  104.     r2_key_item_socket_list
  105.     $game_party.socket_items.each do |si|
  106.       @data.push(si) if @category == :key_item
  107.     end
  108.     @data.compact!
  109.     @data.push(nil) if include?(nil)
  110.   end
  111.   #--------------------------------------------------------------------------
  112.   # * Draw Item
  113.   #--------------------------------------------------------------------------
  114.   def draw_item(index)
  115.     item = @data[index]
  116.     if item
  117.       rect = item_rect(index)
  118.       rect.width -= 4
  119.       draw_item_name(item, rect.x, rect.y, enable?(item))
  120.       draw_item_number(rect, item) unless item.is_a?(RPG::Armor)
  121.     end
  122.   end
  123. end
  124. end
  125.  
  126. class Window_SocketItemData < Window_Base
  127.   #--------------------------------------------------------------------------
  128.   # * initialize
  129.   #--------------------------------------------------------------------------
  130.   def initialize(width, height)
  131.     super(0, 72, width, height)
  132.   end
  133.   #--------------------------------------------------------------------------
  134.   # * socket_item
  135.   #--------------------------------------------------------------------------
  136.   def socket_item=(socket_item)
  137.     @socket_item = socket_item
  138.     refresh
  139.   end
  140.   #--------------------------------------------------------------------------
  141.   # * refresh
  142.   #--------------------------------------------------------------------------
  143.   def refresh
  144.     contents.clear
  145.     return if @socket_item.nil?
  146.     contents.font.size = Font.default_size
  147.     return if @socket_item == []
  148.     @socket_item = @socket_item[0] if @socket_item.is_a?(Array)
  149.     draw_item_name(@socket_item, 0, 0, true, width)
  150.     contents.font.size = 19
  151.     draw_socket_item_stats
  152.   end
  153.   #--------------------------------------------------------------------------
  154.   # * draw_item_name
  155.   #--------------------------------------------------------------------------
  156.   def draw_item_name(item, x, y, enabled = true, width = 172)
  157.     return unless item
  158.     draw_icon(item.icon_index, x, y - 2, enabled)
  159.     change_color(normal_color, enabled)
  160.     draw_text(x + 24, y, width, line_height, item.name)
  161.   end
  162.   #--------------------------------------------------------------------------
  163.   # * draw_icon
  164.   #--------------------------------------------------------------------------
  165.   def draw_icon(icon_index, x, y, enabled = true)
  166.     bitmap = Cache.system("Iconset")
  167.     rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  168.     contents.blt(x, y, bitmap, rect, enabled ? 255 : 120)
  169.   end
  170.   #--------------------------------------------------------------------------
  171.   # * draw_socket_item_stats
  172.   #--------------------------------------------------------------------------
  173.   def draw_socket_item_stats
  174.     list1 = get_params_values
  175.     list2 = get_stats_values
  176.     list3 = get_feature_values
  177.     list1.each_with_index {|param, i| draw_param_value(param, i, false) }
  178.     list2.each_with_index {|param, i| draw_param_value(param, i + list1.size) }
  179.     list3.each_with_index {|ft, i| draw_feature_value(ft, i) }
  180.     draw_vertical_line_ex(R2_Socket_Config::Vertical_Line_View_X, 0, Color.new(255,255,255,128), Color.new(0,0,0,64))
  181.   end
  182.   #--------------------------------------------------------------------------
  183.   # * get_params_values
  184.   #--------------------------------------------------------------------------
  185.   def get_params_values
  186.     list = []
  187.     @socket_item.params.size.times do |i|
  188.       next if @socket_item.params[i] == 0
  189.       list.push({name: Vocab::param(i), value: @socket_item.params[i]})
  190.     end
  191.     list
  192.   end
  193.   #--------------------------------------------------------------------------
  194.   # * get_stats_values
  195.   #--------------------------------------------------------------------------
  196.   def get_stats_values
  197.     list = []
  198.     @socket_item.stats.keys.each do |i|
  199.       next if @socket_item.stats[i] == 0
  200.       list.push({name: Vocab::param(i), value: @socket_item.stats[i]})
  201.     end
  202.     list
  203.   end
  204.   #--------------------------------------------------------------------------
  205.   # * get_params_values
  206.   #--------------------------------------------------------------------------
  207.   def get_feature_values
  208.     list = []
  209.     @socket_item.features.each_with_index do |ft, i|
  210.       next if ft.data_id == 0
  211.       list.push({name: feature_type(ft), value: @socket_item.features[i]})
  212.     end
  213.     list
  214.   end
  215.   #--------------------------------------------------------------------------
  216.   # * feature_type
  217.   #--------------------------------------------------------------------------
  218.   def feature_type(ft)
  219.     code = get_feature_text(ft.code)
  220.     id = ft.data_id
  221.     return "#{code}-#{id}"
  222.   end
  223.   #--------------------------------------------------------------------------
  224.   # * draw_param_value
  225.   #--------------------------------------------------------------------------
  226.   def draw_param_value(param, i, rate = true)
  227.     name  = param[:name]
  228.     plus  = param[:value] < 0 ? "-" : "+"
  229.     value = sprintf("%02d", param[:value].abs)
  230.     rate  = rate ? "%" : ""
  231.     draw_param_info(name, plus, value, rate, i, width - 176, 108)
  232.   end
  233.   #--------------------------------------------------------------------------
  234.   # * draw_param_info
  235.   #--------------------------------------------------------------------------
  236.   def draw_param_info(name, plus, value, rate, i, x, y)
  237.     z = 88
  238.     contents.draw_text(x + 40, z + i * 18, 172, 24, name)
  239.     contents.draw_text(x + y, z + i * 18, 172, 24, plus)
  240.     change_color(plus == "-" ? knockout_color : crisis_color)
  241.     wid = text_size(plus).width
  242.     contents.draw_text(x + y + wid, z + i * 15, 172, 24, value)
  243.     change_color(normal_color)
  244.     wid += text_size(value).width
  245.     contents.draw_text(x + y + wid, z + i * 15, 172, 24, rate)
  246.   end
  247.   #--------------------------------------------------------------------------
  248.   # * draw_feature_value
  249.   #--------------------------------------------------------------------------
  250.   def draw_feature_value(ft, i)
  251.     title = ""
  252.     data  = ft[:name].split("-")
  253.     name = data[0]
  254.     value = (ft[:value].value * 100).to_i
  255.     id = ft[:value].data_id
  256.     draw_feature_info(name, value, id, i, 0, 108)
  257.   end
  258.   #--------------------------------------------------------------------------
  259.   # * draw_feature_info
  260.   #--------------------------------------------------------------------------
  261.   def draw_feature_info(name, value, id, i, x, y)
  262.     z = 88
  263.     contents.draw_text(x, z + i * 15, 172, 24, name)
  264.     case name
  265.     when "Skill"
  266.       skill = $data_skills[id]
  267.       skname = skill.name
  268.       wid = text_size(skname).width
  269.       change_color(system_color)
  270.       contents.draw_text(70, z + i * 15, 172, 24, skname)
  271.       change_color(normal_color)
  272.     when "Element"
  273.       ele = get_element_name(id)
  274.       wid = text_size(ele).width
  275.       change_color(system_color)
  276.       contents.draw_text(70, z + i * 15, 172, 24, ele)
  277.       change_color(crisis_color)
  278.       wid += text_size(value).width
  279.       contents.draw_text(160, z + i * 15, 172, 24, "#{value}%")
  280.     end
  281.   end
  282.   #--------------------------------------------------------------------------
  283.   # * draw_vertical_line
  284.   #--------------------------------------------------------------------------
  285.   def draw_vertical_line_ex(x, y, color, shadow)
  286.     # // Method to draw a vertical line with a shadow.
  287.     line_x = x + line_height / 2 - 1
  288.     contents.fill_rect(line_x, y, 2, contents_height, color)
  289.     line_x += 1
  290.     contents.fill_rect(line_x, y, 2, contents_height, shadow)
  291.   end
  292. end
  293.  
  294.  
  295. #==============================================================================
  296. # ** Window_SocketItems
  297. #------------------------------------------------------------------------------
  298. #  This window shows the socket item list.
  299. #==============================================================================
  300.  
  301. class Window_SocketItems < Window_Selectable
  302.   #--------------------------------------------------------------------------
  303.   # * Public Instance Variables
  304.   #--------------------------------------------------------------------------
  305.   attr_reader   :socket_window
  306.   #--------------------------------------------------------------------------
  307.   # * initialize
  308.   #--------------------------------------------------------------------------
  309.   def initialize
  310.     super(window_x, 72, 192, window_height)
  311.     @data = []
  312.   end
  313.   #--------------------------------------------------------------------------
  314.   # * window_x
  315.   #--------------------------------------------------------------------------
  316.   def window_x
  317.     352 + [Graphics.width - 544, 0].max
  318.   end
  319.   #--------------------------------------------------------------------------
  320.   # * window_height
  321.   #--------------------------------------------------------------------------
  322.   def window_height
  323.     346 + [Graphics.height - 416, 0].max
  324.   end
  325.   #--------------------------------------------------------------------------
  326.   # * item_max
  327.   #--------------------------------------------------------------------------
  328.   def item_max
  329.     @data ? @data.size : 1
  330.   end
  331.   #--------------------------------------------------------------------------
  332.   # * socket_item
  333.   #--------------------------------------------------------------------------
  334.   def socket_item
  335.     @data[index]
  336.   end
  337.   #--------------------------------------------------------------------------
  338.   # * draw_item
  339.   #--------------------------------------------------------------------------
  340.   def draw_item(index)
  341.     item = @data[index]
  342.     if item
  343.       rect = item_rect(index)
  344.       rect.width -= 4
  345.       draw_item_name(item, rect.x, rect.y)
  346.     end
  347.   end
  348.   #--------------------------------------------------------------------------
  349.   # * draw_item_name
  350.   #--------------------------------------------------------------------------
  351.   def draw_item_name(item, x, y, enabled = true, width = 172)
  352.     return unless item
  353.     draw_icon(item.icon_index, x, y, enabled, item)
  354.     change_color(normal_color, enabled)
  355.     draw_text(x + 24, y, width, line_height, item.name)
  356.   end
  357.   #--------------------------------------------------------------------------
  358.   # * draw_icon
  359.   #--------------------------------------------------------------------------
  360.   def draw_icon(icon_index, x, y, enabled = true, item)
  361.     bitmap = Cache.system("Iconset")
  362.     rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  363.     contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
  364.   end
  365.   #--------------------------------------------------------------------------
  366.   # * refresh
  367.   #--------------------------------------------------------------------------
  368.   def refresh
  369.     make_item_list
  370.     create_contents
  371.     draw_all_items
  372.   end
  373.   #--------------------------------------------------------------------------
  374.   # * make_item_list
  375.   #--------------------------------------------------------------------------
  376.   def make_item_list
  377.     @data = $game_party.socket_items.collect {|socket_item| socket_item }
  378.     @data.push(nil)
  379.   end
  380.   #--------------------------------------------------------------------------
  381.   # * materia_window
  382.   #--------------------------------------------------------------------------
  383.   def socket_window=(socket_window)
  384.     @socket_window = socket_window
  385.     call_update_help
  386.   end
  387.   #--------------------------------------------------------------------------
  388.   # * update_help
  389.   #--------------------------------------------------------------------------
  390.   def update_help
  391.     super
  392.     @socket_window.socket_item = socket_item if @socket_window
  393.     return if socket_item.nil? || socket_item == []
  394.     @help_window.set_item(socket_item)
  395.   end
  396.  
  397. end
  398.  
  399. #==============================================================================
  400. # ** Scene_Socket_Data
  401. #------------------------------------------------------------------------------
  402. #  This class performs the materia equip screen processing.
  403. #==============================================================================
  404.  
  405. class Scene_Socket_Data < Scene_MenuBase
  406.   #--------------------------------------------------------------------------
  407.   # * start
  408.   #--------------------------------------------------------------------------
  409.   def start
  410.     super
  411.     create_help_window
  412.     create_socket_data_window
  413.     create_item_window
  414.   end
  415.   #--------------------------------------------------------------------------
  416.   # * create_help_window
  417.   #--------------------------------------------------------------------------
  418.   def create_help_window
  419.     @help_window = Window_Help.new(2)
  420.     @help_window.viewport = @viewport
  421.   end
  422.   #--------------------------------------------------------------------------
  423.   # * create_materia_window
  424.   #--------------------------------------------------------------------------
  425.   def create_socket_data_window
  426.     ww = 352 + [Graphics.width - 544, 0].max
  427.     wh = 346 + [Graphics.height - 416, 0].max
  428.     @socket_data_window = Window_SocketItemData.new(ww, wh)
  429.     @socket_data_window.viewport = @viewport
  430.   end
  431.   #--------------------------------------------------------------------------
  432.   # * create_item_window
  433.   #--------------------------------------------------------------------------
  434.   def create_item_window
  435.     @item_window = Window_SocketItems.new
  436.     @item_window.viewport = @viewport
  437.     @item_window.help_window = @help_window
  438.     @item_window.socket_window = @socket_data_window
  439.     @item_window.set_handler(:cancel, method(:on_item_cancel))
  440.     @item_window.refresh
  441.     @item_window.activate
  442.     @item_window.select(0)
  443.   end
  444.   #--------------------------------------------------------------------------
  445.   # * on_item_cancel
  446.   #--------------------------------------------------------------------------
  447.   def on_item_cancel
  448.     return_scene
  449.   end
  450. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement