Skip to content

Commit

Permalink
see desc#2
Browse files Browse the repository at this point in the history
+auto reload mode
*fix image selector default check
*fix left aligned text offset near the bar when scale > 1.5
+color picker alpha background
+save color picker hue + saturation
  • Loading branch information
Bulb4 committed Jul 30, 2024
1 parent 6a6e23a commit 9b636ce
Show file tree
Hide file tree
Showing 16 changed files with 282 additions and 4,984 deletions.
107 changes: 96 additions & 11 deletions internal/main-menu/Settings/Notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class InternalNotifications {
private readonly tree: Menu.Node
private readonly stateScripts: Menu.Toggle
private readonly clickState: Menu.Toggle
private readonly autoReloadState: Menu.Toggle

constructor(settings: Menu.Node) {
const icon = "menu/icons/notification.svg"
Expand All @@ -33,6 +34,15 @@ export class InternalNotifications {
true,
"Reload scripts on click on notification"
)
this.autoReloadState = treeScripts
.AddToggle("Auto reload on update", false)
.OnValue(t => {
t.IsHidden = !t.value
if (t.value !== !!this.AutoReload) {
// force switching the mode in OnDraw
this.pressStart = hrtime() - this.holdMs * 2
}
})

this.tree
.AddDropdown("Background cover", ["Octarine", "Dota 2"])
Expand All @@ -55,24 +65,85 @@ export class InternalNotifications {
NotificationsSDK.debug = this.tree.IsOpen
}

private ScriptLatest = true
private AutoReload: Nullable<ScriptsUpdated>

private pressStart = 0
private holdMs = 1000

public OnDraw(): void {
if (!this.pressStart) {
return
}

const ms = hrtime()
if (
this.pressStart > ms - this.holdMs * 30 &&
this.pressStart < ms - this.holdMs
) {
this.pressStart = 0

const newState = !this.AutoReload
const max = ms + (1 << 24)
this.AutoReload = new ScriptsUpdated(this.clickState.value, () => {
this.autoReloadState.value = false
this.autoReloadState.TriggerOnValueChangedCBs()
})
this.AutoReload.StartDisplayTime = newState ? ms : max
this.AutoReload.StopDisplayTime = newState ? max : ms

NotificationsSDK.Push(this.AutoReload, true)

if (!newState) {
this.AutoReload = undefined
}
if (this.autoReloadState.value !== newState) {
this.autoReloadState.value = newState
this.autoReloadState.TriggerOnValueChangedCBs()
Menu.Base.SaveConfigASAP = true
}
}
}
public OnBindPressed() {
if (this.ScriptLatest) {
this.pressStart = hrtime()
} else {
reload()
}
}
public OnBindRelease() {
if (hrtime() - this.pressStart < this.holdMs) {
reload()
}
this.pressStart = 0
}
public ScriptsUpdated(): void {
this.ScriptLatest = false
if (this.stateScripts.value) {
NotificationsSDK.Push(new ScriptsUpdated(this.clickState.value))

if (this.AutoReload) {
reload()
}
}
}
}

class ScriptsUpdated extends Notification {
constructor(private readonly clickState: boolean) {
super({ timeToShow: 6 * 1000 })
constructor(
private clickState: boolean,
private stopAutoReload?: () => void
) {
super({
timeToShow: stopAutoReload ? 0 : 6000,
uniqueKey: stopAutoReload ? "AutoReload" : undefined
})
}

public OnClick(): boolean {
if (!this.clickState) {
return false
}
reload()
return true
return this.stopAutoReload
? (this.stopAutoReload(), true)
: (reload(), this.clickState)
}

public Draw(position: Rectangle): void {
Expand Down Expand Up @@ -106,21 +177,35 @@ class ScriptsUpdated extends Notification {

const textFontSize = GUIInfo.ScaleHeight(11)
const textPadding = Math.ceil(infoPadding / 2)
const Text = Menu.Localization.Localize("Scripts update is ready")

let text

if (this.stopAutoReload) {
const waitingS = 0 | ((hrtime() - this.StartDisplayTime) / 1000)
const waitingM = 0 | (waitingS / 60)
text =
"Auto reload is ON.\nClick to disable.\nWaiting for " +
(waitingM ? waitingM + " minutes" : waitingS + " seconds")
} else {
text = Menu.Localization.Localize("Scripts update is ready")
}
const textSize = RendererSDK.GetTextSize(
Text,
text,
RendererSDK.DefaultFontName,
textFontSize
)

Position.AddScalarX(infoSize + textPadding)
Position.AddScalarY((infoSize - textSize.y - textSize.z) / 2)
RendererSDK.Text(
Text,
text,
Position,
opacityWhite,
RendererSDK.DefaultFontName,
textFontSize
textFontSize,
undefined,
undefined,
false
)
}
}
4 changes: 3 additions & 1 deletion internal/main-menu/Settings/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ export const InternalSettings = new (class {
const key = reloadTree.AddKeybind("Key Bind")
reloadTree.AddButton("Reload").OnValue(() => reload())
key.ActivatesInMenu = true
key.OnPressed(() => reload())
key.OnPressed(() => this.InternalNotifications.OnBindPressed())
key.OnRelease(() => this.InternalNotifications.OnBindRelease())
}

public Draw() {
this.InternalCamera.Draw()
this.InternalConfig.OnDraw()
this.InternalNotifications.onDraw()
this.InternalNotifications.OnDraw()
}

public MouseWheel(up: boolean) {
Expand Down
Loading

0 comments on commit 9b636ce

Please sign in to comment.