36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using Unity.Mathematics;
|
|
|
|
namespace DanieleMarotta.RiversongCodeShowcase
|
|
{
|
|
public class PopulationPanelUIController : UIControllerSystem<PopulationPanelUIView>, IUpdatable
|
|
{
|
|
[InjectService]
|
|
private World _world;
|
|
|
|
private PopulationPanelModel _model;
|
|
|
|
public PopulationPanelUIController(IServiceLocator serviceLocator) : base(serviceLocator)
|
|
{
|
|
}
|
|
|
|
protected override PopulationPanelUIView View => UIRoot.GetView<PopulationPanelUIView>();
|
|
|
|
public override async UniTask InitializeAsync()
|
|
{
|
|
await base.InitializeAsync();
|
|
|
|
_model = new PopulationPanelModel();
|
|
View.SetModel(_model);
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
var population = _world.PopulationState.Population;
|
|
var happiness = math.clamp((int)math.round(_world.PopulationState.Happiness * 100), 0, 100);
|
|
_model.Update(population, happiness, _world.ProductionState.LaborTier);
|
|
|
|
View.UpdateHappinessIconAnimation();
|
|
}
|
|
}
|
|
} |