Unciv icon indicating copy to clipboard operation
Unciv copied to clipboard

Spy Icon disabled when not on turn

Open tuvus opened this issue 1 year ago • 6 comments

This PR is a small fix of #11584 and #11587

Basically, the spy icon could be clicked from a spectator or when it isn't the active player's turn. I simply added an extra if statement since the icon can't be disabled.

tuvus avatar May 16 '24 13:05 tuvus

since the icon can't be disabled

Why not? Anything can... What would the desired effect be?

SomeTroglodyte avatar May 16 '24 14:05 SomeTroglodyte

Why not? Anything can... What would the desired effect be?

That the onClick() doesn't trigger. The way I have here works as well.

tuvus avatar May 16 '24 14:05 tuvus

Well yes the other place is a Button and we're using our extension .disable() that does style manipulation the hard way but also sets the Gdx flag so that clicks are discarded... But giving a Table+Images based element a visual clue isn't out of the question...

Interestingly, changing the container's (the Table getSpyIcon returns) color tint has no effect, but setting alpha (else this.color.a = 0.5f) does show... Gdx and its premultiplied alpha handling isn't always intuitive.

An aside - Actor.color = Color.GRAY looks like it assigns the static but mutable instance's reference to the Actor's field... But it doesn't, it mutates the Actor's own private Color instance and copies rgba into it. There's counter-examples which will get you psychedelic effects from opening up one of the predefined statics to mutation - with exactly the same syntax...

All that said, dimmed Spy icons don't really look that good. Do it only if you want to hammer home the Spectator has not have power over them.

SomeTroglodyte avatar May 16 '24 15:05 SomeTroglodyte

Looking at the code - dunno why I didn't notice earlier.

  • getImage("OtherIcons/Spy_White").apply { color = Color.WHITE } - the entire apply is redundant, doesn't change anything. Any Actor's default color field is already white. Same for arrow.color = Color.WHITE in MoveToCityButton.

  • And we could probably get away with something like

    private fun Table.addActivationHandlers(spy: Spy) {
        onClick {
            onSpyClicked(moveSpyButtons[spy]!!, spy)
        }
        onRightClick {
            onSpyRightClicked(spy)
        }
    }

... to merge the two cases of onClick+onRightClick, but likely could be prettier in how/where access to the button where the feedback should happen is done...

SomeTroglodyte avatar May 16 '24 15:05 SomeTroglodyte

@SomeTroglodyte is there anything here that's a no-go, or are these meant to be comments and hints?

yairm210 avatar May 21 '24 16:05 yairm210

no-go

Nope far from it, all lint-level

SomeTroglodyte avatar May 21 '24 17:05 SomeTroglodyte