Compare commits
22 Commits
1.11.4
...
1.12.0-Dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
73f130a95a | ||
|
|
7c4269b011 | ||
|
|
b0b149d8bc | ||
|
|
777e6b9d27 | ||
|
|
37c11e9d73 | ||
| e8f8512cdd | |||
| 7569b15993 | |||
| d91f1a3356 | |||
| 0c38b9397a | |||
| 9d850f8fa6 | |||
| 9eb2309018 | |||
|
|
5dce1977c7 | ||
|
|
e396d2cf46 | ||
| c5e6c06005 | |||
| 14ec282f21 | |||
| c7316e4f55 | |||
| 8c308ab488 | |||
| a8512e2a86 | |||
| abe28e931c | |||
|
|
b177dbd595 | ||
|
|
10d5519cc1 | ||
|
|
dc0265f614 |
268
.gitea/workflows/lightless-tag-and-release.yml
Normal file
268
.gitea/workflows/lightless-tag-and-release.yml
Normal file
@@ -0,0 +1,268 @@
|
||||
name: Tag and Release Lightless
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master, dev ]
|
||||
|
||||
env:
|
||||
PLUGIN_NAME: LightlessSync
|
||||
DOTNET_VERSION: 9.x
|
||||
|
||||
jobs:
|
||||
tag-and-release:
|
||||
runs-on: ubuntu-22.04
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- name: Checkout Lightless
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
submodules: true
|
||||
|
||||
- name: Setup .NET 9 SDK
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: 9.x
|
||||
|
||||
- name: Download Dalamud
|
||||
run: |
|
||||
cd /
|
||||
mkdir -p root/.xlcore/dalamud/Hooks/dev
|
||||
curl -O https://goatcorp.github.io/dalamud-distrib/stg/latest.zip
|
||||
unzip latest.zip -d /root/.xlcore/dalamud/Hooks/dev
|
||||
|
||||
- name: Lets Build Lightless!
|
||||
run: |
|
||||
dotnet restore
|
||||
dotnet build --configuration Release --no-restore
|
||||
dotnet publish --configuration Release --no-build
|
||||
|
||||
- name: Get version
|
||||
id: package_version
|
||||
uses: KageKirin/get-csproj-version@v0
|
||||
with:
|
||||
file: LightlessSync/LightlessSync.csproj
|
||||
|
||||
- name: Display version
|
||||
run: |
|
||||
echo "Version: ${{ steps.package_version.outputs.version }}"
|
||||
|
||||
- name: Prepare Lightless Client
|
||||
run: |
|
||||
PUBLISH_PATH="/workspace/Lightless-Sync/LightlessClient/LightlessSync/bin/x64/Release/publish/"
|
||||
if [ -d "$PUBLISH_PATH" ]; then
|
||||
rm -rf "$PUBLISH_PATH"
|
||||
echo "Removed $PUBLISH_PATH"
|
||||
else
|
||||
echo "$PUBLISH_PATH does not exist, nothing to remove."
|
||||
fi
|
||||
|
||||
mkdir -p output
|
||||
(cd /workspace/Lightless-Sync/LightlessClient/LightlessSync/bin/x64/Release/ && zip -r $OLDPWD/output/LightlessClient.zip *)
|
||||
|
||||
- name: Create Git tag if not exists (master)
|
||||
if: github.ref == 'refs/heads/master'
|
||||
run: |
|
||||
tag="${{ steps.package_version.outputs.version }}"
|
||||
git fetch --tags
|
||||
if ! git tag -l "$tag" | grep -q "$tag"; then
|
||||
echo "Tag $tag does not exist. Creating and pushing..."
|
||||
git config user.name "GitHub Action"
|
||||
git config user.email "action@github.com"
|
||||
git tag "$tag"
|
||||
git push origin "$tag"
|
||||
else
|
||||
echo "Tag $tag already exists. Skipping tag creation."
|
||||
fi
|
||||
|
||||
- name: Create Git tag if not exists (dev)
|
||||
if: github.ref == 'refs/heads/dev'
|
||||
run: |
|
||||
tag="${{ steps.package_version.outputs.version }}-Dev"
|
||||
git fetch --tags
|
||||
if ! git tag -l "$tag" | grep -q "$tag"; then
|
||||
echo "Tag $tag does not exist. Creating and pushing..."
|
||||
git config user.name "GitHub Action"
|
||||
git config user.email "action@github.com"
|
||||
git tag "$tag"
|
||||
git push origin "$tag"
|
||||
else
|
||||
echo "Tag $tag already exists. Skipping tag creation."
|
||||
fi
|
||||
|
||||
- name: Create Release (master)
|
||||
if: github.ref == 'refs/heads/master'
|
||||
id: create_release
|
||||
run: |
|
||||
echo "=== Searching for existing release ${{ steps.package_version.outputs.version }}==="
|
||||
|
||||
release_id=$(curl -s -H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
||||
"https://git.lightless-sync.org/api/v1/repos/${GITHUB_REPOSITORY}/releases/tags/${{ steps.package_version.outputs.version }}" | jq -r .id)
|
||||
|
||||
if [ "$release_id" != "null" ]; then
|
||||
echo "=== Deleting existing release ${{ steps.package_version.outputs.version }}==="
|
||||
curl -X DELETE -H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
||||
"https://git.lightless-sync.org/api/v1/repos/${GITHUB_REPOSITORY}/releases/$release_id"
|
||||
fi
|
||||
|
||||
echo "=== Creating new release ${{ steps.package_version.outputs.version }}==="
|
||||
response=$(
|
||||
curl --fail-with-body -X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
||||
-d '{
|
||||
"tag_name": "${{ steps.package_version.outputs.version }}",
|
||||
"name": "${{ steps.package_version.outputs.version }}",
|
||||
"draft": false,
|
||||
"prerelease": false
|
||||
}' \
|
||||
"https://git.lightless-sync.org/api/v1/repos/${GITHUB_REPOSITORY}/releases"
|
||||
)
|
||||
|
||||
release_id=$(echo "$response" | jq -r .id)
|
||||
echo "release_id=$release_id" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Create Release (dev)
|
||||
if: github.ref == 'refs/heads/dev'
|
||||
id: create_release
|
||||
run: |
|
||||
version="${{ steps.package_version.outputs.version }}-Dev"
|
||||
echo "=== Searching for existing release $version==="
|
||||
release_id=$(curl -s -H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
||||
"https://git.lightless-sync.org/api/v1/repos/${GITHUB_REPOSITORY}/releases/tags/$version" | jq -r .id)
|
||||
if [ "$release_id" != "null" ]; then
|
||||
echo "=== Deleting existing release $version==="
|
||||
curl -X DELETE -H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
||||
"https://git.lightless-sync.org/api/v1/repos/${GITHUB_REPOSITORY}/releases/$release_id"
|
||||
fi
|
||||
echo "=== Creating new release $version==="
|
||||
response=$(
|
||||
curl --fail-with-body -X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
||||
-d '{
|
||||
"tag_name": "'"$version"'",
|
||||
"name": "'"$version"'",
|
||||
"draft": false,
|
||||
"prerelease": false
|
||||
}' \
|
||||
"https://git.lightless-sync.org/api/v1/repos/${GITHUB_REPOSITORY}/releases"
|
||||
)
|
||||
release_id=$(echo "$response" | jq -r .id)
|
||||
echo "release_id=$release_id" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Upload Assets to release
|
||||
run: |
|
||||
curl --fail-with-body -s -X POST \
|
||||
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
||||
-F "attachment=@output/LightlessClient.zip" \
|
||||
"https://git.lightless-sync.org/api/v1/repos/${GITHUB_REPOSITORY}/releases/${{ steps.create_release.outputs.release_id }}/assets"
|
||||
|
||||
- name: Clone plugin hosting repo
|
||||
run: |
|
||||
mkdir LightlessSyncRepo
|
||||
cd LightlessSyncRepo
|
||||
git clone https://git.lightless-sync.org/${{ gitea.repository_owner }}/LightlessSync.git
|
||||
env:
|
||||
GIT_TERMINAL_PROMPT: 0
|
||||
|
||||
- name: Update plogonmaster.json with version (master)
|
||||
if: github.ref == 'refs/heads/master'
|
||||
env:
|
||||
VERSION: ${{ steps.package_version.outputs.version }}
|
||||
run: |
|
||||
set -e
|
||||
|
||||
pluginJsonPath="${PLUGIN_NAME}/bin/x64/Release/${PLUGIN_NAME}.json"
|
||||
repoJsonPath="LightlessSyncRepo/LightlessSync/plogonmaster.json"
|
||||
version="${VERSION}"
|
||||
downloadUrl="https://git.lightless-sync.org/${{ gitea.repository_owner }}/LightlessClient/releases/download/$version/LightlessClient.zip"
|
||||
|
||||
# Read plugin JSON
|
||||
pluginJson=$(cat "$pluginJsonPath")
|
||||
internalName=$(jq -r '.InternalName' <<< "$pluginJson")
|
||||
dalamudApiLevel=$(jq -r '.DalamudApiLevel' <<< "$pluginJson")
|
||||
|
||||
# Read repo JSON (force array if not already)
|
||||
repoJsonRaw=$(cat "$repoJsonPath")
|
||||
if echo "$repoJsonRaw" | jq 'type' | grep -q '"array"'; then
|
||||
repoJson="$repoJsonRaw"
|
||||
else
|
||||
repoJson="[$repoJsonRaw]"
|
||||
fi
|
||||
|
||||
# Update matching plugin entry
|
||||
updatedRepoJson=$(jq \
|
||||
--arg internalName "$internalName" \
|
||||
--arg dalamudApiLevel "$dalamudApiLevel" \
|
||||
--arg version "$version" \
|
||||
--arg downloadUrl "$downloadUrl" \
|
||||
'
|
||||
map(
|
||||
if .InternalName == $internalName
|
||||
then
|
||||
.DalamudApiLevel = $dalamudApiLevel
|
||||
| .AssemblyVersion = $version
|
||||
| .DownloadLinkInstall = $downloadUrl
|
||||
| .DownloadLinkUpdate = $downloadUrl
|
||||
else
|
||||
.
|
||||
end
|
||||
)
|
||||
' <<< "$repoJson")
|
||||
|
||||
# Write back to file
|
||||
echo "$updatedRepoJson" > "$repoJsonPath"
|
||||
# Output the content of the file
|
||||
cat "$repoJsonPath"
|
||||
|
||||
- name: Update plogonmaster.json with version (dev)
|
||||
if: github.ref == 'refs/heads/dev'
|
||||
env:
|
||||
VERSION: ${{ steps.package_version.outputs.version }}
|
||||
run: |
|
||||
set -e
|
||||
pluginJsonPath="${PLUGIN_NAME}/bin/x64/Release/${PLUGIN_NAME}.json"
|
||||
repoJsonPath="LightlessSyncRepo/LightlessSync/plogonmaster.json"
|
||||
assemblyVersion="${VERSION}"
|
||||
version="${VERSION}-Dev"
|
||||
downloadUrl="https://git.lightless-sync.org/${{ gitea.repository_owner }}/LightlessClient/releases/download/$version/LightlessClient.zip"
|
||||
pluginJson=$(cat "$pluginJsonPath")
|
||||
internalName=$(jq -r '.InternalName' <<< "$pluginJson")
|
||||
dalamudApiLevel=$(jq -r '.DalamudApiLevel' <<< "$pluginJson")
|
||||
repoJsonRaw=$(cat "$repoJsonPath")
|
||||
if echo "$repoJsonRaw" | jq 'type' | grep -q '"array"'; then
|
||||
repoJson="$repoJsonRaw"
|
||||
else
|
||||
repoJson="[$repoJsonRaw]"
|
||||
fi
|
||||
updatedRepoJson=$(jq \
|
||||
--arg internalName "$internalName" \
|
||||
--arg dalamudApiLevel "$dalamudApiLevel" \
|
||||
--arg version "$version" \
|
||||
--arg downloadUrl "$downloadUrl" \
|
||||
'
|
||||
map(
|
||||
if .InternalName == $internalName
|
||||
then
|
||||
.DalamudApiLevel = $dalamudApiLevel
|
||||
| .TestingAssemblyVersion = $assemblyVersion
|
||||
| .DownloadLinkTesting = $downloadUrl
|
||||
else
|
||||
.
|
||||
end
|
||||
)
|
||||
' <<< "$repoJson")
|
||||
echo "$updatedRepoJson" > "$repoJsonPath"
|
||||
cat "$repoJsonPath"
|
||||
|
||||
- name: Commit and push to LightlessSync
|
||||
run: |
|
||||
cd LightlessSyncRepo/LightlessSync
|
||||
git config user.name "github-actions"
|
||||
git config user.email "github-actions@github.com"
|
||||
git add .
|
||||
git diff-index --quiet HEAD || git commit -m "Update ${{ env.PLUGIN_NAME }} to ${{ steps.package_version.outputs.version }}"
|
||||
git push https://x-access-token:${{ secrets.AUTOMATION_TOKEN }}@git.lightless-sync.org/${{ gitea.repository_owner }}/LightlessSync.git HEAD:main
|
||||
2
.gitmodules
vendored
2
.gitmodules
vendored
@@ -1,6 +1,6 @@
|
||||
[submodule "LightlessAPI"]
|
||||
path = LightlessAPI
|
||||
url = https://github.com/Light-Public-Syncshells/LightlessAPI
|
||||
url = https://git.lightless-sync.org/Lightless-Sync/LightlessAPI.git
|
||||
[submodule "PenumbraAPI"]
|
||||
path = PenumbraAPI
|
||||
url = https://github.com/Ottermandias/Penumbra.Api.git
|
||||
|
||||
Submodule LightlessAPI updated: 3a69c94f7f...aec2a5023e
@@ -383,7 +383,7 @@ public sealed class CacheMonitor : DisposableMediatorSubscriberBase
|
||||
scanThread.Start();
|
||||
while (scanThread.IsAlive)
|
||||
{
|
||||
await Task.Delay(250).ConfigureAwait(false);
|
||||
await Task.Delay(250, token).ConfigureAwait(false);
|
||||
}
|
||||
TotalFiles = 0;
|
||||
_currentFileProgress = 0;
|
||||
@@ -583,7 +583,14 @@ public sealed class CacheMonitor : DisposableMediatorSubscriberBase
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogWarning(ex, "Failed validating {path}", workload.ResolvedFilepath);
|
||||
if (workload != null)
|
||||
{
|
||||
Logger.LogWarning(ex, "Failed validating {path}", workload.ResolvedFilepath);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogWarning(ex, "Failed validating unknown workload");
|
||||
}
|
||||
}
|
||||
Interlocked.Increment(ref _currentFileProgress);
|
||||
}
|
||||
@@ -612,7 +619,7 @@ public sealed class CacheMonitor : DisposableMediatorSubscriberBase
|
||||
return;
|
||||
}
|
||||
|
||||
if (entitiesToUpdate.Any() || entitiesToRemove.Any())
|
||||
if (entitiesToUpdate.Count != 0 || entitiesToRemove.Count != 0)
|
||||
{
|
||||
foreach (var entity in entitiesToUpdate)
|
||||
{
|
||||
@@ -647,6 +654,12 @@ public sealed class CacheMonitor : DisposableMediatorSubscriberBase
|
||||
CancellationToken = ct
|
||||
}, (cachePath) =>
|
||||
{
|
||||
if (_fileDbManager == null || _ipcManager?.Penumbra == null || cachePath == null)
|
||||
{
|
||||
Logger.LogTrace("Potential null in db: {isDbNull} penumbra: {isPenumbraNull} cachepath: {isPathNull}", _fileDbManager == null, _ipcManager?.Penumbra == null, cachePath == null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ct.IsCancellationRequested) return;
|
||||
|
||||
if (!_ipcManager.Penumbra.APIAvailable)
|
||||
|
||||
@@ -21,7 +21,7 @@ public sealed class FileCacheManager : IHostedService
|
||||
private readonly string _csvPath;
|
||||
private readonly ConcurrentDictionary<string, List<FileCacheEntity>> _fileCaches = new(StringComparer.Ordinal);
|
||||
private readonly SemaphoreSlim _getCachesByPathsSemaphore = new(1, 1);
|
||||
private readonly object _fileWriteLock = new();
|
||||
private readonly Lock _fileWriteLock = new();
|
||||
private readonly IpcManager _ipcManager;
|
||||
private readonly ILogger<FileCacheManager> _logger;
|
||||
public string CacheFolder => _configService.Current.CacheFolder;
|
||||
@@ -42,10 +42,7 @@ public sealed class FileCacheManager : IHostedService
|
||||
FileInfo fi = new(path);
|
||||
if (!fi.Exists) return null;
|
||||
_logger.LogTrace("Creating cache entry for {path}", path);
|
||||
var fullName = fi.FullName.ToLowerInvariant();
|
||||
if (!fullName.Contains(_configService.Current.CacheFolder.ToLowerInvariant(), StringComparison.Ordinal)) return null;
|
||||
string prefixedPath = fullName.Replace(_configService.Current.CacheFolder.ToLowerInvariant(), CachePrefix + "\\", StringComparison.Ordinal).Replace("\\\\", "\\", StringComparison.Ordinal);
|
||||
return CreateFileCacheEntity(fi, prefixedPath);
|
||||
return CreateFileEntity(_configService.Current.CacheFolder.ToLowerInvariant(), CachePrefix, fi);
|
||||
}
|
||||
|
||||
public FileCacheEntity? CreateFileEntry(string path)
|
||||
@@ -53,9 +50,14 @@ public sealed class FileCacheManager : IHostedService
|
||||
FileInfo fi = new(path);
|
||||
if (!fi.Exists) return null;
|
||||
_logger.LogTrace("Creating file entry for {path}", path);
|
||||
return CreateFileEntity(_ipcManager.Penumbra.ModDirectory!.ToLowerInvariant(), PenumbraPrefix, fi);
|
||||
}
|
||||
|
||||
private FileCacheEntity? CreateFileEntity(string directory, string prefix, FileInfo fi)
|
||||
{
|
||||
var fullName = fi.FullName.ToLowerInvariant();
|
||||
if (!fullName.Contains(_ipcManager.Penumbra.ModDirectory!.ToLowerInvariant(), StringComparison.Ordinal)) return null;
|
||||
string prefixedPath = fullName.Replace(_ipcManager.Penumbra.ModDirectory!.ToLowerInvariant(), PenumbraPrefix + "\\", StringComparison.Ordinal).Replace("\\\\", "\\", StringComparison.Ordinal);
|
||||
if (!fullName.Contains(directory, StringComparison.Ordinal)) return null;
|
||||
string prefixedPath = fullName.Replace(directory, prefix + "\\", StringComparison.Ordinal).Replace("\\\\", "\\", StringComparison.Ordinal);
|
||||
return CreateFileCacheEntity(fi, prefixedPath);
|
||||
}
|
||||
|
||||
@@ -66,7 +68,7 @@ public sealed class FileCacheManager : IHostedService
|
||||
List<FileCacheEntity> output = [];
|
||||
if (_fileCaches.TryGetValue(hash, out var fileCacheEntities))
|
||||
{
|
||||
foreach (var fileCache in fileCacheEntities.Where(c => ignoreCacheEntries ? !c.IsCacheEntry : true).ToList())
|
||||
foreach (var fileCache in fileCacheEntities.Where(c => !ignoreCacheEntries || !c.IsCacheEntry).ToList())
|
||||
{
|
||||
if (!validate) output.Add(fileCache);
|
||||
else
|
||||
@@ -106,7 +108,7 @@ public sealed class FileCacheManager : IHostedService
|
||||
var computedHash = Crypto.GetFileHash(fileCache.ResolvedFilepath);
|
||||
if (!string.Equals(computedHash, fileCache.Hash, StringComparison.Ordinal))
|
||||
{
|
||||
_logger.LogInformation("Failed to validate {file}, got hash {hash}, expected hash {hash}", fileCache.ResolvedFilepath, computedHash, fileCache.Hash);
|
||||
_logger.LogInformation("Failed to validate {file}, got hash {computedHash}, expected hash {hash}", fileCache.ResolvedFilepath, computedHash, fileCache.Hash);
|
||||
brokenEntities.Add(fileCache);
|
||||
}
|
||||
}
|
||||
@@ -151,7 +153,7 @@ public sealed class FileCacheManager : IHostedService
|
||||
{
|
||||
if (_fileCaches.TryGetValue(hash, out var hashes))
|
||||
{
|
||||
var item = hashes.OrderBy(p => p.PrefixedFilePath.Contains(PenumbraPrefix) ? 0 : 1).FirstOrDefault();
|
||||
var item = hashes.OrderBy(p => p.PrefixedFilePath.Contains(PenumbraPrefix, StringComparison.Ordinal) ? 0 : 1).FirstOrDefault();
|
||||
if (item != null) return GetValidatedFileCache(item);
|
||||
}
|
||||
return null;
|
||||
@@ -180,37 +182,66 @@ public sealed class FileCacheManager : IHostedService
|
||||
|
||||
try
|
||||
{
|
||||
var cleanedPaths = paths.Distinct(StringComparer.OrdinalIgnoreCase).ToDictionary(p => p,
|
||||
p => p.Replace("/", "\\", StringComparison.OrdinalIgnoreCase)
|
||||
.Replace(_ipcManager.Penumbra.ModDirectory!, _ipcManager.Penumbra.ModDirectory!.EndsWith('\\') ? PenumbraPrefix + '\\' : PenumbraPrefix, StringComparison.OrdinalIgnoreCase)
|
||||
.Replace(_configService.Current.CacheFolder, _configService.Current.CacheFolder.EndsWith('\\') ? CachePrefix + '\\' : CachePrefix, StringComparison.OrdinalIgnoreCase)
|
||||
.Replace("\\\\", "\\", StringComparison.Ordinal),
|
||||
var allEntities = _fileCaches.SelectMany(f => f.Value).ToArray();
|
||||
|
||||
var cacheDict = new ConcurrentDictionary<string, FileCacheEntity>(
|
||||
StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
Dictionary<string, FileCacheEntity?> result = new(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
var dict = _fileCaches.SelectMany(f => f.Value)
|
||||
.ToDictionary(d => d.PrefixedFilePath, d => d, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
foreach (var entry in cleanedPaths)
|
||||
Parallel.ForEach(allEntities, entity =>
|
||||
{
|
||||
//_logger.LogDebug("Checking {path}", entry.Value);
|
||||
cacheDict[entity.PrefixedFilePath] = entity;
|
||||
});
|
||||
|
||||
if (dict.TryGetValue(entry.Value, out var entity))
|
||||
var cleanedPaths = new ConcurrentDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
var seenCleaned = new ConcurrentDictionary<string, byte>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
Parallel.ForEach(paths, p =>
|
||||
{
|
||||
var cleaned = p.Replace("/", "\\", StringComparison.OrdinalIgnoreCase)
|
||||
.Replace(
|
||||
_ipcManager.Penumbra.ModDirectory!,
|
||||
_ipcManager.Penumbra.ModDirectory!.EndsWith('\\')
|
||||
? PenumbraPrefix + '\\' : PenumbraPrefix,
|
||||
StringComparison.OrdinalIgnoreCase)
|
||||
.Replace(
|
||||
_configService.Current.CacheFolder,
|
||||
_configService.Current.CacheFolder.EndsWith('\\')
|
||||
? CachePrefix + '\\' : CachePrefix,
|
||||
StringComparison.OrdinalIgnoreCase)
|
||||
.Replace("\\\\", "\\", StringComparison.Ordinal);
|
||||
|
||||
if (seenCleaned.TryAdd(cleaned, 0))
|
||||
{
|
||||
_logger.LogDebug("Adding to cleanedPaths: {cleaned}", cleaned);
|
||||
cleanedPaths[p] = cleaned;
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Duplicate found: {cleaned}", cleaned);
|
||||
}
|
||||
});
|
||||
|
||||
var result = new ConcurrentDictionary<string, FileCacheEntity?>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
Parallel.ForEach(cleanedPaths, entry =>
|
||||
{
|
||||
_logger.LogDebug("Checking if in cache: {path}", entry.Value);
|
||||
|
||||
if (cacheDict.TryGetValue(entry.Value, out var entity))
|
||||
{
|
||||
var validatedCache = GetValidatedFileCache(entity);
|
||||
result.Add(entry.Key, validatedCache);
|
||||
result[entry.Key] = validatedCache;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!entry.Value.Contains(CachePrefix, StringComparison.Ordinal))
|
||||
result.Add(entry.Key, CreateFileEntry(entry.Key));
|
||||
result[entry.Key] = CreateFileEntry(entry.Key);
|
||||
else
|
||||
result.Add(entry.Key, CreateCacheEntry(entry.Key));
|
||||
result[entry.Key] = CreateCacheEntry(entry.Key);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
return new Dictionary<string, FileCacheEntity?>(result, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -439,7 +470,7 @@ public sealed class FileCacheManager : IHostedService
|
||||
{
|
||||
attempts++;
|
||||
_logger.LogWarning(ex, "Could not open {file}, trying again", _csvPath);
|
||||
Thread.Sleep(100);
|
||||
Task.Delay(100, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using LightlessSync.LightlessConfiguration.Models;
|
||||
using LightlessSync.LightlessConfiguration.Models;
|
||||
using LightlessSync.UI;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
@@ -15,10 +15,12 @@ public class LightlessConfig : ILightlessConfiguration
|
||||
public bool PreferNoteInDtrTooltip { get; set; } = false;
|
||||
public bool IsNameplateColorsEnabled { get; set; } = false;
|
||||
public DtrEntry.Colors NameplateColors { get; set; } = new(Foreground: 0xE69138u, Glow: 0xFFBA47u);
|
||||
public Dictionary<string, string> CustomUIColors { get; set; } = new(StringComparer.OrdinalIgnoreCase);
|
||||
public bool UseColorsInDtr { get; set; } = true;
|
||||
public DtrEntry.Colors DtrColorsDefault { get; set; } = default;
|
||||
public DtrEntry.Colors DtrColorsNotConnected { get; set; } = new(Glow: 0x0428FFu);
|
||||
public DtrEntry.Colors DtrColorsPairsInRange { get; set; } = new(Glow: 0xFFBA47u);
|
||||
public bool UseLightlessRedesign { get; set; } = true;
|
||||
public bool EnableRightClickMenus { get; set; } = true;
|
||||
public NotificationLocation ErrorNotification { get; set; } = NotificationLocation.Both;
|
||||
public string ExportFolder { get; set; } = string.Empty;
|
||||
@@ -42,6 +44,7 @@ public class LightlessConfig : ILightlessConfiguration
|
||||
public bool ShowCharacterNameInsteadOfNotesForVisible { get; set; } = false;
|
||||
public bool ShowOfflineUsersSeparately { get; set; } = true;
|
||||
public bool ShowSyncshellOfflineUsersSeparately { get; set; } = true;
|
||||
public bool ShowGroupedSyncshellsInAll { get; set; } = true;
|
||||
public bool GroupUpSyncshells { get; set; } = true;
|
||||
public bool ShowOnlineNotifications { get; set; } = false;
|
||||
public bool ShowOnlineNotificationsOnlyForIndividualPairs { get; set; } = true;
|
||||
@@ -64,4 +67,8 @@ public class LightlessConfig : ILightlessConfiguration
|
||||
public bool UseFocusTarget { get; set; } = false;
|
||||
public bool overrideFriendColor { get; set; } = false;
|
||||
public bool overridePartyColor { get; set; } = false;
|
||||
public bool BroadcastEnabled { get; set; } = false;
|
||||
public DateTime BroadcastTtl { get; set; } = DateTime.MinValue;
|
||||
public bool SyncshellFinderEnabled { get; set; } = false;
|
||||
public string? SelectedFinderSyncshell { get; set; } = null;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace LightlessSync.LightlessConfiguration.Configurations;
|
||||
|
||||
public class PairTagStorage : ILightlessConfiguration
|
||||
{
|
||||
public Dictionary<string, Models.PairTagStorage> ServerTagStorage { get; set; } = new(StringComparer.OrdinalIgnoreCase);
|
||||
public int Version { get; set; } = 0;
|
||||
}
|
||||
@@ -13,4 +13,7 @@ public class PlayerPerformanceConfig : ILightlessConfiguration
|
||||
public int VRAMSizeAutoPauseThresholdMiB { get; set; } = 550;
|
||||
public int TrisAutoPauseThresholdThousands { get; set; } = 250;
|
||||
public List<string> UIDsToIgnore { get; set; } = new();
|
||||
public bool PauseInInstanceDuty { get; set; } = false;
|
||||
public bool PauseWhilePerforming { get; set; } = true;
|
||||
public bool PauseInCombat { get; set; } = true;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
using LightlessSync.LightlessConfiguration.Models;
|
||||
|
||||
namespace LightlessSync.LightlessConfiguration.Configurations;
|
||||
|
||||
public class ServerTagConfig : ILightlessConfiguration
|
||||
{
|
||||
public Dictionary<string, ServerTagStorage> ServerTagStorage { get; set; } = new(StringComparer.OrdinalIgnoreCase);
|
||||
public int Version { get; set; } = 0;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace LightlessSync.LightlessConfiguration.Configurations;
|
||||
|
||||
public class SyncshellTagStorage : ILightlessConfiguration
|
||||
{
|
||||
public Dictionary<string, Models.SyncshellTagStorage> ServerTagStorage { get; set; } = new(StringComparer.OrdinalIgnoreCase);
|
||||
public int Version { get; set; } = 0;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace LightlessSync.LightlessConfiguration.Models;
|
||||
|
||||
[Serializable]
|
||||
public class ServerTagStorage
|
||||
public class PairTagStorage
|
||||
{
|
||||
public HashSet<string> OpenPairTags { get; set; } = new(StringComparer.Ordinal);
|
||||
public HashSet<string> ServerAvailablePairTags { get; set; } = new(StringComparer.Ordinal);
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace LightlessSync.LightlessConfiguration.Models;
|
||||
|
||||
[Serializable]
|
||||
public class SyncshellTagStorage
|
||||
{
|
||||
public HashSet<string> ServerAvailableSyncshellTags { get; set; } = new(StringComparer.Ordinal);
|
||||
public Dictionary<string, List<string>> SyncshellPairedTags { get; set; } = new(StringComparer.Ordinal);
|
||||
}
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace LightlessSync.LightlessConfiguration;
|
||||
|
||||
public class ServerTagConfigService : ConfigurationServiceBase<ServerTagConfig>
|
||||
public class PairTagConfigService : ConfigurationServiceBase<PairTagStorage>
|
||||
{
|
||||
public const string ConfigName = "servertags.json";
|
||||
|
||||
public ServerTagConfigService(string configDir) : base(configDir)
|
||||
public PairTagConfigService(string configDir) : base(configDir)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
using LightlessSync.LightlessConfiguration.Configurations;
|
||||
|
||||
namespace LightlessSync.LightlessConfiguration;
|
||||
|
||||
public class SyncshellTagConfigService : ConfigurationServiceBase<SyncshellTagStorage>
|
||||
{
|
||||
public const string ConfigName = "syncshelltags.json";
|
||||
|
||||
public SyncshellTagConfigService(string configDir) : base(configDir)
|
||||
{
|
||||
}
|
||||
|
||||
public override string ConfigurationName => ConfigName;
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
using LightlessSync.FileCache;
|
||||
using LightlessSync.FileCache;
|
||||
using LightlessSync.LightlessConfiguration;
|
||||
using LightlessSync.PlayerData.Pairs;
|
||||
using LightlessSync.PlayerData.Services;
|
||||
using LightlessSync.Services;
|
||||
using LightlessSync.Services.Mediator;
|
||||
using LightlessSync.Services.ServerConfiguration;
|
||||
using LightlessSync.UI;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -98,6 +99,7 @@ public class LightlessPlugin : MediatorSubscriberBase, IHostedService
|
||||
Mediator.Subscribe<DalamudLoginMessage>(this, (_) => DalamudUtilOnLogIn());
|
||||
Mediator.Subscribe<DalamudLogoutMessage>(this, (_) => DalamudUtilOnLogOut());
|
||||
|
||||
UIColors.Initialize(_lightlessConfigService);
|
||||
Mediator.StartQueueProcessing();
|
||||
|
||||
return Task.CompletedTask;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project Sdk="Dalamud.NET.Sdk/13.0.0">
|
||||
<Project Sdk="Dalamud.NET.Sdk/13.1.0">
|
||||
<PropertyGroup>
|
||||
<Authors></Authors>
|
||||
<Company></Company>
|
||||
<Version>1.11.4</Version>
|
||||
<Version>1.12.0</Version>
|
||||
<Description></Description>
|
||||
<Copyright></Copyright>
|
||||
<PackageProjectUrl>https://github.com/Light-Public-Syncshells/LightlessClient</PackageProjectUrl>
|
||||
|
||||
@@ -88,20 +88,30 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
|
||||
_redrawOnNextApplication = true;
|
||||
}
|
||||
});
|
||||
Mediator.Subscribe<CombatOrPerformanceEndMessage>(this, (msg) =>
|
||||
Mediator.Subscribe<CombatEndMessage>(this, (msg) =>
|
||||
{
|
||||
if (IsVisible && _dataReceivedInDowntime != null)
|
||||
{
|
||||
ApplyCharacterData(_dataReceivedInDowntime.ApplicationId,
|
||||
_dataReceivedInDowntime.CharacterData, _dataReceivedInDowntime.Forced);
|
||||
_dataReceivedInDowntime = null;
|
||||
}
|
||||
EnableSync();
|
||||
});
|
||||
Mediator.Subscribe<CombatOrPerformanceStartMessage>(this, _ =>
|
||||
Mediator.Subscribe<CombatStartMessage>(this, _ =>
|
||||
{
|
||||
_dataReceivedInDowntime = null;
|
||||
_downloadCancellationTokenSource = _downloadCancellationTokenSource?.CancelRecreate();
|
||||
_applicationCancellationTokenSource = _applicationCancellationTokenSource?.CancelRecreate();
|
||||
DisableSync();
|
||||
});
|
||||
Mediator.Subscribe<PerformanceEndMessage>(this, (msg) =>
|
||||
{
|
||||
EnableSync();
|
||||
});
|
||||
Mediator.Subscribe<PerformanceStartMessage>(this, _ =>
|
||||
{
|
||||
DisableSync();
|
||||
});
|
||||
Mediator.Subscribe<InstanceOrDutyStartMessage>(this, _ =>
|
||||
{
|
||||
DisableSync();
|
||||
});
|
||||
Mediator.Subscribe<InstanceOrDutyEndMessage>(this, (msg) =>
|
||||
{
|
||||
EnableSync();
|
||||
|
||||
});
|
||||
|
||||
LastAppliedDataBytes = -1;
|
||||
@@ -135,11 +145,31 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
|
||||
|
||||
public void ApplyCharacterData(Guid applicationBase, CharacterData characterData, bool forceApplyCustomization = false)
|
||||
{
|
||||
if (_dalamudUtil.IsInCombatOrPerforming)
|
||||
if (_dalamudUtil.IsInCombat)
|
||||
{
|
||||
Mediator.Publish(new EventMessage(new Event(PlayerName, Pair.UserData, nameof(PairHandler), EventSeverity.Warning,
|
||||
"Cannot apply character data: you are in combat or performing music, deferring application")));
|
||||
Logger.LogDebug("[BASE-{appBase}] Received data but player is in combat or performing", applicationBase);
|
||||
"Cannot apply character data: you are in combat, deferring application")));
|
||||
Logger.LogDebug("[BASE-{appBase}] Received data but player is in combat", applicationBase);
|
||||
_dataReceivedInDowntime = new(applicationBase, characterData, forceApplyCustomization);
|
||||
SetUploading(isUploading: false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_dalamudUtil.IsPerforming)
|
||||
{
|
||||
Mediator.Publish(new EventMessage(new Event(PlayerName, Pair.UserData, nameof(PairHandler), EventSeverity.Warning,
|
||||
"Cannot apply character data: you are performing music, deferring application")));
|
||||
Logger.LogDebug("[BASE-{appBase}] Received data but player is performing", applicationBase);
|
||||
_dataReceivedInDowntime = new(applicationBase, characterData, forceApplyCustomization);
|
||||
SetUploading(isUploading: false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_dalamudUtil.IsInInstance)
|
||||
{
|
||||
Mediator.Publish(new EventMessage(new Event(PlayerName, Pair.UserData, nameof(PairHandler), EventSeverity.Warning,
|
||||
"Cannot apply character data: you are in an instance, deferring application")));
|
||||
Logger.LogDebug("[BASE-{appBase}] Received data but player is in instance", applicationBase);
|
||||
_dataReceivedInDowntime = new(applicationBase, characterData, forceApplyCustomization);
|
||||
SetUploading(isUploading: false);
|
||||
return;
|
||||
@@ -716,4 +746,21 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
|
||||
Logger.LogDebug("[BASE-{appBase}] ModdedPaths calculated in {time}ms, missing files: {count}, total files: {total}", applicationBase, st.ElapsedMilliseconds, missingFiles.Count, moddedDictionary.Keys.Count);
|
||||
return [.. missingFiles];
|
||||
}
|
||||
|
||||
private void DisableSync()
|
||||
{
|
||||
_dataReceivedInDowntime = null;
|
||||
_downloadCancellationTokenSource = _downloadCancellationTokenSource?.CancelRecreate();
|
||||
_applicationCancellationTokenSource = _applicationCancellationTokenSource?.CancelRecreate();
|
||||
}
|
||||
|
||||
private void EnableSync()
|
||||
{
|
||||
if (IsVisible && _dataReceivedInDowntime != null)
|
||||
{
|
||||
ApplyCharacterData(_dataReceivedInDowntime.ApplicationId,
|
||||
_dataReceivedInDowntime.CharacterData, _dataReceivedInDowntime.Forced);
|
||||
_dataReceivedInDowntime = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,8 +72,8 @@ public class Pair
|
||||
Name = openProfileSeString,
|
||||
OnClicked = (a) => _mediator.Publish(new ProfileOpenStandaloneMessage(this)),
|
||||
UseDefaultPrefix = false,
|
||||
PrefixChar = 'M',
|
||||
PrefixColor = 526
|
||||
PrefixChar = 'L',
|
||||
PrefixColor = 708
|
||||
});
|
||||
|
||||
args.AddMenuItem(new MenuItem()
|
||||
@@ -81,8 +81,8 @@ public class Pair
|
||||
Name = reapplyDataSeString,
|
||||
OnClicked = (a) => ApplyLastReceivedData(forced: true),
|
||||
UseDefaultPrefix = false,
|
||||
PrefixChar = 'M',
|
||||
PrefixColor = 526
|
||||
PrefixChar = 'L',
|
||||
PrefixColor = 708
|
||||
});
|
||||
|
||||
args.AddMenuItem(new MenuItem()
|
||||
@@ -90,8 +90,8 @@ public class Pair
|
||||
Name = changePermissions,
|
||||
OnClicked = (a) => _mediator.Publish(new OpenPermissionWindow(this)),
|
||||
UseDefaultPrefix = false,
|
||||
PrefixChar = 'M',
|
||||
PrefixColor = 526
|
||||
PrefixChar = 'L',
|
||||
PrefixColor = 708
|
||||
});
|
||||
|
||||
args.AddMenuItem(new MenuItem()
|
||||
@@ -99,8 +99,8 @@ public class Pair
|
||||
Name = cyclePauseState,
|
||||
OnClicked = (a) => _mediator.Publish(new CyclePauseMessage(UserData)),
|
||||
UseDefaultPrefix = false,
|
||||
PrefixChar = 'M',
|
||||
PrefixColor = 526
|
||||
PrefixChar = 'L',
|
||||
PrefixColor = 708
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public sealed class Plugin : IDalamudPlugin
|
||||
IFramework framework, IObjectTable objectTable, IClientState clientState, ICondition condition, IChatGui chatGui,
|
||||
IGameGui gameGui, IDtrBar dtrBar, IPluginLog pluginLog, ITargetManager targetManager, INotificationManager notificationManager,
|
||||
ITextureProvider textureProvider, IContextMenu contextMenu, IGameInteropProvider gameInteropProvider, IGameConfig gameConfig,
|
||||
ISigScanner sigScanner, INamePlateGui namePlateGui)
|
||||
ISigScanner sigScanner, INamePlateGui namePlateGui, IAddonLifecycle addonLifecycle)
|
||||
{
|
||||
if (!Directory.Exists(pluginInterface.ConfigDirectory.FullName))
|
||||
Directory.CreateDirectory(pluginInterface.ConfigDirectory.FullName);
|
||||
@@ -90,6 +90,7 @@ public sealed class Plugin : IDalamudPlugin
|
||||
collection.AddSingleton(new WindowSystem("LightlessSync"));
|
||||
collection.AddSingleton<FileDialogManager>();
|
||||
collection.AddSingleton(new Dalamud.Localization("LightlessSync.Localization.", "", useEmbedded: true));
|
||||
collection.AddSingleton(gameGui);
|
||||
|
||||
// add lightless related singletons
|
||||
collection.AddSingleton<LightlessMediator>();
|
||||
@@ -130,17 +131,23 @@ public sealed class Plugin : IDalamudPlugin
|
||||
s.GetRequiredService<CharaDataManager>(),
|
||||
s.GetRequiredService<LightlessMediator>()));
|
||||
collection.AddSingleton<SelectPairForTagUi>();
|
||||
collection.AddSingleton<RenamePairTagUi>();
|
||||
collection.AddSingleton<SelectSyncshellForTagUi>();
|
||||
collection.AddSingleton<RenameSyncshellTagUi>();
|
||||
collection.AddSingleton((s) => new EventAggregator(pluginInterface.ConfigDirectory.FullName,
|
||||
s.GetRequiredService<ILogger<EventAggregator>>(), s.GetRequiredService<LightlessMediator>()));
|
||||
collection.AddSingleton((s) => new DalamudUtilService(s.GetRequiredService<ILogger<DalamudUtilService>>(),
|
||||
clientState, objectTable, framework, gameGui, condition, gameData, targetManager, gameConfig,
|
||||
s.GetRequiredService<BlockedCharacterHandler>(), s.GetRequiredService<LightlessMediator>(), s.GetRequiredService<PerformanceCollectorService>(),
|
||||
s.GetRequiredService<LightlessConfigService>()));
|
||||
s.GetRequiredService<LightlessConfigService>(), s.GetRequiredService<PlayerPerformanceConfigService>()));
|
||||
collection.AddSingleton((s) => new DtrEntry(s.GetRequiredService<ILogger<DtrEntry>>(), dtrBar, s.GetRequiredService<LightlessConfigService>(),
|
||||
s.GetRequiredService<LightlessMediator>(), s.GetRequiredService<PairManager>(), s.GetRequiredService<ApiController>()));
|
||||
s.GetRequiredService<LightlessMediator>(), s.GetRequiredService<PairManager>(), s.GetRequiredService<ApiController>(), s.GetRequiredService<ServerConfigurationManager>()));
|
||||
collection.AddSingleton(s => new PairManager(s.GetRequiredService<ILogger<PairManager>>(), s.GetRequiredService<PairFactory>(),
|
||||
s.GetRequiredService<LightlessConfigService>(), s.GetRequiredService<LightlessMediator>(), contextMenu));
|
||||
collection.AddSingleton<RedrawManager>();
|
||||
collection.AddSingleton<BroadcastService>();
|
||||
collection.AddSingleton(addonLifecycle);
|
||||
collection.AddSingleton(p => new ContextMenu(contextMenu, pluginInterface, gameData, p.GetRequiredService<ILogger<ContextMenu>>(), p.GetRequiredService<DalamudUtilService>(), p.GetRequiredService<ApiController>(), objectTable));
|
||||
collection.AddSingleton((s) => new IpcCallerPenumbra(s.GetRequiredService<ILogger<IpcCallerPenumbra>>(), pluginInterface,
|
||||
s.GetRequiredService<DalamudUtilService>(), s.GetRequiredService<LightlessMediator>(), s.GetRequiredService<RedrawManager>()));
|
||||
collection.AddSingleton((s) => new IpcCallerGlamourer(s.GetRequiredService<ILogger<IpcCallerGlamourer>>(), pluginInterface,
|
||||
@@ -171,10 +178,16 @@ public sealed class Plugin : IDalamudPlugin
|
||||
httpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("LightlessSync", ver!.Major + "." + ver!.Minor + "." + ver!.Build));
|
||||
return httpClient;
|
||||
});
|
||||
collection.AddSingleton((s) => new LightlessConfigService(pluginInterface.ConfigDirectory.FullName));
|
||||
collection.AddSingleton((s) =>
|
||||
{
|
||||
var cfg = new LightlessConfigService(pluginInterface.ConfigDirectory.FullName);
|
||||
LightlessSync.UI.Style.MainStyle.Init(cfg);
|
||||
return cfg;
|
||||
});
|
||||
collection.AddSingleton((s) => new ServerConfigService(pluginInterface.ConfigDirectory.FullName));
|
||||
collection.AddSingleton((s) => new NotesConfigService(pluginInterface.ConfigDirectory.FullName));
|
||||
collection.AddSingleton((s) => new ServerTagConfigService(pluginInterface.ConfigDirectory.FullName));
|
||||
collection.AddSingleton((s) => new PairTagConfigService(pluginInterface.ConfigDirectory.FullName));
|
||||
collection.AddSingleton((s) => new SyncshellTagConfigService(pluginInterface.ConfigDirectory.FullName));
|
||||
collection.AddSingleton((s) => new TransientConfigService(pluginInterface.ConfigDirectory.FullName));
|
||||
collection.AddSingleton((s) => new XivDataStorageService(pluginInterface.ConfigDirectory.FullName));
|
||||
collection.AddSingleton((s) => new PlayerPerformanceConfigService(pluginInterface.ConfigDirectory.FullName));
|
||||
@@ -182,21 +195,25 @@ public sealed class Plugin : IDalamudPlugin
|
||||
collection.AddSingleton<IConfigService<ILightlessConfiguration>>(s => s.GetRequiredService<LightlessConfigService>());
|
||||
collection.AddSingleton<IConfigService<ILightlessConfiguration>>(s => s.GetRequiredService<ServerConfigService>());
|
||||
collection.AddSingleton<IConfigService<ILightlessConfiguration>>(s => s.GetRequiredService<NotesConfigService>());
|
||||
collection.AddSingleton<IConfigService<ILightlessConfiguration>>(s => s.GetRequiredService<ServerTagConfigService>());
|
||||
collection.AddSingleton<IConfigService<ILightlessConfiguration>>(s => s.GetRequiredService<PairTagConfigService>());
|
||||
collection.AddSingleton<IConfigService<ILightlessConfiguration>>(s => s.GetRequiredService<SyncshellTagConfigService>());
|
||||
collection.AddSingleton<IConfigService<ILightlessConfiguration>>(s => s.GetRequiredService<TransientConfigService>());
|
||||
collection.AddSingleton<IConfigService<ILightlessConfiguration>>(s => s.GetRequiredService<XivDataStorageService>());
|
||||
collection.AddSingleton<IConfigService<ILightlessConfiguration>>(s => s.GetRequiredService<PlayerPerformanceConfigService>());
|
||||
collection.AddSingleton<IConfigService<ILightlessConfiguration>>(s => s.GetRequiredService<CharaDataConfigService>());
|
||||
collection.AddSingleton<ConfigurationMigrator>();
|
||||
collection.AddSingleton<ConfigurationSaveService>();
|
||||
|
||||
collection.AddSingleton<HubFactory>();
|
||||
collection.AddSingleton<NameplateHandler>();
|
||||
collection.AddSingleton(s => new BroadcastScannerService( s.GetRequiredService<ILogger<BroadcastScannerService>>(), clientState, objectTable, framework, s.GetRequiredService<BroadcastService>(), s.GetRequiredService<LightlessMediator>(), s.GetRequiredService<NameplateHandler>(), s.GetRequiredService<DalamudUtilService>(), s.GetRequiredService<LightlessConfigService>()));
|
||||
|
||||
|
||||
// add scoped services
|
||||
collection.AddScoped<DrawEntityFactory>();
|
||||
collection.AddScoped<CacheMonitor>();
|
||||
collection.AddScoped<UiFactory>();
|
||||
collection.AddScoped<SelectTagForPairUi>();
|
||||
collection.AddScoped<SelectTagForSyncshellUi>();
|
||||
collection.AddScoped<WindowMediatorSubscriberBase, SettingsUi>();
|
||||
collection.AddScoped<WindowMediatorSubscriberBase, CompactUi>();
|
||||
collection.AddScoped<WindowMediatorSubscriberBase, IntroUi>();
|
||||
@@ -212,6 +229,8 @@ public sealed class Plugin : IDalamudPlugin
|
||||
s.GetRequiredService<LightlessMediator>(), s.GetRequiredService<ApiController>(), s.GetRequiredService<UiSharedService>(), s.GetRequiredService<FileDialogManager>(),
|
||||
s.GetRequiredService<LightlessProfileManager>(), s.GetRequiredService<PerformanceCollectorService>()));
|
||||
collection.AddScoped<WindowMediatorSubscriberBase, PopupHandler>();
|
||||
collection.AddScoped<WindowMediatorSubscriberBase, BroadcastUI>((s) => new BroadcastUI(s.GetRequiredService<ILogger<BroadcastUI>>(), s.GetRequiredService<LightlessMediator>(), s.GetRequiredService<PerformanceCollectorService>(), s.GetRequiredService<BroadcastService>(), s.GetRequiredService<LightlessConfigService>(), s.GetRequiredService<UiSharedService>(), s.GetRequiredService<ApiController>(), s.GetRequiredService<BroadcastScannerService>()));
|
||||
collection.AddScoped<WindowMediatorSubscriberBase, SyncshellFinderUI>((s) => new SyncshellFinderUI(s.GetRequiredService<ILogger<SyncshellFinderUI>>(), s.GetRequiredService<LightlessMediator>(), s.GetRequiredService<PerformanceCollectorService>(), s.GetRequiredService<BroadcastService>(), s.GetRequiredService<LightlessConfigService>(), s.GetRequiredService<UiSharedService>(), s.GetRequiredService<ApiController>(), s.GetRequiredService<BroadcastScannerService>()));
|
||||
collection.AddScoped<IPopupHandler, BanUserPopupHandler>();
|
||||
collection.AddScoped<IPopupHandler, CensusPopupHandler>();
|
||||
collection.AddScoped<CacheCreationService>();
|
||||
@@ -242,6 +261,8 @@ public sealed class Plugin : IDalamudPlugin
|
||||
collection.AddHostedService(p => p.GetRequiredService<EventAggregator>());
|
||||
collection.AddHostedService(p => p.GetRequiredService<IpcProvider>());
|
||||
collection.AddHostedService(p => p.GetRequiredService<LightlessPlugin>());
|
||||
collection.AddHostedService(p => p.GetRequiredService<ContextMenu>());
|
||||
collection.AddHostedService(p => p.GetRequiredService<BroadcastService>());
|
||||
})
|
||||
.Build();
|
||||
|
||||
|
||||
222
LightlessSync/Services/BroadcastScanningService.cs
Normal file
222
LightlessSync/Services/BroadcastScanningService.cs
Normal file
@@ -0,0 +1,222 @@
|
||||
using Dalamud.Game.ClientState.Objects.SubKinds;
|
||||
using Dalamud.Plugin.Services;
|
||||
using LightlessSync.API.Dto.User;
|
||||
using LightlessSync.LightlessConfiguration;
|
||||
using LightlessSync.Services.Mediator;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace LightlessSync.Services;
|
||||
|
||||
public class BroadcastScannerService : DisposableMediatorSubscriberBase, IDisposable
|
||||
{
|
||||
private readonly ILogger<BroadcastScannerService> _logger;
|
||||
private readonly IObjectTable _objectTable;
|
||||
private readonly IFramework _framework;
|
||||
|
||||
private readonly BroadcastService _broadcastService;
|
||||
private readonly NameplateHandler _nameplateHandler;
|
||||
|
||||
private readonly ConcurrentDictionary<string, BroadcastEntry> _broadcastCache = new();
|
||||
private readonly Queue<string> _lookupQueue = new();
|
||||
private readonly HashSet<string> _lookupQueuedCids = new();
|
||||
private readonly HashSet<string> _syncshellCids = new();
|
||||
|
||||
private static readonly TimeSpan MaxAllowedTtl = TimeSpan.FromMinutes(4);
|
||||
private static readonly TimeSpan RetryDelay = TimeSpan.FromMinutes(1);
|
||||
|
||||
private readonly CancellationTokenSource _cleanupCts = new();
|
||||
private Task? _cleanupTask;
|
||||
|
||||
private int _checkEveryFrames = 20;
|
||||
private int _frameCounter = 0;
|
||||
private int _lookupsThisFrame = 0;
|
||||
private const int MaxLookupsPerFrame = 30;
|
||||
private const int MaxQueueSize = 100;
|
||||
|
||||
private volatile bool _batchRunning = false;
|
||||
|
||||
public IReadOnlyDictionary<string, BroadcastEntry> BroadcastCache => _broadcastCache;
|
||||
public readonly record struct BroadcastEntry(bool IsBroadcasting, DateTime ExpiryTime, string? GID);
|
||||
|
||||
public BroadcastScannerService(ILogger<BroadcastScannerService> logger,
|
||||
IClientState clientState,
|
||||
IObjectTable objectTable,
|
||||
IFramework framework,
|
||||
BroadcastService broadcastService,
|
||||
LightlessMediator mediator,
|
||||
NameplateHandler nameplateHandler,
|
||||
DalamudUtilService dalamudUtil,
|
||||
LightlessConfigService configService) : base(logger, mediator)
|
||||
{
|
||||
_logger = logger;
|
||||
_objectTable = objectTable;
|
||||
_broadcastService = broadcastService;
|
||||
_nameplateHandler = nameplateHandler;
|
||||
|
||||
_logger = logger;
|
||||
_framework = framework;
|
||||
_framework.Update += OnFrameworkUpdate;
|
||||
|
||||
Mediator.Subscribe<BroadcastStatusChangedMessage>(this, OnBroadcastStatusChanged);
|
||||
_cleanupTask = Task.Run(ExpiredBroadcastCleanupLoop);
|
||||
|
||||
_nameplateHandler.Init();
|
||||
}
|
||||
|
||||
private void OnFrameworkUpdate(IFramework framework) => Update();
|
||||
|
||||
public void Update()
|
||||
{
|
||||
_frameCounter++;
|
||||
_lookupsThisFrame = 0;
|
||||
|
||||
if (!_broadcastService.IsBroadcasting)
|
||||
return;
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
|
||||
foreach (var obj in _objectTable)
|
||||
{
|
||||
if (obj is not IPlayerCharacter player || player.Address == IntPtr.Zero)
|
||||
continue;
|
||||
|
||||
var cid = DalamudUtilService.GetHashedCIDFromPlayerPointer(player.Address);
|
||||
var isStale = !_broadcastCache.TryGetValue(cid, out var entry) || entry.ExpiryTime <= now;
|
||||
|
||||
if (isStale && _lookupQueuedCids.Add(cid) && _lookupQueue.Count < MaxQueueSize)
|
||||
_lookupQueue.Enqueue(cid);
|
||||
}
|
||||
|
||||
if (_frameCounter % _checkEveryFrames == 0 && _lookupQueue.Count > 0)
|
||||
{
|
||||
var cidsToLookup = new List<string>();
|
||||
while (_lookupQueue.Count > 0 && _lookupsThisFrame < MaxLookupsPerFrame)
|
||||
{
|
||||
var cid = _lookupQueue.Dequeue();
|
||||
_lookupQueuedCids.Remove(cid);
|
||||
cidsToLookup.Add(cid);
|
||||
_lookupsThisFrame++;
|
||||
}
|
||||
|
||||
if (cidsToLookup.Count > 0 && !_batchRunning)
|
||||
{
|
||||
_batchRunning = true;
|
||||
_ = BatchUpdateBroadcastCacheAsync(cidsToLookup).ContinueWith(_ => _batchRunning = false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task BatchUpdateBroadcastCacheAsync(List<string> cids)
|
||||
{
|
||||
var results = await _broadcastService.AreUsersBroadcastingAsync(cids).ConfigureAwait(false);
|
||||
var now = DateTime.UtcNow;
|
||||
|
||||
foreach (var (cid, info) in results)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(cid) || info == null)
|
||||
continue;
|
||||
|
||||
var ttl = info.IsBroadcasting && info.TTL.HasValue
|
||||
? TimeSpan.FromTicks(Math.Min(info.TTL.Value.Ticks, MaxAllowedTtl.Ticks))
|
||||
: RetryDelay;
|
||||
|
||||
var expiry = now + ttl;
|
||||
|
||||
_broadcastCache.AddOrUpdate(cid,
|
||||
new BroadcastEntry(info.IsBroadcasting, expiry, info.GID),
|
||||
(_, old) => new BroadcastEntry(info.IsBroadcasting, expiry, info.GID));
|
||||
}
|
||||
|
||||
var activeCids = _broadcastCache
|
||||
.Where(e => e.Value.IsBroadcasting && e.Value.ExpiryTime > now)
|
||||
.Select(e => e.Key)
|
||||
.ToList();
|
||||
|
||||
_nameplateHandler.UpdateBroadcastingCids(activeCids);
|
||||
UpdateSyncshellBroadcasts();
|
||||
}
|
||||
|
||||
private void OnBroadcastStatusChanged(BroadcastStatusChangedMessage msg)
|
||||
{
|
||||
if (!msg.Enabled)
|
||||
{
|
||||
_broadcastCache.Clear();
|
||||
_lookupQueue.Clear();
|
||||
_lookupQueuedCids.Clear();
|
||||
_syncshellCids.Clear();
|
||||
|
||||
_nameplateHandler.UpdateBroadcastingCids(Enumerable.Empty<string>());
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateSyncshellBroadcasts()
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
var newSet = _broadcastCache
|
||||
.Where(e => e.Value.IsBroadcasting && e.Value.ExpiryTime > now && !string.IsNullOrEmpty(e.Value.GID))
|
||||
.Select(e => e.Key)
|
||||
.ToHashSet();
|
||||
|
||||
if (!_syncshellCids.SetEquals(newSet))
|
||||
{
|
||||
_syncshellCids.Clear();
|
||||
foreach (var cid in newSet)
|
||||
_syncshellCids.Add(cid);
|
||||
|
||||
Mediator.Publish(new SyncshellBroadcastsUpdatedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public List<BroadcastStatusInfoDto> GetActiveSyncshellBroadcasts()
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
|
||||
return _broadcastCache
|
||||
.Where(e => e.Value.IsBroadcasting && e.Value.ExpiryTime > now && !string.IsNullOrEmpty(e.Value.GID))
|
||||
.Select(e => new BroadcastStatusInfoDto
|
||||
{
|
||||
HashedCID = e.Key,
|
||||
IsBroadcasting = true,
|
||||
TTL = e.Value.ExpiryTime - now,
|
||||
GID = e.Value.GID
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private async Task ExpiredBroadcastCleanupLoop()
|
||||
{
|
||||
var token = _cleanupCts.Token;
|
||||
|
||||
try
|
||||
{
|
||||
while (!token.IsCancellationRequested)
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(10), token);
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
foreach (var (cid, entry) in _broadcastCache.ToArray())
|
||||
{
|
||||
if (entry.ExpiryTime <= now)
|
||||
_broadcastCache.TryRemove(cid, out _);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException) { }
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Broadcast cleanup loop crashed");
|
||||
}
|
||||
|
||||
UpdateSyncshellBroadcasts();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
_framework.Update -= OnFrameworkUpdate;
|
||||
_cleanupCts.Cancel();
|
||||
_cleanupTask?.Wait(100);
|
||||
_nameplateHandler.Uninit();
|
||||
}
|
||||
}
|
||||
378
LightlessSync/Services/BroadcastService.cs
Normal file
378
LightlessSync/Services/BroadcastService.cs
Normal file
@@ -0,0 +1,378 @@
|
||||
using LightlessSync.API.Dto.Group;
|
||||
using LightlessSync.API.Dto.User;
|
||||
using LightlessSync.LightlessConfiguration;
|
||||
using LightlessSync.Services.Mediator;
|
||||
using LightlessSync.Utils;
|
||||
using LightlessSync.WebAPI;
|
||||
using LightlessSync.WebAPI.SignalR;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.AspNetCore.SignalR.Client;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace LightlessSync.Services;
|
||||
public class BroadcastService : IHostedService, IMediatorSubscriber
|
||||
{
|
||||
private readonly ILogger<BroadcastService> _logger;
|
||||
private readonly ApiController _apiController;
|
||||
private readonly LightlessMediator _mediator;
|
||||
private readonly HubFactory _hubFactory;
|
||||
private readonly LightlessConfigService _config;
|
||||
private readonly DalamudUtilService _dalamudUtil;
|
||||
public LightlessMediator Mediator => _mediator;
|
||||
|
||||
public bool IsLightFinderAvailable { get; private set; } = true;
|
||||
|
||||
public bool IsBroadcasting => _config.Current.BroadcastEnabled;
|
||||
private bool _syncedOnStartup = false;
|
||||
private bool _waitingForTtlFetch = false;
|
||||
private TimeSpan? _remainingTtl = null;
|
||||
private DateTime _lastTtlCheck = DateTime.MinValue;
|
||||
private DateTime _lastForcedDisableTime = DateTime.MinValue;
|
||||
private static readonly TimeSpan DisableCooldown = TimeSpan.FromSeconds(5);
|
||||
public TimeSpan? RemainingTtl => _remainingTtl;
|
||||
public TimeSpan? RemainingCooldown
|
||||
{
|
||||
get
|
||||
{
|
||||
var elapsed = DateTime.UtcNow - _lastForcedDisableTime;
|
||||
if (elapsed >= DisableCooldown) return null;
|
||||
return DisableCooldown - elapsed;
|
||||
}
|
||||
}
|
||||
public BroadcastService(ILogger<BroadcastService> logger, LightlessMediator mediator, HubFactory hubFactory, LightlessConfigService config, DalamudUtilService dalamudUtil, ApiController apiController)
|
||||
{
|
||||
_logger = logger;
|
||||
_mediator = mediator;
|
||||
_hubFactory = hubFactory;
|
||||
_config = config;
|
||||
_dalamudUtil = dalamudUtil;
|
||||
_apiController = apiController;
|
||||
}
|
||||
private async Task RequireConnectionAsync(string context, Func<Task> action)
|
||||
{
|
||||
if (!_apiController.IsConnected)
|
||||
{
|
||||
_logger.LogDebug($"{context} skipped, not connected");
|
||||
return;
|
||||
}
|
||||
await action().ConfigureAwait(false);
|
||||
}
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_mediator.Subscribe<EnableBroadcastMessage>(this, OnEnableBroadcast);
|
||||
_mediator.Subscribe<BroadcastStatusChangedMessage>(this, OnBroadcastStatusChanged);
|
||||
_mediator.Subscribe<PriorityFrameworkUpdateMessage>(this, OnTick);
|
||||
|
||||
_apiController.OnConnected += () => _ = CheckLightfinderSupportAsync(cancellationToken);
|
||||
_ = CheckLightfinderSupportAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_mediator.UnsubscribeAll(this);
|
||||
_apiController.OnConnected -= () => _ = CheckLightfinderSupportAsync(cancellationToken);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
// need to rework this, this is cooked
|
||||
private async Task CheckLightfinderSupportAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
while (!_apiController.IsConnected && !cancellationToken.IsCancellationRequested)
|
||||
await Task.Delay(250, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
var hub = _hubFactory.GetOrCreate(CancellationToken.None);
|
||||
var dummy = "0".PadLeft(64, '0');
|
||||
|
||||
await hub.InvokeAsync<BroadcastStatusInfoDto?>("IsUserBroadcasting", dummy, cancellationToken);
|
||||
await hub.InvokeAsync("SetBroadcastStatus", dummy, true, null, cancellationToken);
|
||||
await hub.InvokeAsync<TimeSpan?>("GetBroadcastTtl", dummy, cancellationToken);
|
||||
await hub.InvokeAsync<Dictionary<string, BroadcastStatusInfoDto?>>("AreUsersBroadcasting", new[] { dummy }, cancellationToken);
|
||||
|
||||
IsLightFinderAvailable = true;
|
||||
_logger.LogInformation("Lightfinder is available.");
|
||||
}
|
||||
catch (HubException ex) when (ex.Message.Contains("Method does not exist"))
|
||||
{
|
||||
_logger.LogWarning("Lightfinder unavailable: required method missing.");
|
||||
IsLightFinderAvailable = false;
|
||||
|
||||
_config.Current.BroadcastEnabled = false;
|
||||
_config.Current.BroadcastTtl = DateTime.MinValue;
|
||||
_config.Save();
|
||||
_mediator.Publish(new BroadcastStatusChangedMessage(false, null));
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
_logger.LogInformation("Lightfinder check was canceled.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Lightfinder check failed.");
|
||||
IsLightFinderAvailable = false;
|
||||
|
||||
_config.Current.BroadcastEnabled = false;
|
||||
_config.Current.BroadcastTtl = DateTime.MinValue;
|
||||
_config.Save();
|
||||
_mediator.Publish(new BroadcastStatusChangedMessage(false, null));
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnableBroadcast(EnableBroadcastMessage msg)
|
||||
{
|
||||
_ = RequireConnectionAsync(nameof(OnEnableBroadcast), async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
GroupBroadcastRequestDto? groupDto = null;
|
||||
if (_config.Current.SyncshellFinderEnabled && _config.Current.SelectedFinderSyncshell != null)
|
||||
{
|
||||
groupDto = new GroupBroadcastRequestDto
|
||||
{
|
||||
HashedCID = msg.HashedCid,
|
||||
GID = _config.Current.SelectedFinderSyncshell,
|
||||
Enabled = msg.Enabled,
|
||||
};
|
||||
}
|
||||
|
||||
await _apiController.SetBroadcastStatus(msg.HashedCid, msg.Enabled, groupDto).ConfigureAwait(false);
|
||||
|
||||
_logger.LogInformation("Broadcast {Status} for {Cid}", msg.Enabled ? "enabled" : "disabled", msg.HashedCid);
|
||||
|
||||
if (!msg.Enabled)
|
||||
{
|
||||
_config.Current.BroadcastEnabled = false;
|
||||
_config.Current.BroadcastTtl = DateTime.MinValue;
|
||||
_config.Save();
|
||||
|
||||
_mediator.Publish(new BroadcastStatusChangedMessage(false, null));
|
||||
Mediator.Publish(new EventMessage(new Services.Events.Event(nameof(BroadcastService), Services.Events.EventSeverity.Informational,$"Disabled Lightfinder for Player: {msg.HashedCid}")));
|
||||
return;
|
||||
}
|
||||
|
||||
_waitingForTtlFetch = true;
|
||||
|
||||
var ttl = await GetBroadcastTtlAsync(msg.HashedCid).ConfigureAwait(false);
|
||||
|
||||
if (ttl is { } remaining && remaining > TimeSpan.Zero)
|
||||
{
|
||||
_config.Current.BroadcastTtl = DateTime.UtcNow + remaining;
|
||||
_config.Current.BroadcastEnabled = true;
|
||||
_config.Save();
|
||||
|
||||
_logger.LogInformation("Fetched TTL from server: {TTL}", remaining);
|
||||
_mediator.Publish(new BroadcastStatusChangedMessage(true, remaining));
|
||||
Mediator.Publish(new EventMessage(new Services.Events.Event(nameof(BroadcastService), Services.Events.EventSeverity.Informational, $"Enabled Lightfinder for Player: {msg.HashedCid}")));
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("No valid TTL returned after enabling broadcast. Disabling.");
|
||||
_config.Current.BroadcastEnabled = false;
|
||||
_config.Current.BroadcastTtl = DateTime.MinValue;
|
||||
_config.Save();
|
||||
|
||||
_mediator.Publish(new BroadcastStatusChangedMessage(false, null));
|
||||
}
|
||||
|
||||
_waitingForTtlFetch = false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to toggle broadcast for {Cid}", msg.HashedCid);
|
||||
_waitingForTtlFetch = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void OnBroadcastStatusChanged(BroadcastStatusChangedMessage msg)
|
||||
{
|
||||
_config.Current.BroadcastEnabled = msg.Enabled;
|
||||
_config.Save();
|
||||
}
|
||||
|
||||
public async Task<bool> CheckIfBroadcastingAsync(string targetCid)
|
||||
{
|
||||
bool result = false;
|
||||
await RequireConnectionAsync(nameof(CheckIfBroadcastingAsync), async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("[BroadcastCheck] Checking CID: {cid}", targetCid);
|
||||
|
||||
var info = await _apiController.IsUserBroadcasting(targetCid).ConfigureAwait(false);
|
||||
result = info?.TTL > TimeSpan.Zero;
|
||||
|
||||
|
||||
_logger.LogInformation("[BroadcastCheck] Result for {cid}: {result} (TTL: {ttl}, GID: {gid})", targetCid, result, info?.TTL, info?.GID);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Failed to check broadcast status for {cid}", targetCid);
|
||||
}
|
||||
}).ConfigureAwait(false);
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<TimeSpan?> GetBroadcastTtlAsync(string cid)
|
||||
{
|
||||
TimeSpan? ttl = null;
|
||||
await RequireConnectionAsync(nameof(GetBroadcastTtlAsync), async () => {
|
||||
try
|
||||
{
|
||||
ttl = await _apiController.GetBroadcastTtl(cid).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Failed to fetch broadcast TTL for {cid}", cid);
|
||||
}
|
||||
}).ConfigureAwait(false);
|
||||
return ttl;
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, BroadcastStatusInfoDto?>> AreUsersBroadcastingAsync(List<string> hashedCids)
|
||||
{
|
||||
Dictionary<string, BroadcastStatusInfoDto?> result = new();
|
||||
|
||||
await RequireConnectionAsync(nameof(AreUsersBroadcastingAsync), async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var batch = await _apiController.AreUsersBroadcasting(hashedCids).ConfigureAwait(false);
|
||||
|
||||
if (batch?.Results != null)
|
||||
{
|
||||
foreach (var kv in batch.Results)
|
||||
result[kv.Key] = kv.Value;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Batch broadcast status check complete for {Count} CIDs", hashedCids.Count);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Failed to batch check broadcast status");
|
||||
}
|
||||
}).ConfigureAwait(false);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async void ToggleBroadcast()
|
||||
{
|
||||
if (!IsLightFinderAvailable)
|
||||
{
|
||||
_logger.LogWarning("ToggleBroadcast - Lightfinder is not available.");
|
||||
return;
|
||||
}
|
||||
|
||||
await RequireConnectionAsync(nameof(ToggleBroadcast), async () =>
|
||||
{
|
||||
var cooldown = RemainingCooldown;
|
||||
if (!_config.Current.BroadcastEnabled && cooldown is { } cd && cd > TimeSpan.Zero)
|
||||
{
|
||||
_logger.LogWarning("Cooldown active. Must wait {Remaining}s before re-enabling.", cd.TotalSeconds);
|
||||
return;
|
||||
}
|
||||
|
||||
var hashedCid = (await _dalamudUtil.GetCIDAsync().ConfigureAwait(false)).ToString().GetHash256();
|
||||
|
||||
try
|
||||
{
|
||||
var isCurrentlyBroadcasting = await CheckIfBroadcastingAsync(hashedCid).ConfigureAwait(false);
|
||||
var newStatus = !isCurrentlyBroadcasting;
|
||||
|
||||
if (!newStatus)
|
||||
{
|
||||
_lastForcedDisableTime = DateTime.UtcNow;
|
||||
_logger.LogInformation("Manual disable: cooldown timer started.");
|
||||
}
|
||||
|
||||
_logger.LogInformation("Toggling broadcast. Server currently broadcasting: {ServerStatus}, setting to: {NewStatus}", isCurrentlyBroadcasting, newStatus);
|
||||
|
||||
_mediator.Publish(new EnableBroadcastMessage(hashedCid, newStatus));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to determine current broadcast status for toggle");
|
||||
}
|
||||
}).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async void OnTick(PriorityFrameworkUpdateMessage _)
|
||||
{
|
||||
if (!IsLightFinderAvailable)
|
||||
return;
|
||||
|
||||
if (_config?.Current == null)
|
||||
return;
|
||||
|
||||
if ((DateTime.UtcNow - _lastTtlCheck).TotalSeconds < 1)
|
||||
return;
|
||||
|
||||
_lastTtlCheck = DateTime.UtcNow;
|
||||
|
||||
await RequireConnectionAsync(nameof(OnTick), async () => {
|
||||
if (!_syncedOnStartup && _config.Current.BroadcastEnabled)
|
||||
{
|
||||
_syncedOnStartup = true;
|
||||
try
|
||||
{
|
||||
var hashedCid = (await _dalamudUtil.GetCIDAsync().ConfigureAwait(false)).ToString().GetHash256();
|
||||
var ttl = await GetBroadcastTtlAsync(hashedCid).ConfigureAwait(false);
|
||||
if (ttl is { }
|
||||
remaining && remaining > TimeSpan.Zero)
|
||||
{
|
||||
_config.Current.BroadcastTtl = DateTime.UtcNow + remaining;
|
||||
_config.Current.BroadcastEnabled = true;
|
||||
_config.Save();
|
||||
_logger.LogInformation("Refreshed broadcast TTL from server on first OnTick: {TTL}", remaining);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("No valid TTL found on OnTick. Disabling broadcast state.");
|
||||
_config.Current.BroadcastEnabled = false;
|
||||
_config.Current.BroadcastTtl = DateTime.MinValue;
|
||||
_config.Save();
|
||||
_mediator.Publish(new BroadcastStatusChangedMessage(false, null));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to refresh TTL in OnTick");
|
||||
}
|
||||
}
|
||||
if (_config.Current.BroadcastEnabled)
|
||||
{
|
||||
if (_waitingForTtlFetch)
|
||||
{
|
||||
_logger.LogDebug("OnTick skipped: waiting for TTL fetch");
|
||||
return;
|
||||
}
|
||||
|
||||
var expiry = _config.Current.BroadcastTtl;
|
||||
var remaining = expiry - DateTime.UtcNow;
|
||||
_remainingTtl = remaining > TimeSpan.Zero ? remaining : null;
|
||||
if (_remainingTtl == null)
|
||||
{
|
||||
_logger.LogInformation("Broadcast TTL expired. Disabling broadcast locally.");
|
||||
_config.Current.BroadcastEnabled = false;
|
||||
_config.Current.BroadcastTtl = DateTime.MinValue;
|
||||
_config.Save();
|
||||
_mediator.Publish(new BroadcastStatusChangedMessage(false, null));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_remainingTtl = null;
|
||||
}
|
||||
}).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
@@ -944,9 +944,7 @@ public sealed partial class CharaDataManager : DisposableMediatorSubscriberBase
|
||||
|
||||
Logger.LogTrace("[{appId}] Computing local missing files", applicationId);
|
||||
|
||||
Dictionary<string, string> modPaths;
|
||||
List<FileReplacementData> missingFiles;
|
||||
_fileHandler.ComputeMissingFiles(charaDataDownloadDto, out modPaths, out missingFiles);
|
||||
_fileHandler.ComputeMissingFiles(charaDataDownloadDto, out Dictionary<string, string> modPaths, out List<FileReplacementData> missingFiles);
|
||||
|
||||
Logger.LogTrace("[{appId}] Computing local missing files", applicationId);
|
||||
|
||||
@@ -990,7 +988,7 @@ public sealed partial class CharaDataManager : DisposableMediatorSubscriberBase
|
||||
{
|
||||
_uploadCts = _uploadCts.CancelRecreate();
|
||||
var missingFiles = await _fileHandler.UploadFiles([.. missingFileList.Select(k => k.HashOrFileSwap)], UploadProgress, _uploadCts.Token).ConfigureAwait(false);
|
||||
if (missingFiles.Any())
|
||||
if (missingFiles.Count != 0)
|
||||
{
|
||||
Logger.LogInformation("Failed to upload {files}", string.Join(", ", missingFiles));
|
||||
return ($"Upload failed: {missingFiles.Count} missing or forbidden to upload local files.", false);
|
||||
|
||||
@@ -236,7 +236,7 @@ public sealed class CharaDataNearbyManager : DisposableMediatorSubscriberBase
|
||||
}
|
||||
}
|
||||
|
||||
if (_charaDataConfigService.Current.NearbyDrawWisps && !_dalamudUtilService.IsInGpose && !_dalamudUtilService.IsInCombatOrPerforming)
|
||||
if (_charaDataConfigService.Current.NearbyDrawWisps && !_dalamudUtilService.IsInGpose && !_dalamudUtilService.IsInCombat && !_dalamudUtilService.IsPerforming && !_dalamudUtilService.IsInInstance)
|
||||
await _dalamudUtilService.RunOnFrameworkThread(() => ManageWispsNearby(previousPoses)).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ public sealed class CharaDataNearbyManager : DisposableMediatorSubscriberBase
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_charaDataConfigService.Current.NearbyDrawWisps || _dalamudUtilService.IsInGpose || _dalamudUtilService.IsInCombatOrPerforming)
|
||||
if (!_charaDataConfigService.Current.NearbyDrawWisps || _dalamudUtilService.IsInGpose || _dalamudUtilService.IsInCombat || _dalamudUtilService.IsPerforming || _dalamudUtilService.IsInInstance)
|
||||
ClearAllVfx();
|
||||
|
||||
var camera = CameraManager.Instance()->CurrentCamera;
|
||||
|
||||
@@ -39,6 +39,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
||||
private readonly IObjectTable _objectTable;
|
||||
private readonly PerformanceCollectorService _performanceCollector;
|
||||
private readonly LightlessConfigService _configService;
|
||||
private readonly PlayerPerformanceConfigService _playerPerformanceConfigService;
|
||||
private uint? _classJobId = 0;
|
||||
private DateTime _delayedFrameworkUpdateCheck = DateTime.UtcNow;
|
||||
private string _lastGlobalBlockPlayer = string.Empty;
|
||||
@@ -52,7 +53,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
||||
public DalamudUtilService(ILogger<DalamudUtilService> logger, IClientState clientState, IObjectTable objectTable, IFramework framework,
|
||||
IGameGui gameGui, ICondition condition, IDataManager gameData, ITargetManager targetManager, IGameConfig gameConfig,
|
||||
BlockedCharacterHandler blockedCharacterHandler, LightlessMediator mediator, PerformanceCollectorService performanceCollector,
|
||||
LightlessConfigService configService)
|
||||
LightlessConfigService configService, PlayerPerformanceConfigService playerPerformanceConfigService)
|
||||
{
|
||||
_logger = logger;
|
||||
_clientState = clientState;
|
||||
@@ -66,6 +67,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
||||
Mediator = mediator;
|
||||
_performanceCollector = performanceCollector;
|
||||
_configService = configService;
|
||||
_playerPerformanceConfigService = playerPerformanceConfigService;
|
||||
WorldData = new(() =>
|
||||
{
|
||||
return gameData.GetExcelSheet<Lumina.Excel.Sheets.World>(Dalamud.Game.ClientLanguage.English)!
|
||||
@@ -160,7 +162,9 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
||||
public bool IsLoggedIn { get; private set; }
|
||||
public bool IsOnFrameworkThread => _framework.IsInFrameworkUpdateThread;
|
||||
public bool IsZoning => _condition[ConditionFlag.BetweenAreas] || _condition[ConditionFlag.BetweenAreas51];
|
||||
public bool IsInCombatOrPerforming { get; private set; } = false;
|
||||
public bool IsInCombat { get; private set; } = false;
|
||||
public bool IsPerforming { get; private set; } = false;
|
||||
public bool IsInInstance { get; private set; } = false;
|
||||
public bool HasModifiedGameFiles => _gameData.HasModifiedGameDataFiles;
|
||||
public uint ClassJobId => _classJobId!.Value;
|
||||
public Lazy<Dictionary<uint, string>> JobData { get; private set; }
|
||||
@@ -309,7 +313,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
||||
return await RunOnFrameworkThread(() => _cid.Value.ToString().GetHash256()).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private unsafe static string GetHashedCIDFromPlayerPointer(nint ptr)
|
||||
public unsafe static string GetHashedCIDFromPlayerPointer(nint ptr)
|
||||
{
|
||||
return ((BattleChara*)ptr)->Character.ContentId.ToString().GetHash256();
|
||||
}
|
||||
@@ -417,6 +421,16 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
||||
return await RunOnFrameworkThread(() => IsObjectPresent(obj)).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public IPlayerCharacter? GetPlayerByNameAndWorld(string name, ushort homeWorldId)
|
||||
{
|
||||
EnsureIsOnFramework();
|
||||
return _objectTable
|
||||
.OfType<IPlayerCharacter>()
|
||||
.FirstOrDefault(p =>
|
||||
string.Equals(p.Name.TextValue, name, StringComparison.Ordinal) &&
|
||||
p.HomeWorld.RowId == homeWorldId);
|
||||
}
|
||||
|
||||
public async Task RunOnFrameworkThread(System.Action act, [CallerMemberName] string callerMember = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumber = 0)
|
||||
{
|
||||
var fileName = Path.GetFileNameWithoutExtension(callerFilePath);
|
||||
@@ -667,19 +681,47 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
||||
Mediator.Publish(new GposeEndMessage());
|
||||
}
|
||||
|
||||
if ((_condition[ConditionFlag.Performing] || _condition[ConditionFlag.InCombat]) && !IsInCombatOrPerforming)
|
||||
{
|
||||
_logger.LogDebug("Combat/Performance start");
|
||||
IsInCombatOrPerforming = true;
|
||||
Mediator.Publish(new CombatOrPerformanceStartMessage());
|
||||
Mediator.Publish(new HaltScanMessage(nameof(IsInCombatOrPerforming)));
|
||||
if ((_condition[ConditionFlag.InCombat]) && !IsInCombat && !IsInInstance && _playerPerformanceConfigService.Current.PauseInCombat)
|
||||
{
|
||||
_logger.LogDebug("Combat start");
|
||||
IsInCombat = true;
|
||||
Mediator.Publish(new CombatStartMessage());
|
||||
Mediator.Publish(new HaltScanMessage(nameof(IsInCombat)));
|
||||
}
|
||||
else if ((!_condition[ConditionFlag.Performing] && !_condition[ConditionFlag.InCombat]) && IsInCombatOrPerforming)
|
||||
else if ((!_condition[ConditionFlag.InCombat]) && IsInCombat && !IsInInstance && _playerPerformanceConfigService.Current.PauseInCombat)
|
||||
{
|
||||
_logger.LogDebug("Combat/Performance end");
|
||||
IsInCombatOrPerforming = false;
|
||||
Mediator.Publish(new CombatOrPerformanceEndMessage());
|
||||
Mediator.Publish(new ResumeScanMessage(nameof(IsInCombatOrPerforming)));
|
||||
_logger.LogDebug("Combat end");
|
||||
IsInCombat = false;
|
||||
Mediator.Publish(new CombatEndMessage());
|
||||
Mediator.Publish(new ResumeScanMessage(nameof(IsInCombat)));
|
||||
}
|
||||
if (_condition[ConditionFlag.Performing] && !IsPerforming && _playerPerformanceConfigService.Current.PauseWhilePerforming)
|
||||
{
|
||||
_logger.LogDebug("Performance start");
|
||||
IsInCombat = true;
|
||||
Mediator.Publish(new PerformanceStartMessage());
|
||||
Mediator.Publish(new HaltScanMessage(nameof(IsPerforming)));
|
||||
}
|
||||
else if (!_condition[ConditionFlag.Performing] && IsPerforming && _playerPerformanceConfigService.Current.PauseWhilePerforming)
|
||||
{
|
||||
_logger.LogDebug("Performance end");
|
||||
IsInCombat = false;
|
||||
Mediator.Publish(new PerformanceEndMessage());
|
||||
Mediator.Publish(new ResumeScanMessage(nameof(IsPerforming)));
|
||||
}
|
||||
if ((_condition[ConditionFlag.BoundByDuty]) && !IsInInstance && _playerPerformanceConfigService.Current.PauseInInstanceDuty)
|
||||
{
|
||||
_logger.LogDebug("Instance start");
|
||||
IsInInstance = true;
|
||||
Mediator.Publish(new InstanceOrDutyStartMessage());
|
||||
Mediator.Publish(new HaltScanMessage(nameof(IsInInstance)));
|
||||
}
|
||||
else if (((!_condition[ConditionFlag.BoundByDuty]) && IsInInstance && _playerPerformanceConfigService.Current.PauseInInstanceDuty) || ((_condition[ConditionFlag.BoundByDuty]) && IsInInstance && !_playerPerformanceConfigService.Current.PauseInInstanceDuty))
|
||||
{
|
||||
_logger.LogDebug("Instance end");
|
||||
IsInInstance = false;
|
||||
Mediator.Publish(new InstanceOrDutyEndMessage());
|
||||
Mediator.Publish(new ResumeScanMessage(nameof(IsInInstance)));
|
||||
}
|
||||
|
||||
if (_condition[ConditionFlag.WatchingCutscene] && !IsInCutscene)
|
||||
@@ -735,7 +777,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
||||
_classJobId = localPlayer.ClassJob.RowId;
|
||||
}
|
||||
|
||||
if (!IsInCombatOrPerforming)
|
||||
if (!IsInCombat || !IsPerforming || !IsInInstance)
|
||||
Mediator.Publish(new FrameworkUpdateMessage());
|
||||
|
||||
Mediator.Publish(new PriorityFrameworkUpdateMessage());
|
||||
@@ -764,7 +806,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
||||
IsLodEnabled = lodEnabled;
|
||||
}
|
||||
|
||||
if (IsInCombatOrPerforming)
|
||||
if (IsInCombat || IsPerforming || IsInInstance)
|
||||
Mediator.Publish(new FrameworkUpdateMessage());
|
||||
|
||||
Mediator.Publish(new DelayedFrameworkUpdateMessage());
|
||||
|
||||
@@ -79,8 +79,12 @@ public record OpenPermissionWindow(Pair Pair) : MessageBase;
|
||||
public record DownloadLimitChangedMessage() : SameThreadMessage;
|
||||
public record CensusUpdateMessage(byte Gender, byte RaceId, byte TribeId) : MessageBase;
|
||||
public record TargetPairMessage(Pair Pair) : MessageBase;
|
||||
public record CombatOrPerformanceStartMessage : MessageBase;
|
||||
public record CombatOrPerformanceEndMessage : MessageBase;
|
||||
public record CombatStartMessage : MessageBase;
|
||||
public record CombatEndMessage : MessageBase;
|
||||
public record PerformanceStartMessage : MessageBase;
|
||||
public record PerformanceEndMessage : MessageBase;
|
||||
public record InstanceOrDutyStartMessage : MessageBase;
|
||||
public record InstanceOrDutyEndMessage : MessageBase;
|
||||
public record EventMessage(Event Event) : MessageBase;
|
||||
public record PenumbraDirectoryChangedMessage(string? ModDirectory) : MessageBase;
|
||||
public record PenumbraRedrawCharacterMessage(ICharacter Character) : SameThreadMessage;
|
||||
@@ -93,7 +97,9 @@ public record GPoseLobbyReceiveCharaData(CharaDataDownloadDto CharaDataDownloadD
|
||||
public record GPoseLobbyReceivePoseData(UserData UserData, PoseData PoseData) : MessageBase;
|
||||
public record GPoseLobbyReceiveWorldData(UserData UserData, WorldData WorldData) : MessageBase;
|
||||
public record OpenCharaDataHubWithFilterMessage(UserData UserData) : MessageBase;
|
||||
|
||||
public record EnableBroadcastMessage(string HashedCid, bool Enabled) : MessageBase;
|
||||
public record BroadcastStatusChangedMessage(bool Enabled, TimeSpan? Ttl) : MessageBase;
|
||||
public record SyncshellBroadcastsUpdatedMessage : MessageBase;
|
||||
public record VisibilityChange : MessageBase;
|
||||
#pragma warning restore S2094
|
||||
#pragma warning restore MA0048 // File name must match type name
|
||||
@@ -1,4 +1,5 @@
|
||||
using Dalamud.Interface.Windowing;
|
||||
using LightlessSync.UI.Style;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace LightlessSync.Services.Mediator;
|
||||
@@ -33,6 +34,18 @@ public abstract class WindowMediatorSubscriberBase : Window, IMediatorSubscriber
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
public override void PreDraw()
|
||||
{
|
||||
base.PreDraw();
|
||||
MainStyle.PushStyle(); // internally checks ShouldUseTheme
|
||||
}
|
||||
|
||||
public override void PostDraw()
|
||||
{
|
||||
MainStyle.PopStyle(); // always attempts to pop if pushed
|
||||
base.PostDraw();
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
_performanceCollectorService.LogPerformance(this, $"Draw", DrawInternal);
|
||||
|
||||
301
LightlessSync/Services/NameplateHandler.cs
Normal file
301
LightlessSync/Services/NameplateHandler.cs
Normal file
@@ -0,0 +1,301 @@
|
||||
using Dalamud.Game.Addon.Lifecycle;
|
||||
using Dalamud.Game.Addon.Lifecycle.AddonArgTypes;
|
||||
using Dalamud.Plugin.Services;
|
||||
using FFXIVClientStructs.FFXIV.Client.System.Framework;
|
||||
using FFXIVClientStructs.FFXIV.Client.UI;
|
||||
using FFXIVClientStructs.FFXIV.Component.GUI;
|
||||
using LightlessSync.Services.Mediator;
|
||||
using LightlessSync.UI;
|
||||
using LightlessSync.Utils;
|
||||
// Created using https://github.com/PunishedPineapple/Distance as a reference, thank you!
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace LightlessSync.Services;
|
||||
|
||||
public unsafe class NameplateHandler : IMediatorSubscriber
|
||||
{
|
||||
private readonly ILogger<NameplateHandler> _logger;
|
||||
private readonly IAddonLifecycle _addonLifecycle;
|
||||
private readonly IGameGui _gameGui;
|
||||
private readonly DalamudUtilService _dalamudUtil;
|
||||
private readonly LightlessMediator _mediator;
|
||||
public LightlessMediator Mediator => _mediator;
|
||||
|
||||
private bool mEnabled = false;
|
||||
private bool _needsLabelRefresh = false;
|
||||
private AddonNamePlate* mpNameplateAddon = null;
|
||||
private readonly AtkTextNode*[] mTextNodes = new AtkTextNode*[AddonNamePlate.NumNamePlateObjects];
|
||||
|
||||
internal const uint mNameplateNodeIDBase = 0x7D99D500;
|
||||
|
||||
private volatile HashSet<string> _activeBroadcastingCids = new();
|
||||
|
||||
public NameplateHandler(ILogger<NameplateHandler> logger, IAddonLifecycle addonLifecycle, IGameGui gameGui, DalamudUtilService dalamudUtil, LightlessMediator mediator)
|
||||
{
|
||||
_logger = logger;
|
||||
_addonLifecycle = addonLifecycle;
|
||||
_gameGui = gameGui;
|
||||
_dalamudUtil = dalamudUtil;
|
||||
_mediator = mediator;
|
||||
}
|
||||
|
||||
internal void Init()
|
||||
{
|
||||
EnableNameplate();
|
||||
_mediator.Subscribe<PriorityFrameworkUpdateMessage>(this, OnTick);
|
||||
}
|
||||
|
||||
internal void Uninit()
|
||||
{
|
||||
DisableNameplate();
|
||||
DestroyNameplateNodes();
|
||||
_mediator.Unsubscribe<PriorityFrameworkUpdateMessage>(this);
|
||||
mpNameplateAddon = null;
|
||||
}
|
||||
|
||||
internal void EnableNameplate()
|
||||
{
|
||||
if (!mEnabled)
|
||||
{
|
||||
try
|
||||
{
|
||||
_addonLifecycle.RegisterListener(AddonEvent.PostDraw, "NamePlate", NameplateDrawDetour);
|
||||
mEnabled = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError($"Unknown error while trying to enable nameplate distances:\n{e}");
|
||||
DisableNameplate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void DisableNameplate()
|
||||
{
|
||||
if (mEnabled)
|
||||
{
|
||||
try
|
||||
{
|
||||
_addonLifecycle.UnregisterListener(NameplateDrawDetour);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError($"Unknown error while unregistering nameplate listener:\n{e}");
|
||||
}
|
||||
|
||||
mEnabled = false;
|
||||
HideAllNameplateNodes();
|
||||
}
|
||||
}
|
||||
|
||||
private void NameplateDrawDetour(AddonEvent type, AddonArgs args)
|
||||
{
|
||||
var pNameplateAddon = (AddonNamePlate*)args.Addon.Address;
|
||||
|
||||
if (mpNameplateAddon != pNameplateAddon)
|
||||
{
|
||||
for (int i = 0; i < mTextNodes.Length; ++i) mTextNodes[i] = null;
|
||||
mpNameplateAddon = pNameplateAddon;
|
||||
if (mpNameplateAddon != null) CreateNameplateNodes();
|
||||
}
|
||||
|
||||
UpdateNameplateNodes();
|
||||
}
|
||||
|
||||
private void CreateNameplateNodes()
|
||||
{
|
||||
for (int i = 0; i < AddonNamePlate.NumNamePlateObjects; ++i)
|
||||
{
|
||||
var nameplateObject = GetNameplateObject(i);
|
||||
if (nameplateObject == null)
|
||||
continue;
|
||||
|
||||
var pNameplateResNode = nameplateObject.Value.NameContainer;
|
||||
var pNewNode = AtkNodeHelpers.CreateOrphanTextNode(mNameplateNodeIDBase + (uint)i, TextFlags.Edge | TextFlags.Glare);
|
||||
|
||||
if (pNewNode != null)
|
||||
{
|
||||
var pLastChild = pNameplateResNode->ChildNode;
|
||||
while (pLastChild->PrevSiblingNode != null) pLastChild = pLastChild->PrevSiblingNode;
|
||||
pNewNode->AtkResNode.NextSiblingNode = pLastChild;
|
||||
pNewNode->AtkResNode.ParentNode = pNameplateResNode;
|
||||
pLastChild->PrevSiblingNode = (AtkResNode*)pNewNode;
|
||||
nameplateObject.Value.RootComponentNode->Component->UldManager.UpdateDrawNodeList();
|
||||
pNewNode->AtkResNode.SetUseDepthBasedPriority(true);
|
||||
mTextNodes[i] = pNewNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DestroyNameplateNodes()
|
||||
{
|
||||
var pCurrentNameplateAddon = (AddonNamePlate*)_gameGui.GetAddonByName("NamePlate", 1).Address;
|
||||
if (mpNameplateAddon == null || mpNameplateAddon != pCurrentNameplateAddon)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < AddonNamePlate.NumNamePlateObjects; ++i)
|
||||
{
|
||||
var pTextNode = mTextNodes[i];
|
||||
var pNameplateNode = GetNameplateComponentNode(i);
|
||||
if (pTextNode != null && pNameplateNode != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (pTextNode->AtkResNode.PrevSiblingNode != null)
|
||||
pTextNode->AtkResNode.PrevSiblingNode->NextSiblingNode = pTextNode->AtkResNode.NextSiblingNode;
|
||||
if (pTextNode->AtkResNode.NextSiblingNode != null)
|
||||
pTextNode->AtkResNode.NextSiblingNode->PrevSiblingNode = pTextNode->AtkResNode.PrevSiblingNode;
|
||||
pNameplateNode->Component->UldManager.UpdateDrawNodeList();
|
||||
pTextNode->AtkResNode.Destroy(true);
|
||||
mTextNodes[i] = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError($"Unknown error while removing text node 0x{(IntPtr)pTextNode:X} for nameplate {i} on component node 0x{(IntPtr)pNameplateNode:X}:\n{e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void HideAllNameplateNodes()
|
||||
{
|
||||
for (int i = 0; i < mTextNodes.Length; ++i)
|
||||
{
|
||||
HideNameplateTextNode(i);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateNameplateNodes()
|
||||
{
|
||||
var framework = Framework.Instance();
|
||||
var ui3DModule = framework->GetUIModule()->GetUI3DModule();
|
||||
|
||||
if (ui3DModule == null)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < ui3DModule->NamePlateObjectInfoCount; ++i)
|
||||
{
|
||||
var objectInfo = ui3DModule->NamePlateObjectInfoPointers[i].Value;
|
||||
if (objectInfo == null || objectInfo->GameObject == null)
|
||||
continue;
|
||||
|
||||
var nameplateIndex = objectInfo->NamePlateIndex;
|
||||
if (nameplateIndex < 0 || nameplateIndex >= AddonNamePlate.NumNamePlateObjects)
|
||||
continue;
|
||||
|
||||
var pNode = mTextNodes[nameplateIndex];
|
||||
if (pNode == null)
|
||||
continue;
|
||||
|
||||
var cid = DalamudUtilService.GetHashedCIDFromPlayerPointer((nint)objectInfo->GameObject);
|
||||
|
||||
//_logger.LogInformation($"checking cid: {cid}", cid);
|
||||
|
||||
if (cid == null || !_activeBroadcastingCids.Contains(cid))
|
||||
{
|
||||
pNode->AtkResNode.ToggleVisibility(false);
|
||||
continue;
|
||||
}
|
||||
|
||||
pNode->AtkResNode.ToggleVisibility(true);
|
||||
|
||||
var nameplateObject = mpNameplateAddon->NamePlateObjectArray[nameplateIndex];
|
||||
nameplateObject.RootComponentNode->Component->UldManager.UpdateDrawNodeList();
|
||||
|
||||
var nameContainer = nameplateObject.NameContainer;
|
||||
var nameText = nameplateObject.NameText;
|
||||
|
||||
var labelColor = UIColors.Get("LightlessPurple");
|
||||
var edgeColor = UIColors.Get("FullBlack");
|
||||
|
||||
var labelY = nameContainer->Height - nameplateObject.TextH - (int)(24 * nameText->AtkResNode.ScaleY);
|
||||
|
||||
pNode->AtkResNode.SetPositionShort(58, (short)labelY);
|
||||
pNode->AtkResNode.SetUseDepthBasedPriority(true);
|
||||
pNode->AtkResNode.SetScale(0.5f, 0.5f);
|
||||
|
||||
pNode->AtkResNode.Color.A = 255;
|
||||
|
||||
pNode->TextColor.R = (byte)(labelColor.X * 255);
|
||||
pNode->TextColor.G = (byte)(labelColor.Y * 255);
|
||||
pNode->TextColor.B = (byte)(labelColor.Z * 255);
|
||||
pNode->TextColor.A = (byte)(labelColor.W * 255);
|
||||
|
||||
pNode->EdgeColor.R = (byte)(edgeColor.X * 255);
|
||||
pNode->EdgeColor.G = (byte)(edgeColor.Y * 255);
|
||||
pNode->EdgeColor.B = (byte)(edgeColor.Z * 255);
|
||||
pNode->EdgeColor.A = (byte)(edgeColor.W * 255);
|
||||
|
||||
pNode->FontSize = 24;
|
||||
pNode->AlignmentType = AlignmentType.Center;
|
||||
pNode->FontType = FontType.MiedingerMed;
|
||||
pNode->LineSpacing = 24;
|
||||
pNode->CharSpacing = 1;
|
||||
|
||||
pNode->TextFlags = TextFlags.Edge | TextFlags.Glare;
|
||||
|
||||
pNode->SetText("Lightfinder");
|
||||
}
|
||||
}
|
||||
|
||||
private void HideNameplateTextNode(int i)
|
||||
{
|
||||
var pNode = mTextNodes[i];
|
||||
if (pNode != null)
|
||||
{
|
||||
pNode->AtkResNode.ToggleVisibility(false);
|
||||
}
|
||||
}
|
||||
|
||||
private AddonNamePlate.NamePlateObject? GetNameplateObject(int i)
|
||||
{
|
||||
if (i < AddonNamePlate.NumNamePlateObjects &&
|
||||
mpNameplateAddon != null &&
|
||||
mpNameplateAddon->NamePlateObjectArray[i].RootComponentNode != null)
|
||||
{
|
||||
return mpNameplateAddon->NamePlateObjectArray[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private AtkComponentNode* GetNameplateComponentNode(int i)
|
||||
{
|
||||
var nameplateObject = GetNameplateObject(i);
|
||||
return nameplateObject != null ? nameplateObject.Value.RootComponentNode : null;
|
||||
}
|
||||
|
||||
public void FlagRefresh()
|
||||
{
|
||||
_needsLabelRefresh = true;
|
||||
}
|
||||
|
||||
public void OnTick(PriorityFrameworkUpdateMessage _)
|
||||
{
|
||||
if (_needsLabelRefresh)
|
||||
{
|
||||
UpdateNameplateNodes();
|
||||
_needsLabelRefresh = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateBroadcastingCids(IEnumerable<string> cids)
|
||||
{
|
||||
var newSet = cids.ToHashSet();
|
||||
|
||||
var changed = !_activeBroadcastingCids.SetEquals(newSet);
|
||||
if (!changed)
|
||||
return;
|
||||
|
||||
_activeBroadcastingCids.Clear();
|
||||
foreach (var cid in newSet)
|
||||
_activeBroadcastingCids.Add(cid);
|
||||
|
||||
_logger.LogInformation("Active broadcast CIDs: {Cids}", string.Join(",", _activeBroadcastingCids));
|
||||
|
||||
FlagRefresh();
|
||||
}
|
||||
}
|
||||
@@ -8,10 +8,12 @@ using LightlessSync.PlayerData.Pairs;
|
||||
using LightlessSync.Services.Mediator;
|
||||
using LightlessSync.UI;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace LightlessSync.Services;
|
||||
|
||||
public class NameplateService : DisposableMediatorSubscriberBase
|
||||
{
|
||||
private readonly ILogger<NameplateService> _logger;
|
||||
private readonly LightlessConfigService _configService;
|
||||
private readonly IClientState _clientState;
|
||||
private readonly INamePlateGui _namePlateGui;
|
||||
@@ -24,10 +26,12 @@ public class NameplateService : DisposableMediatorSubscriberBase
|
||||
PairManager pairManager,
|
||||
LightlessMediator lightlessMediator) : base(logger, lightlessMediator)
|
||||
{
|
||||
_logger = logger;
|
||||
_configService = configService;
|
||||
_namePlateGui = namePlateGui;
|
||||
_clientState = clientState;
|
||||
_pairManager = pairManager;
|
||||
|
||||
_namePlateGui.OnNamePlateUpdate += OnNamePlateUpdate;
|
||||
_namePlateGui.RequestRedraw();
|
||||
Mediator.Subscribe<VisibilityChange>(this, (_) => _namePlateGui.RequestRedraw());
|
||||
@@ -37,14 +41,23 @@ public class NameplateService : DisposableMediatorSubscriberBase
|
||||
private void OnNamePlateUpdate(INamePlateUpdateContext context, IReadOnlyList<INamePlateUpdateHandler> handlers)
|
||||
{
|
||||
|
||||
if (!_configService.Current.IsNameplateColorsEnabled && !_clientState.IsPvPExcludingDen) return;
|
||||
var visibleUsersIds = _pairManager.GetOnlineUserPairs().Where(u => u.IsVisible && u.PlayerCharacterId != uint.MaxValue).Select(u => (ulong)u.PlayerCharacterId).ToHashSet();
|
||||
if (!_configService.Current.IsNameplateColorsEnabled || (_configService.Current.IsNameplateColorsEnabled && _clientState.IsPvPExcludingDen))
|
||||
return;
|
||||
|
||||
var visibleUsersIds = _pairManager.GetOnlineUserPairs()
|
||||
.Where(u => u.IsVisible && u.PlayerCharacterId != uint.MaxValue)
|
||||
.Select(u => (ulong)u.PlayerCharacterId)
|
||||
.ToHashSet();
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
var colors = _configService.Current.NameplateColors;
|
||||
|
||||
foreach (var handler in handlers)
|
||||
{
|
||||
var playerCharacter = handler.PlayerCharacter;
|
||||
if (playerCharacter == null) { continue; }
|
||||
if (playerCharacter == null)
|
||||
continue;
|
||||
|
||||
var isInParty = playerCharacter.StatusFlags.HasFlag(StatusFlags.PartyMember);
|
||||
var isFriend = playerCharacter.StatusFlags.HasFlag(StatusFlags.Friend);
|
||||
bool partyColorAllowed = (_configService.Current.overridePartyColor && isInParty);
|
||||
@@ -56,13 +69,16 @@ public class NameplateService : DisposableMediatorSubscriberBase
|
||||
(isFriend && !friendColorAllowed)
|
||||
))
|
||||
{
|
||||
//_logger.LogInformation("added nameplate color to {Name}", playerCharacter.Name.TextValue);
|
||||
handler.NameParts.TextWrap = CreateTextWrap(colors);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void RequestRedraw()
|
||||
{
|
||||
|
||||
_namePlateGui.RequestRedraw();
|
||||
}
|
||||
|
||||
@@ -80,12 +96,11 @@ public class NameplateService : DisposableMediatorSubscriberBase
|
||||
return (left.ToReadOnlySeString().ToDalamudString(), right.ToReadOnlySeString().ToDalamudString());
|
||||
}
|
||||
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
_namePlateGui.OnNamePlateUpdate -= OnNamePlateUpdate;
|
||||
_namePlateGui.RequestRedraw();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,15 +23,18 @@ public class ServerConfigurationManager
|
||||
private readonly ILogger<ServerConfigurationManager> _logger;
|
||||
private readonly LightlessMediator _lightlessMediator;
|
||||
private readonly NotesConfigService _notesConfig;
|
||||
private readonly ServerTagConfigService _serverTagConfig;
|
||||
private readonly PairTagConfigService _pairTagConfig;
|
||||
private readonly SyncshellTagConfigService _syncshellTagConfig;
|
||||
private readonly int _maxCharactersFolder = 20;
|
||||
|
||||
public ServerConfigurationManager(ILogger<ServerConfigurationManager> logger, ServerConfigService configService,
|
||||
ServerTagConfigService serverTagConfig, NotesConfigService notesConfig, DalamudUtilService dalamudUtil,
|
||||
PairTagConfigService pairTagConfig, SyncshellTagConfigService syncshellTagConfig, NotesConfigService notesConfig, DalamudUtilService dalamudUtil,
|
||||
LightlessConfigService lightlessConfigService, HttpClient httpClient, LightlessMediator lightlessMediator)
|
||||
{
|
||||
_logger = logger;
|
||||
_configService = configService;
|
||||
_serverTagConfig = serverTagConfig;
|
||||
_pairTagConfig = pairTagConfig;
|
||||
_syncshellTagConfig = syncshellTagConfig;
|
||||
_notesConfig = notesConfig;
|
||||
_dalamudUtil = dalamudUtil;
|
||||
_lightlessConfigService = lightlessConfigService;
|
||||
@@ -258,7 +261,7 @@ public class ServerConfigurationManager
|
||||
{
|
||||
if (serverSelectionIndex == -1) serverSelectionIndex = CurrentServerIndex;
|
||||
var server = GetServerByIndex(serverSelectionIndex);
|
||||
if (server.Authentications.Any(c => string.Equals(c.CharacterName, _dalamudUtil.GetPlayerNameAsync().GetAwaiter().GetResult(), StringComparison.Ordinal)
|
||||
if (server.Authentications.Exists(c => string.Equals(c.CharacterName, _dalamudUtil.GetPlayerNameAsync().GetAwaiter().GetResult(), StringComparison.Ordinal)
|
||||
&& c.WorldId == _dalamudUtil.GetHomeWorldIdAsync().GetAwaiter().GetResult()))
|
||||
return;
|
||||
|
||||
@@ -277,15 +280,15 @@ public class ServerConfigurationManager
|
||||
var server = GetServerByIndex(serverSelectionIndex);
|
||||
server.Authentications.Add(new Authentication()
|
||||
{
|
||||
SecretKeyIdx = server.SecretKeys.Any() ? server.SecretKeys.First().Key : -1,
|
||||
SecretKeyIdx = server.SecretKeys.Count != 0 ? server.SecretKeys.First().Key : -1,
|
||||
});
|
||||
Save();
|
||||
}
|
||||
|
||||
internal void AddOpenPairTag(string tag)
|
||||
{
|
||||
CurrentServerTagStorage().OpenPairTags.Add(tag);
|
||||
_serverTagConfig.Save();
|
||||
CurrentPairTagStorage().OpenPairTags.Add(tag);
|
||||
_pairTagConfig.Save();
|
||||
}
|
||||
|
||||
internal void AddServer(ServerStorage serverStorage)
|
||||
@@ -294,36 +297,79 @@ public class ServerConfigurationManager
|
||||
Save();
|
||||
}
|
||||
|
||||
internal void AddTag(string tag)
|
||||
internal void AddPairTag(string tag)
|
||||
{
|
||||
CurrentServerTagStorage().ServerAvailablePairTags.Add(tag);
|
||||
_serverTagConfig.Save();
|
||||
_lightlessMediator.Publish(new RefreshUiMessage());
|
||||
if (tag.Length <= _maxCharactersFolder)
|
||||
{
|
||||
CurrentPairTagStorage().ServerAvailablePairTags.Add(tag);
|
||||
_pairTagConfig.Save();
|
||||
_lightlessMediator.Publish(new RefreshUiMessage());
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation("Couldn't save/add {tag}. Name too long to be saved", tag);
|
||||
}
|
||||
}
|
||||
|
||||
internal void AddSyncshellTag(string tag)
|
||||
{
|
||||
if (tag.Length <= _maxCharactersFolder)
|
||||
{
|
||||
CurrentSyncshellTagStorage().ServerAvailableSyncshellTags.Add(tag);
|
||||
_syncshellTagConfig.Save();
|
||||
_lightlessMediator.Publish(new RefreshUiMessage());
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation("Couldn't save/add {tag}. Name too long to be saved", tag);
|
||||
}
|
||||
}
|
||||
|
||||
internal void AddTagForUid(string uid, string tagName)
|
||||
{
|
||||
if (CurrentServerTagStorage().UidServerPairedUserTags.TryGetValue(uid, out var tags))
|
||||
if (CurrentPairTagStorage().UidServerPairedUserTags.TryGetValue(uid, out var tags))
|
||||
{
|
||||
tags.Add(tagName);
|
||||
_lightlessMediator.Publish(new RefreshUiMessage());
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentServerTagStorage().UidServerPairedUserTags[uid] = [tagName];
|
||||
CurrentPairTagStorage().UidServerPairedUserTags[uid] = [tagName];
|
||||
}
|
||||
|
||||
_serverTagConfig.Save();
|
||||
_pairTagConfig.Save();
|
||||
}
|
||||
|
||||
internal bool ContainsOpenPairTag(string tag)
|
||||
internal void AddTagForSyncshell(string syncshellName, string tagName)
|
||||
{
|
||||
return CurrentServerTagStorage().OpenPairTags.Contains(tag);
|
||||
if (CurrentSyncshellTagStorage().SyncshellPairedTags.TryGetValue(syncshellName, out var tags))
|
||||
{
|
||||
tags.Add(tagName);
|
||||
_lightlessMediator.Publish(new RefreshUiMessage());
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentSyncshellTagStorage().SyncshellPairedTags[syncshellName] = [tagName];
|
||||
}
|
||||
|
||||
_syncshellTagConfig.Save();
|
||||
}
|
||||
|
||||
internal bool ContainsTag(string uid, string tag)
|
||||
internal bool ContainsOpenPairTag(string tag) => CurrentPairTagStorage().OpenPairTags.Contains(tag);
|
||||
|
||||
internal bool ContainsPairTag(string uid, string tag)
|
||||
{
|
||||
if (CurrentServerTagStorage().UidServerPairedUserTags.TryGetValue(uid, out var tags))
|
||||
if (CurrentPairTagStorage().UidServerPairedUserTags.TryGetValue(uid, out var tags))
|
||||
{
|
||||
return tags.Contains(tag, StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
internal bool ContainsSyncshellTag(string name, string tag)
|
||||
{
|
||||
if (CurrentSyncshellTagStorage().SyncshellPairedTags.TryGetValue(name, out var tags))
|
||||
{
|
||||
return tags.Contains(tag, StringComparer.Ordinal);
|
||||
}
|
||||
@@ -364,30 +410,19 @@ public class ServerConfigurationManager
|
||||
return null;
|
||||
}
|
||||
|
||||
internal HashSet<string> GetServerAvailablePairTags()
|
||||
{
|
||||
return CurrentServerTagStorage().ServerAvailablePairTags;
|
||||
}
|
||||
internal HashSet<string> GetServerAvailablePairTags() => CurrentPairTagStorage().ServerAvailablePairTags;
|
||||
|
||||
internal Dictionary<string, List<string>> GetUidServerPairedUserTags()
|
||||
{
|
||||
return CurrentServerTagStorage().UidServerPairedUserTags;
|
||||
}
|
||||
internal HashSet<string> GetServerAvailableSyncshellTags() => CurrentSyncshellTagStorage().ServerAvailableSyncshellTags;
|
||||
|
||||
internal HashSet<string> GetUidsForTag(string tag)
|
||||
{
|
||||
return CurrentServerTagStorage().UidServerPairedUserTags.Where(p => p.Value.Contains(tag, StringComparer.Ordinal)).Select(p => p.Key).ToHashSet(StringComparer.Ordinal);
|
||||
}
|
||||
internal Dictionary<string, List<string>> GetUidServerPairedUserTags() => CurrentPairTagStorage().UidServerPairedUserTags;
|
||||
|
||||
internal bool HasTags(string uid)
|
||||
{
|
||||
if (CurrentServerTagStorage().UidServerPairedUserTags.TryGetValue(uid, out var tags))
|
||||
{
|
||||
return tags.Any();
|
||||
}
|
||||
internal HashSet<string> GetUidsForPairTag(string tag) => CurrentPairTagStorage().UidServerPairedUserTags.Where(p => p.Value.Contains(tag, StringComparer.Ordinal)).Select(p => p.Key).ToHashSet(StringComparer.Ordinal);
|
||||
|
||||
return false;
|
||||
}
|
||||
internal HashSet<string> GetNamesForSyncshellTag(string tag) => CurrentSyncshellTagStorage().SyncshellPairedTags.Where(p => p.Value.Contains(tag, StringComparer.Ordinal)).Select(p => p.Key).ToHashSet(StringComparer.Ordinal);
|
||||
|
||||
internal bool HasPairTags(string uid) => CurrentPairTagStorage().UidServerPairedUserTags.TryGetValue(uid, out var tags) && tags.Count != 0;
|
||||
|
||||
internal bool HasSyncshellTags(string name) => CurrentSyncshellTagStorage().SyncshellPairedTags.TryGetValue(name, out var tags) && tags.Count != 0;
|
||||
|
||||
internal void RemoveCharacterFromServer(int serverSelectionIndex, Authentication item)
|
||||
{
|
||||
@@ -398,51 +433,96 @@ public class ServerConfigurationManager
|
||||
|
||||
internal void RemoveOpenPairTag(string tag)
|
||||
{
|
||||
CurrentServerTagStorage().OpenPairTags.Remove(tag);
|
||||
_serverTagConfig.Save();
|
||||
CurrentPairTagStorage().OpenPairTags.Remove(tag);
|
||||
_pairTagConfig.Save();
|
||||
}
|
||||
|
||||
internal void RemoveTag(string tag)
|
||||
internal void RemovePairTag(string tag)
|
||||
{
|
||||
CurrentServerTagStorage().ServerAvailablePairTags.Remove(tag);
|
||||
foreach (var uid in GetUidsForTag(tag))
|
||||
{
|
||||
RemoveTagForUid(uid, tag, save: false);
|
||||
}
|
||||
_serverTagConfig.Save();
|
||||
RemoveTag(CurrentPairTagStorage().ServerAvailablePairTags, tag);
|
||||
_pairTagConfig.Save();
|
||||
_lightlessMediator.Publish(new RefreshUiMessage());
|
||||
}
|
||||
|
||||
internal void RemoveSyncshellTag(string tag)
|
||||
{
|
||||
RemoveTag(CurrentSyncshellTagStorage().ServerAvailableSyncshellTags, tag, true);
|
||||
_syncshellTagConfig.Save();
|
||||
_lightlessMediator.Publish(new RefreshUiMessage());
|
||||
}
|
||||
|
||||
internal void RemoveTag(HashSet<string> storage, string tag, bool syncshell = false)
|
||||
{
|
||||
storage.Remove(tag);
|
||||
if (syncshell)
|
||||
{
|
||||
foreach (var uid in GetNamesForSyncshellTag(tag))
|
||||
{
|
||||
RemoveTagForSyncshell(uid, tag, save: false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var uid in GetUidsForPairTag(tag))
|
||||
{
|
||||
RemoveTagForUid(uid, tag, save: false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void RemoveTagForUid(string uid, string tagName, bool save = true)
|
||||
{
|
||||
if (CurrentServerTagStorage().UidServerPairedUserTags.TryGetValue(uid, out var tags))
|
||||
if (CurrentPairTagStorage().UidServerPairedUserTags.TryGetValue(uid, out var tags))
|
||||
{
|
||||
tags.Remove(tagName);
|
||||
|
||||
if (save)
|
||||
{
|
||||
_serverTagConfig.Save();
|
||||
_pairTagConfig.Save();
|
||||
_lightlessMediator.Publish(new RefreshUiMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void RenameTag(string oldName, string newName)
|
||||
internal void RemoveTagForSyncshell(string name, string tagName, bool save = true)
|
||||
{
|
||||
CurrentServerTagStorage().ServerAvailablePairTags.Remove(oldName);
|
||||
CurrentServerTagStorage().ServerAvailablePairTags.Add(newName);
|
||||
foreach (var existingTags in CurrentServerTagStorage().UidServerPairedUserTags.Select(k => k.Value))
|
||||
if (CurrentSyncshellTagStorage().SyncshellPairedTags.TryGetValue(name, out var tags))
|
||||
{
|
||||
if (existingTags.Remove(oldName))
|
||||
existingTags.Add(newName);
|
||||
tags.Remove(tagName);
|
||||
|
||||
if (save)
|
||||
{
|
||||
_syncshellTagConfig.Save();
|
||||
_lightlessMediator.Publish(new RefreshUiMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void SaveNotes()
|
||||
internal void RenamePairTag(string oldName, string newName) => RenameTag(CurrentPairTagStorage().UidServerPairedUserTags, CurrentPairTagStorage().ServerAvailablePairTags, oldName, newName);
|
||||
|
||||
internal void RenameSyncshellTag(string oldName, string newName) => RenameTag(CurrentSyncshellTagStorage().SyncshellPairedTags, CurrentSyncshellTagStorage().ServerAvailableSyncshellTags, oldName, newName);
|
||||
|
||||
internal void RenameTag(Dictionary<string, List<string>> tags, HashSet<string> storage, string oldName, string newName)
|
||||
{
|
||||
_notesConfig.Save();
|
||||
if (newName.Length > _maxCharactersFolder)
|
||||
{
|
||||
storage.Remove(oldName);
|
||||
storage.Add(newName);
|
||||
foreach (var existingTags in tags.Select(k => k.Value))
|
||||
{
|
||||
if (existingTags.Remove(oldName))
|
||||
existingTags.Add(newName);
|
||||
}
|
||||
_lightlessMediator.Publish(new RefreshUiMessage());
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation("Couldn't save/add {tag}. Name too long to be saved", newName);
|
||||
}
|
||||
}
|
||||
|
||||
internal void SaveNotes() => _notesConfig.Save();
|
||||
|
||||
internal void SetNoteForGid(string gid, string note, bool save = true)
|
||||
{
|
||||
if (string.IsNullOrEmpty(gid)) return;
|
||||
@@ -476,10 +556,16 @@ public class ServerConfigurationManager
|
||||
return _notesConfig.Current.ServerNotes[CurrentApiUrl];
|
||||
}
|
||||
|
||||
private ServerTagStorage CurrentServerTagStorage()
|
||||
private PairTagStorage CurrentPairTagStorage()
|
||||
{
|
||||
TryCreateCurrentServerTagStorage();
|
||||
return _serverTagConfig.Current.ServerTagStorage[CurrentApiUrl];
|
||||
TryCreateCurrentPairTagStorage();
|
||||
return _pairTagConfig.Current.ServerTagStorage[CurrentApiUrl];
|
||||
}
|
||||
|
||||
private SyncshellTagStorage CurrentSyncshellTagStorage()
|
||||
{
|
||||
TryCreateCurrentSyncshellTagStorage();
|
||||
return _syncshellTagConfig.Current.ServerTagStorage[CurrentApiUrl];
|
||||
}
|
||||
|
||||
private void EnsureMainExists()
|
||||
@@ -499,11 +585,19 @@ public class ServerConfigurationManager
|
||||
}
|
||||
}
|
||||
|
||||
private void TryCreateCurrentServerTagStorage()
|
||||
private void TryCreateCurrentPairTagStorage()
|
||||
{
|
||||
if (!_serverTagConfig.Current.ServerTagStorage.ContainsKey(CurrentApiUrl))
|
||||
if (!_pairTagConfig.Current.ServerTagStorage.ContainsKey(CurrentApiUrl))
|
||||
{
|
||||
_serverTagConfig.Current.ServerTagStorage[CurrentApiUrl] = new();
|
||||
_pairTagConfig.Current.ServerTagStorage[CurrentApiUrl] = new();
|
||||
}
|
||||
}
|
||||
|
||||
private void TryCreateCurrentSyncshellTagStorage()
|
||||
{
|
||||
if (!_syncshellTagConfig.Current.ServerTagStorage.ContainsKey(CurrentApiUrl))
|
||||
{
|
||||
_syncshellTagConfig.Current.ServerTagStorage[CurrentApiUrl] = new();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ using LightlessSync.PlayerData.Pairs;
|
||||
using LightlessSync.Services.Mediator;
|
||||
using LightlessSync.Services.ServerConfiguration;
|
||||
using LightlessSync.UI;
|
||||
using LightlessSync.UI.Components.Popup;
|
||||
using LightlessSync.WebAPI;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ using Dalamud.Interface.Windowing;
|
||||
using LightlessSync.LightlessConfiguration;
|
||||
using LightlessSync.Services.Mediator;
|
||||
using LightlessSync.UI;
|
||||
using LightlessSync.UI.Components.Popup;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace LightlessSync.Services;
|
||||
|
||||
382
LightlessSync/UI/BroadcastUI.cs
Normal file
382
LightlessSync/UI/BroadcastUI.cs
Normal file
@@ -0,0 +1,382 @@
|
||||
using Dalamud.Bindings.ImGui;
|
||||
using Dalamud.Interface.Utility;
|
||||
using Dalamud.Utility;
|
||||
using LightlessSync.API.Dto.Group;
|
||||
using LightlessSync.LightlessConfiguration;
|
||||
using LightlessSync.Services;
|
||||
using LightlessSync.Services.Mediator;
|
||||
using LightlessSync.WebAPI;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Numerics;
|
||||
|
||||
namespace LightlessSync.UI
|
||||
{
|
||||
public class BroadcastUI : WindowMediatorSubscriberBase
|
||||
{
|
||||
private readonly ApiController _apiController;
|
||||
private readonly LightlessConfigService _configService;
|
||||
private readonly BroadcastService _broadcastService;
|
||||
private readonly UiSharedService _uiSharedService;
|
||||
private readonly BroadcastScannerService _broadcastScannerService;
|
||||
|
||||
private IReadOnlyList<GroupFullInfoDto> _allSyncshells;
|
||||
private string _userUid = string.Empty;
|
||||
|
||||
private List<(string Label, string? GID, bool IsAvailable)> _syncshellOptions = new();
|
||||
|
||||
public BroadcastUI(
|
||||
ILogger<BroadcastUI> logger,
|
||||
LightlessMediator mediator,
|
||||
PerformanceCollectorService performanceCollectorService,
|
||||
BroadcastService broadcastService,
|
||||
LightlessConfigService configService,
|
||||
UiSharedService uiShared,
|
||||
ApiController apiController,
|
||||
BroadcastScannerService broadcastScannerService
|
||||
) : base(logger, mediator, "Lightfinder###LightlessLightfinderUI", performanceCollectorService)
|
||||
{
|
||||
_broadcastService = broadcastService;
|
||||
_uiSharedService = uiShared;
|
||||
_configService = configService;
|
||||
_apiController = apiController;
|
||||
_broadcastScannerService = broadcastScannerService;
|
||||
|
||||
IsOpen = false;
|
||||
this.SizeConstraints = new()
|
||||
{
|
||||
MinimumSize = new(600, 340),
|
||||
MaximumSize = new(750, 400)
|
||||
};
|
||||
|
||||
mediator.Subscribe<RefreshUiMessage>(this, async _ => await RefreshSyncshells());
|
||||
}
|
||||
|
||||
private void RebuildSyncshellDropdownOptions()
|
||||
{
|
||||
var selectedGid = _configService.Current.SelectedFinderSyncshell;
|
||||
var allSyncshells = _allSyncshells ?? Array.Empty<GroupFullInfoDto>();
|
||||
var ownedSyncshells = allSyncshells
|
||||
.Where(g => string.Equals(g.OwnerUID, _userUid, StringComparison.Ordinal))
|
||||
.ToList();
|
||||
|
||||
_syncshellOptions.Clear();
|
||||
_syncshellOptions.Add(("None", null, true));
|
||||
|
||||
var addedGids = new HashSet<string>();
|
||||
|
||||
foreach (var shell in ownedSyncshells)
|
||||
{
|
||||
var label = shell.GroupAliasOrGID ?? shell.GID;
|
||||
_syncshellOptions.Add((label, shell.GID, true));
|
||||
addedGids.Add(shell.GID);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(selectedGid) && !addedGids.Contains(selectedGid))
|
||||
{
|
||||
var matching = allSyncshells.FirstOrDefault(g => g.GID == selectedGid);
|
||||
if (matching != null)
|
||||
{
|
||||
var label = matching.GroupAliasOrGID ?? matching.GID;
|
||||
_syncshellOptions.Add((label, matching.GID, true));
|
||||
addedGids.Add(matching.GID);
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(selectedGid) && !addedGids.Contains(selectedGid))
|
||||
{
|
||||
_syncshellOptions.Add(($"[Unavailable] {selectedGid}", selectedGid, false));
|
||||
}
|
||||
}
|
||||
|
||||
public Task RefreshSyncshells()
|
||||
{
|
||||
return RefreshSyncshellsInternal();
|
||||
}
|
||||
|
||||
private async Task RefreshSyncshellsInternal()
|
||||
{
|
||||
if (!_apiController.IsConnected)
|
||||
{
|
||||
_allSyncshells = Array.Empty<GroupFullInfoDto>();
|
||||
RebuildSyncshellDropdownOptions();
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_allSyncshells = await _apiController.GroupsGetAll().ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to fetch Syncshells.");
|
||||
_allSyncshells = Array.Empty<GroupFullInfoDto>();
|
||||
}
|
||||
|
||||
RebuildSyncshellDropdownOptions();
|
||||
}
|
||||
|
||||
|
||||
public override void OnOpen()
|
||||
{
|
||||
_userUid = _apiController.UID;
|
||||
_ = RefreshSyncshellsInternal();
|
||||
}
|
||||
|
||||
protected override void DrawInternal()
|
||||
{
|
||||
if (!_broadcastService.IsLightFinderAvailable)
|
||||
{
|
||||
_uiSharedService.MediumText("This server doesn't support Lightfinder.", UIColors.Get("LightlessYellow"));
|
||||
|
||||
ImGuiHelpers.ScaledDummy(0.25f);
|
||||
}
|
||||
|
||||
if (ImGui.BeginTabBar("##MyTabBar"))
|
||||
{
|
||||
if (ImGui.BeginTabItem("Lightfinder"))
|
||||
{
|
||||
_uiSharedService.MediumText("Lightfinder", UIColors.Get("PairBlue"));
|
||||
|
||||
ImGui.PushTextWrapPos();
|
||||
ImGui.Text("This lets other Lightless users know you use Lightless.");
|
||||
ImGui.Text("By enabling this, the server will allow other people to see that you are using Lightless.");
|
||||
ImGui.Text("When disabled, pairing is still possible but both parties need to mutually send each other requests, receiving party will not be notified about the request unless the pairing is complete.");
|
||||
ImGui.Text("At no point ever, even when Lightfinder is active that any Lightless data is getting sent to other people (including ID's), the server keeps this to itself.");
|
||||
ImGui.Text("You can request to pair by right-clicking any (not yourself) character and using 'Send Pair Request'.");
|
||||
ImGui.PopTextWrapPos();
|
||||
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, UIColors.Get("DimRed"));
|
||||
ImGui.Text("Use it only when you want to be visible.");
|
||||
ImGui.PopStyleColor();
|
||||
|
||||
ImGuiHelpers.ScaledDummy(0.2f);
|
||||
_uiSharedService.ColoredSeparator(UIColors.Get("LightlessPurple"), 2f);
|
||||
|
||||
if (_configService.Current.BroadcastEnabled)
|
||||
{
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, UIColors.Get("LightlessGreen"));
|
||||
ImGui.Text("The Lightfinder calls, and somewhere, a soul may answer."); // cringe..
|
||||
ImGui.PopStyleColor();
|
||||
|
||||
var ttl = _broadcastService.RemainingTtl;
|
||||
if (ttl is { } remaining && remaining > TimeSpan.Zero)
|
||||
{
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, UIColors.Get("LightlessYellow"));
|
||||
ImGui.Text($"Still shining, for {remaining:hh\\:mm\\:ss}");
|
||||
ImGui.PopStyleColor();
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, UIColors.Get("DimRed"));
|
||||
ImGui.Text("The Lightfinder’s light wanes, but not in vain."); // cringe..
|
||||
ImGui.PopStyleColor();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, UIColors.Get("DimRed"));
|
||||
ImGui.Text("The Lightfinder rests, waiting to shine again."); // cringe..
|
||||
ImGui.PopStyleColor();
|
||||
}
|
||||
|
||||
var cooldown = _broadcastService.RemainingCooldown;
|
||||
if (cooldown is { } cd)
|
||||
{
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, UIColors.Get("DimRed"));
|
||||
ImGui.Text($"The Lightfinder gathers its strength... ({Math.Ceiling(cd.TotalSeconds)}s)");
|
||||
ImGui.PopStyleColor();
|
||||
}
|
||||
|
||||
ImGuiHelpers.ScaledDummy(0.5f);
|
||||
|
||||
bool isBroadcasting = _broadcastService.IsBroadcasting;
|
||||
bool isOnCooldown = cooldown.HasValue && cooldown.Value.TotalSeconds > 0;
|
||||
|
||||
ImGui.PushStyleVar(ImGuiStyleVar.FrameRounding, 10.0f);
|
||||
|
||||
if (isOnCooldown)
|
||||
ImGui.PushStyleColor(ImGuiCol.Button, UIColors.Get("DimRed"));
|
||||
else if (isBroadcasting)
|
||||
ImGui.PushStyleColor(ImGuiCol.Button, UIColors.Get("LightlessGreen"));
|
||||
else
|
||||
ImGui.PushStyleColor(ImGuiCol.Button, UIColors.Get("PairBlue"));
|
||||
|
||||
if (isOnCooldown || !_broadcastService.IsLightFinderAvailable)
|
||||
ImGui.BeginDisabled();
|
||||
|
||||
string buttonText = isBroadcasting ? "Disable Lightfinder" : "Enable Lightfinder";
|
||||
|
||||
if (ImGui.Button(buttonText, new Vector2(200 * ImGuiHelpers.GlobalScale, 0)))
|
||||
{
|
||||
_broadcastService.ToggleBroadcast();
|
||||
}
|
||||
|
||||
if (isOnCooldown || !_broadcastService.IsLightFinderAvailable)
|
||||
ImGui.EndDisabled();
|
||||
|
||||
ImGui.PopStyleColor();
|
||||
ImGui.PopStyleVar();
|
||||
|
||||
ImGui.EndTabItem();
|
||||
}
|
||||
|
||||
if (ImGui.BeginTabItem("Syncshell Finder"))
|
||||
{
|
||||
if (_allSyncshells == null)
|
||||
{
|
||||
ImGui.Text("Loading Syncshells...");
|
||||
return;
|
||||
}
|
||||
|
||||
_uiSharedService.MediumText("Syncshell Finder", UIColors.Get("PairBlue"));
|
||||
|
||||
_uiSharedService.ColoredSeparator(UIColors.Get("LightlessPurple"), 2f);
|
||||
|
||||
ImGui.PushTextWrapPos();
|
||||
ImGui.Text("Allow your owned Syncshell to be indexed by the Nearby Syncshell Finder.");
|
||||
ImGui.Text("To enable this, select one of your owned Syncshells from the dropdown menu below and ensure that \"Toggle Syncshell Finder\" is enabled. Your Syncshell will be visible in the Nearby Syncshell Finder as long as Lightfinder is active.");
|
||||
ImGui.PopTextWrapPos();
|
||||
|
||||
ImGuiHelpers.ScaledDummy(0.2f);
|
||||
_uiSharedService.ColoredSeparator(UIColors.Get("LightlessPurple"), 2f);
|
||||
|
||||
bool ShellFinderEnabled = _configService.Current.SyncshellFinderEnabled;
|
||||
bool isBroadcasting = _broadcastService.IsBroadcasting;
|
||||
|
||||
if (isBroadcasting)
|
||||
ImGui.BeginDisabled();
|
||||
|
||||
if (ImGui.Checkbox("Toggle Syncshell Finder", ref ShellFinderEnabled))
|
||||
{
|
||||
_configService.Current.SyncshellFinderEnabled = ShellFinderEnabled;
|
||||
_configService.Save();
|
||||
}
|
||||
|
||||
if (ImGui.IsItemHovered())
|
||||
{
|
||||
ImGui.BeginTooltip();
|
||||
ImGui.Text("Toggle to broadcast specified Syncshell.");
|
||||
ImGui.EndTooltip();
|
||||
}
|
||||
|
||||
var selectedGid = _configService.Current.SelectedFinderSyncshell;
|
||||
var currentOption = _syncshellOptions.FirstOrDefault(o => o.GID == selectedGid);
|
||||
var preview = currentOption.Label ?? "Select a Syncshell...";
|
||||
|
||||
if (ImGui.BeginCombo("##SyncshellDropdown", preview))
|
||||
{
|
||||
foreach (var (label, gid, available) in _syncshellOptions)
|
||||
{
|
||||
bool isSelected = gid == selectedGid;
|
||||
|
||||
if (!available)
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, UIColors.Get("DimRed"));
|
||||
|
||||
if (ImGui.Selectable(label, isSelected))
|
||||
{
|
||||
_configService.Current.SelectedFinderSyncshell = gid;
|
||||
_configService.Save();
|
||||
}
|
||||
|
||||
if (!available && ImGui.IsItemHovered())
|
||||
{
|
||||
ImGui.BeginTooltip();
|
||||
ImGui.Text("This Syncshell is not available on the current service.");
|
||||
ImGui.EndTooltip();
|
||||
}
|
||||
|
||||
if (!available)
|
||||
ImGui.PopStyleColor();
|
||||
|
||||
if (isSelected)
|
||||
ImGui.SetItemDefaultFocus();
|
||||
}
|
||||
|
||||
ImGui.EndCombo();
|
||||
}
|
||||
|
||||
|
||||
if (ImGui.IsItemHovered())
|
||||
{
|
||||
ImGui.BeginTooltip();
|
||||
ImGui.Text("Choose one of the available options.");
|
||||
ImGui.EndTooltip();
|
||||
}
|
||||
|
||||
|
||||
if (isBroadcasting)
|
||||
ImGui.EndDisabled();
|
||||
|
||||
ImGui.EndTabItem();
|
||||
}
|
||||
|
||||
if (ImGui.BeginTabItem("Debug"))
|
||||
{
|
||||
ImGui.Text("Broadcast Cache");
|
||||
|
||||
if (ImGui.BeginTable("##BroadcastCacheTable", 4, ImGuiTableFlags.RowBg | ImGuiTableFlags.Borders | ImGuiTableFlags.ScrollY, new Vector2(-1, 225f)))
|
||||
{
|
||||
ImGui.TableSetupColumn("CID", ImGuiTableColumnFlags.WidthStretch);
|
||||
ImGui.TableSetupColumn("IsBroadcasting", ImGuiTableColumnFlags.WidthStretch);
|
||||
ImGui.TableSetupColumn("Expires In", ImGuiTableColumnFlags.WidthStretch);
|
||||
ImGui.TableSetupColumn("Syncshell GID", ImGuiTableColumnFlags.WidthStretch);
|
||||
ImGui.TableHeadersRow();
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
|
||||
foreach (var (cid, entry) in _broadcastScannerService.BroadcastCache)
|
||||
{
|
||||
ImGui.TableNextRow();
|
||||
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.TextUnformatted(cid.Truncate(12));
|
||||
if (ImGui.IsItemHovered())
|
||||
{
|
||||
ImGui.BeginTooltip();
|
||||
ImGui.TextUnformatted(cid);
|
||||
ImGui.EndTooltip();
|
||||
}
|
||||
|
||||
ImGui.TableNextColumn();
|
||||
var colorBroadcast = entry.IsBroadcasting
|
||||
? UIColors.Get("LightlessGreen")
|
||||
: UIColors.Get("DimRed");
|
||||
|
||||
ImGui.TableSetBgColor(ImGuiTableBgTarget.CellBg, ImGui.GetColorU32(colorBroadcast));
|
||||
ImGui.TextUnformatted(entry.IsBroadcasting.ToString());
|
||||
|
||||
ImGui.TableNextColumn();
|
||||
var remaining = entry.ExpiryTime - now;
|
||||
var colorTtl =
|
||||
remaining <= TimeSpan.Zero ? UIColors.Get("DimRed") :
|
||||
remaining < TimeSpan.FromSeconds(10) ? UIColors.Get("LightlessYellow") :
|
||||
(Vector4?)null;
|
||||
|
||||
if (colorTtl != null)
|
||||
ImGui.TableSetBgColor(ImGuiTableBgTarget.CellBg, ImGui.GetColorU32(colorTtl.Value));
|
||||
|
||||
ImGui.TextUnformatted(remaining > TimeSpan.Zero
|
||||
? remaining.ToString("hh\\:mm\\:ss")
|
||||
: "Expired");
|
||||
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.TextUnformatted(entry.GID ?? "-");
|
||||
}
|
||||
|
||||
ImGui.EndTable();
|
||||
}
|
||||
|
||||
|
||||
ImGui.EndTabItem();
|
||||
}
|
||||
|
||||
ImGui.EndTabBar();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,7 +90,7 @@ internal sealed partial class CharaDataHubUi
|
||||
if (!_uiSharedService.IsInGpose)
|
||||
{
|
||||
ImGuiHelpers.ScaledDummy(5);
|
||||
UiSharedService.DrawGroupedCenteredColorText("Assigning users to characters is only available in GPose.", ImGuiColors.DalamudYellow, 300);
|
||||
UiSharedService.DrawGroupedCenteredColorText("Assigning users to characters is only available in GPose.", UIColors.Get("LightlessYellow"), 300);
|
||||
}
|
||||
UiSharedService.DistanceSeparator();
|
||||
ImGui.TextUnformatted("Users In Lobby");
|
||||
@@ -104,7 +104,7 @@ internal sealed partial class CharaDataHubUi
|
||||
|
||||
if (!_charaDataGposeTogetherManager.UsersInLobby.Any() && !string.IsNullOrEmpty(_charaDataGposeTogetherManager.CurrentGPoseLobbyId))
|
||||
{
|
||||
UiSharedService.DrawGroupedCenteredColorText("No other users in current GPose lobby", ImGuiColors.DalamudYellow);
|
||||
UiSharedService.DrawGroupedCenteredColorText("No other users in current GPose lobby", UIColors.Get("LightlessYellow"));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -23,7 +23,7 @@ internal sealed partial class CharaDataHubUi
|
||||
if (dataDto == null)
|
||||
{
|
||||
ImGuiHelpers.ScaledDummy(5);
|
||||
UiSharedService.DrawGroupedCenteredColorText("Select an entry above to edit its data.", ImGuiColors.DalamudYellow);
|
||||
UiSharedService.DrawGroupedCenteredColorText("Select an entry above to edit its data.", UIColors.Get("LightlessYellow"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ internal sealed partial class CharaDataHubUi
|
||||
|
||||
if (updateDto == null)
|
||||
{
|
||||
UiSharedService.DrawGroupedCenteredColorText("Something went awfully wrong and there's no update DTO. Try updating Character Data via the button above.", ImGuiColors.DalamudYellow);
|
||||
UiSharedService.DrawGroupedCenteredColorText("Something went awfully wrong and there's no update DTO. Try updating Character Data via the button above.", UIColors.Get("LightlessYellow"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ internal sealed partial class CharaDataHubUi
|
||||
}
|
||||
if (_charaDataManager.CharaUpdateTask != null && !_charaDataManager.CharaUpdateTask.IsCompleted)
|
||||
{
|
||||
UiSharedService.ColorTextWrapped("Updating data on server, please wait.", ImGuiColors.DalamudYellow);
|
||||
UiSharedService.ColorTextWrapped("Updating data on server, please wait.", UIColors.Get("LightlessYellow"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ internal sealed partial class CharaDataHubUi
|
||||
{
|
||||
if (_charaDataManager.UploadProgress != null)
|
||||
{
|
||||
UiSharedService.ColorTextWrapped(_charaDataManager.UploadProgress.Value ?? string.Empty, ImGuiColors.DalamudYellow);
|
||||
UiSharedService.ColorTextWrapped(_charaDataManager.UploadProgress.Value ?? string.Empty, UIColors.Get("LightlessYellow"));
|
||||
}
|
||||
if ((!_charaDataManager.UploadTask?.IsCompleted ?? false) && _uiSharedService.IconTextButton(FontAwesomeIcon.Ban, "Cancel Upload"))
|
||||
{
|
||||
@@ -112,7 +112,7 @@ internal sealed partial class CharaDataHubUi
|
||||
UiSharedService.DrawGrouped(() =>
|
||||
{
|
||||
ImGui.AlignTextToFramePadding();
|
||||
UiSharedService.ColorTextWrapped($"You have {otherUpdates} other entries with unsaved changes.", ImGuiColors.DalamudYellow);
|
||||
UiSharedService.ColorTextWrapped($"You have {otherUpdates} other entries with unsaved changes.", UIColors.Get("LightlessYellow"));
|
||||
ImGui.SameLine();
|
||||
using (ImRaii.Disabled(_charaDataManager.CharaUpdateTask != null && !_charaDataManager.CharaUpdateTask.IsCompleted))
|
||||
{
|
||||
@@ -259,7 +259,7 @@ internal sealed partial class CharaDataHubUi
|
||||
ImGui.SameLine();
|
||||
ImGuiHelpers.ScaledDummy(20, 1);
|
||||
ImGui.SameLine();
|
||||
UiSharedService.ColorTextWrapped("New data was set. It may contain files that require to be uploaded (will happen on Saving to server)", ImGuiColors.DalamudYellow);
|
||||
UiSharedService.ColorTextWrapped("New data was set. It may contain files that require to be uploaded (will happen on Saving to server)", UIColors.Get("LightlessYellow"));
|
||||
}
|
||||
|
||||
ImGui.TextUnformatted("Contains Manipulation Data");
|
||||
@@ -414,7 +414,7 @@ internal sealed partial class CharaDataHubUi
|
||||
}
|
||||
}
|
||||
ImGui.SameLine();
|
||||
using (ImRaii.PushColor(ImGuiCol.Text, ImGuiColors.DalamudYellow, poseCount == maxPoses))
|
||||
using (ImRaii.PushColor(ImGuiCol.Text, UIColors.Get("LightlessYellow"), poseCount == maxPoses))
|
||||
ImGui.TextUnformatted($"{poseCount}/{maxPoses} poses attached");
|
||||
ImGuiHelpers.ScaledDummy(5);
|
||||
|
||||
@@ -424,7 +424,7 @@ internal sealed partial class CharaDataHubUi
|
||||
if (!_uiSharedService.IsInGpose && _charaDataManager.BrioAvailable)
|
||||
{
|
||||
ImGuiHelpers.ScaledDummy(5);
|
||||
UiSharedService.DrawGroupedCenteredColorText("To attach pose and world data you need to be in GPose.", ImGuiColors.DalamudYellow);
|
||||
UiSharedService.DrawGroupedCenteredColorText("To attach pose and world data you need to be in GPose.", UIColors.Get("LightlessYellow"));
|
||||
ImGuiHelpers.ScaledDummy(5);
|
||||
}
|
||||
else if (!_charaDataManager.BrioAvailable)
|
||||
@@ -443,7 +443,7 @@ internal sealed partial class CharaDataHubUi
|
||||
if (pose.Id == null)
|
||||
{
|
||||
UiSharedService.ScaledSameLine(50);
|
||||
_uiSharedService.IconText(FontAwesomeIcon.Plus, ImGuiColors.DalamudYellow);
|
||||
_uiSharedService.IconText(FontAwesomeIcon.Plus, UIColors.Get("LightlessYellow"));
|
||||
UiSharedService.AttachToolTip("This pose has not been added to the server yet. Save changes to upload this Pose data.");
|
||||
}
|
||||
|
||||
@@ -451,14 +451,14 @@ internal sealed partial class CharaDataHubUi
|
||||
if (poseHasChanges)
|
||||
{
|
||||
UiSharedService.ScaledSameLine(50);
|
||||
_uiSharedService.IconText(FontAwesomeIcon.ExclamationTriangle, ImGuiColors.DalamudYellow);
|
||||
_uiSharedService.IconText(FontAwesomeIcon.ExclamationTriangle, UIColors.Get("LightlessYellow"));
|
||||
UiSharedService.AttachToolTip("This pose has changes that have not been saved to the server yet.");
|
||||
}
|
||||
|
||||
UiSharedService.ScaledSameLine(75);
|
||||
if (pose.Description == null && pose.WorldData == null && pose.PoseData == null)
|
||||
{
|
||||
UiSharedService.ColorText("Pose scheduled for deletion", ImGuiColors.DalamudYellow);
|
||||
UiSharedService.ColorText("Pose scheduled for deletion", UIColors.Get("LightlessYellow"));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -669,7 +669,7 @@ internal sealed partial class CharaDataHubUi
|
||||
var idText = entry.FullId;
|
||||
if (uDto?.HasChanges ?? false)
|
||||
{
|
||||
UiSharedService.ColorText(idText, ImGuiColors.DalamudYellow);
|
||||
UiSharedService.ColorText(idText, UIColors.Get("LightlessYellow"));
|
||||
UiSharedService.AttachToolTip("This entry has unsaved changes");
|
||||
}
|
||||
else
|
||||
@@ -724,7 +724,7 @@ internal sealed partial class CharaDataHubUi
|
||||
FontAwesomeIcon eIcon = FontAwesomeIcon.None;
|
||||
if (!Equals(DateTime.MaxValue, entry.ExpiryDate))
|
||||
eIcon = FontAwesomeIcon.Clock;
|
||||
_uiSharedService.IconText(eIcon, ImGuiColors.DalamudYellow);
|
||||
_uiSharedService.IconText(eIcon, UIColors.Get("LightlessYellow"));
|
||||
if (ImGui.IsItemClicked()) SelectedDtoId = entry.Id;
|
||||
if (eIcon != FontAwesomeIcon.None)
|
||||
{
|
||||
@@ -759,13 +759,13 @@ internal sealed partial class CharaDataHubUi
|
||||
if (_charaDataManager.OwnCharaData.Count == _charaDataManager.MaxCreatableCharaData)
|
||||
{
|
||||
ImGui.AlignTextToFramePadding();
|
||||
UiSharedService.ColorTextWrapped("You have reached the maximum Character Data entries and cannot create more.", ImGuiColors.DalamudYellow);
|
||||
UiSharedService.ColorTextWrapped("You have reached the maximum Character Data entries and cannot create more.", UIColors.Get("LightlessYellow"));
|
||||
}
|
||||
}
|
||||
|
||||
if (_charaDataManager.DataCreationTask != null && !_charaDataManager.DataCreationTask.IsCompleted)
|
||||
{
|
||||
UiSharedService.ColorTextWrapped("Creating new character data entry on server...", ImGuiColors.DalamudYellow);
|
||||
UiSharedService.ColorTextWrapped("Creating new character data entry on server...", UIColors.Get("LightlessYellow"));
|
||||
}
|
||||
else if (_charaDataManager.DataCreationTask != null && _charaDataManager.DataCreationTask.IsCompleted)
|
||||
{
|
||||
|
||||
@@ -78,7 +78,7 @@ internal partial class CharaDataHubUi
|
||||
if (!_uiSharedService.IsInGpose)
|
||||
{
|
||||
ImGuiHelpers.ScaledDummy(5);
|
||||
UiSharedService.DrawGroupedCenteredColorText("Spawning and applying pose data is only available in GPose.", ImGuiColors.DalamudYellow);
|
||||
UiSharedService.DrawGroupedCenteredColorText("Spawning and applying pose data is only available in GPose.", UIColors.Get("LightlessYellow"));
|
||||
ImGuiHelpers.ScaledDummy(5);
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ internal partial class CharaDataHubUi
|
||||
using var indent = ImRaii.PushIndent(5f);
|
||||
if (_charaDataNearbyManager.NearbyData.Count == 0)
|
||||
{
|
||||
UiSharedService.DrawGroupedCenteredColorText("No Shared World Poses found nearby.", ImGuiColors.DalamudYellow);
|
||||
UiSharedService.DrawGroupedCenteredColorText("No Shared World Poses found nearby.", UIColors.Get("LightlessYellow"));
|
||||
}
|
||||
|
||||
bool wasAnythingHovered = false;
|
||||
|
||||
@@ -190,7 +190,7 @@ internal sealed partial class CharaDataHubUi : WindowMediatorSubscriberBase
|
||||
}
|
||||
if (!string.IsNullOrEmpty(_charaDataManager.DataApplicationProgress))
|
||||
{
|
||||
UiSharedService.ColorTextWrapped(_charaDataManager.DataApplicationProgress, ImGuiColors.DalamudYellow);
|
||||
UiSharedService.ColorTextWrapped(_charaDataManager.DataApplicationProgress, UIColors.Get("LightlessYellow"));
|
||||
}
|
||||
if (_charaDataManager.DataApplicationTask != null)
|
||||
{
|
||||
@@ -436,7 +436,7 @@ internal sealed partial class CharaDataHubUi : WindowMediatorSubscriberBase
|
||||
if (!_hasValidGposeTarget)
|
||||
{
|
||||
ImGuiHelpers.ScaledDummy(3);
|
||||
UiSharedService.DrawGroupedCenteredColorText("Applying data is only available in GPose with a valid selected GPose target.", ImGuiColors.DalamudYellow, 350);
|
||||
UiSharedService.DrawGroupedCenteredColorText("Applying data is only available in GPose with a valid selected GPose target.", UIColors.Get("LightlessYellow"), 350);
|
||||
}
|
||||
|
||||
ImGuiHelpers.ScaledDummy(10);
|
||||
@@ -595,7 +595,7 @@ internal sealed partial class CharaDataHubUi : WindowMediatorSubscriberBase
|
||||
|
||||
if (_configService.Current.FavoriteCodes.Count == 0)
|
||||
{
|
||||
UiSharedService.ColorTextWrapped("You have no favorites added. Add Favorites through the other tabs before you can use this tab.", ImGuiColors.DalamudYellow);
|
||||
UiSharedService.ColorTextWrapped("You have no favorites added. Add Favorites through the other tabs before you can use this tab.", UIColors.Get("LightlessYellow"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -644,7 +644,7 @@ internal sealed partial class CharaDataHubUi : WindowMediatorSubscriberBase
|
||||
ImGui.NewLine();
|
||||
if (!_charaDataManager.DownloadMetaInfoTask?.IsCompleted ?? false)
|
||||
{
|
||||
UiSharedService.ColorTextWrapped("Downloading meta info. Please wait.", ImGuiColors.DalamudYellow);
|
||||
UiSharedService.ColorTextWrapped("Downloading meta info. Please wait.", UIColors.Get("LightlessYellow"));
|
||||
}
|
||||
if ((_charaDataManager.DownloadMetaInfoTask?.IsCompleted ?? false) && !_charaDataManager.DownloadMetaInfoTask.Result.Success)
|
||||
{
|
||||
@@ -850,12 +850,12 @@ internal sealed partial class CharaDataHubUi : WindowMediatorSubscriberBase
|
||||
UiSharedService.ColorTextWrapped("Failure to read MCDF file. MCDF file is possibly corrupt. Re-export the MCDF file and try again.",
|
||||
ImGuiColors.DalamudRed);
|
||||
UiSharedService.ColorTextWrapped("Note: if this is your MCDF, try redrawing yourself, wait and re-export the file. " +
|
||||
"If you received it from someone else have them do the same.", ImGuiColors.DalamudYellow);
|
||||
"If you received it from someone else have them do the same.", UIColors.Get("LightlessYellow"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UiSharedService.ColorTextWrapped("Loading Character...", ImGuiColors.DalamudYellow);
|
||||
UiSharedService.ColorTextWrapped("Loading Character...", UIColors.Get("LightlessYellow"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -896,7 +896,7 @@ internal sealed partial class CharaDataHubUi : WindowMediatorSubscriberBase
|
||||
}, Directory.Exists(_configService.Current.LastSavedCharaDataLocation) ? _configService.Current.LastSavedCharaDataLocation : null);
|
||||
}
|
||||
UiSharedService.ColorTextWrapped("Note: For best results make sure you have everything you want to be shared as well as the correct character appearance" +
|
||||
" equipped and redraw your character before exporting.", ImGuiColors.DalamudYellow);
|
||||
" equipped and redraw your character before exporting.", UIColors.Get("LightlessYellow"));
|
||||
|
||||
ImGui.Unindent();
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using Dalamud.Bindings.ImGui;
|
||||
using Dalamud.Interface;
|
||||
using Dalamud.Interface.Colors;
|
||||
using Dalamud.Interface.Utility;
|
||||
using Dalamud.Interface.Utility.Raii;
|
||||
using Dalamud.Utility;
|
||||
using LightlessSync.API.Data.Enum;
|
||||
using LightlessSync.API.Data.Extensions;
|
||||
using LightlessSync.API.Dto.Group;
|
||||
using LightlessSync.Interop.Ipc;
|
||||
@@ -15,6 +15,7 @@ using LightlessSync.Services.Mediator;
|
||||
using LightlessSync.Services.ServerConfiguration;
|
||||
using LightlessSync.UI.Components;
|
||||
using LightlessSync.UI.Handlers;
|
||||
using LightlessSync.Utils;
|
||||
using LightlessSync.WebAPI;
|
||||
using LightlessSync.WebAPI.Files;
|
||||
using LightlessSync.WebAPI.Files.Models;
|
||||
@@ -30,35 +31,61 @@ namespace LightlessSync.UI;
|
||||
|
||||
public class CompactUi : WindowMediatorSubscriberBase
|
||||
{
|
||||
private readonly CharacterAnalyzer _characterAnalyzer;
|
||||
private readonly ApiController _apiController;
|
||||
private readonly LightlessConfigService _configService;
|
||||
private readonly LightlessMediator _lightlessMediator;
|
||||
private readonly ConcurrentDictionary<GameObjectHandler, Dictionary<string, FileDownloadStatus>> _currentDownloads = new();
|
||||
private readonly DrawEntityFactory _drawEntityFactory;
|
||||
private readonly FileUploadManager _fileTransferManager;
|
||||
private readonly PlayerPerformanceConfigService _playerPerformanceConfig;
|
||||
private readonly PairManager _pairManager;
|
||||
private readonly SelectTagForPairUi _selectGroupForPairUi;
|
||||
private readonly SelectTagForPairUi _selectTagForPairUi;
|
||||
private readonly SelectTagForSyncshellUi _selectTagForSyncshellUi;
|
||||
private readonly SelectSyncshellForTagUi _selectSyncshellForTagUi;
|
||||
private readonly RenameSyncshellTagUi _renameSyncshellTagUi;
|
||||
private readonly SelectPairForTagUi _selectPairsForGroupUi;
|
||||
private readonly RenamePairTagUi _renamePairTagUi;
|
||||
private readonly IpcManager _ipcManager;
|
||||
private readonly ServerConfigurationManager _serverManager;
|
||||
private readonly TopTabMenu _tabMenu;
|
||||
private readonly TagHandler _tagHandler;
|
||||
private readonly UiSharedService _uiSharedService;
|
||||
private readonly BroadcastService _broadcastService;
|
||||
|
||||
private List<IDrawFolder> _drawFolders;
|
||||
private Dictionary<ObjectKind, Dictionary<string, CharacterAnalyzer.FileDataEntry>>? _cachedAnalysis;
|
||||
private Pair? _lastAddedUser;
|
||||
private string _lastAddedUserComment = string.Empty;
|
||||
private Vector2 _lastPosition = Vector2.One;
|
||||
private Vector2 _lastSize = Vector2.One;
|
||||
private int _secretKeyIdx = -1;
|
||||
private bool _showModalForUserAddition;
|
||||
private float _transferPartHeight;
|
||||
private bool _wasOpen;
|
||||
private float _windowContentWidth;
|
||||
|
||||
public CompactUi(ILogger<CompactUi> logger, UiSharedService uiShared, LightlessConfigService configService, ApiController apiController, PairManager pairManager,
|
||||
ServerConfigurationManager serverManager, LightlessMediator mediator, FileUploadManager fileTransferManager,
|
||||
TagHandler tagHandler, DrawEntityFactory drawEntityFactory, SelectTagForPairUi selectTagForPairUi, SelectPairForTagUi selectPairForTagUi,
|
||||
PerformanceCollectorService performanceCollectorService, IpcManager ipcManager)
|
||||
: base(logger, mediator, "###LightlessSyncMainUI", performanceCollectorService)
|
||||
public CompactUi(
|
||||
ILogger<CompactUi> logger,
|
||||
UiSharedService uiShared,
|
||||
LightlessConfigService configService,
|
||||
ApiController apiController,
|
||||
PairManager pairManager,
|
||||
ServerConfigurationManager serverManager,
|
||||
LightlessMediator mediator,
|
||||
FileUploadManager fileTransferManager,
|
||||
TagHandler tagHandler,
|
||||
DrawEntityFactory drawEntityFactory,
|
||||
SelectTagForPairUi selectTagForPairUi,
|
||||
SelectPairForTagUi selectPairForTagUi,
|
||||
RenamePairTagUi renameTagUi,
|
||||
SelectTagForSyncshellUi selectTagForSyncshellUi,
|
||||
SelectSyncshellForTagUi selectSyncshellForTagUi,
|
||||
RenameSyncshellTagUi renameSyncshellTagUi,
|
||||
PerformanceCollectorService performanceCollectorService,
|
||||
IpcManager ipcManager,
|
||||
BroadcastService broadcastService,
|
||||
CharacterAnalyzer characterAnalyzer,
|
||||
PlayerPerformanceConfigService playerPerformanceConfig) : base(logger, mediator, "###LightlessSyncMainUI", performanceCollectorService)
|
||||
{
|
||||
_uiSharedService = uiShared;
|
||||
_configService = configService;
|
||||
@@ -68,12 +95,17 @@ public class CompactUi : WindowMediatorSubscriberBase
|
||||
_fileTransferManager = fileTransferManager;
|
||||
_tagHandler = tagHandler;
|
||||
_drawEntityFactory = drawEntityFactory;
|
||||
_selectGroupForPairUi = selectTagForPairUi;
|
||||
_selectTagForPairUi = selectTagForPairUi;
|
||||
_selectTagForSyncshellUi = selectTagForSyncshellUi;
|
||||
_selectSyncshellForTagUi = selectSyncshellForTagUi;
|
||||
_renameSyncshellTagUi = renameSyncshellTagUi;
|
||||
_selectPairsForGroupUi = selectPairForTagUi;
|
||||
_renamePairTagUi = renameTagUi;
|
||||
_ipcManager = ipcManager;
|
||||
_broadcastService = broadcastService;
|
||||
_tabMenu = new TopTabMenu(Mediator, _apiController, _pairManager, _uiSharedService);
|
||||
|
||||
AllowPinning = false;
|
||||
AllowPinning = true;
|
||||
AllowClickthrough = false;
|
||||
TitleBarButtons = new()
|
||||
{
|
||||
@@ -106,10 +138,10 @@ public class CompactUi : WindowMediatorSubscriberBase
|
||||
ImGui.Text("Open Lightless Event Viewer");
|
||||
ImGui.EndTooltip();
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
_drawFolders = GetDrawFolders().ToList();
|
||||
_drawFolders = [.. GetDrawFolders()];
|
||||
|
||||
#if DEBUG
|
||||
string dev = "Dev Build";
|
||||
@@ -135,6 +167,9 @@ public class CompactUi : WindowMediatorSubscriberBase
|
||||
MinimumSize = new Vector2(375, 400),
|
||||
MaximumSize = new Vector2(375, 2000),
|
||||
};
|
||||
_characterAnalyzer = characterAnalyzer;
|
||||
_playerPerformanceConfig = playerPerformanceConfig;
|
||||
_lightlessMediator = mediator;
|
||||
}
|
||||
|
||||
protected override void DrawInternal()
|
||||
@@ -149,10 +184,10 @@ public class CompactUi : WindowMediatorSubscriberBase
|
||||
var uidTextSize = ImGui.CalcTextSize(unsupported);
|
||||
ImGui.SetCursorPosX((ImGui.GetWindowContentRegionMax().X + ImGui.GetWindowContentRegionMin().X) / 2 - uidTextSize.X / 2);
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.TextColored(ImGuiColors.DalamudRed, unsupported);
|
||||
ImGui.TextColored(UIColors.Get("DimRed"), unsupported);
|
||||
}
|
||||
UiSharedService.ColorTextWrapped($"Your Lightless Sync installation is out of date, the current version is {ver.Major}.{ver.Minor}.{ver.Build}. " +
|
||||
$"It is highly recommended to keep Lightless Sync up to date. Open /xlplugins and update the plugin.", ImGuiColors.DalamudRed);
|
||||
$"It is highly recommended to keep Lightless Sync up to date. Open /xlplugins and update the plugin.", UIColors.Get("DimRed"));
|
||||
}
|
||||
|
||||
if (!_ipcManager.Initialized)
|
||||
@@ -164,12 +199,12 @@ public class CompactUi : WindowMediatorSubscriberBase
|
||||
var uidTextSize = ImGui.CalcTextSize(unsupported);
|
||||
ImGui.SetCursorPosX((ImGui.GetWindowContentRegionMax().X + ImGui.GetWindowContentRegionMin().X) / 2 - uidTextSize.X / 2);
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.TextColored(ImGuiColors.DalamudRed, unsupported);
|
||||
ImGui.TextColored(UIColors.Get("DimRed"), unsupported);
|
||||
}
|
||||
var penumAvailable = _ipcManager.Penumbra.APIAvailable;
|
||||
var glamAvailable = _ipcManager.Glamourer.APIAvailable;
|
||||
|
||||
UiSharedService.ColorTextWrapped($"One or more Plugins essential for Lightless operation are unavailable. Enable or update following plugins:", ImGuiColors.DalamudRed);
|
||||
UiSharedService.ColorTextWrapped($"One or more Plugins essential for Lightless operation are unavailable. Enable or update following plugins:", UIColors.Get("DimRed"));
|
||||
using var indent = ImRaii.PushIndent(10f);
|
||||
if (!penumAvailable)
|
||||
{
|
||||
@@ -185,7 +220,7 @@ public class CompactUi : WindowMediatorSubscriberBase
|
||||
}
|
||||
|
||||
using (ImRaii.PushId("header")) DrawUIDHeader();
|
||||
ImGui.Separator();
|
||||
_uiSharedService.RoundedSeparator(UIColors.Get("LightlessPurple"), 2.5f, 1f, 12f);
|
||||
using (ImRaii.PushId("serverstatus")) DrawServerStatus();
|
||||
ImGui.Separator();
|
||||
|
||||
@@ -197,8 +232,12 @@ public class CompactUi : WindowMediatorSubscriberBase
|
||||
float pairlistEnd = ImGui.GetCursorPosY();
|
||||
using (ImRaii.PushId("transfers")) DrawTransfers();
|
||||
_transferPartHeight = ImGui.GetCursorPosY() - pairlistEnd - ImGui.GetTextLineHeight();
|
||||
using (ImRaii.PushId("group-user-popup")) _selectPairsForGroupUi.Draw(_pairManager.DirectPairs);
|
||||
using (ImRaii.PushId("grouping-popup")) _selectGroupForPairUi.Draw();
|
||||
using (ImRaii.PushId("group-pair-popup")) _selectPairsForGroupUi.Draw(_pairManager.DirectPairs);
|
||||
using (ImRaii.PushId("group-syncshell-popup")) _selectSyncshellForTagUi.Draw([.. _pairManager.Groups.Values]);
|
||||
using (ImRaii.PushId("group-pair-edit")) _renamePairTagUi.Draw();
|
||||
using (ImRaii.PushId("group-syncshell-edit")) _renameSyncshellTagUi.Draw();
|
||||
using (ImRaii.PushId("grouping-pair-popup")) _selectTagForPairUi.Draw();
|
||||
using (ImRaii.PushId("grouping-syncshell-popup")) _selectTagForSyncshellUi.Draw();
|
||||
}
|
||||
|
||||
if (_configService.Current.OpenPopupOnAdd && _pairManager.LastAddedUser != null)
|
||||
@@ -284,7 +323,7 @@ public class CompactUi : WindowMediatorSubscriberBase
|
||||
else
|
||||
{
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.TextColored(ImGuiColors.DalamudRed, "Not connected to any server");
|
||||
ImGui.TextColored(UIColors.Get("DimRed"), "Not connected to any server");
|
||||
}
|
||||
|
||||
if (printShard)
|
||||
@@ -393,11 +432,158 @@ public class CompactUi : WindowMediatorSubscriberBase
|
||||
{
|
||||
var uidText = GetUidText();
|
||||
|
||||
//Getting information of character and triangles threshold to show overlimit status in UID bar.
|
||||
_cachedAnalysis = _characterAnalyzer.LastAnalysis.DeepClone();
|
||||
|
||||
Vector2 uidTextSize, iconSize;
|
||||
using (_uiSharedService.UidFont.Push())
|
||||
uidTextSize = ImGui.CalcTextSize(uidText);
|
||||
|
||||
using (_uiSharedService.IconFont.Push())
|
||||
iconSize = ImGui.CalcTextSize(FontAwesomeIcon.PersonCirclePlus.ToIconString());
|
||||
|
||||
float contentWidth = ImGui.GetWindowContentRegionMax().X - ImGui.GetWindowContentRegionMin().X;
|
||||
float uidStartX = (contentWidth - uidTextSize.X) / 2f;
|
||||
float cursorY = ImGui.GetCursorPosY();
|
||||
|
||||
if (_configService.Current.BroadcastEnabled)
|
||||
{
|
||||
float iconYOffset = (uidTextSize.Y - iconSize.Y) * 0.5f;
|
||||
var buttonSize = new Vector2(iconSize.X, uidTextSize.Y);
|
||||
|
||||
ImGui.SetCursorPos(new Vector2(ImGui.GetStyle().ItemSpacing.X + 5f, cursorY));
|
||||
ImGui.InvisibleButton("BroadcastIcon", buttonSize);
|
||||
|
||||
var iconPos = ImGui.GetItemRectMin() + new Vector2(0f, iconYOffset);
|
||||
using (_uiSharedService.IconFont.Push())
|
||||
ImGui.GetWindowDrawList().AddText(iconPos, ImGui.GetColorU32(UIColors.Get("LightlessGreen")), FontAwesomeIcon.PersonCirclePlus.ToIconString());
|
||||
|
||||
|
||||
if (ImGui.IsItemHovered())
|
||||
{
|
||||
ImGui.BeginTooltip();
|
||||
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, UIColors.Get("PairBlue"));
|
||||
ImGui.Text("Lightfinder");
|
||||
ImGui.PopStyleColor();
|
||||
|
||||
ImGui.Text("This lets other Lightless users know you use Lightless.");
|
||||
ImGui.Text("By enabling this, the server will allow other people to see that you are using Lightless.");
|
||||
ImGui.Text("When disabled, pairing is still possible but both parties need to mutually send each other requests, receiving party will not be notified about the request unless the pairing is complete.");
|
||||
ImGui.Text("At no point ever, even when Lightfinder is active that any Lightless data is getting sent to other people (including ID's), the server keeps this to itself.");
|
||||
ImGui.Text("You can request to pair by right-clicking any (not yourself) character and using 'Send Pair Request'.");
|
||||
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, UIColors.Get("DimRed"));
|
||||
ImGui.Text("Use it only when you want to be visible.");
|
||||
ImGui.PopStyleColor();
|
||||
|
||||
ImGuiHelpers.ScaledDummy(0.2f);
|
||||
_uiSharedService.ColoredSeparator(UIColors.Get("LightlessPurple"), 2f);
|
||||
|
||||
if (_configService.Current.BroadcastEnabled)
|
||||
{
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, UIColors.Get("LightlessGreen"));
|
||||
ImGui.Text("The Lightfinder calls, and somewhere, a soul may answer."); // cringe..
|
||||
ImGui.PopStyleColor();
|
||||
|
||||
var ttl = _broadcastService.RemainingTtl;
|
||||
if (ttl is { } remaining && remaining > TimeSpan.Zero)
|
||||
{
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, UIColors.Get("LightlessYellow"));
|
||||
ImGui.Text($"Still shining, for {remaining:hh\\:mm\\:ss}");
|
||||
ImGui.PopStyleColor();
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, UIColors.Get("DimRed"));
|
||||
ImGui.Text("The Lightfinder's light wanes, but not in vain."); // cringe..
|
||||
ImGui.PopStyleColor();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, UIColors.Get("DimRed"));
|
||||
ImGui.Text("The Lightfinder rests, waiting to shine again."); // cringe..
|
||||
ImGui.PopStyleColor();
|
||||
}
|
||||
|
||||
var cooldown = _broadcastService.RemainingCooldown;
|
||||
if (cooldown is { } cd)
|
||||
{
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, UIColors.Get("DimRed"));
|
||||
ImGui.Text($"The Lightfinder gathers its strength... ({Math.Ceiling(cd.TotalSeconds)}s)");
|
||||
ImGui.PopStyleColor();
|
||||
}
|
||||
|
||||
ImGui.EndTooltip();
|
||||
}
|
||||
|
||||
if (ImGui.IsItemClicked())
|
||||
_lightlessMediator.Publish(new UiToggleMessage(typeof(BroadcastUI)));
|
||||
}
|
||||
|
||||
ImGui.SetCursorPosY(cursorY);
|
||||
ImGui.SetCursorPosX(uidStartX);
|
||||
using (_uiSharedService.UidFont.Push())
|
||||
{
|
||||
var uidTextSize = ImGui.CalcTextSize(uidText);
|
||||
ImGui.SetCursorPosX((ImGui.GetWindowContentRegionMax().X - ImGui.GetWindowContentRegionMin().X) / 2 - (uidTextSize.X / 2));
|
||||
ImGui.TextColored(GetUidColor(), uidText);
|
||||
if (ImGui.IsItemClicked())
|
||||
ImGui.SetClipboardText(uidText);
|
||||
}
|
||||
UiSharedService.AttachToolTip("Click to copy");
|
||||
|
||||
if (_cachedAnalysis != null && _apiController.ServerState is ServerState.Connected)
|
||||
{
|
||||
var firstEntry = _cachedAnalysis.FirstOrDefault();
|
||||
var valueDict = firstEntry.Value;
|
||||
if (valueDict != null && valueDict.Count > 0)
|
||||
{
|
||||
var groupedfiles = valueDict
|
||||
.Select(v => v.Value)
|
||||
.Where(v => v != null)
|
||||
.GroupBy(f => f.FileType, StringComparer.Ordinal)
|
||||
.OrderBy(k => k.Key, StringComparer.Ordinal)
|
||||
.ToList();
|
||||
|
||||
var actualTriCount = valueDict
|
||||
.Select(v => v.Value)
|
||||
.Where(v => v != null)
|
||||
.Sum(f => f.Triangles);
|
||||
|
||||
if (groupedfiles != null)
|
||||
{
|
||||
//Checking of VRAM threshhold
|
||||
var texGroup = groupedfiles.SingleOrDefault(v => string.Equals(v.Key, "tex", StringComparison.Ordinal));
|
||||
var actualVramUsage = texGroup != null ? texGroup.Sum(f => f.OriginalSize) : 0L;
|
||||
var isOverVRAMUsage = _playerPerformanceConfig.Current.VRAMSizeWarningThresholdMiB * 1024 * 1024 < actualVramUsage;
|
||||
var isOverTriHold = actualTriCount > (_playerPerformanceConfig.Current.TrisWarningThresholdThousands * 1000);
|
||||
|
||||
if ((isOverTriHold || isOverVRAMUsage) && _playerPerformanceConfig.Current.WarnOnExceedingThresholds)
|
||||
{
|
||||
ImGui.SameLine();
|
||||
_uiSharedService.IconText(FontAwesomeIcon.ExclamationTriangle, UIColors.Get("LightlessYellow"));
|
||||
|
||||
string warningMessage = "";
|
||||
if (isOverTriHold)
|
||||
{
|
||||
warningMessage += $"You exceed your own triangles threshold by " +
|
||||
$"{actualTriCount - _playerPerformanceConfig.Current.TrisWarningThresholdThousands * 1000} triangles.";
|
||||
warningMessage += Environment.NewLine;
|
||||
|
||||
}
|
||||
if (isOverVRAMUsage)
|
||||
{
|
||||
warningMessage += $"You exceed your own VRAM threshold by " +
|
||||
$"{UiSharedService.ByteToString(actualVramUsage - (_playerPerformanceConfig.Current.VRAMSizeWarningThresholdMiB * 1024 * 1024))}.";
|
||||
}
|
||||
UiSharedService.AttachToolTip(warningMessage);
|
||||
if (ImGui.IsItemClicked())
|
||||
{
|
||||
_lightlessMediator.Publish(new UiToggleMessage(typeof(DataAnalysisUi)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_apiController.ServerState is ServerState.Connected)
|
||||
@@ -406,18 +592,17 @@ public class CompactUi : WindowMediatorSubscriberBase
|
||||
{
|
||||
ImGui.SetClipboardText(_apiController.DisplayName);
|
||||
}
|
||||
UiSharedService.AttachToolTip("Click to copy");
|
||||
|
||||
if (!string.Equals(_apiController.DisplayName, _apiController.UID, StringComparison.Ordinal))
|
||||
{
|
||||
var origTextSize = ImGui.CalcTextSize(_apiController.UID);
|
||||
ImGui.SetCursorPosX((ImGui.GetWindowContentRegionMax().X - ImGui.GetWindowContentRegionMin().X) / 2 - (origTextSize.X / 2));
|
||||
ImGui.TextColored(GetUidColor(), _apiController.UID);
|
||||
UiSharedService.AttachToolTip("Click to copy");
|
||||
if (ImGui.IsItemClicked())
|
||||
{
|
||||
ImGui.SetClipboardText(_apiController.UID);
|
||||
_lightlessMediator.Publish(new UiToggleMessage(typeof(DataAnalysisUi)));
|
||||
}
|
||||
UiSharedService.AttachToolTip("Click to copy");
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -459,12 +644,14 @@ public class CompactUi : WindowMediatorSubscriberBase
|
||||
bool FilterVisibleUsers(KeyValuePair<Pair, List<GroupFullInfoDto>> u)
|
||||
=> u.Key.IsVisible
|
||||
&& (_configService.Current.ShowSyncshellUsersInVisible || !(!_configService.Current.ShowSyncshellUsersInVisible && !u.Key.IsDirectlyPaired));
|
||||
bool FilterTagusers(KeyValuePair<Pair, List<GroupFullInfoDto>> u, string tag)
|
||||
=> u.Key.IsDirectlyPaired && !u.Key.IsOneSidedPair && _tagHandler.HasTag(u.Key.UserData.UID, tag);
|
||||
bool FilterTagUsers(KeyValuePair<Pair, List<GroupFullInfoDto>> u, string tag)
|
||||
=> u.Key.IsDirectlyPaired && !u.Key.IsOneSidedPair && _tagHandler.HasPairTag(u.Key.UserData.UID, tag);
|
||||
bool FilterGroupUsers(KeyValuePair<Pair, List<GroupFullInfoDto>> u, GroupFullInfoDto group)
|
||||
=> u.Value.Exists(g => string.Equals(g.GID, group.GID, StringComparison.Ordinal));
|
||||
bool FilterNotTaggedUsers(KeyValuePair<Pair, List<GroupFullInfoDto>> u)
|
||||
=> u.Key.IsDirectlyPaired && !u.Key.IsOneSidedPair && !_tagHandler.HasAnyTag(u.Key.UserData.UID);
|
||||
=> u.Key.IsDirectlyPaired && !u.Key.IsOneSidedPair && !_tagHandler.HasAnyPairTag(u.Key.UserData.UID);
|
||||
bool FilterNotTaggedSyncshells(GroupFullInfoDto group)
|
||||
=> (!_tagHandler.HasAnySyncshellTag(group.GID) && !_configService.Current.ShowGroupedSyncshellsInAll) || true;
|
||||
bool FilterOfflineUsers(KeyValuePair<Pair, List<GroupFullInfoDto>> u)
|
||||
=> ((u.Key.IsDirectlyPaired && _configService.Current.ShowSyncshellOfflineUsersSeparately)
|
||||
|| !_configService.Current.ShowSyncshellOfflineUsersSeparately)
|
||||
@@ -484,46 +671,51 @@ public class CompactUi : WindowMediatorSubscriberBase
|
||||
}
|
||||
|
||||
List<IDrawFolder> groupFolders = new();
|
||||
|
||||
foreach (var group in _pairManager.GroupPairs.Select(g => g.Key).OrderBy(g => g.GroupAliasOrGID, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
var allGroupPairs = ImmutablePairList(allPairs
|
||||
.Where(u => FilterGroupUsers(u, group)));
|
||||
|
||||
var filteredGroupPairs = filteredPairs
|
||||
.Where(u => FilterGroupUsers(u, group) && FilterOnlineOrPausedSelf(u))
|
||||
.OrderByDescending(u => u.Key.IsOnline)
|
||||
.ThenBy(u =>
|
||||
{
|
||||
if (string.Equals(u.Key.UserData.UID, group.OwnerUID, StringComparison.Ordinal)) return 0;
|
||||
if (group.GroupPairUserInfos.TryGetValue(u.Key.UserData.UID, out var info))
|
||||
{
|
||||
if (info.IsModerator()) return 1;
|
||||
if (info.IsPinned()) return 2;
|
||||
}
|
||||
return u.Key.IsVisible ? 3 : 4;
|
||||
})
|
||||
.ThenBy(AlphabeticalSort, StringComparer.OrdinalIgnoreCase)
|
||||
.ToDictionary(k => k.Key, k => k.Value);
|
||||
|
||||
groupFolders.Add(_drawEntityFactory.CreateDrawGroupFolder(group, filteredGroupPairs, allGroupPairs));
|
||||
GetGroups(allPairs, filteredPairs, group, out ImmutableList<Pair> allGroupPairs, out Dictionary<Pair, List<GroupFullInfoDto>> filteredGroupPairs);
|
||||
if (FilterNotTaggedSyncshells(group))
|
||||
{
|
||||
groupFolders.Add(_drawEntityFactory.CreateDrawGroupFolder(group, filteredGroupPairs, allGroupPairs));
|
||||
}
|
||||
}
|
||||
|
||||
if (_configService.Current.GroupUpSyncshells)
|
||||
drawFolders.Add(new DrawGroupedGroupFolder(groupFolders, _tagHandler, _uiSharedService));
|
||||
drawFolders.Add(new DrawGroupedGroupFolder(groupFolders, _tagHandler, _uiSharedService, _selectSyncshellForTagUi, _renameSyncshellTagUi, ""));
|
||||
else
|
||||
drawFolders.AddRange(groupFolders);
|
||||
|
||||
var tags = _tagHandler.GetAllTagsSorted();
|
||||
var tags = _tagHandler.GetAllPairTagsSorted();
|
||||
foreach (var tag in tags)
|
||||
{
|
||||
var allTagPairs = ImmutablePairList(allPairs
|
||||
.Where(u => FilterTagusers(u, tag)));
|
||||
.Where(u => FilterTagUsers(u, tag)));
|
||||
var filteredTagPairs = BasicSortedDictionary(filteredPairs
|
||||
.Where(u => FilterTagusers(u, tag) && FilterOnlineOrPausedSelf(u)));
|
||||
.Where(u => FilterTagUsers(u, tag) && FilterOnlineOrPausedSelf(u)));
|
||||
|
||||
drawFolders.Add(_drawEntityFactory.CreateDrawTagFolder(tag, filteredTagPairs, allTagPairs));
|
||||
}
|
||||
|
||||
var syncshellTags = _tagHandler.GetAllSyncshellTagsSorted();
|
||||
foreach (var syncshelltag in syncshellTags)
|
||||
{
|
||||
List<IDrawFolder> syncshellFolderTags = [];
|
||||
foreach (var group in _pairManager.GroupPairs.Select(g => g.Key).OrderBy(g => g.GroupAliasOrGID, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
if (_tagHandler.HasSyncshellTag(group.GID, syncshelltag))
|
||||
{
|
||||
GetGroups(allPairs, filteredPairs, group, out ImmutableList<Pair> allGroupPairs, out Dictionary<Pair, List<GroupFullInfoDto>> filteredGroupPairs);
|
||||
syncshellFolderTags.Add(_drawEntityFactory.CreateDrawGroupFolder($"tag_{group.GID}", group, filteredGroupPairs, allGroupPairs));
|
||||
}
|
||||
}
|
||||
|
||||
if (syncshellFolderTags.Count > 0)
|
||||
{
|
||||
drawFolders.Add(new DrawGroupedGroupFolder(syncshellFolderTags, _tagHandler, _uiSharedService, _selectSyncshellForTagUi, _renameSyncshellTagUi, syncshelltag));
|
||||
}
|
||||
}
|
||||
|
||||
var allOnlineNotTaggedPairs = ImmutablePairList(allPairs
|
||||
.Where(FilterNotTaggedUsers));
|
||||
var onlineNotTaggedPairs = BasicSortedDictionary(filteredPairs
|
||||
@@ -558,6 +750,27 @@ public class CompactUi : WindowMediatorSubscriberBase
|
||||
ImmutablePairList(allPairs.Where(u => u.Key.IsOneSidedPair))));
|
||||
|
||||
return drawFolders;
|
||||
|
||||
void GetGroups(Dictionary<Pair, List<GroupFullInfoDto>> allPairs, Dictionary<Pair, List<GroupFullInfoDto>> filteredPairs, GroupFullInfoDto group, out ImmutableList<Pair> allGroupPairs, out Dictionary<Pair, List<GroupFullInfoDto>> filteredGroupPairs)
|
||||
{
|
||||
allGroupPairs = ImmutablePairList(allPairs
|
||||
.Where(u => FilterGroupUsers(u, group)));
|
||||
filteredGroupPairs = filteredPairs
|
||||
.Where(u => FilterGroupUsers(u, group) && FilterOnlineOrPausedSelf(u))
|
||||
.OrderByDescending(u => u.Key.IsOnline)
|
||||
.ThenBy(u =>
|
||||
{
|
||||
if (string.Equals(u.Key.UserData.UID, group.OwnerUID, StringComparison.Ordinal)) return 0;
|
||||
if (group.GroupPairUserInfos.TryGetValue(u.Key.UserData.UID, out var info))
|
||||
{
|
||||
if (info.IsModerator()) return 1;
|
||||
if (info.IsPinned()) return 2;
|
||||
}
|
||||
return u.Key.IsVisible ? 3 : 4;
|
||||
})
|
||||
.ThenBy(AlphabeticalSort, StringComparer.OrdinalIgnoreCase)
|
||||
.ToDictionary(k => k.Key, k => k.Value);
|
||||
}
|
||||
}
|
||||
|
||||
private string GetServerError()
|
||||
@@ -587,21 +800,21 @@ public class CompactUi : WindowMediatorSubscriberBase
|
||||
{
|
||||
return _apiController.ServerState switch
|
||||
{
|
||||
ServerState.Connecting => ImGuiColors.DalamudYellow,
|
||||
ServerState.Reconnecting => ImGuiColors.DalamudRed,
|
||||
ServerState.Connecting => UIColors.Get("LightlessYellow"),
|
||||
ServerState.Reconnecting => UIColors.Get("DimRed"),
|
||||
ServerState.Connected => UIColors.Get("LightlessPurple"),
|
||||
ServerState.Disconnected => ImGuiColors.DalamudYellow,
|
||||
ServerState.Disconnecting => ImGuiColors.DalamudYellow,
|
||||
ServerState.Unauthorized => ImGuiColors.DalamudRed,
|
||||
ServerState.VersionMisMatch => ImGuiColors.DalamudRed,
|
||||
ServerState.Offline => ImGuiColors.DalamudRed,
|
||||
ServerState.RateLimited => ImGuiColors.DalamudYellow,
|
||||
ServerState.NoSecretKey => ImGuiColors.DalamudYellow,
|
||||
ServerState.MultiChara => ImGuiColors.DalamudYellow,
|
||||
ServerState.OAuthMisconfigured => ImGuiColors.DalamudRed,
|
||||
ServerState.OAuthLoginTokenStale => ImGuiColors.DalamudRed,
|
||||
ServerState.NoAutoLogon => ImGuiColors.DalamudYellow,
|
||||
_ => ImGuiColors.DalamudRed
|
||||
ServerState.Disconnected => UIColors.Get("LightlessYellow"),
|
||||
ServerState.Disconnecting => UIColors.Get("LightlessYellow"),
|
||||
ServerState.Unauthorized => UIColors.Get("DimRed"),
|
||||
ServerState.VersionMisMatch => UIColors.Get("DimRed"),
|
||||
ServerState.Offline => UIColors.Get("DimRed"),
|
||||
ServerState.RateLimited => UIColors.Get("LightlessYellow"),
|
||||
ServerState.NoSecretKey => UIColors.Get("LightlessYellow"),
|
||||
ServerState.MultiChara => UIColors.Get("LightlessYellow"),
|
||||
ServerState.OAuthMisconfigured => UIColors.Get("DimRed"),
|
||||
ServerState.OAuthLoginTokenStale => UIColors.Get("DimRed"),
|
||||
ServerState.NoAutoLogon => UIColors.Get("LightlessYellow"),
|
||||
_ => UIColors.Get("DimRed")
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -19,16 +19,18 @@ public class DrawFolderGroup : DrawFolderBase
|
||||
private readonly GroupFullInfoDto _groupFullInfoDto;
|
||||
private readonly IdDisplayHandler _idDisplayHandler;
|
||||
private readonly LightlessMediator _lightlessMediator;
|
||||
private readonly SelectTagForSyncshellUi _selectTagForSyncshellUi;
|
||||
|
||||
public DrawFolderGroup(string id, GroupFullInfoDto groupFullInfoDto, ApiController apiController,
|
||||
IImmutableList<DrawUserPair> drawPairs, IImmutableList<Pair> allPairs, TagHandler tagHandler, IdDisplayHandler idDisplayHandler,
|
||||
LightlessMediator lightlessMediator, UiSharedService uiSharedService) :
|
||||
LightlessMediator lightlessMediator, UiSharedService uiSharedService, SelectTagForSyncshellUi selectTagForSyncshellUi) :
|
||||
base(id, drawPairs, allPairs, tagHandler, uiSharedService)
|
||||
{
|
||||
_groupFullInfoDto = groupFullInfoDto;
|
||||
_apiController = apiController;
|
||||
_idDisplayHandler = idDisplayHandler;
|
||||
_lightlessMediator = lightlessMediator;
|
||||
_selectTagForSyncshellUi = selectTagForSyncshellUi;
|
||||
}
|
||||
|
||||
protected override bool RenderIfEmpty => true;
|
||||
@@ -99,6 +101,13 @@ public class DrawFolderGroup : DrawFolderBase
|
||||
}
|
||||
UiSharedService.AttachToolTip("Copies all your notes for all users in this Syncshell to the clipboard." + Environment.NewLine + "They can be imported via Settings -> General -> Notes -> Import notes from clipboard");
|
||||
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Folder, "Syncshell Groups", menuWidth, true))
|
||||
{
|
||||
ImGui.CloseCurrentPopup();
|
||||
_selectTagForSyncshellUi.Open(_groupFullInfoDto);
|
||||
}
|
||||
UiSharedService.AttachToolTip("Choose syncshell groups for " + _groupFullInfoDto.GID);
|
||||
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.ArrowCircleLeft, "Leave Syncshell", menuWidth, true) && UiSharedService.CtrlPressed())
|
||||
{
|
||||
_ = _apiController.GroupLeave(_groupFullInfoDto);
|
||||
@@ -185,7 +194,7 @@ public class DrawFolderGroup : DrawFolderBase
|
||||
|
||||
_uiSharedService.IconText(FontAwesomeIcon.UsersCog, (_groupFullInfoDto.GroupPermissions.IsPreferDisableAnimations() != individualAnimDisabled
|
||||
|| _groupFullInfoDto.GroupPermissions.IsPreferDisableSounds() != individualSoundsDisabled
|
||||
|| _groupFullInfoDto.GroupPermissions.IsPreferDisableVFX() != individualVFXDisabled) ? ImGuiColors.DalamudYellow : null);
|
||||
|| _groupFullInfoDto.GroupPermissions.IsPreferDisableVFX() != individualVFXDisabled) ? UIColors.Get("LightlessYellow") : null);
|
||||
if (ImGui.IsItemHovered())
|
||||
{
|
||||
ImGui.BeginTooltip();
|
||||
|
||||
@@ -13,13 +13,15 @@ public class DrawFolderTag : DrawFolderBase
|
||||
{
|
||||
private readonly ApiController _apiController;
|
||||
private readonly SelectPairForTagUi _selectPairForTagUi;
|
||||
private readonly RenamePairTagUi _renameTagUi;
|
||||
|
||||
public DrawFolderTag(string id, IImmutableList<DrawUserPair> drawPairs, IImmutableList<Pair> allPairs,
|
||||
TagHandler tagHandler, ApiController apiController, SelectPairForTagUi selectPairForTagUi, UiSharedService uiSharedService)
|
||||
TagHandler tagHandler, ApiController apiController, SelectPairForTagUi selectPairForTagUi, RenamePairTagUi renameTagUi, UiSharedService uiSharedService)
|
||||
: base(id, drawPairs, allPairs, tagHandler, uiSharedService)
|
||||
{
|
||||
_apiController = apiController;
|
||||
_selectPairForTagUi = selectPairForTagUi;
|
||||
_renameTagUi = renameTagUi;
|
||||
}
|
||||
|
||||
protected override bool RenderIfEmpty => _id switch
|
||||
@@ -100,14 +102,17 @@ public class DrawFolderTag : DrawFolderBase
|
||||
protected override void DrawMenu(float menuWidth)
|
||||
{
|
||||
ImGui.TextUnformatted("Group Menu");
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Users, "Select Pairs", menuWidth, true))
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Users, "Select Pairs", menuWidth, isInPopup: true))
|
||||
{
|
||||
_selectPairForTagUi.Open(_id);
|
||||
}
|
||||
UiSharedService.AttachToolTip("Select Individual Pairs for this Pair Group");
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Delete Pair Group", menuWidth, true) && UiSharedService.CtrlPressed())
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Edit, "Rename Pair Group", menuWidth, isInPopup: true))
|
||||
{
|
||||
_tagHandler.RemoveTag(_id);
|
||||
_renameTagUi.Open(_id);
|
||||
}
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Delete Pair Group", menuWidth, isInPopup: true) && UiSharedService.CtrlPressed())
|
||||
{
|
||||
_tagHandler.RemovePairTag(_id);
|
||||
}
|
||||
UiSharedService.AttachToolTip("Hold CTRL to remove this Group permanently." + Environment.NewLine +
|
||||
"Note: this will not unpair with users in this Group.");
|
||||
|
||||
@@ -9,20 +9,27 @@ namespace LightlessSync.UI.Components;
|
||||
|
||||
public class DrawGroupedGroupFolder : IDrawFolder
|
||||
{
|
||||
private readonly string _tag;
|
||||
private readonly IEnumerable<IDrawFolder> _groups;
|
||||
private readonly TagHandler _tagHandler;
|
||||
private readonly UiSharedService _uiSharedService;
|
||||
private readonly SelectSyncshellForTagUi _selectSyncshellForTagUi;
|
||||
private readonly RenameSyncshellTagUi _renameSyncshellTagUi;
|
||||
private bool _wasHovered = false;
|
||||
private float _menuWidth;
|
||||
|
||||
public IImmutableList<DrawUserPair> DrawPairs => throw new NotSupportedException();
|
||||
public int OnlinePairs => _groups.SelectMany(g => g.DrawPairs).Where(g => g.Pair.IsOnline).DistinctBy(g => g.Pair.UserData.UID).Count();
|
||||
public int TotalPairs => _groups.Sum(g => g.TotalPairs);
|
||||
|
||||
public DrawGroupedGroupFolder(IEnumerable<IDrawFolder> groups, TagHandler tagHandler, UiSharedService uiSharedService)
|
||||
public DrawGroupedGroupFolder(IEnumerable<IDrawFolder> groups, TagHandler tagHandler, UiSharedService uiSharedService, SelectSyncshellForTagUi selectSyncshellForTagUi, RenameSyncshellTagUi renameSyncshellTagUi, string tag)
|
||||
{
|
||||
_groups = groups;
|
||||
_tagHandler = tagHandler;
|
||||
_uiSharedService = uiSharedService;
|
||||
_selectSyncshellForTagUi = selectSyncshellForTagUi;
|
||||
_renameSyncshellTagUi = renameSyncshellTagUi;
|
||||
_tag = tag;
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
@@ -30,6 +37,11 @@ public class DrawGroupedGroupFolder : IDrawFolder
|
||||
if (!_groups.Any()) return;
|
||||
|
||||
string _id = "__folder_syncshells";
|
||||
if (_tag != "")
|
||||
{
|
||||
_id = $"__folder_{_tag}";
|
||||
}
|
||||
|
||||
using var id = ImRaii.PushId(_id);
|
||||
var color = ImRaii.PushColor(ImGuiCol.ChildBg, ImGui.GetColorU32(ImGuiCol.FrameBgHovered), _wasHovered);
|
||||
using (ImRaii.Child("folder__" + _id, new System.Numerics.Vector2(UiSharedService.GetWindowContentRegionWidth() - ImGui.GetCursorPosX(), ImGui.GetFrameHeight())))
|
||||
@@ -49,18 +61,36 @@ public class DrawGroupedGroupFolder : IDrawFolder
|
||||
|
||||
ImGui.SameLine();
|
||||
ImGui.AlignTextToFramePadding();
|
||||
_uiSharedService.IconText(FontAwesomeIcon.UsersRectangle);
|
||||
using (ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, ImGui.GetStyle().ItemSpacing with { X = ImGui.GetStyle().ItemSpacing.X / 2f }))
|
||||
|
||||
if (_tag != "")
|
||||
{
|
||||
ImGui.SameLine();
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.TextUnformatted("[" + OnlinePairs.ToString() + "]");
|
||||
_uiSharedService.IconText(FontAwesomeIcon.FolderPlus);
|
||||
}
|
||||
else
|
||||
{
|
||||
_uiSharedService.IconText(FontAwesomeIcon.UsersRectangle);
|
||||
}
|
||||
|
||||
using (ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, ImGui.GetStyle().ItemSpacing with { X = ImGui.GetStyle().ItemSpacing.X / 2f }))
|
||||
{
|
||||
ImGui.SameLine();
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.TextUnformatted("[" + OnlinePairs.ToString() + "]");
|
||||
}
|
||||
UiSharedService.AttachToolTip(OnlinePairs + " online in all of your joined syncshells" + Environment.NewLine +
|
||||
TotalPairs + " pairs combined in all of your joined syncshells");
|
||||
ImGui.SameLine();
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.TextUnformatted("All Syncshells");
|
||||
if (_tag != "")
|
||||
{
|
||||
ImGui.TextUnformatted(_tag);
|
||||
|
||||
ImGui.SameLine();
|
||||
DrawMenu();
|
||||
} else
|
||||
{
|
||||
ImGui.TextUnformatted("All Syncshells");
|
||||
}
|
||||
}
|
||||
color.Dispose();
|
||||
_wasHovered = ImGui.IsItemHovered();
|
||||
@@ -76,4 +106,40 @@ public class DrawGroupedGroupFolder : IDrawFolder
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void DrawMenu()
|
||||
{
|
||||
var barButtonSize = _uiSharedService.GetIconButtonSize(FontAwesomeIcon.EllipsisV);
|
||||
var windowEndX = ImGui.GetWindowContentRegionMin().X + UiSharedService.GetWindowContentRegionWidth();
|
||||
|
||||
ImGui.SameLine(windowEndX - barButtonSize.X);
|
||||
if (_uiSharedService.IconButton(FontAwesomeIcon.EllipsisV))
|
||||
{
|
||||
ImGui.OpenPopup("User Flyout Menu");
|
||||
}
|
||||
if (ImGui.BeginPopup("User Flyout Menu"))
|
||||
{
|
||||
using (ImRaii.PushId($"buttons-syncshell-{_tag}")) GroupMenu(_menuWidth);
|
||||
_menuWidth = ImGui.GetWindowContentRegionMax().X - ImGui.GetWindowContentRegionMin().X;
|
||||
ImGui.EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
protected void GroupMenu(float menuWidth)
|
||||
{
|
||||
ImGui.TextUnformatted("Syncshell Group Menu");
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Users, "Select Syncshells", menuWidth, isInPopup: true))
|
||||
{
|
||||
_selectSyncshellForTagUi.Open(_tag);
|
||||
}
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Edit, "Rename Syncshell Group", menuWidth, isInPopup: true))
|
||||
{
|
||||
_renameSyncshellTagUi.Open(_tag);
|
||||
}
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Delete Syncshell Group", menuWidth, isInPopup: true) && UiSharedService.CtrlPressed())
|
||||
{
|
||||
_tagHandler.RemoveSyncshellTag(_tag);
|
||||
}
|
||||
UiSharedService.AttachToolTip("Hold CTRL to remove this Group permanently.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Dalamud.Bindings.ImGui;
|
||||
using Dalamud.Interface;
|
||||
using Dalamud.Interface.Colors;
|
||||
using Dalamud.Interface.Utility;
|
||||
using Dalamud.Interface.Utility.Raii;
|
||||
using LightlessSync.API.Data.Extensions;
|
||||
@@ -12,6 +11,7 @@ using LightlessSync.Services;
|
||||
using LightlessSync.Services.Mediator;
|
||||
using LightlessSync.Services.ServerConfiguration;
|
||||
using LightlessSync.UI.Handlers;
|
||||
using LightlessSync.Utils;
|
||||
using LightlessSync.WebAPI;
|
||||
|
||||
namespace LightlessSync.UI.Components;
|
||||
@@ -196,7 +196,7 @@ public class DrawUserPair
|
||||
|
||||
if (_pair.IsPaused)
|
||||
{
|
||||
using var _ = ImRaii.PushColor(ImGuiCol.Text, ImGuiColors.DalamudYellow);
|
||||
using var _ = ImRaii.PushColor(ImGuiCol.Text, UIColors.Get("LightlessYellow"));
|
||||
_uiSharedService.IconText(FontAwesomeIcon.PauseCircle);
|
||||
userPairText = _pair.UserData.AliasOrUID + " is paused";
|
||||
}
|
||||
@@ -274,7 +274,7 @@ public class DrawUserPair
|
||||
{
|
||||
ImGui.SameLine();
|
||||
|
||||
_uiSharedService.IconText(FontAwesomeIcon.ExclamationTriangle, ImGuiColors.DalamudYellow);
|
||||
_uiSharedService.IconText(FontAwesomeIcon.ExclamationTriangle, UIColors.Get("LightlessYellow"));
|
||||
|
||||
string userWarningText = "WARNING: This user exceeds one or more of your defined thresholds:" + UiSharedService.TooltipSeparator;
|
||||
bool shownVram = false;
|
||||
@@ -295,6 +295,31 @@ public class DrawUserPair
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
|
||||
if (_pair.UserData.IsAdmin || _pair.UserData.IsModerator)
|
||||
{
|
||||
ImGui.SameLine();
|
||||
|
||||
var iconId = _pair.UserData.IsAdmin ? 67 : 68;
|
||||
var colorKey = _pair.UserData.IsAdmin ? "LightlessAdminText" : "LightlessModeratorText";
|
||||
var roleColor = UIColors.Get(colorKey);
|
||||
|
||||
var iconPos = ImGui.GetCursorScreenPos();
|
||||
SeStringUtils.RenderIconWithHitbox(iconId, iconPos);
|
||||
|
||||
if (ImGui.IsItemHovered())
|
||||
{
|
||||
ImGui.BeginTooltip();
|
||||
using (ImRaii.PushColor(ImGuiCol.Text, roleColor))
|
||||
{
|
||||
ImGui.TextUnformatted(_pair.UserData.IsAdmin
|
||||
? "Official Lightless Admin"
|
||||
: "Official Lightless Moderator");
|
||||
}
|
||||
ImGui.EndTooltip();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void DrawName(float leftSide, float rightSide)
|
||||
@@ -376,7 +401,7 @@ public class DrawUserPair
|
||||
currentRightSide -= (_uiSharedService.GetIconSize(individualIcon).X + spacingX);
|
||||
|
||||
ImGui.SameLine(currentRightSide);
|
||||
using (ImRaii.PushColor(ImGuiCol.Text, ImGuiColors.DalamudYellow, individualAnimDisabled || individualSoundsDisabled || individualVFXDisabled))
|
||||
using (ImRaii.PushColor(ImGuiCol.Text, UIColors.Get("LightlessYellow"), individualAnimDisabled || individualSoundsDisabled || individualVFXDisabled))
|
||||
_uiSharedService.IconText(individualIcon);
|
||||
if (ImGui.IsItemHovered())
|
||||
{
|
||||
|
||||
79
LightlessSync/UI/Components/RenamePairTagUi.cs
Normal file
79
LightlessSync/UI/Components/RenamePairTagUi.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using Dalamud.Bindings.ImGui;
|
||||
using Dalamud.Interface.Utility;
|
||||
using Dalamud.Interface.Utility.Raii;
|
||||
using LightlessSync.UI.Handlers;
|
||||
|
||||
using System.Numerics;
|
||||
|
||||
namespace LightlessSync.UI.Components;
|
||||
|
||||
public class RenamePairTagUi
|
||||
{
|
||||
private readonly TagHandler _tagHandler;
|
||||
private readonly UiSharedService _uiSharedService;
|
||||
private string _desiredName = string.Empty;
|
||||
private bool _opened = false;
|
||||
private bool _show = false;
|
||||
private string _tag = string.Empty;
|
||||
|
||||
public RenamePairTagUi(TagHandler tagHandler, UiSharedService uiSharedService)
|
||||
{
|
||||
_tagHandler = tagHandler;
|
||||
_uiSharedService = uiSharedService;
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
var workHeight = ImGui.GetMainViewport().WorkSize.Y / ImGuiHelpers.GlobalScale;
|
||||
var minSize = new Vector2(300, workHeight < 110 ? workHeight : 110) * ImGuiHelpers.GlobalScale;
|
||||
var maxSize = new Vector2(300, 110) * ImGuiHelpers.GlobalScale;
|
||||
|
||||
var popupName = $"Renaming Pair Group {_tag}";
|
||||
|
||||
if (!_show)
|
||||
{
|
||||
_opened = false;
|
||||
}
|
||||
|
||||
if (_show && !_opened)
|
||||
{
|
||||
ImGui.SetNextWindowSize(minSize);
|
||||
UiSharedService.CenterNextWindow(minSize.X, minSize.Y, ImGuiCond.Always);
|
||||
ImGui.OpenPopup(popupName);
|
||||
_opened = true;
|
||||
}
|
||||
|
||||
ImGui.SetNextWindowSizeConstraints(minSize, maxSize);
|
||||
if (ImGui.BeginPopupModal(popupName, ref _show, ImGuiWindowFlags.Popup | ImGuiWindowFlags.Modal))
|
||||
{
|
||||
ImGui.TextUnformatted($"Renaming {_tag}");
|
||||
|
||||
ImGui.InputTextWithHint("##desiredname", "Enter new group name", ref _desiredName, 20, ImGuiInputTextFlags.None);
|
||||
using (ImRaii.Disabled(string.IsNullOrEmpty(_desiredName)))
|
||||
{
|
||||
if (_uiSharedService.IconTextButton(Dalamud.Interface.FontAwesomeIcon.Plus, "Rename Group"))
|
||||
{
|
||||
RenameTag(_tag, _desiredName);
|
||||
_show = false;
|
||||
}
|
||||
}
|
||||
ImGui.EndPopup();
|
||||
}
|
||||
else
|
||||
{
|
||||
_show = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Open(string tag)
|
||||
{
|
||||
_tag = tag;
|
||||
_desiredName = "";
|
||||
_show = true;
|
||||
}
|
||||
|
||||
public void RenameTag(string oldTag, string newTag)
|
||||
{
|
||||
_tagHandler.RenamePairTag(oldTag, newTag);
|
||||
}
|
||||
}
|
||||
79
LightlessSync/UI/Components/RenameSyncshellTagUi.cs
Normal file
79
LightlessSync/UI/Components/RenameSyncshellTagUi.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using Dalamud.Bindings.ImGui;
|
||||
using Dalamud.Interface.Utility;
|
||||
using Dalamud.Interface.Utility.Raii;
|
||||
using LightlessSync.UI.Handlers;
|
||||
|
||||
using System.Numerics;
|
||||
|
||||
namespace LightlessSync.UI.Components;
|
||||
|
||||
public class RenameSyncshellTagUi
|
||||
{
|
||||
private readonly TagHandler _tagHandler;
|
||||
private readonly UiSharedService _uiSharedService;
|
||||
private string _desiredName = string.Empty;
|
||||
private bool _opened = false;
|
||||
private bool _show = false;
|
||||
private string _tag = string.Empty;
|
||||
|
||||
public RenameSyncshellTagUi(TagHandler tagHandler, UiSharedService uiSharedService)
|
||||
{
|
||||
_tagHandler = tagHandler;
|
||||
_uiSharedService = uiSharedService;
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
var workHeight = ImGui.GetMainViewport().WorkSize.Y / ImGuiHelpers.GlobalScale;
|
||||
var minSize = new Vector2(300, workHeight < 110 ? workHeight : 110) * ImGuiHelpers.GlobalScale;
|
||||
var maxSize = new Vector2(300, 110) * ImGuiHelpers.GlobalScale;
|
||||
|
||||
var popupName = $"Renaming Syncshell Group {_tag}";
|
||||
|
||||
if (!_show)
|
||||
{
|
||||
_opened = false;
|
||||
}
|
||||
|
||||
if (_show && !_opened)
|
||||
{
|
||||
ImGui.SetNextWindowSize(minSize);
|
||||
UiSharedService.CenterNextWindow(minSize.X, minSize.Y, ImGuiCond.Always);
|
||||
ImGui.OpenPopup(popupName);
|
||||
_opened = true;
|
||||
}
|
||||
|
||||
ImGui.SetNextWindowSizeConstraints(minSize, maxSize);
|
||||
if (ImGui.BeginPopupModal(popupName, ref _show, ImGuiWindowFlags.Popup | ImGuiWindowFlags.Modal))
|
||||
{
|
||||
ImGui.TextUnformatted($"Renaming {_tag}");
|
||||
|
||||
ImGui.InputTextWithHint("##desiredname", "Enter new group name", ref _desiredName, 20, ImGuiInputTextFlags.None);
|
||||
using (ImRaii.Disabled(string.IsNullOrEmpty(_desiredName)))
|
||||
{
|
||||
if (_uiSharedService.IconTextButton(Dalamud.Interface.FontAwesomeIcon.Plus, "Rename Group"))
|
||||
{
|
||||
RenameTag(_tag, _desiredName);
|
||||
_show = false;
|
||||
}
|
||||
}
|
||||
ImGui.EndPopup();
|
||||
}
|
||||
else
|
||||
{
|
||||
_show = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Open(string tag)
|
||||
{
|
||||
_tag = tag;
|
||||
_desiredName = "";
|
||||
_show = true;
|
||||
}
|
||||
|
||||
public void RenameTag(string oldTag, string newTag)
|
||||
{
|
||||
_tagHandler.RenameSyncshellTag(oldTag, newTag);
|
||||
}
|
||||
}
|
||||
@@ -60,7 +60,7 @@ public class SelectPairForTagUi
|
||||
{
|
||||
if (isInGroup)
|
||||
{
|
||||
_tagHandler.AddTagToPairedUid(item.UserData.UID, _tag);
|
||||
_tagHandler.AddPairTagToPairedUid(item.UserData.UID, _tag);
|
||||
_peopleInGroup.Add(item.UserData.UID);
|
||||
}
|
||||
else
|
||||
|
||||
86
LightlessSync/UI/Components/SelectSyncshellForTagUi.cs
Normal file
86
LightlessSync/UI/Components/SelectSyncshellForTagUi.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using Dalamud.Bindings.ImGui;
|
||||
using Dalamud.Interface.Utility;
|
||||
using LightlessSync.API.Dto.Group;
|
||||
using LightlessSync.UI.Handlers;
|
||||
|
||||
using System.Numerics;
|
||||
|
||||
namespace LightlessSync.UI.Components;
|
||||
|
||||
public class SelectSyncshellForTagUi
|
||||
{
|
||||
private readonly TagHandler _tagHandler;
|
||||
private string _filter = string.Empty;
|
||||
private bool _opened = false;
|
||||
private HashSet<string> _syncshellsInGroup = new(StringComparer.Ordinal);
|
||||
private bool _show = false;
|
||||
private string _tag = string.Empty;
|
||||
|
||||
public SelectSyncshellForTagUi(TagHandler tagHandler)
|
||||
{
|
||||
_tagHandler = tagHandler;
|
||||
}
|
||||
|
||||
public void Draw(List<GroupFullInfoDto> groups)
|
||||
{
|
||||
var workHeight = ImGui.GetMainViewport().WorkSize.Y / ImGuiHelpers.GlobalScale;
|
||||
var minSize = new Vector2(300, workHeight < 400 ? workHeight : 400) * ImGuiHelpers.GlobalScale;
|
||||
var maxSize = new Vector2(300, 1000) * ImGuiHelpers.GlobalScale;
|
||||
|
||||
var popupName = $"Choose Syncshells for Group {_tag}";
|
||||
|
||||
if (!_show)
|
||||
{
|
||||
_opened = false;
|
||||
}
|
||||
|
||||
if (_show && !_opened)
|
||||
{
|
||||
ImGui.SetNextWindowSize(minSize);
|
||||
UiSharedService.CenterNextWindow(minSize.X, minSize.Y, ImGuiCond.Always);
|
||||
ImGui.OpenPopup(popupName);
|
||||
_opened = true;
|
||||
}
|
||||
|
||||
ImGui.SetNextWindowSizeConstraints(minSize, maxSize);
|
||||
if (ImGui.BeginPopupModal(popupName, ref _show, ImGuiWindowFlags.Popup | ImGuiWindowFlags.Modal))
|
||||
{
|
||||
ImGui.TextUnformatted($"Select syncshells for group {_tag}");
|
||||
|
||||
ImGui.InputTextWithHint("##filter", "Filter", ref _filter, 255, ImGuiInputTextFlags.None);
|
||||
foreach (var group in groups
|
||||
.Where(g => string.IsNullOrEmpty(_filter) || g.GID.Contains(_filter, StringComparison.OrdinalIgnoreCase))
|
||||
.OrderBy(g => g.GroupAliasOrGID, StringComparer.OrdinalIgnoreCase)
|
||||
.ToList())
|
||||
{
|
||||
var isInGroup = _syncshellsInGroup.Contains(group.GID);
|
||||
if (ImGui.Checkbox(group.GroupAliasOrGID, ref isInGroup))
|
||||
{
|
||||
if (isInGroup)
|
||||
{
|
||||
_tagHandler.AddTagToSyncshell(group.GID, _tag);
|
||||
_syncshellsInGroup.Add(group.GID);
|
||||
}
|
||||
else
|
||||
{
|
||||
_tagHandler.RemoveTagFromSyncshell(group.GID, _tag);
|
||||
_syncshellsInGroup.Remove(group.GID);
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui.EndPopup();
|
||||
}
|
||||
else
|
||||
{
|
||||
_filter = string.Empty;
|
||||
_show = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Open(string tag)
|
||||
{
|
||||
_syncshellsInGroup = _tagHandler.GetOtherSyncshellsForTag(tag);
|
||||
_tag = tag;
|
||||
_show = true;
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,7 @@ public class SelectTagForPairUi
|
||||
|
||||
if (ImGui.BeginPopup(popupName))
|
||||
{
|
||||
var tags = _tagHandler.GetAllTagsSorted();
|
||||
var tags = _tagHandler.GetAllPairTagsSorted();
|
||||
var childHeight = tags.Count != 0 ? tags.Count * 25 : 1;
|
||||
var childSize = new Vector2(0, childHeight > 100 ? 100 : childHeight) * ImGuiHelpers.GlobalScale;
|
||||
|
||||
@@ -80,7 +80,7 @@ public class SelectTagForPairUi
|
||||
HandleAddTag();
|
||||
}
|
||||
ImGui.SameLine();
|
||||
ImGui.InputTextWithHint("##category_name", "New Group", ref _tagNameToAdd, 40);
|
||||
ImGui.InputTextWithHint("##category_name", "New Group", ref _tagNameToAdd, 20);
|
||||
if (ImGui.IsKeyDown(ImGuiKey.Enter))
|
||||
{
|
||||
HandleAddTag();
|
||||
@@ -101,13 +101,13 @@ public class SelectTagForPairUi
|
||||
|
||||
private void DrawGroupName(Pair pair, string name)
|
||||
{
|
||||
var hasTagBefore = _tagHandler.HasTag(pair.UserData.UID, name);
|
||||
var hasTagBefore = _tagHandler.HasPairTag(pair.UserData.UID, name);
|
||||
var hasTag = hasTagBefore;
|
||||
if (ImGui.Checkbox(name, ref hasTag))
|
||||
{
|
||||
if (hasTag)
|
||||
{
|
||||
_tagHandler.AddTagToPairedUid(pair.UserData.UID, name);
|
||||
_tagHandler.AddPairTagToPairedUid(pair.UserData.UID, name);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -120,10 +120,10 @@ public class SelectTagForPairUi
|
||||
{
|
||||
if (!_tagNameToAdd.IsNullOrWhitespace() && _tagNameToAdd is not (TagHandler.CustomOfflineTag or TagHandler.CustomOnlineTag or TagHandler.CustomVisibleTag))
|
||||
{
|
||||
_tagHandler.AddTag(_tagNameToAdd);
|
||||
_tagHandler.AddPairTag(_tagNameToAdd);
|
||||
if (_pair != null)
|
||||
{
|
||||
_tagHandler.AddTagToPairedUid(_pair.UserData.UID, _tagNameToAdd);
|
||||
_tagHandler.AddPairTagToPairedUid(_pair.UserData.UID, _tagNameToAdd);
|
||||
}
|
||||
_tagNameToAdd = string.Empty;
|
||||
}
|
||||
|
||||
132
LightlessSync/UI/Components/SelectTagForSyncshellUi.cs
Normal file
132
LightlessSync/UI/Components/SelectTagForSyncshellUi.cs
Normal file
@@ -0,0 +1,132 @@
|
||||
using Dalamud.Bindings.ImGui;
|
||||
using Dalamud.Interface;
|
||||
using Dalamud.Interface.Utility;
|
||||
using Dalamud.Interface.Utility.Raii;
|
||||
using Dalamud.Utility;
|
||||
using LightlessSync.API.Dto.Group;
|
||||
using LightlessSync.UI.Handlers;
|
||||
|
||||
using System.Numerics;
|
||||
|
||||
namespace LightlessSync.UI.Components;
|
||||
|
||||
public class SelectTagForSyncshellUi
|
||||
{
|
||||
private readonly TagHandler _tagHandler;
|
||||
private readonly UiSharedService _uiSharedService;
|
||||
|
||||
/// <summary>
|
||||
/// The group UI is always open for a specific pair. This defines which pair the UI is open for.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private GroupFullInfoDto? _group;
|
||||
|
||||
/// <summary>
|
||||
/// Should the panel show, yes/no
|
||||
/// </summary>
|
||||
private bool _show;
|
||||
|
||||
/// <summary>
|
||||
/// For the add category option, this stores the currently typed in tag name
|
||||
/// </summary>
|
||||
private string _tagNameToAdd = "";
|
||||
|
||||
public SelectTagForSyncshellUi(TagHandler tagHandler, UiSharedService uiSharedService)
|
||||
{
|
||||
_show = false;
|
||||
_group = null;
|
||||
_tagHandler = tagHandler;
|
||||
_uiSharedService = uiSharedService;
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
if (_group == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var name = _group.GroupAliasOrGID;
|
||||
var popupName = $"Choose Groups for {_group.GroupAliasOrGID}";
|
||||
// Is the popup supposed to show but did not open yet? Open it
|
||||
if (_show)
|
||||
{
|
||||
ImGui.OpenPopup(popupName);
|
||||
_show = false;
|
||||
}
|
||||
|
||||
if (ImGui.BeginPopup(popupName))
|
||||
{
|
||||
var tags = _tagHandler.GetAllSyncshellTagsSorted();
|
||||
var childHeight = tags.Count != 0 ? tags.Count * 25 : 1;
|
||||
var childSize = new Vector2(0, childHeight > 100 ? 100 : childHeight) * ImGuiHelpers.GlobalScale;
|
||||
|
||||
ImGui.TextUnformatted($"Select the groups you want {name} to be in.");
|
||||
if (ImGui.BeginChild(name + "##listGroups", childSize))
|
||||
{
|
||||
foreach (var tag in tags)
|
||||
{
|
||||
using (ImRaii.PushId($"groups-syncshell-{_group.GID}-{tag}")) DrawGroupName(_group, tag);
|
||||
}
|
||||
ImGui.EndChild();
|
||||
}
|
||||
|
||||
ImGui.Separator();
|
||||
ImGui.TextUnformatted($"Create a new group for {name}.");
|
||||
if (_uiSharedService.IconButton(FontAwesomeIcon.Plus))
|
||||
{
|
||||
HandleAddTag();
|
||||
}
|
||||
ImGui.SameLine();
|
||||
ImGui.InputTextWithHint("##category_name", "New Group", ref _tagNameToAdd, 20);
|
||||
if (ImGui.IsKeyDown(ImGuiKey.Enter))
|
||||
{
|
||||
HandleAddTag();
|
||||
}
|
||||
ImGui.EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
public void Open(GroupFullInfoDto group)
|
||||
{
|
||||
_group = group;
|
||||
// Using "_show" here to de-couple the opening of the popup
|
||||
// The popup name is derived from the name the user currently sees, which is
|
||||
// based on the showUidForEntry dictionary.
|
||||
// We'd have to derive the name here to open it popup modal here, when the Open() is called
|
||||
_show = true;
|
||||
}
|
||||
|
||||
private void DrawGroupName(GroupFullInfoDto group, string name)
|
||||
{
|
||||
var hasTag = _tagHandler.HasSyncshellTag(group.GID, name);
|
||||
if (ImGui.Checkbox(name, ref hasTag))
|
||||
{
|
||||
if (hasTag)
|
||||
{
|
||||
_tagHandler.AddTagToSyncshell(group.GID, name);
|
||||
}
|
||||
else
|
||||
{
|
||||
_tagHandler.RemoveTagFromSyncshell(group.GID, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleAddTag()
|
||||
{
|
||||
if (!_tagNameToAdd.IsNullOrWhitespace())
|
||||
{
|
||||
_tagHandler.AddSyncshellTag(_tagNameToAdd);
|
||||
if (_group != null)
|
||||
{
|
||||
_tagHandler.AddTagToSyncshell(_group.GID, _tagNameToAdd);
|
||||
}
|
||||
_tagNameToAdd = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
_tagNameToAdd = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
151
LightlessSync/UI/ContextMenu.cs
Normal file
151
LightlessSync/UI/ContextMenu.cs
Normal file
@@ -0,0 +1,151 @@
|
||||
using Dalamud.Game.ClientState.Objects.SubKinds;
|
||||
using Dalamud.Game.ClientState.Objects.Types;
|
||||
using Dalamud.Game.Gui.ContextMenu;
|
||||
using Dalamud.Plugin;
|
||||
using Dalamud.Plugin.Services;
|
||||
using LightlessSync.Services;
|
||||
using LightlessSync.Utils;
|
||||
using LightlessSync.WebAPI;
|
||||
using Lumina.Excel.Sheets;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace LightlessSync.UI;
|
||||
|
||||
internal class ContextMenu : IHostedService
|
||||
{
|
||||
private readonly IContextMenu _contextMenu;
|
||||
private readonly IDalamudPluginInterface _pluginInterface;
|
||||
private readonly IDataManager _gameData;
|
||||
private readonly ILogger<ContextMenu> _logger;
|
||||
private readonly DalamudUtilService _dalamudUtil;
|
||||
private readonly ApiController _apiController;
|
||||
private readonly IObjectTable _objectTable;
|
||||
|
||||
private static readonly string[] ValidAddons = new[]
|
||||
{
|
||||
null,
|
||||
"PartyMemberList", "FriendList", "FreeCompany", "LinkShell", "CrossWorldLinkshell",
|
||||
"_PartyList", "ChatLog", "LookingForGroup", "BlackList", "ContentMemberList",
|
||||
"SocialList", "ContactList", "BeginnerChatList", "MuteList"
|
||||
};
|
||||
|
||||
public ContextMenu(
|
||||
IContextMenu contextMenu,
|
||||
IDalamudPluginInterface pluginInterface,
|
||||
IDataManager gameData,
|
||||
ILogger<ContextMenu> logger,
|
||||
DalamudUtilService dalamudUtil,
|
||||
ApiController apiController,
|
||||
IObjectTable objectTable)
|
||||
{
|
||||
_contextMenu = contextMenu;
|
||||
_pluginInterface = pluginInterface;
|
||||
_gameData = gameData;
|
||||
_logger = logger;
|
||||
_dalamudUtil = dalamudUtil;
|
||||
_apiController = apiController;
|
||||
_objectTable = objectTable;
|
||||
}
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_contextMenu.OnMenuOpened += OnMenuOpened;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_contextMenu.OnMenuOpened -= OnMenuOpened;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public void Enable()
|
||||
{
|
||||
_contextMenu.OnMenuOpened += OnMenuOpened;
|
||||
_logger.LogDebug("Context menu enabled.");
|
||||
}
|
||||
|
||||
public void Disable()
|
||||
{
|
||||
_contextMenu.OnMenuOpened -= OnMenuOpened;
|
||||
_logger.LogDebug("Context menu disabled.");
|
||||
}
|
||||
|
||||
private void OnMenuOpened(IMenuOpenedArgs args)
|
||||
{
|
||||
if (!_pluginInterface.UiBuilder.ShouldModifyUi)
|
||||
return;
|
||||
|
||||
if (!ValidAddons.Contains(args.AddonName))
|
||||
return;
|
||||
|
||||
if (args.Target is not MenuTargetDefault target)
|
||||
return;
|
||||
|
||||
if (string.IsNullOrEmpty(target.TargetName) || target.TargetObjectId == 0 || target.TargetHomeWorld.RowId == 0)
|
||||
return;
|
||||
|
||||
var world = GetWorld(target.TargetHomeWorld.RowId);
|
||||
if (!IsWorldValid(world))
|
||||
return;
|
||||
|
||||
args.AddMenuItem(new MenuItem
|
||||
{
|
||||
Name = "Send Pair Request",
|
||||
PrefixChar = 'L',
|
||||
UseDefaultPrefix = false,
|
||||
PrefixColor = 708,
|
||||
OnClicked = async _ => await HandleSelection(args)
|
||||
});
|
||||
}
|
||||
|
||||
private async Task HandleSelection(IMenuArgs args)
|
||||
{
|
||||
if (args.Target is not MenuTargetDefault target)
|
||||
return;
|
||||
|
||||
var world = GetWorld(target.TargetHomeWorld.RowId);
|
||||
if (!IsWorldValid(world))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
var targetData = _objectTable
|
||||
.OfType<IPlayerCharacter>()
|
||||
.FirstOrDefault(p =>
|
||||
string.Equals(p.Name.TextValue, target.TargetName, StringComparison.OrdinalIgnoreCase) &&
|
||||
p.HomeWorld.RowId == target.TargetHomeWorld.RowId);
|
||||
|
||||
if (targetData == null || targetData.Address == IntPtr.Zero)
|
||||
{
|
||||
_logger.LogWarning("Target player {TargetName}@{World} not found in object table.", target.TargetName, world.Name);
|
||||
return;
|
||||
}
|
||||
|
||||
var senderCid = (await _dalamudUtil.GetCIDAsync()).ToString().GetHash256();
|
||||
var receiverCid = DalamudUtilService.GetHashedCIDFromPlayerPointer(targetData.Address);
|
||||
|
||||
_logger.LogInformation("Sending pair request: sender {SenderCid}, receiver {ReceiverCid}", senderCid, receiverCid);
|
||||
await _apiController.TryPairWithContentId(receiverCid, senderCid);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error sending pair request.");
|
||||
}
|
||||
}
|
||||
|
||||
private World GetWorld(uint worldId)
|
||||
{
|
||||
var sheet = _gameData.GetExcelSheet<World>()!;
|
||||
return sheet.TryGetRow(worldId, out var world) ? world : sheet.First();
|
||||
}
|
||||
|
||||
public bool IsWorldValid(uint worldId) => IsWorldValid(GetWorld(worldId));
|
||||
|
||||
public static bool IsWorldValid(World world)
|
||||
{
|
||||
var name = world.Name.ToString();
|
||||
return !string.IsNullOrWhiteSpace(name) && char.IsUpper(name[0]);
|
||||
}
|
||||
}
|
||||
@@ -371,7 +371,7 @@ public class DataAnalysisUi : WindowMediatorSubscriberBase
|
||||
ImGuiHelpers.ScaledDummy(5);
|
||||
UiSharedService.DrawGroupedCenteredColorText("Important Note: If you need to fix an animation that should apply across multiple jobs, you need to repeat this process with at least one additional job, " +
|
||||
"otherwise the animation will only be fixed for the currently active job. This goes primarily for emotes that are used across multiple jobs.",
|
||||
ImGuiColors.DalamudYellow, 800);
|
||||
UIColors.Get("LightlessYellow"), 800);
|
||||
ImGuiHelpers.ScaledDummy(5);
|
||||
UiSharedService.DrawGroupedCenteredColorText("WARNING: WHILE RECORDING TRANSIENT DATA, DO NOT CHANGE YOUR APPEARANCE, ENABLED MODS OR ANYTHING. JUST DO THE ANIMATION(S) OR WHATEVER YOU NEED DOING AND STOP THE RECORDING.",
|
||||
ImGuiColors.DalamudRed, 800);
|
||||
@@ -399,7 +399,7 @@ public class DataAnalysisUi : WindowMediatorSubscriberBase
|
||||
if (_transientResourceManager.IsTransientRecording)
|
||||
{
|
||||
ImGui.SameLine();
|
||||
UiSharedService.ColorText($"RECORDING - Time Remaining: {_transientResourceManager.RecordTimeRemaining.Value}", ImGuiColors.DalamudYellow);
|
||||
UiSharedService.ColorText($"RECORDING - Time Remaining: {_transientResourceManager.RecordTimeRemaining.Value}", UIColors.Get("LightlessYellow"));
|
||||
ImGuiHelpers.ScaledDummy(5);
|
||||
UiSharedService.DrawGroupedCenteredColorText("DO NOT CHANGE YOUR APPEARANCE OR MODS WHILE RECORDING, YOU CAN ACCIDENTALLY MAKE SOME OF YOUR APPEARANCE RELATED MODS PERMANENT.", ImGuiColors.DalamudRed, 800);
|
||||
}
|
||||
@@ -422,7 +422,7 @@ public class DataAnalysisUi : WindowMediatorSubscriberBase
|
||||
if (_transientResourceManager.RecordedTransients.Any(k => !k.AlreadyTransient))
|
||||
{
|
||||
ImGuiHelpers.ScaledDummy(5);
|
||||
UiSharedService.DrawGroupedCenteredColorText("Please review the recorded mod files before saving and deselect files that got into the recording on accident.", ImGuiColors.DalamudYellow);
|
||||
UiSharedService.DrawGroupedCenteredColorText("Please review the recorded mod files before saving and deselect files that got into the recording on accident.", UIColors.Get("LightlessYellow"));
|
||||
ImGuiHelpers.ScaledDummy(5);
|
||||
}
|
||||
|
||||
@@ -485,7 +485,7 @@ public class DataAnalysisUi : WindowMediatorSubscriberBase
|
||||
if (isAnalyzing)
|
||||
{
|
||||
UiSharedService.ColorTextWrapped($"Analyzing {_characterAnalyzer.CurrentFile}/{_characterAnalyzer.TotalFiles}",
|
||||
ImGuiColors.DalamudYellow);
|
||||
UIColors.Get("LightlessYellow"));
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.StopCircle, "Cancel analysis"))
|
||||
{
|
||||
_characterAnalyzer.CancelAnalyze();
|
||||
@@ -496,7 +496,7 @@ public class DataAnalysisUi : WindowMediatorSubscriberBase
|
||||
if (_cachedAnalysis!.Any(c => c.Value.Any(f => !f.Value.IsComputed)))
|
||||
{
|
||||
UiSharedService.ColorTextWrapped("Some entries in the analysis have file size not determined yet, press the button below to analyze your current data",
|
||||
ImGuiColors.DalamudYellow);
|
||||
UIColors.Get("LightlessYellow"));
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.PlayCircle, "Start analysis (missing entries)"))
|
||||
{
|
||||
_ = _characterAnalyzer.ComputeAnalysis(print: false);
|
||||
@@ -592,7 +592,7 @@ public class DataAnalysisUi : WindowMediatorSubscriberBase
|
||||
{
|
||||
UiSharedService.ColorText($"You exceed your own threshold by " +
|
||||
$"{UiSharedService.ByteToString(actualVramUsage - (currentVramWarning * 1024 * 1024))}.",
|
||||
ImGuiColors.DalamudYellow);
|
||||
UIColors.Get("LightlessYellow"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -609,7 +609,7 @@ public class DataAnalysisUi : WindowMediatorSubscriberBase
|
||||
{
|
||||
UiSharedService.ColorText($"You exceed your own threshold by " +
|
||||
$"{actualTriCount - (currentTriWarning * 1000)} triangles.",
|
||||
ImGuiColors.DalamudYellow);
|
||||
UIColors.Get("LightlessYellow"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -629,7 +629,7 @@ public class DataAnalysisUi : WindowMediatorSubscriberBase
|
||||
{
|
||||
string fileGroupText = fileGroup.Key + " [" + fileGroup.Count() + "]";
|
||||
var requiresCompute = fileGroup.Any(k => !k.IsComputed);
|
||||
using var tabcol = ImRaii.PushColor(ImGuiCol.Tab, UiSharedService.Color(ImGuiColors.DalamudYellow), requiresCompute);
|
||||
using var tabcol = ImRaii.PushColor(ImGuiCol.Tab, UiSharedService.Color(UIColors.Get("LightlessYellow")), requiresCompute);
|
||||
if (requiresCompute)
|
||||
{
|
||||
fileGroupText += " (!)";
|
||||
@@ -668,7 +668,7 @@ public class DataAnalysisUi : WindowMediatorSubscriberBase
|
||||
ImGui.Checkbox("Enable BC7 Conversion Mode", ref _enableBc7ConversionMode);
|
||||
if (_enableBc7ConversionMode)
|
||||
{
|
||||
UiSharedService.ColorText("WARNING BC7 CONVERSION:", ImGuiColors.DalamudYellow);
|
||||
UiSharedService.ColorText("WARNING BC7 CONVERSION:", UIColors.Get("LightlessYellow"));
|
||||
ImGui.SameLine();
|
||||
UiSharedService.ColorText("Converting textures to BC7 is irreversible!", ImGuiColors.DalamudRed);
|
||||
UiSharedService.ColorTextWrapped("- Converting textures to BC7 will reduce their size (compressed and uncompressed) drastically. It is recommended to be used for large (4k+) textures." +
|
||||
@@ -676,7 +676,7 @@ public class DataAnalysisUi : WindowMediatorSubscriberBase
|
||||
Environment.NewLine + "- Before converting textures, make sure to have the original files of the mod you are converting so you can reimport it in case of issues." +
|
||||
Environment.NewLine + "- Conversion will convert all found texture duplicates (entries with more than 1 file path) automatically." +
|
||||
Environment.NewLine + "- Converting textures to BC7 is a very expensive operation and, depending on the amount of textures to convert, will take a while to complete."
|
||||
, ImGuiColors.DalamudYellow);
|
||||
, UIColors.Get("LightlessYellow"));
|
||||
if (_texturesToConvert.Count > 0 && _uiSharedService.IconTextButton(FontAwesomeIcon.PlayCircle, "Start conversion of " + _texturesToConvert.Count + " texture(s)"))
|
||||
{
|
||||
_conversionCancellationTokenSource = _conversionCancellationTokenSource.CancelRecreate();
|
||||
@@ -697,7 +697,7 @@ public class DataAnalysisUi : WindowMediatorSubscriberBase
|
||||
|
||||
ImGui.TextUnformatted("Selected file:");
|
||||
ImGui.SameLine();
|
||||
UiSharedService.ColorText(_selectedHash, ImGuiColors.DalamudYellow);
|
||||
UiSharedService.ColorText(_selectedHash, UIColors.Get("LightlessYellow"));
|
||||
|
||||
if (_cachedAnalysis[_selectedObjectTab].TryGetValue(_selectedHash, out CharacterAnalyzer.FileDataEntry? item))
|
||||
{
|
||||
@@ -823,8 +823,8 @@ public class DataAnalysisUi : WindowMediatorSubscriberBase
|
||||
}
|
||||
if (string.Equals(_selectedHash, item.Hash, StringComparison.Ordinal))
|
||||
{
|
||||
ImGui.TableSetBgColor(ImGuiTableBgTarget.RowBg1, UiSharedService.Color(ImGuiColors.DalamudYellow));
|
||||
ImGui.TableSetBgColor(ImGuiTableBgTarget.RowBg0, UiSharedService.Color(ImGuiColors.DalamudYellow));
|
||||
ImGui.TableSetBgColor(ImGuiTableBgTarget.RowBg1, UiSharedService.Color(UIColors.Get("LightlessYellow")));
|
||||
ImGui.TableSetBgColor(ImGuiTableBgTarget.RowBg0, UiSharedService.Color(UIColors.Get("LightlessYellow")));
|
||||
}
|
||||
ImGui.TextUnformatted(item.Hash);
|
||||
if (ImGui.IsItemClicked()) _selectedHash = item.Hash;
|
||||
|
||||
@@ -169,7 +169,7 @@ public class DownloadUi : WindowMediatorSubscriberBase
|
||||
var dlProgressPercent = transferredBytes / (double)totalBytes;
|
||||
drawList.AddRectFilled(dlBarStart,
|
||||
dlBarEnd with { X = dlBarStart.X + (float)(dlProgressPercent * dlBarWidth) },
|
||||
UiSharedService.Color(173, 138, 245, transparency), 1);
|
||||
UiSharedService.Color(UIColors.Get("LightlessPurple")));
|
||||
|
||||
if (_configService.Current.TransferBarsShowText)
|
||||
{
|
||||
|
||||
@@ -23,19 +23,25 @@ public class DrawEntityFactory
|
||||
private readonly PlayerPerformanceConfigService _playerPerformanceConfigService;
|
||||
private readonly CharaDataManager _charaDataManager;
|
||||
private readonly SelectTagForPairUi _selectTagForPairUi;
|
||||
private readonly RenamePairTagUi _renamePairTagUi;
|
||||
private readonly SelectTagForSyncshellUi _selectTagForSyncshellUi;
|
||||
private readonly RenameSyncshellTagUi _renameSyncshellTagUi;
|
||||
private readonly SelectSyncshellForTagUi _selectSyncshellForTagUi;
|
||||
private readonly TagHandler _tagHandler;
|
||||
private readonly IdDisplayHandler _uidDisplayHandler;
|
||||
|
||||
public DrawEntityFactory(ILogger<DrawEntityFactory> logger, ApiController apiController, IdDisplayHandler uidDisplayHandler,
|
||||
SelectTagForPairUi selectTagForPairUi, LightlessMediator mediator,
|
||||
SelectTagForPairUi selectTagForPairUi, RenamePairTagUi renamePairTagUi, LightlessMediator mediator,
|
||||
TagHandler tagHandler, SelectPairForTagUi selectPairForTagUi,
|
||||
ServerConfigurationManager serverConfigurationManager, UiSharedService uiSharedService,
|
||||
PlayerPerformanceConfigService playerPerformanceConfigService, CharaDataManager charaDataManager)
|
||||
PlayerPerformanceConfigService playerPerformanceConfigService, CharaDataManager charaDataManager,
|
||||
SelectTagForSyncshellUi selectTagForSyncshellUi, RenameSyncshellTagUi renameSyncshellTagUi, SelectSyncshellForTagUi selectSyncshellForTagUi)
|
||||
{
|
||||
_logger = logger;
|
||||
_apiController = apiController;
|
||||
_uidDisplayHandler = uidDisplayHandler;
|
||||
_selectTagForPairUi = selectTagForPairUi;
|
||||
_renamePairTagUi = renamePairTagUi;
|
||||
_mediator = mediator;
|
||||
_tagHandler = tagHandler;
|
||||
_selectPairForTagUi = selectPairForTagUi;
|
||||
@@ -43,6 +49,9 @@ public class DrawEntityFactory
|
||||
_uiSharedService = uiSharedService;
|
||||
_playerPerformanceConfigService = playerPerformanceConfigService;
|
||||
_charaDataManager = charaDataManager;
|
||||
_selectTagForSyncshellUi = selectTagForSyncshellUi;
|
||||
_renameSyncshellTagUi = renameSyncshellTagUi;
|
||||
_selectSyncshellForTagUi = selectSyncshellForTagUi;
|
||||
}
|
||||
|
||||
public DrawFolderGroup CreateDrawGroupFolder(GroupFullInfoDto groupFullInfoDto,
|
||||
@@ -51,15 +60,24 @@ public class DrawEntityFactory
|
||||
{
|
||||
return new DrawFolderGroup(groupFullInfoDto.Group.GID, groupFullInfoDto, _apiController,
|
||||
filteredPairs.Select(p => CreateDrawPair(groupFullInfoDto.Group.GID + p.Key.UserData.UID, p.Key, p.Value, groupFullInfoDto)).ToImmutableList(),
|
||||
allPairs, _tagHandler, _uidDisplayHandler, _mediator, _uiSharedService);
|
||||
allPairs, _tagHandler, _uidDisplayHandler, _mediator, _uiSharedService, _selectTagForSyncshellUi);
|
||||
}
|
||||
|
||||
public DrawFolderGroup CreateDrawGroupFolder(string id, GroupFullInfoDto groupFullInfoDto,
|
||||
Dictionary<Pair, List<GroupFullInfoDto>> filteredPairs,
|
||||
IImmutableList<Pair> allPairs)
|
||||
{
|
||||
return new DrawFolderGroup(id, groupFullInfoDto, _apiController,
|
||||
filteredPairs.Select(p => CreateDrawPair(groupFullInfoDto.Group.GID + p.Key.UserData.UID, p.Key, p.Value, groupFullInfoDto)).ToImmutableList(),
|
||||
allPairs, _tagHandler, _uidDisplayHandler, _mediator, _uiSharedService, _selectTagForSyncshellUi);
|
||||
}
|
||||
|
||||
public DrawFolderTag CreateDrawTagFolder(string tag,
|
||||
Dictionary<Pair, List<GroupFullInfoDto>> filteredPairs,
|
||||
IImmutableList<Pair> allPairs)
|
||||
{
|
||||
return new(tag, filteredPairs.Select(u => CreateDrawPair(tag, u.Key, u.Value, null)).ToImmutableList(),
|
||||
allPairs, _tagHandler, _apiController, _selectPairForTagUi, _uiSharedService);
|
||||
return new(tag, filteredPairs.Select(u => CreateDrawPair(tag, u.Key, u.Value, currentGroup: null)).ToImmutableList(),
|
||||
allPairs, _tagHandler, _apiController, _selectPairForTagUi, _renamePairTagUi, _uiSharedService);
|
||||
}
|
||||
|
||||
public DrawUserPair CreateDrawPair(string id, Pair user, List<GroupFullInfoDto> groups, GroupFullInfoDto? currentGroup)
|
||||
|
||||
@@ -6,7 +6,9 @@ using LightlessSync.LightlessConfiguration;
|
||||
using LightlessSync.LightlessConfiguration.Configurations;
|
||||
using LightlessSync.PlayerData.Pairs;
|
||||
using LightlessSync.Services.Mediator;
|
||||
using LightlessSync.Services.ServerConfiguration;
|
||||
using LightlessSync.WebAPI;
|
||||
using LightlessSync.WebAPI.SignalR.Utils;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Runtime.InteropServices;
|
||||
@@ -16,6 +18,7 @@ namespace LightlessSync.UI;
|
||||
public sealed class DtrEntry : IDisposable, IHostedService
|
||||
{
|
||||
private readonly ApiController _apiController;
|
||||
private readonly ServerConfigurationManager _serverManager;
|
||||
private readonly CancellationTokenSource _cancellationTokenSource = new();
|
||||
private readonly ConfigurationServiceBase<LightlessConfig> _configService;
|
||||
private readonly IDtrBar _dtrBar;
|
||||
@@ -28,7 +31,7 @@ public sealed class DtrEntry : IDisposable, IHostedService
|
||||
private string? _tooltip;
|
||||
private Colors _colors;
|
||||
|
||||
public DtrEntry(ILogger<DtrEntry> logger, IDtrBar dtrBar, ConfigurationServiceBase<LightlessConfig> configService, LightlessMediator lightlessMediator, PairManager pairManager, ApiController apiController)
|
||||
public DtrEntry(ILogger<DtrEntry> logger, IDtrBar dtrBar, ConfigurationServiceBase<LightlessConfig> configService, LightlessMediator lightlessMediator, PairManager pairManager, ApiController apiController, ServerConfigurationManager serverManager)
|
||||
{
|
||||
_logger = logger;
|
||||
_dtrBar = dtrBar;
|
||||
@@ -37,6 +40,7 @@ public sealed class DtrEntry : IDisposable, IHostedService
|
||||
_lightlessMediator = lightlessMediator;
|
||||
_pairManager = pairManager;
|
||||
_apiController = apiController;
|
||||
_serverManager = serverManager;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
@@ -59,7 +63,7 @@ public sealed class DtrEntry : IDisposable, IHostedService
|
||||
|
||||
public async Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_cancellationTokenSource.Cancel();
|
||||
await _cancellationTokenSource.CancelAsync().ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
await _runTask!.ConfigureAwait(false);
|
||||
@@ -89,10 +93,43 @@ public sealed class DtrEntry : IDisposable, IHostedService
|
||||
{
|
||||
_logger.LogTrace("Creating new DtrBar entry");
|
||||
var entry = _dtrBar.Get("Lightless Sync");
|
||||
entry.OnClick = _ => _lightlessMediator.Publish(new UiToggleMessage(typeof(CompactUi)));
|
||||
entry.OnClick = interactionEvent => OnClickEvent(interactionEvent);
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
private void OnClickEvent(DtrInteractionEvent interactionEvent)
|
||||
{
|
||||
if (interactionEvent.ClickType.Equals(MouseClickType.Left) && !interactionEvent.ModifierKeys.Equals(ClickModifierKeys.Shift))
|
||||
{
|
||||
_lightlessMediator.Publish(new UiToggleMessage(typeof(CompactUi)));
|
||||
}
|
||||
else if (interactionEvent.ClickType.Equals(MouseClickType.Left) && interactionEvent.ModifierKeys.Equals(ClickModifierKeys.Shift))
|
||||
{
|
||||
_lightlessMediator.Publish(new UiToggleMessage(typeof(SettingsUi)));
|
||||
}
|
||||
|
||||
if (interactionEvent.ClickType.Equals(MouseClickType.Right))
|
||||
{
|
||||
bool isConnectingOrConnected = _apiController.ServerState is ServerState.Connected or ServerState.Connecting or ServerState.Reconnecting;
|
||||
|
||||
if (_apiController.ServerState is not (ServerState.Reconnecting or ServerState.Disconnecting))
|
||||
{
|
||||
if (isConnectingOrConnected && !_serverManager.CurrentServer.FullPause)
|
||||
{
|
||||
_serverManager.CurrentServer.FullPause = true;
|
||||
_serverManager.Save();
|
||||
}
|
||||
else if (!isConnectingOrConnected && _serverManager.CurrentServer.FullPause)
|
||||
{
|
||||
_serverManager.CurrentServer.FullPause = false;
|
||||
_serverManager.Save();
|
||||
}
|
||||
|
||||
_ = _apiController.CreateConnectionsAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RunAsync()
|
||||
{
|
||||
|
||||
@@ -110,7 +110,7 @@ internal class EventViewerUI : WindowMediatorSubscriberBase
|
||||
{
|
||||
ImGui.SameLine();
|
||||
ImGui.AlignTextToFramePadding();
|
||||
UiSharedService.ColorTextWrapped("New events are available, press refresh to update", ImGuiColors.DalamudYellow);
|
||||
UiSharedService.ColorTextWrapped("New events are available, press refresh to update", UIColors.Get("LightlessYellow"));
|
||||
}
|
||||
|
||||
var buttonSize = _uiSharedService.GetIconTextButtonSize(FontAwesomeIcon.FolderOpen, "Open EventLog Folder");
|
||||
@@ -180,7 +180,7 @@ internal class EventViewerUI : WindowMediatorSubscriberBase
|
||||
var iconColor = ev.EventSeverity switch
|
||||
{
|
||||
EventSeverity.Informational => new Vector4(),
|
||||
EventSeverity.Warning => ImGuiColors.DalamudYellow,
|
||||
EventSeverity.Warning => UIColors.Get("LightlessYellow"),
|
||||
EventSeverity.Error => ImGuiColors.DalamudRed,
|
||||
_ => new Vector4()
|
||||
};
|
||||
|
||||
@@ -6,6 +6,8 @@ using LightlessSync.LightlessConfiguration;
|
||||
using LightlessSync.PlayerData.Pairs;
|
||||
using LightlessSync.Services.Mediator;
|
||||
using LightlessSync.Services.ServerConfiguration;
|
||||
using LightlessSync.Utils;
|
||||
using System.Numerics;
|
||||
|
||||
namespace LightlessSync.UI.Handlers;
|
||||
|
||||
@@ -43,9 +45,9 @@ public class IdDisplayHandler
|
||||
if (ImGui.IsItemClicked(ImGuiMouseButton.Left))
|
||||
{
|
||||
var prevState = textIsUid;
|
||||
if (_showIdForEntry.ContainsKey(group.GID))
|
||||
if (_showIdForEntry.TryGetValue(group.GID, out bool value))
|
||||
{
|
||||
prevState = _showIdForEntry[group.GID];
|
||||
prevState = value;
|
||||
}
|
||||
_showIdForEntry[group.GID] = !prevState;
|
||||
}
|
||||
@@ -89,11 +91,37 @@ public class IdDisplayHandler
|
||||
{
|
||||
ImGui.SameLine(textPosX);
|
||||
(bool textIsUid, string playerText) = GetPlayerText(pair);
|
||||
|
||||
if (!string.Equals(_editEntry, pair.UserData.UID, StringComparison.Ordinal))
|
||||
{
|
||||
ImGui.AlignTextToFramePadding();
|
||||
|
||||
using (ImRaii.PushFont(UiBuilder.MonoFont, textIsUid)) ImGui.TextUnformatted(playerText);
|
||||
var font = UiBuilder.MonoFont;
|
||||
|
||||
var isAdmin = pair.UserData.IsAdmin;
|
||||
var isModerator = pair.UserData.IsModerator;
|
||||
|
||||
Vector4? textColor = isAdmin
|
||||
? UIColors.Get("LightlessAdminText")
|
||||
: isModerator
|
||||
? UIColors.Get("LightlessModeratorText")
|
||||
: null;
|
||||
|
||||
Vector4? glowColor = isAdmin
|
||||
? UIColors.Get("LightlessAdminGlow")
|
||||
: isModerator
|
||||
? UIColors.Get("LightlessModeratorGlow")
|
||||
: null;
|
||||
|
||||
var seString = (textColor != null || glowColor != null)
|
||||
? SeStringUtils.BuildFormattedPlayerName(playerText, textColor, glowColor)
|
||||
: SeStringUtils.BuildPlain(playerText);
|
||||
|
||||
using (ImRaii.PushFont(font, textIsUid))
|
||||
{
|
||||
var pos = ImGui.GetCursorScreenPos();
|
||||
SeStringUtils.RenderSeStringWithHitbox(seString, pos, font);
|
||||
}
|
||||
|
||||
if (ImGui.IsItemHovered())
|
||||
{
|
||||
@@ -173,10 +201,12 @@ public class IdDisplayHandler
|
||||
{
|
||||
_editEntry = string.Empty;
|
||||
}
|
||||
|
||||
UiSharedService.AttachToolTip("Hit ENTER to save\nRight click to cancel");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public (bool isGid, string text) GetGroupText(GroupFullInfoDto group)
|
||||
{
|
||||
var textIsGid = true;
|
||||
|
||||
@@ -17,61 +17,146 @@ public class TagHandler
|
||||
_serverConfigurationManager = serverConfigurationManager;
|
||||
}
|
||||
|
||||
public void AddTag(string tag)
|
||||
{
|
||||
_serverConfigurationManager.AddTag(tag);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creation of an pair tag
|
||||
/// </summary>
|
||||
/// <param name="tag">Name of the tag</param>
|
||||
public void AddPairTag(string tag) => _serverConfigurationManager.AddPairTag(tag);
|
||||
|
||||
public void AddTagToPairedUid(string uid, string tagName)
|
||||
{
|
||||
_serverConfigurationManager.AddTagForUid(uid, tagName);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creation of an syncshell tag
|
||||
/// </summary>
|
||||
/// <param name="tag">Name of the tag</param>
|
||||
public void AddSyncshellTag(string tag) => _serverConfigurationManager.AddSyncshellTag(tag);
|
||||
|
||||
public List<string> GetAllTagsSorted()
|
||||
{
|
||||
return
|
||||
[
|
||||
/// <summary>
|
||||
/// Add pair to tag
|
||||
/// </summary>
|
||||
/// <param name="uid">UID that will be added to tag/param>
|
||||
/// <param name="tagName">Name of the tag</param>
|
||||
public void AddPairTagToPairedUid(string uid, string tagName) => _serverConfigurationManager.AddTagForUid(uid, tagName);
|
||||
|
||||
/// <summary>
|
||||
/// Add syncshell to tag
|
||||
/// </summary>
|
||||
/// <param name="name">Syncshell that will be added to tag/param>
|
||||
/// <param name="tagName">Name of the tag</param>
|
||||
public void AddTagToSyncshell(string name, string tagName) => _serverConfigurationManager.AddTagForSyncshell(name, tagName);
|
||||
|
||||
/// <summary>
|
||||
/// Get all pair tags
|
||||
/// </summary>
|
||||
public List<string> GetAllPairTagsSorted() => [
|
||||
.. _serverConfigurationManager.GetServerAvailablePairTags()
|
||||
.OrderBy(s => s, StringComparer.OrdinalIgnoreCase)
|
||||
.Order(StringComparer.OrdinalIgnoreCase)
|
||||
,
|
||||
];
|
||||
}
|
||||
|
||||
public HashSet<string> GetOtherUidsForTag(string tag)
|
||||
{
|
||||
return _serverConfigurationManager.GetUidsForTag(tag);
|
||||
}
|
||||
/// <summary>
|
||||
/// Get all syncshell tags
|
||||
/// </summary>
|
||||
public List<string> GetAllSyncshellTagsSorted() => [
|
||||
.. _serverConfigurationManager.GetServerAvailableSyncshellTags()
|
||||
.Order(StringComparer.OrdinalIgnoreCase)
|
||||
,
|
||||
];
|
||||
|
||||
public bool HasAnyTag(string uid)
|
||||
{
|
||||
return _serverConfigurationManager.HasTags(uid);
|
||||
}
|
||||
/// <summary>
|
||||
/// Get all UIDs bound to an given tag
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the tag</param>
|
||||
public HashSet<string> GetOtherUidsForTag(string tag) => _serverConfigurationManager.GetUidsForPairTag(tag);
|
||||
|
||||
public bool HasTag(string uid, string tagName)
|
||||
{
|
||||
return _serverConfigurationManager.ContainsTag(uid, tagName);
|
||||
}
|
||||
/// <summary>
|
||||
/// Get all syncshells bound to an given tag
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the tag</param>
|
||||
public HashSet<string> GetOtherSyncshellsForTag(string tag) => _serverConfigurationManager.GetNamesForSyncshellTag(tag);
|
||||
|
||||
/// <summary>
|
||||
/// Checking if the UID is connected to any tag
|
||||
/// </summary>
|
||||
/// <param name="uid">Syncshell that needs to be checked</param>
|
||||
public bool HasAnyPairTag(string uid) => _serverConfigurationManager.HasPairTags(uid);
|
||||
|
||||
/// <summary>
|
||||
/// Checking if the syncshell is connected to the tag
|
||||
/// </summary>
|
||||
/// <param name="name">Syncshell that needs to be checked</param>
|
||||
public bool HasAnySyncshellTag(string name) => _serverConfigurationManager.HasSyncshellTags(name);
|
||||
|
||||
/// <summary>
|
||||
/// Checking if the UID is connected to the tag
|
||||
/// </summary>
|
||||
/// <param name="uid">UID that needs to be checked</param>
|
||||
/// <param name="tagName">Name of the tag</param>
|
||||
public bool HasPairTag(string uid, string tagName) => _serverConfigurationManager.ContainsPairTag(uid, tagName);
|
||||
|
||||
/// <summary>
|
||||
/// Checking if the syncshell is connected to the tag
|
||||
/// </summary>
|
||||
/// <param name="name">Syncshell that needs to be checked</param>
|
||||
/// <param name="tagName">Name of the tag</param>
|
||||
public bool HasSyncshellTag(string name, string tagName) => _serverConfigurationManager.ContainsSyncshellTag(name, tagName);
|
||||
|
||||
/// <summary>
|
||||
/// Is this tag opened in the paired clients UI?
|
||||
/// </summary>
|
||||
/// <param name="tag">the tag</param>
|
||||
/// <returns>open true/false</returns>
|
||||
public bool IsTagOpen(string tag)
|
||||
public bool IsTagOpen(string tag) => _serverConfigurationManager.ContainsOpenPairTag(tag);
|
||||
|
||||
/// <summary>
|
||||
/// Removal of Pair Tags from Storage
|
||||
/// </summary>
|
||||
/// <param name="tag">Name of the tag</param>
|
||||
public void RemovePairTag(string tag) => _serverConfigurationManager.RemovePairTag(tag);
|
||||
|
||||
/// <summary>
|
||||
/// Removal of Syncshell Tags from Storage
|
||||
/// </summary>
|
||||
/// <param name="tag">Name of the tag</param>
|
||||
public void RemoveSyncshellTag(string tag) => _serverConfigurationManager.RemoveSyncshellTag(tag);
|
||||
|
||||
/// <summary>
|
||||
/// Removal of UID in a Tag
|
||||
/// </summary>
|
||||
/// <param name="uid">UID of user thats bound to the tag</param>
|
||||
/// <param name="tagName">Name of the tag</param>
|
||||
public void RemoveTagFromPairedUid(string uid, string tagName) => _serverConfigurationManager.RemoveTagForUid(uid, tagName);
|
||||
|
||||
/// <summary>
|
||||
/// Removal of Syncshell in a Tag
|
||||
/// </summary>
|
||||
/// <param name="name">Syncshell thats bound to the tag</param>
|
||||
/// <param name="tagName">Name of the tag</param>
|
||||
public void RemoveTagFromSyncshell(string name, string tagName) => _serverConfigurationManager.RemoveTagForSyncshell(name, tagName);
|
||||
|
||||
/// <summary>
|
||||
/// Rename of a pair tag
|
||||
/// </summary>
|
||||
/// <param name="oldName">Old pair tag name</param>
|
||||
/// <param name="newName">New pair tag name</param>
|
||||
public void RenamePairTag(string oldName, string newName)
|
||||
{
|
||||
return _serverConfigurationManager.ContainsOpenPairTag(tag);
|
||||
_serverConfigurationManager.RenamePairTag(oldName, newName);
|
||||
}
|
||||
|
||||
public void RemoveTag(string tag)
|
||||
/// <summary>
|
||||
/// Rename of a syncshell tag
|
||||
/// </summary>
|
||||
/// <param name="oldName">Old syncshell tag name</param>
|
||||
/// <param name="newName">New syncshell tag name</param>
|
||||
public void RenameSyncshellTag(string oldName, string newName)
|
||||
{
|
||||
_serverConfigurationManager.RemoveTag(tag);
|
||||
}
|
||||
|
||||
public void RemoveTagFromPairedUid(string uid, string tagName)
|
||||
{
|
||||
_serverConfigurationManager.RemoveTagForUid(uid, tagName);
|
||||
_serverConfigurationManager.RenameSyncshellTag(oldName, newName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the tag to open/close
|
||||
/// </summary>
|
||||
/// <param name="tag">The Tag that will be modified</param>
|
||||
/// <param name="open">True/False</param>
|
||||
public void SetTagOpen(string tag, bool open)
|
||||
{
|
||||
if (open)
|
||||
|
||||
@@ -78,7 +78,7 @@ public partial class IntroUi : WindowMediatorSubscriberBase
|
||||
|
||||
UiSharedService.ColorTextWrapped("Note: Any modifications you have applied through anything but Penumbra cannot be shared and your character state on other clients " +
|
||||
"might look broken because of this or others players mods might not apply on your end altogether. " +
|
||||
"If you want to use this plugin you will have to move your mods to Penumbra.", ImGuiColors.DalamudYellow);
|
||||
"If you want to use this plugin you will have to move your mods to Penumbra.", UIColors.Get("LightlessYellow"));
|
||||
if (!_uiShared.DrawOtherPluginState()) return;
|
||||
ImGui.Separator();
|
||||
if (ImGui.Button("Next##toAgreement"))
|
||||
@@ -172,8 +172,8 @@ public partial class IntroUi : WindowMediatorSubscriberBase
|
||||
"Once the storage folder is set and the scan complete, this page will automatically forward to registration at a service.");
|
||||
UiSharedService.TextWrapped("Note: The initial scan, depending on the amount of mods you have, might take a while. Please wait until it is completed.");
|
||||
UiSharedService.ColorTextWrapped("Warning: once past this step you should not delete the FileCache.csv of Lightless Sync in the Plugin Configurations folder of Dalamud. " +
|
||||
"Otherwise on the next launch a full re-scan of the file cache database will be initiated.", ImGuiColors.DalamudYellow);
|
||||
UiSharedService.ColorTextWrapped("Warning: if the scan is hanging and does nothing for a long time, chances are high your Penumbra folder is not set up properly.", ImGuiColors.DalamudYellow);
|
||||
"Otherwise on the next launch a full re-scan of the file cache database will be initiated.", UIColors.Get("LightlessYellow"));
|
||||
UiSharedService.ColorTextWrapped("Warning: if the scan is hanging and does nothing for a long time, chances are high your Penumbra folder is not set up properly.", UIColors.Get("LightlessYellow"));
|
||||
_uiShared.DrawCacheDirectorySetting();
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ public partial class IntroUi : WindowMediatorSubscriberBase
|
||||
_configService.Save();
|
||||
}
|
||||
UiSharedService.ColorTextWrapped("The File Compactor can save a tremendeous amount of space on the hard disk for downloads through Lightless. It will incur a minor CPU penalty on download but can speed up " +
|
||||
"loading of other characters. It is recommended to keep it enabled. You can change this setting later anytime in the Lightless settings.", ImGuiColors.DalamudYellow);
|
||||
"loading of other characters. It is recommended to keep it enabled. You can change this setting later anytime in the Lightless settings.", UIColors.Get("LightlessYellow"));
|
||||
}
|
||||
}
|
||||
else if (!_uiShared.ApiController.ServerAlive)
|
||||
@@ -255,7 +255,7 @@ public partial class IntroUi : WindowMediatorSubscriberBase
|
||||
ImGuiHelpers.ScaledDummy(5);
|
||||
UiSharedService.DrawGroupedCenteredColorText("Strongly consider to use OAuth2 to authenticate, if the server supports it (the current main server does). " +
|
||||
"The authentication flow is simpler and you do not require to store or maintain Secret Keys. " +
|
||||
"You already implicitly register using Discord, so the OAuth2 method will be cleaner and more straight-forward to use.", ImGuiColors.DalamudYellow, 500);
|
||||
"You already implicitly register using Discord, so the OAuth2 method will be cleaner and more straight-forward to use.", UIColors.Get("LightlessYellow"), 500);
|
||||
ImGuiHelpers.ScaledDummy(5);
|
||||
|
||||
ImGui.AlignTextToFramePadding();
|
||||
|
||||
@@ -88,7 +88,7 @@ internal class JoinSyncshellUI : WindowMediatorSubscriberBase
|
||||
UiSharedService.ColorTextWrapped("Failed to join the Syncshell. This is due to one of following reasons:" + Environment.NewLine +
|
||||
"- The Syncshell does not exist or the password is incorrect" + Environment.NewLine +
|
||||
"- You are already in that Syncshell or are banned from that Syncshell" + Environment.NewLine +
|
||||
"- The Syncshell is at capacity or has invites disabled" + Environment.NewLine, ImGuiColors.DalamudYellow);
|
||||
"- The Syncshell is at capacity or has invites disabled" + Environment.NewLine, UIColors.Get("LightlessYellow"));
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -111,7 +111,7 @@ internal class JoinSyncshellUI : WindowMediatorSubscriberBase
|
||||
|| _groupJoinInfo.GroupPermissions.IsPreferDisableAnimations() != _ownPermissions.DisableGroupAnimations)
|
||||
{
|
||||
ImGuiHelpers.ScaledDummy(2f);
|
||||
UiSharedService.ColorText("Your current preferred default Syncshell permissions deviate from the suggested permissions:", ImGuiColors.DalamudYellow);
|
||||
UiSharedService.ColorText("Your current preferred default Syncshell permissions deviate from the suggested permissions:", UIColors.Get("LightlessYellow"));
|
||||
if (_groupJoinInfo.GroupPermissions.IsPreferDisableSounds() != _ownPermissions.DisableGroupSounds)
|
||||
{
|
||||
ImGui.AlignTextToFramePadding();
|
||||
|
||||
@@ -102,7 +102,7 @@ public class PermissionWindowUI : WindowMediatorSubscriberBase
|
||||
{
|
||||
_ownPermissions.SetDisableAnimations(disableAnimations);
|
||||
}
|
||||
_uiSharedService.DrawHelpText("Disabling sounds will remove all animations synced with this user on both sides." + UiSharedService.TooltipSeparator
|
||||
_uiSharedService.DrawHelpText("Disabling animations will remove all animations synced with this user on both sides." + UiSharedService.TooltipSeparator
|
||||
+ "Note: this is bidirectional, either user disabling animation sync will stop animation sync on both sides.");
|
||||
using (ImRaii.PushIndent(indentSize, false))
|
||||
{
|
||||
@@ -116,7 +116,7 @@ public class PermissionWindowUI : WindowMediatorSubscriberBase
|
||||
{
|
||||
_ownPermissions.SetDisableVFX(disableVfx);
|
||||
}
|
||||
_uiSharedService.DrawHelpText("Disabling sounds will remove all VFX synced with this user on both sides." + UiSharedService.TooltipSeparator
|
||||
_uiSharedService.DrawHelpText("Disabling VFX will remove all VFX synced with this user on both sides." + UiSharedService.TooltipSeparator
|
||||
+ "Note: this is bidirectional, either user disabling VFX sync will stop VFX sync on both sides.");
|
||||
using (ImRaii.PushIndent(indentSize, false))
|
||||
{
|
||||
|
||||
@@ -135,12 +135,12 @@ public class PopoutProfileUi : WindowMediatorSubscriberBase
|
||||
if (_pair.UserPair.OwnPermissions.IsPaused())
|
||||
{
|
||||
ImGui.SameLine();
|
||||
UiSharedService.ColorText("You: paused", ImGuiColors.DalamudYellow);
|
||||
UiSharedService.ColorText("You: paused", UIColors.Get("LightlessYellow"));
|
||||
}
|
||||
if (_pair.UserPair.OtherPermissions.IsPaused())
|
||||
{
|
||||
ImGui.SameLine();
|
||||
UiSharedService.ColorText("They: paused", ImGuiColors.DalamudYellow);
|
||||
UiSharedService.ColorText("They: paused", UIColors.Get("LightlessYellow"));
|
||||
}
|
||||
}
|
||||
if (_pair.UserPair.Groups.Any())
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -130,12 +130,12 @@ public class StandaloneProfileUi : WindowMediatorSubscriberBase
|
||||
if (Pair.UserPair.OwnPermissions.IsPaused())
|
||||
{
|
||||
ImGui.SameLine();
|
||||
UiSharedService.ColorText("You: paused", ImGuiColors.DalamudYellow);
|
||||
UiSharedService.ColorText("You: paused", UIColors.Get("LightlessYellow"));
|
||||
}
|
||||
if (Pair.UserPair.OtherPermissions.IsPaused())
|
||||
{
|
||||
ImGui.SameLine();
|
||||
UiSharedService.ColorText("They: paused", ImGuiColors.DalamudYellow);
|
||||
UiSharedService.ColorText("They: paused", UIColors.Get("LightlessYellow"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
169
LightlessSync/UI/Style/MainStyle.cs
Normal file
169
LightlessSync/UI/Style/MainStyle.cs
Normal file
@@ -0,0 +1,169 @@
|
||||
// inspiration: brio because it's style is fucking amazing
|
||||
|
||||
using Dalamud.Bindings.ImGui;
|
||||
using LightlessSync.LightlessConfiguration;
|
||||
using System.Numerics;
|
||||
|
||||
namespace LightlessSync.UI.Style
|
||||
{
|
||||
internal static class MainStyle
|
||||
{
|
||||
private static LightlessConfigService? _config;
|
||||
public static void Init(LightlessConfigService config) => _config = config;
|
||||
public static bool ShouldUseTheme => _config?.Current.UseLightlessRedesign ?? false;
|
||||
|
||||
private static bool _hasPushed;
|
||||
private static int _pushedColorCount;
|
||||
private static int _pushedStyleVarCount;
|
||||
|
||||
public static void PushStyle()
|
||||
{
|
||||
if (_hasPushed)
|
||||
PopStyle();
|
||||
|
||||
if (!ShouldUseTheme)
|
||||
{
|
||||
_hasPushed = false;
|
||||
return;
|
||||
}
|
||||
|
||||
_hasPushed = true;
|
||||
_pushedColorCount = 0;
|
||||
_pushedStyleVarCount = 0;
|
||||
|
||||
Push(ImGuiCol.Text, new Vector4(255, 255, 255, 255));
|
||||
Push(ImGuiCol.TextDisabled, new Vector4(128, 128, 128, 255));
|
||||
|
||||
Push(ImGuiCol.WindowBg, new Vector4(23, 23, 23, 248));
|
||||
Push(ImGuiCol.ChildBg, new Vector4(23, 23, 23, 66));
|
||||
Push(ImGuiCol.PopupBg, new Vector4(23, 23, 23, 248));
|
||||
|
||||
Push(ImGuiCol.Border, new Vector4(65, 65, 65, 255));
|
||||
Push(ImGuiCol.BorderShadow, new Vector4(0, 0, 0, 150));
|
||||
|
||||
Push(ImGuiCol.FrameBg, new Vector4(40, 40, 40, 255));
|
||||
Push(ImGuiCol.FrameBgHovered, new Vector4(50, 50, 50, 255));
|
||||
Push(ImGuiCol.FrameBgActive, new Vector4(30, 30, 30, 255));
|
||||
|
||||
Push(ImGuiCol.TitleBg, new Vector4(24, 24, 24, 232));
|
||||
Push(ImGuiCol.TitleBgActive, new Vector4(30, 30, 30, 255));
|
||||
Push(ImGuiCol.TitleBgCollapsed, new Vector4(27, 27, 27, 255));
|
||||
|
||||
Push(ImGuiCol.MenuBarBg, new Vector4(36, 36, 36, 255));
|
||||
Push(ImGuiCol.ScrollbarBg, new Vector4(0, 0, 0, 0));
|
||||
Push(ImGuiCol.ScrollbarGrab, new Vector4(62, 62, 62, 255));
|
||||
Push(ImGuiCol.ScrollbarGrabHovered, new Vector4(70, 70, 70, 255));
|
||||
Push(ImGuiCol.ScrollbarGrabActive, new Vector4(70, 70, 70, 255));
|
||||
|
||||
Push(ImGuiCol.CheckMark, UIColors.Get("LightlessPurple"));
|
||||
|
||||
Push(ImGuiCol.SliderGrab, new Vector4(101, 101, 101, 255));
|
||||
Push(ImGuiCol.SliderGrabActive, new Vector4(123, 123, 123, 255));
|
||||
|
||||
Push(ImGuiCol.Button, UIColors.Get("ButtonDefault"));
|
||||
Push(ImGuiCol.ButtonHovered, UIColors.Get("LightlessPurple"));
|
||||
Push(ImGuiCol.ButtonActive, UIColors.Get("LightlessPurpleActive"));
|
||||
|
||||
Push(ImGuiCol.Header, new Vector4(0, 0, 0, 60));
|
||||
Push(ImGuiCol.HeaderHovered, new Vector4(0, 0, 0, 90));
|
||||
Push(ImGuiCol.HeaderActive, new Vector4(0, 0, 0, 120));
|
||||
|
||||
Push(ImGuiCol.Separator, new Vector4(75, 75, 75, 121));
|
||||
Push(ImGuiCol.SeparatorHovered, UIColors.Get("LightlessPurple"));
|
||||
Push(ImGuiCol.SeparatorActive, UIColors.Get("LightlessPurpleActive"));
|
||||
|
||||
Push(ImGuiCol.ResizeGrip, new Vector4(0, 0, 0, 0));
|
||||
Push(ImGuiCol.ResizeGripHovered, new Vector4(0, 0, 0, 0));
|
||||
Push(ImGuiCol.ResizeGripActive, UIColors.Get("LightlessPurpleActive"));
|
||||
|
||||
Push(ImGuiCol.Tab, new Vector4(40, 40, 40, 255));
|
||||
Push(ImGuiCol.TabHovered, UIColors.Get("LightlessPurple"));
|
||||
Push(ImGuiCol.TabActive, UIColors.Get("LightlessPurpleActive"));
|
||||
Push(ImGuiCol.TabUnfocused, new Vector4(40, 40, 40, 255));
|
||||
Push(ImGuiCol.TabUnfocusedActive, UIColors.Get("LightlessPurpleActive"));
|
||||
|
||||
Push(ImGuiCol.DockingPreview, UIColors.Get("LightlessPurpleActive"));
|
||||
Push(ImGuiCol.DockingEmptyBg, new Vector4(50, 50, 50, 255));
|
||||
|
||||
Push(ImGuiCol.PlotLines, new Vector4(150, 150, 150, 255));
|
||||
|
||||
Push(ImGuiCol.TableHeaderBg, new Vector4(48, 48, 48, 255));
|
||||
Push(ImGuiCol.TableBorderStrong, new Vector4(79, 79, 89, 255));
|
||||
Push(ImGuiCol.TableBorderLight, new Vector4(59, 59, 64, 255));
|
||||
Push(ImGuiCol.TableRowBg, new Vector4(0, 0, 0, 0));
|
||||
Push(ImGuiCol.TableRowBgAlt, new Vector4(255, 255, 255, 15));
|
||||
|
||||
Push(ImGuiCol.TextSelectedBg, new Vector4(98, 75, 224, 255));
|
||||
Push(ImGuiCol.DragDropTarget, new Vector4(98, 75, 224, 255));
|
||||
|
||||
Push(ImGuiCol.NavHighlight, new Vector4(98, 75, 224, 179));
|
||||
Push(ImGuiCol.NavWindowingDimBg, new Vector4(204, 204, 204, 51));
|
||||
Push(ImGuiCol.NavWindowingHighlight, new Vector4(204, 204, 204, 89));
|
||||
|
||||
PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(6, 6));
|
||||
PushStyleVar(ImGuiStyleVar.FramePadding, new Vector2(4, 3));
|
||||
PushStyleVar(ImGuiStyleVar.CellPadding, new Vector2(4, 4));
|
||||
PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(4, 4));
|
||||
PushStyleVar(ImGuiStyleVar.ItemInnerSpacing, new Vector2(4, 4));
|
||||
|
||||
PushStyleVar(ImGuiStyleVar.IndentSpacing, 21.0f);
|
||||
PushStyleVar(ImGuiStyleVar.ScrollbarSize, 10.0f);
|
||||
PushStyleVar(ImGuiStyleVar.GrabMinSize, 20.0f);
|
||||
|
||||
PushStyleVar(ImGuiStyleVar.WindowBorderSize, 1.5f);
|
||||
PushStyleVar(ImGuiStyleVar.ChildBorderSize, 1.5f);
|
||||
PushStyleVar(ImGuiStyleVar.PopupBorderSize, 1.5f);
|
||||
PushStyleVar(ImGuiStyleVar.FrameBorderSize, 0f);
|
||||
|
||||
PushStyleVar(ImGuiStyleVar.WindowRounding, 7f);
|
||||
PushStyleVar(ImGuiStyleVar.ChildRounding, 4f);
|
||||
PushStyleVar(ImGuiStyleVar.FrameRounding, 4f);
|
||||
PushStyleVar(ImGuiStyleVar.PopupRounding, 4f);
|
||||
PushStyleVar(ImGuiStyleVar.ScrollbarRounding, 4f);
|
||||
PushStyleVar(ImGuiStyleVar.GrabRounding, 4f);
|
||||
PushStyleVar(ImGuiStyleVar.TabRounding, 4f);
|
||||
}
|
||||
|
||||
public static void PopStyle()
|
||||
{
|
||||
if (!_hasPushed)
|
||||
return;
|
||||
|
||||
if (_pushedStyleVarCount > 0)
|
||||
ImGui.PopStyleVar(_pushedStyleVarCount);
|
||||
if (_pushedColorCount > 0)
|
||||
ImGui.PopStyleColor(_pushedColorCount);
|
||||
|
||||
_hasPushed = false;
|
||||
_pushedColorCount = 0;
|
||||
_pushedStyleVarCount = 0;
|
||||
}
|
||||
|
||||
private static void Push(ImGuiCol col, Vector4 rgba)
|
||||
{
|
||||
if (rgba.X > 1f || rgba.Y > 1f || rgba.Z > 1f || rgba.W > 1f)
|
||||
rgba /= 255f;
|
||||
|
||||
ImGui.PushStyleColor(col, rgba);
|
||||
_pushedColorCount++;
|
||||
}
|
||||
|
||||
private static void Push(ImGuiCol col, uint packedRgba)
|
||||
{
|
||||
ImGui.PushStyleColor(col, packedRgba);
|
||||
_pushedColorCount++;
|
||||
}
|
||||
|
||||
private static void PushStyleVar(ImGuiStyleVar var, float value)
|
||||
{
|
||||
ImGui.PushStyleVar(var, value);
|
||||
_pushedStyleVarCount++;
|
||||
}
|
||||
|
||||
private static void PushStyleVar(ImGuiStyleVar var, Vector2 value)
|
||||
{
|
||||
ImGui.PushStyleVar(var, value);
|
||||
_pushedStyleVarCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ using LightlessSync.WebAPI;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Globalization;
|
||||
|
||||
namespace LightlessSync.UI.Components.Popup;
|
||||
namespace LightlessSync.UI;
|
||||
|
||||
public class SyncshellAdminUI : WindowMediatorSubscriberBase
|
||||
{
|
||||
@@ -63,7 +63,7 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase
|
||||
using var id = ImRaii.PushId("syncshell_admin_" + GroupFullInfo.GID);
|
||||
|
||||
using (_uiSharedService.UidFont.Push())
|
||||
ImGui.TextUnformatted(GroupFullInfo.GroupAliasOrGID + " Administrative Panel");
|
||||
_uiSharedService.UnderlinedBigText(GroupFullInfo.GroupAliasOrGID + " Administrative Panel", UIColors.Get("LightlessBlue"));
|
||||
|
||||
ImGui.Separator();
|
||||
var perm = GroupFullInfo.GroupPermissions;
|
||||
@@ -72,119 +72,205 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase
|
||||
|
||||
if (tabbar)
|
||||
{
|
||||
var inviteTab = ImRaii.TabItem("Invites");
|
||||
if (inviteTab)
|
||||
{
|
||||
bool isInvitesDisabled = perm.IsDisableInvites();
|
||||
DrawInvites(perm);
|
||||
|
||||
if (_uiSharedService.IconTextButton(isInvitesDisabled ? FontAwesomeIcon.Unlock : FontAwesomeIcon.Lock,
|
||||
isInvitesDisabled ? "Unlock Syncshell" : "Lock Syncshell"))
|
||||
DrawManagement();
|
||||
|
||||
DrawPermission(perm);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawPermission(GroupPermissions perm)
|
||||
{
|
||||
var permissionTab = ImRaii.TabItem("Permissions");
|
||||
if (permissionTab)
|
||||
{
|
||||
bool isDisableAnimations = perm.IsPreferDisableAnimations();
|
||||
bool isDisableSounds = perm.IsPreferDisableSounds();
|
||||
bool isDisableVfx = perm.IsPreferDisableVFX();
|
||||
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.Text("Suggest Sound Sync");
|
||||
_uiSharedService.BooleanToColoredIcon(!isDisableSounds);
|
||||
ImGui.SameLine(230);
|
||||
using (ImRaii.PushColor(ImGuiCol.Text, isDisableSounds ? UIColors.Get("PairBlue") : UIColors.Get("DimRed")))
|
||||
{
|
||||
if (_uiSharedService.IconTextButton(isDisableSounds ? FontAwesomeIcon.VolumeUp : FontAwesomeIcon.VolumeMute,
|
||||
isDisableSounds ? "Suggest to enable sound sync" : "Suggest to disable sound sync"))
|
||||
{
|
||||
perm.SetDisableInvites(!isInvitesDisabled);
|
||||
perm.SetPreferDisableSounds(!perm.IsPreferDisableSounds());
|
||||
_ = _apiController.GroupChangeGroupPermissionState(new(GroupFullInfo.Group, perm));
|
||||
}
|
||||
}
|
||||
|
||||
ImGuiHelpers.ScaledDummy(2f);
|
||||
|
||||
UiSharedService.TextWrapped("One-time invites work as single-use passwords. Use those if you do not want to distribute your Syncshell password.");
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Envelope, "Single one-time invite"))
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.Text("Suggest Animation Sync");
|
||||
_uiSharedService.BooleanToColoredIcon(!isDisableAnimations);
|
||||
ImGui.SameLine(230);
|
||||
using (ImRaii.PushColor(ImGuiCol.Text, isDisableAnimations ? UIColors.Get("PairBlue") : UIColors.Get("DimRed")))
|
||||
{
|
||||
if (_uiSharedService.IconTextButton(isDisableAnimations ? FontAwesomeIcon.Running : FontAwesomeIcon.Stop,
|
||||
isDisableAnimations ? "Suggest to enable animation sync" : "Suggest to disable animation sync"))
|
||||
{
|
||||
ImGui.SetClipboardText(_apiController.GroupCreateTempInvite(new(GroupFullInfo.Group), 1).Result.FirstOrDefault() ?? string.Empty);
|
||||
}
|
||||
UiSharedService.AttachToolTip("Creates a single-use password for joining the syncshell which is valid for 24h and copies it to the clipboard.");
|
||||
ImGui.InputInt("##amountofinvites", ref _multiInvites);
|
||||
ImGui.SameLine();
|
||||
using (ImRaii.Disabled(_multiInvites <= 1 || _multiInvites > 100))
|
||||
{
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Envelope, "Generate " + _multiInvites + " one-time invites"))
|
||||
{
|
||||
_oneTimeInvites.AddRange(_apiController.GroupCreateTempInvite(new(GroupFullInfo.Group), _multiInvites).Result);
|
||||
}
|
||||
}
|
||||
|
||||
if (_oneTimeInvites.Any())
|
||||
{
|
||||
var invites = string.Join(Environment.NewLine, _oneTimeInvites);
|
||||
ImGui.InputTextMultiline("Generated Multi Invites", ref invites, 5000, new(0, 0), ImGuiInputTextFlags.ReadOnly);
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Copy, "Copy Invites to clipboard"))
|
||||
{
|
||||
ImGui.SetClipboardText(invites);
|
||||
}
|
||||
perm.SetPreferDisableAnimations(!perm.IsPreferDisableAnimations());
|
||||
_ = _apiController.GroupChangeGroupPermissionState(new(GroupFullInfo.Group, perm));
|
||||
}
|
||||
}
|
||||
inviteTab.Dispose();
|
||||
|
||||
var mgmtTab = ImRaii.TabItem("User Management");
|
||||
if (mgmtTab)
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.Text("Suggest VFX Sync");
|
||||
_uiSharedService.BooleanToColoredIcon(!isDisableVfx);
|
||||
ImGui.SameLine(230);
|
||||
using (ImRaii.PushColor(ImGuiCol.Text, isDisableVfx ? UIColors.Get("PairBlue") : UIColors.Get("DimRed")))
|
||||
{
|
||||
var userNode = ImRaii.TreeNode("User List & Administration");
|
||||
if (userNode)
|
||||
if (_uiSharedService.IconTextButton(isDisableVfx ? FontAwesomeIcon.Sun : FontAwesomeIcon.Circle,
|
||||
isDisableVfx ? "Suggest to enable vfx sync" : "Suggest to disable vfx sync"))
|
||||
{
|
||||
if (!_pairManager.GroupPairs.TryGetValue(GroupFullInfo, out var pairs))
|
||||
perm.SetPreferDisableVFX(!perm.IsPreferDisableVFX());
|
||||
_ = _apiController.GroupChangeGroupPermissionState(new(GroupFullInfo.Group, perm));
|
||||
}
|
||||
}
|
||||
|
||||
UiSharedService.TextWrapped("Note: those suggested permissions will be shown to users on joining the Syncshell.");
|
||||
}
|
||||
permissionTab.Dispose();
|
||||
|
||||
if (_isOwner)
|
||||
{
|
||||
var ownerTab = ImRaii.TabItem("Owner Settings");
|
||||
if (ownerTab)
|
||||
{
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.TextUnformatted("New Password");
|
||||
var availableWidth = ImGui.GetWindowContentRegionMax().X - ImGui.GetWindowContentRegionMin().X;
|
||||
var buttonSize = _uiSharedService.GetIconTextButtonSize(FontAwesomeIcon.Passport, "Change Password");
|
||||
var textSize = ImGui.CalcTextSize("New Password").X;
|
||||
var spacing = ImGui.GetStyle().ItemSpacing.X;
|
||||
|
||||
ImGui.SameLine();
|
||||
ImGui.SetNextItemWidth(availableWidth - buttonSize - textSize - spacing * 2);
|
||||
ImGui.InputTextWithHint("##changepw", "Min 10 characters", ref _newPassword, 50);
|
||||
ImGui.SameLine();
|
||||
using (ImRaii.Disabled(_newPassword.Length < 10))
|
||||
{
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Passport, "Change Password"))
|
||||
{
|
||||
UiSharedService.ColorTextWrapped("No users found in this Syncshell", ImGuiColors.DalamudYellow);
|
||||
_pwChangeSuccess = _apiController.GroupChangePassword(new GroupPasswordDto(GroupFullInfo.Group, _newPassword)).Result;
|
||||
_newPassword = string.Empty;
|
||||
}
|
||||
else
|
||||
}
|
||||
UiSharedService.AttachToolTip("Password requires to be at least 10 characters long. This action is irreversible.");
|
||||
|
||||
if (!_pwChangeSuccess)
|
||||
{
|
||||
UiSharedService.ColorTextWrapped("Failed to change the password. Password requires to be at least 10 characters long.", ImGuiColors.DalamudYellow);
|
||||
}
|
||||
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Delete Syncshell") && UiSharedService.CtrlPressed() && UiSharedService.ShiftPressed())
|
||||
{
|
||||
IsOpen = false;
|
||||
_ = _apiController.GroupDelete(new(GroupFullInfo.Group));
|
||||
}
|
||||
UiSharedService.AttachToolTip("Hold CTRL and Shift and click to delete this Syncshell." + Environment.NewLine + "WARNING: this action is irreversible.");
|
||||
}
|
||||
ownerTab.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawManagement()
|
||||
{
|
||||
var mgmtTab = ImRaii.TabItem("User Management");
|
||||
if (mgmtTab)
|
||||
{
|
||||
if (_uiSharedService.MediumTreeNode("User List & Administration", UIColors.Get("LightlessPurple")))
|
||||
{
|
||||
if (!_pairManager.GroupPairs.TryGetValue(GroupFullInfo, out var pairs))
|
||||
{
|
||||
UiSharedService.ColorTextWrapped("No users found in this Syncshell", ImGuiColors.DalamudYellow);
|
||||
}
|
||||
else
|
||||
{
|
||||
var tableFlags = ImGuiTableFlags.RowBg | ImGuiTableFlags.SizingStretchProp;
|
||||
if (pairs.Count > 10) tableFlags |= ImGuiTableFlags.ScrollY;
|
||||
using var table = ImRaii.Table("userList#" + GroupFullInfo.Group.GID, 3, tableFlags);
|
||||
if (table)
|
||||
{
|
||||
using var table = ImRaii.Table("userList#" + GroupFullInfo.Group.GID, 4, ImGuiTableFlags.RowBg | ImGuiTableFlags.SizingStretchProp | ImGuiTableFlags.ScrollY);
|
||||
if (table)
|
||||
ImGui.TableSetupColumn("Alias/UID/Note", ImGuiTableColumnFlags.None, 4);
|
||||
ImGui.TableSetupColumn("Flags", ImGuiTableColumnFlags.None, 1);
|
||||
ImGui.TableSetupColumn("Actions", ImGuiTableColumnFlags.None, 3);
|
||||
ImGui.TableHeadersRow();
|
||||
|
||||
var groupedPairs = new Dictionary<Pair, GroupPairUserInfo?>(pairs.Select(p => new KeyValuePair<Pair, GroupPairUserInfo?>(p,
|
||||
GroupFullInfo.GroupPairUserInfos.TryGetValue(p.UserData.UID, out GroupPairUserInfo value) ? value : null)));
|
||||
|
||||
foreach (var pair in groupedPairs.OrderBy(p =>
|
||||
{
|
||||
ImGui.TableSetupColumn("Alias/UID/Note", ImGuiTableColumnFlags.None, 3);
|
||||
ImGui.TableSetupColumn("Online/Name", ImGuiTableColumnFlags.None, 2);
|
||||
ImGui.TableSetupColumn("Flags", ImGuiTableColumnFlags.None, 1);
|
||||
ImGui.TableSetupColumn("Actions", ImGuiTableColumnFlags.None, 2);
|
||||
ImGui.TableHeadersRow();
|
||||
if (p.Value == null) return 10;
|
||||
if (string.Equals(p.Key.UserData.UID, GroupFullInfo.OwnerUID, StringComparison.Ordinal)) return 0;
|
||||
if (p.Value.Value.IsModerator()) return 1;
|
||||
if (p.Value.Value.IsPinned()) return 2;
|
||||
return 10;
|
||||
}).ThenBy(p => p.Key.GetNote() ?? p.Key.UserData.AliasOrUID, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
using var tableId = ImRaii.PushId("userTable_" + pair.Key.UserData.UID);
|
||||
var isUserOwner = string.Equals(pair.Key.UserData.UID, GroupFullInfo.OwnerUID, StringComparison.Ordinal);
|
||||
|
||||
var groupedPairs = new Dictionary<Pair, GroupPairUserInfo?>(pairs.Select(p => new KeyValuePair<Pair, GroupPairUserInfo?>(p,
|
||||
GroupFullInfo.GroupPairUserInfos.TryGetValue(p.UserData.UID, out GroupPairUserInfo value) ? value : null)));
|
||||
|
||||
foreach (var pair in groupedPairs.OrderBy(p =>
|
||||
ImGui.TableNextColumn(); // alias/uid/note
|
||||
var note = pair.Key.GetNote();
|
||||
var text = note == null ? pair.Key.UserData.AliasOrUID : note + " (" + pair.Key.UserData.AliasOrUID + ")";
|
||||
ImGui.AlignTextToFramePadding();
|
||||
var boolcolor = UiSharedService.GetBoolColor(pair.Key.IsOnline);
|
||||
UiSharedService.ColorText(text, boolcolor);
|
||||
if (!string.IsNullOrEmpty(pair.Key.PlayerName))
|
||||
{
|
||||
if (p.Value == null) return 10;
|
||||
if (p.Value.Value.IsModerator()) return 0;
|
||||
if (p.Value.Value.IsPinned()) return 1;
|
||||
return 10;
|
||||
}).ThenBy(p => p.Key.GetNote() ?? p.Key.UserData.AliasOrUID, StringComparer.OrdinalIgnoreCase))
|
||||
UiSharedService.AttachToolTip(pair.Key.PlayerName);
|
||||
ImGui.SameLine();
|
||||
}
|
||||
|
||||
ImGui.TableNextColumn(); // special flags
|
||||
if (pair.Value != null && (pair.Value.Value.IsModerator() || pair.Value.Value.IsPinned() || isUserOwner))
|
||||
{
|
||||
using var tableId = ImRaii.PushId("userTable_" + pair.Key.UserData.UID);
|
||||
|
||||
ImGui.TableNextColumn(); // alias/uid/note
|
||||
var note = pair.Key.GetNote();
|
||||
var text = note == null ? pair.Key.UserData.AliasOrUID : note + " (" + pair.Key.UserData.AliasOrUID + ")";
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.TextUnformatted(text);
|
||||
|
||||
ImGui.TableNextColumn(); // online/name
|
||||
string onlineText = pair.Key.IsOnline ? "Online" : "Offline";
|
||||
if (!string.IsNullOrEmpty(pair.Key.PlayerName))
|
||||
if (pair.Value.Value.IsModerator())
|
||||
{
|
||||
onlineText += " (" + pair.Key.PlayerName + ")";
|
||||
_uiSharedService.IconText(FontAwesomeIcon.UserShield, UIColors.Get("LightlessPurple"));
|
||||
UiSharedService.AttachToolTip("Moderator");
|
||||
}
|
||||
var boolcolor = UiSharedService.GetBoolColor(pair.Key.IsOnline);
|
||||
ImGui.AlignTextToFramePadding();
|
||||
UiSharedService.ColorText(onlineText, boolcolor);
|
||||
|
||||
ImGui.TableNextColumn(); // special flags
|
||||
if (pair.Value != null && (pair.Value.Value.IsModerator() || pair.Value.Value.IsPinned()))
|
||||
if (pair.Value.Value.IsPinned() && !isUserOwner)
|
||||
{
|
||||
if (pair.Value.Value.IsModerator())
|
||||
_uiSharedService.IconText(FontAwesomeIcon.Thumbtack);
|
||||
UiSharedService.AttachToolTip("Pinned");
|
||||
}
|
||||
if (isUserOwner)
|
||||
{
|
||||
_uiSharedService.IconText(FontAwesomeIcon.Crown, UIColors.Get("LightlessYellow"));
|
||||
UiSharedService.AttachToolTip("Owner");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_uiSharedService.IconText(FontAwesomeIcon.None);
|
||||
}
|
||||
|
||||
ImGui.TableNextColumn(); // actions
|
||||
if (_isOwner)
|
||||
{
|
||||
using (ImRaii.PushColor(ImGuiCol.Text, UIColors.Get("LightlessYellow")))
|
||||
{
|
||||
using (ImRaii.Disabled(!UiSharedService.ShiftPressed()))
|
||||
{
|
||||
_uiSharedService.IconText(FontAwesomeIcon.UserShield);
|
||||
UiSharedService.AttachToolTip("Moderator");
|
||||
if (_uiSharedService.IconButton(FontAwesomeIcon.Crown))
|
||||
{
|
||||
_ = _apiController.GroupChangeOwnership(new(GroupFullInfo.Group, pair.Key.UserData));
|
||||
IsOpen = false;
|
||||
}
|
||||
}
|
||||
if (pair.Value.Value.IsPinned())
|
||||
{
|
||||
_uiSharedService.IconText(FontAwesomeIcon.Thumbtack);
|
||||
UiSharedService.AttachToolTip("Pinned");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_uiSharedService.IconText(FontAwesomeIcon.None);
|
||||
}
|
||||
|
||||
ImGui.TableNextColumn(); // actions
|
||||
if (_isOwner)
|
||||
}
|
||||
UiSharedService.AttachToolTip("Hold SHIFT and click to transfer ownership of this Syncshell to "
|
||||
+ (pair.Key.UserData.AliasOrUID) + Environment.NewLine + "WARNING: This action is irreversible and will close screen.");
|
||||
ImGui.SameLine();
|
||||
|
||||
using (ImRaii.PushColor(ImGuiCol.Text, pair.Value != null && pair.Value.Value.IsModerator() ? UIColors.Get("DimRed") : UIColors.Get("PairBlue")))
|
||||
{
|
||||
if (_uiSharedService.IconButton(FontAwesomeIcon.UserShield))
|
||||
{
|
||||
@@ -194,11 +280,14 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase
|
||||
|
||||
_ = _apiController.GroupSetUserInfo(new GroupPairUserInfoDto(GroupFullInfo.Group, pair.Key.UserData, userInfo));
|
||||
}
|
||||
UiSharedService.AttachToolTip(pair.Value != null && pair.Value.Value.IsModerator() ? "Demod user" : "Mod user");
|
||||
ImGui.SameLine();
|
||||
}
|
||||
UiSharedService.AttachToolTip(pair.Value != null && pair.Value.Value.IsModerator() ? "Demod user" : "Mod user");
|
||||
ImGui.SameLine();
|
||||
}
|
||||
|
||||
if (_isOwner || (pair.Value == null || (pair.Value != null && !pair.Value.Value.IsModerator())))
|
||||
if (pair.Value == null || pair.Value != null && !pair.Value.Value.IsModerator() && !isUserOwner)
|
||||
{
|
||||
using (ImRaii.PushColor(ImGuiCol.Text, pair.Value != null && pair.Value.Value.IsPinned() ? UIColors.Get("DimRed") : UIColors.Get("PairBlue")))
|
||||
{
|
||||
if (_uiSharedService.IconButton(FontAwesomeIcon.Thumbtack))
|
||||
{
|
||||
@@ -208,9 +297,12 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase
|
||||
|
||||
_ = _apiController.GroupSetUserInfo(new GroupPairUserInfoDto(GroupFullInfo.Group, pair.Key.UserData, userInfo));
|
||||
}
|
||||
UiSharedService.AttachToolTip(pair.Value != null && pair.Value.Value.IsPinned() ? "Unpin user" : "Pin user");
|
||||
ImGui.SameLine();
|
||||
}
|
||||
UiSharedService.AttachToolTip(pair.Value != null && pair.Value.Value.IsPinned() ? "Unpin user" : "Pin user");
|
||||
ImGui.SameLine();
|
||||
|
||||
using (ImRaii.PushColor(ImGuiCol.Text, UIColors.Get("DimRed")))
|
||||
{
|
||||
using (ImRaii.Disabled(!UiSharedService.CtrlPressed()))
|
||||
{
|
||||
if (_uiSharedService.IconButton(FontAwesomeIcon.Trash))
|
||||
@@ -218,10 +310,13 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase
|
||||
_ = _apiController.GroupRemoveUser(new GroupPairDto(GroupFullInfo.Group, pair.Key.UserData));
|
||||
}
|
||||
}
|
||||
UiSharedService.AttachToolTip("Remove user from Syncshell"
|
||||
+ UiSharedService.TooltipSeparator + "Hold CTRL to enable this button");
|
||||
}
|
||||
UiSharedService.AttachToolTip("Remove user from Syncshell"
|
||||
+ UiSharedService.TooltipSeparator + "Hold CTRL to enable this button");
|
||||
ImGui.SameLine();
|
||||
|
||||
ImGui.SameLine();
|
||||
using (ImRaii.PushColor(ImGuiCol.Text, UIColors.Get("DimRed")))
|
||||
{
|
||||
using (ImRaii.Disabled(!UiSharedService.CtrlPressed()))
|
||||
{
|
||||
if (_uiSharedService.IconButton(FontAwesomeIcon.Ban))
|
||||
@@ -229,224 +324,190 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase
|
||||
Mediator.Publish(new OpenBanUserPopupMessage(pair.Key, GroupFullInfo));
|
||||
}
|
||||
}
|
||||
UiSharedService.AttachToolTip("Ban user from Syncshell"
|
||||
+ UiSharedService.TooltipSeparator + "Hold CTRL to enable this button");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
userNode.Dispose();
|
||||
var clearNode = ImRaii.TreeNode("Mass Cleanup");
|
||||
if (clearNode)
|
||||
{
|
||||
using (ImRaii.Disabled(!UiSharedService.CtrlPressed()))
|
||||
{
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Broom, "Clear Syncshell"))
|
||||
{
|
||||
_ = _apiController.GroupClear(new(GroupFullInfo.Group));
|
||||
}
|
||||
}
|
||||
UiSharedService.AttachToolTip("This will remove all non-pinned, non-moderator users from the Syncshell."
|
||||
+ UiSharedService.TooltipSeparator + "Hold CTRL to enable this button");
|
||||
|
||||
ImGuiHelpers.ScaledDummy(2f);
|
||||
ImGui.Separator();
|
||||
ImGuiHelpers.ScaledDummy(2f);
|
||||
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Unlink, "Check for Inactive Users"))
|
||||
{
|
||||
_pruneTestTask = _apiController.GroupPrune(new(GroupFullInfo.Group), _pruneDays, execute: false);
|
||||
_pruneTask = null;
|
||||
}
|
||||
UiSharedService.AttachToolTip($"This will start the prune process for this Syncshell of inactive Lightless users that have not logged in in the past {_pruneDays} days."
|
||||
+ Environment.NewLine + "You will be able to review the amount of inactive users before executing the prune."
|
||||
+ UiSharedService.TooltipSeparator + "Note: this check excludes pinned users and moderators of this Syncshell.");
|
||||
ImGui.SameLine();
|
||||
ImGui.SetNextItemWidth(150);
|
||||
_uiSharedService.DrawCombo("Days of inactivity", [7, 14, 30, 90], (count) =>
|
||||
{
|
||||
return count + " days";
|
||||
},
|
||||
(selected) =>
|
||||
{
|
||||
_pruneDays = selected;
|
||||
_pruneTestTask = null;
|
||||
_pruneTask = null;
|
||||
},
|
||||
_pruneDays);
|
||||
|
||||
if (_pruneTestTask != null)
|
||||
{
|
||||
if (!_pruneTestTask.IsCompleted)
|
||||
{
|
||||
UiSharedService.ColorTextWrapped("Calculating inactive users...", ImGuiColors.DalamudYellow);
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui.AlignTextToFramePadding();
|
||||
UiSharedService.TextWrapped($"Found {_pruneTestTask.Result} user(s) that have not logged into Lightless in the past {_pruneDays} days.");
|
||||
if (_pruneTestTask.Result > 0)
|
||||
{
|
||||
using (ImRaii.Disabled(!UiSharedService.CtrlPressed()))
|
||||
{
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Broom, "Prune Inactive Users"))
|
||||
{
|
||||
_pruneTask = _apiController.GroupPrune(new(GroupFullInfo.Group), _pruneDays, execute: true);
|
||||
_pruneTestTask = null;
|
||||
}
|
||||
}
|
||||
UiSharedService.AttachToolTip($"Pruning will remove {_pruneTestTask?.Result ?? 0} inactive user(s)."
|
||||
UiSharedService.AttachToolTip("Ban user from Syncshell"
|
||||
+ UiSharedService.TooltipSeparator + "Hold CTRL to enable this button");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_pruneTask != null)
|
||||
}
|
||||
_uiSharedService.ColoredSeparator(UIColors.Get("LightlessPurple"), 1.5f);
|
||||
ImGui.TreePop();
|
||||
}
|
||||
ImGui.Separator();
|
||||
|
||||
if (_uiSharedService.MediumTreeNode("Mass Cleanup", UIColors.Get("LightlessPurple")))
|
||||
{
|
||||
using (ImRaii.Disabled(!UiSharedService.CtrlPressed()))
|
||||
{
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Broom, "Clear Syncshell"))
|
||||
{
|
||||
if (!_pruneTask.IsCompleted)
|
||||
{
|
||||
UiSharedService.ColorTextWrapped("Pruning Syncshell...", ImGuiColors.DalamudYellow);
|
||||
}
|
||||
else
|
||||
{
|
||||
UiSharedService.TextWrapped($"Syncshell was pruned and {_pruneTask.Result} inactive user(s) have been removed.");
|
||||
}
|
||||
_ = _apiController.GroupClear(new(GroupFullInfo.Group));
|
||||
}
|
||||
}
|
||||
clearNode.Dispose();
|
||||
UiSharedService.AttachToolTip("This will remove all non-pinned, non-moderator users from the Syncshell."
|
||||
+ UiSharedService.TooltipSeparator + "Hold CTRL to enable this button");
|
||||
|
||||
var banNode = ImRaii.TreeNode("User Bans");
|
||||
if (banNode)
|
||||
ImGuiHelpers.ScaledDummy(2f);
|
||||
ImGui.Separator();
|
||||
ImGuiHelpers.ScaledDummy(2f);
|
||||
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Unlink, "Check for Inactive Users"))
|
||||
{
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Retweet, "Refresh Banlist from Server"))
|
||||
_pruneTestTask = _apiController.GroupPrune(new(GroupFullInfo.Group), _pruneDays, execute: false);
|
||||
_pruneTask = null;
|
||||
}
|
||||
UiSharedService.AttachToolTip($"This will start the prune process for this Syncshell of inactive Lightless users that have not logged in in the past {_pruneDays} day(s)."
|
||||
+ Environment.NewLine + "You will be able to review the amount of inactive users before executing the prune."
|
||||
+ UiSharedService.TooltipSeparator + "Note: this check excludes pinned users and moderators of this Syncshell.");
|
||||
ImGui.SameLine();
|
||||
ImGui.SetNextItemWidth(150);
|
||||
_uiSharedService.DrawCombo("Day(s) of inactivity", [1, 3, 7, 14, 30, 90], (count) =>
|
||||
{
|
||||
return count + " day(s)";
|
||||
},
|
||||
(selected) =>
|
||||
{
|
||||
_pruneDays = selected;
|
||||
_pruneTestTask = null;
|
||||
_pruneTask = null;
|
||||
},
|
||||
_pruneDays);
|
||||
|
||||
if (_pruneTestTask != null)
|
||||
{
|
||||
if (!_pruneTestTask.IsCompleted)
|
||||
{
|
||||
_bannedUsers = _apiController.GroupGetBannedUsers(new GroupDto(GroupFullInfo.Group)).Result;
|
||||
UiSharedService.ColorTextWrapped("Calculating inactive users...", ImGuiColors.DalamudYellow);
|
||||
}
|
||||
|
||||
if (ImGui.BeginTable("bannedusertable" + GroupFullInfo.GID, 6, ImGuiTableFlags.RowBg | ImGuiTableFlags.SizingStretchProp | ImGuiTableFlags.ScrollY))
|
||||
else
|
||||
{
|
||||
ImGui.TableSetupColumn("UID", ImGuiTableColumnFlags.None, 1);
|
||||
ImGui.TableSetupColumn("Alias", ImGuiTableColumnFlags.None, 1);
|
||||
ImGui.TableSetupColumn("By", ImGuiTableColumnFlags.None, 1);
|
||||
ImGui.TableSetupColumn("Date", ImGuiTableColumnFlags.None, 2);
|
||||
ImGui.TableSetupColumn("Reason", ImGuiTableColumnFlags.None, 3);
|
||||
ImGui.TableSetupColumn("Actions", ImGuiTableColumnFlags.None, 1);
|
||||
|
||||
ImGui.TableHeadersRow();
|
||||
|
||||
foreach (var bannedUser in _bannedUsers.ToList())
|
||||
ImGui.AlignTextToFramePadding();
|
||||
UiSharedService.TextWrapped($"Found {_pruneTestTask.Result} user(s) that have not logged into Lightless in the past {_pruneDays} day(s).");
|
||||
if (_pruneTestTask.Result > 0)
|
||||
{
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.TextUnformatted(bannedUser.UID);
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.TextUnformatted(bannedUser.UserAlias ?? string.Empty);
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.TextUnformatted(bannedUser.BannedBy);
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.TextUnformatted(bannedUser.BannedOn.ToLocalTime().ToString(CultureInfo.CurrentCulture));
|
||||
ImGui.TableNextColumn();
|
||||
UiSharedService.TextWrapped(bannedUser.Reason);
|
||||
ImGui.TableNextColumn();
|
||||
using var _ = ImRaii.PushId(bannedUser.UID);
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Check, "Unban"))
|
||||
using (ImRaii.Disabled(!UiSharedService.CtrlPressed()))
|
||||
{
|
||||
_apiController.GroupUnbanUser(bannedUser);
|
||||
_bannedUsers.RemoveAll(b => string.Equals(b.UID, bannedUser.UID, StringComparison.Ordinal));
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Broom, "Prune Inactive Users"))
|
||||
{
|
||||
_pruneTask = _apiController.GroupPrune(new(GroupFullInfo.Group), _pruneDays, execute: true);
|
||||
_pruneTestTask = null;
|
||||
}
|
||||
}
|
||||
UiSharedService.AttachToolTip($"Pruning will remove {_pruneTestTask?.Result ?? 0} inactive user(s)."
|
||||
+ UiSharedService.TooltipSeparator + "Hold CTRL to enable this button");
|
||||
}
|
||||
|
||||
ImGui.EndTable();
|
||||
}
|
||||
}
|
||||
banNode.Dispose();
|
||||
}
|
||||
mgmtTab.Dispose();
|
||||
|
||||
var permissionTab = ImRaii.TabItem("Permissions");
|
||||
if (permissionTab)
|
||||
{
|
||||
bool isDisableAnimations = perm.IsPreferDisableAnimations();
|
||||
bool isDisableSounds = perm.IsPreferDisableSounds();
|
||||
bool isDisableVfx = perm.IsPreferDisableVFX();
|
||||
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.Text("Suggest Sound Sync");
|
||||
_uiSharedService.BooleanToColoredIcon(!isDisableSounds);
|
||||
ImGui.SameLine(230);
|
||||
if (_uiSharedService.IconTextButton(isDisableSounds ? FontAwesomeIcon.VolumeUp : FontAwesomeIcon.VolumeMute,
|
||||
isDisableSounds ? "Suggest to enable sound sync" : "Suggest to disable sound sync"))
|
||||
if (_pruneTask != null)
|
||||
{
|
||||
perm.SetPreferDisableSounds(!perm.IsPreferDisableSounds());
|
||||
_ = _apiController.GroupChangeGroupPermissionState(new(GroupFullInfo.Group, perm));
|
||||
}
|
||||
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.Text("Suggest Animation Sync");
|
||||
_uiSharedService.BooleanToColoredIcon(!isDisableAnimations);
|
||||
ImGui.SameLine(230);
|
||||
if (_uiSharedService.IconTextButton(isDisableAnimations ? FontAwesomeIcon.Running : FontAwesomeIcon.Stop,
|
||||
isDisableAnimations ? "Suggest to enable animation sync" : "Suggest to disable animation sync"))
|
||||
{
|
||||
perm.SetPreferDisableAnimations(!perm.IsPreferDisableAnimations());
|
||||
_ = _apiController.GroupChangeGroupPermissionState(new(GroupFullInfo.Group, perm));
|
||||
}
|
||||
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.Text("Suggest VFX Sync");
|
||||
_uiSharedService.BooleanToColoredIcon(!isDisableVfx);
|
||||
ImGui.SameLine(230);
|
||||
if (_uiSharedService.IconTextButton(isDisableVfx ? FontAwesomeIcon.Sun : FontAwesomeIcon.Circle,
|
||||
isDisableVfx ? "Suggest to enable vfx sync" : "Suggest to disable vfx sync"))
|
||||
{
|
||||
perm.SetPreferDisableVFX(!perm.IsPreferDisableVFX());
|
||||
_ = _apiController.GroupChangeGroupPermissionState(new(GroupFullInfo.Group, perm));
|
||||
}
|
||||
|
||||
UiSharedService.TextWrapped("Note: those suggested permissions will be shown to users on joining the Syncshell.");
|
||||
}
|
||||
permissionTab.Dispose();
|
||||
|
||||
if (_isOwner)
|
||||
{
|
||||
var ownerTab = ImRaii.TabItem("Owner Settings");
|
||||
if (ownerTab)
|
||||
{
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.TextUnformatted("New Password");
|
||||
var availableWidth = ImGui.GetWindowContentRegionMax().X - ImGui.GetWindowContentRegionMin().X;
|
||||
var buttonSize = _uiSharedService.GetIconTextButtonSize(FontAwesomeIcon.Passport, "Change Password");
|
||||
var textSize = ImGui.CalcTextSize("New Password").X;
|
||||
var spacing = ImGui.GetStyle().ItemSpacing.X;
|
||||
|
||||
ImGui.SameLine();
|
||||
ImGui.SetNextItemWidth(availableWidth - buttonSize - textSize - spacing * 2);
|
||||
ImGui.InputTextWithHint("##changepw", "Min 10 characters", ref _newPassword, 50);
|
||||
ImGui.SameLine();
|
||||
using (ImRaii.Disabled(_newPassword.Length < 10))
|
||||
if (!_pruneTask.IsCompleted)
|
||||
{
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Passport, "Change Password"))
|
||||
UiSharedService.ColorTextWrapped("Pruning Syncshell...", ImGuiColors.DalamudYellow);
|
||||
}
|
||||
else
|
||||
{
|
||||
UiSharedService.TextWrapped($"Syncshell was pruned and {_pruneTask.Result} inactive user(s) have been removed.");
|
||||
}
|
||||
}
|
||||
_uiSharedService.ColoredSeparator(UIColors.Get("LightlessPurple"), 1.5f);
|
||||
ImGui.TreePop();
|
||||
}
|
||||
ImGui.Separator();
|
||||
|
||||
if (_uiSharedService.MediumTreeNode("User Bans", UIColors.Get("LightlessPurple")))
|
||||
{
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Retweet, "Refresh Banlist from Server"))
|
||||
{
|
||||
_bannedUsers = _apiController.GroupGetBannedUsers(new GroupDto(GroupFullInfo.Group)).Result;
|
||||
}
|
||||
var tableFlags = ImGuiTableFlags.RowBg | ImGuiTableFlags.SizingStretchProp;
|
||||
if (_bannedUsers.Count > 10) tableFlags |= ImGuiTableFlags.ScrollY;
|
||||
if (ImGui.BeginTable("bannedusertable" + GroupFullInfo.GID, 6, tableFlags))
|
||||
{
|
||||
ImGui.TableSetupColumn("UID", ImGuiTableColumnFlags.None, 1);
|
||||
ImGui.TableSetupColumn("Alias", ImGuiTableColumnFlags.None, 1);
|
||||
ImGui.TableSetupColumn("By", ImGuiTableColumnFlags.None, 1);
|
||||
ImGui.TableSetupColumn("Date", ImGuiTableColumnFlags.None, 2);
|
||||
ImGui.TableSetupColumn("Reason", ImGuiTableColumnFlags.None, 3);
|
||||
ImGui.TableSetupColumn("Actions", ImGuiTableColumnFlags.None, 1);
|
||||
|
||||
ImGui.TableHeadersRow();
|
||||
|
||||
foreach (var bannedUser in _bannedUsers.ToList())
|
||||
{
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.TextUnformatted(bannedUser.UID);
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.TextUnformatted(bannedUser.UserAlias ?? string.Empty);
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.TextUnformatted(bannedUser.BannedBy);
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.TextUnformatted(bannedUser.BannedOn.ToLocalTime().ToString(CultureInfo.CurrentCulture));
|
||||
ImGui.TableNextColumn();
|
||||
UiSharedService.TextWrapped(bannedUser.Reason);
|
||||
ImGui.TableNextColumn();
|
||||
using var _ = ImRaii.PushId(bannedUser.UID);
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Check, "Unban"))
|
||||
{
|
||||
_pwChangeSuccess = _apiController.GroupChangePassword(new GroupPasswordDto(GroupFullInfo.Group, _newPassword)).Result;
|
||||
_newPassword = string.Empty;
|
||||
_apiController.GroupUnbanUser(bannedUser);
|
||||
_bannedUsers.RemoveAll(b => string.Equals(b.UID, bannedUser.UID, StringComparison.Ordinal));
|
||||
}
|
||||
}
|
||||
UiSharedService.AttachToolTip("Password requires to be at least 10 characters long. This action is irreversible.");
|
||||
|
||||
if (!_pwChangeSuccess)
|
||||
{
|
||||
UiSharedService.ColorTextWrapped("Failed to change the password. Password requires to be at least 10 characters long.", ImGuiColors.DalamudYellow);
|
||||
}
|
||||
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Delete Syncshell") && UiSharedService.CtrlPressed() && UiSharedService.ShiftPressed())
|
||||
{
|
||||
IsOpen = false;
|
||||
_ = _apiController.GroupDelete(new(GroupFullInfo.Group));
|
||||
}
|
||||
UiSharedService.AttachToolTip("Hold CTRL and Shift and click to delete this Syncshell." + Environment.NewLine + "WARNING: this action is irreversible.");
|
||||
ImGui.EndTable();
|
||||
}
|
||||
_uiSharedService.ColoredSeparator(UIColors.Get("LightlessPurple"), 1.5f);
|
||||
ImGui.TreePop();
|
||||
}
|
||||
ImGui.Separator();
|
||||
}
|
||||
mgmtTab.Dispose();
|
||||
|
||||
}
|
||||
|
||||
private void DrawInvites(GroupPermissions perm)
|
||||
{
|
||||
var inviteTab = ImRaii.TabItem("Invites");
|
||||
if (inviteTab)
|
||||
{
|
||||
bool isInvitesDisabled = perm.IsDisableInvites();
|
||||
|
||||
if (_uiSharedService.IconTextButton(isInvitesDisabled ? FontAwesomeIcon.Unlock : FontAwesomeIcon.Lock,
|
||||
isInvitesDisabled ? "Unlock Syncshell" : "Lock Syncshell"))
|
||||
{
|
||||
perm.SetDisableInvites(!isInvitesDisabled);
|
||||
_ = _apiController.GroupChangeGroupPermissionState(new(GroupFullInfo.Group, perm));
|
||||
}
|
||||
|
||||
ImGuiHelpers.ScaledDummy(2f);
|
||||
|
||||
UiSharedService.TextWrapped("One-time invites work as single-use passwords. Use those if you do not want to distribute your Syncshell password.");
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Envelope, "Single one-time invite"))
|
||||
{
|
||||
ImGui.SetClipboardText(_apiController.GroupCreateTempInvite(new(GroupFullInfo.Group), 1).Result.FirstOrDefault() ?? string.Empty);
|
||||
}
|
||||
UiSharedService.AttachToolTip("Creates a single-use password for joining the syncshell which is valid for 24h and copies it to the clipboard.");
|
||||
ImGui.InputInt("##amountofinvites", ref _multiInvites);
|
||||
ImGui.SameLine();
|
||||
using (ImRaii.Disabled(_multiInvites <= 1 || _multiInvites > 100))
|
||||
{
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Envelope, "Generate " + _multiInvites + " one-time invites"))
|
||||
{
|
||||
_oneTimeInvites.AddRange(_apiController.GroupCreateTempInvite(new(GroupFullInfo.Group), _multiInvites).Result);
|
||||
}
|
||||
}
|
||||
|
||||
if (_oneTimeInvites.Any())
|
||||
{
|
||||
var invites = string.Join(Environment.NewLine, _oneTimeInvites);
|
||||
ImGui.InputTextMultiline("Generated Multi Invites", ref invites, 5000, new(0, 0), ImGuiInputTextFlags.ReadOnly);
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Copy, "Copy Invites to clipboard"))
|
||||
{
|
||||
ImGui.SetClipboardText(invites);
|
||||
}
|
||||
ownerTab.Dispose();
|
||||
}
|
||||
}
|
||||
inviteTab.Dispose();
|
||||
}
|
||||
|
||||
public override void OnClose()
|
||||
|
||||
298
LightlessSync/UI/SyncshellFinderUI.cs
Normal file
298
LightlessSync/UI/SyncshellFinderUI.cs
Normal file
@@ -0,0 +1,298 @@
|
||||
using Dalamud.Bindings.ImGui;
|
||||
using Dalamud.Interface;
|
||||
using Dalamud.Interface.Colors;
|
||||
using Dalamud.Interface.Utility;
|
||||
using Dalamud.Interface.Utility.Raii;
|
||||
using LightlessSync.API.Data.Enum;
|
||||
using LightlessSync.API.Dto;
|
||||
using LightlessSync.API.Dto.Group;
|
||||
using LightlessSync.LightlessConfiguration;
|
||||
using LightlessSync.Services;
|
||||
using LightlessSync.Services.Mediator;
|
||||
using LightlessSync.Utils;
|
||||
using LightlessSync.WebAPI;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using LightlessSync.API.Data.Extensions;
|
||||
using System.Numerics;
|
||||
|
||||
namespace LightlessSync.UI;
|
||||
|
||||
public class SyncshellFinderUI : WindowMediatorSubscriberBase
|
||||
{
|
||||
private readonly ApiController _apiController;
|
||||
private readonly LightlessConfigService _configService;
|
||||
private readonly BroadcastService _broadcastService;
|
||||
private readonly UiSharedService _uiSharedService;
|
||||
private readonly BroadcastScannerService _broadcastScannerService;
|
||||
|
||||
private readonly List<GroupJoinDto> _nearbySyncshells = new();
|
||||
private int _selectedNearbyIndex = -1;
|
||||
|
||||
private GroupJoinDto? _joinDto;
|
||||
private GroupJoinInfoDto? _joinInfo;
|
||||
private DefaultPermissionsDto _ownPermissions = null!;
|
||||
|
||||
public SyncshellFinderUI(
|
||||
ILogger<SyncshellFinderUI> logger,
|
||||
LightlessMediator mediator,
|
||||
PerformanceCollectorService performanceCollectorService,
|
||||
BroadcastService broadcastService,
|
||||
LightlessConfigService configService,
|
||||
UiSharedService uiShared,
|
||||
ApiController apiController,
|
||||
BroadcastScannerService broadcastScannerService
|
||||
) : base(logger, mediator, "Shellfinder###LightlessSyncshellFinderUI", performanceCollectorService)
|
||||
{
|
||||
_broadcastService = broadcastService;
|
||||
_uiSharedService = uiShared;
|
||||
_configService = configService;
|
||||
_apiController = apiController;
|
||||
_broadcastScannerService = broadcastScannerService;
|
||||
|
||||
IsOpen = false;
|
||||
SizeConstraints = new()
|
||||
{
|
||||
MinimumSize = new(600, 400),
|
||||
MaximumSize = new(600, 550)
|
||||
};
|
||||
|
||||
Mediator.Subscribe<SyncshellBroadcastsUpdatedMessage>(this, async _ => await RefreshSyncshellsAsync());
|
||||
Mediator.Subscribe<BroadcastStatusChangedMessage>(this, async _ => await RefreshSyncshellsAsync());
|
||||
}
|
||||
|
||||
public override async void OnOpen()
|
||||
{
|
||||
_ownPermissions = _apiController.DefaultPermissions.DeepClone()!;
|
||||
await RefreshSyncshellsAsync();
|
||||
}
|
||||
|
||||
protected override void DrawInternal()
|
||||
{
|
||||
_uiSharedService.MediumText("Nearby Syncshells", UIColors.Get("PairBlue"));
|
||||
_uiSharedService.ColoredSeparator(UIColors.Get("PairBlue"));
|
||||
|
||||
if (_nearbySyncshells.Count == 0)
|
||||
{
|
||||
ImGui.TextColored(ImGuiColors.DalamudGrey, "No nearby syncshells are being broadcasted.");
|
||||
|
||||
if (!_broadcastService.IsBroadcasting)
|
||||
{
|
||||
|
||||
_uiSharedService.ColoredSeparator(UIColors.Get("LightlessYellow"));
|
||||
|
||||
ImGui.TextColored(UIColors.Get("LightlessYellow"), "Lightfinder is currently disabled, to locate nearby syncshells, Lightfinder must be active.");
|
||||
ImGuiHelpers.ScaledDummy(0.5f);
|
||||
|
||||
ImGui.PushStyleVar(ImGuiStyleVar.FrameRounding, 10.0f);
|
||||
ImGui.PushStyleColor(ImGuiCol.Button, UIColors.Get("LightlessYellow2"));
|
||||
|
||||
if (ImGui.Button("Open Lightfinder", new Vector2(200 * ImGuiHelpers.GlobalScale, 0)))
|
||||
{
|
||||
Mediator.Publish(new UiToggleMessage(typeof(BroadcastUI)));
|
||||
}
|
||||
|
||||
ImGui.PopStyleColor();
|
||||
ImGui.PopStyleVar();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ImGui.BeginTable("##NearbySyncshellsTable", 3, ImGuiTableFlags.Borders | ImGuiTableFlags.RowBg))
|
||||
{
|
||||
ImGui.TableSetupColumn("Alias", ImGuiTableColumnFlags.WidthStretch);
|
||||
ImGui.TableSetupColumn("GID", ImGuiTableColumnFlags.WidthStretch);
|
||||
ImGui.TableSetupColumn("Join", ImGuiTableColumnFlags.WidthFixed, 80f * ImGuiHelpers.GlobalScale);
|
||||
ImGui.TableHeadersRow();
|
||||
|
||||
for (int i = 0; i < _nearbySyncshells.Count; i++)
|
||||
{
|
||||
var shell = _nearbySyncshells[i];
|
||||
|
||||
ImGui.TableNextRow();
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.TextUnformatted(shell.Group.Alias ?? "(No Alias)");
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.TextUnformatted(shell.Group.GID);
|
||||
ImGui.TableNextColumn();
|
||||
|
||||
var label = $"Join##{shell.Group.GID}";
|
||||
ImGui.PushStyleColor(ImGuiCol.Button, UIColors.Get("LightlessGreen"));
|
||||
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, UIColors.Get("LightlessGreen").WithAlpha(0.85f));
|
||||
ImGui.PushStyleColor(ImGuiCol.ButtonActive, UIColors.Get("LightlessGreen").WithAlpha(0.75f));
|
||||
|
||||
if (ImGui.Button(label))
|
||||
{
|
||||
_logger.LogInformation($"Join requested for Syncshell {shell.Group.GID} ({shell.Group.Alias})");
|
||||
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var info = await _apiController.GroupJoinHashed(new GroupJoinHashedDto(
|
||||
shell.Group,
|
||||
shell.Password,
|
||||
shell.GroupUserPreferredPermissions
|
||||
)).ConfigureAwait(false);
|
||||
|
||||
if (info != null && info.Success)
|
||||
{
|
||||
_joinDto = new GroupJoinDto(shell.Group, shell.Password, shell.GroupUserPreferredPermissions);
|
||||
_joinInfo = info;
|
||||
_ownPermissions = _apiController.DefaultPermissions.DeepClone()!;
|
||||
|
||||
_logger.LogInformation($"Fetched join info for {shell.Group.GID}");
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning($"Failed to join {shell.Group.GID}: info was null or unsuccessful");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"Join failed for {shell.Group.GID}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
ImGui.PopStyleColor(3);
|
||||
}
|
||||
|
||||
ImGui.EndTable();
|
||||
}
|
||||
|
||||
if (_joinDto != null && _joinInfo != null && _joinInfo.Success)
|
||||
DrawConfirmation();
|
||||
}
|
||||
|
||||
private void DrawConfirmation()
|
||||
{
|
||||
ImGui.Separator();
|
||||
ImGui.TextUnformatted($"Join Syncshell: {_joinDto.Group.AliasOrGID} by {_joinInfo.OwnerAliasOrUID}");
|
||||
ImGuiHelpers.ScaledDummy(2f);
|
||||
ImGui.TextUnformatted("Suggested Syncshell Permissions:");
|
||||
|
||||
DrawPermissionRow("Sounds", _joinInfo.GroupPermissions.IsPreferDisableSounds(), _ownPermissions.DisableGroupSounds, v => _ownPermissions.DisableGroupSounds = v);
|
||||
DrawPermissionRow("Animations", _joinInfo.GroupPermissions.IsPreferDisableAnimations(), _ownPermissions.DisableGroupAnimations, v => _ownPermissions.DisableGroupAnimations = v);
|
||||
DrawPermissionRow("VFX", _joinInfo.GroupPermissions.IsPreferDisableVFX(), _ownPermissions.DisableGroupVFX, v => _ownPermissions.DisableGroupVFX = v);
|
||||
|
||||
ImGui.NewLine();
|
||||
ImGui.NewLine();
|
||||
|
||||
if (_uiSharedService.IconTextButton(Dalamud.Interface.FontAwesomeIcon.Plus, $"Finalize and join {_joinDto.Group.AliasOrGID}"))
|
||||
{
|
||||
var finalPermissions = GroupUserPreferredPermissions.NoneSet;
|
||||
finalPermissions.SetDisableSounds(_ownPermissions.DisableGroupSounds);
|
||||
finalPermissions.SetDisableAnimations(_ownPermissions.DisableGroupAnimations);
|
||||
finalPermissions.SetDisableVFX(_ownPermissions.DisableGroupVFX);
|
||||
|
||||
_ = _apiController.GroupJoinFinalize(new GroupJoinDto(_joinDto.Group, _joinDto.Password, finalPermissions));
|
||||
_joinDto = null;
|
||||
_joinInfo = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawPermissionRow(string label, bool suggested, bool current, Action<bool> apply)
|
||||
{
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.TextUnformatted($"- {label}");
|
||||
|
||||
ImGui.SameLine(150 * ImGuiHelpers.GlobalScale);
|
||||
ImGui.TextUnformatted("Current:");
|
||||
ImGui.SameLine();
|
||||
_uiSharedService.BooleanToColoredIcon(!current);
|
||||
|
||||
ImGui.SameLine(300 * ImGuiHelpers.GlobalScale);
|
||||
ImGui.TextUnformatted("Suggested:");
|
||||
ImGui.SameLine();
|
||||
_uiSharedService.BooleanToColoredIcon(!suggested);
|
||||
|
||||
ImGui.SameLine(450 * ImGuiHelpers.GlobalScale);
|
||||
using var id = ImRaii.PushId(label);
|
||||
if (current != suggested)
|
||||
{
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.ArrowRight, "Apply"))
|
||||
apply(suggested);
|
||||
}
|
||||
|
||||
ImGui.NewLine();
|
||||
}
|
||||
|
||||
private async Task RefreshSyncshellsAsync()
|
||||
{
|
||||
var syncshellBroadcasts = _broadcastScannerService.GetActiveSyncshellBroadcasts();
|
||||
|
||||
if (syncshellBroadcasts.Count == 0)
|
||||
{
|
||||
ClearSyncshells();
|
||||
return;
|
||||
}
|
||||
|
||||
List<GroupJoinDto> updatedList;
|
||||
try
|
||||
{
|
||||
var groups = await _apiController.GetBroadcastedGroups(syncshellBroadcasts);
|
||||
updatedList = groups?.ToList() ?? new();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to refresh broadcasted syncshells.");
|
||||
return;
|
||||
}
|
||||
|
||||
var currentGids = _nearbySyncshells.Select(s => s.Group.GID).ToHashSet();
|
||||
var newGids = updatedList.Select(s => s.Group.GID).ToHashSet();
|
||||
|
||||
if (currentGids.SetEquals(newGids))
|
||||
return;
|
||||
|
||||
var previousGid = GetSelectedGid();
|
||||
|
||||
_nearbySyncshells.Clear();
|
||||
_nearbySyncshells.AddRange(updatedList);
|
||||
|
||||
if (previousGid != null)
|
||||
{
|
||||
var newIndex = _nearbySyncshells.FindIndex(s => s.Group.GID == previousGid);
|
||||
if (newIndex >= 0)
|
||||
{
|
||||
_selectedNearbyIndex = newIndex;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ClearSelection();
|
||||
}
|
||||
|
||||
private void ClearSyncshells()
|
||||
{
|
||||
if (_nearbySyncshells.Count == 0)
|
||||
return;
|
||||
|
||||
_nearbySyncshells.Clear();
|
||||
ClearSelection();
|
||||
}
|
||||
|
||||
private void ClearSelection()
|
||||
{
|
||||
_selectedNearbyIndex = -1;
|
||||
_joinDto = null;
|
||||
_joinInfo = null;
|
||||
}
|
||||
|
||||
private string? GetSelectedGid()
|
||||
{
|
||||
if (_selectedNearbyIndex < 0 || _selectedNearbyIndex >= _nearbySyncshells.Count)
|
||||
return null;
|
||||
|
||||
return _nearbySyncshells[_selectedNearbyIndex].Group.GID;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public class TopTabMenu
|
||||
None,
|
||||
Individual,
|
||||
Syncshell,
|
||||
Filter,
|
||||
Lightfinder,
|
||||
UserConfig
|
||||
}
|
||||
|
||||
@@ -60,11 +60,6 @@ public class TopTabMenu
|
||||
{
|
||||
get => _selectedTab; set
|
||||
{
|
||||
if (_selectedTab == SelectedTab.Filter && value != SelectedTab.Filter)
|
||||
{
|
||||
Filter = string.Empty;
|
||||
}
|
||||
|
||||
_selectedTab = value;
|
||||
}
|
||||
}
|
||||
@@ -76,7 +71,7 @@ public class TopTabMenu
|
||||
var buttonY = _uiSharedService.GetIconButtonSize(FontAwesomeIcon.Pause).Y;
|
||||
var buttonSize = new Vector2(buttonX, buttonY);
|
||||
var drawList = ImGui.GetWindowDrawList();
|
||||
var underlineColor = ImGui.GetColorU32(ImGuiCol.Separator);
|
||||
var underlineColor = ImGui.GetColorU32(UIColors.Get("LightlessPurpleActive")); // ImGui.GetColorU32(ImGuiCol.Separator);
|
||||
var btncolor = ImRaii.PushColor(ImGuiCol.Button, ImGui.ColorConvertFloat4ToU32(new(0, 0, 0, 0)));
|
||||
|
||||
ImGuiHelpers.ScaledDummy(spacing.Y / 2f);
|
||||
@@ -117,19 +112,19 @@ public class TopTabMenu
|
||||
using (ImRaii.PushFont(UiBuilder.IconFont))
|
||||
{
|
||||
var x = ImGui.GetCursorScreenPos();
|
||||
if (ImGui.Button(FontAwesomeIcon.Filter.ToIconString(), buttonSize))
|
||||
if (ImGui.Button(FontAwesomeIcon.Compass.ToIconString(), buttonSize))
|
||||
{
|
||||
TabSelection = TabSelection == SelectedTab.Filter ? SelectedTab.None : SelectedTab.Filter;
|
||||
TabSelection = TabSelection == SelectedTab.Lightfinder ? SelectedTab.None : SelectedTab.Lightfinder;
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
var xAfter = ImGui.GetCursorScreenPos();
|
||||
if (TabSelection == SelectedTab.Filter)
|
||||
if (TabSelection == SelectedTab.Lightfinder)
|
||||
drawList.AddLine(x with { Y = x.Y + buttonSize.Y + spacing.Y },
|
||||
xAfter with { Y = xAfter.Y + buttonSize.Y + spacing.Y, X = xAfter.X - spacing.X },
|
||||
underlineColor, 2);
|
||||
}
|
||||
UiSharedService.AttachToolTip("Filter");
|
||||
UiSharedService.AttachToolTip("Lightfinder");
|
||||
|
||||
ImGui.SameLine();
|
||||
using (ImRaii.PushFont(UiBuilder.IconFont))
|
||||
@@ -164,9 +159,9 @@ public class TopTabMenu
|
||||
DrawSyncshellMenu(availableWidth, spacing.X);
|
||||
DrawGlobalSyncshellButtons(availableWidth, spacing.X);
|
||||
}
|
||||
else if (TabSelection == SelectedTab.Filter)
|
||||
else if (TabSelection == SelectedTab.Lightfinder)
|
||||
{
|
||||
DrawFilter(availableWidth, spacing.X);
|
||||
DrawLightfinderMenu(availableWidth, spacing.X);
|
||||
}
|
||||
else if (TabSelection == SelectedTab.UserConfig)
|
||||
{
|
||||
@@ -175,6 +170,8 @@ public class TopTabMenu
|
||||
|
||||
if (TabSelection != SelectedTab.None) ImGuiHelpers.ScaledDummy(3f);
|
||||
ImGui.Separator();
|
||||
|
||||
DrawFilter(availableWidth, spacing.X);
|
||||
}
|
||||
|
||||
private void DrawAddPair(float availableXWidth, float spacingX)
|
||||
@@ -483,6 +480,23 @@ public class TopTabMenu
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawLightfinderMenu(float availableWidth, float spacingX)
|
||||
{
|
||||
var buttonX = (availableWidth - (spacingX)) / 2f;
|
||||
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.PersonCirclePlus, "Lightfinder", buttonX, center: true))
|
||||
{
|
||||
_lightlessMediator.Publish(new UiToggleMessage(typeof(BroadcastUI)));
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Globe, "Syncshell Finder", buttonX, center: true))
|
||||
{
|
||||
_lightlessMediator.Publish(new UiToggleMessage(typeof(SyncshellFinderUI)));
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawUserConfig(float availableWidth, float spacingX)
|
||||
{
|
||||
var buttonX = (availableWidth - spacingX) / 2f;
|
||||
|
||||
@@ -1,26 +1,99 @@
|
||||
using System.Globalization;
|
||||
using System.Globalization;
|
||||
using System.Numerics;
|
||||
using LightlessSync.LightlessConfiguration;
|
||||
|
||||
namespace LightlessSync.UI
|
||||
{
|
||||
internal static class UIColors
|
||||
{
|
||||
private static readonly Dictionary<string, string> HexColors = new(StringComparer.OrdinalIgnoreCase)
|
||||
private static readonly Dictionary<string, string> DefaultHexColors = new(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
{ "LightlessPurple", "#ad8af5" },
|
||||
{ "LightlessBlue", "#64c7e8" },
|
||||
{ "PairBlue", "#4e98b1" },
|
||||
{ "DimRed", "#bd0000" },
|
||||
{ "LightlessPurpleActive", "#be9eff" },
|
||||
{ "LightlessPurpleDefault", "#9375d1" },
|
||||
|
||||
{ "ButtonDefault", "#323232" },
|
||||
{ "FullBlack", "#000000" },
|
||||
|
||||
{ "LightlessBlue", "#a6c2ff" },
|
||||
{ "LightlessYellow", "#ffe97a" },
|
||||
{ "LightlessYellow2", "#cfbd63" },
|
||||
{ "LightlessGreen", "#7cd68a" },
|
||||
{ "PairBlue", "#88a2db" },
|
||||
{ "DimRed", "#d44444" },
|
||||
|
||||
{ "LightlessAdminText", "#ffd663" },
|
||||
{ "LightlessAdminGlow", "#b09343" },
|
||||
{ "LightlessModeratorText", "#94ffda" },
|
||||
{ "LightlessModeratorGlow", "#599c84" },
|
||||
};
|
||||
|
||||
private static LightlessConfigService? _configService;
|
||||
|
||||
public static void Initialize(LightlessConfigService configService)
|
||||
{
|
||||
_configService = configService;
|
||||
}
|
||||
|
||||
public static Vector4 Get(string name)
|
||||
{
|
||||
if (!HexColors.TryGetValue(name, out var hex))
|
||||
if (_configService?.Current.CustomUIColors.TryGetValue(name, out var customColorHex) == true)
|
||||
return HexToRgba(customColorHex);
|
||||
|
||||
if (!DefaultHexColors.TryGetValue(name, out var hex))
|
||||
throw new ArgumentException($"Color '{name}' not found in UIColors.");
|
||||
|
||||
return HexToRgba(hex);
|
||||
}
|
||||
|
||||
public static void Set(string name, Vector4 color)
|
||||
{
|
||||
if (!DefaultHexColors.ContainsKey(name))
|
||||
throw new ArgumentException($"Color '{name}' not found in UIColors.");
|
||||
|
||||
if (_configService != null)
|
||||
{
|
||||
_configService.Current.CustomUIColors[name] = RgbaToHex(color);
|
||||
_configService.Save();
|
||||
}
|
||||
}
|
||||
|
||||
public static void Reset(string name)
|
||||
{
|
||||
if (_configService != null)
|
||||
{
|
||||
_configService.Current.CustomUIColors.Remove(name);
|
||||
_configService.Save();
|
||||
}
|
||||
}
|
||||
|
||||
public static void ResetAll()
|
||||
{
|
||||
if (_configService != null)
|
||||
{
|
||||
_configService.Current.CustomUIColors.Clear();
|
||||
_configService.Save();
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector4 GetDefault(string name)
|
||||
{
|
||||
if (!DefaultHexColors.TryGetValue(name, out var hex))
|
||||
throw new ArgumentException($"Color '{name}' not found in UIColors.");
|
||||
|
||||
return HexToRgba(hex);
|
||||
}
|
||||
|
||||
public static bool IsCustom(string name)
|
||||
{
|
||||
return _configService?.Current.CustomUIColors.ContainsKey(name) == true;
|
||||
}
|
||||
|
||||
public static IEnumerable<string> GetColorNames()
|
||||
{
|
||||
return DefaultHexColors.Keys;
|
||||
}
|
||||
|
||||
public static Vector4 HexToRgba(string hexColor)
|
||||
{
|
||||
hexColor = hexColor.TrimStart('#');
|
||||
@@ -30,5 +103,14 @@ namespace LightlessSync.UI
|
||||
int a = hexColor.Length == 8 ? int.Parse(hexColor.Substring(6, 2), NumberStyles.HexNumber) : 255;
|
||||
return new Vector4(r / 255f, g / 255f, b / 255f, a / 255f);
|
||||
}
|
||||
|
||||
public static string RgbaToHex(Vector4 color)
|
||||
{
|
||||
int r = (int)(color.X * 255);
|
||||
int g = (int)(color.Y * 255);
|
||||
int b = (int)(color.Z * 255);
|
||||
int a = (int)(color.W * 255);
|
||||
return $"#{r:X2}{g:X2}{b:X2}{(a != 255 ? a.ToString("X2") : "")}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,6 +114,15 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
||||
SizePx = 35
|
||||
}));
|
||||
});
|
||||
|
||||
MediumFont = _pluginInterface.UiBuilder.FontAtlas.NewDelegateFontHandle(e =>
|
||||
{
|
||||
e.OnPreBuild(tk => tk.AddDalamudAssetFont(Dalamud.DalamudAsset.NotoSansJpMedium, new()
|
||||
{
|
||||
SizePx = 22,
|
||||
}));
|
||||
});
|
||||
|
||||
GameFont = _pluginInterface.UiBuilder.FontAtlas.NewGameFontHandle(new(GameFontFamilyAndSize.Axis12));
|
||||
IconFont = _pluginInterface.UiBuilder.IconFontFixedWidthHandle;
|
||||
}
|
||||
@@ -133,6 +142,8 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
||||
public string PlayerName => _dalamudUtil.GetPlayerName();
|
||||
|
||||
public IFontHandle UidFont { get; init; }
|
||||
public IFontHandle MediumFont { get; init; }
|
||||
|
||||
public Dictionary<ushort, string> WorldData => _dalamudUtil.WorldData.Value;
|
||||
public uint WorldId => _dalamudUtil.GetHomeWorldId();
|
||||
|
||||
@@ -394,7 +405,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
||||
}
|
||||
|
||||
public static Vector4 UploadColor((long, long) data) => data.Item1 == 0 ? ImGuiColors.DalamudGrey :
|
||||
data.Item1 == data.Item2 ? UIColors.Get("LightlessBlue") : ImGuiColors.DalamudYellow;
|
||||
data.Item1 == data.Item2 ? UIColors.Get("LightlessBlue") : UIColors.Get("LightlessYellow");
|
||||
|
||||
public bool ApplyNotesFromClipboard(string notes, bool overwrite)
|
||||
{
|
||||
@@ -434,6 +445,98 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
||||
FontText(text, UidFont, color);
|
||||
}
|
||||
|
||||
public void UnderlinedBigText(
|
||||
string text,
|
||||
Vector4? textColor = null,
|
||||
Vector4? underlineColor = null,
|
||||
float underlineThickness = 2f)
|
||||
{
|
||||
using var font = UidFont.Push();
|
||||
|
||||
var drawList = ImGui.GetWindowDrawList();
|
||||
var textSize = ImGui.CalcTextSize(text);
|
||||
var pos = ImGui.GetCursorScreenPos();
|
||||
var text_color = textColor ?? ImGuiColors.DalamudWhite;
|
||||
var line_color = underlineColor ?? text_color;
|
||||
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, text_color);
|
||||
ImGui.TextUnformatted(text);
|
||||
ImGui.PopStyleColor();
|
||||
|
||||
var lineY = pos.Y + textSize.Y + 2f;
|
||||
drawList.AddLine(
|
||||
new Vector2(pos.X, lineY),
|
||||
new Vector2(pos.X + textSize.X, lineY),
|
||||
ImGui.GetColorU32(line_color),
|
||||
underlineThickness * ImGuiHelpers.GlobalScale
|
||||
);
|
||||
}
|
||||
|
||||
public void ColoredSeparator(Vector4? color = null, float thickness = 1f, float indent = 0f)
|
||||
{
|
||||
var drawList = ImGui.GetWindowDrawList();
|
||||
var min = ImGui.GetCursorScreenPos();
|
||||
var max = new Vector2(min.X + ImGui.GetContentRegionAvail().X, min.Y);
|
||||
|
||||
min.X += indent;
|
||||
max.X -= indent;
|
||||
|
||||
drawList.AddLine(
|
||||
min,
|
||||
new Vector2(max.X, min.Y),
|
||||
ImGui.GetColorU32(color ?? ImGuiColors.DalamudGrey),
|
||||
thickness * ImGuiHelpers.GlobalScale
|
||||
);
|
||||
|
||||
ImGui.Dummy(new Vector2(0, thickness * ImGuiHelpers.GlobalScale));
|
||||
}
|
||||
|
||||
public void RoundedSeparator(Vector4? color = null, float thickness = 2f, float indent = 0f, float rounding = 4f)
|
||||
{
|
||||
float scale = ImGuiHelpers.GlobalScale;
|
||||
|
||||
var drawList = ImGui.GetWindowDrawList();
|
||||
var min = ImGui.GetCursorScreenPos();
|
||||
var contentWidth = ImGui.GetContentRegionAvail().X;
|
||||
|
||||
min.X += indent * scale;
|
||||
var max = new Vector2(min.X + (contentWidth - indent * 2f) * scale, min.Y + thickness * scale);
|
||||
|
||||
var col = ImGui.GetColorU32(color ?? ImGuiColors.DalamudGrey);
|
||||
|
||||
|
||||
drawList.AddRectFilled(min, max, col, rounding);
|
||||
|
||||
ImGui.Dummy(new Vector2(0, thickness * scale));
|
||||
}
|
||||
|
||||
public void MediumText(string text, Vector4? color = null)
|
||||
{
|
||||
FontText(text, MediumFont, color);
|
||||
}
|
||||
|
||||
public bool MediumTreeNode(string label, Vector4? textColor = null, float lineWidth = 2f, ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags.SpanAvailWidth)
|
||||
{
|
||||
using var font = MediumFont.Push();
|
||||
var lineColor = textColor ?? ImGuiColors.DalamudWhite;
|
||||
|
||||
var textSize = ImGui.CalcTextSize(label);
|
||||
var cursorScreen = ImGui.GetCursorScreenPos();
|
||||
var cursorLocal = ImGui.GetCursorPos();
|
||||
|
||||
ImGui.GetWindowDrawList().AddLine(
|
||||
new Vector2(cursorScreen.X, cursorScreen.Y),
|
||||
new Vector2(cursorScreen.X, cursorScreen.Y + textSize.Y),
|
||||
ImGui.GetColorU32(lineColor),
|
||||
lineWidth * ImGuiHelpers.GlobalScale
|
||||
);
|
||||
|
||||
ImGui.SetCursorPosX(cursorLocal.X + 6f);
|
||||
using var color = ImRaii.PushColor(ImGuiCol.Text, lineColor);
|
||||
|
||||
return ImGui.TreeNodeEx(label, flags);
|
||||
}
|
||||
|
||||
public void BooleanToColoredIcon(bool value, bool inline = true)
|
||||
{
|
||||
using var colorgreen = ImRaii.PushColor(ImGuiCol.Text, UIColors.Get("LightlessBlue"), value);
|
||||
@@ -453,7 +556,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
||||
|
||||
public void DrawCacheDirectorySetting()
|
||||
{
|
||||
ColorTextWrapped("Note: The storage folder should be somewhere close to root (i.e. C:\\LightlessStorage) in a new empty folder. DO NOT point this to your game folder. DO NOT point this to your Penumbra folder.", ImGuiColors.DalamudYellow);
|
||||
ColorTextWrapped("Note: The storage folder should be somewhere close to root (i.e. C:\\LightlessStorage) in a new empty folder. DO NOT point this to your game folder. DO NOT point this to your Penumbra folder.", UIColors.Get("LightlessYellow"));
|
||||
var cacheDirectory = _configService.Current.CacheFolder;
|
||||
ImGui.InputText("Storage Folder##cache", ref cacheDirectory, 255, ImGuiInputTextFlags.ReadOnly);
|
||||
|
||||
@@ -639,7 +742,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
||||
{
|
||||
if (!_discordOAuthCheck.IsCompleted)
|
||||
{
|
||||
ColorTextWrapped($"Checking OAuth2 compatibility with {selectedServer.ServerUri}", ImGuiColors.DalamudYellow);
|
||||
ColorTextWrapped($"Checking OAuth2 compatibility with {selectedServer.ServerUri}", UIColors.Get("LightlessYellow"));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -730,7 +833,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
||||
{
|
||||
if (!_discordOAuthUIDs.IsCompleted)
|
||||
{
|
||||
ColorTextWrapped("Checking UIDs on Server", ImGuiColors.DalamudYellow);
|
||||
ColorTextWrapped("Checking UIDs on Server", UIColors.Get("LightlessYellow"));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1041,11 +1144,11 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
||||
IconText(icon, color == null ? ImGui.GetColorU32(ImGuiCol.Text) : ImGui.GetColorU32(color.Value));
|
||||
}
|
||||
|
||||
public bool IconTextButton(FontAwesomeIcon icon, string text, float? width = null, bool isInPopup = false)
|
||||
public bool IconTextButton(FontAwesomeIcon icon, string text, float? width = null, bool isInPopup = false, bool? center = null)
|
||||
{
|
||||
return IconTextButtonInternal(icon, text,
|
||||
isInPopup ? ColorHelpers.RgbaUintToVector4(ImGui.GetColorU32(ImGuiCol.PopupBg)) : null,
|
||||
width <= 0 ? null : width);
|
||||
width <= 0 ? null : width, center);
|
||||
}
|
||||
|
||||
public IDalamudTextureWrap LoadImage(byte[] imageData)
|
||||
@@ -1085,6 +1188,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
||||
|
||||
UidFont.Dispose();
|
||||
GameFont.Dispose();
|
||||
MediumFont.Dispose();
|
||||
}
|
||||
|
||||
private static void CenterWindow(float width, float height, ImGuiCond cond = ImGuiCond.None)
|
||||
@@ -1108,7 +1212,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
||||
ImGui.TextUnformatted(text);
|
||||
}
|
||||
|
||||
private bool IconTextButtonInternal(FontAwesomeIcon icon, string text, Vector4? defaultColor = null, float? width = null)
|
||||
private bool IconTextButtonInternal(FontAwesomeIcon icon, string text, Vector4? defaultColor = null, float? width = null, bool? center = null)
|
||||
{
|
||||
int num = 0;
|
||||
if (defaultColor.HasValue)
|
||||
@@ -1118,19 +1222,35 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
||||
}
|
||||
|
||||
ImGui.PushID(text);
|
||||
|
||||
Vector2 vector;
|
||||
using (IconFont.Push())
|
||||
vector = ImGui.CalcTextSize(icon.ToIconString());
|
||||
|
||||
Vector2 vector2 = ImGui.CalcTextSize(text);
|
||||
ImDrawListPtr windowDrawList = ImGui.GetWindowDrawList();
|
||||
Vector2 cursorScreenPos = ImGui.GetCursorScreenPos();
|
||||
float num2 = 3f * ImGuiHelpers.GlobalScale;
|
||||
float x = width ?? vector.X + vector2.X + ImGui.GetStyle().FramePadding.X * 2f + num2;
|
||||
|
||||
float totalTextWidth = vector.X + num2 + vector2.X;
|
||||
float x = width ?? totalTextWidth + ImGui.GetStyle().FramePadding.X * 2f;
|
||||
float frameHeight = ImGui.GetFrameHeight();
|
||||
|
||||
bool result = ImGui.Button(string.Empty, new Vector2(x, frameHeight));
|
||||
Vector2 pos = new Vector2(cursorScreenPos.X + ImGui.GetStyle().FramePadding.X, cursorScreenPos.Y + ImGui.GetStyle().FramePadding.Y);
|
||||
|
||||
bool shouldCenter = center == true;
|
||||
|
||||
Vector2 pos = shouldCenter
|
||||
? new Vector2(
|
||||
cursorScreenPos.X + (x - totalTextWidth) / 2f,
|
||||
cursorScreenPos.Y + (frameHeight - vector.Y) / 2f)
|
||||
: new Vector2(
|
||||
cursorScreenPos.X + ImGui.GetStyle().FramePadding.X,
|
||||
cursorScreenPos.Y + ImGui.GetStyle().FramePadding.Y);
|
||||
|
||||
using (IconFont.Push())
|
||||
windowDrawList.AddText(pos, ImGui.GetColorU32(ImGuiCol.Text), icon.ToIconString());
|
||||
|
||||
Vector2 pos2 = new Vector2(pos.X + vector.X + num2, cursorScreenPos.Y + ImGui.GetStyle().FramePadding.Y);
|
||||
windowDrawList.AddText(pos2, ImGui.GetColorU32(ImGuiCol.Text), text);
|
||||
ImGui.PopID();
|
||||
|
||||
99
LightlessSync/Utils/AtkNodeHelpers.cs
Normal file
99
LightlessSync/Utils/AtkNodeHelpers.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
using FFXIVClientStructs.FFXIV.Client.System.Memory;
|
||||
using FFXIVClientStructs.FFXIV.Component.GUI;
|
||||
|
||||
namespace LightlessSync.Utils;
|
||||
|
||||
internal static unsafe class AtkNodeHelpers
|
||||
{
|
||||
internal const ushort DefaultTextNodeWidth = 200;
|
||||
internal const ushort DefaultTextNodeHeight = 14;
|
||||
|
||||
internal static AtkTextNode* CreateNewTextNode(AtkUnitBase* pAddon, uint nodeID)
|
||||
{
|
||||
if (pAddon == null) return null;
|
||||
var pNewNode = CreateOrphanTextNode(nodeID);
|
||||
if (pNewNode != null) AttachTextNode(pAddon, pNewNode);
|
||||
return pNewNode;
|
||||
}
|
||||
|
||||
internal static void HideNode(AtkUnitBase* pAddon, uint nodeID)
|
||||
{
|
||||
var pNode = GetTextNodeByID(pAddon, nodeID);
|
||||
if (pNode != null) ((AtkResNode*)pNode)->ToggleVisibility(false);
|
||||
}
|
||||
|
||||
internal static AtkTextNode* GetTextNodeByID(AtkUnitBase* pAddon, uint nodeID)
|
||||
{
|
||||
if (pAddon == null) return null;
|
||||
for (var i = 0; i < pAddon->UldManager.NodeListCount; ++i)
|
||||
{
|
||||
if (pAddon->UldManager.NodeList[i] == null) continue;
|
||||
if (pAddon->UldManager.NodeList[i]->NodeId == nodeID)
|
||||
{
|
||||
return (AtkTextNode*)pAddon->UldManager.NodeList[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
internal static void AttachTextNode(AtkUnitBase* pAddon, AtkTextNode* pNode)
|
||||
{
|
||||
if (pAddon == null) return;
|
||||
|
||||
if (pNode != null)
|
||||
{
|
||||
var lastNode = pAddon->RootNode;
|
||||
if (lastNode->ChildNode != null)
|
||||
{
|
||||
lastNode = lastNode->ChildNode;
|
||||
while (lastNode->PrevSiblingNode != null)
|
||||
{
|
||||
lastNode = lastNode->PrevSiblingNode;
|
||||
}
|
||||
|
||||
pNode->AtkResNode.NextSiblingNode = lastNode;
|
||||
pNode->AtkResNode.ParentNode = pAddon->RootNode;
|
||||
lastNode->PrevSiblingNode = (AtkResNode*)pNode;
|
||||
}
|
||||
else
|
||||
{
|
||||
lastNode->ChildNode = (AtkResNode*)pNode;
|
||||
pNode->AtkResNode.ParentNode = lastNode;
|
||||
}
|
||||
|
||||
pAddon->UldManager.UpdateDrawNodeList();
|
||||
}
|
||||
}
|
||||
|
||||
internal static AtkTextNode* CreateOrphanTextNode(uint nodeID, TextFlags textFlags = TextFlags.Edge)
|
||||
{
|
||||
var pNewNode = (AtkTextNode*)IMemorySpace.GetUISpace()->Malloc((ulong)sizeof(AtkTextNode), 8);
|
||||
if (pNewNode != null)
|
||||
{
|
||||
IMemorySpace.Memset(pNewNode, 0, (ulong)sizeof(AtkTextNode));
|
||||
pNewNode->Ctor();
|
||||
|
||||
pNewNode->AtkResNode.Type = NodeType.Text;
|
||||
pNewNode->AtkResNode.NodeFlags = NodeFlags.AnchorLeft | NodeFlags.AnchorTop;
|
||||
pNewNode->AtkResNode.DrawFlags = 0;
|
||||
pNewNode->AtkResNode.SetPositionShort(0, 0);
|
||||
pNewNode->AtkResNode.SetWidth(DefaultTextNodeWidth);
|
||||
pNewNode->AtkResNode.SetHeight(DefaultTextNodeHeight);
|
||||
|
||||
pNewNode->LineSpacing = 24;
|
||||
pNewNode->CharSpacing = 1;
|
||||
pNewNode->AlignmentFontType = (byte)AlignmentType.BottomLeft;
|
||||
pNewNode->FontSize = 12;
|
||||
pNewNode->TextFlags = textFlags;
|
||||
|
||||
pNewNode->AtkResNode.NodeId = nodeID;
|
||||
|
||||
pNewNode->AtkResNode.Color.A = 0xFF;
|
||||
pNewNode->AtkResNode.Color.R = 0xFF;
|
||||
pNewNode->AtkResNode.Color.G = 0xFF;
|
||||
pNewNode->AtkResNode.Color.B = 0xFF;
|
||||
}
|
||||
|
||||
return pNewNode;
|
||||
}
|
||||
}
|
||||
171
LightlessSync/Utils/SeStringUtils.cs
Normal file
171
LightlessSync/Utils/SeStringUtils.cs
Normal file
@@ -0,0 +1,171 @@
|
||||
using Dalamud.Bindings.ImGui;
|
||||
using Dalamud.Game.Text.SeStringHandling;
|
||||
using Dalamud.Interface;
|
||||
using Dalamud.Interface.ImGuiSeStringRenderer;
|
||||
using Dalamud.Interface.Utility;
|
||||
using System.Numerics;
|
||||
|
||||
namespace LightlessSync.Utils;
|
||||
|
||||
public static class SeStringUtils
|
||||
{
|
||||
public static SeString BuildFormattedPlayerName(string text, Vector4? textColor, Vector4? glowColor)
|
||||
{
|
||||
var b = new SeStringBuilder();
|
||||
|
||||
if (glowColor is Vector4 glow)
|
||||
b.Add(new GlowPayload(glow));
|
||||
|
||||
if (textColor is Vector4 color)
|
||||
b.Add(new ColorPayload(color));
|
||||
|
||||
b.AddText(text ?? string.Empty);
|
||||
|
||||
if (textColor is not null)
|
||||
b.Add(new ColorEndPayload());
|
||||
|
||||
if (glowColor is not null)
|
||||
b.Add(new GlowEndPayload());
|
||||
|
||||
return b.Build();
|
||||
}
|
||||
|
||||
public static SeString BuildPlain(string text)
|
||||
{
|
||||
var b = new SeStringBuilder();
|
||||
b.AddText(text ?? string.Empty);
|
||||
return b.Build();
|
||||
}
|
||||
|
||||
public static void RenderSeString(SeString seString, Vector2 position, ImFontPtr? font = null, ImDrawListPtr? drawList = null)
|
||||
{
|
||||
drawList ??= ImGui.GetWindowDrawList();
|
||||
|
||||
var drawParams = new SeStringDrawParams
|
||||
{
|
||||
Font = font ?? UiBuilder.MonoFont,
|
||||
Color = 0xFFFFFFFF,
|
||||
WrapWidth = float.MaxValue,
|
||||
TargetDrawList = drawList
|
||||
};
|
||||
|
||||
ImGui.SetCursorScreenPos(position);
|
||||
ImGuiHelpers.SeStringWrapped(seString.Encode(), drawParams);
|
||||
}
|
||||
|
||||
public static Vector2 RenderSeStringWithHitbox(SeString seString, Vector2 position, ImFontPtr? font = null)
|
||||
{
|
||||
var drawList = ImGui.GetWindowDrawList();
|
||||
|
||||
var drawParams = new SeStringDrawParams
|
||||
{
|
||||
Font = font ?? UiBuilder.MonoFont,
|
||||
Color = 0xFFFFFFFF,
|
||||
WrapWidth = float.MaxValue,
|
||||
TargetDrawList = drawList
|
||||
};
|
||||
|
||||
ImGui.SetCursorScreenPos(position);
|
||||
ImGuiHelpers.SeStringWrapped(seString.Encode(), drawParams);
|
||||
|
||||
var textSize = ImGui.CalcTextSize(seString.TextValue);
|
||||
|
||||
ImGui.SetCursorScreenPos(position);
|
||||
ImGui.InvisibleButton($"##hitbox_{Guid.NewGuid()}", textSize);
|
||||
|
||||
return textSize;
|
||||
}
|
||||
|
||||
public static Vector2 RenderIconWithHitbox(int iconId, Vector2 position, ImFontPtr? font = null)
|
||||
{
|
||||
var drawList = ImGui.GetWindowDrawList();
|
||||
|
||||
var drawParams = new SeStringDrawParams
|
||||
{
|
||||
Font = font ?? UiBuilder.MonoFont,
|
||||
Color = 0xFFFFFFFF,
|
||||
WrapWidth = float.MaxValue,
|
||||
TargetDrawList = drawList
|
||||
};
|
||||
|
||||
var iconMacro = $"<icon({iconId})>";
|
||||
var drawResult = ImGuiHelpers.CompileSeStringWrapped(iconMacro, drawParams);
|
||||
|
||||
ImGui.SetCursorScreenPos(position);
|
||||
ImGui.InvisibleButton($"##iconHitbox_{Guid.NewGuid()}", drawResult.Size);
|
||||
|
||||
return drawResult.Size;
|
||||
}
|
||||
|
||||
#region Internal Payloads
|
||||
|
||||
private abstract class AbstractColorPayload : Payload
|
||||
{
|
||||
protected byte Red { get; init; }
|
||||
protected byte Green { get; init; }
|
||||
protected byte Blue { get; init; }
|
||||
|
||||
protected override byte[] EncodeImpl()
|
||||
{
|
||||
return new byte[] { 0x02, ChunkType, 0x05, 0xF6, Red, Green, Blue, 0x03 };
|
||||
}
|
||||
|
||||
protected override void DecodeImpl(BinaryReader reader, long endOfStream) { }
|
||||
|
||||
public override PayloadType Type => PayloadType.Unknown;
|
||||
protected abstract byte ChunkType { get; }
|
||||
}
|
||||
|
||||
private abstract class AbstractColorEndPayload : Payload
|
||||
{
|
||||
protected override byte[] EncodeImpl()
|
||||
{
|
||||
return new byte[] { 0x02, ChunkType, 0x02, 0xEC, 0x03 };
|
||||
}
|
||||
|
||||
protected override void DecodeImpl(BinaryReader reader, long endOfStream) { }
|
||||
|
||||
public override PayloadType Type => PayloadType.Unknown;
|
||||
protected abstract byte ChunkType { get; }
|
||||
}
|
||||
|
||||
private class ColorPayload : AbstractColorPayload
|
||||
{
|
||||
protected override byte ChunkType => 0x13;
|
||||
|
||||
public ColorPayload(Vector3 color)
|
||||
{
|
||||
Red = Math.Max((byte)1, (byte)(color.X * 255f));
|
||||
Green = Math.Max((byte)1, (byte)(color.Y * 255f));
|
||||
Blue = Math.Max((byte)1, (byte)(color.Z * 255f));
|
||||
}
|
||||
|
||||
public ColorPayload(Vector4 color) : this(new Vector3(color.X, color.Y, color.Z)) { }
|
||||
}
|
||||
|
||||
private class ColorEndPayload : AbstractColorEndPayload
|
||||
{
|
||||
protected override byte ChunkType => 0x13;
|
||||
}
|
||||
|
||||
private class GlowPayload : AbstractColorPayload
|
||||
{
|
||||
protected override byte ChunkType => 0x14;
|
||||
|
||||
public GlowPayload(Vector3 color)
|
||||
{
|
||||
Red = Math.Max((byte)1, (byte)(color.X * 255f));
|
||||
Green = Math.Max((byte)1, (byte)(color.Y * 255f));
|
||||
Blue = Math.Max((byte)1, (byte)(color.Z * 255f));
|
||||
}
|
||||
|
||||
public GlowPayload(Vector4 color) : this(new Vector3(color.X, color.Y, color.Z)) { }
|
||||
}
|
||||
|
||||
private class GlowEndPayload : AbstractColorEndPayload
|
||||
{
|
||||
protected override byte ChunkType => 0x14;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -144,28 +144,55 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
||||
|
||||
_downloadStatus[downloadGroup].DownloadStatus = DownloadStatus.Downloading;
|
||||
|
||||
const int maxRetries = 3;
|
||||
int retryCount = 0;
|
||||
TimeSpan retryDelay = TimeSpan.FromSeconds(2);
|
||||
|
||||
HttpResponseMessage response = null!;
|
||||
var requestUrl = LightlessFiles.CacheGetFullPath(fileTransfer[0].DownloadUri, requestId);
|
||||
|
||||
Logger.LogDebug("Downloading {requestUrl} for request {id}", requestUrl, requestId);
|
||||
try
|
||||
while (true)
|
||||
{
|
||||
response = await _orchestrator.SendRequestAsync(HttpMethod.Get, requestUrl, ct, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
Logger.LogWarning(ex, "Error during download of {requestUrl}, HttpStatusCode: {code}", requestUrl, ex.StatusCode);
|
||||
if (ex.StatusCode is HttpStatusCode.NotFound or HttpStatusCode.Unauthorized)
|
||||
try
|
||||
{
|
||||
throw new InvalidDataException($"Http error {ex.StatusCode} (cancelled: {ct.IsCancellationRequested}): {requestUrl}", ex);
|
||||
Logger.LogDebug("Attempt {attempt} - Downloading {requestUrl} for request {id}", retryCount + 1, requestUrl, requestId);
|
||||
|
||||
response = await _orchestrator.SendRequestAsync(HttpMethod.Get, requestUrl, ct, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);
|
||||
response.EnsureSuccessStatusCode();
|
||||
break;
|
||||
}
|
||||
catch (HttpRequestException ex) when (ex.InnerException is TimeoutException || ex.StatusCode == null)
|
||||
{
|
||||
retryCount++;
|
||||
|
||||
Logger.LogWarning(ex, "Timeout during download of {requestUrl}. Attempt {attempt} of {maxRetries}", requestUrl, retryCount, maxRetries);
|
||||
|
||||
if (retryCount >= maxRetries || ct.IsCancellationRequested)
|
||||
{
|
||||
Logger.LogError($"Max retries reached or cancelled. Failing download for {requestUrl}");
|
||||
throw;
|
||||
}
|
||||
|
||||
await Task.Delay(retryDelay, ct).ConfigureAwait(false); // Wait before retrying
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
Logger.LogWarning(ex, "Error during download of {requestUrl}, HttpStatusCode: {code}", requestUrl, ex.StatusCode);
|
||||
|
||||
if (ex.StatusCode is HttpStatusCode.NotFound or HttpStatusCode.Unauthorized)
|
||||
{
|
||||
throw new InvalidDataException($"Http error {ex.StatusCode} (cancelled: {ct.IsCancellationRequested}): {requestUrl}", ex);
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
ThrottledStream? stream = null;
|
||||
FileStream? fileStream = null;
|
||||
|
||||
try
|
||||
{
|
||||
var fileStream = File.Create(tempPath);
|
||||
fileStream = File.Create(tempPath);
|
||||
await using (fileStream.ConfigureAwait(false))
|
||||
{
|
||||
var bufferSize = response.Content.Headers.ContentLength > 1024 * 1024 ? 65536 : 8196;
|
||||
@@ -174,8 +201,11 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
||||
var bytesRead = 0;
|
||||
var limit = _orchestrator.DownloadLimitPerSlot();
|
||||
Logger.LogTrace("Starting Download of {id} with a speed limit of {limit} to {tempPath}", requestId, limit, tempPath);
|
||||
stream = new ThrottledStream(await response.Content.ReadAsStreamAsync(ct).ConfigureAwait(false), limit);
|
||||
|
||||
stream = new(await response.Content.ReadAsStreamAsync(ct).ConfigureAwait(false), limit);
|
||||
|
||||
_activeDownloadStreams.Add(stream);
|
||||
|
||||
while ((bytesRead = await stream.ReadAsync(buffer, ct).ConfigureAwait(false)) > 0)
|
||||
{
|
||||
ct.ThrowIfCancellationRequested();
|
||||
@@ -194,18 +224,22 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!tempPath.IsNullOrEmpty())
|
||||
fileStream?.Close();
|
||||
|
||||
if (!string.IsNullOrEmpty(tempPath) && File.Exists(tempPath))
|
||||
{
|
||||
File.Delete(tempPath);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignore if file deletion fails
|
||||
// Ignore errors during cleanup
|
||||
}
|
||||
throw;
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -69,7 +69,7 @@ public sealed class FileUploadManager : DisposableMediatorSubscriberBase
|
||||
Logger.LogDebug("Trying to upload files");
|
||||
var filesPresentLocally = hashesToUpload.Where(h => _fileDbManager.GetFileCacheByHash(h) != null).ToHashSet(StringComparer.Ordinal);
|
||||
var locallyMissingFiles = hashesToUpload.Except(filesPresentLocally, StringComparer.Ordinal).ToList();
|
||||
if (locallyMissingFiles.Any())
|
||||
if (locallyMissingFiles.Count != 0)
|
||||
{
|
||||
return locallyMissingFiles;
|
||||
}
|
||||
@@ -92,7 +92,7 @@ public sealed class FileUploadManager : DisposableMediatorSubscriberBase
|
||||
var data = await _fileDbManager.GetCompressedFileData(file.Hash, ct ?? CancellationToken.None).ConfigureAwait(false);
|
||||
Logger.LogDebug("[{hash}] Starting upload for {filePath}", data.Item1, _fileDbManager.GetFileCacheByHash(data.Item1)!.ResolvedFilepath);
|
||||
await uploadTask.ConfigureAwait(false);
|
||||
uploadTask = UploadFile(data.Item2, file.Hash, false, ct ?? CancellationToken.None);
|
||||
uploadTask = UploadFile(data.Item2, file.Hash, postProgress: false, ct ?? CancellationToken.None);
|
||||
(ct ?? CancellationToken.None).ThrowIfCancellationRequested();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using LightlessSync.API.Data;
|
||||
using LightlessSync.API.Dto;
|
||||
using LightlessSync.API.Dto.Group;
|
||||
using LightlessSync.API.Dto.User;
|
||||
using Microsoft.AspNetCore.SignalR.Client;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -34,6 +35,36 @@ public partial class ApiController
|
||||
await _lightlessHub!.SendAsync(nameof(UserAddPair), user).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task TryPairWithContentId(string otherCid, string myCid)
|
||||
{
|
||||
if (!IsConnected) return;
|
||||
await _lightlessHub!.SendAsync(nameof(TryPairWithContentId), otherCid, myCid).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task SetBroadcastStatus(string hashedCid, bool enabled, GroupBroadcastRequestDto? groupDto = null)
|
||||
{
|
||||
CheckConnection();
|
||||
await _lightlessHub!.InvokeAsync(nameof(SetBroadcastStatus), hashedCid, enabled, groupDto).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<BroadcastStatusInfoDto?> IsUserBroadcasting(string hashedCid)
|
||||
{
|
||||
CheckConnection();
|
||||
return await _lightlessHub!.InvokeAsync<BroadcastStatusInfoDto?>(nameof(IsUserBroadcasting), hashedCid).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<BroadcastStatusBatchDto> AreUsersBroadcasting(List<string> hashedCids)
|
||||
{
|
||||
CheckConnection();
|
||||
return await _lightlessHub!.InvokeAsync<BroadcastStatusBatchDto>(nameof(AreUsersBroadcasting), hashedCids).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<TimeSpan?> GetBroadcastTtl(string hashedCid)
|
||||
{
|
||||
CheckConnection();
|
||||
return await _lightlessHub!.InvokeAsync<TimeSpan?>(nameof(GetBroadcastTtl), hashedCid).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task UserDelete()
|
||||
{
|
||||
CheckConnection();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using LightlessSync.API.Dto.Group;
|
||||
using LightlessSync.API.Dto.User;
|
||||
using LightlessSync.WebAPI.SignalR.Utils;
|
||||
using Microsoft.AspNetCore.SignalR.Client;
|
||||
|
||||
@@ -80,6 +81,11 @@ public partial class ApiController
|
||||
CheckConnection();
|
||||
return await _lightlessHub!.InvokeAsync<bool>(nameof(GroupJoinFinalize), passwordedGroup).ConfigureAwait(false);
|
||||
}
|
||||
public async Task<GroupJoinInfoDto> GroupJoinHashed(GroupJoinHashedDto dto)
|
||||
{
|
||||
CheckConnection();
|
||||
return await _lightlessHub!.InvokeAsync<GroupJoinInfoDto>("GroupJoinHashed", dto).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task GroupLeave(GroupDto group)
|
||||
{
|
||||
@@ -116,6 +122,18 @@ public partial class ApiController
|
||||
CheckConnection();
|
||||
await _lightlessHub!.SendAsync(nameof(GroupUnbanUser), groupPair).ConfigureAwait(false);
|
||||
}
|
||||
public async Task<bool> SetGroupBroadcastStatus(GroupBroadcastRequestDto dto)
|
||||
{
|
||||
CheckConnection();
|
||||
return await _lightlessHub!.InvokeAsync<bool>(nameof(SetGroupBroadcastStatus), dto).ConfigureAwait(false);
|
||||
}
|
||||
public async Task<List<GroupJoinDto>> GetBroadcastedGroups(List<BroadcastStatusInfoDto> broadcastEntries)
|
||||
{
|
||||
CheckConnection();
|
||||
return await _lightlessHub!.InvokeAsync<List<GroupJoinDto>>(nameof(GetBroadcastedGroups), broadcastEntries)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
||||
private void CheckConnection()
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using LightlessSync.API.Data;
|
||||
using LightlessSync.API.Data.Extensions;
|
||||
using LightlessSync.API.Dto;
|
||||
using LightlessSync.API.Dto.Group;
|
||||
using LightlessSync.API.Dto.User;
|
||||
using LightlessSync.API.SignalR;
|
||||
using LightlessSync.LightlessConfiguration;
|
||||
@@ -100,6 +101,8 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IL
|
||||
|
||||
public string UID => _connectionDto?.User.UID ?? string.Empty;
|
||||
|
||||
public event Action? OnConnected;
|
||||
|
||||
public async Task<bool> CheckClientHealth()
|
||||
{
|
||||
return await _lightlessHub!.InvokeAsync<bool>(nameof(CheckClientHealth)).ConfigureAwait(false);
|
||||
@@ -230,6 +233,7 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IL
|
||||
_connectionDto = await GetConnectionDto().ConfigureAwait(false);
|
||||
|
||||
ServerState = ServerState.Connected;
|
||||
OnConnected?.Invoke();
|
||||
|
||||
var currentClientVer = Assembly.GetExecutingAssembly().GetName().Version!;
|
||||
|
||||
@@ -517,6 +521,7 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IL
|
||||
return;
|
||||
}
|
||||
ServerState = ServerState.Connected;
|
||||
OnConnected?.Invoke();
|
||||
await LoadIninitialPairsAsync().ConfigureAwait(false);
|
||||
await LoadOnlinePairsAsync().ConfigureAwait(false);
|
||||
Mediator.Publish(new ConnectedMessage(_connectionDto));
|
||||
@@ -592,5 +597,20 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IL
|
||||
|
||||
ServerState = state;
|
||||
}
|
||||
|
||||
public Task Client_GroupSendProfile(GroupProfileDto groupInfo)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<GroupProfileDto> GroupGetProfile(GroupDto dto)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task GroupSetProfile(GroupProfileDto dto)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
#pragma warning restore MA0040
|
||||
@@ -4,9 +4,9 @@
|
||||
"net9.0-windows7.0": {
|
||||
"DalamudPackager": {
|
||||
"type": "Direct",
|
||||
"requested": "[13.0.0, )",
|
||||
"resolved": "13.0.0",
|
||||
"contentHash": "Mb3cUDSK/vDPQ8gQIeuCw03EMYrej1B4J44a1AvIJ9C759p9XeqdU9Hg4WgOmlnlPe0G7ILTD32PKSUpkQNa8w=="
|
||||
"requested": "[13.1.0, )",
|
||||
"resolved": "13.1.0",
|
||||
"contentHash": "XdoNhJGyFby5M/sdcRhnc5xTop9PHy+H50PTWpzLhJugjB19EDBiHD/AsiDF66RETM+0qKUdJBZrNuebn7qswQ=="
|
||||
},
|
||||
"DotNet.ReproducibleBuilds": {
|
||||
"type": "Direct",
|
||||
|
||||
Submodule PenumbraAPI updated: 953dd227af...dd14131793
Reference in New Issue
Block a user