Ticket #3205: lobby_gamesetup_color_complete.patch
File lobby_gamesetup_color_complete.patch, 6.4 KB (added by , 9 years ago) |
---|
-
gui/common/color.js
diff -ru public-org/gui/common/color.js public-my/gui/common/color.js
old new 1 //////////////////////////////////////////////////////////////////////////////////////////////// 2 // some color functions previously used from lobby.js 3 // now spread over lobby.js and gamesetup.js 4 5 // Ensure `value` is between 0 and 1. 6 function clampColorValue(value) 7 { 8 return Math.abs(1 - Math.abs(value - 1)); 9 } 10 11 function rgbToHsl(r, g, b) 12 { 13 r /= 255; 14 g /= 255; 15 b /= 255; 16 var max = Math.max(r, g, b), min = Math.min(r, g, b); 17 var h, s, l = (max + min) / 2; 18 19 if (max == min) 20 h = s = 0; // achromatic 21 else 22 { 23 var d = max - min; 24 s = l > 0.5 ? d / (2 - max - min) : d / (max + min); 25 switch (max) 26 { 27 case r: h = (g - b) / d + (g < b ? 6 : 0); break; 28 case g: h = (b - r) / d + 2; break; 29 case b: h = (r - g) / d + 4; break; 30 } 31 h /= 6; 32 } 33 34 return [h, s, l]; 35 } 36 37 function hslToRgb(h, s, l) 38 { 39 function hue2rgb(p, q, t) 40 { 41 if (t < 0) t += 1; 42 if (t > 1) t -= 1; 43 if (t < 1/6) return p + (q - p) * 6 * t; 44 if (t < 1/2) return q; 45 if (t < 2/3) return p + (q - p) * (2/3 - t) * 6; 46 return p; 47 } 48 49 [h, s, l] = [h, s, l].map(clampColorValue); 50 var r, g, b; 51 52 if (s == 0) 53 r = g = b = l; // achromatic 54 else { 55 var q = l < 0.5 ? l * (1 + s) : l + s - l * s; 56 var p = 2 * l - q; 57 r = hue2rgb(p, q, h + 1/3); 58 g = hue2rgb(p, q, h); 59 b = hue2rgb(p, q, h - 1/3); 60 } 61 62 return [r, g, b].map(function (n) Math.round(n * 255)); 63 } 64 65 -
gui/gamesetup/gamesetup.js
diff -ru public-org/gui/gamesetup/gamesetup.js public-my/gui/gamesetup/gamesetup.js
old new 1719 1719 var pData = mapSettings.PlayerData ? mapSettings.PlayerData[player] : {}; 1720 1720 var pDefs = g_DefaultPlayerData ? g_DefaultPlayerData[player] : {}; 1721 1721 1722 color = rgbToGuiColor(getSetting(pData, pDefs, "Colour")); 1722 var col = getSetting(pData, pDefs, "Colour"); 1723 var [h1, s1, l1] = rgbToHsl(col.r,col.g,col.b); 1724 // enlight colors for readability in chat 1725 var [r, g, b] = hslToRgb(h1, s1, Math.max(0.7, l1)); 1726 col.r = r; col.g = g; col.b = b; 1727 color = rgbToGuiColor(col); 1723 1728 } 1724 1729 1725 1730 var formatted; -
gui/gamesetup/gamesetup.xml
diff -ru public-org/gui/gamesetup/gamesetup.xml public-my/gui/gamesetup/gamesetup.xml
old new 2 2 3 3 <objects> 4 4 5 <script file="gui/common/color.js"/> 5 6 <script file="gui/common/network.js"/> 6 7 <script file="gui/common/functions_civinfo.js"/> 7 8 <script file="gui/common/functions_global_object.js"/> -
gui/lobby/lobby.js
diff -ru public-org/gui/lobby/lobby.js public-my/gui/lobby/lobby.js
old new 394 394 // 'waiting' games are highlighted in orange, 'running' in red, and 'init' in green. 395 395 let name; 396 396 if (g.state == 'init') 397 name = '[color="0 1250"]' + g.name + '[/color]';397 name = '[color="0 219 0"]' + g.name + '[/color]'; 398 398 else if (g.state == 'waiting') 399 399 name = '[color="255 127 0"]' + g.name + '[/color]'; 400 400 else 401 name = '[color="2 550 0"]' + g.name + '[/color]';401 name = '[color="219 0 0"]' + g.name + '[/color]'; 402 402 list_name.push(name); 403 403 list_ip.push(g.ip); 404 404 list_mapName.push(translate(g.niceMapName)); … … 443 443 switch (presence) 444 444 { 445 445 case "playing": 446 color = "1 250 0";446 color = "191 0 0"; 447 447 status = translate("Busy"); 448 448 break; 449 449 case "gone": … … 452 452 status = translate("Away"); 453 453 break; 454 454 case "available": 455 color = "0 1250";455 color = "0 219 0"; 456 456 status = translate("Online"); 457 457 break; 458 458 case "offline": … … 1017 1017 // us much more variety if we generate in RGB. Unfortunately, enforcing that RGB values are a certain lightness is very difficult, so 1018 1018 // we convert to HSL to do the computation. Since our GUI code only displays RGB colors, we have to convert back. 1019 1019 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(" "); 1021 1021 } 1022 1022 1023 1023 function repeatString(times, string) { … … 1039 1039 return '[color="' + getPlayerColor(playername.replace(g_modPrefix, "")) + '"]' + playername + '[/color]'; 1040 1040 } 1041 1041 1042 // Ensure `value` is between 0 and 1.1043 function clampColorValue(value)1044 {1045 return Math.abs(1 - Math.abs(value - 1));1046 }1047 1048 // See http://stackoverflow.com/questions/2353211/hsl-to-rgb-color-conversion1049 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; // achromatic1059 else1060 {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; // achromatic1092 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 1103 1042 (function () { 1104 1043 function hexToRgb(hex) { 1105 1044 return parseInt(hex.slice(0, 2), 16) + "." + parseInt(hex.slice(2, 4), 16) + "." + parseInt(hex.slice(4, 6), 16) + "."; -
gui/lobby/lobby.xml
diff -ru public-org/gui/lobby/lobby.xml public-my/gui/lobby/lobby.xml
old new 1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 3 3 <objects> 4 <script file="gui/common/color.js"/> 4 5 <script file="gui/common/functions_global_object.js"/> 5 6 <script file="gui/common/functions_utility.js"/> 6 7 <script file="gui/common/timer.js"/>