Skip to content

Commit da48175

Browse files
committed
Implement toggle for previewing lighting from disabled light posts
Resolves #260
1 parent fc62106 commit da48175

File tree

14 files changed

+60
-19
lines changed

14 files changed

+60
-19
lines changed

src/TSMapEditor/Models/Map.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ public int GetAutoLATIndex(MapTile mapTile, int baseLATTileSetIndex, int transit
13991399
return -1;
14001400
}
14011401

1402-
public void RefreshCellLighting(LightingPreviewMode lightingPreviewMode, List<MapTile> affectedTiles)
1402+
public void RefreshCellLighting(LightingPreviewMode lightingPreviewMode, bool lightDisabledLightSources, List<MapTile> affectedTiles)
14031403
{
14041404
if (affectedTiles == null)
14051405
{
@@ -1409,7 +1409,7 @@ public void RefreshCellLighting(LightingPreviewMode lightingPreviewMode, List<Ma
14091409
return;
14101410
}
14111411

1412-
DoForAllValidTiles(cell => cell.RefreshLighting(Lighting, lightingPreviewMode));
1412+
DoForAllValidTiles(cell => cell.RefreshLighting(Lighting, lightingPreviewMode, lightDisabledLightSources));
14131413
}
14141414
else
14151415
{
@@ -1419,7 +1419,7 @@ public void RefreshCellLighting(LightingPreviewMode lightingPreviewMode, List<Ma
14191419
return;
14201420
}
14211421

1422-
affectedTiles.ForEach(cell => cell.RefreshLighting(Lighting, lightingPreviewMode));
1422+
affectedTiles.ForEach(cell => cell.RefreshLighting(Lighting, lightingPreviewMode, lightDisabledLightSources));
14231423
}
14241424
}
14251425

src/TSMapEditor/Models/MapTile.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public MapTile(byte[] data) : base(data) { }
5757

5858
public List<(Structure Source, double DistanceInLeptons)> LightSources { get; set; } = new();
5959

60-
public void RefreshLighting(Lighting lighting, LightingPreviewMode lightingPreviewMode)
60+
public void RefreshLighting(Lighting lighting, LightingPreviewMode lightingPreviewMode, bool lightDisabledLightSources)
6161
{
6262
if (lightingPreviewMode == LightingPreviewMode.NoLighting)
6363
{
@@ -94,6 +94,9 @@ public void RefreshLighting(Lighting lighting, LightingPreviewMode lightingPrevi
9494
if (source.Source.ObjectType.LightIntensity == 0.0)
9595
continue;
9696

97+
if (!lightDisabledLightSources && !source.Source.Powered)
98+
continue;
99+
97100
var buildingType = source.Source.ObjectType;
98101

99102
double distanceRatio = 1.0 - (source.DistanceInLeptons / source.Source.ObjectType.LightVisibility);

src/TSMapEditor/Mutations/Classes/DrawCliffMutation.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ private void PlaceTile(TileImage tile, Point2D targetCellCoords)
182182

183183
mapTile.ChangeTileIndex(tile.TileID, (byte)i);
184184
mapTile.Level = (byte)Math.Min(originLevel + image.TmpImage.Height, Constants.MaxMapHeightLevel);
185-
mapTile.RefreshLighting(Map.Lighting, MutationTarget.LightingPreviewState);
185+
RefreshCellLighting(mapTile);
186186
}
187187
}
188188
}
@@ -198,7 +198,7 @@ public override void Undo()
198198
{
199199
mapTile.ChangeTileIndex(data.TileIndex, data.SubTileIndex);
200200
mapTile.Level = data.Level;
201-
mapTile.RefreshLighting(Map.Lighting, MutationTarget.LightingPreviewState);
201+
RefreshCellLighting(mapTile);
202202
}
203203
}
204204

src/TSMapEditor/Mutations/Classes/HeightMutations/AlterElevationMutationBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private void RefreshLighting()
133133
{
134134
var cellCoords = totalProcessedCells[i];
135135
var cell = Map.GetTile(cellCoords);
136-
cell?.RefreshLighting(Map.Lighting, MutationTarget.LightingPreviewState);
136+
RefreshCellLighting(cell);
137137
}
138138
}
139139

@@ -144,7 +144,7 @@ public override void Undo()
144144
var cell = Map.GetTile(entry.CellCoords);
145145
cell.ChangeTileIndex(entry.TileIndex, (byte)entry.SubTileIndex);
146146
cell.Level = (byte)entry.HeightLevel;
147-
cell.RefreshLighting(Map.Lighting, MutationTarget.LightingPreviewState);
147+
RefreshCellLighting(cell);
148148
}
149149

150150
MutationTarget.InvalidateMap();

src/TSMapEditor/Mutations/Classes/HeightMutations/LowerCellsMutation.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private void LowerCellLevel(MapTile cell)
6565
{
6666
cell.Level--;
6767
affectedCells.Add(cell.CoordsToPoint());
68-
cell.RefreshLighting(Map.Lighting, MutationTarget.LightingPreviewState);
68+
RefreshCellLighting(cell);
6969
}
7070
}
7171

@@ -80,7 +80,7 @@ public override void Undo()
8080
if (cell.Level < Constants.MaxMapHeight)
8181
{
8282
cell.Level++;
83-
cell.RefreshLighting(Map.Lighting, MutationTarget.LightingPreviewState);
83+
RefreshCellLighting(cell);
8484
}
8585
}
8686

src/TSMapEditor/Mutations/Classes/HeightMutations/RaiseCellsMutation.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private void RaiseCellLevel(MapTile cell)
6565
if (cell.Level < Constants.MaxMapHeightLevel)
6666
{
6767
cell.Level++;
68-
cell.RefreshLighting(Map.Lighting, MutationTarget.LightingPreviewState);
68+
RefreshCellLighting(cell);
6969
affectedCells.Add(cell.CoordsToPoint());
7070
}
7171
}
@@ -81,7 +81,7 @@ public override void Undo()
8181
if (cell.Level > 0)
8282
{
8383
cell.Level--;
84-
cell.RefreshLighting(Map.Lighting, MutationTarget.LightingPreviewState);
84+
RefreshCellLighting(cell);
8585
}
8686
}
8787

src/TSMapEditor/Mutations/Classes/PlaceTerrainTileMutation.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public override void Perform()
121121
{
122122
mapTile.ChangeTileIndex(tile.TileID, (byte)i);
123123
mapTile.Level = (byte)Math.Min(originLevel + image.TmpImage.Height, Constants.MaxMapHeightLevel);
124-
mapTile.RefreshLighting(Map.Lighting, MutationTarget.LightingPreviewState);
124+
RefreshCellLighting(mapTile);
125125
}
126126
}
127127
});
@@ -169,7 +169,7 @@ public override void Undo()
169169
{
170170
mapCell.ChangeTileIndex(originalTerrainData.TileIndex, originalTerrainData.SubTileIndex);
171171
mapCell.Level = originalTerrainData.Level;
172-
mapCell.RefreshLighting(Map.Lighting, MutationTarget.LightingPreviewState);
172+
RefreshCellLighting(mapCell);
173173
}
174174
}
175175

src/TSMapEditor/Mutations/Mutation.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,5 +253,13 @@ protected void ApplyAutoLATForTileSetPlacement(int tileSetIndex, int minX, int m
253253
}
254254
}
255255
}
256+
257+
protected void RefreshCellLighting(MapTile cell)
258+
{
259+
if (cell == null)
260+
return;
261+
262+
cell.RefreshLighting(Map.Lighting, MutationTarget.LightingPreviewState, MutationTarget.LightDisabledLightSources);
263+
}
256264
}
257265
}

src/TSMapEditor/Rendering/EditorState.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,20 @@ public bool Is2DMode
202202
}
203203
}
204204

205+
private bool _lightDisabledLightSources = false;
206+
public bool LightDisabledLightSources
207+
{
208+
get => _lightDisabledLightSources;
209+
set
210+
{
211+
if (value != _lightDisabledLightSources)
212+
{
213+
_lightDisabledLightSources = value;
214+
IsLightingChanged?.Invoke(this, EventArgs.Empty);
215+
}
216+
}
217+
}
218+
205219
private bool _isLighting = true;
206220
public bool IsLighting
207221
{

src/TSMapEditor/Rendering/MapView.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,12 @@ private void LoadShaders()
248248
private void Map_CellLightingModified(object sender, CellLightingEventArgs e)
249249
{
250250
if (EditorState.IsLighting && EditorState.LightingPreviewState != LightingPreviewMode.NoLighting)
251-
Map.RefreshCellLighting(EditorState.LightingPreviewState, e.AffectedTiles);
251+
Map.RefreshCellLighting(EditorState.LightingPreviewState, EditorState.LightDisabledLightSources, e.AffectedTiles);
252252
}
253253

254254
private void LightingChanged()
255255
{
256-
Map.RefreshCellLighting(EditorState.IsLighting ? EditorState.LightingPreviewState : LightingPreviewMode.NoLighting, null);
256+
Map.RefreshCellLighting(EditorState.IsLighting ? EditorState.LightingPreviewState : LightingPreviewMode.NoLighting, EditorState.LightDisabledLightSources, null);
257257

258258
InvalidateMapForMinimap();
259259
if (Constants.VoxelsAffectedByLighting)

0 commit comments

Comments
 (0)