예제 #1
0
        public GalaxyGridView([NotNull] IUnityContainer container)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            _container          = container;
            _appContext         = _container.Resolve <IAppContext>();
            _navigationCommands = _container.Resolve <INavigationCommandsProxy>();

            InitializeComponent();

            Loaded += delegate
            {
                GalaxyGrid.Update();
                GalaxyGrid.SelectedSector = _appContext.LocalPlayerEmpire.SeatOfGovernment.Sector;
                GalaxyGrid.CenterOnSelectedSector();
            };
            Unloaded += OnUnloaded;

            GalaxyGrid.SectorDoubleClicked += OnSectorDoubleClicked;

            PropertyChangedEventManager.AddListener(_appContext, this, "LocalPlayerEmpire");

            _revealMapCommand      = new DelegateCommand <object>(ExecuteRevealMapCommand);
            _cheatMenuCommand      = new DelegateCommand <object>(ExecuteCheatMenuCommand);
            _gameInfoScreenCommand = new DelegateCommand <object>(ExecuteGameInfoScreenCommand);

            DebugCommands.RevealMap.RegisterCommand(_revealMapCommand);
            DebugCommands.CheatMenu.RegisterCommand(_cheatMenuCommand);
            DebugCommands.GameInfoScreen.RegisterCommand(_gameInfoScreenCommand);
        }
예제 #2
0
        public ClientWindow(
            [NotNull] IClientApplication app,
            [NotNull] IAppContext appContext,
            [NotNull] IAudioEngine audioEngine,
            [NotNull] IMusicPlayer musicPlayer,
            [NotNull] ISoundPlayer soundPlayer,
            [NotNull] IEventAggregator eventAggregator,
            [NotNull] INavigationCommandsProxy navigationCommands)
        {
            if (app == null)
            {
                throw new ArgumentNullException("app");
            }
            if (appContext == null)
            {
                throw new ArgumentNullException("appContext");
            }
            if (audioEngine == null)
            {
                throw new ArgumentNullException("audioEngine");
            }
            if (musicPlayer == null)
            {
                throw new ArgumentNullException("musicPlayer");
            }
            if (soundPlayer == null)
            {
                throw new ArgumentNullException("soundPlayer");
            }
            if (eventAggregator == null)
            {
                throw new ArgumentNullException("eventAggregator");
            }
            if (navigationCommands == null)
            {
                throw new ArgumentNullException("navigationCommands");
            }

            _app                 = app;
            _appContext          = appContext;
            _audioEngine         = audioEngine;
            _musicPlayer         = musicPlayer;
            _soundPlayer         = soundPlayer;
            _eventAggregator     = eventAggregator;
            _navigationCommands  = navigationCommands;
            _waitCursorLock      = new object();
            _settingsChangeScope = new StateScope();

            _defaultCursor = new Cursor(
                Path.Combine(
                    Environment.CurrentDirectory,
                    @"Resources\Cursors\cursor.cur"));

            InitializeComponent();

            /*
             * Officially, we only support video resolutions of 1024x768 and up.  However, considering
             * 1280x720 is one of the standard High Definition resolutions, we will adjust our minimum
             * size constraints to accomodate it.
             */
            // ReSharper disable CompareOfFloatsByEqualityOperator
            if (SystemParameters.PrimaryScreenWidth != 1280d ||
                (SystemParameters.PrimaryScreenHeight != 720d))
            {
                MinHeight = 720;
                Height    = 720;
            }
            // ReSharper restore CompareOfFloatsByEqualityOperator

            Cursor = _defaultCursor;

            Loaded      += OnLoaded;
            SizeChanged += OnSizeChanged;

            _eventAggregator.GetEvent <TurnStartedEvent>().Subscribe(OnTurnStarted, ThreadOption.UIThread);
            _eventAggregator.GetEvent <GameStartedEvent>().Subscribe(OnGameStarted, ThreadOption.UIThread);
            _eventAggregator.GetEvent <GameEndedEvent>().Subscribe(OnGameEnded, ThreadOption.UIThread);
            _eventAggregator.GetEvent <GameEndingEvent>().Subscribe(OnGameEnding, ThreadOption.UIThread);
            _eventAggregator.GetEvent <ClientDisconnectedEvent>().Subscribe(OnClientDisconnected, ThreadOption.UIThread);
            _eventAggregator.GetEvent <GameEndedEvent>().Subscribe(OnGameEnded, ThreadOption.UIThread);
            _eventAggregator.GetEvent <AllTurnEndedEvent>().Subscribe(OnAllTurnEnded, ThreadOption.UIThread);
            _eventAggregator.GetEvent <ChatMessageReceivedEvent>().Subscribe(OnChatMessageReceived, ThreadOption.UIThread);

            ModelessDialogsRegion.SelectionChanged += OnModelessDialogsRegionSelectionChanged;
            ModalDialogsRegion.SelectionChanged    += OnModalDialogsRegionSelectionChanged;

            ClientSettings.Current.EnableAntiAliasingChanged += OnEnableAntiAliasingSettingsChanged;

            ApplyAntiAliasingSettings();

            InputBindings.Add(
                new KeyBinding(
                    CollectGarbageCommand,
                    new KeyGesture(Key.G, ModifierKeys.Control | ModifierKeys.Shift)));

            InputBindings.Add(
                new KeyBinding(
                    ClientCommands.EscapeCommand,
                    new KeyGesture(Key.Escape, ModifierKeys.None)));

            InputBindings.Add(
                new KeyBinding(
                    _navigationCommands.ActivateScreen,
                    new KeyGesture(Key.F1, ModifierKeys.None))
            {
                CommandParameter = StandardGameScreens.GalaxyScreen
            });

            InputBindings.Add(
                new KeyBinding(
                    _navigationCommands.ActivateScreen,
                    new KeyGesture(Key.F2, ModifierKeys.None))
            {
                CommandParameter = StandardGameScreens.ColonyScreen
            });

            InputBindings.Add(
                new KeyBinding(
                    _navigationCommands.ActivateScreen,
                    new KeyGesture(Key.F3, ModifierKeys.None))
            {
                CommandParameter = StandardGameScreens.DiplomacyScreen
            });

            InputBindings.Add(
                new KeyBinding(
                    _navigationCommands.ActivateScreen,
                    new KeyGesture(Key.F4, ModifierKeys.None))
            {
                CommandParameter = StandardGameScreens.ScienceScreen
            });

            InputBindings.Add(
                new KeyBinding(
                    _navigationCommands.ActivateScreen,
                    new KeyGesture(Key.F5, ModifierKeys.None))
            {
                CommandParameter = StandardGameScreens.IntelScreen
            });

            InputBindings.Add(
                new KeyBinding(
                    ToggleFullScreenModeCommand,
                    Key.Enter,
                    ModifierKeys.Alt));

            CommandBindings.Add(
                new CommandBinding(
                    ClientCommands.EscapeCommand,
                    ExecuteEscapeCommand));

            CommandBindings.Add(
                new CommandBinding(
                    ToggleFullScreenModeCommand,
                    (s, e) => ToggleFullScreenMode()));

            CommandBindings.Add(
                new CommandBinding(
                    CollectGarbageCommand,
                    (s, e) =>
            {
                var process    = Process.GetCurrentProcess();
                var workingSet = process.WorkingSet64;
                var heapSize   = GC.GetTotalMemory(false);

                GameLog.Client.General.Info("Forcing garbage collection...");

                GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
                GC.WaitForPendingFinalizers();

                process.Refresh();

                GameLog.Client.General.InfoFormat(
                    "[working set [{0:#,#,} K -> {1:#,#,} K], managed heap [{2:#,#,} K -> {3:#,#,} K]]",
                    workingSet,
                    process.WorkingSet64,
                    heapSize,
                    GC.GetTotalMemory(false));

                GameLog.Client.GameData.DebugFormat(
                    "[working set [{0:#,#,} K -> {1:#,#,} K], managed heap [{2:#,#,} K -> {3:#,#,} K]]",
                    workingSet,
                    process.WorkingSet64,
                    heapSize,
                    GC.GetTotalMemory(false));
            }));

            InputBindings.Add(
                new KeyBinding(
                    ClientCommands.AutoTurnCommand,
                    Key.A,
                    ModifierKeys.Alt));

            InputBindings.Add(
                new KeyBinding(
                    ClientCommands.ColonyInfoScreen,
                    Key.F8,
                    ModifierKeys.None));

            InputBindings.Add(
                new KeyBinding(
                    ClientCommands.ColorInfoScreen,
                    Key.F6,
                    ModifierKeys.Alt));

            InputBindings.Add(
                new KeyBinding(
                    ClientCommands.ErrorTxtCommand,
                    Key.E,
                    ModifierKeys.Control));

            InputBindings.Add(
                new KeyBinding(
                    ClientCommands.LogTxtCommand,
                    Key.L,
                    ModifierKeys.Control));

            InputBindings.Add(
                new KeyBinding(
                    ClientCommands.OptionsCommand,
                    Key.O,
                    ModifierKeys.Control));

            // CRTL+S makes saved file "_manual_save"
            InputBindings.Add(
                new KeyBinding(
                    ClientCommands.SaveGame,
                    Key.S,
                    ModifierKeys.Control));

            InputBindings.Add(
                new KeyBinding(
                    ClientCommands.EndTurn,
                    Key.T,
                    ModifierKeys.Control));

            CommandBindings.Add(
                new CommandBinding(
                    ClientCommands.AutoTurnCommand,
                    (s, e) =>
            {
                var service      = ServiceLocator.Current.GetInstance <IPlayerOrderService>();
                service.AutoTurn = !service.AutoTurn;
                if (service.AutoTurn)
                {
                    ClientCommands.EndTurn.Execute(null);
                }
            }));

            var settings = ClientSettings.Current;

            Width  = settings.ClientWindowWidth;
            Height = settings.ClientWindowHeight;

            CheckFullScreenSettings();
        }
예제 #3
0
        public ClientModule(
            [NotNull] IClientApplication app,
            [NotNull] IUnityContainer container,
            [NotNull] IResourceManager resourceManager,
            [NotNull] IRegionViewRegistry regionViewRegistry,
            [NotNull] IDispatcherService dispatcherService,
            [NotNull] IGameErrorService errorService,
            [NotNull] IMusicPlayer musicPlayer,
            [NotNull] ISoundPlayer soundPlayer)
        {
            if (app == null)
            {
                throw new ArgumentNullException("app");
            }
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }
            if (resourceManager == null)
            {
                throw new ArgumentNullException("resourceManager");
            }
            if (regionViewRegistry == null)
            {
                throw new ArgumentNullException("regionViewRegistry");
            }
            if (dispatcherService == null)
            {
                throw new ArgumentNullException("dispatcherService");
            }
            if (errorService == null)
            {
                throw new ArgumentNullException("errorService");
            }
            if (musicPlayer == null)
            {
                throw new ArgumentNullException("musicPlayer");
            }
            if (soundPlayer == null)
            {
                throw new ArgumentNullException("soundPlayer");
            }

            _app                = app;
            _container          = container;
            _resourceManager    = resourceManager;
            _regionViewRegistry = regionViewRegistry;
            _dispatcherService  = dispatcherService;
            _errorService       = errorService;
            _musicPlayer        = musicPlayer;
            _soundPlayer        = soundPlayer;

            _appContext         = _container.Resolve <IAppContext>();
            _regionManager      = _container.Resolve <IRegionManager>();
            _navigationCommands = _container.Resolve <INavigationCommandsProxy>();

            _optionsDialog = new ClientOptionsDialog();

            _optionsCommand = new DelegateCommand <object>(
                ExecuteOptionsCommand);

            _logTxtCommand = new DelegateCommand <object>(
                ExecuteLogTxtCommand);

            _errorTxtCommand = new DelegateCommand <object>(
                ExecuteErrorTxtCommand);

            _startSinglePlayerGameCommand = new DelegateCommand <object>(
                ExecuteStartSinglePlayerGameCommand);

            _continueGameCommand = new DelegateCommand <object>(
                ExecuteContinueGameCommand);

            _endGameCommand = new DelegateCommand <bool>(
                ExecuteEndGameCommand);

            _exitCommand = new DelegateCommand <bool>(
                ExecuteExitCommand);

            _loadGameCommand = new DelegateCommand <SavedGameHeader>(
                ExecuteLoadGameCommand);

            _showCreditsDialogCommand = new DelegateCommand <object>(
                ExecuteShowCreditsDialogCommand);

            _joinMultiplayerGameCommand = new DelegateCommand <MultiplayerConnectParameters>(
                ExecuteJoinMultiplayerGameCommand);

            _hostMultiplayerGameCommand = new DelegateCommand <string>(
                ExecuteHostMultiplayerGameCommand);
        }