コード例 #1
0
        private void BlueprintClicked(BlueprintButton sender)
        {
            //craftTimer = new Timer_Bar(new Size(200,15), new TimeSpan(0,0,0,10));
            if (_playerManager != null)
                if (_playerManager.ControlledEntity != null)
                    if (_playerManager.ControlledEntity.HasComponent(ComponentFamily.Inventory))
                    {
                        var invComp =
                            (InventoryComponent) _playerManager.ControlledEntity.GetComponent(ComponentFamily.Inventory);
                        if (!invComp.ContainsEntity(sender.Compo1) || !invComp.ContainsEntity(sender.Compo2))
                        {
                            _craftStatus.Text = "Status: You do not have the required items.";
                            _craftStatus.Color = Color.DarkRed;
                        }
                        else
                        {
                            _craftSlot1.SetEntity(invComp.GetEntity(sender.Compo1));
                            _craftSlot2.SetEntity(invComp.GetEntity(sender.Compo2));

                            CraftButtonClicked(null); //This is pretty dumb but i hate duplicate code.
                        }
                    }
        }
コード例 #2
0
        private void AddBlueprint(NetIncomingMessage message)
        {
            string compo1Temp = message.ReadString();
            string compo1Name = message.ReadString();
            string compo2Temp = message.ReadString();
            string compo2Name = message.ReadString();
            string resultTemp = message.ReadString();
            string resultName = message.ReadString();

            _craftStatus.Text = "Status: You successfully create '" + resultName + "'";
            _craftStatus.Color = Color.Green;

            foreach (BlueprintButton bpbutt in _blueprints.components)
            {
                var req = new List<string> {compo1Temp, compo2Temp};
                if (req.Exists(x => x.ToLowerInvariant() == bpbutt.Compo1.ToLowerInvariant()))
                    req.Remove(req.First(x => x.ToLowerInvariant() == bpbutt.Compo1.ToLowerInvariant()));
                if (req.Exists(x => x.ToLowerInvariant() == bpbutt.Compo2.ToLowerInvariant()))
                    req.Remove(req.First(x => x.ToLowerInvariant() == bpbutt.Compo2.ToLowerInvariant()));
                if (!req.Any()) return;
            }

            var newBpb = new BlueprintButton(compo1Temp, compo1Name, compo2Temp, compo2Name, resultTemp, resultName,
                                             _resourceManager);
            newBpb.Update(0);

            newBpb.Clicked += BlueprintClicked;

            newBpb.Position = new Point(0, _blueprintsOffset);
            _blueprintsOffset += newBpb.ClientArea.Height;

            _blueprints.components.Add(newBpb);
        }