public void Draw(UIElement ui, SpriteBatch batch)
 {
     if (((ITextControl)ui).DrawCursor)
     {
         batch.Draw(Texture, Position, null, Color.White, 0, Vector2.Zero, Scale, SpriteEffects.None, 0);
     }
 }
        public UIDragHandler(UIElement mouseTarget, UIElement dragControl)
        {
            UpdateHook = new UpdateHookDelegate(Update);

            MouseTarget = mouseTarget;
            DragControl = dragControl;
            MouseEvent = mouseTarget.ListenForMouse(mouseTarget.GetBounds(), new UIMouseEvent(DragMouseEvents));
        }
        /// <summary>
        /// Adds a UIElement at the top most position in the container
        /// </summary>
        /// <param name="child"></param>
        public void Add(UIElement child)
        {
            if (child == null) { return; }

            lock (Children)
            {
                if (Children.Contains(child))
                {
                    Children.Remove(child);
                }
                Children.Add(child);
                child.Parent = this;
            }
        }
Exemple #4
0
        /// <summary>
        /// Handle when a user selects a city
        /// </summary>
        /// <param name="element"></param>
        void CityListBox_OnChange(TSOClient.Code.UI.Framework.UIElement element)
        {
            var selectedItem = CityListBox.SelectedItem;

            if (selectedItem == null)
            {
                return;
            }

            var city = (CityInfo)selectedItem.Data;

            String gamepath = GameFacade.GameFilePath("");
            int    CityNum  = GameFacade.GetCityNumber(city.Name);
            string CityStr  = gamepath + "cities\\" + ((CityNum >= 10) ? "city_00" + CityNum.ToString() : "city_000" + CityNum.ToString());

            //Take a copy so we dont change the original when we alpha mask it
            Texture2D cityThumbTex = TextureUtils.Copy(GameFacade.GraphicsDevice, Texture2D.FromFile(
                                                           GameFacade.Game.GraphicsDevice, CityStr + "\\Thumbnail.bmp"));

            TextureUtils.CopyAlpha(ref cityThumbTex, thumbnailAlphaImage);

            CityThumb.Texture                      = cityThumbTex;
            DescriptionText.CurrentText            = city.Description;
            DescriptionText.VerticalScrollPosition = 0;

            /** Validate **/
            var isValid = true;

            if (city.Status == CityInfoStatus.Reserved)
            {
                isValid = false;
                /** Already have a sim in this city **/
                ShowCityErrorDialog(CityReservedDialogTitle, CityReservedDialogMessage);
            }
            else if (city.Status == CityInfoStatus.Full)
            {
                isValid = false;
                /** City is full **/
                ShowCityErrorDialog(CityFullDialogTitle, CityFullDialogMessage);
            }
            else if (city.Status == CityInfoStatus.Busy)
            {
                isValid = false;
                /** City is busy **/
                ShowCityErrorDialog(CityBusyDialogTitle, CityBusyDialogMessage);
            }

            OkButton.Disabled = !isValid;
        }
        private void SetSelected(UIElement element)
        {
            if (element == null)
            {
                propertyBox.Enabled = false;
                return;
            }

            propertyBox.Enabled = true;
            Selected = element;

            valueX.Value = (decimal)element.X;
            valueY.Value = (decimal)element.Y;
            valueScaleX.Value = (decimal)element.ScaleX;
            valueScaleY.Value = (decimal)element.ScaleY;
            valueAlpha.Value = (decimal)element.Opacity;
        }
Exemple #6
0
        /// <summary>
        /// Handle when a user selects a city
        /// </summary>
        /// <param name="element"></param>
        void CityListBox_OnChange(TSOClient.Code.UI.Framework.UIElement element)
        {
            var selectedItem = CityListBox.SelectedItem;

            if (selectedItem == null)
            {
                return;
            }

            var city = (CityInfo)selectedItem.Data;
            //Take a copy so we dont change the original when we alpha mask it
            var cityThumb = TextureUtils.Copy(Texture2D.FromFile(GameFacade.GraphicsDevice, new MemoryStream(ContentManager.GetResourceFromLongID(city.Thumbnail))));

            TextureUtils.CopyAlpha(ref cityThumb, thumbnailAlphaImage);

            CityThumb.Texture                      = cityThumb;
            DescriptionText.CurrentText            = city.Description;
            DescriptionText.VerticalScrollPosition = 0;

            /** Validate **/
            var isValid = true;

            if (city.Status == CityInfoStatus.Reserved)
            {
                isValid = false;
                /** Already have a sim in this city **/
                ShowCityErrorDialog(CityReservedDialogTitle, CityReservedDialogMessage);
            }
            else if (city.Status == CityInfoStatus.Full)
            {
                isValid = false;
                /** City is full **/
                ShowCityErrorDialog(CityFullDialogTitle, CityFullDialogMessage);
            }
            else if (city.Status == CityInfoStatus.Busy)
            {
                isValid = false;
                /** City is busy **/
                ShowCityErrorDialog(CityBusyDialogTitle, CityBusyDialogMessage);
            }

            OkButton.Disabled = !isValid;
        }
        public UITooltipHandler(UIElement target)
        {
            UpdateHook = new UpdateHookDelegate(Update);

            Target = target;
            Target.AddUpdateHook(UpdateHook);
        }
 public static UITooltipHandler GiveTooltip(UIElement target)
 {
     var handler = new UITooltipHandler(target);
     return handler;
 }
 public void CenterAround(UIElement element)
 {
     CenterAround(element, 0, 0);
 }
 void m_Pagination_OnPageChanged(UIElement from, int pageIndex)
 {
     this.SelectedPage = pageIndex;
 }
        public void DrawOntoPosition(SpriteBatch SBatch, UIElement element, Texture2D m_Texture, float width, float height, Vector2 position)
        {
            /** TL **/
            element.DrawLocalTexture(SBatch, m_Texture, this.TL, position);

            /** TC **/
            element.DrawLocalTexture(SBatch, m_Texture, this.TC, position + new Vector2(this.Left, 0), this.TC_Scale);

            /** TR **/
            element.DrawLocalTexture(SBatch, m_Texture, this.TR, position + new Vector2(width - this.Right, 0));

            /** ML **/
            element.DrawLocalTexture(SBatch, m_Texture, this.ML, position + new Vector2(0, this.Top), this.ML_Scale);

            /** MC **/
            element.DrawLocalTexture(SBatch, m_Texture, this.MC, position + new Vector2(this.Left, this.Top), this.MC_Scale);

            /** MR **/
            element.DrawLocalTexture(SBatch, m_Texture, this.MR, position + new Vector2(width - this.Right, this.Top), this.MR_Scale);

            /** BL **/
            var bottomY = height - this.Bottom;
            element.DrawLocalTexture(SBatch, m_Texture, this.BL, position + new Vector2(0, bottomY));

            /** BC **/
            element.DrawLocalTexture(SBatch, m_Texture, this.BC, position + new Vector2(this.Left, bottomY), this.BC_Scale);

            /** BR **/
            element.DrawLocalTexture(SBatch, m_Texture, this.BR, position + new Vector2(width - this.Right, bottomY));
        }
Exemple #12
0
 void OkButton_OnButtonClick(TSOClient.Code.UI.Framework.UIElement button)
 {
     GameFacade.Controller.ShowPersonCreation((CityInfo)CityListBox.SelectedItem.Data);
 }
        /// <summary>
        /// Adds a UIElement at a specific depth in the container
        /// </summary>
        /// <param name="index"></param>
        /// <param name="child"></param>
        public void AddAt(int index, UIElement child)
        {
            lock (Children)
            {
                if (Children.Contains(child))
                {
                    Children.Remove(child);
                }

                Children.Insert(index, child);
                child.Parent = this;
            }
        }
 public static UIDragHandler MakeDraggable(UIElement mouseTarget, UIElement dragControl)
 {
     var handler = new UIDragHandler(mouseTarget, dragControl);
     return handler;
 }
 public void Remove(UIElement child)
 {
     lock (Children)
     {
         Children.Remove(child);
     }
     //child.Parent = null;
 }
 private void ErrorReturnAlert(UIElement button)
 {
     GameFacade.Controller.ShowPersonSelection();
 }
 /// <summary>
 /// Adds a UIElement at the top most position in the container
 /// </summary>
 /// <param name="child"></param>
 public void AddBefore(UIElement child, UIElement before)
 {
     var index = Children.IndexOf(before);
     if (index != -1)
     {
         AddAt(index, child);
     }
     else
     {
         Add(child);
     }
 }
 public void Remove(UIElement child)
 {
     lock (Children)
     {
         Children.Remove(child);
     }
 }
        public void CenterAround(UIElement element, int offsetX, int offsetY)
        {
            var bounds = element.GetBounds();
            if (bounds == null) { return; }

            var topLeft =
                element.LocalPoint(new Microsoft.Xna.Framework.Vector2(bounds.X, bounds.Y));

            this.X = offsetX + topLeft.X + ((bounds.Width - this.Width) / 2);
            this.Y = offsetY + topLeft.Y + ((bounds.Height - this.Height) / 2);
        }
 public void Draw(SpriteBatch SBatch, UIElement element, float x, float y, float width, float height)
 {
     //TODO: Cache scales for various sizes?
     NineSlice.CalculateScales(width, height);
     NineSlice.DrawOntoPosition(SBatch, element, Texture, width, height, new Vector2(x, y));
 }
 public void SellBack(UIElement button)
 {
     if (Holding == null) return;
     if (Holding.IsBought) HITVM.Get().PlaySoundEvent(UISounds.MoneyBack);
     Holding.Group.Delete(vm.Context);
     OnDelete(Holding, null); //TODO: cleanup callbacks which don't need updatestate into another delegate. will do when refactoring for online
     ClearSelected();
 }
 public void Draw(UIElement ui, SpriteBatch batch)
 {
     batch.Draw(Texture, Position, null, BlendColor, 0, Vector2.Zero, Scale, SpriteEffects.None, 0);
 }
 public static void DrawText(List<ITextDrawCmd> cmds, UIElement target, SpriteBatch batch)
 {
     /**
      * Draw text
      */
     foreach (var cmd in cmds)
     {
         cmd.Draw(target, batch);
     }
 }
 public virtual void Draw(UIElement ui, SpriteBatch batch)
 {
     if (Selected)
     {
         batch.DrawString(Style.SpriteFont, Text, Position, Style.SelectedColor, 0, Vector2.Zero, Scale, SpriteEffects.None, 0);
     }
     else
     {
         batch.DrawString(Style.SpriteFont, Text, Position, Style.Color, 0, Vector2.Zero, Scale, SpriteEffects.None, 0);
     }
 }
Exemple #25
0
 /// <summary>
 /// Removes a previously shown dialog
 /// </summary>
 /// <param name="dialog"></param>
 public static void RemoveDialog(UIElement dialog)
 {
     GameFacade.Screens.RemoveDialog(dialog);
 }
Exemple #26
0
 void CancelButton_OnButtonClick(TSOClient.Code.UI.Framework.UIElement button)
 {
     UIScreen.RemoveDialog(this);
 }
Exemple #27
0
        /// <summary>
        /// Adds a popup dialog
        /// </summary>
        /// <param name="dialog"></param>
        public static void ShowDialog(UIElement dialog, bool modal)
        {
            GameFacade.Screens.AddDialog(new DialogReference
            {
                Dialog = dialog,
                Modal = modal
            });

            if (dialog is UIDialog)
            {
                ((UIDialog)dialog).CenterAround(UIScreen.Current);
            }
        }
        /// <summary>
        /// Computes drawing commands to layout a block of text within
        /// certain constraints
        /// </summary>
        /// <returns></returns>
        public static TextRendererResult ComputeText(string text, TextRendererOptions options, UIElement target)
        {
            var TextStyle = options.TextStyle;
            var _Scale = options.Scale;
            var txtScale = TextStyle.Scale * _Scale;

            var m_LineHeight = TextStyle.MeasureString("W").Y - (2 * txtScale.Y);
            var spaceWidth = TextStyle.MeasureString(" ").X;

            var words = text.Split(' ').ToList();
            var newWordsArray = TextRenderer.ExtractLineBreaks(words);

            var m_Lines = new List<UITextEditLine>();
            TextRenderer.CalculateLines(m_Lines, newWordsArray, TextStyle, options.MaxWidth, spaceWidth, options.TopLeftIconSpace, m_LineHeight);

            var topLeft = options.Position;
            var position = topLeft;

            var result = new TextRendererResult();
            var drawCommands = new List<ITextDrawCmd>();
            result.DrawingCommands = drawCommands;

            var yPosition = topLeft.Y;
            var numLinesAdded = 0;
            for (var i = 0; i < m_Lines.Count; i++)
            {
                var lineOffset = (i*m_LineHeight < options.TopLeftIconSpace.Y) ? options.TopLeftIconSpace.X : 0;
                var line = m_Lines[i];
                var xPosition = topLeft.X+lineOffset;

                /** Alignment **/
                if (options.Alignment == TextAlignment.Center)
                {
                    xPosition += (int)Math.Round(((options.MaxWidth-lineOffset) - line.LineWidth) / 2);
                }

                var segmentPosition = target.LocalPoint(new Vector2(xPosition, yPosition));
                drawCommands.Add(new TextDrawCmd_Text
                {
                    Selected = false,
                    Text = line.Text,
                    Style = TextStyle,
                    Position = segmentPosition,
                    Scale = txtScale
                });
                numLinesAdded++;

                yPosition += m_LineHeight;
                position.Y += m_LineHeight;
            }

            result.BoundingBox = new Rectangle((int)topLeft.X, (int)topLeft.Y, (int)options.MaxWidth, (int)yPosition);
            foreach (var cmd in drawCommands)
            {
                cmd.Init();
            }

            return result;
        }
 void m_Slider_OnChange(UIElement element)
 {
     VerticalScrollPosition = (int)((UISlider)element).Value;
 }