Exemple #1
0
        /// <summary>
        /// Reevaluates the items that can be added to a kerbal's inventory.
        /// </summary>
        internal void RefreshItems()
        {
            if (!WalkAboutKspAccess.IsKisModDetected())
            {
                return;
            }
            $"KIS detected - refreshing".Debug();

            if (Count == 0)
            {
                LoadItemsFromFile();
            }

            $"examining {PartLoader.LoadedPartsList.Count} parts from PartLoader".Debug();
            foreach (var part in PartLoader.LoadedPartsList)
            {
                var volume = CalculatePartVolume(part.partPrefab);
                if (volume == 0.0f)
                {
                    volume = EstimatePartVolume(part.partPrefab);
                }

                if (volume <= HighLogic.CurrentGame.Parameters.CustomParams <WA>().MaxInventoryVolume)
                {
                    var tech = AssetBase.RnDTechTree.FindTech(part.TechRequired);
                    if (tech == null)
                    {
                        $"unable to find tech for {part.name}".Debug();
                        continue;
                    }

                    var available = GetPartAvailability(part);

                    $"info for part {part.name}: cost={part.cost} volume={volume} title={part.title} required tech={(part?.TechRequired) ?? "null"} available={available}".Debug();

                    if (ContainsKey(part.name))
                    {
                        this[part.name].Title       = part.title;
                        this[part.name].IsAvailable = available;
                        this[part.name].Volume      = volume;
                        this[part.name].Cost        = part.cost;
                        _maxQueueing = Math.Max(_maxQueueing, this[part.name].Queueing);
                    }
                    else
                    {
                        Add(part.name, new InventoryItem()
                        {
                            Name        = part.name,
                            Title       = part.title,
                            IsAvailable = available,
                            Volume      = volume,
                            Cost        = part.cost,
                            Queueing    = 0,
                        });
                    }
                }
            }

            SortItems();
        }
Exemple #2
0
        /// <summary>Initializes a new instance of the MainGui class.</summary>
        internal PlaceKerbalGui()
        {
            _kerbalSelectorScrollPosition   = Vector2.zero;
            _facilitySelectorScrollPosition = Vector2.zero;
            _locationSelectorScrollPosition = Vector2.zero;
            _itemsSelectorScrollPosition    = Vector2.zero;
            _itemsSelectedScrollPosition    = Vector2.zero;

            _isKisPresent  = WalkAboutKspAccess.TryGetKisMod(ref _KisMod);
            _itemsSelected = new Dictionary <string, List <InventoryItem> >();

            _windowTitle        = $"{Constants.ModName} v{Constants.Version}";
            _minGuiSize         = new Vector2(200, 50);
            _itemSelectorIsOpen = false;

            IsActive = false;
        }
        /// <summary>Detects if the scene is for a kerbal on EVA and adds any outstanding inventory items.</summary>
        public void Start()
        {
            var kerbalEva = GetKerbalEva();

            if (kerbalEva == null)
            {
                "WalkAboutEva deactivated: not a valid Kerbal EVA".Debug();
                return;
            }

            SetPerpetualMotionKeyCombo();
            _currentMotion = new MotionSettings()
            {
                State     = MotionState.normal,
                IsRunning = false,
            };

            var kerbalPcm = FlightGlobals.ActiveVessel.GetVesselCrew()[0];

            $"Flight scene started for {kerbalPcm.name}".Debug();

            System.Reflection.Assembly KisMod = null;
            if (!WalkAboutKspAccess.TryGetKisMod(ref KisMod))
            {
                $"KIS not installed".Debug();
                return;
            }
            $"obtained KIS mod assembly [{KisMod}]".Debug();

            if (WalkAboutPersistent.AllocatedItems.ContainsKey(kerbalPcm.name))
            {
                AddInventoryItems(kerbalPcm); //, KisMod);
            }
            else
            {
                $"{kerbalPcm.name} has no items to add to inventory".Debug();
            }
        }
        /// <summary>
        /// Called each time the game's GUIs are to be refreshed.
        /// </summary>
        public void OnGUI()
        {
            if (_mainGui?.Display() ?? false)
            {
                _config.SetScreenPosition(_mainGui.GuiCoordinates);
            }

            if (_mainGui?.RequestedPlacement == null)
            {
                return;
            }

            "placing kerbal".Debug();
            WalkAboutKspAccess.PlaceKerbal(_mainGui.RequestedPlacement);
            "Saving game".Log();
            GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE);

            PerformPostPlacementAction();

            _items.UpdateQueueing(_mainGui.RequestedPlacement.Items);
            _map.UpdateQueuing(_mainGui.RequestedPlacement.Location.LocationName);
            _mainGui.RequestedPlacement = null;
        }