Skip to content

Commit

Permalink
Translation on the IngameClassSelector, other SS.dll style fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
MustaphaTR committed Dec 27, 2024
1 parent 81602aa commit bd434cc
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 51 deletions.
4 changes: 2 additions & 2 deletions OpenRA.Mods.SS/Traits/Conditions/GrantConditionAfterDelay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ void ITick.Tick(Actor self)

float ISelectionBar.GetValue()
{
if (IsTraitDisabled || !Info.ShowSelectionBar || ((1f - (float)Ticks / Info.Delay) > 1f && !info.ShowFullBarAfterGranted))
if (IsTraitDisabled || !Info.ShowSelectionBar || (1f - (float)Ticks / Info.Delay > 1f && !info.ShowFullBarAfterGranted))
return 0f;

if ((1f - (float)Ticks / Info.Delay) > 1f && info.ShowFullBarAfterGranted)
if (1f - (float)Ticks / Info.Delay > 1f && info.ShowFullBarAfterGranted)
return 1f;

return 1f - (float)Ticks / Info.Delay;
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.SS/Traits/Crates/ArmageddonCrateAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
namespace OpenRA.Mods.SS.Traits
{
[Desc("Kills all player owned units on the map.")]
class ArmageddonCrateActionInfo : CrateActionInfo
sealed class ArmageddonCrateActionInfo : CrateActionInfo
{
[Desc("The deathtypes used to kill the units.")]
public readonly BitSet<DamageType> DeathTypes = default;

public override object Create(ActorInitializer init) { return new ArmageddonCrateAction(init.Self, this); }
}

class ArmageddonCrateAction : CrateAction
sealed class ArmageddonCrateAction : CrateAction
{
readonly Actor self;
readonly ArmageddonCrateActionInfo info;
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.SS/Traits/Crates/HideMapToAllCrateAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
namespace OpenRA.Mods.Common.Traits
{
[Desc("Hides the entire map in shroud for all players.")]
class HideMapToAllCrateActionInfo : CrateActionInfo
sealed class HideMapToAllCrateActionInfo : CrateActionInfo
{
public override object Create(ActorInitializer init) { return new HideMapToAllCrateAction(init.Self, this); }
}

class HideMapToAllCrateAction : CrateAction
sealed class HideMapToAllCrateAction : CrateAction
{
public HideMapToAllCrateAction(Actor self, HideMapToAllCrateActionInfo info)
: base(self, info) { }
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.SS/Traits/Crates/PlayerExperienceCrateAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
namespace OpenRA.Mods.Common.Traits
{
[Desc("Gives collector's owner experience.")]
class PlayerExperienceCrateActionInfo : CrateActionInfo
sealed class PlayerExperienceCrateActionInfo : CrateActionInfo
{
[Desc("How much player experience this crate action gives.")]
public int Experience = 0;

public override object Create(ActorInitializer init) { return new PlayerExperienceCrateAction(init.Self, this); }
}

class PlayerExperienceCrateAction : CrateAction
sealed class PlayerExperienceCrateAction : CrateAction
{
readonly PlayerExperienceCrateActionInfo info;

Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.SS/Traits/Crates/SSHealCrateAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace OpenRA.Mods.Common.Traits
{
[Desc("Heals the collector if it is damaged, fires a weapon otherwise.")]
class SSHealCrateActionInfo : CrateActionInfo
sealed class SSHealCrateActionInfo : CrateActionInfo
{
[WeaponReference]
[FieldLoader.Require]
Expand All @@ -32,7 +32,7 @@ class SSHealCrateActionInfo : CrateActionInfo
public override object Create(ActorInitializer init) { return new SSHealCrateAction(init.Self, this); }
}

class SSHealCrateAction : CrateAction
sealed class SSHealCrateAction : CrateAction
{
readonly Actor self;
readonly SSHealCrateActionInfo info;
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.SS/Traits/Crates/SwitchConditionCrateAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
namespace OpenRA.Mods.SS.Traits
{
[Desc("Grants a condition on the collector if it is not, revokes it if it is.")]
class SwitchConditionCrateActionInfo : CrateActionInfo
sealed class SwitchConditionCrateActionInfo : CrateActionInfo
{
[FieldLoader.Require]
[Desc("The condition to grant or revoke. Must be included in the target actor's ExternalConditions list.")]
Expand All @@ -42,7 +42,7 @@ class SwitchConditionCrateActionInfo : CrateActionInfo
public override object Create(ActorInitializer init) { return new SwitchConditionCrateAction(init.Self, this); }
}

class SwitchConditionCrateAction : CrateAction
sealed class SwitchConditionCrateAction : CrateAction
{
readonly Actor self;
readonly SwitchConditionCrateActionInfo info;
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.SS/Traits/Crates/TeleportCrateAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
namespace OpenRA.Mods.SS.Traits
{
[Desc("Teleports the unit to a random location.")]
class TeleportCrateActionInfo : CrateActionInfo
sealed class TeleportCrateActionInfo : CrateActionInfo
{
[Desc("The maxiumum distance unit can be teleported to.")]
public readonly int MaxDistance = 50;
Expand All @@ -39,7 +39,7 @@ class TeleportCrateActionInfo : CrateActionInfo
public override object Create(ActorInitializer init) { return new TeleportCrateAction(init.Self, this); }
}

class TeleportCrateAction : CrateAction, IRender
sealed class TeleportCrateAction : CrateAction, IRender
{
readonly Actor self;
readonly TeleportCrateActionInfo info;
Expand Down
10 changes: 5 additions & 5 deletions OpenRA.Mods.SS/Traits/World/SpawnSSUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,17 +242,17 @@ void SpawnUnitForPlayer(World w, Player p, CPos sp)

void SpawnBuildingsForPlayer(World w, Player p, CPos sp)
{
foreach (var b in bases)
foreach (var (actors, amount, inner, outer) in bases)
{
var buildings = b.Actors;
var buildingSpawnCells = w.Map.FindTilesInAnnulus(sp, b.Inner + 1, b.Outer).ToArray();
for (var i = 0; i < b.Amount - (b.Amount % buildings.Length); i++)
var buildings = actors;
var buildingSpawnCells = w.Map.FindTilesInAnnulus(sp, inner + 1, outer).ToArray();
for (var i = 0; i < amount - amount % buildings.Length; i++)
{
var actor = buildings[i % buildings.Length];
SpawnBuildingForPlayer(w, p, buildingSpawnCells, actor);
}

for (var i = 0; i < b.Amount % buildings.Length; i++)
for (var i = 0; i < amount % buildings.Length; i++)
{
var actor = buildings.Random(w.SharedRandom);
SpawnBuildingForPlayer(w, p, buildingSpawnCells, actor);
Expand Down
29 changes: 9 additions & 20 deletions OpenRA.Mods.SS/Widgets/Logic/Ingame/IngameClassSelectorLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.SS.Traits;
Expand All @@ -18,19 +17,8 @@

namespace OpenRA.Mods.Common.Widgets.Logic
{
class IngameClassSelectorLogic : ChromeLogic
sealed class IngameClassSelectorLogic : ChromeLogic
{
public static (string First, string Second) SplitOnFirstToken(string input, string token = "\\n")
{
if (string.IsNullOrEmpty(input))
return (null, null);

var split = input.IndexOf(token, StringComparison.Ordinal);
var first = split > 0 ? input[..split] : input;
var second = split > 0 ? input[(split + token.Length)..] : null;
return (first, second);
}

public void ShowFactionDropDown(World world, SpawnSSUnit spawner, DropDownButtonWidget dropdown, Dictionary<string, LobbyFaction> factions)
{
var player = world.LocalPlayer;
Expand All @@ -54,14 +42,15 @@ ScrollItemWidget SetupItem(string factionId, ScrollItemWidget itemTemplate)
}
});
var faction = factions[factionId];
item.Get<LabelWidget>("LABEL").GetText = () => faction.Name;
item.Get<LabelWidget>("LABEL").GetText = () => FluentProvider.GetMessage(faction.Name);
var flag = item.Get<ImageWidget>("FLAG");
flag.GetImageCollection = () => "flags";
flag.GetImageName = () => factionId;

var tooltip = SplitOnFirstToken(faction.Description);
item.GetTooltipText = () => tooltip.First;
item.GetTooltipDesc = () => tooltip.Second;
var description = faction.Description != null ? FluentProvider.GetMessage(faction.Description) : null;
var (text, desc) = LobbyUtils.SplitOnFirstToken(description);
item.GetTooltipText = () => text;
item.GetTooltipDesc = () => desc;

return item;
}
Expand Down Expand Up @@ -103,11 +92,11 @@ public IngameClassSelectorLogic(Widget widget, World world)
classDropdown.IsDisabled = () => !spawner.ClassChanging || spawner.ClassChangingPaused;
classDropdown.OnMouseDown = _ => ShowFactionDropDown(world, spawner, classDropdown, factions);

classDropdown.GetTooltipText = () => SplitOnFirstToken(factions[spawner.Classes[player]].Description).First;
classDropdown.GetTooltipDesc = () => SplitOnFirstToken(factions[spawner.Classes[player]].Description).Second;
classDropdown.GetTooltipText = () => LobbyUtils.SplitOnFirstToken(FluentProvider.GetMessage(factions[spawner.Classes[player]].Description)).First;
classDropdown.GetTooltipDesc = () => LobbyUtils.SplitOnFirstToken(FluentProvider.GetMessage(factions[spawner.Classes[player]].Description)).Second;

var factionName = classDropdown.Get<LabelWidget>("FACTIONNAME");
factionName.GetText = () => factions[spawner.Classes[player]].Name;
factionName.GetText = () => FluentProvider.GetMessage(factions[spawner.Classes[player]].Name);
var factionFlag = classDropdown.Get<ImageWidget>("FACTIONFLAG");
factionFlag.GetImageName = () => spawner.Classes[player];
factionFlag.GetImageCollection = () => "flags";
Expand Down
24 changes: 12 additions & 12 deletions OpenRA.Mods.SS/Widgets/Logic/Ingame/IngameUnitStatsLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public IngameUnitStatsLogic(Widget widget, World world)
foreach (var dm in unit.TraitsImplementing<IDamageModifier>().Select(dm => dm.GetDamageModifier(unit, new Damage(usv.Health))).Where(d => d != 0))
healthValue = healthValue / dm * 100;

return (int)(((float)(healthValue - usv.Health) / (float)usv.Health) * 100 * max);
return (int)((float)(healthValue - usv.Health) / usv.Health * 100 * max);
}
else if (usv.Health < 0)
{
Expand All @@ -120,7 +120,7 @@ public IngameUnitStatsLogic(Widget widget, World world)
foreach (var dm in unit.TraitsImplementing<IDamageModifier>().Select(dm => dm.GetDamageModifier(unit, new Damage(healthTrait.MaxHP))).Where(d => d != 0))
healthValue = healthValue / dm * 100;

return (int)(((float)(healthValue - healthTrait.MaxHP) / (float)healthTrait.MaxHP) * 100 * max);
return (int)((float)(healthValue - healthTrait.MaxHP) / healthTrait.MaxHP * 100 * max);
}
}

Expand Down Expand Up @@ -178,7 +178,7 @@ public IngameUnitStatsLogic(Widget widget, World world)
foreach (var rsm in unit.TraitsImplementing<IRevealsShroudModifier>().Select(rsm => rsm.GetRevealsShroudModifier()))
revealsShroudValue = revealsShroudValue * rsm / 100;

return (int)(((float)(revealsShroudValue.Length - usv.Sight.Length) / (float)usv.Sight.Length) * 100 * max);
return (int)((float)(revealsShroudValue.Length - usv.Sight.Length) / usv.Sight.Length * 100 * max);
}
else if (usv.Sight < WDist.Zero)
{
Expand All @@ -193,7 +193,7 @@ public IngameUnitStatsLogic(Widget widget, World world)
foreach (var rsm in unit.TraitsImplementing<IRevealsShroudModifier>().Select(rsm => rsm.GetRevealsShroudModifier()))
revealsShroudValue = revealsShroudValue * rsm / 100;

return (int)(((float)(revealsShroudValue.Length - revealsShroudTrait.Info.Range.Length) / (float)revealsShroudTrait.Info.Range.Length) * 100 * max);
return (int)((float)(revealsShroudValue.Length - revealsShroudTrait.Info.Range.Length) / revealsShroudTrait.Info.Range.Length * 100 * max);
}
}

Expand Down Expand Up @@ -238,7 +238,7 @@ public IngameUnitStatsLogic(Widget widget, World world)
foreach (var dm in unit.TraitsImplementing<IFirepowerModifier>().Select(fm => fm.GetFirepowerModifier()))
damageValue = damageValue * dm / 100;

return (int)(((float)(damageValue - usv.Damage) / (float)usv.Damage) * 100 * max);
return (int)((float)(damageValue - usv.Damage) / usv.Damage * 100 * max);
}
}

Expand Down Expand Up @@ -296,7 +296,7 @@ public IngameUnitStatsLogic(Widget widget, World world)
foreach (var rm in unit.TraitsImplementing<IReloadModifier>().Select(sm => sm.GetReloadModifier()))
rofValue = rofValue * rm / 100;

return (int)(((float)(usv.ReloadDelay - rofValue) / (float)usv.ReloadDelay) * 100 * (max + 1));
return (int)((float)(usv.ReloadDelay - rofValue) / usv.ReloadDelay * 100 * (max + 1));
}
else if (usv.ReloadDelay < 0)
{
Expand All @@ -311,7 +311,7 @@ public IngameUnitStatsLogic(Widget widget, World world)
foreach (var rm in unit.TraitsImplementing<IReloadModifier>().Select(sm => sm.GetReloadModifier()))
rofValue = rofValue * rm / 100;

return (int)(((float)(armamanets.Max(ar => ar.Weapon.ReloadDelay - rofValue)) / (float)armamanets.Max(ar => ar.Weapon.ReloadDelay)) * 100 * (max + 1));
return (int)((float)armamanets.Max(ar => ar.Weapon.ReloadDelay - rofValue) / armamanets.Max(ar => ar.Weapon.ReloadDelay) * 100 * (max + 1));
}
}

Expand Down Expand Up @@ -366,7 +366,7 @@ public IngameUnitStatsLogic(Widget widget, World world)
foreach (var rm in unit.TraitsImplementing<IRangeModifier>().Select(rm => rm.GetRangeModifier()))
rangeValue = rangeValue * rm / 100;

return (int)(((float)(rangeValue.Length - usv.Range.Length) / (float)usv.Range.Length) * 100 * max);
return (int)((float)(rangeValue.Length - usv.Range.Length) / usv.Range.Length * 100 * max);
}
else if (usv.Range < WDist.Zero)
{
Expand All @@ -381,7 +381,7 @@ public IngameUnitStatsLogic(Widget widget, World world)
foreach (var rm in unit.TraitsImplementing<IRangeModifier>().Select(rm => rm.GetRangeModifier()))
rangeValue = rangeValue * rm / 100;

return (int)(((float)(rangeValue.Length - armamanets.Max(ar => ar.Weapon.Range.Length)) / (float)armamanets.Max(ar => ar.Weapon.Range.Length)) * 100 * max);
return (int)((float)(rangeValue.Length - armamanets.Max(ar => ar.Weapon.Range.Length)) / armamanets.Max(ar => ar.Weapon.Range.Length) * 100 * max);
}
}

Expand Down Expand Up @@ -449,7 +449,7 @@ public IngameUnitStatsLogic(Widget widget, World world)
foreach (var sm in unit.TraitsImplementing<ISpeedModifier>().Select(sm => sm.GetSpeedModifier()))
speedValue = speedValue * sm / 100;

return (int)(((float)(speedValue - usv.Speed) / (float)usv.Speed) * 100 * max);
return (int)((float)(speedValue - usv.Speed) / usv.Speed * 100 * max);
}
else if (usv.Speed < 0)
{
Expand All @@ -464,7 +464,7 @@ public IngameUnitStatsLogic(Widget widget, World world)
foreach (var sm in unit.TraitsImplementing<ISpeedModifier>().Select(sm => sm.GetSpeedModifier()))
speedValue = speedValue * sm / 100;

return (int)(((float)(speedValue - mobile.Speed) / (float)mobile.Speed) * 100 * max);
return (int)((float)(speedValue - mobile.Speed) / mobile.Speed * 100 * max);
}

var aircraft = unit.Info.TraitInfoOrDefault<AircraftInfo>();
Expand All @@ -474,7 +474,7 @@ public IngameUnitStatsLogic(Widget widget, World world)
foreach (var sm in unit.TraitsImplementing<ISpeedModifier>().Select(sm => sm.GetSpeedModifier()))
speedValue = speedValue * sm / 100;

return (int)(((float)(speedValue - aircraft.Speed) / (float)aircraft.Speed) * 100 * max);
return (int)((float)(speedValue - aircraft.Speed) / aircraft.Speed * 100 * max);
}
}

Expand Down

0 comments on commit bd434cc

Please sign in to comment.