Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
626 changes: 282 additions & 344 deletions FarmExpansion/FarmExpansion.cs

Large diffs are not rendered by default.

15 changes: 7 additions & 8 deletions FarmExpansion/FarmExpansion.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -28,7 +29,11 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
Expand All @@ -37,10 +42,12 @@
<Compile Include="FarmExpansion.cs" />
<Compile Include="Framework\FEConfig.cs" />
<Compile Include="Framework\FEFramework.cs" />
<Compile Include="Framework\IBetterFarmAnimalVarietyApi.cs" />
<Compile Include="Framework\IModApi.cs" />
<Compile Include="Framework\ModApi.cs" />
<Compile Include="Framework\Tile.cs" />
<Compile Include="Framework\TileLayer.cs" />
<Compile Include="Helpers.cs" />
<Compile Include="Menus\FECarpenterMenu.cs" />
<Compile Include="Menus\FEPurchaseAnimalsMenu.cs" />
<Compile Include="Menus\FETreeTransplantMenu.cs" />
Expand All @@ -52,7 +59,6 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="manifest.json" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="assets\TreeTransplantFarmIcon.png">
Expand All @@ -63,11 +69,4 @@
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Pathoschild.Stardew.ModBuildConfig.2.0.2\build\Pathoschild.Stardew.ModBuildConfig.targets" Condition="Exists('..\packages\Pathoschild.Stardew.ModBuildConfig.2.0.2\build\Pathoschild.Stardew.ModBuildConfig.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Pathoschild.Stardew.ModBuildConfig.2.0.2\build\Pathoschild.Stardew.ModBuildConfig.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Pathoschild.Stardew.ModBuildConfig.2.0.2\build\Pathoschild.Stardew.ModBuildConfig.targets'))" />
</Target>
</Project>
349 changes: 203 additions & 146 deletions FarmExpansion/Framework/FEFramework.cs

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions FarmExpansion/Framework/IBetterFarmAnimalVarietyApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;

namespace FarmExpansion.Framework
{
public interface IBetterFarmAnimalVarietyApi
{
/// <param name="farm">StardewValley.Farm</param>
/// <returns>Returns List<StardewValley.Object></returns>
List<StardewValley.Object> GetAnimalShopStock(StardewValley.Farm farm);

/// <summary>Determine if the mod is enabled.</summary>
Dictionary<string, Texture2D> GetAnimalShopIcons();

/// <param name="category">string</param>
/// <param name="farmer">StardewValley.Farmer</param>
/// <returns>Returns string</returns>
string GetRandomAnimalShopType(string category, StardewValley.Farmer farmer);
}
}
15 changes: 14 additions & 1 deletion FarmExpansion/Framework/IModApi.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using StardewValley;
using System;
using StardewValley;

namespace FarmExpansion.Framework
{
Expand All @@ -12,5 +13,17 @@ public interface IModApi
/// <summary>Add a blueprint to all future carpenter menus for the expansion area.</summary>
/// <param name="blueprint">The blueprint to add.</param>
void AddExpansionBluePrint(BluePrint blueprint);

/// <summary>
/// Mod removes itself from game world in BeforeSave and handles saving separately.
/// Hook this if you need to do some fixup to contained stuff (FurnitureAnywhere, Tractor etc).
/// </summary>
/// <param name="handler"></param>
void AddRemoveListener(EventHandler handler);

/// <summary>
/// Second half for AddRemoveListener
/// </summary>
void AddAppendListener(EventHandler handler);
}
}
13 changes: 12 additions & 1 deletion FarmExpansion/Framework/ModApi.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using StardewValley;
using System;
using StardewValley;

namespace FarmExpansion.Framework
{
Expand Down Expand Up @@ -35,5 +36,15 @@ public void AddExpansionBluePrint(BluePrint blueprint)
{
this.Framework.ExpansionBlueprints.Add(blueprint);
}

public void AddRemoveListener(EventHandler handler)
{
Framework.BeforeRemoveEvent += handler;
}

public void AddAppendListener(EventHandler handler)
{
Framework.AfterAppendEvent += handler;
}
}
}
43 changes: 43 additions & 0 deletions FarmExpansion/Helpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Netcode;
using StardewValley;
using StardewValley.Network;

namespace FarmExpansion
{
static class Helpers
{
public static void ReplaceWith<T, TField>(this NetVector2Dictionary<T, TField> collection, NetVector2Dictionary<T, TField> source)
where TField : NetField<T, TField>, new()
{
collection.Clear();
foreach (var kvp in source.Pairs)
{
collection.Add(kvp.Key, kvp.Value);
}
}

public static void ReplaceWith(this OverlaidDictionary collection, OverlaidDictionary source)
{
collection.Clear();
foreach (var kvp in source.Pairs)
{
collection.Add(kvp.Key, kvp.Value);
}
}

public static void ReplaceWith<T>(this Netcode.NetCollection<T> collection, Netcode.NetCollection<T> source)
where T : class, Netcode.INetObject<Netcode.INetSerializable>
{
collection.Clear();
foreach (var item in source)
{
collection.Add(item);
}
}
}
}
42 changes: 24 additions & 18 deletions FarmExpansion/Menus/FECarpenterMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public override void performHoverAction(int x, int y)
{
foreach (Building current in currentFarm.buildings)
{
current.color = Color.White;
current.color.Value = Color.White;
}
Building buildingAt = currentFarm.getBuildingAt(new Vector2((float)((Game1.viewport.X + Game1.getOldMouseX()) / Game1.tileSize), (float)((Game1.viewport.Y + Game1.getOldMouseY()) / Game1.tileSize)));
if (buildingAt == null)
Expand All @@ -327,28 +327,28 @@ public override void performHoverAction(int x, int y)
}
if (this.upgrading)
{
if (buildingAt != null && this.CurrentBlueprint.nameOfBuildingToUpgrade != null && this.CurrentBlueprint.nameOfBuildingToUpgrade.Equals(buildingAt.buildingType))
if (buildingAt != null && this.CurrentBlueprint.nameOfBuildingToUpgrade != null && this.CurrentBlueprint.nameOfBuildingToUpgrade.Equals(buildingAt.buildingType.Value))
{
buildingAt.color = Color.Lime * 0.8f;
buildingAt.color.Value = Color.Lime * 0.8f;
return;
}
if (buildingAt != null)
{
buildingAt.color = Color.Red * 0.8f;
buildingAt.color.Value = Color.Red * 0.8f;
return;
}
}
else if (this.demolishing)
{
if (buildingAt != null)
{
buildingAt.color = Color.Red * 0.8f;
buildingAt.color.Value = Color.Red * 0.8f;
return;
}
}
else if (this.moving && buildingAt != null)
{
buildingAt.color = Color.Lime * 0.8f;
buildingAt.color.Value = Color.Lime * 0.8f;
}
}
return;
Expand Down Expand Up @@ -595,20 +595,20 @@ public override void receiveLeftClick(int x, int y, bool playSound = true)
if (this.demolishing)
{
Building buildingAt = currentFarm.getBuildingAt(new Vector2((float)((Game1.viewport.X + Game1.getOldMouseX()) / Game1.tileSize), (float)((Game1.viewport.Y + Game1.getOldMouseY()) / Game1.tileSize)));
if (buildingAt != null && (buildingAt.daysOfConstructionLeft > 0 || buildingAt.daysUntilUpgrade > 0))
if (buildingAt != null && (buildingAt.daysOfConstructionLeft.Value > 0 || buildingAt.daysUntilUpgrade.Value > 0))
{
Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_DuringConstruction", new object[0]), Color.Red, 3500f));
return;
}
if (buildingAt != null && buildingAt.indoors != null && buildingAt.indoors is AnimalHouse && (buildingAt.indoors as AnimalHouse).animalsThatLiveHere.Count > 0)
if (buildingAt != null && buildingAt.indoors.Value != null && buildingAt.indoors.Value is AnimalHouse && (buildingAt.indoors.Value as AnimalHouse).animalsThatLiveHere.Count > 0)
{
Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_AnimalsHere", new object[0]), Color.Red, 3500f));
return;
}
if (buildingAt != null && currentFarm.destroyStructure(buildingAt))
{
int arg_366_0 = buildingAt.tileY;
int arg_36D_0 = buildingAt.tilesHigh;
int arg_366_0 = buildingAt.tileY.Value;
int arg_36D_0 = buildingAt.tilesHigh.Value;
Game1.flashAlpha = 1f;
buildingAt.showDestroyedAnimation(currentFarm);
Game1.playSound("explosion");
Expand All @@ -624,7 +624,7 @@ public override void receiveLeftClick(int x, int y, bool playSound = true)
if (buildingAt2 != null && this.CurrentBlueprint.name != null && buildingAt2.buildingType.Equals(this.CurrentBlueprint.nameOfBuildingToUpgrade))
{
this.CurrentBlueprint.consumeResources();
buildingAt2.daysUntilUpgrade = 2;
buildingAt2.daysUntilUpgrade.Value = 2;
buildingAt2.showUpgradeAnimation(currentFarm);
Game1.playSound("axe");
DelayedAction.fadeAfterDelay(new Game1.afterFadeFunction(this.returnToCarpentryMenuAfterSuccessfulBuild), 1500);
Expand All @@ -644,7 +644,7 @@ public override void receiveLeftClick(int x, int y, bool playSound = true)
this.buildingToMove = currentFarm.getBuildingAt(new Vector2((float)((Game1.viewport.X + Game1.getMouseX()) / Game1.tileSize), (float)((Game1.viewport.Y + Game1.getMouseY()) / Game1.tileSize)));
if (this.buildingToMove != null)
{
if (this.buildingToMove.daysOfConstructionLeft > 0)
if (this.buildingToMove.daysOfConstructionLeft.Value > 0)
{
this.buildingToMove = null;
return;
Expand All @@ -654,7 +654,10 @@ public override void receiveLeftClick(int x, int y, bool playSound = true)
}
return;
}
if (currentFarm.buildStructure(this.buildingToMove, new Vector2((float)((Game1.viewport.X + Game1.getMouseX()) / Game1.tileSize), (float)((Game1.viewport.Y + Game1.getMouseY()) / Game1.tileSize)), false, Game1.player))
if (currentFarm.buildStructure(
this.buildingToMove,
new Vector2((float)((Game1.viewport.X + Game1.getMouseX()) / Game1.tileSize), (float)((Game1.viewport.Y + Game1.getMouseY()) / Game1.tileSize)),
Game1.player, false))
{
this.buildingToMove = null;
Game1.playSound("axchop");
Expand All @@ -681,7 +684,10 @@ public override void receiveLeftClick(int x, int y, bool playSound = true)

public bool tryToBuild()
{
return currentFarm.buildStructure(this.CurrentBlueprint, new Vector2((float)((Game1.viewport.X + Game1.getOldMouseX()) / Game1.tileSize), (float)((Game1.viewport.Y + Game1.getOldMouseY()) / Game1.tileSize)), false, Game1.player, /*this.magicalConstruction*/false);
return currentFarm.buildStructure(
this.CurrentBlueprint,
new Vector2((float)((Game1.viewport.X + Game1.getOldMouseX()) / Game1.tileSize), (float)((Game1.viewport.Y + Game1.getOldMouseY()) / Game1.tileSize)),
Game1.player, magicalConstruction: false, skipSafetyChecks: false);
}

public void returnToCarpentryMenu()
Expand Down Expand Up @@ -794,7 +800,7 @@ public override void draw(SpriteBatch b)
{
base.draw(b);
IClickableMenu.drawTextureBox(b, this.xPositionOnScreen - Game1.tileSize * 3 / 2, this.yPositionOnScreen - Game1.tileSize / 4, this.maxWidthOfBuildingViewer + Game1.tileSize, this.maxHeightOfBuildingViewer + Game1.tileSize, /*this.magicalConstruction ? Color.RoyalBlue : */Color.White);
this.currentBuilding.drawInMenu(b, this.xPositionOnScreen + this.maxWidthOfBuildingViewer / 2 - this.currentBuilding.tilesWide * Game1.tileSize / 2 - Game1.tileSize, this.yPositionOnScreen + this.maxHeightOfBuildingViewer / 2 - this.currentBuilding.getSourceRectForMenu().Height * Game1.pixelZoom / 2);
this.currentBuilding.drawInMenu(b, this.xPositionOnScreen + this.maxWidthOfBuildingViewer / 2 - this.currentBuilding.tilesWide.Value * Game1.tileSize / 2 - Game1.tileSize, this.yPositionOnScreen + this.maxHeightOfBuildingViewer / 2 - this.currentBuilding.getSourceRectForMenu().Height * Game1.pixelZoom / 2);
if (this.CurrentBlueprint.isUpgrade())
{
this.upgradeIcon.draw(b);
Expand Down Expand Up @@ -832,7 +838,7 @@ public override void draw(SpriteBatch b)
{
vector.Y += (float)(Game1.tileSize + Game1.pixelZoom);
current.drawInMenu(b, vector, 1f);
bool flag = !(current is Object) || Game1.player.hasItemInInventory((current as Object).parentSheetIndex, current.Stack, 0);
bool flag = !(current is Object) || Game1.player.hasItemInInventory((current as Object).ParentSheetIndex, current.Stack, 0);
/*if (this.magicalConstruction)
{
Utility.drawTextWithShadow(b, current.DisplayName, Game1.dialogueFont, new Vector2(vector.X + (float)Game1.tileSize + (float)(Game1.pixelZoom * 3), vector.Y + (float)(Game1.pixelZoom * 6)), Game1.textColor * 0.25f, 1f, -1f, -1, -1, this.magicalConstruction ? 0f : 0.25f, 3);
Expand Down Expand Up @@ -875,9 +881,9 @@ public override void draw(SpriteBatch b)
else if (this.moving && this.buildingToMove != null)
{
Vector2 vector4 = new Vector2((float)((Game1.viewport.X + Game1.getOldMouseX()) / Game1.tileSize), (float)((Game1.viewport.Y + Game1.getOldMouseY()) / Game1.tileSize));
for (int k = 0; k < this.buildingToMove.tilesHigh; k++)
for (int k = 0; k < this.buildingToMove.tilesHigh.Value; k++)
{
for (int l = 0; l < this.buildingToMove.tilesWide; l++)
for (int l = 0; l < this.buildingToMove.tilesWide.Value; l++)
{
int num2 = this.buildingToMove.getTileSheetIndexForStructurePlacementTile(l, k);
Vector2 vector5 = new Vector2(vector4.X + (float)l, vector4.Y + (float)k);
Expand Down
Loading