1using Microsoft.Xna.Framework;
2using Microsoft.Xna.Framework.Graphics;
4using System.Collections.Generic;
5using Terraria.Graphics.Effects;
17 internal static readonly IList<ModUgBgStyle> ugBgStyles =
new List<ModUgBgStyle>();
19 internal static int ReserveBackgroundSlot() {
33 internal static void ResizeAndFillArrays() {
36 internal static void Unload() {
42 if (!GlobalBgStyleLoader.loaded) {
45 foreach (var ugBgStyle
in ugBgStyles) {
46 if (ugBgStyle.ChooseBgStyle()) {
47 style = ugBgStyle.Slot;
50 foreach (var hook
in GlobalBgStyleLoader.HookChooseUgBgStyle) {
56 if (!GlobalBgStyleLoader.loaded) {
60 if (ugBgStyle !=
null) {
61 ugBgStyle.FillTextureArray(textureSlots);
63 foreach (var hook
in GlobalBgStyleLoader.HookFillUgTextureArray) {
64 hook(style, textureSlots);
73 internal static readonly IList<ModSurfaceBgStyle> surfaceBgStyles =
new List<ModSurfaceBgStyle>();
77 internal static int ReserveBackgroundSlot() {
91 internal static void ResizeAndFillArrays() {
96 internal static void Unload() {
98 surfaceBgStyles.Clear();
102 if (!GlobalBgStyleLoader.loaded) {
105 foreach (var surfaceBgStyle
in surfaceBgStyles) {
106 if (surfaceBgStyle.ChooseBgStyle()) {
107 style = surfaceBgStyle.Slot;
110 foreach (var hook
in GlobalBgStyleLoader.HookChooseSurfaceBgStyle) {
115 public static void ModifyFarFades(
int style,
float[] fades,
float transitionSpeed) {
116 if (!GlobalBgStyleLoader.loaded) {
120 if (surfaceBgStyle !=
null) {
121 surfaceBgStyle.ModifyFarFades(fades, transitionSpeed);
123 foreach (var hook
in GlobalBgStyleLoader.HookModifyFarSurfaceFades) {
124 hook(style, fades, transitionSpeed);
129 if (!GlobalBgStyleLoader.loaded) {
133 foreach (var style
in surfaceBgStyles) {
134 int slot = style.Slot;
135 Main.backColor = Main.trueBackColor;
136 Main.backColor.R = (byte)(Main.backColor.R * Main.bgAlpha2[slot]);
137 Main.backColor.G = (byte)(Main.backColor.G * Main.bgAlpha2[slot]);
138 Main.backColor.B = (byte)(Main.backColor.B * Main.bgAlpha2[slot]);
139 Main.backColor.A = (byte)(Main.backColor.A * Main.bgAlpha2[slot]);
140 if (Main.bgAlpha2[slot] > 0f) {
141 int textureSlot = style.ChooseFarTexture();
142 if (textureSlot >= 0 && textureSlot < Main.backgroundTexture.Length) {
143 Main.instance.LoadBackground(textureSlot);
144 for (
int k = 0; k < Main.instance.bgLoops; k++) {
145 Main.spriteBatch.Draw(Main.backgroundTexture[textureSlot],
146 new Vector2(Main.instance.bgStart + Main.bgW * k, Main.instance.bgTop),
147 new Rectangle(0, 0, Main.backgroundWidth[textureSlot], Main.backgroundHeight[textureSlot]),
148 Main.backColor, 0f,
default(Vector2), Main.bgScale, SpriteEffects.None, 0f);
156 if (!GlobalBgStyleLoader.loaded) {
159 foreach (var style
in surfaceBgStyles) {
160 int slot = style.Slot;
161 Main.backColor = Main.trueBackColor;
162 Main.backColor.R = (byte)(Main.backColor.R * Main.bgAlpha2[slot]);
163 Main.backColor.G = (byte)(Main.backColor.G * Main.bgAlpha2[slot]);
164 Main.backColor.B = (byte)(Main.backColor.B * Main.bgAlpha2[slot]);
165 Main.backColor.A = (byte)(Main.backColor.A * Main.bgAlpha2[slot]);
166 if (Main.bgAlpha2[slot] > 0f) {
167 int textureSlot = style.ChooseMiddleTexture();
168 if (textureSlot >= 0 && textureSlot < Main.backgroundTexture.Length) {
169 Main.instance.LoadBackground(textureSlot);
170 for (
int k = 0; k < Main.instance.bgLoops; k++) {
171 Main.spriteBatch.Draw(Main.backgroundTexture[textureSlot],
172 new Vector2(Main.instance.bgStart + Main.bgW * k, Main.instance.bgTop),
173 new Rectangle(0, 0, Main.backgroundWidth[textureSlot], Main.backgroundHeight[textureSlot]),
174 Main.backColor, 0f,
default(Vector2), Main.bgScale, SpriteEffects.None, 0f);
182 if (!GlobalBgStyleLoader.loaded) {
185 if (Main.bgAlpha[style] <= 0f) {
189 if (surfaceBgStyle !=
null && surfaceBgStyle.PreDrawCloseBackground(Main.spriteBatch)) {
190 Main.bgScale = 1.25f;
191 Main.instance.bgParallax = 0.37;
194 int textureSlot = surfaceBgStyle.ChooseCloseTexture(ref Main.bgScale, ref Main.instance.bgParallax, ref a, ref b);
195 if (textureSlot >= 0 && textureSlot < Main.backgroundTexture.Length) {
197 Main.instance.LoadBackground(textureSlot);
199 Main.bgW = (int)((
float)Main.backgroundWidth[textureSlot] * Main.bgScale);
200 SkyManager.Instance.DrawToDepth(Main.spriteBatch, 1f / (
float)Main.instance.bgParallax);
201 Main.instance.bgStart = (int)(-Math.IEEERemainder(Main.screenPosition.X * Main.instance.bgParallax, Main.bgW) - (Main.bgW / 2));
202 Main.instance.bgTop = (int)((-Main.screenPosition.Y + Main.instance.screenOff / 2f) / (Main.worldSurface * 16.0) * a + b) + (
int)Main.instance.scAdj;
204 Main.instance.bgTop = 320;
206 Main.instance.bgLoops = Main.screenWidth / Main.bgW + 2;
207 if ((
double)Main.screenPosition.Y < Main.worldSurface * 16.0 + 16.0) {
208 for (
int k = 0; k < Main.instance.bgLoops; k++) {
209 Main.spriteBatch.Draw(Main.backgroundTexture[textureSlot],
210 new Vector2((Main.instance.bgStart + Main.bgW * k), Main.instance.bgTop),
211 new Rectangle(0, 0, Main.backgroundWidth[textureSlot], Main.backgroundHeight[textureSlot]),
212 Main.backColor, 0f,
default(Vector2), Main.bgScale, SpriteEffects.None, 0f);
220 internal static class GlobalBgStyleLoader
222 internal static readonly IList<GlobalBgStyle> globalBgStyles =
new List<GlobalBgStyle>();
223 internal static bool loaded =
false;
224 internal delegate
void DelegateChooseUgBgStyle(ref
int style);
225 internal static DelegateChooseUgBgStyle[] HookChooseUgBgStyle;
226 internal delegate
void DelegateChooseSurfaceBgStyle(ref
int style);
227 internal static DelegateChooseSurfaceBgStyle[] HookChooseSurfaceBgStyle;
228 internal static Action<int, int[]>[] HookFillUgTextureArray;
229 internal static Action<int, float[], float>[] HookModifyFarSurfaceFades;
231 internal static void ResizeAndFillArrays(
bool unloading =
false) {
232 ModLoader.BuildGlobalHook(ref HookChooseUgBgStyle, globalBgStyles, g => g.ChooseUgBgStyle);
233 ModLoader.BuildGlobalHook(ref HookChooseSurfaceBgStyle, globalBgStyles, g => g.ChooseSurfaceBgStyle);
234 ModLoader.BuildGlobalHook(ref HookFillUgTextureArray, globalBgStyles, g => g.FillUgTextureArray);
235 ModLoader.BuildGlobalHook(ref HookModifyFarSurfaceFades, globalBgStyles, g => g.ModifyFarSurfaceFades);
242 internal static void Unload() {
244 globalBgStyles.Clear();
Each background style determines in its own way how exactly the background is drawn....
Each background style determines in its own way how exactly the background is drawn....
static int nextSurfaceBgStyle
static void ChooseStyle(ref int style)
static void DrawCloseBackground(int style)
static void ModifyFarFades(int style, float[] fades, float transitionSpeed)
static void DrawFarTexture()
static ModSurfaceBgStyle GetSurfaceBgStyle(int style)
Returns the ModSurfaceBgStyle object with the given ID.
static void DrawMiddleTexture()
const int vanillaSurfaceBgStyleCount
This serves as the central class from which ModUgBgStyle functions are supported and carried out.
static ModUgBgStyle GetUgBgStyle(int style)
Returns the ModUgBgStyle object with the given ID.
const int vanillaUgBgStyleCount
static void ChooseStyle(ref int style)
static void FillTextureArray(int style, int[] textureSlots)