Class Visual
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
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
sourceTextureTexture2DThe texture to blur. The method does not change it.
radiusfloatThe 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
databyte[]The bytes of the image file.
pivotVector2?The pivot of the sprite, as a fraction of the sprite size. If null, the pivot is the center.
pixelsPerUnitfloatThe number of texture pixels in one world unit.
transformToOutlineboolIf true, the image changes into a white silhouette with a border.
gaussianBlurRadiusfloat?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
textureTexture2DThe texture for the sprite.
pivotVector2?The pivot of the sprite, as a fraction of the sprite size. If null, the pivot is the center.
pixelsPerUnitfloat?The number of texture pixels in one world unit. If null, the method uses 2112.
transformToOutlineboolIf true, the image changes into a white silhouette with a border.
gaussianBlurRadiusfloat?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
databyte[]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
sharefloatThe share of the usable width, from 0 to 1.
maximumfloatThe 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
__resultstringThe header text that the original method gives.
tileDataTileDataThe data of the tile.
skinSkinTypeThe skin that the localization uses.
playerStatePlayerStateThe player whose tribe the localization uses.
gameStateGameStateThe state of the game. The patch does not use it.
gameLogicDataGameLogicDataThe 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
__resultSpriteThe image that the original method gives.
playerPlayerStateThe 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
selfBasicPopupLegacyThe popup to show.
widthintThe 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
selfBasicPopupLegacyThe popup to show.
sharefloatThe share of the usable screen width, from 0 to 1.
maximumfloatThe 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
__instanceTileThe 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
sourceTextureTexture2DThe texture that gives the shape.
borderSizeInPixelsintThe width of the border around the shape, in pixels.
colorColor?The color of the silhouette. If null, the method uses white.
Returns
- Texture2D
A new RGBA32 texture without mipmaps.