Add New Category for FS22?

Your forum for all discussions around Modding.
darkenb
Posts: 4
Joined: Wed Jun 21, 2023 12:24 pm

Add New Category for FS22?

Post by darkenb »

I'm searching for mod to add a new category to Farming Simulator 22?
User avatar
Dogface
Posts: 1094
Joined: Mon Nov 28, 2016 3:02 pm
Location: PC ⛽ USA

Re: Add New Category for FS22?

Post by Dogface »

new category?
darkenb
Posts: 4
Joined: Wed Jun 21, 2023 12:24 pm

Re: Add New Category for FS22?

Post by darkenb »

Yes, I want to add a new category for some mods to the game. I couldn't find a mod. I researched how to do it but it will take time to figure it out on my own.
darkenb
Posts: 4
Joined: Wed Jun 21, 2023 12:24 pm

Re: Add New Category for FS22?

Post by darkenb »

Dogface wrote: Wed Jun 21, 2023 6:19 pm new category?
You are a mod maker, right? You can help with this. I am looking for the same mod below for FS 22.

Link: https://www.farming-simulator.com/mod.p ... _id=151498
User avatar
Dogface
Posts: 1094
Joined: Mon Nov 28, 2016 3:02 pm
Location: PC ⛽ USA

Re: Add New Category for FS22?

Post by Dogface »

Ah, store vehicle/tool categories.

I don't know much about scripts, sorry. You might contact the author and see if he plans to update it for FS22. He has FS22 mods.
Ziuta Modding
Moderator
Posts: 968
Joined: Sun Jul 17, 2016 9:40 am

Re: Add New Category for FS22?

Post by Ziuta Modding »

No script required, Giants added this capability via modDesc

Code: Select all

<storeCategories>
    <storeCategory name="vehicle" title="$l10n_vehicle" image="icons/icon.dds" type="VEHICLE" />
    <storeCategory name="tool" title="$l10n_tool" image="icons/icon2.dds" type="TOOL" />
    <storeCategory name="object" title="$l10n_object" image="icons/icon3.dds" type="OBJECT"/>
    <storeCategory name="placeable" title="$l10n_placeable" image="icons/icon4.dds" type="PLACEABLE" />
</storeCategories>
SeanBeales29
Posts: 2
Joined: Mon Apr 15, 2024 11:56 pm

Re: Add New Category for FS22?

Post by SeanBeales29 »

I tried this yesterday and today ziuta and it won't work for placeables maybe I am doing something wrong
Ziuta Modding
Moderator
Posts: 968
Joined: Sun Jul 17, 2016 9:40 am

Re: Add New Category for FS22?

Post by Ziuta Modding »

SeanBeales29 wrote: Sun Apr 28, 2024 7:02 pm I tried this yesterday and today ziuta and it won't work for placeables maybe I am doing something wrong
Ah yes, unfortunately Giants blocked these new features only for DLC, it is possible to bypass this “block” through a rather short script, because the features themselves and the layout of the lines is already available in general, you just need to tell the game to look for them in modDesc mod too, not just DLC.
SeanBeales29
Posts: 2
Joined: Mon Apr 15, 2024 11:56 pm

Re: Add New Category for FS22?

Post by SeanBeales29 »

Do u know where I could find the short script to edit to my own
XPModder
Posts: 74
Joined: Thu Oct 30, 2014 2:45 pm

Re: Add New Category for FS22?

Post by XPModder »

Was just looking for the same thing and found this thread.
As there was no script given here that would do this, I wrote my own.

So here is a simple script that allows loading of store categories from mods:

Code: Select all

--[[
========================================================================================================================================================================
                                                                        Store Categories
========================================================================================================================================================================
Enables loading of store categories from modDesc (basegame only allows this from dlc)
]]

StoreCategoryLoader = {
    once = 0
}

function StoreCategoryLoader:loadCategories(xmlHandle, key, isDLCFile, modDir, modName)

    if once == 1 then
        return
    end

    local xmlFile = XMLFile.load("ModFile", modDir .. "/modDesc.xml")

    xmlFile:iterate("modDesc.storeCategories.storeCategory", function (_, key)
        g_storeManager:loadCategoryFromXML(xmlFile, key, modDir, modName)
    end)
    print("  Loaded store categories!")

    xmlFile:delete()

    once = 1

end

TypeManager.loadTypeFromXML = Utils.prependedFunction(TypeManager.loadTypeFromXML, StoreCategoryLoader.loadCategories)
It was pretty easy to figure this out.
The only thing that took me a minute was to find the right place to run this as it has to be very early on in loading. It has to happen before any vehicles or placeables are loaded as otherwise the game will throw errors.
I thought about running it with loading of the script, but then Id have to do the whole modDir and modName myself. Luckily TypeManager already gets this info and is called very early on...
The once variable is needed here, so that it doesnt try to add the categories 2 times, as the game uses 2 instances of TypeManager and therefore TypeManager.loadTypeFromXML gets called twice during mod loading. (once for vehicles and once for placeables)
With this variable, it will run the first time and set the variable, then when it gets called again it will just immediately return as the variable is set already.

The "Store Categories" kind of header comment is there because I have a bunch of other stuff in the same script file and have these headers to navigate a bit easier. Its just a comment, so you can leave it out if you want...
Das Universum ist unvorstellbar groß und wir sind im Vergleich dazu winzig.

Daher kann mir jemand der unter uns Winzlingen Unterschiede in Hautfarbe oder Herkunft sucht, nur Leid tun, weil seine Sichtweise so begrenzt ist!

Fremdenfeindlichkeit ist Menschenfeindlichkeit!
XPModder
Posts: 74
Joined: Thu Oct 30, 2014 2:45 pm

Re: Add New Category for FS22?

Post by XPModder »

Addition to the above:
I added functionality to also load construction categories and tabs for the construction screen/menu to this.
The code that does this for the default ones is in StoreManager and can be found in the luadoc on GDN.
https://gdn.giants-software.com/documen ... apData4154
It is just hardcoded to load from a xml file in dataS in the game.
So I basically copy-pasted that bit of code into my script and just changed it to load directly from the modDesc instead of another xml file.

Here is the update code:

Code: Select all

--[[
========================================================================================================================================================================
                                                                        Store Categories
========================================================================================================================================================================
Enables loading of store categories from modDesc (basegame only allows this from dlc)
Additionally loads new construction categories and tabs from modDesc
]]

StoreCategoryLoader = {
    once = 0
}

function StoreCategoryLoader:loadCategories(xmlHandle, key, isDLCFile, modDir, modName)

    if once == 1 then
        return
    end

    local xmlFile = XMLFile.load("ModFile", modDir .. "/modDesc.xml")

    xmlFile:iterate("modDesc.storeCategories.storeCategory", function (_, key)
        g_storeManager:loadCategoryFromXML(xmlFile, key, modDir, modName)
    end)

    local xmlHandle = xmlFile:getHandle()

    if hasXMLProperty(xmlHandle, "modDesc.constructionCategories") then
        local defaultIconFilename = xmlFile:getString("modDesc.constructionCategories#defaultIconFilename")
        local defaultRefSize = xmlFile:getVector("modDesc.constructionCategories#refSize", {1024, 1024}, 2)
        xmlFile:iterate("modDesc.constructionCategories.category", function(_, key)
            local categoryName = xmlFile:getString(key .. "#name")
            local title = g_i18n:convertText(xmlFile:getString(key .. "#title"), modName)
            local iconFilename = xmlFile:getString(key .. "#iconFilename") or defaultIconFilename
            local refSize = xmlFile:getVector(key .. "#refSize", defaultRefSize, 2)
            local iconUVs = GuiUtils.getUVs(xmlFile:getString(key .. "#iconUVs", "0 0 1 1"), refSize)
            g_storeManager:addConstructionCategory(categoryName, title, iconFilename, iconUVs, "")
            xmlFile:iterate(key .. ".tab", function(_, tKey)
                local tabName = xmlFile:getString(tKey .. "#name")
                local tabTitle = g_i18n:convertText(xmlFile:getString(tKey .. "#title"), modName)
                local tabIconFilename = xmlFile:getString(tKey .. "#iconFilename") or defaultIconFilename
                local tabRefSize = xmlFile:getVector(tKey .. "#refSize", defaultRefSize, 2)
                local tabIconUVs = GuiUtils.getUVs(xmlFile:getString(tKey .. "#iconUVs", "0 0 1 1"), tabRefSize)
                g_storeManager:addConstructionTab(categoryName, tabName, tabTitle, tabIconFilename, tabIconUVs, "")
            end)
        end)
    end

    print("  Loaded store categories!")

    xmlFile:delete()

    once = 1

end

TypeManager.loadTypeFromXML = Utils.prependedFunction(TypeManager.loadTypeFromXML, StoreCategoryLoader.loadCategories)
In the modDesc I then have this entry:

Code: Select all

    <constructionCategories defaultIconFilename="ui_construction_icons.png" refSize="256 256">
        <category name="lowerSaxony" title="$l10n_construction_category_LS_lowerSaxony" iconUVs="0 0 32px 32px">
            <tab name="roads" title="$l10n_construction_tab_LS_roads" iconUVs="41px 0 32px 32px" />
            <tab name="paths" title="$l10n_construction_tab_LS_paths" iconUVs="80px 0 32px 32px" />
            <tab name="bridges" title="$l10n_construction_tab_LS_bridges" iconUVs="200px 0 32px 32px" />
            <tab name="contructionProjects" title="$l10n_construction_tab_LS_contructionProjects" iconUVs="120px 0 32px 32px" />
            <tab name="buildings" title="$l10n_construction_tab_LS_buildings" iconUVs="160px 0 32px 32px" />
            <tab name="other" title="$l10n_construction_tab_LS_other" iconUVs="41px 120px 32px 32px" />
        </category>
    </constructionCategories>
This all works without errors or warnings.

Edit: fixed a small bug where it wouldnt load the correct l10n entries
Das Universum ist unvorstellbar groß und wir sind im Vergleich dazu winzig.

Daher kann mir jemand der unter uns Winzlingen Unterschiede in Hautfarbe oder Herkunft sucht, nur Leid tun, weil seine Sichtweise so begrenzt ist!

Fremdenfeindlichkeit ist Menschenfeindlichkeit!
XPModder
Posts: 74
Joined: Thu Oct 30, 2014 2:45 pm

Re: Add New Category for FS22?

Post by XPModder »

Funny thing I found with the above code to add new construction categories:
I guess my script runs that bit a little bit earlier during loading then the basegame one, but basically the new category ends up all the way to the left (so in front of the basegame ones).
This seems to result in some basegame sheds (namely the ones from Rudolf Hormann) that are missing a bit of information in their storeData to end up in the first tab of my new category... lol
I dont know if there is anything I can do about this, as if I were to add that bit of code to a function appended to StoreManager:loadMapData then it wont work as the store items would be loaded before the category would be added.
I think this should be seen as a bug in the base game anyways, as the xmls for these buildings are simply missing the brush tag and its contents entirely.
Das Universum ist unvorstellbar groß und wir sind im Vergleich dazu winzig.

Daher kann mir jemand der unter uns Winzlingen Unterschiede in Hautfarbe oder Herkunft sucht, nur Leid tun, weil seine Sichtweise so begrenzt ist!

Fremdenfeindlichkeit ist Menschenfeindlichkeit!
sablerock
Posts: 119
Joined: Sat Dec 10, 2022 1:58 pm

Re: Add New Category for FS22?

Post by sablerock »

There’s some experts here
Can you help with my topic

viewtopic.php?p=1609746#p1609746
Post Reply