imgui spaghetti

This commit is contained in:
rootdarkarchon
2023-03-22 18:31:28 +01:00
parent 38d83eff77
commit 3cc3c7a7af
4 changed files with 99 additions and 56 deletions

File diff suppressed because one or more lines are too long

View File

@@ -20,9 +20,12 @@ public class EditProfileUi : WindowMediatorSubscriberBase
private readonly MareProfileManager _mareProfileManager; private readonly MareProfileManager _mareProfileManager;
private readonly UiBuilder _uiBuilder; private readonly UiBuilder _uiBuilder;
private readonly UiSharedService _uiSharedService; private readonly UiSharedService _uiSharedService;
private bool _adjustedForScollBarsLocalProfile = false;
private bool _adjustedForScollBarsOnlineProfile = false;
private string _descriptionText = string.Empty; private string _descriptionText = string.Empty;
private bool _loadedPrior = false;
private TextureWrap? _pfpTextureWrap; private TextureWrap? _pfpTextureWrap;
private string _profileDescription = string.Empty;
private byte[] _profileImage = Array.Empty<byte>();
private bool _showFileDialogError = false; private bool _showFileDialogError = false;
private bool _wasOpen; private bool _wasOpen;
@@ -57,55 +60,63 @@ public class EditProfileUi : WindowMediatorSubscriberBase
public override void Draw() public override void Draw()
{ {
_uiSharedService.BigText("Current Profile"); _uiSharedService.BigText("Current Profile (as saved on server)");
var (loaded, profile) = _mareProfileManager.GetMareProfile(new API.Data.UserData(_apiController.UID)); var profile = _mareProfileManager.GetMareProfile(new UserData(_apiController.UID));
if (!loaded) if (profile.IsFlagged)
{ {
_loadedPrior = false; UiSharedService.ColorTextWrapped(profile.Description, ImGuiColors.DalamudRed);
_descriptionText = string.Empty;
ImGui.TextUnformatted("Loading profile...");
return; return;
} }
else
{
if (profile.IsFlagged)
{
UiSharedService.ColorTextWrapped(profile.Description, ImGuiColors.DalamudRed);
return;
}
if (!_loadedPrior) if (!_profileImage.SequenceEqual(profile.ImageData.Value))
{ {
_descriptionText = profile.Description; _profileImage = profile.ImageData.Value;
_loadedPrior = true; _pfpTextureWrap?.Dispose();
_pfpTextureWrap?.Dispose(); _pfpTextureWrap = _uiBuilder.LoadImage(_profileImage);
_pfpTextureWrap = _uiBuilder.LoadImage(Convert.FromBase64String(profile.Base64ProfilePicture)); }
}
if (!string.Equals(_profileDescription, profile.Description, StringComparison.OrdinalIgnoreCase))
{
_profileDescription = profile.Description;
_descriptionText = _profileDescription;
} }
if (_pfpTextureWrap != null) if (_pfpTextureWrap != null)
{ {
ImGui.Image(_pfpTextureWrap.ImGuiHandle, new System.Numerics.Vector2(_pfpTextureWrap.Width, _pfpTextureWrap.Height)); ImGui.Image(_pfpTextureWrap.ImGuiHandle, ImGuiHelpers.ScaledVector2(_pfpTextureWrap.Width, _pfpTextureWrap.Height));
} }
var spacing = ImGui.GetStyle().ItemSpacing.X; var spacing = ImGui.GetStyle().ItemSpacing.X;
ImGui.SameLine(256 + spacing * 2); ImGui.SameLine(256 + spacing * 2);
var posX = ImGui.GetCursorPosX(); ImGui.PushFont(_uiBuilder.GetGameFontHandle(new GameFontStyle(GameFontFamilyAndSize.Axis12)).ImFont);
var width = UiSharedService.GetWindowContentRegionWidth() - posX + spacing * 2; var descriptionTextSize = ImGui.CalcTextSize(profile.Description, 256f);
if (ImGui.BeginChildFrame(100, new System.Numerics.Vector2(width, 256))) var childFrame = ImGuiHelpers.ScaledVector2(256 + ImGui.GetStyle().WindowPadding.X + ImGui.GetStyle().WindowBorderSize, 256);
if (descriptionTextSize.Y > childFrame.Y)
{ {
var nsfw = profile.IsNSFW; _adjustedForScollBarsOnlineProfile = true;
ImGui.BeginDisabled(); }
ImGui.Checkbox("Is NSFW", ref nsfw); else
ImGui.EndDisabled(); {
ImGui.NewLine(); _adjustedForScollBarsOnlineProfile = false;
ImGui.PushFont(_uiBuilder.GetGameFontHandle(new GameFontStyle(GameFontFamilyAndSize.Axis12)).ImFont); }
UiSharedService.TextWrapped("Description:" + Environment.NewLine + profile.Description); childFrame = childFrame with
ImGui.PopFont(); {
X = childFrame.X + (_adjustedForScollBarsOnlineProfile ? ImGui.GetStyle().ScrollbarSize : 0),
Y = childFrame.Y / ImGuiHelpers.GlobalScale
};
if (ImGui.BeginChildFrame(101, childFrame))
{
UiSharedService.TextWrapped(profile.Description);
} }
ImGui.EndChildFrame(); ImGui.EndChildFrame();
ImGui.PopFont();
var nsfw = profile.IsNSFW;
ImGui.BeginDisabled();
ImGui.Checkbox("Is NSFW", ref nsfw);
ImGui.EndDisabled();
ImGui.Separator(); ImGui.Separator();
_uiSharedService.BigText("Notes and Rules for Profiles"); _uiSharedService.BigText("Notes and Rules for Profiles");
@@ -166,11 +177,41 @@ public class EditProfileUi : WindowMediatorSubscriberBase
_ = _apiController.UserSetProfile(new UserProfileDto(new UserData(_apiController.UID), false, isNsfw, null, null)); _ = _apiController.UserSetProfile(new UserProfileDto(new UserData(_apiController.UID), false, isNsfw, null, null));
} }
UiSharedService.DrawHelpText("If your profile description or image can be considered NSFW, toggle this to ON"); UiSharedService.DrawHelpText("If your profile description or image can be considered NSFW, toggle this to ON");
var widthTextBox = UiSharedService.GetWindowContentRegionWidth() - posX + spacing; var widthTextBox = 400;
ImGui.TextUnformatted($"Description {_descriptionText.Length}/750"); var posX = ImGui.GetCursorPosX();
ImGui.TextUnformatted($"Description {_descriptionText.Length}/1500");
ImGui.SetCursorPosX(posX);
ImGuiHelpers.ScaledRelativeSameLine(widthTextBox, ImGui.GetStyle().ItemSpacing.X);
ImGui.TextUnformatted("Preview (approximate)");
ImGui.PushFont(_uiBuilder.GetGameFontHandle(new GameFontStyle(GameFontFamilyAndSize.Axis12)).ImFont); ImGui.PushFont(_uiBuilder.GetGameFontHandle(new GameFontStyle(GameFontFamilyAndSize.Axis12)).ImFont);
ImGui.InputTextMultiline("##description", ref _descriptionText, 750, new System.Numerics.Vector2(widthTextBox, 200)); ImGui.InputTextMultiline("##description", ref _descriptionText, 1500, ImGuiHelpers.ScaledVector2(widthTextBox, 200));
ImGui.PopFont(); ImGui.PopFont();
ImGui.SameLine();
ImGui.PushFont(_uiBuilder.GetGameFontHandle(new GameFontStyle(GameFontFamilyAndSize.Axis12)).ImFont);
var descriptionTextSizeLocal = ImGui.CalcTextSize(_descriptionText, 256f);
var childFrameLocal = ImGuiHelpers.ScaledVector2(256 + ImGui.GetStyle().WindowPadding.X + ImGui.GetStyle().WindowBorderSize, 200);
if (descriptionTextSizeLocal.Y > childFrameLocal.Y)
{
_adjustedForScollBarsLocalProfile = true;
}
else
{
_adjustedForScollBarsLocalProfile = false;
}
childFrameLocal = childFrameLocal with
{
X = childFrameLocal.X + (_adjustedForScollBarsLocalProfile ? ImGui.GetStyle().ScrollbarSize : 0),
Y = childFrameLocal.Y / ImGuiHelpers.GlobalScale
};
if (ImGui.BeginChildFrame(102, childFrameLocal))
{
UiSharedService.TextWrapped(_descriptionText);
}
ImGui.EndChildFrame();
ImGui.PopFont();
if (UiSharedService.IconTextButton(FontAwesomeIcon.Save, "Save Description")) if (UiSharedService.IconTextButton(FontAwesomeIcon.Save, "Save Description"))
{ {
_ = _apiController.UserSetProfile(new UserProfileDto(new UserData(_apiController.UID), false, null, null, _descriptionText)); _ = _apiController.UserSetProfile(new UserProfileDto(new UserData(_apiController.UID), false, null, null, _descriptionText));

View File

@@ -87,20 +87,20 @@ public class PopoutProfileUi : WindowMediatorSubscriberBase
var mareProfile = _mareProfileManager.GetMareProfile(_pair.UserData); var mareProfile = _mareProfileManager.GetMareProfile(_pair.UserData);
if (_textureWrap == null || !mareProfile.Profile.ImageData.Value.SequenceEqual(_lastProfilePicture)) if (_textureWrap == null || !mareProfile.ImageData.Value.SequenceEqual(_lastProfilePicture))
{ {
_textureWrap?.Dispose(); _textureWrap?.Dispose();
_lastProfilePicture = mareProfile.Profile.ImageData.Value; _lastProfilePicture = mareProfile.ImageData.Value;
_textureWrap = _uiSharedService.LoadImage(_lastProfilePicture); _textureWrap = _uiSharedService.LoadImage(_lastProfilePicture);
} }
if (_supporterTextureWrap == null || !mareProfile.Profile.SupporterImageData.Value.SequenceEqual(_lastSupporterPicture)) if (_supporterTextureWrap == null || !mareProfile.SupporterImageData.Value.SequenceEqual(_lastSupporterPicture))
{ {
_supporterTextureWrap?.Dispose(); _supporterTextureWrap?.Dispose();
_supporterTextureWrap = null; _supporterTextureWrap = null;
if (!string.IsNullOrEmpty(mareProfile.Profile.Base64SupporterPicture)) if (!string.IsNullOrEmpty(mareProfile.Base64SupporterPicture))
{ {
_lastSupporterPicture = mareProfile.Profile.SupporterImageData.Value; _lastSupporterPicture = mareProfile.SupporterImageData.Value;
_supporterTextureWrap = _uiSharedService.LoadImage(_lastSupporterPicture); _supporterTextureWrap = _uiSharedService.LoadImage(_lastSupporterPicture);
} }
} }
@@ -155,7 +155,7 @@ public class PopoutProfileUi : WindowMediatorSubscriberBase
ImGui.Separator(); ImGui.Separator();
ImGui.PushFont(_uiSharedService.GetGameFontHandle()); ImGui.PushFont(_uiSharedService.GetGameFontHandle());
var remaining = ImGui.GetWindowContentRegionMax().Y - ImGui.GetCursorPosY(); var remaining = ImGui.GetWindowContentRegionMax().Y - ImGui.GetCursorPosY();
var descText = mareProfile.Profile.Description; var descText = mareProfile.Description;
var textSize = ImGui.CalcTextSize(descText, 256f * ImGuiHelpers.GlobalScale); var textSize = ImGui.CalcTextSize(descText, 256f * ImGuiHelpers.GlobalScale);
bool trimmed = textSize.Y > remaining; bool trimmed = textSize.Y > remaining;
while (textSize.Y > remaining && descText.Contains(' ')) while (textSize.Y > remaining && descText.Contains(' '))
@@ -163,7 +163,7 @@ public class PopoutProfileUi : WindowMediatorSubscriberBase
descText = descText.Substring(0, descText.LastIndexOf(' ')).TrimEnd(); descText = descText.Substring(0, descText.LastIndexOf(' ')).TrimEnd();
textSize = ImGui.CalcTextSize(descText + $"...{Environment.NewLine}[Open Full Profile for complete description]", 256f * ImGuiHelpers.GlobalScale); textSize = ImGui.CalcTextSize(descText + $"...{Environment.NewLine}[Open Full Profile for complete description]", 256f * ImGuiHelpers.GlobalScale);
} }
UiSharedService.TextWrapped(trimmed ? descText + $"...{Environment.NewLine}[Open Full Profile for complete description]" : mareProfile.Profile.Description); UiSharedService.TextWrapped(trimmed ? descText + $"...{Environment.NewLine}[Open Full Profile for complete description]" : mareProfile.Description);
ImGui.PopFont(); ImGui.PopFont();
var padding = ImGui.GetStyle().WindowPadding.X / 2; var padding = ImGui.GetStyle().WindowPadding.X / 2;

View File

@@ -51,20 +51,20 @@ public class StandaloneProfileUi : WindowMediatorSubscriberBase
var mareProfile = _mareProfileManager.GetMareProfile(Pair.UserData); var mareProfile = _mareProfileManager.GetMareProfile(Pair.UserData);
if (_textureWrap == null || !mareProfile.Profile.ImageData.Value.SequenceEqual(_lastProfilePicture)) if (_textureWrap == null || !mareProfile.ImageData.Value.SequenceEqual(_lastProfilePicture))
{ {
_textureWrap?.Dispose(); _textureWrap?.Dispose();
_lastProfilePicture = mareProfile.Profile.ImageData.Value; _lastProfilePicture = mareProfile.ImageData.Value;
_textureWrap = _uiSharedService.LoadImage(_lastProfilePicture); _textureWrap = _uiSharedService.LoadImage(_lastProfilePicture);
} }
if (_supporterTextureWrap == null || !mareProfile.Profile.SupporterImageData.Value.SequenceEqual(_lastSupporterPicture)) if (_supporterTextureWrap == null || !mareProfile.SupporterImageData.Value.SequenceEqual(_lastSupporterPicture))
{ {
_supporterTextureWrap?.Dispose(); _supporterTextureWrap?.Dispose();
_supporterTextureWrap = null; _supporterTextureWrap = null;
if (!string.IsNullOrEmpty(mareProfile.Profile.Base64SupporterPicture)) if (!string.IsNullOrEmpty(mareProfile.Base64SupporterPicture))
{ {
_lastSupporterPicture = mareProfile.Profile.SupporterImageData.Value; _lastSupporterPicture = mareProfile.SupporterImageData.Value;
_supporterTextureWrap = _uiSharedService.LoadImage(_lastSupporterPicture); _supporterTextureWrap = _uiSharedService.LoadImage(_lastSupporterPicture);
} }
} }
@@ -84,7 +84,7 @@ public class StandaloneProfileUi : WindowMediatorSubscriberBase
ImGuiHelpers.ScaledDummy(new Vector2(256, 256 + spacing.Y)); ImGuiHelpers.ScaledDummy(new Vector2(256, 256 + spacing.Y));
var postDummy = ImGui.GetCursorPosY(); var postDummy = ImGui.GetCursorPosY();
ImGui.SameLine(); ImGui.SameLine();
var descriptionTextSize = ImGui.CalcTextSize(mareProfile.Profile.Description, 256f); var descriptionTextSize = ImGui.CalcTextSize(mareProfile.Description, 256f);
var descriptionChildHeight = rectMax.Y - pos.Y - rectMin.Y - spacing.Y * 2; var descriptionChildHeight = rectMax.Y - pos.Y - rectMin.Y - spacing.Y * 2;
if (descriptionTextSize.Y > descriptionChildHeight && !_adjustedForScrollBars) if (descriptionTextSize.Y > descriptionChildHeight && !_adjustedForScrollBars)
{ {
@@ -105,7 +105,7 @@ public class StandaloneProfileUi : WindowMediatorSubscriberBase
if (ImGui.BeginChildFrame(1000, childFrame)) if (ImGui.BeginChildFrame(1000, childFrame))
{ {
ImGui.PushFont(_uiSharedService.GetGameFontHandle()); ImGui.PushFont(_uiSharedService.GetGameFontHandle());
ImGui.TextWrapped(mareProfile.Profile.Description); ImGui.TextWrapped(mareProfile.Description);
ImGui.PopFont(); ImGui.PopFont();
} }
ImGui.EndChildFrame(); ImGui.EndChildFrame();