diff --git a/FloatingSpace/CircularMenuItem.js b/FloatingSpace/CircularMenuItem.js index 1753835cb..9fb252e8b 100644 --- a/FloatingSpace/CircularMenuItem.js +++ b/FloatingSpace/CircularMenuItem.js @@ -65,13 +65,18 @@ function newCircularMenuItem () { let defaultBackgroudColor = UI_COLOR.RED let backgroundColorToUse = UI_COLOR.RED let temporaryStatus = 0 + let temporaryStatusCounter = 0 const EXTRA_MOUSE_OVER_ICON_SIZE = 2 - const STATUS_DEFAULT = 0 - const STATUS_WORKING = -1 - const STAtUS_SECONDARY_WORKING = -2 + const STATUS_NO_ACTION_TAKEN_YET = 0 + const STATUS_PRIMARY_ACTION_WORKING = -1 + const STATUS_SECONDARY_ACTION_WORKING = -2 const STATUS_PRIMARY_WORK_DONE = -3 + const STATUS_PRIMARY_WORK_FAILED = -4 + const STATUS_WAITING_CONFIRMATION = -5 + const STATUS_SECONDARY_WORK_DONE = -6 + const STATUS_SECONDARY_WORK_FAILED = -7 return thisObject @@ -139,11 +144,12 @@ function newCircularMenuItem () { /* Temporary Status impacts on the label to use and the background of that label */ - if (temporaryStatus > 0) { - temporaryStatus-- + if (temporaryStatusCounter > 0) { + temporaryStatusCounter-- } - if (temporaryStatus === STATUS_DEFAULT) { + if (temporaryStatusCounter === 0) { + temporaryStatus = STATUS_NO_ACTION_TAKEN_YET labelToPrint = thisObject.label backgroundColorToUse = defaultBackgroudColor thisObject.nextAction = thisObject.action @@ -153,7 +159,14 @@ function newCircularMenuItem () { } function iconPhysics () { - if (temporaryStatus === STATUS_PRIMARY_WORK_DONE || temporaryStatus === STAtUS_SECONDARY_WORKING) { + if ( + ( + temporaryStatus === STATUS_PRIMARY_WORK_DONE || + temporaryStatus === STATUS_SECONDARY_ACTION_WORKING || + temporaryStatus === STATUS_SECONDARY_WORK_DONE || + temporaryStatus === STATUS_SECONDARY_WORK_FAILED + ) && thisObject.secondaryAction !== undefined + ) { thisObject.iconOn = canvas.strategySpace.iconCollection.get(thisObject.secondaryIcon) thisObject.iconOff = canvas.strategySpace.iconCollection.get(thisObject.secondaryIcon) } else { @@ -198,65 +211,75 @@ function newCircularMenuItem () { } function onMouseClick () { + if (thisObject.label === undefined) { + /* This is what we have in the case of menu items that are only Icons. In this situation there is no complex logic, just execute the specified action. */ + thisObject.actionFunction(thisObject.payload, thisObject.action) + return + } + if (thisObject.askConfirmation !== true) { /* No confirmation is needed */ - if (temporaryStatus === STATUS_DEFAULT || temporaryStatus === STATUS_PRIMARY_WORK_DONE) { + if (temporaryStatus === STATUS_NO_ACTION_TAKEN_YET || temporaryStatus === STATUS_PRIMARY_WORK_DONE) { executeAction() - } + } // Any click out of those states is ignored } else { /* Confirmation is needed */ - /* A Click during confirmation executes the pre-defined action. */ - if (temporaryStatus > 0) { - executeAction() - } - /* The first click ask for confirmation. */ - if (temporaryStatus === 0) { - setTemporaryStatus(thisObject.confirmationLabel, UI_COLOR.GREY, 250) + if (temporaryStatus === STATUS_NO_ACTION_TAKEN_YET) { + setStatus(thisObject.confirmationLabel, UI_COLOR.GREY, 250, STATUS_WAITING_CONFIRMATION) + return + } + /* A Click during confirmation executes the pre-defined action. */ + if (temporaryStatus === STATUS_WAITING_CONFIRMATION || temporaryStatus === STATUS_PRIMARY_WORK_DONE) { + executeAction() + return } } function executeAction () { - if (labelToPrint !== thisObject.workingLabel) { + if (temporaryStatus === STATUS_NO_ACTION_TAKEN_YET || temporaryStatus === STATUS_WAITING_CONFIRMATION) { /* We need to execute the main Action */ /* If there is a working label defined, we use it here. */ if (thisObject.workingLabel !== undefined) { - setTemporaryStatus(thisObject.workingLabel, UI_COLOR.GREY, STATUS_WORKING) // Status will not expire, will only change with a callback. Mouse Clicks will be ignored. + setStatus(thisObject.workingLabel, UI_COLOR.GREY, undefined, STATUS_PRIMARY_ACTION_WORKING) // Status will not expire, will only change with a callback. Mouse Clicks will be ignored. } /* Execute the action and wait for callbacks to update our statuus. */ thisObject.actionFunction(thisObject.payload, thisObject.action, onPrimaryCallBack) - } else { + return + } + if (temporaryStatus === STATUS_PRIMARY_WORK_DONE && thisObject.secondaryAction !== undefined) { /* We need to execute the secondary action. */ if (thisObject.secondaryWorkingLabel !== undefined) { - setTemporaryStatus(thisObject.secondaryWorkingLabel, UI_COLOR.GREY, STAtUS_SECONDARY_WORKING) // Status will not expire, will only change with a callback. Mouse Clicks will be ignored. + setStatus(thisObject.secondaryWorkingLabel, UI_COLOR.GREY, undefined, STATUS_SECONDARY_ACTION_WORKING) // Status will not expire, will only change with a callback. Mouse Clicks will be ignored. } /* Execute the action and wait for callbacks to update our statuus. */ thisObject.actionFunction(thisObject.payload, thisObject.secondaryAction, onSecondaryCallBack) + return } function onPrimaryCallBack (err) { /* If there is a secondary action we will act different that if there is not */ - if (thisObject.secondaryAction === undefined) { + if (thisObject.secondaryAction === undefined) { // This means there are no more possible actions. if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result) { if (thisObject.workDoneLabel !== undefined) { - setTemporaryStatus(thisObject.workDoneLabel, UI_COLOR.PATINATED_TURQUOISE, 250) + setStatus(thisObject.workDoneLabel, UI_COLOR.PATINATED_TURQUOISE, 250, STATUS_PRIMARY_WORK_DONE) } } else { if (thisObject.workFailedLabel != undefined) { - setTemporaryStatus(thisObject.workFailedLabel, UI_COLOR.TITANIUM_YELLOW, 500) + setStatus(thisObject.workFailedLabel, UI_COLOR.TITANIUM_YELLOW, 500, STATUS_PRIMARY_WORK_FAILED) } } } else { if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result) { if (thisObject.workDoneLabel !== undefined) { thisObject.nextAction = thisObject.secondaryAction - setTemporaryStatus(thisObject.secondaryLabel, defaultBackgroudColor, STATUS_PRIMARY_WORK_DONE) + setStatus(thisObject.secondaryLabel, defaultBackgroudColor, undefined, STATUS_PRIMARY_WORK_DONE) } } else { if (thisObject.workFailedLabel != undefined) { - setTemporaryStatus(thisObject.workFailedLabel, UI_COLOR.TITANIUM_YELLOW, 500) + setStatus(thisObject.workFailedLabel, UI_COLOR.TITANIUM_YELLOW, 500, STATUS_PRIMARY_WORK_FAILED) } } } @@ -264,21 +287,25 @@ function newCircularMenuItem () { function onSecondaryCallBack (err) { if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result) { if (thisObject.secondaryWorkDoneLabel !== undefined) { - setTemporaryStatus(thisObject.secondaryWorkDoneLabel, UI_COLOR.PATINATED_TURQUOISE, 250) + setStatus(thisObject.secondaryWorkDoneLabel, UI_COLOR.PATINATED_TURQUOISE, 250, STATUS_SECONDARY_WORK_DONE) } } else { if (thisObject.secondaryWorkFailedLabel != undefined) { - setTemporaryStatus(thisObject.secondaryWorkFailedLabel, UI_COLOR.TITANIUM_YELLOW, 500) + setStatus(thisObject.secondaryWorkFailedLabel, UI_COLOR.TITANIUM_YELLOW, 500, STATUS_SECONDARY_WORK_FAILED) } } } } } - function setTemporaryStatus (text, backgroundColor, waitingCycles) { + function setStatus (text, backgroundColor, waitingCycles, newStatus) { labelToPrint = text backgroundColorToUse = backgroundColor - temporaryStatus = waitingCycles + temporaryStatus = newStatus + temporaryStatusCounter = newStatus // This will often put this into negatives numbers, which will disable the counting back and automatic reseting. + if (waitingCycles !== undefined) { // This will override the often negative value with a positive one that will tend to zero onto the default state. + temporaryStatusCounter = waitingCycles + } } function drawBackground () {