Ticket #3688: GUIOverlays.patch
File GUIOverlays.patch, 19.1 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/gui/gamesetup/gamesetup.js
1325 1325 ceasefireText.caption = g_Ceasefire.Title[ceasefire.selected]; 1326 1326 1327 1327 // 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); 1329 1329 1330 1330 // Hide/show settings depending on whether we can change them or not 1331 1331 var updateDisplay = function(guiObjChg, guiObjDsp, chg) { -
binaries/data/mods/public/gui/lobby/lobby.js
615 615 // Display map description and preview (or placeholder) 616 616 var mapData = getMapDescriptionAndPreview(g_GameList[g].mapType, g_GameList[g].mapName); 617 617 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; 619 619 } 620 620 621 621 /** -
binaries/data/mods/public/gui/replaymenu/replay_menu.js
203 203 Engine.GetGUIObjectByName("sgNbPlayers").caption = replay.attribs.settings.PlayerData.length; 204 204 Engine.GetGUIObjectByName("sgPlayersNames").caption = getReplayTeamText(replay); 205 205 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; 207 207 } 208 208 209 209 /** -
binaries/data/mods/public/gui/session/utility_functions.js
163 163 164 164 return ent; 165 165 } 166 167 /** 168 * Returns a "color(255 0 0 Alpha)" string based on how many resources are needed. 169 */ 170 function 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
89 89 // add standard gui objects to the data 90 90 // depending on the actual XML, some of this may be undefined 91 91 data.button = Engine.GetGUIObjectByName("unit"+guiName+"Button["+i+"]"); 92 data.affordableMask = Engine.GetGUIObjectByName("unit"+guiName+"Unaffordable["+i+"]");93 92 data.icon = Engine.GetGUIObjectByName("unit"+guiName+"Icon["+i+"]"); 94 93 data.guiSelection = Engine.GetGUIObjectByName("unit"+guiName+"Selection["+i+"]"); 95 94 data.countDisplay = Engine.GetGUIObjectByName("unit"+guiName+"Count["+i+"]"); … … 103 102 data.button.tooltip = ""; 104 103 data.button.caption = ""; 105 104 } 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.109 105 110 106 // GENERAL DATA 111 107 // add general data, and a chance to abort on faulty data 112 108 if (g_SelectionPanels[guiName].addData) … … 146 142 g_SelectionPanels[guiName].used = true; 147 143 } 148 144 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 159 145 /** 160 146 * Updates the selection panels where buttons are supposed to 161 147 * depend on the context. -
binaries/data/mods/public/gui/session/selection_panels.js
18 18 * "rowLength": rowLength 19 19 * "numberOfItems": number of items that will be processed 20 20 * "button": gui Button object 21 * "affordableMask": gui Unaffordable overlay22 21 * "icon": gui Icon object 23 22 * "guiSelection": gui button Selection overlay 24 23 * "countDisplay": gui caption space … … 122 121 data.amount[a] = Engine.GetGUIObjectByName("unitBarter"+a+"Amount["+data.i+"]"); 123 122 } 124 123 data.selectionIcon = Engine.GetGUIObjectByName("unitBarterSellSelection["+data.i+"]"); 125 data.affordableMask = Engine.GetGUIObjectByName("unitBarterSellUnaffordable["+data.i+"]");126 124 127 125 data.amountToSell = BARTER_RESOURCE_AMOUNT_TO_SELL; 128 126 if (Engine.HotkeyIsPressed("session.massbarter")) … … 155 153 }, 156 154 "setGraphics": function(data) 157 155 { 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 159 168 data.button.Buy.hidden = data.isSelected; 160 169 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"; 163 172 164 var neededRes = {};165 neededRes[data.item] = data.amountToSell;166 if (Engine.GuiInterfaceCall("GetNeededResources", neededRes))167 data.affordableMask.hidden = false;168 else169 data.affordableMask.hidden = true;170 173 data.selectionIcon.hidden = !data.isSelected; 171 174 }, 172 175 "setPosition": function(data) … … 328 331 }, 329 332 "setGraphics": function(data) 330 333 { 331 var grayscale= "";334 var modifier = ""; 332 335 if (!data.technologyEnabled || data.limits.canBeAddedCount == 0) 333 336 { 334 337 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:"; 338 340 } 339 341 else if (data.neededResources) 340 342 { 341 343 data.button.enabled = false; 342 data.affordableMask.hidden = false; 343 data.affordableMask.sprite = resourcesToAlphaMask(data.neededResources); 344 modifier += resourcesToAlphaMask(data.neededResources) +":"; 344 345 } 346 345 347 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; 347 349 }, 348 350 "setPosition": function(data) 349 351 { … … 449 451 var grayscale = ""; 450 452 var ents = data.item.ents; 451 453 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) +")"; 453 455 454 456 var player = Engine.GetPlayerID(); 455 457 if(player != data.unitEntState.player && !g_DevSettings.controlAll) … … 553 555 }, 554 556 "setGraphics": function(data) 555 557 { 556 data.affordableMask.hidden == data.neededResources ? true : false;557 558 var gateIcon; 558 559 if (data.item.gate) 559 560 { … … 574 575 data.guiSelection.hidden = true; 575 576 } 576 577 577 data.icon.sprite = "stretched:session/" + gateIcon;578 data.icon.sprite = (data.neededResources ? resourcesToAlphaMask(data.neededResources) + ":" : "") + "stretched:session/" + gateIcon; 578 579 }, 579 580 "setPosition": function(data) 580 581 { … … 770 771 return Engine.GetGUIObjectByName("unitResearchButton["+p+"]"); 771 772 }); 772 773 773 774 data.affordableMask = data.positions.map(function(p) {775 return Engine.GetGUIObjectByName("unitResearchUnaffordable["+p+"]");776 });777 778 774 data.icon = data.positions.map(function(p) { 779 775 return Engine.GetGUIObjectByName("unitResearchIcon["+p+"]"); 780 776 }); … … 854 850 { 855 851 var button = data.button[i]; 856 852 button.hidden = false; 857 var grayscale= "";853 var modifier = ""; 858 854 if (!data.requirementsPassed[i]) 859 855 { 860 856 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:"; 864 859 } 865 860 else if (data.neededResources[i]) 866 861 { 867 862 button.enabled = false; 868 data.affordableMask[i].hidden = false; 869 data.affordableMask[i].sprite = resourcesToAlphaMask(data.neededResources[i]); 863 modifier += resourcesToAlphaMask(data.neededResources[i]) + ":"; 870 864 } 871 865 else 872 {873 data.affordableMask[i].hidden = true;874 866 button.enabled = true; 875 } 867 876 868 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; 878 870 } 879 871 for (var button of data.buttonsToHide) 880 872 button.hidden = true; -
binaries/data/mods/public/gui/session/selection_panels_left/barter_panel.xml
11 11 <!-- sell --> 12 12 <object name="unitBarterSellButton[n]" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottomBold"> 13 13 <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"/>15 14 <object name="unitBarterSellAmount[n]" ghost="true" style="resourceText" type="text" size="0 0 100% 50%"/> 16 15 <object name="unitBarterSellSelection[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="stretched:session/icons/corners.png"/> 17 16 </object> -
binaries/data/mods/public/gui/session/selection_panels_right/training_panel.xml
6 6 <repeat count="24"> 7 7 <object name="unitTrainingButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom"> 8 8 <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"/>10 9 <object name="unitTrainingCount[n]" ghost="true" style="groupIconsText" type="text" z="20"/> 11 10 </object> 12 11 </repeat> -
binaries/data/mods/public/gui/session/selection_panels_right/research_panel.xml
7 7 <object name="unitResearchButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom"> 8 8 <object name="unitResearchIcon[n]" type="image" ghost="true" size="3 3 43 43"/> 9 9 <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"/>11 10 </object> 12 11 </repeat> 13 12 <repeat count="8"> -
binaries/data/mods/public/gui/session/selection_panels_right/gate_panel.xml
7 7 <object name="unitGateButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom"> 8 8 <object name="unitGateIcon[n]" type="image" ghost="true" size="3 3 43 43"/> 9 9 <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"/>11 10 </object> 12 11 </repeat> 13 12 </object> -
binaries/data/mods/public/gui/session/selection_panels_right/construction_panel.xml
6 6 <repeat count="24"> 7 7 <object name="unitConstructionButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom"> 8 8 <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"/>10 9 </object> 11 10 </repeat> 12 11 </object> -
source/gui/GUIRenderer.cpp
75 75 std::map<CStr, CGUISprite*>::iterator it(Sprites.find(SpriteName)); 76 76 if (it == Sprites.end()) 77 77 { 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) 86 91 { 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 { 87 99 // TODO: Should check (nicely) that this is a valid file? 88 100 SGUIImage* Image = new SGUIImage; 89 101 102 Image->m_TextureName = TextureName; 90 103 // Allow grayscale images for disabled portraits 91 if (SpriteName. substr(10, 10) == "grayscale:")104 if (SpriteName.Find("grayscale:") != -1) 92 105 { 93 Image->m_TextureName = VfsPath("art/textures/ui") / wstring_from_utf8(SpriteName.substr(20));94 106 Image->m_Effects = new SGUIImageEffects; 95 107 Image->m_Effects->m_Greyscale = true; 96 108 } 97 else98 {99 Image->m_TextureName = VfsPath("art/textures/ui") / wstring_from_utf8(SpriteName.substr(10));100 }101 109 102 110 CClientArea ca(CRect(0, 0, 0, 0), CRect(0, 0, 100, 100)); 103 111 Image->m_Size = ca; 104 112 Image->m_TextureSize = ca; 105 113 106 CGUISprite* Sprite = new CGUISprite;107 114 Sprite->AddImage(Image); 108 115 109 116 Sprites[SpriteName] = Sprite; 110 111 it = Sprites.find(SpriteName);112 ENSURE(it != Sprites.end()); // The insertion above shouldn't fail113 117 } 114 else if (SpriteName. substr(0, 8) == "cropped:")118 else if (SpriteName.Find("cropped:") != -1) 115 119 { 116 120 // TODO: Should check (nicely) that this is a valid file? 117 121 SGUIImage* Image = new SGUIImage; 118 122 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(); 121 126 122 int PathStart = SpriteName.Find(")") + 1;127 Image->m_TextureName = TextureName; 123 128 124 Image->m_TextureName = VfsPath("art/textures/ui") / wstring_from_utf8(SpriteName.substr(PathStart));125 126 129 CClientArea ca(CRect(0, 0, 0, 0), CRect(0, 0, 100, 100)); 127 130 CClientArea cb(CRect(0, 0, 0, 0), CRect(0, 0, 100/xRatio, 100/yRatio)); 128 131 Image->m_Size = ca; 129 132 Image->m_TextureSize = cb; 130 133 131 CGUISprite* Sprite = new CGUISprite;132 134 Sprite->AddImage(Image); 133 135 134 136 Sprites[SpriteName] = Sprite; 135 136 it = Sprites.find(SpriteName);137 ENSURE(it != Sprites.end()); // The insertion above shouldn't fail138 137 } 139 else if (SpriteName.substr(0, 6) == "color:")138 if (SpriteName.Find("color:") != -1) 140 139 { 141 CStrW value = wstring_from_utf8(SpriteName. substr(6));140 CStrW value = wstring_from_utf8(SpriteName.AfterLast("color:").BeforeFirst(":")); 142 141 CColor color; 143 142 144 143 // Check color is valid … … 156 155 Image->m_Size = ca; 157 156 Image->m_TextureSize = ca; 158 157 159 CGUISprite* Sprite = new CGUISprite;160 158 Sprite->AddImage(Image); 161 159 162 160 Sprites[SpriteName] = Sprite; 161 } 162 it = Sprites.find(SpriteName); 163 163 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()) 168 166 { 169 // Otherwise, just complain and give up:167 SAFE_DELETE(Sprite); 170 168 LOGERROR("Trying to use a sprite that doesn't exist (\"%s\").", SpriteName.c_str()); 171 169 return; 172 170 }