Skip to content

Commit

Permalink
[O] Announcement image size
Browse files Browse the repository at this point in the history
  • Loading branch information
clansty committed Feb 20, 2025
1 parent d7a835c commit d20db83
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions AquaMai.Core/Helpers/MessageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ private static void OnSetMessageManager(IGenericManager genericManager)
_genericManager = genericManager;
}

public static void ShowMessage(string message, WindowSizeID size = WindowSizeID.Middle, string title = null, Sprite sprite = null)
public static void ShowMessage(string message, WindowSizeID size = WindowSizeID.Middle, string title = null, Sprite sprite = null, bool retain = false)
{
if (_genericManager is null)
{
MelonLogger.Error($"[MessageHelper] Unable to show message: `{message}` GenericManager is null");
return;
}

_genericManager.Enqueue(0, WindowMessageID.CollectionAttentionEmptyFavorite, new WindowParam()
_genericManager.Enqueue(0, retain ? WindowMessageID.CollectionCategorySelectAnnounce : WindowMessageID.CollectionAttentionEmptyFavorite, new WindowParam()
{
hideTitle = title is null,
replaceTitle = true,
Expand All @@ -39,4 +39,4 @@ public static void ShowMessage(string message, WindowSizeID size = WindowSizeID.
sprite = sprite,
});
}
}
}
13 changes: 8 additions & 5 deletions AquaMai.Mods/UX/ServerAnnouncement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ namespace AquaMai.Mods.UX;
[ConfigSection(
defaultOn: true,
en: """
Show announcement from the AquaDX server
Show announcement from compatible server
(no side effects for other servers, no extra requests made)
""",
zh: """
显示来自 AquaDX 服务端的公告
显示来自兼容服务端的公告
(对其他服务器无副作用,不会发出额外请求)
""")]
public static class ServerAnnouncement
Expand All @@ -30,6 +30,7 @@ private class ServerAnnouncementEntry
[CanBeNull] public string title = null;
[CanBeNull] public string announcement = null;
[CanBeNull] public string imageUrl = null;
public float imageSizeFactor = 9;
public bool showOnIdle = false;
public bool showOnUserLogin = false;
public string[] locales = [];
Expand Down Expand Up @@ -105,18 +106,20 @@ private static bool ShouldShowAnnouncement(ServerAnnouncementEntry announcement)
MelonLogger.Msg($"[ServerAnnouncement] Now showing announcement: AquaMai version {aquaMaiVersion} < {announcement.minimumAquaMaiVersion}");
return false;
}

if (announcement.maximumAquaMaiVersion != null && aquaMaiVersion > new System.Version(announcement.maximumAquaMaiVersion))
{
MelonLogger.Msg($"[ServerAnnouncement] Now showing announcement: AquaMai version {aquaMaiVersion} > {announcement.maximumAquaMaiVersion}");
return false;
}

var gameVersion = GameInfo.GameVersion;
if (announcement.minimumGameVersion != 0 && gameVersion < announcement.minimumGameVersion)
{
MelonLogger.Msg($"[ServerAnnouncement] Now showing announcement: Game version {gameVersion} < {announcement.minimumGameVersion}");
return false;
}

if (announcement.maximumGameVersion != 0 && gameVersion > announcement.maximumGameVersion)
{
MelonLogger.Msg($"[ServerAnnouncement] Now showing announcement: Game version {gameVersion} > {announcement.maximumGameVersion}");
Expand Down Expand Up @@ -145,7 +148,7 @@ private IEnumerator GetTexture()
else
{
var texture = DownloadHandlerTexture.GetContent(www);
_sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f), texture.width / 4f);
_sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f), texture.width / _announcement.imageSizeFactor);
#if DEBUG
MelonLogger.Msg($"[ServerAnnouncement] Downloaded image success");
#endif
Expand All @@ -170,4 +173,4 @@ private static void EntryProcessOnStart()
if (_announcement == null || !_announcement.showOnUserLogin) return;
MessageHelper.ShowMessage(_announcement.announcement, title: _announcement.title, sprite: _sprite, size: WindowSizeID.LargeVerticalPostImage);
}
}
}

0 comments on commit d20db83

Please sign in to comment.