Skip to content

Commit

Permalink
Merge pull request #14 from Sirspam/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Sirspam authored Feb 12, 2023
2 parents 95a5d5e + 2e60b1c commit f6183ce
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
26 changes: 21 additions & 5 deletions Nya/UI/ViewControllers/NyaViewControllers/NyaViewController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using BeatSaberMarkupLanguage.Attributes;
using HMUI;
using Nya.Configuration;
Expand Down Expand Up @@ -59,15 +60,17 @@ protected NyaViewController(ImageUtils imageUtils, PluginConfig pluginConfig, Ti
protected void NyaPostParse()
{
NyaImage.material = ImageUtils.UIRoundEdgeMaterial;
NyaButton.interactable = false;
ImageUtils.LoadCurrentNyaImage(NyaImage, () => NyaButton.interactable = true);
SetNyaButtonsInteractability(false);
var time = DateTime.Now;
ImageUtils.LoadCurrentNyaImage(NyaImage, () => Task.Run(() => NyaButtonCooldown(time)));
}

[UIAction("nya-click")]
protected void NyaClicked()
{
NyaButton.interactable = false;
ImageUtils.LoadNewNyaImage(NyaImage, () => NyaButton.interactable = true);
SetNyaButtonsInteractability(false);
var time = DateTime.Now;
ImageUtils.LoadNewNyaImage(NyaImage, () => Task.Run(() => NyaButtonCooldown(time)));
}

[UIAction("nya-auto-clicked")]
Expand All @@ -89,6 +92,19 @@ public virtual void Dispose()
ImageUtils.ErrorSpriteLoadedEvent -= ImageUtilsOnErrorSpriteLoadedEvent;
}

private void SetNyaButtonsInteractability(bool value)
{
NyaButton.interactable = value;
NyaAutoButton.interactable = value;
}

private async void NyaButtonCooldown(DateTime pressedTime)
{
pressedTime = pressedTime.AddSeconds(1.25f);
await Task.Delay((int) Math.Max(0, (pressedTime - DateTime.Now).TotalMilliseconds));
SetNyaButtonsInteractability(true);
}

private void ImageUtilsOnErrorSpriteLoadedEvent()
{
if (AutoNyaActive)
Expand Down Expand Up @@ -123,7 +139,7 @@ protected void ToggleAutoNya(bool active)
}
}
}

private class AutoNyaManager : ILateTickable
{
public bool DoingDaThing;
Expand Down
4 changes: 2 additions & 2 deletions Nya/UI/Views/NyaView.bsml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
</vertical>

<vertical pad-top="2">
<img id="nya-image" preserve-aspect="true" pref-width="70" pref-height="70"/>
<horizontal spacing="10">
<img id="nya-image" preserve-aspect="true" pref-width="95" pref-height="70"/>
<horizontal spacing="10" horizontal-fit="PreferredSize" pref-width="70">
<button id="auto-button" text="Auto Nya" font-size="4.5" on-click="nya-auto-clicked" active="true" min-width="20"/>
<primary-button id="nya-button" text="Nya" font-size="4.5" on-click="nya-click" active="true" min-width="20"/>
<button id="settings-button" text="⚙" font-size="4.5" on-click="settings-button-clicked" min-width="20"/>
Expand Down
4 changes: 2 additions & 2 deletions Nya/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"id": "Nya",
"name": "Nya",
"author": "Sirspam",
"version": "0.6.1",
"description": "BeatSaber mod for displaying nya-tastic images from various anime themed web APIs",
"version": "0.6.2",
"description": "BeatSaber mod for displaying nya-tastic images from various web APIs",
"gameVersion": "1.21.0",
"icon": "Nya.Resources.Chocola_Mini_Sitting.png",
"dependsOn": {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Nya <img src="https://raw.githubusercontent.com/Sirspam/Sirspam/main/chocola_mini_sitting.png" align="right" width="150">
Beat Saber mod for displaying nya-tastic images from various anime themed web APIs
Beat Saber mod for displaying nya-tastic images from various web APIs
## Usage
### Accessing Nya's Settings
Nya's settings can be accessed from the ⚙️ button, pressing this will bring up a modal for common settings, such as the currently selected API. Further settings can be accessed from the ➕ tab.
Expand Down

0 comments on commit f6183ce

Please sign in to comment.