Example #1
0
        public Mission(string name, Mod game, Map map)
        {
            Mod     = game;
            Map     = map;
            Name    = name;
            ModName = game.Name;
            MapName = map.Name;
            var testAI  = game.AllAis.FirstOrDefault(ai => ai.ShortName.Contains("NullAI"));
            var player1 = new Player {
                Name = "Player 1", Color = Colors.Blue, Alliance = "Alliance 1", IsHuman = true, IsRequired = true
            };
            var player2 = new Player {
                Name = "Player 2", Color = Colors.Red, Alliance = "Alliance 2", IsHuman = false,
            };

            StartingPlayer = player1;
            Players.Add(player1);
            Players.Add(player2);
            Regions.Add(new Region {
                Name = "Region 1"
            });

            var gamePreloadTrigger = new Trigger();

            Triggers.Add(gamePreloadTrigger);
            gamePreloadTrigger.Logic.Add(new GamePreloadCondition());
            gamePreloadTrigger.Name = "Initialization";

            var gameStartTrigger = new Trigger();

            Triggers.Add(gameStartTrigger);
            gameStartTrigger.Logic.Add(new GameStartedCondition());
            gameStartTrigger.Name = "Game Start";
            var unitType   = game.UnitDefs.First();
            var startUnits = new UnitStartInfo[]  {};

            gamePreloadTrigger.Logic.Add(new CreateUnitsAction(startUnits));

            var widgets = new[] { "cmd_unit_mover.lua", "init_startup_info_selector.lua", "gui_center_n_select.lua", "gui_take_remind.lua", "gui_startup_info_selector.lua", "gui_local_colors.lua", "spring_direct_launch.lua" };

            foreach (var widget in widgets)
            {
                DisabledWidgets.Add(widget);
            }
            var gadgets = new string[] { "game_over.lua", "game_end.lua", "awards.lua" };

            foreach (var gadget in gadgets)
            {
                DisabledGadgets.Add(gadget);
            }
            if (game.Name.Contains("Zero-K"))
            {
                RapidTag = "zk:stable";
            }
            Items = new CompositeObservableCollection <Trigger, Region>(Triggers, Regions);
        }
		void PlaceUnitIcon(UnitStartInfo unit)
		{
			var unitIcon = new UnitIcon();
			unitIcon.DataContext = unit;
			unitIcon.Bind(Canvas.LeftProperty, unit, "X", BindingMode.OneWay, new TranslateConverter(), -8);
			unitIcon.Bind(Canvas.TopProperty, unit, "Y", BindingMode.OneWay, new TranslateConverter(), -8);
			unitIcon.MouseDown += unitIcon_MouseDown;
            unitIcon.MouseUp += unitIcon_MouseUp;
			unitIcon.UnitRequestedDelete += unitIcon_UnitRequestedDelete;
			unitIcon.UnitRequestedSetGroups += unitIcon_UnitRequestedSetGroups;
			unitIcon.UnitRequestedSetOwner += unitIcon_UnitRequestedSetOwner;

			unitCanvas.Children.Add(unitIcon);
			unitIcons.Add(unitIcon);
		}
		public Mission(string name, Mod game, Map map)
		{
			Mod = game;
			Map = map;
			Name = name;
			ModName = game.Name;
			MapName = map.Name;
			var testAI = game.AllAis.FirstOrDefault(ai => ai.ShortName.Contains("NullAI"));
			var player1 = new Player { Name = "Player 1", Color = Colors.Blue, Alliance = "Alliance 1", IsHuman = true, IsRequired = true };
			var player2 = new Player { Name = "Player 2", Color = Colors.Red, Alliance = "Alliance 2", IsHuman = false, };
			StartingPlayer = player1;
			Players.Add(player1);
			Players.Add(player2);
			Regions.Add(new Region { Name = "Region 1" });

            var gamePreloadTrigger = new Trigger();
			Triggers.Add(gamePreloadTrigger);
			gamePreloadTrigger.Logic.Add(new GamePreloadCondition());
            gamePreloadTrigger.Name = "Initialization";

            var gameStartTrigger = new Trigger();
            Triggers.Add(gameStartTrigger);
            gameStartTrigger.Logic.Add(new GameStartedCondition());
            gameStartTrigger.Name = "Game Start";
			var unitType = game.UnitDefs.First();
			var startUnits = new UnitStartInfo[]  {};
			gamePreloadTrigger.Logic.Add(new CreateUnitsAction(startUnits));

            var widgets = new[] { "gui_pauseScreen.lua", "cmd_unit_mover.lua", "init_startup_info_selector.lua", "gui_center_n_select.lua", "gui_take_remind.lua", "gui_startup_info_selector.lua", "gui_local_colors.lua", "spring_direct_launch.lua" };
			foreach (var widget in widgets) DisabledWidgets.Add(widget);
			var gadgets = new string[] { "game_over.lua", "game_end.lua", "awards.lua" };
			foreach (var gadget in gadgets) DisabledGadgets.Add(gadget);
			if (game.Name.Contains("Zero-K")) RapidTag = "zk:stable";
			Items = new CompositeObservableCollection<Trigger, Region>(Triggers, Regions);
		}
		void unitCanvas_PreviewMouseUp(object sender, MouseButtonEventArgs e)
		{ 
			if (dragInfo != null)
			{
				e.Handled = true;
				unitCanvas.ReleaseMouseCapture();
				dragInfo = null;
			}
            if (isBoxSelecting)
            {
                // hide and release the box
                selectionBox.Visibility = Visibility.Collapsed;
                unitCanvas.ReleaseMouseCapture();
                isBoxSelecting = false;

                Point boxEndPos = e.GetPosition(unitCanvas);
                double x1 = boxStartPos.X, y1 = boxStartPos.Y, x2 = boxEndPos.X, y2 = boxEndPos.Y;
                if (x2 < x1)
                {
                    double temp = x1;
                    x1 = x2;
                    x2 = temp;
                }
                if (y2 < y1)
                {
                    double temp = y1;
                    y1 = y2;
                    y2 = temp;
                }
                
                // clear existing selection if not Shift
                if (Keyboard.Modifiers != ModifierKeys.Shift && Keyboard.Modifiers != ModifierKeys.Control)
                {
                    List<UnitIcon> select = unitIcons.Where(i => i.IsSelected).ToList();
                    foreach (UnitIcon i in select) i.IsSelected = false;
                    select = new List<UnitIcon>();
                }
                // add to selection
                foreach (UnitIcon icon in unitIcons)
                {
                    Positionable pos = (Positionable)icon.DataContext;
                    if (pos.X >= x1 && pos.X <= x2 && pos.Y >= y1 && pos.Y <= y2)
                    {
                        icon.IsSelected = true;
                    }
                }
            }

			if (unitDefGrid.Grid.SelectedItem != null && DateTime.Now - mouseDownDate < TimeSpan.FromMilliseconds(150) && e.ChangedButton == MouseButton.Left &&
			    Keyboard.Modifiers == ModifierKeys.None)
			{
				var unitType = (UnitInfo)unitDefGrid.Grid.SelectedItem;
				var mousePos = e.GetPosition(unitCanvas);
				var player = (Player)playerListBox.SelectedItem;
				var unitStartInfo = new UnitStartInfo(unitType, player, SnapToGridX(mousePos.X), SnapToGridY(mousePos.Y));
				((INotifyPropertyChanged)unitStartInfo).PropertyChanged += (se, ea) => // fixme: leak
					{ if (ea.PropertyName == "Groups") MainWindow.Instance.Mission.RaisePropertyChanged("AllGroups"); };
				action.Units.Add(unitStartInfo);
				PlaceUnitIcon(unitStartInfo);
			}
		}
		public UnitEventArgs(UnitStartInfo unitInfo, RoutedEvent routedEvent) : base(routedEvent)
		{
			UnitInfo = unitInfo;
		}