Jump to content

attempt to mod Liquid Valve


Recommended Posts

 

I attempt to create a custom mod to extract exact quantity amount of liquid.

Reusing vanila liquid valve seems to be best approach.

My process approach is gradually decrease the user entered amount every time an amount of liquid flow through the item, till it reach 0 and stop the flowing.

Putting an empty container/reservoir after the item should collect that exact quantity of liquid.

***

My problem is I can't get the data entry/input ui shows up. I believe the code is ValveSideScreen.

 

I have done another mod modifying the gas/liquid filter, the data entry is temperature setting like the temperature monitor, can be done simply implement the interface IThresholdSwitch at the process/controller/logic class.

 

But ValveSideScreen is a class, and I see no interface involved.

I tried search the original code trying to figure out how the ui being invoked by the Valve and ValveBase class, but I got no good clues.

https://github.com/kelmen/ONI-Mods/tree/master/Kelmen.ONI.Mods.ValvesEx

 


 

Link to comment
Share on other sites

First of all, don't fall into the trap where inheriting vanilla buildings seems to be a nice shortcut. Based on personal experience when you do that, ONI updates and then your mod breaks. Copy pasting the class you want to inherit works more reliably.

39 minutes ago, kelmen said:

Now i try using the ISingleSliderControl .

In game, I can see the expected slider control like the liquid valve data input. 

But I can't update the value. It just keep reset any data entered/slided to zero!

You need to look at the interface class you are using, in this case ISliderControl. When the user does something to the slider, the game will call your code with a set method, in this case SetSliderValue. This will give you the new values, which you are responsible for storing and return whenever the get methods are called. You are also responsible for saving those variables in savegames.

Link to comment
Share on other sites

I managed to fix that, it seems like the GetSliderMaxValue is being invoked the moment the class is being instantiate.
Generally this method should be invoked later, giving the instance to have proper setup done first, but it doesn't seems to work in such way.

I set a property in the class to indicate its for liquid purpose, and thus set the max value. But this max value is no longer being fetched by the ISingleSliderControl.GetSliderMaxValue, as that method is invoked already, and I guess it's likely during the object instantiation.

have to fix/hard-code the material type and max value in the class.

now it can accept value, and work as expected.

but now I got new problem:
the single slider data entry allow ** 3 ** numbers to be keyed in, including the decimal.
if i use Gram measurement, it's going to take freaking multiple times to transfer high volume in KG, like 5KG.

As each time it only allow up to 999G

 

if i change it to KG, then I lose precision control, as it's only accept up to minimum hundred based Gram value.

Attempt to pass 50G won't worked, as the control will round it up to 0.1KG = 100G

***
May change the code later to avoid reusing vanilla items, but at moment my changes compare to the vanilla is quite small, only the logic is different.
it's on low priority for me now.

Link to comment
Share on other sites

i change the decimal places to 5, the input still limit to 3. guess it is as by current implementation

i end up making 2 items, 1 for measurement in gram, the other in KG. so precise control can be done with over these 2

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
×
  • Create New...