* The tool windows will now remember what was last selected in them when they are reselecting or reloaded.

* The selected House will now be retained across the infantry, units, and structures tools.
This commit is contained in:
Nyerguds 2023-07-09 03:35:22 +02:00
parent e4991b2539
commit dedb50be55
18 changed files with 248 additions and 19 deletions

View File

@ -476,6 +476,8 @@ Feature updates:
* Units, buildings and waypoints with a radius will now show that radius more clearly in placement preview mode.
* Red Alert data concerning rules.ini data, and map tileset data (dimensions, tile usage, land types) is now read from the original classic files.
* Changing rules will now only clear undo/redo history if bibs were actually changed.
* The tool windows will now remember what was last selected in them when they are reselecting or reloaded.
* The selected House will now be retained across the infantry, units, and structures tools.
Map logic updates:

View File

@ -47,6 +47,9 @@ namespace MobiusEditor.Interface
/// <summary>The game type as enum.</summary>
GameType GameType { get; }
/// <summary>Currently edited house.</summary>
HouseType ActiveHouse { get; set; }
/// <summary>True if the plugin is initialised to handle a megamap.</summary>
bool IsMegaMap { get; }

View File

@ -21,8 +21,9 @@ namespace MobiusEditor.Interface
public interface ITool : IDisposable
{
MapLayerFlag Layers { get; set; }
IGamePlugin Plugin { get; }
NavigationWidget NavigationWidget { get; }
Object CurrentObject { get; set; }
void Activate();
void Deactivate();

View File

@ -1947,6 +1947,13 @@ namespace MobiusEditor
if (toolDialog != null)
{
activeToolForm = (Form)toolDialog;
ITool oldTool = toolDialog.GetTool();
Object mockObject = null;
if (oldTool != null && oldTool.Plugin == plugin)
{
// Same map edit session; restore old data
mockObject = oldTool.CurrentObject;
}
// Creates the actual Tool class
toolDialog.Initialize(mapPanel, active, toolStatusLabel, mouseToolTip, plugin, url);
activeTool = toolDialog.GetTool();
@ -1955,6 +1962,9 @@ namespace MobiusEditor
activeToolForm.Shown += this.ActiveToolForm_Shown;
activeToolForm.Show(this);
activeTool.Activate();
// Ensures that the active house is set in the tool.
// Only set this after activation, so the mock object's PropertyChanged event is active.
activeTool.CurrentObject = mockObject ?? activeTool.CurrentObject;
activeToolForm.ResizeEnd += ActiveToolForm_ResizeEnd;
}
if (plugin.IsMegaMap)

View File

@ -269,6 +269,8 @@ namespace MobiusEditor.RedAlert
public GameType GameType => GameType.RedAlert;
public HouseType ActiveHouse { get; set; }
public bool IsMegaMap => true;
public Map Map { get; }

View File

@ -228,6 +228,8 @@ namespace MobiusEditor.TiberianDawn
public virtual GameType GameType => GameType.TiberianDawn;
public virtual HouseType ActiveHouse { get; set; }
public virtual bool IsMegaMap => isMegaMap;
public virtual Map Map { get; protected set; }

View File

@ -37,6 +37,23 @@ namespace MobiusEditor.Tools
private Map previewMap;
protected override Map RenderMap => previewMap;
public override Object CurrentObject
{
get { return mockBuilding; }
set
{
if (value is Building bld)
{
if (plugin.ActiveHouse != null)
{
bld.House = plugin.ActiveHouse;
}
SelectedBuildingType = bld.Type;
mockBuilding.CloneDataFrom(bld);
}
}
}
/// <summary>
/// Layers that are not painted by the PostRenderMap function on ViewTool level because they are handled
/// at a specific point in the PostRenderMap override by the implementing tool.
@ -79,7 +96,7 @@ namespace MobiusEditor.Tools
mapPanel.Invalidate(map, new Rectangle(navigationWidget.MouseCell, selectedBuildingType.OverlapBounds.Size));
}
mockBuilding.Type = selectedBuildingType;
// No need to call 'RefreshPreviewPanel()'; it is triggered through MockBuilding_PropertyChanged.
RefreshPreviewPanel();
}
}
}
@ -95,7 +112,6 @@ namespace MobiusEditor.Tools
Strength = 256,
Direction = map.BuildingDirectionTypes.Where(d => d.Equals(FacingType.North)).First()
};
mockBuilding.PropertyChanged += MockBuilding_PropertyChanged;
this.buildingTypesBox = buildingTypesBox;
this.buildingTypesBox.SelectedIndexChanged += BuildingTypeComboBox_SelectedIndexChanged;
this.buildingTypeMapPanel = buildingTypeMapPanel;
@ -186,6 +202,10 @@ namespace MobiusEditor.Tools
{
mockBuilding.Direction = map.BuildingDirectionTypes.Where(d => d.Equals(FacingType.North)).First();
}
if (e.PropertyName == "House")
{
plugin.ActiveHouse = mockBuilding.House;
}
RefreshPreviewPanel();
}
@ -886,6 +906,7 @@ namespace MobiusEditor.Tools
{
base.Activate();
this.Deactivate(true);
mockBuilding.PropertyChanged += MockBuilding_PropertyChanged;
this.mapPanel.MouseDown += MapPanel_MouseDown;
this.mapPanel.MouseUp += MapPanel_MouseUp;
this.mapPanel.MouseDoubleClick += MapPanel_MouseDoubleClick;
@ -909,6 +930,7 @@ namespace MobiusEditor.Tools
this.ExitPlacementMode();
base.Deactivate();
}
mockBuilding.PropertyChanged -= MockBuilding_PropertyChanged;
this.mapPanel.MouseDown -= MapPanel_MouseDown;
this.mapPanel.MouseUp -= MapPanel_MouseUp;
this.mapPanel.MouseDoubleClick -= MapPanel_MouseDoubleClick;

View File

@ -52,6 +52,20 @@ namespace MobiusEditor.Tools
private Map previewMap;
protected override Map RenderMap => previewMap;
private string currentObj;
public override Object CurrentObject
{
get { return currentObj; }
set
{
if (value is string trig)
{
this.triggerComboBox.SelectedItem = trig;
}
}
}
private bool placementMode;
protected override Boolean InPlacementMode
@ -340,7 +354,8 @@ namespace MobiusEditor.Tools
triggerComboBox.SelectedItem = trigger;
if (cellTrigBlobCenters.TryGetValue(trigger, out Rectangle[] locations))
{
currentCellTrig = cellTrigger.Trigger;
currentCellTrig = trigger;
currentObj = trigger;
currentCellTrigIndex = 0;
// If found, make sure clicking the "jump to next use" button
// will go to the blob after the currently clicked one.
@ -413,6 +428,7 @@ namespace MobiusEditor.Tools
{
string selected = triggerComboBox.SelectedItem as string;
jumpToButton.Enabled = selected != null && cellTrigBlobCenters.TryGetValue(selected, out Rectangle[] locations) && locations != null && locations.Length > 0;
currentObj = selected;
if (placementMode)
{
// An invalidate without cells won't call PreRenderMap, and will thus

View File

@ -37,6 +37,23 @@ namespace MobiusEditor.Tools
private Map previewMap;
protected override Map RenderMap => previewMap;
public override Object CurrentObject
{
get { return mockInfantry; }
set
{
if (value is Infantry inf)
{
if (plugin.ActiveHouse != null)
{
inf.House = plugin.ActiveHouse;
}
SelectedInfantryType = inf.Type;
mockInfantry.CloneDataFrom(inf);
}
}
}
/// <summary>
/// Layers that are not painted by the PostRenderMap function on ViewTool level because they are handled
/// at a specific point in the PostRenderMap override by the implementing tool.
@ -70,17 +87,13 @@ namespace MobiusEditor.Tools
{
mapPanel.Invalidate(map, navigationWidget.MouseCell);
}
selectedInfantryType = value;
infantryTypesBox.SelectedValue = selectedInfantryType;
if (placementMode && (selectedInfantryType != null))
{
mapPanel.Invalidate(map, navigationWidget.MouseCell);
}
mockInfantry.Type = selectedInfantryType;
RefreshPreviewPanel();
}
}
@ -100,7 +113,6 @@ namespace MobiusEditor.Tools
Direction = map.UnitDirectionTypes.Where(d => d.Equals(FacingType.South)).First(),
Mission = map.GetDefaultMission(infType)
};
mockInfantry.PropertyChanged += MockInfantry_PropertyChanged;
this.infantryTypesBox = infantryTypesBox;
this.infantryTypesBox.Types = infTypes;
this.infantryTypesBox.SelectedIndexChanged += InfantryTypeComboBox_SelectedIndexChanged;
@ -228,6 +240,10 @@ namespace MobiusEditor.Tools
private void MockInfantry_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "House")
{
plugin.ActiveHouse = mockInfantry.House;
}
RefreshPreviewPanel();
}
@ -826,6 +842,7 @@ namespace MobiusEditor.Tools
{
base.Activate();
this.Deactivate(true);
mockInfantry.PropertyChanged += MockInfantry_PropertyChanged;
this.mapPanel.MouseDown += MapPanel_MouseDown;
this.mapPanel.MouseUp += MapPanel_MouseUp;
this.mapPanel.MouseDoubleClick += MapPanel_MouseDoubleClick;
@ -849,6 +866,7 @@ namespace MobiusEditor.Tools
this.ExitPlacementMode();
base.Deactivate();
}
mockInfantry.PropertyChanged -= MockInfantry_PropertyChanged;
this.mapPanel.MouseDown -= MapPanel_MouseDown;
this.mapPanel.MouseUp -= MapPanel_MouseUp;
this.mapPanel.MouseDoubleClick -= MapPanel_MouseDoubleClick;

View File

@ -44,6 +44,18 @@ namespace MobiusEditor.Tools
private Map previewMap;
protected override Map RenderMap => previewMap;
public override Object CurrentObject
{
get { return selectedOverlayType; }
set
{
if (value is OverlayType ovt)
{
SelectedOverlayType = ovt;
}
}
}
private bool placementMode;
protected override Boolean InPlacementMode

View File

@ -39,6 +39,21 @@ namespace MobiusEditor.Tools
private readonly NumericUpDown brushSizeNud;
private readonly CheckBox gemsCheckBox;
public int currentVal;
public override Object CurrentObject
{
get { return currentVal; }
set
{
if (value is int val)
{
currentVal = val;
this.brushSizeNud.Value = (val & 0x7FFFFFFF) | 1;
this.gemsCheckBox.Checked = ((uint)val & 0x80000000) != 0;
}
}
}
private bool placementMode;
private bool additivePlacement;
@ -58,6 +73,7 @@ namespace MobiusEditor.Tools
this.brushSizeNud = brushSizeNud;
this.gemsCheckBox = gemsCheckBox;
this.brushSizeNud.ValueChanged += BrushSizeNud_ValueChanged;
this.gemsCheckBox.CheckedChanged += GemsCheckBox_CheckedChanged;
navigationWidget.MouseoverSize = new Size((int)brushSizeNud.Value, (int)brushSizeNud.Value);
Update();
}
@ -70,6 +86,7 @@ namespace MobiusEditor.Tools
private void BrushSizeNud_ValueChanged(object sender, EventArgs e)
{
int actualValue = (int)brushSizeNud.Value | 1;
currentVal = gemsCheckBox.Checked ? (int)(0x80000000 | (uint)actualValue) : actualValue;
if (brushSizeNud.Value != actualValue)
{
// Will re-trigger this, and then go to the other case.
@ -82,6 +99,11 @@ namespace MobiusEditor.Tools
}
}
private void GemsCheckBox_CheckedChanged(object sender, EventArgs e)
{
int brushValue = (int)brushSizeNud.Value | 1;
currentVal = gemsCheckBox.Checked ? (int)(0x80000000 | (uint)brushValue) : brushValue;
}
private void ResourcesTool_KeyUpDown(object sender, KeyEventArgs e)
{

View File

@ -43,6 +43,19 @@ namespace MobiusEditor.Tools
private Map previewMap;
protected override Map RenderMap => previewMap;
public override Object CurrentObject
{
get { return mockSmudge; }
set
{
if (value is Smudge sm)
{
SelectedSmudgeType = sm.Type;
mockSmudge.CloneDataFrom(sm);
}
}
}
private bool placementMode;
protected override Boolean InPlacementMode
@ -75,9 +88,8 @@ namespace MobiusEditor.Tools
{
mapPanel.Invalidate(map, new Rectangle(navigationWidget.MouseCell, selectedSmudgeType.Size));
}
mockSmudge.Icon = Math.Min(selectedSmudgeType.Icons - 1, mockSmudge.Icon);
mockSmudge.Type = selectedSmudgeType;
RefreshPreviewPanel();
mockSmudge.Icon = Math.Min(selectedSmudgeType.Icons - 1, mockSmudge.Icon);
}
}
}
@ -87,7 +99,6 @@ namespace MobiusEditor.Tools
{
previewMap = map;
mockSmudge = new Smudge(smudgeTypeListBox.Types.First() as SmudgeType, 0);
mockSmudge.PropertyChanged += MockSmudge_PropertyChanged;
this.smudgeTypeListBox = smudgeTypeListBox;
this.smudgeTypeListBox.SelectedIndexChanged += SmudgeTypeComboBox_SelectedIndexChanged;
this.smudgeTypeMapPanel = smudgeTypeMapPanel;
@ -97,6 +108,7 @@ namespace MobiusEditor.Tools
this.smudgeProperties = smudgeProperties;
this.smudgeProperties.Smudge = mockSmudge;
SelectedSmudgeType = smudgeTypeListBox.Types.First() as SmudgeType;
RefreshPreviewPanel();
}
private void MapPanel_MouseLeave(object sender, EventArgs e)
@ -181,6 +193,7 @@ namespace MobiusEditor.Tools
private void SmudgeTypeComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
SelectedSmudgeType = smudgeTypeListBox.SelectedValue as SmudgeType;
RefreshPreviewPanel();
}
private void SmudgeTool_KeyDown(object sender, KeyEventArgs e)
@ -710,13 +723,14 @@ namespace MobiusEditor.Tools
{
base.Activate();
this.Deactivate(true);
this.mockSmudge.PropertyChanged += MockSmudge_PropertyChanged;
this.mapPanel.MouseDown += MapPanel_MouseDown;
this.mapPanel.MouseMove += MapPanel_MouseMove;
this.mapPanel.MouseDoubleClick += MapPanel_MouseDoubleClick;
this.mapPanel.MouseLeave += MapPanel_MouseLeave;
(this.mapPanel as Control).KeyDown += SmudgeTool_KeyDown;
(this.mapPanel as Control).KeyUp += SmudgeTool_KeyUp;
navigationWidget.BoundsMouseCellChanged += MouseoverWidget_MouseCellChanged;
this.navigationWidget.BoundsMouseCellChanged += MouseoverWidget_MouseCellChanged;
this.UpdateStatus();
}
@ -732,6 +746,7 @@ namespace MobiusEditor.Tools
ExitPlacementMode();
base.Deactivate();
}
this.mockSmudge.PropertyChanged -= MockSmudge_PropertyChanged;
this.mapPanel.MouseDown -= MapPanel_MouseDown;
this.mapPanel.MouseMove -= MapPanel_MouseMove;
this.mapPanel.MouseDoubleClick -= MapPanel_MouseDoubleClick;

View File

@ -64,6 +64,41 @@ namespace MobiusEditor.Tools
private Map previewMap;
protected override Map RenderMap => previewMap;
public override Object CurrentObject
{
get
{
Template template = new Template();
template.Type = this.selectedTemplateType;
Point? sel = SelectedIcon;
if (!sel.HasValue)
{
template.Icon = -1;
}
else
{
template.Icon = (sel.Value.Y * template.Type.ThumbnailIconWidth) + sel.Value.X;
}
return template;
}
set
{
if (value is Template tem)
{
SelectedTemplateType = tem.Type;
if (tem.Icon < 0)
{
SelectedIcon = null;
}
else
{
Point p = new Point(tem.Icon % tem.Type.ThumbnailIconWidth, tem.Icon / tem.Type.ThumbnailIconWidth);
SelectedIcon = p;
}
}
}
}
private bool placementMode;
protected override Boolean InPlacementMode

View File

@ -43,6 +43,19 @@ namespace MobiusEditor.Tools
private Map previewMap;
protected override Map RenderMap => previewMap;
public override Object CurrentObject
{
get { return mockTerrain; }
set
{
if (value is Terrain ter)
{
selectedTerrainType = ter.Type;
mockTerrain.CloneDataFrom(ter);
}
}
}
private bool placementMode;
protected override Boolean InPlacementMode
@ -78,7 +91,6 @@ namespace MobiusEditor.Tools
mapPanel.Invalidate(map, new Rectangle(navigationWidget.MouseCell, selectedTerrainType.OverlapBounds.Size));
}
mockTerrain.Type = selectedTerrainType;
RefreshPreviewPanel();
}
}
}
@ -88,7 +100,6 @@ namespace MobiusEditor.Tools
{
previewMap = map;
mockTerrain = new Terrain();
mockTerrain.PropertyChanged += MockTerrain_PropertyChanged;
this.terrainTypeListBox = terrainTypeComboBox;
this.terrainTypeListBox.SelectedIndexChanged += TerrainTypeCombo_SelectedIndexChanged;
this.terrainTypeMapPanel = terrainTypeMapPanel;
@ -99,6 +110,7 @@ namespace MobiusEditor.Tools
this.terrainProperties.Terrain = mockTerrain;
this.terrainProperties.Visible = plugin.Map.TerrainEventTypes.Count > 0;
SelectedTerrainType = terrainTypeComboBox.Types.First() as TerrainType;
RefreshPreviewPanel();
}
private void MapPanel_MouseLeave(object sender, EventArgs e)
@ -189,6 +201,7 @@ namespace MobiusEditor.Tools
private void TerrainTypeCombo_SelectedIndexChanged(object sender, EventArgs e)
{
SelectedTerrainType = terrainTypeListBox.SelectedValue as TerrainType;
RefreshPreviewPanel();
}
private void TerrainTool_KeyDown(object sender, KeyEventArgs e)
@ -593,6 +606,7 @@ namespace MobiusEditor.Tools
{
base.Activate();
this.Deactivate(true);
this.mockTerrain.PropertyChanged += MockTerrain_PropertyChanged;
this.mapPanel.MouseDown += MapPanel_MouseDown;
this.mapPanel.MouseMove += MapPanel_MouseMove;
this.mapPanel.MouseUp += MapPanel_MouseUp;
@ -616,6 +630,7 @@ namespace MobiusEditor.Tools
this.ExitPlacementMode();
base.Deactivate();
}
this.mockTerrain.PropertyChanged -= MockTerrain_PropertyChanged;
this.mapPanel.MouseDown -= MapPanel_MouseDown;
this.mapPanel.MouseMove -= MapPanel_MouseMove;
this.mapPanel.MouseUp -= MapPanel_MouseUp;

View File

@ -43,6 +43,23 @@ namespace MobiusEditor.Tools
private Map previewMap;
protected override Map RenderMap => previewMap;
public override Object CurrentObject
{
get { return mockUnit; }
set
{
if (value is Unit un)
{
if (plugin.ActiveHouse != null)
{
un.House = plugin.ActiveHouse;
}
SelectedUnitType = un.Type;
mockUnit.CloneDataFrom(un);
}
}
}
private bool placementMode;
protected override Boolean InPlacementMode
@ -77,7 +94,6 @@ namespace MobiusEditor.Tools
mapPanel.Invalidate(map, Rectangle.Inflate(new Rectangle(navigationWidget.MouseCell, new Size(1, 1)), 1, 1));
}
mockUnit.Type = selectedUnitType;
RefreshPreviewPanel();
}
}
}
@ -96,7 +112,6 @@ namespace MobiusEditor.Tools
Direction = map.UnitDirectionTypes.Where(d => d.Equals(FacingType.North)).First(),
Mission = map.GetDefaultMission(unitType)
};
mockUnit.PropertyChanged += MockUnit_PropertyChanged;
this.unitTypesBox = unitTypesBox;
this.unitTypesBox.Types = unitTypes;
this.unitTypesBox.SelectedIndexChanged += UnitTypeComboBox_SelectedIndexChanged;
@ -107,6 +122,7 @@ namespace MobiusEditor.Tools
this.objectProperties = objectProperties;
this.objectProperties.Object = mockUnit;
SelectedUnitType = mockUnit.Type;
RefreshPreviewPanel();
}
protected override void UpdateExpansionUnits()
@ -219,6 +235,10 @@ namespace MobiusEditor.Tools
private void MockUnit_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "House")
{
plugin.ActiveHouse = mockUnit.House;
}
RefreshPreviewPanel();
}
@ -657,6 +677,7 @@ namespace MobiusEditor.Tools
{
base.Activate();
Deactivate(true);
mockUnit.PropertyChanged += MockUnit_PropertyChanged;
this.mapPanel.MouseDown += MapPanel_MouseDown;
this.mapPanel.MouseUp += MapPanel_MouseUp;
this.mapPanel.MouseDoubleClick += MapPanel_MouseDoubleClick;
@ -680,6 +701,7 @@ namespace MobiusEditor.Tools
ExitPlacementMode();
base.Deactivate();
}
mockUnit.PropertyChanged -= MockUnit_PropertyChanged;
this.mapPanel.MouseDown -= MapPanel_MouseDown;
this.mapPanel.MouseUp -= MapPanel_MouseUp;
this.mapPanel.MouseDoubleClick -= MapPanel_MouseDoubleClick;

View File

@ -31,6 +31,9 @@ namespace MobiusEditor.Tools
public abstract class ViewTool : ITool
{
protected readonly IGamePlugin plugin;
public IGamePlugin Plugin => plugin;
public abstract Object CurrentObject { get; set; }
protected readonly Map map;
protected readonly MapPanel mapPanel;

View File

@ -44,6 +44,18 @@ namespace MobiusEditor.Tools
private Map previewMap;
protected override Map RenderMap => previewMap;
public override Object CurrentObject
{
get { return selectedWallType; }
set
{
if (value is OverlayType ovt)
{
SelectedWallType = ovt;
}
}
}
private bool placementMode;
protected override Boolean InPlacementMode
@ -65,7 +77,7 @@ namespace MobiusEditor.Tools
}
selectedWallType = value;
wallTypeComboBox.SelectedValue = selectedWallType;
RefreshMapPanel();
base.RefreshPreviewPanel();
}
}
}
@ -310,7 +322,7 @@ namespace MobiusEditor.Tools
}
}
private void RefreshMapPanel()
protected override void RefreshPreviewPanel()
{
wallTypeMapPanel.MapImage = SelectedWallType?.Thumbnail;
}

View File

@ -41,6 +41,20 @@ namespace MobiusEditor.Tools
private Map previewMap;
protected override Map RenderMap => previewMap;
private int lastSelectedIndex;
public override Object CurrentObject
{
get { return lastSelectedIndex; }
set
{
if (value is int index)
{
lastSelectedIndex = index;
waypointCombo.SelectedIndex = index;
}
}
}
private bool placementMode;
protected override Boolean InPlacementMode
@ -166,6 +180,7 @@ namespace MobiusEditor.Tools
waypointCombo.DataSource = null;
waypointCombo.Items.Clear();
waypointCombo.DataSource = wp.ToArray();
lastSelectedIndex = selected;
waypointCombo.SelectedIndex = selected;
if (oldCell.HasValue)
{
@ -387,6 +402,7 @@ namespace MobiusEditor.Tools
private void WaypointCombo_SelectedIndexChanged(Object sender, EventArgs e)
{
lastSelectedIndex = waypointCombo.SelectedIndex;
Waypoint selected = waypointCombo.SelectedItem as Waypoint;
jumpToButton.Enabled = selected != null && selected.Cell.HasValue;
if (selected != null && selected.Cell.HasValue)
@ -554,6 +570,7 @@ namespace MobiusEditor.Tools
waypointCombo.Items.Clear();
waypointCombo.DataSource = map.Waypoints.ToArray();
waypointCombo.SelectedIndex = selected;
lastSelectedIndex = selected;
this.waypointCombo.SelectedIndexChanged += this.WaypointCombo_SelectedIndexChanged;
}