Advertisement
roninator2

Kid Friendly Basic Quest - Menu Function - Armour

Dec 13th, 2024
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 22.78 KB | None | 0 0
  1. # ╔═════════════════════════════════════╦════════════════════╗
  2. # ║ Title: KFBQ Armour Menu Functions   ║  Version: 1.00     ║
  3. # ║ Author: Roninator2                  ║                    ║
  4. # ╠═════════════════════════════════════╬════════════════════╣
  5. # ║ Function:                           ║   Date Created     ║
  6. # ║                                     ╠════════════════════╣
  7. # ║   FFMQ Style Armour Screens         ║    09 Mar 2023     ║
  8. # ╚═════════════════════════════════════╩════════════════════╝
  9. # ╔══════════════════════════════════════════════════════════╗
  10. # ║ Instructions:                                            ║
  11. # ║                                                          ║
  12. # ║  Set the Windows to look like FFMQ.                      ║
  13. # ║                                                          ║
  14. # ╚══════════════════════════════════════════════════════════╝
  15. # ╔══════════════════════════════════════════════════════════╗
  16. # ║ Terms of use:                                            ║
  17. # ║ Free for all uses in RPG Maker - Except nudity           ║
  18. # ╚══════════════════════════════════════════════════════════╝
  19.  
  20. #==============================================================================
  21. # ** Window ArmourHelp
  22. #==============================================================================
  23. class Window_ArmourHelp < Window_Base
  24.   #--------------------------------------------------------------------------
  25.   # * Object Initialization
  26.   #--------------------------------------------------------------------------
  27.   def initialize(line_number = 1)
  28.     super(0, 0, Graphics.width / 2, fitting_height(line_number))
  29.   end
  30.   #--------------------------------------------------------------------------
  31.   # * Set Text
  32.   #--------------------------------------------------------------------------
  33.   def set_text(text)
  34.     if text != @text
  35.       @text = text
  36.       refresh
  37.     end
  38.   end
  39.   #--------------------------------------------------------------------------
  40.   # * Clear
  41.   #--------------------------------------------------------------------------
  42.   def clear
  43.     set_text("")
  44.   end
  45.   #--------------------------------------------------------------------------
  46.   # * Set Item
  47.   #     item : Skills and items etc.
  48.   #--------------------------------------------------------------------------
  49.   def set_item(item)
  50.     set_text(item ? item.name : "")
  51.   end
  52.   #--------------------------------------------------------------------------
  53.   # * Refresh
  54.   #--------------------------------------------------------------------------
  55.   def refresh
  56.     contents.clear
  57.     draw_text_ex(4, 0, @text)
  58.   end
  59. end
  60.  
  61. #==============================================================================
  62. # ** Window Armour Description
  63. #==============================================================================
  64. class Window_ArmourDescription < Window_Base
  65.   #--------------------------------------------------------------------------
  66.   # * Object Initialization
  67.   #--------------------------------------------------------------------------
  68.   def initialize(line_number = 3)
  69.     super(0, 48, Graphics.width / 2 + 60, fitting_height(line_number))
  70.   end
  71.   #--------------------------------------------------------------------------
  72.   # * Set Text
  73.   #--------------------------------------------------------------------------
  74.   def set_text(text)
  75.     if text != @text
  76.       @text = text
  77.       refresh
  78.     end
  79.   end
  80.   #--------------------------------------------------------------------------
  81.   # * Clear
  82.   #--------------------------------------------------------------------------
  83.   def clear
  84.     set_text("")
  85.     @item = nil
  86.   end
  87.   #--------------------------------------------------------------------------
  88.   # * Set Item
  89.   #     item : Skills and items etc.
  90.   #--------------------------------------------------------------------------
  91.   def set_item(item)
  92.     @item = item
  93.     set_text(item ? item.description : "")
  94.   end
  95.   #--------------------------------------------------------------------------
  96.   # * Refresh
  97.   #--------------------------------------------------------------------------
  98.   def refresh
  99.     contents.clear
  100.     draw_text_ex(4, 0, @text)
  101.     draw_icons if @item
  102.   end
  103.   #--------------------------------------------------------------------------
  104.   # * Draw Icons
  105.   #--------------------------------------------------------------------------
  106.   def draw_icons
  107.     data = []
  108.     list = @item.features
  109.     list.each do |fet|
  110.       if fet.code == 14
  111.         state = $data_states[fet.data_id]
  112.         data << state
  113.       end
  114.     end
  115.     data.each do |st|
  116.       num = st.id
  117.       y = 24
  118.       y = 48 if num >= 11
  119.       num -= 11 if num >= 11
  120.       draw_icon(st.icon_index, num * 24, y)
  121.     end
  122.   end
  123.   #--------------------------------------------------------------------------
  124.   # * Update Bottom Padding
  125.   #--------------------------------------------------------------------------
  126.   def update_padding_bottom
  127.     surplus = (height - standard_padding * 2) % item_height
  128.     self.padding_bottom = padding + surplus - 20
  129.   end
  130.   #--------------------------------------------------------------------------
  131.   # * Draw Icon
  132.   #     enabled : Enabled flag. When false, draw semi-transparently.
  133.   #--------------------------------------------------------------------------
  134.   def draw_icon(icon_index, x, y, enabled = true)
  135.     bitmap = Cache.system("Iconset")
  136.     rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  137.     contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
  138.   end
  139. end
  140.  
  141. #==============================================================================
  142. # ** Window_Item_Command
  143. #==============================================================================
  144. class Window_Armour_Command < Window_Base
  145.   #--------------------------------------------------------------------------
  146.   # initialize
  147.   #--------------------------------------------------------------------------
  148.   def initialize
  149.     super(Graphics.width / 2, 0, Graphics.width / 2, fitting_height(1))
  150.     refresh
  151.   end
  152.   #--------------------------------------------------------------------------
  153.   # dispose
  154.   #--------------------------------------------------------------------------
  155.   def dispose
  156.     contents.dispose unless disposed?
  157.     super unless disposed?
  158.   end
  159.   #--------------------------------------------------------------------------
  160.   # refresh
  161.   #--------------------------------------------------------------------------
  162.   def refresh
  163.     contents.clear
  164.     change_color(crisis_color)
  165.     name = "Armour"
  166.     draw_text(4, 0, 200, line_height, name, 1)
  167.   end
  168. end
  169.  
  170. #==============================================================================
  171. # ** Window_ItemList
  172. #==============================================================================
  173. class Window_ArmourList < Window_Selectable
  174.   #--------------------------------------------------------------------------
  175.   # * Object Initialization
  176.   #--------------------------------------------------------------------------
  177.   def initialize(x, y, width, height)
  178.     @height = height
  179.     super
  180.     @category = :none
  181.     @data = []
  182.   end
  183.   #--------------------------------------------------------------------------
  184.   # * Get Digit Count
  185.   #--------------------------------------------------------------------------
  186.   def col_max
  187.     return 4
  188.   end
  189.   #--------------------------------------------------------------------------
  190.   # * Get Item Height
  191.   #--------------------------------------------------------------------------
  192.   def item_height
  193.     return 60
  194.   end
  195.   #--------------------------------------------------------------------------
  196.   # * Get Item
  197.   #--------------------------------------------------------------------------
  198.   def item
  199.     @data && index >= 0 ? @data[index] : nil
  200.   end
  201.   #--------------------------------------------------------------------------
  202.   # * Get Number of Items
  203.   #--------------------------------------------------------------------------
  204.   def item_max
  205.     @data ? @data.size : 1
  206.   end
  207.   #--------------------------------------------------------------------------
  208.   # * Get Activation State of Selection Item
  209.   #--------------------------------------------------------------------------
  210.   def current_item_enabled?
  211.     return true
  212.   end
  213.   #--------------------------------------------------------------------------
  214.   # * Include in Item List?
  215.   #--------------------------------------------------------------------------
  216.   def include?(item)
  217.     case @category
  218.     when :armor
  219.       item.is_a?(RPG::Armor)# && !item.kfbq_exclude?
  220.     else
  221.       false
  222.     end
  223.   end
  224.   #--------------------------------------------------------------------------
  225.   # * Display in Enabled State?
  226.   #--------------------------------------------------------------------------
  227.   def enable?(item)
  228.     return true
  229.   end
  230.   #--------------------------------------------------------------------------
  231.   # * Create Item List
  232.   #--------------------------------------------------------------------------
  233.   def make_item_list
  234.     @data = []
  235.     subtract = 0
  236.     for i in 1..$data_armors.size - 1
  237.       armour = $data_armors[i]
  238.       if !armour.kfbq_exclude?
  239.         @data[i-1] = nil unless !@data[i-1].nil?
  240.       else
  241.         subtract += 1
  242.         next
  243.       end
  244.       if $game_party.has_item?(armour, true)
  245.         armour.note.split(/[\r\n]+/).each { |line|
  246.           case line
  247.           when /<position:[-_ ](\d+)>/i
  248.             pos = $1.to_i
  249.             @data[pos-1-subtract] = armour
  250.           end
  251.         }
  252.       end
  253.     end
  254.   end
  255.   #--------------------------------------------------------------------------
  256.   # * Determine if Specified Item Is Included in Members' Equipment
  257.   #--------------------------------------------------------------------------
  258.   def members_equip_include?(item)
  259.     members.any? {|actor|
  260.     return false if actor == members[1]
  261.     return true if actor.equips.include?(item) }
  262.   end
  263.   #--------------------------------------------------------------------------
  264.   # * Set Help Window
  265.   #--------------------------------------------------------------------------
  266.   def description_window=(help_window)
  267.     @description_window = help_window
  268.     call_update_help
  269.   end
  270.   #--------------------------------------------------------------------------
  271.   # * Restore Previous Selection Position
  272.   #--------------------------------------------------------------------------
  273.   def select_last
  274.     select(@data.index($game_party.last_item.object) || 0)
  275.   end
  276.   #--------------------------------------------------------------------------
  277.   # * Draw Item
  278.   #--------------------------------------------------------------------------
  279.   def draw_item(index)
  280.     item = @data[index]
  281.     if item
  282.       pos = index % 4
  283.       case pos
  284.       when 0
  285.         ox = 8
  286.       when 1
  287.         ox = 22
  288.       when 2
  289.         ox = 40
  290.       when 3
  291.         ox = 60
  292.       end
  293.       rect = item_rect(index)
  294.       rect.x += ox
  295.       draw_icon(item.icon_index, rect.x, rect.y+30, enable?(item))
  296.     end
  297.   end
  298.   #--------------------------------------------------------------------------
  299.   # * Update Help Text
  300.   #--------------------------------------------------------------------------
  301.   def update_help
  302.     @help_window.set_item(item)
  303.     @description_window.set_item(item)
  304.   end
  305.   #--------------------------------------------------------------------------
  306.   # * Item Rect
  307.   #--------------------------------------------------------------------------
  308.   def item_rect(index)
  309.     rect = Rect.new
  310.     rect.width = 60
  311.     rect.height = 60
  312.     rect.x = index % col_max * (60)
  313.     rect.y = index / col_max * (60)
  314.     rect
  315.   end
  316.   #--------------------------------------------------------------------------
  317.   # * Refresh
  318.   #--------------------------------------------------------------------------
  319.   def refresh
  320.     @category = :armor
  321.     make_item_list
  322.     create_contents
  323.     draw_all_items
  324.   end
  325.   #--------------------------------------------------------------------------
  326.   # * Update Cursor
  327.   #--------------------------------------------------------------------------
  328.   def update_cursor
  329.     ensure_cursor_visible
  330.     cursor_rect.set(item_rect(@index))
  331.     cursor_rect.height += 4
  332.     cursor_rect.width += 8
  333.     pos = index % 4
  334.     case pos
  335.     when 0
  336.       ox = 1
  337.     when 1
  338.       ox = 16
  339.     when 2
  340.       ox = 32
  341.     when 3
  342.       ox = 52
  343.     end
  344.     cursor_rect.x += ox
  345.     cursor_rect.y += 24
  346.   end
  347.   #--------------------------------------------------------------------------
  348.   # * Calculate Height of Window Contents
  349.   #--------------------------------------------------------------------------
  350.   def contents_height
  351.     rows = row_max - 3
  352.     rows = 0 if rows <= 0
  353.     return @height - standard_padding * 2 + rows * 60 + 30
  354.   end
  355.   #--------------------------------------------------------------------------
  356.   # * Calculate Height of Window Contents
  357.   #--------------------------------------------------------------------------
  358.   def standard_padding
  359.     return 12
  360.   end
  361.   #--------------------------------------------------------------------------
  362.   # * Update Bottom Padding
  363.   #--------------------------------------------------------------------------
  364.   def update_padding_bottom
  365.     surplus = (height - standard_padding * 2) % item_height
  366.     self.padding_bottom = padding + surplus - 30
  367.   end
  368. end
  369.  
  370. #==============================================================================
  371. # ** Window_ItemList
  372. #==============================================================================
  373. class Window_ArmourList2 < Window_Selectable
  374.   #--------------------------------------------------------------------------
  375.   # * Object Initialization
  376.   #--------------------------------------------------------------------------
  377.   def initialize(x, y, width, height)
  378.     super
  379.     @category = :none
  380.     @data = []
  381.   end
  382.   #--------------------------------------------------------------------------
  383.   # * Get Digit Count
  384.   #--------------------------------------------------------------------------
  385.   def col_max
  386.     return 1
  387.   end
  388.   #--------------------------------------------------------------------------
  389.   # * Get Number of Items
  390.   #--------------------------------------------------------------------------
  391.   def item_max
  392.     return 5
  393.   end
  394.   #--------------------------------------------------------------------------
  395.   # * Get Item
  396.   #--------------------------------------------------------------------------
  397.   def item
  398.     @data && index >= 0 ? @data[index] : nil
  399.   end
  400.   #--------------------------------------------------------------------------
  401.   # * Include in Item List?
  402.   #--------------------------------------------------------------------------
  403.   def include?(item)
  404.     case @category
  405.     when :armor
  406.       item.is_a?(RPG::Armor)
  407.     when :weapon
  408.       item.is_a?(RPG::Weapon)
  409.     else
  410.       false
  411.     end
  412.   end
  413.   #--------------------------------------------------------------------------
  414.   # * Display in Enabled State?
  415.   #--------------------------------------------------------------------------
  416.   def enable?(item)
  417.     return true
  418.     $game_party.usable?(item)
  419.   end
  420.   #--------------------------------------------------------------------------
  421.   # * Create Item List
  422.   #--------------------------------------------------------------------------
  423.   def make_item_list
  424.     for i in 1..4
  425.       item = $game_party.members[1].equips[i]
  426.       if !item.nil?
  427.         @data[i-1] = item
  428.       else
  429.         @data[i-1] = nil
  430.       end
  431.     end
  432.     @data[4] = $game_party.members[1].equips[0]
  433.   end
  434.   #--------------------------------------------------------------------------
  435.   # * Draw Item
  436.   #--------------------------------------------------------------------------
  437.   def draw_item(index)
  438.     if $game_party.members[1].equips[0] == $data_weapons[16]
  439.       text = ($game_party.ninja_stars?).to_s
  440.       draw_text(130,240,50, 24, text)
  441.     end
  442.     item = @data[index]
  443.     if item
  444.       rect = item_rect(index)
  445.       rect.width -= 4
  446.       draw_icon(item.icon_index, rect.x+60, rect.y, enable?(item))
  447.     end
  448.   end
  449.   #--------------------------------------------------------------------------
  450.   # * Item Rect
  451.   #--------------------------------------------------------------------------
  452.   def item_rect(index)
  453.     rect = Rect.new
  454.     rect.width = 60
  455.     rect.height = 60
  456.     rect.x = index % col_max * (60)
  457.     rect.y = index / col_max * (60)
  458.     rect
  459.   end
  460.   #--------------------------------------------------------------------------
  461.   # * Refresh
  462.   #--------------------------------------------------------------------------
  463.   def refresh
  464.     @actor = $game_party.members[1]
  465.     return if @actor == nil
  466.     make_item_list
  467.     create_contents
  468.     draw_all_items
  469.   end
  470. end
  471.  
  472. #==============================================================================
  473. # ** Armour Total Window
  474. #==============================================================================
  475. class Armour_Total_Window < Window_Base
  476.   #--------------------------------------------------------------------------
  477.   # * Initialize
  478.   #--------------------------------------------------------------------------
  479.  def initialize(x, y, width, height)
  480.     super(x,y,width,height)
  481.     self.z = 140
  482.     self.windowskin = Cache.system("Window_Border")
  483.     self.opacity = 0
  484.     self.arrows_visible = false
  485.     self.pause = false
  486.     self.back_opacity = 0
  487.     self.contents_opacity = 255
  488.     refresh
  489.   end
  490.   #--------------------------------------------------------------------------
  491.   # * Remove Padding
  492.   #--------------------------------------------------------------------------
  493.   def standard_padding
  494.     return 0
  495.   end
  496.   #--------------------------------------------------------------------------
  497.   # * Refresh
  498.   #--------------------------------------------------------------------------
  499.   def refresh
  500.     contents.clear unless disposed?
  501.     return if disposed?
  502.     draw_total
  503.   end
  504.   #--------------------------------------------------------------------------
  505.   # * Draw Total Defense
  506.   #--------------------------------------------------------------------------
  507.   def draw_total
  508.     change_color(crisis_color)
  509.     text = "Defense Total " + ($game_party.members[0].def).to_s
  510.     draw_text(0,0,200, 24, text)
  511.   end
  512. end
  513.  
  514. #==============================================================================
  515. # ** Scene_Item
  516. #==============================================================================
  517. class Scene_Armour < Scene_ItemBase
  518.   #--------------------------------------------------------------------------
  519.   # * Start Processing
  520.   #--------------------------------------------------------------------------
  521.   def start
  522.     super
  523.     create_help_window
  524.     create_description_window
  525.     create_armour_window
  526.     create_actor2_equip_window
  527.     create_armour_command
  528.     create_armour_total
  529.   end
  530.   #--------------------------------------------------------------------------
  531.   # * Create Category Window
  532.   #--------------------------------------------------------------------------
  533.   def create_help_window
  534.     @help_window = Window_ArmourHelp.new
  535.     @help_window.viewport = @viewport
  536.   end
  537.   #--------------------------------------------------------------------------
  538.   # * Create Category Window
  539.   #--------------------------------------------------------------------------
  540.   def create_description_window
  541.     @description_window = Window_ArmourDescription.new
  542.     @description_window.viewport = @viewport
  543.   end
  544.   #--------------------------------------------------------------------------
  545.   # * Create Item Command Text Window
  546.   #--------------------------------------------------------------------------
  547.   def create_armour_command
  548.     @command_window = Window_Armour_Command.new
  549.     @command_window.viewport = @viewport
  550.   end
  551.   #--------------------------------------------------------------------------
  552.   # * Create Item Window
  553.   #--------------------------------------------------------------------------
  554.   def create_armour_window
  555.     ww = Graphics.width / 2 + 60
  556.     wy = @description_window.y + @description_window.height
  557.     wh = Graphics.height - wy - 100
  558.     @armour_window = Window_ArmourList.new(0, wy, ww, wh)
  559.     @armour_window.viewport = @viewport
  560.     @armour_window.help_window = @help_window
  561.     @armour_window.description_window = @description_window
  562.     @armour_window.set_handler(:ok,     method(:on_item_ok))
  563.     @armour_window.set_handler(:cancel, method(:return_scene))
  564.     @armour_window.refresh
  565.     @armour_window.activate
  566.     @armour_window.select(0)
  567.   end
  568.   #--------------------------------------------------------------------------
  569.   # * Create Item Window
  570.   #--------------------------------------------------------------------------
  571.   def create_actor2_equip_window
  572.     wx = Graphics.width / 2 + 60
  573.     ww = Graphics.width - wx
  574.     wh = Graphics.height - 148
  575.     @armour_window2 = Window_ArmourList2.new(wx, 48, ww, wh)
  576.     @armour_window2.viewport = @viewport
  577.     @armour_window2.help_window = @help_window
  578.     @armour_window2.set_handler(:cancel, method(:return_scene))
  579.     @armour_window2.refresh
  580.   end
  581.   #--------------------------------------------------------------------------
  582.   # * Create Item Command Text Window
  583.   #--------------------------------------------------------------------------
  584.   def create_armour_total
  585.     @total_window = Armour_Total_Window.new(50, 150, 200, 24)
  586.     @total_window.viewport = @viewport
  587.   end
  588.   #--------------------------------------------------------------------------
  589.   # * Item [OK]
  590.   #--------------------------------------------------------------------------
  591.   def on_item_ok
  592.     if @armour_window.item.nil?
  593.       Sound.play_buzzer
  594.       @armour_window.activate
  595.       return
  596.     end
  597.     slot_id = @armour_window.item.etype_id
  598.     Sound.play_equip
  599.     @actor.change_equip(slot_id, @armour_window.item)
  600.     @armour_window.refresh
  601.     @armour_window.activate
  602.   end
  603. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement