Exemplo n.º 1
0
        public CSFolder GetCreateSubfolder(String name)
        {
            for (int i = 0; i < Tiles.Count; i++)
            {
                if (Tiles[i] is CSFolder && Tiles[i].Text == name)
                {
                    return(Tiles[i] as CSFolder);
                }
            }
            CSFolder f = new CSFolder();

            f.Text = name;
            if (ComponentSelector.folderTextures.ContainsKey(f.Text))
            {
                Texture = ResourceManager.Load <Texture2D>(ComponentSelector.folderTextures[f.Text]);
            }
            else
            {
                Texture = GraphicsEngine.pixel;
            }
            f.position   = new Vector2(4 + position.X + 40, position.Y + Tiles.Count * 40);
            f.parent     = null;
            f.localIndex = Tiles.Count;
            f.isVisible  = true;
            f.Color      = Color.White;
            GUIEngine.s_componentSelector.allTiles.Add(f);
            Tiles.Add(f);
            return(f);
        }
Exemplo n.º 2
0
        public bool LoadStructure(System.IO.BinaryReader br)
        {
            String s = "";

            while (true)
            {
                s = br.ReadString();
                if (s.StartsWith("0"))//CSC
                {
                    var a = GUIEngine.s_componentSelector._getComponent(s.Substring(1));
                    if (a == null)
                    {
                        return(false);
                    }
                    GUIEngine.s_componentSelector.AddComponent(this, a);
                    continue;
                }
                if (s.StartsWith("1"))//CSF
                {
                    CSFolder f = GetCreateSubfolder(s.Substring(1));

                    if (!f.LoadStructure(br))
                    {
                        return(false);
                    }
                    continue;
                }
                if (s.StartsWith("2"))//folder end
                {
                    break;
                }
            }

            return(true);
        }
Exemplo n.º 3
0
        public Vector2 TilePosition(String t)
        {
            var a = t.Split('/');

            if (a.Length == 1)
            {
                foreach (var c in rootTiles)
                {
                    if (c is CSComponentCopy && c.Text == t)
                    {
                        return(c.Position);
                    }
                }
                return(new Vector2(-1, -1));
            }
            CSFolder cur = null;

            foreach (var c in rootTiles)
            {
                if (c is CSFolder && c.Text == a[0] && (c as CSFolder).IsOpened)
                {
                    cur = c as CSFolder;
                    break;
                }
            }
            if (cur == null)
            {
                return(new Vector2(-1, -1));
            }
            bool found = false;

            for (int i = 1; i < a.Length - 1; i++)
            {
                found = false;
                for (int j = 0; j < cur.Tiles.Count; j++)
                {
                    if (cur.Tiles[j] is CSFolder && cur.Tiles[j].Text == a[i] && (cur as CSFolder).IsOpened)
                    {
                        cur   = cur.Tiles[j] as CSFolder;
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    return(new Vector2(-1, -1));
                }
            }
            for (int i = 0; i < cur.Tiles.Count; i++)
            {
                if (cur.Tiles[i] is CSComponentCopy && cur.Tiles[i].Text == a[a.Length - 1])
                {
                    return(cur.Tiles[i].Position);
                }
            }
            return(new Vector2(-1, -1));
        }
Exemplo n.º 4
0
        public CSComponentCopy TileExists(String t)
        {
            var a = t.Split('/');

            if (a.Length == 1)
            {
                foreach (var c in rootTiles)
                {
                    if (c is CSComponentCopy && c.Text == t)
                    {
                        return(c as CSComponentCopy);
                    }
                }
                return(null);
            }
            CSFolder cur = null;

            foreach (var c in rootTiles)
            {
                if (c is CSFolder && c.Text == a[0])
                {
                    cur = c as CSFolder;
                    break;
                }
            }
            if (cur == null)
            {
                return(null);
            }
            bool found = false;

            for (int i = 1; i < a.Length - 1; i++)
            {
                found = false;
                for (int j = 0; j < cur.Tiles.Count; j++)
                {
                    if (cur.Tiles[j] is CSFolder && cur.Tiles[j].Text == a[i])
                    {
                        cur   = cur.Tiles[j] as CSFolder;
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    return(null);
                }
            }
            for (int i = 0; i < cur.Tiles.Count; i++)
            {
                if (cur.Tiles[i] is CSComponentCopy && cur.Tiles[i].Text == a[a.Length - 1])
                {
                    return(cur.Tiles[i] as CSComponentCopy);
                }
            }
            return(null);
        }
Exemplo n.º 5
0
 public CSTile(CSTile t)
 {
     localIndex    = t.localIndex;
     parent        = t.parent;
     texture       = t.texture;
     text          = t.text;
     color         = t.color;
     onTileClicked = t.onTileClicked;
 }
Exemplo n.º 6
0
 public CSTile(CSTile t)
 {
     localIndex = t.localIndex;
     parent = t.parent;
     texture = t.texture;
     text = t.text;
     color = t.color;
     onTileClicked = t.onTileClicked;
 }
Exemplo n.º 7
0
        public void RemoveFav()
        {
            CSFolder f = GUIEngine.s_componentSelector.GetFavFolder();

            if (f == null)
            {
                return;
            }
            GUIEngine.s_componentSelector.RemoveComponent(f, this);
        }
Exemplo n.º 8
0
        public void AddFav()
        {
            CSFolder f = GUIEngine.s_componentSelector.GetFavFolder();

            if (f == null)
            {
                f = GUIEngine.s_componentSelector.AddRootFolder("Favourite");
            }
            GUIEngine.s_componentSelector.AddComponent(f, this);
        }
Exemplo n.º 9
0
        public String GetFullPath()
        {
            String   r   = Text;
            CSFolder cur = parent;

            while (cur != null)
            {
                r   = cur.Text + "/" + r;
                cur = cur.parent;
            }
            return(r);
        }
Exemplo n.º 10
0
 public void RemoveComponent(CSFolder parent, CSComponent component)
 {
     if (parent == null)
     {
         for (int i = 0; i < rootTiles.Count; i++)
         {
             if (rootTiles[i] is CSComponentCopy && (rootTiles[i] as CSComponentCopy).component == component)
             {
                 if (rootTiles[i].position == selectedComponent.position)
                 {
                     ResetSelection();
                 }
                 allTiles.Remove(rootTiles[i]);
                 rootTiles.RemoveAt(i);
                 break;
             }
         }
         for (int i = 0; i < rootTiles.Count; i++)
         {
             rootTiles[i].localIndex = i;
         }
     }
     else
     {
         for (int i = 0; i < parent.Tiles.Count; i++)
         {
             if (parent.Tiles[i] is CSComponentCopy && (parent.Tiles[i] as CSComponentCopy).component == component)
             {
                 if (parent.Tiles[i].position == selectedComponent.position)
                 {
                     ResetSelection();
                 }
                 allTiles.Remove(parent.Tiles[i]);
                 parent.Tiles.RemoveAt(i);
                 break;
             }
         }
         for (int i = 0; i < parent.Tiles.Count; i++)
         {
             parent.Tiles[i].localIndex = i;
         }
     }
 }
Exemplo n.º 11
0
        public void AddComponent(CSFolder parent, CSComponent component)
        {
            var copy = new CSComponentCopy(component);

            copy.parent = parent;
            if (parent == null)
            {
                copy.Position   = new Vector2(4, 4 + rootTiles.Count * 40);
                copy.localIndex = rootTiles.Count;
                copy.isVisible  = true;
                rootTiles.Add(copy);
            }
            else
            {
                copy.Position   = new Vector2(6 + parent.position.X + 40, 4 + parent.Tiles.Count * 40);
                copy.localIndex = parent.Tiles.Count;
                copy.isVisible  = false;
                parent.Tiles.Add(copy);
            }
            copy.Color = Color.White;
            allTiles.Add(copy);
        }
Exemplo n.º 12
0
        public CSFolder AddRootFolder(String text)
        {
            var f = new CSFolder();

            f.Text = text;
            if (folderTextures.ContainsKey(f.Text))
            {
                f.Texture = ResourceManager.Load <Texture2D>(folderTextures[f.Text]);
            }
            else
            {
                f.Texture = GraphicsEngine.pixel;
            }
            f.Position   = new Vector2(4, 4 + rootTiles.Count * 40);
            f.parent     = null;
            f.localIndex = rootTiles.Count;
            f.isVisible  = true;
            f.Color      = Color.White;
            allTiles.Add(f);
            rootTiles.Add(f);
            return(f);
        }
Exemplo n.º 13
0
        public Rectangle[] GetClickabilityRectangles()
        {
            List <Rectangle> t   = new List <Rectangle>();
            CSFolder         cur = null;

            for (int i = 0; i < clickable.Count; i++)
            {
                if (clickable[i].isVisible)
                {
                    t.Add(new Rectangle((int)clickable[i].position.X, (int)clickable[i].position.Y, CSTile.SIZE_X + 2, CSTile.SIZE_Y + 2));
                }
                cur = clickable[i].parent;
                while (cur != null)
                {
                    if (cur.isVisible)
                    {
                        t.Add(new Rectangle((int)cur.position.X, (int)cur.position.Y, CSTile.SIZE_X + 2, CSTile.SIZE_Y + 2));
                    }
                    cur = cur.parent;
                }
            }
            return(t.ToArray());
        }
Exemplo n.º 14
0
 public CSFolder GetCreateSubfolder(String name)
 {
     for (int i = 0; i < Tiles.Count; i++)
     {
         if (Tiles[i] is CSFolder && Tiles[i].Text == name)
         {
             return Tiles[i] as CSFolder;
         }
     }
     CSFolder f = new CSFolder();
     f.Text = name;
     if (ComponentSelector.folderTextures.ContainsKey(f.Text))
         Texture = ResourceManager.Load<Texture2D>(ComponentSelector.folderTextures[f.Text]);
     else
         Texture = GraphicsEngine.pixel;
     f.position = new Vector2(4 + position.X + 40, position.Y + Tiles.Count * 40);
     f.parent = null;
     f.localIndex = Tiles.Count;
     f.isVisible = true;
     f.Color = Color.White;
     GUIEngine.s_componentSelector.allTiles.Add(f);
     Tiles.Add(f);
     return f;
 }
Exemplo n.º 15
0
 public void RemoveComponent(CSFolder parent, CSComponent component)
 {
     if (parent == null)
     {
         for (int i = 0; i < rootTiles.Count; i++)
         {
             if (rootTiles[i] is CSComponentCopy && (rootTiles[i] as CSComponentCopy).component == component)
             {
                 if (rootTiles[i].position == selectedComponent.position)
                     ResetSelection();
                 allTiles.Remove(rootTiles[i]);
                 rootTiles.RemoveAt(i);
                 break;
             }
         }
         for (int i = 0; i < rootTiles.Count; i++)
         {
             rootTiles[i].localIndex = i;
         }
     }
     else
     {
         for (int i = 0; i < parent.Tiles.Count; i++)
         {
             if (parent.Tiles[i] is CSComponentCopy && (parent.Tiles[i] as CSComponentCopy).component == component)
             {
                 if (parent.Tiles[i].position == selectedComponent.position)
                     ResetSelection();
                 allTiles.Remove(parent.Tiles[i]);
                 parent.Tiles.RemoveAt(i);
                 break;
             }
         }
         for (int i = 0; i < parent.Tiles.Count; i++)
         {
             parent.Tiles[i].localIndex = i;
         }
     }
 }
Exemplo n.º 16
0
        public bool LoadStructure()
        {
            IO.Log.Write("        CS load structure");
            rootTiles.Clear();
            allTiles.Clear();

            if (!Directory.Exists("Saves")) return false;
            if (!File.Exists("Saves/cs.prf")) return false;

            IO.Log.Write("        Reading from file...");
            BinaryReader br = new BinaryReader(new FileStream("Saves/cs.prf", FileMode.Open));
            int t = br.ReadInt32();
            IO.Log.Write("        " + t.ToString() + " components in checksum");
            if (t != components.Count)
            {
                br.Close();
                return false;
            }

            String s = "";
            while (true)
            {
                s = br.ReadString();
                if (s.StartsWith("0"))//CSC
                {
                    var a = _getComponent(s.Substring(1));
                    if (a == null)
                    {
                        br.Close();
                        return false;
                    }
                    AddComponent(null, a);
                    continue;
                }
                if (s.StartsWith("1"))//CSF
                {
                    CSFolder f = new CSFolder();
                    f.Text = s.Substring(1);
                    if (ComponentSelector.folderTextures.ContainsKey(f.Text))
                        f.Texture = ResourceManager.Load<Texture2D>(ComponentSelector.folderTextures[f.Text]);
                    else
                        f.Texture = GraphicsEngine.pixel;
                    f.position = new Vector2(4, 4 + rootTiles.Count * 40);
                    f.parent = null;
                    f.localIndex = rootTiles.Count;
                    f.isVisible = true;
                    f.Color = Color.White;
                    rootTiles.Add(f);
                    allTiles.Add(f);

                    if (!f.LoadStructure(br))
                    {
                        br.Close();
                        return false;
                    }
                    continue;
                }
                if (s.StartsWith("3"))//file end
                    break;
            }

            br.Close();
            //scan fav folder
            IO.Log.Write("        Scanning for favourites");
            CSFolder fav = GetFavFolder();
            if (fav != null)
            {
                for (int i = 0; i < fav.Tiles.Count; i++)
                {
                    for (int j = 0; j < components.Count; j++)
                    {
                        if (components[j].Text == fav.Tiles[i].Text)
                        {
                            components[j].isFavourite = true;
                        }
                    }
                }
            }

            return true;
        }
Exemplo n.º 17
0
 public CSFolder AddRootFolder(String text)
 {
     var f = new CSFolder();
     f.Text = text;
     if (folderTextures.ContainsKey(f.Text))
         f.Texture = ResourceManager.Load<Texture2D>(folderTextures[f.Text]);
     else
         f.Texture = GraphicsEngine.pixel;
     f.Position = new Vector2(4, 4 + rootTiles.Count * 40);
     f.parent = null;
     f.localIndex = rootTiles.Count;
     f.isVisible = true;
     f.Color = Color.White;
     allTiles.Add(f);
     rootTiles.Add(f);
     return f;
 }
Exemplo n.º 18
0
 public void AddComponent(CSFolder parent, CSComponent component)
 {
     var copy = new CSComponentCopy(component);
     copy.parent = parent;
     if (parent == null)
     {
         copy.Position = new Vector2(4, 4 + rootTiles.Count * 40);
         copy.localIndex = rootTiles.Count;
         copy.isVisible = true;
         rootTiles.Add(copy);
     }
     else
     {
         copy.Position = new Vector2(6 + parent.position.X + 40, 4 + parent.Tiles.Count * 40);
         copy.localIndex = parent.Tiles.Count;
         copy.isVisible = false;
         parent.Tiles.Add(copy);
     }
     copy.Color = Color.White;
     allTiles.Add(copy);
 }
Exemplo n.º 19
0
        public bool LoadStructure()
        {
            IO.Log.Write("        CS load structure");
            rootTiles.Clear();
            allTiles.Clear();

            if (!Directory.Exists("Saves"))
            {
                return(false);
            }
            if (!File.Exists("Saves/cs.prf"))
            {
                return(false);
            }

            IO.Log.Write("        Reading from file...");
            BinaryReader br = new BinaryReader(new FileStream("Saves/cs.prf", FileMode.Open));
            int          t  = br.ReadInt32();

            IO.Log.Write("        " + t.ToString() + " components in checksum");
            if (t != components.Count)
            {
                br.Close();
                return(false);
            }

            String s = "";

            while (true)
            {
                s = br.ReadString();
                if (s.StartsWith("0"))//CSC
                {
                    var a = _getComponent(s.Substring(1));
                    if (a == null)
                    {
                        br.Close();
                        return(false);
                    }
                    AddComponent(null, a);
                    continue;
                }
                if (s.StartsWith("1"))//CSF
                {
                    CSFolder f = new CSFolder();
                    f.Text = s.Substring(1);
                    if (ComponentSelector.folderTextures.ContainsKey(f.Text))
                    {
                        f.Texture = ResourceManager.Load <Texture2D>(ComponentSelector.folderTextures[f.Text]);
                    }
                    else
                    {
                        f.Texture = GraphicsEngine.pixel;
                    }
                    f.position   = new Vector2(4, 4 + rootTiles.Count * 40);
                    f.parent     = null;
                    f.localIndex = rootTiles.Count;
                    f.isVisible  = true;
                    f.Color      = Color.White;
                    rootTiles.Add(f);
                    allTiles.Add(f);

                    if (!f.LoadStructure(br))
                    {
                        br.Close();
                        return(false);
                    }
                    continue;
                }
                if (s.StartsWith("3"))//file end
                {
                    break;
                }
            }

            br.Close();
            //scan fav folder
            IO.Log.Write("        Scanning for favourites");
            CSFolder fav = GetFavFolder();

            if (fav != null)
            {
                for (int i = 0; i < fav.Tiles.Count; i++)
                {
                    for (int j = 0; j < components.Count; j++)
                    {
                        if (components[j].Text == fav.Tiles[i].Text)
                        {
                            components[j].isFavourite = true;
                        }
                    }
                }
            }

            return(true);
        }
Exemplo n.º 20
0
        public void GenerateStructure()
        {
            IO.Log.Write("        CS genereting structure");
            if (LoadStructure())//load saved settings. sorts if can't load
            {
                return;
            }

            allTiles.Clear();
            rootTiles.Clear();

            String path = "";

            for (int i = 0; i < components.Count; i++)
            {
                path = components[i].componentGraphics.GetComponentSelectorPath();
                if (path == null)
                {
                    AddComponent(null, components[i]);
                }
                else
                {
                    var ps = path.Split(':');
                    foreach (var p2 in ps)
                    {
                        String p = p2;
                        if (p.EndsWith("/"))
                        {
                            p = p.Substring(0, p.Length - 1);
                        }
                        if (p.Length == 0)
                        {
                            AddComponent(null, components[i]);
                        }
                        else
                        {
                            var      a         = p.Split('/');
                            CSFolder curFolder = null;
                            for (int j = 0; j < rootTiles.Count; j++)
                            {
                                if (rootTiles[j].Text == a[0] && rootTiles[j] is CSFolder)
                                {
                                    curFolder = rootTiles[j] as CSFolder;
                                }
                            }
                            if (curFolder == null)
                            {
                                curFolder = AddRootFolder(a[0]);
                            }
                            for (int j = 1; j < a.Length; j++)
                            {
                                curFolder = curFolder.GetCreateSubfolder(a[j]);
                            }
                            AddComponent(curFolder, components[i]);
                            //curFolder.Tiles.Add(components[i]);
                        }
                    }
                }
            }
            AddRootFolder("Favourite");

            Sort();
            SaveStructure();
        }