public override void Draw(SpriteBatch spriteBatch, Rectangle drawArea) { const int margingMult = 3; Vector2 position = drawArea.Position(); Rectangle safeDrawArea = drawArea; safeDrawArea.Width -= ShiftLeftIndicator.Width * 2; safeDrawArea.Width -= Margin * margingMult * 2; position.X += ShiftLeftIndicator.Width + Margin * margingMult; float colorAlpha = this.ControlManager.Screen.TransitionAlpha; Texture2D blank = RaceGame.Instance.WhiteTexture2D; Color borderColor; Color displayAreaColor = new Color(ItemBackground.ToVector3() * colorAlpha); Color whiteLighting = new Color(colorAlpha, colorAlpha, colorAlpha); int firstIndexToDraw; int lastIndexToDraw; FindItemIndicesToDraw(safeDrawArea, out firstIndexToDraw, out lastIndexToDraw); int itemCount = lastIndexToDraw - firstIndexToDraw + 1; int drawnItemsWidth = (ItemWidth * itemCount) + (Margin * (itemCount - 1)); drawArea.Width -= (safeDrawArea.Width - drawnItemsWidth); for (int i = 0; i < itemCount; i++) { int itemIndex = i + firstIndexToDraw; var container = m_contentItems[itemIndex]; borderColor = FindBorderColor(colorAlpha, itemIndex); Rectangle borderRec = new Rectangle((int)position.X, (int)position.Y, ItemWidth, ItemHeight); Rectangle displayBackgroundRect = new Rectangle( borderRec.X + BorderThickness, borderRec.Y + BorderThickness, borderRec.Width - BorderThickness * 2, borderRec.Height - BorderThickness * 2); Rectangle displayRect = new Rectangle( displayBackgroundRect.X + Padding, displayBackgroundRect.Y + Padding, displayBackgroundRect.Width - Padding * 2, displayBackgroundRect.Height - Padding * 2); spriteBatch.Draw(blank, borderRec, borderColor); spriteBatch.Draw(blank, displayBackgroundRect, displayAreaColor); container.DrawDisplayItem(spriteBatch, displayRect, whiteLighting); position.X += ItemWidth + Margin; } DrawIndicators(spriteBatch, drawArea); }
protected override void OnStyleChanged(UIStyle style) { base.OnStyleChanged(style); TextStyle.ValueFor(this).Update(PeerDropdown.captionText, DefaultTextStyle); Background.ValueFor(this).Update(PeerImage, DefaultBackground); ArrowImage.ValueFor(this).Update(PeerArrow, DefaultArrowImage); PeerScrollPanel.Background = PopupBackground.Merge(DefaultPopupBackground); PeerToggle.Checkbox = ItemBackground.Merge(DefaultItemBackgroundSet); PeerToggle.TextStyle = ItemTextStyle.Merge(DefaultItemTextStyleSet); }
//private Sprite GetSprite(YuLegoDropdownOptionMeta optionMeta) //{ // var spriteId = optionMeta.SpriteId; // if (spriteDict.ContainsKey(spriteId)) // { // return spriteDict[spriteId].GetAsset(); // } // var spRef = AssetModule.GetSprite(spriteId); // spriteDict.Add(spriteId, spRef); // return spRef.GetAsset(); //} #endregion public override void Metamorphose(LegoUIMeta uiMeta) { if (MetamorphoseStage == LegoMetamorphoseStage.Completed) { MetamorphoseStage = LegoMetamorphoseStage.Metamorphosing; } if (dropdownMeta == null) { dropdownMeta = uiMeta.NextDropdown; dropdownRectMeta = uiMeta.CurrentRect; } switch (metamorphoseStatus) { case MetamorphoseStatus.Dropdown: MetamorphoseRect(dropdownRectMeta); // 输入框自身附带Image控件变形 SelfImage.Metamorphose(dropdownMeta.DropdownImageMeta); if (dropdownMeta.Transition == LegoTransition.ColorTint) { var colorTintMeta = dropdownMeta.ColorTintMeta; colors = new ColorBlock { normalColor = colorTintMeta.NormalLegoColor.ToColor(), highlightedColor = colorTintMeta.HighlightedLegoColor.ToColor(), pressedColor = colorTintMeta.PressedLegoColor.ToColor(), disabledColor = colorTintMeta.DisabledLegoColor.ToColor(), colorMultiplier = colorTintMeta.ColorMultiplier, fadeDuration = colorTintMeta.FadeDuration }; } // 选项 if (dropdownMeta.OptionMetas != null && dropdownMeta.OptionMetas.Count > 0) { options.Clear(); foreach (var optionMeta in dropdownMeta.OptionMetas) { var optionData = new OptionData(); optionData.text = optionMeta.Text; // todo 下拉框菜单精灵 //optionData.image = SpriteRouter.GetSprite(optionMeta.SpriteId); options.Add(optionData); } } metamorphoseStatus = MetamorphoseStatus.Label; break; case MetamorphoseStatus.Label: Label.Metamorphose(dropdownMeta.LabelRectMeta, dropdownMeta.LabelTextMeta); metamorphoseStatus = MetamorphoseStatus.Arrow; break; case MetamorphoseStatus.Arrow: Arrow.Metamorphose(dropdownMeta.ArrowRectMeta, dropdownMeta.ArrowImageMeta); metamorphoseStatus = MetamorphoseStatus.Template; break; case MetamorphoseStatus.Template: TemplateImage.Metamorphose(dropdownMeta.TemplateRectMeta, dropdownMeta.TemplateImageMeta); metamorphoseStatus = MetamorphoseStatus.Viewport; break; case MetamorphoseStatus.Viewport: ViewportImage.Metamorphose(dropdownMeta.ViewPortRectMeta, dropdownMeta.ViewPortImageMeta); metamorphoseStatus = MetamorphoseStatus.Content; break; case MetamorphoseStatus.Content: YuLegoUtility.MetamorphoseRect(Content, dropdownMeta.ContentRectMeta); metamorphoseStatus = MetamorphoseStatus.Item; break; case MetamorphoseStatus.Item: if (dropdownMeta.ItemTransition == LegoTransition.ColorTint) { var colorTintMeta = dropdownMeta.ItemRootColorTintMeta; Item.colors = new ColorBlock { normalColor = colorTintMeta.NormalLegoColor.ToColor(), highlightedColor = colorTintMeta.HighlightedLegoColor.ToColor(), pressedColor = colorTintMeta.PressedLegoColor.ToColor(), disabledColor = colorTintMeta.DisabledLegoColor.ToColor(), colorMultiplier = colorTintMeta.ColorMultiplier, fadeDuration = colorTintMeta.FadeDuration }; } YuLegoUtility.MetamorphoseRect(Item.RectTransform, dropdownMeta.ItemRootRectMeta); metamorphoseStatus = MetamorphoseStatus.ItemBackground; break; case MetamorphoseStatus.ItemBackground: ItemBackground.Metamorphose(dropdownMeta.ItemBackgroundRectMeta, dropdownMeta.ItemBackgroundImageMeta); metamorphoseStatus = MetamorphoseStatus.ItemCheckmark; break; case MetamorphoseStatus.ItemCheckmark: ItemCheckmark.Metamorphose(dropdownMeta.ItemCheckmarkRectMeta, dropdownMeta.ItemCheckmarkImageMeta); metamorphoseStatus = MetamorphoseStatus.ItemLabel; break; case MetamorphoseStatus.ItemLabel: ItemLabel.Metamorphose(dropdownMeta.ItemLabelRectMeta, dropdownMeta.ItemLabelTextMeta); metamorphoseStatus = MetamorphoseStatus.Scrollbar; break; case MetamorphoseStatus.Scrollbar: ScrollbarImage.Metamorphose(dropdownMeta.ScrollbarRectMeta, dropdownMeta.ScrollbarImageMeta); metamorphoseStatus = MetamorphoseStatus.SlidingArea; break; case MetamorphoseStatus.SlidingArea: YuLegoUtility.MetamorphoseRect(SlidingArea, dropdownMeta.SlidingAreaRectMeta); metamorphoseStatus = MetamorphoseStatus.Handle; break; case MetamorphoseStatus.Handle: HandleImage.Metamorphose(dropdownMeta.ScrollbarHandleRectMeta, dropdownMeta.ScrollbarHandleImageMeta); dropdownMeta = null; dropdownRectMeta = null; metamorphoseStatus = MetamorphoseStatus.Dropdown; MetamorphoseStage = LegoMetamorphoseStage.Completed; break; default: throw new ArgumentOutOfRangeException(); } }