Ejemplo n.º 1
0
        public Button(Vector2 pos, Vector2 size, string textstring, TextStyle style, Action OnPress)
        {
            Debug.Assert(style.font.fontTexture.TextureID != 0);
            this.pos     = pos;
            this.OnPress = OnPress;
            this.text    = new Text(textstring, style, new Vector2(pos.x, pos.y + 0.05));

            colour   = new Vector4(1, 1, 1, 1);
            model    = GuiModel.CreateRectangle(size, Assets.Textures.ButtonTex);
            cooldown = new CooldownTimer(20);
        }
Ejemplo n.º 2
0
        public static void Init()
        {
            TextFont.Init();

            TextStyle style = new TextStyle(TextAlignment.TopLeft, TextFont.LucidaConsole, 0.5f, 2f, int.MaxValue, 1.5f, new Vector3(1, 1, 1));

            DebugText        = new Text("", style, new Vector2(-0.99, 0.97));
            Healthbar        = GuiModel.CreateRectangle(new Vector2(0.52, 0.04), TextureUtil.ColourFromVec4(new Vector4(0.88, 0.3, 0.1, 0.8)));
            HealthbarTexture = GuiModel.CreateRectangle(new Vector2(0.55, 0.065), Textures.HealthbarTexture);
            Background       = GuiModel.CreateRectangle(new Vector2(1, 1), Textures.GameBackgroundTex);
            PausedOverlay    = GuiModel.CreateRectangle(new Vector2(1, 1), TextureUtil.ColourFromVec4(new Vector4(0.2, 0.2, 0.2, 0.9)));
            PausedText       = new Text("Paused", new TextStyle(TextAlignment.Top, TextFont.Chiller, 1.3f, 2f, 1, 1f, new Vector3(1, 1, 1)), new Vector2(0, 1));
            TxtInput         = new InGameTextbox(new Vector2(0, -0.8), new Vector2(1, 0.03), TextFont.LucidaConsole, 0.5f);

            Buttons         = new HashSet <Button>();
            btn_BackToTitle = new Button(new Vector2(0, -0.2), new Vector2(0.4, 0.04), "Save and Quit", TextStyle.Chiller_SingleLine_Large, delegate() {
                Program.SaveWorld();
                Program.SwitchToTitleScreen();
            });
            Buttons.Add(btn_BackToTitle);
        }
Ejemplo n.º 3
0
 public Label(Vector2 pos, Vector2 size, string textstring, TextStyle style)
 {
     this.pos  = pos;
     this.text = new Text(textstring, style, new Vector2(pos.x, pos.y + 0.05));
     model     = GuiModel.CreateRectangle(size, Textures.LabelTex);
 }
Ejemplo n.º 4
0
 protected virtual GuiModel GenModel()
 {
     return(GuiModel.CreateRectangle(size, Textures.TextboxTex));
 }
Ejemplo n.º 5
0
 protected override GuiModel GenModel()
 {
     return(GuiModel.CreateRectangle(size, TextureUtil.CreateTexture(0.2f, 0.2f, 0.2f, 0.4f)));
 }
Ejemplo n.º 6
0
        public static void Init()
        {
            Vector2 buttonSize = new Vector2(0.3, 0.08);

            btn_Back_Title = new Button(new Vector2(0, -0.7), buttonSize, "Back", TextStyle.Chiller_SingleLine_Large, delegate() { SwitchTo(State.Main); });
            backgroundhue  = 180;

            #region Home Screen
            btn_Main_Play    = new Button(new Vector2(0, 0.3), buttonSize, "Play", TextStyle.Chiller_SingleLine_Large, delegate() { SwitchTo(State.WorldSelect); });
            btn_Main_Credits = new Button(new Vector2(0, -0.05), buttonSize, "Credits", TextStyle.Chiller_SingleLine_Large, delegate() { SwitchTo(State.Credits); });
            btn_Main_Help    = new Button(new Vector2(0, -0.4), buttonSize, "Help", TextStyle.Chiller_SingleLine_Large, delegate() { SwitchTo(State.Help); });
            btn_Main_Exit    = new Button(new Vector2(0, -0.75), buttonSize, "Exit", TextStyle.Chiller_SingleLine_Large, delegate() { Glut.glutLeaveMainLoop(); });
            #endregion

            #region Background
            txt_Main_Title = new Text("TITLE HERE", new TextStyle(TextAlignment.Center, TextFont.Chiller, 3f, 2f, 1, 1f, new Vector3(1, 1, 1)), new Vector2(0, 1));
            backgroundpos  = Vector2.Zero;
            float s = 1f / Program.AspectRatio;
            float imageAspectRatio = (float)Textures.TitleBackgroundTex.Size.Width / Textures.TitleBackgroundTex.Size.Height;
            background = GuiModel.CreateRectangle(new Vector2(s * imageAspectRatio, s), Textures.TitleBackgroundTex);
            background.vao.UpdateUVs(new Vector2[] {
                backgroundpos + new Vector2(0, 1f),
                backgroundpos + new Vector2(0, 0),
                backgroundpos + new Vector2(1, 0),
                backgroundpos + new Vector2(1, 1f)
            });
            #endregion

            #region Credits
            TextStyle tstyle = new TextStyle(TextAlignment.Center, TextFont.Chiller, 0.8f, 1.8f, 1 << 30, 0.5f, new Vector3(1, 1, 1));
            txt_CreditsInfo = new Text("Copyright Alex Tan (2016). Apache License. https://github.com/Pilex1/2D-Game/blob/master/LICENSE" + Environment.NewLine + Environment.NewLine + "- code, bugs, game design, bugs, graphics, bugs, everything you see here, bugs. Did I mention bugs?" + Environment.NewLine + Environment.NewLine + "Help me continue making these projects:" + Environment.NewLine + Environment.NewLine + "Visit my github repositories to view and download the full source code plus my other projects" + Environment.NewLine + " - https://github.com/Pilex1" + Environment.NewLine + " - https://github.com/Pilex1/2D-Game" + Environment.NewLine + Environment.NewLine + "Subscribe to my youtube channel where I post videos of Mandelbrot renders and game development" + Environment.NewLine + " - Pilex", tstyle, new Vector2(0, 0.9));
            #endregion

            #region World Pickers
            btnWorldPickers = new List <Button>();

            txtboxWorldPickers = new List <Textbox>();
            worlds             = new HashSet <string>();
            ResetWorldPickers();
            #endregion

            #region New World
            //creating new world
            txtbx_NewWorld_Name = new Textbox(new Vector2(0, 0.5), new Vector2(0.3, 0.03), TextFont.Chiller, 0.6f);
            txtbx_NewWorld_Seed = new Textbox(new Vector2(0, 0.2), new Vector2(0.3, 0.03), TextFont.Chiller, 0.6f);
            float offset = 0.15f;
            txt_NewWorld_Name        = new Text("World Name", tstyle, new Vector2(0, 0.5 + offset));
            txt_NewWorld_Seed        = new Text("Seed", tstyle, new Vector2(0, 0.2 + offset));
            btn_NewWorld_CreateWorld = new Button(new Vector2(0, -0.3), new Vector2(0.3, 0.08), "Create", TextStyle.Chiller_SingleLine_Large, delegate() {
                string worldname = txtbx_NewWorld_Name.GetText();
                worlds.Add(worldname);
                Program.SwitchToGame(worldname, int.Parse(txtbx_NewWorld_Seed.GetText()));
            });
            btn_NewWorld_RandSeed = new Button(new Vector2(0.5, 0.2), new Vector2(0.15, 0.03), "Random seed", TextStyle.Chiller_SingleLine_Small, delegate() {
                int irand = MathUtil.RandInt(Program.Rand, 1 << 24, 1 << 30);
                txtbx_NewWorld_Seed.SetText(irand.ToString());
            });
            btn_NewWorld_Back = new Button(new Vector2(0, -0.7), buttonSize, "Back", TextStyle.Chiller_SingleLine_Large, delegate() {
                txtbx_NewWorld_Name.ClearText();
                txtbx_NewWorld_Name.disabled = true;

                txtbx_NewWorld_Seed.ClearText();
                txtbx_NewWorld_Seed.disabled = true;

                SwitchTo(State.WorldSelect);
            });
            #endregion

            #region Help
            txt_Help = new Text("How to play:" + Environment.NewLine + "W A S D - movement" + Environment.NewLine + "Left click - destroy tile" + Environment.NewLine + "Right click - interact / place tile" + Environment.NewLine + "E - open / close inventory" + Environment.NewLine + "Mousewheel and keys 1 to 9 - hotbar selection" + Environment.NewLine + Environment.NewLine + "Debug controls: (pretend these don't exist)" + Environment.NewLine + "F1 - toggle tile data view" + Environment.NewLine + "F - toggle flying", tstyle, new Vector2(0, 0.9));
            #endregion

            SwitchTo(State.Main);
        }