Game.UI.Editor.SeasonWheel
Assembly: Assembly-CSharp
Namespace: Game.UI.Editor
Type: public class SeasonWheel
Base: Widget
Summary:
SeasonWheel is a UI widget used by the in-game editor to display and edit seasonal entries (the "season wheel"). It exposes a small model (Season struct) for a season entry (entity, start time within the year, and temperature) and an IAdapter interface that the host code implements to provide the list of seasons, react to selection changes, and update season start times. SeasonWheel detects changes from the adapter and updates its serialized properties for the UI (selectedSeason and seasons). It also includes a Bindings factory that enables UI binding triggers (e.g., setSelectedSeason and setSeasonStartTimeOfYear).
Fields
-
private Entity m_SelectedSeason
Holds the currently selected season entity as seen by the widget. This is synchronized from adapter.selectedSeason during Update(). -
private List<Season> m_Seasons = new List<Season>()
Cached list of Season entries received from the adapter. The widget compares this list to adapter.seasons and updates when they differ.
Nested types
public struct Season : IJsonWritable, IEquatable<Season>
- Fields:
Entity entity
— entity identifier for the season entry (Unity.Entities.Entity).Bounds1 startTimeOfYear
— start time range within the year (Colossal.Mathematics.Bounds1).float temperature
— season temperature value.
-
Implements:
void Write(IJsonWriter writer)
— serializes the Season for UI/JSON usage.bool Equals(Season other)
/ overrides of Equals(object) and GetHashCode() — equality/comparison logic (based on startTimeOfYear and temperature).- Equality operators
==
and!=
.
-
public interface IAdapter
- Properties:
Entity selectedSeason { get; set; }
— get/set the currently selected season entity.IEnumerable<Season> seasons { get; }
— current sequence of seasons provided to the widget.
-
Methods:
void SetStartTimeOfYear(Entity season, Bounds1 startTimeOfYear)
— request to change the start time for a season (called by the widget via binding).
-
public class Bindings : IWidgetBindingFactory
- Methods:
IEnumerable<IBinding> CreateBindings(string group, IReader<IWidget> pathResolver, ValueChangedCallback onValueChanged)
— returns two TriggerBindings:- "setSelectedSeason" — sets adapter.selectedSeason when triggered.
- "setSeasonStartTimeOfYear" — calls adapter.SetStartTimeOfYear(...) and calls onValueChanged(widget) to notify changes.
Properties
public IAdapter adapter { get; set; }
Adapter used by the SeasonWheel to obtain seasons and to apply changes. Implement this interface in your UI/controller layer to supply data and handle edits.
Constructors
public SeasonWheel()
Default parameterless constructor (inherited default). The widget relies on the adapter being set externally after instantiation.
Methods
-
protected override WidgetChanges Update()
Checks adapter.selectedSeason and adapter.seasons for changes. If the selected season or the seasons list changed, marks WidgetChanges.Properties and updates the internal caches (m_SelectedSeason and m_Seasons). This drives the widget to reserialize its properties to the frontend. -
protected override void WriteProperties(IJsonWriter writer)
Writes the widget properties used by the UI: - "selectedSeason" — the current selected season entity.
-
"seasons" — the list of Season entries (serialized via IJsonWritable).
-
public IEnumerable<IBinding> Bindings.CreateBindings(string group, IReader<IWidget> pathResolver, ValueChangedCallback onValueChanged)
Creates two trigger bindings used by UI scripts to invoke widget actions: - setSelectedSeason(widget, Entity) — sets adapter.selectedSeason.
-
setSeasonStartTimeOfYear(widget, Entity, Bounds1) — sets season start time via adapter and triggers onValueChanged to refresh bindings.
-
Season.Write(IJsonWriter writer)
Serializes a Season instance to JSON for UI consumption (entity, startTimeOfYear, temperature). -
Season.Equals
,GetHashCode
,operator ==
,operator !=
Equality helpers so seasons can be compared (used in SequenceEqual checks, caching, etc.).
Usage Example
// Example adapter implementation and usage of SeasonWheel
public class MySeasonAdapter : SeasonWheel.IAdapter
{
public Entity selectedSeason { get; set; }
private List<SeasonWheel.Season> _seasons = new List<SeasonWheel.Season>();
public IEnumerable<SeasonWheel.Season> seasons => _seasons;
public void SetStartTimeOfYear(Entity season, Bounds1 startTimeOfYear)
{
// Apply change in your game data, e.g. update the component/authoritative model
var entry = _seasons.Find(s => s.entity == season);
if (entry.entity != Entity.Null)
{
entry.startTimeOfYear = startTimeOfYear;
// persist or notify model changes as needed
}
}
// helper to populate seasons
public void Populate(IEnumerable<SeasonWheel.Season> values)
{
_seasons.Clear();
_seasons.AddRange(values);
}
}
// Creating and wiring the widget
var seasonWheel = new SeasonWheel();
seasonWheel.adapter = new MySeasonAdapter();
// Later, ensure your UI loop calls widget.Update()/serializes properties as part of the UI framework.
// Bindings.CreateBindings(...) can be used by the UI markup/system to hook triggers like "setSelectedSeason".