示例#1
0
 void DrawMouseOverItem(WorkshopItem mouseOverItem, W_KIS_Item mouseOverItemKIS)
 {
     // Tooltip
     adjustedProductivity = WorkshopUtils.GetProductivityBonus(part, ExperienceEffect, SpecialistEfficiencyFactor, ProductivityFactor, WorkshopUtils.ProductivityType.recycler);
     if (mouseOverItem != null)
     {
         var blueprint = WorkshopRecipeDatabase.ProcessPart(mouseOverItem.Part);
         foreach (var resource in blueprint)
         {
             resource.Units *= ConversionRate;
         }
         GUI.Box(new Rect(200, 80, 100, 100), mouseOverItem.Icon.texture);
         GUI.Box(new Rect(310, 80, 150, 100), WorkshopUtils.GetKisStats(mouseOverItem.Part), UI.UIStyles.StatsStyle);
         GUI.Box(new Rect(470, 80, 150, 100), blueprint.Print(WorkshopUtils.ProductivityType.recycler, adjustedProductivity), UI.UIStyles.StatsStyle);
         GUI.Box(new Rect(200, 190, 420, 25), mouseOverItem.Part.title, UI.UIStyles.TitleDescriptionStyle);
         GUI.Box(new Rect(200, 220, 420, 110), mouseOverItem.Part.description, UI.UIStyles.TooltipDescriptionStyle);
     }
     else if (mouseOverItemKIS != null)
     {
         var blueprint = WorkshopRecipeDatabase.ProcessPart(mouseOverItemKIS.availablePart);
         foreach (var resource in blueprint)
         {
             resource.Units *= ConversionRate;
         }
         GUI.Box(new Rect(200, 80, 100, 100), mouseOverItemKIS.Icon.texture);
         GUI.Box(new Rect(310, 80, 150, 100), WorkshopUtils.GetKisStats(mouseOverItemKIS.availablePart), UI.UIStyles.StatsStyle);
         GUI.Box(new Rect(470, 80, 150, 100), blueprint.Print(WorkshopUtils.ProductivityType.recycler, adjustedProductivity), UI.UIStyles.StatsStyle);
         GUI.Box(new Rect(200, 190, 420, 25), mouseOverItemKIS.availablePart.title, UI.UIStyles.TitleDescriptionStyle);
         GUI.Box(new Rect(200, 220, 420, 110), mouseOverItemKIS.availablePart.description, UI.UIStyles.TooltipDescriptionStyle);
     }
 }
示例#2
0
 public void ContextMenuOpenRecycler()
 {
     if (_showGui)
     {
         foreach (var inventory in KISWrapper.GetInventories(vessel).Where(i => i.showGui == false).ToList())
         {
             foreach (var item in inventory.items)
             {
                 item.Value.DisableIcon();
             }
             foreach (var item in _queue)
             {
                 item.DisableIcon();
             }
             if (_processedItem != null)
             {
                 _processedItem.DisableIcon();
             }
         }
         _showGui = false;
     }
     else
     {
         if (!WorkshopUtils.PreLaunch())
         {
             _showGui = true;
         }
         else
         {
             ScreenMessages.PostScreenMessage("Recycler is in travel mode, unable to print at this time", 5, ScreenMessageStyle.UPPER_CENTER);
         }
     }
 }
示例#3
0
 private void UpdateProductivity()
 {
     if (_processedItem != null && UseSpecializationBonus)
     {
         adjustedProductivity = WorkshopUtils.GetProductivityBonus(part, ExperienceEffect, SpecialistEfficiencyFactor, ProductivityFactor);
     }
 }
示例#4
0
 private void SetupAnimations()
 {
     if (Animate)
     {
         foreach (var animator in part.FindModelAnimators("workshop_emissive"))
         {
             _heatAnimation = animator["workshop_emissive"];
             if (_heatAnimation != null)
             {
                 _heatAnimation.speed    = 0;
                 _heatAnimation.enabled  = true;
                 _heatAnimation.wrapMode = WrapMode.ClampForever;
                 animator.Blend("workshop_emissive");
                 break;
             }
             WorkshopUtils.LogError("Unable to load workshop_emissive animation");
         }
         foreach (var animator in part.FindModelAnimators(WorkAnimationName))
         {
             _workAnimation = animator[WorkAnimationName];
             if (_workAnimation != null)
             {
                 _workAnimation.speed    = 0;
                 _workAnimation.enabled  = true;
                 _workAnimation.wrapMode = WrapMode.ClampForever;
                 animator.Blend(WorkAnimationName);
                 break;
             }
             WorkshopUtils.LogError("Unable to load work animation");
         }
     }
 }
示例#5
0
        private void LoadAvailableParts()
        {
            WorkshopUtils.LogVerbose(PartLoader.LoadedPartsList.Count + " loaded parts");
            WorkshopUtils.LogVerbose(PartLoader.LoadedPartsList.Count(WorkshopUtils.PartResearched) + " unlocked parts");

            var items = new List <WorkshopItem>();

            foreach (var loadedPart in PartLoader.LoadedPartsList.Where(p => p.name != "flag" && !p.name.StartsWith("kerbalEVA")))
            {
                try
                {
                    if (IsValid(loadedPart))
                    {
                        items.Add(new WorkshopItem(loadedPart));
                    }
                }
                catch (Exception ex)
                {
                    WorkshopUtils.LogError("Part " + loadedPart.name + " could not be added to available parts list", ex);
                }
            }
            _availableItems = items.OrderBy(i => i.Part.title).ToArray();
            if (string.IsNullOrEmpty(_searchFilter.FilterText))
            {
                _filteredItems = _filters[_activeFilterId].Filter(_availableItems, 0);
            }
            else
            {
                _filteredItems = _searchFilter.Filter(_availableItems, 0);
            }
        }
示例#6
0
        private void LoadFilters()
        {
            var filters = new List <FilterBase>();

            filters.Add(new FilterModule("ModuleKISItem"));
            filters.Add(new FilterCategory(PartCategories.none));

            var filterTextures = new List <Texture>();

            filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/R&D_node_icon_evatech"));
            filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/R&D_node_icon_robotics"));

            var categoryFilterAddOns = vessel.FindPartModulesImplementing <OseModuleCategoryAddon>();

            if (categoryFilterAddOns != null)
            {
                foreach (var addon in categoryFilterAddOns.Distinct(new OseModuleCategoryAddonEqualityComparer()).ToArray())
                {
                    Debug.Log("[OSE] - Found addon for category: " + addon.Category);
                    filters.Add(new FilterCategory(addon.Category));
                    filterTextures.Add(WorkshopUtils.LoadTexture(addon.IconPath));
                }
            }

            _filters        = filters.ToArray();
            _filterTextures = filterTextures.ToArray();
        }
示例#7
0
        public double GetDeltaTime()
        {
            try
            {
                if (Time.timeSinceLevelLoad < 1.0f || !FlightGlobals.ready)
                {
                    return(0);
                }

                if (Math.Abs(_lastUpdateTime) < 0.000000001d)
                {
                    // Just started running
                    _lastUpdateTime = Planetarium.GetUniversalTime();
                    return(0);
                }

                var deltaTime = Math.Min(Planetarium.GetUniversalTime() - _lastUpdateTime, 86400);
                _lastUpdateTime += deltaTime;
                return(deltaTime);
            }
            catch (Exception e)
            {
                WorkshopUtils.LogError("OseClock_GetDeltaTime - ", e);
                return(0);
            }
        }
示例#8
0
 void DrawMouseOverItem(WorkshopItem mouseOverItem, KIS_Item mouseOverItemKIS)
 {
     // Tooltip
     GUI.Box(new Rect(190, 70, 440, 270), "");
     if (mouseOverItem != null)
     {
         var blueprint = WorkshopRecipeDatabase.ProcessPart(mouseOverItem.Part);
         foreach (var resource in blueprint)
         {
             resource.Units *= ConversionRate;
         }
         GUI.Box(new Rect(200, 80, 100, 100), mouseOverItem.Icon.texture);
         GUI.Box(new Rect(310, 80, 150, 100), WorkshopUtils.GetKisStats(mouseOverItem.Part), UI.UIStyles.StatsStyle);
         GUI.Box(new Rect(470, 80, 150, 100), blueprint.Print(adjustedProductivity), UI.UIStyles.StatsStyle);
         GUI.Box(new Rect(200, 190, 420, 25), mouseOverItem.Part.title, UI.UIStyles.TitleDescriptionStyle);
         GUI.Box(new Rect(200, 220, 420, 110), mouseOverItem.Part.description, UI.UIStyles.TooltipDescriptionStyle);
     }
     else if (mouseOverItemKIS != null)
     {
         var blueprint = WorkshopRecipeDatabase.ProcessPart(mouseOverItemKIS.availablePart);
         foreach (var resource in blueprint)
         {
             resource.Units *= ConversionRate;
         }
         GUI.Box(new Rect(200, 80, 100, 100), mouseOverItemKIS.Icon.texture);
         GUI.Box(new Rect(310, 80, 150, 100), WorkshopUtils.GetKisStats(mouseOverItemKIS.availablePart), UI.UIStyles.StatsStyle);
         GUI.Box(new Rect(470, 80, 150, 100), blueprint.Print(adjustedProductivity), UI.UIStyles.StatsStyle);
         GUI.Box(new Rect(200, 190, 420, 25), mouseOverItemKIS.availablePart.title, UI.UIStyles.TitleDescriptionStyle);
         GUI.Box(new Rect(200, 220, 420, 110), mouseOverItemKIS.availablePart.description, UI.UIStyles.TooltipDescriptionStyle);
     }
 }
示例#9
0
 public OseModuleWorkshop()
 {
     _queue        = new WorkshopQueue();
     _pauseTexture = WorkshopUtils.LoadTexture("Workshop/Assets/Icons/icon_pause");
     _playTexture  = WorkshopUtils.LoadTexture("Workshop/Assets/Icons/icon_play");
     _binTexture   = WorkshopUtils.LoadTexture("Workshop/Assets/Icons/icon_bin");
 }
示例#10
0
 public OseModuleRecycler()
 {
     _queue = new WorkshopQueue();
     //_broker = new ResourceBroker();
     _pauseTexture = WorkshopUtils.LoadTexture("Workshop/Assets/Icons/icon_pause");
     _playTexture  = WorkshopUtils.LoadTexture("Workshop/Assets/Icons/icon_play");
     _binTexture   = WorkshopUtils.LoadTexture("Workshop/Assets/Icons/icon_bin");
 }
示例#11
0
 public void DisableIcon()
 {
     WorkshopUtils.LogVerbose("DisableIcon for " + Part.name);
     if (Icon != null)
     {
         Icon.Dispose();
         Icon = null;
     }
 }
示例#12
0
 private void UpdateProductivity()
 {
     if (_processedItem != null && UseSpecializationBonus)
     {
         adjustedProductivity = WorkshopUtils.GetProductivityBonus(this.part, ExperienceEffect, SpecialistEfficiencyFactor, ProductivityFactor, WorkshopUtils.ProductivityType.printer);
     }
     if (_processedItem != null && wdc != null && HighLogic.CurrentGame.Parameters.CustomParams <Workshop_Settings>().unpackedAccelCausesDamage)
     {
         adjustedProductivity /= (float)wdc.CurDamageImpact;
     }
 }
示例#13
0
        private void SubCategories()
        {
            var icon   = PartCategorizer.Instance.iconLoader.GetIcon(IconName);
            var filter = PartCategorizer.Instance.filters.Find(f => f.button.categorydisplayName == CategoryButtonLocalizationId);

            if (filter == null)
            {
                WorkshopUtils.LogError($"Cannot find 'Filter by function' button for category: {SubCategoryTitle}");
                return;
            }
            PartCategorizer.AddCustomSubcategoryFilter(filter, SubCategoryTitle, SubCategoryTitle, icon, p => AvPartItems.Contains(p.name));
        }
        private IEnumerator LoadCustomItems()
        {
            var nodes = GameDatabase.Instance.GetConfigNodes("OSE_Blacklist");

            foreach (var configNode in nodes)
            {
                var items = configNode.GetValue("parts").Split(';');
                WorkshopUtils.LogVerbose("found blacklist items: " + String.Join(" - ", items));
                WorkshopBlacklistItemsDatabase.Blacklist.AddRange(items.Select(i => i.Replace('_', '.')));
                yield return(null);
            }
            Done = true;
        }
示例#15
0
 public override void OnAwake()
 {
     base.OnAwake();
     try
     {
         IsKISAvailable = KISWrapper.Initialize();
     }
     catch (Exception ex)
     {
         IsKISAvailable = false;
         WorkshopUtils.LogError("Error while checking for KIS. Workshop will be disabled", ex);
     }
 }
示例#16
0
 private void DrawMouseOverItem(WorkshopItem mouseOverItem)
 {
     GUI.Box(new Rect(190, 70, 440, 270), "");
     if (mouseOverItem != null)
     {
         var blueprint = WorkshopRecipeDatabase.ProcessPart(mouseOverItem.Part);
         GUI.Box(new Rect(200, 80, 100, 100), mouseOverItem.Icon.texture);
         GUI.Box(new Rect(310, 80, 150, 100), WorkshopUtils.GetKisStats(mouseOverItem.Part), UI.UIStyles.StatsStyle);
         GUI.Box(new Rect(470, 80, 150, 100), blueprint.Print(adjustedProductivity), UI.UIStyles.StatsStyle);
         GUI.Box(new Rect(200, 190, 420, 25), mouseOverItem.Part.title, UI.UIStyles.TitleDescriptionStyle);
         GUI.Box(new Rect(200, 220, 420, 110), mouseOverItem.Part.description, UI.UIStyles.TooltipDescriptionStyle);
     }
 }
示例#17
0
        public override void OnStart(StartState state)
        {
            if (HighLogic.LoadedSceneIsFlight && WorkshopSettings.IsKISAvailable)
            {
                WorkshopUtils.Log("KIS is available - Initialize Workshop");
                SetupAnimations();
                LoadMaxVolume();
                LoadFilters();
                GameEvents.onVesselChange.Add(OnVesselChange);
            }

            base.OnStart(state);
        }
示例#18
0
 public override void OnUpdate()
 {
     try
     {
         UpdateProductivity();
         ApplyPaging();
         ProcessItem();
     }
     catch (Exception ex)
     {
         WorkshopUtils.LogError("OseModuleWorkshop_OnUpdate", ex);
     }
     base.OnUpdate();
 }
示例#19
0
 private void DrawMouseOverItem(WorkshopItem mouseOverItem)
 {
     GUI.Box(new Rect(190, 70, 440, 270), "");
     if (mouseOverItem != null)
     {
         adjustedProductivity = WorkshopUtils.GetProductivityBonus(this.part, ExperienceEffect, SpecialistEfficiencyFactor, ProductivityFactor, WorkshopUtils.ProductivityType.printer);
         var blueprint = WorkshopRecipeDatabase.ProcessPart(mouseOverItem.Part);
         GUI.Box(new Rect(200, 80, 100, 100), mouseOverItem.Icon.texture);
         GUI.Box(new Rect(310, 80, 150, 100), WorkshopUtils.GetKisStats(mouseOverItem.Part), UI.UIStyles.StatsStyle);
         GUI.Box(new Rect(470, 80, 150, 100), blueprint.Print(WorkshopUtils.ProductivityType.printer, adjustedProductivity), UI.UIStyles.StatsStyle);
         GUI.Box(new Rect(200, 190, 420, 25), mouseOverItem.Part.title, UI.UIStyles.TitleDescriptionStyle);
         GUI.Box(new Rect(200, 220, 420, 110), mouseOverItem.Part.description, UI.UIStyles.TooltipDescriptionStyle);
     }
 }
示例#20
0
        public void FixedUpdate()
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }
            try
            {
                UpdateProductivity();

                ApplyFilter();

                updateKACAlarm();

                if (lastUpdateTime == 0)
                {
                    lastUpdateTime = Planetarium.GetUniversalTime();
                    ProcessItem(TimeWarp.deltaTime);
                    return;
                }

                //Get elapsed time
                double elapsedTime = Planetarium.GetUniversalTime() - lastUpdateTime;

                //Update last update time
                lastUpdateTime = Planetarium.GetUniversalTime();

                //If our elapsed time is > the background process interval, then we'll need to do some multiple processings.
                double timeRemaining = 0;
                while (elapsedTime > kBackgroundProcessInterval)
                {
                    timeRemaining = ProcessItem(kBackgroundProcessInterval);
                    elapsedTime  += timeRemaining;
                    elapsedTime  -= kBackgroundProcessInterval;
                }

                //Process the remaining delta time
                if (elapsedTime > 0f)
                {
                    ProcessItem(elapsedTime);
                }
            }
            catch (Exception ex)
            {
                WorkshopUtils.LogError("OseModuleWorkshop_OnUpdate", ex);
            }
        }
示例#21
0
        public override void OnStart(StartState state)
        {
            //Init the KAC Wrapper. KAC Wrapper courtey of TriggerAu
            KACWrapper.InitKACWrapper();
            if (KACWrapper.APIReady)
            {
                KACWrapper.KAC.onAlarmStateChanged += KAC_onAlarmStateChanged;
            }

            if (HighLogic.LoadedSceneIsFlight && WorkshopSettings.IsKISAvailable)
            {
                WorkshopUtils.Log("KIS is available - Initialize Workshop");
                SetupAnimations();
                LoadMaxVolume();
                LoadFilters();
                if (lastUpdateTime == 0)
                {
                    lastUpdateTime = Planetarium.GetUniversalTime();
                }
                GameEvents.onVesselChange.Add(OnVesselChange);
            }

            foreach (PartModule p in this.part.Modules)
            {
                if (p.moduleName == "WorkshopAnimateGeneric")
                {
                    wag = p as WorkshopAnimateGeneric;
                }
                if (p.moduleName == "WorkshopDamageController")
                {
                    wdc = p as WorkshopDamageController;
                }
            }
            if (wag != null && wag.packed)
            {
                Status = "Packed";
            }

            //this.part.GetComponent<WorkshopAnimateGeneric>()

            base.OnStart(state);
        }
示例#22
0
        private void LoadFilters()
        {
            var filters        = new List <FilterBase>();
            var filterTextures = new List <Texture>();

            var categoryFilterAddOns = vessel.FindPartModulesImplementing <OseModuleCategoryAddon>();

            if (categoryFilterAddOns != null)
            {
                foreach (var addon in categoryFilterAddOns.Distinct(new OseModuleCategoryAddonEqualityComparer()).ToArray())
                {
                    Debug.Log("[OSE] - Found addon for category: " + addon.Category);
                    filters.Add(new FilterCategory(addon.Category));
                    filterTextures.Add(WorkshopUtils.LoadTexture(addon.IconPath));
                }
            }

            _filters        = filters.ToArray();
            _filterTextures = filterTextures.ToArray();
        }
示例#23
0
 private void LoadMaxVolume()
 {
     try
     {
         var inventories = KISWrapper.GetInventories(vessel);
         if (inventories.Count == 0)
         {
             WorkshopUtils.LogError("No Inventories found on this vessel!");
         }
         else
         {
             WorkshopUtils.Log(inventories.Count + " inventories found on this vessel!");
             _maxVolume = inventories.Max(i => i.maxVolume);
         }
     }
     catch (Exception ex)
     {
         WorkshopUtils.LogError("Error while determing maximum volume of available inventories!", ex);
     }
     WorkshopUtils.Log($"Max volume is: {_maxVolume} liters");
 }
示例#24
0
        public override void OnStart(StartState state)
        {
            //Init the KAC Wrapper. KAC Wrapper courtey of TriggerAu
            KACWrapper.InitKACWrapper();
            if (KACWrapper.APIReady)
            {
                KACWrapper.KAC.onAlarmStateChanged += KAC_onAlarmStateChanged;
            }

            if (HighLogic.LoadedSceneIsFlight && WorkshopSettings.IsKISAvailable)
            {
                WorkshopUtils.Log("KIS is available - Initialize Workshop");
                SetupAnimations();
                LoadMaxVolume();
                LoadFilters();
                if (lastUpdateTime == 0)
                {
                    lastUpdateTime = Planetarium.GetUniversalTime();
                }
                GameEvents.onVesselChange.Add(OnVesselChange);
            }

            base.OnStart(state);
        }
示例#25
0
        private ModuleKISInventory AddToContainer(WorkshopItem item)
        {
            var inventories = KISWrapper.GetInventories(vessel);

            if (inventories == null || inventories.Count == 0)
            {
                throw new Exception("No KIS Inventory found!");
            }

            var freeInventories = inventories
                                  .Where(i => WorkshopUtils.HasFreeSpace(i, item))
                                  .Where(WorkshopUtils.HasFreeSlot)
                                  .Where(WorkshopUtils.IsOccupied)
                                  .ToArray();

            if (freeInventories.Any())
            {
                // first pass with favored inventories
                var favoredInventories = freeInventories
                                         .Where(i => i.part.GetComponent <OseModuleInventoryPreference>() != null)
                                         .Where(i => i.part.GetComponent <OseModuleInventoryPreference>().IsFavored).ToArray();

                foreach (var inventory in favoredInventories)
                {
                    var kisItem = inventory.AddItem(item.Part.partPrefab);
                    if (kisItem == null)
                    {
                        throw new Exception("Error adding item " + item.Part.name + " to inventory");
                    }
                    foreach (var resourceInfo in kisItem.GetResources())
                    {
                        if (WorkshopRecipeDatabase.HasResourceRecipe(resourceInfo.resourceName))
                        {
                            kisItem.SetResource(resourceInfo.resourceName, (int)resourceInfo.maxAmount);
                        }
                        else
                        {
                            kisItem.SetResource(resourceInfo.resourceName, 0);
                        }
                    }
                    return(inventory);
                }

                // second pass with the rest
                foreach (var inventory in freeInventories)
                {
                    var kisItem = inventory.AddItem(item.Part.partPrefab);
                    if (kisItem == null)
                    {
                        throw new Exception("Error adding item " + item.Part.name + " to inventory");
                    }
                    foreach (var resourceInfo in kisItem.GetResources())
                    {
                        if (WorkshopRecipeDatabase.HasResourceRecipe(resourceInfo.resourceName))
                        {
                            kisItem.SetResource(resourceInfo.resourceName, (int)resourceInfo.maxAmount);
                        }
                        else
                        {
                            kisItem.SetResource(resourceInfo.resourceName, 0);
                        }
                    }
                    return(inventory);
                }
            }
            return(null);
        }
示例#26
0
        public void FixedUpdate()
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }

            maxGeeForce = Math.Max(maxGeeForce, FlightGlobals.ActiveVessel.geeForce);

            if (_showGui)
            {
                Events["ContextMenuOpenWorkbench"].guiName = "Close OSE Workbench";
            }
            else
            {
                Events["ContextMenuOpenWorkbench"].guiName = "Open OSE Workbench";
            }


            if (HighLogic.CurrentGame.Parameters.CustomParams <Workshop_Settings>().requireUnpacking || WorkshopUtils.PreLaunch())
            {
                if (wag != null)
                {
                    if (!wag.packed && !wag.Packing)
                    {
                        Events["ContextMenuOpenWorkbench"].guiActive = true; // (_processedItem == null);
                    }
                    else
                    {
                        Events["ContextMenuOpenWorkbench"].guiActive = false;
                    }
                }
            }

            if (wag != null)
            {
                wag.Busy = (_processedItem != null);
            }

            if (wag != null && wag.packed)
            {
                Status = "Packed";
            }
            else
            {
                Status = "Online";
            }

            try
            {
                UpdateProductivity();

                ApplyFilter();
                if (HighLogic.CurrentGame.Parameters.CustomParams <Workshop_Settings>().setPrintKAC)
                {
                    updateKACAlarm();
                }

                if (lastUpdateTime == 0)
                {
                    lastUpdateTime = Planetarium.GetUniversalTime();
                    ProcessItem(TimeWarp.deltaTime);
                    return;
                }

                //Get elapsed time
                double elapsedTime = Planetarium.GetUniversalTime() - lastUpdateTime;

                //Update last update time
                lastUpdateTime = Planetarium.GetUniversalTime();


                //If our elapsed time is > the background process interval, then we'll need to do some multiple processings.
                double timeRemaining = 0;
                while (elapsedTime > 0.1f) //kBackgroundProcessInterval)
                {
                    timeRemaining = ProcessItem(elapsedTime);

                    if (_processedItem == null)
                    {
                        return;
                    }
                    if (elapsedTime == timeRemaining)
                    {
                        break;
                    }
                    elapsedTime = timeRemaining;
                    //elapsedTime -= kBackgroundProcessInterval;
                }

                //Process the remaining delta time
                if (elapsedTime > 0f)
                {
                    ProcessItem(elapsedTime);
                }
            }
            catch (Exception ex)
            {
                WorkshopUtils.LogError("OseModuleWorkshop_OnUpdate", ex);
            }
        }
示例#27
0
 private bool IsValid(AvailablePart loadedPart)
 {
     return(WorkshopUtils.PartResearched(loadedPart) && WorkshopUtils.GetPackedPartVolume(loadedPart) <= _maxVolume && !WorkshopBlacklistItemsDatabase.Blacklist.Contains(loadedPart.name));
 }
示例#28
0
        private void LoadFilters()
        {
            var filters        = new List <FilterBase>();
            var filterTextures = new List <Texture>();

            if (this.part.partInfo.partConfig == null)
            {
                return;
            }
            ConfigNode[]   nodes        = this.part.partInfo.partConfig.GetNodes("MODULE");
            ConfigNode     node         = null;
            ConfigNode     workshopNode = null;
            PartCategories category;

            //Get the nodes we're interested in
            for (int index = 0; index < nodes.Length; index++)
            {
                node = nodes[index];
                if (node.HasValue("name"))
                {
                    moduleName = node.GetValue("name");
                    if (moduleName == this.ClassName)
                    {
                        workshopNode = node;
                        break;
                    }
                }
            }
            if (workshopNode == null)
            {
                return;
            }

            //Each category represets one of the tab buttons from the KSP editor.
            //Mods have the ability to specify which categories that the workshop can produce.
            //If there are no CATEGORY nodes specified then the defaults are used instead.
            nodes = workshopNode.GetNodes("CATEGORY");

            //If we have no category nodes then just load the defaults.
            if (nodes.Length == 0)
            {
                //Pods
                filters.Add(new FilterCategory(PartCategories.Pods));
                filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/RDicon_commandmodules"));

                //FuelTank
                filters.Add(new FilterCategory(PartCategories.FuelTank));
                filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/RDicon_fuelSystems-advanced"));

                //Engine
                filters.Add(new FilterCategory(PartCategories.Engine));
                filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/RDicon_propulsionSystems"));

                //Control
                filters.Add(new FilterCategory(PartCategories.Control));
                filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/R&D_node_icon_largecontrol"));

                //Structural
                filters.Add(new FilterCategory(PartCategories.Structural));
                filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/R&D_node_icon_generalconstruction"));

                //Aero
                filters.Add(new FilterCategory(PartCategories.Aero));
                filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/R&D_node_icon_advaerodynamics"));

                //Utility
                filters.Add(new FilterCategory(PartCategories.Utility));
                filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/R&D_node_icon_generic"));

                //Electrical
                filters.Add(new FilterCategory(PartCategories.Electrical));
                filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/R&D_node_icon_electrics"));

                //Ground
                filters.Add(new FilterCategory(PartCategories.Ground));
                filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/R&D_node_icon_advancedmotors"));

                //Payload
                filters.Add(new FilterCategory(PartCategories.Payload));
                filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/R&D_node_icon_composites"));

                //Communications
                filters.Add(new FilterCategory(PartCategories.Communication));
                filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/R&D_node_icon_advunmanned"));

                //Coupling
                filters.Add(new FilterCategory(PartCategories.Coupling));
                filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/cs_size3"));

                //Thermal
                filters.Add(new FilterCategory(PartCategories.Thermal));
                filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/fuels_monopropellant"));

                //Science
                filters.Add(new FilterCategory(PartCategories.Science));
                filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/R&D_node_icon_advsciencetech"));

                if (HighLogic.CurrentGame.Parameters.CustomParams <Workshop_MiscSettings>().showMiscCategory)
                {
                    //Misc (catchall for parts not in other categories)
                    filters.Add(new FilterCategory(PartCategories.none));
                    filterTextures.Add(WorkshopUtils.LoadTexture("Workshop/Assets/Icons/Misc"));
                }
            }

            else //Load all the specified CATEGORY nodes.
            {
                //Load the categories
                for (int index = 0; index < nodes.Length; index++)
                {
                    node = nodes[index];
                    if (!node.HasValue("name") && !node.HasValue("iconPath"))
                    {
                        continue;
                    }

                    try
                    {
                        category = (PartCategories)Enum.Parse(typeof(PartCategories), node.GetValue("name"));
                        filters.Add(new FilterCategory(category));
                        filterTextures.Add(WorkshopUtils.LoadTexture(node.GetValue("iconPath")));
                    }
                    catch (Exception ex)
                    {
                        WorkshopUtils.LogError("Error during LoadFilters: " + ex.ToString());
                        continue;
                    }
                }
            }

            _filters        = filters.ToArray();
            _filterTextures = filterTextures.ToArray();
            _searchFilter   = new FilterSearch();
        }
示例#29
0
        private void DrawWindowContents(int windowId)
        {
            WorkshopItem mouseOverItem = null;

            // styles
            var statsStyle = new GUIStyle(GUI.skin.box);

            statsStyle.fontSize     = 11;
            statsStyle.alignment    = TextAnchor.UpperLeft;
            statsStyle.padding.left = statsStyle.padding.top = 5;

            var tooltipDescriptionStyle = new GUIStyle(GUI.skin.box);

            tooltipDescriptionStyle.fontSize    = 11;
            tooltipDescriptionStyle.alignment   = TextAnchor.UpperCenter;
            tooltipDescriptionStyle.padding.top = 5;

            var queueSkin = new GUIStyle(GUI.skin.box);

            queueSkin.alignment   = TextAnchor.UpperCenter;
            queueSkin.padding.top = 5;

            // Filters
            _selectedFilterId = GUI.Toolbar(new Rect(15, 35, 615, 30), _selectedFilterId, _filterTextures);

            // Available Items
            const int itemRows    = 10;
            const int itemColumns = 3;

            for (var y = 0; y < itemRows; y++)
            {
                for (var x = 0; x < itemColumns; x++)
                {
                    var left      = 15 + x * 55;
                    var top       = 70 + y * 55;
                    var itemIndex = y * itemColumns + x;
                    if (_filteredItems.Items.Length > itemIndex)
                    {
                        var item = _filteredItems.Items[itemIndex];
                        if (item.Icon == null)
                        {
                            item.EnableIcon(64);
                        }
                        if (GUI.Button(new Rect(left, top, 50, 50), item.Icon.texture))
                        {
                            _queue.Add(new WorkshopItem(item.Part));
                        }
                        if (Event.current.type == EventType.Repaint && new Rect(left, top, 50, 50).Contains(Event.current.mousePosition))
                        {
                            mouseOverItem = item;
                        }
                    }
                }
            }

            if (_activePage > 0)
            {
                if (GUI.Button(new Rect(15, 645, 75, 25), "Prev"))
                {
                    _selectedPage = _activePage - 1;
                }
            }

            if (_activePage < _filteredItems.MaxPages)
            {
                if (GUI.Button(new Rect(100, 645, 75, 25), "Next"))
                {
                    _selectedPage = _activePage + 1;
                }
            }

            // Queued Items
            const int queueRows    = 4;
            const int queueColumns = 7;

            GUI.Box(new Rect(190, 345, 440, 270), "Queue", queueSkin);
            for (var y = 0; y < queueRows; y++)
            {
                for (var x = 0; x < queueColumns; x++)
                {
                    var left      = 205 + x * 60;
                    var top       = 370 + y * 60;
                    var itemIndex = y * queueColumns + x;
                    if (_queue.Count > itemIndex)
                    {
                        var item = _queue[itemIndex];
                        if (item.Icon == null)
                        {
                            item.EnableIcon(64);
                        }
                        if (GUI.Button(new Rect(left, top, 50, 50), item.Icon.texture))
                        {
                            _queue.Remove(item);
                        }
                        if (Event.current.type == EventType.Repaint && new Rect(left, top, 50, 50).Contains(Event.current.mousePosition))
                        {
                            mouseOverItem = item;
                        }
                    }
                }
            }

            // Tooltip
            GUI.Box(new Rect(190, 70, 440, 270), "");
            if (mouseOverItem != null)
            {
                var blueprint = WorkshopRecipeDatabase.ProcessPart(mouseOverItem.Part);
                GUI.Box(new Rect(200, 80, 100, 100), mouseOverItem.Icon.texture);
                GUI.Box(new Rect(310, 80, 150, 100), WorkshopUtils.GetKisStats(mouseOverItem.Part), statsStyle);
                GUI.Box(new Rect(470, 80, 150, 100), blueprint.Print(adjustedProductivity), statsStyle);
                GUI.Box(new Rect(200, 190, 420, 140), WorkshopUtils.GetDescription(mouseOverItem.Part), tooltipDescriptionStyle);
            }

            // Currently build item
            if (_processedItem != null)
            {
                if (_processedItem.Icon == null)
                {
                    _processedItem.EnableIcon(64);
                }
                GUI.Box(new Rect(190, 620, 50, 50), _processedItem.Icon.texture);
            }
            else
            {
                GUI.Box(new Rect(190, 620, 50, 50), "");
            }

            // Progressbar
            GUI.Box(new Rect(250, 620, 280, 50), "");
            if (progress >= 1)
            {
                var color = GUI.color;
                GUI.color = new Color(0, 1, 0, 1);
                GUI.Box(new Rect(250, 620, 280 * progress / 100, 50), "");
                GUI.color = color;
            }
            GUI.Label(new Rect(250, 620, 280, 50), " " + progress.ToString("0.0") + " / 100");

            //Pause/resume production
            Texture2D buttonTexture = _pauseTexture;

            if (manufacturingPaused || _processedItem == null)
            {
                buttonTexture = _playTexture;
            }
            if (GUI.Button(new Rect(530, 620, 50, 50), buttonTexture) && _processedItem != null)
            {
                manufacturingPaused = !manufacturingPaused;
            }

            //Cancel production
            if (GUI.Button(new Rect(580, 620, 50, 50), _binTexture))
            {
                if (_confirmDelete)
                {
                    _processedItem.DisableIcon();
                    _processedItem      = null;
                    _processedBlueprint = null;
                    progress            = 0;
                    manufacturingPaused = false;
                    Status = "Online";

                    if (Animate && _heatAnimation != null && _workAnimation != null)
                    {
                        StartCoroutine(StopAnimations());
                    }
                    _confirmDelete = false;
                }

                else
                {
                    _confirmDelete = true;
                    ScreenMessages.PostScreenMessage("Click the cancel button again to confirm cancelling current production", 5.0f, ScreenMessageStyle.UPPER_CENTER);
                }
            }

            if (GUI.Button(new Rect(_windowPos.width - 25, 5, 20, 20), "X"))
            {
                ContextMenuOpenWorkbench();
            }

            GUI.DragWindow();
        }
示例#30
0
 public void EnableIcon(int resultion)
 {
     WorkshopUtils.LogVerbose("EnableIcon for " + Part.name);
     DisableIcon();
     Icon = new KIS_IconViewer(Part.partPrefab, resultion);
 }