Interaction logic for ObjectEditDialog.xaml
Inheritance: System.Windows.Window
示例#1
0
        void ShowObjectInDialog(object ob)
        {
            var dlg = new ObjectEditDialog();

            dlg.DataContext = ob;
            dlg.Owner       = Window.GetWindow(this);
            dlg.Show();
        }
        void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            var menuItem = (MenuItem)sender;
            var cm = (ContextMenu)menuItem.Parent;
            DependencyObject obj = cm.PlacementTarget;

            while (obj != null && !(obj is TreeViewItem))
                obj = VisualTreeHelper.GetParent(obj);

            var tvi = obj as TreeViewItem;
            var baseObject = tvi.Header as BaseObject;

            if (baseObject == null)
                return;

            var tag = (string)menuItem.Tag;

            switch (tag)
            {
                case "Goto":
                    {
                        var movable = baseObject as MovableObject;
                        if (movable != null && movable.Environment != null)
                        {
                            App.GameWindow.MapControl.CameraMoveTo(movable);
                            return;
                        }
                    }
                    break;

                case "Info":
                    {
                        var dlg = new ObjectEditDialog();
                        dlg.DataContext = baseObject;
                        dlg.Owner = App.GameWindow;
                        dlg.Show();

                    }
                    break;

                case "Control":
                    {
                        var living = baseObject as LivingObject;

                        if (living == null)
                            return;

                        var wnd = new LivingControlWindow();
                        wnd.DataContext = living;
                        wnd.Owner = App.GameWindow;
                        wnd.Show();
                    }
                    break;

                default:
                    throw new Exception();
            }
        }
示例#3
0
		void ShowObjectInDialog(object ob)
		{
			var dlg = new ObjectEditDialog();
			dlg.DataContext = ob;
			dlg.Owner = this;
			dlg.Show();
		}
示例#4
0
		void MapControl_GotSelection(MapSelection selection)
		{
			var env = this.Map;

			switch (this.ClientTools.ToolMode)
			{
				case ClientToolMode.DesignationRemove:
					env.Designations.RemoveArea(selection.SelectionBox);
					break;

				case ClientToolMode.DesignationMine:
					env.Designations.AddArea(selection.SelectionBox, DesignationType.Mine);
					break;

				case ClientToolMode.DesignationStairs:
					env.Designations.AddArea(selection.SelectionBox, DesignationType.CreateStairs);
					break;

				case ClientToolMode.DesignationChannel:
					env.Designations.AddArea(selection.SelectionBox, DesignationType.Channel);
					break;

				case ClientToolMode.DesignationFellTree:
					env.Designations.AddArea(selection.SelectionBox, DesignationType.FellTree);
					break;

				case ClientToolMode.CreateStockpile:
					{
						var stockpile = Stockpile.CreateStockpile(env, selection.SelectionIntRectZ);

						var dlg = new ObjectEditDialog();
						dlg.DataContext = stockpile;
						dlg.Owner = this;
						dlg.Show();
					}
					break;

				case ClientToolMode.InstallItem:
					{
						var p = selection.SelectionPoint;

						var dlg = new InstallItemDialog();
						dlg.SetContext(env, p);

						var res = dlg.ShowDialog();

						if (res == true)
						{
							var item = dlg.SelectedItem;

							if (item != null)
								env.InstallItemManager.AddInstallJob(item, p);
						}
					}
					break;

				case ClientToolMode.BuildItem:
					{
						var p = selection.SelectionPoint;

						var workbench = env.GetContents(p).OfType<ItemObject>()
							.SingleOrDefault(i => i.IsInstalled && i.ItemCategory == ItemCategory.Workbench);

						if (workbench == null)
							break;

						var ctrl = new BuildingEditControl();
						ctrl.DataContext = BuildItemManager.FindOrCreateBuildItemManager(workbench);

						var dlg = new Window();
						dlg.Content = ctrl;

						var res = dlg.ShowDialog();

						if (res == true)
						{
						}
					}
					break;

				case ClientToolMode.SetTerrain:
					{
						var dialog = new SetTerrainDialog();
						dialog.Owner = this;
						if (m_setTerrainData != null)
							dialog.Data = m_setTerrainData;
						var res = dialog.ShowDialog();

						if (res == true)
						{
							var data = dialog.Data;
							m_setTerrainData = data;

							DebugScriptMessages.SendSetTerrains(dialog, map.Environment, selection.SelectionBox);
						}
					}
					break;

				case ClientToolMode.CreateItem:
					{
						var dialog = new CreateItemDialog();
						dialog.Owner = this;
						dialog.SetContext(env, selection.SelectionBox);
						var res = dialog.ShowDialog();

						if (res == true)
							DebugScriptMessages.SendCreateItem(dialog);
					}
					break;

				case ClientToolMode.CreateLiving:
					{
						var dialog = new CreateLivingDialog();
						dialog.Owner = this;
						dialog.SetContext(env, selection.SelectionIntRectZ);
						var res = dialog.ShowDialog();

						if (res == true)
							DebugScriptMessages.SendCreateLiving(dialog);
					}
					break;

				case ClientToolMode.ConstructRemove:
					env.ConstructManager.RemoveArea(selection.SelectionIntRectZ);
					break;

				case ClientToolMode.ConstructWall:
				case ClientToolMode.ConstructFloor:
				case ClientToolMode.ConstructPavement:
					{
						ConstructMode mode;

						switch (this.ClientTools.ToolMode)
						{
							case ClientToolMode.ConstructWall:
								mode = ConstructMode.Wall;
								break;

							case ClientToolMode.ConstructFloor:
								mode = ConstructMode.Floor;
								break;

							case ClientToolMode.ConstructPavement:
								mode = ConstructMode.Pavement;
								break;

							default:
								throw new Exception();
						}

						var dialog = new ConstructDialog();
						dialog.Owner = this;
						dialog.ConstructMode = mode;
						var res = dialog.ShowDialog();

						if (res == true)
						{
							var area = selection.SelectionIntRectZ;
							var filter = dialog.GetItemFilter();

							env.ConstructManager.AddConstructJob(mode, area, filter);
						}
					}
					break;

				default:
					throw new Exception();
			}

			this.MapControl.Selection = new MapSelection();
		}
        void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            var menuItem         = (MenuItem)sender;
            var cm               = (ContextMenu)menuItem.Parent;
            DependencyObject obj = cm.PlacementTarget;

            while (obj != null && !(obj is TreeViewItem))
            {
                obj = VisualTreeHelper.GetParent(obj);
            }

            var tvi        = obj as TreeViewItem;
            var baseObject = tvi.Header as BaseObject;

            if (baseObject == null)
            {
                return;
            }

            var tag = (string)menuItem.Tag;

            switch (tag)
            {
            case "Goto":
            {
                var movable = baseObject as MovableObject;
                if (movable != null && movable.Environment != null)
                {
                    App.GameWindow.MapControl.CameraMoveTo(movable);
                    return;
                }
            }
            break;

            case "Info":
            {
                var dlg = new ObjectEditDialog();
                dlg.DataContext = baseObject;
                dlg.Owner       = App.GameWindow;
                dlg.Show();
            }
            break;

            case "Control":
            {
                var living = baseObject as LivingObject;

                if (living == null)
                {
                    return;
                }

                var wnd = new LivingControlWindow();
                wnd.DataContext = living;
                wnd.Owner       = App.GameWindow;
                wnd.Show();
            }
            break;

            default:
                throw new Exception();
            }
        }
示例#6
0
        void MapControl_GotSelection(MapSelection selection)
        {
            var env = this.Map;

            switch (this.ToolMode)
            {
            case ClientToolMode.View:
                ShowObjectsPopup(selection.SelectionPoint);
                break;

            case ClientToolMode.DesignationRemove:
                env.Designations.RemoveArea(selection.SelectionBox);
                break;

            case ClientToolMode.DesignationMine:
                env.Designations.AddArea(selection.SelectionBox, DesignationType.Mine);
                break;

            case ClientToolMode.DesignationStairs:
                env.Designations.AddArea(selection.SelectionBox, DesignationType.CreateStairs);
                break;

            case ClientToolMode.DesignationFellTree:
                env.Designations.AddArea(selection.SelectionBox, DesignationType.FellTree);
                break;

            case ClientToolMode.CreateStockpile:
            {
                var stockpile = Stockpile.CreateStockpile(env, selection.SelectionIntRectZ);

                var dlg = new ObjectEditDialog();
                dlg.DataContext = stockpile;
                dlg.Owner       = this;
                dlg.Show();
            }
            break;

            case ClientToolMode.InstallItem:
            {
                var p = selection.SelectionPoint;

                var dlg = new InstallItemDialog();
                dlg.SetContext(env, p);

                var res = dlg.ShowDialog();

                if (res == true)
                {
                    var item = dlg.SelectedItem;

                    if (item != null)
                    {
                        env.InstallItemManager.AddInstallJob(item, p);
                    }
                }
            }
            break;

            case ClientToolMode.BuildItem:
            {
                var p = selection.SelectionPoint;

                var workbench = env.GetContents(p).OfType <ItemObject>()
                                .SingleOrDefault(i => i.IsInstalled && i.ItemCategory == ItemCategory.Workbench);

                if (workbench == null)
                {
                    break;
                }

                var ctrl = new BuildingEditControl();
                ctrl.DataContext = BuildItemManager.FindOrCreateBuildItemManager(workbench);

                var dlg = new Window();
                dlg.Content = ctrl;

                var res = dlg.ShowDialog();

                if (res == true)
                {
                }
            }
            break;

            case ClientToolMode.SetTerrain:
            {
                var dialog = new SetTerrainDialog();
                dialog.Owner = this;
                if (m_setTerrainData != null)
                {
                    dialog.Data = m_setTerrainData;
                }
                var res = dialog.ShowDialog();

                if (res == true)
                {
                    var data = dialog.Data;
                    m_setTerrainData = data;

                    DebugScriptMessages.SendSetTerrains(dialog, map.Environment, selection.SelectionBox);
                }
            }
            break;

            case ClientToolMode.CreateItem:
            {
                var dialog = new CreateItemDialog();
                dialog.Owner = this;
                dialog.SetContext(env, selection.SelectionBox);
                var res = dialog.ShowDialog();

                if (res == true)
                {
                    DebugScriptMessages.SendCreateItem(dialog);
                }
            }
            break;

            case ClientToolMode.CreateLiving:
            {
                var dialog = new CreateLivingDialog();
                dialog.Owner = this;
                dialog.SetContext(env, selection.SelectionIntRectZ);
                var res = dialog.ShowDialog();

                if (res == true)
                {
                    DebugScriptMessages.SendCreateLiving(dialog);
                }
            }
            break;

            case ClientToolMode.ConstructRemove:
                env.ConstructManager.RemoveArea(selection.SelectionIntRectZ);
                break;

            case ClientToolMode.ConstructWall:
            case ClientToolMode.ConstructFloor:
            case ClientToolMode.ConstructPavement:
            {
                ConstructMode mode;

                switch (this.ToolMode)
                {
                case ClientToolMode.ConstructWall:
                    mode = ConstructMode.Wall;
                    break;

                case ClientToolMode.ConstructFloor:
                    mode = ConstructMode.Floor;
                    break;

                case ClientToolMode.ConstructPavement:
                    mode = ConstructMode.Pavement;
                    break;

                default:
                    throw new Exception();
                }

                var dialog = new ConstructDialog();
                dialog.Owner         = this;
                dialog.ConstructMode = mode;
                var res = dialog.ShowDialog();

                if (res == true)
                {
                    var area   = selection.SelectionIntRectZ;
                    var filter = dialog.GetItemFilter();

                    env.ConstructManager.AddConstructJob(mode, area, filter);
                }
            }
            break;

            default:
                throw new Exception();
            }

            this.MapControl.Selection = new MapSelection();
        }
示例#7
0
		void ShowObjectInDialog(object ob)
		{
			var dlg = new ObjectEditDialog();
			dlg.DataContext = ob;
			dlg.Owner = Window.GetWindow(this);
			dlg.Show();
		}