/* These buttons are either Campaign Buttons or Load buttons. * I tried 2 different classes, but I couldn't figure out how * to make the old buttons disappear once I changed screens. * This way works though */ public override void OnUpdate() { if (Instance.HasUpdatedSinceLastClose) { return; } bool debug = false; Instance.HasUpdatedSinceLastClose = true; ArcenUI_ButtonSet elementAsType = (ArcenUI_ButtonSet)Element; elementAsType.ClearButtons(); Dictionary <string, List <SaveGameData> > gameDict = SaveLoadMethods.parseOnDiskSaveGames(); if (!Instance.showCampaignButtons) { //these are Load Game buttons if (Window_LoadGameMenu.Instance.campaignName == "") { ArcenDebugging.ArcenDebugLogSingleLine("WARNING: campaign name is null ", Verbosity.DoNotShow); } if (debug) { ArcenDebugging.ArcenDebugLogSingleLine("Showing saved games in LoadGames from campaign " + Window_LoadGameMenu.Instance.campaignName, Verbosity.DoNotShow); } //get the saved games for this campaign List <SaveGameData> list = gameDict[Window_LoadGameMenu.Instance.campaignName]; //sort saved games by elapsed in game time list.Sort(delegate(SaveGameData x, SaveGameData y) { return(-x.secondsSinceGameStart.CompareTo(y.secondsSinceGameStart)); }); //This code allows for multiple columns to automatically wrap int maxHeightPerColumn = 80; int xModForLoadButtons = -4; //Load buttons are a bit smaller than campaign buttons int yModForLoadButtons = -4; int gamesPerColumn = (int)maxHeightPerColumn / (int)(elementAsType.ButtonHeight + yModForLoadButtons); int distBetweenColumns = 2; Vector2 sizeForLoadButtons; sizeForLoadButtons.x = elementAsType.ButtonWidth + xModForLoadButtons; sizeForLoadButtons.y = elementAsType.ButtonHeight + yModForLoadButtons; if (debug) { ArcenDebugging.ArcenDebugLogSingleLine("gamesPerColumn " + gamesPerColumn + "botton height " + elementAsType.ButtonHeight + "maxHeight " + maxHeightPerColumn, Verbosity.DoNotShow); } for (int k = 0; k < list.Count; k++) { Vector2 offset; offset.y = (k % gamesPerColumn) * (elementAsType.ButtonHeight + yModForLoadButtons); offset.x = (k / gamesPerColumn) * (elementAsType.ButtonWidth + xModForLoadButtons) + distBetweenColumns * (k / gamesPerColumn); AddLoadButton(elementAsType, list[k], offset, sizeForLoadButtons); } } else { //these are campaign buttons List <SaveGameData> campaignList = new List <SaveGameData>(); foreach (KeyValuePair <string, List <SaveGameData> > entry in gameDict) { //Campaign buttons are sorted by "Last save Wall Clock date" //Find the furthest-in game from each campaign to check for the //Wall Clock time and add it to the campaignList List <SaveGameData> list = entry.Value; list.Sort(delegate(SaveGameData x, SaveGameData y) { return(-x.secondsSinceGameStart.CompareTo(y.secondsSinceGameStart)); }); campaignList.Add(list[0]); } //Now sort by Wall Clock campaignList.Sort(delegate(SaveGameData x, SaveGameData y) { return(-x.lastModified.CompareTo(y.lastModified)); }); //Allow columns to wrap nicely int maxHeightPerColumn = 80; int gamesPerColumn = (int)maxHeightPerColumn / (int)elementAsType.ButtonHeight; int distBetweenColumns = 2; for (int k = 0; k < campaignList.Count; k++) { Vector2 offset; offset.y = (k % gamesPerColumn) * elementAsType.ButtonHeight; offset.x = (k / gamesPerColumn) * elementAsType.ButtonWidth + distBetweenColumns * (k / gamesPerColumn); AddCampaignButton(elementAsType, campaignList[k], offset); } } elementAsType.ActuallyPutItemsBackInPoolThatAreStillCleared(); }
public override void OnUpdate() { if (!Instance.NeedsUpdate) { return; } Instance.NeedsUpdate = false; bool debug = false; if (debug) { ArcenDebugging.ArcenDebugLogSingleLine("Reading directory to generate buttons", Verbosity.DoNotShow); } ArcenUI_ButtonSet elementAsType = (ArcenUI_ButtonSet)Element; elementAsType.ClearButtons(); Dictionary <string, List <SaveGameData> > gameDict = SaveLoadMethods.parseOnDiskSaveGames(); foreach (KeyValuePair <string, List <SaveGameData> > entry in gameDict) { //Don't show any saves from other campaigns if (entry.Key != Window_SaveGameMenu.Instance.OverallCampaignName || Window_SaveGameMenu.Instance.OverallCampaignName == "") { continue; } if (debug) { ArcenDebugging.ArcenDebugLogSingleLine("Parsing list from " + entry.Key, Verbosity.DoNotShow); } List <SaveGameData> list = entry.Value; //Sort the found saved games by elapsed in game time list.Sort(delegate(SaveGameData x, SaveGameData y) { return(-x.secondsSinceGameStart.CompareTo(y.secondsSinceGameStart)); }); //Allow for multiple columns int maxHeightPerColumn = 80; int gamesPerColumn = (int)maxHeightPerColumn / (int)elementAsType.ButtonHeight; int distBetweenColumns = 5; //This section here adds a big button at the top //to display information about the campaign Vector2 offset; offset.y = 0; offset.x = 40; string output = getCampaignLabel(list[0]); AddHeaderButton(elementAsType, output, offset); int offsetForHeader = (int)elementAsType.ButtonHeight + 5; //Now print the found saved games underneath the header for (int k = 0; k < list.Count; k++) { offset.y = (k % gamesPerColumn) * elementAsType.ButtonHeight + offsetForHeader; offset.x = (k / gamesPerColumn) * elementAsType.ButtonWidth + distBetweenColumns * (k / gamesPerColumn); AddSaveButton(elementAsType, list[k], offset); } } elementAsType.ActuallyPutItemsBackInPoolThatAreStillCleared(); }