static AGSLayers() { Background = new AGSRenderLayer(100); Foreground = new AGSRenderLayer(0); UI = new AGSRenderLayer(-100); Speech = new AGSRenderLayer(-200); }
static AGSLayers() { Background = new AGSRenderLayer (100); Foreground = new AGSRenderLayer (0); UI = new AGSRenderLayer (-100); Speech = new AGSRenderLayer (-200); }
private async Task addLampPosts(IGameFactory factory) { PointF parallaxSpeed = new PointF (1.4f, 1f); AGSRenderLayer parallaxLayer = new AGSRenderLayer (-50, parallaxSpeed); var image = await factory.Graphics.LoadImageAsync(_baseFolder + "lampPost.png"); var singleFrame = new AGSSingleFrameAnimation (image, factory.Graphics); const int numLampPosts = 3; for (int index = 0; index < numLampPosts; index++) { IObject lampPost = factory.Object.GetObject("Lamp Post " + index); lampPost.X = 200f * index + 30f; lampPost.Y = -130f; lampPost.RenderLayer = parallaxLayer; lampPost.StartAnimation(singleFrame); _room.Objects.Add(lampPost); } }
public IComboBox GetComboBox(string id, IButton dropDownButton = null, ITextBox textBox = null, Func <string, IButton> itemButtonFactory = null, IObject parent = null, bool addToUi = true, float defaultWidth = 500f, float defaultHeight = 40f, string watermark = "") { TypedParameter idParam = new TypedParameter(typeof(string), id); IComboBox comboBox = _resolver.Container.Resolve <IComboBox>(idParam); if (parent != null) { comboBox.RenderLayer = parent.RenderLayer; } defaultHeight = dropDownButton?.Height ?? textBox?.Height ?? defaultHeight; float itemWidth = textBox?.Width ?? defaultWidth; if (textBox == null) { textBox = GetTextBox(id + "_TextBox", 0f, 0f, comboBox, watermark, new AGSTextConfig(alignment: Alignment.MiddleCenter, autoFit: AutoFit.TextShouldFitLabel), false, itemWidth, defaultHeight); textBox.Border = AGSBorders.SolidColor(Colors.WhiteSmoke, 3f); textBox.Tint = Colors.Transparent; } else { setParent(textBox, comboBox); } textBox.RenderLayer = comboBox.RenderLayer; textBox.Enabled = false; if (dropDownButton == null) { (var idle, var hovered, var pushed) = getArrowButtonAnimations(ArrowDirection.Down, 3f); dropDownButton = GetButton(id + "_DropDownButton", idle, hovered, pushed, 0f, 0f, comboBox, "", null, false, 30f, defaultHeight); dropDownButton.Border = idle.Border; } else { setParent(dropDownButton, comboBox); } dropDownButton.RenderLayer = comboBox.RenderLayer; dropDownButton.Z = textBox.Z - 1; dropDownButton.SkinTags.Add(AGSSkin.DropDownButtonTag); dropDownButton.Skin?.Apply(dropDownButton); var dropDownPanelLayer = new AGSRenderLayer(comboBox.RenderLayer.Z - 1, comboBox.RenderLayer.ParallaxSpeed, comboBox.RenderLayer.IndependentResolution); //Making sure that the drop-down layer is rendered before the combobox layer, so that it will appear in front of other ui elements that may be below. if (itemButtonFactory == null) { var yellowBrush = _graphics.Brushes.LoadSolidBrush(Colors.Yellow); var whiteBrush = _graphics.Brushes.LoadSolidBrush(Colors.White); itemButtonFactory = text => { var button = GetButton(id + "_" + text, new ButtonAnimation(null, new AGSTextConfig(whiteBrush, autoFit: AutoFit.LabelShouldFitText), null), new ButtonAnimation(null, new AGSTextConfig(yellowBrush, autoFit: AutoFit.LabelShouldFitText), null), new ButtonAnimation(null, new AGSTextConfig(yellowBrush, outlineBrush: whiteBrush, outlineWidth: 0.5f, autoFit: AutoFit.LabelShouldFitText), null), 0f, 0f, width: itemWidth, height: defaultHeight); button.Pivot = new PointF(0f, 1f); button.RenderLayer = dropDownPanelLayer; return(button); }; } var dropDownPanel = GetPanel(id + "_DropDownPanel", new EmptyImage(1f, 1f), 0f, 0f, null, false); dropDownPanel.Visible = false; _gameState.UI.Add(dropDownPanel); dropDownPanel.Border = AGSBorders.SolidColor(Colors.White, 3f); dropDownPanel.Tint = Colors.Black; dropDownPanel.RenderLayer = dropDownPanelLayer; _gameState.FocusedUI.CannotLoseFocus.Add(dropDownPanel.ID); var contentsPanel = CreateScrollingPanel(dropDownPanel); var listBox = contentsPanel.AddComponent <IListboxComponent>(); listBox.ItemButtonFactory = itemButtonFactory; listBox.MaxHeight = 300f; Action placePanel = () => { var box = textBox.GetBoundingBoxes(_gameState.Viewport)?.ViewportBox; if (box == null) { return; } dropDownPanel.Location = new AGSLocation(box.Value.BottomLeft.X, box.Value.BottomLeft.Y); }; textBox.OnBoundingBoxesChanged.Subscribe(placePanel); placePanel(); contentsPanel.AddComponent <IBoundingBoxWithChildrenComponent>(); contentsPanel.AddComponent <IStackLayoutComponent>(); comboBox.DropDownButton = dropDownButton; comboBox.TextBox = textBox; comboBox.DropDownPanel = contentsPanel; setParent(comboBox, parent); if (addToUi) { _gameState.UI.Add(textBox); _gameState.UI.Add(dropDownButton); _gameState.UI.Add(comboBox); } return(comboBox); }
public IComboBox GetComboBox(string id, [MethodParam(Browsable = false)] IButton dropDownButton = null, [MethodParam(Browsable = false)] ITextBox textBox = null, [MethodParam(Browsable = false)] Func <string, IUIControl> listItemFactory = null, [MethodParam(Browsable = false)] IObject parent = null, [MethodParam(Browsable = false, Default = false)] bool addToUi = true, float defaultWidth = 500f, float defaultHeight = 40f, string watermark = "", float dropDownPanelOffset = 0f) { TypedParameter idParam = new TypedParameter(typeof(string), id); IComboBox comboBox = _resolver.Container.Resolve <IComboBox>(idParam); if (parent != null) { comboBox.RenderLayer = parent.RenderLayer; } defaultHeight = dropDownButton?.Height ?? textBox?.Height ?? defaultHeight; float itemWidth = textBox?.Width ?? defaultWidth; if (textBox == null) { textBox = GetTextBox(id + "_TextBox", 0f, 0f, comboBox, watermark, _fonts.GetTextConfig(alignment: Alignment.MiddleCenter, autoFit: AutoFit.TextShouldFitLabel), false, itemWidth, defaultHeight); textBox.Border = _borders.SolidColor(Colors.WhiteSmoke, 3f); textBox.Tint = Colors.Transparent; } else { setParent(textBox, comboBox); } textBox.RenderLayer = comboBox.RenderLayer; textBox.Enabled = false; if (dropDownButton == null) { (var idle, var hovered, var pushed) = getArrowButtonAnimations(ArrowDirection.Down, 3f); dropDownButton = GetButton(id + "_DropDownButton", idle, hovered, pushed, 0f, 0f, comboBox, "", null, false, 30f, defaultHeight); dropDownButton.Border = idle.Border; } else { setParent(dropDownButton, comboBox); } dropDownButton.RenderLayer = comboBox.RenderLayer; dropDownButton.Z = textBox.Z - 1; dropDownButton.SkinTags.Add(AGSSkin.DropDownButtonTag); dropDownButton.Skin?.Apply(dropDownButton); var dropDownPanelLayer = new AGSRenderLayer(comboBox.RenderLayer.Z - 1, comboBox.RenderLayer.ParallaxSpeed, comboBox.RenderLayer.IndependentResolution); //Making sure that the drop-down layer is rendered before the combobox layer, so that it will appear in front of other ui elements that may be below. var listbox = GetListBox(id, dropDownPanelLayer, listItemFactory, itemWidth, defaultHeight, isVisible: false); _gameState.FocusedUI.CannotLoseFocus.Add(listbox.ScrollingPanel.ID); Action placePanel = () => { var box = textBox.GetBoundingBoxes(_gameState.Viewport)?.ViewportBox; if (box == null) { return; } listbox.ScrollingPanel.Position = new Position(box.Value.BottomLeft.X, box.Value.BottomLeft.Y - dropDownPanelOffset); }; textBox.OnBoundingBoxesChanged.Subscribe(placePanel); placePanel(); comboBox.DropDownButton = dropDownButton; comboBox.TextBox = textBox; comboBox.DropDownPanel = listbox; setParent(comboBox, parent); if (addToUi) { _gameState.UI.Add(textBox); _gameState.UI.Add(dropDownButton); _gameState.UI.Add(comboBox); } return(comboBox); }