From 69b31f24a9786b06f964ec82fd774792441bbc74 Mon Sep 17 00:00:00 2001 From: Guillaume ARM Date: Thu, 23 May 2024 22:19:38 +0200 Subject: [PATCH] feat(CountersSelector): add 'm' shortcut --- libs/ui/CountersSelector.lua | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/libs/ui/CountersSelector.lua b/libs/ui/CountersSelector.lua index e3b016f..85a36b3 100644 --- a/libs/ui/CountersSelector.lua +++ b/libs/ui/CountersSelector.lua @@ -131,7 +131,7 @@ local function renderTitle(win, countersMap, selectedCounter, titleFn) end) end -local function incrementCounter(countersMap, selectedCounter) +local function incrementSelectedCounter(countersMap, selectedCounter) local counterPayload = countersMap[selectedCounter] if counterPayload and counterPayload.count then @@ -146,7 +146,7 @@ local function incrementCounter(countersMap, selectedCounter) return false end -local function decrementCounter(countersMap, selectedCounter) +local function decrementSelectedCounter(countersMap, selectedCounter) local counterPayload = countersMap[selectedCounter] if counterPayload and counterPayload.count and counterPayload.count > 0 then @@ -161,6 +161,24 @@ local function decrementCounter(countersMap, selectedCounter) return false end +local function switchMinMaxSelectedCounter(countersMap, selectedCounter, maxPossibleCount) + local counterPayload = countersMap[selectedCounter] + + if counterPayload and counterPayload.count then + if counterPayload.count > 0 then + countersMap[selectedCounter] = { + count = 0, + name = counterPayload.name + } + else + countersMap[selectedCounter] = { + count = maxPossibleCount, + name = counterPayload.name + } + end + end +end + local function CountersSelector(initialCountersMap, config) local countersMap = utils.shallowClone(initialCountersMap) local counterMax = config.counterMax @@ -201,15 +219,19 @@ local function CountersSelector(initialCountersMap, config) elseif keyPressed == keys.down then selectedCounter = math.min(nbCounters, selectedCounter + 1) elseif keyPressed == keys.left and globalCounter > 0 then - if decrementCounter(countersMap, selectedCounter) then + if decrementSelectedCounter(countersMap, selectedCounter) then globalCounter = globalCounter - 1 end elseif keyPressed == keys.right and globalCounter < counterMax then - if incrementCounter(countersMap, selectedCounter) then + if incrementSelectedCounter(countersMap, selectedCounter) then globalCounter = globalCounter + 1 end + elseif keyPressed == keys.m then + switchMinMaxSelectedCounter(countersMap, selectedCounter, counterMax - globalCounter) + globalCounter = getTotalCount(countersMap) elseif keyPressed == keys.r then countersMap = resetAllCounters(countersMap) + globalCounter = 0 elseif keyPressed == keys.enter then shouldContinue = false elseif keypRessed == keys.q then