Skip to content

Commit 2714e86

Browse files
authored
Allow searching replays by is-MM and rating type. (#2787)
1 parent 144f611 commit 2714e86

4 files changed

Lines changed: 76 additions & 8 deletions

File tree

Shared/PlasmaShared/ISpringieService/RatingCategory.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ public enum RatingCategoryFlags
1111
{
1212
Casual = 1, MatchMaking = 2, Planetwars = 4
1313
}
14+
public enum RatingSearchOption
15+
{
16+
Any = 0, None = 1, Casual = 2, Competitive = 3, Planetwars = 4
17+
}
1418
}

Zero-K.info/Controllers/BattlesController.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public class BattleSearchModel
6767
public YesNoAny Mission { get; set; }
6868
public YesNoAny Bots { get; set; }
6969
public YesNoAny Victory { get; set; }
70+
public YesNoAny Matchmaker { get; set; }
71+
public RatingSearchOption Rating { get; set; }
7072
public RankSelector Rank { get; set; } = RankSelector.Undefined;
7173

7274
public int? MinLength { get; set; }
@@ -166,6 +168,34 @@ public ActionResult Index(BattleSearchModel model) {
166168
q = q.Where(b => b.Rank == rank);
167169
}
168170

171+
if (model.Matchmaker != YesNoAny.Any)
172+
{
173+
var bval = model.Matchmaker == YesNoAny.Yes;
174+
q = q.Where(b => b.IsMatchMaker == bval);
175+
}
176+
177+
if (model.Rating != RatingSearchOption.Any)
178+
{
179+
switch (model.Rating)
180+
{
181+
case RatingSearchOption.Competitive:
182+
q = q.Where(b => b.ApplicableRatings.HasFlag(RatingCategoryFlags.MatchMaking));
183+
break;
184+
case RatingSearchOption.Casual:
185+
q = q.Where(b => b.ApplicableRatings.HasFlag(RatingCategoryFlags.Casual));
186+
break;
187+
case RatingSearchOption.Planetwars:
188+
q = q.Where(b => b.ApplicableRatings.HasFlag(RatingCategoryFlags.Planetwars));
189+
break;
190+
case RatingSearchOption.None:
191+
q = q.Where(b => b.ApplicableRatings == 0);
192+
break;
193+
default:
194+
// The default case being no filtering should be safe enough.
195+
break;
196+
}
197+
}
198+
169199
q = q.OrderByDescending(b => b.StartTime);
170200

171201
if (model.offset.HasValue) q = q.Skip(model.offset.Value);

Zero-K.info/Views/Battles/BattleDetail.cshtml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,37 @@
100100
@Model.IsMission
101101
</td>
102102
</tr>
103+
<tr>
104+
<td>
105+
Rating:
106+
</td>
107+
<td>
108+
@{
109+
if (Model.IsRatedMatch())
110+
{
111+
switch (Model.GetRatingCategory())
112+
{
113+
case RatingCategory.MatchMaking:
114+
<text>Competitive</text>
115+
break;
116+
case RatingCategory.Casual:
117+
<text>Casual</text>
118+
break;
119+
case RatingCategory.Planetwars:
120+
<text>Planetwars</text>
121+
break;
122+
}
123+
}
124+
else
125+
{
126+
<text>None</text>
127+
}
128+
}
129+
</td>
130+
</tr>
103131
</table>
104132
@if (!string.IsNullOrEmpty(Model.ReplayFileName))
105-
{
133+
{
106134
<a href="@Html.PrintSpringLink(string.Format("@start_replay:{0},{1},{2},{3}", GlobalConst.BaseSiteUrl+ "/replays/" + Path.GetFileName(Model.ReplayFileName), Model.ResourceByModResourceID.InternalName, Model.ResourceByMapResourceID.InternalName, Model.EngineVersion, Model.SpringBattleID))">
107135
<span class="textbutton" style="font-size: 130%">Watch Replay Now</span>
108136
</a>
@@ -112,7 +140,7 @@
112140
<a href='/replays/@Model.ReplayFileName'>Manual download</a>
113141
<br />
114142
}
115-
}
143+
}
116144
</div>
117145
<br class="clearfloat" />
118146
<div>

Zero-K.info/Views/Battles/BattleIndex.cshtml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,22 @@
66
<form action="@Url.Action("Index")" id="ajaxScrollForm" method="post">
77
<table class="inputTable">
88
<tr>
9-
<td>Title: </td><td>@Html.TextBoxFor(x => x.Title)</td>
10-
<td>Map: </td><td>@Html.TextBoxFor(x => x.Map, new { data_autocomplete = Url.Action("Maps", "Autocomplete"), data_autocomplete_action = "submit" })</td>
9+
<td>Title: </td>
10+
<td>@Html.TextBoxFor(x => x.Title)</td>
11+
<td>Map: </td>
12+
<td>@Html.TextBoxFor(x => x.Map, new { data_autocomplete = Url.Action("Maps", "Autocomplete"), data_autocomplete_action = "submit" })</td>
1113
</tr>
1214
<tr>
1315
<td>Players: </td>
1416
<td>
15-
@using (var db = new ZkDataContext()) { @Html.MultiSelectFor(x => x.UserId, Url.Action("UsersNoLink", "Autocomplete"), x => Html.PrintAccount(db.Accounts.Find(x))); }
17+
@using (var db = new ZkDataContext())
18+
{@Html.MultiSelectFor(x => x.UserId, Url.Action("UsersNoLink", "Autocomplete"), x => Html.PrintAccount(db.Accounts.Find(x)));
19+
}
1620
</td>
17-
<td>Player count: </td><td> @Html.TextBoxFor(x => x.PlayersFrom) - @Html.TextBoxFor(x => x.PlayersTo)</td>
18-
</tr>
19-
<tr>
21+
<td>Player count: </td>
22+
<td> @Html.TextBoxFor(x => x.PlayersFrom) - @Html.TextBoxFor(x => x.PlayersTo)</td>
2023
</tr>
24+
<tr></tr>
2125
<tr>
2226
<td>Age:</td>
2327
<td>@Html.EnumDropDownListFor(x => x.Age)</td>
@@ -30,6 +34,8 @@
3034
Bots: @Html.EnumDropDownListFor(x => x.Bots)
3135
Rank: @Html.EnumDropDownListFor(x => x.Rank)
3236
Victory: @Html.EnumDropDownListFor(x => x.Victory)
37+
MM: @Html.EnumDropDownListFor(x => x.Matchmaker)
38+
Rating: @Html.EnumDropDownListFor(x => x.Rating)
3339
<input name="sa" value="Search" alt="Search" type="image" src="/img/search_img.png" style="border: none; vertical-align: middle;" />
3440
</td>
3541
</tr>

0 commit comments

Comments
 (0)