Class HexTerrainUserToolStateBase
Provides a base class for user tool states that interact with hex-based terrain, supplying common functionality for managing terrain APIs, tool settings, and view modes.
Inheritance
Implements
Inherited Members
Namespace: Fwt.HexTerrains.UserTools.SM
Assembly: fwt.hexterrains.dll
Syntax
public abstract class HexTerrainUserToolStateBase : UserToolStateBase, ISmState
Remarks
This abstract class is intended to be inherited by user tool state implementations that require access to hex terrain features and UI integration. It centralizes initialization logic, view mode management, and cursor setup for tools operating on hex terrain. Derived classes should override relevant methods to customize behavior for specific tool requirements.
Constructors
HexTerrainUserToolStateBase(ISmState)
Declaration
protected HexTerrainUserToolStateBase(ISmState parent)
Parameters
| Type | Name | Description |
|---|---|---|
| ISmState | parent |
Properties
HexTerrainUserToolSettings
Settings specific to the hex terrain user tool.
Declaration
public virtual HexTerrainUserToolStateSettings HexTerrainUserToolSettings { get; set; }
Property Value
| Type | Description |
|---|---|
| HexTerrainUserToolStateSettings |
PreviousViewMode
The view mode that was active prior to the current one.
Declaration
protected virtual int PreviousViewMode { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
TerrainAPI
The API interface for interacting with hex terrain features.
Declaration
public virtual IHexTerrainAPI TerrainAPI { get; set; }
Property Value
| Type | Description |
|---|---|
| IHexTerrainAPI |
Methods
GetTerrainLayer<TLayerGroup, TLayer>(HexTerrainLayerReference)
Looks for a terrain layer of type TLayer within the terrain layer group specified by TLayerGroup using the provided layer reference.
Declaration
protected virtual TLayer GetTerrainLayer<TLayerGroup, TLayer>(HexTerrainLayerReference layerReference) where TLayerGroup : HexTerrainLayerGroup where TLayer : HexTerrainLayer
Parameters
| Type | Name | Description |
|---|---|---|
| HexTerrainLayerReference | layerReference | reference data to needed layer |
Returns
| Type | Description |
|---|---|
| TLayer | terrain layer if found and null otherwise |
Type Parameters
| Name | Description |
|---|---|
| TLayerGroup | |
| TLayer |
GetUIScreen<TScreen>()
Retrieves an instance of the specified UIScreen type, creating it if it does not already exist.
Declaration
protected virtual TScreen GetUIScreen<TScreen>() where TScreen : UIScreen
Returns
| Type | Description |
|---|---|
| TScreen | An instance of the specified UIScreen type. A new instance is created if one does not already exist. |
Type Parameters
| Name | Description |
|---|---|
| TScreen | The type of UIScreen to retrieve. Must inherit from UIScreen. |
HideSettingsScreen<TScreen>()
Hides the settings screen of the specified type if it is currently active.
Declaration
protected virtual void HideSettingsScreen<TScreen>() where TScreen : UIScreen
Type Parameters
| Name | Description |
|---|---|
| TScreen | The type of settings screen to hide. Must derive from UIScreen. |
Remarks
If the specified screen is not active or does not exist, this method has no effect. Override this method to customize the hiding behavior for specific screen types.
Init(IHexTerrainAPI)
Initializes the instance with the specified terrain API.
Declaration
public virtual void Init(IHexTerrainAPI terrainAPI)
Parameters
| Type | Name | Description |
|---|---|---|
| IHexTerrainAPI | terrainAPI | The terrain API to associate with this instance. Cannot be null. |
Init(HexTerrainUserToolStateSettings)
Initializes the tool with the specified user state settings.
Declaration
public virtual void Init(HexTerrainUserToolStateSettings settings)
Parameters
| Type | Name | Description |
|---|---|---|
| HexTerrainUserToolStateSettings | settings | The user state settings to apply to the tool. Cannot be null. |
Init<TInitArgs>(IHexTerrainAPI, TInitArgs)
Initializes the instance using the specified terrain API and initialization arguments.
Declaration
public virtual void Init<TInitArgs>(IHexTerrainAPI terrainAPI, TInitArgs args)
Parameters
| Type | Name | Description |
|---|---|---|
| IHexTerrainAPI | terrainAPI | An object that provides access to terrain-related functionality required for initialization. Cannot be null. |
| TInitArgs | args | The initialization arguments used to configure the instance. The specific requirements depend on the implementation. |
Type Parameters
| Name | Description |
|---|---|
| TInitArgs | The type of the initialization arguments used to configure the instance. |
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
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.
PrepareToStop()
Performs any necessary actions to prepare the object for stopping or shutdown. Called when the state is about to be deactivated.
Declaration
public override void PrepareToStop()
Overrides
Remarks
Implementations should ensure that all resources are released and any ongoing operations are safely terminated before the object is stopped. This method is typically called prior to disposing or shutting down the object to ensure a clean transition.
SetViewMode(SetViewModeRequest)
Sets the current terrain view mode to the specified value.
Declaration
protected virtual void SetViewMode(SetViewModeRequest request)
Parameters
| Type | Name | Description |
|---|---|---|
| SetViewModeRequest | request |
Remarks
This method stores the previous view mode before updating to the new mode. Derived classes can override this method to implement custom behavior when changing view modes.
SetupTerrainCursor(bool)
Configures the visibility of the terrain brush cursor.
Declaration
protected virtual void SetupTerrainCursor(bool isCursorVisible)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | isCursorVisible | A value indicating whether the terrain cursor should be visible. Specify true to show the cursor; otherwise, false to hide it. |
SetupTerrainCursor(bool, int)
Configures the terrain cursor's visibility and brush size for terrain editing operations.
Declaration
protected virtual void SetupTerrainCursor(bool isCursorVisible, int size)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | isCursorVisible | A value indicating whether the terrain cursor should be visible. Set to true to display the cursor; otherwise, false. |
| int | size | The size of the terrain brush to apply. Must be a positive integer representing the brush diameter in terrain units. |
SetupTerrainCursor(bool, int, Color32)
Configures the terrain cursor's visibility, size, and color for terrain editing operations.
Declaration
protected virtual void SetupTerrainCursor(bool isCursorVisible, int size, Color32 color)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | isCursorVisible | A value indicating whether the terrain cursor should be visible. Set to true to display the cursor; otherwise, false. |
| int | size | The diameter of the terrain cursor brush, in units. Must be a positive integer. |
| Color32 | color | The color to apply to the terrain cursor brush. |
SetupTerrainCursor(bool, int, Color32, bool)
Configures the terrain editing cursor's visibility, size, color, and resizability.
Declaration
protected virtual void SetupTerrainCursor(bool isCursorVisible, int size, Color32 color, bool isResizable)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | isCursorVisible | A value indicating whether the terrain cursor should be visible. Set to true to display the cursor; otherwise, false. |
| int | size | The diameter of the terrain cursor brush, in pixels. Must be a positive integer. |
| Color32 | color | The color to apply to the terrain cursor brush. |
| bool | isResizable | A value indicating whether the terrain cursor brush can be resized interactively. Set to true to allow resizing; otherwise, false. |
ShowSettingsScreen<TViewData, TScreen>(TViewData)
Declaration
protected virtual TScreen ShowSettingsScreen<TViewData, TScreen>(TViewData viewData) where TScreen : UIScreen, IViewDataReceiver<TViewData>
Parameters
| Type | Name | Description |
|---|---|---|
| TViewData | viewData |
Returns
| Type | Description |
|---|---|
| TScreen |
Type Parameters
| Name | Description |
|---|---|
| TViewData | |
| TScreen |
TryRestoreViewMode()
Attempts to restore the previous terrain view mode if a view mode change is enabled in the user tool settings.
Declaration
protected virtual void TryRestoreViewMode()
Remarks
Override this method to customize how the terrain view mode is restored in derived classes. This method has no effect if view mode changes are not enabled.
TrySetViewMode()
Attempts to set the view mode based on the current user tool settings. If a view mode change is required, updates the view mode accordingly.
Declaration
protected virtual void TrySetViewMode()
Remarks
Override this method to customize how the view mode is determined or applied in derived classes. This method does not throw exceptions if no change is needed.