Use simple static fields instead of ugly Dictionary<string, Dictionary<string, object>> for storing persistent data across gui screen changes in the launcher.

This commit is contained in:
UnknownShadow200 2017-08-31 11:00:40 +10:00
parent ebf4d135ba
commit 4006e127e1
5 changed files with 27 additions and 38 deletions

View File

@ -26,6 +26,9 @@ namespace ClassicalSharp.Gui.Screens {
AltTextInputWidget altText;
Font chatFont, chatUrlFont, announcementFont;
// needed for lost contexts, to restore chat typed in
static string chatInInputBuffer = null;
public override void Init() {
float textScale = game.Drawer2D.UseBitmappedChat ? 1.25f : 1;
int fontSize = (int)(8 * game.GuiChatScale);
@ -89,9 +92,9 @@ namespace ClassicalSharp.Gui.Screens {
for (int i = 0; i < chat.ClientStatus.Length; i++)
clientStatus.SetText(i, chat.ClientStatus[i].Text);
if (game.chatInInputBuffer != null) {
OpenTextInputBar(game.chatInInputBuffer);
game.chatInInputBuffer = null;
if (chatInInputBuffer != null) {
OpenTextInputBar(chatInInputBuffer);
chatInInputBuffer = null;
}
}
@ -265,10 +268,10 @@ namespace ClassicalSharp.Gui.Screens {
protected override void ContextLost() {
if (HandlesAllInput) {
game.chatInInputBuffer = input.Text.ToString();
chatInInputBuffer = input.Text.ToString();
game.CursorVisible = false;
} else {
game.chatInInputBuffer = null;
chatInInputBuffer = null;
}
normalChat.Dispose();

View File

@ -107,7 +107,7 @@ namespace ClassicalSharp {
public PickedPosRenderer Picking;
public PickedPos SelectedPos = new PickedPos(), CameraClipPos = new PickedPos();
public ModelCache ModelCache;
internal string skinServer, chatInInputBuffer = null;
internal string skinServer;
internal int defaultIb;
public OtherEvents Events = new OtherEvents();
public EntityEvents EntityEvents = new EntityEvents();

View File

@ -59,30 +59,26 @@ namespace Launcher.Gui.Screens {
booleanFont.Dispose();
}
static string cachedUser, cachedAddress, cachedMppass;
static bool cachedSkins;
void LoadSavedInfo() {
Dictionary<string, object> metadata;
// restore what user last typed into the various fields
if (game.ScreenMetadata.TryGetValue("screen-DC", out metadata)) {
SetText(0, (string)metadata["user"]);
SetText(1, (string)metadata["address"]);
SetText(2, (string)metadata["mppass"]);
SetBool((bool)metadata["skins"]);
if (cachedUser != null) {
SetText(0, cachedUser);
SetText(1, cachedAddress);
SetText(2, cachedMppass);
SetBool(cachedSkins);
} else {
LoadFromOptions();
}
}
void StoreFields() {
Dictionary<string, object> metadata;
if (!game.ScreenMetadata.TryGetValue("screen-DC", out metadata)) {
metadata = new Dictionary<string, object>();
game.ScreenMetadata["screen-DC"] = metadata;
}
metadata["user"] = Get(0);
metadata["address"] = Get(1);
metadata["mppass"] = Get(2);
metadata["skins"] = ((CheckboxWidget)widgets[view.ccSkinsIndex]).Value;
cachedUser = Get(0);
cachedAddress = Get(1);
cachedMppass = Get(2);
cachedSkins = ((CheckboxWidget)widgets[view.ccSkinsIndex]).Value;
}
void LoadFromOptions() {

View File

@ -132,22 +132,17 @@ namespace Launcher.Gui.Screens {
game.Dirty = true;
}
static string cachedUser, cachedPass;
void StoreFields() {
Dictionary<string, object> metadata;
if (!game.ScreenMetadata.TryGetValue("screen-CC", out metadata)) {
metadata = new Dictionary<string, object>();
game.ScreenMetadata["screen-CC"] = metadata;
}
metadata["user"] = Get(0);
metadata["pass"] = Get(1);
cachedUser = Get(0);
cachedPass = Get(1);
}
void LoadSavedInfo() {
Dictionary<string, object> metadata;
// restore what user last typed into the various fields
if (game.ScreenMetadata.TryGetValue("screen-CC", out metadata)) {
Set(0, (string)metadata["user"]);
Set(1, (string)metadata["pass"]);
if (cachedUser != null) {
Set(0, cachedUser);
Set(1, cachedPass);
} else {
LoadFromOptions();
}

View File

@ -61,11 +61,6 @@ namespace Launcher {
get { return Window.WindowState == WindowState.Minimized || (Width == 1 && Height == 1); }
}
/// <summary> Contains metadata attached for different screen instances,
/// typically used to save 'last text entered' text when a screen is disposed. </summary>
public Dictionary<string, Dictionary<string, object>> ScreenMetadata =
new Dictionary<string, Dictionary<string, object>>();
internal ResourceFetcher fetcher;
internal UpdateCheckTask checkTask;
bool fullRedraw;