Move "Damaged" overlay to missile tube "Load" button#2465
Conversation
…/Unload/Fire when 100% damaged or at 0 power
| rows[n].fire_button->enable()->show(); | ||
| if ((health <= 0) || (power_level <=0)) { | ||
| rows[n].fire_button->disable(); | ||
| rows[n].load_button->disable(); |
There was a problem hiding this comment.
the lacking of show might cause a problem in some edge cases, like opening the weapon screen when the system is broken.
There was a problem hiding this comment.
It isn't clear to me when show() should be used or not-used, so I tried to copy existing code. There didn't seem to be a clear precedent for "always call show()" when changing the state of button, but that's easy enough to add.
For test cases, I think I hit all combinations of health==0 (or not) and power==0 (or not) for tubes in all of the states (Empty, Loaded, Loading, Unloading, Firing). The buttons now become non-functional and dimmed when either power or heath hit 0. There is some interplay between the "No Power" and "Damaged" overlays, but I don't think that is new behavior.
There was a problem hiding this comment.
Show just calls setVisible(true) https://github.com/daid/EmptyEpsilon/blob/master/src/gui/gui2_element.cpp#L148
And that just sets a member, so it is really cheap to call. Same for enable/disable. And if they are based on another value, it can be easier to just call setVisible / setEnable instead.
There was a problem hiding this comment.
Hope that makes things a bit clearer?
There was a problem hiding this comment.
I found the definitions already--quite simple indeed :-) The uncertainly is less about what they do, but more about why it would be needed at one time or another.
For example, in the Empty state case, we have this ~line 99 (after patching)
rows[n].fire_button->disable()->show();
But in the Loading state (~line 115, it's merely
rows[n].load_button->disable();
Is there some difference in handling the fire button vs the load button?
Regardless, adding -show() is easy enough.
There was a problem hiding this comment.
Honestly, the code is a bit messy. And there might be edge cases where this currently would go wrong still :)
Addresses #2459.
Also disables the Load (and "Unload") and Fire buttons when the missile system is 100% damaged, or at 0 power.