Ticket #1187: health_bar_hotkey_v01.patch

File health_bar_hotkey_v01.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// Set all inactive status bars on screen to active, removes those off screen
     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            entsOffScreen = splice(entsShowingHealth, entsToDisplayHealthFor);
     1442        entsOffScreen = splice(entsOffScreen, g_Selection.toList());
     1443        entsOffScreen = splice(entsOffScreen, Engine.PickEntitiesAtPoint(mouseX, mouseY));
     1444        Engine.GuiInterfaceCall("SetStatusBars", { "entities": entsOffScreen, "enabled": false });
     1445        entsShowingHealth = null;
     1446    }
     1447
     1448    if (displayingHealthBars)
     1449    {
     1450        Engine.GuiInterfaceCall("SetStatusBars", { "entities": entsToDisplayHealthFor, "enabled": true });
     1451        entsShowingHealth = entsToDisplayHealthFor;
     1452    }
     1453}
  • 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 object to splice from, and an object to slice out
     232function splice(splice_from, what_to_splice)
     233{
     234    if (!what_to_splice || what_to_splice.length == 0)
     235    {
     236        return splice_from;
     237    }
     238
     239    for (var index in what_to_splice)
     240    {
     241        var splice_from_index = splice_from.indexOf(what_to_splice[index]);
     242        if (splice_from_index >= 0)
     243            splice_from.splice(splice_from_index, 1);
     244    }
     245
     246    return splice_from;
     247}