From dc5e637e20960e54cb696f259095e8df4caf4496 Mon Sep 17 00:00:00 2001 From: N0VAN0M4LY <224130499+N0VAN0M4LY@users.noreply.github.com> Date: Thu, 3 Dec 2026 03:02:19 +0800 Subject: [PATCH] fix(mods): track additive pack overlay folders inside mod templates --- .gitignore | 3 + .../config/wpcost.blk.patch.jsonc | 12 + .../lang.vromfs.bin/lang/units.csv.patch.csv | 2 + .../gui/missions/wtomapselector.css | 104 ++++ .../gui/missions/wtomapselectorcards.tpl | 35 ++ .../gui/missions/wtomapselectormodal.tpl | 265 ++++++++++ .../scripts/missions/wtomapselectormodal.nut | 488 ++++++++++++++++++ .../lang.vromfs.bin/lang/menu.csv.patch.csv | 32 ++ 8 files changed, 941 insertions(+) create mode 100644 mod-dev-docs/templates/example-vehicle-tweak/client/packs/char.vromfs.bin/config/wpcost.blk.patch.jsonc create mode 100644 mod-dev-docs/templates/example-vehicle-tweak/client/packs/lang.vromfs.bin/lang/units.csv.patch.csv create mode 100644 mod-dev-docs/templates/official-map-selector/client/packs/gui.vromfs.bin/gui/missions/wtomapselector.css create mode 100644 mod-dev-docs/templates/official-map-selector/client/packs/gui.vromfs.bin/gui/missions/wtomapselectorcards.tpl create mode 100644 mod-dev-docs/templates/official-map-selector/client/packs/gui.vromfs.bin/gui/missions/wtomapselectormodal.tpl create mode 100644 mod-dev-docs/templates/official-map-selector/client/packs/gui.vromfs.bin/scripts/missions/wtomapselectormodal.nut create mode 100644 mod-dev-docs/templates/official-map-selector/client/packs/lang.vromfs.bin/lang/menu.csv.patch.csv diff --git a/.gitignore b/.gitignore index dbfc10f..0a0eada 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ # Never commit game files (copyright, size). The build reads them from a game folder. *.vromfs.bin +# Allow additive patch directories named after target packs inside mod templates (never binary archives). +!mod-dev-docs/templates/**/client/packs/*.vromfs.bin/ +!mod-dev-docs/templates/**/client/packs/ui/*.vromfs.bin/ *.vromfs.bin.orig aces.exe aces*.exe diff --git a/mod-dev-docs/templates/example-vehicle-tweak/client/packs/char.vromfs.bin/config/wpcost.blk.patch.jsonc b/mod-dev-docs/templates/example-vehicle-tweak/client/packs/char.vromfs.bin/config/wpcost.blk.patch.jsonc new file mode 100644 index 0000000..15c3c49 --- /dev/null +++ b/mod-dev-docs/templates/example-vehicle-tweak/client/packs/char.vromfs.bin/config/wpcost.blk.patch.jsonc @@ -0,0 +1,12 @@ +// Incremental BLK patch applied to char.vromfs.bin config/wpcost.blk. +// Only touches the target vehicle block so other mods editing different vehicles stack cleanly. +{ + "ops": [ + { + "op": "setParam", + "path": ["us_m2a4"], + "name": "rewardMulHistorical", + "value": { "type": "real", "value": 1.2 } + } + ] +} diff --git a/mod-dev-docs/templates/example-vehicle-tweak/client/packs/lang.vromfs.bin/lang/units.csv.patch.csv b/mod-dev-docs/templates/example-vehicle-tweak/client/packs/lang.vromfs.bin/lang/units.csv.patch.csv new file mode 100644 index 0000000..94399ae --- /dev/null +++ b/mod-dev-docs/templates/example-vehicle-tweak/client/packs/lang.vromfs.bin/lang/units.csv.patch.csv @@ -0,0 +1,2 @@ +"";"";"";"" +"us_m2a4_shop";"M2A4 (Modded)";"M2A4(模组示例)";"M2A4(模組示例)" diff --git a/mod-dev-docs/templates/official-map-selector/client/packs/gui.vromfs.bin/gui/missions/wtomapselector.css b/mod-dev-docs/templates/official-map-selector/client/packs/gui.vromfs.bin/gui/missions/wtomapselector.css new file mode 100644 index 0000000..2899166 --- /dev/null +++ b/mod-dev-docs/templates/official-map-selector/client/packs/gui.vromfs.bin/gui/missions/wtomapselector.css @@ -0,0 +1,104 @@ +wtoMapCard { + behavior: button; + snd_click: click; + width: 1@mapPreferenceIconSize + 2@blockInterval; + flow: vertical; + margin: 1@mapPreferenceIconMargin, 1@blockInterval; + padding: 1@blockInterval; + background-color: #36101418; + border: yes; + border-color: #38ffffff; + css-hier-invalidate: yes; +} + +wtoMapCard:hover { + background-color: #58202c38; + border-color: @hoverMenuButtonColor; +} + +[wtoFilterMode=include] wtoMapCard[wtoSelected=yes] { + background-color: #48184222; + border-color: @checkBoxLikedCheckColor; +} + +[wtoFilterMode=exclude] wtoMapCard[wtoSelected=yes] { + background-color: #484a1818; + border-color: @checkBoxBannedCheckColor; +} + +[wtoFilterMode=all] wtoMapCard[wtoSelected=yes] { + background-color: #3a243242; + border-color: #88b8d8ff; +} + +wtoMapThumb { + size: 1@mapPreferenceIconSize, 1@mapPreferenceIconSize; + position: relative; + background-color: #cccccc; + input-transparent: yes; + css-hier-invalidate: yes; +} + +wtoMapCard:hover > wtoMapThumb, +wtoMapCard[wtoSelected=yes] > wtoMapThumb { + background-color: @white; +} + +wtoMapCheckBox { + position: absolute; + pos: pw - w - 4@dp, 4@dp; + size: 1@checkboxImgSize, 1@checkboxImgSize; + border: yes; + background-color: #c8101418; + border-color: @checkboxBorderColor; + input-transparent: yes; + css-hier-invalidate: yes; +} + +wtoMapCheckIcon { + position: relative; + pos: 0.5pw - 0.5w, 0.5ph - 0.5h; + size: 1@checkboxImgSize - 4@dp, 1@checkboxImgSize - 4@dp; + background-svg-size: 1@checkboxImgSize - 4@dp, 1@checkboxImgSize - 4@dp; + display: hide; + input-transparent: yes; +} + +[wtoFilterMode=include] wtoMapCard[wtoSelected=yes] wtoMapCheckBox { + border-color: @checkBoxLikedCheckColor; +} + +[wtoFilterMode=include] wtoMapCard[wtoSelected=yes] wtoMapCheckIcon { + display: show; + background-image: #ui/gameuiskin#check.svg; + background-color: @checkBoxLikedCheckColor; +} + +[wtoFilterMode=exclude] wtoMapCard[wtoSelected=yes] wtoMapCheckBox { + border-color: @checkBoxBannedCheckColor; +} + +[wtoFilterMode=exclude] wtoMapCard[wtoSelected=yes] wtoMapCheckIcon { + display: show; + background-image: #ui/gameuiskin#ban_icon.svg; + background-color: @checkBoxBannedCheckColor; +} + +[wtoFilterMode=all] wtoMapCard[wtoSelected=yes] wtoMapCheckIcon { + display: show; + background-image: #ui/gameuiskin#check.svg; + background-color: @commonTextColor; +} + +wtoMapCard > textareaNoTab { + width: 1@mapPreferenceIconSize; + font: @fontSmall; + color: @commonTextColor; + margin-top: 1@blockInterval; + input-transparent: yes; +} + +wtoMapCard:hover > textareaNoTab, +wtoMapCard[wtoSelected=yes] > textareaNoTab { + color: @highlightedTextColor; +} diff --git a/mod-dev-docs/templates/official-map-selector/client/packs/gui.vromfs.bin/gui/missions/wtomapselectorcards.tpl b/mod-dev-docs/templates/official-map-selector/client/packs/gui.vromfs.bin/gui/missions/wtomapselectorcards.tpl new file mode 100644 index 0000000..03fd3d2 --- /dev/null +++ b/mod-dev-docs/templates/official-map-selector/client/packs/gui.vromfs.bin/gui/missions/wtomapselectorcards.tpl @@ -0,0 +1,35 @@ +<<#cards>> +wtoMapCard { + id:t='card_<>' + wtoMapKey:t='<>' + wtoSelected:t='<<#isSelected>>yes<><<^isSelected>>no<>' + on_click:t='onToggleMapCard' + on_hover:t='onHoverMapCard' + + wtoMapThumb { + background-image:t='<>' + + wtoMapCheckBox { + wtoMapCheckIcon {} + } + + <<#variantBadge>> + textareaNoTab { + padding:t='4@sf/@pf, 0' + valign:t='bottom' + style:t='color:@white' + background-color:t='@blurBgrColor' + input-transparent:t='yes' + text:t='<>' + } + <> + } + + textareaNoTab { + id:t='card_title' + word-wrap:t='no' + pare-text:t='yes' + text:t='' + } +} +<> diff --git a/mod-dev-docs/templates/official-map-selector/client/packs/gui.vromfs.bin/gui/missions/wtomapselectormodal.tpl b/mod-dev-docs/templates/official-map-selector/client/packs/gui.vromfs.bin/gui/missions/wtomapselectormodal.tpl new file mode 100644 index 0000000..521e095 --- /dev/null +++ b/mod-dev-docs/templates/official-map-selector/client/packs/gui.vromfs.bin/gui/missions/wtomapselectormodal.tpl @@ -0,0 +1,265 @@ +root { + blur {} + blur_foreground {} + + frame { + width:t='0.92@rw' + max-width:t='1@rw' + height:t='1@maxWindowHeight' + class:t='wnd' + css-hier-invalidate:t='yes' + isCenteredUnderLogo:t='yes' + + frame_header { + activeText { + id:t='wnd_title' + caption:t='yes' + text:t='<>' + } + + textareaNoTab { + id:t='selected_counter' + position:t='relative' + pos:t='0, 0.5ph-0.5h' + margin-left:t='2@blockInterval' + text:t='' + } + + Button_close { id:t='btn_back' } + } + + tdiv { + size:t='pw, fh' + flow:t='vertical' + css-hier-invalidate:t='yes' + + tdiv { + width:t='pw' + padding:t='1@blockInterval, 1@blockInterval' + flow:t='vertical' + + tdiv { + width:t='pw' + flow:t='horizontal' + + HorizontalListBox { + id:t='filter_mode_tabs' + position:t='relative' + on_select:t='onFilterModeChange' + + shopFilter { + id:t='mode_all' + selected:t='yes' + shopFilterText { text:t='#wto/mapSelector/modeAll' } + } + shopFilter { + id:t='mode_include' + shopFilterText { text:t='#wto/mapSelector/modeInclude' } + } + shopFilter { + id:t='mode_exclude' + shopFilterText { text:t='#wto/mapSelector/modeExclude' } + } + } + } + + textareaNoTab { + id:t='filter_mode_hint' + width:t='pw' + smallFont:t='yes' + overlayTextColor:t='silver' + margin-top:t='0.5@blockInterval' + text:t='#wto/mapSelector/hintAll' + } + } + + tdiv { + width:t='pw' + padding:t='1@blockInterval, 0' + padding-bottom:t='1@blockInterval' + flow:t='horizontal' + + tdiv { + id:t='search_container' + width:t='fw' + margin-right:t='1@blockInterval' + + EditBox { + id:t='filter_edit_box' + pos:t='0, 0.5ph-0.5h' + position:t='relative' + width:t='fw' + on_activate:t='onFilterEditBoxActivate' + on_change_value:t='onFilterEditBoxChangeValue' + on_cancel_edit:t='onFilterEditBoxCancel' + text:t='' + edit-hint:t='#wto/mapSelector/searchHint' + } + + Button_text { + id:t='filter_edit_cancel_btn' + pos:t='0, 0.5ph-0.5h' + position:t='relative' + class:t='image' + showConsoleImage:t='no' + noMargin:t='yes' + tooltip:t='#mainmenu/btnReset' + on_click:t='onFilterEditBoxCancel' + display:t='hide' + + img { + background-image:t='#ui/gameuiskin#btn_close.svg' + } + } + } + + Button_text { + id:t='btn_select_all' + text:t='#wto/mapSelector/selectAllVisible' + on_click:t='onSelectAllVisible' + margin-right:t='1@blockInterval' + ButtonImg {} + } + + Button_text { + id:t='btn_clear_selection' + text:t='#wto/mapSelector/clearSelection' + on_click:t='onClearSelection' + ButtonImg {} + } + } + + rowSeparator {} + + tdiv { + size:t='pw, fh' + flow:t='horizontal' + css-hier-invalidate:t='yes' + + tdiv { + size:t='fw, ph' + position:t='relative' + + tdiv { + id:t='maps_list' + size:t='pw, ph' + flow:t='h-flow' + overflow-y:t='auto' + scrollbarShortcuts:t='yes' + position:t='relative' + css-hier-invalidate:t='yes' + wtoFilterMode:t='all' + } + + textAreaCentered { + id:t='empty_list_label' + width:t='0.8pw' + pos:t='0.5pw-0.5w, 0.5ph-0.5h' + position:t='absolute' + text:t='#wto/mapSelector/loading' + } + } + + blockSeparator {} + + tdiv { + id:t='map_preview' + width:t='1@mapPreferencePreviewSize + 2@framePadding' + height:t='ph' + padding:t='1@framePadding' + flow:t='vertical' + position:t='relative' + css-hier-invalidate:t='yes' + + tdiv { + size:t='pw, 1@mapPreferencePreviewSize' + position:t='relative' + + img { + id:t='img_preview' + size:t='pw, 1@mapPreferencePreviewSize' + max-width:t='h' + max-height:t='w' + pos:t='0.5pw-0.5w, 0' + position:t='absolute' + background-image:t='' + display:t='hide' + } + + tdiv { + id:t='tactical-map' + size:t='pw, 1@mapPreferencePreviewSize' + max-width:t='h' + max-height:t='w' + pos:t='0.5pw-0.5w, 0' + position:t='absolute' + display:t='hide' + + tacticalMap { + size:t='pw, ph' + } + } + } + + textAreaCentered { + id:t='preview_title' + width:t='pw' + margin-top:t='1@blockInterval' + class:t='active' + text:t='' + } + + textAreaCentered { + id:t='preview_variants' + width:t='pw' + smallFont:t='yes' + margin-top:t='0.5@blockInterval' + text:t='' + } + + textAreaCentered { + id:t='preview_status' + width:t='pw' + smallFont:t='yes' + overlayTextColor:t='silver' + margin-top:t='0.5@blockInterval' + text:t='#wto/mapSelector/previewHint' + } + } + } + } + + navBar { + navLeft { + textareaNoTab { + id:t='footer_summary' + pos:t='0, 0.5ph-0.5h' + position:t='relative' + smallFont:t='yes' + text:t='' + } + } + + navRight { + Button_text { + id:t='btn_cancel' + text:t='#wto/mapSelector/btnCancel' + _on_click:t='goBack' + btnName:t='B' + ButtonImg {} + } + + Button_text { + id:t='btn_save' + text:t='#wto/mapSelector/btnSave' + on_click:t='onSave' + visualStyle:t='secondary' + btnName:t='A' + ButtonImg {} + } + } + } + } + + gamercard_div {} +} diff --git a/mod-dev-docs/templates/official-map-selector/client/packs/gui.vromfs.bin/scripts/missions/wtomapselectormodal.nut b/mod-dev-docs/templates/official-map-selector/client/packs/gui.vromfs.bin/scripts/missions/wtomapselectormodal.nut new file mode 100644 index 0000000..e730f48 --- /dev/null +++ b/mod-dev-docs/templates/official-map-selector/client/packs/gui.vromfs.bin/scripts/missions/wtomapselectormodal.nut @@ -0,0 +1,488 @@ +// Official WTOffline Mod: Native DaGui Custom Map Pool Selector modal. +// Communicates with the local server's wto_mod.map_selector.get and wto_mod.map_selector.set +// matching RPC endpoints and reuses War Thunder's native map thumbnails and setMapPreview. + +import "regexp2" as regexp2 +from "%scripts/sqDagui/framework/gui_handlers.nut" import register_gui_handler +from "%scripts/baseGuiHandlerWT.nut" import BaseGuiHandlerWT +from "%scripts/sqDagui/framework/handlerType.nut" import handlerType +from "%sqStdLibs/helpers/handyman.nut" import handyman +from "%scripts/missions/mapPreview.nut" import setMapPreview, getMissionBriefingConfig +from "%scripts/missions/missionsText.nut" import getMissionLocName +from "%scripts/events/eventInfo.nut" import getEventEconomicName +from "%scripts/gameModes/gameModeManagerState.nut" import getCurrentGameMode, getGameModeEvent +from "%scripts/popups/popups.nut" import addPopup +from "%scripts/matching/api.nut" import matchingApiFunc +from "%sqstd/string.nut" import trim, utf8ToLower +from "guiMission" import get_meta_mission_info_by_name +from "%scripts/dagui_natives.nut" import get_level_texture, map_to_location +from "%scripts/dagui_library.nut" import * + +let { handlersManager } = require("%scripts/baseGuiHandlerManagerWT.nut") + +dagui_propid_add_name_id("wtoSelected") +dagui_propid_add_name_id("wtoFilterMode") +dagui_propid_add_name_id("wtoMapKey") + +let FILTER_MODES = ["all", "include", "exclude"] +let GROUND_OR_NAVAL_LEVEL_RE = regexp2(@"^av(n|g)") + +function resolveMapThumbnail(mapId, missionInfo) { + let levelPath = missionInfo?.level ?? "" + if (levelPath == "") + return "" + let isGroundOrNaval = GROUND_OR_NAVAL_LEVEL_RE.match(mapId) + let rawTex = get_level_texture(levelPath, isGroundOrNaval) + if (rawTex.len() > 1 && rawTex.endswith("*")) + return $"{rawTex.slice(0, -1)}_thumb*" + return rawTex +} + +function resolveMapTitle(mapId, sampleMission, missionInfo) { + let byDirectLoc = loc($"location/{mapId}", "") + if (byDirectLoc != "") + return byDirectLoc + + let levelPath = missionInfo?.level ?? "" + if (levelPath != "") { + let mappedLocId = map_to_location(levelPath) + if ((mappedLocId ?? "") != "") { + let byMappedLoc = loc($"location/{mappedLocId}", "") + if (byMappedLoc != "") + return byMappedLoc + } + } + + if (missionInfo != null) { + let byMissionLoc = getMissionLocName(missionInfo, "locName") + if ((byMissionLoc ?? "") != "") + return byMissionLoc + } + + let bySampleId = loc($"missions/{sampleMission}", "") + if (bySampleId != "") + return bySampleId + + return mapId +} + +let WtoMapSelectorModal = class (BaseGuiHandlerWT) { + wndType = handlerType.MODAL + sceneTplName = "%gui/missions/wtomapselectormodal.tpl" + + gameMode = null + modeName = "" + economicName = "" + modeDisplayName = "" + + filterMode = "all" + mapsList = null + mapByKey = null + selectedSet = null + focusedMapKey = "" + isLoading = true + isSaving = false + + function getSceneTplView() { + let gm = this.gameMode ?? getCurrentGameMode() + this.gameMode = gm + let event = getGameModeEvent(gm) + this.modeName = event?.name ?? gm?.id ?? "" + this.economicName = event != null ? getEventEconomicName(event) : "" + this.modeDisplayName = (gm?.getText != null) ? gm.getText() : this.modeName + let title = this.modeDisplayName != "" + ? loc("wto/mapSelector/titleWithMode", { mode = this.modeDisplayName }) + : loc("wto/mapSelector/title") + return { + wndTitle = title + } + } + + function initScreen() { + this.mapsList = [] + this.mapByKey = {} + this.selectedSet = {} + this.focusedMapKey = "" + this.isLoading = true + this.isSaving = false + + this.updateActionButtonsState() + this.updateFilterModeUi() + this.updateCounterText() + this.requestMapPool() + } + + function requestMapPool() { + if (this.modeName == "" && this.economicName == "") { + this.isLoading = false + this.showEmptyLabel(loc("wto/mapSelector/emptyMode")) + this.updateActionButtonsState() + return + } + + this.showEmptyLabel(loc("wto/mapSelector/loading")) + matchingApiFunc("wto_mod.map_selector.get", + Callback(@(resp) this.onMapPoolLoaded(resp), this), + { + modeName = this.modeName + economicName = this.economicName + }) + } + + function onMapPoolLoaded(resp) { + if (!this.isValid()) + return + + this.isLoading = false + if ((resp?.error ?? 0) != 0 || !(resp?.ok ?? false)) { + this.showEmptyLabel(loc("wto/mapSelector/loadFailed")) + this.updateActionButtonsState() + return + } + + let resolvedMode = resp?.modeName ?? "" + if (resolvedMode != "") + this.modeName = resolvedMode + + let serverFilter = resp?.filterMode ?? "all" + this.filterMode = FILTER_MODES.indexof(serverFilter) != null ? serverFilter : "all" + + this.selectedSet = {} + foreach (mapId in (resp?.selectedMaps ?? [])) + this.selectedSet[mapId] <- true + + this.mapsList = [] + this.mapByKey = {} + foreach (entry in (resp?.maps ?? [])) { + let mapId = entry?.id ?? "" + if (mapId == "") + continue + let sampleMission = entry?.sampleMission ?? "" + let missionCount = entry?.missionCount ?? 1 + let missionInfo = sampleMission != "" ? get_meta_mission_info_by_name(sampleMission) : null + let title = resolveMapTitle(mapId, sampleMission, missionInfo) + let image = resolveMapThumbnail(mapId, missionInfo) + let item = { + idx = 0 + mapId = mapId + sampleMission = sampleMission + missionCount = missionCount + title = title + searchKey = utf8ToLower(title) + image = image + variantBadge = missionCount > 1 ? $"{missionCount}x" : "" + isSelected = mapId in this.selectedSet + } + this.mapsList.append(item) + this.mapByKey[mapId] <- item + } + + this.mapsList.sort(@(a, b) a.searchKey <=> b.searchKey || a.mapId <=> b.mapId) + foreach (idx, item in this.mapsList) + item.idx = idx + + this.syncFilterTabsToState() + this.renderMapCards() + this.updateFilterModeUi() + this.updateCounterText() + this.updateActionButtonsState() + + if (this.mapsList.len() > 0) + this.focusMapPreview(this.mapsList[0].mapId) + else + this.showEmptyLabel(loc("wto/mapSelector/emptyMode")) + } + + function renderMapCards() { + let listObj = this.scene.findObject("maps_list") + if (!checkObj(listObj)) + return + + let markup = handyman.renderCached("%gui/missions/wtomapselectorcards.tpl", { cards = this.mapsList }) + this.guiScene.replaceContentFromText(listObj, markup, markup.len(), this) + + foreach (item in this.mapsList) { + let cardObj = listObj.findObject($"card_{item.idx}") + if (checkObj(cardObj)) { + cardObj.findObject("card_title")?.setValue(item.title) + cardObj.tooltip = item.title + } + } + + this.applySearchFilter() + } + + function showEmptyLabel(text) { + let labelObj = this.scene.findObject("empty_list_label") + if (!checkObj(labelObj)) + return + labelObj.setValue(text) + labelObj.show(text != "") + } + + function syncFilterTabsToState() { + let tabsObj = this.scene.findObject("filter_mode_tabs") + if (!checkObj(tabsObj)) + return + let idx = FILTER_MODES.indexof(this.filterMode) ?? 0 + if (tabsObj.getValue() != idx) + tabsObj.setValue(idx) + } + + function onFilterModeChange(obj) { + if (!checkObj(obj)) + return + let idx = obj.getValue() + if (idx < 0 || idx >= FILTER_MODES.len()) + return + this.filterMode = FILTER_MODES[idx] + this.updateFilterModeUi() + this.updateCounterText() + this.updatePreviewStatusText() + } + + function updateFilterModeUi() { + let listObj = this.scene.findObject("maps_list") + if (checkObj(listObj)) + listObj.wtoFilterMode = this.filterMode + + let hintKey = this.filterMode == "include" ? "wto/mapSelector/hintInclude" + : this.filterMode == "exclude" ? "wto/mapSelector/hintExclude" + : "wto/mapSelector/hintAll" + this.scene.findObject("filter_mode_hint")?.setValue(loc(hintKey)) + } + + function updateCounterText() { + let selectedCount = this.selectedSet.len() + let totalCount = this.mapsList.len() + let text = loc("wto/mapSelector/counter", { + selected = selectedCount + total = totalCount + }) + this.scene.findObject("selected_counter")?.setValue(text) + this.scene.findObject("footer_summary")?.setValue(text) + } + + function updateActionButtonsState() { + let hasMaps = !this.isLoading && this.mapsList.len() > 0 + let canSave = hasMaps && !this.isSaving + this.scene.findObject("btn_select_all")?.enable(hasMaps) + this.scene.findObject("btn_clear_selection")?.enable(hasMaps) + this.scene.findObject("btn_save")?.enable(canSave) + } + + function onToggleMapCard(obj) { + let mapId = obj?.wtoMapKey ?? "" + if (mapId == "" || !(mapId in this.mapByKey)) + return + + let isNowSelected = !(mapId in this.selectedSet) + if (isNowSelected) + this.selectedSet[mapId] <- true + else + this.selectedSet.$rawdelete(mapId) + + let item = this.mapByKey[mapId] + item.isSelected = isNowSelected + obj.wtoSelected = isNowSelected ? "yes" : "no" + + // Selecting a map while in "all" mode smoothly switches to Whitelist if user hasn't picked one yet? + // Keep the chosen mode explicit so users never lose track of which filter tab is active. + this.updateCounterText() + this.focusMapPreview(mapId) + } + + function onHoverMapCard(obj) { + let mapId = obj?.wtoMapKey ?? "" + if (mapId != "" && mapId != this.focusedMapKey && (mapId in this.mapByKey)) + this.focusMapPreview(mapId) + } + + function focusMapPreview(mapId) { + let item = this.mapByKey?[mapId] + if (item == null) + return + + this.focusedMapKey = mapId + let previewObj = this.scene.findObject("map_preview") + if (!checkObj(previewObj)) + return + + previewObj.findObject("preview_title")?.setValue(item.title) + previewObj.findObject("preview_variants")?.setValue( + loc("wto/mapSelector/variantsCount", { count = item.missionCount })) + this.updatePreviewStatusText() + + let curMission = item.sampleMission != "" + ? get_meta_mission_info_by_name(item.sampleMission) + : null + let tacticalObj = previewObj.findObject("tactical-map") + let imgObj = previewObj.findObject("img_preview") + + if (curMission != null && checkObj(tacticalObj)) { + let config = getMissionBriefingConfig({ blk = curMission }) + setMapPreview(tacticalObj, config) + tacticalObj.show(true) + imgObj?.show(false) + } + else if (checkObj(imgObj)) { + imgObj["background-image"] = item.image + imgObj.show(item.image != "") + tacticalObj?.show(false) + } + } + + function updatePreviewStatusText() { + let statusObj = this.scene.findObject("preview_status") + if (!checkObj(statusObj)) + return + + if (this.focusedMapKey == "" || !(this.focusedMapKey in this.mapByKey)) { + statusObj.setValue(loc("wto/mapSelector/previewHint")) + return + } + + let isSelected = this.focusedMapKey in this.selectedSet + let key = !isSelected || this.filterMode == "all" + ? "wto/mapSelector/statusNormal" + : this.filterMode == "include" + ? "wto/mapSelector/statusIncluded" + : "wto/mapSelector/statusExcluded" + statusObj.setValue(loc(key)) + } + + function getSearchQuery() { + let editObj = this.scene.findObject("filter_edit_box") + return checkObj(editObj) ? utf8ToLower(trim(editObj.getValue())) : "" + } + + function applySearchFilter() { + let listObj = this.scene.findObject("maps_list") + if (!checkObj(listObj)) + return + + let query = this.getSearchQuery() + local visibleCount = 0 + foreach (item in this.mapsList) { + let isVisible = query == "" || item.searchKey.indexof(query) != null || item.mapId.indexof(query) != null + listObj.findObject($"card_{item.idx}")?.show(isVisible) + if (isVisible) + visibleCount++ + } + + if (this.mapsList.len() == 0) + this.showEmptyLabel(loc("wto/mapSelector/emptyMode")) + else if (visibleCount == 0) + this.showEmptyLabel(loc("wto/mapSelector/noSearchResults")) + else + this.showEmptyLabel("") + } + + function onFilterEditBoxChangeValue(obj) { + let value = obj.getValue() + this.scene.findObject("filter_edit_cancel_btn")?.show(value.len() != 0) + this.applySearchFilter() + } + + function onFilterEditBoxActivate() { + this.applySearchFilter() + } + + function onFilterEditBoxCancel() { + let editObj = this.scene.findObject("filter_edit_box") + if (checkObj(editObj) && editObj.getValue() != "") { + editObj.setValue("") + this.scene.findObject("filter_edit_cancel_btn")?.show(false) + this.applySearchFilter() + } + else + this.goBack() + } + + function onSelectAllVisible(_obj) { + let listObj = this.scene.findObject("maps_list") + if (!checkObj(listObj)) + return + + let query = this.getSearchQuery() + foreach (item in this.mapsList) { + let isVisible = query == "" || item.searchKey.indexof(query) != null || item.mapId.indexof(query) != null + if (!isVisible) + continue + this.selectedSet[item.mapId] <- true + item.isSelected = true + let cardObj = listObj.findObject($"card_{item.idx}") + if (checkObj(cardObj)) + cardObj.wtoSelected = "yes" + } + this.updateCounterText() + this.updatePreviewStatusText() + } + + function onClearSelection(_obj) { + let listObj = this.scene.findObject("maps_list") + this.selectedSet.clear() + foreach (item in this.mapsList) { + item.isSelected = false + if (checkObj(listObj)) { + let cardObj = listObj.findObject($"card_{item.idx}") + if (checkObj(cardObj)) + cardObj.wtoSelected = "no" + } + } + this.updateCounterText() + this.updatePreviewStatusText() + } + + function onSave(_obj) { + if (this.isSaving || this.isLoading || this.modeName == "") + return + + this.isSaving = true + this.updateActionButtonsState() + + let selectedMaps = [] + foreach (item in this.mapsList) + if (item.mapId in this.selectedSet) + selectedMaps.append(item.mapId) + + matchingApiFunc("wto_mod.map_selector.set", + Callback(@(resp) this.onSaveComplete(resp, selectedMaps.len()), this), + { + modeName = this.modeName + economicName = this.economicName + filterMode = this.filterMode + selectedMaps = selectedMaps + }) + } + + function onSaveComplete(resp, selectedCount) { + if (!this.isValid()) + return + + this.isSaving = false + if ((resp?.error ?? 0) != 0 || !(resp?.ok ?? false)) { + this.updateActionButtonsState() + addPopup(loc("wto/mapSelector/title"), loc("wto/mapSelector/saveFailed"), null, null, null, "wto_map_selector_err") + return + } + + let modeLabel = this.modeDisplayName != "" ? this.modeDisplayName : this.modeName + let notice = this.filterMode == "include" && selectedCount > 0 + ? loc("wto/mapSelector/savedInclude", { mode = modeLabel, count = selectedCount }) + : this.filterMode == "exclude" && selectedCount > 0 + ? loc("wto/mapSelector/savedExclude", { mode = modeLabel, count = selectedCount }) + : loc("wto/mapSelector/savedAll", { mode = modeLabel }) + + addPopup(loc("wto/mapSelector/title"), notice, null, null, null, "wto_map_selector_saved") + this.goBack() + } +} + +register_gui_handler("WtoMapSelectorModal", WtoMapSelectorModal) + +return freeze({ + open = function(params = null) { + handlersManager.loadHandler(WtoMapSelectorModal, params ?? {}) + } +}) diff --git a/mod-dev-docs/templates/official-map-selector/client/packs/lang.vromfs.bin/lang/menu.csv.patch.csv b/mod-dev-docs/templates/official-map-selector/client/packs/lang.vromfs.bin/lang/menu.csv.patch.csv new file mode 100644 index 0000000..736a4fe --- /dev/null +++ b/mod-dev-docs/templates/official-map-selector/client/packs/lang.vromfs.bin/lang/menu.csv.patch.csv @@ -0,0 +1,32 @@ +"";"";"";"";"" +"wto/mapSelector/btnTitle";"Map Pool";"自定义地图池";"自訂地圖池";"自定义地图池" +"wto/mapSelector/btnWithMode";"Map Pool: {mode}";"地图池:{mode}";"地圖池:{mode}";"地图池:{mode}" +"wto/mapSelector/btnTooltip";"Configure custom map pool (whitelist / blacklist) for the current game mode";"为当前游戏模式配置自定义匹配地图池(白名单 / 黑名单)";"為目前遊戲模式設定自訂配對地圖池(白名單 / 黑名單)";"为当前游戏模式配置自定义匹配地图池(白名单 / 黑名单)" +"wto/mapSelector/btnTooltipWithMode";"Configure custom map pool for {mode}";"为「{mode}」配置自定义匹配地图池(白名单 / 无上限黑名单)";"為「{mode}」設定自訂配對地圖池(白名單 / 無上限黑名單)";"为「{mode}」配置自定义匹配地图池(白名单 / 无上限黑名单)" +"wto/mapSelector/title";"Custom Map Pool";"自定义匹配地图池";"自訂配對地圖池";"自定义匹配地图池" +"wto/mapSelector/titleWithMode";"Custom Map Pool - {mode}";"自定义匹配地图池 - {mode}";"自訂配對地圖池 - {mode}";"自定义匹配地图池 - {mode}" +"wto/mapSelector/counter";"Selected: {selected} / {total}";"已选:{selected} / {total}";"已選:{selected} / {total}";"已选:{selected} / {total}" +"wto/mapSelector/modeAll";"All Maps";"全部地图";"全部地圖";"全部地图" +"wto/mapSelector/modeInclude";"Whitelist (Only Selected)";"白名单(仅匹配所选)";"白名單(僅配對所選)";"白名单(仅匹配所选)" +"wto/mapSelector/modeExclude";"Blacklist (Exclude Selected)";"黑名单(排除所选)";"黑名單(排除所選)";"黑名单(排除所选)" +"wto/mapSelector/hintAll";"No restriction. Matchmaker can pick any map in this mode.";"无限制:匹配将从当前模式的全部地图中随机抽取。";"無限制:配對將從目前模式的全部地圖中隨機抽取。";"无限制:匹配将从当前模式的全部地图中随机抽取。" +"wto/mapSelector/hintInclude";"Whitelist active: matchmaker only picks from checked maps. If none are checked, all maps are used.";"白名单生效:仅会匹配下方勾选的地图;若未勾选任何地图则回退为全部地图。";"白名單生效:僅會配對下方勾選的地圖;若未勾選任何地圖則回退為全部地圖。";"白名单生效:仅会匹配下方勾选的地图;若未勾选任何地图则回退为全部地图。" +"wto/mapSelector/hintExclude";"Blacklist active: checked maps are never matched (unlimited count, no premium required).";"黑名单生效:已勾选的地图不会被匹配到(无数量限制,无需高级账号)。";"黑名單生效:已勾選的地圖不會被配對到(無數量限制,無需高級帳號)。";"黑名单生效:已勾选的地图不会被匹配到(无数量限制,无需高级账号)。" +"wto/mapSelector/searchHint";"Search maps...";"搜索地图名称...";"搜尋地圖名稱...";"搜索地图名称..." +"wto/mapSelector/selectAllVisible";"Select All Visible";"全选可见";"全選可見";"全选可见" +"wto/mapSelector/clearSelection";"Clear Selection";"清空选择";"清空選擇";"清空选择" +"wto/mapSelector/loading";"Loading map pool...";"正在加载地图列表...";"正在載入地圖清單...";"正在加载地图列表..." +"wto/mapSelector/emptyMode";"This mode does not have a configurable PvP map pool.";"当前模式没有可配置的 PvP 地图池。";"目前模式沒有可設定的 PvP 地圖池。";"当前模式没有可配置的 PvP 地图池。" +"wto/mapSelector/noSearchResults";"No maps match the current search filter.";"没有符合搜索条件的地图。";"沒有符合搜尋條件的地圖。";"没有符合搜索条件的地图。" +"wto/mapSelector/loadFailed";"Failed to load map pool from local server.";"无法从本地服务器加载地图池。";"無法從本機伺服器載入地圖池。";"无法从本地服务器加载地图池。" +"wto/mapSelector/saveFailed";"Failed to save map pool settings.";"保存地图池设置失败。";"儲存地圖池設定失敗。";"保存地图池设置失败。" +"wto/mapSelector/savedAll";"Map pool reset to all maps for {mode}.";"已将「{mode}」恢复为匹配全部地图。";"已將「{mode}」恢復為配對全部地圖。";"已将「{mode}」恢复为匹配全部地图。" +"wto/mapSelector/savedInclude";"Saved whitelist ({count} maps) for {mode}.";"已为「{mode}」保存白名单(共 {count} 张地图)。";"已為「{mode}」儲存白名單(共 {count} 張地圖)。";"已为「{mode}」保存白名单(共 {count} 张地图)。" +"wto/mapSelector/savedExclude";"Saved blacklist ({count} maps) for {mode}.";"已为「{mode}」保存黑名单(排除 {count} 张地图)。";"已為「{mode}」儲存黑名單(排除 {count} 張地圖)。";"已为「{mode}」保存黑名单(排除 {count} 张地图)。" +"wto/mapSelector/variantsCount";"Mission variants: {count}";"包含任务变体:{count} 个";"包含任務變體:{count} 個";"包含任务变体:{count} 个" +"wto/mapSelector/previewHint";"Hover or click a map card to preview its tactical map.";"悬停或点击地图卡片以预览战术地图。";"懸停或點擊地圖卡片以預覽戰術地圖。";"悬停或点击地图卡片以预览战术地图。" +"wto/mapSelector/statusIncluded";"Status: Included in whitelist";"状态:已加入白名单";"狀態:已加入白名單";"状态:已加入白名单" +"wto/mapSelector/statusExcluded";"Status: Excluded by blacklist";"状态:已加入黑名单";"狀態:已加入黑名單";"状态:已加入黑名单" +"wto/mapSelector/statusNormal";"Status: Default";"状态:默认";"狀態:預設";"状态:默认" +"wto/mapSelector/btnSave";"Save";"保存";"儲存";"保存" +"wto/mapSelector/btnCancel";"Cancel";"取消";"取消";"取消"