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}");
            }
        }
Beispiel #2
0
        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}");
                }
            });
        }