riversong code showcase

This commit is contained in:
Daniele Marotta
2026-05-21 15:52:18 +02:00
commit 4c9eea1c02
462 changed files with 23406 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
namespace DanieleMarotta.RiversongCodeShowcase
{
public class TimePanelModel : UIModel
{
public int Week { get; private set; }
public int Month { get; private set; }
public int Year { get; private set; }
public void Update(int week, int month, int year)
{
Week = week;
Month = month;
Year = year;
NotifyPropertyChanged();
}
}
}

View File

@@ -0,0 +1,49 @@
using System;
using Cysharp.Threading.Tasks;
namespace DanieleMarotta.RiversongCodeShowcase
{
public class TimePanelUIController : UIControllerSystem<TimePanelUIView>, IDisposable
{
[InjectService]
private World _world;
[InjectService]
private ISignalBus _signalBus;
private TimePanelModel _model;
public TimePanelUIController(IServiceLocator serviceLocator) : base(serviceLocator)
{
}
protected override TimePanelUIView View => UIRoot.GetView<TimePanelUIView>();
public override async UniTask InitializeAsync()
{
await base.InitializeAsync();
_model = new TimePanelModel();
UpdateModel();
View.SetModel(_model);
_signalBus.Subscribe<EndOfWeekSignal>(OnEndOfWeekSignal);
}
public void Dispose()
{
_signalBus.Unsubscribe<EndOfWeekSignal>(OnEndOfWeekSignal);
}
private void OnEndOfWeekSignal(EndOfWeekSignal signal)
{
UpdateModel();
}
private void UpdateModel()
{
var timeState = _world.TimeState;
_model.Update(timeState.WeekNumber, timeState.MonthNumber, timeState.YearNumber);
}
}
}

View File

@@ -0,0 +1,45 @@
using Cysharp.Threading.Tasks;
using UnityEngine.UIElements;
namespace DanieleMarotta.RiversongCodeShowcase
{
[UIView("time-panel")]
public class TimePanelUIView : UIView<TimePanelModel>
{
private Label _weekNumberText;
private Label _monthNumberText;
private Label _yearNumberText;
public override async UniTask InitializeAsync(UIService uiService, VisualElement rootElement)
{
await base.InitializeAsync(uiService, rootElement);
_weekNumberText = rootElement.Q<Label>(className: "time-panel__week-number");
_monthNumberText = rootElement.Q<Label>(className: "time-panel__month-number");
_yearNumberText = rootElement.Q<Label>(className: "time-panel__year-number");
}
protected override void OnNewModel(TimePanelModel model)
{
base.OnNewModel(model);
UpdateText();
}
protected override void OnModelPropertyChanged(object sender, BindablePropertyChangedEventArgs e)
{
base.OnModelPropertyChanged(sender, e);
UpdateText();
}
private void UpdateText()
{
_weekNumberText.text = $"Week {Model.Week + 1},";
_monthNumberText.text = $"Month {Model.Month + 1},";
_yearNumberText.text = $"Year {Model.Year + 1}";
}
}
}