コード例 #1
0
        public override void Initialize(params object[] parameters)
        {
            base.Initialize();

            string text = "";

            if (parameters.Length >= 1 && parameters[0] is string txt)
            {
                text = txt;
            }

            FontFamily font = new FontFamily("Consolas");

            if (parameters.Length >= 2 && parameters[1] is FontFamily fnt)
            {
                font = fnt;
            }

            GUIInteractionColors colors = new GUIInteractionColors(
                Color.BLACK,
                Color.BLACK,
                Color.LIGHT_GRAY
                );

            if (parameters.Length >= 3 && parameters[2] is GUIInteractionColors c)
            {
                colors = c;
            }

            GUIInteractionGraphics graphics = new GUIInteractionGraphics(
                GraphicsHandler.CreateDefaultTexture(1, 1, Color.WHITE),
                GraphicsHandler.CreateDefaultTexture(1, 1, Color.LIGHT_GRAY),
                GraphicsHandler.CreateDefaultTexture(1, 1, Color.DARK_GRAY)
                );

            if (parameters.Length >= 4 && parameters[3] is GUIInteractionGraphics g)
            {
                graphics = g;
            }

            this.graphics = graphics;
            this.colors   = colors;

            this.sprite     = GameObject.AddComponent <Sprite>(Color.WHITE, graphics.Get(InteractionState));
            this.textSprite = GameObject.AddComponent <TextSprite>(text, 16, font, colors.Get(InteractionState), new Rectangle(0, 0, Width, Height));

            UpdateMesh();
            UpdateTextureAndColor();

            OnMouseEntered  += (component, x, y) => UpdateTextureAndColor();
            OnMouseExited   += (component, x, y) => UpdateTextureAndColor();
            OnMouseClicked  += (component, x, y) => UpdateTextureAndColor();
            OnMouseReleased += (component, x, y) => UpdateTextureAndColor();

            OnSizeChanged += UpdateMesh;
        }
コード例 #2
0
        public override void Initialize(object[] parameters)
        {
            CellularAutomataInitializationData initializationData;

            if (parameters.Length > 0 && parameters[0] is CellularAutomataInitializationData)
            {
                initializationData = parameters[0] as CellularAutomataInitializationData;
            }
            else
            {
                initializationData = new CellularAutomataInitializationData(0, 100, true, NeighbourhoodMode.Moore);
            }

            CellCount         = initializationData.CellCount;
            IsTorus           = initializationData.IsTorus;
            NeighbourhoodMode = initializationData.NeighbourhoodMode;
            Seed           = initializationData.Seed == 0 ? new Random().Next() : initializationData.Seed;
            this.random    = new Random(Seed);
            needGeneration = !initializationData.IsReadOnly();

            sprite = GameObject.GetComponent <Sprite>();
            sprite.SetTexture(GraphicsHandler.CreateDefaultTexture(CellCount, CellCount, Color.WHITE));
            this.dataImage1 = new Bitmap(CellCount, CellCount);
            this.dataImage2 = new Bitmap(CellCount, CellCount);

            isPaused = true;

            this.grid = new CellularAutomataCell[CellCount, CellCount];
            InitializeGrid(initializationData.CellData);

            InputHandler.AddKeyUpEventHandler((key, modifiers) => {
                if (key == ExitKey)
                {
                    ModBase.Instance.Shutdown();
                }
                else if (key == PauseKey)
                {
                    isPaused = !isPaused;
                }
            });
        }
コード例 #3
0
ファイル: GUIPanel.cs プロジェクト: gartoks/GameEngineY
        public override void Initialize(params object[] parameters)
        {
            base.Initialize();

            Color color = Color.WHITE;

            if (parameters.Length >= 1 && parameters[0] is Color c)
            {
                color = c;
            }

            ITexture tex;

            if (parameters.Length >= 2 && parameters[1] is ITexture t)
            {
                tex = t;
            }
            else
            {
                tex = GraphicsHandler.CreateDefaultTexture(1, 1, Color.WHITE);
            }

            IShader sh;

            if (parameters.Length >= 3 && parameters[2] is IShader s)
            {
                sh = s;
            }
            else
            {
                sh = GraphicsHandler.CreateDefaultShader(1);
            }

            sprite = GameObject.AddComponent <Sprite>(color, tex, sh);

            UpdateMesh();

            OnSizeChanged += UpdateMesh;
        }
コード例 #4
0
        public override void Initialize(object[] parameters)
        {
            Color color = Color.WHITE;

            if (parameters.Length >= 1 && parameters[0] is Color c)
            {
                color = c;
            }

            ITexture tex;

            if (parameters.Length >= 2 && parameters[1] is ITexture t)
            {
                tex = t;
            }
            else
            {
                tex = GraphicsHandler.CreateDefaultTexture(1, 1, Color.MAGENTA);
            }

            IShader sh;

            if (parameters.Length >= 3 && parameters[2] is IShader s)
            {
                sh = s;
            }
            else
            {
                sh = GraphicsHandler.CreateDefaultShader(1);
            }

            CreateRenderable(ResolveAttributes, AssignUniforms, sh, BuildMesh());

            SetTexture(tex);
            Color = color;
        }
コード例 #5
0
        public override void Initialize(object[] parameters)
        {
            base.Initialize();

            string text = "";

            if (parameters.Length >= 1 && parameters[0] is string txt)
            {
                text = txt;
            }

            FontFamily font = new FontFamily("Consolas");

            if (parameters.Length >= 2 && parameters[1] is FontFamily fnt)
            {
                font = fnt;
            }

            Color color = Color.BLACK;

            if (parameters.Length >= 3 && parameters[2] is Color c)
            {
                color = c;
            }

            ITexture tex;

            if (parameters.Length >= 4 && parameters[3] is ITexture t)
            {
                tex = t;
            }
            else
            {
                tex = GraphicsHandler.CreateDefaultTexture(1, 1, Color.WHITE);
            }

            this.sprite          = GameObject.AddComponent <Sprite>(Color.WHITE, tex);
            this.textSprite      = GameObject.AddComponent <TextSprite>(text, 16, font, color, (Width, Height));
            this.textSprite.Dock = GUIDock.LeftCenter;

            this.blinkTime = -CURSOR_BLINK_TIME;

            this.text     = text;
            MaxTextLength = 10;

            OnSizeChanged += UpdateMesh;

            InputHandler.AddKeyPressEventHandler(keyChar => {
                if (!HasFocus)
                {
                    return;
                }

                if (keyChar == '\0' || Text.Length == MaxTextLength)
                {
                    return;
                }

                Text += keyChar;
            });

            InputHandler.AddKeyDownEventHandler((key, modifiers) => {
                if (!HasFocus)
                {
                    return;
                }

                if (key == Key.Back && Text.Length > 0)
                {
                    Text = Text.Substring(0, Text.Length - 1);
                }

                if (key == Key.Enter)
                {
                    OnTextApplied?.Invoke(this);
                }
            });
        }
コード例 #6
0
ファイル: GUIProgressbar.cs プロジェクト: gartoks/GameEngineY
        public override void Initialize(params object[] parameters)
        {
            base.Initialize();

            int pIdx = 1;

            Color bgColor = Color.LIGHT_GRAY;

            if (parameters.Length >= 1 && parameters[0] is Color bgc)
            {
                bgColor = bgc;
            }

            Color pbColor = Color.LIME;

            if (parameters.Length >= 2 && parameters[1] is Color pbc)
            {
                pbColor = pbc;
            }

            ITexture bgtex;

            if (parameters.Length >= 3 && parameters[2] is ITexture bgt)
            {
                bgtex = bgt;
            }
            else
            {
                bgtex = GraphicsHandler.CreateDefaultTexture(1, 1, Color.WHITE);
            }

            ITexture pbtex;

            if (parameters.Length >= 4 && parameters[3] is ITexture pbt)
            {
                pbtex = pbt;
            }
            else
            {
                pbtex = GraphicsHandler.CreateDefaultTexture(1, 1, Color.WHITE);
            }

            IShader sh;

            if (parameters.Length >= 5 && parameters[4] is IShader s)
            {
                sh = s;
            }
            else
            {
                sh = GraphicsHandler.CreateDefaultShader(1);
            }

            backgroundSprite = GameObject.AddComponent <Sprite>(bgColor, bgtex, sh);
            barSprite        = GameObject.AddComponent <Sprite>(pbColor, pbtex, sh);

            Value = 0.0f;

            UpdateMesh();

            OnSizeChanged += UpdateMesh;
        }
コード例 #7
0
ファイル: DebugGUIPrefab.cs プロジェクト: gartoks/GameEngineY
        public static DebugGUIHandler Create(string name)
        {
            IGameObject     gO      = Scene.CreateGameObject(name);
            DebugGUIHandler handler = gO.AddComponent <DebugGUIHandler>(22);

            IGameObject fpsGO    = Scene.CreateGameObject("fps", gO, new Vector2(Scene.MainViewport.Right, Scene.MainViewport.Top));
            GUILabel    fpsLabel = fpsGO.AddComponent <GUILabel>("fps", new FontFamily("Consolas"), Color.LIME);

            fpsLabel.Dock    = GUIDock.TopRight;
            fpsLabel.Width   = 0.1f;
            fpsLabel.Height  = 0.06f;
            handler.FpsLabel = fpsLabel;

            IGameObject upsGO    = Scene.CreateGameObject("ups", gO, new Vector2(Scene.MainViewport.Right - fpsLabel.WorldWidth * 1.1f, Scene.MainViewport.Top));
            GUILabel    upsLabel = upsGO.AddComponent <GUILabel>("ups", new FontFamily("Consolas"), Color.ORANGE);

            upsLabel.Dock    = GUIDock.TopRight;
            upsLabel.Width   = 0.1f;
            upsLabel.Height  = 0.06f;
            handler.UpsLabel = upsLabel;

            Timer fpsUpsTimer = gO.AddComponent <Timer>();

            fpsUpsTimer.Time             = 0.1f;
            fpsUpsTimer.OnTimerComplete += timer => {
                fpsLabel.Text = Window.Window.FramesPerSecond + "fps";
                upsLabel.Text = Time.UpdatesPerSecond + "ups";
                timer.Start();
            };
            fpsUpsTimer.Start();
            handler.Timer = fpsUpsTimer;

            IGameObject[] logGOs    = new IGameObject[handler.LineCount];
            GUILabel[]    logLabels = new GUILabel[handler.LineCount];
            for (int i = 0; i < handler.LineCount; i++)
            {
                logGOs[i]           = Scene.CreateGameObject($"log_line_{i}", gO, new Vector2(Scene.MainViewport.Left, Scene.MainViewport.Top - i * Scene.MainViewport.Height / (handler.LineCount + 1)));
                logLabels[i]        = logGOs[i].AddComponent <GUILabel>($"", new FontFamily("Consolas"), Color.WHITE);
                logLabels[i].Width  = 2 / 3f;
                logLabels[i].Height = 2 / (float)(handler.LineCount + 1);
            }

            for (int i = 0; i < handler.LineCount; i++)
            {
                logLabels[i].Dock     = GUIDock.TopLeft;
                logLabels[i].TextDock = GUIDock.LeftCenter;
            }
            handler.Logs = logLabels;

            IGameObject consoleGO = Scene.CreateGameObject("console", gO, new Vector2(Scene.MainViewport.Left, Scene.MainViewport.Bottom));
            GUITextbox  consoleTb = consoleGO.AddComponent <GUITextbox>("", new FontFamily("Consolas"), Color.WHITE, GraphicsHandler.CreateDefaultTexture(1, 1, new Color(31, 31, 31, 127)));

            consoleTb.Width         = 2f / 3f;
            consoleTb.Height        = 2f / handler.LineCount;
            consoleTb.Dock          = GUIDock.BottomLeft;
            consoleTb.MaxTextLength = 40;
            handler.Console         = consoleTb;

            return(handler);
        }