feat: add eating gizmo to TableBase

made a component tracking if colonists are allowed to eat at a table or not (doesn't actually forbid eating yet)
This commit is contained in:
Maciej Pawłowski 2025-04-17 19:03:28 +02:00
parent 7a5ea082bf
commit c298657f6f
Signed by: maciek
GPG key ID: 9FC186633565C9C7
3 changed files with 132 additions and 0 deletions

35
Patches/Tables.xml Normal file
View file

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2025 Maciej Pawłowski
This file is part of "Table Eating Toggle".
"Table Eating Toggle" is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
"Table Eating Toggle" is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with "Table Eating Toggle". If not, see <https://www.gnu.org/licenses/>.
-->
<Patch>
<Operation Class="PatchOperationSequence">
<operations>
<li Class="PatchOperationConditional">
<xpath>Defs/ThingDef[@Name="TableBase"]/comps</xpath>
<nomatch Class="PatchOperationAdd">
<xpath>Defs/ThingDef[@Name="TableBase"]</xpath>
<value>
<comps />
</value>
</nomatch>
</li>
<li Class="PatchOperationAdd">
<xpath>Defs/ThingDef[@Name="TableBase"]/comps</xpath>
<value>
<li>
<compClass>TableToggle.EatableComp</compClass>
</li>
</value>
</li>
</operations>
</Operation>
</Patch>

52
Source/EatableComp.cs Normal file
View file

@ -0,0 +1,52 @@
/*
Copyright 2025 Maciej Pawłowski
This file is part of "Table Eating Toggle".
"Table Eating Toggle" is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
"Table Eating Toggle" is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with "Table Eating Toggle". If not, see <https://www.gnu.org/licenses/>.
*/
using System.Collections.Generic;
using RimWorld;
using Verse;
namespace TableToggle;
public class EatableComp : ThingComp
{
public bool EatableFrom = true;
public override IEnumerable<Gizmo> CompGetGizmosExtra()
{
foreach (Gizmo item in base.CompGetGizmosExtra())
{
yield return item;
}
if (parent.Faction == Faction.OfPlayer)
{
Command_Toggle command_Toggle = new()
{
icon = TexCommand.ForbidOff,
isActive = () => EatableFrom,
defaultLabel = "eating",
defaultDesc = "Colonists will eat from this table.",
toggleAction = delegate
{
EatableFrom = !EatableFrom;
}
};
if (!EatableFrom)
{
command_Toggle.defaultDesc = "Colonists will not eat from this table.";
}
yield return command_Toggle;
}
}
public override void PostExposeData()
{
Scribe_Values.Look(ref EatableFrom, "eatable", defaultValue: true);
}
}

45
Source/TableToggle.csproj Normal file
View file

@ -0,0 +1,45 @@
<Project Sdk="Microsoft.NET.Sdk">
<!--
Copyright 2025 Maciej Pawłowski
This file is part of "Table Eating Toggle".
"Table Eating Toggle" is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
"Table Eating Toggle" is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with "Table Eating Toggle". If not, see <https://www.gnu.org/licenses/>.
-->
<PropertyGroup>
<OutputPath>../Assemblies</OutputPath>
<TargetFramework>net48</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<!-- <Nullable>enable</Nullable> -->
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>../Assemblies</OutputPath>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp.dll">
<HintPath>../../../RimWorldLinux_Data/Managed/Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.CoreModule.dll">
<HintPath>../../../RimWorldLinux_Data/Managed/UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
</Project>