Skip to content

Commit

Permalink
Add new keyboard shortcut to hide toolbar panels
Browse files Browse the repository at this point in the history
  • Loading branch information
sway2020 committed Dec 11, 2021
1 parent e54bb08 commit f23df59
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 30 deletions.
23 changes: 10 additions & 13 deletions src/GUI/UIThreading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public override void OnUpdate(float realTimeDelta, float simulationTimeDelta)

KeyCode modeToggleKey = (KeyCode)(Settings.modeToggleKey.keyCode);
KeyCode quickMenuKey = (KeyCode)(Settings.quickMenuKey.keyCode);
KeyCode hideMenuKey = (KeyCode)(Settings.hideMenuKey.keyCode);

// Null checks for safety.
// Check modifier keys according to settings.
Expand All @@ -42,6 +43,10 @@ public override void OnUpdate(float realTimeDelta, float simulationTimeDelta)
{
ProcessPressedKey(1);
}
else if (quickMenuKey != KeyCode.None && Input.GetKey(hideMenuKey) && CheckHotkey(Settings.hideMenuKey, altPressed, ctrlPressed, shiftPressed))
{
ProcessPressedKey(2);
}
else
{
// Relevant keys aren't pressed anymore; this keystroke is over, so reset and continue.
Expand Down Expand Up @@ -79,24 +84,16 @@ public void ProcessPressedKey(int index)
YetAnotherToolbar.instance.Expand();
YetAnotherToolbar.instance.mainButton.normalFgSprite = "Collapse";
}

// show update notice
if (!YetAnotherToolbar.instance.shownUpdateNoticeFlag)
{
YetAnotherToolbar.instance.shownUpdateNoticeFlag = true;
// show update notice
if (!Settings.disableUpdateNotice && (ModInfo.updateNoticeDate > Settings.lastUpdateNotice))
{
UIUpdateNoticePopUp.ShowAt();
Settings.lastUpdateNotice = ModInfo.updateNoticeDate;
XMLUtils.SaveSettings();
}
}

}
else if (index == 1)
{
UIQuickMenuPopUp.ShowAt(YetAnotherToolbar.instance.mainButton);
}
else if (index == 2)
{
YetAnotherToolbar.instance.ToggleMenuVisibility();
}

}
catch (Exception e)
Expand Down
Binary file added src/Icons/Collapse-Inverted.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Icons/Expand-Inverted.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 7 additions & 4 deletions src/ModInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@ namespace YetAnotherToolbar
{
public class ModInfo : IUserMod
{
public const string version = "1.0.2";
public const string version = "1.0.4";
public string Name => "Yet Another Toolbar " + version;
public string Description
{
get { return Translations.Translate("YAT_DESC"); }
}

public const double updateNoticeDate = 20210921;
public const double updateNoticeDate = 20211210;
public const string updateNotice =

"- Fix the main button position issue on non-16:9 resolutions\n\n" +
"- New keyboard shortcut (Alt+Space) to quickly hide toolbar panels\n\n" +

"- Offset and row/column numbers now can be manually entered\n\n";
" Unlike closing a panel, you can continue placing selected assets when the panels are hidden\n" +
" This should be useful when the panels are expanded to 3+ rows\n" +
" YAT\'s main button will be shown in inverted colors when this feature is active\n";

public void OnEnabled()
{
Expand Down Expand Up @@ -116,6 +118,7 @@ public void OnSettingsUI(UIHelperBase helper)
// shortcut keys
panel.gameObject.AddComponent<ModeToggleKeyMapping>();
panel.gameObject.AddComponent<QuickMenuKeyMapping>();
panel.gameObject.AddComponent<HideMenuKeyMapping>();
group.AddSpace(10);

}
Expand Down
4 changes: 4 additions & 0 deletions src/ModSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ internal static class Settings

internal static KeyBinding modeToggleKey = new KeyBinding { keyCode = (int)KeyCode.T, control = false, shift = false, alt = true };
internal static KeyBinding quickMenuKey = new KeyBinding { keyCode = (int)KeyCode.Q, control = false, shift = false, alt = true };
internal static KeyBinding hideMenuKey = new KeyBinding { keyCode = (int)KeyCode.Space, control = false, shift = false, alt = true };
}

/// <summary>
Expand Down Expand Up @@ -84,6 +85,9 @@ public class XMLSettingsFile
[XmlElement("quickMenuKey")]
public KeyBinding QuickMenuKey { get => Settings.quickMenuKey; set => Settings.quickMenuKey = value; }

[XmlElement("hideMenuKey")]
public KeyBinding HideMenuKey { get => Settings.hideMenuKey; set => Settings.hideMenuKey = value; }

[XmlElement("Language")]
public string Language
{
Expand Down
13 changes: 13 additions & 0 deletions src/OptionsKeymapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,17 @@ public override void UpdateSettingKeyBinding()
Settings.quickMenuKey = keyBinding;
}
}

public class HideMenuKeyMapping : OptionsKeymapping
{
HideMenuKeyMapping()
{
keyBinding = Settings.hideMenuKey;
labelString = Translations.Translate("YAT_SET_HMKEY");
}
public override void UpdateSettingKeyBinding()
{
Settings.hideMenuKey = keyBinding;
}
}
}
2 changes: 1 addition & 1 deletion src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.2")]
[assembly: AssemblyVersion("1.0.3")]
//[assembly: AssemblyFileVersion("1.1")]
1 change: 1 addition & 0 deletions src/Translations/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<Translation ID="YAT_QM_TRS" String="Transparent" />
<Translation ID="YAT_UP_TIT" String="Update" />
<Translation ID="YAT_UP_CNF" String="Confirm" />
<Translation ID="YAT_SET_HMKEY" String="Hide toolbar panels" />

</Translations>
</Language>
59 changes: 47 additions & 12 deletions src/YetAnotherToolbar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public class YetAnotherToolbar : MonoBehaviour
private Dictionary<UIPanel, UIScrollbar> dictVerticalScrollbars = new Dictionary<UIPanel, UIScrollbar>();
public bool shownUpdateNoticeFlag = false;

private bool hideMenuFlag = false;
private Vector2 lastMenuPosition;

public void Start()
{
try
Expand Down Expand Up @@ -70,18 +73,6 @@ public void Start()
mainButton.normalFgSprite = "Collapse";
}

// show update notice
if (!YetAnotherToolbar.instance.shownUpdateNoticeFlag)
{
YetAnotherToolbar.instance.shownUpdateNoticeFlag = true;
// show update notice
if (!Settings.disableUpdateNotice && (ModInfo.updateNoticeDate > Settings.lastUpdateNotice))
{
UIUpdateNoticePopUp.ShowAt();
Settings.lastUpdateNotice = ModInfo.updateNoticeDate;
XMLUtils.SaveSettings();
}
}
};
}
}
Expand All @@ -105,6 +96,19 @@ public void Update()
Expand();
}
UpdateBackground();

// show update notice
if (!YetAnotherToolbar.instance.shownUpdateNoticeFlag)
{
YetAnotherToolbar.instance.shownUpdateNoticeFlag = true;
// show update notice
if (!Settings.disableUpdateNotice && (ModInfo.updateNoticeDate > Settings.lastUpdateNotice))
{
UIUpdateNoticePopUp.ShowAt();
Settings.lastUpdateNotice = ModInfo.updateNoticeDate;
XMLUtils.SaveSettings();
}
}
}
}

Expand All @@ -116,6 +120,8 @@ private static UITextureAtlas LoadResources()
{
"Collapse",
"Expand",
"Collapse-Inverted",
"Expand-Inverted",
"SubcategoriesPanel75",
"SubcategoriesPanel50",
"SubcategoriesPanel25",
Expand Down Expand Up @@ -179,8 +185,35 @@ public void RestoreScale()
tsContainer.transform.localScale = new Vector2(Settings.toolbarScale, Settings.toolbarScale);
}

public void ToggleMenuVisibility()
{
if (!this.hideMenuFlag)
{
this.hideMenuFlag = true;
lastMenuPosition = tsContainer.relativePosition;
tsContainer.relativePosition = new Vector2(-50000, -50000);

if (Settings.expanded) mainButton.normalFgSprite = "Collapse-Inverted";
else mainButton.normalFgSprite = "Expand-Inverted";
}
else
{
this.hideMenuFlag = false;
tsContainer.relativePosition = this.lastMenuPosition;
if (Settings.expanded) mainButton.normalFgSprite = "Collapse";
else mainButton.normalFgSprite = "Expand";
}
}

public void CheckMenuVisibility()
{
if (!this.hideMenuFlag) return;
ToggleMenuVisibility();
}

public void UpdatePanelPosition()
{
CheckMenuVisibility();
UIView view = UIView.GetAView();
float x = (596f * view.GetScreenResolution().x / 1920f) + Settings.horizontalOffset;
float y = -110f + Settings.verticalOffset;
Expand All @@ -196,8 +229,10 @@ public void UpdatePanelPosition()

}


private void UpdateLayout(int numOfRows, int numOfCols)
{
CheckMenuVisibility();
try
{
UITabContainer gtsContainer;
Expand Down
2 changes: 2 additions & 0 deletions src/YetAnotherToolbar.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@
<ItemGroup>
<EmbeddedResource Include="Icons\GenericTabHovered.png" />
<EmbeddedResource Include="Icons\SubcategoriesPanel.png" />
<EmbeddedResource Include="Icons\Collapse-Inverted.png" />
<EmbeddedResource Include="Icons\Expand-Inverted.png" />
<Content Include="Translations\en.xml" />
<Content Include="Translations\es.xml" />
<Content Include="Translations\fr.xml" />
Expand Down

0 comments on commit f23df59

Please sign in to comment.