public UIInventorySlot(ClientInventory inventory, byte slotId, Action <UIEvent, byte> clickAction = null, Action <UIEvent, byte> enterAction = null, bool hotBarMode = false) : base(nameof(UIInventorySlot)) { _inventory = inventory; _slotId = slotId; _hover = false; _hotBarMode = hotBarMode; Color color = _hotBarMode ? Color.Black : Color.Silver; this.AspectRatio(1) .Background(new Color(0, 0, 0, 0.5f)) .Border(3, color) .FontSize(0.5f); AddEvent("click", e => { clickAction?.Invoke(e, slotId); }); AddEvent("hover", e => { RenderAttributes = DefaultAttributes.CascadeAttributes(new UIAttributes { Background = new Color(0, 0, 0, 0.2f) }); }); AddEvent("mouseenter", e => { enterAction?.Invoke(e, _slotId); _hover = true; }); AddEvent("mouseleave", e => _hover = false); }
private void HoverEventHandler(UIEvent e) { UIAttributes attr = new UIAttributes(); _actionHover?.Invoke(e, attr); RenderAttributes = DefaultAttributes.CascadeAttributes(attr); }
private void ClickEvent(UIEvent e) { UIAttributes attr = new UIAttributes(); _clickAction?.Invoke(e, attr); RenderAttributes = DefaultAttributes.CascadeAttributes(attr); }
private void HandleHoverEvent(UIEvent e) { UIAttributes attr = new UIAttributes { Background = new Color(125, 125, 125), Color = Color.White }; RenderAttributes = DefaultAttributes.CascadeAttributes(attr); }
private void KeyPressEvent(UIEvent e) { //mark key pressed _previousKey = e.Keyboard.KeyEnum; _keyRepeatCounter = 0; ProcessKeys(e); UIAttributes attr = new UIAttributes(); _keyPressAction?.Invoke(e, attr); RenderAttributes = DefaultAttributes.CascadeAttributes(attr); e.StopPropagation(); }
private void SetProperties(Type type) { foreach (PropertyInfo property in Properties) { ManagedProperties.Add(property.Name, property); FilteredProperties.Add(property.Name, property); foreach (CustomAttributeData attribute in property.CustomAttributes) { switch (attribute.AttributeType.Name) { case nameof(UnmanagedProperty): UnmanagedProperties.Add(property.Name, property); ManagedProperties.Remove(property.Name); FilteredProperties.Remove(property.Name); break; case nameof(AutoProperty): AutoProperties.Add(property.Name, property); AutoPropertyAttributes.Add(property.Name, property.GetCustomAttribute <AutoProperty>()); FilteredProperties.Remove(property.Name); break; case nameof(PrimaryKey): PrimaryKeyProperty = property; break; case nameof(DateCreated): DateCreatedProperty = property; AutoProperties.Add(property.Name, property); AutoPropertyAttributes.Add(property.Name, new AutoProperty(AutoPropertyTypes.DateTime)); FilteredProperties.Remove(property.Name); break; case nameof(DateModified): DateModifiedProperty = property; AutoProperties.Add(property.Name, property); AutoPropertyAttributes.Add(property.Name, new AutoProperty(AutoPropertyTypes.DateTime)); FilteredProperties.Remove(property.Name); break; case nameof(ForeignKey): ForeignKeyProperties.Add(property.Name, property); ForeignKeyAttributes.Add(property.Name, property.GetCustomAttribute <ForeignKey>()); break; case nameof(Unique): UniqueKeyProperties.Add(property.Name, property); break; case nameof(Default): DefaultProperties.Add(property.Name, property); DefaultAttributes.Add(property.Name, property.GetCustomAttribute <Default>()); break; case nameof(DataLength): DataLengthProperties.Add(property.Name, property); DataLengthAttributes.Add(property.Name, property.GetCustomAttribute <DataLength>()); break; case nameof(ForeignData): ForeignDataProperties.Add(property.Name, property); ForeignDataAttributes.Add(property.Name, ConfigureForeignDataAttribute(property.GetCustomAttribute <ForeignData>(), property)); ManagedProperties.Remove(property.Name); FilteredProperties.Remove(property.Name); break; default: break; } } } PerformPropertiesValidation(type); }
/** * Used to generate a UIComponent making use of all applied constraints and modifiers. * Modifiers and constraints are applied in the same order as they are defined */ public void Build(UILayer layer) { #region Inherit/Defaults DefaultAttributes.X = Parent?.DefaultAttributes.X ?? 0; DefaultAttributes.Y = Parent?.DefaultAttributes.Y ?? 0; DefaultAttributes.Width = Parent?.DefaultAttributes.Width ?? DefaultAttributes.Width; DefaultAttributes.Height = Parent?.DefaultAttributes.Height ?? DefaultAttributes.Height; if (DefaultAttributes.StackDirection == StackDirection.Inherit) { DefaultAttributes.StackDirection = Parent?.DefaultAttributes.StackDirection ?? StackDirection.None; } if (DefaultAttributes.Overflow == Overflow.Inherit) { DefaultAttributes.Overflow = Parent?.DefaultAttributes.Overflow ?? Overflow.Show; } if (DefaultAttributes.Sizing == Sizing.Inherit) { DefaultAttributes.Sizing = Parent?.DefaultAttributes.Sizing ?? Sizing.Proportion; } if (DefaultAttributes.Position == Position.Inherit) { DefaultAttributes.Position = Parent?.DefaultAttributes.Position ?? Position.Relative; } if (DefaultAttributes.JustifyText == JustifyText.Inherit) { DefaultAttributes.JustifyText = Parent?.DefaultAttributes.JustifyText ?? JustifyText.Start; } if (DefaultAttributes.TextWrap == TextWrap.Inherit) { DefaultAttributes.TextWrap = Parent?.DefaultAttributes.TextWrap ?? TextWrap.Wrap; } if (DefaultAttributes.FontScaleMode == FontScaleMode.Inherit) { DefaultAttributes.FontScaleMode = Parent?.DefaultAttributes.FontScaleMode ?? FontScaleMode.FontSizeScale; } if (DefaultAttributes.VerticalAlignText == VerticalAlignText.Inherit) { DefaultAttributes.VerticalAlignText = Parent?.DefaultAttributes.VerticalAlignText ?? VerticalAlignText.Start; } #endregion #region Apply Contraints/ Build Indexes if (EventHandlers.Any()) { layer.AddEventComponent(this); } if (Focusable) { layer.AddTabIndexComponent(this); } if (Updateable) { layer.AddUpdateIndexComponent(this); } #endregion //If the parent node is null then we stop here if (Parent != null) { if (Parent.DefaultAttributes.Sizing == Sizing.Proportion) { #region Proportional Container Positioning int totalProportionNumber = Parent.Children.Sum(x => x.DefaultAttributes.Grow); int leadingProportionNumber = Parent.Children.TakeWhile(child => child.Index != Index).Sum(x => x.DefaultAttributes.Grow); //Correctly render in the correct stack direction switch (Parent.DefaultAttributes.StackDirection) { case StackDirection.Horizontal: int oneProportionWidth = DefaultAttributes.Width / totalProportionNumber; DefaultAttributes.X += leadingProportionNumber * oneProportionWidth; DefaultAttributes.OffsetX = leadingProportionNumber * oneProportionWidth; DefaultAttributes.Width = oneProportionWidth * DefaultAttributes.Grow; break; case StackDirection.Vertical: int oneProportionHeight = DefaultAttributes.Height / totalProportionNumber; DefaultAttributes.Y += leadingProportionNumber * oneProportionHeight; DefaultAttributes.OffsetY = leadingProportionNumber * oneProportionHeight; DefaultAttributes.Height = oneProportionHeight * DefaultAttributes.Grow; break; } #endregion } else if (Parent.DefaultAttributes.Sizing == Sizing.Dimension) { #region Dimensional Container Positioning switch (Parent.DefaultAttributes.StackDirection) { case StackDirection.Horizontal: int nextWidth = Index * Parent.Children[0].DefaultAttributes.Width; DefaultAttributes.X += nextWidth; DefaultAttributes.OffsetX = nextWidth; break; case StackDirection.Vertical: int nextHeight = Index * Parent.Children[0].DefaultAttributes.Height; DefaultAttributes.Y += nextHeight; DefaultAttributes.OffsetY = nextHeight; break; } #endregion } } foreach (UIConstraint uiConstraint in Constraints) { uiConstraint.Apply(this); } RenderAttributes = DefaultAttributes.CascadeAttributes(DefaultAttributes); }