Fixed bugs with placement grid showing up on double-clicking object.
This commit is contained in:
parent
1b1f1686d4
commit
2f92167e28
@ -906,7 +906,8 @@ namespace MobiusEditor
|
|||||||
bool isTdMegaMap = false;
|
bool isTdMegaMap = false;
|
||||||
using (NewMapDialog nmd = new NewMapDialog(withImage))
|
using (NewMapDialog nmd = new NewMapDialog(withImage))
|
||||||
{
|
{
|
||||||
if (nmd.ShowDialog() != DialogResult.OK)
|
nmd.StartPosition = FormStartPosition.CenterParent;
|
||||||
|
if (nmd.ShowDialog(this) != DialogResult.OK)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -951,6 +952,7 @@ namespace MobiusEditor
|
|||||||
if (!IdentifyMap(name, out FileType fileType, out GameType gameType, out bool isTdMegaMap))
|
if (!IdentifyMap(name, out FileType fileType, out GameType gameType, out bool isTdMegaMap))
|
||||||
{
|
{
|
||||||
string extension = Path.GetExtension(name).TrimStart('.');
|
string extension = Path.GetExtension(name).TrimStart('.');
|
||||||
|
// No point in supporting jpeg here; the mapping needs distinct colours without fades.
|
||||||
if ("PNG".Equals(extension, StringComparison.OrdinalIgnoreCase)
|
if ("PNG".Equals(extension, StringComparison.OrdinalIgnoreCase)
|
||||||
|| "BMP".Equals(extension, StringComparison.OrdinalIgnoreCase)
|
|| "BMP".Equals(extension, StringComparison.OrdinalIgnoreCase)
|
||||||
|| "GIF".Equals(extension, StringComparison.OrdinalIgnoreCase)
|
|| "GIF".Equals(extension, StringComparison.OrdinalIgnoreCase)
|
||||||
|
@ -47,7 +47,7 @@ namespace MobiusEditor.Tools
|
|||||||
|
|
||||||
protected override Boolean InPlacementMode
|
protected override Boolean InPlacementMode
|
||||||
{
|
{
|
||||||
get { return placementMode || selectedBuildingLocation.HasValue; }
|
get { return placementMode || startedDragging; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly Building mockBuilding;
|
private readonly Building mockBuilding;
|
||||||
@ -56,6 +56,8 @@ namespace MobiusEditor.Tools
|
|||||||
private Point? selectedBuildingLocation;
|
private Point? selectedBuildingLocation;
|
||||||
private Dictionary<Point, Smudge> selectedBuildingEatenSmudge;
|
private Dictionary<Point, Smudge> selectedBuildingEatenSmudge;
|
||||||
private Point selectedBuildingPivot;
|
private Point selectedBuildingPivot;
|
||||||
|
private bool startedDragging;
|
||||||
|
|
||||||
private ObjectPropertiesPopup selectedObjectProperties;
|
private ObjectPropertiesPopup selectedObjectProperties;
|
||||||
|
|
||||||
private BuildingType selectedBuildingType;
|
private BuildingType selectedBuildingType;
|
||||||
@ -118,6 +120,8 @@ namespace MobiusEditor.Tools
|
|||||||
selectedBuilding = null;
|
selectedBuilding = null;
|
||||||
selectedBuildingLocation = null;
|
selectedBuildingLocation = null;
|
||||||
selectedBuildingPivot = Point.Empty;
|
selectedBuildingPivot = Point.Empty;
|
||||||
|
startedDragging = false;
|
||||||
|
mapPanel.Invalidate();
|
||||||
Building preEdit = building.Clone();
|
Building preEdit = building.Clone();
|
||||||
selectedObjectProperties?.Close();
|
selectedObjectProperties?.Close();
|
||||||
selectedObjectProperties = new ObjectPropertiesPopup(objectProperties.Plugin, building);
|
selectedObjectProperties = new ObjectPropertiesPopup(objectProperties.Plugin, building);
|
||||||
@ -259,6 +263,7 @@ namespace MobiusEditor.Tools
|
|||||||
selectedBuilding = null;
|
selectedBuilding = null;
|
||||||
selectedBuildingLocation = null;
|
selectedBuildingLocation = null;
|
||||||
selectedBuildingPivot = Point.Empty;
|
selectedBuildingPivot = Point.Empty;
|
||||||
|
startedDragging = false;
|
||||||
mapPanel.Invalidate();
|
mapPanel.Invalidate();
|
||||||
UpdateStatus();
|
UpdateStatus();
|
||||||
}
|
}
|
||||||
@ -336,6 +341,11 @@ namespace MobiusEditor.Tools
|
|||||||
}
|
}
|
||||||
else if (selectedBuilding != null)
|
else if (selectedBuilding != null)
|
||||||
{
|
{
|
||||||
|
if (!startedDragging && selectedBuildingLocation.HasValue
|
||||||
|
&& new Point(selectedBuildingLocation.Value.X + selectedBuildingPivot.X, selectedBuildingLocation.Value.Y + selectedBuildingPivot.Y) != e.NewCell)
|
||||||
|
{
|
||||||
|
startedDragging = true;
|
||||||
|
}
|
||||||
Building toMove = selectedBuilding;
|
Building toMove = selectedBuilding;
|
||||||
var oldLocation = map.Technos[toMove].Value;
|
var oldLocation = map.Technos[toMove].Value;
|
||||||
var newLocation = new Point(Math.Max(0, e.NewCell.X - selectedBuildingPivot.X), Math.Max(0, e.NewCell.Y - selectedBuildingPivot.Y));
|
var newLocation = new Point(Math.Max(0, e.NewCell.X - selectedBuildingPivot.X), Math.Max(0, e.NewCell.Y - selectedBuildingPivot.Y));
|
||||||
@ -406,10 +416,18 @@ namespace MobiusEditor.Tools
|
|||||||
|
|
||||||
private void AddBuilding(Point location)
|
private void AddBuilding(Point location)
|
||||||
{
|
{
|
||||||
|
if (!map.Metrics.Contains(location))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (SelectedBuildingType == null)
|
if (SelectedBuildingType == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
selectedBuilding = null;
|
||||||
|
selectedBuildingLocation = null;
|
||||||
|
selectedBuildingPivot = Point.Empty;
|
||||||
|
startedDragging = false;
|
||||||
var building = mockBuilding.Clone();
|
var building = mockBuilding.Clone();
|
||||||
if (!map.Technos.CanAdd(location, building, building.Type.BaseOccupyMask))
|
if (!map.Technos.CanAdd(location, building, building.Type.BaseOccupyMask))
|
||||||
{
|
{
|
||||||
@ -430,9 +448,6 @@ namespace MobiusEditor.Tools
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
selectedBuilding = null;
|
|
||||||
selectedBuildingLocation = null;
|
|
||||||
selectedBuildingPivot = Point.Empty;
|
|
||||||
if (map.Buildings.Add(location, building))
|
if (map.Buildings.Add(location, building))
|
||||||
{
|
{
|
||||||
Building[] baseBuildings = null;
|
Building[] baseBuildings = null;
|
||||||
@ -643,6 +658,7 @@ namespace MobiusEditor.Tools
|
|||||||
selectedBuilding = null;
|
selectedBuilding = null;
|
||||||
selectedBuildingLocation = null;
|
selectedBuildingLocation = null;
|
||||||
selectedBuildingPivot = Point.Empty;
|
selectedBuildingPivot = Point.Empty;
|
||||||
|
startedDragging = false;
|
||||||
if (map.Metrics.GetCell(location, out int cell))
|
if (map.Metrics.GetCell(location, out int cell))
|
||||||
{
|
{
|
||||||
Building selected = map.Buildings[cell] as Building;
|
Building selected = map.Buildings[cell] as Building;
|
||||||
|
@ -47,7 +47,7 @@ namespace MobiusEditor.Tools
|
|||||||
|
|
||||||
protected override Boolean InPlacementMode
|
protected override Boolean InPlacementMode
|
||||||
{
|
{
|
||||||
get { return placementMode || selectedInfantryLocation.HasValue; }
|
get { return placementMode || startedDragging; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly Infantry mockInfantry;
|
private readonly Infantry mockInfantry;
|
||||||
@ -55,6 +55,7 @@ namespace MobiusEditor.Tools
|
|||||||
private Infantry selectedInfantry;
|
private Infantry selectedInfantry;
|
||||||
private Point? selectedInfantryLocation;
|
private Point? selectedInfantryLocation;
|
||||||
private int selectedInfantryStop = -1;
|
private int selectedInfantryStop = -1;
|
||||||
|
private bool startedDragging;
|
||||||
private ObjectPropertiesPopup selectedObjectProperties;
|
private ObjectPropertiesPopup selectedObjectProperties;
|
||||||
|
|
||||||
private InfantryType selectedInfantryType;
|
private InfantryType selectedInfantryType;
|
||||||
@ -163,6 +164,9 @@ namespace MobiusEditor.Tools
|
|||||||
{
|
{
|
||||||
selectedInfantry = null;
|
selectedInfantry = null;
|
||||||
selectedInfantryLocation = null;
|
selectedInfantryLocation = null;
|
||||||
|
selectedInfantryStop = -1;
|
||||||
|
startedDragging = false;
|
||||||
|
mapPanel.Invalidate();
|
||||||
Infantry preEdit = infantry.Clone();
|
Infantry preEdit = infantry.Clone();
|
||||||
selectedObjectProperties?.Close();
|
selectedObjectProperties?.Close();
|
||||||
selectedObjectProperties = new ObjectPropertiesPopup(objectProperties.Plugin, infantry);
|
selectedObjectProperties = new ObjectPropertiesPopup(objectProperties.Plugin, infantry);
|
||||||
@ -274,14 +278,19 @@ namespace MobiusEditor.Tools
|
|||||||
}
|
}
|
||||||
else if (selectedInfantry != null)
|
else if (selectedInfantry != null)
|
||||||
{
|
{
|
||||||
|
Point curCell = navigationWidget.MouseCell;
|
||||||
Point oldLocation = map.Technos[selectedInfantry.InfantryGroup].Value;
|
Point oldLocation = map.Technos[selectedInfantry.InfantryGroup].Value;
|
||||||
|
if (!startedDragging && selectedInfantryLocation.HasValue && selectedInfantryLocation.Value != curCell)
|
||||||
|
{
|
||||||
|
startedDragging = true;
|
||||||
|
}
|
||||||
int oldStop = selectedInfantry.InfantryGroup.GetLocation(selectedInfantry);
|
int oldStop = selectedInfantry.InfantryGroup.GetLocation(selectedInfantry);
|
||||||
InfantryGroup infantryGroup = null;
|
InfantryGroup infantryGroup = null;
|
||||||
var techno = map.Technos[navigationWidget.MouseCell];
|
var techno = map.Technos[curCell];
|
||||||
if (techno == null)
|
if (techno == null)
|
||||||
{
|
{
|
||||||
infantryGroup = new InfantryGroup();
|
infantryGroup = new InfantryGroup();
|
||||||
map.Technos.Add(navigationWidget.MouseCell, infantryGroup);
|
map.Technos.Add(curCell, infantryGroup);
|
||||||
}
|
}
|
||||||
else if (techno is InfantryGroup)
|
else if (techno is InfantryGroup)
|
||||||
{
|
{
|
||||||
@ -309,6 +318,10 @@ namespace MobiusEditor.Tools
|
|||||||
}
|
}
|
||||||
if (infantryGroup == selectedInfantry.InfantryGroup)
|
if (infantryGroup == selectedInfantry.InfantryGroup)
|
||||||
{
|
{
|
||||||
|
if (!startedDragging && selectedInfantryStop != i)
|
||||||
|
{
|
||||||
|
startedDragging = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -351,6 +364,7 @@ namespace MobiusEditor.Tools
|
|||||||
selectedInfantry = null;
|
selectedInfantry = null;
|
||||||
selectedInfantryLocation = null;
|
selectedInfantryLocation = null;
|
||||||
selectedInfantryStop = -1;
|
selectedInfantryStop = -1;
|
||||||
|
startedDragging = false;
|
||||||
mapPanel.Invalidate();
|
mapPanel.Invalidate();
|
||||||
UpdateStatus();
|
UpdateStatus();
|
||||||
}
|
}
|
||||||
@ -450,14 +464,18 @@ namespace MobiusEditor.Tools
|
|||||||
|
|
||||||
private void AddInfantry(Point location)
|
private void AddInfantry(Point location)
|
||||||
{
|
{
|
||||||
if (SelectedInfantryType == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!map.Metrics.GetCell(location, out int cell))
|
if (!map.Metrics.GetCell(location, out int cell))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (SelectedInfantryType == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
selectedInfantry = null;
|
||||||
|
selectedInfantryLocation = null;
|
||||||
|
selectedInfantryStop = -1;
|
||||||
|
startedDragging = false;
|
||||||
InfantryGroup infantryGroup = null;
|
InfantryGroup infantryGroup = null;
|
||||||
var techno = map.Technos[cell];
|
var techno = map.Technos[cell];
|
||||||
if (techno == null)
|
if (techno == null)
|
||||||
|
@ -47,7 +47,7 @@ namespace MobiusEditor.Tools
|
|||||||
|
|
||||||
protected override Boolean InPlacementMode
|
protected override Boolean InPlacementMode
|
||||||
{
|
{
|
||||||
get { return placementMode || selectedTerrainLocation.HasValue; }
|
get { return placementMode || startedDragging; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly Terrain mockTerrain;
|
private readonly Terrain mockTerrain;
|
||||||
@ -55,9 +55,11 @@ namespace MobiusEditor.Tools
|
|||||||
private Terrain selectedTerrain;
|
private Terrain selectedTerrain;
|
||||||
private Point? selectedTerrainLocation;
|
private Point? selectedTerrainLocation;
|
||||||
private Point selectedTerrainPivot;
|
private Point selectedTerrainPivot;
|
||||||
|
private bool startedDragging;
|
||||||
|
|
||||||
|
private TerrainPropertiesPopup selectedTerrainProperties;
|
||||||
|
|
||||||
private TerrainType selectedTerrainType;
|
private TerrainType selectedTerrainType;
|
||||||
private TerrainPropertiesPopup selectedTerrainProperties;
|
|
||||||
private TerrainType SelectedTerrainType
|
private TerrainType SelectedTerrainType
|
||||||
{
|
{
|
||||||
get => selectedTerrainType;
|
get => selectedTerrainType;
|
||||||
@ -118,6 +120,8 @@ namespace MobiusEditor.Tools
|
|||||||
selectedTerrain = null;
|
selectedTerrain = null;
|
||||||
selectedTerrainLocation = null;
|
selectedTerrainLocation = null;
|
||||||
selectedTerrainPivot = Point.Empty;
|
selectedTerrainPivot = Point.Empty;
|
||||||
|
startedDragging = false;
|
||||||
|
mapPanel.Invalidate();
|
||||||
selectedTerrainProperties?.Close();
|
selectedTerrainProperties?.Close();
|
||||||
// only TD supports triggers ("Attacked" type) on terrain types.
|
// only TD supports triggers ("Attacked" type) on terrain types.
|
||||||
if (plugin.GameType == GameType.TiberianDawn)
|
if (plugin.GameType == GameType.TiberianDawn)
|
||||||
@ -235,6 +239,7 @@ namespace MobiusEditor.Tools
|
|||||||
selectedTerrain = null;
|
selectedTerrain = null;
|
||||||
selectedTerrainLocation = null;
|
selectedTerrainLocation = null;
|
||||||
selectedTerrainPivot = Point.Empty;
|
selectedTerrainPivot = Point.Empty;
|
||||||
|
startedDragging = false;
|
||||||
mapPanel.Invalidate();
|
mapPanel.Invalidate();
|
||||||
UpdateStatus();
|
UpdateStatus();
|
||||||
}
|
}
|
||||||
@ -298,6 +303,11 @@ namespace MobiusEditor.Tools
|
|||||||
}
|
}
|
||||||
else if (selectedTerrain != null)
|
else if (selectedTerrain != null)
|
||||||
{
|
{
|
||||||
|
if (!startedDragging && selectedTerrainLocation.HasValue
|
||||||
|
&& new Point(selectedTerrainLocation.Value.X + selectedTerrainPivot.X, selectedTerrainLocation.Value.Y + selectedTerrainPivot.Y) != e.NewCell)
|
||||||
|
{
|
||||||
|
startedDragging = true;
|
||||||
|
}
|
||||||
Terrain toMove = selectedTerrain;
|
Terrain toMove = selectedTerrain;
|
||||||
var oldLocation = map.Technos[toMove].Value;
|
var oldLocation = map.Technos[toMove].Value;
|
||||||
var newLocation = new Point(Math.Max(0, e.NewCell.X - selectedTerrainPivot.X), Math.Max(0, e.NewCell.Y - selectedTerrainPivot.Y));
|
var newLocation = new Point(Math.Max(0, e.NewCell.X - selectedTerrainPivot.X), Math.Max(0, e.NewCell.Y - selectedTerrainPivot.Y));
|
||||||
@ -324,34 +334,39 @@ namespace MobiusEditor.Tools
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (SelectedTerrainType != null)
|
if (SelectedTerrainType == null)
|
||||||
{
|
{
|
||||||
var terrain = mockTerrain.Clone();
|
return;
|
||||||
if (map.Technos.Add(location, terrain))
|
}
|
||||||
|
selectedTerrain = null;
|
||||||
|
selectedTerrainLocation = null;
|
||||||
|
selectedTerrainPivot = Point.Empty;
|
||||||
|
startedDragging = false;
|
||||||
|
var terrain = mockTerrain.Clone();
|
||||||
|
if (map.Technos.Add(location, terrain))
|
||||||
|
{
|
||||||
|
bool origDirtyState = plugin.Dirty;
|
||||||
|
plugin.Dirty = true;
|
||||||
|
mapPanel.Invalidate(map, terrain);
|
||||||
|
void undoAction(UndoRedoEventArgs e)
|
||||||
{
|
{
|
||||||
bool origDirtyState = plugin.Dirty;
|
e.MapPanel.Invalidate(e.Map, location);
|
||||||
plugin.Dirty = true;
|
e.Map.Technos.Remove(terrain);
|
||||||
mapPanel.Invalidate(map, terrain);
|
if (e.Plugin != null)
|
||||||
void undoAction(UndoRedoEventArgs e)
|
|
||||||
{
|
{
|
||||||
e.MapPanel.Invalidate(e.Map, location);
|
e.Plugin.Dirty = origDirtyState;
|
||||||
e.Map.Technos.Remove(terrain);
|
|
||||||
if (e.Plugin != null)
|
|
||||||
{
|
|
||||||
e.Plugin.Dirty = origDirtyState;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
void redoAction(UndoRedoEventArgs e)
|
|
||||||
{
|
|
||||||
e.Map.Technos.Add(location, terrain);
|
|
||||||
e.MapPanel.Invalidate(e.Map, location);
|
|
||||||
if (e.Plugin != null)
|
|
||||||
{
|
|
||||||
e.Plugin.Dirty = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
url.Track(undoAction, redoAction);
|
|
||||||
}
|
}
|
||||||
|
void redoAction(UndoRedoEventArgs e)
|
||||||
|
{
|
||||||
|
e.Map.Technos.Add(location, terrain);
|
||||||
|
e.MapPanel.Invalidate(e.Map, location);
|
||||||
|
if (e.Plugin != null)
|
||||||
|
{
|
||||||
|
e.Plugin.Dirty = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
url.Track(undoAction, redoAction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -433,6 +448,7 @@ namespace MobiusEditor.Tools
|
|||||||
selectedTerrain = null;
|
selectedTerrain = null;
|
||||||
selectedTerrainLocation = null;
|
selectedTerrainLocation = null;
|
||||||
selectedTerrainPivot = Point.Empty;
|
selectedTerrainPivot = Point.Empty;
|
||||||
|
startedDragging = false;
|
||||||
if (map.Metrics.GetCell(location, out int cell) && map.Technos[cell] is Terrain selected && selected != null)
|
if (map.Metrics.GetCell(location, out int cell) && map.Technos[cell] is Terrain selected && selected != null)
|
||||||
{
|
{
|
||||||
Point? selectedLocation = map.Technos[selected];
|
Point? selectedLocation = map.Technos[selected];
|
||||||
|
@ -47,13 +47,15 @@ namespace MobiusEditor.Tools
|
|||||||
|
|
||||||
protected override Boolean InPlacementMode
|
protected override Boolean InPlacementMode
|
||||||
{
|
{
|
||||||
get { return placementMode || selectedUnitLocation.HasValue; }
|
get { return placementMode || startedDragging; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly Unit mockUnit;
|
private readonly Unit mockUnit;
|
||||||
|
|
||||||
private Unit selectedUnit;
|
private Unit selectedUnit;
|
||||||
private Point? selectedUnitLocation;
|
private Point? selectedUnitLocation;
|
||||||
|
private bool startedDragging;
|
||||||
|
|
||||||
private ObjectPropertiesPopup selectedObjectProperties;
|
private ObjectPropertiesPopup selectedObjectProperties;
|
||||||
|
|
||||||
private UnitType selectedUnitType;
|
private UnitType selectedUnitType;
|
||||||
@ -156,6 +158,8 @@ namespace MobiusEditor.Tools
|
|||||||
{
|
{
|
||||||
selectedUnit = null;
|
selectedUnit = null;
|
||||||
selectedUnitLocation = null;
|
selectedUnitLocation = null;
|
||||||
|
startedDragging = false;
|
||||||
|
mapPanel.Invalidate();
|
||||||
Unit preEdit = unit.Clone();
|
Unit preEdit = unit.Clone();
|
||||||
selectedObjectProperties?.Close();
|
selectedObjectProperties?.Close();
|
||||||
selectedObjectProperties = new ObjectPropertiesPopup(objectProperties.Plugin, unit);
|
selectedObjectProperties = new ObjectPropertiesPopup(objectProperties.Plugin, unit);
|
||||||
@ -292,6 +296,7 @@ namespace MobiusEditor.Tools
|
|||||||
AddMoveUndoTracking(selectedUnit, selectedUnitLocation.Value);
|
AddMoveUndoTracking(selectedUnit, selectedUnitLocation.Value);
|
||||||
selectedUnit = null;
|
selectedUnit = null;
|
||||||
selectedUnitLocation = null;
|
selectedUnitLocation = null;
|
||||||
|
startedDragging = false;
|
||||||
mapPanel.Invalidate();
|
mapPanel.Invalidate();
|
||||||
UpdateStatus();
|
UpdateStatus();
|
||||||
}
|
}
|
||||||
@ -344,16 +349,21 @@ namespace MobiusEditor.Tools
|
|||||||
}
|
}
|
||||||
else if (selectedUnit != null)
|
else if (selectedUnit != null)
|
||||||
{
|
{
|
||||||
var oldLocation = map.Technos[selectedUnit].Value;
|
if (!startedDragging && selectedUnitLocation.HasValue && selectedUnitLocation.Value != e.NewCell)
|
||||||
mapPanel.Invalidate(map, selectedUnit);
|
|
||||||
map.Technos.Remove(selectedUnit);
|
|
||||||
if (map.Technos.Add(e.NewCell, selectedUnit))
|
|
||||||
{
|
{
|
||||||
mapPanel.Invalidate(map, selectedUnit);
|
startedDragging = true;
|
||||||
|
}
|
||||||
|
Unit toMove = selectedUnit;
|
||||||
|
var oldLocation = map.Technos[toMove].Value;
|
||||||
|
mapPanel.Invalidate(map, toMove);
|
||||||
|
map.Technos.Remove(toMove);
|
||||||
|
if (map.Technos.Add(e.NewCell, toMove))
|
||||||
|
{
|
||||||
|
mapPanel.Invalidate(map, toMove);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
map.Technos.Add(oldLocation, selectedUnit);
|
map.Technos.Add(oldLocation, toMove);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (e.MouseButtons == MouseButtons.Right)
|
else if (e.MouseButtons == MouseButtons.Right)
|
||||||
@ -364,34 +374,42 @@ namespace MobiusEditor.Tools
|
|||||||
|
|
||||||
private void AddUnit(Point location)
|
private void AddUnit(Point location)
|
||||||
{
|
{
|
||||||
if (SelectedUnitType != null)
|
if (!map.Metrics.Contains(location))
|
||||||
{
|
{
|
||||||
var unit = mockUnit.Clone();
|
return;
|
||||||
if (map.Technos.Add(location, unit))
|
}
|
||||||
|
if (SelectedUnitType == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
selectedUnit = null;
|
||||||
|
selectedUnitLocation = null;
|
||||||
|
startedDragging = false;
|
||||||
|
var unit = mockUnit.Clone();
|
||||||
|
if (map.Technos.Add(location, unit))
|
||||||
|
{
|
||||||
|
bool origDirtyState = plugin.Dirty;
|
||||||
|
plugin.Dirty = true;
|
||||||
|
mapPanel.Invalidate(map, unit);
|
||||||
|
void undoAction(UndoRedoEventArgs e)
|
||||||
{
|
{
|
||||||
bool origDirtyState = plugin.Dirty;
|
e.MapPanel.Invalidate(e.Map, unit);
|
||||||
plugin.Dirty = true;
|
e.Map.Technos.Remove(unit);
|
||||||
mapPanel.Invalidate(map, unit);
|
if (e.Plugin != null)
|
||||||
void undoAction(UndoRedoEventArgs e)
|
|
||||||
{
|
{
|
||||||
e.MapPanel.Invalidate(e.Map, unit);
|
e.Plugin.Dirty = origDirtyState;
|
||||||
e.Map.Technos.Remove(unit);
|
|
||||||
if (e.Plugin != null)
|
|
||||||
{
|
|
||||||
e.Plugin.Dirty = origDirtyState;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
void redoAction(UndoRedoEventArgs e)
|
|
||||||
{
|
|
||||||
e.Map.Technos.Add(location, unit);
|
|
||||||
e.MapPanel.Invalidate(e.Map, unit);
|
|
||||||
if (e.Plugin != null)
|
|
||||||
{
|
|
||||||
e.Plugin.Dirty = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
url.Track(undoAction, redoAction);
|
|
||||||
}
|
}
|
||||||
|
void redoAction(UndoRedoEventArgs e)
|
||||||
|
{
|
||||||
|
e.Map.Technos.Add(location, unit);
|
||||||
|
e.MapPanel.Invalidate(e.Map, unit);
|
||||||
|
if (e.Plugin != null)
|
||||||
|
{
|
||||||
|
e.Plugin.Dirty = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
url.Track(undoAction, redoAction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -475,6 +493,7 @@ namespace MobiusEditor.Tools
|
|||||||
{
|
{
|
||||||
selectedUnit = null;
|
selectedUnit = null;
|
||||||
selectedUnitLocation = null;
|
selectedUnitLocation = null;
|
||||||
|
startedDragging = false;
|
||||||
if (map.Metrics.GetCell(location, out int cell))
|
if (map.Metrics.GetCell(location, out int cell))
|
||||||
{
|
{
|
||||||
Unit selected = map.Technos[cell] as Unit;
|
Unit selected = map.Technos[cell] as Unit;
|
||||||
|
@ -52,22 +52,22 @@ namespace MobiusEditor.Utility
|
|||||||
image.UnlockBits(sourceData);
|
image.UnlockBits(sourceData);
|
||||||
// Binarization: get brightness
|
// Binarization: get brightness
|
||||||
Single[,] brightness = new Single[height, width];
|
Single[,] brightness = new Single[height, width];
|
||||||
Int32 offset = 0;
|
Int32 lineOffset = 0;
|
||||||
for (Int32 y = 0; y < height; ++y)
|
for (Int32 y = 0; y < height; ++y)
|
||||||
{
|
{
|
||||||
// use stride to get the start offset of each line
|
// use stride to get the start offset of each line
|
||||||
Int32 usedOffset = offset;
|
Int32 offset = lineOffset;
|
||||||
for (Int32 x = 0; x < width; ++x)
|
for (Int32 x = 0; x < width; ++x)
|
||||||
{
|
{
|
||||||
// get colour
|
// get colour
|
||||||
Byte blu = data[usedOffset + 0];
|
Byte blu = data[offset + 0];
|
||||||
Byte grn = data[usedOffset + 1];
|
Byte grn = data[offset + 1];
|
||||||
Byte red = data[usedOffset + 2];
|
Byte red = data[offset + 2];
|
||||||
Color c = Color.FromArgb(red, grn, blu);
|
Color c = Color.FromArgb(red, grn, blu);
|
||||||
brightness[y, x] = c.GetBrightness();
|
brightness[y, x] = c.GetBrightness();
|
||||||
usedOffset += 4;
|
offset += 4;
|
||||||
}
|
}
|
||||||
offset += stride;
|
lineOffset += stride;
|
||||||
}
|
}
|
||||||
Func<Single[,], Int32, Int32, Boolean> clearsThreshold;
|
Func<Single[,], Int32, Int32, Boolean> clearsThreshold;
|
||||||
if (detectDark)
|
if (detectDark)
|
||||||
@ -111,7 +111,7 @@ namespace MobiusEditor.Utility
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Detects a list of all blobs in the image, and merges any with bounds that intersect with each other according to the 'mergeThreshold' parameter.
|
/// Detects a list of all blobs in the image, and merges any with bounds that intersect with each other according to the 'mergeThreshold' parameter.
|
||||||
/// Returns the result as Boolean[,] array.
|
/// Returns the results as Boolean[,] arrays.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">Type of the list to detect equal neighbours in.</typeparam>
|
/// <typeparam name="T">Type of the list to detect equal neighbours in.</typeparam>
|
||||||
/// <param name="data">Image data array. It is processed as one pixel per coordinate.</param>
|
/// <param name="data">Image data array. It is processed as one pixel per coordinate.</param>
|
||||||
@ -164,7 +164,7 @@ namespace MobiusEditor.Utility
|
|||||||
public static List<List<Point>> FindBlobs<T>(T data, Int32 width, Int32 height, Func<T, Int32, Int32, Boolean> clearsThreshold, Boolean allEightEdges, Boolean getEdgesOnly, out List<Boolean[,]> inBlobs, out Boolean[,] inAnyBlob)
|
public static List<List<Point>> FindBlobs<T>(T data, Int32 width, Int32 height, Func<T, Int32, Int32, Boolean> clearsThreshold, Boolean allEightEdges, Boolean getEdgesOnly, out List<Boolean[,]> inBlobs, out Boolean[,] inAnyBlob)
|
||||||
{
|
{
|
||||||
List<List<Point>> blobs = new List<List<Point>>();
|
List<List<Point>> blobs = new List<List<Point>>();
|
||||||
inAnyBlob = new Boolean[height,width];
|
inAnyBlob = new Boolean[height, width];
|
||||||
inBlobs = new List<Boolean[,]>();
|
inBlobs = new List<Boolean[,]>();
|
||||||
for (Int32 y = 0; y < height; ++y)
|
for (Int32 y = 0; y < height; ++y)
|
||||||
{
|
{
|
||||||
@ -392,7 +392,7 @@ namespace MobiusEditor.Utility
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the list of neighbouring points around one point in an image.
|
/// Gets the list of neighbouring points around one point in an image that are inside the full image bounds.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="x">X-coordinate of the point to get neighbours of.</param>
|
/// <param name="x">X-coordinate of the point to get neighbours of.</param>
|
||||||
/// <param name="y">Y-coordinate of the point to get neighbours of.</param>
|
/// <param name="y">Y-coordinate of the point to get neighbours of.</param>
|
||||||
|
@ -294,13 +294,17 @@ namespace MobiusEditor.Utility
|
|||||||
public static Color[] FindMostCommonColors(int amount, byte[] imageData, int width, int height, int stride)
|
public static Color[] FindMostCommonColors(int amount, byte[] imageData, int width, int height, int stride)
|
||||||
{
|
{
|
||||||
// Store colour frequencies in a dictionary.
|
// Store colour frequencies in a dictionary.
|
||||||
|
if (amount < 0)
|
||||||
|
amount = Int32.MaxValue;
|
||||||
Dictionary<Color, Int32> colorFreq = new Dictionary<Color, Int32>();
|
Dictionary<Color, Int32> colorFreq = new Dictionary<Color, Int32>();
|
||||||
|
Int32 lineStart = 0;
|
||||||
for (Int32 y = 0; y < height; ++y)
|
for (Int32 y = 0; y < height; ++y)
|
||||||
{
|
{
|
||||||
// Reset offset on every line, since stride is not guaranteed to always be width * pixel size.
|
// Reset offset on every line, since stride is not guaranteed to always be width * pixel size.
|
||||||
Int32 inputOffs = y * stride;
|
Int32 inputOffs = lineStart;
|
||||||
//Final offset = y * line length in bytes + x * pixel length in bytes.
|
//Final offset = y * linelength + x * pixellength.
|
||||||
//To avoid recalculating that offset each time we just increase it with the pixel size at the end of each x iteration.
|
// To avoid recalculating that offset each time we just increase it with the pixel size at the end of each x iteration,
|
||||||
|
// and increase the line start with the stride at the end of each y iteration.
|
||||||
for (Int32 x = 0; x < width; ++x)
|
for (Int32 x = 0; x < width; ++x)
|
||||||
{
|
{
|
||||||
//Get colour components out. "ARGB" is actually the order in the final integer which is read as little-endian, so the real order is BGRA.
|
//Get colour components out. "ARGB" is actually the order in the final integer which is read as little-endian, so the real order is BGRA.
|
||||||
@ -318,6 +322,7 @@ namespace MobiusEditor.Utility
|
|||||||
// Increase the offset by the pixel width. For 32bpp ARGB, each pixel is 4 bytes.
|
// Increase the offset by the pixel width. For 32bpp ARGB, each pixel is 4 bytes.
|
||||||
inputOffs += 4;
|
inputOffs += 4;
|
||||||
}
|
}
|
||||||
|
lineStart += stride;
|
||||||
}
|
}
|
||||||
// Get the maximum value in the dictionary values
|
// Get the maximum value in the dictionary values
|
||||||
return colorFreq.OrderByDescending(kvp => kvp.Value).Select(kvp => kvp.Key).Take(amount).ToArray();
|
return colorFreq.OrderByDescending(kvp => kvp.Value).Select(kvp => kvp.Key).Take(amount).ToArray();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user