Module:Item Navbox: Difference between revisions

No edit summary
No edit summary
Tag: Manual revert
Line 29: Line 29:
end
end


-- Directly fetches and formats Item text for the navbox (Icons removed)
-- Directly fetches and formats ItemIcons for the navbox
local function get_item_text(slot, min_souls, max_souls, filter_mode)
local function get_item_icons(slot, min_souls, max_souls, filter_mode)
     if slot ~= 'Weapon' and slot ~= 'Armor' and slot ~= 'Tech' then return '' end
     if slot ~= 'Weapon' and slot ~= 'Armor' and slot ~= 'Tech' then return '' end
      
      
Line 57: Line 57:
                  
                  
                 local item_template
                 local item_template
                -- Output as a standard wikilink instead of an icon template
                 if lang_code == "en" then
                 if lang_code == "en" then
                     item_template = "[[" .. item_name_english .. "]]"
                     item_template = "{{ItemIcon|" .. item_name_english .. "|size=26px}}"
                 else
                 else
                     item_template = "[[" .. item_name_english .. "|" .. item_name_local .. "]]"
                     item_template = "{{ItemIcon|" .. item_name_english .. "|lang=" .. lang_code .. "|l1=" .. item_name_local .. "|size=26px}}"
                 end
                 end
                  
                  
Line 90: Line 89:
end
end


-- Generates the Navbox using standard MediaWiki template structure
-- Generates the full HTML item navbox recursively and efficiently
function p.generate_full_navbox(frame)
function p.generate_full_navbox(frame)
     local debug_mode = type(frame) == "table" and frame.args and frame.args["debug_mode"] or nil
     local debug_mode = type(frame) == "table" and frame.args and frame.args["debug_mode"] or nil


     local wikitext = {}
     local html = {}
   
table.insert(html, '<div class="itemnav-header"> [[Items]] <div class="item-nav-search-container"></div></div>\n')
    -- Insert standard stylesheet call
     table.insert(html, '<div class="itemnav-container"><templatestyles src="User:Kai/mp/itemnavbox/styles.css"/>\n')
    table.insert(wikitext, '<templatestyles src="User:Kai/mp/itemnavbox/styles.css"/>\n')
 
   
     -- Maps Headers to Slots and distinct CSS Classes
    -- Start building the main {{Navbox}} call
    table.insert(wikitext, '{{Navbox')
   
    -- IMPORTANT: Change "Template:ItemNavbox" below to the actual name of your template page
    -- so that the v/d/e (view/discuss/edit) links in the top left work properly.
    table.insert(wikitext, '| name  = Template:ItemNavbox')
   
    -- Title including your custom search container element floated to the right
     table.insert(wikitext, '| title = [[Items]] <div class="item-nav-search-container" style="display:inline-block; float:right;"></div>')
      
     local categories = {
     local categories = {
         { header = "Weapon", slot = "Weapon" },
         { header = "Weapon",   slot = "Weapon", css = "itemnav-weapon" },
         { header = "Vitality", slot = "Armor" },
         { header = "Vitality", slot = "Armor",  css = "itemnav-vitality" },
         { header = "Spirit", slot = "Tech" }
         { header = "Spirit",   slot = "Tech",  css = "itemnav-tech" }
     }
     }


    -- Maps tier boundaries and formatting
     local tiers = {
     local tiers = {
         { label = "{{Souls|800}}", min = 0, max = 801 },
         { label = "{{Souls|800}}", min = 0, max = 801 },
Line 120: Line 110:
         { label = "{{Souls|3200}}", min = 1601, max = 3201 },
         { label = "{{Souls|3200}}", min = 1601, max = 3201 },
         { label = "{{Souls|6400}}", min = 3201, max = 6401 },
         { label = "{{Souls|6400}}", min = 3201, max = 6401 },
         { label = '<span class="itemnav-legendary">[[Street Brawl|{{Legendary|{{#invoke:Lang|get_string|Citadel_ItemDraft_Legendary}}}}]]</span>', min = 6401, max = 99999 }
         { label = "[[Street Brawl|{{Legendary|{{#invoke:Lang|get_string|Citadel_ItemDraft_Legendary}}}}]]", min = 6401, max = 99999, extra_css = "itemnav-legendary " }
     }
     }


    -- Loop through categories and build collapsed child navboxes for the vertical layout
     for _, cat in ipairs(categories) do
     for i, cat in ipairs(categories) do
         table.insert(html, '\n<div class="itemnav-type-header">\'\'\'' .. cat.header .. '\'\'\'</div>\n')
        -- Instead of |group=, we drop a full child navbox into the list to span the whole width
         table.insert(html, '<div class="itemnav-type-container">\n')
         table.insert(wikitext, '| list' .. i .. '  = {{Navbox|child')
 
       
         for _, tier in ipairs(tiers) do
        -- Creating the clickable headers for Weapon, Vitality, Spirit
             local css_class = "itemnav-soul " .. (tier.extra_css or "") .. cat.css
        table.insert(wikitext, ' | title = ' .. cat.header)
             local items_wikitext = get_item_icons(cat.slot, tier.min, tier.max, nil)
         table.insert(wikitext, ' | state = collapsed')
 
       
             table.insert(html, '\n<div class="imsodonenamingclasses">\n')
         for j, tier in ipairs(tiers) do
             table.insert(html, '<div class="' .. css_class .. '">' .. tier.label .. '</div><!--\n')
             table.insert(wikitext, '  | group' .. j .. ' = ' .. tier.label)
            table.insert(html, '--><div class="itemnav-cost-type-container">' .. items_wikitext .. '</div>\n')
           
            table.insert(html, '</div>\n')
             local items_string = get_item_text(cat.slot, tier.min, tier.max, nil)
             -- Wrap the items in our flex container for layout
             table.insert(wikitext, ' | list' .. j .. ' = <div class="itemnav-cost-type-container">' .. items_string .. '</div>')
         end
         end
       
 
         table.insert(wikitext, '}}') -- Close subgroup navbox
         table.insert(html, '\n</div>\n')
     end
     end


     table.insert(wikitext, '}}') -- Close parent navbox
     table.insert(html, '\n</div>')


     -- Only ONE preprocess call for the entire structure
     -- Only ONE preprocess call for the entire structure
     return process_debug_mode(table.concat(wikitext, '\n'), debug_mode)
     return process_debug_mode(table.concat(html), debug_mode)
end
end


return p
return p