Skip to content

Commit 9948621

Browse files
committed
add workermenu to be able to toggle unit builds
1 parent a5f1741 commit 9948621

File tree

10 files changed

+261
-169
lines changed

10 files changed

+261
-169
lines changed

src/dsstats.maui/dsstats.builder/dsstats.builder/BuildArea.cs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,15 @@ public List<InputEvent> GetBuildEvents(ScreenArea screenArea, CmdrBuild build)
5555

5656
foreach (var centerUnit in centerUnits)
5757
{
58-
var unitChar = build.GetUnitChar(centerUnit.UnitName);
59-
if (unitChar is null)
60-
{
61-
continue;
62-
}
63-
events.AddRange(DsBuilder.BuildUnit(unitChar.Value, centerUnit.Pos.X, centerUnit.Pos.Y));
58+
events.AddRange(build.GetBuildEvents(centerUnit.UnitName, centerUnit.Pos, screenArea));
6459
}
6560
if (topUnits.Count > 0)
6661
{
6762
events.AddRange(DsBuilder.ScrollY(Convert.ToInt32(250 * screenArea._scaleY), screenArea.GetCenter()));
6863
foreach (var topUnit in topUnits)
6964
{
70-
var unitChar = build.GetUnitChar(topUnit.UnitName);
71-
if (unitChar is null)
72-
{
73-
continue;
74-
}
75-
events.AddRange(DsBuilder.BuildUnit(unitChar.Value, topUnit.Pos.X, topUnit.Pos.Y + Convert.ToInt32(125 * screenArea._scaleY)));
65+
events.AddRange(build.GetBuildEvents(topUnit.UnitName,
66+
topUnit.Pos with { Y = topUnit.Pos.Y + Convert.ToInt32(125 * screenArea._scaleY) }, screenArea));
7667
}
7768
}
7869
if (bottomUnits.Count > 0)
@@ -83,12 +74,8 @@ public List<InputEvent> GetBuildEvents(ScreenArea screenArea, CmdrBuild build)
8374
events.AddRange(DsBuilder.ScrollY(Convert.ToInt32(-500 * screenArea._scaleY), screenArea.GetCenter()));
8475
foreach (var bottomUnit in bottomUnits)
8576
{
86-
var unitChar = build.GetUnitChar(bottomUnit.UnitName);
87-
if (unitChar is null)
88-
{
89-
continue;
90-
}
91-
events.AddRange(DsBuilder.BuildUnit(unitChar.Value, bottomUnit.Pos.X, bottomUnit.Pos.Y - Convert.ToInt32(300 * screenArea._scaleY)));
77+
events.AddRange(build.GetBuildEvents(bottomUnit.UnitName,
78+
bottomUnit.Pos with { Y = bottomUnit.Pos.Y - Convert.ToInt32(300 * screenArea._scaleY) }, screenArea));
9279
}
9380
}
9481

src/dsstats.maui/dsstats.builder/dsstats.builder/BuildPlayer.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ public static void ReplayInput(List<InputEvent> events)
8585
{
8686
User32Wrapper.SimulateRelativeMouseMove(e.X, e.Y);
8787
}
88+
else if (e.Type == InputType.MouseRightClick)
89+
{
90+
User32Wrapper.SetCursorPos(e.X, e.Y);
91+
User32Wrapper.mouse_event(User32Wrapper.MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, UIntPtr.Zero);
92+
User32Wrapper.mouse_event(User32Wrapper.MOUSEEVENTF_RIGHTUP, 0, 0, 0, UIntPtr.Zero);
93+
}
8894
}
8995
if (shiftCurrentlyDown)
9096
User32Wrapper.keybd_event(User32Wrapper.VK_SHIFT, 0, User32Wrapper.KEYEVENTF_KEYUP, UIntPtr.Zero);

src/dsstats.maui/dsstats.builder/dsstats.builder/Builds/CmdrBuild.cs

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,67 @@ namespace dsstats.builder;
44

55
public abstract class CmdrBuild
66
{
7-
protected Dictionary<string, char> UnitMap = [];
8-
protected Dictionary<string, char> UpgradeMap = [];
9-
protected Dictionary<string, char> AbilityMap = [];
7+
protected Dictionary<string, BuildOption> UnitMap = [];
8+
protected Dictionary<string, BuildOption> UpgradeMap = [];
9+
protected Dictionary<string, BuildOption> AbilityMap = [];
10+
protected WorkerMenu WorkerMenu = new();
11+
protected Dictionary<string, bool> activeUnits = [];
12+
13+
protected void CreateActiveUnits()
14+
{
15+
activeUnits = UnitMap.Where(x => x.Value.RequiresToggle).ToDictionary(k => k.Key, v => v.Value.IsActive);
16+
}
17+
18+
public virtual List<InputEvent> GetBuildEvents(string unitName, RlPoint pos, ScreenArea screenArea)
19+
{
20+
if (!UnitMap.TryGetValue(unitName, out var buildOption)
21+
|| buildOption is null)
22+
{
23+
return [];
24+
}
25+
List<InputEvent> events = [];
26+
if (buildOption.RequiresToggle)
27+
{
28+
if (activeUnits.TryGetValue(unitName, out var isActive))
29+
{
30+
if (!isActive)
31+
{
32+
var toggleEvent = WorkerMenu.ToggleBuildMenu(buildOption.Key, screenArea);
33+
if (toggleEvent != null)
34+
{
35+
events.Add(toggleEvent);
36+
var otherToggleUnit = UnitMap.FirstOrDefault(f => f.Value.Key == buildOption.Key && f.Key != unitName);
37+
if (!string.IsNullOrEmpty(otherToggleUnit.Key))
38+
{
39+
activeUnits[otherToggleUnit.Key] = false;
40+
}
41+
activeUnits[unitName] = true;
42+
}
43+
}
44+
}
45+
}
46+
events.AddRange(DsBuilder.BuildUnit(buildOption.Key, pos.X, pos.Y));
47+
return events;
48+
}
1049

1150
public virtual char? GetUnitChar(string unitName)
1251
{
13-
return UnitMap.TryGetValue(unitName, out var c)
14-
? c
52+
return UnitMap.TryGetValue(unitName, out var buildOption)
53+
? buildOption.Key
1554
: null;
1655
}
1756

1857
public virtual char? GetUpgradeChar(string upgradeName)
1958
{
20-
return UpgradeMap.TryGetValue(upgradeName, out var c)
21-
? c
59+
return UpgradeMap.TryGetValue(upgradeName, out var buildOption)
60+
? buildOption.Key
2261
: null;
2362
}
2463

2564
public virtual char? GetAbilityChar(string abilityName)
2665
{
27-
return AbilityMap.TryGetValue(abilityName, out var c)
28-
? c
66+
return AbilityMap.TryGetValue(abilityName, out var buildOption)
67+
? buildOption.Key
2968
: null;
3069
}
3170
}
@@ -42,4 +81,6 @@ public static class CmdrBuildFactory
4281
_ => null
4382
};
4483
}
45-
}
84+
}
85+
86+
public sealed record BuildOption(char Key, bool RequiresToggle = false, bool IsActive = false);

src/dsstats.maui/dsstats.builder/dsstats.builder/Builds/ProtossBuild.cs

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,65 +4,66 @@ public class ProtossBuild : CmdrBuild
44
{
55
public ProtossBuild()
66
{
7-
UnitMap = new Dictionary<string, char>
7+
UnitMap = new Dictionary<string, BuildOption>
88
{
99
// Q-menu units
10-
{ "Zealot", 'q' },
11-
{ "Stalker", 'w' },
12-
{ "Adept", 'e' },
13-
{ "Sentry", 'r' },
14-
{ "HighTemplar", 't' },
15-
{ "DarkTemplar", 'a' },
16-
{ "Immortal", 's' },
17-
{ "Colossus", 'd' },
18-
{ "Disruptor", 'f' },
19-
{ "Archon", 'g' },
20-
{ "Phoenix", 'z' },
21-
{ "VoidRay", 'x' },
22-
{ "Oracle", 'c' },
23-
{ "Tempest", 'v' },
24-
{ "Carrier", 'b' },
25-
{ "Mothership", 'n' },
10+
{ "Zealot", new('q') },
11+
{ "Stalker", new('w') },
12+
{ "Adept", new('e') },
13+
{ "Sentry", new('r') },
14+
{ "HighTemplar", new('t') },
15+
{ "DarkTemplar", new('a') },
16+
{ "Immortal", new('s') },
17+
{ "Colossus", new('d') },
18+
{ "Disruptor", new('f') },
19+
{ "Archon", new('g') },
20+
{ "Phoenix", new('z') },
21+
{ "VoidRay", new('x') },
22+
{ "Oracle", new('c') },
23+
{ "Tempest", new('v') },
24+
{ "Carrier", new('b') },
25+
{ "Mothership", new('n') },
2626
};
2727

28-
AbilityMap = new Dictionary<string, char>
28+
AbilityMap = new Dictionary<string, BuildOption>
2929
{
3030
// W-menu: abilities and tech
31-
{ "Charge", 'q' },
32-
{ "Blink", 'w' },
33-
{ "ResonatingGlaives", 'e' },
34-
{ "GuardianShield", 'r' },
35-
{ "PsionicStorm", 't' },
36-
{ "ShadowStride", 'a' },
37-
{ "Barrier", 's' },
38-
{ "ExtendedThermalLance", 'd' },
39-
{ "PurificationNova", 'f' },
40-
{ "GravitonBeam", 'g' },
41-
{ "FluxVanes", 'z' },
42-
{ "Revelation", 'x' },
43-
{ "TectonicDestabilizers", 'c' },
44-
{ "InterceptorLaunchSpeed", 'v' },
45-
{ "MassRecall", 'b' },
31+
{ "Charge", new('q') },
32+
{ "Blink", new('w') },
33+
{ "ResonatingGlaives", new('e') },
34+
{ "GuardianShield", new('r') },
35+
{ "PsionicStorm", new('t') },
36+
{ "ShadowStride", new('a') },
37+
{ "Barrier", new('s') },
38+
{ "ExtendedThermalLance", new('d') },
39+
{ "PurificationNova", new('f') },
40+
{ "GravitonBeam", new('g') },
41+
{ "FluxVanes", new('z') },
42+
{ "Revelation", new('x') },
43+
{ "TectonicDestabilizers", new('c') },
44+
{ "InterceptorLaunchSpeed", new('v') },
45+
{ "MassRecall", new('b') },
4646
};
4747

48-
UpgradeMap = new Dictionary<string, char>
48+
UpgradeMap = new Dictionary<string, BuildOption>
4949
{
5050
// Forge + Cyber Core + Fleet Beacon
51-
{ "GroundWeaponsLevel1", 'a' },
52-
{ "GroundWeaponsLevel2", 'a' },
53-
{ "GroundWeaponsLevel3", 'a' },
54-
{ "GroundArmorLevel1", 's' },
55-
{ "GroundArmorLevel2", 's' },
56-
{ "GroundArmorLevel3", 's' },
57-
{ "ShieldsLevel1", 'd' },
58-
{ "ShieldsLevel2", 'd' },
59-
{ "ShieldsLevel3", 'd' },
60-
{ "AirWeaponsLevel1", 'f' },
61-
{ "AirWeaponsLevel2", 'f' },
62-
{ "AirWeaponsLevel3", 'f' },
63-
{ "AirArmorLevel1", 'g' },
64-
{ "AirArmorLevel2", 'g' },
65-
{ "AirArmorLevel3", 'g' },
51+
{ "GroundWeaponsLevel1", new('a') },
52+
{ "GroundWeaponsLevel2", new('a') },
53+
{ "GroundWeaponsLevel3", new('a') },
54+
{ "GroundArmorLevel1", new('s') },
55+
{ "GroundArmorLevel2", new('s') },
56+
{ "GroundArmorLevel3", new('s') },
57+
{ "ShieldsLevel1", new('d') },
58+
{ "ShieldsLevel2", new('d') },
59+
{ "ShieldsLevel3", new('d') },
60+
{ "AirWeaponsLevel1", new('f') },
61+
{ "AirWeaponsLevel2", new('f') },
62+
{ "AirWeaponsLevel3", new('f') },
63+
{ "AirArmorLevel1", new('g') },
64+
{ "AirArmorLevel2", new('g') },
65+
{ "AirArmorLevel3", new('g') },
6666
};
67+
CreateActiveUnits();
6768
}
6869
}

src/dsstats.maui/dsstats.builder/dsstats.builder/Builds/TerranBuild.cs

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,62 +4,63 @@ public class TerranBuild : CmdrBuild
44
{
55
public TerranBuild()
66
{
7-
UnitMap = new Dictionary<string, char>
7+
UnitMap = new Dictionary<string, BuildOption>
88
{
99
// Q-menu
10-
{ "Marine", 'q' },
11-
{ "Marauder", 'w' },
12-
{ "Reaper", 'e' },
13-
{ "Ghost", 'r' },
14-
{ "Hellion", 't' },
15-
{ "Hellbat", 'a' },
16-
{ "SiegeTank", 's' },
17-
{ "WidowMine", 'd' },
18-
{ "Cyclone", 'f' },
19-
{ "Thor", 'g' },
20-
{ "Viking", 'z' },
21-
{ "Medivac", 'x' },
22-
{ "Banshee", 'c' },
23-
{ "Raven", 'v' },
24-
{ "Battlecruiser", 'b' },
10+
{ "Marine", new('q') },
11+
{ "Marauder", new('w') },
12+
{ "Reaper", new('e') },
13+
{ "Ghost", new('r') },
14+
{ "Hellion", new('t') },
15+
{ "Hellbat", new('a') },
16+
{ "SiegeTank", new('s') },
17+
{ "WidowMine", new('d') },
18+
{ "Cyclone", new('f') },
19+
{ "Thor", new('g') },
20+
{ "Viking", new('z') },
21+
{ "Medivac", new('x') },
22+
{ "Banshee", new('c') },
23+
{ "Raven", new('v') },
24+
{ "Battlecruiser", new('b') },
2525
};
2626

27-
AbilityMap = new Dictionary<string, char>
27+
AbilityMap = new Dictionary<string, BuildOption>
2828
{
2929
// W-menu (upgrades & abilities)
30-
{ "Stimpack", 'q' },
31-
{ "ConcussiveShells", 'w' },
32-
{ "CloakingField", 'e' },
33-
{ "DrillingClaws", 'r' },
34-
{ "InfernalPreigniter", 't' }, // Hellion upgrade
35-
{ "SmartServos", 'a' }, // Viking/Thor transform speed
36-
{ "HighImpactPayload", 's' }, // Thor mode toggle
37-
{ "HyperflightRotors", 'd' }, // Banshee speed
38-
{ "AdvancedBallistics", 'f' }, // Raven range
39-
{ "WeaponRefit", 'g' }, // Battlecruiser Yamato
30+
{ "Stimpack", new('q') },
31+
{ "ConcussiveShells", new('w') },
32+
{ "CloakingField", new('e') },
33+
{ "DrillingClaws", new('r') },
34+
{ "InfernalPreigniter", new('t') }, // Hellion upgrade
35+
{ "SmartServos", new('a') }, // Viking/Thor transform speed
36+
{ "HighImpactPayload", new('s') }, // Thor mode toggle
37+
{ "HyperflightRotors", new('d') }, // Banshee speed
38+
{ "AdvancedBallistics", new('f') }, // Raven range
39+
{ "WeaponRefit", new('g') }, // Battlecruiser Yamato
4040
};
4141

42-
UpgradeMap = new Dictionary<string, char>
42+
UpgradeMap = new Dictionary<string, BuildOption>
4343
{
4444
// Main armory upgrades
45-
{ "InfantryWeaponsLevel1", 'a' },
46-
{ "InfantryWeaponsLevel2", 'a' },
47-
{ "InfantryWeaponsLevel3", 'a' },
48-
{ "InfantryArmorLevel1", 's' },
49-
{ "InfantryArmorLevel2", 's' },
50-
{ "InfantryArmorLevel3", 's' },
51-
{ "VehicleWeaponsLevel1", 'd' },
52-
{ "VehicleWeaponsLevel2", 'd' },
53-
{ "VehicleWeaponsLevel3", 'd' },
54-
{ "ShipWeaponsLevel1", 'f' },
55-
{ "ShipWeaponsLevel2", 'f' },
56-
{ "ShipWeaponsLevel3", 'f' },
57-
{ "VehiclePlatingLevel1", 'g' },
58-
{ "VehiclePlatingLevel2", 'g' },
59-
{ "VehiclePlatingLevel3", 'g' },
60-
{ "ShipPlatingLevel1", 'h' },
61-
{ "ShipPlatingLevel2", 'h' },
62-
{ "ShipPlatingLevel3", 'h' },
45+
{ "InfantryWeaponsLevel1", new('a') },
46+
{ "InfantryWeaponsLevel2", new('a') },
47+
{ "InfantryWeaponsLevel3", new('a') },
48+
{ "InfantryArmorLevel1", new('s') },
49+
{ "InfantryArmorLevel2", new('s') },
50+
{ "InfantryArmorLevel3", new('s') },
51+
{ "VehicleWeaponsLevel1", new('d') },
52+
{ "VehicleWeaponsLevel2", new('d') },
53+
{ "VehicleWeaponsLevel3", new('d') },
54+
{ "ShipWeaponsLevel1", new('f') },
55+
{ "ShipWeaponsLevel2", new('f') },
56+
{ "ShipWeaponsLevel3", new('f') },
57+
{ "VehiclePlatingLevel1", new('g') },
58+
{ "VehiclePlatingLevel2", new('g') },
59+
{ "VehiclePlatingLevel3", new('g') },
60+
{ "ShipPlatingLevel1", new('h') },
61+
{ "ShipPlatingLevel2", new('h') },
62+
{ "ShipPlatingLevel3", new('h') },
6363
};
64+
CreateActiveUnits();
6465
}
6566
}

0 commit comments

Comments
 (0)