Table of Contents

Class Visual

Namespace
PolyMod.Managers
Assembly
PolyMod.dll

The manager for sprites, textures, terrain graphics, and popups. It also contains the Harmony patches that change how the game shows these items.

public static class Visual
Inheritance
Visual
Inherited Members

Fields

basicPopupWidths

The custom widths of shown popups, keyed by the Unity instance ID of the popup. PolyMod removes an entry when the popup closes.

public static Dictionary<int, Visual.PopupWidth> basicPopupWidths

Field Value

Dictionary<int, Visual.PopupWidth>

Methods

ApplyGaussianBlur(Texture2D, float)

Makes a blurred copy of a texture with a Gaussian blur. The method blurs the rows and then the columns, on more than one thread. It blurs premultiplied colors, so transparent pixels do not make the edges dark. At the edges of the texture, the method uses the nearest edge pixel. The standard deviation is half of the radius, and the kernel reaches three standard deviations.

public static Texture2D ApplyGaussianBlur(Texture2D sourceTexture, float radius = 2)

Parameters

sourceTexture Texture2D

The texture to blur. The method does not change it.

radius float

The radius of the blur, in pixels.

Returns

Texture2D

A new RGBA32 texture without mipmaps.

BuildSprite(byte[], Vector2?, float, bool, float?)

Makes a sprite from the bytes of an image file. The method makes the texture with BuildTexture(byte[]) and the sprite with BuildSpriteWithTexture(Texture2D, Vector2?, float?, bool, float?).

public static Sprite BuildSprite(byte[] data, Vector2? pivot = null, float pixelsPerUnit = 2112, bool transformToOutline = false, float? gaussianBlurRadius = null)

Parameters

data byte[]

The bytes of the image file.

pivot Vector2?

The pivot of the sprite, as a fraction of the sprite size. If null, the pivot is the center.

pixelsPerUnit float

The number of texture pixels in one world unit.

transformToOutline bool

If true, the image changes into a white silhouette with a border.

gaussianBlurRadius float?

The radius of the Gaussian blur, or null for no blur.

Returns

Sprite

The new sprite.

BuildSpriteWithTexture(Texture2D, Vector2?, float?, bool, float?)

Makes a sprite that uses all of a texture. If transformToOutline is true, the method first changes the texture with TransformToOutline(Texture2D, int, Color?). Then, if the blur radius is not null, it applies ApplyGaussianBlur(Texture2D, float).

public static Sprite BuildSpriteWithTexture(Texture2D texture, Vector2? pivot = null, float? pixelsPerUnit = 2112, bool transformToOutline = false, float? gaussianBlurRadius = null)

Parameters

texture Texture2D

The texture for the sprite.

pivot Vector2?

The pivot of the sprite, as a fraction of the sprite size. If null, the pivot is the center.

pixelsPerUnit float?

The number of texture pixels in one world unit. If null, the method uses 2112.

transformToOutline bool

If true, the image changes into a white silhouette with a border.

gaussianBlurRadius float?

The radius of the Gaussian blur, or null for no blur.

Returns

Sprite

The new sprite.

BuildTexture(byte[])

Makes a texture from the bytes of an image file, such as a PNG file. If the image looks premultiplied, the method changes it back to straight alpha. The method also copies color into the transparent pixels near the edges of the image. The texture uses trilinear filter mode, clamp wrap mode, and mipmaps.

public static Texture2D BuildTexture(byte[] data)

Parameters

data byte[]

The bytes of the image file.

Returns

Texture2D

The new texture.

CreateInnerOriginSprites()

Makes and registers the sprites in PolyMod.Managers.Visual.pendingInnerOriginSpriteInfos, and then clears that list. For each entry, the method finds the game sprite with the origin name. If the game sprite does not exist, it writes a warning to the log and skips the entry. If the entry has a pivot, pixels per unit, an outline or a blur, the method makes a new sprite with these settings. A setting that the entry does not have comes from the game sprite. Without these settings, the method registers the game sprite with no changes.

public static void CreateInnerOriginSprites()

CreateSprites()

Makes and registers the sprites from mod textures. First, the method makes a sprite for each entry in PolyMod.Registry.spriteInfos. If the entry has an origin name, the method uses the texture with that name. Otherwise, it uses the texture with the sprite name. It skips an entry without a texture, and keeps Inner entries for CreateInnerOriginSprites(). Then it makes a sprite with the default settings for each texture that does not have a registered sprite with the same name. A texture that only an origin name uses therefore also gets a sprite with its own name.

public static void CreateSprites()

GetResponsivePopupWidth(float, float)

Changes a share of the usable screen width into a popup width in canvas units. The method changes the safe screen width from screen pixels to canvas units with the UI scale of the game. If share is 0 or less, the method gives maximum as a fixed width.

public static int GetResponsivePopupWidth(float share, float maximum)

Parameters

share float

The share of the usable width, from 0 to 1.

maximum float

The maximum width in canvas units. It keeps text easy to read on wide screens.

Returns

int

The width in canvas units, rounded to an integer. For a share above 0, the width is not smaller than the width of the game's own popups.

GetTileTipHeader(ref string, TileData, SkinType, PlayerState, GameState, GameLogicData)

A Harmony postfix on TileTipGenerator.GetTileTipHeader. It removes the localized name of each custom flood effect on the tile from the header text.

[HarmonyPostfix]
[HarmonyPatch(typeof(TileTipGenerator), "GetTileTipHeader")]
public static void GetTileTipHeader(ref string __result, TileData tileData, SkinType skin, PlayerState playerState, GameState gameState, GameLogicData gameLogicData)

Parameters

__result string

The header text that the original method gives.

tileData TileData

The data of the tile.

skin SkinType

The skin that the localization uses.

playerState PlayerState

The player whose tribe the localization uses.

gameState GameState

The state of the game. The patch does not use it.

gameLogicData GameLogicData

The game logic data. The patch does not use it.

PopupContentBuilder_GetMightyLeaderTopImage(ref Sprite, PlayerState)

A Harmony postfix on PopupContentBuilder.GetMightyLeaderTopImage. It replaces the image with the registered mightyleader sprite for the tribe and visual skin of the player, if one exists.

[HarmonyPostfix]
[HarmonyPatch(typeof(PopupContentBuilder), "GetMightyLeaderTopImage")]
public static void PopupContentBuilder_GetMightyLeaderTopImage(ref Sprite __result, PlayerState player)

Parameters

__result Sprite

The image that the original method gives.

player PlayerState

The player that the popup is for.

ShowSetWidth(BasicPopupLegacy, int)

Shows a popup with a fixed custom width. The method adds the width to basicPopupWidths and then shows the popup.

public static void ShowSetWidth(this BasicPopupLegacy self, int width)

Parameters

self BasicPopupLegacy

The popup to show.

width int

The width of the popup, in canvas units.

ShowSetWidth(BasicPopupLegacy, float, float)

Shows a popup with a width that is a share of the usable screen width. The method adds the width settings to basicPopupWidths and then shows the popup. GetResponsivePopupWidth(float, float) calculates the width.

public static void ShowSetWidth(this BasicPopupLegacy self, float share, float maximum)

Parameters

self BasicPopupLegacy

The popup to show.

share float

The share of the usable screen width, from 0 to 1.

maximum float

The maximum width of the popup, in canvas units.

Tile_RenderDebug(Tile)

A Harmony postfix on Tile.RenderDebug. If the showCoordinates setting is on, it adds a child object with white text that shows the tile coordinates. The text uses the terrain sorting layer, above the tile.

[HarmonyPostfix]
[HarmonyPatch(typeof(Tile), "RenderDebug")]
public static void Tile_RenderDebug(Tile __instance)

Parameters

__instance Tile

The tile.

TransformToOutline(Texture2D, int, Color?)

Makes a silhouette texture with a border from the visible pixels of a texture. The new texture is larger than the source texture by the border size on each side. Each pixel within the border size of a visible source pixel gets the given color. All other pixels are transparent. A source pixel is visible if its alpha is more than 0.01.

public static Texture2D TransformToOutline(Texture2D sourceTexture, int borderSizeInPixels = 8, Color? color = null)

Parameters

sourceTexture Texture2D

The texture that gives the shape.

borderSizeInPixels int

The width of the border around the shape, in pixels.

color Color?

The color of the silhouette. If null, the method uses white.

Returns

Texture2D

A new RGBA32 texture without mipmaps.