#!/usr/bin/env bash
# Steam в Wine/Whisky: пустой VGUI (winFont), кнопки без текста → DWriteEnable + шрифты.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
# shellcheck source=config.sh
source "${SCRIPT_DIR}/config.sh"

cmd_wine_check() {
  if [[ ! -x "${WINE64}" ]]; then
    echo "Нет WhiskyWine: bash ${SCRIPT_DIR}/install-whiskywine-manual.sh"
    exit 1
  fi
}

cmd_install_fonts() {
  local fonts="${BOTTLE_DIR}/drive_c/windows/Fonts"
  local steam="${STEAM_DIR}"
  mkdir -p "${fonts}"
  for f in /System/Library/Fonts/Supplemental/{Arial,Tahoma,Verdana,"Times New Roman","Courier New"}.ttf; do
    [[ -f "${f}" ]] && cp -n "${f}" "${fonts}/" 2>/dev/null || true
  done
  cp -n "${steam}/resource/fonts/marlett.ttf" "${fonts}/" 2>/dev/null || true
  cp -n "${steam}/clientui/fonts/"*.ttf "${fonts}/" 2>/dev/null || true
  echo "Шрифты в ${fonts}/ ($(ls "${fonts}" | wc -l | tr -d ' ') файлов)"
}

cmd_dwrite_registry() {
  export WINEPREFIX="${BOTTLE_DIR}"
  "${WINE64}" reg add 'HKCU\Software\Valve\Steam' /v DWriteEnable /t REG_DWORD /d 0 /f >/dev/null
  echo "Registry: HKCU\\Software\\Valve\\Steam\\DWriteEnable = 0"
}

main() {
  cmd_wine_check
  cmd_install_fonts
  cmd_dwrite_registry
  echo ""
  echo "OK. Перезапустите Steam:"
  echo "  bash ${SCRIPT_DIR}/start.sh reset"
  echo "  bash ${SCRIPT_DIR}/start.sh steam-ui"
  echo ""
  echo "Если текст всё ещё пустой — пройдите диалог вслепую: правая кнопка внизу или Tab → Enter."
}

main "$@"
