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

View File

@@ -20,9 +20,12 @@ public class EditProfileUi : WindowMediatorSubscriberBase
private readonly MareProfileManager _mareProfileManager;
private readonly UiBuilder _uiBuilder;
private readonly UiSharedService _uiSharedService;
private bool _adjustedForScollBarsLocalProfile = false;
private bool _adjustedForScollBarsOnlineProfile = false;
private string _descriptionText = string.Empty;
private bool _loadedPrior = false;
private TextureWrap? _pfpTextureWrap;
private string _profileDescription = string.Empty;
private byte[] _profileImage = Array.Empty<byte>();
private bool _showFileDialogError = false;
private bool _wasOpen;
@@ -57,55 +60,63 @@ public class EditProfileUi : WindowMediatorSubscriberBase
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;
_descriptionText = string.Empty;
ImGui.TextUnformatted("Loading profile...");
UiSharedService.ColorTextWrapped(profile.Description, ImGuiColors.DalamudRed);
return;
}
else
{
if (profile.IsFlagged)
{
UiSharedService.ColorTextWrapped(profile.Description, ImGuiColors.DalamudRed);
return;
}
if (!_loadedPrior)
{
_descriptionText = profile.Description;
_loadedPrior = true;
_pfpTextureWrap?.Dispose();
_pfpTextureWrap = _uiBuilder.LoadImage(Convert.FromBase64String(profile.Base64ProfilePicture));
}
if (!_profileImage.SequenceEqual(profile.ImageData.Value))
{
_profileImage = profile.ImageData.Value;
_pfpTextureWrap?.Dispose();
_pfpTextureWrap = _uiBuilder.LoadImage(_profileImage);
}
if (!string.Equals(_profileDescription, profile.Description, StringComparison.OrdinalIgnoreCase))
{
_profileDescription = profile.Description;
_descriptionText = _profileDescription;
}
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;
ImGui.SameLine(256 + spacing * 2);
var posX = ImGui.GetCursorPosX();
var width = UiSharedService.GetWindowContentRegionWidth() - posX + spacing * 2;
if (ImGui.BeginChildFrame(100, new System.Numerics.Vector2(width, 256)))
ImGui.PushFont(_uiBuilder.GetGameFontHandle(new GameFontStyle(GameFontFamilyAndSize.Axis12)).ImFont);
var descriptionTextSize = ImGui.CalcTextSize(profile.Description, 256f);
var childFrame = ImGuiHelpers.ScaledVector2(256 + ImGui.GetStyle().WindowPadding.X + ImGui.GetStyle().WindowBorderSize, 256);
if (descriptionTextSize.Y > childFrame.Y)
{
var nsfw = profile.IsNSFW;
ImGui.BeginDisabled();
ImGui.Checkbox("Is NSFW", ref nsfw);
ImGui.EndDisabled();
ImGui.NewLine();
ImGui.PushFont(_uiBuilder.GetGameFontHandle(new GameFontStyle(GameFontFamilyAndSize.Axis12)).ImFont);
UiSharedService.TextWrapped("Description:" + Environment.NewLine + profile.Description);
ImGui.PopFont();
_adjustedForScollBarsOnlineProfile = true;
}
else
{
_adjustedForScollBarsOnlineProfile = false;
}
childFrame = childFrame with
{
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.PopFont();
var nsfw = profile.IsNSFW;
ImGui.BeginDisabled();
ImGui.Checkbox("Is NSFW", ref nsfw);
ImGui.EndDisabled();
ImGui.Separator();
_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));
}
UiSharedService.DrawHelpText("If your profile description or image can be considered NSFW, toggle this to ON");
var widthTextBox = UiSharedService.GetWindowContentRegionWidth() - posX + spacing;
ImGui.TextUnformatted($"Description {_descriptionText.Length}/750");
var widthTextBox = 400;
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.InputTextMultiline("##description", ref _descriptionText, 750, new System.Numerics.Vector2(widthTextBox, 200));
ImGui.InputTextMultiline("##description", ref _descriptionText, 1500, ImGuiHelpers.ScaledVector2(widthTextBox, 200));
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"))
{
_ = _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);
if (_textureWrap == null || !mareProfile.Profile.ImageData.Value.SequenceEqual(_lastProfilePicture))
if (_textureWrap == null || !mareProfile.ImageData.Value.SequenceEqual(_lastProfilePicture))
{
_textureWrap?.Dispose();
_lastProfilePicture = mareProfile.Profile.ImageData.Value;
_lastProfilePicture = mareProfile.ImageData.Value;
_textureWrap = _uiSharedService.LoadImage(_lastProfilePicture);
}
if (_supporterTextureWrap == null || !mareProfile.Profile.SupporterImageData.Value.SequenceEqual(_lastSupporterPicture))
if (_supporterTextureWrap == null || !mareProfile.SupporterImageData.Value.SequenceEqual(_lastSupporterPicture))
{
_supporterTextureWrap?.Dispose();
_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);
}
}
@@ -155,7 +155,7 @@ public class PopoutProfileUi : WindowMediatorSubscriberBase
ImGui.Separator();
ImGui.PushFont(_uiSharedService.GetGameFontHandle());
var remaining = ImGui.GetWindowContentRegionMax().Y - ImGui.GetCursorPosY();
var descText = mareProfile.Profile.Description;
var descText = mareProfile.Description;
var textSize = ImGui.CalcTextSize(descText, 256f * ImGuiHelpers.GlobalScale);
bool trimmed = textSize.Y > remaining;
while (textSize.Y > remaining && descText.Contains(' '))
@@ -163,7 +163,7 @@ public class PopoutProfileUi : WindowMediatorSubscriberBase
descText = descText.Substring(0, descText.LastIndexOf(' ')).TrimEnd();
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();
var padding = ImGui.GetStyle().WindowPadding.X / 2;

View File

@@ -51,20 +51,20 @@ public class StandaloneProfileUi : WindowMediatorSubscriberBase
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();
_lastProfilePicture = mareProfile.Profile.ImageData.Value;
_lastProfilePicture = mareProfile.ImageData.Value;
_textureWrap = _uiSharedService.LoadImage(_lastProfilePicture);
}
if (_supporterTextureWrap == null || !mareProfile.Profile.SupporterImageData.Value.SequenceEqual(_lastSupporterPicture))
if (_supporterTextureWrap == null || !mareProfile.SupporterImageData.Value.SequenceEqual(_lastSupporterPicture))
{
_supporterTextureWrap?.Dispose();
_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);
}
}
@@ -84,7 +84,7 @@ public class StandaloneProfileUi : WindowMediatorSubscriberBase
ImGuiHelpers.ScaledDummy(new Vector2(256, 256 + spacing.Y));
var postDummy = ImGui.GetCursorPosY();
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;
if (descriptionTextSize.Y > descriptionChildHeight && !_adjustedForScrollBars)
{
@@ -105,7 +105,7 @@ public class StandaloneProfileUi : WindowMediatorSubscriberBase
if (ImGui.BeginChildFrame(1000, childFrame))
{
ImGui.PushFont(_uiSharedService.GetGameFontHandle());
ImGui.TextWrapped(mareProfile.Profile.Description);
ImGui.TextWrapped(mareProfile.Description);
ImGui.PopFont();
}
ImGui.EndChildFrame();