|
| 1 | +using System.Resources; |
| 2 | +using Intersect.Client.Framework.Content; |
| 3 | +using Intersect.Client.Framework.File_Management; |
| 4 | +using Intersect.Client.Framework.GenericClasses; |
| 5 | +using Intersect.Client.Framework.Graphics; |
| 6 | +using Intersect.Client.Framework.Gwen.Control; |
| 7 | +using Intersect.Client.Framework.Gwen.Skin.Texturing; |
| 8 | +using Intersect.Core; |
| 9 | +using Microsoft.Extensions.Logging; |
| 10 | +using Single = Intersect.Client.Framework.Gwen.Skin.Texturing.Single; |
| 11 | + |
| 12 | +namespace Intersect.Client.Framework.Gwen.Skin; |
| 13 | + |
| 14 | + |
| 15 | +/// <summary> |
| 16 | +/// Base textured skin. |
| 17 | +/// </summary> |
| 18 | +public class IntersectSkin : TexturedBase |
| 19 | +{ |
| 20 | + private static GameTexture LoadEmbeddedSkinTexture(GameContentManager contentManager) |
| 21 | + { |
| 22 | + const string skinTextureName = "skin-intersect.png"; |
| 23 | + var skinResourceName = $"{typeof(IntersectSkin).Namespace}.{skinTextureName}"; |
| 24 | + var resourceNames = typeof(IntersectSkin).Assembly.GetManifestResourceNames(); |
| 25 | + if (!resourceNames.Contains(skinResourceName)) |
| 26 | + { |
| 27 | + throw new MissingManifestResourceException("Missing embedded Intersect GWEN skin"); |
| 28 | + } |
| 29 | + |
| 30 | + if (contentManager.GetTexture(TextureType.Gui, skinTextureName) is { } textureFromFile) |
| 31 | + { |
| 32 | + ApplicationContext.Context.Value?.Logger.LogDebug( |
| 33 | + "{SkinName} was found on disk, not using embedded version", |
| 34 | + skinTextureName |
| 35 | + ); |
| 36 | + return textureFromFile; |
| 37 | + } |
| 38 | + |
| 39 | + ApplicationContext.Context.Value?.Logger.LogDebug( |
| 40 | + "{SkinName} was not found on disk, using embedded version", |
| 41 | + skinTextureName |
| 42 | + ); |
| 43 | + |
| 44 | + return contentManager.Load<GameTexture>( |
| 45 | + ContentType.Interface, |
| 46 | + skinTextureName, |
| 47 | + () => typeof(IntersectSkin).Assembly.GetManifestResourceStream(skinResourceName) ?? |
| 48 | + throw new MissingManifestResourceException($"Missing '{skinResourceName}") |
| 49 | + ); |
| 50 | + } |
| 51 | + |
| 52 | + public IntersectSkin(Renderer.Base renderer, GameContentManager contentManager) : base( |
| 53 | + renderer, |
| 54 | + LoadEmbeddedSkinTexture(contentManager) |
| 55 | + ) |
| 56 | + { |
| 57 | + |
| 58 | + } |
| 59 | + |
| 60 | + /// <summary> |
| 61 | + /// Initializes a new instance of the <see cref="TexturedBase" /> class. |
| 62 | + /// </summary> |
| 63 | + /// <param name="renderer">Renderer to use.</param> |
| 64 | + /// <param name="contentManager"></param> |
| 65 | + /// <param name="textureName"></param> |
| 66 | + public IntersectSkin(Renderer.Base renderer, GameContentManager contentManager, string textureName) : base( |
| 67 | + renderer, |
| 68 | + contentManager, |
| 69 | + textureName |
| 70 | + ) |
| 71 | + { |
| 72 | + } |
| 73 | + |
| 74 | + /// <summary> |
| 75 | + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. |
| 76 | + /// </summary> |
| 77 | + public override void Dispose() |
| 78 | + { |
| 79 | + base.Dispose(); |
| 80 | + } |
| 81 | + |
| 82 | + #region Initialization |
| 83 | + |
| 84 | + protected override void InitializeTextures() |
| 85 | + { |
| 86 | + base.InitializeTextures(); |
| 87 | + |
| 88 | + mTextures.Input.Button.Normal = new Bordered(_texture, 48, 0, 12, 12, Margin.Four); |
| 89 | + mTextures.Input.Button.Disabled = new Bordered(_texture, 48, 24, 12, 12, Margin.Four); |
| 90 | + mTextures.Input.Button.Hovered = new Bordered(_texture, 48, 12, 12, 12, Margin.Four); |
| 91 | + mTextures.Input.Button.Pressed = new Bordered(_texture, 48, 36, 12, 12, Margin.Four); |
| 92 | + |
| 93 | + mTextures.CheckBox.Default.Box = new Single(_texture, 84, 0, 22, 22); |
| 94 | + mTextures.CheckBox.Default.Fill = new Single(_texture, 106, 0, 22, 22); |
| 95 | + mTextures.CheckBox.Active.Box = new Single(_texture, 84, 22, 22, 22); |
| 96 | + mTextures.CheckBox.Active.Fill = new Single(_texture, 106, 22, 22, 22); |
| 97 | + mTextures.CheckBox.Hovered.Box = new Single(_texture, 84, 44, 22, 22); |
| 98 | + mTextures.CheckBox.Hovered.Fill = new Single(_texture, 106, 44, 22, 22); |
| 99 | + mTextures.CheckBox.Disabled.Box = new Single(_texture, 84, 66, 22, 22); |
| 100 | + mTextures.CheckBox.Disabled.Fill = new Single(_texture, 106, 66, 22, 22); |
| 101 | + |
| 102 | + mTextures.Panel.Normal = new Bordered(_texture, 32, 0, 16, 16, Margin.Four); |
| 103 | + mTextures.Panel.Highlight = new Bordered(_texture, 32, 16, 16, 16, Margin.Four); |
| 104 | + mTextures.Panel.Bright = new Bordered(_texture, 32, 32, 16, 16, Margin.Four); |
| 105 | + mTextures.Panel.Dark = new Bordered(_texture, 32, 48, 16, 16, Margin.Four); |
| 106 | + |
| 107 | + mTextures.RadioButton.Default.Box = new Single(_texture, 128, 0, 22, 22); |
| 108 | + mTextures.RadioButton.Default.Fill = new Single(_texture, 150, 0, 22, 22); |
| 109 | + mTextures.RadioButton.Active.Box = new Single(_texture, 128, 22, 22, 22); |
| 110 | + mTextures.RadioButton.Active.Fill = new Single(_texture, 150, 22, 22, 22); |
| 111 | + mTextures.RadioButton.Hovered.Box = new Single(_texture, 128, 44, 22, 22); |
| 112 | + mTextures.RadioButton.Hovered.Fill = new Single(_texture, 150, 44, 22, 22); |
| 113 | + mTextures.RadioButton.Disabled.Box = new Single(_texture, 128, 66, 22, 22); |
| 114 | + mTextures.RadioButton.Disabled.Fill = new Single(_texture, 150, 66, 22, 22); |
| 115 | + |
| 116 | + mTextures.Tab.Control = new Bordered(_texture, 0, 48, 16, 16, Margin.Four); |
| 117 | + mTextures.Tab.Top.Active = new Bordered(_texture, 0, 64, 16, 10, new Margin(4, 4, 4, 2)); |
| 118 | + mTextures.Tab.Top.Inactive = new Bordered(_texture, 16, 64, 16, 10, new Margin(4, 4, 4, 2)); |
| 119 | + mTextures.Tab.Bottom.Active = new Bordered(_texture, 0, 80, 16, 10, new Margin(4, 2, 4, 4)); |
| 120 | + mTextures.Tab.Bottom.Inactive = new Bordered(_texture, 16, 80, 16, 10, new Margin(4, 2, 4, 4)); |
| 121 | + mTextures.Tab.Right.Active = new Bordered(_texture, 0, 96, 10, 16, new Margin(2, 4, 4, 4)); |
| 122 | + mTextures.Tab.Right.Inactive = new Bordered(_texture, 16, 96, 10, 16, new Margin(2, 4, 4, 4)); |
| 123 | + mTextures.Tab.Left.Active = new Bordered(_texture, 0, 112, 10, 16, new Margin(4, 4, 2, 4)); |
| 124 | + mTextures.Tab.Left.Inactive = new Bordered(_texture, 16, 112, 10, 16, new Margin(4, 4, 2, 4)); |
| 125 | + |
| 126 | + mTextures.TextBox.Normal = new Bordered(_texture, 32, 64, 16, 16, Margin.Four); |
| 127 | + mTextures.TextBox.Focus = new Bordered(_texture, 32, 80, 16, 16, Margin.Four); |
| 128 | + mTextures.TextBox.Disabled = new Bordered(_texture, 32, 96, 16, 16, Margin.Four); |
| 129 | + |
| 130 | + mTextures.Tooltip = new Bordered(_texture, 64, 96, 16, 16, Margin.Four); |
| 131 | + |
| 132 | + mTextures.Tree.Background = new Bordered(_texture, 32, 112, 16, 16, Margin.Four); |
| 133 | + mTextures.Tree.Plus = new Single(_texture, 448, 96, 15, 15); |
| 134 | + mTextures.Tree.Minus = new Single(_texture, 464, 96, 15, 15); |
| 135 | + |
| 136 | + mTextures.Window.Normal = new Bordered(_texture, 0, 24, 16, 16, Margin.Four); |
| 137 | + mTextures.Window.ActiveTitleBar = new Bordered(_texture, 0, 0, 16, 24, Margin.Four); |
| 138 | + mTextures.Window.Inactive = new Bordered(_texture, 16, 24, 16, 16, Margin.Four); |
| 139 | + mTextures.Window.InactiveTitleBar = new Bordered(_texture, 16, 0, 16, 24, Margin.Four); |
| 140 | + |
| 141 | + mTextures.Window.Close = new Single(_texture, 60, 0, 24, 24); |
| 142 | + mTextures.Window.CloseDown = new Single(_texture, 60, 24, 24, 24); |
| 143 | + mTextures.Window.CloseDisabled = new Single(_texture, 60, 48, 24, 24); |
| 144 | + mTextures.Window.CloseHover = new Single(_texture, 60, 72, 24, 24); |
| 145 | + } |
| 146 | + |
| 147 | + #endregion |
| 148 | + |
| 149 | + #region Rendering Overrides |
| 150 | + |
| 151 | + public override void DrawCheckBox(Control.Base control, bool selected, bool hovered, bool depressed) |
| 152 | + { |
| 153 | + if (!(control is CheckBox checkBox)) |
| 154 | + { |
| 155 | + return; |
| 156 | + } |
| 157 | + |
| 158 | + if (TryGetOverrideTexture(checkBox, selected, depressed, out var overrideTexture)) |
| 159 | + { |
| 160 | + Renderer.DrawColor = checkBox.RenderColor; |
| 161 | + Renderer.DrawTexturedRect(overrideTexture, checkBox.RenderBounds, checkBox.RenderColor); |
| 162 | + return; |
| 163 | + } |
| 164 | + |
| 165 | + SkinTextures._FillableButton buttonState = mTextures.CheckBox.Default; |
| 166 | + if (checkBox.IsDisabled) |
| 167 | + { |
| 168 | + buttonState = mTextures.CheckBox.Disabled; |
| 169 | + } |
| 170 | + else if (depressed) |
| 171 | + { |
| 172 | + buttonState = mTextures.CheckBox.Active; |
| 173 | + } |
| 174 | + else if (hovered) |
| 175 | + { |
| 176 | + buttonState = mTextures.CheckBox.Hovered; |
| 177 | + } |
| 178 | + |
| 179 | + buttonState.Box.Draw(Renderer, checkBox.RenderBounds, checkBox.RenderColor); |
| 180 | + if (checkBox.IsChecked) |
| 181 | + { |
| 182 | + buttonState.Fill.Draw(Renderer, checkBox.RenderBounds, checkBox.RenderColor); |
| 183 | + } |
| 184 | + } |
| 185 | + |
| 186 | + public override void DrawRadioButton(Control.Base control, bool selected, bool hovered, bool depressed) |
| 187 | + { |
| 188 | + if (!(control is RadioButton radioButton)) |
| 189 | + { |
| 190 | + return; |
| 191 | + } |
| 192 | + |
| 193 | + if (TryGetOverrideTexture(radioButton, selected, depressed, out var overrideTexture)) |
| 194 | + { |
| 195 | + Renderer.DrawColor = radioButton.RenderColor; |
| 196 | + Renderer.DrawTexturedRect(overrideTexture, radioButton.RenderBounds, radioButton.RenderColor); |
| 197 | + return; |
| 198 | + } |
| 199 | + |
| 200 | + SkinTextures._FillableButton buttonState = mTextures.RadioButton.Default; |
| 201 | + if (radioButton.IsDisabled) |
| 202 | + { |
| 203 | + buttonState = mTextures.RadioButton.Disabled; |
| 204 | + } |
| 205 | + else if (depressed) |
| 206 | + { |
| 207 | + buttonState = mTextures.RadioButton.Active; |
| 208 | + } |
| 209 | + else if (hovered) |
| 210 | + { |
| 211 | + buttonState = mTextures.RadioButton.Hovered; |
| 212 | + } |
| 213 | + |
| 214 | + buttonState.Box.Draw(Renderer, radioButton.RenderBounds, radioButton.RenderColor); |
| 215 | + if (radioButton.IsChecked) |
| 216 | + { |
| 217 | + buttonState.Fill.Draw(Renderer, radioButton.RenderBounds, radioButton.RenderColor); |
| 218 | + } |
| 219 | + } |
| 220 | + |
| 221 | + |
| 222 | + public override void DrawWindow(Control.Base control, int topHeight, bool inFocus) |
| 223 | + { |
| 224 | + if (control is not WindowControl windowControl) |
| 225 | + { |
| 226 | + return; |
| 227 | + } |
| 228 | + |
| 229 | + GameTexture? renderTexture = null; |
| 230 | + if (windowControl.TryGetTexture(WindowControl.ControlState.Active, out var activeTexture)) |
| 231 | + { |
| 232 | + renderTexture = activeTexture; |
| 233 | + } |
| 234 | + |
| 235 | + if (windowControl.TryGetTexture(WindowControl.ControlState.Inactive, out var inactiveTexture)) |
| 236 | + { |
| 237 | + renderTexture = inactiveTexture; |
| 238 | + } |
| 239 | + |
| 240 | + if (renderTexture != null) |
| 241 | + { |
| 242 | + Renderer.DrawColor = control.RenderColor; |
| 243 | + Renderer.DrawTexturedRect(renderTexture, control.RenderBounds, control.RenderColor); |
| 244 | + return; |
| 245 | + } |
| 246 | + |
| 247 | + Bordered titleBar; |
| 248 | + Bordered frame; |
| 249 | + |
| 250 | + if (inFocus) |
| 251 | + { |
| 252 | + titleBar = mTextures.Window.ActiveTitleBar; |
| 253 | + frame = mTextures.Window.Normal; |
| 254 | + } |
| 255 | + else |
| 256 | + { |
| 257 | + titleBar = mTextures.Window.InactiveTitleBar; |
| 258 | + frame = mTextures.Window.Inactive; |
| 259 | + } |
| 260 | + |
| 261 | + Rectangle frameBounds = windowControl.Bounds; |
| 262 | + |
| 263 | + var shouldDrawTitlebarBackground = titleBar != default && windowControl.Titlebar.ShouldDrawBackground; |
| 264 | + if (shouldDrawTitlebarBackground) |
| 265 | + { |
| 266 | + var titlebarBottom = windowControl.Titlebar.Bottom; |
| 267 | + frameBounds = new Rectangle( |
| 268 | + 0, |
| 269 | + titlebarBottom, |
| 270 | + control.RenderBounds.Width, |
| 271 | + control.RenderBounds.Height - titlebarBottom |
| 272 | + ); |
| 273 | + } |
| 274 | + |
| 275 | + if (frame != default && windowControl.ShouldDrawBackground) |
| 276 | + { |
| 277 | + frame.Draw(Renderer, frameBounds, windowControl.RenderColor); |
| 278 | + } |
| 279 | + |
| 280 | + if (shouldDrawTitlebarBackground) |
| 281 | + { |
| 282 | + titleBar.Draw(Renderer, windowControl.Titlebar.Bounds, windowControl.RenderColor); |
| 283 | + } |
| 284 | + } |
| 285 | + |
| 286 | + #endregion |
| 287 | + |
| 288 | +} |
0 commit comments