diff --git a/.ci/Arch/Dockerfile b/.ci/Arch/Dockerfile
index f37315262..b08e568f3 100644
--- a/.ci/Arch/Dockerfile
+++ b/.ci/Arch/Dockerfile
@@ -8,6 +8,7 @@ RUN pacman --sync --refresh --sysupgrade --needed --noconfirm \
gtest \
mariadb-libs \
ninja \
+ openssl \
protobuf \
qt6-base \
qt6-declarative \
diff --git a/.ci/Debian12/Dockerfile b/.ci/Debian12/Dockerfile
index 0fa227d6f..fc756aac2 100644
--- a/.ci/Debian12/Dockerfile
+++ b/.ci/Debian12/Dockerfile
@@ -15,14 +15,15 @@ RUN apt-get update && \
libprotobuf-dev \
libqt6multimedia6 \
libqt6sql6-mysql \
+ libssl-dev \
ninja-build \
protobuf-compiler \
+ qt6-declarative-dev \
qt6-image-formats-plugins \
qt6-l10n-tools \
qt6-multimedia-dev \
- qt6-declarative-dev \
- qt6-svg-dev \
qt6-shadertools-dev \
+ qt6-svg-dev \
qt6-tools-dev \
qt6-tools-dev-tools \
qt6-websockets-dev \
diff --git a/.ci/Debian13/Dockerfile b/.ci/Debian13/Dockerfile
index 13e8b35c7..bdecb56df 100644
--- a/.ci/Debian13/Dockerfile
+++ b/.ci/Debian13/Dockerfile
@@ -16,14 +16,15 @@ RUN apt-get update && \
libprotobuf-dev \
libqt6multimedia6 \
libqt6sql6-mysql \
+ libssl-dev \
ninja-build \
protobuf-compiler \
+ qt6-declarative-dev \
qt6-image-formats-plugins \
qt6-l10n-tools \
qt6-multimedia-dev \
- qt6-declarative-dev \
- qt6-svg-dev \
qt6-shadertools-dev \
+ qt6-svg-dev \
qt6-tools-dev \
qt6-tools-dev-tools \
qt6-websockets-dev \
diff --git a/.ci/Fedora43/Dockerfile b/.ci/Fedora43/Dockerfile
index 68e894543..463da5a51 100644
--- a/.ci/Fedora43/Dockerfile
+++ b/.ci/Fedora43/Dockerfile
@@ -7,8 +7,9 @@ RUN dnf install -y \
git \
mariadb-devel \
ninja-build \
+ openssl-devel \
protobuf-devel \
- qt6-{qtdeclarative,qtshadertools,qttools,qtsvg,qtmultimedia,qtwebsockets}-devel \
+ qt6-{qtdeclarative,qtmultimedia,qtshadertools,qtsvg,qttools,qtwebsockets}-devel \
qt6-qtimageformats \
rpm-build \
xz-devel \
diff --git a/.ci/Fedora44/Dockerfile b/.ci/Fedora44/Dockerfile
index ffd7c1b9b..62238e760 100644
--- a/.ci/Fedora44/Dockerfile
+++ b/.ci/Fedora44/Dockerfile
@@ -7,8 +7,9 @@ RUN dnf install -y \
git \
mariadb-devel \
ninja-build \
+ openssl-devel \
protobuf-devel \
- qt6-{qtdeclarative,qtshadertools,qttools,qtsvg,qtmultimedia,qtwebsockets}-devel \
+ qt6-{qtdeclarative,qtmultimedia,qtshadertools,qtsvg,qttools,qtwebsockets}-devel \
qt6-qtimageformats \
rpm-build \
xz-devel \
diff --git a/.ci/Servatrice_Debian12/Dockerfile b/.ci/Servatrice_Debian12/Dockerfile
index 21f6a036e..321aa7c0f 100644
--- a/.ci/Servatrice_Debian12/Dockerfile
+++ b/.ci/Servatrice_Debian12/Dockerfile
@@ -12,6 +12,7 @@ RUN apt-get update && \
libmariadb-dev-compat \
libprotobuf-dev \
libqt6sql6-mysql \
+ libssl-dev \
ninja-build \
protobuf-compiler \
qt6-tools-dev \
diff --git a/.ci/Ubuntu24.04/Dockerfile b/.ci/Ubuntu24.04/Dockerfile
index 12320c276..715997474 100644
--- a/.ci/Ubuntu24.04/Dockerfile
+++ b/.ci/Ubuntu24.04/Dockerfile
@@ -15,14 +15,15 @@ RUN apt-get update && \
libprotobuf-dev \
libqt6multimedia6 \
libqt6sql6-mysql \
+ libssl-dev \
ninja-build \
protobuf-compiler \
+ qt6-declarative-dev \
qt6-image-formats-plugins \
qt6-l10n-tools \
qt6-multimedia-dev \
- qt6-declarative-dev \
- qt6-svg-dev \
qt6-shadertools-dev \
+ qt6-svg-dev \
qt6-tools-dev \
qt6-tools-dev-tools \
qt6-websockets-dev \
diff --git a/.ci/Ubuntu26.04/Dockerfile b/.ci/Ubuntu26.04/Dockerfile
index ce3d9cd6c..96dd10763 100644
--- a/.ci/Ubuntu26.04/Dockerfile
+++ b/.ci/Ubuntu26.04/Dockerfile
@@ -16,14 +16,15 @@ RUN apt-get update && \
libprotobuf-dev \
libqt6multimedia6 \
libqt6sql6-mysql \
+ libssl-dev \
ninja-build \
protobuf-compiler \
+ qt6-declarative-dev \
qt6-image-formats-plugins \
qt6-l10n-tools \
qt6-multimedia-dev \
- qt6-declarative-dev \
- qt6-svg-dev \
qt6-shadertools-dev \
+ qt6-svg-dev \
qt6-tools-dev \
qt6-tools-dev-tools \
qt6-websockets-dev \
diff --git a/.ci/compile.sh b/.ci/compile.sh
index 8a16d3243..f20432893 100755
--- a/.ci/compile.sh
+++ b/.ci/compile.sh
@@ -149,6 +149,9 @@ if [[ $MAKE_TEST ]]; then
fi
if [[ $USE_CCACHE ]]; then
flags+=("-DUSE_CCACHE=1")
+ # PCH-aware caching is required or ccache refuses to cache any TU that
+ # consumes a precompiled header, silently recompiling everything on every run.
+ ccache --set-config sloppiness=pch_defines,time_macros
if [[ $CCACHE_SIZE ]]; then
# note, this setting persists after running the script
ccache --max-size "$CCACHE_SIZE"
@@ -324,4 +327,32 @@ if [[ $MAKE_PACKAGE ]]; then
BUILD_DIR="$BUILD_DIR" .ci/name_build.sh "$PACKAGE_SUFFIX"
echo "::endgroup::"
fi
+
+ if [[ $RUNNER_OS == Windows ]]; then
+ echo "::group::Check installer for build-tree artifacts"
+ cd "$BUILD_DIR"
+ package="$(find . -maxdepth 1 -type f -name 'Cockatrice-*.exe' -print -quit)"
+ if [[ ! $package ]]; then
+ echo "::error file=$0::Could not find installer to inspect"
+ exit 1
+ fi
+ seven_zip="$(command -v 7z || true)"
+ if [[ ! $seven_zip ]]; then
+ seven_zip="/c/Program Files/7-Zip/7z.exe"
+ fi
+ if [[ ! -f $seven_zip ]]; then
+ echo "::warning file=$0::7-Zip not found, skipping installer content check"
+ else
+ echo "Inspecting $package"
+ # Fail the build if the installer contains any path left behind by the MSBuild or
+ # Qt AUTOMOC tooling (build-tree artifacts must live in the build dir, not the install)
+ if "$seven_zip" l "$package" |
+ grep -E "_autogen|\.dir[\\/]|\.tlog|(^|[\\/])x64[\\/]|(^|[\\/])\.qt[\\/]|(^|[\\/])\.qsb[\\/]|(^|[\\/])\.lupdate[\\/]|CMakeFiles"; then
+ echo "::error file=$0::Installer contains build-tree artifacts"
+ exit 1
+ fi
+ echo "Installer content is clean"
+ fi
+ echo "::endgroup::"
+ fi
fi
diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml
index e895e2220..75fbc59f1 100644
--- a/.github/workflows/codeql.yml
+++ b/.github/workflows/codeql.yml
@@ -40,7 +40,7 @@ jobs:
steps:
- name: "Checkout repository"
- uses: actions/checkout@v6
+ uses: actions/checkout@v7
- name: "Initialize CodeQL"
uses: github/codeql-action/init@v4
diff --git a/.github/workflows/desktop-build.yml b/.github/workflows/desktop-build.yml
index 04037a74e..bd528f245 100644
--- a/.github/workflows/desktop-build.yml
+++ b/.github/workflows/desktop-build.yml
@@ -152,7 +152,7 @@ jobs:
env:
CACHE: ${{ github.workspace }}/.cache/${{ matrix.distro }}${{ matrix.version }} # directory for caching docker image and ccache
CCACHE_EVICTION_AGE: 7d
- CCACHE_SIZE: 550M # space of all repo is 10Gi: https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#usage-limits-and-eviction-policy
+ CCACHE_SIZE: 600M # space of all repo is 10Gi: https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#usage-limits-and-eviction-policy
CMAKE_GENERATOR: 'Ninja'
NAME: ${{ matrix.distro }}${{ matrix.version }}
@@ -176,8 +176,12 @@ jobs:
shell: bash
run: |
source .ci/docker.sh
- RUN --server --debug --test --ccache "$CCACHE_SIZE" \
- --cmake-generator "$CMAKE_GENERATOR"
+ args=()
+ [[ $GITHUB_REF == "refs/heads/master" ]] && args+=(--evict-ccache "$CCACHE_EVICTION_AGE")
+ args+=(--ccache "$CCACHE_SIZE")
+ args+=(--cmake-generator "$CMAKE_GENERATOR")
+
+ RUN --server --debug --test "${args[@]}"
- name: "Build release package"
id: build
@@ -268,8 +272,8 @@ jobs:
make_package: 1
override_target: 13
package_suffix: "-macOS13_Intel"
- qt_version: 6.11.1
- qt_modules: qtimageformats qtmultimedia qtwebsockets qtshadertools
+ qt_version: 6.11.*
+ qt_modules: qtimageformats qtmultimedia qtshadertools qtwebsockets
soc: Intel
type: Release
use_ccache: 1
@@ -284,8 +288,8 @@ jobs:
make_package: 1
override_target: 14
package_suffix: "-macOS14"
- qt_version: 6.11.1
- qt_modules: qtimageformats qtmultimedia qtwebsockets qtshadertools
+ qt_version: 6.11.*
+ qt_modules: qtimageformats qtmultimedia qtshadertools qtwebsockets
soc: Apple
type: Release
use_ccache: 1
@@ -300,8 +304,8 @@ jobs:
make_package: 1
override_target: 15
package_suffix: "-macOS15"
- qt_version: 6.11.1
- qt_modules: qtimageformats qtmultimedia qtwebsockets qtshadertools
+ qt_version: 6.11.*
+ qt_modules: qtimageformats qtmultimedia qtshadertools qtwebsockets
soc: Apple
type: Release
use_ccache: 1
@@ -313,8 +317,8 @@ jobs:
ccache_eviction_age: 7d
cmake_generator: Ninja
- qt_version: 6.11.1
- qt_modules: qtimageformats qtmultimedia qtwebsockets qtshadertools
+ qt_version: 6.11.*
+ qt_modules: qtimageformats qtmultimedia qtshadertools qtwebsockets
soc: Apple
type: Debug
use_ccache: 1
@@ -328,8 +332,8 @@ jobs:
cmake_generator_platform: x64
make_package: 1
package_suffix: "-Win10"
- qt_version: 6.11.1
- qt_modules: qtimageformats qtmultimedia qtwebsockets qtshadertools
+ qt_version: 6.11.*
+ qt_modules: qtimageformats qtmultimedia qtshadertools qtwebsockets
type: Release
name: ${{ matrix.os }} ${{ matrix.target }}${{ matrix.soc == 'Intel' && ' Intel' || '' }}${{ matrix.type == 'Debug' && ' Debug' || '' }}
@@ -338,7 +342,7 @@ jobs:
timeout-minutes: 100
env:
CCACHE_DIR: ${{ github.workspace }}/.cache/
- CCACHE_SIZE: 550M # space of all repo is 10Gi: https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#usage-limits-and-eviction-policy
+ CCACHE_SIZE: 600M # space of all repo is 10Gi: https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#usage-limits-and-eviction-policy
steps:
- name: "Checkout"
@@ -364,18 +368,20 @@ jobs:
key: ccache-${{ matrix.runner }}_${{ matrix.override_target }}-Xcode${{ matrix.xcode }}
path: ${{ env.CCACHE_DIR }}
- - name: "Install aqtinstall"
+ - name: "[macOS] Install aqtinstall"
+ if: matrix.os == 'macOS'
run: pipx install aqtinstall
# Resolve given wildcard versions (e.g. Qt 6.6.*) to latest version via aqtinstall to avoid stale caches on new releases
- - name: "Resolve latest Qt patch version"
+ - name: "[macOS] Resolve latest Qt from ${{ matrix.qt_version }} input"
+ if: matrix.os == 'macOS'
env:
QT_VERSION: ${{ matrix.qt_version }}
id: resolve_qt_version
shell: bash
run: .ci/resolve_latest_aqt_qt_version.sh "$QT_VERSION"
- - name: "[macOS] Restore thin Qt ${{ steps.resolve_qt_version.outputs.version }} libraries"
+ - name: "[macOS] Restore thin Qt ${{ steps.resolve_qt_version.outputs.version }}"
if: matrix.os == 'macOS'
id: restore_qt
uses: actions/cache/restore@v6
@@ -385,21 +391,22 @@ jobs:
# Using jurplel/install-qt-action to install Qt without using brew
# Qt build using vcpkg either just fails or takes too long to build
- - name: "[macOS] Install fat Qt ${{ steps.resolve_qt_version.outputs.version }}"
+ - name: "[macOS] Install fat Qt ${{ matrix.qt_version }}"
if: matrix.os == 'macOS' && steps.restore_qt.outputs.cache-hit != 'true'
uses: jurplel/install-qt-action@v4
with:
cache: false
- dir: ${{ github.workspace }}
+ # cache-key-prefix: Qt
+ dir: ${{ github.workspace }} # thinning script depends on this location
modules: ${{ matrix.qt_modules }}
- version: ${{ steps.resolve_qt_version.outputs.version }}
+ version: ${{ matrix.qt_version }}
- name: "[macOS] Create thin Qt libraries"
if: matrix.os == 'macOS' && steps.restore_qt.outputs.cache-hit != 'true'
run: .ci/thin_macos_qtlib.sh
- name: "[macOS] Cache thin Qt libraries"
- if: matrix.os == 'macOS' && steps.restore_qt.outputs.cache-hit != 'true'
+ if: matrix.os == 'macOS' && steps.restore_qt.outputs.cache-hit != 'true' && github.ref == 'refs/heads/master'
uses: actions/cache/save@v6
with:
key: ${{ steps.restore_qt.outputs.cache-primary-key }}
@@ -411,10 +418,10 @@ jobs:
with:
# Qt 6.11.0 only works with aqtinstall directly from git until aqtinstall 3.4 is released
aqtsource: git+https://github.com/miurahr/aqtinstall.git
- cache: true
+ cache: ${{ github.ref == 'refs/heads/master' }}
cache-key-prefix: Qt
modules: ${{ matrix.qt_modules }}
- version: ${{ steps.resolve_qt_version.outputs.version }}
+ version: ${{ matrix.qt_version }}
- name: "[Windows] Install NSIS"
if: matrix.os == 'Windows'
@@ -446,7 +453,7 @@ jobs:
PACKAGE_SUFFIX: '${{ matrix.package_suffix }}'
TARGET_MACOS_VERSION: ${{ matrix.override_target }}
USE_CCACHE: ${{ matrix.use_ccache }}
- VCPKG_BINARY_SOURCES: 'clear;files,${{ steps.vcpkg-cache.outputs.path }},readwrite'
+ VCPKG_BINARY_SOURCES: "clear;files,${{ steps.vcpkg-cache.outputs.path }},${{ case(github.ref == 'refs/heads/master', 'readwrite', 'read') }}"
VCPKG_DISABLE_METRICS: 1
VCPKG_FEATURE_FLAGS: dependencygraph
run: .ci/compile.sh --server --test --vcpkg
diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml
index df4fe233c..967d94c58 100644
--- a/.github/workflows/docker-release.yml
+++ b/.github/workflows/docker-release.yml
@@ -76,7 +76,7 @@ jobs:
uses: docker/build-push-action@v7
with:
cache-from: type=gha,scope=${{ env.CACHE_SCOPE }}
- cache-to: type=gha,mode=max,scope=${{ env.CACHE_SCOPE }}
+ cache-to: ${{ case(github.ref == 'refs/heads/master', format('type=gha,mode=max,scope={0}', env.CACHE_SCOPE), '') }}
context: .
platforms: ${{ matrix.platform }}
push: false
@@ -127,7 +127,7 @@ jobs:
steps:
- name: "Download digests"
- uses: actions/download-artifact@v7
+ uses: actions/download-artifact@v8
with:
path: ${{ runner.temp }}/digests
pattern: digest-*
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 27fecc979..293e25dd9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -5,23 +5,23 @@
# This file sets all the variables shared between the projects
# like the installation path, compilation flags etc..
-# cmake 3.16 is required if using qt6
-cmake_minimum_required(VERSION 3.10)
+# 3.16 required for Qt6 and target_precompile_headers()
+cmake_minimum_required(VERSION 3.16)
-# Early detect ccache
+# Use compiler cache (ccache)
option(USE_CCACHE "Cache the build results with ccache" ON)
# Treat warnings as errors (Debug builds only)
option(WARNING_AS_ERROR "Treat warnings as errors in debug builds" ON)
# Check for translation updates
option(UPDATE_TRANSLATIONS "Update translations on compile" OFF)
-# Compile servatrice
-option(WITH_SERVER "build servatrice" OFF)
-# Compile cockatrice
-option(WITH_CLIENT "build cockatrice" ON)
-# Compile oracle
-option(WITH_ORACLE "build oracle" ON)
+# Compile Cockatrice
+option(WITH_CLIENT "Build Cockatrice client" ON)
+# Compile Oracle
+option(WITH_ORACLE "Build Cockatrice card database tool (Oracle)" ON)
+# Compile Servatrice
+option(WITH_SERVER "Build Cockatrice server (Servatrice)" OFF)
# Compile tests
-option(TEST "build tests" OFF)
+option(TEST "Build tests" OFF)
# Use vcpkg regardless of OS
option(USE_VCPKG "Use vcpkg regardless of OS" OFF)
@@ -39,13 +39,24 @@ else()
)
endif()
-if(USE_CCACHE)
+# ccache does not support MSVC and must not auto-engage on Windows
+# (it is installed unintentionally on the Windows CI runner).
+# NOTE: this keys off the target OS, so a mingw/Ninja configuration on Windows
+# also opts out of ccache even though the GNUCXX branch below supports it.
+if(USE_CCACHE AND NOT WIN32)
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
# Support Unix Makefiles and Ninja
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
+ # PCH-aware caching, matching .ci/compile.sh: without this ccache refuses
+ # to cache any TU that consumes a precompiled header, so every PCH-backed
+ # target recompiles from scratch on each build.
+ execute_process(COMMAND ${CCACHE_PROGRAM} --set-config sloppiness=pch_defines,time_macros)
message(STATUS "Found CCache ${CCACHE_PROGRAM}")
endif()
+elseif(USE_CCACHE AND WIN32)
+ # An explicit opt-in must not disappear silently on Windows.
+ message(STATUS "ccache disabled: not supported for the MSVC toolchain on Windows")
endif()
if(WIN32 OR USE_VCPKG)
@@ -184,6 +195,9 @@ elseif(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}")
endif()
endforeach()
+
+ # Reduce compiler I/O by using pipes between stages instead of temp files
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pipe")
else()
# other: osx/llvm, bsd/llvm
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
@@ -192,6 +206,9 @@ else()
else()
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall -Wextra")
endif()
+
+ # Reduce compiler I/O by using pipes between stages instead of temp files
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pipe")
endif()
# GNU systems need to define the Mersenne exponent for the RNG to compile w/o warning
@@ -239,11 +256,6 @@ if(WIN32)
find_package(OpenSSL REQUIRED)
if(OPENSSL_FOUND)
include_directories(${OPENSSL_INCLUDE_DIRS})
- else()
- message(
- WARNING
- "Could not find OpenSSL runtime libraries. They are not required for compiling, but needs to be available at runtime."
- )
endif()
endif()
@@ -281,7 +293,7 @@ if(UNIX)
if(CPACK_GENERATOR STREQUAL "RPM")
set(CPACK_RPM_PACKAGE_LICENSE "GPLv2")
set(CPACK_RPM_MAIN_COMPONENT "cockatrice")
- set(CPACK_RPM_PACKAGE_REQUIRES "protobuf, qt6-qttools, qt6-qtsvg, qt6-qtmultimedia, qt6-qtimageformats")
+ set(CPACK_RPM_PACKAGE_REQUIRES "protobuf, qt6-qtimageformats, qt6-qtmultimedia, qt6-qtsvg, qt6-qttools")
set(CPACK_RPM_PACKAGE_GROUP "Amusements/Games")
set(CPACK_RPM_PACKAGE_URL "http://github.com/Cockatrice/Cockatrice")
# stop directories from making package conflicts
@@ -299,7 +311,7 @@ if(UNIX)
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_DEBIAN_PACKAGE_SECTION "games")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "http://github.com/Cockatrice/Cockatrice")
- set(CPACK_DEBIAN_PACKAGE_DEPENDS "libqt6multimedia6, libqt6svg6, qt6-qpa-plugins, qt6-image-formats-plugins")
+ set(CPACK_DEBIAN_PACKAGE_DEPENDS "libqt6multimedia6, libqt6svg6, qt6-image-formats-plugins, qt6-qpa-plugins")
set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "libqt6sql6-mysql") # for connecting servatrice to a mysql db
endif()
endif()
diff --git a/Dockerfile b/Dockerfile
index 382309d47..7d3deb5fb 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -14,6 +14,7 @@ RUN apt-get update \
libmariadb-dev-compat \
libprotobuf-dev \
libqt6sql6-mysql \
+ libssl-dev \
qt6-websockets-dev \
protobuf-compiler \
qt6-tools-dev \
@@ -42,6 +43,7 @@ RUN apt-get update \
libprotobuf32t64 \
libqt6sql6-mysql \
libqt6websockets6 \
+ libssl3 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
diff --git a/README.md b/README.md
index f22df461f..5935bb540 100644
--- a/README.md
+++ b/README.md
@@ -149,15 +149,15 @@ You can then
The following flags (with their non-default values) can be passed to `cmake`:
-| Flag | Description |
-| --- | --- |
-| `-DWITH_SERVER=1` | Build Servatrice server |
-| `-DWITH_CLIENT=0` | Don't build Cockatrice client |
-| `-DWITH_ORACLE=0` | Don't build Oracle card database tool |
-| `-DCMAKE_BUILD_TYPE=Debug` | Compile in debug mode
Enables extra logging output, debug symbols, and much more verbose compiler warnings |
-| `-DWARNING_AS_ERROR=0` | Don't treat compilation warnings as errors in debug mode |
-| `-DUPDATE_TRANSLATIONS=1` | Configure `make` to update the translation .ts files for new strings in the source code
**Note:** `make clean` will remove the .ts files |
-| `-DTEST=1` | Enable regression tests
**Note:** `make test` to run tests, *googletest* will be downloaded if not available |
+| Flag | Description |
+| -------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
+| `-DWITH_SERVER=1` | Build Servatrice server |
+| `-DWITH_CLIENT=0` | Don't build Cockatrice client |
+| `-DWITH_ORACLE=0` | Don't build Oracle card database tool |
+| `-DCMAKE_BUILD_TYPE=Debug` | Compile in debug mode
Enables extra logging output, debug symbols, and much more verbose compiler warnings |
+| `-DWARNING_AS_ERROR=0` | Don't treat compilation warnings as errors in debug mode |
+| `-DUPDATE_TRANSLATIONS=1` | Configure `make` to update the translation .ts files for new strings in the source code
**Note:** `make clean` will remove the .ts files |
+| `-DTEST=1` | Enable regression tests
**Note:** `make test` to run tests, *googletest* will be downloaded if not available |
# Run
diff --git a/cmake/FindQtRuntime.cmake b/cmake/FindQtRuntime.cmake
index 0259d12e1..971c9094d 100644
--- a/cmake/FindQtRuntime.cmake
+++ b/cmake/FindQtRuntime.cmake
@@ -28,7 +28,7 @@ if(WITH_CLIENT)
)
endif()
if(WITH_ORACLE)
- set(_ORACLE_NEEDED Concurrent Network Svg Widgets)
+ set(_ORACLE_NEEDED Concurrent Network Svg Widgets Xml)
endif()
if(TEST)
# Union of Qt modules required across all test targets (independent of application targets).
diff --git a/cmake/NSIS.template.in b/cmake/NSIS.template.in
index 5af116470..b3cbcece8 100644
--- a/cmake/NSIS.template.in
+++ b/cmake/NSIS.template.in
@@ -387,19 +387,14 @@ SectionEnd
Section "un.Application" UnSecApplication
SetShellVarContext all
- RMDir /r "$INSTDIR\plugins"
- RMDir /r "$INSTDIR\sounds"
- RMDir /r "$INSTDIR\themes"
- RMDir /r "$INSTDIR\translations"
- Delete "$INSTDIR\*.exe"
- Delete "$INSTDIR\*.dll"
- Delete "$INSTDIR\qt.conf"
- Delete "$INSTDIR\qdebug.txt"
- Delete "$INSTDIR\servatrice.sql"
- Delete "$INSTDIR\servatrice.ini.example"
- RMDir "$INSTDIR"
- RMDir "$SMPROGRAMS\Cockatrice"
+ ; Remove the entire application directory so any file that is not part of
+ ; the installed payload (e.g. build-tree artifacts such as *.dir folders,
+ ; *_autogen and *.tlog files from a build) cannot survive between an
+ ; uninstall and a fresh reinstall.
+ RMDir /r "$INSTDIR"
+
+ RMDir /r "$SMPROGRAMS\Cockatrice"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Cockatrice"
SectionEnd
diff --git a/cmake/pch/qtcore_pch.h b/cmake/pch/qtcore_pch.h
new file mode 100644
index 000000000..cc3dd12ee
--- /dev/null
+++ b/cmake/pch/qtcore_pch.h
@@ -0,0 +1,24 @@
+/** @file qtcore_pch.h
+ * @brief Precompiled header for all Qt targets (Qt Core only).
+ *
+ * Safe for every target that links Qt Core, including the headless
+ * Servatrice binary. Keep this header free of any widget/gui types.
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
diff --git a/cmake/pch/qtwidgets_pch.h b/cmake/pch/qtwidgets_pch.h
new file mode 100644
index 000000000..2c63f450e
--- /dev/null
+++ b/cmake/pch/qtwidgets_pch.h
@@ -0,0 +1,30 @@
+/** @file qtwidgets_pch.h
+ * @brief Precompiled header for GUI targets (Cockatrice client, Oracle).
+ *
+ * Includes the Qt Core precompiled header plus the heavy Gui, Widgets and
+ * Network layers that virtually every client translation unit re-parses.
+ * Do not use on Servatrice (headless, QT_DONT_USE_QTGUI).
+ */
+
+#include "qtcore_pch.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
diff --git a/cockatrice/CMakeLists.txt b/cockatrice/CMakeLists.txt
index c00f1b9ce..9b31310e6 100644
--- a/cockatrice/CMakeLists.txt
+++ b/cockatrice/CMakeLists.txt
@@ -45,11 +45,14 @@ set(cockatrice_SOURCES
src/interface/widgets/dialogs/dlg_load_deck_from_website.cpp
src/interface/widgets/dialogs/dlg_load_remote_deck.cpp
src/interface/widgets/dialogs/dlg_local_game_options.cpp
+ src/interface/widgets/dialogs/dlg_login_prompt.cpp
src/interface/widgets/dialogs/dlg_manage_sets.cpp
src/interface/widgets/dialogs/dlg_my_reports.cpp
src/interface/widgets/dialogs/dlg_register.cpp
src/interface/widgets/dialogs/dlg_report_user.cpp
src/interface/widgets/dialogs/dlg_select_set_for_cards.cpp
+ src/interface/widgets/dialogs/dlg_share_deck.cpp
+ src/interface/widgets/dialogs/dlg_shared_decks_preview.cpp
src/interface/widgets/dialogs/dlg_settings.cpp
src/interface/widgets/dialogs/dlg_startup_card_check.cpp
src/interface/widgets/dialogs/dlg_tip_of_the_day.cpp
@@ -57,6 +60,9 @@ set(cockatrice_SOURCES
src/interface/widgets/dialogs/dlg_view_log.cpp
src/interface/widgets/dialogs/override_printing_warning.cpp
src/interface/widgets/dialogs/tip_of_the_day.cpp
+ src/interface/widgets/deck_share/deck_share_utils.cpp
+ src/interface/widgets/deck_share/shared_deck_preview_widget.cpp
+ src/interface/widgets/deck_share/share_bar_widget.cpp
src/filters/deck_filter_string.cpp
src/filters/filter_builder.cpp
src/filters/filter_tree_model.cpp
@@ -163,9 +169,11 @@ set(cockatrice_SOURCES
src/interface/palette_editor/palette_grid_widget.cpp
src/interface/palette_editor/palette_editor_dialog.cpp
src/interface/widgets/cards/additional_info/color_identity_widget.cpp
+ src/interface/widgets/cards/additional_info/deck_color_identity.cpp
src/interface/widgets/cards/additional_info/mana_cost_widget.cpp
src/interface/widgets/cards/additional_info/mana_symbol_widget.cpp
src/interface/widgets/cards/art_crop_attribution.cpp
+ src/interface/widgets/cards/card_art_utils.cpp
src/interface/widgets/cards/card_group_display_widgets/card_group_display_widget.cpp
src/interface/widgets/cards/card_group_display_widgets/flat_card_group_display_widget.cpp
src/interface/widgets/cards/card_group_display_widgets/overlapped_card_group_display_widget.cpp
@@ -214,6 +222,7 @@ set(cockatrice_SOURCES
src/interface/widgets/deck_editor/deck_editor_printing_selector_dock_widget.cpp
src/interface/widgets/deck_editor/deck_list_style_proxy.cpp
src/interface/widgets/deck_editor/deck_state_manager.cpp
+ src/interface/widgets/deck_editor/deck_zone_dialog.cpp
src/interface/widgets/deck_editor/printing_disabled_info_widget.cpp
src/interface/widgets/general/background_sources.cpp
src/interface/widgets/general/display/background_plate_widget.cpp
@@ -271,6 +280,7 @@ set(cockatrice_SOURCES
src/interface/widgets/server/user/user_context_menu.cpp
src/interface/widgets/server/user/user_info_box.cpp
src/interface/widgets/server/user/user_info_connection.cpp
+ src/interface/widgets/server/user/user_list_dialog.cpp
src/interface/widgets/server/user/user_list_manager.cpp
src/interface/widgets/server/user/user_list_painter.cpp
src/interface/widgets/server/user/user_list_panel_widget.cpp
@@ -314,6 +324,8 @@ set(cockatrice_SOURCES
src/interface/widgets/visual_deck_storage/deck_preview/deck_preview_tag_display_widget.cpp
src/interface/widgets/visual_deck_storage/deck_preview/deck_preview_tag_item_widget.cpp
src/interface/widgets/visual_deck_storage/deck_preview/deck_preview_widget.cpp
+ src/interface/widgets/visual_deck_storage/deck_preview/public_deck_preview_widget.cpp
+ src/interface/widgets/visual_deck_storage/remote_public_decks_model.cpp
src/interface/widgets/visual_deck_storage/visual_deck_storage_folder_display_widget.cpp
src/interface/widgets/visual_deck_storage/visual_deck_storage_model.cpp
src/interface/widgets/visual_deck_storage/visual_deck_storage_quick_settings_widget.cpp
@@ -379,11 +391,13 @@ set(cockatrice_SOURCES
src/interface/widgets/tabs/tab_card_art_rules.cpp
src/interface/widgets/tabs/tab_deck_editor.cpp
src/interface/widgets/tabs/tab_deck_storage.cpp
+ src/interface/widgets/tabs/tab_developer.cpp
src/interface/widgets/tabs/tab_game.cpp
src/interface/widgets/tabs/tab_home.cpp
src/interface/widgets/tabs/tab_logs.cpp
src/interface/widgets/tabs/tab_message.cpp
src/interface/widgets/tabs/tab_moderation.cpp
+ src/interface/widgets/tabs/tab_public_decks.cpp
src/interface/widgets/tabs/tab_report.cpp
src/interface/widgets/tabs/tab_replays.cpp
src/interface/widgets/tabs/tab_room.cpp
@@ -399,6 +413,7 @@ set(cockatrice_SOURCES
src/interface/widgets/tabs/api/commander_spellbook/commander_bracket_widget.cpp
src/interface/widgets/tabs/api/commander_spellbook/handle_commander_brackets.cpp
src/interface/widgets/onboarding/banner_shader_config.h
+ src/interface/widgets/onboarding/brand_colors.h
src/interface/widgets/onboarding/first_run_wizard.cpp
src/interface/widgets/onboarding/first_run_wizard.h
src/interface/widgets/onboarding/first_run_wizard_page.cpp
@@ -439,6 +454,8 @@ set(cockatrice_SOURCES
src/interface/intents/intent_login.h
src/interface/intents/intent_open_server_room_by_name.cpp
src/interface/intents/intent_open_server_room_by_name.h
+ src/interface/intents/intent_open_shared_deck.cpp
+ src/interface/intents/intent_open_shared_deck.h
src/interface/intents/url_parser.cpp
src/interface/intents/url_parser.h
src/interface/widgets/server/user/user_info_popup.cpp
@@ -515,6 +532,8 @@ qt6_add_executable(
MANUAL_FINALIZATION
)
+target_precompile_headers(cockatrice PRIVATE "${CMAKE_SOURCE_DIR}/cmake/pch/qtwidgets_pch.h")
+
qt6_add_shaders(
cockatrice
"onboarding_shaders"
@@ -524,6 +543,7 @@ qt6_add_shaders(
"src/interface/widgets/onboarding/shaders"
FILES
src/interface/widgets/onboarding/shaders/brand_banner.frag
+ src/interface/widgets/onboarding/shaders/brand_plate.frag
)
qt6_add_resources(
@@ -648,18 +668,35 @@ if(WIN32)
set(qtconf_dest_dir .)
install(
- DIRECTORY "${CMAKE_BINARY_DIR}/${PROJECT_NAME}/${CMAKE_BUILD_TYPE}/"
+ DIRECTORY "$/"
DESTINATION ./
FILES_MATCHING
PATTERN "*.dll"
+ PATTERN "*.pdb" EXCLUDE
+ PATTERN "*.dir*" EXCLUDE
+ PATTERN "*_autogen*" EXCLUDE
+ PATTERN "*.tlog*" EXCLUDE
+ PATTERN "CMakeFiles*" EXCLUDE
+ PATTERN "x64*" EXCLUDE
+ PATTERN ".qt*" EXCLUDE
+ PATTERN ".qsb*" EXCLUDE
+ PATTERN ".lupdate*" EXCLUDE
)
install(
DIRECTORY "${CMAKE_BINARY_DIR}/cockatrice/"
DESTINATION ./
FILES_MATCHING
- PATTERN "CMakeFiles" EXCLUDE
PATTERN "*.ini"
+ PATTERN "CMakeFiles*" EXCLUDE
+ PATTERN "*.dir*" EXCLUDE
+ PATTERN "*_autogen*" EXCLUDE
+ PATTERN "*.tlog*" EXCLUDE
+ PATTERN "*.pdb" EXCLUDE
+ PATTERN "x64*" EXCLUDE
+ PATTERN ".qt*" EXCLUDE
+ PATTERN ".qsb*" EXCLUDE
+ PATTERN ".lupdate*" EXCLUDE
)
# Qt plugins: audio, iconengines, imageformats, multimedia, platforms, printsupport, styles, tls
@@ -712,10 +749,6 @@ Data = Resources\")
"
COMPONENT Runtime
)
-
- if(OPENSSL_FOUND)
- install(FILES ${OPENSSL_INCLUDE_DIRS} DESTINATION ./)
- endif()
endif()
if(Qt6LinguistTools_FOUND)
diff --git a/cockatrice/cockatrice.qrc b/cockatrice/cockatrice.qrc
index e21bdb0be..14cf15b2f 100644
--- a/cockatrice/cockatrice.qrc
+++ b/cockatrice/cockatrice.qrc
@@ -63,6 +63,8 @@
resources/icons/mana/W.svg
resources/backgrounds/home.png
+ resources/backgrounds/home-dark.png
+ resources/backgrounds/home-light.png
resources/backgrounds/card_triplet.svg
resources/backgrounds/placeholder_printing_selector.svg
@@ -363,6 +365,8 @@
resources/usericons/pawn_single.svg
resources/usericons/pawn_double.svg
+ resources/usericons/pawn_dev_single.svg
+ resources/usericons/pawn_dev_double.svg
resources/usericons/pawn_donator_single.svg
resources/usericons/pawn_donator_double.svg
resources/usericons/pawn_judge_single.svg
diff --git a/cockatrice/resources/backgrounds/home-dark.png b/cockatrice/resources/backgrounds/home-dark.png
new file mode 100644
index 000000000..68f48e2c2
Binary files /dev/null and b/cockatrice/resources/backgrounds/home-dark.png differ
diff --git a/cockatrice/resources/backgrounds/home-light.png b/cockatrice/resources/backgrounds/home-light.png
new file mode 100644
index 000000000..eaaaba932
Binary files /dev/null and b/cockatrice/resources/backgrounds/home-light.png differ
diff --git a/cockatrice/resources/backgrounds/home.png b/cockatrice/resources/backgrounds/home.png
index 68f48e2c2..eaaaba932 100644
Binary files a/cockatrice/resources/backgrounds/home.png and b/cockatrice/resources/backgrounds/home.png differ
diff --git a/cockatrice/resources/help/search.md b/cockatrice/resources/help/search.md
index 0c8bdb450..fd0a12507 100644
--- a/cockatrice/resources/help/search.md
+++ b/cockatrice/resources/help/search.md
@@ -52,6 +52,7 @@ In this list of examples below, each entry has an explanation and can be clicked
Edition:
[set:lea](#set:lea) (Cards that appear in Alpha, which has the set code LEA)
[e:lea OR e:leb](#e:lea OR e:leb) (Cards that appear in Alpha or Beta)
+[e<8ED](#e<8ED) (Cards that appear before 8th edition)
Negate:
[c:wu -c:m](#c:wu -c:m) (Any card that is white or blue, but not multicolored)
diff --git a/cockatrice/resources/usericons/pawn_dev_double.svg b/cockatrice/resources/usericons/pawn_dev_double.svg
new file mode 100644
index 000000000..57ed5c2da
--- /dev/null
+++ b/cockatrice/resources/usericons/pawn_dev_double.svg
@@ -0,0 +1,343 @@
+
+
+
+
diff --git a/cockatrice/resources/usericons/pawn_dev_single.svg b/cockatrice/resources/usericons/pawn_dev_single.svg
new file mode 100644
index 000000000..f7c4e7018
--- /dev/null
+++ b/cockatrice/resources/usericons/pawn_dev_single.svg
@@ -0,0 +1,211 @@
+
+
+
+
diff --git a/cockatrice/src/client/network/connection_controller/remote_connection_controller.cpp b/cockatrice/src/client/network/connection_controller/remote_connection_controller.cpp
index 890a621c8..c1598bd25 100644
--- a/cockatrice/src/client/network/connection_controller/remote_connection_controller.cpp
+++ b/cockatrice/src/client/network/connection_controller/remote_connection_controller.cpp
@@ -1,5 +1,6 @@
#include "remote_connection_controller.h"
+#include "../../../interface/pixel_map_generator.h"
#include "../../settings/cache_settings.h"
#include "../interface/widgets/dialogs/dlg_connect.h"
#include "../interface/widgets/dialogs/dlg_forgot_password_challenge.h"
@@ -180,7 +181,7 @@ void ConnectionController::onServerShutdownEvent(const Event_ServerShutdown &eve
"games will be lost.\nReason for shutdown: %1",
"", event.minutes())
.arg(QString::fromStdString(event.reason())));
- serverShutdownMessageBox.setIconPixmap(QPixmap("theme:cockatrice").scaled(64, 64));
+ serverShutdownMessageBox.setIconPixmap(themePixmap(QStringLiteral("cockatrice")).scaled(64, 64));
serverShutdownMessageBox.setText(tr("Scheduled server shutdown"));
serverShutdownMessageBox.setWindowModality(Qt::ApplicationModal);
serverShutdownMessageBox.setVisible(true);
diff --git a/cockatrice/src/client/settings/cache_settings.h b/cockatrice/src/client/settings/cache_settings.h
index 23cdb4dbf..7a90d82f1 100644
--- a/cockatrice/src/client/settings/cache_settings.h
+++ b/cockatrice/src/client/settings/cache_settings.h
@@ -58,33 +58,33 @@ signals:
void themeChanged();
private:
- QSettings *settings;
- ShortcutsSettings *shortcutsSettings;
- CardDatabaseSettings *cardDatabaseSettings;
- ServersSettings *serversSettings;
- MessageSettings *messageSettings;
- GameFiltersSettings *gameFiltersSettings;
- LayoutsSettings *layoutsSettings;
- DownloadSettings *downloadSettings;
- RecentsSettings *recentsSettings;
- CardOverrideSettings *cardOverrideSettings;
- DebugSettings *debugSettings;
- CardCounterSettings *cardCounterSettings;
- TabsSettings *tabsSettings;
- SoundSettings *soundSettings;
- GameSettings *gameSettings;
- ChatSettings *chatSettings;
- CacheStorageSettings *cacheStorageSettings;
- UpdatesSettings *updatesSettings;
- PersonalSettings *personalSettings;
- CardsDisplaySettings *cardsDisplaySettings;
- InterfaceSettings *interfaceSettings;
- DeckEditorSettings *deckEditorSettings;
- PathsSettings *pathsSettings;
- VisualDeckStorageSettings *visualDeckStorageSettings;
- AppearanceSettings *appearanceSettings;
- NetworkSettings *networkSettings;
- CommanderBracketSettings *commanderBracketSettings;
+ QSettings *settings = nullptr;
+ ShortcutsSettings *shortcutsSettings = nullptr;
+ CardDatabaseSettings *cardDatabaseSettings = nullptr;
+ ServersSettings *serversSettings = nullptr;
+ MessageSettings *messageSettings = nullptr;
+ GameFiltersSettings *gameFiltersSettings = nullptr;
+ LayoutsSettings *layoutsSettings = nullptr;
+ DownloadSettings *downloadSettings = nullptr;
+ RecentsSettings *recentsSettings = nullptr;
+ CardOverrideSettings *cardOverrideSettings = nullptr;
+ DebugSettings *debugSettings = nullptr;
+ CardCounterSettings *cardCounterSettings = nullptr;
+ TabsSettings *tabsSettings = nullptr;
+ SoundSettings *soundSettings = nullptr;
+ GameSettings *gameSettings = nullptr;
+ ChatSettings *chatSettings = nullptr;
+ CacheStorageSettings *cacheStorageSettings = nullptr;
+ UpdatesSettings *updatesSettings = nullptr;
+ PersonalSettings *personalSettings = nullptr;
+ CardsDisplaySettings *cardsDisplaySettings = nullptr;
+ InterfaceSettings *interfaceSettings = nullptr;
+ DeckEditorSettings *deckEditorSettings = nullptr;
+ PathsSettings *pathsSettings = nullptr;
+ VisualDeckStorageSettings *visualDeckStorageSettings = nullptr;
+ AppearanceSettings *appearanceSettings = nullptr;
+ NetworkSettings *networkSettings = nullptr;
+ CommanderBracketSettings *commanderBracketSettings = nullptr;
QString themeName;
diff --git a/cockatrice/src/client/sound_engine.cpp b/cockatrice/src/client/sound_engine.cpp
index 18de2264d..96cafa3d3 100644
--- a/cockatrice/src/client/sound_engine.cpp
+++ b/cockatrice/src/client/sound_engine.cpp
@@ -94,7 +94,7 @@ QStringMap &SoundEngine::getAvailableThemes()
QDir dir;
availableThemes.clear();
- // load themes from user profile dir
+ // Load themes from user profile dir
dir.setPath(SettingsCache::instance().getDataPath() + "/sounds");
@@ -104,7 +104,7 @@ QStringMap &SoundEngine::getAvailableThemes()
}
}
- // load themes from cockatrice system dir
+ // Load themes from Cockatrice system dir
dir.setPath(qApp->applicationDirPath() +
#ifdef Q_OS_MAC
"/../Resources/sounds"
diff --git a/cockatrice/src/filters/deck_filter_string.cpp b/cockatrice/src/filters/deck_filter_string.cpp
index 4abb8210c..a2b7519a8 100644
--- a/cockatrice/src/filters/deck_filter_string.cpp
+++ b/cockatrice/src/filters/deck_filter_string.cpp
@@ -43,6 +43,12 @@ NumericValue <- [0-9]+
static std::once_flag init;
+// The peglib parser is a single permanent object, so the rule actions below cannot see
+// per-instance state. The card language that the nested [[card name]] search matches
+// against is passed through this thread-local context, which is live only while a
+// DeckFilterString is being parsed, and copied into the nested FilterString closures.
+thread_local CardSearchLanguage deckSearchLanguageContext;
+
static void setupParserRules()
{
// plumbing
@@ -116,7 +122,7 @@ static void setupParserRules()
// actual functionality
search["DeckContentQuery"] = [](const peg::SemanticValues &sv) -> DeckFilter {
- auto cardFilter = FilterString(std::any_cast(sv[0]));
+ auto cardFilter = FilterString(std::any_cast(sv[0]), deckSearchLanguageContext);
auto numberMatcher = sv.size() > 1 ? std::any_cast(sv[1]) : [](int count) { return count > 0; };
return [=](const DeckSearchData &data) -> bool {
@@ -186,7 +192,7 @@ DeckFilterString::DeckFilterString()
_error = "Not initialized";
}
-DeckFilterString::DeckFilterString(const QString &expr)
+DeckFilterString::DeckFilterString(const QString &expr, const CardSearchLanguage &searchLanguage)
{
QByteArray ba = expr.simplified().toUtf8();
@@ -199,6 +205,8 @@ DeckFilterString::DeckFilterString(const QString &expr)
return;
}
+ deckSearchLanguageContext = searchLanguage;
+
search.set_logger([&](size_t /*ln*/, size_t col, const std::string &msg) {
_error = QString("Error at position %1: %2").arg(col).arg(QString::fromStdString(msg));
});
diff --git a/cockatrice/src/filters/deck_filter_string.h b/cockatrice/src/filters/deck_filter_string.h
index 90a6a17eb..5b1419004 100644
--- a/cockatrice/src/filters/deck_filter_string.h
+++ b/cockatrice/src/filters/deck_filter_string.h
@@ -12,6 +12,7 @@
#include
#include
#include
+#include
inline Q_LOGGING_CATEGORY(DeckFilterStringLog, "deck_filter_string");
@@ -35,7 +36,7 @@ class DeckFilterString
{
public:
DeckFilterString();
- explicit DeckFilterString(const QString &expr);
+ explicit DeckFilterString(const QString &expr, const CardSearchLanguage &searchLanguage = {});
bool check(const DeckSearchData &data) const
{
return filter(data);
diff --git a/cockatrice/src/filters/filter_builder.cpp b/cockatrice/src/filters/filter_builder.cpp
index 785f753e7..f109fbcd3 100644
--- a/cockatrice/src/filters/filter_builder.cpp
+++ b/cockatrice/src/filters/filter_builder.cpp
@@ -1,5 +1,6 @@
#include "filter_builder.h"
+#include "../interface/pixel_map_generator.h"
#include "../interface/widgets/utility/custom_line_edit.h"
#include
@@ -21,7 +22,7 @@ FilterBuilder::FilterBuilder(QWidget *parent) : QWidget(parent)
typeCombo->addItem(CardFilter::typeName(static_cast(i)), QVariant(i));
}
- QPushButton *ok = new QPushButton(QPixmap("theme:icons/increment"), QString());
+ QPushButton *ok = new QPushButton(themePixmap(QStringLiteral("icons/increment")), QString());
ok->setObjectName("ok");
ok->setMaximumSize(20, 20);
diff --git a/cockatrice/src/game/board/counter_state.cpp b/cockatrice/src/game/board/counter_state.cpp
index 6da18b662..0970e4272 100644
--- a/cockatrice/src/game/board/counter_state.cpp
+++ b/cockatrice/src/game/board/counter_state.cpp
@@ -13,12 +13,12 @@ CounterState *CounterState::fromProto(const ServerInfo_Counter &counter, QObject
convertColorToQColor(counter.counter_color()), counter.radius(), counter.count(), parent);
}
-void CounterState::setValue(int newValue)
+void CounterState::setValue(int newValue, bool skipDamageAnimation)
{
if (newValue == value) {
return;
}
int old = value;
value = newValue;
- emit valueChanged(old, newValue);
+ emit valueChanged(old, newValue, skipDamageAnimation);
}
\ No newline at end of file
diff --git a/cockatrice/src/game/board/counter_state.h b/cockatrice/src/game/board/counter_state.h
index 0f2f16b55..4c7b34473 100644
--- a/cockatrice/src/game/board/counter_state.h
+++ b/cockatrice/src/game/board/counter_state.h
@@ -35,10 +35,23 @@ public:
return value;
}
- void setValue(int newValue);
+ /**
+ * @brief Set the counter value.
+ * @param newValue The new value.
+ * @param skipDamageAnimation When true, valueChanged is emitted with skipDamageAnimation=true, letting views
+ * suppress damage-related feedback (e.g. battlefield shimmer, life counter flash) for values set during replay
+ * rewinds.
+ */
+ void setValue(int newValue, bool skipDamageAnimation = false);
signals:
- void valueChanged(int oldValue, int newValue);
+ /**
+ * @brief Emitted whenever the value changes.
+ * @param oldValue The previous value.
+ * @param newValue The new value.
+ * @param skipDamageAnimation True when the change should not trigger damage/life-change feedback in views.
+ */
+ void valueChanged(int oldValue, int newValue, bool skipDamageAnimation);
private:
int id;
diff --git a/cockatrice/src/game/game_event_handler.cpp b/cockatrice/src/game/game_event_handler.cpp
index bc68d4d7c..f146cdbb4 100644
--- a/cockatrice/src/game/game_event_handler.cpp
+++ b/cockatrice/src/game/game_event_handler.cpp
@@ -430,12 +430,13 @@ void GameEventHandler::eventJoin(const Event_Join &event, int /*eventPlayerId*/,
QString playerName = QString::fromStdString(playerInfo.user_info().name());
emit addPlayerToAutoCompleteList(playerName);
- if (game->getPlayerManager()->getPlayers().contains(playerId)) {
+ PlayerManager *playerManager = game->getPlayerManager();
+ if (playerManager->getPlayers().contains(playerId) || playerManager->getSpectators().contains(playerId)) {
return;
}
if (playerInfo.spectator()) {
- game->getPlayerManager()->addSpectator(playerId, playerInfo);
+ playerManager->addSpectator(playerId, playerInfo);
emit logJoinSpectator(playerName);
emit spectatorJoined(playerInfo);
} else {
diff --git a/cockatrice/src/game/player/event_processing_options.h b/cockatrice/src/game/player/event_processing_options.h
index 4c7663789..06238d77e 100644
--- a/cockatrice/src/game/player/event_processing_options.h
+++ b/cockatrice/src/game/player/event_processing_options.h
@@ -13,7 +13,8 @@
enum EventProcessingOption
{
SKIP_REVEAL_WINDOW = 0x0001,
- SKIP_TAP_ANIMATION = 0x0002
+ SKIP_TAP_ANIMATION = 0x0002,
+ SKIP_DAMAGE_ANIMATION = 0x0004
};
// Wrap it in a QFlags typedef
diff --git a/cockatrice/src/game/player/player_event_handler.cpp b/cockatrice/src/game/player/player_event_handler.cpp
index bc48298f7..277b8b1d4 100644
--- a/cockatrice/src/game/player/player_event_handler.cpp
+++ b/cockatrice/src/game/player/player_event_handler.cpp
@@ -262,14 +262,15 @@ void PlayerEventHandler::eventCreateCounter(const Event_CreateCounter &event)
player->addCounter(event.counter_info());
}
-void PlayerEventHandler::eventSetCounter(const Event_SetCounter &event)
+void PlayerEventHandler::eventSetCounter(const Event_SetCounter &event, EventProcessingOptions options)
{
CounterState *ctr = player->getCounters().value(event.counter_id(), nullptr);
if (!ctr) {
return;
}
int oldValue = ctr->getValue();
- ctr->setValue(event.value());
+ const bool skipDamageAnimation = options.testFlag(SKIP_DAMAGE_ANIMATION);
+ ctr->setValue(event.value(), skipDamageAnimation);
emit logSetCounter(player, ctr->getName(), event.value(), oldValue);
}
@@ -625,7 +626,7 @@ void PlayerEventHandler::processGameEvent(GameEvent::GameEventType type,
eventCreateCounter(event.GetExtension(Event_CreateCounter::ext));
break;
case GameEvent::SET_COUNTER:
- eventSetCounter(event.GetExtension(Event_SetCounter::ext));
+ eventSetCounter(event.GetExtension(Event_SetCounter::ext), options);
break;
case GameEvent::DEL_COUNTER:
eventDelCounter(event.GetExtension(Event_DelCounter::ext));
diff --git a/cockatrice/src/game/player/player_event_handler.h b/cockatrice/src/game/player/player_event_handler.h
index 48ad85e88..300cacd08 100644
--- a/cockatrice/src/game/player/player_event_handler.h
+++ b/cockatrice/src/game/player/player_event_handler.h
@@ -153,7 +153,7 @@ public:
void eventCreateCounter(const Event_CreateCounter &event);
/// Set a player-level counter value.
- void eventSetCounter(const Event_SetCounter &event);
+ void eventSetCounter(const Event_SetCounter &event, EventProcessingOptions options);
/// Delete a player-level counter.
void eventDelCounter(const Event_DelCounter &event);
diff --git a/cockatrice/src/game/player/player_logic.cpp b/cockatrice/src/game/player/player_logic.cpp
index 45ba09aac..143df5c57 100644
--- a/cockatrice/src/game/player/player_logic.cpp
+++ b/cockatrice/src/game/player/player_logic.cpp
@@ -175,7 +175,15 @@ void PlayerLogic::processPlayerInfo(const ServerInfo_Player &info)
const ServerInfo_Card &cardInfo = zoneInfo.card_list(j);
auto *card = new CardItem(this);
card->processCardInfo(cardInfo);
- zone->addCard(card, false, cardInfo.x(), cardInfo.y());
+ // Zones without coordinates (hand, piles, stack) preserve the order
+ // they arrive in on the server in the positions of their cards list.
+ // The x coordinate of such cards is always 0, so inserting at it
+ // would reverse the list on reconnect. Append instead.
+ if (zoneInfo.with_coords()) {
+ zone->addCard(card, false, cardInfo.x(), cardInfo.y());
+ } else {
+ zone->addCard(card, false, -1);
+ }
}
}
if (zoneInfo.has_always_reveal_top_card()) {
diff --git a/cockatrice/src/game/player/player_manager.cpp b/cockatrice/src/game/player/player_manager.cpp
index 6772d3ff1..8486efbeb 100644
--- a/cockatrice/src/game/player/player_manager.cpp
+++ b/cockatrice/src/game/player/player_manager.cpp
@@ -75,6 +75,14 @@ PlayerLogic *PlayerManager::getPlayer(int playerId) const
return player;
}
+void PlayerManager::clearSpectators()
+{
+ const QList spectatorIds = spectators.keys();
+ for (int spectatorId : spectatorIds) {
+ removeSpectator(spectatorId);
+ }
+}
+
void PlayerManager::onPlayerConceded(int playerId, bool conceded)
{
// Everything else cares about this
diff --git a/cockatrice/src/game/player/player_manager.h b/cockatrice/src/game/player/player_manager.h
index 2f8b87af8..504e65396 100644
--- a/cockatrice/src/game/player/player_manager.h
+++ b/cockatrice/src/game/player/player_manager.h
@@ -100,6 +100,9 @@ public:
emit spectatorRemoved(spectatorId, spectatorInfo);
}
+ /** @brief Remove all spectators, emitting the removal signal for each. */
+ void clearSpectators();
+
[[nodiscard]] AbstractGame *getGame() const
{
return game;
diff --git a/cockatrice/src/game_graphics/board/abstract_card_item.cpp b/cockatrice/src/game_graphics/board/abstract_card_item.cpp
index 1410d0c80..3969b7d03 100644
--- a/cockatrice/src/game_graphics/board/abstract_card_item.cpp
+++ b/cockatrice/src/game_graphics/board/abstract_card_item.cpp
@@ -1,6 +1,7 @@
#include "abstract_card_item.h"
#include "../../client/settings/cache_settings.h"
+#include "../../interface/card_localization.h"
#include "../../interface/card_picture_loader/card_picture_loader.h"
#include "../game_scene.h"
#include "../z_values.h"
@@ -26,6 +27,8 @@ AbstractCardItem::AbstractCardItem(QGraphicsItem *parent, const CardRef &cardRef
connect(&SettingsCache::instance().cardsDisplay(), &CardsDisplaySettings::displayCardNamesChanged, this,
[this] { update(); });
+ connect(&SettingsCache::instance().cardsDisplay(), &CardsDisplaySettings::cardLangChanged, this,
+ [this] { update(); });
refreshCardInfo();
connect(&SettingsCache::instance().cardsDisplay(), &CardsDisplaySettings::roundCardCornersChanged, this,
@@ -171,7 +174,7 @@ void AbstractCardItem::paintPicture(QPainter *painter, const QSizeF &translatedS
if (SettingsCache::instance().debug().getShowCardId()) {
prefix = "#" + QString::number(id) + " ";
}
- nameStr = prefix + cardRef.name;
+ nameStr = prefix + CardLocalization::displayName(getCardInfo());
}
painter->drawText(QRectF(3 * scaleFactor, 3 * scaleFactor, translatedSize.width() - 6 * scaleFactor,
translatedSize.height() - 6 * scaleFactor),
diff --git a/cockatrice/src/game_graphics/board/abstract_counter.cpp b/cockatrice/src/game_graphics/board/abstract_counter.cpp
index e63117e13..4ba04804f 100644
--- a/cockatrice/src/game_graphics/board/abstract_counter.cpp
+++ b/cockatrice/src/game_graphics/board/abstract_counter.cpp
@@ -29,9 +29,9 @@ AbstractCounter::AbstractCounter(CounterState *state,
{
setAcceptHoverEvents(true);
- connect(state, &CounterState::valueChanged, this, [this](int oldValue, int newValue) {
+ connect(state, &CounterState::valueChanged, this, [this](int oldValue, int newValue, bool skipDamageAnimation) {
value = newValue;
- onValueChanged(oldValue, newValue);
+ onValueChanged(oldValue, newValue, skipDamageAnimation);
update();
});
@@ -230,7 +230,7 @@ void AbstractCounterDialog::changeValue(int diff)
setTextValue(QString::number(curValue));
}
-void AbstractCounter::onValueChanged(int /*oldValue*/, int /*newValue*/)
+void AbstractCounter::onValueChanged(int /*oldValue*/, int /*newValue*/, bool /*skipDamageAnimation*/)
{
// Default: no feedback. Subclasses such as PlayerCounter override this to
// flash the counter on meaningful changes (life gain/loss).
diff --git a/cockatrice/src/game_graphics/board/abstract_counter.h b/cockatrice/src/game_graphics/board/abstract_counter.h
index 9ddcc6d58..67b5b4074 100644
--- a/cockatrice/src/game_graphics/board/abstract_counter.h
+++ b/cockatrice/src/game_graphics/board/abstract_counter.h
@@ -39,8 +39,9 @@ protected:
* @brief Hook for subclasses that need per-value-change feedback (e.g. life-total flash).
*
* Called whenever the counter's value changes, before the item repaints.
+ * @param skipDamageAnimation True when damage-related feedback should be suppressed (replay rewinds).
*/
- virtual void onValueChanged(int oldValue, int newValue);
+ virtual void onValueChanged(int oldValue, int newValue, bool skipDamageAnimation);
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
diff --git a/cockatrice/src/game_graphics/board/card_item.cpp b/cockatrice/src/game_graphics/board/card_item.cpp
index c40c8c214..c2dc455cc 100644
--- a/cockatrice/src/game_graphics/board/card_item.cpp
+++ b/cockatrice/src/game_graphics/board/card_item.cpp
@@ -316,7 +316,7 @@ void CardItem::drawAttachArrow()
for (const auto &item : scene()->selectedItems()) {
CardItem *card = qgraphicsitem_cast(item);
- if (card == nullptr) {
+ if (card == nullptr || card == this) {
continue;
}
if (card->getZone() != state->getZone()) {
diff --git a/cockatrice/src/game_graphics/deckview/deck_view.cpp b/cockatrice/src/game_graphics/deckview/deck_view.cpp
index 1278737a0..1acd02a75 100644
--- a/cockatrice/src/game_graphics/deckview/deck_view.cpp
+++ b/cockatrice/src/game_graphics/deckview/deck_view.cpp
@@ -10,7 +10,6 @@
#include
#include
#include
-#include
#include
DeckViewCardDragItem::DeckViewCardDragItem(DeckViewCard *_item,
@@ -381,12 +380,10 @@ void DeckViewScene::rebuildTree()
addItem(container);
}
- for (int j = 0; j < currentZone->size(); j++) {
- auto *currentCard = dynamic_cast(currentZone->at(j));
- if (!currentCard) {
- continue;
- }
-
+ // Cards in custom zones nested under a board are regular board cards in-game.
+ // They are collected recursively (like every other consumer) and reported with
+ // the top-level board zone as their origin, so that sideboard plans keep working.
+ for (auto *currentCard : deck->getCardNodes({currentZone->getName()})) {
for (int k = 0; k < currentCard->getNumber(); ++k) {
auto *newCard = new DeckViewCard(container, currentCard->toCardRef(), currentZone->getName());
container->addCard(newCard);
diff --git a/cockatrice/src/game_graphics/dialogs/dlg_create_token.cpp b/cockatrice/src/game_graphics/dialogs/dlg_create_token.cpp
index b311d2ebd..6d8ad0534 100644
--- a/cockatrice/src/game_graphics/dialogs/dlg_create_token.cpp
+++ b/cockatrice/src/game_graphics/dialogs/dlg_create_token.cpp
@@ -16,11 +16,13 @@
#include
#include
#include
+#include
#include
#include
#include
#include
#include
+#include
#include
#include
#include
@@ -88,6 +90,17 @@ DlgCreateToken::DlgCreateToken(const QStringList &_predefinedTokens, QWidget *pa
cardDatabaseDisplayModel = new TokenDisplayModel(this);
cardDatabaseDisplayModel->setSourceModel(cardDatabaseModel);
+ const auto applyCardSearchLanguage = [this]() {
+ const CardsDisplaySettings &cardsDisplay = SettingsCache::instance().cardsDisplay();
+ cardDatabaseDisplayModel->setSearchLanguage(CardSearchLanguage{
+ cardsDisplay.getCardLang(), static_cast(cardsDisplay.getCardSearchLanguage())});
+ };
+ applyCardSearchLanguage();
+ connect(&SettingsCache::instance().cardsDisplay(), &CardsDisplaySettings::cardLangChanged, this,
+ applyCardSearchLanguage);
+ connect(&SettingsCache::instance().cardsDisplay(), &CardsDisplaySettings::cardSearchLanguageChanged, this,
+ applyCardSearchLanguage);
+
chooseTokenFromAllRadioButton = new QRadioButton(tr("Show &all tokens"));
connect(chooseTokenFromAllRadioButton, &QRadioButton::toggled, this, &DlgCreateToken::actChooseTokenFromAll);
chooseTokenFromDeckRadioButton = new QRadioButton(tr("Show tokens from this &deck"));
diff --git a/cockatrice/src/game_graphics/game_scene.cpp b/cockatrice/src/game_graphics/game_scene.cpp
index cd2b12828..17af7618b 100644
--- a/cockatrice/src/game_graphics/game_scene.cpp
+++ b/cockatrice/src/game_graphics/game_scene.cpp
@@ -44,11 +44,16 @@ GameScene::GameScene(PhasesToolbar *_phasesToolbar, QObject *parent)
GameScene::~GameScene()
{
- // Sever all incoming connections (animated item destroy-tracking) before the
- // members below are destroyed: the base QGraphicsScene destructor destroys the
- // remaining items, and their destroyed() signals must not reach slots that
- // reference members that no longer exist.
- disconnect(this);
+ // Sever all destroyed->removeAnimatedItem connections before the members below
+ // are destroyed: the base QGraphicsScene destructor destroys the remaining items,
+ // and their destroyed() signals must not reach slots that reference members that
+ // no longer exist. The connection handle overload is used because the string-based
+ // disconnect(nullptr, nullptr, this, nullptr) is invalid (the sender must never be
+ // nullptr) and would otherwise fail to sever these pointer-to-member connections.
+ for (auto it = animationItemConnections.constBegin(); it != animationItemConnections.constEnd(); ++it) {
+ QObject::disconnect(*it);
+ }
+ animationItemConnections.clear();
delete animationTimer;
animationTimer = nullptr;
@@ -216,7 +221,12 @@ void GameScene::removePlayer(PlayerLogic *player)
clearArrowsForPlayer(player->getPlayerInfo()->getId());
- for (ZoneViewWidget *zone : zoneViews) {
+ // Closing a view removes it from zoneViews synchronously, so iterate over a
+ // copy: otherwise a player with several open views (e.g. library and hand)
+ // only has the first one closed here and the remaining views are left
+ // pointing at a player that is about to be deleted.
+ const QList zoneViewCopy = zoneViews;
+ for (ZoneViewWidget *zone : zoneViewCopy) {
if (zone->getPlayer() == player) {
zone->close();
}
@@ -659,7 +669,10 @@ CardItem *GameScene::findTopmostCardInZone(const QList &items,
*/
void GameScene::toggleZoneView(PlayerLogic *player, const QString &zoneName, int numberCards, bool isReversed)
{
- for (auto &view : zoneViews) {
+ // Closing a view removes it from zoneViews synchronously, so iterate over a
+ // copy to make sure every already-open matching view is closed.
+ const QList zoneViewCopy = zoneViews;
+ for (auto *view : zoneViewCopy) {
ZoneViewZone *temp = view->getZone();
if (temp->getLogic()->getName() == zoneName && temp->getLogic()->getPlayer() == player &&
qobject_cast(temp->getLogic())->getNumberCards() == numberCards) {
@@ -777,8 +790,15 @@ void GameScene::registerAnimationItem(IAnimatedItem *item)
if (!object) {
return;
}
- if (!animatedItems.contains(object)) {
- connect(object, &QObject::destroyed, this, &GameScene::removeAnimatedItem);
+ // Guard against duplicate connections using the connection map, not
+ // animatedItems: the animation timer removes entries from animatedItems when an
+ // animation completes, but the destroyed->removeAnimatedItem connection must
+ // persist until the object is destroyed. Relying on animatedItems here would let
+ // a re-registered item (e.g. a life counter that flashes repeatedly) accumulate
+ // duplicate destroyed connections, the older ones of which would survive teardown.
+ if (!animationItemConnections.contains(object)) {
+ animationItemConnections.insert(object,
+ connect(object, &QObject::destroyed, this, &GameScene::removeAnimatedItem));
}
animatedItems.insert(object, item);
if (animationTimer && !animationTimer->isActive()) {
@@ -797,6 +817,7 @@ void GameScene::unregisterAnimationItem(IAnimatedItem *item)
void GameScene::removeAnimatedItem(QObject *item)
{
animatedItems.remove(item);
+ animationItemConnections.remove(item);
if (animationTimer && animatedItems.isEmpty()) {
animationTimer->stop();
}
diff --git a/cockatrice/src/game_graphics/game_scene.h b/cockatrice/src/game_graphics/game_scene.h
index c12696189..859d7a6eb 100644
--- a/cockatrice/src/game_graphics/game_scene.h
+++ b/cockatrice/src/game_graphics/game_scene.h
@@ -54,9 +54,11 @@ private:
QPointer hoveredCard; ///< Currently hovered card
QBasicTimer *animationTimer; ///< Timer for scene animations
QHash animatedItems; ///< Items currently animating
- int playerRotation; ///< Rotation offset for player layout
- bool rearranging = false; ///< Guard against re-entrant rearrange
- bool needsReArrange = false; ///< Pending rearrange requested during a pass
+ QHash
+ animationItemConnections; ///< destroyed->removeAnimatedItem handles per animated item
+ int playerRotation; ///< Rotation offset for player layout
+ bool rearranging = false; ///< Guard against re-entrant rearrange
+ bool needsReArrange = false; ///< Pending rearrange requested during a pass
/**
* @brief Updates which card is currently hovered based on scene coordinates.
diff --git a/cockatrice/src/game_graphics/hand_counter.cpp b/cockatrice/src/game_graphics/hand_counter.cpp
index 35989ff38..8dcbcfdaa 100644
--- a/cockatrice/src/game_graphics/hand_counter.cpp
+++ b/cockatrice/src/game_graphics/hand_counter.cpp
@@ -1,5 +1,6 @@
#include "hand_counter.h"
+#include "../interface/pixel_map_generator.h"
#include "zones/card_zone.h"
#include
@@ -32,7 +33,8 @@ void HandCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*op
QSize translatedSize = painter->combinedTransform().mapRect(boundingRect()).size().toSize();
QPixmap cachedPixmap;
if (!QPixmapCache::find("handCounter" + QString::number(translatedSize.width()), &cachedPixmap)) {
- cachedPixmap = QPixmap("theme:hand").scaled(translatedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
+ cachedPixmap =
+ themePixmap(QStringLiteral("hand")).scaled(translatedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
QPixmapCache::insert("handCounter" + QString::number(translatedSize.width()), cachedPixmap);
}
resetPainterTransform(painter);
diff --git a/cockatrice/src/game_graphics/player/menu/tally_menu.cpp b/cockatrice/src/game_graphics/player/menu/tally_menu.cpp
index 7eb3945b3..08cb6cac9 100644
--- a/cockatrice/src/game_graphics/player/menu/tally_menu.cpp
+++ b/cockatrice/src/game_graphics/player/menu/tally_menu.cpp
@@ -12,11 +12,13 @@ TallyMenu::TallyMenu()
aTallyNone = createTallyAction(TallyType::None);
aTallySubtypes = createTallyAction(TallyType::Subtypes);
aTallyTotalPower = createTallyAction(TallyType::TotalPower);
+ aTallyTotalToughness = createTallyAction(TallyType::TotalToughness);
addAction(aTallyNone);
addSeparator();
addAction(aTallySubtypes);
addAction(aTallyTotalPower);
+ addAction(aTallyTotalToughness);
retranslateUi();
}
@@ -54,4 +56,5 @@ void TallyMenu::retranslateUi()
aTallyNone->setText(tr("None"));
aTallySubtypes->setText(tr("Subtypes"));
aTallyTotalPower->setText(tr("Total Power"));
+ aTallyTotalToughness->setText(tr("Total Toughness"));
}
diff --git a/cockatrice/src/game_graphics/player/menu/tally_menu.h b/cockatrice/src/game_graphics/player/menu/tally_menu.h
index acd1daf67..11802fd20 100644
--- a/cockatrice/src/game_graphics/player/menu/tally_menu.h
+++ b/cockatrice/src/game_graphics/player/menu/tally_menu.h
@@ -24,6 +24,7 @@ private:
QAction *aTallyNone = nullptr;
QAction *aTallySubtypes = nullptr;
QAction *aTallyTotalPower = nullptr;
+ QAction *aTallyTotalToughness = nullptr;
QAction *createTallyAction(TallyType tallyType);
};
diff --git a/cockatrice/src/game_graphics/player/player_graphics_item.cpp b/cockatrice/src/game_graphics/player/player_graphics_item.cpp
index 8bf2703e1..122ab83be 100644
--- a/cockatrice/src/game_graphics/player/player_graphics_item.cpp
+++ b/cockatrice/src/game_graphics/player/player_graphics_item.cpp
@@ -3,6 +3,7 @@
#include "../../game/player/player_actions.h"
#include "../../interface/card_picture_loader/card_picture_loader.h"
#include "../../interface/widgets/cards/art_crop_attribution.h"
+#include "../../interface/widgets/cards/card_art_utils.h"
#include "../../interface/widgets/playmat/playmat_utils.h"
#include "../../interface/widgets/tabs/tab_game.h"
#include "../board/abstract_card_item.h"
@@ -251,8 +252,8 @@ void PlayerGraphicsItem::onCounterAdded(CounterState *state)
AbstractCounter *widget;
if (state->getName() == "life") {
widget = playerTarget->addCounter(state);
- connect(state, &CounterState::valueChanged, this, [this](int oldValue, int newValue) {
- if (newValue < oldValue) {
+ connect(state, &CounterState::valueChanged, this, [this](int oldValue, int newValue, bool skipDamageAnimation) {
+ if (newValue < oldValue && !skipDamageAnimation) {
tableZoneGraphicsItem->triggerDamageShimmer();
}
});
@@ -442,7 +443,7 @@ void PlayerGraphicsItem::updatePlaymat()
hasPlaymat = true;
emit playmatChanged(true);
}
- playmatPixmap = fullRes;
+ playmatPixmap = CardArtUtils::rotateSidewaysLayoutArt(fullRes, card);
update();
}
diff --git a/cockatrice/src/game_graphics/player/player_list_widget.cpp b/cockatrice/src/game_graphics/player/player_list_widget.cpp
index 4268e1019..a7ec2e4a9 100644
--- a/cockatrice/src/game_graphics/player/player_list_widget.cpp
+++ b/cockatrice/src/game_graphics/player/player_list_widget.cpp
@@ -53,13 +53,13 @@ PlayerListWidget::PlayerListWidget(TabSupervisor *_tabSupervisor,
QWidget *parent)
: QTreeWidget(parent), tabSupervisor(_tabSupervisor), client(_client), game(_game), gameStarted(false)
{
- readyIcon = QPixmap("theme:icons/ready_start");
- notReadyIcon = QPixmap("theme:icons/not_ready_start");
- concededIcon = QPixmap("theme:icons/conceded");
+ readyIcon = themePixmap(QStringLiteral("icons/ready_start"));
+ notReadyIcon = themePixmap(QStringLiteral("icons/not_ready_start"));
+ concededIcon = themePixmap(QStringLiteral("icons/conceded"));
playerIcon = loadColorAdjustedPixmap("theme:icons/player");
judgeIcon = loadColorAdjustedPixmap("theme:icons/scales");
spectatorIcon = loadColorAdjustedPixmap("theme:icons/spectator");
- lockIcon = QPixmap("theme:icons/lock");
+ lockIcon = themePixmap(QStringLiteral("icons/lock"));
if (tabSupervisor) {
itemDelegate = new PlayerListItemDelegate(this);
@@ -92,6 +92,11 @@ void PlayerListWidget::retranslateUi()
void PlayerListWidget::addPlayer(const ServerInfo_PlayerProperties &player)
{
+ if (players.contains(player.player_id())) {
+ updatePlayerProperties(player);
+ return;
+ }
+
QTreeWidgetItem *newPlayer = new PlayerListTWI;
players.insert(player.player_id(), newPlayer);
updatePlayerProperties(player);
@@ -176,6 +181,17 @@ void PlayerListWidget::removePlayer(int playerId)
delete takeTopLevelItem(indexOfTopLevelItem(player));
}
+void PlayerListWidget::clearSpectators()
+{
+ const QList playerIds = players.keys();
+ for (int playerId : playerIds) {
+ QTreeWidgetItem *player = players.value(playerId, 0);
+ if (player && !player->data(1, Qt::UserRole).toBool()) {
+ removePlayer(playerId);
+ }
+ }
+}
+
void PlayerListWidget::setActivePlayer(int playerId)
{
QMapIterator i(players);
diff --git a/cockatrice/src/game_graphics/player/player_list_widget.h b/cockatrice/src/game_graphics/player/player_list_widget.h
index a53cfa989..f2f0be5fd 100644
--- a/cockatrice/src/game_graphics/player/player_list_widget.h
+++ b/cockatrice/src/game_graphics/player/player_list_widget.h
@@ -66,6 +66,7 @@ public slots:
void addPlayer(const ServerInfo_PlayerProperties &player);
void removePlayer(int playerId);
void updatePlayerProperties(const ServerInfo_PlayerProperties &prop, int playerId = -1);
+ void clearSpectators();
};
#endif
diff --git a/cockatrice/src/game_graphics/player/player_target.cpp b/cockatrice/src/game_graphics/player/player_target.cpp
index 910ee9c17..d6c28370d 100644
--- a/cockatrice/src/game_graphics/player/player_target.cpp
+++ b/cockatrice/src/game_graphics/player/player_target.cpp
@@ -69,7 +69,7 @@ void PlayerCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*
}
}
-void PlayerCounter::onValueChanged(int oldValue, int newValue)
+void PlayerCounter::onValueChanged(int oldValue, int newValue, bool skipDamageAnimation)
{
flashDelta = newValue - oldValue;
if (flashDelta == 0) {
@@ -81,6 +81,11 @@ void PlayerCounter::onValueChanged(int oldValue, int newValue)
return;
}
+ if (skipDamageAnimation) {
+ flashAlpha = 0.0;
+ return;
+ }
+
flashAlpha = 1.0;
flashClock.start();
if (scene()) {
@@ -132,8 +137,18 @@ void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*o
QRectF translatedRect = painter->combinedTransform().mapRect(avatarBoundingRect);
QSize translatedSize = translatedRect.size().toSize();
QPixmap cachedPixmap;
+ // The key must cover everything the generated pawn depends on: the rendered
+ // size, the user level, and the pixmap being drawn. fullPixmap.cacheKey() is
+ // 0 for every null pixmap, so the default-pawn branch additionally needs the
+ // pawn's privlevel (lowercased, matching UserLevelPixmapGenerator) and colors
+ // in the key — otherwise two players without a custom avatar (and the same
+ // user level) would share one cached pawn.
const QString cacheKey = "avatar" + QString::number(translatedSize.width()) + "_" +
- QString::number(info->user_level()) + "_" + QString::number(fullPixmap.cacheKey());
+ QString::number(translatedSize.height()) + "_" + QString::number(info->user_level()) +
+ "_" + QString::number(fullPixmap.cacheKey()) + "_" +
+ QString::fromStdString(info->privlevel()).toLower() + "_" +
+ QString::fromStdString(info->pawn_colors().left_side()) + "_" +
+ QString::fromStdString(info->pawn_colors().right_side());
if (!QPixmapCache::find(cacheKey, &cachedPixmap)) {
cachedPixmap = QPixmap(translatedSize.width(), translatedSize.height());
diff --git a/cockatrice/src/game_graphics/player/player_target.h b/cockatrice/src/game_graphics/player/player_target.h
index af0e9c8b7..1d06c6274 100644
--- a/cockatrice/src/game_graphics/player/player_target.h
+++ b/cockatrice/src/game_graphics/player/player_target.h
@@ -21,7 +21,7 @@ class PlayerCounter : public AbstractCounter, public IAnimatedItem
{
Q_OBJECT
protected:
- void onValueChanged(int oldValue, int newValue) override;
+ void onValueChanged(int oldValue, int newValue, bool skipDamageAnimation) override;
private:
static constexpr qreal flashDurationMs = 450.0;
diff --git a/cockatrice/src/game_graphics/tally/stats_tally.cpp b/cockatrice/src/game_graphics/tally/stats_tally.cpp
index e7a6621fa..7e05c3fb1 100644
--- a/cockatrice/src/game_graphics/tally/stats_tally.cpp
+++ b/cockatrice/src/game_graphics/tally/stats_tally.cpp
@@ -34,3 +34,31 @@ QList StatsTally::computeTotalPower(const QList &cards)
QString name = QCoreApplication::translate("StatsTally", "Total Power");
return {TallyRow{name, QString::number(total)}};
}
+
+static int sumToughness(const QList &cards)
+{
+ int total = 0;
+ for (auto card : cards) {
+ QVariantList parsed = CardItem::parsePT(card->getPT());
+ if (parsed.size() == 2) {
+ int toughness = parsed.at(1).toInt(); // toInt will default to 0 if it's not an int
+ total += qMax(toughness, 0);
+ }
+ }
+ return total;
+}
+
+QList StatsTally::computeTotalToughness(const QList &cards)
+{
+ // don't bother if none of the cards have pt
+ bool hasPT =
+ std::any_of(cards.cbegin(), cards.cend(), [](const CardItem *card) { return !card->getPT().isEmpty(); });
+ if (!hasPT) {
+ return {};
+ }
+
+ int total = sumToughness(cards);
+
+ QString name = QCoreApplication::translate("StatsTally", "Total Toughness");
+ return {TallyRow{name, QString::number(total)}};
+}
diff --git a/cockatrice/src/game_graphics/tally/stats_tally.h b/cockatrice/src/game_graphics/tally/stats_tally.h
index 4c3d93b56..e499587eb 100644
--- a/cockatrice/src/game_graphics/tally/stats_tally.h
+++ b/cockatrice/src/game_graphics/tally/stats_tally.h
@@ -16,6 +16,14 @@ namespace StatsTally
*/
QList computeTotalPower(const QList &cards);
+/**
+ * @brief Sums the toughness of all selected cards
+ *
+ * @param cards The list of selected card items to analyze.
+ * @return A single row containing the total, or an empty list if none of the cards have pt
+ */
+QList computeTotalToughness(const QList &cards);
+
} // namespace StatsTally
#endif // COCKATRICE_STATS_TALLY_H
diff --git a/cockatrice/src/game_graphics/tally/tally.cpp b/cockatrice/src/game_graphics/tally/tally.cpp
index aa2cae024..21806ee84 100644
--- a/cockatrice/src/game_graphics/tally/tally.cpp
+++ b/cockatrice/src/game_graphics/tally/tally.cpp
@@ -21,6 +21,8 @@ QList Tally::compute(const QList &cards, const TallyType t
return SubtypeTally::countSubtypes(cards);
case TallyType::TotalPower:
return StatsTally::computeTotalPower(cards);
+ case TallyType::TotalToughness:
+ return StatsTally::computeTotalToughness(cards);
}
return {};
}
diff --git a/cockatrice/src/game_graphics/tally/tally.h b/cockatrice/src/game_graphics/tally/tally.h
index 97406cddb..84c54918f 100644
--- a/cockatrice/src/game_graphics/tally/tally.h
+++ b/cockatrice/src/game_graphics/tally/tally.h
@@ -21,7 +21,8 @@ enum class TallyType
None,
Subtypes,
TotalPower,
- MaxValue = TotalPower // sentinel value
+ TotalToughness,
+ MaxValue = TotalToughness // sentinel value
};
namespace Tally
diff --git a/cockatrice/src/game_graphics/zones/hand_zone.cpp b/cockatrice/src/game_graphics/zones/hand_zone.cpp
index b52a4955a..1a8f7a910 100644
--- a/cockatrice/src/game_graphics/zones/hand_zone.cpp
+++ b/cockatrice/src/game_graphics/zones/hand_zone.cpp
@@ -41,7 +41,8 @@ void HandZone::handleDropEvent(const QList &dragItems,
}
}
} else {
- x = calcDropIndexFromY(dropPoint.y());
+ bool sameZone = startZone == getLogic();
+ x = calcDropIndexFromY(dropPoint.y(), !sameZone);
}
Command_MoveCard cmd;
diff --git a/cockatrice/src/game_graphics/zones/select_zone.cpp b/cockatrice/src/game_graphics/zones/select_zone.cpp
index c58c41b92..470c70fcf 100644
--- a/cockatrice/src/game_graphics/zones/select_zone.cpp
+++ b/cockatrice/src/game_graphics/zones/select_zone.cpp
@@ -83,7 +83,7 @@ SelectZone::StackLayoutParams SelectZone::buildStackParams(qreal minOffset) cons
return {cardCount, boundingRect().height(), cardHeight, offset, minOffset};
}
-int SelectZone::calcDropIndexFromY(qreal dropY, qreal minOffset) const
+int SelectZone::calcDropIndexFromY(qreal dropY, bool allowCountExpand, qreal minOffset) const
{
const auto &cards = getLogic()->getCards();
if (cards.isEmpty()) {
@@ -94,7 +94,8 @@ int SelectZone::calcDropIndexFromY(qreal dropY, qreal minOffset) const
if (effectiveOffset <= 0.0) {
return 0;
}
- return qBound(0, qRound((dropY - start) / effectiveOffset), params.cardCount - 1);
+ int max = allowCountExpand ? params.cardCount : params.cardCount - 1;
+ return qBound(0, qRound((dropY - start) / effectiveOffset), max);
}
void SelectZone::restoreStaleEscapedCards()
diff --git a/cockatrice/src/game_graphics/zones/select_zone.h b/cockatrice/src/game_graphics/zones/select_zone.h
index 7408f29b6..b5d3ca37a 100644
--- a/cockatrice/src/game_graphics/zones/select_zone.h
+++ b/cockatrice/src/game_graphics/zones/select_zone.h
@@ -104,8 +104,12 @@ protected:
/**
* @brief Computes the card index at a given y-coordinate within the zone's vertical layout.
* Returns 0 if the zone has no cards or the offset is zero.
+ *
+ * @param dropY The y-coordinate that the card was dropped at
+ * @param allowCountExpand If false, clamps the index at the number of cards minus 1
+ * @param minOffset Minimum offset to preserve
*/
- int calcDropIndexFromY(qreal dropY, qreal minOffset = 0.0) const;
+ int calcDropIndexFromY(qreal dropY, bool allowCountExpand, qreal minOffset = 0.0) const;
/**
* @brief Positions cards vertically with alternating left/right x-offsets.
diff --git a/cockatrice/src/game_graphics/zones/stack_zone.cpp b/cockatrice/src/game_graphics/zones/stack_zone.cpp
index e9b14f13d..ff62097c7 100644
--- a/cockatrice/src/game_graphics/zones/stack_zone.cpp
+++ b/cockatrice/src/game_graphics/zones/stack_zone.cpp
@@ -57,18 +57,14 @@ void StackZone::handleDropEvent(const QList &dragItems,
return;
}
- const auto &cards = getLogic()->getCards();
- int index;
- if (startZone == getLogic()) {
- // Reordering within the zone: use drop position
- index = calcDropIndexFromY(dropPoint.y(), MIN_CARD_VISIBLE);
+ bool sameZone = startZone == getLogic();
+ int index = calcDropIndexFromY(dropPoint.y(), !sameZone, MIN_CARD_VISIBLE);
+ if (sameZone) {
// Same-zone no-op: don't move a card onto itself
+ const auto &cards = getLogic()->getCards();
if (!cards.isEmpty() && cards.at(index)->getId() == dragItems.at(0)->getId()) {
return;
}
- } else {
- // Coming from another zone: append at end (top of stack, rendered on top)
- index = static_cast(cards.size());
}
Command_MoveCard cmd;
diff --git a/cockatrice/src/game_graphics/zones/view_zone.cpp b/cockatrice/src/game_graphics/zones/view_zone.cpp
index baf7b8b30..5bd5d262f 100644
--- a/cockatrice/src/game_graphics/zones/view_zone.cpp
+++ b/cockatrice/src/game_graphics/zones/view_zone.cpp
@@ -1,5 +1,6 @@
#include "view_zone.h"
+#include "../../client/settings/cache_settings.h"
#include "../../game/player/player_actions.h"
#include "../../game/player/player_logic.h"
#include "../../game/zones/view_zone_logic.h"
@@ -11,11 +12,13 @@
#include
#include
#include
+#include
#include
#include
#include
#include
#include
+#include
/**
* @param parent the parent QGraphicsWidget containing the reveal zone
@@ -253,7 +256,10 @@ ZoneViewZone::GridSize ZoneViewZone::positionCardsForDisplay(CardList &cards, Ca
void ZoneViewZone::setFilterString(const QString &_filterString)
{
- filterString = FilterString(_filterString);
+ const CardsDisplaySettings &cardsDisplay = SettingsCache::instance().cardsDisplay();
+ filterString = FilterString(
+ _filterString, CardSearchLanguage{cardsDisplay.getCardLang(),
+ static_cast(cardsDisplay.getCardSearchLanguage())});
reorganizeCards();
}
diff --git a/cockatrice/src/game_graphics/zones/view_zone_widget.cpp b/cockatrice/src/game_graphics/zones/view_zone_widget.cpp
index 17118e80d..fa6733413 100644
--- a/cockatrice/src/game_graphics/zones/view_zone_widget.cpp
+++ b/cockatrice/src/game_graphics/zones/view_zone_widget.cpp
@@ -21,6 +21,7 @@
#include
#include
#include
+#include
#include
namespace
@@ -62,7 +63,7 @@ ZoneViewWidget::ZoneViewWidget(PlayerLogic *_player,
searchEdit.setPlaceholderText(tr("Search by card name (or search expressions)"));
searchEdit.setClearButtonEnabled(true);
searchEdit.addAction(loadColorAdjustedPixmap("theme:icons/search"), QLineEdit::LeadingPosition);
- auto help = searchEdit.addAction(QPixmap("theme:icons/info"), QLineEdit::TrailingPosition);
+ auto help = searchEdit.addAction(themePixmap(QStringLiteral("icons/info")), QLineEdit::TrailingPosition);
connect(help, &QAction::triggered, this, [this] { createSearchSyntaxHelpWindow(&searchEdit); });
@@ -168,6 +169,12 @@ ZoneViewWidget::ZoneViewWidget(PlayerLogic *_player,
}
connect(&searchEdit, &QLineEdit::textChanged, zone, &ZoneViewZone::setFilterString);
+
+ const auto applyCardSearchLanguage = [this] { zone->setFilterString(searchEdit.text()); };
+ connect(&SettingsCache::instance().cardsDisplay(), &CardsDisplaySettings::cardLangChanged, this,
+ applyCardSearchLanguage);
+ connect(&SettingsCache::instance().cardsDisplay(), &CardsDisplaySettings::cardSearchLanguageChanged, this,
+ applyCardSearchLanguage);
}
setLayout(vbox);
@@ -549,7 +556,7 @@ void ZoneViewWidget::initStyleOption(QStyleOption *option) const
{
QStyleOptionTitleBar *titleBar = qstyleoption_cast(option);
if (titleBar) {
- titleBar->icon = QPixmap("theme:cockatrice");
+ titleBar->icon = themePixmap(QStringLiteral("cockatrice"));
}
}
diff --git a/cockatrice/src/interface/card_localization.h b/cockatrice/src/interface/card_localization.h
new file mode 100644
index 000000000..0bfe4a764
--- /dev/null
+++ b/cockatrice/src/interface/card_localization.h
@@ -0,0 +1,59 @@
+#ifndef COCKATRICE_CARD_LOCALIZATION_H
+#define COCKATRICE_CARD_LOCALIZATION_H
+
+#include "../client/settings/cache_settings.h"
+
+#include
+#include
+#include
+
+namespace CardLocalization
+{
+/**
+ * @brief The language code selected for localized card text and images.
+ */
+inline QString displayLang()
+{
+ return SettingsCache::instance().cardsDisplay().getCardLang();
+}
+
+/**
+ * @brief Card name in the configured display language, falling back to English.
+ * @param card The card to display.
+ * @return The localized name, or an empty string for a null card.
+ */
+inline QString displayName(const CardInfoPtr &card)
+{
+ return card.isNull() ? QString() : card->getLocalizedName(displayLang());
+}
+
+/**
+ * @brief Card rules text in the configured display language, falling back to English.
+ * @param card The card to display.
+ * @return The localized text, or an empty string for a null card.
+ */
+inline QString displayText(const CardInfoPtr &card)
+{
+ return card.isNull() ? QString() : card->getLocalizedText(displayLang());
+}
+
+/**
+ * @brief Card name in the configured display language, falling back to English.
+ * @param card The card to display.
+ */
+inline QString displayName(const CardInfo &card)
+{
+ return card.getLocalizedName(displayLang());
+}
+
+/**
+ * @brief Card rules text in the configured display language, falling back to English.
+ * @param card The card to display.
+ */
+inline QString displayText(const CardInfo &card)
+{
+ return card.getLocalizedText(displayLang());
+}
+} // namespace CardLocalization
+
+#endif // COCKATRICE_CARD_LOCALIZATION_H
\ No newline at end of file
diff --git a/cockatrice/src/interface/card_picture_loader/card_picture_loader.cpp b/cockatrice/src/interface/card_picture_loader/card_picture_loader.cpp
index 2f46e7941..8e34942e1 100644
--- a/cockatrice/src/interface/card_picture_loader/card_picture_loader.cpp
+++ b/cockatrice/src/interface/card_picture_loader/card_picture_loader.cpp
@@ -1,15 +1,17 @@
#include "card_picture_loader.h"
#include "../../client/settings/cache_settings.h"
+#include "../pixel_map_generator.h"
#include "card_picture_loader_cache_method.h"
#include "card_picture_loader_local_schemes.h"
#include
#include
#include
-#include
+#include
#include
#include
+#include
#include
#include
#include
@@ -19,6 +21,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -36,9 +39,12 @@ CardPictureLoader::CardPictureLoader() : QObject(nullptr)
&CardPictureLoader::picsPathChanged);
connect(&SettingsCache::instance().downloads(), &DownloadSettings::picDownloadChanged, this,
&CardPictureLoader::picDownloadChanged);
+ connect(&SettingsCache::instance().cardsDisplay(), &CardsDisplaySettings::cardLangChanged, this,
+ &CardPictureLoader::cardLangChanged);
- qRegisterMetaType();
+ qRegisterMetaType("ExactCard");
connect(worker, &CardPictureLoaderWorker::imageLoaded, this, &CardPictureLoader::imageLoaded);
+ connect(worker, &CardPictureLoaderWorker::networkCacheCleared, this, &CardPictureLoader::networkCacheCleared);
statusBar = new CardPictureLoaderStatusBar(nullptr);
QMainWindow *mainWindow = qobject_cast(QApplication::activeWindow());
@@ -54,7 +60,18 @@ CardPictureLoader::CardPictureLoader() : QObject(nullptr)
CardPictureLoader::~CardPictureLoader()
{
- worker->deleteLater();
+ if (worker) {
+ // Capture the thread first: shutdownThread() blocks until the worker has been freed by the
+ // finished() -> deleteLater chain, after which the worker pointer must not be dereferenced.
+ QThread *pictureLoaderThread = worker->workerThread();
+ const bool stopped = worker->shutdownThread();
+ worker = nullptr;
+ // Deleting a QThread that is still running is undefined behaviour, so only free it once the
+ // bounded wait in shutdownThread() confirmed that it stopped.
+ if (stopped) {
+ delete pictureLoaderThread;
+ }
+ }
}
void CardPictureLoader::getCardBackPixmap(QPixmap &pixmap, QSize size)
@@ -62,7 +79,7 @@ void CardPictureLoader::getCardBackPixmap(QPixmap &pixmap, QSize size)
QString backCacheKey = "_trice_card_back_" + QString::number(size.width()) + "x" + QString::number(size.height());
if (!QPixmapCache::find(backCacheKey, &pixmap)) {
qCDebug(CardPictureLoaderLog) << "PictureLoader: cache miss for" << backCacheKey;
- QPixmap tmpPixmap("theme:cardback");
+ QPixmap tmpPixmap = themePixmap(QStringLiteral("cardback"));
if (tmpPixmap.isNull()) {
qCWarning(CardPictureLoaderLog) << "Failed to load 'theme:cardback'! Using fallback pixmap.";
@@ -83,7 +100,7 @@ void CardPictureLoader::getCardBackLoadingInProgressPixmap(QPixmap &pixmap, QSiz
"_trice_card_back_inprogress_" + QString::number(size.width()) + "x" + QString::number(size.height());
if (!QPixmapCache::find(backCacheKey, &pixmap)) {
qCDebug(CardPictureLoaderCardBackCacheFailLog) << "PictureLoader: cache miss for" << backCacheKey;
- QPixmap tmpPixmap("theme:cardback");
+ QPixmap tmpPixmap = themePixmap(QStringLiteral("cardback"));
if (tmpPixmap.isNull()) {
qCWarning(CardPictureLoaderLog) << "Failed to load 'theme:cardback' for in-progress state! Using fallback.";
@@ -105,7 +122,7 @@ void CardPictureLoader::getCardBackLoadingFailedPixmap(QPixmap &pixmap, QSize si
"_trice_card_back_failed_" + QString::number(size.width()) + "x" + QString::number(size.height());
if (!QPixmapCache::find(backCacheKey, &pixmap)) {
qCDebug(CardPictureLoaderCardBackCacheFailLog) << "PictureLoader: cache miss for" << backCacheKey;
- QPixmap tmpPixmap("theme:cardback");
+ QPixmap tmpPixmap = themePixmap(QStringLiteral("cardback"));
if (tmpPixmap.isNull()) {
qCWarning(CardPictureLoaderLog) << "Failed to load 'theme:cardback' for failed state! Using fallback.";
@@ -138,7 +155,8 @@ void CardPictureLoader::getPixmap(QPixmap &pixmap, const ExactCard &card, QSize
QPixmap bigPixmap;
if (QPixmapCache::find(key, &bigPixmap)) {
if (bigPixmap.isNull()) {
- getCardBackLoadingFailedPixmap(pixmap, size);
+ // Leave the pixmap null so callers fall back to a solid color
+ // instead of showing the card back.
QDateTime failedAtTime = getInstance().failedAt.value(key);
if (!failedAtTime.isValid() ||
failedAtTime.addSecs(RETRY_FAILED_CARDS_SECS) < QDateTime::currentDateTime()) {
@@ -204,7 +222,49 @@ void CardPictureLoader::imageLoaded(const ExactCard &card, const QImage &image)
card.emitPixmapUpdated();
}
-void CardPictureLoader::saveCardImageToLocalStorage(const ExactCard &card, const QPixmap &pixmap)
+void CardPictureLoader::deleteAllLocalOverrides(const ExactCard &card)
+{
+ const QString picsRoot = SettingsCache::instance().paths().getPicsPath();
+ if (picsRoot.isEmpty() || !card) {
+ return;
+ }
+
+ QDir baseDir(picsRoot);
+ if (!baseDir.cd("downloadedPics")) {
+ return;
+ }
+
+ const QString name = card.getInfo().getCorrectedName();
+
+ QString set, collector, uuid;
+ auto printing = card.getPrinting();
+ if (printing.getSet()) {
+ set = printing.getSet()->getCorrectedShortName();
+ collector = printing.getProperty("num");
+ uuid = printing.getUuid();
+ }
+
+ for (const auto &scheme : CardPictureLoaderLocalSchemes::exportSchemes()) {
+ QString rel = CardPictureLoaderLocalSchemes::expandPattern(scheme.pattern, name, set, collector, uuid);
+
+ if (rel.isEmpty()) {
+ continue;
+ }
+
+ rel += ".png";
+ rel = QDir::cleanPath(rel);
+
+ QString fullPath = baseDir.filePath(rel);
+
+ if (QFile::exists(fullPath)) {
+ QFile::remove(fullPath);
+ }
+ }
+}
+
+void CardPictureLoader::saveCardImageToLocalStorage(const ExactCard &card,
+ const QPixmap &pixmap,
+ const bool allowOverwrite)
{
if (pixmap.isNull() || !card) {
return;
@@ -264,8 +324,9 @@ void CardPictureLoader::saveCardImageToLocalStorage(const ExactCard &card, const
QFileInfo outInfo(baseDir.filePath(relativePath));
- // Do not overwrite existing files
- if (outInfo.exists()) {
+ // Automatic cache writes (FILESYSTEM_CACHE) must never clobber an explicit user override.
+ // Only the explicit override paths pass allowOverwrite == true.
+ if (!allowOverwrite && outInfo.exists()) {
return;
}
@@ -286,6 +347,122 @@ void CardPictureLoader::saveCardImageToLocalStorage(const ExactCard &card, const
}
}
+void CardPictureLoader::installPrintingOverrideOnLoad(const ExactCard &originalCard, const ExactCard &overrideCard)
+{
+ // Overriding a card with itself is the reset case, not a real override: every code path below
+ // would re-enter itself through emitPixmapUpdated(). Reject it outright.
+ if (originalCard == overrideCard) {
+ return;
+ }
+
+ CardInfoPtr cardPtr = overrideCard.getCardPtr();
+ if (!cardPtr) {
+ return;
+ }
+
+ // Heap-allocate so the lambda can capture it before the connection is made
+ auto *connectionHandle = new QMetaObject::Connection;
+
+ *connectionHandle =
+ connect(cardPtr.data(), &CardInfo::pixmapUpdated, cardPtr.data(),
+ [originalCard, overrideCard, connectionHandle, this](const PrintingInfo &printing) {
+ // All printings share the same CardInfo, so ignore updates triggered by any
+ // other printing (e.g., the original card re-loading from disk).
+ if (printing != overrideCard.getPrinting()) {
+ return;
+ }
+
+ QPixmap pixmap;
+ if (QPixmapCache::find(overrideCard.getPixmapCacheKey(), &pixmap) && !pixmap.isNull()) {
+ // The override art has resolved — persist it and reflect it immediately.
+ // Retire the connection before emitting so the refresh can't re-enter.
+ saveCardImageToLocalStorage(originalCard, pixmap, /*allowOverwrite=*/true);
+
+ QObject::disconnect(*connectionHandle);
+ delete connectionHandle;
+
+ QPixmapCache::clear();
+ originalCard.emitPixmapUpdated();
+ return;
+ }
+
+ // The art could not be resolved. Keep the connection armed so a late resolution
+ // still lands, and surface a visible refusal instead of a silent no-op. An
+ // override already on disk is left untouched and simply re-displayed.
+ QPixmapCache::clear();
+ if (!hasLocalOverrides(originalCard)) {
+ QPixmap refusedPixmap;
+ getCardBackLoadingFailedPixmap(refusedPixmap, QSize(480, 672));
+ QPixmapCache::insert(originalCard.getPixmapCacheKey(), refusedPixmap);
+ }
+ originalCard.emitPixmapUpdated();
+ });
+
+ // Now enqueue; if the image is already loading (deduplicated in the worker),
+ // the signal will still fire when it completes
+ CardPictureLoader::getInstance().worker->enqueueImageLoad(overrideCard);
+}
+
+void CardPictureLoader::installPrintingOverride(const ExactCard &originalCard, const ExactCard &overrideCard)
+{
+ // Same guard as installPrintingOverrideOnLoad: self-override is the reset case.
+ if (originalCard == overrideCard) {
+ return;
+ }
+
+ QPixmap pixmap;
+ const QString key = overrideCard.getPixmapCacheKey();
+
+ if (QPixmapCache::find(key, &pixmap) && !pixmap.isNull()) {
+ // Already cached — save immediately; the caller refreshes the card.
+ saveCardImageToLocalStorage(originalCard, pixmap, /*allowOverwrite=*/true);
+ return;
+ }
+
+ // Cache miss or previously failed load — enqueue load and wait for the signal.
+ installPrintingOverrideOnLoad(originalCard, overrideCard);
+}
+
+bool CardPictureLoader::hasLocalOverrides(const ExactCard &card)
+{
+ const QString picsRoot = SettingsCache::instance().paths().getPicsPath();
+ if (picsRoot.isEmpty() || !card) {
+ return false;
+ }
+
+ QDir baseDir(picsRoot);
+ if (!baseDir.cd("downloadedPics")) {
+ return false;
+ }
+
+ const QString name = card.getInfo().getCorrectedName();
+
+ QString set, collector, uuid;
+ const PrintingInfo printing = card.getPrinting();
+ if (printing.getSet()) {
+ set = printing.getSet()->getCorrectedShortName();
+ collector = printing.getProperty("num");
+ uuid = printing.getUuid();
+ }
+
+ for (const auto &scheme : CardPictureLoaderLocalSchemes::exportSchemes()) {
+ QString rel = CardPictureLoaderLocalSchemes::expandPattern(scheme.pattern, name, set, collector, uuid);
+
+ if (rel.isEmpty()) {
+ continue;
+ }
+
+ rel += ".png";
+ rel = QDir::cleanPath(rel);
+
+ if (QFile::exists(baseDir.filePath(rel))) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
void CardPictureLoader::clearPixmapCache()
{
QPixmapCache::clear();
@@ -293,7 +470,17 @@ void CardPictureLoader::clearPixmapCache()
void CardPictureLoader::clearNetworkCache()
{
- getInstance().worker->clearNetworkCache();
+ // During teardown the worker is released before this singleton, so a queued clear may still
+ // arrive with no worker left to run it.
+ CardPictureLoaderWorker *worker = getInstance().worker;
+ if (!worker) {
+ return;
+ }
+ // The disk cache and redirect cache are owned by the worker thread, so the clear has to run
+ // there. Invoke it asynchronously to keep the GUI responsive while the worker may be walking
+ // the user's picture directories or recursively deleting the cache directory; callers that
+ // need to know when it is done can listen for networkCacheCleared().
+ QMetaObject::invokeMethod(worker, &CardPictureLoaderWorker::clearNetworkCache, Qt::QueuedConnection);
}
void CardPictureLoader::cacheCardPixmaps(const QList &cards)
@@ -325,31 +512,11 @@ void CardPictureLoader::picsPathChanged()
QPixmapCache::clear();
}
-bool CardPictureLoader::hasCustomArt()
+void CardPictureLoader::cardLangChanged()
{
- auto picsPath = SettingsCache::instance().paths().getPicsPath();
- QDirIterator it(picsPath, QDir::Dirs | QDir::NoDotAndDotDot);
-
- // Check if there is at least one non-directory file in the pics path, other
- // than in the "downloadedPics" subdirectory.
- while (it.hasNext()) {
-#if (QT_VERSION >= QT_VERSION_CHECK(6, 3, 0))
- QFileInfo dir(it.nextFileInfo());
-#else
- // nextFileInfo() is only available in Qt 6.3+, for previous versions, we build
- // the QFileInfo from a QString which requires more system calls.
- QFileInfo dir(it.next());
-#endif
-
- if (it.fileName() == "downloadedPics") {
- continue;
- }
-
- QDirIterator subIt(it.filePath(), QDir::Files, QDirIterator::Subdirectories | QDirIterator::FollowSymlinks);
- if (subIt.hasNext()) {
- return true;
- }
- }
-
- return false;
+ // Localized images are fetched via a different URL, but the in-memory
+ // pixmap cache is keyed by card name/uuid, so drop everything cached
+ // (including failure timestamps) to force a reload in the new language.
+ QPixmapCache::clear();
+ failedAt.clear();
}
diff --git a/cockatrice/src/interface/card_picture_loader/card_picture_loader.h b/cockatrice/src/interface/card_picture_loader/card_picture_loader.h
index 5c3ac84a3..6224befbf 100644
--- a/cockatrice/src/interface/card_picture_loader/card_picture_loader.h
+++ b/cockatrice/src/interface/card_picture_loader/card_picture_loader.h
@@ -97,10 +97,17 @@ public:
static void cacheCardPixmaps(const QList &cards);
/**
- * @brief Check if the user has custom card art in the picsPath directory.
- * @return True if any custom art exists.
+ * @brief Check if a local override image already exists for the card.
+ * @param card The card to check.
+ * @return True if the card has at least one locally stored override image.
*/
- static bool hasCustomArt();
+ static bool hasLocalOverrides(const ExactCard &card);
+
+ /**
+ * @brief Removes all locally stored override images for the card.
+ * @param card The card to remove the override images of.
+ */
+ static void deleteAllLocalOverrides(const ExactCard &card);
/**
* @brief Clears the in-memory QPixmap cache for all cards.
@@ -110,6 +117,9 @@ public:
public slots:
/**
* @brief Clears the network disk cache of the worker.
+ *
+ * The clear runs on the worker thread, so this returns before it has completed; connect to
+ * networkCacheCleared() to act once it is done.
*/
static void clearNetworkCache();
@@ -120,7 +130,13 @@ public slots:
* @param image Loaded QImage.
*/
void imageLoaded(const ExactCard &card, const QImage &image);
- void saveCardImageToLocalStorage(const ExactCard &card, const QPixmap &pixmap);
+ void saveCardImageToLocalStorage(const ExactCard &card, const QPixmap &pixmap, bool allowOverwrite = false);
+ void installPrintingOverride(const ExactCard &originalCard, const ExactCard &overrideCard);
+ void installPrintingOverrideOnLoad(const ExactCard &originalCard, const ExactCard &overrideCard);
+
+signals:
+ /** @brief Emitted after the worker has finished clearing the network and redirect caches. */
+ void networkCacheCleared();
private slots:
/**
@@ -134,6 +150,12 @@ private slots:
* Clears the QPixmap cache to reload images.
*/
void picsPathChanged();
+
+ /**
+ * @brief Triggered when the card language setting changes.
+ * Clears the in-memory picture caches so images reload in the new language.
+ */
+ void cardLangChanged();
};
#endif
diff --git a/cockatrice/src/interface/card_picture_loader/card_picture_loader_local.cpp b/cockatrice/src/interface/card_picture_loader/card_picture_loader_local.cpp
index 39621839a..12165e8f3 100644
--- a/cockatrice/src/interface/card_picture_loader/card_picture_loader_local.cpp
+++ b/cockatrice/src/interface/card_picture_loader/card_picture_loader_local.cpp
@@ -94,10 +94,14 @@ QImage CardPictureLoaderLocal::tryLoadCardImageFromDisk(const QString &setName,
candidatePaths << picsPath + "/downloadedPics/" + setName + "/" + nameVariant;
}
+ // Non-set-folder export schemes (e.g., Name_Set_Collector) write straight into
+ // downloadedPics/; check there as a fallback so local overrides round-trip.
+ candidatePaths << picsPath + "/downloadedPics/" + nameVariant;
+
for (const QString &path : candidatePaths) {
QFileInfo fileInfo(path);
QDir dir = fileInfo.dir();
- QString baseName = fileInfo.fileName();
+ QString baseName = fileInfo.completeBaseName();
if (!dir.exists()) {
continue;
@@ -105,7 +109,8 @@ QImage CardPictureLoaderLocal::tryLoadCardImageFromDisk(const QString &setName,
QStringList files = dir.entryList(QDir::Files);
for (const QString &file : files) {
- if (!file.startsWith(baseName)) {
+ QFileInfo fi(file);
+ if (fi.completeBaseName() != baseName) {
continue;
}
diff --git a/cockatrice/src/interface/card_picture_loader/card_picture_loader_worker.cpp b/cockatrice/src/interface/card_picture_loader/card_picture_loader_worker.cpp
index d288236d2..0fd6a42d5 100644
--- a/cockatrice/src/interface/card_picture_loader/card_picture_loader_worker.cpp
+++ b/cockatrice/src/interface/card_picture_loader/card_picture_loader_worker.cpp
@@ -16,13 +16,16 @@
#include
#include
-static constexpr int MAX_REQUESTS_PER_SEC = 10;
-static constexpr int MIN_HOST_QUOTA = 1; ///< Floor for the per-host request allowance
-static constexpr qint64 QUOTA_RECOVER_MS = 60000; ///< Idle time before a reduced quota starts recovering
+static constexpr int MAX_REQUESTS_PER_SEC = DownloadSettings::DEFAULT_HOST_REQUEST_LIMIT;
+static constexpr int MIN_HOST_QUOTA = DownloadSettings::MIN_HOST_REQUEST_LIMIT;
+static constexpr qint64 QUOTA_RECOVER_MS = 60000; ///< Idle time before a reduced quota starts recovering
+static constexpr int DISPATCH_INTERVAL_MS = 100; ///< Pacing between individual network requests
+static constexpr qint64 QUOTA_RESET_INTERVAL_MS = 1000; ///< Interval at which the request quota resets
+static constexpr int THREAD_SHUTDOWN_WAIT_MS = 5000; ///< Bounded wait for the worker thread to stop at exit
CardPictureLoaderWorker::CardPictureLoaderWorker()
: QObject(nullptr), picDownload(SettingsCache::instance().downloads().getPicDownload()),
- requestQuota(MAX_REQUESTS_PER_SEC)
+ hostRequestLimits(SettingsCache::instance().downloads().getHostRequestLimits())
{
networkManager = new QNetworkAccessManager(this);
// We need a timeout to ensure requests don't hang indefinitely in case of
@@ -57,20 +60,59 @@ CardPictureLoaderWorker::CardPictureLoaderWorker()
localLoader = new CardPictureLoaderLocal(this);
pictureLoaderThread = new QThread;
+ // The worker object frees itself once its thread finishes, so no event loop is left
+ // running and the QThread is never destroyed while still executing.
+ connect(pictureLoaderThread, &QThread::finished, this, &QObject::deleteLater);
pictureLoaderThread->start(QThread::LowPriority);
moveToThread(pictureLoaderThread);
+ // QTimer value members are not QObject children, so moveToThread on the worker doesn't move
+ // them. They must live in the worker's thread to be started from the slot code that runs there.
+ requestTimer.moveToThread(pictureLoaderThread);
+ dispatchTimer.moveToThread(pictureLoaderThread);
+
connect(this, &CardPictureLoaderWorker::imageLoadEnqueued, this, &CardPictureLoaderWorker::handleImageLoadEnqueued);
connect(&requestTimer, &QTimer::timeout, this, &CardPictureLoaderWorker::resetRequestQuota);
- requestTimer.setInterval(1000);
- requestTimer.start();
+ requestTimer.setInterval(static_cast(QUOTA_RESET_INTERVAL_MS));
+
+ connect(&dispatchTimer, &QTimer::timeout, this, &CardPictureLoaderWorker::dispatchQueuedRequest);
+ dispatchTimer.setInterval(DISPATCH_INTERVAL_MS);
+
+ connect(&SettingsCache::instance().downloads(), &DownloadSettings::hostRequestLimitsChanged, this,
+ [this] { hostRequestLimits = SettingsCache::instance().downloads().getHostRequestLimits(); });
}
CardPictureLoaderWorker::~CardPictureLoaderWorker()
{
saveRedirectCache();
- pictureLoaderThread->deleteLater();
+}
+
+bool CardPictureLoaderWorker::shutdownThread()
+{
+ // The finished() -> deleteLater chain (wired in the constructor) frees this worker as soon as
+ // its event loop exits, so nothing - not even a member read - may run once wait() returns.
+ // QThread::quit() and QThread::wait() are thread-safe and may be called from the owning thread.
+ QThread *thread = pictureLoaderThread;
+ if (!thread) {
+ return true;
+ }
+ thread->quit();
+ // Only an unbounded wait() would guarantee the thread stops, but this runs from a function-local
+ // static destructor after main() has returned, with no UI left to interrupt a worker stuck in a
+ // slow slot or on a stalled filesystem. Bound the wait and leave such a thread to the OS rather
+ // than hanging the process forever.
+ if (!thread->wait(THREAD_SHUTDOWN_WAIT_MS)) {
+ qCWarning(CardPictureLoaderWorkerLog) << "Picture loader worker thread did not stop within"
+ << THREAD_SHUTDOWN_WAIT_MS << "ms; leaving it to be torn down by the OS";
+ return false;
+ }
+ return true;
+}
+
+QThread *CardPictureLoaderWorker::workerThread() const
+{
+ return pictureLoaderThread;
}
void CardPictureLoaderWorker::queueRequest(const QUrl &url, CardPictureLoaderWorkerWork *worker)
@@ -84,8 +126,8 @@ void CardPictureLoaderWorker::queueRequest(const QUrl &url, CardPictureLoaderWor
SettingsCache::instance().cacheStorage().getCardPictureLoaderCacheMethod()) ==
CardPictureLoaderCacheMethod::CacheMethod::NETWORK_CACHE &&
cache->metaData(url).isValid()) {
- // If we hit a cached url, we get to make the request for free, since it won't contribute towards the
- // rate-limit
+ // A request that will be served from the disk cache never touches the network and therefore
+ // doesn't use up any of the rate limit, so it gets to skip the queue.
makeRequest(url, worker);
return;
}
@@ -99,7 +141,17 @@ QNetworkReply *CardPictureLoaderWorker::makeRequest(const QUrl &url, CardPicture
// Check for cached redirects
QUrl cachedRedirect = getCachedRedirect(url);
if (!cachedRedirect.isEmpty()) {
+ // The status bar still needs to reclaim this URL's widget even when we hand the request back
+ // for a deferred retry instead of dispatching it onto the network.
emit imageRequestSucceeded(url);
+ // The redirect target is a different host, which may itself be in 429 backoff; hand the
+ // entry back to its worker so it waits the backoff out instead of dispatching straight
+ // onto the backed-off host.
+ if (CardPictureLoaderWorkerWork::rateLimiter().isRateLimited(cachedRedirect.host(),
+ QDateTime::currentDateTime())) {
+ worker->scheduleDeferredRetry(cachedRedirect.host());
+ return nullptr;
+ }
return makeRequest(cachedRedirect, worker);
}
@@ -107,67 +159,261 @@ QNetworkReply *CardPictureLoaderWorker::makeRequest(const QUrl &url, CardPicture
req.setHeader(QNetworkRequest::UserAgentHeader, QString("Cockatrice %1").arg(VERSION_STRING));
req.setRawHeader("Accept", "image/avif,image/webp,image/apng,image/,/*;q=0.8");
- bool useNetworkCache =
- !picDownload && static_cast(
- SettingsCache::instance().cacheStorage().getCardPictureLoaderCacheMethod()) ==
- CardPictureLoaderCacheMethod::CacheMethod::NETWORK_CACHE;
+ // Cached entries are served straight from the disk cache even when picture downloads are
+ // enabled: re-fetching an already-cached image would burn the rate limit for nothing. Only a
+ // genuine cache miss goes to the network, and only when downloads are enabled.
+ bool useNetworkCache = !requestTouchesNetwork(url);
req.setAttribute(QNetworkRequest::CacheLoadControlAttribute,
useNetworkCache ? QNetworkRequest::AlwaysCache : QNetworkRequest::AlwaysNetwork);
QNetworkReply *reply = networkManager->get(req);
- // Connect reply handling
- connect(reply, &QNetworkReply::finished, worker, [reply, worker] { worker->handleNetworkReply(reply); });
+ // Track in-flight replies per host so the unlocked fast path can bound how many requests it
+ // issues at once, instead of creating replies that time out before Qt opens a connection.
+ const QString host = url.host();
+ hostInFlight.insert(host, hostInFlight.value(host) + 1);
+
+ // Release the in-flight slot when the reply is destroyed, not when it emits `finished`, and use
+ // the worker (not the work object) as the context object: a reply can go away without ever
+ // finishing (aborted, or a work object deleted while a reply is still pending), and a connection
+ // bound to that work object's lifetime would then never run, permanently shrinking the fast
+ // path's concurrency until it wedges. This way the slot is released exactly once.
+ connect(reply, &QObject::destroyed, this,
+ [this, host] { hostInFlight.insert(host, qMax(0, hostInFlight.value(host) - 1)); });
+
+ // Connect reply handling; the work object is the context so its handler dies with it.
+ connect(reply, &QNetworkReply::finished, worker, [worker, reply] { worker->handleNetworkReply(reply); });
return reply;
}
void CardPictureLoaderWorker::resetRequestQuota()
{
- requestQuota = MAX_REQUESTS_PER_SEC;
-
QDateTime now = QDateTime::currentDateTime();
- for (auto it = hostRequestQuota.begin(); it != hostRequestQuota.end(); ++it) {
+ for (auto it = hostRequestQuota.begin(); it != hostRequestQuota.end();) {
if (!hostLast429.contains(it.key()) || now.msecsTo(hostLast429.value(it.key())) < -QUOTA_RECOVER_MS) {
- it.value() = qMin(MAX_REQUESTS_PER_SEC, it.value() + 1);
+ if (hostAllowanceCeiling(it.key()) == DownloadSettings::UNLIMITED_HOST_QUOTA) {
+ // A developer-unlocked host that fell back after a 429 recovers towards the default
+ // allowance; once it gets there it becomes unlocked (fast-path) again.
+ if (it.value() + 1 >= DownloadSettings::DEFAULT_HOST_REQUEST_LIMIT) {
+ it = hostRequestQuota.erase(it);
+ continue;
+ }
+ it.value() += 1;
+ } else {
+ // Recover towards the host's effective allowance ceiling, which may be
+ // lowered by the user's per-host request limits.
+ it.value() = qMin(hostAllowanceCeiling(it.key()), it.value() + 1);
+ }
}
+ ++it;
}
- for (const auto &request : requestLoadQueue) {
- const QString host = request.first.host();
- hostQuotaRemaining.insert(host, hostRequestQuota.value(host, MAX_REQUESTS_PER_SEC));
- }
+ // Forget the per-second allowances; each host's allowance is re-seeded lazily from its
+ // reduced sustained quota the first time it is dispatched in the new second, so a host that
+ // enters the queue mid-second no longer falls through to a fresh full quota.
+ hostQuotaRemaining.clear();
- processQueuedRequests();
+ updateTimerState();
}
void CardPictureLoaderWorker::processQueuedRequests()
{
- while (requestQuota > 0 && processSingleRequest()) {
- --requestQuota;
+ // QTimer must be started from the thread it lives in; if this public slot is ever reached from
+ // another thread, replay it on the worker's event loop instead of letting start() fail silently.
+ if (thread() != QThread::currentThread()) {
+ QMetaObject::invokeMethod(this, &CardPictureLoaderWorker::processQueuedRequests, Qt::QueuedConnection);
+ return;
+ }
+ updateTimerState();
+}
+
+void CardPictureLoaderWorker::dispatchQueuedRequest()
+{
+ if (requestLoadQueue.isEmpty()) {
+ // All queued requests have been dispatched; stop the pacing timers.
+ updateTimerState();
+ return;
+ }
+
+ QDateTime now = QDateTime::currentDateTime();
+ bool dispatched = false;
+ // Set while an unlocked host still has queued work blocked only by the in-flight cap; the
+ // timer must keep running so it gets another try as soon as a slot frees. A host blocked by
+ // its 429 backoff instead waits for the next quota-reset tick to restart the dispatcher.
+ bool unlockedCapped = false;
+
+ // Unlocked hosts (developer cap UNLIMITED_HOST_QUOTA) skip the pacing and the per-host
+ // allowance: dispatch their queued requests back-to-back, bounded by their 429 backoff and the
+ // per-host in-flight cap so a large burst can't queue replies that time out before Qt opens a
+ // connection for them.
+ for (int i = 0; i < requestLoadQueue.size();) {
+ const auto &request = requestLoadQueue.at(i);
+ // Dispatch decisions must key on the host the request will actually go to, not the URL that
+ // merely redirects to it: a redirect learned after this URL was queued would otherwise
+ // bypass the in-flight cap and drain the whole queue onto the target host unchecked.
+ const QUrl resolvedUrl = resolveCachedRedirect(request.first);
+ const QString host = resolvedUrl.host();
+ if (isUnlockedHost(host)) {
+ if (CardPictureLoaderWorkerWork::rateLimiter().isRateLimited(host, now)) {
+ ++i;
+ continue;
+ }
+ if (hostInFlight.value(host) < MAX_IN_FLIGHT_PER_HOST) {
+ makeRequest(resolvedUrl, request.second);
+ requestLoadQueue.removeAt(i);
+ dispatched = true;
+ continue;
+ }
+ unlockedCapped = true;
+ }
+ ++i;
+ }
+
+ if (requestLoadQueue.isEmpty()) {
+ dispatchTimer.stop();
+ requestTimer.stop();
+ return;
+ }
+
+ if (processSingleRequest()) {
+ dispatched = true;
+ }
+
+ // Keep the timer running while there is progress to make or unlocked work waiting on a free
+ // in-flight slot; otherwise no host has allowance left this second, so wait for the quota reset.
+ if (!dispatched && !unlockedCapped) {
+ dispatchTimer.stop();
+ }
+}
+
+void CardPictureLoaderWorker::updateTimerState()
+{
+ // Never restart an active timer: that would reset the pacing countdown and a burst of enqueues
+ // could keep starving the dispatcher, so only (re)start a timer that has actually stopped.
+ if (requestLoadQueue.isEmpty()) {
+ dispatchTimer.stop();
+ // Forget per-second allowances once nothing is pending: a stale zero would otherwise delay
+ // the next single request by a full quota-reset interval.
+ hostQuotaRemaining.clear();
+ } else if (!dispatchTimer.isActive()) {
+ dispatchTimer.start();
+ }
+
+ // The quota timer resets allowances every second and is also the only thing that heals a host
+ // after a 429 (see resetRequestQuota). It must keep ticking while work is queued or a host is
+ // still recovering below the ceiling, and only winds down once no host needs recovery anymore.
+ // Keeping it alive during such idle periods lets reduced quotas recover as intended.
+ bool hostRecovering = false;
+ for (auto it = hostRequestQuota.cbegin(); it != hostRequestQuota.cend(); ++it) {
+ if (it.value() < MAX_REQUESTS_PER_SEC) {
+ hostRecovering = true;
+ break;
+ }
+ }
+
+ if (!requestLoadQueue.isEmpty() || hostRecovering) {
+ if (!requestTimer.isActive()) {
+ requestTimer.start();
+ }
+ } else if (requestTimer.isActive()) {
+ requestTimer.stop();
}
}
bool CardPictureLoaderWorker::processSingleRequest()
{
+ QDateTime now = QDateTime::currentDateTime();
for (int i = 0; i < requestLoadQueue.size(); ++i) {
- const auto &request = requestLoadQueue.at(i);
- QString host = request.first.host();
- int allowance = hostQuotaRemaining.value(host, MAX_REQUESTS_PER_SEC);
+ // Copy the entry: takeAt(i) below erases within the list this reference points into.
+ const auto request = requestLoadQueue.at(i);
+ // Resolve cached redirects so the rate-limit and allowance arithmetic keys on the host the
+ // request will actually hit (see resolveCachedRedirect).
+ const QUrl resolvedUrl = resolveCachedRedirect(request.first);
+ const QString host = resolvedUrl.host();
+ // Don't dispatch requests to a host that is currently in its 429 backoff; hand the entry
+ // back to its worker so it can wait the backoff out or fall through to another source,
+ // instead of leaving it parked in the queue with no reply pending. Only applies to
+ // requests that will actually touch the network: one that will be served from the disk
+ // cache costs nothing and shouldn't wait out the 429.
+ if (requestTouchesNetwork(request.first) &&
+ CardPictureLoaderWorkerWork::rateLimiter().isRateLimited(host, now)) {
+ // The queued URL is usually a cached-redirect target whose host differs from
+ // cardToDownload.getCurrentUrl(), so scheduleDeferredRetry() (which waits out the
+ // blocked host's deadline) is used instead of startNextPicDownload() looping on the
+ // original host.
+ auto entry = requestLoadQueue.takeAt(i);
+ if (host != entry.first.host()) {
+ // A cached redirect target is what is blocked, which the work object would not
+ // discover from its own URL; wait out that specific host (with jitter) instead.
+ entry.second->scheduleDeferredRetry(host);
+ } else {
+ entry.second->startNextPicDownload();
+ }
+ return true;
+ }
+ // Unlocked hosts are handled by dispatchQueuedRequest's fast path, bounded by the in-flight
+ // cap; they must not fall through to the per-host allowance arithmetic below.
+ if (isUnlockedHost(host)) {
+ continue;
+ }
+ int ceiling = hostAllowanceCeiling(host);
+ if (ceiling == DownloadSettings::UNLIMITED_HOST_QUOTA) {
+ // A 429 dropped this unlocked host out of the fast path and installed a concrete
+ // allowance; pace it against that allowance until the recovery loop unlocks it again.
+ ceiling = hostRequestQuota.value(host, DownloadSettings::DEFAULT_HOST_REQUEST_LIMIT);
+ }
+ // Seed the allowance lazily so a host that enters the queue mid-second gets its reduced
+ // per-host allowance, clamped against the ceiling so a lowered user cap applies from this
+ // second onward.
+ if (!hostQuotaRemaining.contains(host)) {
+ hostQuotaRemaining.insert(host, qMin(ceiling, hostRequestQuota.value(host, ceiling)));
+ }
+ int allowance = hostQuotaRemaining.value(host);
if (allowance > 0) {
hostQuotaRemaining.insert(host, allowance - 1);
- makeRequest(request.first, request.second);
- requestLoadQueue.removeAt(i);
+ auto entry = requestLoadQueue.takeAt(i);
+ makeRequest(resolvedUrl, entry.second);
return true;
}
}
return false;
}
+bool CardPictureLoaderWorker::requestTouchesNetwork(const QUrl &url) const
+{
+ bool useNetworkCache = static_cast(
+ SettingsCache::instance().cacheStorage().getCardPictureLoaderCacheMethod()) ==
+ CardPictureLoaderCacheMethod::CacheMethod::NETWORK_CACHE &&
+ (cache->metaData(url).isValid() || !picDownload);
+ return !useNetworkCache;
+}
+
+int CardPictureLoaderWorker::hostAllowanceCeiling(const QString &host) const
+{
+ const int devCap = DownloadSettings::getDeveloperHostCaps().value(host, MAX_REQUESTS_PER_SEC);
+ if (devCap == DownloadSettings::UNLIMITED_HOST_QUOTA && !hostRequestLimits.contains(host)) {
+ return DownloadSettings::UNLIMITED_HOST_QUOTA;
+ }
+ const int requested = hostRequestLimits.value(host, devCap);
+ return SettingsCache::instance().downloads().clampHostRequestLimit(host, requested);
+}
+
+bool CardPictureLoaderWorker::isUnlockedHost(const QString &host) const
+{
+ return hostAllowanceCeiling(host) == DownloadSettings::UNLIMITED_HOST_QUOTA && !hostRequestQuota.contains(host);
+}
+
void CardPictureLoaderWorker::onHostRateLimited(const QString &host)
{
- hostRequestQuota.insert(host, qMax(MIN_HOST_QUOTA, hostRequestQuota.value(host, MAX_REQUESTS_PER_SEC) / 2));
+ const int ceiling = hostAllowanceCeiling(host);
+ // An unlocked host has no per-host allowance to halve. Install one instead so it drops out of
+ // the unlocked fast path and is paced like a throttled host; the recovery loop in
+ // resetRequestQuota() then walks it back up and unlocks it again.
+ const int base =
+ ceiling == DownloadSettings::UNLIMITED_HOST_QUOTA ? DownloadSettings::DEFAULT_HOST_REQUEST_LIMIT : ceiling;
+ hostRequestQuota.insert(host, qMax(MIN_HOST_QUOTA, hostRequestQuota.value(host, base) / 2));
hostLast429.insert(host, QDateTime::currentDateTime());
}
@@ -225,6 +471,22 @@ QUrl CardPictureLoaderWorker::getCachedRedirect(const QUrl &originalUrl) const
return {};
}
+QUrl CardPictureLoaderWorker::resolveCachedRedirect(const QUrl &url) const
+{
+ // Follow the whole cached-redirect chain so dispatch keys on the host that is really hit. The
+ // depth bound keeps a corrupt or self-referencing cache entry from spinning us forever.
+ QUrl resolved = url;
+ int depth = 0;
+ while (depth++ < MAX_REDIRECT_CHAIN_DEPTH) {
+ QUrl target = getCachedRedirect(resolved);
+ if (target.isEmpty() || target == resolved) {
+ break;
+ }
+ resolved = target;
+ }
+ return resolved;
+}
+
void CardPictureLoaderWorker::loadRedirectCache()
{
QSettings settings(cacheFilePath, QSettings::IniFormat);
@@ -277,4 +539,5 @@ void CardPictureLoaderWorker::clearNetworkCache()
{
networkManager->cache()->clear();
redirectCache.clear();
+ emit networkCacheCleared();
}
diff --git a/cockatrice/src/interface/card_picture_loader/card_picture_loader_worker.h b/cockatrice/src/interface/card_picture_loader/card_picture_loader_worker.h
index d1c519b7a..8b136f309 100644
--- a/cockatrice/src/interface/card_picture_loader/card_picture_loader_worker.h
+++ b/cockatrice/src/interface/card_picture_loader/card_picture_loader_worker.h
@@ -74,10 +74,37 @@ public:
*/
void onHostRateLimited(const QString &host);
- /** @brief Clears the network cache and redirect cache. */
- void clearNetworkCache();
+ /**
+ * @brief Stops the worker thread and reports whether it stopped.
+ *
+ * Called from the owning thread (CardPictureLoader) on its way out. QThread::quit() posts an
+ * exit request to the worker's event loop and QThread::wait() blocks (bounded) until the loop
+ * has returned and the thread finished. Only QThread members are touched here, so this method
+ * is safe to call from the owning thread. The worker object itself is freed by the finished()
+ * -> deleteLater chain (see the constructor); the QThread object is deleted afterwards by the
+ * owner (CardPictureLoader::~CardPictureLoader), not by this method.
+ *
+ * @return true if the thread stopped within the timeout, false if it is still running (in
+ * which case the owner must not delete the QThread).
+ */
+ [[nodiscard]] bool shutdownThread();
+
+ /**
+ * @brief Returns the worker's QThread.
+ * @return The worker thread
+ *
+ * Only meaningful while the worker object is alive; capture it before calling shutdownThread().
+ */
+ QThread *workerThread() const;
public slots:
+ /**
+ * @brief Clears the network cache and redirect cache.
+ *
+ * Runs on the worker thread; invoke it via a queued call when coming from another thread,
+ * since both caches are owned by the worker thread.
+ */
+ void clearNetworkCache();
/**
* @brief Makes a network request for the given URL using the specified worker.
* @param url URL to load
@@ -86,9 +113,12 @@ public slots:
*/
QNetworkReply *makeRequest(const QUrl &url, CardPictureLoaderWorkerWork *workThread);
- /** @brief Processes all queued requests respecting the request quota. */
+ /** @brief Ensures the pacing and quota-reset timers reflect the current queue and recovery state. */
void processQueuedRequests();
+ /** @brief Chooses a request from the queue and starts it, respecting the quota and pacing. */
+ void dispatchQueuedRequest();
+
/**
* @brief Processes a single queued request.
* @return true if a request was processed, false if queue is empty.
@@ -118,18 +148,56 @@ private:
bool picDownload; ///< Whether downloading images from network is enabled
QQueue> requestLoadQueue; ///< Queue of pending network requests
- int requestQuota; ///< Remaining requests allowed per second
QTimer requestTimer; ///< Timer to reset the request quota
+ QTimer dispatchTimer; ///< Timer pacing individual network requests
QHash hostRequestQuota; ///< Sustained per-host request allowance
+ QHash hostRequestLimits; ///< User-set per-host request allowances
QHash hostQuotaRemaining; ///< Per-host allowance left in the current second
QHash hostLast429; ///< When each host was last rate limited
+ QHash hostInFlight; ///< Network replies currently in flight, per host
+
+ /** @brief Maximum concurrent in-flight network replies per host. */
+ static constexpr int MAX_IN_FLIGHT_PER_HOST = 6;
+
+ /** @brief Bound on how many cached-redirect hops dispatch resolution will follow. */
+ static constexpr int MAX_REDIRECT_CHAIN_DEPTH = 10;
CardPictureLoaderLocal *localLoader; ///< Loader for local images
QSet currentlyLoading; ///< Deduplication: contains pixmapCacheKey currently being loaded
+ /**
+ * @brief Effective per-host allowance ceiling for a host.
+ * @param host The host to look up
+ * @return The allowance ceiling in requests/second, or DownloadSettings::UNLIMITED_HOST_QUOTA
+ * when the developer unlocked the host and no user limit is set for it.
+ */
+ [[nodiscard]] int hostAllowanceCeiling(const QString &host) const;
+
+ /**
+ * @brief Whether a host may skip dispatch pacing and per-host allowance entirely.
+ *
+ * A host is unlocked while it has no user limit and no reduced allowance installed by a 429.
+ * A 429 drops it out of the fast path until resetRequestQuota() walks the allowance back up.
+ */
+ [[nodiscard]] bool isUnlockedHost(const QString &host) const;
+
/** @brief Returns cached redirect URL for the given original URL, if available. */
[[nodiscard]] QUrl getCachedRedirect(const QUrl &originalUrl) const;
+ /** @brief Whether a request for this URL would actually touch the network, rather than being served from the disk
+ * cache. */
+ [[nodiscard]] bool requestTouchesNetwork(const QUrl &url) const;
+
+ /**
+ * @brief Follows the cached-redirect chain to the URL that will actually be requested.
+ * @param url The URL to resolve
+ * @return The final URL after chasing cached redirects, or @p url itself if none lead elsewhere
+ *
+ * Dispatch decisions (unlocked-host fast path, 429 backoff, in-flight cap) must key on the host
+ * a request really goes to, not the URL that merely redirects to it.
+ */
+ [[nodiscard]] QUrl resolveCachedRedirect(const QUrl &url) const;
+
/** @brief Loads redirect cache from disk. */
void loadRedirectCache();
@@ -139,6 +207,9 @@ private:
/** @brief Removes stale redirect entries older than TTL. */
void cleanStaleEntries();
+ /** @brief Starts or stops the pacing and quota-reset timers to match the queue and recovery state. */
+ void updateTimerState();
+
private slots:
/** @brief Resets the request quota for rate-limiting. */
void resetRequestQuota();
@@ -158,6 +229,9 @@ signals:
/** @brief Emitted when a network request successfully completes. */
void imageRequestSucceeded(const QUrl &url);
+
+ /** @brief Emitted after clearNetworkCache() has finished clearing both caches. */
+ void networkCacheCleared();
};
#endif // PICTURE_LOADER_WORKER_H
diff --git a/cockatrice/src/interface/card_picture_loader/card_picture_loader_worker_work.cpp b/cockatrice/src/interface/card_picture_loader/card_picture_loader_worker_work.cpp
index 66c56337c..19c6be469 100644
--- a/cockatrice/src/interface/card_picture_loader/card_picture_loader_worker_work.cpp
+++ b/cockatrice/src/interface/card_picture_loader/card_picture_loader_worker_work.cpp
@@ -22,8 +22,13 @@ static const QStringList MD5_BLACKLIST = {
"fbc7d763c08771c260b39e2115414eeb" // Current card back hash
};
-CardPictureLoaderWorkerWork::CardPictureLoaderWorkerWork(const CardPictureLoaderWorker *worker, const ExactCard &toLoad)
- : QObject(nullptr), cardToDownload(CardPictureToLoad(toLoad)),
+const ServerRateLimiter &CardPictureLoaderWorkerWork::rateLimiter()
+{
+ return s_rateLimiter;
+}
+
+CardPictureLoaderWorkerWork::CardPictureLoaderWorkerWork(CardPictureLoaderWorker *worker, const ExactCard &toLoad)
+ : QObject(worker), cardToDownload(CardPictureToLoad(toLoad)),
picDownload(SettingsCache::instance().downloads().getPicDownload())
{
// Hook up signals to the orchestrator
@@ -168,7 +173,7 @@ void CardPictureLoaderWorkerWork::handleFailedReply(const QNetworkReply *reply)
<< "PictureLoader: [card: " << cardToDownload.getCard().getName()
<< " set: " << cardToDownload.getSetName() << "]: Too many requests from " << host
<< ", backing off until " << backoffUntil.toString(Qt::ISODate) << ", retrying the same url";
- scheduleDeferredRetry();
+ scheduleDeferredRetry(host);
} else {
qCWarning(CardPictureLoaderWorkerWorkLog).nospace()
<< "PictureLoader: [card: " << cardToDownload.getCard().getName()
@@ -273,14 +278,16 @@ QImage CardPictureLoaderWorkerWork::tryLoadImageFromReply(QNetworkReply *reply)
return imgReader.read();
}
-void CardPictureLoaderWorkerWork::scheduleDeferredRetry()
+void CardPictureLoaderWorkerWork::scheduleDeferredRetry(const QString &preferredHost)
{
QDateTime now = QDateTime::currentDateTime();
- // Prefer waiting on the current URL's server so we retry the same source.
- QString currentHost = QUrl(cardToDownload.getCurrentUrl()).host();
- QDateTime backoffUntil = s_rateLimiter.deadline(currentHost);
- if (!s_rateLimiter.isRateLimited(currentHost, now)) {
+ // Prefer waiting on the server that is actually blocking the request: callers hand in the
+ // rate-limited host when it differs from the current URL (e.g. a cached redirect target still
+ // in backoff), otherwise fall back to the current URL's server so we retry the same source.
+ QString waitHost = preferredHost.isEmpty() ? QUrl(cardToDownload.getCurrentUrl()).host() : preferredHost;
+ QDateTime backoffUntil = s_rateLimiter.deadline(waitHost);
+ if (!s_rateLimiter.isRateLimited(waitHost, now)) {
backoffUntil = s_rateLimiter.earliestDeadline(now);
}
diff --git a/cockatrice/src/interface/card_picture_loader/card_picture_loader_worker_work.h b/cockatrice/src/interface/card_picture_loader/card_picture_loader_worker_work.h
index 1e56a4373..84a7dafdb 100644
--- a/cockatrice/src/interface/card_picture_loader/card_picture_loader_worker_work.h
+++ b/cockatrice/src/interface/card_picture_loader/card_picture_loader_worker_work.h
@@ -10,6 +10,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -36,13 +37,36 @@ class CardPictureLoaderWorkerWork : public QObject
public:
/**
* @brief Constructs a worker for downloading a specific card image.
- * @param worker The orchestrating CardPictureLoaderWorker
+ * @param worker The orchestrating CardPictureLoaderWorker; the work object becomes its child so
+ * it is destroyed with the worker even if it never reaches concludeImageLoad().
* @param toLoad The ExactCard to download
*/
- explicit CardPictureLoaderWorkerWork(const CardPictureLoaderWorker *worker, const ExactCard &toLoad);
+ explicit CardPictureLoaderWorkerWork(CardPictureLoaderWorker *worker, const ExactCard &toLoad);
CardPictureToLoad cardToDownload; ///< The card and associated URLs to try downloading
+ /** @brief Shared per-server 429 backoff state. */
+ static const ServerRateLimiter &rateLimiter();
+
+ /**
+ * @brief Starts downloading the next URL for this card.
+ *
+ * Skips URLs whose server is currently in 429 backoff, either waiting the
+ * backoff out or falling through to the other configured sources.
+ */
+ void startNextPicDownload();
+
+ /**
+ * @brief Schedules a deferred retry after the relevant server backoff expires.
+ * @param preferredHost The server that is actually blocking the request, or an empty
+ * string to use the current URL's server
+ *
+ * Waits on the blocking server's backoff deadline, otherwise on the earliest active
+ * backoff. If no servers are in backoff, concludes with failure. Otherwise resets the
+ * CardPictureToLoad indices and retries after the backoff period.
+ */
+ void scheduleDeferredRetry(const QString &preferredHost = {});
+
public slots:
/**
* @brief Handles a finished network reply for the card image.
@@ -55,9 +79,6 @@ private:
static ServerRateLimiter s_rateLimiter; ///< Shared per-server 429 backoff state
- /** @brief Starts downloading the next URL for this card. */
- void startNextPicDownload();
-
/** @brief Called when all URLs have been exhausted or download failed. */
void picDownloadFailed();
@@ -82,16 +103,6 @@ private:
*/
void concludeImageLoad(const QImage &image);
- /**
- * @brief Schedules a deferred retry after the relevant server backoff expires.
- *
- * Waits on the current URL's server when it is the reason we are blocked,
- * otherwise on the earliest active backoff. If no servers are in backoff,
- * concludes with failure. Otherwise resets the CardPictureToLoad indices and
- * retries after the backoff period.
- */
- void scheduleDeferredRetry();
-
private slots:
/** @brief Updates the picDownload setting when it changes. */
void picDownloadChanged();
diff --git a/cockatrice/src/interface/card_picture_loader/card_picture_to_load.cpp b/cockatrice/src/interface/card_picture_loader/card_picture_to_load.cpp
index 5f4ff0bbd..4f933207e 100644
--- a/cockatrice/src/interface/card_picture_loader/card_picture_to_load.cpp
+++ b/cockatrice/src/interface/card_picture_loader/card_picture_to_load.cpp
@@ -282,8 +282,15 @@ QString CardPictureToLoad::transformUrl(const QString &urlTemplate) const
}
// language setting
- transformMap["!sflang!"] = QString(QCoreApplication::translate(
- "PictureLoader", "en", "code for scryfall's language property, not available for all languages"));
+ const QString cardLang = SettingsCache::instance().cardsDisplay().getCardLang();
+ transformMap["!sflang!"] = cardLang;
+
+ // The localized printing's own id is unknown, so Scryfall must resolve it by
+ // its translated name (see populateSetUrls); expose that name for the
+ // `/cards/named` template.
+ if (cardLang != "en") {
+ transformMap["!localizedName!"] = card.getInfo().getLocalizedName(cardLang);
+ }
QString transformedUrl = urlTemplate;
for (const QString &prop : transformMap.keys()) {
diff --git a/cockatrice/src/interface/deck_loader/deck_file_format.h b/cockatrice/src/interface/deck_loader/deck_file_format.h
index 995de32c0..3a25797ec 100644
--- a/cockatrice/src/interface/deck_loader/deck_file_format.h
+++ b/cockatrice/src/interface/deck_loader/deck_file_format.h
@@ -17,7 +17,7 @@ enum Format
PlainText,
/**
- * This is cockatrice's native deck file format, and supports deck metadata such as banner cards and tags.
+ * This is Cockatrice's native deck file format, and supports deck metadata such as banner cards and tags.
* Stored as .cod files.
*/
Cockatrice
diff --git a/cockatrice/src/interface/deck_loader/deck_loader.cpp b/cockatrice/src/interface/deck_loader/deck_loader.cpp
index 39a0c1071..f29b4eed2 100644
--- a/cockatrice/src/interface/deck_loader/deck_loader.cpp
+++ b/cockatrice/src/interface/deck_loader/deck_loader.cpp
@@ -50,7 +50,7 @@ DeckLoader::loadFromFile(const QString &fileName, DeckFileFormat::Format fmt, bo
result = deckList.loadFromFile_Native(&file);
if (!result) {
qCInfo(DeckLoaderLog) << "Failed to load " << fileName
- << "as cockatrice format; retrying as plain format";
+ << "as Cockatrice format; retrying as plain format";
file.seek(0);
result = deckList.loadFromFile_Plain(&file, CardNameNormalizer());
fmt = DeckFileFormat::PlainText;
@@ -375,15 +375,32 @@ void DeckLoader::saveToStream_DeckHeader(QTextStream &out, const DeckList &deckL
void DeckLoader::saveToStream_DeckZone(QTextStream &out,
const InnerDecklistNode *zoneNode,
bool addComments,
- bool addSetNameAndNumber)
+ bool addSetNameAndNumber,
+ const QString &boardZoneName)
{
+ // Nested sub-zones keep their owning board's identity: the top-level call
+ // passes no board, so the zone's own name is used; recursive calls carry the
+ // owning board down so the sideboard marker survives sub-zone nesting.
+ const QString owningBoardZoneName = boardZoneName.isEmpty() ? zoneNode->getName() : boardZoneName;
+
// group cards by card type and count the subtotals
QMultiMap cardsByType;
QMap cardTotalByType;
int cardTotal = 0;
+ QList subZones;
for (int j = 0; j < zoneNode->size(); j++) {
auto *card = dynamic_cast(zoneNode->at(j));
+ if (!card) {
+ // Cards collected in nested sub-zones are exported by recursion so
+ // they don't end up invisible in the plain text output. They are
+ // deferred until after this zone's own header and cards so they read
+ // as part of this zone's block.
+ if (auto *subZone = dynamic_cast(zoneNode->at(j))) {
+ subZones.append(subZone);
+ }
+ continue;
+ }
CardInfoPtr info = CardDatabaseManager::query()->getCardInfo(card->getName());
QString cardType = info ? info->getMainCardType() : "unknown";
@@ -411,25 +428,30 @@ void DeckLoader::saveToStream_DeckZone(QTextStream &out,
QList cards = cardsByType.values(cardType);
- saveToStream_DeckZoneCards(out, zoneNode, cards, addComments, addSetNameAndNumber);
+ saveToStream_DeckZoneCards(out, cards, addComments, addSetNameAndNumber, owningBoardZoneName);
if (addComments) {
out << "\n";
}
}
+
+ // Nested sub-zones come last, after the parent's own header and cards.
+ for (const auto *subZone : subZones) {
+ saveToStream_DeckZone(out, subZone, addComments, addSetNameAndNumber, owningBoardZoneName);
+ }
}
void DeckLoader::saveToStream_DeckZoneCards(QTextStream &out,
- const InnerDecklistNode *zoneNode,
QList cards,
bool addComments,
- bool addSetNameAndNumber)
+ bool addSetNameAndNumber,
+ const QString &boardZoneName)
{
// QMultiMap sorts values in reverse order
for (int i = cards.size() - 1; i >= 0; --i) {
DecklistCardNode *card = cards[i];
- if (zoneNode->getName() == DECK_ZONE_SIDE && addComments) {
+ if (boardZoneName == DECK_ZONE_SIDE && addComments) {
out << "SB: ";
}
@@ -510,9 +532,26 @@ bool DeckLoader::convertToCockatriceFormat(LoadedDeck &deck)
void DeckLoader::printDeckListNode(QTextCursor *cursor, const InnerDecklistNode *node)
{
+ if (!node || node->isEmpty()) {
+ return;
+ }
+
const int totalColumns = 2;
- if (node->height() == 1) {
+ // Dispatch children by type instead of trusting a whole-node height: a deck
+ // node may hold direct cards and nested zones side by side (custom zones),
+ // and an empty node would previously crash on at(0).
+ QVector cards;
+ QVector subZones;
+ for (int i = 0; i < node->size(); i++) {
+ if (auto *card = dynamic_cast(node->at(i))) {
+ cards.append(card);
+ } else if (auto *zone = dynamic_cast(node->at(i))) {
+ subZones.append(zone);
+ }
+ }
+
+ if (!cards.isEmpty()) {
QTextBlockFormat blockFormat;
QTextCharFormat charFormat;
charFormat.setFontPointSize(11);
@@ -523,9 +562,9 @@ void DeckLoader::printDeckListNode(QTextCursor *cursor, const InnerDecklistNode
tableFormat.setCellPadding(0);
tableFormat.setCellSpacing(0);
tableFormat.setBorder(0);
- QTextTable *table = cursor->insertTable(node->size() + 1, totalColumns, tableFormat);
- for (int i = 0; i < node->size(); i++) {
- auto *card = dynamic_cast(node->at(i));
+ QTextTable *table = cursor->insertTable(cards.size() + 1, totalColumns, tableFormat);
+ for (int i = 0; i < cards.size(); i++) {
+ const AbstractDecklistCardNode *card = cards[i];
QTextCharFormat cellCharFormat;
cellCharFormat.setFontPointSize(9);
@@ -540,7 +579,13 @@ void DeckLoader::printDeckListNode(QTextCursor *cursor, const InnerDecklistNode
cellCursor = cell.firstCursorPosition();
cellCursor.insertText(card->getName());
}
- } else if (node->height() == 2) {
+ }
+
+ for (const InnerDecklistNode *subZone : subZones) {
+ if (subZone->isEmpty()) {
+ continue;
+ }
+
QTextBlockFormat blockFormat;
QTextCharFormat charFormat;
charFormat.setFontPointSize(14);
@@ -559,10 +604,8 @@ void DeckLoader::printDeckListNode(QTextCursor *cursor, const InnerDecklistNode
tableFormat.setColumnWidthConstraints(constraints);
QTextTable *table = cursor->insertTable(1, totalColumns, tableFormat);
- for (int i = 0; i < node->size(); i++) {
- QTextCursor cellCursor = table->cellAt(0, (i * totalColumns) / node->size()).lastCursorPosition();
- printDeckListNode(&cellCursor, dynamic_cast(node->at(i)));
- }
+ QTextCursor cellCursor = table->cellAt(0, 0).firstCursorPosition();
+ printDeckListNode(&cellCursor, subZone);
}
cursor->movePosition(QTextCursor::End);
diff --git a/cockatrice/src/interface/deck_loader/deck_loader.h b/cockatrice/src/interface/deck_loader/deck_loader.h
index ac23e1ee0..be0df311d 100644
--- a/cockatrice/src/interface/deck_loader/deck_loader.h
+++ b/cockatrice/src/interface/deck_loader/deck_loader.h
@@ -131,7 +131,7 @@ public:
static void printDeckList(QPrinter *printer, const DeckList &deckList);
/**
- * Converts the given deck's file to the cockatrice file format.
+ * Converts the given deck's file to the Cockatrice file format.
* Uses the lastLoadInfo in the LoadedDeck to determine the current name of the file and where to save to.
* @param deck The deck to convert. Should have valid lastLoadInfo. Will update the lastLoadInfo.
* @return Whether the conversion succeeded.
@@ -159,12 +159,13 @@ private:
static void saveToStream_DeckZone(QTextStream &out,
const InnerDecklistNode *zoneNode,
bool addComments = true,
- bool addSetNameAndNumber = true);
+ bool addSetNameAndNumber = true,
+ const QString &boardZoneName = QString());
static void saveToStream_DeckZoneCards(QTextStream &out,
- const InnerDecklistNode *zoneNode,
QList cards,
bool addComments = true,
- bool addSetNameAndNumber = true);
+ bool addSetNameAndNumber = true,
+ const QString &boardZoneName = QString());
};
#endif
diff --git a/cockatrice/src/interface/intents/contexts/context_open_deck.h b/cockatrice/src/interface/intents/contexts/context_open_deck.h
new file mode 100644
index 000000000..03dca088e
--- /dev/null
+++ b/cockatrice/src/interface/intents/contexts/context_open_deck.h
@@ -0,0 +1,14 @@
+#ifndef COCKATRICE_CONTEXT_OPEN_DECK_H
+#define COCKATRICE_CONTEXT_OPEN_DECK_H
+
+#include "context_connect_to_server.h"
+
+#include
+
+struct ContextOpenDeck
+{
+ ContextConnectToServer serverContext;
+ QString shareToken;
+};
+
+#endif // COCKATRICE_CONTEXT_OPEN_DECK_H
diff --git a/cockatrice/src/interface/intents/intent.cpp b/cockatrice/src/interface/intents/intent.cpp
index c02a89f35..db0d13b2c 100644
--- a/cockatrice/src/interface/intents/intent.cpp
+++ b/cockatrice/src/interface/intents/intent.cpp
@@ -2,10 +2,11 @@
Intent::Intent(QObject *parent) : QObject(parent)
{
- // An intent is done as soon as it reports success or failure. Deleting it
- // also tears down its dependency chain and disconnects any signal wiring.
+ // An intent is done as soon as it reports success, failure, or cancellation.
+ // Deleting it also tears down its dependency chain and disconnects any signal wiring.
connect(this, &Intent::finished, this, &QObject::deleteLater);
connect(this, &Intent::failed, this, &QObject::deleteLater);
+ connect(this, &Intent::cancelled, this, &QObject::deleteLater);
}
Intent::~Intent() = default;
@@ -27,6 +28,7 @@ void Intent::runDependency(Intent *dependency)
this->execute();
});
connect(dependency, &Intent::failed, this, &Intent::failed);
+ connect(dependency, &Intent::cancelled, this, &Intent::cancelled);
dependency->execute();
}
@@ -46,3 +48,11 @@ void Intent::emitFailed(const QString &reason)
emit failed(reason);
}
}
+
+void Intent::emitCancelled()
+{
+ if (!completed) {
+ completed = true;
+ emit cancelled();
+ }
+}
diff --git a/cockatrice/src/interface/intents/intent.h b/cockatrice/src/interface/intents/intent.h
index 125900ecd..5d9fdd3d6 100644
--- a/cockatrice/src/interface/intents/intent.h
+++ b/cockatrice/src/interface/intents/intent.h
@@ -16,6 +16,7 @@ public:
signals:
void finished();
void failed(QString reason);
+ void cancelled();
protected:
// --- Subclasses must implement these ---
@@ -29,6 +30,7 @@ protected:
// Emit the outcome exactly once; ignore late signals after the intent is done.
void emitFinished();
void emitFailed(const QString &reason);
+ void emitCancelled();
private:
bool completed = false;
diff --git a/cockatrice/src/interface/intents/intent_join_server_game.cpp b/cockatrice/src/interface/intents/intent_join_server_game.cpp
index 205c4dc70..b22b200ed 100644
--- a/cockatrice/src/interface/intents/intent_join_server_game.cpp
+++ b/cockatrice/src/interface/intents/intent_join_server_game.cpp
@@ -19,13 +19,15 @@ bool IntentJoinServerGame::checkPrecondition() const
if (remoteClient->getStatus() != ClientStatus::StatusLoggedIn) {
return false;
}
- // peerPort() reflects the actual TCP peer, which may differ from the
- // configured server port (e.g. when connecting through a proxy), so only
- // the hostname is compared here.
- if (remoteClient->peerName() != context->roomContext.serverContext.hostname) {
+ // serverName()/serverPort() reflect the server the client was configured
+ // to connect to, which may differ from the actual TCP peer (e.g. when
+ // connecting through a proxy), so compare those configured values. A link
+ // naming the same host on another port is a different server and must not
+ // reuse the session there.
+ if (remoteClient->serverName().compare(context->roomContext.serverContext.hostname, Qt::CaseInsensitive) != 0) {
return false;
}
- if (QString::number(remoteClient->peerPort()) != context->roomContext.serverContext.port) {
+ if (QString::number(remoteClient->serverPort()) != context->roomContext.serverContext.port) {
return false;
}
diff --git a/cockatrice/src/interface/intents/intent_login.cpp b/cockatrice/src/interface/intents/intent_login.cpp
index ff871fd03..7beb63e1d 100644
--- a/cockatrice/src/interface/intents/intent_login.cpp
+++ b/cockatrice/src/interface/intents/intent_login.cpp
@@ -1,9 +1,14 @@
#include "intent_login.h"
#include "../../client/settings/cache_settings.h"
+#include "../widgets/dialogs/dlg_login_prompt.h"
#include "libcockatrice/settings/servers_settings.h"
-IntentGetLoginCredentials::IntentGetLoginCredentials(ContextConnectToServer *_context) : Intent(), context(_context)
+#include
+
+IntentGetLoginCredentials::IntentGetLoginCredentials(ContextConnectToServer *_context,
+ bool _promptForMissingCredentials)
+ : Intent(), context(_context), promptForMissingCredentials(_promptForMissingCredentials)
{
}
@@ -29,5 +34,46 @@ void IntentGetLoginCredentials::onPreconditionSatisfied()
void IntentGetLoginCredentials::onPreconditionNotSatisfied()
{
- emitFailed(tr("No saved credentials for this server"));
+ // MainWindow::applyStartupDestination runs this intent on every launch for
+ // users whose startup tab is Server / Server Room; keep that path quiet, as
+ // it was before the link-driven sign-in dialog existed.
+ if (!promptForMissingCredentials) {
+ emitFailed(tr("No saved credentials for this server"));
+ return;
+ }
+
+ // No credentials saved for the target server: ask the user for them. They
+ // opt into saving them so later links to the same server connect directly.
+ const QString serverText = context->hostname + ":" + context->port;
+ DlgLoginPrompt dialog(serverText);
+ // ApplicationModal: the dialog has no parent (the intent is not a widget),
+ // so WindowModal would not actually block any other window.
+ dialog.setWindowModality(Qt::ApplicationModal);
+
+ if (dialog.exec() != QDialog::Accepted) {
+ emitCancelled();
+ return;
+ }
+
+ context->username = dialog.username();
+ context->password = dialog.password();
+
+ if (dialog.savePassword() && !context->username.isEmpty()) {
+ ServersSettings &servers = SettingsCache::instance().servers();
+ // The host may already be saved under a friendly name (e.g. a public-server
+ // list entry) with no credentials; reuse that name instead of overwriting
+ // it with the raw hostname when addNewServer updates the entry in place.
+ QString saveName = context->hostname;
+ const int existingIndex = servers.findServerIndex(context->hostname, context->port);
+ if (existingIndex >= 0) {
+ saveName =
+ servers.getValue(QString("saveName%1").arg(existingIndex), "server", "server_details").toString();
+ if (saveName.isEmpty()) {
+ saveName = context->hostname;
+ }
+ }
+ servers.addNewServer(saveName, context->hostname, context->port, context->username, context->password, true);
+ }
+
+ emitFinished();
}
diff --git a/cockatrice/src/interface/intents/intent_login.h b/cockatrice/src/interface/intents/intent_login.h
index c7fec92b7..8ffd91a0a 100644
--- a/cockatrice/src/interface/intents/intent_login.h
+++ b/cockatrice/src/interface/intents/intent_login.h
@@ -9,7 +9,10 @@ class IntentGetLoginCredentials : public Intent
Q_OBJECT
public:
- IntentGetLoginCredentials(ContextConnectToServer *_context);
+ // When promptForMissingCredentials is false (the default) a server without
+ // saved credentials fails silently; only intent chains from cockatrice://
+ // links opt into the interactive sign-in dialog.
+ explicit IntentGetLoginCredentials(ContextConnectToServer *_context, bool _promptForMissingCredentials = false);
protected:
bool checkPrecondition() const override;
@@ -18,6 +21,7 @@ protected:
private:
ContextConnectToServer *context;
+ bool promptForMissingCredentials;
};
#endif // COCKATRICE_INTENT_LOGIN_H
diff --git a/cockatrice/src/interface/intents/intent_open_shared_deck.cpp b/cockatrice/src/interface/intents/intent_open_shared_deck.cpp
new file mode 100644
index 000000000..016de63e6
--- /dev/null
+++ b/cockatrice/src/interface/intents/intent_open_shared_deck.cpp
@@ -0,0 +1,208 @@
+#include "intent_open_shared_deck.h"
+
+#include "../deck_loader/deck_loader.h"
+#include "../widgets/dialogs/dlg_shared_decks_preview.h"
+#include "../widgets/tabs/tab_supervisor.h"
+#include "intent_connect_to_server.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+IntentOpenSharedDeck::IntentOpenSharedDeck(TabSupervisor *_tabSupervisor,
+ RemoteClient *_remoteClient,
+ const CardDatabaseQuerier *_querier,
+ std::unique_ptr _context)
+ : Intent(), tabSupervisor(_tabSupervisor), remoteClient(_remoteClient), querier(_querier),
+ context(_context.release())
+{
+ downloadTimer = new QTimer(this);
+ downloadTimer->setSingleShot(true);
+ downloadTimer->setInterval(15000);
+ connect(downloadTimer, &QTimer::timeout, this, &IntentOpenSharedDeck::onDownloadTimeout);
+}
+
+bool IntentOpenSharedDeck::checkPrecondition() const
+{
+ if (remoteClient->getStatus() != ClientStatus::StatusLoggedIn) {
+ return false;
+ }
+ // serverName()/serverPort() reflect the server the client was configured
+ // to connect to, which may differ from the actual TCP peer (e.g. when
+ // connecting through a proxy), so compare those configured values. The
+ // share token must be resolved against the host the link named — a link to
+ // the same host on another port is a different server.
+ if (remoteClient->serverName().compare(context->serverContext.hostname, Qt::CaseInsensitive) != 0) {
+ return false;
+ }
+ return QString::number(remoteClient->serverPort()) == context->serverContext.port;
+}
+
+void IntentOpenSharedDeck::onPreconditionSatisfied()
+{
+ // Resolve the share token to its items first; a share can contain more than
+ // one deck, and each item is downloaded by id. Time the round trip like the
+ // downloads, so a silent server cannot hang the chain forever.
+ listPhase = true;
+ downloadTimer->start();
+
+ Command_DeckShareList cmd;
+ cmd.set_token(context->shareToken.toStdString());
+
+ PendingCommand *pend = AbstractClient::prepareSessionCommand(cmd);
+ connect(pend, &PendingCommand::finished, this, &IntentOpenSharedDeck::listShareFinished);
+ remoteClient->sendCommand(pend);
+}
+
+void IntentOpenSharedDeck::onPreconditionNotSatisfied()
+{
+ runDependency(new IntentConnectToServer(remoteClient, &context->serverContext));
+}
+
+void IntentOpenSharedDeck::listShareFinished(const Response &response, const CommandContainer & /* commandContainer */)
+{
+ downloadTimer->stop();
+ listPhase = false;
+
+ if (response.response_code() != Response::RespOk) {
+ emitFailed(tr("The shared deck could not be found or has expired"));
+ return;
+ }
+
+ const Response_DeckShareList &resp = response.GetExtension(Response_DeckShareList::ext);
+ if (resp.items_size() == 0) {
+ emitFailed(tr("The shared deck is empty"));
+ return;
+ }
+
+ QList items;
+ items.reserve(resp.items_size());
+ for (const ServerInfo_DeckShareItem &item : resp.items()) {
+ items.append(item);
+ itemNames.insert(item.id(), QString::fromStdString(item.name()));
+ }
+
+ const QString serverText = context->serverContext.hostname + ":" + context->serverContext.port;
+
+ // Ask the user which decks to open before downloading anything.
+ previewDialog = new DlgSharedDecksPreview(tabSupervisor, querier, QString::fromStdString(resp.name()),
+ resp.expires_at(), serverText, items);
+ connect(previewDialog, &DlgSharedDecksPreview::openRequested, this, &IntentOpenSharedDeck::startDownloads);
+ connect(previewDialog, &DlgSharedDecksPreview::cancelled, this, &IntentOpenSharedDeck::emitCancelled);
+ connect(previewDialog, &DlgSharedDecksPreview::cancelled, previewDialog, &QWidget::deleteLater);
+ previewDialog->show();
+ previewDialog->raise();
+ previewDialog->activateWindow();
+}
+
+void IntentOpenSharedDeck::startDownloads(const QList &itemIds)
+{
+ pendingItemIds = itemIds;
+ totalItems = itemIds.size();
+ completedItems = 0;
+ loadedDecks.clear();
+ downloadNextItem();
+}
+
+void IntentOpenSharedDeck::downloadNextItem()
+{
+ if (pendingItemIds.isEmpty()) {
+ finishAll();
+ return;
+ }
+
+ currentItemId = pendingItemIds.takeFirst();
+ downloadTimer->start();
+
+ Command_DeckShareDownload cmd;
+ cmd.set_token(context->shareToken.toStdString());
+ cmd.set_item_id(currentItemId);
+
+ PendingCommand *pend = AbstractClient::prepareSessionCommand(cmd);
+ connect(pend, &PendingCommand::finished, this, &IntentOpenSharedDeck::downloadShareFinished);
+ remoteClient->sendCommand(pend);
+}
+
+void IntentOpenSharedDeck::downloadShareFinished(const Response &response,
+ const CommandContainer & /* commandContainer */)
+{
+ downloadTimer->stop();
+
+ QString failureReason;
+ if (response.response_code() != Response::RespOk) {
+ failureReason = tr("Failed to download the shared deck");
+ } else {
+ const Response_DeckShareDownload &resp = response.GetExtension(Response_DeckShareDownload::ext);
+ const QString deckString = QString::fromStdString(resp.deck());
+ if (deckString.isEmpty()) {
+ failureReason = tr("The shared deck is empty");
+ } else {
+ std::optional deckOpt =
+ DeckLoader::loadFromRemote(deckString, LoadedDeck::LoadInfo::NON_REMOTE_ID);
+ if (!deckOpt) {
+ failureReason = tr("The shared deck could not be loaded");
+ } else {
+ loadedDecks.append(deckOpt.value());
+ ++completedItems;
+ previewDialog->setDownloadProgress(completedItems, totalItems,
+ itemNames.value(currentItemId, tr("Unknown deck")));
+ downloadNextItem();
+ return;
+ }
+ }
+ }
+
+ onItemFailure(failureReason);
+}
+
+void IntentOpenSharedDeck::onItemFailure(const QString &reason)
+{
+ downloadTimer->stop();
+
+ if (loadedDecks.isEmpty()) {
+ previewDialog->deleteLater();
+ emitFailed(reason);
+ return;
+ }
+
+ const int downloadedCount = loadedDecks.size();
+ const QMessageBox::StandardButton answer = QMessageBox::question(
+ previewDialog, tr("Open shared decks"),
+ tr("Could not download the deck \"%1\".\n\n%n deck(s) were already downloaded. Open them?", "", downloadedCount)
+ .arg(itemNames.value(currentItemId, tr("Unknown deck"))),
+ QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
+
+ if (answer == QMessageBox::Yes) {
+ finishAll();
+ } else {
+ previewDialog->deleteLater();
+ emitCancelled();
+ }
+}
+
+void IntentOpenSharedDeck::onDownloadTimeout()
+{
+ // The list phase has no preview dialog yet to report progress into; fail the
+ // whole intent instead of letting the shared deck hang in limbo.
+ if (listPhase) {
+ emitFailed(tr("Timed out while loading the shared deck"));
+ return;
+ }
+ onItemFailure(tr("Timed out while downloading the shared deck"));
+}
+
+void IntentOpenSharedDeck::finishAll()
+{
+ previewDialog->deleteLater();
+ for (const LoadedDeck &deck : loadedDecks) {
+ tabSupervisor->openDeckInNewTab(deck);
+ }
+ emitFinished();
+}
diff --git a/cockatrice/src/interface/intents/intent_open_shared_deck.h b/cockatrice/src/interface/intents/intent_open_shared_deck.h
new file mode 100644
index 000000000..87812bdea
--- /dev/null
+++ b/cockatrice/src/interface/intents/intent_open_shared_deck.h
@@ -0,0 +1,60 @@
+#ifndef COCKATRICE_INTENT_OPEN_SHARED_DECK_H
+#define COCKATRICE_INTENT_OPEN_SHARED_DECK_H
+
+#include "contexts/context_open_deck.h"
+#include "intent.h"
+#include "remote_client.h"
+
+#include
+#include
+#include
+#include
+
+class TabSupervisor;
+struct LoadedDeck;
+class CardDatabaseQuerier;
+class DlgSharedDecksPreview;
+class QTimer;
+
+class IntentOpenSharedDeck : public Intent
+{
+ Q_OBJECT
+
+public:
+ IntentOpenSharedDeck(TabSupervisor *_tabSupervisor,
+ RemoteClient *_remoteClient,
+ const CardDatabaseQuerier *_querier,
+ std::unique_ptr _context);
+
+protected:
+ bool checkPrecondition() const override;
+ void onPreconditionSatisfied() override;
+ void onPreconditionNotSatisfied() override;
+
+private slots:
+ void listShareFinished(const Response &response, const CommandContainer &commandContainer);
+ void downloadShareFinished(const Response &response, const CommandContainer &commandContainer);
+ void onDownloadTimeout();
+
+private:
+ void startDownloads(const QList &itemIds);
+ void downloadNextItem();
+ void onItemFailure(const QString &reason);
+ void finishAll();
+
+ TabSupervisor *tabSupervisor;
+ RemoteClient *remoteClient;
+ const CardDatabaseQuerier *querier;
+ QScopedPointer context;
+ DlgSharedDecksPreview *previewDialog = nullptr;
+ QTimer *downloadTimer;
+ QMap itemNames;
+ QList pendingItemIds;
+ QList loadedDecks;
+ bool listPhase = true;
+ int currentItemId = 0;
+ int totalItems = 0;
+ int completedItems = 0;
+};
+
+#endif // COCKATRICE_INTENT_OPEN_SHARED_DECK_H
diff --git a/cockatrice/src/interface/intents/url_parser.cpp b/cockatrice/src/interface/intents/url_parser.cpp
index 509390611..707863354 100644
--- a/cockatrice/src/interface/intents/url_parser.cpp
+++ b/cockatrice/src/interface/intents/url_parser.cpp
@@ -1,19 +1,28 @@
#include "url_parser.h"
+#include "../../client/settings/cache_settings.h"
#include "../widgets/tabs/tab_room.h"
#include "../widgets/tabs/tab_supervisor.h"
#include "../window_main.h"
#include "contexts/context_join_game.h"
+#include "contexts/context_open_deck.h"
+#include "intent.h"
#include "intent_join_server_game.h"
#include "intent_login.h"
+#include "intent_open_shared_deck.h"
#include
+#include
#include
#include
#include
+#include
#include
+#include
#include
+inline Q_LOGGING_CATEGORY(UrlParserLog, "url_parser");
+
IntentUrlParser::IntentUrlParser(QObject *parent, MainWindow *_mainWindow) : QObject(parent), mainWindow(_mainWindow)
{
}
@@ -29,16 +38,33 @@ void IntentUrlParser::handle(const QString &urlStr)
const QString action = url.host();
QUrlQuery query(url);
+ qCDebug(UrlParserLog) << "Parsing intent URL, action:" << action;
+
+ PendingIntentChain chain;
+ Intent *firstIntent = nullptr;
if (action == "joingame") {
- handleJoinGame(query);
+ firstIntent = createJoinGameIntent(query, chain);
} else if (action == "opendeck") {
- // handleOpenDeck(query);
+ firstIntent = createOpenDeckIntent(query, chain);
} else {
qWarning() << "Unknown intent:" << action;
}
+
+ if (firstIntent == nullptr) {
+ // The link was invalid or the user declined the confirm: nothing runs.
+ // Report the idle state when no other chain is queued so that a startup
+ // launch (which skipped its own connection for this URL) falls back to it.
+ if (!chainRunning && pendingChains.isEmpty()) {
+ emit urlChainFinished(mainWindow->getRemoteClient()->getStatus() == StatusLoggedIn);
+ }
+ return;
+ }
+
+ pendingChains.append(chain);
+ startNextChain();
}
-void IntentUrlParser::handleJoinGame(const QUrlQuery &query)
+Intent *IntentUrlParser::createJoinGameIntent(const QUrlQuery &query, PendingIntentChain &chain)
{
auto showError = [this](const QString &message) { QMessageBox::warning(mainWindow, tr("Open game"), message); };
@@ -49,21 +75,21 @@ void IntentUrlParser::handleJoinGame(const QUrlQuery &query)
if (ctx->roomContext.serverContext.hostname.isEmpty()) {
showError(tr("Missing or empty hostname in the game link"));
- return;
+ return nullptr;
}
bool ok = false;
ctx->roomContext.serverContext.port.toUShort(&ok);
if (!ok) {
showError(tr("Invalid or missing port in the game link"));
- return;
+ return nullptr;
}
ctx->roomContext.roomId = query.queryItemValue("roomid").toInt(&ok);
if (!ok) {
showError(tr("Invalid or missing room id in the game link"));
- return;
+ return nullptr;
}
ok = false;
@@ -71,7 +97,7 @@ void IntentUrlParser::handleJoinGame(const QUrlQuery &query)
if (!ok) {
showError(tr("Invalid or missing game id in the game link"));
- return;
+ return nullptr;
}
const QString gameDescription = query.queryItemValue("game", QUrl::FullyDecoded);
@@ -80,24 +106,33 @@ void IntentUrlParser::handleJoinGame(const QUrlQuery &query)
const QMessageBox::StandardButton answer = QMessageBox::question(
mainWindow, tr("Join game"), message, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
if (answer != QMessageBox::Yes) {
- return;
+ return nullptr;
}
+ RemoteClient *client = mainWindow->getRemoteClient();
+ ContextConnectToServer *serverContext = &ctx->roomContext.serverContext;
+
// The join game intent owns the context and the credential lookup; once the
// chain finishes (or fails) it deletes the whole tree.
- ContextConnectToServer *serverContext = &ctx->roomContext.serverContext;
- auto joinGameIntent =
- new IntentJoinServerGame(mainWindow->getTabSupervisor(), mainWindow->getRemoteClient(), std::move(ctx));
+ auto joinGameIntent = new IntentJoinServerGame(mainWindow->getTabSupervisor(), client, std::move(ctx));
joinGameIntent->setParent(this);
-
- auto getLoginCredentialsIntent = new IntentGetLoginCredentials(serverContext);
- getLoginCredentialsIntent->setParent(joinGameIntent);
-
- connect(getLoginCredentialsIntent, &Intent::finished, joinGameIntent, &Intent::execute);
- connect(getLoginCredentialsIntent, &Intent::failed, joinGameIntent, &Intent::failed);
+ chain.intents.append(joinGameIntent);
connect(joinGameIntent, &Intent::failed, this, [showError](const QString &reason) { showError(reason); });
- getLoginCredentialsIntent->execute();
+ Intent *firstIntent = joinGameIntent;
+ if (!isConnectedTo(serverContext->hostname, serverContext->port)) {
+ auto getLoginCredentialsIntent =
+ new IntentGetLoginCredentials(serverContext, /*promptForMissingCredentials=*/true);
+ getLoginCredentialsIntent->setParent(joinGameIntent);
+ chain.intents.insert(0, getLoginCredentialsIntent);
+
+ connect(getLoginCredentialsIntent, &Intent::finished, joinGameIntent, &Intent::execute);
+ connect(getLoginCredentialsIntent, &Intent::failed, joinGameIntent, &Intent::failed);
+ connect(getLoginCredentialsIntent, &Intent::cancelled, joinGameIntent, &Intent::cancelled);
+ firstIntent = getLoginCredentialsIntent;
+ }
+
+ return firstIntent;
}
QString IntentUrlParser::generateJoinGameMessage(const ContextJoinGame &context, const QString &gameDescription)
@@ -134,3 +169,270 @@ QString IntentUrlParser::generateJoinGameMessage(const ContextJoinGame &context,
.arg(gameDescription, gameIdStr, roomTab->getRoomName(), server)
: tr("Join game \"%1\" (#%2) on %3?").arg(gameDescription, gameIdStr, server);
}
+
+Intent *IntentUrlParser::createOpenDeckIntent(const QUrlQuery &query, PendingIntentChain &chain)
+{
+ auto showError = [this](const QString &message) {
+ QMessageBox::warning(mainWindow, tr("Open shared deck"), message);
+ };
+
+ auto ctx = std::make_unique();
+
+ ctx->serverContext.hostname = query.queryItemValue("hostname");
+ ctx->serverContext.port = query.queryItemValue("port");
+ ctx->shareToken = query.queryItemValue("share");
+
+ qCDebug(UrlParserLog) << "Open-deck intent: host" << ctx->serverContext.hostname << "port"
+ << ctx->serverContext.port << "token length" << ctx->shareToken.length();
+
+ if (ctx->serverContext.hostname.isEmpty()) {
+ showError(tr("Missing or empty hostname in the share link"));
+ return nullptr;
+ }
+
+ bool ok = false;
+ const quint16 port = ctx->serverContext.port.toUShort(&ok);
+ if (!ok || port == 0) {
+ showError(tr("Invalid or missing port in the share link"));
+ return nullptr;
+ }
+
+ if (ctx->shareToken.isEmpty()) {
+ showError(tr("Missing or empty share value in the share link"));
+ return nullptr;
+ }
+
+ RemoteClient *client = mainWindow->getRemoteClient();
+
+ // The open deck download needs a connection to the link's server. Ask before
+ // taking the session anywhere it isn't already, naming the host we would
+ // connect to. Remember the link's target when it moves us away from a live
+ // session so a failed or cancelled chain can restore the session it left.
+ // The hostname is link-supplied and percent-decoded, so escape it: QMessageBox
+ // renders AutoText, and markup in a hostname would otherwise flip the whole
+ // prompt to rich text and let a link pad the message the user is shown.
+ const bool alreadyConnected = isConnectedTo(ctx->serverContext.hostname, ctx->serverContext.port);
+ if (!alreadyConnected) {
+ const QString target =
+ QStringLiteral("%1:%2").arg(ctx->serverContext.hostname.toHtmlEscaped(), ctx->serverContext.port);
+
+ if (client->getStatus() == StatusLoggedIn) {
+ const QString current =
+ QStringLiteral("%1:%2").arg(client->serverName(), QString::number(client->serverPort()));
+ const QMessageBox::StandardButton answer = QMessageBox::question(
+ mainWindow, tr("Open shared deck"),
+ tr("Opening this share link connects you to %1 instead of %2.\n\nContinue?").arg(target, current),
+ QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
+ if (answer != QMessageBox::Yes) {
+ return nullptr;
+ }
+ chain.migrationTargetHost = ctx->serverContext.hostname;
+ chain.migrationTargetPort = ctx->serverContext.port;
+ chain.pendingRestore = true;
+ } else {
+ // Fresh connection is harmless to wander away from, but a server the
+ // client has never been configured for deserves a harder warning (no
+ // by default) so a stray link cannot silently steer the client there.
+ const bool knownHost = SettingsCache::instance().servers().findHostIndex(ctx->serverContext.hostname) >= 0;
+ const QMessageBox::StandardButton answer =
+ knownHost
+ ? QMessageBox::question(mainWindow, tr("Open shared deck"),
+ tr("Opening this share link connects you to %1.\n\nContinue?").arg(target))
+ : QMessageBox::warning(mainWindow, tr("Open shared deck"),
+ tr("Opening this share link connects you to %1, a server you have "
+ "never connected to before.\n\nContinue?")
+ .arg(target),
+ QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
+ if (answer != QMessageBox::Yes) {
+ return nullptr;
+ }
+ }
+ }
+
+ ContextConnectToServer *serverContext = &ctx->serverContext;
+
+ // The open deck intent owns the context and the credential lookup; once
+ // the chain finishes (or fails) it deletes the whole tree.
+ auto openDeckIntent =
+ new IntentOpenSharedDeck(mainWindow->getTabSupervisor(), client, CardDatabaseManager::query(), std::move(ctx));
+ openDeckIntent->setParent(this);
+ chain.intents.append(openDeckIntent);
+ connect(openDeckIntent, &Intent::failed, this, [showError](const QString &reason) { showError(reason); });
+
+ Intent *firstIntent = openDeckIntent;
+ if (!isConnectedTo(serverContext->hostname, serverContext->port)) {
+ auto getLoginCredentialsIntent =
+ new IntentGetLoginCredentials(serverContext, /*promptForMissingCredentials=*/true);
+ getLoginCredentialsIntent->setParent(openDeckIntent);
+ chain.intents.insert(0, getLoginCredentialsIntent);
+
+ connect(getLoginCredentialsIntent, &Intent::finished, openDeckIntent, &Intent::execute);
+ connect(getLoginCredentialsIntent, &Intent::failed, openDeckIntent, &Intent::failed);
+ connect(getLoginCredentialsIntent, &Intent::cancelled, openDeckIntent, &Intent::cancelled);
+ firstIntent = getLoginCredentialsIntent;
+ }
+
+ return firstIntent;
+}
+
+bool IntentUrlParser::isConnectedTo(const QString &hostname, const QString &port) const
+{
+ // serverName() reflects the server the client was configured to connect to,
+ // which may differ from the actual TCP peer (e.g. when connecting through a
+ // proxy), so compare the configured host and port — exactly what a link
+ // names. A link to the same host on another port is a different server and
+ // must not silently reuse an existing session there.
+ RemoteClient *client = mainWindow->getRemoteClient();
+ return client->getStatus() == StatusLoggedIn && client->serverName().compare(hostname, Qt::CaseInsensitive) == 0 &&
+ QString::number(client->serverPort()) == port;
+}
+
+void IntentUrlParser::startNextChain()
+{
+ if (chainRunning || pendingChains.isEmpty()) {
+ return;
+ }
+ chainRunning = true;
+
+ PendingIntentChain &chain = pendingChains.first();
+ if (chain.intents.isEmpty()) {
+ pendingChains.removeFirst();
+ chainRunning = false;
+ startNextChain();
+ return;
+ }
+
+ // Snapshot the session this chain moves away from now that it actually
+ // runs. Chains are parsed while earlier ones are still queued, so a capture
+ // at parse time would follow whichever server the chain before it settled
+ // on, not the one the user is really on when this link is handled.
+ if (chain.pendingRestore) {
+ RemoteClient *client = mainWindow->getRemoteClient();
+ chain.previousServerHost = client->serverName();
+ chain.previousServerPort = QString::number(client->serverPort());
+ }
+
+ // Only the last intent completes the chain; its terminal signal ends the
+ // whole run. Cancellation of an intermediate intent (e.g. declined login
+ // prompt) is forwarded onto the last intent in the chain builders above.
+ Intent *finalIntent = chain.intents.last();
+ connect(finalIntent, &Intent::finished, this, [this]() { chainEnded(true); });
+ connect(finalIntent, &Intent::failed, this, [this]() { chainEnded(false); });
+ connect(finalIntent, &Intent::cancelled, this, [this]() { chainEnded(false); });
+ // Backstop: if the final intent is destroyed without emitting a terminal
+ // signal (e.g. a network error dropped it while running), end the chain so
+ // later links are not queued and dropped for the rest of the session.
+ chainBackstopConnection = connect(finalIntent, &QObject::destroyed, this, &IntentUrlParser::onChainIntentDestroyed);
+
+ chain.intents.first()->execute();
+}
+
+void IntentUrlParser::chainEnded(bool chainSucceeded)
+{
+ chainRunning = false;
+ QObject::disconnect(chainBackstopConnection);
+
+ const PendingIntentChain chain = pendingChains.takeFirst();
+
+ // Only a failed or cancelled chain restores the session the link migrated
+ // away from; a successful one leaves the user where they are.
+ if (chain.pendingRestore && !chainSucceeded) {
+ restorePreviousServer(chain);
+ }
+
+ startNextChain();
+
+ // Only report the terminal state once the queue has fully drained, so a
+ // queued follow-up link keeps the startup fallback out of the picture.
+ if (!chainRunning && pendingChains.isEmpty()) {
+ emit urlChainFinished(mainWindow->getRemoteClient()->getStatus() == StatusLoggedIn);
+ }
+}
+
+void IntentUrlParser::onChainIntentDestroyed()
+{
+ if (!chainRunning) {
+ return;
+ }
+ qCWarning(UrlParserLog) << "Share-link intent destroyed without a terminal signal; ending its chain";
+ chainEnded(false);
+}
+
+void IntentUrlParser::restorePreviousServer(const PendingIntentChain &chain)
+{
+ if (chain.previousServerHost.isEmpty()) {
+ return;
+ }
+
+ RemoteClient *client = mainWindow->getRemoteClient();
+ const ClientStatus status = client->getStatus();
+
+ // A failed/cancelled chain can fire while the client is still settling the
+ // in-flight connection attempt (wrong password, connect timeout). Only
+ // decide once the client has settled into logged-in or disconnected;
+ // deciding mid-connect would strand the user offline from their previous
+ // server.
+ if (status == StatusDisconnected || status == StatusLoggedIn) {
+ restoreToPreviousServer(chain);
+ return;
+ }
+ auto waitConnection = std::make_shared();
+ *waitConnection = connect(client, &RemoteClient::statusChanged, this, [this, chain, client, waitConnection]() {
+ const ClientStatus settled = client->getStatus();
+ if (settled == StatusDisconnected || settled == StatusLoggedIn) {
+ QObject::disconnect(*waitConnection);
+ restoreToPreviousServer(chain);
+ }
+ });
+}
+
+void IntentUrlParser::restoreToPreviousServer(const PendingIntentChain &chain)
+{
+ RemoteClient *client = mainWindow->getRemoteClient();
+
+ // Back on the previous server already → nothing to undo.
+ if (client->serverName().compare(chain.previousServerHost, Qt::CaseInsensitive) == 0 &&
+ QString::number(client->serverPort()) == chain.previousServerPort) {
+ return;
+ }
+
+ // When logged in somewhere, only intervene if that somewhere is the server
+ // the link moved us to; if the user went elsewhere on their own, leave them.
+ if (client->getStatus() == StatusLoggedIn) {
+ const bool onMigrationTarget =
+ client->serverName().compare(chain.migrationTargetHost, Qt::CaseInsensitive) == 0 &&
+ QString::number(client->serverPort()) == chain.migrationTargetPort;
+ if (!onMigrationTarget) {
+ return;
+ }
+
+ ServersSettings &servers = SettingsCache::instance().servers();
+ const int index = servers.findServerIndex(chain.previousServerHost, chain.previousServerPort);
+ if (index >= 0 && servers.hasLoginData(chain.previousServerHost, chain.previousServerPort)) {
+ const QString username =
+ servers.getValue(QString("username%1").arg(index), "server", "server_details").toString();
+ const QString password =
+ servers.getValue(QString("password%1").arg(index), "server", "server_details").toString();
+ client->connectToServer(chain.previousServerHost, chain.previousServerPort.toUInt(), username, password);
+ return;
+ }
+ client->disconnectFromServer();
+ return;
+ }
+
+ if (client->getStatus() != StatusDisconnected) {
+ return;
+ }
+
+ // The link's connection attempt failed: reconnect to the previous server
+ // when credentials are saved, otherwise stay offline.
+ ServersSettings &servers = SettingsCache::instance().servers();
+ const int index = servers.findServerIndex(chain.previousServerHost, chain.previousServerPort);
+ if (index >= 0 && servers.hasLoginData(chain.previousServerHost, chain.previousServerPort)) {
+ const QString username =
+ servers.getValue(QString("username%1").arg(index), "server", "server_details").toString();
+ const QString password =
+ servers.getValue(QString("password%1").arg(index), "server", "server_details").toString();
+ client->connectToServer(chain.previousServerHost, chain.previousServerPort.toUInt(), username, password);
+ }
+}
diff --git a/cockatrice/src/interface/intents/url_parser.h b/cockatrice/src/interface/intents/url_parser.h
index 6d705e013..ea29fed53 100644
--- a/cockatrice/src/interface/intents/url_parser.h
+++ b/cockatrice/src/interface/intents/url_parser.h
@@ -1,10 +1,46 @@
#ifndef COCKATRICE_URL_PARSER_H
#define COCKATRICE_URL_PARSER_H
+
+#include
#include
#include
+class Intent;
class MainWindow;
struct ContextJoinGame;
+
+/**
+ * @brief One queued intent chain with the session-migration bookkeeping for it.
+ *
+ * The restore fields are per-chain on purpose: chains are parsed while earlier
+ * ones are still queued, so parser-wide state would let one chain's failure
+ * consume the restore data another chain recorded.
+ */
+struct PendingIntentChain
+{
+ QList intents;
+
+ // Snapshot of the session in place when this chain started running, so a
+ // queued chain follows whichever server the chain before it settled on.
+ QString previousServerHost;
+ QString previousServerPort;
+
+ // Recorded at parse time when the user confirmed migrating away from a live
+ // session to the host/port named by the link.
+ QString migrationTargetHost;
+ QString migrationTargetPort;
+ bool pendingRestore = false;
+};
+
+/**
+ * @brief Parses cockatrice:// links and runs them as serialized intent chains.
+ *
+ * Links are parsed by action (joingame/opendeck) and translated into an intent
+ * chain. Chains are queued and run one at a time: a document can hand multiple
+ * links to the window while an earlier chain still connects, and running two
+ * connect chains concurrently tears the connection down. urlChainFinished is
+ * emitted once the queue has fully drained.
+ */
class IntentUrlParser : public QObject
{
Q_OBJECT
@@ -12,12 +48,28 @@ class IntentUrlParser : public QObject
public:
IntentUrlParser(QObject *parent, MainWindow *mainWindow);
void handle(const QString &urlStr);
- void handleJoinGame(const QUrlQuery &query);
+
+signals:
+ /** @brief Emitted when the last queued chain ended; carries whether the client is logged in. */
+ void urlChainFinished(bool connected);
private:
+ Intent *createJoinGameIntent(const QUrlQuery &query, PendingIntentChain &chain);
+ Intent *createOpenDeckIntent(const QUrlQuery &query, PendingIntentChain &chain);
QString generateJoinGameMessage(const ContextJoinGame &context, const QString &gameDescription);
+ [[nodiscard]] bool isConnectedTo(const QString &hostname, const QString &port) const;
+ void startNextChain();
+ void chainEnded(bool chainSucceeded);
+ void onChainIntentDestroyed();
+ void restorePreviousServer(const PendingIntentChain &chain);
+ void restoreToPreviousServer(const PendingIntentChain &chain);
MainWindow *mainWindow;
+ QList pendingChains;
+ bool chainRunning = false;
+ // Disconnects the destroyed-signal backstop once a chain ends, so an old
+ // intent's deferred deletion cannot end the chain that runs after it.
+ QMetaObject::Connection chainBackstopConnection;
};
#endif // COCKATRICE_URL_PARSER_H
diff --git a/cockatrice/src/interface/palette_editor/palette_editor_dialog.cpp b/cockatrice/src/interface/palette_editor/palette_editor_dialog.cpp
index 9cde72c01..d5a168708 100644
--- a/cockatrice/src/interface/palette_editor/palette_editor_dialog.cpp
+++ b/cockatrice/src/interface/palette_editor/palette_editor_dialog.cpp
@@ -1,6 +1,5 @@
#include "palette_editor_dialog.h"
-#include "../../client/settings/cache_settings.h"
#include "../theme_manager.h"
#include "palette_generator.h"
#include "palette_grid_widget.h"
@@ -11,31 +10,11 @@
#include
#include
#include
-#include
#include
-#include
#include
-#include
#include
#include
-#include
#include
-#include
-
-// Probe whether a directory is truly writable by trying to create and remove a
-// temporary file. QFileInfo::isWritable() on a directory is unreliable (notably
-// on Windows where UAC VirtualStore can make a system dir appear writable).
-static bool isDirReallyWritable(const QString &dirPath)
-{
- const QString probe = QDir(dirPath).absoluteFilePath(".cockatrice_write_test");
- QFile f(probe);
- if (!f.open(QIODevice::WriteOnly)) {
- return false;
- }
- f.close();
- f.remove();
- return true;
-}
PaletteEditorDialog::PaletteEditorDialog(const QString &_themeDirPath, const QString &_themeName, QWidget *parent)
: QDialog(parent), themeDirPath(_themeDirPath), themeName(_themeName)
@@ -46,14 +25,7 @@ PaletteEditorDialog::PaletteEditorDialog(const QString &_themeDirPath, const QSt
// Resolve a writable directory for saving. Built-in (Default / Fusion) and
// other read-only theme directories must be customised in the user-writable
// themes directory; otherwise the write would fail or be lost on upgrade.
- if (!themeDirPath.isEmpty() && isDirReallyWritable(themeDirPath)) {
- saveDir = themeDirPath;
- } else {
- saveDir = QDir(SettingsCache::instance().paths().getThemesPath()).absoluteFilePath(themeName);
- if (!QDir().mkpath(saveDir)) {
- qWarning() << "Failed to create palette save directory:" << saveDir;
- }
- }
+ saveDir = ThemeManager::writableThemeDir(themeName);
// Load both scheme configs upfront so switching is instant
loadSchemes();
@@ -214,7 +186,7 @@ void PaletteEditorDialog::retranslateUi()
resetBtn->setToolTip(tr("Discard unsaved edits and restore the last saved palette"));
saveBtn->setToolTip(tr("Write palette-%1.toml and reload the theme").arg(loadedScheme.toLower()));
- if (saveDir.isEmpty() || !isDirReallyWritable(saveDir)) {
+ if (saveDir.isEmpty() || !ThemeManager::isDirReallyWritable(saveDir)) {
saveBtn->setEnabled(false);
saveBtn->setToolTip(tr("Cannot save: this theme has no writable directory"));
}
@@ -297,7 +269,7 @@ void PaletteEditorDialog::onSave()
if (it.key() == loadedScheme) {
continue;
}
- if (it.value().colors == savedConfig.value(it.key()).colors) {
+ if (it.value() == savedConfig.value(it.key())) {
continue;
}
if (!ThemeManager::commitPalette(saveDir, it.key(), it.value())) {
@@ -308,7 +280,7 @@ void PaletteEditorDialog::onSave()
}
// Commit the active scheme last so the global colour scheme matches.
- if (workingConfig[loadedScheme].colors != savedConfig.value(loadedScheme).colors) {
+ if (workingConfig[loadedScheme] != savedConfig.value(loadedScheme)) {
if (!ThemeManager::commitPalette(saveDir, loadedScheme, workingConfig[loadedScheme])) {
QMessageBox::warning(this, tr("Save failed"),
tr("Could not write %1 to:\n%2").arg(PaletteConfig::fileName(loadedScheme), saveDir));
diff --git a/cockatrice/src/interface/palette_editor/palette_generator.cpp b/cockatrice/src/interface/palette_editor/palette_generator.cpp
index d30dd14f1..822e57250 100644
--- a/cockatrice/src/interface/palette_editor/palette_generator.cpp
+++ b/cockatrice/src/interface/palette_editor/palette_generator.cpp
@@ -150,6 +150,17 @@ PaletteConfig fromAccent(const QColor &accent, int intensity, const QString &sch
cfg.colors[CG::Disabled][CR::HighlightedText] = disText;
cfg.colors[CG::Inactive][CR::HighlightedText] = dark ? Qt::white : Qt::black;
+ // Accent: same primary hue as Highlight, so palettes derived from a
+ // QuickSetup accent always carry a matching Accent role.
+#if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
+ set3(CR::Accent, hl, disText, hl);
+#endif
+
+ // Application role colors: Strong tracks the primary accent, while Soft is
+ // the lightened, desaturated companion used for button-gradient highlights.
+ cfg.appColors[AppColor::AccentStrong] = hl;
+ cfg.appColors[AppColor::AccentSoft] = hsl(accent.lightness() + 60, qRound(accent.hslSaturation() * 70 / 100.0));
+
// BrightText
QColor bright;
if (achromatic) {
diff --git a/cockatrice/src/interface/palette_editor/palette_grid_widget.cpp b/cockatrice/src/interface/palette_editor/palette_grid_widget.cpp
index 67294cd98..97d28b731 100644
--- a/cockatrice/src/interface/palette_editor/palette_grid_widget.cpp
+++ b/cockatrice/src/interface/palette_editor/palette_grid_widget.cpp
@@ -1,5 +1,7 @@
#include "palette_grid_widget.h"
+#include "../theme_manager.h"
+
#include
#include
#include
@@ -45,6 +47,11 @@ static const QMap ROLE_DESCRIPTIONS = {
{QPalette::Shadow, QT_TR_NOOP("Very dark shadow colour")},
};
+static const QMap APP_ROLE_DESCRIPTIONS = {
+ {AppColor::AccentStrong, QT_TR_NOOP("Vivid primary accent (e.g. home-tab button gradient start)")},
+ {AppColor::AccentSoft, QT_TR_NOOP("Lightened, desaturated accent (e.g. home-tab button gradient end)")},
+};
+
PaletteGridWidget::PaletteGridWidget(QWidget *parent) : QWidget(parent)
{
scroll = new QScrollArea(this);
@@ -122,6 +129,46 @@ void PaletteGridWidget::buildGrid(QWidget *host)
grid->addWidget(btn, row + 1, col + 1, Qt::AlignHCenter | Qt::AlignVCenter);
}
}
+
+ // Application color section: one ColorButton per role below the role grid.
+ // These are not tied to a color group, so a single button spans the row.
+ QMetaEnum appEnum = QMetaEnum::fromType();
+
+ const int appHeaderRow = roles.size() + 1;
+
+ auto *appHeader = new QLabel(tr("App colors"), host);
+ appHeader->setToolTip(tr("Application-specific colors layered on top of the Qt palette"));
+ QFont appHeaderFont = appHeader->font();
+ appHeaderFont.setBold(true);
+ appHeader->setFont(appHeaderFont);
+ appHeader->setAutoFillBackground(true);
+ appHeader->setContentsMargins(4, 4, 4, 4);
+ grid->addWidget(appHeader, appHeaderRow, 0, 1, 4);
+ headerLabels.append(appHeader);
+
+ for (int i = 0; i < appEnum.keyCount(); ++i) {
+ auto role = static_cast(appEnum.value(i));
+ const int row = appHeaderRow + 1 + i;
+
+ if (i % 2 == 0) {
+ for (int col = 0; col < 4; ++col) {
+ auto *shade = new QWidget(host);
+ shade->setAutoFillBackground(true);
+ grid->addWidget(shade, row, col);
+ rowShadeWidgets.push_back(shade);
+ }
+ }
+
+ auto *label = new QLabel(QString(appEnum.valueToKey(role)), host);
+ label->setToolTip(APP_ROLE_DESCRIPTIONS.value(role, {}));
+ label->setContentsMargins(4, 2, 8, 2);
+ grid->addWidget(label, row, 0);
+
+ auto *btn = new ColorButton(host);
+ connect(btn, &ColorButton::colorChanged, this, [this] { emit paletteChanged(); });
+ appColorButtons[role] = btn;
+ grid->addWidget(btn, row, 1, Qt::AlignHCenter | Qt::AlignVCenter);
+ }
}
void PaletteGridWidget::changeEvent(QEvent *e)
@@ -166,6 +213,16 @@ void PaletteGridWidget::loadPalette(const PaletteConfig &cfg)
colorButtons[group][role]->setColor(color);
}
}
+
+ QMetaEnum appEnum = QMetaEnum::fromType();
+ for (int i = 0; i < appEnum.keyCount(); ++i) {
+ auto role = static_cast(appEnum.value(i));
+ QColor color = cfg.appColors.value(role);
+ if (!color.isValid()) {
+ color = themeManager->appColor(role);
+ }
+ appColorButtons[role]->setColor(color);
+ }
}
PaletteConfig PaletteGridWidget::currentPaletteConfig() const
@@ -176,5 +233,12 @@ PaletteConfig PaletteGridWidget::currentPaletteConfig() const
cfg.colors[group][role] = colorButtons[group][role]->getColor();
}
}
+
+ QMetaEnum appEnum = QMetaEnum::fromType();
+ for (int i = 0; i < appEnum.keyCount(); ++i) {
+ auto role = static_cast(appEnum.value(i));
+ cfg.appColors[role] = appColorButtons[role]->getColor();
+ }
+
return cfg;
}
\ No newline at end of file
diff --git a/cockatrice/src/interface/palette_editor/palette_grid_widget.h b/cockatrice/src/interface/palette_editor/palette_grid_widget.h
index 1a665971a..77cbf1c62 100644
--- a/cockatrice/src/interface/palette_editor/palette_grid_widget.h
+++ b/cockatrice/src/interface/palette_editor/palette_grid_widget.h
@@ -31,6 +31,7 @@ private:
void refreshChromePalettes();
QMap> colorButtons;
+ QMap appColorButtons;
QScrollArea *scroll;
QWidget *gridHost;
QVBoxLayout *layout;
diff --git a/cockatrice/src/interface/pixel_map_generator.cpp b/cockatrice/src/interface/pixel_map_generator.cpp
index 9b8c4bcdc..b70dc576f 100644
--- a/cockatrice/src/interface/pixel_map_generator.cpp
+++ b/cockatrice/src/interface/pixel_map_generator.cpp
@@ -1,5 +1,7 @@
#include "pixel_map_generator.h"
+#include "theme_manager.h"
+
#include
#include
#include
@@ -82,7 +84,13 @@ static QPixmap loadSvg(const QString &svgPath, const QSize &size, bool expandOnl
/**
* Try to load path image from non-SVG formats, otherwise fall back to SVG.
* This is to allow custom themes to support non-SVG format type overrides, since SVG requires custom loading.
- * @param path The path to the file, with no file extension. File formats will be automatically detected.
+ *
+ * The path may already carry the resolved file extension (e.g. via
+ * ThemeManager::assetPath); such paths are loaded directly. Otherwise a
+ * format-agnostic lookup probes png, jpg and finally svg.
+ *
+ * @param path The path to the file, with no file extension unless the caller
+ * already resolved it. File formats will be automatically detected.
* @param size The desired size of the pixmap.
* @param expandOnly If true, then keep the size of the initial pixmap to at least the size (Only relevant if SVG).
*
@@ -90,6 +98,19 @@ static QPixmap loadSvg(const QString &svgPath, const QSize &size, bool expandOnl
*/
static QPixmap tryLoadImage(const QString &path, const QSize &size, bool expandOnly = false)
{
+ if (path.endsWith(QLatin1String(".svg"), Qt::CaseInsensitive)) {
+ return loadSvg(path, size, expandOnly);
+ }
+ if (path.endsWith(QLatin1String(".png"), Qt::CaseInsensitive) ||
+ path.endsWith(QLatin1String(".jpg"), Qt::CaseInsensitive) ||
+ path.endsWith(QLatin1String(".jpeg"), Qt::CaseInsensitive)) {
+ QPixmap pix(path);
+ if (!pix.isNull()) {
+ return pix.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
+ }
+ return {};
+ }
+
const auto formats = {"png", "jpg"};
QPixmap returnPixmap;
@@ -111,7 +132,8 @@ QPixmap PhasePixmapGenerator::generatePixmap(int height, QString name)
return pmCache.value(key);
}
- QPixmap pixmap = tryLoadImage("theme:phases/" + name, QSize(height, height));
+ QPixmap pixmap = tryLoadImage(QStringLiteral("theme:") + themeManager->assetPath(QStringLiteral("phases/") + name),
+ QSize(height, height));
pmCache.insert(key, pixmap);
return pixmap;
@@ -339,6 +361,10 @@ static QString getIconType(const bool isBuddy, const UserLevelFlags &userLevelFl
return "pawn_judge";
}
+ if (userLevelFlags.testFlag(ServerInfo_User::IsDeveloper)) {
+ return "pawn_dev";
+ }
+
if (!privLevel.isEmpty() && privLevel.toLower() != "none") {
return QString("pawn_%1").arg(privLevel.toLower());
}
@@ -396,7 +422,8 @@ QPixmap LockPixmapGenerator::generatePixmap(int height)
return pmCache.value(key);
}
- QPixmap pixmap = tryLoadImage("theme:icons/lock", QSize(height, height), true);
+ QPixmap pixmap = tryLoadImage(QStringLiteral("theme:") + themeManager->assetPath(QStringLiteral("icons/lock")),
+ QSize(height, height), true);
pmCache.insert(key, pixmap);
return pixmap;
}
@@ -411,7 +438,8 @@ QPixmap DropdownIconPixmapGenerator::generatePixmap(int height, bool expanded)
}
QString name = expanded ? "dropdown_expanded" : "dropdown_collapsed";
- QPixmap pixmap = tryLoadImage("theme:icons/" + name, QSize(height, height), true);
+ QPixmap pixmap = tryLoadImage(QStringLiteral("theme:") + themeManager->assetPath(QStringLiteral("icons/") + name),
+ QSize(height, height), true);
pmCache.insert(key, pixmap);
return pixmap;
@@ -472,6 +500,13 @@ QHash ManaSymbolPixmapGenerator::scaledCache;
QPixmap loadColorAdjustedPixmap(const QString &name)
{
+ // Prefer an authored scheme-qualified variant when one exists for this asset.
+ const QString variant = themeManager->schemeVariantPath(QStringView(name).mid(QStringLiteral("theme:").size()));
+ if (!variant.isEmpty()) {
+ return QPixmap(QStringLiteral("theme:") + variant);
+ }
+
+ // Legacy fallback: runtime-invert for dark mode when no authored variant.
if (qApp->palette().windowText().color().lightness() > 200) {
QImage img(name);
img.invertPixels();
@@ -482,3 +517,21 @@ QPixmap loadColorAdjustedPixmap(const QString &name)
return QPixmap(name);
}
}
+
+QPixmap themePixmap(QStringView prefix)
+{
+ const QString resolved = themeManager->assetPath(prefix);
+ return QPixmap(QStringLiteral("theme:") + resolved);
+}
+
+void clearPixmapGeneratorCaches()
+{
+ PhasePixmapGenerator::clear();
+ CounterPixmapGenerator::clear();
+ PingPixmapGenerator::clear();
+ CountryPixmapGenerator::clear();
+ UserLevelPixmapGenerator::clear();
+ LockPixmapGenerator::clear();
+ DropdownIconPixmapGenerator::clear();
+ ManaSymbolPixmapGenerator::clear();
+}
diff --git a/cockatrice/src/interface/pixel_map_generator.h b/cockatrice/src/interface/pixel_map_generator.h
index 17720166a..b6e822fd9 100644
--- a/cockatrice/src/interface/pixel_map_generator.h
+++ b/cockatrice/src/interface/pixel_map_generator.h
@@ -156,4 +156,15 @@ public:
QPixmap loadColorAdjustedPixmap(const QString &name);
+// Loads a "theme:" asset (with no file extension in prefix), preferring the
+// scheme-qualified variant (prefix-dark / prefix-light, resolved via
+// ThemeManager::assetPath) and falling back to the plain asset. Callers load
+// the returned path directly. Use for scheme-sensitive pixmaps like
+// backgrounds, the card back, and the app logo.
+QPixmap themePixmap(QStringView prefix);
+
+// Clears every PixmapGenerator's static cache so scheme variants are
+// re-resolved when the active theme or color scheme changes.
+void clearPixmapGeneratorCaches();
+
#endif
diff --git a/cockatrice/src/interface/theme_config.cpp b/cockatrice/src/interface/theme_config.cpp
index 3c43c467d..8293a82cf 100644
--- a/cockatrice/src/interface/theme_config.cpp
+++ b/cockatrice/src/interface/theme_config.cpp
@@ -16,7 +16,7 @@ QString ThemeConfig::toIni() const
out += "[Appearance]\n";
out += QString("ColorScheme = %1\n").arg(colorScheme.isEmpty() ? "System" : colorScheme);
out += "\n[Style]\n";
- out += QString("Name = %1\n").arg(styleName.isEmpty() ? "Default" : styleName);
+ out += QString("Name = %1\n").arg(styleName.isEmpty() ? "System" : styleName);
return out;
}
@@ -96,7 +96,7 @@ bool ThemeConfig::save(const QString &themeDirPath) const
bool PaletteConfig::hasPalette() const
{
- return !colors.isEmpty();
+ return !colors.isEmpty() || !appColors.isEmpty();
}
QString PaletteConfig::toToml() const
@@ -133,6 +133,24 @@ QString PaletteConfig::toToml() const
out += "\n";
}
+ if (!appColors.isEmpty()) {
+ QMetaEnum appEnum = QMetaEnum::fromType();
+
+ out += "[AppColors]\n";
+
+ for (auto it = appColors.cbegin(); it != appColors.cend(); ++it) {
+ const char *roleName = appEnum.valueToKey(it.key());
+
+ if (!roleName) {
+ continue;
+ }
+
+ out += QString("%1 = %2\n").arg(QString(roleName), -20).arg(it.value().name(QColor::HexArgb));
+ }
+
+ out += "\n";
+ }
+
return out;
}
@@ -152,6 +170,7 @@ PaletteConfig PaletteConfig::fromFile(const QString &filePath)
}
QMetaEnum roleEnum = QMetaEnum::fromType();
+ QMetaEnum appEnum = QMetaEnum::fromType();
QString currentSection;
QPalette::ColorGroup currentGroup = QPalette::Active;
@@ -202,6 +221,26 @@ PaletteConfig PaletteConfig::fromFile(const QString &filePath)
}
}
+ QColor color(value);
+
+ if (!color.isValid()) {
+ continue;
+ }
+
+ if (currentSection.compare("AppColors", Qt::CaseInsensitive) == 0) {
+ if (key.startsWith("AppColor::")) {
+ key = key.mid(10);
+ }
+
+ int appRoleInt = appEnum.keyToValue(key.toUtf8().constData());
+
+ if (appRoleInt >= 0) {
+ cfg.appColors[static_cast(appRoleInt)] = color;
+ }
+
+ continue;
+ }
+
if (!currentSection.startsWith("Palette", Qt::CaseInsensitive)) {
continue;
}
@@ -216,11 +255,7 @@ PaletteConfig PaletteConfig::fromFile(const QString &filePath)
continue;
}
- QColor color(value);
-
- if (color.isValid()) {
- cfg.colors[currentGroup][static_cast(roleInt)] = color;
- }
+ cfg.colors[currentGroup][static_cast(roleInt)] = color;
}
return cfg;
diff --git a/cockatrice/src/interface/theme_config.h b/cockatrice/src/interface/theme_config.h
index 07bf55b7a..567aeccda 100644
--- a/cockatrice/src/interface/theme_config.h
+++ b/cockatrice/src/interface/theme_config.h
@@ -3,9 +3,25 @@
#include
#include
+#include
#include
#include
+// Application-specific color roles, layered on top of the fixed QPalette role
+// set. Stored in the same palette-.toml under an [AppColors] section
+// and editable from the palette editor, so theme authors can control colors
+// beyond what Qt's palette can express.
+namespace AppColor
+{
+Q_NAMESPACE
+enum Role
+{
+ AccentStrong,
+ AccentSoft,
+};
+Q_ENUM_NS(Role)
+} // namespace AppColor
+
struct ThemeConfig
{
QString colorScheme;
@@ -21,7 +37,16 @@ struct ThemeConfig
struct PaletteConfig
{
QMap> colors;
+ QMap