Skip to content

Commit 8b8756e

Browse files
FeTetraSlendy
andauthored
Implement checkboxes in slot settings to toggle various slot properties (#1063)
* Implement checkboxes in slot settings to toggle various slot properties * Fix UI inconsistencies in checkboxes * Update ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml Co-authored-by: Josh <josh@slendy.pw> * Update ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml Co-authored-by: Josh <josh@slendy.pw> * Fix missing end quote and add extra margin * Update SlotSettingsPage.cshtml.cs Resolve file conflict --------- Co-authored-by: Josh <josh@slendy.pw>
1 parent f059b20 commit 8b8756e

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,33 @@ function onSubmit(){
6060
<label style="text-align: left" for="description">Description</label>
6161
<textarea name="description" id="description" spellcheck="false" placeholder="Description">@HttpUtility.HtmlDecode(Model.Slot.Description)</textarea>
6262
</div>
63+
<div class="ui divider"></div>
64+
<label class="ui button @(Model.Slot.InitiallyLocked ? "selected" : "")" style="margin-bottom: 1em;" for="checkboxInitiallyLocked">
65+
<i class="lock icon"></i>
66+
Locked
67+
<input type="checkbox" name="initiallyLocked" id="checkboxInitiallyLocked" style="margin-left: 5px;" onchange="onCheckboxChange(this)" @(Model.Slot.InitiallyLocked ? "checked" : "") value="true">
68+
</label>
69+
<label class="ui button @(Model.Slot.Shareable == 1 ? "selected" : "")" style="margin-bottom: 1em;" for="checkboxShareable">
70+
<i class="check icon"></i>
71+
Copyable
72+
<input type="checkbox" name="shareable" id="checkboxShareable" style="margin-left: 5px;" onchange="onCheckboxChange(this)" @(Model.Slot.Shareable == 1 ? "checked" : "") value="1">
73+
</label>
74+
@if (Model.Slot.GameVersion != GameVersion.LittleBigPlanet1)
75+
{
76+
<label class="ui button @(Model.Slot.SubLevel ? "selected" : "")" style="margin-bottom: 1em;" for="checkboxSubLevel">
77+
<i class="arrow circle down icon"></i>
78+
Sub Level
79+
<input type="checkbox" name="subLevel" id="checkboxSubLevel" style="margin-left: 5px;" onchange="onCheckboxChange(this)" @(Model.Slot.SubLevel ? "checked" : "") value="true">
80+
</label>
81+
}
82+
else
83+
{
84+
<label class="ui button @(Model.Slot.Lbp1Only ? "selected" : "")" style="margin-bottom: 1em;" for="checkboxLbp1Only">
85+
<i class="eye icon"></i>
86+
LBP1 Only
87+
<input type="checkbox" name="lbp1Only" id="checkboxLbp1Only" style="margin-left: 5px;" onchange="onCheckboxChange(this)" @(Model.Slot.Lbp1Only ? "checked" : "") value="true">
88+
</label>
89+
}
6390
@if (Model.Slot.GameVersion != GameVersion.LittleBigPlanet1)
6491
{
6592
<div class="field">
@@ -106,6 +133,14 @@ function onSubmit(){
106133
function onHoverStart(btn){
107134
generateRandomSkew(btn);
108135
}
136+
function onCheckboxChange(checkbox) {
137+
const label = checkbox.parentElement;
138+
if (checkbox.checked) {
139+
label.classList.add('selected');
140+
} else {
141+
label.classList.remove('selected');
142+
}
143+
}
109144
function generateRandomSkew(element){
110145
let rand = Math.random() * 6 - 3;
111146
element.style.setProperty("--skew", "rotate(" + rand + "deg)");

ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using LBPUnion.ProjectLighthouse.Helpers;
66
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
77
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
8+
using LBPUnion.ProjectLighthouse.Types.Users;
89
using LBPUnion.ProjectLighthouse.Types.Filter;
910
using Microsoft.AspNetCore.Mvc;
1011
using Microsoft.EntityFrameworkCore;
@@ -18,7 +19,18 @@ public class SlotSettingsPage : BaseLayout
1819
public SlotSettingsPage(DatabaseContext database) : base(database)
1920
{}
2021

21-
public async Task<IActionResult> OnPost([FromRoute] int slotId, [FromForm] string? avatar, [FromForm] string? name, [FromForm] string? description, string? labels)
22+
public async Task<IActionResult> OnPost
23+
(
24+
[FromRoute] int slotId,
25+
[FromForm] string? avatar,
26+
[FromForm] string? name,
27+
[FromForm] string? description,
28+
[FromForm] string? labels,
29+
[FromForm] bool initiallyLocked,
30+
[FromForm] int shareable,
31+
[FromForm] bool subLevel,
32+
[FromForm] bool lbp1Only
33+
)
2234
{
2335
this.Slot = await this.Database.Slots.FirstOrDefaultAsync(u => u.SlotId == slotId);
2436
if (this.Slot == null) return this.NotFound();
@@ -56,6 +68,22 @@ public async Task<IActionResult> OnPost([FromRoute] int slotId, [FromForm] strin
5668
this.Slot.AuthorLabels = labels;
5769
}
5870

71+
if (this.Slot.InitiallyLocked != initiallyLocked) this.Slot.InitiallyLocked = initiallyLocked;
72+
73+
if (this.Slot.Shareable != shareable) this.Slot.Shareable = shareable;
74+
75+
if (this.Slot.SubLevel != subLevel)
76+
{
77+
if (this.Slot.GameVersion != GameVersion.LittleBigPlanet1)
78+
this.Slot.SubLevel = subLevel;
79+
}
80+
81+
if (this.Slot.Lbp1Only != lbp1Only)
82+
{
83+
if (this.Slot.GameVersion == GameVersion.LittleBigPlanet1)
84+
this.Slot.Lbp1Only = lbp1Only;
85+
}
86+
5987
// ReSharper disable once InvertIf
6088
if (this.Database.ChangeTracker.HasChanges())
6189
{
@@ -77,4 +105,4 @@ public async Task<IActionResult> OnGet([FromRoute] int slotId)
77105

78106
return this.Page();
79107
}
80-
}
108+
}

0 commit comments

Comments
 (0)