Skip to content

Commit 2c26800

Browse files
authored
Merge pull request #4343 from pleroy/4333
Make our windows opaque dark grey
2 parents 99a4e14 + 3a7d880 commit 2c26800

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

ksp_plugin_adapter/style.cs

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,38 @@ internal static class Style {
1414
public static UnityEngine.Color MarkerCaptionPinned { get; }
1515
= new UnityEngine.Color(191f / 255f, 1f, 0f, 0.6f);
1616

17+
public static UnityEngine.GUIStyle WindowBackground() {
18+
// Apparently the textures disappear on scene changes, so we must check if
19+
// they still exist.
20+
if (window_background_style_ == null ||
21+
!window_background_style_.active.background) {
22+
// Don't do anything for hover, it causes the title bar to change color
23+
// and become unreadable.
24+
window_background_style_ =
25+
new UnityEngine.GUIStyle(UnityEngine.GUI.skin.window){
26+
active = {
27+
background = dark_grey_texture
28+
},
29+
focused = {
30+
background = dark_grey_texture
31+
},
32+
normal = {
33+
background = dark_grey_texture
34+
},
35+
onActive = {
36+
background = dark_grey_texture
37+
},
38+
onFocused = {
39+
background = dark_grey_texture
40+
},
41+
onNormal = {
42+
background = dark_grey_texture
43+
}
44+
};
45+
}
46+
return window_background_style_;
47+
}
48+
1749
public static UnityEngine.GUIStyle DarkToggleButton() {
1850
var style = new UnityEngine.GUIStyle(UnityEngine.GUI.skin.button){
1951
active = {
@@ -114,7 +146,8 @@ public static UnityEngine.GUIStyle Multiline(UnityEngine.GUIStyle style) {
114146
}
115147

116148
public static void HorizontalLine() {
117-
if (horizontal_line_style_ == null) {
149+
if (horizontal_line_style_ == null ||
150+
!horizontal_line_style_.normal.background) {
118151
horizontal_line_style_ =
119152
new UnityEngine.GUIStyle(UnityEngine.GUI.skin.horizontalSlider);
120153
horizontal_line_style_.fixedHeight /= 5;
@@ -125,12 +158,26 @@ public static void HorizontalLine() {
125158

126159
public static void LineSpacing() {
127160
if (line_spacing_style_ == null) {
128-
line_spacing_style_ = new UnityEngine.GUIStyle(UnityEngine.GUI.skin.label);
161+
line_spacing_style_ =
162+
new UnityEngine.GUIStyle(UnityEngine.GUI.skin.label);
129163
line_spacing_style_.fixedHeight /= 5;
130164
}
131165
UnityEngine.GUILayout.Label("", line_spacing_style_);
132166
}
133167

168+
private static UnityEngine.Texture2D dark_grey_texture {
169+
get {
170+
var texture = new UnityEngine.Texture2D(width: 4, height: 4);
171+
for (int i = 0; i < 4; ++i) {
172+
for (int j = 0; j < 4; ++j) {
173+
texture.SetPixel(i, j, XKCDColors.DarkGrey);
174+
}
175+
}
176+
texture.Apply();
177+
return texture;
178+
}
179+
}
180+
134181
private static UnityEngine.Texture2D ultra_cool_grey_texture {
135182
get {
136183
var texture = new UnityEngine.Texture2D(width : 4, height : 4);
@@ -139,6 +186,7 @@ private static UnityEngine.Texture2D ultra_cool_grey_texture {
139186
texture.SetPixel(i, j, ultra_cool_grey_);
140187
}
141188
}
189+
texture.Apply();
142190
return texture;
143191
}
144192
}
@@ -152,6 +200,7 @@ private static UnityEngine.Texture2D ultra_cool_grey_texture {
152200
// for each horizontal line we display. See #3064.
153201
private static UnityEngine.GUIStyle horizontal_line_style_;
154202
private static UnityEngine.GUIStyle line_spacing_style_;
203+
private static UnityEngine.GUIStyle window_background_style_;
155204
}
156205

157206
} // namespace ksp_plugin_adapter

ksp_plugin_adapter/window_renderer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ public void RenderWindow() {
140140
screenRect : rectangle_,
141141
func : RenderWindowAndRecordTooltip,
142142
text : Title,
143+
style : Style.WindowBackground(),
143144
options : options_);
144145

145146
// The first time a window is shown, we have a moral duty to place it at
@@ -160,6 +161,7 @@ public void RenderWindow() {
160161
height : 0),
161162
func : RenderWindowAndRecordTooltip,
162163
text : Title,
164+
style : Style.WindowBackground(),
163165
options : options_);
164166
must_centre_ = false;
165167
}

0 commit comments

Comments
 (0)