/// <summary> /// Gets the next element, starting from the given element. /// </summary> /// <param name="_current">The current element to search from.</param> /// <returns> /// The next element from the given one if exist, or <c>null</c>. /// </returns> /// <remarks> /// Changes the <see cref="CurrentIndex" /> in case of success. /// </remarks> virtual public IDialogComponent GetNext(IDialogComponent _current) { if (HasChildren()) { lock (SyncLock) { try { var i = IndexOfElement(_current); if (i >= 0) { // if this element is another group etc ... if (_current is IIteratable) { var next = GetNextOfIIteratableChild(_current as IIteratable); if (next != null) { return(next); } } if (i < (ChildEntries.Count - 1)) { CurrentIndex = i + 1; return(ChildEntries[CurrentIndex]); } } } catch { } finally { } } } return(null); }
public void Update(GameTime deltaTime, Entity entity) { var keyboardState = Keyboard.GetState(); if (keyboardState.IsKeyDown(Keys.Z)) { Entity interactedEntity = _factory .GetIntersectingEntities(entity.BoundingBox) .FirstOrDefault(x => x.Id != entity.Id); if (interactedEntity != null) { IDialogComponent dialog = interactedEntity.Components .OfType <IDialogComponent>() .FirstOrDefault(); if (dialog != null) { dialog.ProgressDialogue(); } } } if (entity.State == null) { entity.State = PlayerStates.Standing; } IEntityState oldState = entity.State; entity.State.Update(entity, keyboardState); if (entity.State != null && entity.State != oldState) { entity.State.EnterState(entity, oldState); } }
/// <summary> /// Determines whether this instance has a further sub-menu. /// </summary> /// <returns> /// <c>true</c> if this instance has a sub-menu; otherwise, <c>false</c>. /// </returns> public virtual bool HasSubmenu() { if (Type == DialogEntryType.Submenu) { if (ChildEntries.Count > 0) { if (ChildEntries.Count == 1) { if (ChildEntries[0] is Dialog) { return(true); } else { ChildEntries.Clear(); } } else { // clean up if it was a group before IDialogComponent dlg = null; dlg = ChildEntries.FindLast((item) => { return(item is Dialog); }); ChildEntries.Clear(); // remove the not if (dlg != null) // if a dialog was found in all children, add them again. { ChildEntries.Add(dlg); return(ChildEntries.Count == 1); } } } } return(false); }
/// <summary> /// Adds a child to the list of children. /// Does only work for groups, submenus and user defined types. /// </summary> /// <param name="child">The child to add. The child have to have a specific class type /// regarding to the parents type.</param> /// <returns><c>true</c> if the child could be added. Otherwise, <c>false</c>.</returns> public virtual bool AddChild(IDialogComponent child) { if (child != null) { switch (Type) { case DialogEntryType.Unknown: if (!childEntries.Contains(child)) { childEntries.Add(child); return(childEntries.Contains(child)); } break; //case DialogEntryType.Activation: // break; case DialogEntryType.Submenu: if (child is Dialog && !childEntries.Contains(child)) { childEntries.Add(child); return(childEntries.Contains(child)); } break; case DialogEntryType.Group: if (child is DialogEntry && !childEntries.Contains(child)) { childEntries.Add(child); return(childEntries.Contains(child)); } break; //case DialogEntryType.Checkbox: // break; //case DialogEntryType.RadioButton: // break; //case DialogEntryType.Button: // break; //case DialogEntryType.EditField: // break; default: break; } } return(false); }
/// <summary> /// Determines whether this instance has a previous element. /// </summary> /// <param name="_current">The element to be searched from.</param> /// <returns> /// <c>true</c> if this instance has a previous element; otherwise, <c>false</c>. /// </returns> /// <remarks> /// Does not set the iterator index to the index of the current element. /// </remarks> virtual public bool HasPrevious(IDialogComponent _current) { if (HasChildren()) { lock (SyncLock) { // if this element is another group etc ... if (_current is IIteratable && ((IIteratable)_current).HasChildren()) { return(true); //((IIteratable)_current).GetNext(); } var i = IndexOfElement(_current); return(HasPrevious(i)); } } return(false); }
/// <summary> /// Indexes the of element. /// </summary> /// <param name="_current">The current to search it's index.</param> /// <returns> /// The index of the element inside the list if it is contained; otherwise -1. /// </returns> virtual public int IndexOfElement(IDialogComponent _current) { if (_current != null && HasChildren()) { lock (SyncLock) { try { for (int i = 0; i < ChildEntries.Count; i++) { if (ChildEntries[i] != null && ChildEntries[i] == _current) { return(i); } } } catch { } finally { } } } return(-1); }
/// <summary> /// Gets the next previous, starting from the given element. /// </summary> /// <param name="_current">The current element to search from.</param> /// <returns> /// The previous element from the given one if exist, or <c>null</c>. /// </returns> /// <remarks> /// Changes the <see cref="CurrentIndex" /> in case of success. /// </remarks> virtual public IDialogComponent GetPrevious(IDialogComponent _current) { if (HasChildren()) { lock (SyncLock) { try { var i = IndexOfElement(_current); if (i > 0) { CurrentIndex = i; // if this element is another group etc ... if (ChildEntries[CurrentIndex] is IIteratable) { var prev = GetPreviouseOfIIteratableChild(ChildEntries[CurrentIndex] as IIteratable); if (prev != null) { return(prev); } } } if (i > 1) { CurrentIndex = i - 1; return(ChildEntries[i]); } } catch { } finally { } } } return(null); }
/// <summary> /// Adds a child to the list of children. /// Does only work for groups, submenus and user defined types. /// </summary> /// <param name="child">The child to add. The child have to have a specific class type /// regarding to the parents type.</param> /// <returns> /// <c>true</c> if the child could be added. Otherwise, <c>false</c>. /// </returns> public override bool AddChild(IDialogComponent child) { return(AddToGroupList(child as DialogEntry)); }