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 = AccessTools.Field(typeof(GauntletEncyclopediaScreenManager), "_encyclopediaData").GetValue(gauntletEncyclopediaScreenManager) as EncyclopediaData; EncyclopediaPageVM?encyclopediaPageVM = AccessTools.Field(typeof(EncyclopediaData), "_activeDatasource").GetValue(encyclopediaData) as EncyclopediaPageVM; selectedHeroPage = (encyclopediaPageVM as EncyclopediaHeroPageVM); if (selectedHeroPage == null) { return; } selectedHero = selectedHeroPage.Obj as Hero; if (selectedHero == null) { return; } gauntletLayer ??= new GauntletLayer(211); try { if (gauntletMovie != null) { gauntletLayer.ReleaseMovie(gauntletMovie); }
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 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}"); } }); }
protected override void OnGameStart(Game game, IGameStarter gameStarterObject) { base.OnGameStart(game, gameStarterObject); if (!(game.GameType is Campaign)) { return; } if (!(gameStarterObject is CampaignGameStarter)) { return; } AddModels(gameStarterObject as CampaignGameStarter); TimeSinceLastSave = CampaignTime.Now; game.AddGameHandler <AgingGameHandler>(); game.EventManager.RegisterEvent(delegate(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 = AccessTools.Field(typeof(GauntletEncyclopediaScreenManager), "_encyclopediaData").GetValue(gauntletEncyclopediaScreenManager) as EncyclopediaData; EncyclopediaPageVM?encyclopediaPageVM = AccessTools.Field(typeof(EncyclopediaData), "_activeDatasource").GetValue(encyclopediaData) as EncyclopediaPageVM; 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(heroModel, delegate(Hero editHero) { InformationManager.DisplayMessage(new InformationMessage(EditAppearanceForHeroMessage.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}"); } }); }
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 = AccessTools.Field(typeof(GauntletEncyclopediaScreenManager), "_encyclopediaData").GetValue(gauntletEncyclopediaScreenManager) as EncyclopediaData; EncyclopediaPageVM?encyclopediaPageVM = AccessTools.Field(typeof(EncyclopediaData), "_activeDatasource").GetValue(encyclopediaData) as EncyclopediaPageVM; selectedHeroPage = (encyclopediaPageVM as EncyclopediaHeroPageVM); if (selectedHeroPage == null) { return; } selectedHero = selectedHeroPage.Obj as Hero; if (selectedHero == null) { return; } gauntletLayer ??= new GauntletLayer(211); try { if (gauntletMovie != null) { gauntletLayer.ReleaseMovie(gauntletMovie); } //static void Callback(Hero editHero) => InformationManager.DisplayMessage(new InformationMessage(SubModule.EditAppearanceForHeroMessage.ToString() + editHero)); //ConstructorInfo constructor = HeroBuilderVMType.GetConstructor(new[] { typeof(Action<Hero>) }); //viewModel = constructor?.Invoke(new[] {(Action<Hero>) Callback}) as ViewModel; //if (viewModel == default) return; if (viewModel == null) { viewModel = new HeroBuilderVM(hero => InformationManager.DisplayMessage(new InformationMessage(SubModule.EditAppearanceForHeroMessage.ToString() + hero))); } if (DCCSettingsUtil.Instance.DebugMode) { Debug.Print($"[CharacterCreation] viewModel is of type {viewModel.GetType().FullName}"); } //AccessTools.Method(HeroBuilderVMType, "SetHero").Invoke(viewModel, new[] { selectedHero }); viewModel.SetHero(selectedHero); //// BEGIN compatibility code block //if (viewModel.GetType() == typeof(HeroBuilderVM)) // gauntletMovie = gauntletLayer.LoadMovie("DCCHeroEditor", viewModel); //else if (viewModel.GetType().FullName == "CharacterReload.VM.HeroBuilderVM") // gauntletMovie = gauntletLayer.LoadMovie("HeroEditor", viewModel); //else return; //// END gauntletMovie = gauntletLayer.LoadMovie("DCCHeroEditor", 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}"); } }