Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement checkboxes in slot settings to toggle various slot properties #1063

Merged
merged 7 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,34 @@ function onSubmit(){
<label style="text-align: left" for="description">Description</label>
<textarea name="description" id="description" spellcheck="false" placeholder="Description">@HttpUtility.HtmlDecode(Model.Slot.Description)</textarea>
</div>
<div class="ui divider"></div>
<label class="ui button label" id="labelInitiallyLocked" for="checkboxInitiallyLocked">
<i class="lock icon"></i>
Locked
<input type="checkbox" name="initiallyLocked" id="checkboxInitiallyLocked" style="margin-left: 5px;" onchange="onCheckboxChange(this)" @(Model.Slot.InitiallyLocked ? "checked" : "") value="true">
</label>
<label class="ui button label" id="labelShareable" for="checkboxShareable">
<i class="check icon"></i>
Copyable
<input type="checkbox" name="shareable" id="checkboxShareable" style="margin-left: 5px;" onchange="onCheckboxChange(this)" @(Model.Slot.Shareable == 1 ? "checked" : "") value="1">
</label>
@if (Model.Slot.GameVersion != GameVersion.LittleBigPlanet1)
{
<label class="ui button label" id="labelSubLevel" for="checkboxSubLevel">
<i class="arrow circle down icon"></i>
Sub Level
<input type="checkbox" name="subLevel" id="checkboxSubLevel" style="margin-left: 5px;" onchange="onCheckboxChange(this)" @(Model.Slot.SubLevel ? "checked" : "") value="true">
</label>
}
else
{
<label class="ui button label" id="labelLbp1Only" for="checkboxLbp1Only">
<i class="eye icon"></i>
LBP1 Only
<input type="checkbox" name="lbp1Only" id="checkboxLbp1Only" style="margin-left: 5px;" onchange="onCheckboxChange(this)" @(Model.Slot.Lbp1Only ? "checked" : "") value="true">
</label>
}
<div class="ui divider fitted hidden"></div>
FeTetra marked this conversation as resolved.
Show resolved Hide resolved
@if (Model.Slot.GameVersion != GameVersion.LittleBigPlanet1)
{
<div class="field">
Expand Down Expand Up @@ -106,6 +134,15 @@ function onSubmit(){
function onHoverStart(btn){
generateRandomSkew(btn);
}
function onCheckboxChange(checkbox) {
const labelId = checkbox.id.replace('checkbox', 'label');
const label = document.getElementById(labelId);
FeTetra marked this conversation as resolved.
Show resolved Hide resolved
if (checkbox.checked) {
label.classList.add('selected');
} else {
label.classList.remove('selected');
}
}
function generateRandomSkew(element){
let rand = Math.random() * 6 - 3;
element.style.setProperty("--skew", "rotate(" + rand + "deg)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
using LBPUnion.ProjectLighthouse.Types.Users;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

Expand All @@ -17,7 +18,18 @@ public class SlotSettingsPage : BaseLayout
public SlotSettingsPage(DatabaseContext database) : base(database)
{}

public async Task<IActionResult> OnPost([FromRoute] int slotId, [FromForm] string? avatar, [FromForm] string? name, [FromForm] string? description, string? labels)
public async Task<IActionResult> OnPost
(
[FromRoute] int slotId,
[FromForm] string? avatar,
[FromForm] string? name,
[FromForm] string? description,
[FromForm] string? labels,
[FromForm] bool initiallyLocked,
[FromForm] int shareable,
[FromForm] bool subLevel,
[FromForm] bool lbp1Only
)
{
this.Slot = await this.Database.Slots.FirstOrDefaultAsync(u => u.SlotId == slotId);
if (this.Slot == null) return this.NotFound();
Expand Down Expand Up @@ -55,6 +67,22 @@ public async Task<IActionResult> OnPost([FromRoute] int slotId, [FromForm] strin
this.Slot.AuthorLabels = labels;
}

if (this.Slot.InitiallyLocked != initiallyLocked) this.Slot.InitiallyLocked = initiallyLocked;

if (this.Slot.Shareable != shareable) this.Slot.Shareable = shareable;

if (this.Slot.SubLevel != subLevel)
{
if (this.Slot.GameVersion != GameVersion.LittleBigPlanet1)
this.Slot.SubLevel = subLevel;
}

if (this.Slot.Lbp1Only != lbp1Only)
{
if (this.Slot.GameVersion == GameVersion.LittleBigPlanet1)
this.Slot.Lbp1Only = lbp1Only;
}

// ReSharper disable once InvertIf
if (this.Database.ChangeTracker.HasChanges())
{
Expand Down