public void AddEffect(Effect effect) { bool shouldCreateEffect = true; foreach (Effect child in GetChildren()) { StackResult result = child.StackEffects(effect); if (result == StackResult.StopStacking) { shouldCreateEffect = false; break; } else if (result == StackResult.ContinueStacking) { shouldCreateEffect = false; } } if (shouldCreateEffect) { AddChild(effect); } else { // effect.QueueFree(); } }
private void AddBuff(Modifier modifier) { List <Modifier> ongoingModifiersOfSameType = new List <Modifier>(); foreach (Modifier ongoingModifier in ongoingModifiers) { if (ongoingModifier.Type() == modifier.Type()) { if (ongoingModifier.SubType() == modifier.SubType()) { StackResult stackResult = ongoingModifier.TryStackWithNewOne(modifier); if (stackResult == StackResult.Manual) { return; } if (stackResult == StackResult.Stack) { StackBuff(modifier); return; } ongoingModifiersOfSameType.Add(ongoingModifier); } } } foreach (Modifier m in ongoingModifiersOfSameType) { m.OnBeReplaced(this, modifier); ongoingModifiers.Remove(m); } modifier.OnReplaceOtherModifiers(this, ongoingModifiersOfSameType); ongoingModifiers.Add(modifier); modifier.OnAttachAsMain(this); NotifyModifierAttachment(modifier); }
public StackResult Navigate(IStackOptions options) { lock (_lock) { StackResult stackResult = StackResult.StackStarted; if (options.StackChoice == null) { throw new NullReferenceException($"{nameof(NavigationService)}.{nameof(Navigate)} can not accept a null {nameof(options.StackChoice)}"); } // Don't change to the same stack if (_currentStack != null && _currentStack.Equals(options.StackChoice)) { return(StackResult.None); } if (!_stacks.ContainsKey(options.StackChoice)) { throw new NullReferenceException($"{nameof(NavigationService)} does not contain a stack named {options.StackChoice.ToString()}"); } // Current / Previous Stack IStack oldStack = null; if (_currentStack != null) { oldStack = _stacks[_currentStack]; oldStack.StateChange(StackStatus.Background); // Schedules NoHistoryRemoval } var stack = _stacks[options.StackChoice]; _currentStack = options.StackChoice; // Set new status stack.Proxy.ViewStatus = VisualStatus.Visible; // Switch over services _displayService.Init(stack.Proxy); ThreadHelper.RunOnUIThread(async() => { if (stack.Status == StackStatus.Stopped) { object args = null; // If ArgsKey present only pass args along if the StartKey is the same if ((!string.IsNullOrEmpty(options?.ArgsKey) && stack.NavigationStartKey == options?.ArgsKey) || string.IsNullOrEmpty(options?.ArgsKey)) { stackResult = stackResult | StackResult.ArgsPassed; args = options?.Args; } var loadStartKey = options?.PredefinedStack == null; if (loadStartKey) { stackResult = stackResult | StackResult.NavigationStarted; } await stack.StartNavigation(args: args, loadStartKey: loadStartKey); } // Preload Stack if (options?.PredefinedStack != null) { foreach (var page in options.PredefinedStack) { await Navigate(page.Key, page.Value); } } // Find mainview from ViewHierarchy var viewContainer = _viewContainers[_stackViewContainers[options.StackChoice]]; if (viewContainer is IMasterDetailContainer) { var masterDetailContainer = viewContainer as IMasterDetailContainer; if (masterDetailContainer.DetailStack != null) { // Setup Detail Stack var detailStack = _stacks[masterDetailContainer.DetailStack.StackIdentifier]; if (detailStack.Status == StackStatus.Stopped) { await detailStack.StartNavigation(); } masterDetailContainer.Proxy.DetailNativeView = detailStack.Proxy.NativeView; // Setup Master Stack var masterStack = _stacks[masterDetailContainer.MasterStack.StackIdentifier]; if (masterStack.Status == StackStatus.Stopped) { await masterStack.StartNavigation(); } masterDetailContainer.Proxy.MasterNativeView = masterStack.Proxy.NativeView; } } _currentViewContainer = viewContainer; if (!string.IsNullOrEmpty(options.ViewKey)) { await Navigate(options.ViewKey, options.Args, options.NewInstance); } _setRoot?.Invoke(viewContainer.NativeView); if (oldStack != null) { await oldStack.StackChanged(); } }); return(stackResult); } }
public void OnDrop(PointerEventData eventData) { if (UIItem.DraggedItem == null) { return; } if (UIItem.DraggedItem.Item == null) { return; } if (HaveItem == false) { AddUIItem(UIItem.DraggedItem); if (IsCrossInventory) { Debug.Log("EMPTY CROSS PANEL"); // Remove item from inventory that its coming from EventMessenger.Instance.Raise(new EventRemoveItemFromInventory(UIItem.DraggedItemStartSlot.InventoryUUID, UIItem.DraggedItem.Item, false)); UIItem.DraggedItem.Item.BaseData.InventoryUUID = InventoryUUID; // IMPORTANT SET THE INVENTORY // IMPORTANT SET THE INVENTORY //this.ThisUIItem.Item.Inventory = ThisUIItem.Item.Inventory; // Add Item to the new inventory EventMessenger.Instance.Raise(new EventAddItemToInventory(InventoryUUID, UIItem.DraggedItem.Item, false)); this.ThisUIItem.transform.SetParent(UIItem.DraggedItemStartSlot.transform); } else { Debug.Log("EMPTY SAME PANEL"); // IMPORTANT SET THE INVENTORY // IMPORTANT SET THE INVENTORY //UIItem.DraggedItem.Item.Inventory = ThisUIItem.Item.Inventory; this.ThisUIItem.transform.SetParent(UIItem.DraggedItemStartSlot.transform); } } else { // If the item in the slot is stackable check here too and dont return to original position // if we have an item in the slot where this slot is being dragged return to original position // Set the start slot ItemContainer to this slot item container UIItem.DraggedItemStartSlot.ThisUIItem = this.ThisUIItem; // Here I can change where to check for the stackable interface // could be in the item itself (ItemContainer.Item) // or it could be in the data (ItemContainer.Item.BaseData) IStackable stackInterface = ThisUIItem.Item as IStackable; if (stackInterface != null && stackInterface.IsStackable) { StackResult stackResult = stackInterface.Stack(UIItem.DraggedItem.Item as BaseItem); if (stackResult != null) { if ((stackResult.item.BaseData as IStackableData).Quantity <= 0) { //Debug.Log("ITEMS WERE STACKED RESULT QUANTITY IS <= 0"); // Set the slot ItemContainer that the item is being dragged from to null UIItem.DraggedItemStartSlot.ThisUIItem = ThisUIItem; ThisUIItem.UpdateQuantity(); UIItem.DraggedItem.UpdateQuantity(); if (IsCrossInventory) { Debug.Log("STACK WITH DESTROY CROSS PANEL"); // --> EventMessenger.Instance.Raise(new EventUIInventoryItemChanged(InventoryPanel.Inventory.UniqueUUID, InventoryItem.Item.BaseData)); } else { Debug.Log("STACK WITH DESTROY SAME PANEL"); UIItem.DraggedItem.transform.SetParent(UIItem.DraggedItemStartSlot.transform); // --> EventMessenger.Instance.Raise(new EventUIInventoryItemChanged(InventoryPanel.Inventory.UniqueUUID, InventoryItem.Item.BaseData)); } } else { Debug.Log("ITEMS WERE STACKED BOTH ITEMS STILL HAVE QUANTITY"); // right item (dragged item) exchanged the quantities but // it still have quantity put it back where it came from UIItem.DraggedItem.transform.SetParent(UIItem.DraggedItemStartSlot.transform); // update the left (item in this slot) item quantity ThisUIItem.UpdateQuantity(); // update right item (dragged item) quantity UIItem.DraggedItem.UpdateQuantity(); } } else { // stack failed for some reason maybe the items were not stackable // or the left item (item in the slot) was full. Do a switch; Debug.Log("STACK IS NULL DO A SWITCH ON THE ITEMS"); SwapNonStackable(); } } else { Debug.LogError("Item [" + ThisUIItem.Item.BaseData.Name + "] Does not implement the IStackable interface. Or the item is not marked as stackable " + "[" + ThisUIItem.GetType() + "]"); //Debug.Log("ITEM COREDATA IS MARKED AS NON STACKABLE SWAP ITEMS"); SwapNonStackable(); } ThisUIItem.UpdateSlotInfo(); // When stacking an item the inventory item of tmpItemStartSlot will // be null. Lets check that and only update the slot info if its not null if (UIItem.DraggedItemStartSlot.ThisUIItem != null) { UIItem.DraggedItemStartSlot.ThisUIItem.UpdateSlotInfo(); } } }
public StackResult Navigate(object containerId, object regionId, IStackOptions options) { lock (_lock) { StackResult stackResult = StackResult.StackStarted; if (options.StackChoice == null) { throw new NullReferenceException($"{nameof(NavigationService)}.{nameof(Navigate)} can not accept a null {nameof(options.StackChoice)}"); } // Don't change to the same stack if (_currentStack != null && _currentStack.Equals(options.StackChoice)) { if (_getRoot != null) { if (_getRoot() == null) { // Set Root Page ThreadHelper.RunOnUIThread(() => { var viewContainer = _viewContainers[_stackViewContainers[options.StackChoice]]; _setRoot?.Invoke(viewContainer?.NativeView); }); } } return(StackResult.None); } if (!_stacks.ContainsKey(options.StackChoice) && regionId == null) { throw new NullReferenceException($"{nameof(NavigationService)} does not contain a stack named {options.StackChoice.ToString()}"); } // Current / Previous Stack IStack oldStack = null; if (_currentStack != null) { oldStack = _stacks[_currentStack]; oldStack.StateChange(StackStatus.Background); // Schedules NoHistoryRemoval } var stack = _stacks[options.StackChoice]; _currentStack = options.StackChoice; // Set new status stack.Proxy.ViewStatus = VisualStatus.Visible; // Switch over services _displayService.Init(stack.Proxy); ThreadHelper.RunOnUIThread(async() => { if (stack.Status == StackStatus.Stopped) { object args = null; // If ArgsKey present only pass args along if the StartKey is the same if ((!string.IsNullOrEmpty(options?.ArgsKey) && stack.NavigationStartKey == options?.ArgsKey) || string.IsNullOrEmpty(options?.ArgsKey)) { stackResult = stackResult | StackResult.ArgsPassed; args = options?.Args; } var loadStartKey = options?.PredefinedStack == null; if (loadStartKey) { stackResult = stackResult | StackResult.NavigationStarted; } await stack.StartNavigation(args: args, loadStartKey: loadStartKey); } // Preload Stack if (options?.PredefinedStack != null) { foreach (var page in options.PredefinedStack) { await Navigate(page.Key, page.Value); } } IViewContainer viewContainer = null; // Find mainview from ViewHierarchy object viewContainerKey = regionId; if (containerId != null && regionId != null) { var container = _viewContainers[containerId.ToString()]; if (container.RegionMapping.Any(x => x.Key.ToString() == regionId.ToString())) { viewContainer = container; } } else if (containerId != null && regionId == null) { var container = _viewContainers[containerId.ToString()]; viewContainer = container; } else { if (_stackViewContainers.ContainsKey(stack.StackIdentifier)) { viewContainer = _viewContainers[_stackViewContainers[stack.StackIdentifier]]; } else { // Create single container viewContainer = new SingleViewContainer(Guid.NewGuid().ToString(), stack); // Add to list _viewContainers.Add(viewContainer.Identifier, viewContainer); } } // Tabbed View if (viewContainer is ITabbedContainer tabbedView) { await InitializeTabbedView(tabbedView); } var containerSwitch = viewContainer.RegionMapping.Any(x => x.Key.ToString() == Convert.ToString(regionId)); KeyValuePair <object, ContainerType>?containerType = viewContainer.RegionMapping.FirstOrDefault(x => x.Key.ToString() == Convert.ToString(regionId)); // MasterDetail View load if (viewContainer is IMasterDetailContainer) { var masterDetailContainer = viewContainer as IMasterDetailContainer; if (masterDetailContainer.DetailStack != null) { if (masterDetailContainer.DetailStack is IStack detailStackDefinition) { // Setup Detail Stack var detailStack = _stacks[detailStackDefinition.StackIdentifier]; if (detailStack.Status == StackStatus.Stopped) { await detailStack.StartNavigation(options?.Args); } masterDetailContainer.Proxy.DetailNativeView = detailStack.Proxy.NativeView; } else if (masterDetailContainer.DetailStack is ITabbedContainer detailTabbedDefinition) { await InitializeTabbedView(detailTabbedDefinition); masterDetailContainer.Proxy.DetailNativeView = detailTabbedDefinition.NativeView; } if (masterDetailContainer.MasterStack is IStack masterStackDefinition) { // Setup Master Stack var masterStack = _stacks[masterStackDefinition.StackIdentifier]; if (masterStack.Status == StackStatus.Stopped) { await masterStack.StartNavigation(options?.Args); } masterDetailContainer.Proxy.MasterNativeView = masterStack.Proxy.NativeView; } else if (masterDetailContainer.MasterStack is ITabbedContainer masterTabbedDefinition) { await InitializeTabbedView(masterTabbedDefinition); masterDetailContainer.Proxy.MasterNativeView = masterTabbedDefinition.NativeView; } } } if (viewContainer is ITabbedContainer tabbedContainer) { // switch current page tabbedContainer.SetCurrentPage(stack); } // If parent, then move switch container if (viewContainer.ParentContainer != null) { viewContainer = viewContainer.ParentContainer; } _currentViewContainer = viewContainer; if (!string.IsNullOrEmpty(options.ViewKey)) { await Navigate(options.ViewKey, options.Args, options.NewInstance); } if (!containerSwitch) { _setRoot?.Invoke(viewContainer?.NativeView); } else if (viewContainer is IMasterDetailContainer container) { container.SetStack(containerType.Value.Value, stack.Proxy.NativeView); } if (oldStack != null) { await oldStack.StackChanged(); } }); return(stackResult); } async Task InitializeTabbedView(ITabbedContainer tabbedView) { // Must start all stacks on the first tabbed view load // because when the tab changes, I can't block while I load an individual tab // I can only block moving to an entire page foreach (var item in tabbedView.Children) { if (item.Status == StackStatus.Stopped) { await item.StartNavigation(options?.Args); } } } }