Exemple #1
0
        public DisplayBar(Vector2 a_dimensions, int a_border, Color a_color)
        {
            _border = a_border;
            _color  = a_color;

            _bar           = new Asset2D("Assets\\UI\\solid", new Vector2(0, 0), new Vector2(a_dimensions.X - _border * 2, a_dimensions.Y - _border * 2));
            _barBackground = new Asset2D("Assets\\UI\\shade", new Vector2(0, 0), new Vector2(a_dimensions.X, a_dimensions.Y));
        }
Exemple #2
0
        public UI(PassObject a_resetWorld, PassObject a_changeGameState)
        {
            _font = Globals.MyContent.Load <SpriteFont>("Fonts\\Arial16");

            _pauseOverlay   = new Asset2D("Assets\\UI\\pause_overlay", new Vector2(Globals.ScreenWidth / 2, Globals.ScreenHeight / 2), new Vector2(300, 300));
            _resetButton    = new Button("Assets\\UI\\simple_button", new Vector2(0, 0), new Vector2(96, 32), "Fonts\\Arial16", "Restart", a_resetWorld, null);
            _mainMenuButton = new Button("Assets\\UI\\simple_button", new Vector2(0, 0), new Vector2(96, 32), "Fonts\\Arial16", "Main menu", a_changeGameState, null);

            _healthBar  = new Engine.Output.DisplayBar(new Vector2(154, 20), 3, Color.Red);
            _staminaBar = new Engine.Output.DisplayBar(new Vector2(154, 20), 3, Color.Yellow);
        }
        public ActionResult Publish(AssetImages model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Publish", model));
            }
            model.asset.Publisher   = User.Identity.Name;
            model.asset.ReleaseDate = DateTime.Now.ToString();
            if (!model.File.FileName.EndsWith("rar") && !model.File.FileName.EndsWith("zip"))
            {
                return(View("Publish", model));
            }
            string[] formats = new string[] { ".jpg", ".png", ".jpeg" };
            bool     Wrong   = true;

            foreach (var image in model.Files)
            {
                foreach (var item in formats)
                {
                    if (image.FileName.Contains(item))
                    {
                        Wrong = false;
                        break;
                    }
                }
            }
            if (Wrong)
            {
                return(View("Publish", model));
            }

            foreach (var file in model.Files)
            {
                if (file == null)
                {
                    //at least 1 photo per asset
                    return(View(model));
                }
                else if (file.ContentLength > 0)
                {
                    Picture c = new Picture();
                    c.ImageData = new byte[file.ContentLength];
                    file.InputStream.Read(c.ImageData, 0, c.ImageData.Length);

                    _photoContext.AssetsPhotos.Add(c);
                    _photoContext.SaveChanges();
                    if (model.asset.imagesId == null)
                    {
                        model.asset.imagesId = c.Id.ToString();
                    }
                    else
                    {
                        model.asset.imagesId += "," + c.Id.ToString();
                    }
                }
            }

            if (model.File.ContentLength > 0)
            {
                MemoryStream target = new MemoryStream();
                model.File.InputStream.CopyTo(target);
                byte[] data = target.ToArray();
                model.asset.assetZip = data;
            }
            model.asset.Size = model.asset.assetZip.Count() / 1048576f;

            //////
            if (model.asset.Type == "2D")
            {
                Asset2D asset2D = new Asset2D(model.asset);
                _context.Assets2D.Add(asset2D);
            }
            else if (model.asset.Type == "3D")
            {
                Asset3D asset3D = new Asset3D(model.asset);
                _context.Assets3D.Add(asset3D);
            }
            else if (model.asset.Type == "Audio")
            {
                AssetAudio assetAudio = new AssetAudio(model.asset);
                _context.AssetsAudio.Add(assetAudio);
            }
            else if (model.asset.Type == "Tools")
            {
                AssetTools assetTools = new AssetTools(model.asset);
                _context.AssetsTools.Add(assetTools);
            }
            else
            {
                return(HttpNotFound());
            }

            try
            {
                _context.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                    eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                        ve.PropertyName, ve.ErrorMessage);
                    }
                }
                Debug.WriteLine(model.asset.Type);
            }


            AllAssets allAssets = new AllAssets();

            allAssets.assets2D    = _context.Assets2D.ToList();
            allAssets.assets3D    = _context.Assets3D.ToList();
            allAssets.assetsAudio = _context.AssetsAudio.ToList();
            allAssets.assetsTools = _context.AssetsTools.ToList();

            return(RedirectToAction("Index", allAssets));
        }