Skip to content

Commit bfdffd5

Browse files
authored
Merge pull request #43 from Floogen/feature/terrain-reflections
Added terrain, furniture and building reflections.
2 parents e252b85 + 6962c5d commit bfdffd5

11 files changed

Lines changed: 647 additions & 87 deletions

File tree

DynamicReflections/DynamicReflections.cs

Lines changed: 273 additions & 41 deletions
Large diffs are not rendered by default.

DynamicReflections/Framework/External/GenericModConfigMenu/GMCMHelper.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public static void Register(IGenericModConfigMenuApi configApi, DynamicReflectio
3737
configApi.AddBoolOption(ModManifest, () => DynamicReflections.modConfig.ArePuddleReflectionsEnabled, value => DynamicReflections.modConfig.ArePuddleReflectionsEnabled = value, () => Helper.Translation.Get("config.general_settings.puddle_reflections"));
3838
configApi.AddBoolOption(ModManifest, () => DynamicReflections.modConfig.AreNPCReflectionsEnabled, value => DynamicReflections.modConfig.AreNPCReflectionsEnabled = value, () => Helper.Translation.Get("config.general_settings.npc_reflections"));
3939
configApi.AddBoolOption(ModManifest, () => DynamicReflections.modConfig.AreCompanionReflectionsEnabled, value => DynamicReflections.modConfig.AreCompanionReflectionsEnabled = value, () => Helper.Translation.Get("config.general_settings.companion_reflections"));
40+
configApi.AddBoolOption(ModManifest, () => DynamicReflections.modConfig.AreGrassReflectionsEnabled, value => DynamicReflections.modConfig.AreGrassReflectionsEnabled = value, () => Helper.Translation.Get("config.general_settings.grass_reflections"));
41+
configApi.AddBoolOption(ModManifest, () => DynamicReflections.modConfig.AreTerrainReflectionsEnabled, value => DynamicReflections.modConfig.AreTerrainReflectionsEnabled = value, () => Helper.Translation.Get("config.general_settings.terrain_reflections"));
42+
configApi.AddBoolOption(ModManifest, () => DynamicReflections.modConfig.ArePlayerBuildingReflectionsEnabled, value => DynamicReflections.modConfig.ArePlayerBuildingReflectionsEnabled = value, () => Helper.Translation.Get("config.general_settings.player_buildings_reflections"));
43+
configApi.AddBoolOption(ModManifest, () => DynamicReflections.modConfig.AreFurnitureReflectionsEnabled, value => DynamicReflections.modConfig.AreFurnitureReflectionsEnabled = value, () => Helper.Translation.Get("config.general_settings.furniture_reflections"));
4044
configApi.AddBoolOption(ModManifest, () => DynamicReflections.modConfig.AreSkyReflectionsEnabled, value => DynamicReflections.modConfig.AreSkyReflectionsEnabled = value, () => Helper.Translation.Get("config.general_settings.sky_reflections"));
4145
configApi.AddKeybind(ModManifest, () => DynamicReflections.modConfig.QuickMenuKey, value => DynamicReflections.modConfig.QuickMenuKey = value, () => Helper.Translation.Get("config.general_settings.shortcut_key"), () => Helper.Translation.Get("config.general_settings.shortcut_key.description"));
4246

DynamicReflections/Framework/External/GenericModConfigMenu/ModConfig.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ public class ModConfig
1616
public bool ArePuddleReflectionsEnabled { get; set; } = true;
1717
public bool AreNPCReflectionsEnabled { get; set; } = true;
1818
public bool AreCompanionReflectionsEnabled { get; set; } = true;
19+
public bool AreGrassReflectionsEnabled { get; set; } = true;
20+
public bool AreTerrainReflectionsEnabled { get; set; } = true;
21+
public bool ArePlayerBuildingReflectionsEnabled { get; set; } = true;
22+
public bool AreFurnitureReflectionsEnabled { get; set; } = true;
1923
public bool AreSkyReflectionsEnabled { get; set; } = true;
2024

2125
public WaterSettings WaterReflectionSettings { get; set; } = new WaterSettings();
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Microsoft.Xna.Framework;
2+
using Microsoft.Xna.Framework.Graphics;
3+
using StardewValley;
4+
using StardewValley.Buildings;
5+
6+
namespace DynamicReflections.Framework.Models.Reflections
7+
{
8+
public class ReflectableBuilding : ReflectableObject
9+
{
10+
public Building Building;
11+
12+
public ReflectableBuilding(Building building)
13+
{
14+
Building = building;
15+
Tile = new Vector2(building.tileX.Value, building.tileY.Value);
16+
}
17+
18+
public override void Draw(SpriteBatch spriteBatch)
19+
{
20+
Building.draw(spriteBatch);
21+
}
22+
23+
public override bool IsOnScreen()
24+
{
25+
return Utility.isOnScreen(Tile * 64, 8 * 64);
26+
}
27+
28+
public override bool IsEnabled()
29+
{
30+
return DynamicReflections.modConfig.ArePlayerBuildingReflectionsEnabled;
31+
}
32+
}
33+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Microsoft.Xna.Framework.Graphics;
2+
using StardewValley;
3+
using StardewValley.Objects;
4+
5+
namespace DynamicReflections.Framework.Models.Reflections
6+
{
7+
public class ReflectableFurniture : ReflectableObject
8+
{
9+
public Furniture Furniture;
10+
11+
public ReflectableFurniture(Furniture furniture)
12+
{
13+
Furniture = furniture;
14+
Tile = furniture.TileLocation;
15+
}
16+
17+
public override void Draw(SpriteBatch spriteBatch)
18+
{
19+
Furniture.isDrawingLocationFurniture = true;
20+
Furniture.draw(spriteBatch, -1, -1);
21+
Furniture.isDrawingLocationFurniture = false;
22+
}
23+
24+
public override bool IsOnScreen()
25+
{
26+
// Allow for three tile (3 * 64) spacing for trees and bushes
27+
return Utility.isOnScreen(Tile * 64, 3 * 64);
28+
}
29+
30+
public override bool IsEnabled()
31+
{
32+
return DynamicReflections.modConfig.AreFurnitureReflectionsEnabled;
33+
}
34+
}
35+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Microsoft.Xna.Framework;
2+
using Microsoft.Xna.Framework.Graphics;
3+
4+
namespace DynamicReflections.Framework.Models.Reflections
5+
{
6+
public abstract class ReflectableObject
7+
{
8+
public Vector2 Tile { get; set; }
9+
10+
public abstract void Draw(SpriteBatch spriteBatch);
11+
public abstract bool IsOnScreen();
12+
public abstract bool IsEnabled();
13+
}
14+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using Microsoft.Xna.Framework.Graphics;
2+
using StardewValley;
3+
using StardewValley.TerrainFeatures;
4+
5+
namespace DynamicReflections.Framework.Models.Reflections
6+
{
7+
public class ReflectableTerrain : ReflectableObject
8+
{
9+
public TerrainFeature Terrain;
10+
11+
public ReflectableTerrain(TerrainFeature terrain)
12+
{
13+
Terrain = terrain;
14+
Tile = terrain.Tile;
15+
}
16+
17+
public override void Draw(SpriteBatch spriteBatch)
18+
{
19+
if (Terrain is Tree tree)
20+
{
21+
float alphaCache = tree.alpha;
22+
tree.alpha = 1f;
23+
24+
Terrain.draw(spriteBatch);
25+
tree.alpha = alphaCache;
26+
}
27+
else
28+
{
29+
Terrain.draw(spriteBatch);
30+
}
31+
}
32+
33+
public override bool IsOnScreen()
34+
{
35+
// Allow for three tile (3 * 64) spacing for trees and bushes
36+
return Utility.isOnScreen(Tile * 64, 8 * 64);
37+
}
38+
39+
public override bool IsEnabled()
40+
{
41+
if (Terrain is Grass)
42+
{
43+
return DynamicReflections.modConfig.AreGrassReflectionsEnabled;
44+
}
45+
46+
return DynamicReflections.modConfig.AreTerrainReflectionsEnabled;
47+
}
48+
}
49+
}

DynamicReflections/Framework/Patches/Locations/GameLocationPatch.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ internal void Apply(Harmony harmony)
3535
harmony.CreateReversePatcher(AccessTools.Method(_type, nameof(GameLocation.drawWater), new[] { typeof(SpriteBatch) }), new HarmonyMethod(GetType(), nameof(DrawWaterReversePatch))).Patch();
3636

3737
harmony.Patch(AccessTools.Method(_type, nameof(GameLocation.UpdateWhenCurrentLocation), new[] { typeof(GameTime) }), postfix: new HarmonyMethod(GetType(), nameof(UpdateWhenCurrentLocationPostfix)));
38+
harmony.Patch(AccessTools.Method(_type, nameof(GameLocation.OnBuildingMoved), new[] { typeof(Building) }), postfix: new HarmonyMethod(GetType(), nameof(OnBuildingMovedPostfix)));
3839
}
3940

4041
[HarmonyBefore(new string[] { "shekurika.WaterFish" })]
@@ -154,6 +155,11 @@ private static void UpdateWhenCurrentLocationPostfix(GameLocation __instance, Ga
154155
}
155156
}
156157

158+
private static void OnBuildingMovedPostfix(GameLocation __instance, Building building)
159+
{
160+
DynamicReflections.ResetLocationTerrainCache(__instance);
161+
}
162+
157163
private static void GenerateRipple(GameLocation location, Point puddleTile, bool playSound = false)
158164
{
159165
TemporaryAnimatedSprite splashSprite = new TemporaryAnimatedSprite("TileSheets\\animations", new Microsoft.Xna.Framework.Rectangle(0, 0, 64, 64), Game1.random.Next(50, 100), 9, 1, new Vector2(puddleTile.X, puddleTile.Y) * 64f, flicker: false, flipped: false, 0f, 0f, DynamicReflections.currentPuddleSettings.RippleColor, 1f, 0f, 0f, 0f);

DynamicReflections/Framework/Patches/xTile/LayerPatch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private static bool DrawNormalPrefix(Layer __instance, IDisplayDevice displayDev
9595
}
9696

9797
// Handle preliminary water reflection logic
98-
if (DynamicReflections.shouldDrawWaterReflection is true)
98+
if (DynamicReflections.modConfig.AreWaterReflectionsEnabled)
9999
{
100100
DynamicReflections.isFilteringWater = true;
101101
SpriteBatchToolkit.RenderWaterReflectionPlayerSprite();

0 commit comments

Comments
 (0)