[REL] Settings Manager v1.6.0 [67342]

Discussion in 'Released Mods' started by Raevn, December 9, 2013.

  1. DeathByDenim

    DeathByDenim Post Master General

    Messages:
    4,328
    Likes Received:
    2,125
    Weird. I just plunked your code as is in my favourite colour mod and it just works... (I mean your previous version without the model.)
  2. LavaSnake

    LavaSnake Post Master General

    Messages:
    1,620
    Likes Received:
    691
    Odd. Well just for the fun of it, here's my full code:
    Code:
    $(function () {
        var settings = decode(localStorage.settings);
        var rules = settings.LUnitNames_Rules_options;
        var selected = settings.LUnitNames_Rules;
        if (!rules) {
            rules = new Array();
        }
        if (!selected) {
            selected = new Array();
        }
           
        model.addSetting_MultiSelect("Rules to apply to units for renaming:", "LUnitNames_Rules", "UI", rules, 0, 10, "Unit renaming rules");
        model.addSetting_Button("", "Add new rule", "UI", "model.LUnitNames_Add", "Unit renaming rules");
        model.addSetting_Button("", "Edit selected rule", "UI", "model.LUnitNames_Edit", "Unit renaming rules");
        model.addSetting_Button("", "Remove selected rule", "UI", "model.LUnitNames_Remove", "Unit renaming rules");
        console.log("LUnitNames: Settings GUI setup");
    });
    
    model.LUnitNames_Add = function () {
        var settings = decode(localStorage.settings);
        var rules = settings.LUnitNames_Rules_options;
        rules.push('Original Unit Name -> Custom Unit Name');
        console.log('LUnitNames: Added');
    }
    
    model.LUnitNames_Edit = function () {
        console.log('LUnitNames: Editing');
    }
    
    model.LUnitNames_Remove = function () {
        var settings = decode(localStorage.settings);
        var rules = settings.LUnitNames_Rules_options;
        var selected = settings.LUnitNames_Rules;
        rules.splice(rules.indexOf(selected[0]), 1);
        console.log('LUnitNames: Removed');
    }
    Nothing seems wrong to me...
  3. Raevn

    Raevn Moderator Alumni

    Messages:
    4,226
    Likes Received:
    4,324
    What errors etc. are you getting in the debugger? Is there any log output at all?
  4. DeathByDenim

    DeathByDenim Post Master General

    Messages:
    4,328
    Likes Received:
    2,125
    That's really strange. It seems to be a jQuery-thing?
    Replace
    Code:
    $(function () {
    by
    Code:
    (function () {
    and also replace
    Code:
    });
    by
    Code:
    })();
    Then it works, but I don't know why...
    LavaSnake likes this.
  5. LavaSnake

    LavaSnake Post Master General

    Messages:
    1,620
    Likes Received:
    691
    IT WORKS NOW!
    THANK YOU VERY MUCH!!!!!!!!!!!
  6. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    Theory for the "why":

    Assuming your mod is run as a pamm ui mod.
    PA itself does something like this:

    $(function() {
    <<PA code defines model and stuff>>
    <<load ui mods here>>
    <<bind ko>>
    });

    So this enables mods to modify the model before it is bound. If you modify the model after it is bound it wont have any effects.
    I dunno the exact definition of $(function()); but I think it is kind of like an on load callback.
    So it probably adds the given function to the end of the list of functions that is called on document load.
    So it will be executed after that on load function of PA, after knockout has already been bound.
    => Modifications to the knockout model wont have effects.

    So generally PA UI mods should never use $(...), as they can assume that they are run in the perfect sweet spot (in document on load, after the PA model definition before the knockout bind) by PA already.
  7. LavaSnake

    LavaSnake Post Master General

    Messages:
    1,620
    Likes Received:
    691
    Hm, I guess that makes sense.
  8. DeathByDenim

    DeathByDenim Post Master General

    Messages:
    4,328
    Likes Received:
    2,125
    Ah, good theory. I'll take it to be true. :)
    There is a reference to $(function()) in orfjackal's thread about being a good JavaScript citizen. He claims you should only use it for DOM operations, which happens after the document is loaded, I think. So you are probably spot on.
  9. LavaSnake

    LavaSnake Post Master General

    Messages:
    1,620
    Likes Received:
    691
    That's why I started using it...
  10. LavaSnake

    LavaSnake Post Master General

    Messages:
    1,620
    Likes Received:
    691
    I'm having another issue. Basically whenever I sort an array in the setting for the MultiSelect's options it displays it as a CSV list instead of multiple entries. I've done all sorts of checks and things in code and through the debugger and nothing seams to work. Thanks in advance!
  11. Raevn

    Raevn Moderator Alumni

    Messages:
    4,226
    Likes Received:
    4,324
    Can you post the code in question?
  12. LavaSnake

    LavaSnake Post Master General

    Messages:
    1,620
    Likes Received:
    691
    Sure, the simplest thing I tried was using this line in the debugger and then restarting it:
    Code:
    window.localStorage.LUnitNames_Rules_options  = ["Item1", "Item2"]
    That appeared as "Item1,Item2" on one line.
    Here's the full code: (I've added a LOT of checks to try and fix this.)
    Code:
    (function () {   
        if (window.localStorage.LUnitNames_Rules_options.length == 0) {
            model.addSetting_MultiSelect("Rules to apply to units for renaming:", "LUnitNames_Rules", "UI", null, 0, 10, "Unit renaming rules");
        } else if (window.localStorage.LUnitNames_Rules_options instanceof Array) {
            model.addSetting_MultiSelect("Rules to apply to units for renaming:", "LUnitNames_Rules", "UI", window.localStorage.LUnitNames_Rules_options, 0, 10, "Unit renaming rules");
        } else {
            model.addSetting_MultiSelect("Rules to apply to units for renaming:", "LUnitNames_Rules", "UI", [window.localStorage.LUnitNames_Rules_options], 0, 10, "Unit renaming rules");
        }
        model.addSetting_Button("", "Add new rule", "UI", "model.LUnitNames_Add", "Unit renaming rules");
        model.addSetting_Button("", "Edit selected rule", "UI", "model.LUnitNames_Edit", "Unit renaming rules");
        model.addSetting_Button("", "Remove selected rule", "UI", "model.LUnitNames_Remove", "Unit renaming rules");
       
        $("body").html($("body").html().replace("data-bind=\"options: LUnitNames_Rules_options, selectedOptions: LUnitNames_Rules\"", "data-bind=\"options: LUnitNames_Rules_options, selectedOptions: LUnitNames_Rules\" style='width: 100%;'"));
       
        console.log("LUnitNames: Settings GUI has been setup");
    })();
    
    model.LUnitNames_Add = function () {
        if (!window.localStorage.LUnitNames_Rules_options) {
            window.localStorage.LUnitNames_Rules_options = ["Original Unit Name > Custom Unit Name"];
        } else {
            var array = window.localStorage.LUnitNames_Rules_options;
            if (!(array instanceof Array)) {
                window.localStorage.LUnitNames_Rules_options = [array, "Original Unit Name > Custom Unit Name"];
            } else {
                window.localStorage.LUnitNames_Rules_options = array.push("Original Unit Name > Custom Unit Name");
            }
        }
       
        console.log("LUnitNames: Added");
        console.log(window.localStorage.LUnitNames_Rules_options);
    }
    
    model.LUnitNames_Edit = function () {
        console.log("LUnitNames: Editing");
    }
    
    model.LUnitNames_Remove = function () {
        if (window.localStorage.LUnitNames_Rules) {
            var array = window.localStorage.LUnitNames_Rules_options;
            if (!(array instanceof Array)) {
                window.localStorage.LUnitNames_Rules_options = new Array();
            } else {
                window.localStorage.LUnitNames_Rules_options = array.splice(array.indexOf(window.localStorage.LUnitNames_Rules[0]), 1);
            }
        }
       
        console.log("LUnitNames: Removed");
        console.log(window.localStorage.LUnitNames_Rules_options);
    }
  13. Raevn

    Raevn Moderator Alumni

    Messages:
    4,226
    Likes Received:
    4,324
    change
    Code:
    window.localStorage.LUnitNames_Rules_options = <array>
    to
    Code:
    model.LUnitNames_Rules_options(<array>)
    The only value that is stored in localStorage is the selected value(s): window.localStorage.LUnitNames_Rules. The settings themselves are stored in the KO model.
  14. LavaSnake

    LavaSnake Post Master General

    Messages:
    1,620
    Likes Received:
    691
    That works! Thanks a ton.
  15. SideSplitter

    SideSplitter New Member

    Messages:
    18
    Likes Received:
    12
    Is it possible to create a slider(like the sliders in the "Audio" tab) with this mod?
  16. Raevn

    Raevn Moderator Alumni

    Messages:
    4,226
    Likes Received:
    4,324
    Not yet, but it's something I want to add.
  17. Raevn

    Raevn Moderator Alumni

    Messages:
    4,226
    Likes Received:
    4,324
    Version 1.5.0 released, now adds support for sliders :)
  18. SideSplitter

    SideSplitter New Member

    Messages:
    18
    Likes Received:
    12
    Some bug reports regarding the slider:
    1. When sliding all the way to zero, it assumes that there is no value and will set it to the default value given by initialSettingValue
    2. Pressing "Restore Default" and using the slider gives a TypeError: "Uncaught TypeError: Property 'undefined' of object #<SettingsViewModel> is not a function"
    Last edited: January 27, 2014
  19. Raevn

    Raevn Moderator Alumni

    Messages:
    4,226
    Likes Received:
    4,324
    These and one other bug should be fixed now, just pushed v1.5.2.
  20. thetrophysystem

    thetrophysystem Post Master General

    Messages:
    7,050
    Likes Received:
    2,874
    I am here to ask for end user troubleshooting.

    I can not get PAMM to install settings manager. Anything I try to install that requires it asks to install it first, when I click for it to install it first it stalls (as it does when trying to directly install it). Deleting and reinstalling PAMM didn't help either. It had an update that wouldn't push, wouldn't update and just stalled, so I deleted mod and tried reinstall mod, still stalls to install indefinitely, and if I try to enable a mod requiring it I get a error that I cannot enable it without settings manager.

    Any ideas what all this is about? Is it possibly the new update and the link in the PAMM is bad, or...?

    EDIT: Eh shoot, it broke my whole game (new game menu is greyed webpage boxed and won't click anything after that point), so I deleted PA folder and ran launcher to re-install. Might fix mod problem too, who knows.
    Last edited: January 28, 2014

Share This Page