Skip to content

Commit

Permalink
Team settings (#245)
Browse files Browse the repository at this point in the history
Co-authored-by: snixtho <[email protected]>
  • Loading branch information
araszka and snixtho authored Jul 14, 2024
1 parent 7c04e8c commit fd29f91
Show file tree
Hide file tree
Showing 33 changed files with 1,064 additions and 19 deletions.
15 changes: 14 additions & 1 deletion EvoSC.sln
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LocalRecordsModule", "src/M
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LocalRecordsModule.Tests", "tests\Modules\LocalRecordsModule.Tests\LocalRecordsModule.Tests.csproj", "{7401429B-B842-4316-B7A2-B77E9AD966CB}"
EndProject

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamSettingsModule", "src\Modules\TeamSettingsModule\TeamSettingsModule.csproj", "{C10A11E5-4AD8-4229-81F1-57D7DC364E27}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamSettingsModule.Tests", "tests\Modules\TeamSettingsModule.Tests\TeamSettingsModule.Tests.csproj", "{B1745099-0081-4443-BF79-26A888765E16}"
EndProject



Expand Down Expand Up @@ -343,6 +346,14 @@ Global
{7401429B-B842-4316-B7A2-B77E9AD966CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7401429B-B842-4316-B7A2-B77E9AD966CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7401429B-B842-4316-B7A2-B77E9AD966CB}.Release|Any CPU.Build.0 = Release|Any CPU
{C10A11E5-4AD8-4229-81F1-57D7DC364E27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C10A11E5-4AD8-4229-81F1-57D7DC364E27}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C10A11E5-4AD8-4229-81F1-57D7DC364E27}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C10A11E5-4AD8-4229-81F1-57D7DC364E27}.Release|Any CPU.Build.0 = Release|Any CPU
{B1745099-0081-4443-BF79-26A888765E16}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B1745099-0081-4443-BF79-26A888765E16}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B1745099-0081-4443-BF79-26A888765E16}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B1745099-0081-4443-BF79-26A888765E16}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -397,5 +408,7 @@ Global
{098D1F9B-054D-4158-BB6C-AC908C4595F6} = {6D75D6A2-6ECD-4DE4-96C5-CAD7D134407A}
{1D8DBFC8-EC21-4DDA-9D88-DE7CA04C8449} = {DC47658A-F421-4BA4-B617-090A7DFB3900}
{7401429B-B842-4316-B7A2-B77E9AD966CB} = {6D75D6A2-6ECD-4DE4-96C5-CAD7D134407A}
{C10A11E5-4AD8-4229-81F1-57D7DC364E27} = {DC47658A-F421-4BA4-B617-090A7DFB3900}
{B1745099-0081-4443-BF79-26A888765E16} = {6D75D6A2-6ECD-4DE4-96C5-CAD7D134407A}
EndGlobalSection
EndGlobal
2 changes: 2 additions & 0 deletions src/EvoSC.Common/Database/Repository/Maps/MapRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using EvoSC.Common.Interfaces.Models;
using EvoSC.Common.Models.Maps;
using LinqToDB;
using LinqToDB.DataProvider.MySql;
using LinqToDB.Tools;
using Microsoft.Extensions.Logging;

namespace EvoSC.Common.Database.Repository.Maps;
Expand Down
2 changes: 2 additions & 0 deletions src/EvoSC.Common/Services/MatchSettingsService.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using EvoSC.Common.Config.Models;
using EvoSC.Common.Database.Repository.Maps;
using EvoSC.Common.Interfaces;
using EvoSC.Common.Interfaces.Models;
using EvoSC.Common.Interfaces.Services;
using EvoSC.Common.Interfaces.Util;
using EvoSC.Common.Models.Maps;
using EvoSC.Common.Util;
using EvoSC.Common.Util.MatchSettings;
using EvoSC.Common.Util.MatchSettings.Builders;
Expand Down
2 changes: 1 addition & 1 deletion src/EvoSC.Manialinks/Attributes/FormEntryModelAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace EvoSC.Manialinks.Attributes;

/// <summary>
/// Specifies that the annotated class is used as an Form Entry Model.
/// Specifies that the annotated class is used as a Form Entry Model.
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class FormEntryModelAttribute : Attribute;
9 changes: 8 additions & 1 deletion src/EvoSC.Manialinks/Templates/Controls/TextInput.mt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Basic text input control.

<!-- The name of the control. -->
<property type="string" name="id" />

<!-- Additional classes for the entry control. -->
<property type="string" name="classes" default="" />

<!-- The X position of the control. -->
<property type="double" name="x" default="0.0"/>
Expand Down Expand Up @@ -37,6 +40,9 @@ Basic text input control.
<!-- Default text to show when empty -->
<property type="string" name="placeholder" default="" />

<!-- Text to prepend inside the input -->
<property type="string" name="prefix" default="" />

<template>
<frame pos="{{ x }} {{ y }}" id="{{ id }}">
<Rectangle
Expand All @@ -51,13 +57,14 @@ Basic text input control.
focusareacolor1="00000000"
focusareacolor2="00000000"
textformat='{{ isPassword ? "Password" : "Basic" }}'
textprefix="{{ prefix }}"
name="{{ id }}"
data-id="{{ id }}"
default="{{ value }}"
selecttext="{{ autoSelect }}"
maxlen="{{ maxLength }}"
z-index="0"
class="txtinput-text"
class="txtinput-text {{ classes }}"
size="{{ width-2 }} {{ height }}"
pos="{{ 1 }} {{ -height/4 }}"
/>
Expand Down
24 changes: 15 additions & 9 deletions src/EvoSC.Manialinks/Templates/FormEntry.mt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<property type="int" name="zIndex" default="0"/>
<property type="string" name="label" default=""/>
<property type="double" name="w" default="0.0"/>
<property type="double" name="h" default="9.0"/>
<property type="double" name="h" default="20.0"/>
<property type="double" name="x" default="0.0"/>
<property type="double" name="y" default="0.0"/>
<property type="bool" name="isPassword" default="false"/>
Expand All @@ -23,28 +23,34 @@
<frame pos="{{ x }} {{ y }}" size="{{ w }} {{ h }}">
<Label
text="{{ label }}"
class="text-primary"
x="0"
y="0"
textsize="1"
halign="left" valign="top"
halign="left"
valign="top"
/>
<TextInput
x="0"
y="-3"
id="{{ name }}"
value='{{ value ?? "" }}'
width="{{ w }}"
height="3"
isPassword="{{ isPassword }}"
valueType="{{ valueType }}"
/>
<Label
text='$s$F00 {{ validationResults?.FirstOrDefault(v => v.IsInvalid)?.Message ?? "Invalid input." }}'
x="0"
y="-6"
textsize="0.5"
halign="left" valign="top"
<Label
if='validationResults?.Any(v => v.IsInvalid) ?? false'
text='$s$e11 {{ validationResults?.FirstOrDefault(v => v.IsInvalid)?.Message ?? "Invalid input." }}'
class="text-primary"
x="0"
y="-10"
w="{{ w }}"
h="10"
autonewline="1"
textsize="0.75"
halign="left"
valign="top"
/>
</frame>
</template>
Expand Down
1 change: 1 addition & 0 deletions src/EvoSC.Manialinks/Templates/Scripts/UIScripts.ms
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!--
#Include "TextLib" as TextLib
#Include "MathLib" as Math
#Include "ColorLib" as ColorLib

Void __DoNothing() {}

Expand Down
Empty file.
1 change: 1 addition & 0 deletions src/EvoSC/EvoSC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<ProjectReference Include="..\Modules\MatchManagerModule\MatchManagerModule.csproj" />
<ProjectReference Include="..\Modules\ASayModule\ASayModule.csproj" />
<ProjectReference Include="..\Modules\SpectatorTargetInfoModule\SpectatorTargetInfoModule.csproj" />
<ProjectReference Include="..\Modules\TeamSettingsModule\TeamSettingsModule.csproj" />
<ProjectReference Include="..\Modules\WorldRecordModule\WorldRecordModule.csproj" />
<ProjectReference Include="..\Modules\MotdModule\MotdModule.csproj" />
<ProjectReference Include="..\Modules\Player\Player.csproj" />
Expand Down
4 changes: 3 additions & 1 deletion src/EvoSC/InternalModules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using EvoSC.Modules.Official.Scoreboard;
using EvoSC.Modules.Official.SetName;
using EvoSC.Modules.Official.SpectatorTargetInfoModule;
using EvoSC.Modules.Official.TeamSettingsModule;
using EvoSC.Modules.Official.WorldRecordModule;
using FluentMigrator.Runner.Exceptions;

Expand Down Expand Up @@ -51,7 +52,8 @@ public static class InternalModules
typeof(SpectatorTargetInfoModule),
typeof(MapQueueModule),
typeof(MapListModule),
typeof(LocalRecordsModule)
typeof(LocalRecordsModule),
typeof(TeamSettingsModule)
};

/// <summary>
Expand Down
10 changes: 10 additions & 0 deletions src/Modules/MapListModule/Templates/Styles.mt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<component>
<template>
<stylesheet>
<style
class="maplistrow-linkbtn-btn-default"
textsize="0.3"
/>
</stylesheet>
</template>
</component>
18 changes: 18 additions & 0 deletions src/Modules/MapListModule/Themes/DefaultMapListTheme.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using EvoSC.Common.Interfaces.Themes;
using EvoSC.Common.Themes;
using EvoSC.Common.Themes.Attributes;
using EvoSC.Common.Util;

namespace EvoSC.Modules.Official.MapListModule.Themes;

[Theme(Name = "Map List", Description = "Default theme for the Map List.")]
public class DefaultMapListTheme(IThemeManager theme) : Theme<DefaultMapListTheme>
{
private readonly dynamic _theme = theme.Theme;

public override Task ConfigureAsync()
{

return Task.CompletedTask;
}
}
2 changes: 1 addition & 1 deletion src/Modules/SetName/Localization.resx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<value>$&lt;{0}$&gt; changed their nickname to $&lt;{1}$&gt;</value>
</data>
<data name="UI.EditYourNickname" xml:space="preserve">
<value>Edit your nickname</value>
<value>Change name</value>
</data>
<data name="UI.Nickname" xml:space="preserve">
<value>Nickname:</value>
Expand Down
13 changes: 8 additions & 5 deletions src/Modules/SetName/Templates/EditName.mt
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,27 @@
<UIStyle />

<Window
width="50"
height="23"
width="55"
height="{{ (Validation != null && !Validation.IsValid) ? 40 : 30 }}"
x="-25"
y="11.5"
title="{{ Locale.PlayerLanguage.UI_EditYourNickname }}"
icon=""
>
<FormEntry
validationResults='{{ Validation?.GetResult("Nickname") }}'
value='{{ Nickname }}'
name="Nickname"
label="{{ Locale.PlayerLanguage.UI_Nickname }}"
w="48"
w="49"
x="0"
y="0"
/>

<Button id="btnEdit" text="{{ Locale.PlayerLanguage.UI_Submit }}" action="SetName/EditName" x="14" y="-8" />
<Button id="btnCancel" text="{{ Locale.PlayerLanguage.UI_Cancel }}" action="SetName/Cancel" x="32" y="-8" type="secondary" />
<frame pos="0 {{ (Validation != null && !Validation.IsValid) ? -10 : 0 }}">
<Button id="btnEdit" text="{{ Locale.PlayerLanguage.UI_Submit }}" action="SetName/EditName" x="0" y="-11" />
<Button id="btnCancel" text="{{ Locale.PlayerLanguage.UI_Cancel }}" action="SetName/Cancel" x="32" y="-11" type="secondary" />
</frame>
</Window>
</template>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using EvoSC.Commands.Attributes;
using EvoSC.Commands.Interfaces;
using EvoSC.Common.Controllers;
using EvoSC.Common.Controllers.Attributes;
using EvoSC.Modules.Official.TeamSettingsModule.Interfaces;

namespace EvoSC.Modules.Official.TeamSettingsModule.Controllers;

[Controller]
public class TeamSettingsCommandsController(ITeamSettingsService teamSettingsService) : EvoScController<ICommandInteractionContext>
{
[ChatCommand("teams", "[Command.TeamSettings]")]
public async Task EditTeamSettingsAsync()
{
await teamSettingsService.ShowTeamSettingsAsync(Context.Player, await teamSettingsService.GetCurrentTeamSettingsModel());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using EvoSC.Common.Controllers.Attributes;
using EvoSC.Common.Interfaces.Localization;
using EvoSC.Manialinks;
using EvoSC.Modules.Official.TeamSettingsModule.Interfaces;
using EvoSC.Modules.Official.TeamSettingsModule.Models;

namespace EvoSC.Modules.Official.TeamSettingsModule.Controllers;

[Controller]
public class TeamSettingsManialinkController(ITeamSettingsService teamSettingsService, Locale locale) : ManialinkController
{
public async Task SaveTeamSettingsAsync(TeamSettingsModel input)
{
if (!IsModelValid)
{
await ShowAsync(Context.Player, "TeamSettingsModule.EditTeamSettings",
new { Settings = input, Locale = locale }
);
return;
}

await teamSettingsService.SetTeamSettingsAsync(input);
await teamSettingsService.HideTeamSettingsAsync(Context.Player);

Context.AuditEvent
.Success()
.WithEventName("EditTeamSettings")
.HavingProperties(new { TeamSettings = input });
}
}
17 changes: 17 additions & 0 deletions src/Modules/TeamSettingsModule/DataAnnotations/ColorCode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;

namespace EvoSC.Modules.Official.TeamSettingsModule.DataAnnotations;

public partial class ColorCode : ValidationAttribute
{
public override bool IsValid(object? value)
{
var colorCode = value?.ToString() ?? "";

return ValidColorCodeRegex().IsMatch(colorCode);
}

[GeneratedRegex("^(?:[0-9a-fA-F]{3}){1,2}$")]
private static partial Regex ValidColorCodeRegex();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace EvoSC.Modules.Official.TeamSettingsModule.DataAnnotations;

public class NullableColorCode : ColorCode
{
public override bool IsValid(object? value)
{
return value?.ToString()?.Length == 0 || base.IsValid(value);
}
}
13 changes: 13 additions & 0 deletions src/Modules/TeamSettingsModule/DataAnnotations/NullableUrl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.ComponentModel.DataAnnotations;

namespace EvoSC.Modules.Official.TeamSettingsModule.DataAnnotations;

public class NullableUrl : ValidationAttribute
{
public override bool IsValid(object? value)
{
string url = value?.ToString()?.Trim() ?? "";

return url.Length == 0 || Uri.IsWellFormedUriString(url, UriKind.Absolute);
}
}
Loading

0 comments on commit fd29f91

Please sign in to comment.