Skip to content

Commit 66f214e

Browse files
committed
Improve edit display for progress trigger
1 parent 1b71a09 commit 66f214e

File tree

3 files changed

+29
-22
lines changed

3 files changed

+29
-22
lines changed

src/trigger/progress/mod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,12 @@ impl ProgressTrigger {
5353
pub fn active_or_edit(&mut self, ctx: &Context, state: &RenderState) -> Option<ProgressActive> {
5454
if ctx.edit.is_editing() {
5555
if state.is_edit(ctx) {
56-
let apply = ctx.now - (ctx.now % 5000);
57-
Some(ProgressActive::Buff {
58-
stacks: 1,
59-
runout: apply + 5000,
60-
apply,
61-
})
56+
Some(self.source.progress_edit(ctx))
6257
} else {
6358
None
6459
}
6560
} else {
66-
self.active(ctx).map(Clone::clone)
61+
self.active(ctx).cloned()
6762
}
6863
}
6964
}

src/trigger/progress/source.rs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use super::ProgressActive;
12
use crate::{
23
action::Action,
34
colors,
@@ -10,15 +11,12 @@ use nexus::imgui::{ComboBoxFlags, InputTextFlags, Ui};
1011
use serde::{Deserialize, Serialize};
1112
use strum::{AsRefStr, EnumIter, IntoStaticStr};
1213

13-
use super::ProgressActive;
14-
15-
// FIXME: serde does not support flatten aliases, see https://github.com/serde-rs/serde/pull/2387
1614
#[derive(Debug, Default, Clone, AsRefStr, IntoStaticStr, EnumIter, Serialize, Deserialize)]
1715
pub enum ProgressSource {
1816
/// Always active, no associated progress.
1917
#[default]
20-
#[serde(alias = "Always")]
21-
None,
18+
#[serde(alias = "None")]
19+
Always,
2220

2321
/// Single buff id.
2422
#[serde(alias = "Single")]
@@ -44,13 +42,13 @@ impl_static_variants!(ProgressSource);
4442

4543
impl ProgressSource {
4644
pub fn always(&self) -> bool {
47-
matches!(self, Self::None)
45+
matches!(self, Self::Always)
4846
}
4947

5048
pub fn progress(&self, ctx: &Context) -> ProgressActive {
5149
match self {
52-
ProgressSource::None => ProgressActive::Resource(Resource { current: 1, max: 1 }),
53-
ProgressSource::Buff(id) => {
50+
Self::Always => ProgressActive::Resource(Resource { current: 1, max: 1 }),
51+
Self::Buff(id) => {
5452
let stacks = ctx.stacks_of(*id).unwrap_or(0);
5553
let (apply, runout) = ctx.time_range(*id).unwrap_or((0, 0));
5654
ProgressActive::Buff {
@@ -59,7 +57,7 @@ impl ProgressSource {
5957
runout,
6058
}
6159
}
62-
ProgressSource::AnyBuff(ids) => {
60+
Self::AnyBuff(ids) => {
6361
let stacks = ids.iter().filter_map(|id| ctx.stacks_of(*id)).sum(); // sum of all stacks
6462
let (apply, runout) = ids
6563
.iter()
@@ -71,11 +69,25 @@ impl ProgressSource {
7169
runout,
7270
}
7371
}
74-
ProgressSource::PrimaryResource => {
75-
ProgressActive::Resource(ctx.resources.primary.clone())
72+
Self::PrimaryResource => ProgressActive::Resource(ctx.resources.primary.clone()),
73+
Self::SecondaryResource => ProgressActive::Resource(ctx.resources.secondary.clone()),
74+
}
75+
}
76+
77+
pub fn progress_edit(&self, ctx: &Context) -> ProgressActive {
78+
match self {
79+
Self::Always => ProgressActive::Resource(Resource { current: 1, max: 1 }),
80+
Self::Buff(_) | Self::AnyBuff(_) => {
81+
let apply = ctx.now - (ctx.now % 5000);
82+
ProgressActive::Buff {
83+
stacks: 1,
84+
apply,
85+
runout: apply + 5000,
86+
}
7687
}
77-
ProgressSource::SecondaryResource => {
78-
ProgressActive::Resource(ctx.resources.secondary.clone())
88+
Self::PrimaryResource | Self::SecondaryResource => {
89+
let current = (ctx.now % 5000) / 100;
90+
ProgressActive::Resource(Resource { current, max: 50 })
7991
}
8092
}
8193
}

src/trigger/progress/threshold.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ pub enum ProgressThreshold {
2626
#[strum(serialize = "Max amount")]
2727
Max(u32),
2828

29-
/// Range of.
30-
#[strum(serialize = "Range of")]
29+
/// Range of amounts.
30+
#[strum(serialize = "Amount between")]
3131
Between(u32, u32),
3232
}
3333

0 commit comments

Comments
 (0)