In the course of #5387, this moves the diplomacy dialog components and related code from global procedures from menu.js to a class design in separate files and folders.
This does:
- further defragmetation, group all code relating to one GUI object in one class in an according file
- makes the different code components more agnostic of each other
The purpose of this is:
- to increae extensibility for modders and future authors:
- since new classes can be inserted with little hooks into existing classes (whereas previously one would be forced to overwrite various unrelated core functions),
- since the new functions are shorter and prototype properties, the diffs to overwrite or extend them become shorter,
- since many fixed values such as translated strings, size numbers, math constants can become modifiable properties of the prototype instead of hardcoded in the functions; without introducing more 'evil globals' (citation from removed code, see also Coding_Conventions).
- to improve readability. While there is little complexity added to propagate messages, one can now read one file at a time, focus on that, and if needing more context checking for parent classes, becoming able to ignore everything else.
An example of this is the spy request or diplomacy colors button, which are logically very different from the other features added to the diplomacy screen that shouldn't be intertwined with diplomacy logic.
Another example of the benefit of the localization are the TributeButtons which now can hold the state of the current amount without having to rest to even more global closure hoisting hackery, thus solving D1191 without making it worse.
The patch is conservative with regards to features and translated strings (very few strings have changed).
Minor changes while at it:
- input.js massbarter state was removed, it looks like it was only added to create the on-released event (which is more recent (rP19028) than the button), compare with the masstribute implementation
- Fixes D1191.
- SpyButton tooltip simplification
- Makes the diplomacy dialog resizing from rP22970 more friendly (https://en.wikipedia.org/wiki/Separation_of_concerns)
While reviewing (viewing again?) my patch, I noticed a cmd.source variable problem in the SpyRequestButton and AttackRequestButton from rP16533, rP19247.
Since that changes petra and simulation code, it should be fixed separately.