Ticket #1187: health_bar_hotkey_v02.patch

File health_bar_hotkey_v02.patch, 3.4 KB (added by Kieran P, 12 years ago)
  • binaries/data/config/default.cfg

     
    197197hotkey.session.gui.toggle = "Alt+G"          ; Toggle visibility of session GUI
    198198hotkey.menu.toggle = "F10"                   ; Toggle in-game menu
    199199hotkey.timeelapsedcounter.toggle = "F12"     ; Toggle time elapsed counter
     200hotkey.healthbars.toggle = Tab               ; Toggle display of health bars
    200201
    201202; > HOTKEYS ONLY
    202203hotkey.chat = Return                        ; Toggle chat window
  • binaries/data/mods/public/gui/session/input.js

     
    5252var doublePressTimer = 0;
    5353var prevHotkey = 0;
    5454
     55// Toggling of health bars
     56var displayingHealthBars = false;
     57var entsShowingHealth = null;
     58
    5559function updateCursorAndTooltip()
    5660{
    5761    var cursorSet = false;
     
    8387        Engine.SetCursor("arrow-default");
    8488    if (!tooltipSet)
    8589        informationTooltip.hidden = true;
     90    if (displayingHealthBars)
     91        recalculateHealthBarDisplay();
    8692}
    8793
    8894function updateBuildingPlacementPreview()
     
    760766            Engine.RewindTimeWarp();
    761767    }
    762768
     769    if (ev.hotkey == "healthbars.toggle")
     770    {
     771        displayingHealthBars = (ev.type == "hotkeydown");
     772        recalculateHealthBarDisplay();
     773    }
     774
    763775    // State-machine processing:
    764776
    765777    switch (inputState)
     
    14151427{
    14161428    Engine.PostNetworkCommand({"type": "unload-all", "garrisonHolder": garrisonHolder});
    14171429}
     1430
     1431// Recalculate the display of on-screen health bars
     1432function recalculateHealthBarDisplay()
     1433{
     1434    if (displayingHealthBars)
     1435        var entsToDisplayHealthFor = Engine.PickFriendlyEntitiesOnScreen(Engine.GetPlayerID());
     1436
     1437    if (entsShowingHealth)
     1438    {
     1439        var entsOffScreen = entsShowingHealth;
     1440        if (displayingHealthBars)
     1441            array_splice(entsOffScreen, entsToDisplayHealthFor);
     1442        // Always keep selected and hovered unit health bars showing
     1443        array_splice(entsOffScreen, g_Selection.toList());
     1444        array_splice(entsOffScreen, Engine.PickEntitiesAtPoint(mouseX, mouseY));
     1445        Engine.GuiInterfaceCall("SetStatusBars", { "entities": entsOffScreen, "enabled": false });
     1446        entsShowingHealth = null;
     1447    }
     1448
     1449    if (displayingHealthBars)
     1450    {
     1451        Engine.GuiInterfaceCall("SetStatusBars", { "entities": entsToDisplayHealthFor, "enabled": true });
     1452        entsShowingHealth = entsToDisplayHealthFor;
     1453    }
     1454}
  • binaries/data/mods/public/gui/common/functions_utility.js

     
    226226    return hours + ':' + (minutes < 10 ? '0' + minutes : minutes) + ':' + (seconds < 10 ? '0' + seconds : seconds);
    227227}
    228228
     229// ====================================================================
     230
     231// Takes an array to splice from, and an array to splice out
     232function array_splice(splice_from, what_to_splice)
     233{
     234    if (!what_to_splice || what_to_splice.length == 0)
     235        return splice_from;
     236
     237    for (var index in what_to_splice)
     238    {
     239        var splice_from_index = splice_from.indexOf(what_to_splice[index]);
     240        if (splice_from_index >= 0)
     241            splice_from.splice(splice_from_index, 1);
     242    }
     243
     244    return splice_from;
     245}