2020-12-27 07:26:19 -08:00
|
|
|
class MapBrowserPageControls
|
|
|
|
|
{
|
|
|
|
|
constructor(mapBrowserPage, gridBrowser)
|
|
|
|
|
{
|
2025-05-06 08:17:48 -07:00
|
|
|
for (const name in this)
|
2020-12-27 07:26:19 -08:00
|
|
|
this[name] = new this[name](mapBrowserPage, gridBrowser);
|
|
|
|
|
|
|
|
|
|
this.mapBrowserPage = mapBrowserPage;
|
|
|
|
|
this.gridBrowser = gridBrowser;
|
|
|
|
|
|
|
|
|
|
this.setupButtons();
|
2024-12-27 23:51:12 -08:00
|
|
|
|
2025-05-03 00:37:00 -07:00
|
|
|
const alignmentHelper = new AlignmentHelper("max");
|
|
|
|
|
const labelMargin = 5;
|
2024-12-27 23:51:12 -08:00
|
|
|
|
|
|
|
|
this.mapBrowserSearchBoxLabel = Engine.GetGUIObjectByName("mapBrowserSearchBoxLabel");
|
|
|
|
|
this.mapBrowserSearchBoxControl = Engine.GetGUIObjectByName("mapBrowserSearchBoxControl");
|
2025-05-03 00:37:00 -07:00
|
|
|
alignmentHelper.setObject(this.mapBrowserSearchBoxControl, "left", this.mapBrowserSearchBoxLabel.size.right + labelMargin);
|
2024-12-27 23:51:12 -08:00
|
|
|
|
|
|
|
|
this.mapBrowserMapTypeLabel = Engine.GetGUIObjectByName("mapBrowserMapTypeLabel");
|
|
|
|
|
this.mapBrowserMapTypeControl = Engine.GetGUIObjectByName("mapBrowserMapTypeControl");
|
2025-05-03 00:37:00 -07:00
|
|
|
alignmentHelper.setObject(this.mapBrowserMapTypeControl, "left", this.mapBrowserMapTypeLabel.size.right + labelMargin);
|
2024-12-27 23:51:12 -08:00
|
|
|
|
|
|
|
|
this.mapBrowserMapFilterLabel = Engine.GetGUIObjectByName("mapBrowserMapFilterLabel");
|
|
|
|
|
this.mapBrowserMapFilterControl = Engine.GetGUIObjectByName("mapBrowserMapFilterControl");
|
2025-05-03 00:37:00 -07:00
|
|
|
alignmentHelper.setObject(this.mapBrowserMapFilterControl, "left", this.mapBrowserMapFilterLabel.size.right + labelMargin);
|
2020-12-27 07:26:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setupButtons()
|
|
|
|
|
{
|
|
|
|
|
this.pickRandom = Engine.GetGUIObjectByName("mapBrowserPagePickRandom");
|
2025-12-30 00:57:37 -08:00
|
|
|
this.pickRandom.onPress = () =>
|
|
|
|
|
{
|
2025-05-06 08:17:48 -07:00
|
|
|
const index = randIntInclusive(0, this.gridBrowser.itemCount - 1);
|
2020-12-27 07:26:19 -08:00
|
|
|
this.gridBrowser.setSelectedIndex(index);
|
|
|
|
|
this.gridBrowser.goToPageOfSelected();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.select = Engine.GetGUIObjectByName("mapBrowserPageSelect");
|
|
|
|
|
this.select.onPress = () => this.onSelect();
|
|
|
|
|
|
|
|
|
|
this.close = Engine.GetGUIObjectByName("mapBrowserPageClose");
|
|
|
|
|
this.close.onPress = () => this.mapBrowserPage.closePage();
|
|
|
|
|
|
2023-10-28 04:32:37 -07:00
|
|
|
this.mapBrowserPage.registerOpenPageHandler(this.onOpenPage.bind(this));
|
2020-12-27 07:26:19 -08:00
|
|
|
this.gridBrowser.registerSelectionChangeHandler(() => this.onSelectionChange());
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-28 04:32:37 -07:00
|
|
|
onOpenPage(allowSelection)
|
|
|
|
|
{
|
|
|
|
|
this.pickRandom.hidden = !allowSelection;
|
|
|
|
|
this.select.hidden = !allowSelection;
|
|
|
|
|
|
|
|
|
|
const usedCaptions = allowSelection ? MapBrowserPageControls.Captions.cancel :
|
|
|
|
|
MapBrowserPageControls.Captions.close;
|
|
|
|
|
|
|
|
|
|
this.close.caption = usedCaptions.caption;
|
|
|
|
|
this.close.tooltip = colorizeHotkey(usedCaptions.tooltip, "cancel");
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-27 07:26:19 -08:00
|
|
|
onSelectionChange()
|
|
|
|
|
{
|
|
|
|
|
this.select.enabled = this.gridBrowser.selected != -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onSelect()
|
|
|
|
|
{
|
Separate Game Settings from the GUI Gamesetup
Split the gamesetup in two: the 'GameAttributes' part into gamesettings/
and the GUI/Presentation part in gamesetup/. This makes it easier to
separate the presentation from the data.
The immediate benefit is that campaigns & autostart scripts don't need
to load the gamesetup folder at all. This also makes it much easier for
any modder that would want to to change the GameSetup itself.
Each 'game attribute' is given a unique class extending GameSetting
(with a few exceptions), in charge of:
- 'Serializing' to the JSON-compatible 'InitAttributes' format, which is
used for persisted settings, network synchronization, map script
settings, hotloading.
- Deserializing from the same format.
- Watching for settings it depends on (such that e.g. unexploring the
map also unreveals it).
The GUI controls remain in charge of presenting the state accurately,
however they now directly subscribe to changes of the GameSettings for
update. The updating logic in general has been lightened on the GUI
side, making it more straightforward to know when something will update,
and reducing un-necessary computations (in theory - in practice, I
believe the gamesetup was already fairly good about this).
The 'Controller' class of the gamesetup have also been lightened, since
more responsibility now lies with GameSettings. In particular, this
include code to actually launch a game.
In general the GameSettings class is permissive - the GUI gamesetup has
tighter restriction for what the player can/cannot modify. This is
intended to give flexibility for campaign maps, which may want to change
arbitrary settings.
Further work would be useful, non-exhaustively:
- the setting of default values remains messy. They currently exist
somethings in GameSettings, sometimes in the GUI gamesetup, and in the
simulation itself (in case attributes are not set).
- the availability and 'lockedness' of settings remains a
work-in-progress.
- some attributes, like disabled technologies, should probably be
removed and triggers used instead.
- the Handling of AI and player-specific data could be improved.
- settings Persistence should follow its own path - not all settings are
worth persisting.
- GAIA settings are added simulation-side but not in the GUI, which is
confusing.
Thanks langbart & Freagarach for testing.
Follows the gamesetup rewrite in 34138a7764.
Refs #3049
Differential Revision: https://code.wildfiregames.com/D3243
This was SVN commit r25077.
2021-03-18 06:59:53 -07:00
|
|
|
this.mapBrowserPage.submitMapSelection();
|
2020-12-27 07:26:19 -08:00
|
|
|
}
|
2023-10-28 04:32:37 -07:00
|
|
|
|
|
|
|
|
static Captions =
|
2025-05-03 00:37:00 -07:00
|
|
|
{
|
|
|
|
|
"close":
|
2023-10-28 04:32:37 -07:00
|
|
|
{
|
|
|
|
|
"caption": translate("Close"),
|
|
|
|
|
"tooltip": translate("%(hotkey)s: Close map browser.")
|
|
|
|
|
},
|
2025-05-03 00:37:00 -07:00
|
|
|
"cancel":
|
2023-10-28 04:32:37 -07:00
|
|
|
{
|
|
|
|
|
"caption": translate("Cancel"),
|
|
|
|
|
"tooltip": translate("%(hotkey)s: Close map browser and discard the selection.")
|
|
|
|
|
}
|
2025-05-03 00:37:00 -07:00
|
|
|
};
|
2020-12-27 07:26:19 -08:00
|
|
|
}
|