Class StampUserToolStateBase<TBrushTarget, TTerrainLayer, TCellData>
Provides a base class for stamp-style terrain editing user tool states, enabling cell data to be read from an origin cell and applied to other cells within a hex terrain layer group.
Inheritance
Implements
Inherited Members
Namespace: Fwt.HexTerrains.UserTools.SM.States
Assembly: fwt.hexterrains.dll
Syntax
public abstract class StampUserToolStateBase<TBrushTarget, TTerrainLayer, TCellData> : BrushUserToolState<TBrushTarget, UserToolSettingsDataSource, UniversalToolSettingsScreen, TTerrainLayer>, ISmState where TBrushTarget : HexTerrainLayerGroup where TTerrainLayer : HexTerrainLayer
Type Parameters
| Name | Description |
|---|---|
| TBrushTarget | The type of the terrain layer group that the brush operates on. Must be a HexTerrainLayerGroup. |
| TTerrainLayer | The type of terrain layer being edited. Must be a HexTerrainLayer. |
| TCellData | The type of cell data that is read from the origin cell and applied to target cells. |
Remarks
This class manages the origin cell coordinates and index, and facilitates reading and applying cell data between terrain layers. It supports configuration of the key used to read cell data and provides mechanisms for saving and loading tool settings. Derived classes must implement logic for reading cell data from the origin and applying it to the target cell. Thread safety is not guaranteed.
Constructors
StampUserToolStateBase(ISmState)
Declaration
protected StampUserToolStateBase(ISmState parent)
Parameters
| Type | Name | Description |
|---|---|---|
| ISmState | parent |
Properties
OriginCellIndex
The index of the origin cell based on the origin coordinates.
Declaration
public virtual int? OriginCellIndex { get; }
Property Value
| Type | Description |
|---|---|
| int? |
OriginCoordinate
The origin coordinate as an int2 structure.
Declaration
public virtual int2 OriginCoordinate { get; set; }
Property Value
| Type | Description |
|---|---|
| int2 |
OriginXCoord
The X-coordinate of the origin point.
Declaration
public virtual int OriginXCoord { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
OriginYCoord
The Y-coordinate of the origin point in the data source.
Declaration
public virtual int OriginYCoord { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
ReadCellKey
When this key is pressed, the tool changes the origin cell to the cell under the cursor.
Declaration
public virtual KeyCode ReadCellKey { get; set; }
Property Value
| Type | Description |
|---|---|
| KeyCode |
StartPaintCellCoord
The starting cell coordinate when painting begins.
Declaration
protected virtual int2? StartPaintCellCoord { get; set; }
Property Value
| Type | Description |
|---|---|
| int2? |
TerrainLayerIndex
If IsGetLayerByIndex is true, this index is used to get terrain layer from terrain layers list."/>
Declaration
public override int TerrainLayerIndex { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
Overrides
Methods
ApplyBrush(int, int2, int, TBrushTarget, int)
Applies brush to the brushView. Returns true if changes were applied
Declaration
public override bool ApplyBrush(int brushMode, int2 cellCoord, int cellIndex, TBrushTarget brushTarget, int mouseButton)
Parameters
| Type | Name | Description |
|---|---|---|
| int | brushMode | |
| int2 | cellCoord | |
| int | cellIndex | |
| TBrushTarget | brushTarget | |
| int | mouseButton |
Returns
| Type | Description |
|---|---|
| bool |
Overrides
Init(UserToolStateSettings)
Initializes the tool state with the specified settings.
Declaration
public override void Init(UserToolStateSettings settings)
Parameters
| Type | Name | Description |
|---|---|---|
| UserToolStateSettings | settings | The settings to apply to the tool state. Cannot be null. |
Overrides
InitDefaultSettings()
Initializes the default settings for the current instance. This method is intended to be overridden in derived classes to configure initial values or options as needed.
Declaration
protected override void InitDefaultSettings()
Overrides
Remarks
Override this method in a subclass to provide custom initialization logic for default settings. The base implementation does not perform any actions.
Init<TInitArgs>(TInitArgs)
Initializes the tool using the specified initialization arguments.
Declaration
public override void Init<TInitArgs>(TInitArgs args)
Parameters
| Type | Name | Description |
|---|---|---|
| TInitArgs | args | The initialization arguments used to configure the tool. If the argument implements IUserToolStateConfig, its ToolSettings are used; otherwise, default settings are applied. |
Type Parameters
| Name | Description |
|---|---|
| TInitArgs | The type of the initialization arguments used to configure the tool. If the type implements IUserToolStateConfig, its ToolSettings will be used; otherwise, default settings are applied. |
Overrides
LoadSettings()
Loads configuration settings for the current instance. Derived classes override this method to implement custom settings initialization.
Declaration
protected override void LoadSettings()
Overrides
Remarks
Override this method in a subclass to provide specific logic for loading or initializing settings. This method is called during the setup or initialization phase and does not perform any actions in the base implementation.
PrepareToRun()
Performs any necessary initialization or setup required before executing the main operation. Called by state machine once when state becomes active. If state is disabled and then enabled again, this method will be called again.
Declaration
public override void PrepareToRun()
Overrides
Remarks
Override this method to implement preparation logic specific to the derived class. This method should be called prior to running the core functionality to ensure all prerequisites are met.
ReadOriginCellData(TTerrainLayer, int, out TCellData)
Attempts to read the original cell data for the specified terrain layer and cell index.
Declaration
public abstract bool ReadOriginCellData(TTerrainLayer terrainLayer, int cellIndex, out TCellData cellData)
Parameters
| Type | Name | Description |
|---|---|---|
| TTerrainLayer | terrainLayer | The terrain layer from which to retrieve cell data. Cannot be null. |
| int | cellIndex | The zero-based index of the cell within the terrain layer whose data is to be read. Must be within the valid range of cell indices for the specified layer. |
| TCellData | cellData | When this method returns, contains the cell data associated with the specified cell index if the operation succeeds; otherwise, contains the default value for the cell data type. |
Returns
| Type | Description |
|---|---|
| bool | true if the cell data was successfully read; otherwise, false. |
SaveSettings()
Saves the current settings to the underlying storage or configuration source.
Declaration
protected override void SaveSettings()
Overrides
Remarks
Override this method in a derived class to implement custom logic for persisting settings. This method does not perform any action in the base implementation.
SetCellDataToTarget(TTerrainLayer, int, TCellData)
Attempts to set the specified cell data on the target terrain layer at the given cell index.
Declaration
public abstract bool SetCellDataToTarget(TTerrainLayer terrainLayer, int cellIndex, TCellData cellData)
Parameters
| Type | Name | Description |
|---|---|---|
| TTerrainLayer | terrainLayer | The terrain layer on which to set the cell data. Cannot be null. |
| int | cellIndex | The zero-based index of the cell within the terrain layer to update. Must be within the valid range of cell indices for the layer. |
| TCellData | cellData | The cell data to assign to the specified cell. Cannot be null. |
Returns
| Type | Description |
|---|---|
| bool | true if the cell data was successfully set; otherwise, false. |
Remarks
This method does not modify the terrain layer if the cell index is out of range or if the cell data is invalid. Implementations may impose additional constraints on valid cell data or indices.
UpdateBrush()
Updates the terrain brush's appearance and behavior based on the current input state and configuration. This includes setting brush visibility, color, size, and opacity according to user interactions and allowed changes.
Declaration
protected override void UpdateBrush()
Overrides
Remarks
This method responds to user input to adjust the brush size or opacity, depending on the active mode and configuration flags. It is typically called to synchronize the brush's properties with the user's actions in real time. Override this method to customize how brush updates are handled in derived classes.