Beispiel #1
0
        private void UpdateBindings()
        {
            bool         flag1         = false;
            ushort       extractorID   = GetFishExtractorID();
            ushort       fishFarmID    = BuildingExtension.GetFishFarm(extractorID);
            BuildingInfo extractorInfo = BuildingManager.instance.m_buildings.m_buffer[extractorID].Info;
            BuildingInfo fishFarmInfo  = BuildingManager.instance.m_buildings.m_buffer[fishFarmID].Info;

            ItemClass.Service service = fishFarmInfo.GetService();
            BuildingExtension.FishItemClass fishfarm = new BuildingExtension.FishItemClass(service);
            if (!FishFarmUtil.IsValidFishFarm(fishFarmID))
            {
                flag1 = true;
            }
            if (flag1 || _updateFishFarms[fishfarm])
            {
                PopulateFishFarmDropDown(extractorInfo, fishFarmInfo);
                _updateFishFarms[fishfarm] = false;
            }
            if (_fishFarmDropDown.Items.Length == 0)
            {
                _fishFarmDropDown.Text = "No fish farm found.";
            }
            else
            {
                _fishFarmDropDown.SelectedItem = fishFarmID;
            }
            Vector3[] extractor_pos_arr = new Vector3[BuildingExtension._extractorData.Length];
            BuildingExtension._extractorData.ForEach <BuildingExtension.ExtractorData>(item => {
                extractor_pos_arr = extractor_pos_arr.Concat <Vector3>(new Vector3[] { item.Position }).ToArray();
            });
            m_extractionPositions = extractor_pos_arr;
        }
Beispiel #2
0
 private void PopulateFishFarmDropDown(BuildingInfo extractorInfo, BuildingInfo fishFarmInfo)
 {
     _fishFarmDropDown.ClearItems();
     if (extractorInfo == null || fishFarmInfo == null)
     {
         return;
     }
     _fishFarmDropDown.AddItems(BuildingExtension.GetFishFarms(extractorInfo, fishFarmInfo), IDToName);
 }
Beispiel #3
0
        private void OnSelectedFishFarmChanged(UIComponent component, ushort selectedItem)
        {
            ushort ExtractorId = GetFishExtractorID();

            if ((int)ExtractorId == 0)
            {
                return;
            }
            BuildingExtension.SetFishFarm(ExtractorId, selectedItem);
        }
Beispiel #4
0
        public static ushort AutoAssignExtractorFishFarm(ushort extractorID, ushort fishFarmID, out Vector3 position)
        {
            position = BuildingManager.instance.m_buildings.m_buffer[extractorID].m_position;
            ushort closestFishFarm = GetClosestFishFarm(extractorID, fishFarmID, position);

            if ((int)closestFishFarm != 0)
            {
                BuildingExtension.SetFishFarm(extractorID, closestFishFarm);
                LogHelper.Information($"auto assigned fish farm {closestFishFarm} to extractor {extractorID}");
            }
            return(closestFishFarm);
        }
Beispiel #5
0
        public static ushort GetClosestFishFarm(ushort extractorID, ushort fishFarmID, Vector3 position)
        {
            ushort result           = 0;
            var    previousDistance = float.MaxValue;
            var    instance         = Singleton <BuildingManager> .instance;
            var    extractorInfo    = Singleton <BuildingManager> .instance.m_buildings.m_buffer[extractorID].Info;
            var    fishFarmInfo     = Singleton <BuildingManager> .instance.m_buildings.m_buffer[fishFarmID].Info;
            var    fishFarmsIds     = BuildingExtension.GetFishFarms(extractorInfo, fishFarmInfo);

            foreach (var fishFarmId in fishFarmsIds)
            {
                var distance = Vector3.Distance(position, instance.m_buildings.m_buffer[fishFarmId].m_position);
                if (!(distance < (double)previousDistance))
                {
                    continue;
                }
                result           = fishFarmId;
                previousDistance = distance;
            }
            return(result);
        }
Beispiel #6
0
        private void Init()
        {
            _buildingWorldInfoPanel = GameObject.Find("(Library) BuildingWorldInfoPanel").GetComponent <BuildingWorldInfoPanel>();
            UIComponent fishExtractorPanel = _buildingWorldInfoPanel.Find("FishFarmPanel");

            _fishAmount   = BuildingExtension.GetPrivate <UILabel>((object)_buildingWorldInfoPanel, "m_incomingResources");
            _mainSubPanel = fishExtractorPanel.parent;
            UIPanel uiPanel = _mainSubPanel.AddUIComponent <UIPanel>();

            uiPanel.name   = "IshmContainer";
            uiPanel.width  = 301f;
            uiPanel.height = 166f;
            uiPanel.autoLayoutDirection = LayoutDirection.Vertical;
            uiPanel.autoLayoutStart     = LayoutStart.TopLeft;
            uiPanel.autoLayoutPadding   = new RectOffset(0, 0, 0, 5);
            uiPanel.autoLayout          = true;
            uiPanel.relativePosition    = new Vector3(10f, 224.0f);
            _ishmContainer = uiPanel;
            CreateDropDownPanel();
            BuildingExtension.OnFishFarmAdded   += OnFishFarmChanged;
            BuildingExtension.OnFishFarmRemoved += OnFishFarmChanged;
            _initialized = true;
        }
Beispiel #7
0
 private void Deinit()
 {
     BuildingExtension.Deinit();
 }