Пример #1
0
        /// <summary>
        /// Adds a new resourcebox to system
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SchemaUI_Click(object sender, System.EventArgs e)
        {
            if (Scheme.Instance.ActiveName != null)
            {
                // Create a new resourcebox 1h where the mouse pointer is
                int new_x = PointToClient(Cursor.Position).X;
                int new_y = PointToClient(Cursor.Position).Y;

                DateTime st;
                calcDateTime(new_x, new_y, out st);

                // Create the new resourcebox with calculated time and duration of 1h endtime=starttime+1h
                ResourceBox rb = new ResourceBox(st, st.AddHours(1), Scheme.Instance.ActiveName, false, false, new DateTime(0), new DateTime(0));

                Scheme.Instance.setResourceBox(rb, true);
                this.addResourcebox(rb);

                // #1.02.001 - row added
                this.Invalidate(true);
            }
            else
            {
                ErrorHandler.ShowInformation(ErrorHandler.ERR_NO_SELECTED);
            }
        }
Пример #2
0
        /// <summary>
        /// Find a old RbUI in cahce or create a new one.
        /// Revision:
        /// #1.01.001 Added param rb to solve bug SL-5
        /// </summary>
        /// <returns>Free resoucebox UI</returns>
        private ResourceBoxUI findFreeResourceBoxUI(ResourceBox rb)
        {
//			foreach ( ResourceBoxUI rbui in this.resursboxuis_.Values ) #1.02.001 - row changed
            foreach (ResourceBoxUI rbui in resursboxuis_.Values)
            {
                try
                {
                    // Use only resourceboxes that are not displayed
                    if (rbui.ResourceBox.StartTime < Scheme.Instance.SelectedWeek.DateOfFirstDayInWeek ||
                        rbui.ResourceBox.StartTime > Scheme.Instance.SelectedWeek.DateOfFirstDayInWeek.AddDays(SchemaUI.DAYS_SHOWN))
                    {
                        ((ActivePersonResource)Scheme.Instance.ActivePersonsResources[rbui.ResourceBox.Name]).RemoveObserver(rbui);
                        rbui.ResourceBox.RemoveObserver(rbui);
                        return(rbui);
                    }
                }
                catch
                {
                    // #1.01.007 - cause of SL-11?
//					return rbui; -- line removed
                }
            }
            // No cahed object found, create a new
            // # 1.01.001 Row changed
//			ResourceBoxUI newrbui = new ResourceBoxUI();
            ResourceBoxUI newrbui = new ResourceBoxUI(rb, information_);

//			this.Controls.Add(newrbui); # 1.02.001 - row removed

            return(newrbui);
        }
        void DrawDotOnRadar(ResourceBox resourceBox, float distance, Vector3 direction)
        {
            var           percentageDistance = distance / RADAR_DISTANCE;
            var           dotPosition        = direction.normalized * ((radarRectTransform.rect.width / 2) * percentageDistance);
            RectTransform dotRectTransform;

            if (radarDotsRectTransforms.TryGetValue(resourceBox, out dotRectTransform))
            {
                dotRectTransform.anchoredPosition = dotPosition;
            }

            Image dotImage;

            if (radarDotsImages.TryGetValue(resourceBox, out dotImage))
            {
                if (distance <= 3 * TERTILE_RADAR_DISTANCE && distance > 2 * TERTILE_RADAR_DISTANCE)
                {
                    dotImage.CrossFadeColor(Color.red, 0.2f, true, true);
                }
                if (distance <= 2 * TERTILE_RADAR_DISTANCE && distance > TERTILE_RADAR_DISTANCE)
                {
                    dotImage.CrossFadeColor(Color.yellow, 0.2f, true, true);
                }
                if (distance <= TERTILE_RADAR_DISTANCE)
                {
                    dotImage.CrossFadeColor(Color.green, 0.2f, true, true);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Handle properties using the "Res" domain
        /// </summary>
        /// <param name="resourceProp"></param>
        private void assignResource(string[] propKey, string propValue)
        {
            if (propKey.Length < 3)
            {
                return;
            }

            ResourceBox newBox;

            if (propKey[2] == "type")
            {
                Resources rType = findEnumValue <Resources>(propValue);
                newBox = new ResourceBox(rType);
            }
            else if (_eventResources.ContainsKey(propKey[1]))
            {
                newBox = _eventResources[propKey[1]];
                try
                {
                    int volumeValue = Int32.Parse(propValue);
                    newBox.IncreaseQuantity(volumeValue);
                }
                catch
                {
                    throw new Exception("Invalid property value");
                }
            }
        }
Пример #5
0
 void OnBoxDrilled(ResourceBox box)
 {
     box.OnBoxDrilled -= OnBoxDrilled;
     gameManager.ResourceBoxCollected(box);
     resourceBoxFactory.Despawn(box);
     ResourceBoxes.Remove(box);
     OnBoxCollected?.Invoke(box);
 }
Пример #6
0
        private void saveResourceBox(ResourceBox box, string target)
        {
            if (!_eventResources.ContainsKey(target))
            {
                _eventResources.Add(target, box);
                return;
            }

            _eventResources[target] = box;
        }
Пример #7
0
        /// <summary>
        /// Kopiera resursbox
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ResourceBoxUI_Click2(object sender, EventArgs e)
        {
            ResourceBox rb = new ResourceBox(resursbox_.StartTime, resursbox_.EndTime, resursbox_.Name, resursbox_.Free,
                                             resursbox_.Locked, resursbox_.LockedStartTime, resursbox_.LockedEndTime);

            // #1.01
            //			SchemaUI.addResourcebox(this.Parent, rb);
            Scheme.Instance.setResourceBox(rb, true);
            ((SchemaUI)this.Parent).addResourcebox(rb);
            displayInformation();
        }
 void AddBoxDot(ResourceBox box)
 {
     if (!radarDots.ContainsKey(box))
     {
         var dotInstance      = Instantiate(dotPrefab, dotContainer.transform);
         var dotRectTransform = dotInstance.GetComponent <RectTransform>();
         var dotImage         = dotInstance.GetComponent <Image>();
         radarDots.Add(box, dotInstance);
         radarDotsRectTransforms.Add(box, dotRectTransform);
         radarDotsImages.Add(box, dotImage);
     }
 }
Пример #9
0
		public override void OnTurn ()
		{
			Output = ResourceBox.EMPTY();

			if (Input.Type == _eventResources["input"].Type)
			{
				/// If the building gets insufficient input resources
				/// then the output is left empty
				if (Input.Spend(_eventResources["input"].Quantity))
				{
					Output = _eventResources["output"];
				}
			}
		}
Пример #10
0
        /// <summary>
        /// Add resourceboxUI to a schemaUI
        /// </summary>
        /// <param name="rb">ResourceBox</param>
        public void addResourcebox(ResourceBox rb)
        {
            // Check if the resoucebox already exists
//			if ( this.resursboxuis_.ContainsKey(rb.Id) ) #1.02.001 - row changed
            if (resursboxuis_.ContainsKey(rb.Id))
            {
//				((ResourceBoxUI)this.resursboxuis_[rb.Id]).Update(this); #1.02.001 - row changed
                ((ResourceBoxUI)resursboxuis_[rb.Id]).Update(this);
                return;
            }

            // Create graphics object to represent the resourcebox
            ResourceBoxUI rbui;

//			if ( this.resursboxuis_.Count < this.cacheSize ) #1.02.001 - row changed
            if (resursboxuis_.Count < this.cacheSize)
            {
                rbui = new ResourceBoxUI(rb, information_);
//				Controls.Add(rbui); #1.02.001 - row removed
//				this.resursboxuis_.Add(rb.Id, rbui); #1.02.001 - row changed
                resursboxuis_.Add(rb.Id, rbui);
            }
            else
            {
                // #1.01.001 Added param rb to solve bug SL-5
                rbui = findFreeResourceBoxUI(rb);

                // HACK: Better code please!
                try
                {
                    resursboxuis_.Remove(rbui.ResourceBox.Id);
                }
                catch
                {
                }

                rbui.ResourceBox = rb;

//				this.resursboxuis_.Add(rb.Id, rbui); #1.02.001 - row changed
                resursboxuis_.Add(rb.Id, rbui);
            }
            // #1.02.001 - row added
            rbui.Parent = this;
            rb.AddObserver(rbui);
            ((ActivePersonResource)Scheme.Instance.ActivePersonsResources[rb.Name]).AddObserver(rbui);
            rbui.Update(this);
        }
Пример #11
0
        void initResourceBoxes()
        {
            var resources = Enum.GetValues(typeof(ResourceType));

            var spacing = (menuTexure.Width -
                           (resourceBoxSize.X * resources.Length)) / resources.Length;

            int offsetTop = 83;

            resourceBoxes = new ResourceBox[resources.Length];

            var costs = building.Properties.GetUpgradeCost(targetLevel);

            for (int i = 0; i < resources.Length; i++)
            {
                var resource = (ResourceType)resources.GetValue(i);

                int total = world.Bank.GetTotal(resource);

                int cost = costs.FromType(resource);

                var bounds = new Rectangle()
                {
                    X      = (i * (spacing + resourceBoxSize.X)) + (spacing / 2),
                    Y      = offsetTop,
                    Width  = resourceBoxSize.X,
                    Height = resourceBoxSize.Y
                };

                bool affordable = total >= cost;

                if (!affordable)
                {
                    purchaseAffordable = false;
                }

                resourceBoxes[i] = new ResourceBox(resourceIcons[i],
                                                   affordableIcons[affordable ? 1 : 0],
                                                   bounds,
                                                   Enum.GetName(resource.GetType(), resource),
                                                   cost,
                                                   total);
            }
        }
Пример #12
0
        /// <summary>
        /// Creates a resourceboxUI given a resourcebox
        /// </summary>
        /// <param name="resursbox">Resourcebox to represent</param>
        public ResourceBoxUI(ResourceBox resursbox, Observer information)
        {
            resursbox_ = resursbox;
            //			this.AllowDrop = true; #1.02.001 - row removed
            // Setup events
            // #1.02.001 - rows removed - start
            //			this.MouseDown += new System.Windows.Forms.MouseEventHandler(ResourceBoxUI_MouseDown);
            //			this.MouseMove +=new System.Windows.Forms.MouseEventHandler(ResourceBoxUI_MouseMove);
            //			this.MouseUp += new System.Windows.Forms.MouseEventHandler(ResourceBoxUI_MouseMove);
            //			this.Leave +=new EventHandler(ResourceBoxUI_Leave);
            // #1.02.001 - rows removed - end
            // Set apperance properties

            // #1.01.005 removed property
            //			this.BorderStyle = BorderStyle.Fixed3D;
            this.Font = new Font("Arial", 7);
            //			this.Paint +=new PaintEventHandler(ResourceBoxUI_Paint); #1.02.001 - row removed
            information_ = information;
        }
        void RemoveBoxDot(ResourceBox box)
        {
            GameObject dotInstance;

            if (radarDots.TryGetValue(box, out dotInstance))
            {
                Destroy(dotInstance);
                radarDots.Remove(box);
            }

            if (radarDotsImages.ContainsKey(box))
            {
                radarDotsImages.Remove(box);
            }

            if (radarDotsRectTransforms.ContainsKey(box))
            {
                radarDotsRectTransforms.Remove(box);
            }
        }
Пример #14
0
    public static T Load <T>(Category category, string assetname)
        where T : class
    {
        ResourceBox retv  = null;
        Depot       depot = null;

        if (!s_depotDict.TryGetValue(category, out depot))
        {
            depot = new Depot();
            s_depotDict[category] = depot;
        }

        if (!depot.m_resourceDict.TryGetValue(assetname, out retv))
        {
            retv      = new ResourceBox();
            retv.type = typeof(T);
            ICustomLoader loader = null;
            s_loader.TryGetValue(retv.type, out loader);
            if (loader != null)
            {
                retv.res = loader.LoadResource(assetname);
            }
            else
            {
                retv.res = Resources.Load(assetname) as T;
            }
            depot.m_resourceDict[assetname] = retv;
        }

        if (s_tempDepot != null && s_tempDepotName == category)         // 로딩 세션 사용중이라면 임시 보관소에도 로딩 현황을 올린다.
        {
            s_tempDepot.m_resourceDict[assetname] = retv;
        }

        return(retv.res as T);
    }
Пример #15
0
 /// <summary>
 /// Called when the building is built
 /// </summary>
 /// <returns>Resources provided once the building is completed</returns>
 public ResourceBox OnBuild()
 {
     return(ResourceBox.EMPTY());
 }
Пример #16
0
 /// <summary>
 /// Called each time building is upgraded
 /// </summary>
 /// <returns>Resources provided on upgrade</returns>
 public ResourceBox OnUpgrade()
 {
     return(ResourceBox.EMPTY());
 }
 public void ResourceBoxCollected(ResourceBox resourceBox)
 {
     globalAudio.PlayCollectSound();
     BoxesCollected++;
     OnBoxCollected?.Invoke();
 }