-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2ced4ab
commit 01ddf8a
Showing
32 changed files
with
1,917 additions
and
2 deletions.
There are no files selected for viewing
170 changes: 170 additions & 0 deletions
170
OpenRA.Mods.Common/EditorBrushes/EditorMirrorLayerBrush.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
#region Copyright & License Information | ||
/* | ||
* Copyright (c) The OpenRA Developers and Contributors | ||
* This file is part of OpenRA, which is free software. It is made | ||
* available to you under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation, either version 3 of | ||
* the License, or (at your option) any later version. For more | ||
* information, see COPYING. | ||
*/ | ||
#endregion | ||
|
||
using OpenRA.Graphics; | ||
using OpenRA.Mods.Common.Traits; | ||
using static OpenRA.Mods.Common.Traits.MirrorLayerOverlay; | ||
|
||
namespace OpenRA.Mods.Common.Widgets | ||
{ | ||
public sealed class EditorMirrorLayerBrush : IEditorBrush | ||
{ | ||
public readonly int Template; | ||
|
||
readonly WorldRenderer worldRenderer; | ||
readonly World world; | ||
readonly EditorActionManager editorActionManager; | ||
readonly MirrorLayerOverlay mirrorLayerOverlay; | ||
readonly EditorViewportControllerWidget editorWidget; | ||
|
||
bool painting; | ||
|
||
public EditorMirrorLayerBrush(EditorViewportControllerWidget editorWidget, int id, WorldRenderer wr) | ||
{ | ||
this.editorWidget = editorWidget; | ||
worldRenderer = wr; | ||
world = wr.World; | ||
|
||
editorActionManager = world.WorldActor.Trait<EditorActionManager>(); | ||
mirrorLayerOverlay = world.WorldActor.Trait<MirrorLayerOverlay>(); | ||
|
||
Template = id; | ||
worldRenderer = wr; | ||
world = wr.World; | ||
} | ||
|
||
public bool HandleMouseInput(MouseInput mi) | ||
{ | ||
if (mi.Button != MouseButton.Left && mi.Button != MouseButton.Right) | ||
return false; | ||
|
||
if (mi.Button == MouseButton.Right) | ||
{ | ||
if (mi.Event == MouseInputEvent.Up) | ||
{ | ||
editorWidget.ClearBrush(); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
if (mi.Button == MouseButton.Left) | ||
{ | ||
if (mi.Event == MouseInputEvent.Down) | ||
painting = true; | ||
else if (mi.Event == MouseInputEvent.Up) | ||
painting = false; | ||
} | ||
|
||
if (!painting) | ||
return true; | ||
|
||
if (mi.Event != MouseInputEvent.Down && mi.Event != MouseInputEvent.Move) | ||
return true; | ||
|
||
var cell = worldRenderer.Viewport.ViewToWorld(mi.Location); | ||
if (!world.Map.Contains(cell)) | ||
return false; | ||
|
||
PaintCell(cell); | ||
|
||
return true; | ||
} | ||
|
||
void PaintCell(CPos cell) | ||
{ | ||
var current = mirrorLayerOverlay.CellLayer[cell]; | ||
if (current != Template) | ||
{ | ||
editorActionManager.Add(new PaintMirrorTileEditorAction( | ||
Template, | ||
cell, | ||
mirrorLayerOverlay)); | ||
} | ||
} | ||
|
||
public void Tick() { } | ||
|
||
public void Dispose() { } | ||
} | ||
|
||
class PaintMirrorTileEditorAction : IEditorAction | ||
{ | ||
[TranslationReference("type")] | ||
const string AddedMirrorTile = "notification-added-mirror-tile"; | ||
|
||
public string Text { get; } | ||
|
||
readonly int type; | ||
readonly MirrorTileMode mode; | ||
readonly int numSides; | ||
readonly int axisAngle; | ||
readonly MirrorLayerOverlay mirrorLayerOverlay; | ||
readonly CPos[] targetCells; | ||
readonly int?[] previousTypes; | ||
|
||
public PaintMirrorTileEditorAction( | ||
int type, | ||
CPos cell, | ||
MirrorLayerOverlay mirrorLayerOverlay) | ||
{ | ||
this.mirrorLayerOverlay = mirrorLayerOverlay; | ||
this.type = type; | ||
mode = mirrorLayerOverlay.MirrorMode; | ||
numSides = mirrorLayerOverlay.NumSides; | ||
axisAngle = mirrorLayerOverlay.AxisAngle; | ||
targetCells = mirrorLayerOverlay.CalculateMirrorPositions(cell); | ||
|
||
previousTypes = new int?[targetCells.Length]; | ||
for (var i = 0; i < targetCells.Length; i++) | ||
{ | ||
var targetCell = targetCells[i]; | ||
previousTypes[i] = mirrorLayerOverlay.CellLayer[targetCell]; | ||
} | ||
|
||
Text = TranslationProvider.GetString(AddedMirrorTile, | ||
Translation.Arguments("type", type)); | ||
} | ||
|
||
public void Execute() | ||
{ | ||
Do(); | ||
} | ||
|
||
public void Do() | ||
{ | ||
mirrorLayerOverlay.SetMirrorMode(mode); | ||
mirrorLayerOverlay.NumSides = numSides; | ||
mirrorLayerOverlay.AxisAngle = axisAngle; | ||
|
||
for (var i = 0; i < targetCells.Length; i++) | ||
{ | ||
var targetCell = targetCells[i]; | ||
mirrorLayerOverlay.SetTile(targetCell, type); | ||
} | ||
} | ||
|
||
public void Undo() | ||
{ | ||
mirrorLayerOverlay.SetMirrorMode(mode); | ||
mirrorLayerOverlay.NumSides = numSides; | ||
mirrorLayerOverlay.AxisAngle = axisAngle; | ||
|
||
for (var i = 0; i < targetCells.Length; i++) | ||
{ | ||
var targetCell = targetCells[i]; | ||
var previousType = previousTypes[i]; | ||
mirrorLayerOverlay.SetTile(targetCell, previousType); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.