Пример #1
0
        public MatchScreen(
            Vector2f WindowSize,
            Match Match,
            IEnumerable <Army> FollowedArmies,
            TileRenderer TileRenderer,
            UnitConfigurationRenderer UnitRenderer,
            FactionRenderer FactionRenderer)
            : base(WindowSize, Match.Map, TileRenderer)
        {
            Match.OnStartPhase   += _EventBuffer.Hook <StartTurnComponentEventArgs>(HandleNewTurn).Invoke;
            Match.OnExecuteOrder += _EventBuffer.Hook <ExecuteOrderEventArgs>(HandleOrderExecuted).Invoke;

            this.UnitRenderer    = UnitRenderer;
            this.FactionRenderer = FactionRenderer;

            _FollowedArmies  = new HashSet <Army>(FollowedArmies);
            _FogOfWar        = Match.Scenario.Rules.FogOfWar;
            _FogOfWarHandler = _EventBuffer.Hook <SightUpdatedEventArgs>(HandleSightUpdated);

            EventHandler <NewUnitEventArgs> addUnitHandler = _EventBuffer.Hook <NewUnitEventArgs>(AddUnit).Invoke;

            foreach (Army a in Match.Armies)
            {
                a.OnUnitAdded += addUnitHandler;
                foreach (Unit u in a.Units)
                {
                    AddUnit(u);
                }
            }

            for (int i = 0; i < Match.Scenario.TurnConfiguration.Turns; ++i)
            {
                _TurnCounter.Add(new Checkbox("overlay-turn-counter-box")
                {
                    Enabled = false
                });
            }

            _FinishButton.Position            = Size - _FinishButton.Size - new Vector2f(32, 32);
            _FinishButton.OnClick            += HandleFinishClicked;
            _InfoDisplay.Position             = _FinishButton.Position - new Vector2f(0, _InfoDisplay.Size.Y + 16);
            _VictoryConditionDisplay.Position =
                _InfoDisplay.Position - new Vector2f(0, _VictoryConditionDisplay.Size.Y + 16);
            _ActionDisplay.Position = new Vector2f(WindowSize.X - _ActionDisplay.Size.X - 16, 16);

            _TransformedItems.Add(_StackLayer);

            _Items.Add(_FinishButton);
            _Items.Add(_InfoDisplay);
            _Items.Add(_VictoryConditionDisplay);
            _Items.Add(_TurnCounter);
            _Items.Add(_ActionDisplay);
        }
Пример #2
0
        public UnitView(Unit Unit, UnitConfigurationRenderer Renderer, float Scale, bool Reactive)
        {
            this.Unit     = Unit;
            this.Reactive = Reactive;

            _Renderer = Renderer;
            _UnitConfigurationView = new UnitConfigurationView(
                Unit.Configuration, Unit.Army.Configuration.Faction, Renderer, Scale);
            Unit.OnConfigurationChange +=
                _UnitConfigurationChangedBuffer.Hook <EventArgs>(UpdateConfigurationView).Invoke;

            Vector2f tl = new Vector2f(-.5f, -.15f) * Scale;
            Vector2f tr = new Vector2f(.5f, -.15f) * Scale;
            Vector2f br = new Vector2f(.5f, .15f) * Scale;
            Vector2f bl = new Vector2f(-.5f, .15f) * Scale;

            if (MOVED_DISPLAY == null)
            {
                MOVED_DISPLAY = new Button("overlay-moved-box")
                {
                    DisplayedString = "MOVED"
                };
                MOVED_DISPLAY.Position = -.5f * new Vector2f(64, MOVED_DISPLAY.Size.Y);
            }
            if (FIRED_DISPLAY == null)
            {
                FIRED_DISPLAY = new Button("overlay-fired-box")
                {
                    DisplayedString = "FIRED"
                };
                FIRED_DISPLAY.Position = -.5f * new Vector2f(64, FIRED_DISPLAY.Size.Y);
            }
            if (MOVING_DISPLAY == null)
            {
                MOVING_DISPLAY = new Button("overlay-moving-box")
                {
                    DisplayedString = "MOVING"
                };
                MOVING_DISPLAY.Position = -.5f * new Vector2f(64, MOVING_DISPLAY.Size.Y);
            }
            if (WORKING_DISPLAY == null)
            {
                WORKING_DISPLAY = new Button("overlay-working-box")
                {
                    DisplayedString = "WORKING"
                };
                WORKING_DISPLAY.Position = -.5f * new Vector2f(64, WORKING_DISPLAY.Size.Y);
            }
        }
Пример #3
0
        public override Pod SetupState(ProgramContext ProgramContext, ProgramStateContext ProgramStateContext)
        {
            _Context = ProgramStateContext;
            var context = (MatchLobbyContext)_Context;

            var screen = new MatchLobbyScreen(
                ProgramContext.ScreenResolution,
                context.IsHost,
                context.Lobby,
                context.Chat,
                GameData.Player,
                GameData.Scenarios);

            _Controller                     = new MatchLobbyController(context.MakeMatchLobbyAdapter(), screen);
            _ChatController                 = new ChatController(context.MakeChatAdapter(), screen.ChatView, GameData.Player);
            context.Lobby.OnLaunched       += _LaunchBuffer.Hook <ValuedEventArgs <Scenario> >(HandleLaunch).Invoke;
            screen.OnPulse                 += HandlePulse;
            screen.OnMainMenuButtonClicked += HandleBack;
            return(screen);
        }
        public override Pod SetupState(ProgramContext ProgramContext, ProgramStateContext ProgramStateContext)
        {
            _Context        = (MatchContext)ProgramStateContext;
            _MatchEndBuffer = new EventBuffer <EventArgs>();

            var renderer = new UnitConfigurationRenderer(
                _Context.Match.Scenario,
                GameData.UnitRenderDetails,
                128,
                1024,
                ClassLibrary.Instance.GetFont("compacta"));
            var factionRenderer =
                new FactionRenderer(_Context.Match.Scenario, GameData.FactionRenderDetails, 512, 1024);
            var armies = new HashSet <Army>(_Context.GetPlayerControlledArmies());

            var screen = new MatchScreen(
                ProgramContext.ScreenResolution,
                _Context.Match,
                armies,
                GameData.TileRenderers[_Context.Match.Scenario.Environment.UniqueKey],
                renderer,
                factionRenderer);
            var controller =
                new HumanMatchPlayerController(
                    _Context.MakeMatchAdapter(), armies, renderer, screen, ProgramContext.KeyController);

            var playerControllers = new Dictionary <Army, MatchPlayerController>();

            foreach (Army a in _Context.Match.Armies)
            {
                // var controller = new AIMatchPlayerController(_Context.MakeMatchAdapter(), a);
                var overrideController = _Context.GetOverridePlayerController(a);
                playerControllers.Add(a, overrideController ?? controller);
            }
            _MatchController             = new MatchController(_Context.Match, playerControllers);
            screen.OnPulse              += HandlePulse;
            _Context.Match.OnMatchEnded += _MatchEndBuffer.Hook <EventArgs>(HandleMatchEnd).Invoke;
            _Context.Match.Start();

            return(screen);
        }
        public HumanMatchPlayerController(
            MatchAdapter Match,
            IEnumerable <Army> AllowedArmies,
            UnitConfigurationRenderer UnitConfigurationRenderer,
            MatchScreen MatchScreen,
            KeyController KeyController)
        {
            _NewUnitBuffer = new EventBuffer <ValuedEventArgs <UnitView> >();

            this.Match                     = Match;
            this.AllowedArmies             = new HashSet <Army>(AllowedArmies);
            this.UnitConfigurationRenderer = UnitConfigurationRenderer;

            _MatchScreen = MatchScreen;
            _MatchScreen.OnFinishClicked += EndTurn;
            _MatchScreen.OnUnitAdded     += _NewUnitBuffer.Hook <ValuedEventArgs <UnitView> >(AddUnit).Invoke;
            _MatchScreen.OnPulse         += (sender, e) => _NewUnitBuffer.DispatchEvents();

            _Controllers = new Dictionary <TurnComponent, Subcontroller>
            {
                { TurnComponent.DEPLOYMENT, new DeploymentController(this) },
                { TurnComponent.AIRCRAFT, new AircraftController(this) },
                { TurnComponent.ANTI_AIRCRAFT, new AntiAircraftController(this) },
                { TurnComponent.ARTILLERY, new ArtilleryController(this) },
                { TurnComponent.ATTACK, new AttackController(this) },
                { TurnComponent.VEHICLE_COMBAT_MOVEMENT, new OverrunController(this) },
                { TurnComponent.VEHICLE_MOVEMENT, new MovementController(this, true) },
                { TurnComponent.CLOSE_ASSAULT, new CloseAssaultController(this) },
                { TurnComponent.NON_VEHICLE_MOVEMENT, new MovementController(this, false) },
                { TurnComponent.RESET, new NoOpController(this) },
                { TurnComponent.WAIT, new NoOpController(this) },
                { TurnComponent.SPECTATE, new NoOpController(this) }
            };

            foreach (TileView t in MatchScreen.MapView.TilesEnumerable)
            {
                t.OnClick      += OnTileClick;
                t.OnRightClick += OnTileRightClick;
            }
            foreach (UnitView u in _MatchScreen.UnitViews)
            {
                AddUnit(u);
            }
            _KeyController              = KeyController;
            KeyController.OnKeyPressed += OnKeyPressed;

            MatchScreen.LoadButton.OnClick +=
                (sender, e) => LoadUnit(_CurrentTurn.TurnComponent != TurnComponent.DEPLOYMENT);
            MatchScreen.UnloadButton.OnClick         += (sender, e) => UnloadUnit();
            MatchScreen.FortifyButton.OnClick        += (sender, e) => FortifyUnit();
            MatchScreen.AbandonButton.OnClick        += (sender, e) => AbandonUnit();
            MatchScreen.DismountButton.OnClick       += (sender, e) => Dismount();
            MatchScreen.MountButton.OnClick          += (sender, e) => Mount();
            MatchScreen.EvacuateButton.OnClick       += (sender, e) => Evacuate();
            MatchScreen.ReconButton.OnClick          += (sender, e) => Recon();
            MatchScreen.ClearMinefieldButton.OnClick += (sender, e) => ClearMinefield();
            MatchScreen.EmplaceButton.OnClick        += (sender, e) => Emplace();

            _AllowedActions = new Dictionary <Button, Func <bool> >
            {
                { MatchScreen.LoadButton, () => _Controllers[_CurrentTurn.TurnComponent].CanLoad() },
                { MatchScreen.UnloadButton, () => _Controllers[_CurrentTurn.TurnComponent].CanUnload() },
                { MatchScreen.FortifyButton, () => _Controllers[_CurrentTurn.TurnComponent].CanFortify() },
                { MatchScreen.AbandonButton, () => _Controllers[_CurrentTurn.TurnComponent].CanAbandon() },
                { MatchScreen.DismountButton, () => _Controllers[_CurrentTurn.TurnComponent].CanDismount() },
                { MatchScreen.MountButton, () => _Controllers[_CurrentTurn.TurnComponent].CanMount() },
                { MatchScreen.EvacuateButton, () => _Controllers[_CurrentTurn.TurnComponent].CanEvacuate() },
                { MatchScreen.ReconButton, () => _Controllers[_CurrentTurn.TurnComponent].CanRecon() },
                {
                    MatchScreen.ClearMinefieldButton,
                    () => _Controllers[_CurrentTurn.TurnComponent].CanClearMinefield()
                },
                { MatchScreen.EmplaceButton, () => _Controllers[_CurrentTurn.TurnComponent].CanEmplace() }
            };
        }