table-eating-toggle/Source/EatableComp.cs
maciek c298657f6f
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)
2025-04-17 19:03:28 +02:00

52 lines
1.8 KiB
C#

/*
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);
}
}