Ejemplo n.º 1
0
        private void AddItems(Skin skin)
        {
            var textButtonStyle = new ImageButtonStyle
            {
                Up             = new PrimitiveDrawable(Color.DarkGray, 6, 2),
                Over           = new PrimitiveDrawable(Color.DimGray),
                Down           = new PrimitiveDrawable(Color.DimGray),
                PressedOffsetX = 0,
                PressedOffsetY = 0
            };

            int count = 0;

            foreach (var i in LoginManagerClient.GetCharacter().Equipment)
            {
                float f = GetWidth();
                if (count % 5 == 0)
                {
                    Row();
                }
                if (i != null && i.GetSprite() == null)
                {
                    i.SetSprite(TextureContainer.GetSpriteAtlasByName("Items").GetSprite(i.TextureName));
                }

                if (i != null)
                {
                    SpriteDrawable    spd = new SpriteDrawable(i.GetSprite());
                    NinePatchDrawable ninePatchDrawable = new NinePatchDrawable(i.GetSprite(), 0, 0, 0, 0)
                    {
                        MinHeight = 48, MinWidth = 48
                    };

                    ItemButton imButton = new ItemButton(ninePatchDrawable, count, i);

                    imButton.SetTouchable(Touchable.Enabled);
                    imButton.OnHovered += delegate { OnHovered(imButton, i, skin, stage); };
                    imButton.OnExited  += delegate { OnExit(imButton, stage); };
                    imButton.OnMoved   += delegate { OnMovedAndHovered(imButton); };
                    imButton.OnClicked += delegate { OnClickedCharacter(imButton); };
                    Add(imButton).Size(48, 48).Pad(4).Expand();
                }
                else
                {
                    ItemButton imButton = new ItemButton(textButtonStyle, count, null);
                    imButton.Add(new Label("")).Expand().Left().SetAlign(Nez.UI.Align.BottomLeft);
                    imButton.SetTouchable(Touchable.Disabled);
                    Add(imButton).Size(48, 48).Pad(4).Expand();
                }
                count++;
            }
        }
Ejemplo n.º 2
0
        public ISceneDrawable NewDrawable(ISceneDrawable drawable, Xna.Color tint)
        {
            if (drawable is TextureRegionDrawable)
            {
                TextureRegion region = (drawable as TextureRegionDrawable).Region;
                Sprite        sprite;
                if (region is TextureAtlas.AtlasRegion)
                {
                    sprite = new TextureAtlas.AtlasSprite(region as TextureAtlas.AtlasRegion);
                }
                else
                {
                    sprite = new Sprite(region);
                }

                sprite.Color = tint;
                return(new SpriteDrawable(sprite));
            }

            if (drawable is NinePatchDrawable)
            {
                NinePatchDrawable patchDrawable = new NinePatchDrawable(drawable as NinePatchDrawable);
                patchDrawable.Patch = new NinePatch(patchDrawable.Patch, tint);
                return(patchDrawable);
            }

            if (drawable is SpriteDrawable)
            {
                SpriteDrawable spriteDrawable = new SpriteDrawable(drawable as SpriteDrawable);
                Sprite         sprite         = spriteDrawable.Sprite;

                if (sprite is TextureAtlas.AtlasSprite)
                {
                    sprite = new TextureAtlas.AtlasSprite(sprite as TextureAtlas.AtlasSprite);
                }
                else
                {
                    sprite = new Sprite(sprite);
                }

                sprite.Color          = tint;
                spriteDrawable.Sprite = sprite;
                return(spriteDrawable);
            }

            throw new Exception("Unable to copy, unknown drawbale type: " + drawable.GetType());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// creates a overlay scene to display status text.
        /// </summary>
        /// <param name="window"></param>
        /// <param name="scene"></param>
        private static void SetupStatus(Window window, Scene scene)
        {
            Scene         scene2         = new Scene();
            PhysicsEngine physicsEngine2 = scene2.Engine;

            physicsEngine2.BroadPhase = new Physics2DDotNet.Detectors.SelectiveSweepDetector();
            //physicsEngine.BroadPhase = new Physics2DDotNet.Detectors.SpatialHashDetector();
            Physics2DDotNet.Solvers.SequentialImpulsesSolver solver = new Physics2DDotNet.Solvers.SequentialImpulsesSolver();
            solver.Iterations = 1;

            physicsEngine2.Solver = solver;

            Viewport viewport2 = new Viewport(
                new Rectangle(0, 0, window.Size.Width, window.Size.Height), //where
                Matrix2x3.Identity,                                         //how
                scene2,                                                     //who
                new Lifespan());                                            // how long

            window.AddViewport(viewport2);


            window.Resized += delegate(object sender, SizeEventArgs e)
            {
                viewport2.Width  = e.Width;
                viewport2.Height = e.Height;
            };

            numbers  = new IShape[10];
            numbers2 = new SurfacePolygons[10];
            for (int index = 0; index < numbers.Length; ++index)
            {
                numbers2[index] = Cache <SurfacePolygons> .GetItem(numberString[index] + "|FreeSans.ttf:20", Color.Black);

                numbers[index] = ShapeFactory.CreateSprite(numbers2[index], 0, 8, 2);
                SpriteDrawable s = numbers[index].Tag as SpriteDrawable;
                s.Color = new ScalarColor4(.1f, .1f, 1, 1);
            }

            DoBodyCount(window, viewport2, scene, scene2, new Vector2D(100, 2));
            DoJointCount(window, viewport2, scene, scene2, new Vector2D(100, 30));
            DoLogicsCount(window, viewport2, scene, scene2, new Vector2D(270, 2));
            DoFPS(window, viewport2, scene, scene2, new Vector2D(2, 2));
            DoUPS(window, viewport2, scene, scene2, new Vector2D(2, 30));
        }
Ejemplo n.º 4
0
        private static void DoBodyCount(Window window, Viewport viewport2, Scene scene1, Scene scene2, Vector2D pos)
        {
            List <Body> bodies = DemoHelper.AddText(new DemoOpenInfo(window, viewport2, scene2), "Bodies: 000000", pos, 20);

            foreach (Body body in bodies)
            {
                SpriteDrawable s = body.Shape.Tag as SpriteDrawable;
                s.Color = new ScalarColor4(.1f, .1f, 1, 1);
            }
            bodies.RemoveRange(0, 7);
            Vector2D[] positions = new Vector2D[bodies.Count];
            for (int index = 0; index < positions.Length; index++)
            {
                positions[index] = bodies[index].State.Position.Linear - numbers2[0].Offset;
            }
            EventHandler <CollectionEventArgs <Body> > handler = delegate(object sender, CollectionEventArgs <Body> e)
            {
                string val = scene1.Engine.Bodies.Count.ToString();
                SetBodiesText(bodies, positions, val);
            };

            scene1.Engine.BodiesAdded   += handler;
            scene1.Engine.BodiesRemoved += handler;
        }
Ejemplo n.º 5
0
        private static void DoFPS(Window window, Viewport viewport2, Scene scene1, Scene scene2, Vector2D pos)
        {
            List <Body> bodies = DemoHelper.AddText(new DemoOpenInfo(window, viewport2, scene2), "FPS: 000", pos, 20);

            foreach (Body body in bodies)
            {
                SpriteDrawable s = body.Shape.Tag as SpriteDrawable;
                s.Color = new ScalarColor4(.1f, .1f, 1, 1);
            }
            bodies.RemoveRange(0, 4);
            Vector2D[] positions = new Vector2D[bodies.Count];
            for (int index = 0; index < positions.Length; index++)
            {
                positions[index] = bodies[index].State.Position.Linear - numbers2[0].Offset;
            }
            int    frames       = 100;
            Scalar frameSeconds = 1;

            viewport2.BeginDrawing += delegate(object sender, DrawEventArgs e)
            {
                if (frames >= 10)
                {
                    frames       /= 2;
                    frameSeconds /= 2;
                }
                frames++;
                frameSeconds += e.DrawInfo.TrueDt;
                int ups = (int)(frames / frameSeconds);
                if (ups < 0)
                {
                    ups = 0;
                }
                string val = ups.ToString();
                SetBodiesText(bodies, positions, val);
            };
        }
Ejemplo n.º 6
0
        public TrackMixerEntity(Scene scene, Vector2 TracksPos, UICanvas canvas, bool[] trackbtn)
        {
            //
            // ONLY piano key entities come here
            //
            MainGameScene = scene as MainScene;              //hand entity belongs to MainScene
            //
            // Background for mixer
            //
            StartX = TracksPos.X;
            StartY = TracksPos.Y;
            //Background = scene.CreateEntity("background", new Vector2(StartX, StartY));
            //Background.Tag = 90;
            //Background.AddComponent(new SpriteRenderer(scene.Content.Load<Texture2D>("Slider/BackgroundMetal")).SetOrigin(new Vector2(0, 0)).SetRenderLayer(99));


            StartX = TracksPos.X + 10;
            StartY = TracksPos.Y + 10;
            //
            // bitmap font for checkbox
            //
            Nez.BitmapFonts.BitmapFont bf = scene.Content.Load <BitmapFont>("fonts/futura");
            slidertick = new SpriteDrawable((scene.Content.Load <Texture2D>("Slider/SliderMetalSmall")));
            sliderknob = new SpriteDrawable((scene.Content.Load <Texture2D>("Slider/SliderKnobBlk")));

            selecton  = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/SelOn")));
            selectoff = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/SelOff")));

            soloon  = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/SoloOn")));
            solooff = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/SoloOff")));

            muteon  = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/MuteOn")));
            muteoff = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/MuteOff")));
            //
            // Add all the buttons for each track used (I assume 16 maximum)
            //

            int trackNo = 0;

            foreach (bool trkOnOff in trackbtn)
            {
                //
                // track is being used (check mark) button is disabled
                //
                sel = canvas.Stage.AddElement(new Nez.UI.CheckBox("", new CheckBoxStyle(selectoff, selecton, bf, Color.Black)));
                sel.SetPosition(StartX, StartY);
                sel.OnClicked += MainGameScene.Track_Selection;
                sel.IsChecked  = trkOnOff;                          //on or off button?
                sel.SetDisabled(!trkOnOff);                         //if !trkOnOff = true then track not in use
                sel.Tag = trackNo;
                //
                // volume slider
                //
                slider = canvas.Stage.AddElement(new Slider(0, 100, 5, true, new SliderStyle(slidertick, sliderknob)));
                slider.SetPosition(StartX, StartY + 30);
                slider.SetHeight(150);

                slider.OnChanged += MainGameScene.Vol_Changed;
                slider.SetValue(100);
                //slider.Tag = trackNo;
                //
                // track SOLO
                //
                solo = canvas.Stage.AddElement(new Nez.UI.CheckBox("", new CheckBoxStyle(solooff, soloon, bf, Color.Black)));
                solo.SetPosition(StartX, StartY + 180);
                solo.OnClicked += MainGameScene.SoloBtn_OnClicked;
                solo.IsChecked  = false;
                solo.Tag        = trackNo;
                MainGameScene.SoloBtnGroup[trackNo] = solo;         //add solo button to the group
                //
                // track MUTE
                //
                mute = canvas.Stage.AddElement(new Nez.UI.CheckBox("", new CheckBoxStyle(muteoff, muteon, bf, Color.Black)));
                mute.SetPosition(StartX, StartY + 210);
                mute.OnClicked += MainGameScene.Track_Selection;
                mute.IsChecked  = false;
                mute.Tag        = trackNo;
                //
                // On/Off button to give track instrument/channel number
                //
                switch (trackNo)
                {
                case 0:
                    trkon  = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk00On")));
                    trkoff = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk00Off")));
                    break;

                case 1:
                    trkon  = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk01On")));
                    trkoff = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk01Off")));
                    break;

                case 2:
                    trkon  = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk02On")));
                    trkoff = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk02Off")));
                    break;

                case 3:
                    trkon  = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk03On")));
                    trkoff = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk03Off")));
                    break;

                case 4:
                    trkon  = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk04On")));
                    trkoff = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk04Off")));
                    break;

                case 5:
                    trkon  = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk05On")));
                    trkoff = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk05Off")));
                    break;

                case 6:
                    trkon  = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk06On")));
                    trkoff = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk06Off")));
                    break;

                case 7:
                    trkon  = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk07On")));
                    trkoff = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk07Off")));
                    break;

                case 8:
                    trkon  = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk08On")));
                    trkoff = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk08Off")));
                    break;

                case 9:
                    trkon  = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk09On")));
                    trkoff = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk09Off")));
                    break;

                case 10:
                    trkon  = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk10On")));
                    trkoff = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk10Off")));
                    break;

                case 11:
                    trkon  = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk11On")));
                    trkoff = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk11Off")));
                    break;

                case 12:
                    trkon  = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk12On")));
                    trkoff = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk12Off")));
                    break;

                case 13:
                    trkon  = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk13On")));
                    trkoff = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk13Off")));
                    break;

                case 14:
                    trkon  = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk14On")));
                    trkoff = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk14Off")));
                    break;

                case 15:
                    trkon  = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk15On")));
                    trkoff = new SpriteDrawable((scene.Content.Load <Texture2D>("slider/Trk15Off")));
                    break;
                }
                trk = canvas.Stage.AddElement(new Nez.UI.CheckBox("", new CheckBoxStyle(trkoff, trkoff, bf, Color.Black)));

                trk.SetPosition(StartX, StartY + 240);
                trk.OnClicked += MainGameScene.TrackBtn_OnClicked;
                trk.Tag        = trackNo;
                trk.IsChecked  = false;
                trk.SetDisabled(!trkOnOff);                      //if !trkOnOff = true then track not in use

                StartX  += 36.5f;
                trackNo += 1;
            }
        }
Ejemplo n.º 7
0
        private void SetUpUI()
        {
            frame = AddComponent(new UICanvas());
            frame.IsFullScreen = true;
            frame.RenderLayer  = -1;
            frame.LayerDepth   = 0.1f;

            internals = AddComponent(new UICanvas());
            internals.IsFullScreen = true;
            internals.RenderLayer  = -1;

            {
                int x = 20, y = 20;

                var frameTexture = Scene.Content.LoadTexture(ContentPaths.HealthBarFrame);
                var healthFrame  = frame.Stage.AddElement(new Image(frameTexture));
                healthFrame.SetPosition(x, y);
                healthFrame.SetSize(508, 58);

                ShadedImage <UIMaskEffect> AddBar(string path, Vector2 pos)
                {
                    var effect  = Scene.Content.LoadEffect <UIMaskEffect>(ContentPaths.MaskEffect);
                    var texture = Scene.Content.LoadTexture(path);
                    var image   = new ShadedImage <UIMaskEffect>(effect, texture);

                    image.SetPosition(pos.X, pos.Y);
                    image.SetSize(texture.Width * 2, texture.Height * 2);
                    internals.Stage.AddElement(image);
                    return(image);
                }

                speedRegular = new SpriteDrawable(Scene.Content.LoadTexture(ContentPaths.SpeedInternal));
                speedMaxed   = new SpriteDrawable(Scene.Content.LoadTexture(ContentPaths.SpeedInternalMaxed));

                healthBar = AddBar(ContentPaths.HealthInternal, new Vector2(x + 50, y + 8));
                dashBar   = AddBar(ContentPaths.DashInternal, new Vector2(x + 80, y + 34));
                speedBar  = AddBar(ContentPaths.SpeedInternal, new Vector2(x + 342, y + 34));
            }
            {
                var x = 20;
                var y = 140;

                var texture   = Scene.Content.LoadTexture(ContentPaths.AmmoFrame);
                var ammoFrame = frame.Stage.AddElement(new Table().Top().Left());
                ammoFrame.SetPosition(x, y);
                var cell = ammoFrame.Add(new Image(texture));
                cell.Size(64, 384);

                var style = ProgressBarStyle.Create(Color.Transparent, AmmoHighlight);
                style.KnobBefore.MinWidth  = style.KnobAfter.MinWidth = 24;
                style.KnobBefore.MinHeight = 0;

                ammo = internals.Stage.AddElement(new ProgressBar(0, playerAmmo.MaxAmmo, 1, true, style));
                ammo.SetSize(0, 324);
                ammo.SetOrigin((int)Align.TopLeft);
                ammo.SetPosition(x + 16 * 2, y + 29 * 2);
            }
            {
                weaponSlots = new List <Image>();

                var table = internals.Stage.AddElement(new Table());
                table.SetOrigin((int)VerticalAlign.Bottom);
                table.SetPosition(internals.Stage.GetWidth() / 2, internals.Stage.GetHeight() - 48 - 20);

                var iconTextures = Scene.Content.LoadTexture(ContentPaths.WeaponIcons);
                weaponIcons = Sprite.SpritesFromAtlas(iconTextures, 32, 32);

                void addIcon(int size)
                {
                    var image = new Image(Scene.Content.LoadTexture(ContentPaths.EmptySprite));

                    table.Add(image).Size(size).Pad(5);
                    weaponSlots.Add(image);
                }

                addIcon(64);
                addIcon(96);
                addIcon(64);

                UpdateWeaponIcons();
            }
        }
Ejemplo n.º 8
0
        public override void Initialize()
        {
            base.Initialize();
            font = new NezSpriteFont(Content.Load <SpriteFont>("Arial"));
            //
            // MIDI sequencer must have processes
            //
            sequencer1                            = new Sanford.Multimedia.Midi.Sequencer();
            sequencer1.clock.Tick                += onTick;
            this.sequencer1.PlayingCompleted     += new System.EventHandler(this.HandlePlayingCompleted);
            this.sequencer1.ChannelMessagePlayed += new System.EventHandler <Sanford.Multimedia.Midi.ChannelMessageEventArgs>(this.HandleChannelMessagePlayed);
            this.sequencer1.SysExMessagePlayed   += new System.EventHandler <Sanford.Multimedia.Midi.SysExMessageEventArgs>(this.HandleSysExMessagePlayed);
            this.sequencer1.Chased               += new System.EventHandler <Sanford.Multimedia.Midi.ChasedEventArgs>(this.HandleChased);
            this.sequencer1.Stopped              += new System.EventHandler <Sanford.Multimedia.Midi.StoppedEventArgs>(this.HandleStopped);
            //
            // Default output device (usually 0)
            //
            outDevice = new OutputDevice(outDeviceID);

            //DialogBar db = new DialogBar(-1);

            //znznznznznznznznznznznznznznznznznznznznznznznznznznznznzn
            // mouse entity (used for tracking of clicks)
            //znznznznznznznznznznznznznznznznznznznznznznznznznznznznzn
            MouseCursor = CreateEntity("mouse");
            MouseCursor.AddComponent(new BoxCollider());
            MouseCursor.AddComponent(new MouseComponent());

            //znznznznznznznznznznznznznznznznznznznznznznznznznznznznzn
            // keyboard entity (playing piano manually)
            //znznznznznznznznznznznznznznznznznznznznznznznznznznznznzn
            MouseCursor = CreateEntity("keyboard");
            MouseCursor.AddComponent(new KeyComponent());

            //znznznznznznznznznznznznznznznznznznznznznznznznznznznznzn
            // Text entity with component (Game name label)
            //znznznznznznznznznznznznznznznznznznznznznznznznznznznznzn
            TextEntity = CreateEntity("txt");
            TextEntity.Transform.Position = new Vector2(10, 20);
            TextEntity.Transform.Scale    = new Vector2(1, 1);
            txt = new TextComponent(Graphics.Instance.BitmapFont, "MIDI Player", new Vector2(0, 0), Color.White);
            txt.SetFont(font);
            TextEntity.AddComponent(txt);

            //znznznznznznznznznznznznznznznznznznznznznznznznznznznznzn
            // Background, with high value render layer
            //znznznznznznznznznznznznznznznznznznznznznznznznznznznznzn
            Background     = CreateEntity("background", new Vector2(0, 0));
            Background.Tag = 90;
            //SpriteRenderer comp = new SpriteRenderer(Content.Load<Texture2D>("Background")).SetRenderLayer(99);

            Background.AddComponent(new SpriteRenderer(Content.Load <Texture2D>("Slider/BackgroundMetal")).SetRenderLayer(99));
            Background.GetComponent <SpriteRenderer>().SetOrigin(new Vector2(0, 0));
            Background.SetPosition(new Vector2(310, 15));
            //znznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznzn
            // Canvas
            //znznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznzn
            //
            int    StartX = 10;
            Entity uiCan  = CreateEntity("ui");

            canvas = uiCan.AddComponent(new UICanvas());

            canvas.IsFullScreen = true;
            canvas.RenderLayer  = -10;//= SCREEN_SPACE_RENDER_LAYER;
            //
            // Display for track number
            //
            TrackMsg = canvas.Stage.AddElement(new Nez.UI.Label("All Tracks"));
            TrackMsg.SetPosition(320, 310);
            TrackMsg.SetSize(100f, 50f);
            //
            // Display for channel number
            //
            ChnlMsg = canvas.Stage.AddElement(new Nez.UI.Label("All Channels"));
            ChnlMsg.SetPosition(320, 330);
            ChnlMsg.SetSize(100f, 50f);
            AllChannels = -1;
            //
            // Display for instrument name
            //
            InstrumentMsg = canvas.Stage.AddElement(new Nez.UI.Label("All Channels"));
            InstrumentMsg.SetPosition(320, 350);
            InstrumentMsg.SetSize(100f, 50f);
            //
            // Dispaly for note number being played
            //
            NoteMsg = canvas.Stage.AddElement(new Nez.UI.Label("Piano note played"));
            NoteMsg.SetPosition(320, 370);
            NoteMsg.SetSize(100f, 50f);

            //
            // Track buttons and channels
            //
            for (int i = 0; i < 16; i++)
            {
                TrackChanl[i]      = -1;
                TracksInMidi[i]    = false;             //is track number active in MIDI file
                TracksPlaying[i]   = false;             //individual tracks playing (buttons)
                ChannelsPlaying[i] = true;              //they all are playing
            }

            //
            // turn off all buttons
            //
            //SetTrackButtonOff();
            //
            // Progress bar
            //
            PgBar = canvas.Stage.AddElement(new Nez.UI.ProgressBar(0, 1000, 1, false, Nez.UI.ProgressBarStyle.Create(Color.Green, Color.White)));
            PgBar.SetPosition(10, StartPos);
            //
            // Play button
            //
            PlayImageUp = new SpriteDrawable((Content.Load <Texture2D>("Player/play_blk")));
            PlayImageDn = new SpriteDrawable((Content.Load <Texture2D>("Player/play_grn")));
            PlayBtn     = canvas.Stage.AddElement(new ImageButton(PlayImageUp, PlayImageDn));
            PlayBtn.SetPosition(StartX, StartPos + 30);
            PlayBtn.OnClicked += Play;

            //
            // Stop button
            //
            StopImageUp = new SpriteDrawable((Content.Load <Texture2D>("Player/stop_blk")));
            StopImageDn = new SpriteDrawable((Content.Load <Texture2D>("Player/stop_grn")));
            StopBtn     = canvas.Stage.AddElement(new ImageButton(StopImageUp, StopImageDn));
            StopBtn.SetPosition(StartX + 71, StartPos + 30);
            StopBtn.OnClicked += Stop;

            //
            // Load/Eject button (stop playing, look for another MIDI file)
            //
            LoadImageUp = new SpriteDrawable((Content.Load <Texture2D>("Player/eject_blk")));
            LoadImageDn = new SpriteDrawable((Content.Load <Texture2D>("Player/eject_grn")));
            LoadBtn     = canvas.Stage.AddElement(new ImageButton(LoadImageUp, LoadImageDn));
            LoadBtn.SetPosition(StartX + 110, StartPos + 30);
            LoadBtn.OnClicked += Load;
            //
            //znznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznzn
            // Systems to process our requests
            //znznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznzn
            //
            this.AddEntityProcessor(new MouseClickSystem(new Matcher().All(typeof(MouseComponent))));
            this.AddEntityProcessor(new KeyClickSystem(new Matcher().All(typeof(KeyComponent))));
            this.AddEntityProcessor(new PianoClickSystem(new Matcher().All(typeof(NoteComponent), typeof(PlayingComponent))));
            //
            // Start by loading a file
            //
            if (!LoadMidiFile())
            {
                return;
            }
            //
            // Create the Mixer image with buttons, sliders, etc
            //
            var Track = new TrackMixerEntity(this, new Vector2(310, 20), canvas, TracksInMidi);
            //
            // Create the piano keys on bottom of mixer
            //
            var pi00 = new PianoEntity(this, new Vector2(StartX + 245, StartPos + 420), 0);

            //
            // Octave 4 is the middle C (note 60), color the keys
            //
            HandleOctaveColor(60);
        }
Ejemplo n.º 9
0
        public ISceneDrawable GetDrawable(string name)
        {
            ISceneDrawable drawable = Optional <ISceneDrawable>(name);

            if (drawable != null)
            {
                return(drawable);
            }

            drawable = Optional <TiledDrawable>(name);
            if (drawable != null)
            {
                return(drawable);
            }

            try {
                TextureRegion textureRegion = GetRegion(name);
                if (textureRegion is TextureAtlas.AtlasRegion)
                {
                    TextureAtlas.AtlasRegion region = textureRegion as TextureAtlas.AtlasRegion;
                    if (region.Splits != null)
                    {
                        drawable = new NinePatchDrawable(GetPatch(name));
                    }
                    else if (region.Rotate || region.PackedWidth != region.OriginalWidth || region.PackedHeight != region.OriginalHeight)
                    {
                        drawable = new SpriteDrawable(GetSprite(name));
                    }
                }

                if (drawable == null)
                {
                    drawable = new TextureRegionDrawable(textureRegion);
                }
            }
            catch { /* ignore */ }

            if (drawable == null)
            {
                NinePatch patch = Optional <NinePatch>(name);
                if (patch != null)
                {
                    drawable = new NinePatchDrawable(patch);
                }
                else
                {
                    Sprite sprite = Optional <Sprite>(name);
                    if (sprite != null)
                    {
                        drawable = new SpriteDrawable(sprite);
                    }
                    else
                    {
                        throw new Exception("No Drawable, NinePatch, TextureRegion, Texture, or Sprite registered with name: " + name);
                    }
                }
            }

            Add <ISceneDrawable>(name, drawable);
            return(drawable);
        }
Ejemplo n.º 10
0
        protected override async Task LoadContent()
        {
            material = new Material();

            string vsSource = @"
                attribute vec4 aPosition;
                attribute vec2 aTexture;
                attribute vec4 aColor;
                attribute float aSamplerIndex;

                uniform mat4 uProjectionMatrix;

                varying mediump vec4 vColor;
                varying highp vec2 vTextureCoord;
                varying mediump float vSamplerIndex;

                void main(void) {
                    gl_Position = uProjectionMatrix * aPosition;
                    vTextureCoord = aTexture;
                    vColor = aColor;
                    vSamplerIndex = aSamplerIndex;
                }";

            string fsSource = @"
                varying highp vec2 vTextureCoord;
                varying mediump vec4 vColor;
                varying mediump float vSamplerIndex;

                uniform sampler2D uSampler0;
                uniform sampler2D uSampler1;
                uniform sampler2D uSampler2;
                uniform sampler2D uSampler3;
                uniform sampler2D uSampler4;
                uniform sampler2D uSampler5;
                uniform sampler2D uSampler6;
                uniform sampler2D uSampler7;
                uniform sampler2D uSampler8;
                uniform sampler2D uSampler9;

                void main(void) {

                    mediump vec4 color;
                
                    if(vSamplerIndex > -0.5 && vSamplerIndex < 0.5)
                    {
                        color = texture2D(uSampler0, vTextureCoord);
                    }
                    if(vSamplerIndex > 0.5 && vSamplerIndex < 1.5)
                    {
                        color = texture2D(uSampler1, vTextureCoord);
                    }
                    if(vSamplerIndex > 1.5 && vSamplerIndex < 2.5)
                    {
                        color = texture2D(uSampler2, vTextureCoord);
                    }
                    if(vSamplerIndex > 2.5 && vSamplerIndex < 3.5)
                    {
                        color = texture2D(uSampler3, vTextureCoord);
                    }
                    if(vSamplerIndex > 3.5 && vSamplerIndex < 4.5)
                    {
                        color = texture2D(uSampler4, vTextureCoord);
                    }
                    if(vSamplerIndex > 4.5 && vSamplerIndex < 5.5)
                    {
                        color = texture2D(uSampler5, vTextureCoord);
                    }
                    if(vSamplerIndex > 5.5 && vSamplerIndex < 6.5)
                    {
                        color = texture2D(uSampler6, vTextureCoord);
                    }
                    if(vSamplerIndex > 6.5 && vSamplerIndex < 7.5)
                    {
                        color = texture2D(uSampler7, vTextureCoord);
                    }
                    if(vSamplerIndex > 7.5 && vSamplerIndex < 8.5)
                    {
                        color = texture2D(uSampler8, vTextureCoord);
                    }
                    if(vSamplerIndex > 8.5 && vSamplerIndex < 9.5)
                    {
                        color = texture2D(uSampler9, vTextureCoord);
                    }
                        
                    gl_FragColor = color * vColor;
                }";

            var vertexShader   = Context.CompileShader(ShaderType.VERTEX_SHADER, vsSource);
            var fragmentShader = Context.CompileShader(ShaderType.FRAGMENT_SHADER, fsSource);

            material.Program = Context.CreateShaderProgram();
            material.Program.Attach(vertexShader);
            material.Program.Attach(fragmentShader);

            material.Program.Link();

            Texture1 = await Context.LoadTextureAsync("res/birb.jpg");

            Texture2 = await Context.LoadTextureAsync("res/nyan.png");

            material.Textures = new[] { Texture1 };

            // material.Int32Uniforms = new Dictionary<string,int>()
            // {
            //     { "uSampler0", 0 },
            //     { "uSampler1", 1 },
            //     { "uSampler2", 2 },
            //     { "uSampler3", 3 },
            //     { "uSampler4", 4 },
            //     { "uSampler5", 5 },
            //     { "uSampler6", 6 },
            //     { "uSampler7", 7 },
            //     { "uSampler8", 8 },
            //     { "uSampler9", 9 }
            // };

            material.Matrix4Uniforms = new Dictionary <string, Matrix4>()
            {
                {
                    "uProjectionMatrix",
                    Matrix4.Orthogonal(-Context.Width * 0.5f, -Context.Height * 0.5f,
                                       Context.Width * 0.5f, Context.Height * 0.5f, -1, 1)
                }
            };

            drawables = new SpriteDrawable[benchmarkElementCount];
            Random random = new Random();

            for (int i = 0; i < benchmarkElementCount; i++)
            {
                drawables[i] = new SpriteDrawable()
                {
                    Color           = new Color(1, 1, 1, 1),
                    Size            = new Vector2(100, 100),
                    SourceRectangle = null,
                    Texture         = Texture1,
                    Transform       = TransformUtils.MakeTransform(
                        Vector3.Zero,
                        new Vector3(
                            (float)random.NextDouble() * Context.Width - Context.Width * 0.5f,
                            (float)random.NextDouble() * Context.Height - Context.Height * 0.5f,
                            0
                            ),
                        new Vector3(0, 0, (float)(random.NextDouble() * Math.PI)),
                        Vector3.One
                        )
                };
            }

            SpriteManager = new SpriteManager();
        }