public void LoadSprites(IconStorageObject json)
        {
            iconList2  = new List <IconReference>();
            storedList = new List <StoredIconReference>();

            if (json != null)
            {
                foreach (IconModel icon in json.Icons)
                {
                    if (icon.Tag == SpriteTypes.IconTag)
                    {
                        var newIcon = spriteModelFactory.MakeIconBase64(icon.Base64, icon.Text, icon.X, icon.Y, icon.Scale, icon.TextScale, icon.TextVisible);

                        iconList2.Add(new IconReference(newIcon, icon.Base64, 1f, true));
                        AddEventListener(mListener.Copy(), newIcon);
                    }
                }

                foreach (FolderModel icon in json.Folders)
                {
                    if (icon.Tag == SpriteTypes.FolderTag)
                    {
                        var newIcon = spriteModelFactory.MakeFolder(icon.AssetName, icon.Text, icon.X, icon.Y, icon.Scale);
                        newIcon.Tag = SpriteTypes.FolderTag;
                        iconList2.Add(new IconReference(newIcon, icon.AssetName, icon.TextScale, icon.TextVisible));
                        AddEventListener(mListener.Copy(), newIcon);
                    }
                }

                foreach (StoredIconModel icon in json.StoredIcons)
                {
                    var newIcon       = spriteModelFactory.MakeIconBase64(icon.Base64, icon.Text, icon.X, icon.Y, icon.Scale, icon.TextScale, icon.TextVisible);
                    var storedIconRef = new StoredIconReference(newIcon, icon.Base64, icon.Folder, icon.Scale, icon.TextScale, icon.TextVisible);

                    storedList.Add(storedIconRef);
                }

                SetSingleMode(json.SingleMode);
            }

            var counter = 1;

            foreach (IconReference icon in iconList2)
            {
                AddChild(icon.Sprite, counter, icon.Sprite.Tag);
                counter++;
            }
        }
        public GameLayer(float _dynamicWidth, float _dynamicHeight, IconStorageObject json, GamePage _gamePage) : base(CCColor4B.Gray)
        {
            this.Color          = CCColor3B.Gray;
            this.GamePageParent = _gamePage;
            this.mRandom        = new Random(DateTime.Now.Millisecond);

            spriteModelFactory = new SpriteMaker(_dynamicWidth, _dynamicHeight);

            MakeListener();

            MakeStaticSprites();

            LoadSprites(json);

            Schedule(RunGameLogic);
        }
Exemple #3
0
        public void ConstructGameScene(CCGameView nativeGameView)
        {
            gameScene = new CCScene(nativeGameView);

            string json = GetBoards("IconBoard");

            IconStorageObject jsonObject = null;

            if (json != "")
            {
                try
                {
                    jsonObject = JsonConvert.DeserializeObject <IconStorageObject>(json);
                }
                catch
                {
                    jsonObject = null;
                }
            }

            mLayer = new GameLayer(width, height, jsonObject, this);

            gameScene.AddLayer(mLayer);
        }
        public static CCScene GameStartLayerScene(CCGameView mainWindow, float _dynamicWidth, float _dynamicHeight, string json, GamePage gamePage)
        {
            var scene = new CCScene(mainWindow);

            IconStorageObject jsonObject = null;

            if (json != "")
            {
                try
                {
                    jsonObject = JsonConvert.DeserializeObject <IconStorageObject>(json);
                }
                catch
                {
                    jsonObject = null;
                }
            }

            var layer = new GameLayer(_dynamicWidth, _dynamicHeight, jsonObject, gamePage);

            scene.AddLayer(layer);

            return(scene);
        }
Exemple #5
0
        public void SaveBoards(List <IconReference> icons, List <StoredIconReference> storedIcons, bool inSingleMode)
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                List <IconModel> mJsonIconArray             = new List <IconModel>();
                List <FolderModel> mJsonFolderArray         = new List <FolderModel>();
                List <StoredIconModel> mJsonStoredIconArray = new List <StoredIconModel>();

                foreach (IconReference iconRef in icons)
                {
                    if (iconRef.Sprite.Tag == SpriteTypes.IconTag)
                    {
                        var mModel = new IconModel("", "", 0, 0, -1, iconRef.Sprite.ScaleX);

                        var spriteLabel = iconRef.Sprite.GetChildByTag(SpriteTypes.ContentTag) as CCLabel;

                        if (spriteLabel != null)
                        {
                            mModel.Text = spriteLabel.Text;
                        }

                        mModel.Base64      = iconRef.Base64;
                        mModel.X           = (int)iconRef.Sprite.PositionX;
                        mModel.Y           = (int)iconRef.Sprite.PositionY;
                        mModel.Tag         = iconRef.Sprite.Tag;
                        mModel.TextScale   = spriteLabel.ScaleX;
                        mModel.TextVisible = spriteLabel.Visible;

                        mJsonIconArray.Add(mModel);
                    }
                    else if (iconRef.Sprite.Tag == SpriteTypes.FolderTag)
                    {
                        var mModel = new FolderModel("", "", 0, 0, -1, iconRef.Sprite.ScaleX);

                        var spriteLabel = iconRef.Sprite.GetChildByTag(SpriteTypes.ContentTag) as CCLabel;

                        if (spriteLabel != null)
                        {
                            mModel.Text = spriteLabel.Text;
                        }

                        mModel.AssetName   = iconRef.Base64;
                        mModel.X           = (int)iconRef.Sprite.PositionX;
                        mModel.Y           = (int)iconRef.Sprite.PositionY;
                        mModel.Tag         = iconRef.Sprite.Tag;
                        mModel.TextScale   = spriteLabel.ScaleX;
                        mModel.TextVisible = spriteLabel.Visible;

                        mJsonFolderArray.Add(mModel);
                    }
                }

                foreach (StoredIconReference mStoredRef in storedIcons)
                {
                    var mModel = new StoredIconModel("", "", 0, 0, -1, mStoredRef.Base64, mStoredRef.Sprite.ScaleX);

                    var spriteLabel = mStoredRef.Sprite.GetChildByTag(SpriteTypes.ContentTag) as CCLabel;

                    if (spriteLabel != null)
                    {
                        mModel.Text = spriteLabel.Text;
                    }

                    mModel.Base64      = mStoredRef.Base64;
                    mModel.Folder      = mStoredRef.FolderName;
                    mModel.X           = (int)mStoredRef.Sprite.PositionX;
                    mModel.Y           = (int)mStoredRef.Sprite.PositionY;
                    mModel.Tag         = mStoredRef.Sprite.Tag;
                    mModel.TextScale   = spriteLabel.ScaleX;
                    mModel.TextVisible = spriteLabel.Visible;

                    mJsonStoredIconArray.Add(mModel);
                }

                var mIconStorage         = new IconStorageObject();
                mIconStorage.Icons       = mJsonIconArray;
                mIconStorage.Folders     = mJsonFolderArray;
                mIconStorage.StoredIcons = mJsonStoredIconArray;
                mIconStorage.SingleMode  = inSingleMode;

                var mJsonString = JsonConvert.SerializeObject(mIconStorage);

                Console.WriteLine("saved!");

                DependencyService.Get <ISaveAndLoad>().SaveJSON("IconBoard", mJsonString);
            });
        }