Skip to content

Commit d389d63

Browse files
committed
Feat(#93): Added field for custom map name and fixed result calc
1 parent 5019425 commit d389d63

File tree

5 files changed

+72
-31
lines changed

5 files changed

+72
-31
lines changed

VexTrack/Core/HistoryDataCalc.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ namespace VexTrack.Core
55
{
66
public static class HistoryDataCalc
77
{
8-
public static string CalcHistoryResultFromScores(string scoreType, int score, int enemyScore, bool surrenderedWin, bool surrenderedLoss)
8+
public static string CalcHistoryResultFromScores(string scoreType, string description, int score, int enemyScore, bool surrenderedWin, bool surrenderedLoss)
99
{
1010
if (scoreType == "Score")
1111
{
1212
if (surrenderedWin) return "Surrendered Win";
1313
if (surrenderedLoss) return "Surrendered Loss";
1414
}
1515

16-
if (scoreType == "Placement" || scoreType == "None") enemyScore = -1;
17-
if (scoreType == "None") score = -1;
16+
if (scoreType == "Placement") enemyScore = -1;
17+
if (scoreType == "None") (_, _, score, enemyScore) = DescriptionToScores(description);
1818

1919
if (enemyScore == -1)
2020
{
@@ -136,7 +136,7 @@ public HistoryEntryData(string sUUID, string hUUID, string gameMode, long time,
136136
SurrenderedLoss = surrenderedLoss;
137137

138138
if (Constants.ScoreTypes[GameMode] == "None") Title = Description;
139-
else if (Constants.ScoreTypes[GameMode] == "Placement") Title = GameMode + " " + HistoryDataCalc.CalcHistoryResultFromScores("Placement", Score, EnemyScore, SurrenderedWin, SurrenderedLoss);
139+
else if (Constants.ScoreTypes[GameMode] == "Placement") Title = GameMode + " " + HistoryDataCalc.CalcHistoryResultFromScores("Placement", Description, Score, EnemyScore, SurrenderedWin, SurrenderedLoss);
140140
else Title = GameMode + " " + Score.ToString() + "-" + EnemyScore.ToString();
141141
}
142142
}

VexTrack/Core/TrackingData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ public static void EditHistoryEntry(string sUUID, string hUUID, HistoryEntry dat
673673
.History.FindIndex(he => he.UUID == hUUID)] = data;
674674

675675
HistoryViewModel HistoryVM = (HistoryViewModel)ViewModelManager.ViewModels["History"];
676-
HistoryVM.EditEntry(new HistoryEntryData(sUUID, hUUID, data.GameMode, data.Time, data.Amount, data.Map, HistoryDataCalc.CalcHistoryResultFromScores(Constants.ScoreTypes[data.GameMode], data.Score, data.EnemyScore, data.SurrenderedWin, data.SurrenderedLoss), data.Description, data.Score, data.EnemyScore, data.SurrenderedWin, data.SurrenderedLoss));
676+
HistoryVM.EditEntry(new HistoryEntryData(sUUID, hUUID, data.GameMode, data.Time, data.Amount, data.Map, HistoryDataCalc.CalcHistoryResultFromScores(Constants.ScoreTypes[data.GameMode], data.Description, data.Score, data.EnemyScore, data.SurrenderedWin, data.SurrenderedLoss), data.Description, data.Score, data.EnemyScore, data.SurrenderedWin, data.SurrenderedLoss));
677677

678678
Recalculate();
679679
CallUpdate();

VexTrack/MVVM/View/Popups/EditableHistoryEntryPopup.xaml

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<conv:TimestampToStringConverter x:Key="TimestampConv"/>
1616
<conv:StringToVisibilityConverter x:Key="StringToVisibleConv"/>
1717
<conv:InvertedStringToVisibilityConverter x:Key="InvStringToVisibleConv"/>
18+
<BooleanToVisibilityConverter x:Key="BoolToVisibleConv"/>
1819
</UserControl.Resources>
1920

2021
<Grid Height="Auto"
@@ -53,6 +54,7 @@
5354
<RowDefinition Height="Auto"/>
5455
<RowDefinition Height="30"/>
5556
<RowDefinition Height="30"/>
57+
<RowDefinition Height="30"/>
5658
</Grid.RowDefinitions>
5759

5860
<TextBlock Text="Game mode"
@@ -105,26 +107,35 @@
105107
Margin="0, 0, 0, 8"/>
106108

107109
<TextBlock Text="Map"
108-
Grid.Row="3"
109-
Grid.Column="0"
110-
FontSize="14"
111-
FontWeight="Bold"
112-
VerticalAlignment="Center"
113-
Foreground="{Binding Result, Converter={StaticResource ResultToKeyConv}, ConverterParameter=Foreground}"
114-
Margin="0, 0, 0, 8"/>
110+
Grid.Row="3"
111+
Grid.Column="0"
112+
FontSize="14"
113+
FontWeight="Bold"
114+
VerticalAlignment="Center"
115+
Foreground="{Binding Result, Converter={StaticResource ResultToKeyConv}, ConverterParameter=Foreground}"
116+
Margin="0, 0, 0, 8"/>
117+
118+
<TextBlock Text="Custom Map Name"
119+
Grid.Row="4"
120+
Grid.Column="0"
121+
FontSize="14"
122+
FontWeight="Bold"
123+
VerticalAlignment="Center"
124+
Foreground="{Binding Result, Converter={StaticResource ResultToKeyConv}, ConverterParameter=Foreground}"
125+
Visibility="{Binding IsMapCustom, Converter={StaticResource BoolToVisibleConv}, ConverterParameter=None}"
126+
Margin="0, 0, 0, 8"/>
115127

116128
<TextBlock Text="Result"
117-
Grid.Row="4"
129+
Grid.Row="5"
118130
Grid.Column="0"
119131
FontSize="14"
120132
FontWeight="Bold"
121133
VerticalAlignment="Center"
122134
Foreground="{Binding Result, Converter={StaticResource ResultToKeyConv}, ConverterParameter=Foreground}"
123-
Visibility="{Binding ScoreType, Converter={StaticResource StringToVisibleConv}, ConverterParameter=Score}"
124135
Margin="0, 0, 0, 8"/>
125136

126137
<TextBlock Text="Time"
127-
Grid.Row="5"
138+
Grid.Row="6"
128139
Grid.Column="0"
129140
FontSize="14"
130141
FontWeight="Bold"
@@ -133,7 +144,7 @@
133144
Margin="0, 0, 0, 8"/>
134145

135146
<TextBlock Text="Gained XP"
136-
Grid.Row="6"
147+
Grid.Row="7"
137148
Grid.Column="0"
138149
FontSize="14"
139150
FontWeight="Bold"
@@ -259,24 +270,32 @@
259270
</Grid>
260271

261272
<ComboBox Grid.Row="3"
262-
Grid.Column="1"
263-
Margin="0, 0, 0, 8"
264-
FontSize="14"
265-
ItemsSource="{Binding Maps}"
266-
SelectedIndex="0"
267-
SelectedItem="{Binding Map, UpdateSourceTrigger=PropertyChanged}"/>
273+
Grid.Column="1"
274+
Margin="0, 0, 0, 8"
275+
FontSize="14"
276+
ItemsSource="{Binding Maps}"
277+
SelectedIndex="0"
278+
SelectedItem="{Binding Map, UpdateSourceTrigger=PropertyChanged}"/>
279+
280+
<TextBox Text="{Binding CustomMapName, UpdateSourceTrigger=PropertyChanged}"
281+
Grid.Row="4"
282+
Grid.Column="1"
283+
FontSize="14"
284+
Margin="0, 0, 0, 8"
285+
Height="22"
286+
Visibility="{Binding IsMapCustom, Converter={StaticResource BoolToVisibleConv}, ConverterParameter=None}"
287+
Style="{DynamicResource TextBoxTheme}"/>
268288

269289
<TextBlock Text="{Binding Result, UpdateSourceTrigger=PropertyChanged}"
270-
Grid.Row="4"
290+
Grid.Row="5"
271291
Grid.Column="1"
272292
FontSize="14"
273293
Foreground="{Binding Result, Converter={StaticResource ResultToKeyConv}, ConverterParameter=Foreground}"
274-
Visibility="{Binding ScoreType, Converter={StaticResource StringToVisibleConv}, ConverterParameter=Score}"
275294
Margin="0, 0, 0, 8"
276295
Height="22"/>
277296

278297
<TextBox x:Name="PART_DateTimeBox"
279-
Grid.Row="5"
298+
Grid.Row="6"
280299
Grid.Column="1"
281300
FontSize="14"
282301
Margin="0, 0, 0, 8"
@@ -297,7 +316,7 @@
297316
</TextBox>
298317

299318
<TextBox x:Name="PART_AmountBox"
300-
Grid.Row="6"
319+
Grid.Row="7"
301320
Grid.Column="1"
302321
FontSize="14"
303322
Margin="0, 0, 0, 8"

VexTrack/MVVM/ViewModel/HistoryViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ from e in g.Entries
7474
where e.HUUID == he.UUID
7575
select e).Any())
7676
{
77-
string result = HistoryDataCalc.CalcHistoryResultFromScores(Constants.ScoreTypes[he.GameMode], he.Score, he.EnemyScore, he.SurrenderedWin, he.SurrenderedLoss);
77+
string result = HistoryDataCalc.CalcHistoryResultFromScores(Constants.ScoreTypes[he.GameMode], he.Description, he.Score, he.EnemyScore, he.SurrenderedWin, he.SurrenderedLoss);
7878
HistoryEntryData hed = new HistoryEntryData(TrackingDataHelper.CurrentSeasonUUID, he.UUID, he.GameMode, he.Time, he.Amount, he.Map, result, he.Description, he.Score, he.EnemyScore, he.SurrenderedWin, he.SurrenderedLoss);
7979

8080
InsertEntry(hed);

VexTrack/MVVM/ViewModel/Popups/EditableHistoryEntryPopupViewModel.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class EditableHistoryEntryPopupViewModel : BasePopupViewModel
2424
private long _time;
2525
private int _amount;
2626
private string _map;
27+
private string _customMapName;
2728
private bool _surrenderedWin;
2829
private bool _surrenderedLoss;
2930

@@ -34,6 +35,7 @@ public string Description
3435
{
3536
_description = value;
3637
OnPropertyChanged();
38+
OnPropertyChanged(nameof(Result));
3739
}
3840
}
3941
public string GameMode
@@ -50,6 +52,7 @@ public string GameMode
5052
OnPropertyChanged(nameof(EnemyScore));
5153
OnPropertyChanged(nameof(Description));
5254
OnPropertyChanged(nameof(ScoreType));
55+
OnPropertyChanged(nameof(Result));
5356
}
5457
}
5558
public int Score
@@ -97,8 +100,19 @@ public string Map
97100
{
98101
_map = value;
99102
OnPropertyChanged();
103+
OnPropertyChanged(nameof(IsMapCustom));
104+
}
105+
}
106+
public string CustomMapName
107+
{
108+
get => _customMapName;
109+
set
110+
{
111+
_customMapName = value;
112+
OnPropertyChanged();
100113
}
101114
}
115+
102116
public bool SurrenderedWin
103117
{
104118
get => _surrenderedWin;
@@ -126,7 +140,11 @@ public bool SurrenderedLoss
126140
}
127141
}
128142

129-
public string Result => HistoryDataCalc.CalcHistoryResultFromScores(ScoreType, Score, EnemyScore, SurrenderedWin, SurrenderedLoss);
143+
public string Result =>
144+
HistoryDataCalc.CalcHistoryResultFromScores(ScoreType, Description, Score, EnemyScore, SurrenderedWin,
145+
SurrenderedLoss);
146+
147+
public bool IsMapCustom => Map == "Custom";
130148

131149
public EditableHistoryEntryPopupViewModel()
132150
{
@@ -139,8 +157,10 @@ public EditableHistoryEntryPopupViewModel()
139157
if (ScoreType == "None") Score = -1;
140158
if (ScoreType == "Score") Description = "";
141159

142-
if (EditMode) TrackingDataHelper.EditHistoryEntry(SUUID, HUUID, new HistoryEntry(HUUID, Time, GameMode, Amount, Map, Description, Score, EnemyScore, SurrenderedWin, SurrenderedLoss));
143-
else TrackingDataHelper.AddHistoryEntry(SUUID, new HistoryEntry(HUUID, Time, GameMode, Amount, Map, Description, Score, EnemyScore, SurrenderedWin, SurrenderedLoss));
160+
var map = Map == "Custom" ? CustomMapName : Map;
161+
162+
if (EditMode) TrackingDataHelper.EditHistoryEntry(SUUID, HUUID, new HistoryEntry(HUUID, Time, GameMode, Amount, map, Description, Score, EnemyScore, SurrenderedWin, SurrenderedLoss));
163+
else TrackingDataHelper.AddHistoryEntry(SUUID, new HistoryEntry(HUUID, Time, GameMode, Amount, map, Description, Score, EnemyScore, SurrenderedWin, SurrenderedLoss));
144164
Close();
145165
});
146166
}
@@ -163,6 +183,7 @@ public void InitData()
163183
Description = "";
164184
GameMode = Constants.Gamemodes[0];
165185
Map = Constants.Maps[0];
186+
CustomMapName = "";
166187
Amount = 0;
167188
Score = 0;
168189
EnemyScore = 0;
@@ -181,7 +202,8 @@ public void SetData(HistoryEntryData data)
181202
EnemyScore = data.EnemyScore;
182203
Time = data.Time;
183204
Amount = data.Amount;
184-
Map = data.Map;
205+
Map = Constants.Maps.Contains(data.Map) ? data.Map : "Custom";
206+
CustomMapName = Constants.Maps.Contains(data.Map) ? "" : data.Map;
185207
Description = data.Description;
186208
SurrenderedWin = data.SurrenderedWin;
187209
SurrenderedLoss = data.SurrenderedLoss;

0 commit comments

Comments
 (0)