示例#1
0
        public GUIWidgets(int width, int height, SharedObjects shared) : base(Box.LayoutMode.Vertical, new WidgetStyle(new GUIStyle(HighLogic.Skin.window)))
        {
            instances.Add(new WeakReference(this));

            RecentToolTip = "";
            var gskin = UnityEngine.Object.Instantiate(HighLogic.Skin);

            // Use Arial as that's what used in other KSP GUIs
            gskin.font = WidgetStyle.FontNamed("Arial");

            // Undo KSP weirdness with toggle style
            gskin.toggle.clipping            = TextClipping.Clip;
            gskin.toggle.contentOffset       = Vector2.zero;
            gskin.toggle.fixedWidth          = 0;
            gskin.toggle.overflow            = new RectOffset(8, -45, 10, -1);
            gskin.toggle.padding             = new RectOffset(27, 0, 3, 0);
            gskin.toggle.margin              = new RectOffset(4, 4, 4, 4);
            gskin.toggle.border              = new RectOffset(40, 0, 40, 0);
            gskin.toggle.normal.background   = GameDatabase.Instance.GetTexture("kOS/GFX/toggle_bg_normal", false);
            gskin.toggle.onNormal.background = GameDatabase.Instance.GetTexture("kOS/GFX/toggle_bg_onnormal", false);
            gskin.toggle.active.background   = GameDatabase.Instance.GetTexture("kOS/GFX/toggle_bg_onactive", false);
            gskin.toggle.onActive.background = GameDatabase.Instance.GetTexture("kOS/GFX/toggle_bg_active", false);
            gskin.toggle.hover.background    = GameDatabase.Instance.GetTexture("kOS/GFX/toggle_bg_hover", false);
            gskin.toggle.onHover.background  = GameDatabase.Instance.GetTexture("kOS/GFX/toggle_bg_onhover", false);

            // Get back the style we made in the base initializer.
            gskin.window = ReadOnlyStyle;
            // no title area.
            gskin.window.padding.top = gskin.window.padding.bottom;

            // Stretch labels, otherwise ALIGN is confusing.
            gskin.label.stretchWidth = true;

            // align better with labels.
            gskin.horizontalSlider.margin.top    = 8;
            gskin.horizontalSlider.margin.bottom = 8;

            List <GUIStyle> styles = new List <GUIStyle>(gskin.customStyles);

            var flatLayout = new GUIStyle(gskin.box);

            flatLayout.name              = "flatLayout";
            flatLayout.margin            = new RectOffset(0, 0, 0, 0);
            flatLayout.padding           = new RectOffset(0, 0, 0, 0);
            flatLayout.normal.background = null;
            styles.Add(flatLayout);

            var popupWindow = new GUIStyle(gskin.window);

            popupWindow.name              = "popupWindow";
            popupWindow.padding.left      = 0;
            popupWindow.padding.right     = 0;
            popupWindow.margin            = new RectOffset(0, 0, 0, 0);
            popupWindow.normal.background = gskin.button.onNormal.background;
            popupWindow.border            = gskin.button.border;

            styles.Add(popupWindow);

            var popupMenu = new GUIStyle(gskin.button);

            popupMenu.name      = "popupMenu";
            popupMenu.alignment = TextAnchor.MiddleLeft;
            styles.Add(popupMenu);

            var popupMenuItem = new GUIStyle(gskin.label);

            popupMenuItem.name              = "popupMenuItem";
            popupMenuItem.margin.top        = 0;
            popupMenuItem.margin.bottom     = 0;
            popupMenuItem.normal.background = null;
            popupMenuItem.hover.background  = GameDatabase.Instance.GetTexture("kOS/GFX/popupmenu_bg_hover", false);
            popupMenuItem.hover.textColor   = Color.black;
            popupMenuItem.active.background = popupMenuItem.hover.background;
            popupMenuItem.stretchWidth      = true;
            styles.Add(popupMenuItem);

            var emptyHintStyle = new GUIStyle(gskin.label);

            emptyHintStyle.name             = "emptyHintStyle";
            emptyHintStyle.normal.textColor = new Color(0.6f, 0.6f, 0.6f, 0.8f);
            styles.Add(emptyHintStyle);

            var tipDisplayLabel = new GUIStyle(gskin.label);

            tipDisplayLabel.name             = "tipDisplay";
            tipDisplayLabel.normal.textColor = new Color(1f, 1f, 1f, 1f);
            styles.Add(tipDisplayLabel);

            gskin.customStyles = styles.ToArray();

            Skin = new WidgetSkin(gskin);

            var go = new GameObject("kOSGUIWindow");

            window = go.AddComponent <GUIWindow>();
            window.AttachTo(width, height, "", shared, this);
            InitializeSuffixes();
        }