Exemple #1
0
        static void Main(string[] args)
        {
            TUI.TUI.Initialize();
            UIPlayer me = new UIPlayer();

            TUI.TUI.InitializePlayer(me.Index);
            RootVisualObject root = TUI.TUI.Create(new RootVisualObject("Game", 55, 115, 50, 40));

            root.SetupGrid(new ISize[] { new Relative(100), new Absolute(20) }, new ISize[] { new Absolute(20), new Relative(100) }, new Indent()
            {
                Right = 1
            });
            TUI.TUI.Update();
            TUI.TUI.Touched(me.Index, new Touch(124, 110, TouchState.Begin, 0, 0));
            TUI.TUI.Touched(me.Index, new Touch(125, 110, TouchState.Moving, 0, 0));
            TUI.TUI.Touched(me.Index, new Touch(124, 110, TouchState.Moving, 0, 0));
            TUI.TUI.Touched(me.Index, new Touch(125, 110, TouchState.Moving, 0, 0));
            TUI.TUI.Touched(me.Index, new Touch(124, 110, TouchState.End, 0, 0));
            TUI.TUI.Touched(me.Index, new Touch(124, 110, TouchState.Begin, 0, 0));
            TUI.TUI.Touched(me.Index, new Touch(125, 110, TouchState.Moving, 0, 0));
            TUI.TUI.Touched(me.Index, new Touch(124, 110, TouchState.Moving, 0, 0));
            TUI.TUI.Touched(me.Index, new Touch(125, 110, TouchState.Moving, 0, 0));
            TUI.TUI.Touched(me.Index, new Touch(124, 110, TouchState.End, 0, 0));
            //game.Remove(game["lol"]);
            //UI.Touched(me, new Touch(24, 10, TouchState.Begin, session));
        }
Exemple #2
0
        /// <summary>
        /// Create user interface tree and add it to TUI.
        /// </summary>
        /// <param name="root">Root of user interface tree.
        /// <para></para>
        /// Consider using Panel widget for ability to automatically save position and size.</param>
        public static RootVisualObject Create(RootVisualObject root)
        {
            if (!(root.Provider is MainTileProvider) &&
                (root.Width > root.Provider.Width || root.Height > root.Provider.Height))
            {
                throw new ArgumentException("Provider size is less than RootVisualObject size: " + root.FullName);
            }

            // Locking for Child and Active
            lock (Child)
            {
                if (Child.Count(r => r.Name == root.Name) > 0)
                {
                    throw new ArgumentException($"TUI.Create: name {root.Name} is already taken.");
                }

                int index = Child.Count;
                while (index > 0 && Child[index - 1].Layer > root.Layer)
                {
                    index--;
                }
                Child.Insert(index, root);

                if (Active)
                {
                    root.Load();
                }
            }
            return(root);
        }
Exemple #3
0
        public static bool SetTop(RootVisualObject root)
        {
            lock (Child)
            {
                int previousIndex = Child.IndexOf(root);
                int index         = previousIndex;
                if (index < 0)
                {
                    throw new InvalidOperationException("Trying to SetTop an object that isn't a child of current VisualDOM");
                }
                int count = Child.Count;
                index++;
                while (index < count && Child[index].Layer <= root.Layer)
                {
                    index++;
                }

                if (index == previousIndex + 1)
                {
                    return(false);
                }

                Child.Remove(root);
                Child.Insert(index - 1, root);

                if (!root.UsesDefaultMainProvider)
                {
                    root.Provider.Collection.SetTop(root.Provider.Key);
                }

                return(true);
            }
        }
Exemple #4
0
 public SetXYWHArgs(RootVisualObject root, int x, int y, int width, int height)
 {
     Root   = root;
     X      = x;
     Y      = y;
     Width  = width;
     Height = height;
 }
Exemple #5
0
        public static void TUIPanelCommand(CommandArgs args)
        {
            if (args.Parameters.Count != 1 && args.Parameters.Count != 3 && args.Parameters.Count != 5)
            {
                args.Player.SendErrorMessage("Usage: /tuipanel <panel name> [<x> <y>] [<width> <height>]");
                return;
            }

            RootVisualObject root = TUI.TUI.GetRoots().Where(r => r.Name == args.Parameters[0]).FirstOrDefault();

            if (root == null)
            {
                args.Player.SendErrorMessage("Invalid panel name: " + args.Parameters[0]);
                return;
            }

            if (args.Parameters.Count == 1)
            {
                args.Player.SendInfoMessage("Panel position and size: " + root.XYWH());
                return;
            }

            int x;
            int y;

            if (!Int32.TryParse(args.Parameters[1], out x) || !Int32.TryParse(args.Parameters[2], out y) ||
                x < 0 || y < 0 || x >= Main.maxTilesX || y >= Main.maxTilesY)
            {
                args.Player.SendErrorMessage("Invalid panel coordinates: " + args.Parameters[1] + ", " + args.Parameters[2]);
                return;
            }

            int width  = root.Width;
            int height = root.Height;

            if (args.Parameters.Count == 5 &&
                (!Int32.TryParse(args.Parameters[3], out width) || !Int32.TryParse(args.Parameters[4], out height) ||
                 width < 0 || height < 0 || width >= Main.maxTilesX || height >= Main.maxTilesY))
            {
                args.Player.SendErrorMessage("Invalid panel size: " + args.Parameters[3] + ", " + args.Parameters[4]);
                return;
            }

            if (root is Panel panel)
            {
                panel.Drag(x, y);
                if (width != panel.Width || height != panel.Height)
                {
                    panel.Resize(width, height);
                }
            }
            else
            {
                root.Clear().Draw().SetXYWH(x, y, width, height).Update().Apply().Draw();
            }

            args.Player.SendSuccessMessage(root.Name + " new position and size: " + root.XYWH());
        }
Exemple #6
0
 public static void PostSetTop(RootVisualObject child)
 {
     // Should not apply if intersecting objects have different tile provider
     (bool intersects, bool needsApply) = ChildIntersectingOthers(child);
     if (intersects)
     {
         if (needsApply)
         {
             child.Apply();
         }
         child.Draw();
     }
 }
Exemple #7
0
        public static (bool intersects, bool needsApply) ChildIntersectingOthers(RootVisualObject o)
        {
            bool intersects = false;

            foreach (RootVisualObject child in Child)
            {
                if (child != o && child.Active && o.Intersecting(child))
                {
                    intersects = true;
                    dynamic provider1 = o.Provider.Tile;
                    dynamic provider2 = child.Provider.Tile;
                    if (provider1.GetType() == provider2.GetType() && provider1 == provider2)
                    {
                        return(true, true);
                    }
                }
            }
            return(intersects, false);
        }
Exemple #8
0
 public static bool TouchedChild(Touch touch, ref bool insideUI)
 {
     lock (Child)
         for (int i = Child.Count - 1; i >= 0; i--)
         {
             RootVisualObject o = Child[i];
             int saveX = o.X, saveY = o.Y;
             if (o.Active && o.Contains(touch) && o.Players.Contains(touch.Session.PlayerIndex))
             {
                 insideUI = true;
                 touch.MoveBack(saveX, saveY);
                 if (o.Touched(touch))
                 {
                     if (SetTop(o))
                     {
                         PostSetTop(o);
                     }
                     return(true);
                 }
                 touch.Move(saveX, saveY);
             }
         }
     return(false);
 }
Exemple #9
0
 public EnabledArgs(RootVisualObject root, bool value)
 {
     Root  = root;
     Value = value;
 }
Exemple #10
0
 public static void Destroy(RootVisualObject obj)
 {
     lock (Child)
         Child.Remove(obj);
 }
Exemple #11
0
 public SetTopArgs(RootVisualObject root)
 {
     Root = root;
 }