Skip to content

Commit

Permalink
Clean up class parsing + add visible classes to be displayed in the G…
Browse files Browse the repository at this point in the history
…UI without adding them separatedly to our tooltips

git-svn-id: http://svn.wildfiregames.com/public/ps/trunk@15195 3db68df2-c116-0410-a063-a993310a9797
  • Loading branch information
sanderd17 committed May 22, 2014
1 parent f280288 commit 9d74acc
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 33 deletions.
9 changes: 9 additions & 0 deletions binaries/data/mods/public/gui/session/selection_details.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,15 @@ function displaySingle(entState, template)
if (genericName)
iconTooltip = "[font=\"sans-bold-16\"]" + genericName + "[/font]";

if (template.visibleIdentityClasses && template.visibleIdentityClasses.length)
{
iconTooltip += "\n[font=\"sans-bold-13\"]" + translate("Classes:") + "[/font] ";
iconTooltip += "[font=\"sans-13\"]" + translate(template.visibleIdentityClasses[0]) ;
for (var i = 1; i < template.visibleIdentityClasses.length; i++)
iconTooltip += ", " + translate(template.visibleIdentityClasses[i]);
iconTooltip += "[/font]";
}

if (template.tooltip)
iconTooltip += "\n[font=\"sans-13\"]" + template.tooltip + "[/font]";

Expand Down
9 changes: 9 additions & 0 deletions binaries/data/mods/public/gui/session/unit_commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,15 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, playerState, items, c
if (key)
tooltip = "[color=\"255 251 131\"][font=\"sans-bold-16\"][" + key + "][/font][/color] " + tooltip;

if (template.visibleIdentityClasses && template.visibleIdentityClasses.length)
{
tooltip += "\n[font=\"sans-bold-13\"]" + translate("Classes:") + "[/font] ";
tooltip += "[font=\"sans-13\"]" + translate(template.visibleIdentityClasses[0]) ;
for (var c = 1; c < template.visibleIdentityClasses.length; c++)
tooltip += ", " + translate(template.visibleIdentityClasses[c]);
tooltip += "[/font]";
}

if (template.tooltip)
tooltip += "\n[font=\"sans-13\"]" + template.tooltip + "[/font]";

Expand Down
3 changes: 3 additions & 0 deletions binaries/data/mods/public/l10n/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@
"keywords": {
"GenericName": {},
"SpecificName": {},
"VisibleClasses": {
"splitOnWhitespace": true
},
"Tooltip": {},
"GateConversionTooltip": {},
"DisabledTooltip": {},
Expand Down
11 changes: 2 additions & 9 deletions binaries/data/mods/public/simulation/components/AuraManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,9 @@ AuraManager.prototype.ApplyTemplateModifications = function(valueName, value, pl
if (!this.templateModificationsCache[valueName] || !this.templateModificationsCache[valueName][player])
return value;

var rawClasses;
var classes = [];
if (template && template.Identity)
{
rawClasses = template.Identity.Classes;
rawClasses = "_string" in rawClasses ? rawClasses._string : "";
if (template.Identity.Rank)
rawClasses += " " + template.Identity.Rank;
}

var classes = rawClasses && rawClasses.length ? rawClasses.split(/\s+/) : [];
classes = GetIdentityClasses(template.Identity);

var keyList = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ GuiInterface.prototype.GetEntityState = function(player, ent)
ret.identity = {
"rank": cmpIdentity.GetRank(),
"classes": cmpIdentity.GetClassesList(),
"visibleClasses": cmpIdentity.GetVisibleClassesList(),
"selectionGroupName": cmpIdentity.GetSelectionGroupName()
};
}
Expand Down Expand Up @@ -630,7 +631,7 @@ GuiInterface.prototype.GetTemplateData = function(player, extendedName)
ret.tooltip = template.Identity.Tooltip;
ret.gateConversionTooltip = template.Identity.GateConversionTooltip;
ret.requiredTechnology = template.Identity.RequiredTechnology;
ret.identityClassesString = GetTemplateIdentityClassesString(template);
ret.visibleIdentityClasses = GetVisibleIdentityClasses(template.Identity);
}

if (template.UnitMotion)
Expand Down
24 changes: 15 additions & 9 deletions binaries/data/mods/public/simulation/components/Identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ Identity.prototype.Schema =
"<text/>" +
"</element>" +
"</optional>" +
"<optional>" +
"<element name='VisibleClasses' a:help='Optional list of space-separated classes applying to this entity. These classes will also be visible in various GUI elements, if the classes need spaces. Underscores will be replaced with spaces.'>" +
"<attribute name='datatype'>" +
"<value>tokens</value>" +
"</attribute>" +
"<text/>" +
"</element>" +
"</optional>" +
"<optional>" +
"<element name='Formations' a:help='Optional list of space-separated formations this unit is allowed to use. Choices include: Scatter, Box, ColumnClosed, LineClosed, ColumnOpen, LineOpen, Flank, Skirmish, Wedge, Testudo, Phalanx, Syntagma, BattleLine'>" +
"<attribute name='datatype'>" +
Expand Down Expand Up @@ -99,11 +107,12 @@ Identity.prototype.GetRank = function()

Identity.prototype.GetClassesList = function()
{
if (this.template.Classes && "_string" in this.template.Classes)
return ( this.template.Classes._string + " " + this.GetRank() ).split(/\s+/);
if (this.GetRank().length)
return [this.GetRank()];
return [];
return GetIdentityClasses(this.template);
};

Identity.prototype.GetVisibleClassesList = function()
{
return GetVisibleIdentityClasses(this.template);
};

Identity.prototype.HasClass = function(name)
Expand All @@ -118,10 +127,7 @@ Identity.prototype.GetFormationsList = function()
var string = this.template.Formations._string;
return string.split(/\s+/);
}
else
{
return [];
}
return [];
};

Identity.prototype.CanUseFormation = function(template)
Expand Down
33 changes: 20 additions & 13 deletions binaries/data/mods/public/simulation/helpers/Templates.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
/**
* Return template.Identity.Classes._string if exists
* Gets an array of all classes for this identity template
*/
function GetTemplateIdentityClassesString(template)
function GetIdentityClasses(template)
{
var identityClassesString = undefined;
if (template.Identity && template.Identity.Classes && "_string" in template.Identity.Classes)
identityClassesString = template.Identity.Classes._string;
return identityClassesString;
var classList = [];
if (template.Classes && template.Classes._string)
classList = classList.concat(template.Classes._string.split(/\s+/));

if (template.VisibleClasses && template.VisibleClasses._string)
classList.concat(template.VisibleClasses._string.split(/\s+/));

if (template.Rank)
classList = classList.concat(template.Rank);
return classList;
}

/**
* Check whether template.Identity.Classes contains specified class
* Gets an array with all classes for this identity template
* that should be shown in the GUI
*/
function TemplateHasIdentityClass(template, className)
function GetVisibleIdentityClasses(template)
{
var identityClassesString = GetTemplateIdentityClassesString(template);
var hasClass = identityClassesString && identityClassesString.indexOf(className) != -1;
return hasClass;
if (template.VisibleClasses && template.VisibleClasses._string)
return template.VisibleClasses._string.split(/\s+/);
return [];
}

Engine.RegisterGlobal("GetTemplateIdentityClassesString", GetTemplateIdentityClassesString);
Engine.RegisterGlobal("TemplateHasIdentityClass", TemplateHasIdentityClass);
Engine.RegisterGlobal("GetIdentityClasses", GetIdentityClasses);
Engine.RegisterGlobal("GetVisibleIdentityClasses", GetVisibleIdentityClasses);

6 changes: 5 additions & 1 deletion source/tools/i18n/potter/extractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,11 @@ def extractFromFile(self, filepath):
comment = element.get("comment")
comment = u" ".join(comment.split()) # Remove tabs, line breaks and unecessary spaces.
comments.append(comment)
yield element.text, context, position, comments
if "splitOnWhitespace" in self.keywords[keyword]:
for splitText in element.text.split():
yield splitText, context, position, comments
else:
yield element.text, context, position, comments


# Hack from http://stackoverflow.com/a/2819788
Expand Down

0 comments on commit 9d74acc

Please sign in to comment.