public void ClosePage() { GauntletEncyclopediaScreenManager gauntletEncyclopediaScreenManager = MapScreen.Instance.EncyclopediaScreenManager as GauntletEncyclopediaScreenManager; if (gauntletEncyclopediaScreenManager == null) { return; } //FieldInfo field = typeof(GauntletEncyclopediaScreenManager).GetField("_encyclopediaData", BindingFlags.Instance | BindingFlags.NonPublic); //FieldInfo field2 = typeof(EncyclopediaData).GetField("_activeDatasource", BindingFlags.Instance | BindingFlags.NonPublic); //EncyclopediaData encyclopediaData = (EncyclopediaData)field.GetValue(gauntletEncyclopediaScreenManager); //EncyclopediaPageVM encyclopediaPageVM = (EncyclopediaPageVM)field2.GetValue(encyclopediaData); EncyclopediaData? encyclopediaData = AccessTools.Field(typeof(GauntletEncyclopediaScreenManager), "_encyclopediaData").GetValue(gauntletEncyclopediaScreenManager) as EncyclopediaData; EncyclopediaPageVM?encyclopediaPageVM = AccessTools.Field(typeof(EncyclopediaData), "_activeDatasource").GetValue(encyclopediaData) as EncyclopediaPageVM; this.selectedHeroPage = (encyclopediaPageVM as EncyclopediaHeroPageVM); if (this.selectedHeroPage == null) { return; } gauntletEncyclopediaScreenManager.CloseEncyclopedia(); }
public static EncyclopediaPageVM GetEncycData(ref GauntletEncyclopediaScreenManager manager) { var dataInfo = typeof(GauntletEncyclopediaScreenManager).GetField("_encyclopediaData", BindingFlags.Instance | BindingFlags.NonPublic); if (dataInfo == null) { return(null); } var data = (EncyclopediaData)dataInfo.GetValue(manager); if (data == null) { return(null); } ; var dataSrcInfo = typeof(EncyclopediaData).GetField("_activeDatasource", BindingFlags.Instance | BindingFlags.NonPublic); if (dataSrcInfo == null) { return(null); } var dataSrc = (EncyclopediaPageVM)dataSrcInfo.GetValue(data); return(dataSrc); }
private static void Postfix(GauntletEncyclopediaScreenManager __instance) { try { Log("GauntletEncyclopediaScreenManagerCtorPatch"); gauntletEncyclopediaScreenManager = __instance; } catch (Exception ex) { Log(ex); } }
protected override void OnGameStart(Game game, IGameStarter gameStarterObject) { // Directories and Config.ini Helper.ReadConfig(); // Logs Helper.ClearLog(); Helper.ShowAndLog($"Initialized {Config.MOD_NAME} mod."); if (!(game.GameType is Campaign)) { Helper.Log("Game mode is not campaign."); return; } Helper.Log("Game mode is campaign."); // Current hero is by default the playerChar. currChar = this.PlayerChar; Helper.Log(currChar == null ? $"Unable to get the player's character. Current Character is null." : $"Current Character: {currChar.Name}, age: {currChar.Age}"); // Inject Harmony //var harmony = new Harmony("com.clivic.birthday_trait_tweak"); //harmony.PatchAll(); base.OnGameStart(game, gameStarterObject); // Bind events game.EventManager.RegisterEvent <EncyclopediaPageChangedEvent>((e) => { EncyclopediaData.EncyclopediaPages type = e.NewPage; if (type == EncyclopediaData.EncyclopediaPages.Hero) { GauntletEncyclopediaScreenManager m = MapScreen.Instance.EncyclopediaScreenManager as GauntletEncyclopediaScreenManager; var data = Helper.GetEncycData(ref m); if (data != null) { currChar = (Hero)data.Obj; Helper.Log(CurrentCharacterLogString); } } }); }
public void ClosePage() { GauntletEncyclopediaScreenManager gauntletEncyclopediaScreenManager = MapScreen.Instance.EncyclopediaScreenManager as GauntletEncyclopediaScreenManager; if (gauntletEncyclopediaScreenManager == null) { return; } EncyclopediaData encyclopediaData = AccessTools.Field(typeof(GauntletEncyclopediaScreenManager), "_encyclopediaData").GetValue(gauntletEncyclopediaScreenManager) as EncyclopediaData; EncyclopediaPageVM encyclopediaPageVM = AccessTools.Field(typeof(EncyclopediaData), "_activeDatasource").GetValue(encyclopediaData) as EncyclopediaPageVM; this.selectedHeroPage = (encyclopediaPageVM as EncyclopediaHeroPageVM); if (this.selectedHeroPage == null) { return; } gauntletEncyclopediaScreenManager.CloseEncyclopedia(); }
public void RefreshPage() { GauntletEncyclopediaScreenManager gauntletEncyclopediaScreenManager = MapScreen.Instance.EncyclopediaScreenManager as GauntletEncyclopediaScreenManager; if (gauntletEncyclopediaScreenManager == null) { return; } FieldInfo field = typeof(GauntletEncyclopediaScreenManager).GetField("_encyclopediaData", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field2 = typeof(EncyclopediaData).GetField("_activeDatasource", BindingFlags.Instance | BindingFlags.NonPublic); EncyclopediaData encyclopediaData = (EncyclopediaData)field.GetValue(gauntletEncyclopediaScreenManager); EncyclopediaPageVM encyclopediaPageVM = (EncyclopediaPageVM)field2.GetValue(encyclopediaData); this.selectedHeroPage = (encyclopediaPageVM as EncyclopediaHeroPageVM); if (this.selectedHeroPage == null) { return; } this.selectedHeroPage.Refresh(); }
public void OnEncyclopediaPageChanged(EncyclopediaPageChangedEvent e) { EncyclopediaData.EncyclopediaPages newPage = e.NewPage; if ((int)newPage != 12) { selectedHeroPage = null; selectedHero = null; if (gauntletLayerTopScreen != null && gauntletLayer != null) { gauntletLayerTopScreen.RemoveLayer(gauntletLayer); if (gauntletMovie != null) { gauntletLayer.ReleaseMovie(gauntletMovie); } gauntletLayerTopScreen = null; gauntletMovie = null; } return; } GauntletEncyclopediaScreenManager gauntletEncyclopediaScreenManager = MapScreen.Instance.EncyclopediaScreenManager as GauntletEncyclopediaScreenManager; if (gauntletEncyclopediaScreenManager == null) { return; } EncyclopediaData encyclopediaData = ReflectUtils.ReflectField <EncyclopediaData>("_encyclopediaData", gauntletEncyclopediaScreenManager); EncyclopediaPageVM encyclopediaPageVM = ReflectUtils.ReflectField <EncyclopediaPageVM>("_activeDatasource", encyclopediaData); selectedHeroPage = (encyclopediaPageVM as EncyclopediaHeroPageVM); if (selectedHeroPage == null) { return; } selectedHero = (selectedHeroPage.Obj as Hero); if (selectedHero == null) { return; } if (gauntletLayer == null) { gauntletLayer = new GauntletLayer(211, "GauntletLayer"); } try { if (viewModel == null) { viewModel = new HeroBuilderVM(delegate(Hero editHero) { InformationManager.DisplayMessage(new InformationMessage(new TextObject("{=CharacterCreation_EditAppearanceForHeroMessage}Entering edit appearance for: ").ToString() + editHero)); }); } viewModel.SetHero(selectedHero); gauntletMovie = gauntletLayer.LoadMovie("HeroEditor", viewModel); gauntletLayerTopScreen = ScreenManager.TopScreen; gauntletLayerTopScreen.AddLayer(gauntletLayer); gauntletLayer.InputRestrictions.SetInputRestrictions(true, InputUsageMask.MouseButtons); // Refresh selectedHeroPage.Refresh(); } catch (Exception ex) { // MessageBox.Show($"Error :\n{ex.Message} \n\n{ex.InnerException?.Message}"); } }
protected override void OnGameStart(Game game, IGameStarter gameStarterObject) { base.OnGameStart(game, gameStarterObject); if (!(game.GameType is Campaign)) { return; } AddModels(gameStarterObject as CampaignGameStarter); game.EventManager.RegisterEvent(delegate(EncyclopediaPageChangedEvent e) { EncyclopediaData.EncyclopediaPages newPage = e.NewPage; if ((int)newPage != 12) { this.selectedHeroPage = null; this.selectedHero = null; if (this.gauntletLayerTopScreen != null && this.gauntletLayer != null) { this.gauntletLayerTopScreen.RemoveLayer(this.gauntletLayer); if (this.gauntletMovie != null) { this.gauntletLayer.ReleaseMovie(this.gauntletMovie); } this.gauntletLayerTopScreen = null; this.gauntletMovie = null; } return; } GauntletEncyclopediaScreenManager gauntletEncyclopediaScreenManager = MapScreen.Instance.EncyclopediaScreenManager as GauntletEncyclopediaScreenManager; if (gauntletEncyclopediaScreenManager == null) { return; } FieldInfo field = typeof(GauntletEncyclopediaScreenManager).GetField("_encyclopediaData", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field2 = typeof(EncyclopediaData).GetField("_activeDatasource", BindingFlags.Instance | BindingFlags.NonPublic); EncyclopediaData encyclopediaData = (EncyclopediaData)field.GetValue(gauntletEncyclopediaScreenManager); EncyclopediaPageVM encyclopediaPageVM = (EncyclopediaPageVM)field2.GetValue(encyclopediaData); this.selectedHeroPage = (encyclopediaPageVM as EncyclopediaHeroPageVM); if (this.selectedHeroPage == null) { return; } this.selectedHero = (this.selectedHeroPage.Obj as Hero); if (this.selectedHero == null) { return; } if (this.gauntletLayer == null) { this.gauntletLayer = new GauntletLayer(211, "GauntletLayer"); } try { if (this.viewModel == null) { this.viewModel = new HeroBuilderVM(this.heroModel, delegate(Hero editHero) { InformationManager.DisplayMessage(new InformationMessage("Entering edit appearance for: " + editHero)); }); } this.viewModel.SetHero(this.selectedHero); this.gauntletMovie = this.gauntletLayer.LoadMovie("HeroEditor", this.viewModel); this.gauntletLayerTopScreen = ScreenManager.TopScreen; this.gauntletLayerTopScreen.AddLayer(this.gauntletLayer); this.gauntletLayer.InputRestrictions.SetInputRestrictions(true, InputUsageMask.MouseButtons); // Refresh this.selectedHeroPage.Refresh(); } catch (Exception ex) { MessageBox.Show($"Error :\n{ex.Message} \n\n{ex.InnerException?.Message}"); } }); }