[MOD] Improved Object Menu

The place to discuss scripting and game modifications for X Rebirth.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

Post Reply
User avatar
MegaJohnny
Posts: 2195
Joined: Wed, 4. Jun 08, 22:30
x4

[MOD] Improved Object Menu

Post by MegaJohnny » Fri, 23. Mar 18, 20:09

Here's my next menu overhaul! This time, it's the object details menu. You use this a lot in XR for many different types of objects, but I sadly don't find the vanilla one very nice to use. It gets the job done, obviously. But it's a pain to expand and collapse all these sections to find what you want, it has lots of (IMO) wasted space, and nothing updates like it did in X3. So this is just my attempt at a replacement that does all these things.

Changes
  • Two columns! Make use of that screen space!
  • Extra information on many rows, and more use of colour for readability/to catch your eye on any warnings (see images!)
  • Smaller font if the menu thinks it's running in a high resolution
  • Many things update in quasi-realtime - ware amounts, production status, crew commands, location, etc...
  • Most categories are expanded by default (now we have the luxury of double the rows)
  • C hotkey is enabled - if you have an NPC selected it comms that NPC, otherwise it comms the object normally
  • Shipyards have their build modules displayed (mostly for fun, but maybe this is useful if you have a player shipyard mod? let me know...)
Images
Freighter with colour-coded shopping list info
Olmekron starts repairs after a combat mission (see the engineer row showing at a glance what's under repair)
Plot URV forge chugging away (empty resources are still displayed among the cargo, in grey)

Download
Nexusmods
Steam Workshop

Notes
There maybe some niggles with when data is displayed vs. when it should display ???. I'll try to squash these as I find them!
Last edited by MegaJohnny on Wed, 24. Oct 18, 09:58, edited 1 time in total.

bitvoid
Posts: 119
Joined: Wed, 6. Nov 02, 20:31
x4

Re: [MOD/WIP] Improved Object Menu

Post by bitvoid » Wed, 24. Oct 18, 07:52

Hi MegaJohnny, I've been using your excellent mod for a while now with the New Frontiers mod. One thing I noticed is that it crashes when trying to view the details of a shipyard with damaged build modules that are unable to produce anything. While I can imagine this also happening on Vanilla I didn't actually try it out.

I've patched the "rcProduction:display" function with some added nil checks to prevent the crash, feel free to include it if you want :)

Code: Select all

function rcProduction:display(setup, module)
    self.module = module
    self.nameKnown = IsInfoUnlockedForPlayer(module, "name")
    self.timeKnown = IsInfoUnlockedForPlayer(module, "production_time")
    self.effKnown = IsInfoUnlockedForPlayer(module, "efficiency_amount")
    
    self.name = Helper.unlockInfo(self.nameKnown, GetComponentData(module, "name"))
    
    local data = GetProductionModuleData(module)
    self.data = data
    
    local productText
    local iconCell = ""
    if data.products and data.products[1] ~= nil then
        local product = data.products[1]
        productText = "\27Z" .. ConvertIntegerString(product.cycle * 3600 / data.cycletime, true, 4, true) .. "x\27X" .. product.name
        if self.effKnown then
            iconCell = Helper.createIcon(GetWareData(product.ware, "icon"), false, 255, 255, 255, 100, 0, 0, Helper.standardTextHeight, Helper.standardButtonWidth)
        end
    else
        productText = "\27Z--"
    end
    
    self.lastState = data.state
    self.lastWare = data.products and data.products[1] ~= nil and data.products[1].ware
    
    self.row = setup:addRow(true, {
        iconCell,
        self:getNameText(),
        Helper.unlockInfo(self.effKnown, productText),
        Helper.unlockInfo(self.timeKnown, self:getTimeText())
    }, self, {1, 1, 3, 1})
end

User avatar
MegaJohnny
Posts: 2195
Joined: Wed, 4. Jun 08, 22:30
x4

Re: [MOD/WIP] Improved Object Menu

Post by MegaJohnny » Wed, 24. Oct 18, 09:54

Thanks a lot for the report! I imagine the bug will be just the same in vanilla. I'll check it out tonight and upload a patch with your changes in. :)

Edit: I didn't get round to it yesterday, but I promise I haven't forgotten, and will get a look at it soon.

bitvoid
Posts: 119
Joined: Wed, 6. Nov 02, 20:31
x4

Re: [MOD/WIP] Improved Object Menu

Post by bitvoid » Fri, 26. Oct 18, 19:25

MegaJohnny wrote:
Wed, 24. Oct 18, 09:54
Edit: I didn't get round to it yesterday, but I promise I haven't forgotten, and will get a look at it soon.
No worries, I'm not in a hurry :)

User avatar
MegaJohnny
Posts: 2195
Joined: Wed, 4. Jun 08, 22:30
x4

Re: [MOD/WIP] Improved Object Menu

Post by MegaJohnny » Sat, 27. Oct 18, 22:11

bitvoid wrote:
Fri, 26. Oct 18, 19:25
No worries, I'm not in a hurry :)
OK, I've managed to look at your changes, and it turns out I wasn't using "lastWare" anywhere at all :roll: so thanks for bringing that to light, haha!

Just to clarify, your post mentioned the bug being to do with build modules, but I don't think the production rowclass is affected by this - and I didn't get any errors when viewing a station with a destroyed production module. Do you have any debuglog output from when the bug happened?

bitvoid
Posts: 119
Joined: Wed, 6. Nov 02, 20:31
x4

Re: [MOD/WIP] Improved Object Menu

Post by bitvoid » Sun, 28. Oct 18, 08:34

Thank you for looking into this.
MegaJohnny wrote:
Sat, 27. Oct 18, 22:11
Just to clarify, your post mentioned the bug being to do with build modules, but I don't think the production rowclass is affected by this - and I didn't get any errors when viewing a station with a destroyed production module. Do you have any debuglog output from when the bug happened?
Oh well, looks like I remembered that wrong. The station that I initially had this problem with was a Xenon Shipyard which has both XL/L ship productions and also a production line for small ships. It turns out that it was not the damage on the big ship productions that triggered it but instead the damage on the small ship production (which is a regular production module FWIW).

I managed to reproduce the problem by loading up one of the saves I used to reproduce the problem at first when I was still thinking that this may be a problem with the New Frontiers mod and even saw another problem, but first the debuglog entry from trying to open the object details menu when the small ship production (Medium Shipyard) module is damaged:

Code: Select all

[General] 9228.62 ======================================
[=ERROR=] 9228.62 Error while executing onEvent script for event: showObjectMenu.
Errormessage: [string "extensions/mej_improved_object_menu/ui/addons..."]:886: attempt to index local 'product' (a nil value)
[General] 9228.62 ======================================
[General] 9228.62 ======================================
[=ERROR=] 9228.62 Error detected while displaying Improved Object Menu! Please contact MegaJohnny with the relevant error messages
[General] 9228.62 ======================================
In the save I still had laying around the module was at 100% already and I had to destroy it again. To find it I wanted to set a waypoint to the module from the map. When I tried to open the object details of that module I as greeted with another crash, this is what I got in the debuglog for it:

Code: Select all

[General] 9079.07 ======================================
[=ERROR=] 9079.07 C:/Spiele/SteamLibrary/steamapps/common/X Rebirth/extensions/mej_improved_object_menu/ui/addons...(413): GetWareCapacity(): Component 'Mittlere Schiffswerft' is not of class container
[General] 9079.07 ======================================
[General] 9079.07 ======================================
[=ERROR=] 9079.07 Error while executing onEvent script for event: showObjectMenu.
Errormessage: [string "extensions/mej_improved_object_menu/ui/addons..."]:413: attempt to compare number with nil
[General] 9079.07 ======================================
[General] 9079.07 ======================================
[=ERROR=] 9079.07 Error detected while displaying Improved Object Menu! Please contact MegaJohnny with the relevant error messages
[General] 9079.07 ======================================
I tested another change which seems to prevent the problem from happening (if combined with my first change to "rcProduction:display") but I don't know if that's how you'd like to address this. The root of this issue seems to be that "GetWareCapacity" will return nil for the damaged small ship production module.

Code: Select all

function rcWare:getWareAmountCell()
    local mot
    local amountString = ConvertIntegerString(self.ware.amount, true, 4, true)
    
    --decide the color of the amount, and whether there should be any "x / y" bit
    if self.ware.amount == 0 then
            amountString = "\27Z" .. amountString .. "\27X"
    elseif menu.isPlayerOwned then
        local capacity = GetWareCapacity(menu.object, self.ware.ware, false)
        if capacity ~= nil then
            self.isFull = next(self.category.productCycleAmounts) and (capacity <= self.cycleAmount or (self.limit - self.cycleAmount) < self.ware.amount)
        else
            self.isFull = false
        end
        if self.isFull then
            if self.cycleAmount > 0 then
                --it's a product with full storage (which actually stalls production so it gets a harsher colour)
                amountString = "\27R" .. amountString .. "\27X"
                mot = ReadText(1001, 1125)
            else
                --it's a resource with full storage
                amountString = "\27Y" .. amountString .. "\27X"
                mot = ReadText(1001, 1126)
            end
        end
    end
    
    if menu.isPlayerOwned and self.limit > 0 then
        amountString = amountString .. " / " .. ConvertIntegerString(self.limit, true, 4, true)
    end
    
    return Helper.createFontString(amountString, false, "right", 255, 255, 255, 100, nil, nil, nil, nil, nil, nil, nil, mot)
end
Edit: If you're interested I can also upload the save somewhere. But you'd need to have at least the New Frontiers mod installed to run it.

Edit2: Looks like even with my second change, it still spams the debuglog a little afterwards when opening the object details of the single module:

Code: Select all

[General] 9305.03 ======================================
[=ERROR=] 9305.03 C:/Spiele/SteamLibrary/steamapps/common/X Rebirth/extensions/mej_improved_object_menu/ui/addons...(413): GetWareCapacity(): Component 'Mittlere Schiffswerft' is not of class container
[General] 9305.03 ======================================
Edit3: I did some more testing and managed to reproduce the "rcProduction" error using a mostly complete vanilla setup. The only mod I had active was Simooms Lantern to speed up the testing process, but that should not really influence the results. I started a new "Free Play" game and after equipping the Skunk a bit jumped straight to "Cuspid Splint" in Albion. I then damaged one of the medium shipyard modules of the Ledda Industrial small shipyard there to roughly 80%. After that when opening the object details menu for the whole station or the single module the "rcProduction" nil error happens.

I did not manage to reproduce the second error from above. Not even after using Simooms Lantern to take over the station since I saw that it would only trigger on player-owned stations. So I'm still a bit unsure under which conditions that one happens. I suppose in plain vanilla this one would never happen since there is no way to own a small ship production without using mods.

I've uploaded the savegame of that experiment, you can download it here. It should be safe to load this without any mods enabled besides the official DLCs. After loading you should have the damage medium shipyard module in target. Just try opening the object details menu of the module or the whole station and you should see the error. Watch out though, Ledda Industrial is still a little upset about my testing methods :lol:

User avatar
MegaJohnny
Posts: 2195
Joined: Wed, 4. Jun 08, 22:30
x4

Re: [MOD/WIP] Improved Object Menu

Post by MegaJohnny » Sun, 28. Oct 18, 16:26

Thanks so much for the detailed report, it's a big help! I downloaded your save and the problem is reproduced just fine. Your fix from the earlier post seems like the way to go, so I'll get that uploaded very soon.

Definitely strange about GetWareCapacity being fired when it shouldn't be - I'm not sure how that could happen, but for now I'll just do some defensive programming and hope it goes away.

Thanks again for investigating this bug :)

bitvoid
Posts: 119
Joined: Wed, 6. Nov 02, 20:31
x4

Re: [MOD] Improved Object Menu

Post by bitvoid » Sun, 28. Oct 18, 16:49

Thank you for creating this mod in the first place. It's gems like this that still help me enjoy X:Rebirth to this very day.

I can see that it probably took a lot of effort to create this mod so when reporting problems I want to put in a little effort from my side as well. I feel that it's also in my best interest because this way I can continue using the mods I like. And if it also helps some others, it's all the better.

Again, thank you for creating this mod. After using it for quite some time I wouldn't want to go back to the vanilla object menu any more :mrgreen:

User avatar
MegaJohnny
Posts: 2195
Joined: Wed, 4. Jun 08, 22:30
x4

Re: [MOD] Improved Object Menu

Post by MegaJohnny » Tue, 30. Oct 18, 20:29

It's very much appreciated, there's (evidently) so many permutations of what states a game can be in, that getting a look at the debug log, or a save game, or any reproduction steps, makes things so much easier.

Anyway the update is out as of Sunday; if you're downloading from Nexusmods I recommend as always to delete your old folder first. ;)

Post Reply

Return to “X Rebirth - Scripts and Modding”