예제 #1
0
        public void InitCanvas()
        {
            canvas = new Canvas();

            ListView listView = new ListView(new Point(20, 20), new Vector2(300, 300), new Point(10, 40), new Vector2(50, 30));
            Button   button   = new Button("Add Item", new Point(400, 20), new Vector2(80, 30), CONTENT_MANAGER.Fonts["default"]);
            Label    label    = new Label("", new Point(400, 60), new Vector2(50, 30), CONTENT_MANAGER.Fonts["default"])
            {
                Origin = new Vector2(-2, -2)
            };

            button.MouseClick += (o, e) =>
            {
                listView.AddItem(count++.ToString());
            };

            listView.ItemSelected += (o, e) =>
            {
                label.Text = e.Text;
                CONTENT_MANAGER.Log(e.Text);
            };

            canvas.AddElement("listView", listView);
            canvas.AddElement("button", button);
            canvas.AddElement("label", label);
        }
예제 #2
0
        public bool AddElement(string uiName, UIObject element, int collumn, int row)
        {
            bool throwFlag = false;

            if (collumn >= CollumnCount)
            {
                CONTENT_MANAGER.Log(string.Format("Collumn overflow : {0} at {1}", uiName ?? nameof(element), collumn));
                throwFlag = true;
            }
            if (row >= RowCount)
            {
                CONTENT_MANAGER.Log(string.Format("Row overflow : {0} at {1}", uiName ?? nameof(element), collumn));
                throwFlag = true;
            }
            if (throwFlag)
            {
                throw new ArgumentOutOfRangeException(string.Format("c: {0};r: {1}", collumn, row));
            }

            if (uiName == null || !CheckGridCellContainKey(uiName))
            {
                _cells[collumn, row].AddElement(uiName, element);
                return(true);
            }
            else
            {
                //log stuff
                CONTENT_MANAGER.Log("Duplicate UI element : " + uiName ?? nameof(element));
                return(false);
            }
        }
예제 #3
0
        /// <summary>
        /// Tells this entity to play an specific animation
        /// </summary>
        /// <param name="key">The name of the animation you want to play</param>
        public void PlayAnimation(string key)
        {
            if (string.IsNullOrEmpty(key) || !animations.ContainsKey(key))
            {
                CONTENT_MANAGER.Log(key + "not found");
                return;
            }

            //TODO find the meaning of the following code

            //if (currentAnimation != null)
            //{
            //    if (currentAnimation.Name == key)
            //    {
            //        if (animations.ContainsKey(key))
            //        {
            //            return;
            //        }
            //    }
            //}

            isPlaying = true;

            currentAnimation = animations[key];
            currentAnimation.Reset();
        }
예제 #4
0
 public void RemoveAnimation(string animationName)
 {
     if (animations.ContainsKey(animationName))
     {
         animations.Remove(animationName);
     }
     else
     {
         CONTENT_MANAGER.Log("animation doesn't exist : " + animationName);
     }
 }
예제 #5
0
 public T GetElementAs <T>(string uiName)
 {
     if (UIelements.ContainsKey(uiName))
     {
         return((T)(object)UIelements[uiName]);
     }
     else
     {
         //log stuff
         CONTENT_MANAGER.Log("UI element not found : " + uiName);
         return(default(T));
     }
 }
예제 #6
0
 public UIObject GetElement(string uiName)
 {
     if (UIelements.ContainsKey(uiName))
     {
         return(UIelements[uiName]);
     }
     else
     {
         //log stuff
         CONTENT_MANAGER.Log("UI element not found : " + uiName);
         return(null);
     }
 }
예제 #7
0
 public bool AddElement(string uiName, UIObject element)
 {
     if (uiName == null || !UIelements.ContainsKey(uiName))
     {
         UIelements.Add(uiName ?? nameof(element), element);
         element.Container = this;
         return(true);
     }
     else
     {
         //log stuff
         CONTENT_MANAGER.Log("Duplicate UI element : " + nameof(element));
         return(false);
     }
 }
예제 #8
0
 /// <summary>
 /// Helper method to add Animations to this entity
 /// </summary>
 /// <param name="animation">The Animation we want to add</param>
 public void AddAnimation(Animation animation)
 {
     // Is this Animation already in the Dictionary?
     if (!animations.ContainsKey(animation.Name))
     {
         // If not we can safely add it
         animations.Add(animation.Name, animation);
     }
     else
     {
         // Otherwise we tell are computer to yell at us
         //log stuff
         CONTENT_MANAGER.Log("duplicate animation : " + animation.Name);
     }
 }
예제 #9
0
        public override void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            try
            {
                if (Font.MeasureString(textBuffer).X <= rect.Width)
                {
                    spriteBatch.DrawString(Font, textBuffer, rect.Location.ToVector2(), foregroundColor, Rotation, origin, scale, SpriteEffects.None, LayerDepth.GuiLower);
                }
                else
                {
                    spriteBatch.DrawString(Font, temp_text, rect.Location.ToVector2(), foregroundColor, Rotation, origin, scale, SpriteEffects.None, LayerDepth.GuiLower);
                }
            }
            catch (Exception e)
            {
                CONTENT_MANAGER.Log(e.Message);
            }

            //Draw text caret
            spriteBatch.DrawString(Font, IsFocused ? isCursor_flicker ? "" : "|" : "|", rect.Location.ToVector2() + new Vector2(CursorPosition * textSpacing - 5, -2), caretColor);

            DrawingHelper.DrawRectangle(rect, BackgroundColor, true);
        }