コード例 #1
0
 /// <summary>
 /// Changes inventory item's amount. When add/remove object to/from building queue
 /// </summary>
 /// <param name="remove">Remove = true, Add = false</param>
 /// <param name="ratio">Ratio of item's amount</param>
 /// <param name="objectToBuild">Object to build</param>
 private void ChangeInventoryItemsAmount(bool remove, float ratio, MyObjectToBuild objectToBuild)
 {
     foreach (IMyBuildingRequirement buildingRequirement in objectToBuild.BuildingSpecification.BuildingRequirements)
     {
         MyBuildingRequirementInventoryItem buildingRequirementInventoryItem = buildingRequirement as MyBuildingRequirementInventoryItem;
         if (buildingRequirementInventoryItem != null)
         {
             if (buildingRequirementInventoryItem.RemoveAfterBuild)
             {
                 if (remove)
                 {
                     Player.Ship.Inventory.RemoveInventoryItemAmount(buildingRequirementInventoryItem.ObjectBuilderType,
                                                                     buildingRequirementInventoryItem.ObjectBuilderId,
                                                                     buildingRequirementInventoryItem.Amount * ratio);
                 }
                 else
                 {
                     Player.Ship.Inventory.AddInventoryItem(buildingRequirementInventoryItem.ObjectBuilderType,
                                                            buildingRequirementInventoryItem.ObjectBuilderId,
                                                            buildingRequirementInventoryItem.Amount * ratio, false);
                 }
             }
         }
     }
 }
コード例 #2
0
        protected override void OnDragDrop(object sender, EventArgs ea)
        {
            // Return if drop is done on some control
            foreach (var control in m_editorControls)
            {
                if (control == m_addObjectTreeViewdragDrop)
                {
                    continue;
                }
                if (control.Visible && control.ContainsMouse())
                {
                    return;
                }
            }

            MyObjectToBuild objectToBuild = m_addObjectTreeViewdragDrop.DraggedItem.Tag as MyObjectToBuild;

            if (objectToBuild != null && IsDragAndDropObject(objectToBuild))
            {
                List <MyInventoryItem> prefabInventoryItems = GetInventoryItems(objectToBuild.ObjectBuilder);
                if (prefabInventoryItems.Count > 0)
                {
                    AddPrefab(objectToBuild.ObjectBuilder as MyMwcObjectBuilder_PrefabBase);
                    MyInventoryItem prefabInventoryItem = prefabInventoryItems[0];
                    MyEditor.Static.FoundationFactory.PrefabContainer.Inventory.RemoveInventoryItem(prefabInventoryItem, true);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Removes object from building queue
        /// </summary>
        /// <param name="objectToBuild">Object to build</param>
        public void RemoveFromBuildingQueue(MyObjectToBuild objectToBuild)
        {
            int indexOfLastObjectToBuild = BuildingQueue.FindLastIndex(x => x == objectToBuild);

            if (indexOfLastObjectToBuild >= 0)
            {
                BuildingQueue.RemoveAt(indexOfLastObjectToBuild);
            }
            ChangeInventoryItemsAmount(false, MyFoundationFactoryConstants.RETURN_AMOUNT_RATIO, objectToBuild);
        }
コード例 #4
0
 private bool IsDragAndDropObject(MyObjectToBuild objectToBuild)
 {
     return(objectToBuild.ObjectBuilder.GetObjectBuilderType() == MyMwcObjectBuilderTypeEnum.Prefab ||
            objectToBuild.ObjectBuilder.GetObjectBuilderType() == MyMwcObjectBuilderTypeEnum.PrefabLight ||
            objectToBuild.ObjectBuilder.GetObjectBuilderType() == MyMwcObjectBuilderTypeEnum.PrefabParticles ||
            objectToBuild.ObjectBuilder.GetObjectBuilderType() == MyMwcObjectBuilderTypeEnum.PrefabSound ||
            objectToBuild.ObjectBuilder.GetObjectBuilderType() == MyMwcObjectBuilderTypeEnum.PrefabKinematic ||
            objectToBuild.ObjectBuilder.GetObjectBuilderType() == MyMwcObjectBuilderTypeEnum.PrefabLargeShip ||
            objectToBuild.ObjectBuilder.GetObjectBuilderType() == MyMwcObjectBuilderTypeEnum.PrefabLargeWeapon);
 }
コード例 #5
0
        /// <summary>
        /// Updates building progress
        /// </summary>
        /// <param name="treeViewItem">Treeview item</param>
        private void UpdateTreeViewItemStateBuildingProgress(MyTreeViewItem treeViewItem)
        {
            MyObjectToBuild objectToBuild = treeViewItem.Tag as MyObjectToBuild;

            treeViewItem.IconTexts[MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER].Text.Clear();
            //if (MyObjectToBuild.HasSameObjectBuilders(MyEditor.Static.FoundationFactory.BuildingObject, objectToBuild))
            if (MyEditor.Static.FoundationFactory.BuildingObject != null && MyEditor.Static.FoundationFactory.BuildingObject.IsSame(objectToBuild))
            {
                treeViewItem.IconTexts[MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER].Text.Append(GetBuildingObjectState(objectToBuild));
                treeViewItem.IconTexts[MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER].Text.Append(PERCENTAGE);
            }
        }
コード例 #6
0
        /// <summary>
        /// Updates building queue count
        /// </summary>
        /// <param name="treeViewItem">Treeview item</param>
        private void UpdateTreeViewItemStateBuildingQueue(MyTreeViewItem treeViewItem)
        {
            MyObjectToBuild objectToBuild = treeViewItem.Tag as MyObjectToBuild;

            int objectsInBuildingQueue = GetBuildingObjectInBuildinQueueCount(objectToBuild);

            treeViewItem.IconTexts[MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_BOTTOM].Text.Clear();
            if (objectsInBuildingQueue > 0)
            {
                treeViewItem.IconTexts[MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_BOTTOM].Text.Append(objectsInBuildingQueue);
            }
        }
コード例 #7
0
 private int?GetBuildingObjectState(MyObjectToBuild objectToBuild)
 {
     if (MyEditor.Static.FoundationFactory.IsBuilding &&
         //MyObjectToBuild.HasSameObjectBuilders(MyEditor.Static.FoundationFactory.BuildingObject, objectToBuild))
         MyEditor.Static.FoundationFactory.BuildingObject.IsSame(objectToBuild))
     {
         return((int?)(MyEditor.Static.FoundationFactory.BuildingPercentageComplete * 100f));
     }
     else
     {
         return(null);
     }
 }
コード例 #8
0
        private void OnBuildingComplete(MyPrefabFoundationFactory sender, MyObjectToBuild buildObject)
        {
            MyTreeViewItemUpdateStateFlag updateFlags = MyTreeViewItemUpdateStateFlag.BuildCountAndDragAndDrop | MyTreeViewItemUpdateStateFlag.BuildingProgress;

            MyTreeViewItem treeViewItem = GetTreeViewItem(buildObject);

            UpdateTreeViewItemState(treeViewItem, updateFlags);

            if (sender.BuildingObject != null)
            {
                UpdateTreeViewItemState(GetTreeViewItem(sender.BuildingObject), MyTreeViewItemUpdateStateFlag.BuildingQueue);
            }
            FilterAddObjectTreePrivate(MyEditorGizmo.SelectedSnapPoint);
        }
コード例 #9
0
        private MyTreeViewItem GetTreeViewItem(MyObjectToBuild objectToBuild)
        {
            MyTreeViewItem result     = null;
            int            itemsCount = m_addObjectTreeView.GetItemCount();

            for (int i = 0; i < itemsCount; i++)
            {
                result = GetTreeViewItem(m_addObjectTreeView.GetItem(i), objectToBuild);
                if (result != null)
                {
                    break;
                }
            }
            return(result);
        }
コード例 #10
0
        private void OnBuildingQueueChanged(MyObjectToBuild objectToBuild, bool added)
        {
            MyTreeViewItemUpdateStateFlag updateFlags = MyTreeViewItemUpdateStateFlag.BuildingQueue;

            if (!added)
            {
                updateFlags = updateFlags | MyTreeViewItemUpdateStateFlag.BuildingProgress;
            }

            MyTreeViewItem treeViewItem = GetTreeViewItem(objectToBuild);

            UpdateTreeViewItemState(treeViewItem, updateFlags);

            UpdateTreeViewItemsState(MyTreeViewItemUpdateStateFlag.CanBuildAndRequirements);
        }
コード例 #11
0
        private bool FilterResultByBuildItem(MyTreeViewItem item)
        {
            MyObjectToBuild objectToBuild = item.Tag as MyObjectToBuild;

            if (m_activeItemsWhichHasBuildFilter)
            {
                //if (MyEditor.Static.FoundationFactory.PrefabContainer.Inventory.GetInventoryItems(objectToBuild.ObjectBuilder).Count > 0)
                if (GetInventoryItemsCount(objectToBuild.ObjectBuilder) > 0)
                {
                    return(true);
                }
                return(false);
            }
            return(true);
        }
コード例 #12
0
        /// <summary>
        /// Adds object to building queue
        /// </summary>
        /// <param name="objectToBuild">Object to build</param>
        public void AddToBuildingQueue(MyObjectToBuild objectToBuild)
        {
            if (!objectToBuild.BuildingSpecification.CanBuild(this))
            {
                throw new Exception("You can't build this!");
            }

            BuildingQueue.Add(objectToBuild);
            ChangeInventoryItemsAmount(true, 1f, objectToBuild);

            if (!IsBuilding)
            {
                StartBuilding();
            }
        }
コード例 #13
0
        private bool FilterResultByItemAndPrefabSnapPoint(MyTreeViewItem item)
        {
            if (!MyEditor.Static.SnapPointFilter || m_activeSnapPointFilter == null)
            {
                // Always pass if snap point filter is disabled or no snap point selected
                return(true);
            }

            MyObjectToBuild objectToBuild = item.Tag as MyObjectToBuild;

            if (objectToBuild.ObjectBuilder is MyMwcObjectBuilder_PrefabBase)
            {
                var snapPoints = MyEditor.GetPrefabSnapPoints(objectToBuild.ObjectBuilder.GetObjectBuilderType(), objectToBuild.ObjectBuilder.GetObjectBuilderId().Value);
                return(snapPoints.Exists(a => m_activeSnapPointFilter.CanAttachTo(a)));
            }

            return(false);
        }
コード例 #14
0
        protected override void InitPrefab(string displayName, Vector3 relativePosition, Matrix localOrientation, MyMwcObjectBuilder_PrefabBase objectBuilder, MyPrefabConfiguration prefabConfig)
        {
            MyMwcObjectBuilder_PrefabFoundationFactory objectBuilderFF = objectBuilder as MyMwcObjectBuilder_PrefabFoundationFactory;

            IsBuilding = objectBuilderFF.IsBuilding;
            m_buildingTimeFromStart = objectBuilderFF.BuildingTimeFromStart;
            if (objectBuilderFF.BuildingObject != null)
            {
                BuildingObject = MyObjectToBuild.CreateFromObjectBuilder(objectBuilderFF.BuildingObject.ObjectBuilder, objectBuilderFF.BuildingObject.Amount);
            }
            if (objectBuilderFF.BuildingQueue != null)
            {
                foreach (MyMwcObjectBuilder_ObjectToBuild buildingQueue in objectBuilderFF.BuildingQueue)
                {
                    BuildingQueue.Add(MyObjectToBuild.CreateFromObjectBuilder(buildingQueue.ObjectBuilder, buildingQueue.Amount));
                }
            }
        }
コード例 #15
0
        private void OnItemAction(object sender, EventArgs args)
        {
            MyTreeViewItem  item          = sender as MyTreeViewItem;
            MyObjectToBuild objectToBuild = item.Tag as MyObjectToBuild;

            if (objectToBuild != null)
            {
                if (MyGuiScreenGamePlay.Static != null && MyGuiScreenGamePlay.Static.IsCheatEnabled(MyGameplayCheatsEnum.INSTANT_BUILDING))
                {
                    MyEditor.Static.FoundationFactory.PrefabContainer.Inventory.AddInventoryItem(objectToBuild.ObjectBuilder, objectToBuild.Amount, true);
                    UpdateTreeViewItemState(item, MyTreeViewItemUpdateStateFlag.BuildCountAndDragAndDrop);
                }
                else if (objectToBuild.BuildingSpecification.CanBuild(MyEditor.Static.FoundationFactory))
                {
                    MyEditor.Static.FoundationFactory.AddToBuildingQueue(objectToBuild);
                    OnBuildingQueueChanged(objectToBuild, true);
                }
            }
        }
コード例 #16
0
        /// <summary>
        /// Updates build count and enable/disable drag and drop on item
        /// </summary>
        /// <param name="treeViewItem">Treeview item</param>
        private void UpdateTreeViewItemStateBuildCount(MyTreeViewItem treeViewItem)
        {
            MyObjectToBuild objectToBuild     = treeViewItem.Tag as MyObjectToBuild;
            int             buildObjectsCount = GetBuildObjectsCount(objectToBuild);

            treeViewItem.IconTexts[MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM].Text.Clear();
            treeViewItem.IconTexts[MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM].Text.Append(buildObjectsCount);

            // we can drag and drop only prefabs
            if (IsDragAndDropObject(objectToBuild))
            {
                if (buildObjectsCount > 0 && treeViewItem.DragDrop == null)
                {
                    treeViewItem.DragDrop = m_addObjectTreeViewdragDrop;
                }
                else if (buildObjectsCount == 0 && treeViewItem.DragDrop != null)
                {
                    treeViewItem.DragDrop = null;
                }
            }
        }
コード例 #17
0
        private bool FilterResultByItemOnWhichHasBlueprints(MyTreeViewItem item)
        {
            MyObjectToBuild objectToBuild = item.Tag as MyObjectToBuild;

            if (m_activeItemsOnWhichHasBlueprintsFilter)
            {
                foreach (IMyBuildingRequirement buildingRequirement in objectToBuild.BuildingSpecification.BuildingRequirements)
                {
                    if (buildingRequirement is MyBuildingRequirementBlueprint)
                    {
                        MyBuildingRequirementBlueprint blueprintRequirement = buildingRequirement as MyBuildingRequirementBlueprint;
                        if (!blueprintRequirement.Check(MyEditor.Static.FoundationFactory))
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            }
            return(true);
        }
コード例 #18
0
        private MyTreeViewItem GetTreeViewItem(MyTreeViewItem treeViewItem, MyObjectToBuild objectToBuild)
        {
            MyTreeViewItem result = null;

            if (treeViewItem.Tag is MyObjectToBuild && ((MyObjectToBuild)treeViewItem.Tag).IsSame(objectToBuild))
            {
                result = treeViewItem;
            }
            else
            {
                int itemsCount = treeViewItem.GetItemCount();
                for (int i = 0; i < itemsCount; i++)
                {
                    result = GetTreeViewItem(treeViewItem.GetItem(i), objectToBuild);
                    if (result != null)
                    {
                        break;
                    }
                }
            }
            return(result);
        }
コード例 #19
0
        private bool FilterResultByItemOnWhichHasOre(MyTreeViewItem item)
        {
            MyObjectToBuild objectToBuild = item.Tag as MyObjectToBuild;

            if (m_activeItemsOnWhichHasOreFilter)
            {
                foreach (IMyBuildingRequirement buildingRequirement in objectToBuild.BuildingSpecification.BuildingRequirements)
                {
                    if (buildingRequirement is MyBuildingRequirementInventoryItem)
                    {
                        MyBuildingRequirementInventoryItem inventoryItemRequirement = buildingRequirement as MyBuildingRequirementInventoryItem;
                        if (inventoryItemRequirement.ObjectBuilderType == MyMwcObjectBuilderTypeEnum.Ore &&
                            !inventoryItemRequirement.Check(MyEditor.Static.FoundationFactory))
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            }
            return(true);
        }
コード例 #20
0
        /// <summary>
        /// Completes actual building
        /// </summary>
        private void CompleteBuilding()
        {
            MyObjectToBuild buildObject = BuildingObject;

            PrefabContainer.Inventory.AddInventoryItem(buildObject.ObjectBuilder, buildObject.Amount, false, true);

            if (BuildingQueue.Count != 0)
            {
                SetBuildingNextObject();
            }
            else
            {
                BuildingObject = null;
                IsBuilding     = false;
            }

            m_buildingTimeFromStart = 0;

            if (BuildingComplete != null)
            {
                BuildingComplete(this, buildObject);
            }
        }
コード例 #21
0
        /// <summary>
        /// Updates can build state and refresh building requirements
        /// </summary>
        /// <param name="treeViewItem">Treeview item</param>
        private void UpdateTreeViewItemStateCanBuild(MyTreeViewItem treeViewItem)
        {
            MyObjectToBuild objectToBuild = treeViewItem.Tag as MyObjectToBuild;

            treeViewItem.Enabled = GetBuildingObjectCanBuildState(objectToBuild);

            //treeViewItem.IconTexts[MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER].Text.Clear();
            ////if (MyObjectToBuild.HasSameObjectBuilders(MyEditor.Static.FoundationFactory.BuildingObject, objectToBuild))
            //if (MyEditor.Static.FoundationFactory.BuildingObject.IsSame(objectToBuild))
            //{
            //    treeViewItem.IconTexts[MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER].Text.Append(GetBuildingObjectState(objectToBuild));
            //    treeViewItem.IconTexts[MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER].Text.Append(PERCENTAGE);
            //}

            if (objectToBuild.BuildingSpecification.BuildingRequirements.Count > 0)
            {
                //int toolTipsCount = treeViewItem.ToolTip.GetToolTips().Count;
                //if (toolTipsCount > 1)
                //{
                //    treeViewItem.ToolTip.RemoveRange(1, toolTipsCount - 1);
                //}
                GetBuildingRequirementsDescription(treeViewItem.ToolTip, objectToBuild);
            }
        }
コード例 #22
0
        private void OnItemRighClick(object sender, EventArgs args)
        {
            MyTreeViewItem  item          = sender as MyTreeViewItem;
            MyObjectToBuild objectToBuild = item.Tag as MyObjectToBuild;

            if (objectToBuild != null)
            {
                //if (MyEditor.Static.FoundationFactory.IsBuilding && MyObjectToBuild.HasSameObjectBuilders(MyEditor.Static.FoundationFactory.BuildingObject, objectToBuild))
                if (MyEditor.Static.FoundationFactory.IsBuilding && MyEditor.Static.FoundationFactory.BuildingObject.IsSame(objectToBuild))
                {
                    MyEditor.Static.FoundationFactory.CancelBuilding();
                }
                else
                {
                    //MyObjectToBuild objectToRemove = MyEditor.Static.FoundationFactory.BuildingQueue.FindLast(x => MyObjectToBuild.HasSameObjectBuilders(x, objectToBuild));
                    MyObjectToBuild objectToRemove = MyEditor.Static.FoundationFactory.BuildingQueue.FindLast(x => x.IsSame(objectToBuild));
                    if (objectToRemove != null)
                    {
                        MyEditor.Static.FoundationFactory.RemoveFromBuildingQueue(objectToRemove);
                    }
                }
                OnBuildingQueueChanged(objectToBuild, false);
            }
        }
コード例 #23
0
        private void GetBuildingRequirementsDescription(MyToolTips requirementsDescription, MyObjectToBuild objectToBuild)
        {
            StringBuilder meetRequirements    = requirementsDescription.GetToolTips()[2].Text;
            StringBuilder notMeetRequirements = requirementsDescription.GetToolTips()[3].Text;

            meetRequirements.Clear();
            notMeetRequirements.Clear();

            foreach (IMyBuildingRequirement buildingRequirement in objectToBuild.BuildingSpecification.BuildingRequirements)
            {
                if (buildingRequirement.Check(MyEditor.Static.FoundationFactory))
                {
                    MyMwcUtils.AppendStringBuilder(meetRequirements, buildingRequirement.GetDescription());
                    meetRequirements.AppendLine();
                }
                else
                {
                    MyMwcUtils.AppendStringBuilder(notMeetRequirements, buildingRequirement.GetDescription());
                    notMeetRequirements.AppendLine();
                }
            }

            requirementsDescription.RecalculateSize();
        }
コード例 #24
0
 /// <summary>
 /// Removes build object from build objects collection
 /// </summary>
 /// <param name="objectToBuild">Build object</param>
 public void RemoveFromBuildObjects(MyObjectToBuild objectToBuild)
 {
     BuildObjects.Remove(objectToBuild);
 }
コード例 #25
0
 private int GetBuildObjectsCount(MyObjectToBuild objectToBuild)
 {
     //return MyEditor.Static.FoundationFactory.PrefabContainer.Inventory.GetInventoryItems(objectToBuild.ObjectBuilder).Count;
     return(GetInventoryItemsCount(objectToBuild.ObjectBuilder));
 }
コード例 #26
0
 private bool GetBuildingObjectCanBuildState(MyObjectToBuild objectToBuild)
 {
     return(objectToBuild.BuildingSpecification.CanBuild(MyEditor.Static.FoundationFactory));
 }
コード例 #27
0
 private int GetBuildingObjectInBuildinQueueCount(MyObjectToBuild objectToBuild)
 {
     //return MyEditor.Static.FoundationFactory.BuildingQueue.Count(x => MyObjectToBuild.HasSameObjectBuilders(x, objectToBuild));
     return(MyEditor.Static.FoundationFactory.BuildingQueue.Count(x => x.IsSame(objectToBuild)));
 }