Skip to content

Commit

Permalink
Merge branch 'ScreenshotsDisplay'
Browse files Browse the repository at this point in the history
  • Loading branch information
FenPhoenix committed Mar 6, 2024
2 parents 9ffe506 + 178da9f commit 26da535
Show file tree
Hide file tree
Showing 78 changed files with 4,637 additions and 927 deletions.
1 change: 1 addition & 0 deletions AL_Common/FenGenAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#pragma warning disable IDE0060 // Remove unused parameter.
#pragma warning disable RCS1163 // Unused parameter.
#pragma warning disable RCS1139 // Add summary element to documentation comment.
#pragma warning disable CS9113 // Parameter is unread.

namespace AL_Common;

Expand Down
20 changes: 18 additions & 2 deletions AngelLoader/Common/Comparers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ internal static class Comparers

#region Misc comparers

private static FileNameNoExtComparer? _fileNameNoExtComparer;
internal static FileNameNoExtComparer FileNameNoExt => _fileNameNoExtComparer ??= new FileNameNoExtComparer();
internal static FileNameNoExtComparer FileNameNoExt = new();

internal static ScreenshotComparer Screenshot = new();

#endregion

Expand Down Expand Up @@ -442,5 +443,20 @@ public int Compare(string x, string y) =>
StringComparison.OrdinalIgnoreCase);
}

internal sealed class ScreenshotComparer : IComparer<FileInfo>
{
public SortDirection SortDirection = SortDirection.Ascending;

public int Compare(FileInfo x, FileInfo y)
{
int cmp = x.LastWriteTime.CompareTo(y.LastWriteTime);
int ret = cmp == 0
// @TDM_CASE when file is a TDM screenshot
? string.Compare(x.Name, y.Name, StringComparison.OrdinalIgnoreCase)
: cmp;
return SortDirection == SortDirection.Descending ? -ret : ret;
}
}

#endregion
}
15 changes: 13 additions & 2 deletions AngelLoader/Common/DataClasses/ConfigData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,13 @@ internal float FMsListFontSizeInPoints
private float _topSplitterPercent = Defaults.TopSplitterPercent;
internal float TopSplitterPercent { get => _topSplitterPercent; set => _topSplitterPercent = value.ClampZeroToOne(); }

internal bool TopRightPanelCollapsed;
private float _lowerSplitterPercent = Defaults.LowerSplitterPercent;
internal float LowerSplitterPercent { get => _lowerSplitterPercent; set => _lowerSplitterPercent = value.ClampZeroToOne(); }

internal readonly TopRightTabsData TopRightTabsData = new();
internal bool TopFMTabsPanelCollapsed;
internal bool BottomFMTabsPanelCollapsed = true;

internal readonly FMTabsData FMTabsData = new();

#endregion

Expand Down Expand Up @@ -462,6 +466,13 @@ private static string[] InitWebSearchUrls()

internal CheckForUpdates CheckForUpdates = CheckForUpdates.FirstTimeAsk;

private int _screenshotGammaPercent = 50;
internal int ScreenshotGammaPercent
{
get => _screenshotGammaPercent;
set => _screenshotGammaPercent = value.Clamp(0, 100);
}

#if !ReleaseBeta && !ReleasePublic
// Quick-n-dirty session-only var for now
internal bool ForceWindowed;
Expand Down
76 changes: 50 additions & 26 deletions AngelLoader/Common/DataClasses/ConfigDataSupporting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,40 +95,53 @@ public enum CheckForUpdates
False
}

#region Top-right tabs
#region FM tabs

// IMPORTANT(TopRightTab enum): Do not rename members, they're used in the config file
internal enum TopRightTab { Statistics, EditFM, Comment, Tags, Patch, Mods }
// IMPORTANT(FM tabs enum): Do not rename members, they're used in the config file
[FenGenEnumCount]
internal enum FMTab
{
Statistics,
EditFM,
Comment,
Tags,
Patch,
Mods,
Screenshots
}

internal sealed class TopRightTabData
public enum FMTabVisibleIn
{
None,
Top,
Bottom
}

internal sealed class FMTabData
{
private int _displayIndex;
internal int DisplayIndex { get => _displayIndex; set => _displayIndex = value.Clamp(0, TopRightTabsData.Count - 1); }
internal int DisplayIndex { get => _displayIndex; set => _displayIndex = value.Clamp(0, FMTabCount - 1); }

internal bool Visible = true;
internal FMTabVisibleIn Visible = FMTabVisibleIn.Top;
}

internal sealed class TopRightTabsData
internal sealed class FMTabsData
{
/// <summary>
/// Returns the number of tabs that have been defined in the <see cref="TopRightTab"/> enum.
/// </summary>
internal static readonly int Count = Enum.GetValues(typeof(TopRightTab)).Length;

internal readonly TopRightTabData[] Tabs = InitializedArray<TopRightTabData>(Count);
internal readonly FMTabData[] Tabs = InitializedArray<FMTabData>(FMTabCount);

internal TopRightTab SelectedTab = TopRightTab.Statistics;
internal FMTab SelectedTab = FMTab.Statistics;
internal FMTab SelectedTab2 = FMTab.Statistics;

internal TopRightTabsData() => ResetAllDisplayIndexes();
internal FMTabsData() => ResetAllDisplayIndexes();

internal TopRightTabData GetTab(TopRightTab tab) => Tabs[(int)tab];
internal FMTabData GetTab(FMTab tab) => Tabs[(int)tab];

internal void EnsureValidity()
{
#region Fallback if multiple tabs have the same display index

var displayIndexesSet = new HashSet<int>();
for (int i = 0; i < Count; i++)
for (int i = 0; i < FMTabCount; i++)
{
if (!displayIndexesSet.Add(Tabs[i].DisplayIndex))
{
Expand All @@ -139,16 +152,27 @@ internal void EnsureValidity()

#endregion

if (NoneVisible()) SetAllVisible(true);
if (NoneVisible()) SetAllVisible(FMTabVisibleIn.Top);

// Fallback if selected tab is not marked as visible
if (!GetTab(SelectedTab).Visible)
if (GetTab(SelectedTab).Visible != FMTabVisibleIn.Top)
{
for (int i = 0; i < FMTabCount; i++)
{
if (Tabs[i].Visible == FMTabVisibleIn.Top)
{
SelectedTab = (FMTab)i;
break;
}
}
}
if (GetTab(SelectedTab2).Visible != FMTabVisibleIn.Bottom)
{
for (int i = 0; i < Count; i++)
for (int i = 0; i < FMTabCount; i++)
{
if (Tabs[i].Visible)
if (Tabs[i].Visible == FMTabVisibleIn.Bottom)
{
SelectedTab = (TopRightTab)i;
SelectedTab2 = (FMTab)i;
break;
}
}
Expand All @@ -157,18 +181,18 @@ internal void EnsureValidity()

private bool NoneVisible()
{
for (int i = 0; i < Count; i++) if (Tabs[i].Visible) return false;
for (int i = 0; i < FMTabCount; i++) if (Tabs[i].Visible != FMTabVisibleIn.None) return false;
return true;
}

private void SetAllVisible(bool visible)
private void SetAllVisible(FMTabVisibleIn visible)
{
for (int i = 0; i < Count; i++) Tabs[i].Visible = visible;
for (int i = 0; i < FMTabCount; i++) Tabs[i].Visible = visible;
}

private void ResetAllDisplayIndexes()
{
for (int i = 0; i < Count; i++) Tabs[i].DisplayIndex = i;
for (int i = 0; i < FMTabCount; i++) Tabs[i].DisplayIndex = i;
}
}

Expand Down
10 changes: 9 additions & 1 deletion AngelLoader/Common/DataClasses/DarkColors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ public static class DarkColors
public static readonly Color DGV_RecentHighlightColorLight = Color.LightGoldenrodYellow;
public static readonly Color DGV_UnavailableColorLight = Color.MistyRose;

public static readonly Color SuccessGreenDark = Color.FromArgb(68, 178, 68);

public static readonly Color TabDragOverlay_Light = Color.FromArgb(60,
SystemColors.Highlight.R,
SystemColors.Highlight.G,
SystemColors.Highlight.B);
public static readonly Color TabDragOverlay_Dark = Color.FromArgb(64, 75, 110, 175);

#endregion

#region DarkUI
Expand Down Expand Up @@ -96,7 +104,7 @@ public static class DarkColors
//public static readonly Pen DarkBlueBackgroundPen = new Pen(DarkBlueBackground);
public static readonly Pen DarkBackgroundPen = new Pen(DarkBackground);
//public static readonly Pen MediumBackgroundPen = new Pen(MediumBackground);
//public static readonly Pen LightBackgroundPen = new Pen(LightBackground);
public static readonly Pen LightBackgroundPen = new Pen(LightBackground);
public static readonly Pen LighterBackgroundPen = new Pen(LighterBackground);
//public static readonly Pen LightestBackgroundPen = new Pen(LightestBackground);
public static readonly Pen LightBorderPen = new Pen(LightBorder);
Expand Down
1 change: 1 addition & 0 deletions AngelLoader/Common/DataClasses/ErrorText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ internal static class ErrorText
internal static readonly string FoundRegKey = "Found the registry key but ";
internal static readonly string RegKeyPath = "Registry key path was: ";
internal static readonly string FMInstDirNF = "FM install directory not found.";
internal static readonly string FMScreenshotsDirNF = "FM screenshot directory not found.";
internal static readonly string ExInLWT = Ex + "in last write time compare ";
}
#pragma warning restore RCS1187 // Use constant instead of field.
19 changes: 19 additions & 0 deletions AngelLoader/Common/DataClasses/LocalizationData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ internal sealed class LText_Class
internal readonly FilterBar_Class FilterBar = new();
internal readonly FMsList_Class FMsList = new();
internal readonly FMSelectedStats_Class FMSelectedStats = new();
internal readonly FMTabs_Class FMTabs = new();
internal readonly StatisticsTab_Class StatisticsTab = new();
internal readonly EditFMTab_Class EditFMTab = new();
internal readonly CommentTab_Class CommentTab = new();
internal readonly TagsTab_Class TagsTab = new();
internal readonly PatchTab_Class PatchTab = new();
internal readonly ModsTab_Class ModsTab = new();
internal readonly ScreenshotsTab_Class ScreenshotsTab = new();
internal readonly ReadmeArea_Class ReadmeArea = new();
internal readonly PlayOriginalGameMenu_Class PlayOriginalGameMenu = new();
internal readonly MainButtons_Class MainButtons = new();
Expand Down Expand Up @@ -496,6 +498,11 @@ internal sealed class FMSelectedStats_Class
internal readonly string FMsFinished_Plural_AfterNumber = " FMs finished";
}

internal sealed class FMTabs_Class
{
internal readonly string EmptyTabAreaMessage = "Drag a tab here, or right-click to add a tab.";
}

internal sealed class StatisticsTab_Class
{
internal readonly string TabText = "Statistics";
Expand Down Expand Up @@ -626,6 +633,18 @@ internal sealed class ModsTab_Class
// @GENGAMES (Localization - ModsTab_Class) - End
}

internal sealed class ScreenshotsTab_Class
{
internal readonly string TabText = "Screenshots";
internal readonly string Gamma = "Gamma:";
internal readonly string OpenScreenshotsFolderToolTip = "Open screenshots folder";
internal readonly string CopyImageToolTip = "Copy image (Ctrl+C)";
internal readonly string ScreenshotsFolderNotFound = "Screenshots folder not found.";
internal readonly string ScreenshotsFolderOpenError = "There was an error trying to open the screenshots folder.";
internal readonly string ImageCopied = "Image copied";
internal readonly string ImageCopyFailed = "Image copy failed";
}

internal sealed class ReadmeArea_Class
{
internal readonly string ViewHTMLReadme = "View HTML Readme";
Expand Down
1 change: 1 addition & 0 deletions AngelLoader/Common/EnumData.Generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public static partial class Misc
{
public const int ColumnCount = 14;
public const int HideableFilterControlsCount = 10;
public const int FMTabCount = 7;
public const int SettingsTabCount = 5;
public static readonly string[] CustomResourcesNames =
{
Expand Down
16 changes: 16 additions & 0 deletions AngelLoader/Common/Misc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ internal static class Defaults

internal const float TopSplitterPercent = 0.741f;
internal const float MainSplitterPercent = 0.4425f;
internal const float LowerSplitterPercent = 0.741f;

// @NET5: Remember to change this to match the new font
internal const float FMsListFontSizeInPoints = 8.25f;
Expand Down Expand Up @@ -197,4 +198,19 @@ internal static class Defaults

internal const int StreamCopyBufferSize = 81920;
internal const int FileStreamBufferSize = 4096;

// Another leak of view implementation details into here (GDI+/Bitmap supported formats)
// @ScreenshotDisplay: NewDark games can also have .pcx, and TDM can also have .tga
// Neither are supported by Bitmap, so, you're kinda outta luck on those.
public static readonly string[] SupportedScreenshotExtensions =
{
// Common/likely ones first
".png",
".bmp",
".jpg",
".jpeg",
".gif",
".tif",
".tiff"
};
}
43 changes: 42 additions & 1 deletion AngelLoader/Common/Native/NativeCommon.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Runtime.InteropServices;
using System;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Win32.SafeHandles;

Expand All @@ -22,4 +23,44 @@ Admin privileges(?!). At least on Framework anyway.
internal static extern SafeProcessHandle OpenProcess(uint dwDesiredAccess, bool bInheritHandle, int dwProcessId);

#endregion

#region Open folder and select file

internal static bool OpenFolderAndSelectFile(string filePath)
{
try
{
IntPtr pidl = ILCreateFromPathW(filePath);
if (pidl == IntPtr.Zero) return false;

try
{
int result = SHOpenFolderAndSelectItems(pidl, 0, IntPtr.Zero, 0);
return result == 0;
}
catch
{
return false;
}
finally
{
ILFree(pidl);
}
}
catch
{
return false;
}
}

[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
private static extern IntPtr ILCreateFromPathW(string pszPath);

[DllImport("shell32.dll")]
private static extern int SHOpenFolderAndSelectItems(IntPtr pidlFolder, int cild, IntPtr apidl, int dwFlags);

[DllImport("shell32.dll")]
private static extern void ILFree(IntPtr pidl);

#endregion
}
9 changes: 9 additions & 0 deletions AngelLoader/Common/Utility/PathUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ internal static bool ExtIsArchive(this string value) =>

internal static bool ExtIsRar(this string value) => value.EndsWithI(".rar");

internal static bool ExtIsUISupportedImage(this string value)
{
for (int i = 0; i < Misc.SupportedScreenshotExtensions.Length; i++)
{
if (value.EndsWithI(Misc.SupportedScreenshotExtensions[i])) return true;
}
return false;
}

#endregion

#endregion
Expand Down
Loading

0 comments on commit 26da535

Please sign in to comment.