GUI cleanup.
Remove toTitleCase(). Unify iColorToString() and rgbToGuiColor(). Translate XMPP errors (displayed when connecting). This was SVN commit r15960.
This commit is contained in:
parent
6e788fb15e
commit
1a0f9b086e
@ -87,20 +87,6 @@ function escapeText(text)
|
||||
|
||||
// ====================================================================
|
||||
|
||||
function toTitleCase (string)
|
||||
{
|
||||
if (!string)
|
||||
return string;
|
||||
|
||||
// Returns the title-case version of a given string.
|
||||
string = string.toString();
|
||||
string = string[0].toUpperCase() + string.substring(1).toLowerCase();
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
// Load default player data, for when it's not otherwise specified
|
||||
function initPlayerDefaults()
|
||||
{
|
||||
@ -182,13 +168,12 @@ function initGameSpeeds()
|
||||
// ====================================================================
|
||||
|
||||
// Convert integer color values to string (for use in GUI objects)
|
||||
function iColorToString(color)
|
||||
function rgbToGuiColor(color)
|
||||
{
|
||||
var string = "0 0 0";
|
||||
if (color && ("r" in color) && ("g" in color) && ("b" in color))
|
||||
string = color.r + " " + color.g + " " + color.b;
|
||||
return color.r + " " + color.g + " " + color.b;
|
||||
|
||||
return string;
|
||||
return "0 0 0";
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
@ -1290,7 +1290,7 @@ function onGameAttributesChange()
|
||||
var pDefs = g_DefaultPlayerData ? g_DefaultPlayerData[i] : {};
|
||||
|
||||
// Common to all game types
|
||||
var color = iColorToString(getSetting(pData, pDefs, "Colour"));
|
||||
var color = rgbToGuiColor(getSetting(pData, pDefs, "Colour"));
|
||||
pColor.sprite = "colour:" + color + " 100";
|
||||
pName.caption = translate(getSetting(pData, pDefs, "Name"));
|
||||
|
||||
@ -1599,7 +1599,7 @@ function addChatMessage(msg)
|
||||
var pData = mapSettings.PlayerData ? mapSettings.PlayerData[player] : {};
|
||||
var pDefs = g_DefaultPlayerData ? g_DefaultPlayerData[player] : {};
|
||||
|
||||
color = iColorToString(getSetting(pData, pDefs, "Colour"));
|
||||
color = rgbToGuiColor(getSetting(pData, pDefs, "Colour"));
|
||||
}
|
||||
|
||||
var formatted;
|
||||
|
@ -6,6 +6,8 @@ var g_specialKey = Math.random();
|
||||
var g_spamMonitor = {};
|
||||
var g_timestamp = Engine.ConfigDB_GetValue("user", "lobby.chattimestamp") == "true";
|
||||
var g_mapSizes = {};
|
||||
const g_mapTypesText = [translateWithContext("map", "Skirmish"), translateWithContext("map", "Random"), translate("Scenario")];
|
||||
const g_mapTypes = ["skirmish", "random", "scenario"];
|
||||
var g_userRating = ""; // Rating of user, defaults to Unrated
|
||||
var g_modPrefix = "@";
|
||||
// Block spammers for 30 seconds.
|
||||
@ -34,8 +36,8 @@ function init(attribs)
|
||||
playersNumberFilter.list_data = ["",2,3,4,5,6,7,8];
|
||||
|
||||
var mapTypeFilter = Engine.GetGUIObjectByName("mapTypeFilter");
|
||||
mapTypeFilter.list = [translateWithContext("map", "Any"), translateWithContext("map", "Skirmish"), translateWithContext("map", "Random"), translate("Scenario")];
|
||||
mapTypeFilter.list_data = ["", "skirmish", "random", "scenario"];
|
||||
mapTypeFilter.list = [translateWithContext("map", "Any")].concat(g_mapTypesText);
|
||||
mapTypeFilter.list_data = [""].concat(g_mapTypes);
|
||||
|
||||
Engine.LobbySetPlayerPresence("available");
|
||||
Engine.SendGetGameList();
|
||||
@ -387,7 +389,7 @@ function updateGameList()
|
||||
if(!filterGame(g))
|
||||
{
|
||||
// 'waiting' games are highlighted in orange, 'running' in red, and 'init' in green.
|
||||
var name;
|
||||
let name;
|
||||
if (g.state == 'init')
|
||||
name = '[color="0 125 0"]' + g.name + '[/color]';
|
||||
else if (g.state == 'waiting')
|
||||
@ -401,7 +403,8 @@ function updateGameList()
|
||||
list_mapSize.push(translate(g.mapSize));
|
||||
else
|
||||
list_mapSize.push(g_mapSizes.shortNames[g_mapSizes.tiles.indexOf(+g.mapSize)]);
|
||||
list_mapType.push(translate(toTitleCase(g.mapType)));
|
||||
let idx = g_mapTypes.indexOf(g.mapType);
|
||||
list_mapType.push(idx != -1 ? g_mapTypesText[idx] : "");
|
||||
list_nPlayers.push(g.nbp + "/" +g.tnbp);
|
||||
list.push(g.name);
|
||||
list_data.push(c);
|
||||
@ -515,7 +518,8 @@ function updateGameSelection()
|
||||
Engine.GetGUIObjectByName("sgNbPlayers").caption = g_GameList[g].nbp + "/" + g_GameList[g].tnbp;
|
||||
Engine.GetGUIObjectByName("sgPlayersNames").caption = g_GameList[g].players;
|
||||
Engine.GetGUIObjectByName("sgMapSize").caption = g_GameList[g].mapSize.split("(")[0];
|
||||
Engine.GetGUIObjectByName("sgMapType").caption = translate(toTitleCase(g_GameList[g].mapType));
|
||||
let idx = g_mapTypes.indexOf(g_GameList[g].mapType);
|
||||
Engine.GetGUIObjectByName("sgMapType").caption = idx != -1 ? g_mapTypesText[idx] : "";
|
||||
|
||||
// Display map description if it exists, otherwise display a placeholder.
|
||||
if (mapData && mapData.settings.Description)
|
||||
|
@ -192,7 +192,7 @@ function onTick()
|
||||
else if (message.type == "system" && message.text == "registered")
|
||||
{
|
||||
// Great, we are registered. Switch to the connection window.
|
||||
feedback.caption = toTitleCase(message.text);
|
||||
feedback.caption = translate("Registered");
|
||||
Engine.StopXmppClient();
|
||||
g_LobbyIsConnecting = false;
|
||||
Engine.GetGUIObjectByName("connectUsername").caption = username;
|
||||
@ -202,7 +202,7 @@ function onTick()
|
||||
else if(message.type == "system" && (message.level == "error" || message.text == "disconnected"))
|
||||
{
|
||||
g_hasSystemMessage = true;
|
||||
feedback.caption = toTitleCase(message.text);
|
||||
feedback.caption = message.text == "disconnected" ? translate("Disconnected") : message.text;
|
||||
Engine.StopXmppClient();
|
||||
g_LobbyIsConnecting = false;
|
||||
}
|
||||
|
@ -257,25 +257,25 @@ function openDiplomacy()
|
||||
closeTrade();
|
||||
isDiplomacyOpen = true;
|
||||
|
||||
var we = Engine.GetPlayerID();
|
||||
var players = getPlayerData(g_PlayerAssignments);
|
||||
let we = Engine.GetPlayerID();
|
||||
let players = getPlayerData(g_PlayerAssignments);
|
||||
|
||||
// Get offset for one line
|
||||
var onesize = Engine.GetGUIObjectByName("diplomacyPlayer[0]").size;
|
||||
var rowsize = onesize.bottom - onesize.top;
|
||||
let onesize = Engine.GetGUIObjectByName("diplomacyPlayer[0]").size;
|
||||
let rowsize = onesize.bottom - onesize.top;
|
||||
|
||||
// We don't include gaia
|
||||
for (var i = 1; i < players.length; i++)
|
||||
for (let i = 1; i < players.length; ++i)
|
||||
{
|
||||
// Apply offset
|
||||
var row = Engine.GetGUIObjectByName("diplomacyPlayer["+(i-1)+"]");
|
||||
var size = row.size;
|
||||
let row = Engine.GetGUIObjectByName("diplomacyPlayer["+(i-1)+"]");
|
||||
let size = row.size;
|
||||
size.top = rowsize*(i-1);
|
||||
size.bottom = rowsize*i;
|
||||
row.size = size;
|
||||
|
||||
// Set background colour
|
||||
var playerColor = players[i].color.r+" "+players[i].color.g+" "+players[i].color.b;
|
||||
let playerColor = rgbToGuiColor(players[i].color);
|
||||
row.sprite = "colour: "+playerColor + " 32";
|
||||
|
||||
Engine.GetGUIObjectByName("diplomacyPlayerName["+(i-1)+"]").caption = "[color=\"" + playerColor + "\"]" + players[i].name + "[/color]";
|
||||
@ -290,27 +290,27 @@ function openDiplomacy()
|
||||
if (i == we || players[we].state != "active" || players[i].state != "active")
|
||||
{
|
||||
// Hide the unused/unselectable options
|
||||
for each (var a in ["TributeFood", "TributeWood", "TributeStone", "TributeMetal", "Ally", "Neutral", "Enemy"])
|
||||
for each (let a in ["TributeFood", "TributeWood", "TributeStone", "TributeMetal", "Ally", "Neutral", "Enemy"])
|
||||
Engine.GetGUIObjectByName("diplomacyPlayer"+a+"["+(i-1)+"]").hidden = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Tribute
|
||||
for each (var resource in ["food", "wood", "stone", "metal"])
|
||||
for each (let resource in ["food", "wood", "stone", "metal"])
|
||||
{
|
||||
var button = Engine.GetGUIObjectByName("diplomacyPlayerTribute"+toTitleCase(resource)+"["+(i-1)+"]");
|
||||
let button = Engine.GetGUIObjectByName("diplomacyPlayerTribute"+resource[0].toUpperCase()+resource.substring(1)+"["+(i-1)+"]");
|
||||
button.onpress = (function(player, resource, button){
|
||||
// Implement something like how unit batch training works. Shift+click to send 500, shift+click+click to send 1000, etc.
|
||||
// Also see input.js (searching for "INPUT_MASSTRIBUTING" should get all the relevant parts).
|
||||
var multiplier = 1;
|
||||
let multiplier = 1;
|
||||
return function() {
|
||||
var isBatchTrainPressed = Engine.HotkeyIsPressed("session.masstribute");
|
||||
let isBatchTrainPressed = Engine.HotkeyIsPressed("session.masstribute");
|
||||
if (isBatchTrainPressed)
|
||||
{
|
||||
inputState = INPUT_MASSTRIBUTING;
|
||||
multiplier += multiplier == 1 ? 4 : 5;
|
||||
}
|
||||
var amounts = {
|
||||
let amounts = {
|
||||
"food": (resource == "food" ? 100 : 0) * multiplier,
|
||||
"wood": (resource == "wood" ? 100 : 0) * multiplier,
|
||||
"stone": (resource == "stone" ? 100 : 0) * multiplier,
|
||||
@ -338,32 +338,12 @@ function openDiplomacy()
|
||||
|
||||
// Diplomacy settings
|
||||
// Set up the buttons
|
||||
for each (var setting in ["ally", "neutral", "enemy"])
|
||||
for each (let setting in ["Ally", "Neutral", "Enemy"])
|
||||
{
|
||||
var button = Engine.GetGUIObjectByName("diplomacyPlayer"+toTitleCase(setting)+"["+(i-1)+"]");
|
||||
let button = Engine.GetGUIObjectByName("diplomacyPlayer"+setting+"["+(i-1)+"]");
|
||||
|
||||
if (setting == "ally")
|
||||
{
|
||||
if (players[we].isAlly[i])
|
||||
button.caption = translate("x");
|
||||
else
|
||||
button.caption = "";
|
||||
}
|
||||
else if (setting == "neutral")
|
||||
{
|
||||
if (players[we].isNeutral[i])
|
||||
button.caption = translate("x");
|
||||
else
|
||||
button.caption = "";
|
||||
}
|
||||
else // "enemy"
|
||||
{
|
||||
if (players[we].isEnemy[i])
|
||||
button.caption = translate("x");
|
||||
else
|
||||
button.caption = "";
|
||||
}
|
||||
button.onpress = (function(e){ return function() { setDiplomacy(e) } })({"player": i, "to": setting});
|
||||
button.caption = players[we]["is"+setting][i] ? translate("x") : "";
|
||||
button.onpress = (function(e){ return function() { setDiplomacy(e) } })({"player": i, "to": setting.toLowerCase()});
|
||||
button.hidden = false;
|
||||
}
|
||||
}
|
||||
@ -692,7 +672,7 @@ function closeOpenDialogs()
|
||||
|
||||
function formatTributeTooltip(player, resource, amount)
|
||||
{
|
||||
var playerColor = player.color.r + " " + player.color.g + " " + player.color.b;
|
||||
let playerColor = rgbToGuiColor(player.color);
|
||||
return sprintf(translate("Tribute %(resourceAmount)s %(resourceType)s to %(playerName)s. Shift-click to tribute %(greaterAmount)s."), {
|
||||
resourceAmount: amount,
|
||||
resourceType: getLocalizedResourceName(resource, "withinSentence"),
|
||||
|
@ -141,10 +141,7 @@ g_SelectionPanels.Command = {
|
||||
},
|
||||
"setTooltip": function(data)
|
||||
{
|
||||
if (data.item.tooltip)
|
||||
data.button.tooltip = data.item.tooltip
|
||||
else
|
||||
data.button.tooltip = toTitleCase(data.item.name);
|
||||
data.button.tooltip = data.item.tooltip;
|
||||
},
|
||||
"setAction": function(data)
|
||||
{
|
||||
|
@ -16,27 +16,6 @@ const COST_DISPLAY_NAMES = {
|
||||
// Utility functions
|
||||
//-------------------------------- --------------------------------
|
||||
|
||||
function toTitleCase(word)
|
||||
{
|
||||
if (word.length > 0)
|
||||
{
|
||||
var titleCased = word.substring(0, 1).toUpperCase();
|
||||
|
||||
if (word.length > 1)
|
||||
{
|
||||
titleCased += word.substring(1).toLowerCase();
|
||||
}
|
||||
return titleCased;
|
||||
}
|
||||
|
||||
return word;
|
||||
}
|
||||
|
||||
function rgbToGuiColor(color)
|
||||
{
|
||||
return color.r + " " + color.g + " " + color.b;
|
||||
}
|
||||
|
||||
//===============================================
|
||||
// Player functions
|
||||
|
||||
|
@ -651,6 +651,7 @@ function setup_all_libs ()
|
||||
source_dirs = {
|
||||
"lobby",
|
||||
"lobby/scripting",
|
||||
"i18n",
|
||||
"third_party/encryption"
|
||||
}
|
||||
|
||||
@ -658,6 +659,7 @@ function setup_all_libs ()
|
||||
"spidermonkey",
|
||||
"boost",
|
||||
"gloox",
|
||||
"tinygettext"
|
||||
}
|
||||
setup_static_lib_project("lobby", source_dirs, extern_libs, {})
|
||||
|
||||
|
@ -19,19 +19,12 @@
|
||||
#include "XmppClient.h"
|
||||
#include "StanzaExtensions.h"
|
||||
|
||||
#include "lib/utf8.h"
|
||||
|
||||
// Debug
|
||||
#include "ps/CLogger.h"
|
||||
|
||||
// Gloox
|
||||
#include "glooxwrapper/glooxwrapper.h"
|
||||
|
||||
// Game - script
|
||||
#include "scriptinterface/ScriptInterface.h"
|
||||
|
||||
// Configuration
|
||||
#include "i18n/L10n.h"
|
||||
#include "lib/utf8.h"
|
||||
#include "ps/CLogger.h"
|
||||
#include "ps/ConfigDB.h"
|
||||
#include "scriptinterface/ScriptInterface.h"
|
||||
|
||||
//debug
|
||||
#if 1
|
||||
@ -225,7 +218,7 @@ void XmppClient::onDisconnect(gloox::ConnectionError error)
|
||||
m_Profile.clear();
|
||||
|
||||
if(error == gloox::ConnAuthenticationFailed)
|
||||
CreateSimpleMessage("system", "authentication failed", "error");
|
||||
CreateSimpleMessage("system", g_L10n.Translate("Authentication failed"), "error");
|
||||
else
|
||||
CreateSimpleMessage("system", "disconnected");
|
||||
}
|
||||
@ -461,15 +454,15 @@ void XmppClient::handleRegistrationResult(const glooxwrapper::JID&, gloox::Regis
|
||||
#define CASE(X, Y) case gloox::X: msg = Y; break
|
||||
switch(result)
|
||||
{
|
||||
CASE(RegistrationNotAcceptable, "Registration not acceptable");
|
||||
CASE(RegistrationConflict, "Registration conflict");
|
||||
CASE(RegistrationNotAuthorized, "Registration not authorized");
|
||||
CASE(RegistrationBadRequest, "Registration bad request");
|
||||
CASE(RegistrationForbidden, "Registration forbidden");
|
||||
CASE(RegistrationRequired, "Registration required");
|
||||
CASE(RegistrationUnexpectedRequest, "Registration unexpected request");
|
||||
CASE(RegistrationNotAllowed, "Registration not allowed");
|
||||
default: msg = "Registration unknown error";
|
||||
CASE(RegistrationNotAcceptable, g_L10n.Translate("Registration not acceptable"));
|
||||
CASE(RegistrationConflict, g_L10n.Translate("Registration conflict"));
|
||||
CASE(RegistrationNotAuthorized, g_L10n.Translate("Registration not authorized"));
|
||||
CASE(RegistrationBadRequest, g_L10n.Translate("Registration bad request"));
|
||||
CASE(RegistrationForbidden, g_L10n.Translate("Registration forbidden"));
|
||||
CASE(RegistrationRequired, g_L10n.Translate("Registration required"));
|
||||
CASE(RegistrationUnexpectedRequest, g_L10n.Translate("Registration unexpected request"));
|
||||
CASE(RegistrationNotAllowed, g_L10n.Translate("Registration not allowed"));
|
||||
default: msg = g_L10n.Translate("Registration unknown error");
|
||||
}
|
||||
#undef CASE
|
||||
CreateSimpleMessage("system", msg, "error");
|
||||
@ -754,7 +747,9 @@ bool XmppClient::handleIq(const glooxwrapper::IQ& iq)
|
||||
}
|
||||
else
|
||||
{
|
||||
CreateSimpleMessage("system", std::string("unknown subtype : ") + tag_name(iq), "error");
|
||||
CreateSimpleMessage("system", g_L10n.Translate("unknown subtype (see logs)"), "error");
|
||||
std::string tag = tag_name(iq);
|
||||
LOGMESSAGE(L"unknown subtype '%hs'", tag.c_str());
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -998,32 +993,32 @@ std::string XmppClient::StanzaErrorToString(gloox::StanzaError err)
|
||||
#define CASE(X, Y) case gloox::X: return Y
|
||||
switch (err)
|
||||
{
|
||||
CASE(StanzaErrorBadRequest, "Bad request");
|
||||
CASE(StanzaErrorConflict, "Player name already in use");
|
||||
CASE(StanzaErrorFeatureNotImplemented, "Feature not implemented");
|
||||
CASE(StanzaErrorForbidden, "Forbidden");
|
||||
CASE(StanzaErrorGone, "Recipient or server gone");
|
||||
CASE(StanzaErrorInternalServerError, "Internal server error");
|
||||
CASE(StanzaErrorItemNotFound, "Item not found");
|
||||
CASE(StanzaErrorJidMalformed, "Jid malformed");
|
||||
CASE(StanzaErrorNotAcceptable, "Not acceptable");
|
||||
CASE(StanzaErrorNotAllowed, "Not allowed");
|
||||
CASE(StanzaErrorNotAuthorized, "Not authorized");
|
||||
CASE(StanzaErrorNotModified, "Not modified");
|
||||
CASE(StanzaErrorPaymentRequired, "Payment required");
|
||||
CASE(StanzaErrorRecipientUnavailable, "Recipient unavailable");
|
||||
CASE(StanzaErrorRedirect, "Redirect");
|
||||
CASE(StanzaErrorRegistrationRequired, "Registration required");
|
||||
CASE(StanzaErrorRemoteServerNotFound, "Remote server not found");
|
||||
CASE(StanzaErrorRemoteServerTimeout, "Remote server timeout");
|
||||
CASE(StanzaErrorResourceConstraint, "Resource constraint");
|
||||
CASE(StanzaErrorServiceUnavailable, "Service unavailable");
|
||||
CASE(StanzaErrorSubscribtionRequired, "Subscribtion Required");
|
||||
CASE(StanzaErrorUndefinedCondition, "Undefined condition");
|
||||
CASE(StanzaErrorUnexpectedRequest, "Unexpected request");
|
||||
CASE(StanzaErrorUnknownSender, "Unknown sender");
|
||||
CASE(StanzaErrorBadRequest, g_L10n.Translate("Bad request"));
|
||||
CASE(StanzaErrorConflict, g_L10n.Translate("Player name already in use"));
|
||||
CASE(StanzaErrorFeatureNotImplemented, g_L10n.Translate("Feature not implemented"));
|
||||
CASE(StanzaErrorForbidden, g_L10n.Translate("Forbidden"));
|
||||
CASE(StanzaErrorGone, g_L10n.Translate("Recipient or server gone"));
|
||||
CASE(StanzaErrorInternalServerError, g_L10n.Translate("Internal server error"));
|
||||
CASE(StanzaErrorItemNotFound, g_L10n.Translate("Item not found"));
|
||||
CASE(StanzaErrorJidMalformed, g_L10n.Translate("Jid malformed"));
|
||||
CASE(StanzaErrorNotAcceptable, g_L10n.Translate("Not acceptable"));
|
||||
CASE(StanzaErrorNotAllowed, g_L10n.Translate("Not allowed"));
|
||||
CASE(StanzaErrorNotAuthorized, g_L10n.Translate("Not authorized"));
|
||||
CASE(StanzaErrorNotModified, g_L10n.Translate("Not modified"));
|
||||
CASE(StanzaErrorPaymentRequired, g_L10n.Translate("Payment required"));
|
||||
CASE(StanzaErrorRecipientUnavailable, g_L10n.Translate("Recipient unavailable"));
|
||||
CASE(StanzaErrorRedirect, g_L10n.Translate("Redirect"));
|
||||
CASE(StanzaErrorRegistrationRequired, g_L10n.Translate("Registration required"));
|
||||
CASE(StanzaErrorRemoteServerNotFound, g_L10n.Translate("Remote server not found"));
|
||||
CASE(StanzaErrorRemoteServerTimeout, g_L10n.Translate("Remote server timeout"));
|
||||
CASE(StanzaErrorResourceConstraint, g_L10n.Translate("Resource constraint"));
|
||||
CASE(StanzaErrorServiceUnavailable, g_L10n.Translate("Service unavailable"));
|
||||
CASE(StanzaErrorSubscribtionRequired, g_L10n.Translate("Subscribtion Required"));
|
||||
CASE(StanzaErrorUndefinedCondition, g_L10n.Translate("Undefined condition"));
|
||||
CASE(StanzaErrorUnexpectedRequest, g_L10n.Translate("Unexpected request"));
|
||||
CASE(StanzaErrorUnknownSender, g_L10n.Translate("Unknown sender"));
|
||||
default:
|
||||
return "Error undefined";
|
||||
return g_L10n.Translate("Error undefined");
|
||||
}
|
||||
#undef CASE
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user