Key Binding Help Request

Discussion in 'Mod Discussions' started by trialq, February 11, 2014.

  1. trialq

    trialq Post Master General

    Messages:
    1,295
    Likes Received:
    917
    I've tried to bind a hotkey and am having trouble (spent more time trying to get this to work than I'd like to admit :p ). There's no error in coherent, and the binding is in the settings menu, the function just doesn't execute. If someone more knowledgeable could look at this and see what's wrong that would be great. I have tried looking at hotbuild2 as an example, everything looks equivalent that I'm aware of.

    modinfo:
    Code:
    ...
      "live_game": [
      "coui://ui/mods/tAutoFactory/tAutoFactory.js",
      "coui://ui/mods/tAutoFactory/live_game/tAutoFactory.css",
      "coui://ui/mods/tAutoFactory/live_game/init.js"
      ],
      "settings": [
      "coui://ui/mods/tAutoFactory/settings/init.js"
      ],
      "global_mod_list": [
      "coui://ui/mods/tAutoFactory/global_mod_list/tAutoFactory.js"
      ],
    ...
    \ui\mods\tAutoFactory\global_mod_list\tAutoFactory.js:
    Code:
    ...
    (function () {
    console.log("af global");
    
      action_sets.tAutoFactory = {};
      action_sets.tAutoFactory["Manually Execute"] = function(event) { console.log("af hotkey");/*tAutoFactory.manual();*/ };
    
      default_keybinds.tAutoFactory = {};
      default_keybinds.tAutoFactory["Manually Execute"] = "q";
    
    })();
    ...
    \ui\mods\tAutoFactory\live_game\init.js:
    Code:
    $(function () {
    ...
      var tAutoFactoryapplyUIDisplaySettings = model.applyUIDisplaySettings;
      model.applyUIDisplaySettings = function () {
      apply_keybinds("tAutoFactory");
      tAutoFactoryapplyUIDisplaySettings();
      };
    ...
    
    });
    ...
    Apologies if I don't reply promptly. Might not be here for a few days.

    Attached Files:

    Last edited: February 11, 2014
  2. proeleert

    proeleert Post Master General

    Messages:
    1,681
    Likes Received:
    1,656
    Looks good at first glance. Is nothing else bound to q ? Cause last bind wins.
  3. proeleert

    proeleert Post Master General

    Messages:
    1,681
    Likes Received:
    1,656
    Oh is this up on github ? If so I'll fix it
  4. trialq

    trialq Post Master General

    Messages:
    1,295
    Likes Received:
    917
    It's not on github, but the wip version is attached the the above post. Thanks for looking, but don't worry too much about trying to fix it. When I get enough time I'll stare it into submission 8)
  5. proeleert

    proeleert Post Master General

    Messages:
    1,681
    Likes Received:
    1,656
    Can you try this ? so your apply_keybinds is last.
  6. trialq

    trialq Post Master General

    Messages:
    1,295
    Likes Received:
    917
    Nice try, but it didn't work.

    When I get time I'll start fresh. Make a mod that does the keybind, then add the other stuff to it.
  7. proeleert

    proeleert Post Master General

    Messages:
    1,681
    Likes Received:
    1,656
  8. proeleert

    proeleert Post Master General

    Messages:
    1,681
    Likes Received:
    1,656
    Hmmm if you run
    model.applyUIDisplaySettings()




    In console after everything is loaded it works hmm.
  9. proeleert

    proeleert Post Master General

    Messages:
    1,681
    Likes Received:
    1,656
    hmmm why isn't it executing
    "coui://ui/mods/tAutoFactory/global_mod_list/tAutoFactory.js"
  10. trialq

    trialq Post Master General

    Messages:
    1,295
    Likes Received:
    917
    That's great, running model.applyUIDisplaySettings(); just after hijacking it seems to work, is there anything wrong with that? I thought we hijack so it executes at the right time, but if this works then great.
  11. proeleert

    proeleert Post Master General

    Messages:
    1,681
    Likes Received:
    1,656
    Never mind pamm replaced old **** :)

    Yes found out what the error is :)

    Code:
    (function () {
        "use strict";
    
        function loadTemplate(element, url) {
            element.load(url, function () {
                ko.applyBindings(model, element.get(0));
            });
        }
    
        //visible to knockout
        model.tAutoFactory = tAutoFactory;
    
        //update every second
        setInterval(tAutoFactory.update, 1000);
        //instead of polling, try hijacking api.select.empty
        //var tAutoFactory_api_select_empty = api.select.commander;
        //api.select.commander = function(){
        //    console.log("hijacked select empty");
        //    tAutoFactory_api_select_empty();
        //};
    
        //hotkey doesn't work, TODO
        //action_sets.tautofactory["Manually Execute"] = function(event) { console.log("af hotkey");tAutoFactory.manual(); };
        //action_sets.tAutoFactory["Manually Execute"] = function(event) { console.log("af hotkey");/*tAutoFactory.manual();*/ };
        var tAutoFactoryapplyUIDisplaySettings = model.applyUIDisplaySettings;
        model.applyUIDisplaySettings = function () {
            debugger;
            apply_keybinds("tAutoFactory");
            tAutoFactoryapplyUIDisplaySettings();
        };
    
        createFloatingFrame('tAutoFactory_frame', 200, 40, {'offset': 'leftCenter', 'left': 0});
        loadTemplate($('#tAutoFactory_frame_content'), 'coui://ui/mods/tAutoFactory/live_game/tAutoFactory.html');
    
    })();
    This works.
    $(); is to early

    and it's not needed cause we are in a big $() anyway :)

    Now this was fun :)
  12. trialq

    trialq Post Master General

    Messages:
    1,295
    Likes Received:
    917
    Thank you for your help. I'll digest what you're saying later :)
  13. trialq

    trialq Post Master General

    Messages:
    1,295
    Likes Received:
    917
    Got it to work. I couldn't remove the jquery from there, because it was needed to load the html at the right time. So I moved the binding to the other js loaded in live_game.

    Thank you for your help.

Share This Page