andrewgu / ModConfigMenu

XCOM 2 Mod Config Menu: a project to build a shared settings menu for Xcom 2 mods.
11 stars 13 forks source link

ModConfigMenu should set/save config values automatically #8

Closed BlueRaja closed 7 years ago

BlueRaja commented 8 years ago

The SaveButtonClicked for nearly every mod is going to be the same: Get the values of each setting, save them each to some variable, call SaveConfig(). The API can and should handle that automatically.

Superd22 commented 8 years ago

the api can't do much on its own, see #1

BlueRaja commented 8 years ago

Oh, hrm. You can pass a value-type-reference in unrealscript using out, but there doesn't seem to be any way to save that reference for later, the language has no reference/pointer types or closures.

I thought for sure there'd be some way to do this, but I think you're right that there's not :(

[Edit] Hmm, maybe there is some way to have all the variables managed by ModConfigMenu, rather than using config var's in the mods themselves, using an array of key-value pairs.

Or, we could write a macro that classes will use to declare their config variables, which could expose getters/setters for our class.

I'm pretty sure one of these methods will work.

Superd22 commented 8 years ago

This is what i tried to do for my own version of MCM before we switched to this one. There is NO reflection whatsoever in UnrealScript as in they purposely patched it out of the language.

1/ Arrays : Arrays are not passed by reference but copied around in memory in unrealscript (see https://wiki.beyondunreal.com/Dynamic_arrays) So any change the MCM would make wouldn't be copied in the mod.

2/ Macro : Like arrays, all primitive type are passed around by copy and not by reference, the only ref in us are for classes/objects. So yeah, you could declare a macro, set a copy of every variable in memory inside MCM, then do all the logic on MCM side... Then you'd end-up with all your variables and NO WAY to replicate them in the mod class.

Again, i can't stress it enough, no reflection means you cannot infer at runtime what members an object has, nor can you change it even if you know it does.

You could store all configs in MCM and let it handle everything, and only acess/set-up config via MCM functions, but that means your mod would break if the user doesn't have MCM, which is not what we want.

BlueRaja commented 8 years ago

Sorry, I didn't explain my suggestions very well.

I spoke with @andrewgu, we both agreed the second option (using macros to generate default implementations) would be better. The first suggestion (managing all config values through the mod) wouldn't work if we want to keep the mod optional.

andrewgu commented 8 years ago

I'll mock up what @BlueRaja meant later tonight. I think that should demonstrate the point better.

BlueRaja commented 8 years ago

Actually I'm starting to think this request won't be doable, I can't think of a way of doing this that will support nice cancellation. I've opened #13 as a replacement idea, which is better UI anyways.

It might be possible to do both, but if there is, I can't think of it..

andrewgu commented 8 years ago

Leaving this open for the possibility that we might internalize the settings in the future, but for the time being it is not being implemented. Instead, there are some helper macros so that saving values when the user clicks "Save and Exit" can be done in a few lines.

andrewgu commented 7 years ago

Closing this as a "won't fix". For the foreseeable future, I think the helper macros will be sufficient. Might reopen this in the future if we find a better way to approach the problem.