Skip to content

Commit

Permalink
Large Amount of Changes, Preparing for the "FOOLS" Update
Browse files Browse the repository at this point in the history
  • Loading branch information
CarJem committed Apr 1, 2020
1 parent 96dce19 commit fbc30ed
Show file tree
Hide file tree
Showing 58 changed files with 1,985 additions and 1,886 deletions.
2 changes: 1 addition & 1 deletion ManiacEditor/Actions/ActionEntityPropertyChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ActionEntityPropertyChange : IAction
object newValue;
Action<EditorEntity, string, object, object> setValue;

public string Description => $"Changing {tag} on {entity.Object.Name} from {oldValue} to {newValue}";
public string Description => $"Changing {tag} on {entity.Object.Name} from {(oldValue == null ? "UNKNOWN" : oldValue)} to {newValue}";

public ActionEntityPropertyChange(EditorEntity entity, string tag, object oldValue, object newValue, Action<EditorEntity, string, object, object> setValue)
{
Expand Down
33 changes: 23 additions & 10 deletions ManiacEditor/Actions/ActionSwapSlotIDs.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,48 @@
using RSDKv5;
using System;
using ManiacEditor.Classes.Scene;

namespace ManiacEditor.Actions
{
class ActionSwapSlotIDs : IAction
{
SceneEntity EntityA;
SceneEntity EntityB;
ushort SlotA;
ushort SlotB;
Action<SceneEntity, SceneEntity, ushort, ushort> setValue;
EditorEntity EntityA;
EditorEntity EntityB;

ushort SlotA
{
get
{
return EntityA.SlotID;
}
}
ushort SlotB
{
get
{
return EntityB.SlotID;
}
}

Action<EditorEntity, EditorEntity> setValue;

public string Description => $"Swap SlotID's of {EntityA.Object.Name.Name} ({SlotA}) and {EntityB.Object.Name.Name} ({SlotB})";

public ActionSwapSlotIDs(SceneEntity entityA, SceneEntity entityB, ushort slotA, ushort slotB, Action<SceneEntity, SceneEntity, ushort, ushort> setValue)
public ActionSwapSlotIDs(EditorEntity entityA, EditorEntity entityB, Action<EditorEntity, EditorEntity> setValue)
{
this.EntityA = entityA;
this.EntityB = entityB;
this.SlotA = slotA;
this.SlotB = slotB;
this.setValue = setValue;
}

public void Undo()
{
setValue(EntityA, EntityB, SlotB, SlotA);
setValue(EntityA, EntityB);
}

public IAction Redo()
{
return new ActionSwapSlotIDs(EntityA, EntityB, SlotB, SlotA, setValue);
return new ActionSwapSlotIDs(EntityA, EntityB, setValue);
}
}
}
106 changes: 106 additions & 0 deletions ManiacEditor/Actions/UndoRedoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,111 @@ public static class UndoRedoModel
{
public static Stack<IAction> UndoStack { get; set; } = new Stack<IAction>(); //Undo Actions Stack
public static Stack<IAction> RedoStack { get; set; } = new Stack<IAction>(); //Redo Actions Stack

public static void UpdateLastEntityAction()
{
if (Methods.Editor.Solution.Entities.LastAction != null || Methods.Editor.Solution.Entities.LastActionInternal != null) Actions.UndoRedoModel.RedoStack.Clear();
if (Methods.Editor.Solution.Entities.LastAction != null)
{
Actions.UndoRedoModel.UndoStack.Push(Methods.Editor.Solution.Entities.LastAction);
Methods.Editor.Solution.Entities.LastAction = null;
}
if (Methods.Editor.Solution.Entities.LastActionInternal != null)
{
Actions.UndoRedoModel.UndoStack.Push(Methods.Editor.Solution.Entities.LastActionInternal);
Methods.Editor.Solution.Entities.LastActionInternal = null;
}
if (Methods.Editor.Solution.Entities.LastAction != null || Methods.Editor.Solution.Entities.LastActionInternal != null) Methods.Internal.UserInterface.UpdateControls();

}
public static void UpdateEditEntitiesActions()
{
if (ManiacEditor.Methods.Editor.SolutionState.IsEntitiesEdit())
{
if (Methods.Editor.Solution.Entities.SelectedEntities.Count > 0)
{
IAction action = new ActionMoveEntities(Methods.Editor.Solution.Entities.SelectedEntities.ToList(), new System.Drawing.Point(Methods.Editor.SolutionState.DraggedX, Methods.Editor.SolutionState.DraggedY));
if (Methods.Editor.Solution.Entities.LastAction != null)
{
// If it is move & duplicate, merge them together
var taction = new ActionsGroup();
taction.AddAction(Methods.Editor.Solution.Entities.LastAction);
Methods.Editor.Solution.Entities.LastAction = null;
taction.AddAction(action);
taction.Close();
action = taction;
}
Actions.UndoRedoModel.UndoStack.Push(action);
Actions.UndoRedoModel.RedoStack.Clear();
Methods.Internal.UserInterface.UpdateControls();
}
if (Methods.Editor.Solution.Entities.SelectedInternalEntities.Count > 0)
{
IAction action = new ActionMoveEntities(Methods.Editor.Solution.Entities.SelectedInternalEntities.ToList(), new System.Drawing.Point(Methods.Editor.SolutionState.DraggedX, Methods.Editor.SolutionState.DraggedY));
if (Methods.Editor.Solution.Entities.LastActionInternal != null)
{
// If it is move & duplicate, merge them together
var taction = new ActionsGroup();
taction.AddAction(Methods.Editor.Solution.Entities.LastActionInternal);
Methods.Editor.Solution.Entities.LastActionInternal = null;
taction.AddAction(action);
taction.Close();
action = taction;
}
Actions.UndoRedoModel.UndoStack.Push(action);
Actions.UndoRedoModel.RedoStack.Clear();
Methods.Internal.UserInterface.UpdateControls();
}
}
}
public static void UpdateEditLayerActions()
{
if (Methods.Editor.Solution.EditLayerA != null)
{
List<IAction> actions = Methods.Editor.Solution.EditLayerA?.Actions;
if (actions.Count > 0) Actions.UndoRedoModel.RedoStack.Clear();
while (actions.Count > 0)
{
bool create_new = false;
if (Actions.UndoRedoModel.UndoStack.Count == 0 || !(Actions.UndoRedoModel.UndoStack.Peek() is ActionsGroup))
{
create_new = true;
}
else
{
create_new = (Actions.UndoRedoModel.UndoStack.Peek() as ActionsGroup).IsClosed;
}
if (create_new)
{
Actions.UndoRedoModel.UndoStack.Push(new ActionsGroup());
}
(Actions.UndoRedoModel.UndoStack.Peek() as ActionsGroup).AddAction(actions[0]);
actions.RemoveAt(0);
}
}
if (Methods.Editor.Solution.EditLayerB != null)
{
List<IAction> actions = Methods.Editor.Solution.EditLayerB?.Actions;
if (actions.Count > 0) Actions.UndoRedoModel.RedoStack.Clear();
while (actions.Count > 0)
{
bool create_new = false;
if (Actions.UndoRedoModel.UndoStack.Count == 0 || !(Actions.UndoRedoModel.UndoStack.Peek() is ActionsGroup))
{
create_new = true;
}
else
{
create_new = (Actions.UndoRedoModel.UndoStack.Peek() as ActionsGroup).IsClosed;
}
if (create_new)
{
Actions.UndoRedoModel.UndoStack.Push(new ActionsGroup());
}
(Actions.UndoRedoModel.UndoStack.Peek() as ActionsGroup).AddAction(actions[0]);
actions.RemoveAt(0);
}
}
}
}
}
47 changes: 47 additions & 0 deletions ManiacEditor/Classes/General/SceneSelectCategoriesCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ManiacEditor.Classes.General
{
public class SceneSelectCategoriesCollection
{
public List<SceneSelectCategory> Items { get; set; } = new List<SceneSelectCategory>();

public void Clear()
{
Items.Clear();
}

public void Add(string _name, List<SceneSelectScene> _entries)
{
Items.Add(new SceneSelectCategory(_name, _entries));
}
}

public class SceneSelectCategory
{
public string Name { get; set; }
public List<SceneSelectScene> Entries { get; set; } = new List<SceneSelectScene>();

public SceneSelectCategory(string _name, List<SceneSelectScene> _entries)
{
Name = _name;
Entries = _entries;
}
}

public struct SceneSelectScene
{
public string Name { get; set; }
public string Path { get; set; }

public SceneSelectScene(string _name, string _path)
{
Name = _name;
Path = _path;
}
}
}
21 changes: 21 additions & 0 deletions ManiacEditor/Classes/General/SceneSelectDirectoriesCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RSDKv5;

namespace ManiacEditor.Classes.General
{
public struct SceneSelectDirectory
{
public string Name { get; set; }
public Tuple<Gameconfig.SceneInfo,string> SceneInfo { get; set; }

public SceneSelectDirectory(string _name, Gameconfig.SceneInfo _sceneInfo, string _path)
{
Name = _name;
SceneInfo = new Tuple<Gameconfig.SceneInfo, string>(_sceneInfo, _path);
}
}
}
42 changes: 40 additions & 2 deletions ManiacEditor/Classes/Rendering/LayerTileProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class LayerTileProvider
public LayerRenderer MapRenderTileID { get; set; }
public LayerRenderer MapRenderCollisionMapA { get; set; }
public LayerRenderer MapRenderCollisionMapB { get; set; }
public LayerRenderer MapRenderSelected { get; set; }

#endregion

Expand Down Expand Up @@ -124,6 +125,33 @@ public void TileProvider(int x, int y, int layer, double Zoom, out SFML.Graphics



}
public void TileSelectedProvider(int x, int y, int layer, double Zoom, out SFML.Graphics.Color color, out IntRect rec)
{
if (IsTileWithinRange(x, y))
{
Point point = new Point(x, y);
if (IsTileSelected(point))
{
rec = GetTileSelectedRect();
color = new SFML.Graphics.Color(255, 0, 0, (byte)ParentLayer.RenderingTransparency);
}
else
{
rec = GetNullTileProviderRect();
color = GetNullTileProviderColor();
}

}
else
{
rec = GetNullTileProviderRect();
color = GetNullTileProviderColor();
}




}
public void TileCollisionProviderA(int x, int y, int layer, double Zoom, out SFML.Graphics.Color color, out IntRect rec)
{
Expand Down Expand Up @@ -184,6 +212,17 @@ public IntRect GetNullTileProviderRect()
{
return new IntRect(0, 0, 16, 16);
}
private IntRect GetTileSelectedRect()
{
int tile_size = Methods.Editor.EditorConstants.TILE_SIZE;
int tile_texture_y = 1 * tile_size;
int rect_x = 0;
int rect_y = tile_texture_y;
int rect_width = tile_size;
int rect_height = tile_size;

return new IntRect(rect_x, rect_y, rect_width, rect_height);
}
private IntRect GetTileRect(ushort tile, double zoom, bool FlipGuideMode = false)
{
int index = (tile & 0x3ff);
Expand Down Expand Up @@ -246,8 +285,7 @@ private IntRect GetTileRect(ushort tile, double zoom, bool FlipGuideMode = false

private SFML.Graphics.Color GetNormalColors(Point point, ushort value)
{
if (IsTileSelected(point)) return new SFML.Graphics.Color(255, 0, 0, (byte)ParentLayer.RenderingTransparency);
else return new SFML.Graphics.Color(255, 255, 255, (byte)ParentLayer.RenderingTransparency);
return new SFML.Graphics.Color(255, 255, 255, (byte)ParentLayer.RenderingTransparency);
}
public SFML.Graphics.Color GetNullTileProviderColor()
{
Expand Down
24 changes: 15 additions & 9 deletions ManiacEditor/Classes/Scene/EditorChunks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,10 @@ public void DuplicateChunk(int ChunkIndex)
}
public void AutoGenerateChunks(Classes.Scene.EditorLayer LayerA)
{
Methods.Internal.UserInterface.UpdateWaitingScreen(true);
Methods.Internal.UserInterface.ToggleEditorButtons(false);

Methods.Internal.UserInterface.LockUserInterface = true;
Methods.Internal.UserInterface.ShowWaitScreen = true;
Methods.Internal.UserInterface.UpdateControls();

System.Threading.Thread thread = new System.Threading.Thread(() => {
int width = LayerA.Width;
Expand Down Expand Up @@ -306,17 +308,20 @@ public void AutoGenerateChunks(Classes.Scene.EditorLayer LayerA)
if (duplicate == false) AddChunk(newChunk);
}
}
Instance.Dispatcher.Invoke(new Action(() => Methods.Internal.UserInterface.UpdateWaitingScreen(false)));
Instance.Dispatcher.Invoke(new Action(() => Methods.Internal.UserInterface.ToggleEditorButtons(true)));

Instance.Dispatcher.Invoke(new Action(() => Methods.Internal.UserInterface.LockUserInterface = false));
Instance.Dispatcher.Invoke(new Action(() => Methods.Internal.UserInterface.ShowWaitScreen = false));
Instance.Dispatcher.Invoke(new Action(() => Methods.Internal.UserInterface.UpdateControls()));

})
{ IsBackground = true };
thread.Start();
}
public void AutoGenerateChunks(Classes.Scene.EditorLayer LayerA, Classes.Scene.EditorLayer LayerB)
{
Methods.Internal.UserInterface.UpdateWaitingScreen(true);
Methods.Internal.UserInterface.ToggleEditorButtons(false);
Methods.Internal.UserInterface.LockUserInterface = true;
Methods.Internal.UserInterface.ShowWaitScreen = true;
Methods.Internal.UserInterface.UpdateControls();

System.Threading.Thread thread = new System.Threading.Thread(() => {
int width = (LayerA.Width > LayerB.Width ? LayerA.Width : LayerB.Width);
Expand Down Expand Up @@ -352,8 +357,9 @@ public void AutoGenerateChunks(Classes.Scene.EditorLayer LayerA, Classes.Scene.E
if (duplicate == false) AddChunk(newChunk);
}
}
Instance.Dispatcher.Invoke(new Action(() => Methods.Internal.UserInterface.UpdateWaitingScreen(false)));
Instance.Dispatcher.Invoke(new Action(() => Methods.Internal.UserInterface.ToggleEditorButtons(true)));
Instance.Dispatcher.Invoke(new Action(() => Methods.Internal.UserInterface.LockUserInterface = false));
Instance.Dispatcher.Invoke(new Action(() => Methods.Internal.UserInterface.ShowWaitScreen = false));
Instance.Dispatcher.Invoke(new Action(() => Methods.Internal.UserInterface.UpdateControls()));

})
{ IsBackground = true };
Expand Down Expand Up @@ -555,7 +561,7 @@ public void PasteStamp(Point ChunkCoord, int index, Classes.Scene.EditorLayer Ed

EditLayerA?.PasteFromClipboard(TileCoord, ConvertedChunkA);
EditLayerB?.PasteFromClipboard(TileCoord, ConvertedChunkB);
Methods.Internal.UserInterface.UpdateEditLayerActions();
Actions.UndoRedoModel.UpdateEditLayerActions();
EditLayerA?.Deselect();
EditLayerB?.Deselect();
}
Expand Down
Loading

0 comments on commit fbc30ed

Please sign in to comment.