Ticket #3688: GUIOverlays.patch

File GUIOverlays.patch, 19.1 KB (added by wraitii, 8 years ago)

Attached patch does the above, removing the "unaffordable" overlays.

  • binaries/data/mods/public/gui/gamesetup/gamesetup.js

     
    13251325    ceasefireText.caption = g_Ceasefire.Title[ceasefire.selected];
    13261326
    13271327    // Update map preview
    1328     Engine.GetGUIObjectByName("mapPreview").sprite = "cropped:(0.78125,0.5859375)session/icons/mappreview/" + getMapPreview(mapName);
     1328    Engine.GetGUIObjectByName("mapPreview").sprite = "cropped:0.78125,0.5859375:session/icons/mappreview/" + getMapPreview(mapName);
    13291329
    13301330    // Hide/show settings depending on whether we can change them or not
    13311331    var updateDisplay = function(guiObjChg, guiObjDsp, chg) {
  • binaries/data/mods/public/gui/lobby/lobby.js

     
    615615    // Display map description and preview (or placeholder)
    616616    var mapData = getMapDescriptionAndPreview(g_GameList[g].mapType, g_GameList[g].mapName);
    617617    Engine.GetGUIObjectByName("sgMapDescription").caption = mapData.description;
    618     Engine.GetGUIObjectByName("sgMapPreview").sprite = "cropped:(0.7812,0.5859)session/icons/mappreview/" + mapData.preview;
     618    Engine.GetGUIObjectByName("sgMapPreview").sprite = "cropped:0.7812,0.5859:session/icons/mappreview/" + mapData.preview;
    619619}
    620620
    621621/**
  • binaries/data/mods/public/gui/replaymenu/replay_menu.js

     
    203203    Engine.GetGUIObjectByName("sgNbPlayers").caption = replay.attribs.settings.PlayerData.length;
    204204    Engine.GetGUIObjectByName("sgPlayersNames").caption = getReplayTeamText(replay);
    205205    Engine.GetGUIObjectByName("sgMapDescription").caption = mapData.description;
    206     Engine.GetGUIObjectByName("sgMapPreview").sprite = "cropped:(0.7812,0.5859)session/icons/mappreview/" + mapData.preview;
     206    Engine.GetGUIObjectByName("sgMapPreview").sprite = "cropped:0.7812,0.5859:session/icons/mappreview/" + mapData.preview;
    207207}
    208208
    209209/**
  • binaries/data/mods/public/gui/session/utility_functions.js

     
    163163
    164164    return ent;
    165165}
     166
     167/**
     168 * Returns a "color(255 0 0 Alpha)" string based on how many resources are needed.
     169 */
     170function resourcesToAlphaMask(neededResources)
     171{
     172    var totalCost = 0;
     173    for (var resource in neededResources)
     174        totalCost += +neededResources[resource];
     175    var alpha = 50 + Math.round(+totalCost/10.0);
     176    alpha = alpha > 125 ? 125 : alpha;
     177    return "color: 255 0 0 " + alpha;
     178}
  • binaries/data/mods/public/gui/session/unit_commands.js

     
    8989        // add standard gui objects to the data
    9090        // depending on the actual XML, some of this may be undefined
    9191        data.button = Engine.GetGUIObjectByName("unit"+guiName+"Button["+i+"]");
    92         data.affordableMask = Engine.GetGUIObjectByName("unit"+guiName+"Unaffordable["+i+"]");
    9392        data.icon = Engine.GetGUIObjectByName("unit"+guiName+"Icon["+i+"]");
    9493        data.guiSelection = Engine.GetGUIObjectByName("unit"+guiName+"Selection["+i+"]");
    9594        data.countDisplay = Engine.GetGUIObjectByName("unit"+guiName+"Count["+i+"]");
     
    103102            data.button.tooltip = "";
    104103            data.button.caption = "";
    105104        }
    106 
    107         if (data.affordableMask)
    108             data.affordableMask.hidden = true;  // actually used for the red "lack of resource" overlay, and darkening if unavailable. Sort of a hack.
    109105
    110106        // GENERAL DATA
    111107        // add general data, and a chance to abort on faulty data
    112108        if (g_SelectionPanels[guiName].addData)
     
    146142    g_SelectionPanels[guiName].used = true;
    147143}
    148144
    149 function resourcesToAlphaMask(neededResources)
    150 {
    151     var totalCost = 0;
    152     for each (var resource in neededResources)
    153         totalCost += resource;
    154     var alpha = 50 + Math.round(totalCost/10);
    155     alpha = alpha > 125 ? 125 : alpha;
    156     return "color: 255 0 0 " + (alpha);
    157 }
    158 
    159145/**
    160146 * Updates the selection panels where buttons are supposed to
    161147 * depend on the context.
  • binaries/data/mods/public/gui/session/selection_panels.js

     
    1818 *   "rowLength":      rowLength
    1919 *   "numberOfItems":  number of items that will be processed
    2020 *   "button":         gui Button object
    21  *   "affordableMask": gui Unaffordable overlay
    2221 *   "icon":           gui Icon object
    2322 *   "guiSelection":   gui button Selection overlay
    2423 *   "countDisplay":   gui caption space
     
    122121            data.amount[a] = Engine.GetGUIObjectByName("unitBarter"+a+"Amount["+data.i+"]");
    123122        }
    124123        data.selectionIcon = Engine.GetGUIObjectByName("unitBarterSellSelection["+data.i+"]");
    125         data.affordableMask = Engine.GetGUIObjectByName("unitBarterSellUnaffordable["+data.i+"]");
    126124
    127125        data.amountToSell = BARTER_RESOURCE_AMOUNT_TO_SELL;
    128126        if (Engine.HotkeyIsPressed("session.massbarter"))
     
    155153    },
    156154    "setGraphics": function(data)
    157155    {
    158         var grayscale = data.isSelected ? "grayscale:" : "";
     156        var grayscale = data.isSelected ? "color: 0 0 0 100:grayscale:" : "";
     157
     158        // do we have enough of this resource to sell?
     159        var neededRes = {};
     160        neededRes[data.item] = data.amountToSell;
     161        var canSellCurrent = Engine.GuiInterfaceCall("GetNeededResources", neededRes) ? "color(255 0 0 127):" : "";
     162        // Let's see if we have enough resources to barter.
     163        neededRes = {};
     164        neededRes[g_barterSell] = data.amountToSell;
     165        var canBuyAny = Engine.GuiInterfaceCall("GetNeededResources", neededRes) ? "color(255 0 0 127):" : "";
     166
     167
    159168        data.button.Buy.hidden = data.isSelected;
    160169        data.button.Sell.hidden = false;
    161         for each (var icon in data.icon)
    162             icon.sprite = "stretched:"+grayscale+"session/icons/resources/" + data.item + ".png";
     170        data.icon.Sell.sprite = canSellCurrent + "stretched:"+grayscale+"session/icons/resources/" + data.item + ".png";
     171        data.icon.Buy.sprite = canBuyAny + "stretched:"+grayscale+"session/icons/resources/" + data.item + ".png";
    163172
    164         var neededRes = {};
    165         neededRes[data.item] = data.amountToSell;
    166         if (Engine.GuiInterfaceCall("GetNeededResources", neededRes))
    167             data.affordableMask.hidden = false;
    168         else
    169             data.affordableMask.hidden = true;
    170173        data.selectionIcon.hidden = !data.isSelected;
    171174    },
    172175    "setPosition": function(data)
     
    328331    },
    329332    "setGraphics": function(data)
    330333    {
    331         var grayscale = "";
     334        var modifier = "";
    332335        if (!data.technologyEnabled || data.limits.canBeAddedCount == 0)
    333336        {
    334337            data.button.enabled = false;
    335             grayscale = "grayscale:";
    336             data.affordableMask.hidden = false;
    337             data.affordableMask.sprite = "color: 0 0 0 127";
     338            modifier += "color: 0 0 0 127:";
     339            modifier += "grayscale:";
    338340        }
    339341        else if (data.neededResources)
    340342        {
    341343            data.button.enabled = false;
    342             data.affordableMask.hidden = false;
    343             data.affordableMask.sprite = resourcesToAlphaMask(data.neededResources);
     344            modifier += resourcesToAlphaMask(data.neededResources) +":";
    344345        }
     346
    345347        if (data.template.icon)
    346             data.icon.sprite = "stretched:" + grayscale + "session/portraits/" + data.template.icon;
     348            data.icon.sprite = modifier + "stretched:session/portraits/" + data.template.icon;
    347349    },
    348350    "setPosition": function(data)
    349351    {
     
    449451        var grayscale = "";
    450452        var ents = data.item.ents;
    451453        var entplayer = GetEntityState(ents[0]).player;
    452         data.button.sprite = "color: " + rgbToGuiColor(g_Players[entplayer].color);
     454        data.button.sprite = "color(" + rgbToGuiColor(g_Players[entplayer].color) +")";
    453455
    454456        var player = Engine.GetPlayerID();
    455457        if(player != data.unitEntState.player && !g_DevSettings.controlAll)
     
    553555    },
    554556    "setGraphics": function(data)
    555557    {
    556         data.affordableMask.hidden == data.neededResources ? true : false;
    557558        var gateIcon;
    558559        if (data.item.gate)
    559560        {
     
    574575            data.guiSelection.hidden = true;
    575576        }
    576577
    577         data.icon.sprite = "stretched:session/" + gateIcon;
     578        data.icon.sprite = (data.neededResources ? resourcesToAlphaMask(data.neededResources) + ":" : "") + "stretched:session/" + gateIcon;
    578579    },
    579580    "setPosition": function(data)
    580581    {
     
    770771            return Engine.GetGUIObjectByName("unitResearchButton["+p+"]");
    771772        });
    772773
    773 
    774         data.affordableMask = data.positions.map(function(p) {
    775             return Engine.GetGUIObjectByName("unitResearchUnaffordable["+p+"]");
    776         });
    777 
    778774        data.icon = data.positions.map(function(p) {
    779775            return Engine.GetGUIObjectByName("unitResearchIcon["+p+"]");
    780776        });
     
    854850        {
    855851            var button = data.button[i];
    856852            button.hidden = false;
    857             var grayscale = "";
     853            var modifier = "";
    858854            if (!data.requirementsPassed[i])
    859855            {
    860856                button.enabled = false;
    861                 grayscale = "grayscale:";
    862                 data.affordableMask[i].hidden = false;
    863                 data.affordableMask[i].sprite = "color: 0 0 0 127";
     857                modifier += "color: 0 0 0 127:";
     858                modifier += "grayscale:";
    864859            }
    865860            else if (data.neededResources[i])
    866861            {
    867862                button.enabled = false;
    868                 data.affordableMask[i].hidden = false;
    869                 data.affordableMask[i].sprite = resourcesToAlphaMask(data.neededResources[i]);
     863                modifier += resourcesToAlphaMask(data.neededResources[i]) + ":";
    870864            }
    871865            else
    872             {
    873                 data.affordableMask[i].hidden = true;
    874866                button.enabled = true;
    875             }
     867
    876868            if (data.template[i].icon)
    877                 data.icon[i].sprite = "stretched:" + grayscale + "session/portraits/" + data.template[i].icon;
     869                data.icon[i].sprite = modifier + "stretched:session/portraits/" + data.template[i].icon;
    878870        }
    879871        for (var button of data.buttonsToHide)
    880872            button.hidden = true;
  • binaries/data/mods/public/gui/session/selection_panels_left/barter_panel.xml

     
    1111            <!-- sell -->
    1212            <object name="unitBarterSellButton[n]" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottomBold">
    1313                <object name="unitBarterSellIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
    14                 <object name="unitBarterSellUnaffordable[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="color: 255 0 0 60"/>
    1514                <object name="unitBarterSellAmount[n]" ghost="true" style="resourceText" type="text" size="0 0 100% 50%"/>
    1615                <object name="unitBarterSellSelection[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="stretched:session/icons/corners.png"/>
    1716            </object>
  • binaries/data/mods/public/gui/session/selection_panels_right/training_panel.xml

     
    66    <repeat count="24">
    77        <object name="unitTrainingButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom">
    88        <object name="unitTrainingIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
    9         <object name="unitTrainingUnaffordable[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="color: 255 0 0 127"/>
    109        <object name="unitTrainingCount[n]" ghost="true" style="groupIconsText" type="text" z="20"/>
    1110        </object>
    1211    </repeat>
  • binaries/data/mods/public/gui/session/selection_panels_right/research_panel.xml

     
    77        <object name="unitResearchButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom">
    88        <object name="unitResearchIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
    99        <object name="unitResearchUnchosenIcon[n]" type="image" hidden="true" ghost="true" size="3 3 43 43" sprite="stretched:session/icons/tech_pair_would_be_unavailable.png"/>
    10         <object name="unitResearchUnaffordable[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="color: 255 0 0 60"/>
    1110        </object>
    1211    </repeat>
    1312    <repeat count="8">
  • binaries/data/mods/public/gui/session/selection_panels_right/gate_panel.xml

     
    77        <object name="unitGateButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom">
    88        <object name="unitGateIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
    99        <object name="unitGateSelection[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="stretched:session/icons/corners.png"/>
    10         <object name="unitGateUnaffordable[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="color: 255 0 0 127"/>
    1110        </object>
    1211    </repeat>
    1312    </object>
  • binaries/data/mods/public/gui/session/selection_panels_right/construction_panel.xml

     
    66    <repeat count="24">
    77        <object name="unitConstructionButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom">
    88        <object name="unitConstructionIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
    9         <object name="unitConstructionUnaffordable[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="color: 255 0 0 127"/>
    109        </object>
    1110    </repeat>
    1211    </object>
  • source/gui/GUIRenderer.cpp

     
    7575    std::map<CStr, CGUISprite*>::iterator it(Sprites.find(SpriteName));
    7676    if (it == Sprites.end())
    7777    {
    78         // Sprite not found. Check whether this a special sprite:
    79         //     "stretched:filename.ext" - stretched image
    80         //     "stretched:grayscale:filename.ext" - stretched grayscale image
    81         //     "cropped:(0.5, 0.25)"    - stretch this ratio (x,y) of the top left of the image
    82         //     "color:r g b a"         - solid color
    83         //
    84         // and if so, try to create it as a new sprite.
    85         if (SpriteName.substr(0, 10) == "stretched:")
     78        /*
     79         * Sprite not found. Check whether this a special sprite,
     80         * and if so create a new sprite:
     81         * "stretched:filename.ext" - stretched image
     82         * "stretched:grayscale:filename.ext" - stretched grayscale image.
     83         * "cropped:0.5, 0.25"    - stretch this ratio (x,y) of the top left of the image
     84         * "color:r g b a"         - solid color
     85         * These can be combined, but they must be separated by a ":"
     86         * So you can have a white overlay over an stretched grayscale image with:
     87         * "grayscale:color:255 255 255 100:stretched:filename.ext"
     88         */
     89        // Check that this can be a special sprite.
     90        if (SpriteName.ReverseFind(":") == -1 && SpriteName.Find("color(") == -1)
    8691        {
     92            LOGERROR("Trying to use a sprite that doesn't exist (\"%s\").", SpriteName.c_str());
     93            return;
     94        }
     95        CGUISprite* Sprite = new CGUISprite;
     96        VfsPath TextureName = VfsPath("art/textures/ui") / wstring_from_utf8(SpriteName.AfterLast(":"));
     97        if (SpriteName.Find("stretched:") != -1)
     98        {
    8799            // TODO: Should check (nicely) that this is a valid file?
    88100            SGUIImage* Image = new SGUIImage;
    89101
     102            Image->m_TextureName = TextureName;
    90103            // Allow grayscale images for disabled portraits
    91             if (SpriteName.substr(10, 10) == "grayscale:")
     104            if (SpriteName.Find("grayscale:") != -1)
    92105            {
    93                 Image->m_TextureName = VfsPath("art/textures/ui") / wstring_from_utf8(SpriteName.substr(20));
    94106                Image->m_Effects = new SGUIImageEffects;
    95107                Image->m_Effects->m_Greyscale = true;
    96108            }
    97             else
    98             {
    99                 Image->m_TextureName = VfsPath("art/textures/ui") / wstring_from_utf8(SpriteName.substr(10));
    100             }
    101109
    102110            CClientArea ca(CRect(0, 0, 0, 0), CRect(0, 0, 100, 100));
    103111            Image->m_Size = ca;
    104112            Image->m_TextureSize = ca;
    105113
    106             CGUISprite* Sprite = new CGUISprite;
    107114            Sprite->AddImage(Image);
    108115
    109116            Sprites[SpriteName] = Sprite;
    110 
    111             it = Sprites.find(SpriteName);
    112             ENSURE(it != Sprites.end()); // The insertion above shouldn't fail
    113117        }
    114         else if (SpriteName.substr(0, 8) == "cropped:")
     118        else if (SpriteName.Find("cropped:") != -1)
    115119        {
    116120            // TODO: Should check (nicely) that this is a valid file?
    117121            SGUIImage* Image = new SGUIImage;
    118122
    119             double xRatio = SpriteName.BeforeFirst(",").AfterLast("(").ToDouble();
    120             double yRatio = SpriteName.BeforeFirst(")").AfterLast(",").ToDouble();
     123            CStr info = SpriteName.AfterLast("cropped:").BeforeFirst(":");
     124            double xRatio = info.BeforeFirst(",").ToDouble();
     125            double yRatio = info.AfterLast(",").ToDouble();
    121126
    122             int PathStart = SpriteName.Find(")") + 1;
     127            Image->m_TextureName = TextureName;
    123128
    124             Image->m_TextureName = VfsPath("art/textures/ui") / wstring_from_utf8(SpriteName.substr(PathStart));
    125 
    126129            CClientArea ca(CRect(0, 0, 0, 0), CRect(0, 0, 100, 100));
    127130            CClientArea cb(CRect(0, 0, 0, 0), CRect(0, 0, 100/xRatio, 100/yRatio));
    128131            Image->m_Size = ca;
    129132            Image->m_TextureSize = cb;
    130133
    131             CGUISprite* Sprite = new CGUISprite;
    132134            Sprite->AddImage(Image);
    133135
    134136            Sprites[SpriteName] = Sprite;
    135 
    136             it = Sprites.find(SpriteName);
    137             ENSURE(it != Sprites.end()); // The insertion above shouldn't fail
    138137        }
    139         else if (SpriteName.substr(0, 6) == "color:")
     138        if (SpriteName.Find("color:") != -1)
    140139        {
    141             CStrW value = wstring_from_utf8(SpriteName.substr(6));
     140            CStrW value = wstring_from_utf8(SpriteName.AfterLast("color:").BeforeFirst(":"));
    142141            CColor color;
    143142
    144143            // Check color is valid
     
    156155            Image->m_Size = ca;
    157156            Image->m_TextureSize = ca;
    158157
    159             CGUISprite* Sprite = new CGUISprite;
    160158            Sprite->AddImage(Image);
    161159
    162160            Sprites[SpriteName] = Sprite;
     161        }
     162        it = Sprites.find(SpriteName);
    163163
    164             it = Sprites.find(SpriteName);
    165             ENSURE(it != Sprites.end()); // The insertion above shouldn't fail
    166         }
    167         else
     164        // Otherwise, just complain and give up:
     165        if (it == Sprites.end())
    168166        {
    169             // Otherwise, just complain and give up:
     167            SAFE_DELETE(Sprite);
    170168            LOGERROR("Trying to use a sprite that doesn't exist (\"%s\").", SpriteName.c_str());
    171169            return;
    172170        }