Exemple #1
0
        public void OnClickLoadFontButton()
        {
            Debug.Log($"{nameof(MenuWindow)}.{nameof(OnClickLoadFontButton)}");

            string   latestBMPFontPath = Setting.Instance.LatestBMPFontPath;
            FileInfo fontFileInfo      = null;

            if (!string.IsNullOrWhiteSpace(latestBMPFontPath))
            {
                fontFileInfo = new FileInfo(latestBMPFontPath);
            }
            FileAndDirectoryWindow window = FileAndDirectoryWindow.OpenWindow(fontFileInfo);

            window.Title       = "读取一个 *.fnt 文件";
            window.OKCallback += (_) =>
            {
                string fontPath = window.SelectedFileSystemInfo.FullName;
                Debug.Log($"{window.SelectedFileSystemInfo.GetType().Name} : {fontPath}");
                Setting.Instance.LatestBMPFontPath = fontPath;
                Setting.Instance.SaveOutPlayerPrefs();
                GameSystemData.Instance.Font?.Dispose();
                BMPFont font = new BMPFont();
                font.LoadFontFromFile(window.SelectedFileSystemInfo.FullName);
                font.UseIt();
            };
        }
        /// <summary>
        /// 渲染一个字符
        /// </summary>
        /// <param name="font">使用的字体</param>
        /// <param name="char">字体内容</param>
        /// <returns>此渲染单位对应的游戏对象</returns>
        private GameObject AppendChar(BMPFont font, char @char, out BMPFontChar fontChar)
        {
            GameObject charItem = UnityEngine.Object.Instantiate(m_CharItemPrefab);

            CharGo.Add(charItem);
            charItem.transform.SetParent(m_ScrollContent, false);

            if (font.Chars.TryGetValue(@char, out fontChar))
            {
                Image image = charItem.GetComponent <Image>();
                // 离谱,Unity 渲染大小为0, 0 的精灵图片报错??
                if (fontChar.Size.x * fontChar.Size.y == 0f)
                {
                    image.color = new Color();
                    (charItem.transform as RectTransform).sizeDelta = fontChar.Size;
                }
                else
                {
                    image.sprite = fontChar.Sprite;
                    image.color  = Color.white;
                    image.SetNativeSize();
                }
            }
            charItem.SetActive(true);
            return(charItem);
        }
Exemple #3
0
        public StaticGui(MainWindow window, MasterRenderer renderer)
        {
            this.window   = window;
            this.renderer = renderer;

            gsys = renderer.Sprites.GUISystem;

            area = new GUIArea(gsys);
            renderer.Sprites.Add(area);

            BMPFont smallFont  = AssetManager.LoadFont("arial-bold-12");
            BMPFont normalFont = AssetManager.LoadFont("arial-bold-14");
            BMPFont bigFont    = AssetManager.LoadFont("arial-bold-20");
            BMPFont tinyFont   = AssetManager.LoadFont("arial-bold-10");

            GUITheme theme = AssetManager.CreateDefaultGameTheme();

            theme.SetField("SmallFont", smallFont);
            theme.SetField("Font", normalFont);
            theme.SetField("TinyFont", tinyFont);

            controls        = new ControlsWindow(gsys, theme);
            controls.ZIndex = 200;

            // Overlay
            fpsLabel     = new GUILabel(UDim2.Zero, UDim2.Zero, "FPS: --", TextAlign.TopLeft, theme);
            timeLabel    = new GUILabel(new UDim2(1f, 0, 0, 0), UDim2.Zero, "Time: --", TextAlign.TopRight, theme);
            versionLabel = new GUILabel(new UDim2(0, 0, 1f, 0), UDim2.Zero, GameVersion.Current.ToString(),
                                        TextAlign.BottomLeft, theme);
            fpsLabel.Font     = smallFont;
            timeLabel.Font    = smallFont;
            versionLabel.Font = bigFont;

            if (screenshots == null)
            {
                string[] mainMenuFiles = Directory.GetFiles("Content/Textures/MainMenu");
                screenshots = new List <Texture>();

                foreach (string file in mainMenuFiles)
                {
                    // Skip thumbs.db
                    if (file.EndsWith(".db"))
                    {
                        continue;
                    }

                    try { screenshots.Add(GLoader.LoadTexture(file, TextureMinFilter.Linear, TextureMagFilter.Linear, true)); }
                    catch (Exception e) { DashCMD.WriteError("Failed to load main menu background '{1}'. \n{0}", e, file); }
                }
            }

            background        = new GUIFrame(UDim2.Zero, new UDim2(1f, 0, 1f, 0), Image.Blank);
            background.ZIndex = -100;

            area.AddTopLevel(background, fpsLabel, timeLabel, versionLabel);
            gsys.Add(controls);
        }
        public ControlsWindow(GUISystem system, GUITheme theme)
            : base(system, UDim2.Zero, "Controls", theme)
        {
            labels = new List <GUILabel>();
            Setup();
            ZIndex = 100;

            font = theme.GetField <BMPFont>(null, "SmallFont");
        }
        public void RefreshUI()
        {
            BMPFont bmpFont = GameSystemData.Instance.Font;

            UIBMPFontCommon.BMPFontCommon = bmpFont?.Common;
            UIBMPFontInfo.BMPFontInfo     = bmpFont?.Info;

            UIBMPFontCommon.RefreshUI();
            UIBMPFontInfo.RefreshUI();
        }
Exemple #6
0
        //bool showGameItems;

        public HUD(MasterRenderer renderer)
        {
            this.renderer = renderer;
            font          = AssetManager.LoadFont("karmasuture-26");

            feed           = new List <FeedItem>();
            hitIndications = new List <HitIndication>();

            if (palletTex == null)
            {
                palletTex = GLoader.LoadTexture("Textures/Gui/palette.png");
                Texture crosshairTex = GLoader.LoadTexture("Textures/Gui/crosshair.png");
                Texture hitmarkerTex = GLoader.LoadTexture("Textures/Gui/hitmarker.png");
                crosshairImage = new Image(crosshairTex);
                hitmarkerImage = new Image(hitmarkerTex);
                hurtRingTex    = GLoader.LoadTexture("Textures/Gui/hurt-ring.png");
                intelTex       = GLoader.LoadTexture("Textures/Gui/intel.png", TextureMinFilter.Nearest, TextureMagFilter.Nearest);
            }

            GUISystem gsys = renderer.Sprites.GUISystem;

            area        = new GUIArea(gsys);
            area.ZIndex = -1;

            theme = GUITheme.Basic;
            theme.SetField("Font", font);
            theme.SetField("SmallFont", AssetManager.LoadFont("arial-bold-14"));
            theme.SetField("Label.TextColor", Color.White);
            theme.SetField("Label.TextShadowColor", new Color(0, 0, 0, 0.6f));

            healthLabel       = new GUILabel(new UDim2(0, 40, 1, -20), UDim2.Zero, "Health: --", TextAlign.BottomLeft, theme);
            ammoLabel         = new GUILabel(new UDim2(1, -50, 1, -25), UDim2.Zero, "", TextAlign.BottomRight, theme);
            crosshair         = new GUIFrame(new UDim2(0.5f, -28, 0.5f, -28), new UDim2(0, 56, 0, 56), crosshairImage);
            hitmarker         = new GUIFrame(new UDim2(0.5f, -43, 0.5f, -43), new UDim2(0, 86, 0, 86), hitmarkerImage);
            hitmarker.Visible = false;

            intelInHand = new GUIFrame(new UDim2(0.5f, -20, 0, 100), new UDim2(0, 40, 0, 40), new Image(intelTex));
            intelPickedUpNotification = new GUILabel(new UDim2(0.5f, 0, 0, 150), UDim2.Zero,
                                                     "You have picked up the intel!", TextAlign.TopCenter, theme);
            intelInHand.Visible = false;
            intelPickedUpNotification.Visible = false;

            crosshair.CapturesMouseClicks   = false;
            hitmarker.CapturesMouseClicks   = false;
            ammoLabel.CapturesMouseClicks   = false;
            healthLabel.CapturesMouseClicks = false;

            area.AddTopLevel(ammoLabel, healthLabel, crosshair, hitmarker, intelInHand, intelPickedUpNotification);
        }
Exemple #7
0
        public ChatBox(UDim2 position, UDim2 size, GUITheme theme, MultiplayerScreen screen)
            : base(position, size, theme)
        {
            this.screen = screen;
            items       = new List <ChatItem>();
            Image       = null;
            font        = AssetManager.LoadFont("arial-bold-11");

            textField = new GUITextField(new UDim2(0, 0, 1f, -15), new UDim2(1f, 0, 0, 30), theme)
            {
                Parent = this
            };

            textField.OnEnterPressed += TextField_OnEnterPressed;
        }
Exemple #8
0
            public ChatItem(GUITheme theme, float height, int numFeed,
                            string text, BMPFont font)
                : base(UDim2.Zero, UDim2.Zero, image: null)
            {
                Position = new UDim2(0, 0, 0, 20 + (height * numFeed));
                Size     = new UDim2(0, 1f, 0, height);

                label = new GUILabel(UDim2.Zero, new UDim2(0, 1, 1f, 0), text, TextAlign.Left, Color.White, theme)
                {
                    Parent = this
                };

                label.Font = font;

                TimeLeft = 60f;
            }
        public static BMPFont LoadFont(string fileName)
        {
            if (GlobalNetwork.IsServer)
            {
                return(null);
            }

            string filePath = GLoader.GetContentRelativePath(Path.Combine("Fonts", fileName + ".fnt"));

            BMPFont font;

            if (fonts.TryGetValue(filePath, out font))
            {
                return(font);
            }
            else
            {
                font = new BMPFont(filePath);
                fonts.Add(filePath, font);
                return(font);
            }
        }
Exemple #10
0
        public void AddFeedItem(string left, string leftAssist, Color leftColor, string middle, string right, Color rightColor)
        {
            BMPFont font = theme.GetField <BMPFont>(null, "SmallFont");

            if (!string.IsNullOrWhiteSpace(leftAssist))
            {
                if (string.IsNullOrWhiteSpace(left))
                {
                    left = right + " + " + leftAssist;
                }
                else
                {
                    left = left + " + " + leftAssist;
                }
            }

            FeedItem item = new FeedItem(theme, 25, feed.Count,
                                         left, leftColor, middle, right, rightColor, font);

            feed.Add(item);
            area.AddTopLevel(item);
        }
        public void Drawing(string content)
        {
            if (string.IsNullOrEmpty(content))
            {
                return;
            }
            BMPFont font = GameSystemData.Instance.Font;

            if (font is null || font.HaveError)
            {
                return;
            }

            string[] lines = content.Split('\n');
            for (int lineIndex = 0; lineIndex < lines.Length; lineIndex++)
            {
                string line       = lines[lineIndex];
                int    lineLocalY = -font.Common.LineHelght * lineIndex - BorderWidth;
                int    lineLocalX = BorderWidth;

                for (int charIndex = 0; charIndex < line.Length; charIndex++)
                {
                    char       @char = line[charIndex];
                    GameObject go    = AppendChar(font, @char, out BMPFontChar fontChar);
                    go.name = $"char : {lineIndex}, {charIndex}";
                    RectTransform trans = (go.transform as RectTransform);
                    trans.localPosition = new Vector2(lineLocalX + (fontChar?.Offset.x ?? 0), lineLocalY + (fontChar?.Offset.y ?? 0));
                    if (fontChar is null)
                    {
                        lineLocalX += (int)trans.sizeDelta.x;
                    }
                    else
                    {
                        lineLocalX += fontChar.XAdvance;
                    }
                }
            }
        }
        public MultiplayerScreen(MainWindow window)
            : base(window, "Multiplayer")
        {
            debugRenderer = Renderer.GetRenderer3D <DebugRenderer>();

            gamemodes = new Dictionary <GamemodeType, NetworkedGamemode>()
            {
                { GamemodeType.TDM, new TDMGamemode(this) },
                { GamemodeType.CTF, new CTFGamemode(this) }
            };

            // Build the UI elements
            theme = AssetManager.CreateDefaultGameTheme();
            font  = theme.GetField <BMPFont>(null, "SmallFont");

            hud                       = new HUD(Renderer);
            loadingBar                = new MultiplayerLoadingBar(GUISystem, theme);
            chat                      = new ChatBox(new UDim2(0, 40, 1f, -240), new UDim2(0, 350, 0, 165), theme, this);
            menu                      = new MultiplayerMenu(GUISystem, theme, Window);
            menu.OnClosed            += Menu_OnClosed;
            announcementLabel         = new GUILabel(new UDim2(0.5f, 0, 0.5f, 0), UDim2.Zero, "", TextAlign.Center, theme);
            announcementLabel.Font    = AssetManager.LoadFont("karmasuture-32");
            announcementLabel.Visible = false;

            // Add each UI element
            GUIArea.AddTopLevel(chat, announcementLabel);
            GUISystem.Add(loadingBar, menu);
            Windows.Add(loadingBar);
            Windows.Add(menu);

            // Setup default multiplayer cvars
            DashCMD.SetCVar("cl_impacts", false);
            DashCMD.SetCVar("cl_interp", 0.5f);               // Client interpolation with server position
            DashCMD.SetCVar("cl_interp_movement_smooth", 1f); // Client player movement smoothing (1f = no smoothing)
            DashCMD.SetCVar("cl_interp_rep", 20f);            // Replicated entities interpolation
            DashCMD.SetCVar("cl_max_error_dist", 12f);        // Max distance the client's position can be off from the server's
        }
Exemple #13
0
            public FeedItem(GUITheme theme, float height, int numFeed,
                            string left, Color leftColor, string middle, string right, Color rightColor,
                            BMPFont font)
                : base(UDim2.Zero, UDim2.Zero, image: null)
            {
                float leftLen  = font.MeasureString(left).X;
                float midLen   = font.MeasureString(middle).X;
                float rightLen = font.MeasureString(right).X;

                float fullLen = leftLen + midLen + rightLen + 20;
                float midX    = ((leftLen + 10) + (fullLen - rightLen - 10)) / 2f;

                Position = new UDim2(1f, -fullLen - 10, 0, 20 + (height * numFeed));
                Size     = new UDim2(0, fullLen, 0, 25);

                leftLabel = new GUILabel(UDim2.Zero, new UDim2(0, 1, 1f, 0), left, TextAlign.Left, leftColor, theme)
                {
                    Parent = this
                };
                rightLabel = new GUILabel(new UDim2(1, 0, 0, 0),
                                          new UDim2(0, 1, 1f, 0), right, TextAlign.Right, rightColor, theme)
                {
                    Parent = this
                };
                centerLabel = new GUILabel(new UDim2(0, midX, 0, 0),
                                           new UDim2(0, 1, 1f, 0), middle, TextAlign.Center, theme)
                {
                    Parent = this
                };

                leftLabel.Font   = font;
                rightLabel.Font  = font;
                centerLabel.Font = font;

                TimeLeft = 5f;
            }
        public Leaderboard(GUISystem gsys, GUITheme theme, NetPlayerComponent netPlayerComponent)
            : base(gsys, new UDim2(0.65f, 0, 0.65f, 0), "Leaderboard", theme, false, false)
        {
            MinSize = new UDim2(0, 300, 0, 400);

            this.netPlayerComponent = netPlayerComponent;
            IsDraggable             = false;

            playerFrames = new Dictionary <ushort, PlayerFrame>();
            orderedTeamA = new List <PlayerFrame>();
            orderedTeamB = new List <PlayerFrame>();

            bigFont = AssetManager.LoadFont("karmasuture-26");
            theme.SetField("Leaderboard.PlayerLabel.Font", AssetManager.LoadFont("arial-14"));

            teamAFrame  = new GUIFrame(UDim2.Zero, new UDim2(0.5f, 0, 1f, 0), image: null);
            teamBFrame  = new GUIFrame(new UDim2(0.5f, 0, 0, 0), new UDim2(0.5f, 0, 1f, 0), image: null);
            footerFrame = new GUIFrame(new UDim2(0, 0, 1f, -30), new UDim2(1f, 0, 0, 30), theme);

            gamemodeLabel = new GUILabel(UDim2.Zero, new UDim2(0.5f, 0, 1f, 0), "Current Gamemode: --", TextAlign.Left, theme)
            {
                Parent = footerFrame
            };
            gamemodeInfoLabel = new GUILabel(new UDim2(0.5f, 0, 0, 0), new UDim2(0.5f, 0, 1f, 0), "", TextAlign.Right, theme)
            {
                Parent = footerFrame
            };

            GUILabel teamALabel = new GUILabel(new UDim2(0, 0, 0, 0), new UDim2(1f, 0, 0, 40),
                                               "Red Team", TextAlign.Left, Theme)
            {
                Parent = teamAFrame
            };
            GUILabel teamBLabel = new GUILabel(new UDim2(0, 0, 0, 0), new UDim2(1f, 0, 0, 40),
                                               "Blue Team", TextAlign.Left, Theme)
            {
                Parent = teamBFrame
            };

            teamAScoreLabel = new GUILabel(new UDim2(1f, 0, 0, 0), new UDim2(0, 1, 0, 40),
                                           "0", TextAlign.Right, Theme)
            {
                Parent = teamAFrame
            };
            teamBScoreLabel = new GUILabel(new UDim2(1f, 0, 0, 0), new UDim2(0, 1, 0, 40),
                                           "0", TextAlign.Right, Theme)
            {
                Parent = teamBFrame
            };

            GUILabel teamAPlayerNameLabel = new GUILabel(new UDim2(0, 0, 0, 40), new UDim2(1f, 0, 0, 20), "Name", TextAlign.Left, theme)
            {
                Parent = teamAFrame
            };
            GUILabel teamAPlayerScoreLabel = new GUILabel(new UDim2(0, 0, 0, 40), new UDim2(1f, -50, 0, 20), "Score", TextAlign.Right, theme)
            {
                Parent = teamAFrame
            };
            GUILabel teamAPlayerPingLabel = new GUILabel(new UDim2(0, 0, 0, 40), new UDim2(1f, 0, 0, 20), "Ping", TextAlign.Right, theme)
            {
                Parent = teamAFrame
            };

            GUILabel teamBPlayerNameLabel = new GUILabel(new UDim2(0, 0, 0, 40), new UDim2(1f, 0, 0, 20), "Name", TextAlign.Left, theme)
            {
                Parent = teamBFrame
            };
            GUILabel teamBPlayerScoreLabel = new GUILabel(new UDim2(0, 0, 0, 40), new UDim2(1f, -50, 0, 20), "Score", TextAlign.Right, theme)
            {
                Parent = teamBFrame
            };
            GUILabel teamBPlayerPingLabel = new GUILabel(new UDim2(0, 0, 0, 40), new UDim2(1f, 0, 0, 20), "Ping", TextAlign.Right, theme)
            {
                Parent = teamBFrame
            };

            teamALabel.TextPadding.X      = 6;
            teamBLabel.TextPadding.X      = 6;
            teamAScoreLabel.TextPadding.Z = 6;
            teamBScoreLabel.TextPadding.Z = 6;

            teamAPlayerNameLabel.TextPadding.X  = 6;
            teamAPlayerScoreLabel.TextPadding.Z = 6;
            teamAPlayerPingLabel.TextPadding.Z  = 6;

            teamBPlayerNameLabel.TextPadding.X  = 6;
            teamBPlayerScoreLabel.TextPadding.Z = 6;
            teamBPlayerPingLabel.TextPadding.Z  = 6;

            teamALabel.BackgroundImage           = Image.CreateBlank(new Color(186, 52, 52, 127));
            teamBLabel.BackgroundImage           = Image.CreateBlank(new Color(39, 78, 194, 127));
            teamAPlayerNameLabel.BackgroundImage = theme.GetField <Image>(null, "Frame.Image");
            teamBPlayerNameLabel.BackgroundImage = theme.GetField <Image>(null, "Frame.Image");

            teamALabel.Font      = bigFont;
            teamBLabel.Font      = bigFont;
            teamAScoreLabel.Font = bigFont;
            teamBScoreLabel.Font = bigFont;

            teamAScoreLabel.ZIndex       = 1;
            teamBScoreLabel.ZIndex       = 1;
            teamAPlayerScoreLabel.ZIndex = 1;
            teamBPlayerScoreLabel.ZIndex = 1;
            teamAPlayerPingLabel.ZIndex  = 1;
            teamBPlayerPingLabel.ZIndex  = 1;

            AddTopLevel(teamAFrame, teamBFrame, footerFrame);
        }
Exemple #15
0
 public NewTextScreen(MainWindow window)
     : base(window, "NewText")
 {
     font  = new BMPFont("Content/Fonts/arial-20.fnt");
     font2 = new BMPFont("Content/Fonts/karmasuture-21.fnt");
 }