Skip to content

Commit 49de33a

Browse files
Fixed issue with stock toolbar not changing textures
Replaced Debug.Log with logging class to reduce log spam
1 parent 1fafb21 commit 49de33a

File tree

8 files changed

+149
-29
lines changed

8 files changed

+149
-29
lines changed
44 KB
Binary file not shown.

ChangeLog.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
0.1.0
2-
Initial release
1+
0.1.2
2+
Fixed issue with stock toolbar not changing textures
3+
Replaced Debug.Log with logging class to reduce log spam
34

45
0.1.1
56
Moved mod into the 000_Toolbar directory
@@ -10,5 +11,10 @@
1011
Show tooltips
1112
Stock tooltip timeout
1213

14+
0.1.0
15+
Initial release
16+
17+
18+
1319
TODO
1420
Add tooltip options to Blizzy

GameData/000_Toolbar/ToolbarControl.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
{
1212
"MAJOR" : 0,
1313
"MINOR" : 1,
14-
"PATCH" : 1,
14+
"PATCH" : 2,
1515
"BUILD" : 0
1616
}
1717
}

ToolbarControl.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
{
1212
"MAJOR" : 0,
1313
"MINOR" : 1,
14-
"PATCH" : 1,
14+
"PATCH" : 2,
1515
"BUILD" : 0
1616
}
1717
}

ToolbarControl/AssemblyVersion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55

66
using System.Reflection;
77

8-
[assembly: AssemblyVersion("0.1.1.0")]
8+
[assembly: AssemblyVersion("0.1.2.0")]

ToolbarControl/Log.cs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
using System;
2+
using System.Collections;
3+
using System.Diagnostics;
4+
5+
namespace ToolbarControl_NS
6+
{
7+
public static class Log
8+
{
9+
public enum LEVEL
10+
{
11+
OFF = 0,
12+
ERROR = 1,
13+
WARNING = 2,
14+
INFO = 3,
15+
DETAIL = 4,
16+
TRACE = 5
17+
};
18+
19+
public static LEVEL level = LEVEL.INFO;
20+
21+
private static readonly String PREFIX = "EngineIgnitor" + ": ";
22+
23+
public static LEVEL GetLevel()
24+
{
25+
return level;
26+
}
27+
28+
public static void SetLevel(LEVEL level)
29+
{
30+
UnityEngine.Debug.Log("log level " + level);
31+
Log.level = level;
32+
}
33+
34+
public static LEVEL GetLogLevel()
35+
{
36+
return level;
37+
}
38+
39+
private static bool IsLevel(LEVEL level)
40+
{
41+
return level == Log.level;
42+
}
43+
44+
public static bool IsLogable(LEVEL level)
45+
{
46+
return level <= Log.level;
47+
}
48+
49+
public static void Trace(String msg)
50+
{
51+
if (IsLogable(LEVEL.TRACE))
52+
{
53+
UnityEngine.Debug.Log(PREFIX + msg);
54+
}
55+
}
56+
57+
public static void Detail(String msg)
58+
{
59+
if (IsLogable(LEVEL.DETAIL))
60+
{
61+
UnityEngine.Debug.Log(PREFIX + msg);
62+
}
63+
}
64+
65+
[ConditionalAttribute("DEBUG")]
66+
public static void Info(String msg)
67+
{
68+
if (IsLogable(LEVEL.INFO))
69+
{
70+
UnityEngine.Debug.Log(PREFIX + msg);
71+
}
72+
}
73+
74+
[ConditionalAttribute("DEBUG")]
75+
public static void Test(String msg)
76+
{
77+
//if (IsLogable(LEVEL.INFO))
78+
{
79+
UnityEngine.Debug.LogWarning(PREFIX + "TEST:" + msg);
80+
}
81+
}
82+
83+
public static void Warning(String msg)
84+
{
85+
if (IsLogable(LEVEL.WARNING))
86+
{
87+
UnityEngine.Debug.LogWarning(PREFIX + msg);
88+
}
89+
}
90+
91+
public static void Error(String msg)
92+
{
93+
if (IsLogable(LEVEL.ERROR))
94+
{
95+
UnityEngine.Debug.LogError(PREFIX + msg);
96+
}
97+
}
98+
99+
public static void Exception(Exception e)
100+
{
101+
Log.Error("exception caught: " + e.GetType() + ": " + e.Message);
102+
}
103+
104+
}
105+
}

ToolbarControl/ToolbarControl.cs

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,18 @@ private void SetIsEnabled(bool b)
101101
/// <param name="largeToolbarIcon"></param>
102102
/// <param name="smallToolbarIcon"></param>
103103
public void AddToAllToolbars(TC_ClickHandler onTrue, TC_ClickHandler onFalse,
104-
ApplicationLauncher.AppScenes visibleInScenes, string nameSpace, string toolbarId, string largeToolbarIcon, string smallToolbarIcon, string toolTip = null)
104+
ApplicationLauncher.AppScenes visibleInScenes, string nameSpace, string toolbarId,
105+
string largeToolbarIcon,
106+
string smallToolbarIcon,
107+
string toolTip = null)
105108
{
106109
AddToAllToolbars(onTrue, onFalse, null, null, null, null,
107110
visibleInScenes, nameSpace, toolbarId, largeToolbarIcon, largeToolbarIcon, smallToolbarIcon, smallToolbarIcon, toolTip);
108111
}
112+
109113
public void AddToAllToolbars(TC_ClickHandler onTrue, TC_ClickHandler onFalse,
110-
ApplicationLauncher.AppScenes visibleInScenes, string nameSpace, string toolbarId, string largeToolbarIconActive,
114+
ApplicationLauncher.AppScenes visibleInScenes, string nameSpace, string toolbarId,
115+
string largeToolbarIconActive,
111116
string largeToolbarIconInactive,
112117
string smallToolbarIconActive,
113118
string smallToolbarIconInactive, string toolTip = null)
@@ -156,7 +161,7 @@ public void AddToAllToolbars(TC_ClickHandler onTrue, TC_ClickHandler onFalse, TC
156161
this.StockToolbarIconInactive = largeToolbarIconInactive;
157162
if (HighLogic.CurrentGame.Parameters.CustomParams<TC>().showStockTooltips)
158163
this.ToolTip = toolTip;
159-
Debug.Log("AddToAllToolbars");
164+
Log.Info("AddToAllToolbars");
160165
SetupGameScenes(visibleInScenes);
161166
StartAfterInit();
162167
}
@@ -197,8 +202,8 @@ void SetButtonPos()
197202
private ApplicationLauncherButton stockButton;
198203
private IButton blizzyButton;
199204

200-
private string toolbarIconActive = "";
201-
private string toolbarIconInactive = "";
205+
//private string toolbarIconActive = "";
206+
//private string toolbarIconInactive = "";
202207

203208
public static bool buttonActive = false;
204209

@@ -232,13 +237,13 @@ private void RemoveBlizzyButton()
232237

233238
private void SetBlizzySettings()
234239
{
235-
Debug.Log("SetBlzzySettings");
240+
Log.Info("SetBlzzySettings");
236241
if (activeToolbarType == ToolBarSelected.stock)
237242
{
238243
RemoveStockButton();
239244
}
240-
this.toolbarIconActive = BlizzyToolbarIconActive;
241-
this.toolbarIconInactive = BlizzyToolbarIconInactive;
245+
//this.toolbarIconActive = BlizzyToolbarIconActive;
246+
//this.toolbarIconInactive = BlizzyToolbarIconInactive;
242247

243248
this.blizzyButton = ToolbarManager.Instance.add(nameSpace, toolbarId);
244249
this.blizzyButton.ToolTip = ToolTip;
@@ -252,7 +257,7 @@ private void SetBlizzySettings()
252257

253258
private void SetStockSettings()
254259
{
255-
Debug.Log("SetStockSettings");
260+
Log.Info("SetStockSettings");
256261
if (activeToolbarType == ToolBarSelected.blizzy)
257262
{
258263
RemoveBlizzyButton();
@@ -262,8 +267,8 @@ private void SetStockSettings()
262267
GameEvents.onGUIApplicationLauncherDestroyed.Add(OnGUIAppLauncherDestroyed);
263268
OnGUIAppLauncherReady();
264269

265-
this.toolbarIconActive = StockToolbarIconActive;
266-
this.toolbarIconInactive = StockToolbarIconInactive;
270+
//this.toolbarIconActive = StockToolbarIconActive;
271+
//this.toolbarIconInactive = StockToolbarIconInactive;
267272

268273
activeToolbarType = ToolBarSelected.stock;
269274
this.UpdateToolbarIcon();
@@ -272,7 +277,7 @@ private void SetStockSettings()
272277

273278
private void StartAfterInit()
274279
{
275-
Debug.Log("StartAfterInit");
280+
Log.Info("StartAfterInit");
276281

277282
SetStockSettings();
278283

@@ -285,7 +290,7 @@ private void StartAfterInit()
285290

286291
public void OnDestroy()
287292
{
288-
Debug.Log("ToolbarControl OnDestroy");
293+
Log.Info("ToolbarControl OnDestroy");
289294
if (activeToolbarType == ToolBarSelected.stock)
290295
{
291296
GameEvents.onGUIApplicationLauncherReady.Remove(OnGUIAppLauncherReady);
@@ -301,18 +306,21 @@ public void OnDestroy()
301306

302307
private void UpdateToolbarIcon()
303308
{
304-
Debug.Log("UpdateToolbarIcon, isEnabled: " + isEnabled);
309+
Log.Info("UpdateToolbarIcon, isEnabled: " + isEnabled);
305310
SetIsEnabled(isEnabled);
306311
if (activeToolbarType == ToolBarSelected.blizzy)
307312
{
308-
this.blizzyButton.TexturePath = buttonActive ? this.toolbarIconActive : this.toolbarIconInactive;
313+
this.blizzyButton.TexturePath = buttonActive ? this.BlizzyToolbarIconActive : this.BlizzyToolbarIconInactive;
309314
}
310315
else
311316
{
312317
if (stockButton == null)
313-
Debug.Log("stockButton is null");
318+
Log.Info("stockButton is null");
314319
else
315-
this.stockButton.SetTexture((Texture)GameDatabase.Instance.GetTexture(buttonActive ? this.toolbarIconActive : this.toolbarIconInactive, false));
320+
{
321+
Log.Info("buttonActive: " + buttonActive + ", StockToolbarIconActive: " + StockToolbarIconActive + ", StockToolbarIconInactive: " + StockToolbarIconInactive);
322+
this.stockButton.SetTexture((Texture)GameDatabase.Instance.GetTexture(buttonActive ? this.StockToolbarIconActive : this.StockToolbarIconInactive, false));
323+
}
316324
}
317325
}
318326
private void OnGUIAppLauncherReady()
@@ -326,27 +334,27 @@ private void OnGUIAppLauncherReady()
326334
doOnFalse,
327335
doOnHover,
328336
doOnHoverOut,
329-
doOonEnable,
337+
doOnEnable,
330338
doOnDisable,
331339
visibleInScenes,
332340
(Texture)GameDatabase.Instance.GetTexture(StockToolbarIconActive, false));
333341
SetStockSettings();
334342
}
335343
}
336-
private void doOnTrue() { SetButtonPos(); onTrue(); }
337-
private void doOnFalse() { SetButtonPos(); onFalse(); }
344+
private void doOnTrue() { SetButtonPos(); if (this.onTrue != null) ToggleButtonActive(); }
345+
private void doOnFalse() { SetButtonPos(); if (this.onFalse != null) ToggleButtonActive(); }
338346
private void doOnHover()
339347
{
340348
if (activeToolbarType == ToolBarSelected.stock)
341349
{
342350
drawTooltip = true;
343351
starttimeToolTipShown = Time.fixedTime;
344352
}
345-
onHover();
353+
if (this.onHover != null) onHover();
346354
}
347-
private void doOnHoverOut() { drawTooltip = false; onHoverOut(); }
348-
private void doOonEnable() { onEnable(); }
349-
private void doOnDisable() { onDisable(); }
355+
private void doOnHoverOut() { drawTooltip = false; if (this.onHoverOut != null) onHoverOut(); }
356+
private void doOnEnable() { if (this.onEnable != null) onEnable(); }
357+
private void doOnDisable() { if (this.onDisable != null) onDisable(); }
350358

351359
private void button_Click(ClickEvent e)
352360
{

ToolbarControl/ToolbarControl.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
<DesignTime>True</DesignTime>
5353
<DependentUpon>AssemblyVersion.tt</DependentUpon>
5454
</Compile>
55+
<Compile Include="Log.cs" />
5556
<Compile Include="Properties\AssemblyInfo.cs" />
5657
<Compile Include="Settings.cs" />
5758
<Compile Include="ToolbarControl.cs" />

0 commit comments

Comments
 (0)