-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiverse.cs
More file actions
151 lines (144 loc) · 4.22 KB
/
Multiverse.cs
File metadata and controls
151 lines (144 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using Multiverse.ModWorlds;
using SubworldLibrary;
using static Terraria.ModLoader.ModContent;
using Terraria.ModLoader;
using Terraria.UI;
using Multiverse.ModUI;
using Terraria;
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using Terraria.IO;
namespace Multiverse
{
public class Multiverse : Mod
{
string id;
internal UserInterface worldSelectInterface;
internal WorldSelectUi worldSelectUI;
private GameTime _lastUpdateUiGameTime;
public static Multiverse instance;
public override void UpdateUI(GameTime gameTime)
{
_lastUpdateUiGameTime = gameTime;
if (worldSelectInterface?.CurrentState != null)
{
worldSelectInterface.Update(gameTime);
}
}
internal void ShowMyUI()
{
worldSelectInterface?.SetState(worldSelectUI);
}
internal void HideMyUI()
{
worldSelectInterface?.SetState(null);
}
public override void ModifyInterfaceLayers(List<GameInterfaceLayer> layers)
{
int mouseTextIndex = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Mouse Text"));
if (mouseTextIndex != -1)
{
layers.Insert(mouseTextIndex, new LegacyGameInterfaceLayer(
"Multiverse: worldSelectInterface",
delegate
{
if (_lastUpdateUiGameTime != null && worldSelectInterface?.CurrentState != null)
{
worldSelectInterface.Draw(Main.spriteBatch, _lastUpdateUiGameTime);
}
return true;
},
InterfaceScaleType.UI));
}
}
public override void Load()
{
base.Load();
instance = this;
}
public override void Unload()
{
base.Unload();
SubworldManager.Unload();
worldSelectUI = null;
}
public override void MidUpdateTimeWorld()
{
if (Subworld.AnyActive<Multiverse>() && GetInstance<Config>().WorldsRegistry[Util.KeyByValue(SubworldManager.WorldsEnter, SLWorld.currentSubworld.Current)].type == WorldType.NormalWorld)//lotta stuff copied from vanilla
{
Main.UpdateSundial();
Main.time += Main.dayRate;
Terraria.GameContent.Events.BirthdayParty.UpdateTime();
Terraria.GameContent.Events.DD2Event.UpdateTime();
if (Main.time > 54000 && Main.dayTime)//replace main.daytime with speed adjust (add/mult)
{
Main.time = 0;
Main.dayTime = !Main.dayTime;
}
else if (Main.time > 32400 && !Main.dayTime)
{
if (Main.fastForwardTime)
{
Main.fastForwardTime = false;
Main.UpdateSundial();
}
Main.checkXMas();
Main.checkHalloween();
Main.AnglerQuestSwap();
Terraria.GameContent.Events.BirthdayParty.CheckMorning();
Main.time = 0;
Main.dayTime = !Main.dayTime;
if (Main.sundialCooldown > 0)
{
Main.sundialCooldown--;
}
Main.moonPhase++;
if (Main.moonPhase >= 8)
{
Main.moonPhase = 0;
}
}
}
}
public override void PostSetupContent()
{
base.PostSetupContent();
foreach(string name in GetInstance<Config>().WorldsRegistry.Keys)
{
switch (GetInstance<Config>().WorldsRegistry[name].type)
{
case WorldType.VoidWorld:
id = SubworldManager.CreateVoidWorld(name, GetInstance<Config>().WorldsRegistry[name].size, GetInstance<Config>().WorldsRegistry[name].save);
if (!SubworldManager.WorldsEnter.ContainsKey(name))
{
SubworldManager.WorldsEnter.Add(name, id);
}
break;
case WorldType.FlatWorld:
id = SubworldManager.CreateFlatWorld(name, GetInstance<Config>().WorldsRegistry[name].size, GetInstance<Config>().WorldsRegistry[name].save);
if (!SubworldManager.WorldsEnter.ContainsKey(name))
{
SubworldManager.WorldsEnter.Add(name, id);
}
break;
case WorldType.NormalWorld:
id = SubworldManager.CreateNormalWorld(name, GetInstance<Config>().WorldsRegistry[name].size, GetInstance<Config>().WorldsRegistry[name].save);
if (!SubworldManager.WorldsEnter.ContainsKey(name))
{
SubworldManager.WorldsEnter.Add(name, id);
}
break;
default:
break;
}
id = string.Empty;
}
if (!Main.dedServ)
{
worldSelectInterface = new UserInterface();
worldSelectUI = new WorldSelectUi();
worldSelectUI.Activate(); // Activate calls Initialize() on the UIState if not initialized, then calls OnActivate and then calls Activate on every child element
}
}
}
}