Пример #1
0
        private void SetupList(WidgetListView listA, WidgetListView listB, List <ResourceAmount> resourcesA,
                               List <ResourceAmount> resourcesB)
        {
            foreach (var resource in resourcesA)
            {
                var lineItem = CreateLineItem(resource);

                var lambdaResource = resource;
                lineItem.TriggerOnChildClick = true;
                lineItem.EnableHoverClick();
                lineItem.OnClick = (sender, args) =>
                {
                    if (lambdaResource.Count <= 0)
                    {
                        return;
                    }
                    var toMove = 1;
                    if (args.Control)
                    {
                        toMove = lambdaResource.Count;
                    }
                    if (args.Shift)
                    {
                        toMove = Math.Min(5, lambdaResource.Count);
                    }
                    if (lambdaResource.Count - toMove < 0)
                    {
                        return;
                    }
                    lambdaResource.Count -= toMove;
                    SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_change_selection, 0.1f, MathFunctions.Rand() * 0.25f);
                    var existingEntry = resourcesB.FirstOrDefault(r => r.Type == lambdaResource.Type);
                    if (existingEntry == null)
                    {
                        existingEntry = new ResourceAmount(lambdaResource.Type, toMove);
                        resourcesB.Add(existingEntry);
                        var rightLineItem = CreateLineItem(existingEntry);
                        rightLineItem.EnableHoverClick();
                        listA.AddItem(rightLineItem);

                        rightLineItem.TriggerOnChildClick = true;
                        rightLineItem.OnClick             = (_sender, _args) =>
                        {
                            var _toMove = 1;
                            if (_args.Control)
                            {
                                _toMove = existingEntry.Count;
                            }
                            if (_args.Shift)
                            {
                                _toMove = Math.Min(5, existingEntry.Count);
                            }
                            if (existingEntry.Count - _toMove < 0)
                            {
                                return;
                            }
                            existingEntry.Count -= _toMove;
                            SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_change_selection, 0.1f, MathFunctions.Rand() * 0.25f);
                            if (existingEntry.Count == 0)
                            {
                                var index = resourcesB.IndexOf(existingEntry);
                                if (index >= 0)
                                {
                                    resourcesB.RemoveAt(index);
                                    listA.RemoveChild(listA.GetChild(index + 1));
                                }
                            }

                            UpdateColumn(listA, resourcesB);

                            var sourceEntry = resourcesA.FirstOrDefault(
                                r => r.Type == existingEntry.Type);
                            int idx = resourcesA.IndexOf(sourceEntry);
                            sourceEntry.Count += _toMove;
                            if (idx >= 0)
                            {
                                UpdateLineItemText(
                                    listB.GetChild(resourcesA.IndexOf(sourceEntry) + 1),
                                    sourceEntry);
                            }
                            Root.SafeCall(OnTotalSelectedChanged, this);
                        };
                    }
                    else
                    {
                        existingEntry.Count += toMove;
                    }

                    UpdateColumn(listA, resourcesB);
                    UpdateLineItemText(lineItem, lambdaResource);

                    Root.SafeCall(OnTotalSelectedChanged, this);
                };

                listB.AddItem(lineItem);
            }
        }
Пример #2
0
        private void SetupList(WidgetListView rightList, WidgetListView leftList, List <ResourceAmount> sourceResources,
                               List <ResourceAmount> selectedResources)
        {
            foreach (var resource in sourceResources)
            {
                var lineItem = CreateLineItem(resource);

                var lambdaResource = resource;
                lineItem.TriggerOnChildClick = true;
                lineItem.OnClick             = (sender, args) =>
                {
                    if (lambdaResource.NumResources == 0)
                    {
                        return;
                    }

                    var toMove = 1;
                    if (args.Control)
                    {
                        toMove = lambdaResource.NumResources;
                    }
                    if (args.Shift)
                    {
                        toMove = Math.Min(5, lambdaResource.NumResources);
                    }
                    lambdaResource.NumResources -= toMove;

                    var existingEntry = selectedResources.FirstOrDefault(r => r.ResourceType == lambdaResource.ResourceType);
                    if (existingEntry == null)
                    {
                        existingEntry = new ResourceAmount(lambdaResource.ResourceType, 0);
                        selectedResources.Add(existingEntry);
                        var rightLineItem = CreateLineItem(existingEntry);
                        rightList.AddItem(rightLineItem);

                        rightLineItem.TriggerOnChildClick = true;
                        rightLineItem.OnClick             = (_sender, _args) =>
                        {
                            var _toMove = 1;
                            if (_args.Control)
                            {
                                _toMove = existingEntry.NumResources;
                            }
                            if (_args.Shift)
                            {
                                _toMove = Math.Min(5, existingEntry.NumResources);
                            }
                            existingEntry.NumResources -= _toMove;

                            if (existingEntry.NumResources == 0)
                            {
                                var index = selectedResources.IndexOf(existingEntry);
                                selectedResources.RemoveAt(index);
                                rightList.RemoveChild(rightList.GetChild(index + 1));
                            }

                            UpdateColumn(rightList, selectedResources);

                            var sourceEntry = sourceResources.FirstOrDefault(
                                r => r.ResourceType == existingEntry.ResourceType);
                            sourceEntry.NumResources += _toMove;
                            UpdateLineItemText(
                                leftList.GetChild(sourceResources.IndexOf(sourceEntry) + 1),
                                sourceEntry);

                            Root.SafeCall(OnTotalSelectedChanged, this);
                        };
                    }
                    existingEntry.NumResources += toMove;

                    UpdateColumn(rightList, selectedResources);
                    UpdateLineItemText(lineItem, lambdaResource);

                    Root.SafeCall(OnTotalSelectedChanged, this);
                };

                leftList.AddItem(lineItem);
            }
        }