Skip to content

Commit

Permalink
Prompt about unsaved changes in LandBrush Manager
Browse files Browse the repository at this point in the history
  • Loading branch information
kaczy93 committed Oct 8, 2024
1 parent fd80ada commit bfb4d22
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions CentrED/UI/Windows/LandBrushManagerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class LandBrushManagerWindow : Window

private static readonly Vector2 ComboFramePadding = ImGui.GetStyle().FramePadding with{ Y = (float)((HalfSize.Y - ImGui.GetTextLineHeight()) * 0.5) };

private bool _unsavedChanges;

protected override void InternalDraw()
{
if (!CEDGame.MapManager.Client.Initialized)
Expand All @@ -42,9 +44,17 @@ protected override void InternalDraw()

DrawImport();

ImGui.BeginDisabled(!_unsavedChanges);
if (ImGui.Button("Save"))
{
ProfileManager.Save();
_unsavedChanges = false;
}
ImGui.EndDisabled();
if (_unsavedChanges)
{
ImGui.SameLine();
ImGui.TextColored(UIManager.Green, "Unsaved Changes");
}
ImGui.Separator();

Expand Down Expand Up @@ -175,6 +185,7 @@ private void DrawFullTiles()
{
Selected.Tiles.Remove(fullTile);
CEDGame.MapManager.RemoveLandBrushEntry(fullTile, _selectedLandBrushName, _selectedLandBrushName);
_unsavedChanges = true;
}
ImGui.PopStyleColor(2);
ImGui.Text($"0x{fullTile:X4}");
Expand All @@ -195,6 +206,7 @@ private void DrawFullTiles()
{
Selected.Tiles.Add(id);
CEDGame.MapManager.AddLandBrushEntry(id, _selectedLandBrushName, _selectedLandBrushName);
_unsavedChanges = true;
}
}
}
Expand Down Expand Up @@ -244,6 +256,7 @@ private void DrawTransitions()
{
transitions.Remove(transition);
CEDGame.MapManager.RemoveLandBrushEntry(transition.TileID, _selectedLandBrushName, _selectedTransitionBrushName);
_unsavedChanges = true;
}
ImGui.PopStyleColor(2);
ImGui.Text($"0x{transition.TileID:X4}");
Expand Down Expand Up @@ -287,6 +300,7 @@ private void DrawTransitions()
{
transitions.Add(new LandBrushTransition(id));
CEDGame.MapManager.AddLandBrushEntry(id, _selectedLandBrushName, _selectedTransitionBrushName);
_unsavedChanges = true;
}
}
}
Expand All @@ -308,6 +322,7 @@ private void ToggleDirButton(LandBrushTransition transition, Direction dir, (nin
{
transition.Direction |= dir;
}
_unsavedChanges = true;
}
UIManager.Tooltip(isSet ? _selectedTransitionBrushName : _selectedLandBrushName);
}
Expand Down Expand Up @@ -342,6 +357,7 @@ private void DrawBrushPopups()
_selectedLandBrushName = _landBrushNewName;
_selectedTransitionBrushName = Selected.Transitions.Keys.FirstOrDefault("");
_landBrushNewName = "";
_unsavedChanges = true;
ImGui.CloseCurrentPopup();
}
}
Expand All @@ -366,6 +382,7 @@ private void DrawBrushPopups()
_landBrushes.Remove(Selected.Name);
_selectedLandBrushName = _landBrushes.Keys.FirstOrDefault("");
_selectedTransitionBrushName = Selected?.Transitions.Keys.FirstOrDefault("") ?? "";
_unsavedChanges = true;
ImGui.CloseCurrentPopup();
}
ImGui.SameLine();
Expand All @@ -392,6 +409,7 @@ private void DrawTransitionPopups()
Selected.Transitions.Add(_transitionAddName, new List<LandBrushTransition>());
_selectedTransitionBrushName = _transitionAddName;
_transitionAddName = "";
_unsavedChanges = true;
ImGui.CloseCurrentPopup();
}
ImGui.EndDisabled();
Expand All @@ -415,6 +433,7 @@ private void DrawTransitionPopups()
else
_selectedTransitionBrushName = "";
_selectedTransitionBrushName = Selected.Transitions.Keys.FirstOrDefault("");
_unsavedChanges = true;
ImGui.CloseCurrentPopup();
}
ImGui.SameLine();
Expand Down

0 comments on commit bfb4d22

Please sign in to comment.