Ticket #3205: t3205_enlighten_too_dark_chat_colors_a18.patch

File t3205_enlighten_too_dark_chat_colors_a18.patch, 7.6 KB (added by elexis, 9 years ago)

Same patch as above, but compatible to a18.

  • binaries/data/mods/public/gui/common/color.js

     
     1// Ensure `value` is between 0 and 1.
     2function clampColorValue(value)
     3{
     4    return Math.abs(1 - Math.abs(value - 1));
     5}
     6
     7function rgbToHsl(r, g, b)
     8{
     9    r /= 255;
     10    g /= 255;
     11    b /= 255;
     12    var max = Math.max(r, g, b), min = Math.min(r, g, b);
     13    var h, s, l = (max + min) / 2;
     14
     15    if (max == min)
     16        h = s = 0; // achromatic
     17    else
     18    {
     19        var d = max - min;
     20        s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
     21        switch (max)
     22        {
     23            case r: h = (g - b) / d + (g < b ? 6 : 0); break;
     24            case g: h = (b - r) / d + 2; break;
     25            case b: h = (r - g) / d + 4; break;
     26        }
     27        h /= 6;
     28    }
     29
     30    return [h, s, l];
     31}
     32
     33function hslToRgb(h, s, l)
     34{
     35    function hue2rgb(p, q, t)
     36    {
     37        if (t < 0) t += 1;
     38        if (t > 1) t -= 1;
     39        if (t < 1/6) return p + (q - p) * 6 * t;
     40        if (t < 1/2) return q;
     41        if (t < 2/3) return p + (q - p) * (2/3 - t) * 6;
     42        return p;
     43    }
     44
     45    [h, s, l] = [h, s, l].map(clampColorValue);
     46    var r, g, b;
     47
     48    if (s == 0)
     49        r = g = b = l; // achromatic
     50    else {
     51        var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
     52        var p = 2 * l - q;
     53        r = hue2rgb(p, q, h + 1/3);
     54        g = hue2rgb(p, q, h);
     55        b = hue2rgb(p, q, h - 1/3);
     56    }
     57
     58    return [r, g, b].map(function (n) Math.round(n * 255));
     59}
     60 No newline at end of file
  • binaries/data/mods/public/gui/gamesetup/gamesetup.js

     
    17171717        var mapData = loadMapData(mapName);
    17181718        var mapSettings = (mapData && mapData.settings ? mapData.settings : {});
    17191719        var pData = mapSettings.PlayerData ? mapSettings.PlayerData[player] : {};
    17201720        var pDefs = g_DefaultPlayerData ? g_DefaultPlayerData[player] : {};
    17211721
    1722         color = rgbToGuiColor(getSetting(pData, pDefs, "Colour"));
     1722+       color = getSetting(pData, pDefs, "Colour");
     1723
     1724+       // enlighten colors to improve readability
     1725+       var [h, s, l] = rgbToHsl(color.r, color.g, color.b);
     1726+       var [r, g, b] = hslToRgb(h, s, Math.max(0.7, l));
     1727+       color = rgbToGuiColor({"r": r, "g": g, "b": b});
    17231728    }
    17241729
    17251730    var formatted;
    17261731    switch (msg.type)
    17271732    {
  • binaries/data/mods/public/gui/gamesetup/gamesetup.xml

     
    11<?xml version="1.0" encoding="utf-8"?>
    22
    33<objects>
    44
     5    <script file="gui/common/color.js"/>
    56    <script file="gui/common/network.js"/>
    67    <script file="gui/common/functions_civinfo.js"/>
    78    <script file="gui/common/functions_global_object.js"/>
    89    <script file="gui/common/functions_utility.js"/>
    910    <script file="gui/gamesetup/gamesetup.js"/>
  • binaries/data/mods/public/gui/lobby/lobby.js

     
    232232    if (role && caller == "lobbylist")
    233233    {
    234234        // Make the role uppercase.
    235235        role = role.charAt(0).toUpperCase() + role.slice(1);
    236236        if (role == "Moderator")
    237             role = '[color="0 125 0"]' + translate(role) + '[/color]';
     237            role = '[color="0 219 0"]' + translate(role) + '[/color]';
    238238    }
    239239    else
    240240        role = "";
    241241
    242242    Engine.GetGUIObjectByName("usernameText").caption = user;
     
    392392        if(!filterGame(g))
    393393        {
    394394            // 'waiting' games are highlighted in orange, 'running' in red, and 'init' in green.
    395395            let name;
    396396            if (g.state == 'init')
    397                 name = '[color="0 125 0"]' + g.name + '[/color]';
     397                name = '[color="0 219 0"]' + g.name + '[/color]';
    398398            else if (g.state == 'waiting')
    399399                name = '[color="255 127 0"]' + g.name + '[/color]';
    400400            else
    401                 name = '[color="255 0 0"]' + g.name + '[/color]';
     401                name = '[color="219 0 0"]' + g.name + '[/color]';
    402402            list_name.push(name);
    403403            list_ip.push(g.ip);
    404404            list_mapName.push(translate(g.niceMapName));
    405405            list_mapSize.push(translatedMapSize(g.mapSize));
    406406            let idx = g_mapTypes.indexOf(g.mapType);
     
    450450    case "away":
    451451        color = "229 76 13";
    452452        status = translate("Away");
    453453        break;
    454454    case "available":
    455         color = "0 125 0";
     455        color = "0 219 0";
    456456        status = translate("Online");
    457457        break;
    458458    case "offline":
    459459        color = "0 0 0";
    460460        status = translate("Offline");
     
    10151015    // First create the color in RGB then HSL, clamp the lightness so it's not too dark to read, and then convert back to RGB to display.
    10161016    // The reason for this roundabout method is this algorithm can generate values from 0 to 255 for RGB but only 0 to 100 for HSL; this gives
    10171017    // us much more variety if we generate in RGB. Unfortunately, enforcing that RGB values are a certain lightness is very difficult, so
    10181018    // we convert to HSL to do the computation. Since our GUI code only displays RGB colors, we have to convert back.
    10191019    var [h, s, l] = rgbToHsl(hash >> 24 & 0xFF, hash >> 16 & 0xFF, hash >> 8 & 0xFF);
    1020     return hslToRgb(h, s, Math.max(0.4, l)).join(" ");
     1020    return hslToRgb(h, s, Math.max(0.7, l)).join(" ");
    10211021}
    10221022
    10231023function repeatString(times, string) {
    10241024    return Array(times + 1).join(string);
    10251025}
     
    10431043function clampColorValue(value)
    10441044{
    10451045    return Math.abs(1 - Math.abs(value - 1));
    10461046}
    10471047
    1048 // See http://stackoverflow.com/questions/2353211/hsl-to-rgb-color-conversion
    1049 function rgbToHsl(r, g, b)
    1050 {
    1051     r /= 255;
    1052     g /= 255;
    1053     b /= 255;
    1054     var max = Math.max(r, g, b), min = Math.min(r, g, b);
    1055     var h, s, l = (max + min) / 2;
    1056 
    1057     if (max == min)
    1058         h = s = 0; // achromatic
    1059     else
    1060     {
    1061         var d = max - min;
    1062         s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
    1063         switch (max)
    1064         {
    1065             case r: h = (g - b) / d + (g < b ? 6 : 0); break;
    1066             case g: h = (b - r) / d + 2; break;
    1067             case b: h = (r - g) / d + 4; break;
    1068         }
    1069         h /= 6;
    1070     }
    1071 
    1072     return [h, s, l];
    1073 }
    1074 
    1075 function hslToRgb(h, s, l)
    1076 {
    1077     function hue2rgb(p, q, t)
    1078     {
    1079         if (t < 0) t += 1;
    1080         if (t > 1) t -= 1;
    1081         if (t < 1/6) return p + (q - p) * 6 * t;
    1082         if (t < 1/2) return q;
    1083         if (t < 2/3) return p + (q - p) * (2/3 - t) * 6;
    1084         return p;
    1085     }
    1086 
    1087     [h, s, l] = [h, s, l].map(clampColorValue);
    1088     var r, g, b;
    1089 
    1090     if (s == 0)
    1091         r = g = b = l; // achromatic
    1092     else {
    1093         var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
    1094         var p = 2 * l - q;
    1095         r = hue2rgb(p, q, h + 1/3);
    1096         g = hue2rgb(p, q, h);
    1097         b = hue2rgb(p, q, h - 1/3);
    1098     }
    1099 
    1100     return [r, g, b].map(function (n) Math.round(n * 255));
    1101 }
    1102 
    11031048(function () {
    11041049function hexToRgb(hex) {
    11051050    return parseInt(hex.slice(0, 2), 16) + "." + parseInt(hex.slice(2, 4), 16) + "." + parseInt(hex.slice(4, 6), 16) + ".";
    11061051}
    11071052function r(times, hex) {
  • binaries/data/mods/public/gui/lobby/lobby.xml

     
    11<?xml version="1.0" encoding="utf-8"?>
    22
    33<objects>
    44    <script file="gui/common/functions_global_object.js"/>
    55    <script file="gui/common/functions_utility.js"/>
     6    <script file="gui/common/color.js"/>
    67    <script file="gui/common/timer.js"/>
    78    <script file="gui/common/music.js"/>
    8 
    99    <script file="gui/lobby/lobby.js"/>
    1010
    1111    <object type="image" style="ModernWindow" size="0 0 100% 100%" name="lobbyWindow">
    1212
    1313        <object style="ModernLabelText" type="text" size="50%-128 0%+4 50%+128 36">