Ticket #2474: alert-buttons.patch

File alert-buttons.patch, 6.0 KB (added by Itms, 9 years ago)
  • binaries/data/mods/public/gui/session/input.js

     
    18461846        var state = GetEntityState(e);
    18471847        return (state && state.unitAI && state.unitAI.hasWorkOrders);
    18481848    });
    1849    
     1849
    18501850    Engine.PostNetworkCommand({"type": "back-to-work", "entities": workers});
    1851    
    18521851}
    18531852
    18541853function removeGuard()
     
    18581857        var state = GetEntityState(e);
    18591858        return (state && state.unitAI && state.unitAI.isGuarding);
    18601859    });
    1861    
     1860
    18621861    Engine.PostNetworkCommand({"type": "remove-guard", "entities": entities});
    18631862}
    18641863
     
    18681867        var state = GetEntityState(e);
    18691868        return (state && state.alertRaiser && state.alertRaiser.canIncreaseLevel);
    18701869    });
    1871    
    1872     Engine.PostNetworkCommand({"type": "increase-alert-level", "entities": entities}); 
     1870
     1871    Engine.PostNetworkCommand({"type": "increase-alert-level", "entities": entities});
    18731872}
    18741873
    18751874function endOfAlert()
     
    18781877        var state = GetEntityState(e);
    18791878        return (state && state.alertRaiser && state.alertRaiser.hasRaisedAlert);
    18801879    });
    1881    
     1880
    18821881    Engine.PostNetworkCommand({"type": "alert-end", "entities": entities});
    18831882}
    18841883
  • binaries/data/mods/public/gui/session/selection_panels.js

     
    4343
    4444var g_SelectionPanels = {};
    4545
     46// ALERT
     47g_SelectionPanels.Alert = {
     48    "getMaxNumberOfItems": function()
     49    {
     50        return 2;
     51    },
     52    "getItems": function(unitEntState)
     53    {
     54        if (!unitEntState.alertRaiser)
     55            return [];
     56        return ["increase", "end"];
     57    },
     58    "setAction": function(data)
     59    {
     60        data.button.onPress = function() {
     61            if (data.item == "increase")
     62                increaseAlertLevel();
     63            else if (data.item == "end")
     64                endOfAlert();
     65        };
     66    },
     67    "setTooltip": function(data)
     68    {
     69        if (data.item == "increase")
     70        {
     71            if (data.unitEntState.alertRaiser.hasRaisedAlert)
     72                data.button.tooltip = translate("Increase the alert level to protect more units");
     73            else
     74                data.button.tooltip = translate("Raise an alert!");
     75        }
     76        else if (data.item == "end")
     77            data.button.tooltip = translate("End of alert.");
     78    },
     79    "setGraphics": function(data)
     80    {
     81        data.button.enabled = !data.stanceSelected;
     82        if (data.item == "increase")
     83        {
     84            data.button.enabled = data.unitEntState.alertRaiser.canIncreaseLevel;
     85            data.icon.sprite = "stretched:session/icons/bell_level1.png";
     86        }
     87        else if (data.item == "end")
     88        {
     89            data.button.enabled = data.unitEntState.alertRaiser.hasRaisedAlert;
     90            data.icon.sprite = "stretched:session/icons/bell_level0.png";
     91        }
     92    },
     93};
     94
    4695// BARTER
    4796g_SelectionPanels.Barter = {
    4897    "getMaxNumberOfItems": function()
     
    10801129    // LEFT PANE
    10811130    "Barter", // must always be visible on markets
    10821131    "Garrison", // more important than Formation, as you want to see the garrisoned units in ships
     1132    "Alert",
    10831133    "Formation",
    10841134    "Stance", // normal together with formation
    10851135
  • binaries/data/mods/public/gui/session/selection_panels_left/alert_panel.xml

     
     1<?xml version="1.0" encoding="utf-8"?>
     2<object name="unitAlertPanel"
     3    style="TranslucentPanel"
     4    size="4 100%-43 100%-4 100%-4"
     5    type="text"
     6>
     7    <object size="100%-72 2 100% 100%">
     8        <repeat count="2">
     9            <object name="unitAlertButton[n]" hidden="true" style="iconButton" type="button" size="0 0 36 36" tooltip_style="sessionToolTipBottomBold" z="100">
     10                <object name="unitAlertIcon[n]" type="image" ghost="true" size="3 3 33 33"/>
     11            </object>
     12        </repeat>
     13    </object>
     14</object>
  • binaries/data/mods/public/gui/session/unit_actions.js

     
    877877            toggleTrade();
    878878        },
    879879    },
    880     // Raise alert
    881     "increase-alert-level": {
    882         "getInfo": function(entState)
    883         {
    884             if (!entState.alertRaiser || !entState.alertRaiser.canIncreaseLevel)
    885                 return false;
    886 
    887             if (entState.alertRaiser.hasRaisedAlert)
    888                 var tooltip = translate("Increase the alert level to protect more units");
    889             else
    890                 var tooltip = translate("Raise an alert!");
    891             return {
    892                 "tooltip": tooltip,
    893                 "icon": "bell_level1.png"
    894             };
    895         },
    896         "execute": function(entState)
    897         {
    898             increaseAlertLevel();
    899         },
    900     },
    901     // End alert
    902     "alert-end": {
    903         "getInfo": function(entState)
    904         {
    905             if (!entState.alertRaiser || !entState.alertRaiser.hasRaisedAlert)
    906                 return false
    907             return {
    908                 "tooltip": translate("End of alert."),
    909                 "icon": "bell_level0.png"
    910             };
    911         },
    912         "execute": function(entState)
    913         {
    914             endOfAlert();
    915         },
    916     },
    917880};
    918881
    919882var g_AllyEntityCommands =
  • binaries/data/mods/public/gui/session/unit_commands.js

     
    11// The number of currently visible buttons (used to optimise showing/hiding)
    2 var g_unitPanelButtons = {"Selection": 0, "Queue": 0, "Formation": 0, "Garrison": 0, "Training": 0, "Research": 0, "Barter": 0, "Construction": 0, "Command": 0, "AllyCommand": 0, "Stance": 0, "Gate": 0, "Pack": 0};
     2var g_unitPanelButtons = {"Selection": 0, "Queue": 0, "Formation": 0, "Garrison": 0, "Training": 0, "Research": 0, "Alert": 0, "Barter": 0, "Construction": 0, "Command": 0, "AllyCommand": 0, "Stance": 0, "Gate": 0, "Pack": 0};
    33
    44/**
    55 * Set the position of a panel object according to the index,