diff --git a/.ci/Debian11/Dockerfile b/.ci/Debian11/Dockerfile
deleted file mode 100644
index b994863bf..000000000
--- a/.ci/Debian11/Dockerfile
+++ /dev/null
@@ -1,26 +0,0 @@
-FROM debian:11
-
-RUN apt-get update && \
- DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
- build-essential \
- ccache \
- clang-format \
- cmake \
- file \
- g++ \
- git \
- liblzma-dev \
- libmariadb-dev-compat \
- libprotobuf-dev \
- libqt5multimedia5-plugins \
- libqt5sql5-mysql \
- libqt5svg5-dev \
- libqt5websockets5-dev \
- ninja-build \
- protobuf-compiler \
- qt5-image-formats-plugins \
- qtmultimedia5-dev \
- qttools5-dev \
- qttools5-dev-tools \
- && apt-get clean \
- && rm -rf /var/lib/apt/lists/*
diff --git a/.ci/Fedora42/Dockerfile b/.ci/Fedora44/Dockerfile
similarity index 95%
rename from .ci/Fedora42/Dockerfile
rename to .ci/Fedora44/Dockerfile
index ee4a856f2..e6c8da7f3 100644
--- a/.ci/Fedora42/Dockerfile
+++ b/.ci/Fedora44/Dockerfile
@@ -1,4 +1,4 @@
-FROM fedora:42
+FROM fedora:44
RUN dnf install -y \
ccache \
diff --git a/.ci/Servatrice_Debian11/Dockerfile b/.ci/Servatrice_Debian12/Dockerfile
similarity index 75%
rename from .ci/Servatrice_Debian11/Dockerfile
rename to .ci/Servatrice_Debian12/Dockerfile
index fadc9e0e7..21f6a036e 100644
--- a/.ci/Servatrice_Debian11/Dockerfile
+++ b/.ci/Servatrice_Debian12/Dockerfile
@@ -1,4 +1,4 @@
-FROM debian:11
+FROM debian:12
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
@@ -11,11 +11,11 @@ RUN apt-get update && \
git \
libmariadb-dev-compat \
libprotobuf-dev \
- libqt5sql5-mysql \
- libqt5websockets5-dev \
+ libqt6sql6-mysql \
ninja-build \
protobuf-compiler \
- qttools5-dev \
- qttools5-dev-tools \
+ qt6-tools-dev \
+ qt6-tools-dev-tools \
+ qt6-websockets-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
diff --git a/.ci/Ubuntu22.04/Dockerfile b/.ci/Ubuntu22.04/Dockerfile
deleted file mode 100644
index 93c8fdea9..000000000
--- a/.ci/Ubuntu22.04/Dockerfile
+++ /dev/null
@@ -1,26 +0,0 @@
-FROM ubuntu:22.04
-
-RUN apt-get update && \
- DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
- build-essential \
- ccache \
- clang-format \
- cmake \
- file \
- g++ \
- git \
- liblzma-dev \
- libmariadb-dev-compat \
- libprotobuf-dev \
- libqt5multimedia5-plugins \
- libqt5sql5-mysql \
- libqt5svg5-dev \
- libqt5websockets5-dev \
- ninja-build \
- protobuf-compiler \
- qt5-image-formats-plugins \
- qtmultimedia5-dev \
- qttools5-dev \
- qttools5-dev-tools \
- && apt-get clean \
- && rm -rf /var/lib/apt/lists/*
diff --git a/.ci/compile.sh b/.ci/compile.sh
index 7ebdd6e4e..ee846897b 100755
--- a/.ci/compile.sh
+++ b/.ci/compile.sh
@@ -203,7 +203,11 @@ if [[ $RUNNER_OS == macOS ]]; then
arch="x64"
fi
mkdir -p "$triplets_dir"
- cp "../vcpkg/triplets/$arch-osx.cmake" "$triplet_file"
+ triplet_source="../vcpkg/triplets/$arch-osx.cmake"
+ if [[ ! -f "$triplet_source" ]]; then
+ triplet_source="../vcpkg/triplets/community/$arch-osx.cmake"
+ fi
+ cp "$triplet_source" "$triplet_file"
echo "set(VCPKG_CMAKE_SYSTEM_VERSION $TARGET_MACOS_VERSION)" >>"$triplet_file"
echo "set(VCPKG_OSX_DEPLOYMENT_TARGET $TARGET_MACOS_VERSION)" >>"$triplet_file"
flags+=("-DVCPKG_OVERLAY_TRIPLETS=$triplets_dir")
diff --git a/.ci/lint_cpp.sh b/.ci/lint_cpp.sh
index cfb1e1f07..9786a83fc 100755
--- a/.ci/lint_cpp.sh
+++ b/.ci/lint_cpp.sh
@@ -13,17 +13,9 @@ fi
# Check formatting using format.sh
echo "Checking your code using format.sh..."
-diff="$(./format.sh --diff --cmake --shell --print-version --branch origin/master)"
+./format.sh --color-diff --cmake --shell --print-version --branch origin/master
err=$?
-sep="
-----------
-"
-used_version="${diff%%"$sep"*}"
-diff="${diff#*"$sep"}"
-changes_to_make="${diff%%"$sep"*}"
-files_to_edit="${diff#*"$sep"}"
-
case $err in
1)
cat < is the markdown comment escape sequence, emojis are way better
generated_list="${generated_list//-->/→}"
+ # Escape & to preserve it from commit message into markdown output
+ generated_list="${generated_list//&/\\&}"
body="${body//--REPLACE-WITH-GENERATED-LIST--/$generated_list}"
body="${body//--REPLACE-WITH-COMMIT-COUNT--/$count}"
body="${body//--REPLACE-WITH-PREVIOUS-RELEASE-TAG--/$previous}"
diff --git a/.ci/release_template.md b/.ci/release_template.md
index 1ce9f4bf7..ac78a193a 100644
--- a/.ci/release_template.md
+++ b/.ci/release_template.md
@@ -19,12 +19,10 @@ Available pre-compiled binaries for installation:
Linux
• Ubuntu 26.04 LTSResolute Racoon
• Ubuntu 24.04 LTSNoble Numbat
- • Ubuntu 22.04 LTSJammy Jellyfish
• Debian 13Trixie
• Debian 12Bookworm
- • Debian 11Bullseye
+ • Fedora 44
• Fedora 43
- • Fedora 42We are also packaged in Arch Linux's official extra repository, courtesy of @FFY00.General Linux support is available via a flatpak package at Flathub!
@@ -85,7 +83,6 @@ Remove empty headers when done.
### Under the Hood
### Oracle
### Servatrice
-### Webatrice
diff --git a/.clang-format b/.clang-format
index 1ef3ca6db..1db97481a 100644
--- a/.clang-format
+++ b/.clang-format
@@ -3,7 +3,9 @@ AccessModifierOffset: -4
ColumnLimit: 120
---
Language: Cpp
-BreakBeforeBraces: Custom
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortFunctionsOnASingleLine: None
+BinPackParameters: false
BraceWrapping:
AfterClass: true
AfterControlStatement: false
@@ -18,16 +20,14 @@ BraceWrapping:
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
-AllowShortFunctionsOnASingleLine: None
-BinPackParameters: false
-AllowAllParametersOfDeclarationOnNextLine: false
-IndentCaseLabels: true
-PointerAlignment: Right
-SortIncludes: true
+BreakBeforeBraces: Custom
IncludeBlocks: Regroup
+IndentCaseLabels: true
+InsertBraces: true
+PointerAlignment: Right
+RemoveSemicolon: true
+SortIncludes: true
StatementAttributeLikeMacros: [emit]
-# requires clang-format 16
-# RemoveSemicolon: true
---
Language: Proto
AllowShortFunctionsOnASingleLine: None
diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
index b293b3937..56ad64283 100644
--- a/.github/CONTRIBUTING.md
+++ b/.github/CONTRIBUTING.md
@@ -209,6 +209,16 @@ nowadays and clean it up for you.
Lines should be 120 characters or less. Please break up lines that are too long
into smaller parts, for example at spaces or after opening a brace.
+### Documentation Comments ###
+
+Use [Doxygen](https://www.doxygen.nl/) for code documentation:
+
+- **Doc blocks**: Use `/** @brief Description */` (Javadoc-style), not `///`
+- **Member comments**: Use trailing `///<` for inline member documentation
+- **TODOs**: Use `//! \todo Description` (Qt-style), Doxygen collects them into a Todo List
+ (uses [Qt-style comments](https://www.doxygen.nl/manual/docblocks.html) with
+ Doxygen's [\todo command](https://www.doxygen.nl/manual/commands.html#cmdtodo))
+
### Memory Management ###
New code should be written using references over pointers and stack allocation
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index 88bed3663..404cac62e 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -10,7 +10,7 @@ updates:
# Look for `.gitmodules` in the `root` directory
directory: "/"
ignore:
- # Ignore updates for vcpkg (Bump to latest tag not working (no SemVer used) & macOS Intel triplet broken with newer releases)
+ # Ignore updates for vcpkg (Bump to latest tag not working (no SemVer used)
- dependency-name: "vcpkg"
# Check for updates once a month
schedule:
@@ -39,13 +39,3 @@ updates:
interval: "weekly"
# Limit the amout of open PR's (default = 5, disabled = 0, security updates are not impacted)
open-pull-requests-limit: 2
-
- # # Enable version updates for npm
- # - package-ecosystem: "npm"
- # # Look for `package.json` and `lock` files in the `webclient` subdirectory
- # directory: "/webclient"
- # # Check the npm registry for updates once a week
- # schedule:
- # interval: "weekly"
- # # Limit the amout of open PR's (default = 5, disabled = 0, security updates are not impacted)
- # open-pull-requests-limit: 5
diff --git a/.github/workflows/desktop-build.yml b/.github/workflows/desktop-build.yml
index 3c8e915a8..19c9a15e3 100644
--- a/.github/workflows/desktop-build.yml
+++ b/.github/workflows/desktop-build.yml
@@ -1,10 +1,10 @@
name: Build Desktop
permissions:
+ actions: write # needed to delete entries in GHA cache (update ccache)
+ attestations: write # needed to persist the attestation.
contents: write
- id-token: write
- attestations: write
- actions: write # needed for ccache action to be able to delete gha caches
+ id-token: write # needed for signing certificate in attestation
on:
push:
@@ -14,14 +14,12 @@ on:
- '*/**' # matches all files not in root
- '!**.md'
- '!.github/**'
- - '!.husky/**'
- '!.tx/**'
- '!doc/**'
- - '!webclient/**'
- '.github/workflows/desktop-build.yml'
- 'CMakeLists.txt'
- 'vcpkg.json'
- - 'vcpkg'
+ - 'vcpkg' # needed to match submodule bumps (gitlink)
tags:
- '*'
pull_request:
@@ -29,14 +27,12 @@ on:
- '*/**' # matches all files not in root
- '!**.md'
- '!.github/**'
- - '!.husky/**'
- '!.tx/**'
- '!doc/**'
- - '!webclient/**'
- '.github/workflows/desktop-build.yml'
- 'CMakeLists.txt'
- 'vcpkg.json'
- - 'vcpkg'
+ - 'vcpkg' # needed to match submodule bumps (gitlink)
# Cancel earlier, unfinished runs of this workflow on the same branch (unless on release)
concurrency:
@@ -48,11 +44,11 @@ jobs:
name: Configure
runs-on: ubuntu-slim
outputs:
- tag: ${{steps.configure.outputs.tag}}
- sha: ${{steps.configure.outputs.sha}}
+ tag: ${{ steps.configure.outputs.tag }}
+ sha: ${{ steps.configure.outputs.sha }}
steps:
- - name: Configure
+ - name: "Configure"
id: configure
shell: bash
run: |
@@ -68,154 +64,150 @@ jobs:
fi
echo "sha=$sha" >>"$GITHUB_OUTPUT"
- - name: Checkout
+ - name: "Checkout"
if: steps.configure.outputs.tag != null
uses: actions/checkout@v6
with:
- fetch-depth: 0
+ fetch-depth: 0 # fetch all history for all branches and tags
- - name: Prepare release parameters
+ - name: "Prepare release parameters"
id: prepare
if: steps.configure.outputs.tag != null
shell: bash
env:
- TAG: ${{steps.configure.outputs.tag}}
+ TAG: ${{ steps.configure.outputs.tag }}
run: .ci/prep_release.sh
- - name: Create release
+ - name: "Create release"
if: steps.configure.outputs.tag != null
id: create_release
shell: bash
env:
- GH_TOKEN: ${{github.token}}
- tag_name: ${{steps.configure.outputs.tag}}
- target: ${{steps.configure.outputs.sha}}
- release_name: ${{steps.prepare.outputs.title}}
- body_path: ${{steps.prepare.outputs.body_path}}
- prerelease: ${{steps.prepare.outputs.is_beta}}
+ GH_TOKEN: ${{ github.token }}
+ tag_name: ${{ steps.configure.outputs.tag }}
+ target: ${{ steps.configure.outputs.sha }}
+ release_name: ${{ steps.prepare.outputs.title }}
+ body_path: ${{ steps.prepare.outputs.body_path }}
+ prerelease: ${{ steps.prepare.outputs.is_beta }}
run: |
- if [[ $prerelease == yes ]]; then
- args="--prerelease"
- fi
- gh release create "$tag_name" --draft --verify-tag $args \
- --target "$target" --title "$release_name" \
- --notes-file "$body_path"
+ args=()
+ [[ $prerelease == yes ]] && args+=(--prerelease)
+
+ gh release create "$tag_name" --verify-tag --draft "${args[@]}" \
+ --target "$target" \
+ --title "$release_name" \
+ --notes-file "$body_path"
build-linux:
strategy:
fail-fast: false
matrix:
- # These names correspond to the files in ".ci/$distro$version"
+ # The files in ".ci/$distro$version" correspond to the values given here
include:
- distro: Arch
- package: skip # We are packaged in Arch already
+
allow-failure: yes
-
- - distro: Debian
- version: 11
- package: DEB
+ package: skip # We are packaged in Arch already
- distro: Servatrice_Debian
- version: 11
+ version: 12
+
package: DEB
- test: skip
server_only: yes
+ test: skip
- distro: Debian
version: 12
+
package: DEB
test: skip # Running tests on all distros is superfluous
- distro: Debian
version: 13
+
package: DEB
- - distro: Fedora
- version: 42
- package: RPM
- test: skip # Running tests on all distros is superfluous
-
- distro: Fedora
version: 43
+
+ package: RPM
+ test: skip # Running tests on all distros is superfluous
+
+ - distro: Fedora
+ version: 44
+
package: RPM
- distro: Ubuntu
- version: 22.04
+ version: 24.04
+
package: DEB
test: skip # Running tests on all distros is superfluous
- - distro: Ubuntu
- version: 24.04
- package: DEB
-
- distro: Ubuntu
version: 26.04
+
package: DEB
- name: ${{matrix.distro}} ${{matrix.version}}
+ name: ${{ matrix.distro }} ${{ matrix.version }}
needs: configure
runs-on: ubuntu-latest
- continue-on-error: ${{matrix.allow-failure == 'yes'}}
+ continue-on-error: ${{ matrix.allow-failure == 'yes' }}
timeout-minutes: 70
env:
- NAME: ${{matrix.distro}}${{matrix.version}}
- CACHE: ${{github.workspace}}/.cache/${{matrix.distro}}${{matrix.version}} # directory for caching docker image and ccache
- # Cache size over the entire repo is 10Gi:
- # https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#usage-limits-and-eviction-policy
- CCACHE_SIZE: 550M
+ 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
CMAKE_GENERATOR: 'Ninja'
+ NAME: ${{ matrix.distro }}${{ matrix.version }}
steps:
- - name: Checkout
+ - name: "Checkout"
uses: actions/checkout@v6
- - name: Restore compiler cache (ccache)
+ - name: "Restore compiler cache (ccache)"
id: ccache_restore
uses: actions/cache/restore@v5
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
with:
- path: ${{env.CACHE}}
- key: ccache-${{matrix.distro}}${{matrix.version}}-${{env.BRANCH_NAME}}
- restore-keys: ccache-${{matrix.distro}}${{matrix.version}}-
+ key: ccache-${{ matrix.distro }}${{ matrix.version }}-${{ env.BRANCH_NAME }}
+ path: ${{ env.CACHE }}
+ restore-keys: ccache-${{ matrix.distro }}${{ matrix.version }}-
- - name: Build ${{matrix.distro}} ${{matrix.version}} Docker image
+ - name: "Build ${{ matrix.distro }} ${{ matrix.version }} Docker image"
shell: bash
run: source .ci/docker.sh --build
- - name: Build debug and test
+ - name: "Build debug and test"
if: matrix.test != 'skip'
shell: bash
run: |
source .ci/docker.sh
RUN --server --debug --test --ccache "$CCACHE_SIZE" \
- --cmake-generator "$CMAKE_GENERATOR"
+ --cmake-generator "$CMAKE_GENERATOR"
- - name: Build release package
+ - name: "Build release package"
id: build
if: matrix.package != 'skip'
shell: bash
env:
- SUFFIX: '-${{matrix.distro}}${{matrix.version}}'
- package: '${{matrix.package}}'
- server_only: '${{matrix.server_only}}'
+ SUFFIX: '-${{ matrix.distro }}${{ matrix.version }}'
+ package: '${{ matrix.package }}'
+ server_only: '${{ matrix.server_only }}'
run: |
source .ci/docker.sh
args=()
- if [[ $server_only == yes ]]; then
- args+=(--no-client)
- fi
- if [[ $GITHUB_REF == "refs/heads/master" ]]; then
- args+=(--evict-ccache "$CCACHE_EVICTION_AGE")
- fi
+ [[ $server_only == yes ]] && args+=(--no-client)
+ [[ $GITHUB_REF == "refs/heads/master" ]] && args+=(--evict-ccache "$CCACHE_EVICTION_AGE")
args+=(--ccache "$CCACHE_SIZE")
args+=(--cmake-generator "$CMAKE_GENERATOR")
args+=(--suffix "$SUFFIX")
+
RUN --server --release --package "$package" "${args[@]}"
# Delete used cache to emulate a ccache update. See https://github.com/actions/cache/issues/342
- - name: Delete remote compiler cache (ccache)
+ - name: "Delete remote compiler cache (ccache)"
if: github.ref == 'refs/heads/master' && steps.ccache_restore.outputs.cache-hit
continue-on-error: true
env:
@@ -225,47 +217,47 @@ jobs:
echo "Cache deleted successfully"
fi
- - name: Save updated compiler cache (ccache)
+ - name: "Save updated compiler cache (ccache)"
if: github.ref == 'refs/heads/master'
uses: actions/cache/save@v5
with:
- path: ${{env.CACHE}}
key: ${{ steps.ccache_restore.outputs.cache-primary-key }}
+ path: ${{ env.CACHE }}
- - name: Upload artifact
+ - name: "Upload artifact"
id: upload_artifact
if: matrix.package != 'skip'
uses: actions/upload-artifact@v7
with:
- path: ${{steps.build.outputs.path}}
archive: false
if-no-files-found: error
+ path: ${{ steps.build.outputs.path }}
- - name: Upload to release
+ - name: "Upload to release"
id: upload_release
if: matrix.package != 'skip' && needs.configure.outputs.tag != null
shell: bash
env:
- GH_TOKEN: ${{github.token}}
- tag_name: ${{needs.configure.outputs.tag}}
- asset_name: ${{steps.build.outputs.fullname}}
- asset_path: ${{steps.build.outputs.path}}
+ asset_name: ${{ steps.build.outputs.fullname }}
+ asset_path: ${{ steps.build.outputs.path }}
+ GH_TOKEN: ${{ github.token }}
+ tag_name: ${{ needs.configure.outputs.tag }}
run: gh release upload "$tag_name" "$asset_path#$asset_name"
- - name: Attest binary provenance
+ - name: "Attest binary provenance"
id: attestation
if: steps.upload_release.outcome == 'success'
uses: actions/attest@v4
with:
- subject-path: ${{steps.build.outputs.path}}
show-summary: false
+ subject-path: ${{ steps.build.outputs.path }}
- - name: Verify binary attestation
+ - name: "Verify binary attestation"
if: steps.attestation.outcome == 'success'
shell: bash
env:
- GH_TOKEN: ${{github.token}}
- run: gh attestation verify ${{steps.build.outputs.path}} --repo Cockatrice/Cockatrice
+ GH_TOKEN: ${{ github.token }}
+ run: gh attestation verify "${{ steps.build.outputs.path }}" --repo Cockatrice/Cockatrice
build-vcpkg:
strategy:
@@ -275,200 +267,202 @@ jobs:
- os: macOS
target: 13
runner: macos-15-intel
- soc: Intel
- xcode: "16.4"
- type: Release
- override_target: 13
+
+ ccache_eviction_age: 7d
+ cmake_generator: Ninja
make_package: 1
+ override_target: 13
package_suffix: "-macOS13_Intel"
- qt_version: 6.11.*
+ qt_version: 6.11.0
qt_arch: clang_64
qt_modules: qtimageformats qtmultimedia qtwebsockets
- cmake_generator: Ninja
+ soc: Intel
+ type: Release
use_ccache: 1
- ccache_eviction_age: 7d
+ xcode: "16.4"
- os: macOS
target: 14
runner: macos-14
- soc: Apple
- xcode: "15.4"
- type: Release
+
+ ccache_eviction_age: 7d
+ cmake_generator: Ninja
make_package: 1
package_suffix: "-macOS14"
- qt_version: 6.11.*
+ qt_version: 6.11.0
qt_arch: clang_64
qt_modules: qtimageformats qtmultimedia qtwebsockets
- cmake_generator: Ninja
+ soc: Apple
+ type: Release
use_ccache: 1
- ccache_eviction_age: 7d
+ xcode: "15.4"
- os: macOS
target: 15
runner: macos-15
- soc: Apple
- xcode: "16.4"
- type: Release
+
+ ccache_eviction_age: 7d
+ cmake_generator: Ninja
make_package: 1
package_suffix: "-macOS15"
- qt_version: 6.11.*
+ qt_version: 6.11.0
qt_arch: clang_64
qt_modules: qtimageformats qtmultimedia qtwebsockets
- cmake_generator: Ninja
+ soc: Apple
+ type: Release
use_ccache: 1
- ccache_eviction_age: 7d
+ xcode: "16.4"
- os: macOS
target: 15
runner: macos-15
- soc: Apple
- xcode: "16.4"
- type: Debug
- qt_version: 6.11.*
+
+ ccache_eviction_age: 7d
+ cmake_generator: Ninja
+ qt_version: 6.11.0
qt_arch: clang_64
qt_modules: qtimageformats qtmultimedia qtwebsockets
- cmake_generator: Ninja
+ soc: Apple
+ type: Debug
use_ccache: 1
- ccache_eviction_age: 7d
+ xcode: "16.4"
- os: Windows
target: 10
runner: windows-2025
- type: Release
- make_package: 1
- package_suffix: "-Win10"
- qt_version: 6.11.*
- qt_arch: win64_msvc2022_64
- qt_modules: qtimageformats qtmultimedia qtwebsockets
+
cmake_generator: "Visual Studio 17 2022"
cmake_generator_platform: x64
+ make_package: 1
+ package_suffix: "-Win10"
+ qt_version: 6.11.0
+ qt_arch: win64_msvc2022_64
+ qt_modules: qtimageformats qtmultimedia qtwebsockets
+ type: Release
- name: ${{matrix.os}} ${{matrix.target}}${{ matrix.soc == 'Intel' && ' Intel' || '' }}${{ matrix.type == 'Debug' && ' Debug' || '' }}
+ name: ${{ matrix.os }} ${{ matrix.target }}${{ matrix.soc == 'Intel' && ' Intel' || '' }}${{ matrix.type == 'Debug' && ' Debug' || '' }}
needs: configure
- runs-on: ${{matrix.runner}}
+ runs-on: ${{ matrix.runner }}
timeout-minutes: 100
env:
- CCACHE_DIR: ${{github.workspace}}/.cache/
- # Cache size over the entire repo is 10Gi:
- # https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#usage-limits-and-eviction-policy
- CCACHE_SIZE: 550M
+ 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
steps:
- - name: Checkout
+ - name: "Checkout"
uses: actions/checkout@v6
with:
submodules: recursive
- - name: Add msbuild to PATH
+ - name: "[Windows] Add msbuild to PATH"
if: matrix.os == 'Windows'
id: add-msbuild
uses: microsoft/setup-msbuild@v3
with:
msbuild-architecture: x64
- - name: Setup ccache
- if: matrix.use_ccache == 1 && matrix.os == 'macOS'
+ - name: "[macOS] Setup ccache"
+ if: matrix.os == 'macOS' && matrix.use_ccache == 1
run: brew install ccache
- - name: Restore compiler cache (ccache)
- if: matrix.use_ccache == 1
+ - name: "[macOS] Restore compiler cache (ccache)"
+ if: matrix.os == 'macOS' && matrix.use_ccache == 1
id: ccache_restore
uses: actions/cache/restore@v5
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
with:
- path: ${{env.CCACHE_DIR}}
- key: ccache-${{matrix.runner}}-${{matrix.soc}}-${{matrix.type}}-${{env.BRANCH_NAME}}
- restore-keys: ccache-${{matrix.runner}}-${{matrix.soc}}-${{matrix.type}}-
+ key: ccache-${{ matrix.runner }}-${{ matrix.soc }}-${{ matrix.type }}-${{ env.BRANCH_NAME }}
+ path: ${{ env.CCACHE_DIR }}
+ restore-keys: ccache-${{ matrix.runner }}-${{ matrix.soc }}-${{ matrix.type }}-
- - name: Install aqtinstall
+ - name: "Install aqtinstall"
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: "Resolve latest Qt patch version"
id: resolve_qt_version
shell: bash
- run: .ci/resolve_latest_aqt_qt_version.sh "${{matrix.qt_version}}"
+ run: .ci/resolve_latest_aqt_qt_version.sh "${{ matrix.qt_version }}"
- - name: Restore thin Qt ${{ steps.resolve_qt_version.outputs.version }} libraries (${{ matrix.soc }} macOS)
+ - name: "[macOS] Restore thin Qt ${{ steps.resolve_qt_version.outputs.version }} libraries"
if: matrix.os == 'macOS'
id: restore_qt
uses: actions/cache/restore@v5
with:
- path: ${{ github.workspace }}/Qt
key: thin-qt-macos-${{ matrix.soc }}-${{ steps.resolve_qt_version.outputs.version }}
+ path: ${{ github.workspace }}/Qt
# 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: Install fat Qt ${{ steps.resolve_qt_version.outputs.version }} (${{ matrix.soc }} macOS)
+ # Qt build using vcpkg either just fails or takes too long to build
+ - name: "[macOS] Install fat Qt ${{ steps.resolve_qt_version.outputs.version }}"
if: matrix.os == 'macOS' && steps.restore_qt.outputs.cache-hit != 'true'
uses: jurplel/install-qt-action@v4
with:
- version: ${{ steps.resolve_qt_version.outputs.version }}
- arch: ${{matrix.qt_arch}}
- modules: ${{matrix.qt_modules}}
+ arch: ${{ matrix.qt_arch }}
cache: false
- dir: ${{github.workspace}}
+ dir: ${{ github.workspace }}
+ modules: ${{ matrix.qt_modules }}
+ version: ${{ steps.resolve_qt_version.outputs.version }}
- - name: Thin Qt libraries (${{ matrix.soc }} macOS)
+ - name: "[macOS] Create thin Qt libraries"
if: matrix.os == 'macOS' && steps.restore_qt.outputs.cache-hit != 'true'
run: .ci/thin_macos_qtlib.sh
- - name: Cache thin Qt libraries (${{ matrix.soc }} macOS)
+ - name: "[macOS] Cache thin Qt libraries"
if: matrix.os == 'macOS' && steps.restore_qt.outputs.cache-hit != 'true'
uses: actions/cache/save@v5
with:
- path: ${{ github.workspace }}/Qt
key: thin-qt-macos-${{ matrix.soc }}-${{ steps.resolve_qt_version.outputs.version }}
+ path: ${{ github.workspace }}/Qt
- - name: Install Qt ${{matrix.qt_version}} (Windows)
+ - name: "[Windows] Install Qt ${{ matrix.qt_version }}"
if: matrix.os == 'Windows'
uses: jurplel/install-qt-action@v4
with:
- # qt 6.11.0 only works with aqtinstall directly from git until aqtinstall 3.4 is released
+ # 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
- version: ${{ steps.resolve_qt_version.outputs.version }}
- arch: ${{matrix.qt_arch}}
- modules: ${{matrix.qt_modules}}
+ arch: ${{ matrix.qt_arch }}
cache: true
+ modules: ${{ matrix.qt_modules }}
+ version: ${{ steps.resolve_qt_version.outputs.version }}
- - name: Install NSIS
+ - name: "[Windows] Install NSIS"
if: matrix.os == 'Windows'
shell: bash
run: choco install nsis
- - name: Setup vcpkg cache
+ - name: "Setup vcpkg cache"
id: vcpkg-cache
uses: TAServers/vcpkg-cache@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
- # uses environment variables, see compile.sh for more details
- - name: Build Cockatrice
+ # Uses environment variables, see compile.sh for more details
+ - name: "Build Cockatrice"
id: build
shell: bash
env:
- BUILDTYPE: '${{matrix.type}}'
- MAKE_PACKAGE: '${{matrix.make_package}}'
- PACKAGE_SUFFIX: '${{matrix.package_suffix}}'
- CMAKE_GENERATOR: ${{matrix.cmake_generator}}
- CMAKE_GENERATOR_PLATFORM: ${{matrix.cmake_generator_platform}}
- USE_CCACHE: ${{matrix.use_ccache}}
- VCPKG_DISABLE_METRICS: 1
- VCPKG_BINARY_SOURCES: 'clear;files,${{ steps.vcpkg-cache.outputs.path }},readwrite'
- # macOS-specific environment variables, will be ignored on Windows
- MACOS_CERTIFICATE: ${{ secrets.PROD_MACOS_CERTIFICATE }}
- MACOS_CERTIFICATE_PWD: ${{ secrets.PROD_MACOS_CERTIFICATE_PWD }}
- MACOS_CERTIFICATE_NAME: ${{ secrets.PROD_MACOS_CERTIFICATE_NAME }}
- MACOS_CI_KEYCHAIN_PWD: ${{ secrets.PROD_MACOS_CI_KEYCHAIN_PWD }}
- DEVELOPER_DIR: '/Applications/Xcode_${{matrix.xcode}}.app/Contents/Developer'
- TARGET_MACOS_VERSION: ${{ matrix.override_target }}
+ BUILDTYPE: '${{ matrix.type }}'
CCACHE_EVICTION_AGE: ${{ matrix.ccache_eviction_age }}
+ CMAKE_GENERATOR: ${{ matrix.cmake_generator }}
+ CMAKE_GENERATOR_PLATFORM: ${{ matrix.cmake_generator_platform }}
+ DEVELOPER_DIR: '/Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer'
+ MACOS_CERTIFICATE: ${{ secrets.PROD_MACOS_CERTIFICATE }}
+ MACOS_CERTIFICATE_NAME: ${{ secrets.PROD_MACOS_CERTIFICATE_NAME }}
+ MACOS_CERTIFICATE_PWD: ${{ secrets.PROD_MACOS_CERTIFICATE_PWD }}
+ MACOS_CI_KEYCHAIN_PWD: ${{ secrets.PROD_MACOS_CI_KEYCHAIN_PWD }}
+ MAKE_PACKAGE: '${{ matrix.make_package }}'
+ 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_DISABLE_METRICS: 1
run: .ci/compile.sh --server --test --vcpkg
# Delete used cache to emulate a ccache update. See https://github.com/actions/cache/issues/342
- - name: Delete remote compiler cache (ccache)
- if: github.ref == 'refs/heads/master' && matrix.use_ccache == 1 && steps.ccache_restore.outputs.cache-hit
+ - name: "[macOS] Delete remote compiler cache (ccache)"
+ if: matrix.os == 'macOS' && matrix.use_ccache == 1 && github.ref == 'refs/heads/master' && steps.ccache_restore.outputs.cache-hit
continue-on-error: true
env:
GH_TOKEN: ${{ github.token }}
@@ -477,14 +471,14 @@ jobs:
echo "Cache deleted successfully"
fi
- - name: Save updated compiler cache (ccache)
- if: github.ref == 'refs/heads/master' && matrix.use_ccache == 1
+ - name: "[macOS] Save updated compiler cache (ccache)"
+ if: matrix.os == 'macOS' && matrix.use_ccache == 1 && github.ref == 'refs/heads/master'
uses: actions/cache/save@v5
with:
- path: ${{env.CCACHE_DIR}}
key: ${{ steps.ccache_restore.outputs.cache-primary-key }}
+ path: ${{ env.CCACHE_DIR }}
- - name: Sign app bundle
+ - name: "[macOS] Sign app bundle"
if: matrix.os == 'macOS' && matrix.make_package && needs.configure.outputs.tag != null
id: sign_macos
env:
@@ -494,15 +488,15 @@ jobs:
if [[ -n "$MACOS_CERTIFICATE_NAME" ]]
then
security unlock-keychain -p "$MACOS_CI_KEYCHAIN_PWD" build.keychain
- /usr/bin/codesign --sign="$MACOS_CERTIFICATE_NAME" --entitlements=".ci/macos.entitlements" --options=runtime --force --deep --timestamp --verbose ${{steps.build.outputs.path}}
+ /usr/bin/codesign --sign="$MACOS_CERTIFICATE_NAME" --entitlements=".ci/macos.entitlements" --options=runtime --force --deep --timestamp --verbose "${{ steps.build.outputs.path }}"
fi
- - name: Notarize app bundle
- if: steps.sign_macos.outcome == 'success'
+ - name: "[macOS] Notarize app bundle"
+ if: matrix.os == 'macOS' && steps.sign_macos.outcome == 'success'
env:
MACOS_NOTARIZATION_APPLE_ID: ${{ secrets.PROD_MACOS_NOTARIZATION_APPLE_ID }}
- MACOS_NOTARIZATION_TEAM_ID: ${{ secrets.PROD_MACOS_NOTARIZATION_TEAM_ID }}
MACOS_NOTARIZATION_PWD: ${{ secrets.PROD_MACOS_NOTARIZATION_PWD }}
+ MACOS_NOTARIZATION_TEAM_ID: ${{ secrets.PROD_MACOS_NOTARIZATION_TEAM_ID }}
run: |
if [[ -n "$MACOS_NOTARIZATION_APPLE_ID" ]]
then
@@ -514,7 +508,7 @@ jobs:
# Therefore, we create a zip file containing our app bundle, so that we can send it to the
# notarization service
echo "Creating temp notarization archive"
- ditto -c -k --keepParent ${{steps.build.outputs.path}} "notarization.zip"
+ ditto -c -k --keepParent "${{ steps.build.outputs.path }}" "notarization.zip"
# Here we send the notarization request to the Apple's Notarization service, waiting for the result.
# This typically takes a few seconds inside a CI environment, but it might take more depending on the App
@@ -526,51 +520,51 @@ jobs:
# Finally, we need to "attach the staple" to our executable, which will allow our app to be
# validated by macOS even when an internet connection is not available.
echo "Attach staple"
- xcrun stapler staple ${{steps.build.outputs.path}}
+ xcrun stapler staple "${{ steps.build.outputs.path }}"
fi
- - name: Upload artifact
+ - name: "Upload artifact"
if: matrix.make_package
id: upload_artifact
uses: actions/upload-artifact@v7
with:
- path: ${{steps.build.outputs.path}}
archive: false
if-no-files-found: error
+ path: ${{ steps.build.outputs.path }}
- - name: Upload PDBs (Program Databases)
+ - name: "[Windows] Upload PDBs (Program Databases)"
if: matrix.os == 'Windows' && github.ref_type != 'tag'
uses: actions/upload-artifact@v7
with:
- name: ${{steps.build.outputs.name}}-PDBs
+ if-no-files-found: error
+ name: ${{ steps.build.outputs.name }}-PDBs
path: |
build/cockatrice/Release/*.pdb
build/oracle/Release/*.pdb
build/servatrice/Release/*.pdb
- if-no-files-found: error
- - name: Upload to release
+ - name: "Upload to release"
if: needs.configure.outputs.tag != null && matrix.make_package == '1'
id: upload_release
shell: bash
env:
- GH_TOKEN: ${{github.token}}
- tag_name: ${{needs.configure.outputs.tag}}
- asset_name: ${{steps.build.outputs.fullname}}
- asset_path: ${{steps.build.outputs.path}}
+ asset_name: ${{ steps.build.outputs.fullname }}
+ asset_path: ${{ steps.build.outputs.path }}
+ GH_TOKEN: ${{ github.token }}
+ tag_name: ${{ needs.configure.outputs.tag }}
run: gh release upload "$tag_name" "$asset_path#$asset_name"
- - name: Attest binary provenance
+ - name: "Attest binary provenance"
if: steps.upload_release.outcome == 'success'
id: attestation
uses: actions/attest@v4
with:
- subject-path: ${{steps.build.outputs.path}}
show-summary: false
+ subject-path: ${{ steps.build.outputs.path }}
- - name: Verify binary attestation
+ - name: "Verify binary attestation"
if: steps.attestation.outcome == 'success'
shell: bash
env:
- GH_TOKEN: ${{github.token}}
- run: gh attestation verify ${{steps.build.outputs.path}} --repo Cockatrice/Cockatrice
+ GH_TOKEN: ${{ github.token }}
+ run: gh attestation verify "${{ steps.build.outputs.path }}" --repo Cockatrice/Cockatrice
diff --git a/.github/workflows/desktop-lint.yml b/.github/workflows/desktop-lint.yml
index fe7be0287..54931933c 100644
--- a/.github/workflows/desktop-lint.yml
+++ b/.github/workflows/desktop-lint.yml
@@ -1,17 +1,15 @@
name: Code Style (C++)
on:
- # push trigger not needed for linting, we do not allow direct pushes to master
+ # Push trigger not needed for linting, we do not allow direct pushes to master
pull_request:
paths:
- '*/**' # matches all files not in root
- '!**.md'
- '!.ci/**'
- '!.github/**'
- - '!.husky/**'
- '!.tx/**'
- '!doc/**'
- - '!webclient/**'
- '.ci/lint_cpp.sh'
- '.github/workflows/desktop-lint.yml'
- '.clang-format'
@@ -23,17 +21,20 @@ jobs:
runs-on: ubuntu-slim
steps:
- - name: Checkout
+ - name: "Checkout"
uses: actions/checkout@v6
with:
fetch-depth: 20 # should be enough to find merge base
- - name: Install dependencies
+ - name: "Install dependencies"
shell: bash
run: |
sudo apt-get update
- sudo apt-get install -y --no-install-recommends clang-format cmake-format shellcheck
+ sudo apt-get install -y --no-install-recommends \
+ clang-format \
+ cmake-format \
+ shellcheck
- - name: Check code formatting
+ - name: "Check code formatting"
shell: bash
run: ./.ci/lint_cpp.sh
diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml
index fca1e97d4..d9ff06282 100644
--- a/.github/workflows/docker-release.yml
+++ b/.github/workflows/docker-release.yml
@@ -1,9 +1,11 @@
name: Build Docker Image
+permissions:
+ contents: read
+ packages: write
+
on:
push:
- tags:
- - '*Release*'
branches:
- master
pull_request:
@@ -12,61 +14,64 @@ on:
paths:
- '.github/workflows/docker-release.yml'
- 'Dockerfile'
+ release:
+ types:
+ - released # publishing of stable releases
# Cancel earlier, unfinished runs of this workflow on the same branch (unless on release)
concurrency:
group: "${{ github.workflow }} @ ${{ github.ref_name }}"
- cancel-in-progress: ${{ github.ref_type != 'tag' }}
+ cancel-in-progress: ${{ github.event_name != 'release' }}
jobs:
docker:
name: amd64 & arm64
+ if: ${{ github.repository_owner == 'Cockatrice' }}
runs-on: ubuntu-latest
- permissions:
- contents: read
- packages: write
-
+
steps:
- - name: Checkout
+ - name: "Checkout"
uses: actions/checkout@v6
- - name: Docker metadata
+ - name: "Docker metadata"
id: metadata
uses: docker/metadata-action@v6
+ env:
+ DOCKER_METADATA_ANNOTATIONS_LEVELS: index # needed for GHCR
with:
+ annotations: |
+ org.opencontainers.image.title=Servatrice
+ org.opencontainers.image.url=https://cockatrice.github.io/
+ org.opencontainers.image.description=Server for Cockatrice, a cross-platform virtual tabletop for multiplayer card games
images: |
ghcr.io/cockatrice/servatrice
labels: |
org.opencontainers.image.title=Servatrice
org.opencontainers.image.url=https://cockatrice.github.io/
org.opencontainers.image.description=Server for Cockatrice, a cross-platform virtual tabletop for multiplayer card games
- annotations: |
- org.opencontainers.image.title=Servatrice
- org.opencontainers.image.url=https://cockatrice.github.io/
- org.opencontainers.image.description=Server for Cockatrice, a cross-platform virtual tabletop for multiplayer card games
- - name: Set up QEMU
+ - name: "Set up QEMU"
uses: docker/setup-qemu-action@v4
- - name: Set up Docker buildx
+ - name: "Set up Docker buildx"
uses: docker/setup-buildx-action@v4
- - name: Login to GitHub Container Registry
- if: github.ref_type == 'tag'
+ - name: "Login to GitHub Container Registry"
+ if: contains(github.event.release.tag_name, 'Release') && github.event.release.target_commitish == 'master'
uses: docker/login-action@v4
with:
+ password: ${{ github.token }}
registry: ghcr.io
username: ${{ github.actor }}
- password: ${{ github.token }}
- - name: Build and push Docker image
+ - name: "Build and push Docker image"
uses: docker/build-push-action@v7
with:
- context: .
- platforms: linux/amd64,linux/arm64
- push: ${{ github.ref_type == 'tag' }}
- tags: ${{ steps.metadata.outputs.tags }}
- labels: ${{ steps.metadata.outputs.labels }}
annotations: ${{ steps.metadata.outputs.annotations }}
cache-from: type=gha,scope=servatrice
cache-to: type=gha,mode=max,scope=servatrice
+ context: .
+ labels: ${{ steps.metadata.outputs.labels }}
+ platforms: linux/amd64,linux/arm64
+ push: ${{ github.ref_type == 'tag' }}
+ tags: ${{ steps.metadata.outputs.tags }}
diff --git a/.github/workflows/documentation-build.yml b/.github/workflows/documentation-build.yml
index ce331d113..717999d5a 100644
--- a/.github/workflows/documentation-build.yml
+++ b/.github/workflows/documentation-build.yml
@@ -1,18 +1,18 @@
name: Generate Docs
on:
- push:
- tags:
- - '*' # Only re-generate docs when a new tagged version is pushed
pull_request:
paths:
- 'doc/doxygen/**'
- '.github/workflows/documentation-build.yml'
- 'Doxyfile'
+ release:
+ types:
+ - published # publishing of stable releases and pre-releases
workflow_dispatch:
env:
- COCKATRICE_REF: ${{ github.ref_name }} # Tag name if the commit is tagged, otherwise branch name
+ COCKATRICE_REF: ${{ github.ref_name }} # tag name if the commit is tagged, otherwise branch name
jobs:
docs:
@@ -20,22 +20,22 @@ jobs:
runs-on: ubuntu-latest
steps:
- - name: Checkout code
+ - name: "Checkout code"
uses: actions/checkout@v6
with:
submodules: recursive
- - name: Install Graphviz
+ - name: "Install Graphviz"
run: |
sudo apt-get install -y graphviz
dot -V
- - name: Install Doxygen
+ - name: "Install Doxygen"
uses: ssciwr/doxygen-install@v2
with:
- version: "1.14.0"
+ version: "1.16.1"
- - name: Update Doxygen Configuration
+ - name: "Update Doxygen Configuration"
run: |
git diff Doxyfile
doxygen -u Doxyfile
@@ -48,16 +48,16 @@ jobs:
exit 1
fi
- - name: Generate Documentation
+ - name: "Generate Documentation"
if: always()
run: doxygen Doxyfile
- - name: Deploy to cockatrice.github.io
- if: github.event_name != 'pull_request'
+ - name: "Deploy to cockatrice.github.io"
+ if: github.event_name == 'release' || github.event_name == 'workflow_dispatch'
uses: peaceiris/actions-gh-pages@v4
with:
deploy_key: ${{ secrets.DOCS_DEPLOY_KEY }}
+ destination_dir: docs # docs will be available at https://cockatrice.github.io/docs/
external_repository: Cockatrice/cockatrice.github.io
publish_branch: master
publish_dir: ./docs/html
- destination_dir: docs # Docs will live under https://cockatrice.github.io/docs/
diff --git a/.github/workflows/translations-pull.yml b/.github/workflows/translations-pull.yml
index ca9069192..057381f8a 100644
--- a/.github/workflows/translations-pull.yml
+++ b/.github/workflows/translations-pull.yml
@@ -1,14 +1,14 @@
name: Update Translations
on:
- workflow_dispatch:
- schedule:
- # runs in the middle of each month starting a quarter (UTC) = two weeks after new strings are built
- - cron: '0 0 15 1,4,7,10 *'
pull_request:
paths:
- '.tx/**'
- '.github/workflows/translations-pull.yml'
+ schedule:
+ # Runs in the middle of each month starting a quarter (UTC) = two weeks after new strings are built
+ - cron: '0 0 15 1,4,7,10 *'
+ workflow_dispatch:
jobs:
translations:
@@ -19,18 +19,18 @@ jobs:
runs-on: ubuntu-slim
steps:
- - name: Checkout repo
+ - name: "Checkout repo"
uses: actions/checkout@v6
- - name: Pull translated strings from Transifex
+ - name: "Pull translated strings from Transifex"
uses: transifex/cli-action@v2
with:
- # used config file: https://github.com/Cockatrice/Cockatrice/blob/master/.tx/config
- # https://github.com/transifex/cli#pulling-files-from-transifex
- token: ${{ secrets.TX_TOKEN }}
+ # Used config file: https://github.com/Cockatrice/Cockatrice/blob/master/.tx/config
+ # Docs: https://github.com/transifex/cli#pulling-files-from-transifex
args: pull --force --all
+ token: ${{ secrets.TX_TOKEN }}
- - name: Create pull request
+ - name: "Create pull request"
if: github.event_name != 'pull_request'
id: create_pr
uses: peter-evans/create-pull-request@v8
@@ -38,13 +38,7 @@ jobs:
add-paths: |
cockatrice/translations/*.ts
oracle/translations/*.ts
- webclient/public/locales/*/translation.json
- commit-message: Update translation files
- # author is the owner of the commit
- author: github-actions
- branch: ci-update_translations
- delete-branch: true
- title: 'Update translations'
+ author: github-actions # owner of the commit
body: |
Pulled all translated strings from [Transifex][1].
@@ -54,12 +48,16 @@ jobs:
[1]: https://explore.transifex.com/cockatrice/cockatrice/
[2]: https://github.com/Cockatrice/Cockatrice/actions/workflows/translations-pull.yml?query=branch%3Amaster
+ branch: ci-update_translations
+ commit-message: Update translation files
+ delete-branch: true
+ draft: false
labels: |
CI
Translation
- draft: false
+ title: 'Update translations'
- - name: PR Status
+ - name: "PR Status"
if: github.event_name != 'pull_request'
shell: bash
env:
diff --git a/.github/workflows/translations-push.yml b/.github/workflows/translations-push.yml
index e926a58ed..4adcaf4a4 100644
--- a/.github/workflows/translations-push.yml
+++ b/.github/workflows/translations-push.yml
@@ -1,14 +1,14 @@
name: Update Translation Source
on:
- workflow_dispatch:
- schedule:
- # runs at the start of each quarter (UTC)
- - cron: '0 0 1 1,4,7,10 *'
pull_request:
paths:
- '.ci/update_translation_source_strings.sh'
- '.github/workflows/translations-push.yml'
+ schedule:
+ # Runs at the start of each quarter (UTC)
+ - cron: '0 0 1 1,4,7,10 *'
+ workflow_dispatch:
jobs:
translations:
@@ -19,16 +19,16 @@ jobs:
runs-on: ubuntu-slim
steps:
- - name: Checkout repo
+ - name: "Checkout repo"
uses: actions/checkout@v6
- - name: Install lupdate
+ - name: "Install lupdate"
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends qttools5-dev-tools
- - name: Update Cockatrice translation source
+ - name: "Update Cockatrice translation source"
id: cockatrice
shell: bash
run: |
@@ -36,15 +36,15 @@ jobs:
export DIRS="cockatrice/src $(find . -maxdepth 1 -type d -name 'libcockatrice_*')"
FILE="$FILE" DIRS="$DIRS" .ci/update_translation_source_strings.sh
- - name: Update Oracle translation source
+ - name: "Update Oracle translation source"
id: oracle
shell: bash
env:
- FILE: 'oracle/oracle_en@source.ts'
DIRS: 'oracle/src'
+ FILE: 'oracle/oracle_en@source.ts'
run: .ci/update_translation_source_strings.sh
- - name: Render template
+ - name: "Render template"
id: template
uses: chuhlomin/render-template/binary@v1
with:
@@ -54,7 +54,7 @@ jobs:
oracle_output: ${{ steps.oracle.outputs.output }}
commit: ${{ github.sha }}
- - name: Create pull request
+ - name: "Create pull request"
if: github.event_name != 'pull_request'
id: create_pr
uses: peter-evans/create-pull-request@v8
@@ -62,19 +62,18 @@ jobs:
add-paths: |
cockatrice/cockatrice_en@source.ts
oracle/oracle_en@source.ts
- commit-message: Update translation source strings
- # author is the owner of the commit
- author: github-actions
- branch: ci-update_translation_source
- delete-branch: true
- title: 'Update source strings'
+ author: github-actions # owner of the commit
body: ${{ steps.template.outputs.result }}
+ branch: ci-update_translation_source
+ commit-message: Update translation source strings
+ delete-branch: true
+ draft: false
labels: |
CI
Translation
- draft: false
+ title: 'Update source strings'
- - name: PR Status
+ - name: "PR Status"
if: github.event_name != 'pull_request'
shell: bash
env:
diff --git a/.github/workflows/web-build.yml b/.github/workflows/web-build.yml
deleted file mode 100644
index 8d756da02..000000000
--- a/.github/workflows/web-build.yml
+++ /dev/null
@@ -1,54 +0,0 @@
-name: Build Web
-
-on:
- push:
- branches:
- - master
- paths:
- - '.husky/**'
- - 'webclient/**'
- - '!**.md'
- - '.github/workflows/web-build.yml'
- pull_request:
- paths:
- - '.husky/**'
- - 'webclient/**'
- - '!**.md'
- - '.github/workflows/web-build.yml'
-
-jobs:
- build-web:
- name: React (Node ${{matrix.node_version}})
-
- runs-on: ubuntu-latest
-
- defaults:
- run:
- working-directory: webclient
-
- strategy:
- fail-fast: false
- matrix:
- node_version:
- - 16
- - lts/*
-
- steps:
- - name: Checkout
- uses: actions/checkout@v6
-
- - name: Setup Node.js
- uses: actions/setup-node@v6
- with:
- node-version: ${{matrix.node_version}}
- cache: 'npm'
- cache-dependency-path: 'webclient/package-lock.json'
-
- - name: Install dependencies
- run: npm clean-install
-
- - name: Build app
- run: npm run build
-
- - name: Test app
- run: npm run test
diff --git a/.github/workflows/web-lint.yml b/.github/workflows/web-lint.yml
deleted file mode 100644
index ecc6d14d1..000000000
--- a/.github/workflows/web-lint.yml
+++ /dev/null
@@ -1,33 +0,0 @@
-name: Code Style (TypeScript)
-
-on:
- # push trigger not needed for linting, we do not allow direct pushes to master
- pull_request:
- paths:
- - 'webclient/**'
- - '!**.md'
- - '.github/workflows/web-lint.yml'
-
-jobs:
- ESLint:
- runs-on: ubuntu-slim
-
- defaults:
- run:
- working-directory: webclient
-
- steps:
- - name: Checkout
- uses: actions/checkout@v6
-
- - name: Setup Node.js
- uses: actions/setup-node@v6
- with:
- cache: 'npm'
- cache-dependency-path: 'webclient/package-lock.json'
-
- - name: Install ESLint
- run: npm clean-install --ignore-scripts
-
- - name: Run ESLint
- run: npm run lint
diff --git a/.husky/pre-commit b/.husky/pre-commit
deleted file mode 100755
index 369435d6b..000000000
--- a/.husky/pre-commit
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/sh
-. "$(dirname "$0")/_/husky.sh"
-
-cd webclient
-npm run translate
-
-git add src/i18n-default.json
diff --git a/.tx/config b/.tx/config
index 9bc5ce950..8174a4dfd 100644
--- a/.tx/config
+++ b/.tx/config
@@ -16,11 +16,3 @@ source_file = oracle/oracle_en@source.ts
file_filter = oracle/translations/oracle_.ts
type = QT
minimum_perc = 10
-
-[o:cockatrice:p:cockatrice:r:webclient-src-i18n-default-json--master]
-resource_name = Webclient
-source_lang = en
-source_file = webclient/src/i18n-default.json
-file_filter = webclient/public/locales//translation.json
-type = KEYVALUEJSON
-minimum_perc = 10
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4a5e944c4..c10e1db68 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -74,7 +74,7 @@ endif()
# A project name is needed for CPack
# Version can be overriden by git tags, see cmake/getversion.cmake
-project("Cockatrice" VERSION 3.0.0)
+project("Cockatrice" VERSION 3.1.0)
# Set release name if not provided via env/cmake var
if(NOT DEFINED GIT_TAG_RELEASENAME)
@@ -174,6 +174,7 @@ elseif(CMAKE_COMPILER_IS_GNUCXX)
-Wno-error=delete-non-virtual-dtor
-Wno-error=sign-compare
-Wno-error=missing-declarations
+ -Wno-error=sfinae-incomplete # GCC 16+: Qt MOC + protobuf forward decls trigger this
)
foreach(FLAG ${ADDITIONAL_DEBUG_FLAGS})
diff --git a/Dockerfile b/Dockerfile
index d185b746a..7c5c773c9 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,5 +1,5 @@
# -------- Build Stage --------
-FROM ubuntu:24.04 AS build
+FROM ubuntu:26.04 AS build
ARG DEBIAN_FRONTEND=noninteractive
@@ -26,7 +26,7 @@ RUN mkdir build && cd build && \
# -------- Runtime Stage (clean) --------
-FROM ubuntu:24.04
+FROM ubuntu:26.04
RUN apt-get update && apt-get install -y --no-install-recommends \
libprotobuf32t64 \
diff --git a/Doxyfile b/Doxyfile
index 0f2642fd8..fc96b5f22 100644
--- a/Doxyfile
+++ b/Doxyfile
@@ -1,4 +1,4 @@
-# Doxyfile 1.14.0
+# Doxyfile 1.16.1
# This file describes the settings to be used by the documentation system
# Doxygen (www.doxygen.org) for a project.
@@ -361,6 +361,20 @@ EXTENSION_MAPPING =
MARKDOWN_SUPPORT = YES
+# If the MARKDOWN_STRICT tag is enabled then Doxygen treats text in comments as
+# Markdown formatted also in cases where Doxygen's native markup format
+# conflicts with that of Markdown. This is only relevant in cases where
+# backticks are used. Doxygen's native markup style allows a single quote to end
+# a text fragment started with a backtick and then treat it as a piece of quoted
+# text, whereas in Markdown such text fragment is treated as verbatim and only
+# ends when a second matching backtick is found. Also, Doxygen's native markup
+# format requires double quotes to be escaped when they appear in a backtick
+# section, whereas this is not needed for Markdown.
+# The default value is: YES.
+# This tag requires that the tag MARKDOWN_SUPPORT is set to YES.
+
+MARKDOWN_STRICT = YES
+
# When the TOC_INCLUDE_HEADINGS tag is set to a non-zero value, all headings up
# to that level are automatically included in the table of contents, even if
# they do not have an id attribute.
@@ -392,8 +406,8 @@ AUTOLINK_SUPPORT = YES
# This tag specifies a list of words that, when matching the start of a word in
# the documentation, will suppress auto links generation, if it is enabled via
-# AUTOLINK_SUPPORT. This list does not affect links explicitly created using \#
-# or the \link or commands.
+# AUTOLINK_SUPPORT. This list does not affect links explicitly created using #
+# or the \link or \ref commands.
# This tag requires that the tag AUTOLINK_SUPPORT is set to YES.
AUTOLINK_IGNORE_WORDS =
@@ -510,9 +524,9 @@ LOOKUP_CACHE_SIZE = 0
# which effectively disables parallel processing. Please report any issues you
# encounter. Generating dot graphs in parallel is controlled by the
# DOT_NUM_THREADS setting.
-# Minimum value: 0, maximum value: 32, default value: 1.
+# Minimum value: 0, maximum value: 512, default value: 1.
-NUM_PROC_THREADS = 1
+NUM_PROC_THREADS = 0
# If the TIMESTAMP tag is set different from NO then each generated page will
# contain the date or date and time when the page was generated. Setting this to
@@ -779,6 +793,27 @@ GENERATE_BUGLIST = YES
GENERATE_DEPRECATEDLIST= YES
+# The GENERATE_REQUIREMENTS tag can be used to enable (YES) or disable (NO) the
+# requirements page. When enabled, this page is automatically created when at
+# least one comment block with a \requirement command appears in the input.
+# The default value is: YES.
+
+GENERATE_REQUIREMENTS = YES
+
+# The REQ_TRACEABILITY_INFO tag controls if traceability information is shown on
+# the requirements page (only relevant when using \requirement comment blocks).
+# The setting NO will disable the traceablility information altogether. The
+# setting UNSATISFIED_ONLY will show a list of requirements that are missing a
+# satisfies relation (through the command: \satisfies). Similarly the setting
+# UNVERIFIED_ONLY will show a list of requirements that are missing a verifies
+# relation (through the command: \verifies). Setting the tag to YES (the
+# default) will show both lists if applicable.
+# Possible values are: YES, NO, UNSATISFIED_ONLY and UNVERIFIED_ONLY.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_REQUIREMENTS is set to YES.
+
+REQ_TRACEABILITY_INFO = YES
+
# The ENABLED_SECTIONS tag can be used to enable conditional documentation
# sections, marked by \if ... \endif and \cond
# ... \endcond blocks.
@@ -1070,8 +1105,7 @@ EXCLUDE = build/ \
cmake/ \
doc/doxygen/theme/docs/ \
doc/doxygen/theme/include/ \
- vcpkg/ \
- webclient/
+ vcpkg/
# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
# directories that are symbolic links (a Unix file system feature) are excluded
@@ -1887,7 +1921,7 @@ USE_MATHJAX = NO
# regards to the different settings, so it is possible that also other MathJax
# settings have to be changed when switching between the different MathJax
# versions.
-# Possible values are: MathJax_2 and MathJax_3.
+# Possible values are: MathJax_2, MathJax_3 and MathJax_4.
# The default value is: MathJax_2.
# This tag requires that the tag USE_MATHJAX is set to YES.
@@ -1896,9 +1930,10 @@ MATHJAX_VERSION = MathJax_2
# When MathJax is enabled you can set the default output format to be used for
# the MathJax output. For more details about the output format see MathJax
# version 2 (see:
-# http://docs.mathjax.org/en/v2.7-latest/output.html) and MathJax version 3
+# https://docs.mathjax.org/en/v2.7/output.html), MathJax version 3 (see:
+# https://docs.mathjax.org/en/v3.2/output/index.html) and MathJax version 4
# (see:
-# http://docs.mathjax.org/en/latest/web/components/output.html).
+# https://docs.mathjax.org/en/v4.0/output/index.htm).
# Possible values are: HTML-CSS (which is slower, but has the best
# compatibility. This is the name for Mathjax version 2, for MathJax version 3
# this will be translated into chtml), NativeMML (i.e. MathML. Only supported
@@ -1911,36 +1946,50 @@ MATHJAX_VERSION = MathJax_2
MATHJAX_FORMAT = HTML-CSS
# When MathJax is enabled you need to specify the location relative to the HTML
-# output directory using the MATHJAX_RELPATH option. The destination directory
-# should contain the MathJax.js script. For instance, if the mathjax directory
-# is located at the same level as the HTML output directory, then
-# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax
-# Content Delivery Network so you can quickly see the result without installing
-# MathJax. However, it is strongly recommended to install a local copy of
-# MathJax from https://www.mathjax.org before deployment. The default value is:
+# output directory using the MATHJAX_RELPATH option. For Mathjax version 2 the
+# destination directory should contain the MathJax.js script. For instance, if
+# the mathjax directory is located at the same level as the HTML output
+# directory, then MATHJAX_RELPATH should be ../mathjax.s For Mathjax versions 3
+# and 4 the destination directory should contain the tex-.js script
+# (where is either chtml or svg). The default value points to the
+# MathJax Content Delivery Network so you can quickly see the result without
+# installing MathJax. However, it is strongly recommended to install a local
+# copy of MathJax from https://www.mathjax.org before deployment. The default
+# value is:
# - in case of MathJax version 2: https://cdn.jsdelivr.net/npm/mathjax@2
# - in case of MathJax version 3: https://cdn.jsdelivr.net/npm/mathjax@3
+# - in case of MathJax version 4: https://cdn.jsdelivr.net/npm/mathjax@4
# This tag requires that the tag USE_MATHJAX is set to YES.
MATHJAX_RELPATH =
# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax
# extension names that should be enabled during MathJax rendering. For example
-# for MathJax version 2 (see
-# https://docs.mathjax.org/en/v2.7-latest/tex.html#tex-and-latex-extensions):
+# for MathJax version 2 (see https://docs.mathjax.org/en/v2.7/tex.html):
# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols
# For example for MathJax version 3 (see
-# http://docs.mathjax.org/en/latest/input/tex/extensions/index.html):
+# https://docs.mathjax.org/en/v3.2/input/tex/extensions/):
# MATHJAX_EXTENSIONS = ams
+# For example for MathJax version 4 (see
+# https://docs.mathjax.org/en/v4.0/input/tex/extensions/):
+# MATHJAX_EXTENSIONS = units
+# Note that for Mathjax version 4 quite a few extensions are already
+# automatically loaded. To disable a package in Mathjax version 4 one can use
+# the package name prepended with a minus sign (- like MATHJAX_EXTENSIONS +=
+# -textmacros)
# This tag requires that the tag USE_MATHJAX is set to YES.
MATHJAX_EXTENSIONS =
# The MATHJAX_CODEFILE tag can be used to specify a file with JavaScript pieces
-# of code that will be used on startup of the MathJax code. See the MathJax site
-# (see:
-# http://docs.mathjax.org/en/v2.7-latest/output.html) for more details. For an
-# example see the documentation.
+# of code that will be used on startup of the MathJax code. See the Mathjax site
+# for more details:
+# - MathJax version 2 (see:
+# https://docs.mathjax.org/en/v2.7/)
+# - MathJax version 3 (see:
+# https://docs.mathjax.org/en/v3.2/)
+# - MathJax version 4 (see:
+# https://docs.mathjax.org/en/v4.0/) For an example see the documentation.
# This tag requires that the tag USE_MATHJAX is set to YES.
MATHJAX_CODEFILE =
@@ -2601,7 +2650,7 @@ HAVE_DOT = YES
# processors available in the system. You can set it explicitly to a value
# larger than 0 to get control over the balance between CPU load and processing
# speed.
-# Minimum value: 0, maximum value: 32, default value: 0.
+# Minimum value: 0, maximum value: 512, default value: 0.
# This tag requires that the tag HAVE_DOT is set to YES.
DOT_NUM_THREADS = 0
diff --git a/README.md b/README.md
index 8ad9a092c..9a27601cd 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@
Related|Community|Contribute|
- Build|
+ Build|Run
@@ -25,7 +25,6 @@
Cockatrice is an open-source, multiplatform application for playing tabletop card games over a network. The program's server design prevents users from manipulating the game for unfair advantage. The client also provides a single-player mode, which allows users to brew while offline.
This project uses C++ and the Qt libraries.
-First work on a webclient with Typescript was started as well.
# Download [](https://tooomm.github.io/github-release-stats/?username=Cockatrice&repository=Cockatrice&search=0)
@@ -48,6 +47,7 @@ Latest beta version:
- [Magic-Spoiler](https://github.com/Cockatrice/Magic-Spoiler): Code to generate MtG spoiler data from [MTGJSON](https://github.com/mtgjson/mtgjson) for use in Cockatrice
- [cockatrice.github.io](https://github.com/Cockatrice/cockatrice.github.io): Code of the official Cockatrice webpage
- [io.github.Cockatrice.cockatrice](https://github.com/flathub/io.github.Cockatrice.cockatrice): Configuration of our Linux `flatpak` package hosted at [Flathub](https://flathub.org/en/apps/io.github.Cockatrice.cockatrice)
+- [Webatrice](https://github.com/Cockatrice/Webatrice): Web client for Cockatrice servers (TypeScript / React)
# Community Resources [](https://discord.gg/3Z9yzmA)
@@ -107,12 +107,12 @@ Cockatrice tries to use the [Google Developer Documentation Style Guide](https:/
### Translation [](https://explore.transifex.com/cockatrice/cockatrice/)
-Cockatrice uses Transifex to manage translations. You can help us bring Cockatrice, Oracle and Webatrice to your language and just adjust single wordings right from within your browser by visiting our [Transifex project page](https://explore.transifex.com/cockatrice/cockatrice/).
+Cockatrice uses Transifex to manage translations. You can help us bring Cockatrice and Oracle to your language and just adjust single wordings right from within your browser by visiting our [Transifex project page](https://explore.transifex.com/cockatrice/cockatrice/). The [Webatrice](https://github.com/seavor/Webatrice) web client manages its own translations in its repo.
Check out our [Translator FAQ](https://github.com/Cockatrice/Cockatrice/wiki/Translation-FAQ) for more information about getting involved, and join a group of hundreds of others!
-# Build [](https://github.com/Cockatrice/Cockatrice/actions/workflows/desktop-build.yml?query=branch%3Amaster+event%3Apush) [](https://github.com/Cockatrice/Cockatrice/actions/workflows/docker-release.yml?query=branch%3Amaster+event%3Apush) [](https://github.com/Cockatrice/Cockatrice/actions/workflows/web-build.yml?query=branch%3Amaster+event%3Apush)
+# Build [](https://github.com/Cockatrice/Cockatrice/actions/workflows/desktop-build.yml?query=branch%3Amaster+event%3Apush) [](https://github.com/Cockatrice/Cockatrice/actions/workflows/docker-release.yml?query=branch%3Amaster+event%3Apush)
Dependencies: *(for minimum versions search our [CMake file](https://github.com/Cockatrice/Cockatrice/blob/master/CMakeLists.txt))*
- [Qt](https://www.qt.io/developers/)
diff --git a/cmake/getversion.cmake b/cmake/getversion.cmake
index cb27ebd87..b24b520d5 100644
--- a/cmake/getversion.cmake
+++ b/cmake/getversion.cmake
@@ -213,7 +213,8 @@ set(PROJECT_VERSION_FRIENDLY "${PROJECT_VERSION} (${GIT_COMMIT_DATE_FRIENDLY})")
# Format: [-ReleaseName]-MAJ.MIN.PATCH[-prerelease_label]
set(PROJECT_VERSION_FILENAME "${PROJECT_NAME}")
if(PROJECT_VERSION_RELEASENAME)
- set(PROJECT_VERSION_FILENAME "${PROJECT_VERSION_FILENAME}-${PROJECT_VERSION_RELEASENAME}")
+ string(REPLACE " " "-" PROJECT_VERSION_RELEASENAME_SAFE "${PROJECT_VERSION_RELEASENAME}")
+ set(PROJECT_VERSION_FILENAME "${PROJECT_VERSION_FILENAME}-${PROJECT_VERSION_RELEASENAME_SAFE}")
endif()
set(PROJECT_VERSION_FILENAME "${PROJECT_VERSION_FILENAME}-${PROJECT_VERSION}")
diff --git a/cmake/gtest-CMakeLists.txt.in b/cmake/gtest-CMakeLists.txt.in
index 2d71a55e5..2062d7f8c 100644
--- a/cmake/gtest-CMakeLists.txt.in
+++ b/cmake/gtest-CMakeLists.txt.in
@@ -1,15 +1,16 @@
-cmake_minimum_required(VERSION 3.2)
+cmake_minimum_required(VERSION 3.10)
project(gtest-download LANGUAGES NONE)
include(ExternalProject)
-ExternalProject_Add(googletest
- URL https://github.com/google/googletest/archive/release-1.11.0.zip
- URL_HASH SHA1=9ffb7b5923f4a8fcdabf2f42c6540cce299f44c0
+externalproject_add(
+ googletest
+ URL https://github.com/google/googletest/archive/refs/tags/v1.17.0.zip
+ URL_HASH SHA1=f638fa0e724760e2ba07ff8cfba32cd644e1ce28
SOURCE_DIR "${CMAKE_BINARY_DIR}/gtest-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/gtest-build"
CONFIGURE_COMMAND ""
- BUILD_COMMAND ""
- INSTALL_COMMAND ""
- TEST_COMMAND ""
+ BUILD_COMMAND ""
+ INSTALL_COMMAND ""
+ TEST_COMMAND ""
)
diff --git a/cockatrice/CMakeLists.txt b/cockatrice/CMakeLists.txt
index 12733afe6..028161ee0 100644
--- a/cockatrice/CMakeLists.txt
+++ b/cockatrice/CMakeLists.txt
@@ -7,6 +7,7 @@ project(Cockatrice VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${
set(cockatrice_SOURCES
${VERSION_STRING_CPP}
# sort by alphabetical order, so that there is no debate about where to add new sources to the list
+ src/client/network/connection_controller/remote_connection_controller.cpp
src/client/network/update/client/update_downloader.cpp
src/client/network/interfaces/deck_stats_interface.cpp
src/client/network/interfaces/tapped_out_interface.cpp
@@ -55,15 +56,19 @@ set(cockatrice_SOURCES
src/filters/filter_tree_model.cpp
src/filters/syntax_help.cpp
src/game/abstract_game.cpp
+ src/game/arrow_registry.cpp
src/game/board/abstract_card_drag_item.cpp
src/game/board/abstract_card_item.cpp
src/game/board/abstract_counter.cpp
+ src/game/board/arrow_data.cpp
src/game/board/arrow_item.cpp
src/game/board/arrow_target.cpp
src/game/board/card_drag_item.cpp
src/game/board/card_item.cpp
src/game/board/card_list.cpp
+ src/game/board/card_state.cpp
src/game/board/counter_general.cpp
+ src/game/board/counter_state.cpp
src/game/board/translate_counter_name.cpp
src/game/deckview/deck_view.cpp
src/game/deckview/deck_view_container.cpp
@@ -93,30 +98,30 @@ set(cockatrice_SOURCES
src/game/player/menu/say_menu.cpp
src/game/player/menu/sideboard_menu.cpp
src/game/player/menu/utility_menu.cpp
- src/game/player/player.cpp
src/game/player/player_actions.cpp
src/game/player/player_area.cpp
src/game/player/player_event_handler.cpp
src/game/player/player_graphics_item.cpp
src/game/player/player_info.cpp
src/game/player/player_list_widget.cpp
+ src/game/player/player_logic.cpp
src/game/player/player_manager.cpp
src/game/player/player_target.cpp
src/game/replay.cpp
- src/game/zones/card_zone.cpp
- src/game/zones/hand_zone.cpp
- src/game/zones/logic/card_zone_logic.cpp
- src/game/zones/logic/hand_zone_logic.cpp
- src/game/zones/logic/pile_zone_logic.cpp
- src/game/zones/logic/stack_zone_logic.cpp
- src/game/zones/logic/table_zone_logic.cpp
- src/game/zones/logic/view_zone_logic.cpp
- src/game/zones/pile_zone.cpp
- src/game/zones/select_zone.cpp
- src/game/zones/stack_zone.cpp
- src/game/zones/table_zone.cpp
- src/game/zones/view_zone.cpp
- src/game/zones/view_zone_widget.cpp
+ src/game/zones/card_zone_logic.cpp
+ src/game/zones/hand_zone_logic.cpp
+ src/game/zones/pile_zone_logic.cpp
+ src/game/zones/stack_zone_logic.cpp
+ src/game/zones/table_zone_logic.cpp
+ src/game/zones/view_zone_logic.cpp
+ src/game_graphics/zones/card_zone.cpp
+ src/game_graphics/zones/hand_zone.cpp
+ src/game_graphics/zones/pile_zone.cpp
+ src/game_graphics/zones/select_zone.cpp
+ src/game_graphics/zones/stack_zone.cpp
+ src/game_graphics/zones/table_zone.cpp
+ src/game_graphics/zones/view_zone.cpp
+ src/game_graphics/zones/view_zone_widget.cpp
src/game_graphics/board/abstract_graphics_item.cpp
src/interface/card_picture_loader/card_picture_loader.cpp
src/interface/card_picture_loader/card_picture_loader_local.cpp
@@ -129,7 +134,13 @@ set(cockatrice_SOURCES
src/interface/layouts/overlap_layout.cpp
src/interface/widgets/utility/line_edit_completer.cpp
src/interface/pixel_map_generator.cpp
+ src/interface/theme_config.cpp
src/interface/theme_manager.cpp
+ src/interface/palette_editor/color_button.cpp
+ src/interface/palette_editor/palette_generator.cpp
+ src/interface/palette_editor/quick_setup_panel.cpp
+ 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/mana_cost_widget.cpp
src/interface/widgets/cards/additional_info/mana_symbol_widget.cpp
@@ -171,6 +182,7 @@ set(cockatrice_SOURCES
src/interface/widgets/deck_analytics/analyzer_modules/mana_distribution/mana_distribution_single_display_widget.cpp
src/interface/widgets/deck_analytics/analyzer_modules/mana_curve/mana_curve_total_widget.cpp
src/interface/widgets/deck_analytics/analyzer_modules/mana_curve/mana_curve_category_widget.cpp
+ src/interface/widgets/deck_editor/card_database_view.cpp
src/interface/widgets/deck_editor/deck_list_history_manager_widget.cpp
src/interface/widgets/deck_editor/deck_editor_card_database_dock_widget.cpp
src/interface/widgets/deck_editor/deck_editor_card_info_dock_widget.cpp
@@ -216,6 +228,7 @@ set(cockatrice_SOURCES
src/interface/widgets/replay/replay_manager.cpp
src/interface/widgets/replay/replay_timeline_widget.cpp
src/interface/widgets/server/chat_view/chat_view.cpp
+ src/interface/widgets/server/game_filter_configs.cpp
src/interface/widgets/server/game_selector.cpp
src/interface/widgets/server/game_selector_quick_filter_toolbar.cpp
src/interface/widgets/server/games_model.cpp
@@ -227,6 +240,14 @@ set(cockatrice_SOURCES
src/interface/widgets/server/user/user_info_connection.cpp
src/interface/widgets/server/user/user_list_manager.cpp
src/interface/widgets/server/user/user_list_widget.cpp
+ src/interface/widgets/settings_page/appearance_settings_page.cpp
+ src/interface/widgets/settings_page/deck_editor_settings_page.cpp
+ src/interface/widgets/settings_page/general_settings_page.cpp
+ src/interface/widgets/settings_page/messages_settings_page.cpp
+ src/interface/widgets/settings_page/shortcut_settings_page.cpp
+ src/interface/widgets/settings_page/sound_settings_page.cpp
+ src/interface/widgets/settings_page/storage_settings_page.cpp
+ src/interface/widgets/settings_page/user_interface_settings_page.cpp
src/interface/widgets/utility/custom_line_edit.cpp
src/interface/widgets/utility/get_text_with_max.cpp
src/interface/widgets/utility/sequence_edit.cpp
@@ -325,6 +346,8 @@ set(cockatrice_SOURCES
src/interface/widgets/tabs/api/edhrec/display/commander/edhrec_commander_api_response_bracket_navigation_widget.h
src/interface/widgets/tabs/api/edhrec/display/commander/edhrec_commander_api_response_budget_navigation_widget.cpp
src/interface/widgets/tabs/api/edhrec/display/commander/edhrec_commander_api_response_budget_navigation_widget.h
+ src/interface/widgets/utility/compact_push_button.cpp
+ src/interface/widgets/utility/compact_push_button.h
)
add_subdirectory(sounds)
@@ -539,6 +562,7 @@ if(WIN32)
DIRECTORY "${CMAKE_BINARY_DIR}/cockatrice/"
DESTINATION ./
FILES_MATCHING
+ PATTERN "CMakeFiles" EXCLUDE
PATTERN "*.ini"
)
diff --git a/cockatrice/cockatrice.qrc b/cockatrice/cockatrice.qrc
index 37fb145f0..9c34929b7 100644
--- a/cockatrice/cockatrice.qrc
+++ b/cockatrice/cockatrice.qrc
@@ -55,6 +55,7 @@
resources/icons/view.svgresources/icons/mana/B.svg
+ resources/icons/mana/C.svgresources/icons/mana/G.svgresources/icons/mana/R.svgresources/icons/mana/U.svg
@@ -69,6 +70,7 @@
resources/config/interface.svgresources/config/messages.svgresources/config/deckeditor.svg
+ resources/config/storage.svgresources/config/shorcuts.svgresources/config/sound.svgresources/config/debug.ini
diff --git a/cockatrice/resources/config/qtlogging.ini b/cockatrice/resources/config/qtlogging.ini
index 20aa206ce..7ac0d9ca4 100644
--- a/cockatrice/resources/config/qtlogging.ini
+++ b/cockatrice/resources/config/qtlogging.ini
@@ -28,6 +28,8 @@
#dlg_tip_of_the_day = true
#dlg_update = true
+#general_settings_page = true
+
#settings_cache = true
#servers_settings = true
#shortcuts_settings = true
diff --git a/cockatrice/resources/config/storage.svg b/cockatrice/resources/config/storage.svg
new file mode 100644
index 000000000..de85228dc
--- /dev/null
+++ b/cockatrice/resources/config/storage.svg
@@ -0,0 +1,799 @@
+
+
+
+
diff --git a/cockatrice/resources/icons/mana/C.svg b/cockatrice/resources/icons/mana/C.svg
new file mode 100644
index 000000000..eb09fb872
--- /dev/null
+++ b/cockatrice/resources/icons/mana/C.svg
@@ -0,0 +1,72 @@
+
+
+
+
diff --git a/cockatrice/src/client/network/connection_controller/remote_connection_controller.cpp b/cockatrice/src/client/network/connection_controller/remote_connection_controller.cpp
new file mode 100644
index 000000000..75cedcafc
--- /dev/null
+++ b/cockatrice/src/client/network/connection_controller/remote_connection_controller.cpp
@@ -0,0 +1,587 @@
+#include "remote_connection_controller.h"
+
+#include "../../settings/cache_settings.h"
+#include "../interface/widgets/dialogs/dlg_connect.h"
+#include "../interface/widgets/dialogs/dlg_forgot_password_challenge.h"
+#include "../interface/widgets/dialogs/dlg_forgot_password_request.h"
+#include "../interface/widgets/dialogs/dlg_forgot_password_reset.h"
+#include "../interface/widgets/dialogs/dlg_register.h"
+#include "../interface/widgets/utility/get_text_with_max.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+ConnectionController::ConnectionController(QWidget *dialogParent, QObject *parent)
+ : QObject(parent), dialogParent(dialogParent)
+{
+ remoteClient = new RemoteClient(nullptr, &SettingsCache::instance());
+
+ clientThread = new QThread(this);
+ remoteClient->moveToThread(clientThread);
+ clientThread->start();
+
+ wireClientSignals();
+}
+
+ConnectionController::~ConnectionController()
+{
+ remoteClient->deleteLater();
+ clientThread->wait();
+}
+
+void ConnectionController::wireClientSignals()
+{
+ connect(remoteClient, &RemoteClient::connectionClosedEventReceived, this,
+ &ConnectionController::onConnectionClosedEvent);
+
+ connect(remoteClient, &RemoteClient::serverShutdownEventReceived, this,
+ &ConnectionController::onServerShutdownEvent);
+
+ connect(remoteClient, &RemoteClient::statusChanged, this, &ConnectionController::onStatusChanged);
+
+ connect(remoteClient, &RemoteClient::userInfoChanged, this, &ConnectionController::onUserInfoReceived,
+ Qt::BlockingQueuedConnection);
+
+ connect(remoteClient, &RemoteClient::loginError, this,
+ [this](Response::ResponseCode r, QString rs, quint32 et, QList mf) {
+ onLoginError(static_cast(r), rs, et, mf);
+ });
+
+ connect(remoteClient, &RemoteClient::registerError, this,
+ [this](Response::ResponseCode r, QString rs, quint32 et) { onRegisterError(static_cast(r), rs, et); });
+
+ connect(remoteClient, &RemoteClient::activateError, this, &ConnectionController::onActivateError);
+ connect(remoteClient, &RemoteClient::socketError, this, &ConnectionController::onSocketError);
+ connect(remoteClient, &RemoteClient::serverTimeout, this, &ConnectionController::onServerTimeout);
+
+ connect(remoteClient, &RemoteClient::protocolVersionMismatch, this,
+ &ConnectionController::onProtocolVersionMismatch);
+
+ connect(remoteClient, &RemoteClient::registerAccepted, this, &ConnectionController::onRegisterAccepted);
+
+ connect(remoteClient, &RemoteClient::registerAcceptedNeedsActivate, this,
+ &ConnectionController::onRegisterAcceptedNeedsActivate);
+
+ connect(remoteClient, &RemoteClient::activateAccepted, this, &ConnectionController::onActivateAccepted);
+
+ connect(remoteClient, &RemoteClient::notifyUserAboutUpdate, this, &ConnectionController::onNotifyUserAboutUpdate);
+
+ connect(remoteClient, &RemoteClient::sigForgotPasswordSuccess, this,
+ &ConnectionController::onForgotPasswordSuccess);
+
+ connect(remoteClient, &RemoteClient::sigForgotPasswordError, this, &ConnectionController::onForgotPasswordError);
+
+ connect(remoteClient, &RemoteClient::sigPromptForForgotPasswordReset, this,
+ &ConnectionController::onPromptForgotPasswordReset);
+
+ connect(remoteClient, &RemoteClient::sigPromptForForgotPasswordChallenge, this,
+ &ConnectionController::onPromptForgotPasswordChallenge);
+}
+
+void ConnectionController::connectToServer()
+{
+ dlgConnect = new DlgConnect(dialogParent);
+ connect(dlgConnect, &DlgConnect::sigStartForgotPasswordRequest, this, &ConnectionController::forgotPasswordRequest);
+
+ if (dlgConnect->exec()) {
+ remoteClient->connectToServer(dlgConnect->getHost(), static_cast(dlgConnect->getPort()),
+ dlgConnect->getPlayerName(), dlgConnect->getPassword());
+ }
+}
+
+void ConnectionController::connectToServerDirect(const QString &host,
+ unsigned int port,
+ const QString &playerName,
+ const QString &password)
+{
+ remoteClient->connectToServer(host, port, playerName, password);
+}
+
+void ConnectionController::disconnectFromServer()
+{
+ remoteClient->disconnectFromServer();
+}
+
+void ConnectionController::registerToServer()
+{
+ DlgRegister dlg(dialogParent);
+ if (dlg.exec()) {
+ remoteClient->registerToServer(dlg.getHost(), static_cast(dlg.getPort()), dlg.getPlayerName(),
+ dlg.getPassword(), dlg.getEmail(), dlg.getCountry(), dlg.getRealName());
+ }
+}
+
+void ConnectionController::forgotPasswordRequest()
+{
+ DlgForgotPasswordRequest dlg(dialogParent);
+ if (dlg.exec()) {
+ remoteClient->requestForgotPasswordToServer(dlg.getHost(), static_cast(dlg.getPort()),
+ dlg.getPlayerName());
+ }
+}
+
+void ConnectionController::onConnectionClosedEvent(const Event_ConnectionClosed &event)
+{
+ remoteClient->disconnectFromServer();
+
+ QString reasonStr;
+ switch (event.reason()) {
+ case Event_ConnectionClosed::USER_LIMIT_REACHED: {
+ reasonStr = tr("The server has reached its maximum user capacity, please check back later.");
+ break;
+ }
+ case Event_ConnectionClosed::TOO_MANY_CONNECTIONS: {
+ reasonStr = tr("There are too many concurrent connections from your address.");
+ break;
+ }
+ case Event_ConnectionClosed::BANNED: {
+ reasonStr = tr("Banned by moderator");
+ if (event.has_end_time()) {
+ reasonStr.append(
+ "\n" + tr("Expected end time: %1").arg(QDateTime::fromSecsSinceEpoch(event.end_time()).toString()));
+ } else {
+ reasonStr.append("\n" + tr("This ban lasts indefinitely."));
+ }
+ if (event.has_reason_str()) {
+ reasonStr.append("\n\n" + QString::fromStdString(event.reason_str()));
+ }
+ break;
+ }
+ case Event_ConnectionClosed::SERVER_SHUTDOWN: {
+ reasonStr = tr("Scheduled server shutdown.");
+ break;
+ }
+ case Event_ConnectionClosed::USERNAMEINVALID: {
+ reasonStr = tr("Invalid username.");
+ break;
+ }
+ case Event_ConnectionClosed::LOGGEDINELSEWERE: {
+ reasonStr = tr("You have been logged out due to logging in at another location.");
+ break;
+ }
+ default:
+ reasonStr = QString::fromStdString(event.reason_str());
+ }
+
+ QMessageBox::critical(dialogParent, tr("Connection closed"),
+ tr("The server has terminated your connection.\nReason: %1").arg(reasonStr));
+}
+
+void ConnectionController::onServerShutdownEvent(const Event_ServerShutdown &event)
+{
+ serverShutdownMessageBox.setInformativeText(tr("The server is going to be restarted in %n minute(s).\nAll running "
+ "games will be lost.\nReason for shutdown: %1",
+ "", event.minutes())
+ .arg(QString::fromStdString(event.reason())));
+ serverShutdownMessageBox.setIconPixmap(QPixmap("theme:cockatrice").scaled(64, 64));
+ serverShutdownMessageBox.setText(tr("Scheduled server shutdown"));
+ serverShutdownMessageBox.setWindowModality(Qt::ApplicationModal);
+ serverShutdownMessageBox.setVisible(true);
+}
+
+void ConnectionController::onStatusChanged(ClientStatus status)
+{
+ // Update the window title first, then let MainWindow handle its own UI
+ // state via the forwarded signal
+ updateWindowTitle();
+ emit statusChanged(status);
+
+ // TabSupervisor::stop() needs calling on disconnect; start() is driven by
+ // onUserInfoReceived → tabSupervisorStartRequested.
+ if (status == StatusDisconnected) {
+ emit tabSupervisorStopRequested();
+ }
+}
+
+void ConnectionController::onUserInfoReceived(const ServerInfo_User &info)
+{
+ emit tabSupervisorStartRequested(info);
+}
+
+void ConnectionController::onLoginError(int r,
+ QString reasonStr,
+ quint32 endTime,
+ const QList &missingFeatures)
+{
+ switch (static_cast(r)) {
+ case Response::RespClientUpdateRequired: {
+ QString formatted = "Missing Features: ";
+ for (int i = 0; i < missingFeatures.size(); ++i) {
+ formatted.append(QString("\n %1").arg(QChar(0x2022)) + " " + missingFeatures.value(i));
+ }
+
+ QMessageBox msgBox(dialogParent);
+ msgBox.setIcon(QMessageBox::Critical);
+ msgBox.setWindowTitle(tr("Failed Login"));
+ msgBox.setText(tr("Your client seems to be missing features this server requires for connection.") +
+ "\n\n" + tr("To update your client, go to 'Help -> Check for Client Updates'."));
+ msgBox.setDetailedText(formatted);
+ msgBox.exec();
+ break;
+ }
+
+ case Response::RespWrongPassword: {
+ QMessageBox::critical(dialogParent, tr("Error"),
+ tr("Incorrect username or password. "
+ "Please check your authentication information and try again."));
+ break;
+ }
+
+ case Response::RespWouldOverwriteOldSession: {
+ QMessageBox::critical(dialogParent, tr("Error"),
+ tr("There is already an active session using this user name.\n"
+ "Please close that session first and re-login."));
+ break;
+ }
+
+ case Response::RespUserIsBanned: {
+ QString bannedStr =
+ endTime ? tr("You are banned until %1.").arg(QDateTime::fromSecsSinceEpoch(endTime).toString())
+ : tr("You are banned indefinitely.");
+ if (!reasonStr.isEmpty()) {
+ bannedStr.append("\n\n" + reasonStr);
+ }
+ QMessageBox::critical(dialogParent, tr("Error"), bannedStr);
+ break;
+ }
+
+ case Response::RespUsernameInvalid: {
+ QMessageBox::critical(dialogParent, tr("Error"), extractInvalidUsernameMessage(reasonStr));
+ break;
+ }
+
+ case Response::RespRegistrationRequired: {
+ if (QMessageBox::question(dialogParent, tr("Error"),
+ tr("This server requires user registration. Do you want to register now?"),
+ QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
+ registerToServer();
+ }
+ return; // don't re-prompt connect
+ }
+
+ case Response::RespClientIdRequired: {
+ QMessageBox::critical(dialogParent, tr("Error"),
+ tr("This server requires client IDs. Your client is either failing to generate an "
+ "ID or you are running a modified client.\n"
+ "Please close and reopen your client to try again."));
+ break;
+ }
+
+ case Response::RespContextError: {
+ QMessageBox::critical(dialogParent, tr("Error"),
+ tr("An internal error has occurred, please close and reopen Cockatrice before "
+ "trying again.\nIf the error persists, ensure you are running the latest "
+ "version of the software and if needed contact the software developers."));
+ break;
+ }
+
+ case Response::RespAccountNotActivated: {
+ bool ok = false;
+ QString token =
+ getTextWithMax(dialogParent, tr("Account activation"),
+ tr("Your account has not been activated yet.\n"
+ "You need to provide the activation token received in the activation email."),
+ QLineEdit::Normal, QString(), &ok);
+
+ if (ok && !token.isEmpty()) {
+ remoteClient->activateToServer(token);
+ return;
+ }
+ remoteClient->disconnectFromServer();
+ return;
+ }
+
+ case Response::RespServerFull: {
+ QMessageBox::critical(dialogParent, tr("Server Full"),
+ tr("The server has reached its maximum user capacity, please check back later."));
+ break;
+ }
+
+ default: {
+ QMessageBox::critical(dialogParent, tr("Error"),
+ tr("Unknown login error: %1").arg(r) +
+ tr("\nThis usually means that your client version is out of date, and the server "
+ "sent a reply your client doesn't understand."));
+ break;
+ }
+ }
+
+ // Re-open the connect dialog after any handled error
+ connectToServer();
+}
+
+void ConnectionController::onRegisterError(int r, QString reasonStr, quint32 endTime)
+{
+ switch (static_cast(r)) {
+ case Response::RespRegistrationDisabled: {
+ QMessageBox::critical(dialogParent, tr("Registration denied"),
+ tr("Registration is currently disabled on this server"));
+ break;
+ }
+ case Response::RespUserAlreadyExists: {
+ QMessageBox::critical(dialogParent, tr("Registration denied"),
+ tr("There is already an existing account with the same user name."));
+ break;
+ }
+ case Response::RespEmailRequiredToRegister: {
+ QMessageBox::critical(dialogParent, tr("Registration denied"),
+ tr("It's mandatory to specify a valid email address when registering."));
+ break;
+ }
+ case Response::RespEmailBlackListed: {
+ if (reasonStr.isEmpty()) {
+ reasonStr =
+ "The email address provider used during registration has been blocked from use on this server.";
+ }
+ QMessageBox::critical(dialogParent, tr("Registration denied"), reasonStr);
+ break;
+ }
+ case Response::RespTooManyRequests: {
+ QMessageBox::critical(dialogParent, tr("Registration denied"),
+ tr("It appears you are attempting to register a new account on this server yet you "
+ "already have an account registered with the email provided. This server "
+ "restricts the number of accounts a user can register per address. Please "
+ "contact the server operator for further assistance or to obtain your "
+ "credential information."));
+ break;
+ }
+ case Response::RespPasswordTooShort: {
+ QMessageBox::critical(dialogParent, tr("Registration denied"), tr("Password too short."));
+ break;
+ }
+ case Response::RespUserIsBanned: {
+ QString bannedStr =
+ endTime ? tr("You are banned until %1.").arg(QDateTime::fromSecsSinceEpoch(endTime).toString())
+ : tr("You are banned indefinitely.");
+ if (!reasonStr.isEmpty()) {
+ bannedStr.append("\n\n" + reasonStr);
+ }
+ QMessageBox::critical(dialogParent, tr("Error"), bannedStr);
+ break;
+ }
+ case Response::RespUsernameInvalid: {
+ QMessageBox::critical(dialogParent, tr("Error"), extractInvalidUsernameMessage(reasonStr));
+ break;
+ }
+ case Response::RespRegistrationFailed: {
+ QMessageBox::critical(dialogParent, tr("Error"),
+ tr("Registration failed for a technical problem on the server."));
+ break;
+ }
+ case Response::RespNotConnected: {
+ QMessageBox::critical(dialogParent, tr("Error"), tr("The connection to the server has been lost."));
+ break;
+ }
+ default: {
+ QMessageBox::critical(dialogParent, tr("Error"),
+ tr("Unknown registration error: %1").arg(r) +
+ tr("\nThis usually means that your client version is out of date, and the server "
+ "sent a reply your client doesn't understand."));
+ break;
+ }
+ }
+
+ registerToServer();
+}
+
+void ConnectionController::onActivateError()
+{
+ QMessageBox::critical(dialogParent, tr("Error"), tr("Account activation failed"));
+ remoteClient->disconnectFromServer();
+ connectToServer();
+}
+
+void ConnectionController::onSocketError(const QString &errorStr)
+{
+ QMessageBox::critical(dialogParent, tr("Error"), tr("Socket error: %1").arg(errorStr));
+ connectToServer();
+}
+
+void ConnectionController::onServerTimeout()
+{
+ QMessageBox::critical(dialogParent, tr("Error"), tr("Server timeout"));
+ connectToServer();
+}
+
+void ConnectionController::onProtocolVersionMismatch(int localVersion, int remoteVersion)
+{
+ if (localVersion > remoteVersion) {
+ QMessageBox::critical(dialogParent, tr("Error"),
+ tr("You are trying to connect to an obsolete server. Please downgrade your Cockatrice "
+ "version or connect to a suitable server.\n"
+ "Local version is %1, remote version is %2.")
+ .arg(localVersion)
+ .arg(remoteVersion));
+ } else {
+ QMessageBox::critical(dialogParent, tr("Error"),
+ tr("Your Cockatrice client is obsolete. Please update your Cockatrice version.\n"
+ "Local version is %1, remote version is %2.")
+ .arg(localVersion)
+ .arg(remoteVersion));
+ }
+}
+
+void ConnectionController::onRegisterAccepted()
+{
+ QMessageBox::information(dialogParent, tr("Success"), tr("Registration accepted.\nWill now login."));
+}
+
+void ConnectionController::onRegisterAcceptedNeedsActivate()
+{
+ // Server will send activation email; nothing to display here.
+}
+
+void ConnectionController::onActivateAccepted()
+{
+ QMessageBox::information(dialogParent, tr("Success"), tr("Account activation accepted.\nWill now login."));
+}
+
+void ConnectionController::onNotifyUserAboutUpdate()
+{
+ QMessageBox::information(
+ dialogParent, tr("Information"),
+ tr("This server supports additional features that your client doesn't have.\n"
+ "This is most likely not a problem, but this message might mean there is a new version of "
+ "Cockatrice available or this server is running a custom or pre-release version.\n\n"
+ "To update your client, go to Help -> Check for Updates."));
+}
+
+void ConnectionController::onForgotPasswordSuccess()
+{
+ QMessageBox::information(
+ dialogParent, tr("Reset Password"),
+ tr("Your password has been reset successfully, you can now log in using the new credentials."));
+ SettingsCache::instance().servers().setFPHostName("");
+ SettingsCache::instance().servers().setFPPort("");
+ SettingsCache::instance().servers().setFPPlayerName("");
+}
+
+void ConnectionController::onForgotPasswordError()
+{
+ QMessageBox::warning(
+ dialogParent, tr("Reset Password"),
+ tr("Failed to reset user account password, please contact the server operator to reset your password."));
+ SettingsCache::instance().servers().setFPHostName("");
+ SettingsCache::instance().servers().setFPPort("");
+ SettingsCache::instance().servers().setFPPlayerName("");
+}
+
+void ConnectionController::onPromptForgotPasswordReset()
+{
+ QMessageBox::information(dialogParent, tr("Reset Password"),
+ tr("Activation request received, please check your email for an activation token."));
+ DlgForgotPasswordReset dlg(dialogParent);
+ if (dlg.exec()) {
+ remoteClient->submitForgotPasswordResetToServer(dlg.getHost(), static_cast(dlg.getPort()),
+ dlg.getPlayerName(), dlg.getToken(), dlg.getPassword());
+ }
+}
+
+void ConnectionController::onPromptForgotPasswordChallenge()
+{
+ DlgForgotPasswordChallenge dlg(dialogParent);
+ if (dlg.exec()) {
+ remoteClient->submitForgotPasswordChallengeToServer(dlg.getHost(), static_cast(dlg.getPort()),
+ dlg.getPlayerName(), dlg.getEmail());
+ }
+}
+
+void ConnectionController::updateWindowTitle()
+{
+ const QString appName = QStringLiteral("Cockatrice");
+ QString title;
+
+ switch (remoteClient->getStatus()) {
+ case StatusConnecting: {
+ title = appName + " - " + tr("Connecting to %1...").arg(remoteClient->peerName());
+ break;
+ }
+ case StatusRegistering: {
+ title = appName + " - " +
+ tr("Registering to %1 as %2...").arg(remoteClient->peerName()).arg(remoteClient->getUserName());
+ break;
+ }
+ case StatusDisconnected: {
+ title = appName + " - " + tr("Disconnected");
+ break;
+ }
+ case StatusLoggingIn: {
+ title = appName + " - " + tr("Connected, logging in at %1").arg(remoteClient->peerName());
+ break;
+ }
+ case StatusLoggedIn: {
+ title = remoteClient->getUserName() + "@" + remoteClient->peerName();
+ break;
+ }
+ case StatusRequestingForgotPassword:
+ case StatusSubmitForgotPasswordChallenge:
+ case StatusSubmitForgotPasswordReset:
+ title = appName + " - " +
+ tr("Requesting forgotten password to %1 as %2...")
+ .arg(remoteClient->peerName())
+ .arg(remoteClient->getUserName());
+ break;
+ default:
+ title = appName;
+ }
+
+ emit windowTitleChanged(title);
+}
+
+// static
+QString ConnectionController::extractInvalidUsernameMessage(QString &in)
+{
+ QString out = tr("Invalid username.") + " ";
+ QStringList rules = in.split(QChar('|'));
+
+ if (rules.size() == 7 || rules.size() == 9) {
+ out += tr("Your username must respect these rules:") + "
" + tr("can contain the following punctuation: %1").arg(rules.at(6).toHtmlEscaped()) + "
";
+ }
+
+ out += "
" +
+ tr("first character can %1 be a punctuation mark").arg((rules.at(5).toInt() > 0) ? "" : tr("NOT")) +
+ "
";
+
+ if (rules.size() == 9) {
+ if (rules.at(7).size() > 0) {
+ QString words = rules.at(7).toHtmlEscaped();
+ if (words.startsWith("\n")) {
+ out += tr("no unacceptable language as specified by these server rules:",
+ "note that the following lines will not be translated");
+ for (QString &line : words.split("\n", Qt::SkipEmptyParts)) {
+ out += "
" + line + "
";
+ }
+ } else {
+ out += "
" + tr("can not contain any of the following words: %1").arg(words) + "
";
+ }
+ }
+
+ if (rules.at(8).size() > 0) {
+ out += "
" +
+ tr("can not match any of the following expressions: %1").arg(rules.at(8).toHtmlEscaped()) +
+ "
";
+ }
+ }
+
+ out += "
";
+ } else {
+ out += tr("You may only use A-Z, a-z, 0-9, _, ., and - in your username.");
+ }
+
+ return out;
+}
\ No newline at end of file
diff --git a/cockatrice/src/client/network/connection_controller/remote_connection_controller.h b/cockatrice/src/client/network/connection_controller/remote_connection_controller.h
new file mode 100644
index 000000000..7486bc81a
--- /dev/null
+++ b/cockatrice/src/client/network/connection_controller/remote_connection_controller.h
@@ -0,0 +1,98 @@
+#ifndef COCKATRICE_REMOTE_CONNECTION_CONTROLLER_H
+#define COCKATRICE_REMOTE_CONNECTION_CONTROLLER_H
+
+#include "abstract_client.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+class RemoteClient;
+class ServerInfo_User;
+class DlgConnect;
+
+/**
+ * Owns the RemoteClient and its worker thread.
+ * Encapsulates all connection, authentication, and registration logic so that
+ * MainWindow only needs to react to high-level signals.
+ */
+class ConnectionController : public QObject
+{
+ Q_OBJECT
+
+public:
+ explicit ConnectionController(QWidget *dialogParent, QObject *parent = nullptr);
+ ~ConnectionController() override;
+
+ RemoteClient *client() const
+ {
+ return remoteClient;
+ }
+
+ void registerToServer();
+ void forgotPasswordRequest();
+ void connectToServer();
+ void
+ connectToServerDirect(const QString &host, unsigned int port, const QString &playerName, const QString &password);
+ void disconnectFromServer();
+
+ void refreshWindowTitle()
+ {
+ updateWindowTitle();
+ }
+
+signals:
+ void windowTitleChanged(const QString &title);
+
+ void tabSupervisorStartRequested(const ServerInfo_User &info);
+ void tabSupervisorStopRequested();
+
+ // Passes the raw ClientStatus through so MainWindow can drive its own
+ // action enable/disable logic
+ void statusChanged(ClientStatus status);
+
+private slots:
+ // Slots wired directly to RemoteClient signals
+ void onStatusChanged(ClientStatus status);
+ void onUserInfoReceived(const ServerInfo_User &info);
+ void onLoginError(int r, QString reasonStr, quint32 endTime, const QList &missingFeatures);
+ void onRegisterAccepted();
+ void onRegisterAcceptedNeedsActivate();
+ void onRegisterError(int r, QString reasonStr, quint32 endTime);
+ void onActivateAccepted();
+ void onActivateError();
+ void onProtocolVersionMismatch(int localVersion, int remoteVersion);
+ void onNotifyUserAboutUpdate();
+ void onConnectionClosedEvent(const Event_ConnectionClosed &event);
+ void onServerShutdownEvent(const Event_ServerShutdown &event);
+ void onSocketError(const QString &errorStr);
+ void onServerTimeout();
+
+ // Forgot-password flow
+ void onForgotPasswordSuccess();
+ void onForgotPasswordError();
+ void onPromptForgotPasswordReset();
+ void onPromptForgotPasswordChallenge();
+
+private:
+ void wireClientSignals();
+ void updateWindowTitle();
+
+ /** Parse the server's pipe-delimited username-rule string into HTML. */
+ static QString extractInvalidUsernameMessage(QString &in);
+
+ RemoteClient *remoteClient{nullptr};
+ QThread *clientThread{nullptr};
+ QWidget *dialogParent{nullptr}; // used as parent for QMessageBox / dialog calls
+
+ // Persistent so it can be updated in-place by onServerShutdownEvent
+ QMessageBox serverShutdownMessageBox;
+
+ // Kept as a member so the forgot-password signal can be wired to it
+ DlgConnect *dlgConnect{nullptr};
+};
+
+#endif // COCKATRICE_REMOTE_CONNECTION_CONTROLLER_H
diff --git a/cockatrice/src/client/network/interfaces/deck_stats_interface.cpp b/cockatrice/src/client/network/interfaces/deck_stats_interface.cpp
index 0298daa6b..8689a19e9 100644
--- a/cockatrice/src/client/network/interfaces/deck_stats_interface.cpp
+++ b/cockatrice/src/client/network/interfaces/deck_stats_interface.cpp
@@ -6,12 +6,12 @@
#include
#include
#include
+#include
#include
#include
#include
-DeckStatsInterface::DeckStatsInterface(CardDatabase &_cardDatabase, QObject *parent)
- : QObject(parent), cardDatabase(_cardDatabase)
+DeckStatsInterface::DeckStatsInterface(QObject *parent) : QObject(parent)
{
manager = new QNetworkAccessManager(this);
connect(manager, &QNetworkAccessManager::finished, this, &DeckStatsInterface::queryFinished);
@@ -70,8 +70,8 @@ void DeckStatsInterface::analyzeDeck(const DeckList &deck)
void DeckStatsInterface::copyDeckWithoutTokens(const DeckList &source, DeckList &destination)
{
- auto copyIfNotAToken = [this, &destination](const auto node, const auto card) {
- CardInfoPtr dbCard = cardDatabase.query()->getCardInfo(card->getName());
+ auto copyIfNotAToken = [&destination](const auto node, const auto card) {
+ CardInfoPtr dbCard = CardDatabaseManager::query()->getCardInfo(card->getName());
if (dbCard && !dbCard->getIsToken()) {
DecklistCardNode *addedCard = destination.addCard(card->getName(), node->getName(), -1);
addedCard->setNumber(card->getNumber());
diff --git a/cockatrice/src/client/network/interfaces/deck_stats_interface.h b/cockatrice/src/client/network/interfaces/deck_stats_interface.h
index 7dc841027..09bf998de 100644
--- a/cockatrice/src/client/network/interfaces/deck_stats_interface.h
+++ b/cockatrice/src/client/network/interfaces/deck_stats_interface.h
@@ -1,13 +1,12 @@
/**
* @file deck_stats_interface.h
* @ingroup ApiInterfaces
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef DECKSTATS_INTERFACE_H
#define DECKSTATS_INTERFACE_H
-#include
#include
class QByteArray;
@@ -21,8 +20,6 @@ class DeckStatsInterface : public QObject
private:
QNetworkAccessManager *manager;
- CardDatabase &cardDatabase;
-
/**
* Deckstats doesn't recognize token cards, and instead tries to find the
* closest non-token card instead. So we construct a new deck which has no
@@ -35,7 +32,7 @@ private slots:
void getAnalyzeRequestData(const DeckList &deck, QByteArray &data);
public:
- explicit DeckStatsInterface(CardDatabase &_cardDatabase, QObject *parent = nullptr);
+ explicit DeckStatsInterface(QObject *parent = nullptr);
void analyzeDeck(const DeckList &deck);
};
diff --git a/cockatrice/src/client/network/interfaces/tapped_out_interface.cpp b/cockatrice/src/client/network/interfaces/tapped_out_interface.cpp
index af377d176..5dc77fa2c 100644
--- a/cockatrice/src/client/network/interfaces/tapped_out_interface.cpp
+++ b/cockatrice/src/client/network/interfaces/tapped_out_interface.cpp
@@ -6,12 +6,12 @@
#include
#include
#include
+#include
#include
#include
#include
-TappedOutInterface::TappedOutInterface(CardDatabase &_cardDatabase, QObject *parent)
- : QObject(parent), cardDatabase(_cardDatabase)
+TappedOutInterface::TappedOutInterface(QObject *parent) : QObject(parent)
{
manager = new QNetworkAccessManager(this);
connect(manager, &QNetworkAccessManager::finished, this, &TappedOutInterface::queryFinished);
@@ -97,16 +97,18 @@ void TappedOutInterface::analyzeDeck(const DeckList &deck)
void TappedOutInterface::copyDeckSplitMainAndSide(const DeckList &source, DeckList &mainboard, DeckList &sideboard)
{
- auto copyMainOrSide = [this, &mainboard, &sideboard](const auto node, const auto card) {
- CardInfoPtr dbCard = cardDatabase.query()->getCardInfo(card->getName());
- if (!dbCard || dbCard->getIsToken())
+ auto copyMainOrSide = [&mainboard, &sideboard](const auto node, const auto card) {
+ CardInfoPtr dbCard = CardDatabaseManager::query()->getCardInfo(card->getName());
+ if (!dbCard || dbCard->getIsToken()) {
return;
+ }
DecklistCardNode *addedCard;
- if (node->getName() == DECK_ZONE_SIDE)
+ if (node->getName() == DECK_ZONE_SIDE) {
addedCard = sideboard.addCard(card->getName(), node->getName(), -1);
- else
+ } else {
addedCard = mainboard.addCard(card->getName(), node->getName(), -1);
+ }
addedCard->setNumber(card->getNumber());
};
diff --git a/cockatrice/src/client/network/interfaces/tapped_out_interface.h b/cockatrice/src/client/network/interfaces/tapped_out_interface.h
index 0ea9c8358..32f9369d5 100644
--- a/cockatrice/src/client/network/interfaces/tapped_out_interface.h
+++ b/cockatrice/src/client/network/interfaces/tapped_out_interface.h
@@ -1,14 +1,14 @@
/**
* @file tapped_out_interface.h
* @ingroup ApiInterfaces
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef TAPPEDOUT_INTERFACE_H
#define TAPPEDOUT_INTERFACE_H
-#include
-#include
+#include
+#include
inline Q_LOGGING_CATEGORY(TappedOutInterfaceLog, "tapped_out_interface");
@@ -29,14 +29,13 @@ class TappedOutInterface : public QObject
private:
QNetworkAccessManager *manager;
- CardDatabase &cardDatabase;
void copyDeckSplitMainAndSide(const DeckList &source, DeckList &mainboard, DeckList &sideboard);
private slots:
void queryFinished(QNetworkReply *reply);
void getAnalyzeRequestData(const DeckList &deck, QByteArray &data);
public:
- explicit TappedOutInterface(CardDatabase &_cardDatabase, QObject *parent = nullptr);
+ explicit TappedOutInterface(QObject *parent = nullptr);
void analyzeDeck(const DeckList &deck);
};
diff --git a/cockatrice/src/client/network/parsers/deck_link_to_api_transformer.h b/cockatrice/src/client/network/parsers/deck_link_to_api_transformer.h
index 1e2372fd1..bbdd70c97 100644
--- a/cockatrice/src/client/network/parsers/deck_link_to_api_transformer.h
+++ b/cockatrice/src/client/network/parsers/deck_link_to_api_transformer.h
@@ -1,8 +1,8 @@
/**
* @file deck_link_to_api_transformer.h
* @ingroup ApiInterfaces
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef DECK_LINK_TO_API_TRANSFORMER_H
#define DECK_LINK_TO_API_TRANSFORMER_H
diff --git a/cockatrice/src/client/network/parsers/interface_json_deck_parser.h b/cockatrice/src/client/network/parsers/interface_json_deck_parser.h
index 1818aa35c..87fde4d54 100644
--- a/cockatrice/src/client/network/parsers/interface_json_deck_parser.h
+++ b/cockatrice/src/client/network/parsers/interface_json_deck_parser.h
@@ -1,8 +1,8 @@
/**
* @file interface_json_deck_parser.h
* @ingroup ApiInterfaces
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef INTERFACE_JSON_DECK_PARSER_H
#define INTERFACE_JSON_DECK_PARSER_H
diff --git a/cockatrice/src/client/network/update/card_spoiler/spoiler_background_updater.h b/cockatrice/src/client/network/update/card_spoiler/spoiler_background_updater.h
index a2feb5ccf..03d4897a2 100644
--- a/cockatrice/src/client/network/update/card_spoiler/spoiler_background_updater.h
+++ b/cockatrice/src/client/network/update/card_spoiler/spoiler_background_updater.h
@@ -1,8 +1,8 @@
/**
* @file spoiler_background_updater.h
* @ingroup Client
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef COCKATRICE_SPOILER_DOWNLOADER_H
#define COCKATRICE_SPOILER_DOWNLOADER_H
diff --git a/cockatrice/src/client/network/update/client/client_update_checker.h b/cockatrice/src/client/network/update/client/client_update_checker.h
index 4e6f279c3..1a89de533 100644
--- a/cockatrice/src/client/network/update/client/client_update_checker.h
+++ b/cockatrice/src/client/network/update/client/client_update_checker.h
@@ -1,8 +1,8 @@
/**
* @file client_update_checker.h
* @ingroup ClientUpdate
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef CLIENT_UPDATE_CHECKER_H
#define CLIENT_UPDATE_CHECKER_H
diff --git a/cockatrice/src/client/network/update/client/release_channel.cpp b/cockatrice/src/client/network/update/client/release_channel.cpp
index 9edfe7caf..260167bc8 100644
--- a/cockatrice/src/client/network/update/client/release_channel.cpp
+++ b/cockatrice/src/client/network/update/client/release_channel.cpp
@@ -129,8 +129,9 @@ void StableReleaseChannel::releaseListFinished()
return;
}
- if (!lastRelease)
+ if (!lastRelease) {
lastRelease = new Release;
+ }
lastRelease->setName(resultMap["name"].toString());
lastRelease->setDescriptionUrl(resultMap["html_url"].toString());
@@ -246,8 +247,9 @@ void BetaReleaseChannel::releaseListFinished()
return;
}
- if (lastRelease == nullptr)
+ if (lastRelease == nullptr) {
lastRelease = new Release;
+ }
lastRelease->setCommitHash(resultMap["target_commitish"].toString());
lastRelease->setPublishDate(resultMap["published_at"].toDate());
diff --git a/cockatrice/src/client/network/update/client/release_channel.h b/cockatrice/src/client/network/update/client/release_channel.h
index 93e6b985d..c56d0cfce 100644
--- a/cockatrice/src/client/network/update/client/release_channel.h
+++ b/cockatrice/src/client/network/update/client/release_channel.h
@@ -1,8 +1,8 @@
/**
* @file release_channel.h
* @ingroup ClientUpdate
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef RELEASECHANNEL_H
#define RELEASECHANNEL_H
diff --git a/cockatrice/src/client/network/update/client/update_downloader.cpp b/cockatrice/src/client/network/update/client/update_downloader.cpp
index c0f3e945c..a71bcf8f8 100644
--- a/cockatrice/src/client/network/update/client/update_downloader.cpp
+++ b/cockatrice/src/client/network/update/client/update_downloader.cpp
@@ -10,8 +10,9 @@ UpdateDownloader::UpdateDownloader(QObject *parent) : QObject(parent), response(
void UpdateDownloader::beginDownload(QUrl downloadUrl)
{
// Save the original URL because we need it for the filename
- if (originalUrl.isEmpty())
+ if (originalUrl.isEmpty()) {
originalUrl = downloadUrl;
+ }
response = netMan->get(QNetworkRequest(downloadUrl));
connect(response, &QNetworkReply::finished, this, &UpdateDownloader::fileFinished);
@@ -21,8 +22,9 @@ void UpdateDownloader::beginDownload(QUrl downloadUrl)
void UpdateDownloader::downloadError(QNetworkReply::NetworkError)
{
- if (response == nullptr)
+ if (response == nullptr) {
return;
+ }
emit error(response->errorString().toUtf8());
}
diff --git a/cockatrice/src/client/network/update/client/update_downloader.h b/cockatrice/src/client/network/update/client/update_downloader.h
index d70759038..9a0caccbc 100644
--- a/cockatrice/src/client/network/update/client/update_downloader.h
+++ b/cockatrice/src/client/network/update/client/update_downloader.h
@@ -1,8 +1,8 @@
/**
* @file update_downloader.h
* @ingroup ClientUpdate
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef COCKATRICE_UPDATEDOWNLOADER_H
#define COCKATRICE_UPDATEDOWNLOADER_H
diff --git a/cockatrice/src/client/settings/cache_settings.cpp b/cockatrice/src/client/settings/cache_settings.cpp
index a66897b4a..64416e5ee 100644
--- a/cockatrice/src/client/settings/cache_settings.cpp
+++ b/cockatrice/src/client/settings/cache_settings.cpp
@@ -1,5 +1,7 @@
#include "cache_settings.h"
+#include "../../interface/card_picture_loader/card_picture_loader_cache_method.h"
+#include "../../interface/card_picture_loader/card_picture_loader_local_schemes.h"
#include "../network/update/client/release_channel.h"
#include "card_counter_settings.h"
#include "version_string.h"
@@ -24,10 +26,11 @@ SettingsCache &SettingsCache::instance()
QString SettingsCache::getDataPath()
{
- if (isPortableBuild)
+ if (isPortableBuild) {
return qApp->applicationDirPath() + "/data";
- else
+ } else {
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
+ }
}
QString SettingsCache::getSettingsPath()
@@ -37,10 +40,11 @@ QString SettingsCache::getSettingsPath()
QString SettingsCache::getCachePath() const
{
- if (isPortableBuild)
+ if (isPortableBuild) {
return qApp->applicationDirPath() + "/cache";
- else
+ } else {
return QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
+ }
}
QString SettingsCache::getNetworkCachePath() const
@@ -50,14 +54,17 @@ QString SettingsCache::getNetworkCachePath() const
void SettingsCache::translateLegacySettings()
{
- if (isPortableBuild)
+ if (isPortableBuild) {
return;
+ }
// Layouts
QFile layoutFile(getSettingsPath() + "layouts/deckLayout.ini");
- if (layoutFile.exists())
- if (layoutFile.copy(getSettingsPath() + "layouts.ini"))
+ if (layoutFile.exists()) {
+ if (layoutFile.copy(getSettingsPath() + "layouts.ini")) {
layoutFile.remove();
+ }
+ }
QStringList usedKeys;
QSettings legacySetting;
@@ -116,10 +123,11 @@ void SettingsCache::translateLegacySettings()
gameFilters().setHideIgnoredUserGames(legacySetting.value("hide_ignored_user_games").toBool());
gameFilters().setMinPlayers(legacySetting.value("min_players").toInt());
- if (legacySetting.value("max_players").toInt() > 1)
+ if (legacySetting.value("max_players").toInt() > 1) {
gameFilters().setMaxPlayers(legacySetting.value("max_players").toInt());
- else
+ } else {
gameFilters().setMaxPlayers(99); // This prevents a bug where no games will show if max was not set before
+ }
QStringList allFilters = legacySetting.allKeys();
for (int i = 0; i < allFilters.size(); ++i) {
@@ -135,8 +143,9 @@ void SettingsCache::translateLegacySettings()
QStringList allLegacyKeys = legacySetting.allKeys();
for (int i = 0; i < allLegacyKeys.size(); ++i) {
- if (usedKeys.contains(allLegacyKeys.at(i)))
+ if (usedKeys.contains(allLegacyKeys.at(i))) {
continue;
+ }
settings->setValue(allLegacyKeys.at(i), legacySetting.value(allLegacyKeys.at(i)));
}
}
@@ -147,8 +156,9 @@ QString SettingsCache::getSafeConfigPath(QString configEntry, QString defaultPat
// if the config settings is empty or refers to a not-existing folder,
// ensure that the defaut path exists and return it
if (tmp.isEmpty() || !QDir(tmp).exists()) {
- if (!QDir().mkpath(defaultPath))
+ if (!QDir().mkpath(defaultPath)) {
qCInfo(SettingsCacheLog) << "[SettingsCache] Could not create folder:" << defaultPath;
+ }
tmp = defaultPath;
}
return tmp;
@@ -159,8 +169,9 @@ QString SettingsCache::getSafeConfigFilePath(QString configEntry, QString defaul
QString tmp = settings->value(configEntry).toString();
// if the config settings is empty or refers to a not-existing file,
// return the default Path
- if (!QFile::exists(tmp) || tmp.isEmpty())
+ if (!QFile::exists(tmp) || tmp.isEmpty()) {
tmp = std::move(defaultPath);
+ }
return tmp;
}
@@ -168,8 +179,9 @@ SettingsCache::SettingsCache()
{
// first, figure out if we are running in portable mode
isPortableBuild = QFile::exists(qApp->applicationDirPath() + "/portable.dat");
- if (isPortableBuild)
+ if (isPortableBuild) {
qCInfo(SettingsCacheLog) << "Portable mode enabled";
+ }
// define a dummy context that will be used where needed
QString dummy = QT_TRANSLATE_NOOP("i18n", "English");
@@ -189,8 +201,9 @@ SettingsCache::SettingsCache()
cardCounterSettings = new CardCounterSettings(settingsPath, this);
- if (!QFile(settingsPath + "global.ini").exists())
+ if (!QFile(settingsPath + "global.ini").exists()) {
translateLegacySettings();
+ }
// updates - don't reorder them or their index in the settings won't match
// append channels one by one, or msvc will add them in the wrong order.
@@ -211,6 +224,7 @@ SettingsCache::SettingsCache()
startupCardUpdateCheckAlwaysUpdate = settings->value("personal/startupCardUpdateCheckAlwaysUpdate", false).toBool();
cardUpdateCheckInterval = settings->value("personal/cardUpdateCheckInterval", 7).toInt();
lastCardUpdateCheck = settings->value("personal/lastCardUpdateCheck", QDateTime::currentDateTime().date()).toDate();
+ alwaysEnableNewSets = settings->value("personal/alwaysEnableNewSets", false).toBool();
notifyAboutUpdates = settings->value("personal/updatenotification", true).toBool();
notifyAboutNewVersion = settings->value("personal/newversionnotification", true).toBool();
@@ -256,14 +270,26 @@ SettingsCache::SettingsCache()
settings->setValue("personal/pixmapCacheSize", pixmapCacheSize);
settings->setValue("personal/picturedownloadhq", false);
settings->setValue("revert/pixmapCacheSize", true);
- } else
+ } else {
pixmapCacheSize = settings->value("personal/pixmapCacheSize", PIXMAPCACHE_SIZE_DEFAULT).toInt();
+ }
// sanity check
- if (pixmapCacheSize < PIXMAPCACHE_SIZE_MIN || pixmapCacheSize > PIXMAPCACHE_SIZE_MAX)
+ if (pixmapCacheSize < PIXMAPCACHE_SIZE_MIN || pixmapCacheSize > PIXMAPCACHE_SIZE_MAX) {
pixmapCacheSize = PIXMAPCACHE_SIZE_DEFAULT;
+ }
networkCacheSize = settings->value("personal/networkCacheSize", NETWORK_CACHE_SIZE_DEFAULT).toInt();
redirectCacheTtl = settings->value("personal/redirectCacheTtl", NETWORK_REDIRECT_CACHE_TTL_DEFAULT).toInt();
+ cardPictureLoaderCacheMethod =
+ settings
+ ->value("personal/cardPictureLoaderCacheMethod",
+ static_cast(CardPictureLoaderCacheMethod::CacheMethod::NETWORK_CACHE))
+ .toInt();
+ localCardImageStorageNamingScheme =
+ settings
+ ->value("personal/localCardImageStorageNamingScheme",
+ static_cast(CardPictureLoaderLocalSchemes::NamingScheme::Set_Folder_Name_Set_Collector))
+ .toInt();
picDownload = settings->value("personal/picturedownload", true).toBool();
showStatusBar = settings->value("personal/showStatusBar", false).toBool();
@@ -769,8 +795,9 @@ void SettingsCache::setPrintingSelectorCardSize(int _printingSelectorCardSize)
void SettingsCache::setIncludeRebalancedCards(bool _includeRebalancedCards)
{
- if (includeRebalancedCards == _includeRebalancedCards)
+ if (includeRebalancedCards == _includeRebalancedCards) {
return;
+ }
includeRebalancedCards = _includeRebalancedCards;
settings->setValue("cards/includerebalancedcards", includeRebalancedCards);
@@ -1097,6 +1124,13 @@ void SettingsCache::setPixmapCacheSize(const int _pixmapCacheSize)
emit pixmapCacheSizeChanged(pixmapCacheSize);
}
+void SettingsCache::setCardImageCacheMethod(const CardPictureLoaderCacheMethod::CacheMethod _cardImageCachingMethod)
+{
+ cardPictureLoaderCacheMethod = static_cast(_cardImageCachingMethod);
+ settings->setValue("personal/cardPictureLoaderCacheMethod", cardPictureLoaderCacheMethod);
+ emit cardPictureLoaderCacheMethodChanged(cardPictureLoaderCacheMethod);
+}
+
void SettingsCache::setNetworkCacheSizeInMB(const int _networkCacheSize)
{
networkCacheSize = _networkCacheSize;
@@ -1111,6 +1145,14 @@ void SettingsCache::setNetworkRedirectCacheTtl(const int _redirectCacheTtl)
emit redirectCacheTtlChanged(redirectCacheTtl);
}
+void SettingsCache::setLocalCardImageStorageNamingScheme(
+ const CardPictureLoaderLocalSchemes::NamingScheme _localCardImageStorageNamingScheme)
+{
+ localCardImageStorageNamingScheme = static_cast(_localCardImageStorageNamingScheme);
+ settings->setValue("personal/localCardImageStorageNamingScheme", localCardImageStorageNamingScheme);
+ emit localCardImageStorageNamingSchemeChanged(localCardImageStorageNamingScheme);
+}
+
void SettingsCache::setClientID(const QString &_clientID)
{
clientID = _clientID;
@@ -1246,6 +1288,12 @@ void SettingsCache::setLastCardUpdateCheck(QDate value)
settings->setValue("personal/lastCardUpdateCheck", lastCardUpdateCheck);
}
+void SettingsCache::setAlwaysEnableNewSets(bool value)
+{
+ alwaysEnableNewSets = value;
+ settings->setValue("personal/alwaysEnableNewSets", alwaysEnableNewSets);
+}
+
void SettingsCache::setRememberGameSettings(const bool _rememberGameSettings)
{
rememberGameSettings = _rememberGameSettings;
@@ -1303,8 +1351,9 @@ void SettingsCache::setMaxFontSize(int _max)
void SettingsCache::setRoundCardCorners(bool _roundCardCorners)
{
- if (_roundCardCorners == roundCardCorners)
+ if (_roundCardCorners == roundCardCorners) {
return;
+ }
roundCardCorners = _roundCardCorners;
settings->setValue("cards/roundcardcorners", _roundCardCorners);
diff --git a/cockatrice/src/client/settings/cache_settings.h b/cockatrice/src/client/settings/cache_settings.h
index ece61487f..b1197e267 100644
--- a/cockatrice/src/client/settings/cache_settings.h
+++ b/cockatrice/src/client/settings/cache_settings.h
@@ -1,12 +1,14 @@
/**
* @file cache_settings.h
* @ingroup Settings
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef SETTINGSCACHE_H
#define SETTINGSCACHE_H
+#include "../../interface/card_picture_loader/card_picture_loader_cache_method.h"
+#include "../../interface/card_picture_loader/card_picture_loader_local_schemes.h"
#include "shortcuts_settings.h"
#include
@@ -184,6 +186,8 @@ signals:
void pixmapCacheSizeChanged(int newSizeInMBs);
void networkCacheSizeChanged(int newSizeInMBs);
void redirectCacheTtlChanged(int newTtl);
+ void cardPictureLoaderCacheMethodChanged(int cardPictureLoaderCacheMethod);
+ void localCardImageStorageNamingSchemeChanged(int localCardImageStorageNamingScheme);
void masterVolumeChanged(int value);
void chatMentionCompleterChanged();
void downloadSpoilerTimeIndexChanged();
@@ -216,6 +220,7 @@ private:
bool checkCardUpdatesOnStartup;
int cardUpdateCheckInterval;
QDate lastCardUpdateCheck;
+ bool alwaysEnableNewSets;
bool notifyAboutUpdates;
bool notifyAboutNewVersion;
bool showTipsOnStartup;
@@ -302,6 +307,8 @@ private:
int pixmapCacheSize;
int networkCacheSize;
int redirectCacheTtl;
+ int cardPictureLoaderCacheMethod;
+ int localCardImageStorageNamingScheme;
bool scaleCards;
int verticalCardOverlapPercent;
bool showMessagePopups;
@@ -502,6 +509,10 @@ public:
return getLastCardUpdateCheck().daysTo(QDateTime::currentDateTime().date()) >= getCardUpdateCheckInterval() &&
getLastCardUpdateCheck() != QDateTime::currentDateTime().date();
}
+ [[nodiscard]] bool getAlwaysEnableNewSets() const
+ {
+ return alwaysEnableNewSets;
+ }
[[nodiscard]] bool getNotifyAboutUpdates() const override
{
return notifyAboutUpdates;
@@ -781,6 +792,10 @@ public:
{
return pixmapCacheSize;
}
+ [[nodiscard]] CardPictureLoaderCacheMethod::CacheMethod getCardPictureLoaderCacheMethod() const
+ {
+ return static_cast(cardPictureLoaderCacheMethod);
+ }
[[nodiscard]] int getNetworkCacheSizeInMB() const
{
return networkCacheSize;
@@ -789,6 +804,10 @@ public:
{
return redirectCacheTtl;
}
+ [[nodiscard]] CardPictureLoaderLocalSchemes::NamingScheme getLocalCardImageStorageNamingScheme() const
+ {
+ return static_cast(localCardImageStorageNamingScheme);
+ }
[[nodiscard]] bool getScaleCards() const
{
return scaleCards;
@@ -1093,8 +1112,11 @@ public slots:
void setIgnoreUnregisteredUsers(QT_STATE_CHANGED_T _ignoreUnregisteredUsers);
void setIgnoreUnregisteredUserMessages(QT_STATE_CHANGED_T _ignoreUnregisteredUserMessages);
void setPixmapCacheSize(const int _pixmapCacheSize);
+ void setCardImageCacheMethod(CardPictureLoaderCacheMethod::CacheMethod _cardImageCachingMethod);
void setNetworkCacheSizeInMB(const int _networkCacheSize);
void setNetworkRedirectCacheTtl(const int _redirectCacheTtl);
+ void setLocalCardImageStorageNamingScheme(
+ const CardPictureLoaderLocalSchemes::NamingScheme _localCardImageStorageNamingScheme);
void setCardScaling(const QT_STATE_CHANGED_T _scaleCards);
void setStackCardOverlapPercent(const int _verticalCardOverlapPercent);
void setShowMessagePopups(const QT_STATE_CHANGED_T _showMessagePopups);
@@ -1125,6 +1147,7 @@ public slots:
void setStartupCardUpdateCheckAlwaysUpdate(bool value);
void setCardUpdateCheckInterval(int value);
void setLastCardUpdateCheck(QDate value);
+ void setAlwaysEnableNewSets(bool value);
void setNotifyAboutUpdate(QT_STATE_CHANGED_T _notifyaboutupdate);
void setNotifyAboutNewVersion(QT_STATE_CHANGED_T _notifyaboutnewversion);
void setUpdateReleaseChannelIndex(int value);
diff --git a/cockatrice/src/client/settings/card_counter_settings.cpp b/cockatrice/src/client/settings/card_counter_settings.cpp
index 399365c99..662ae0c7d 100644
--- a/cockatrice/src/client/settings/card_counter_settings.cpp
+++ b/cockatrice/src/client/settings/card_counter_settings.cpp
@@ -15,8 +15,9 @@ void CardCounterSettings::setColor(int counterId, const QColor &color)
QString key = QString("cards/counters/%1/color").arg(counterId);
- if (settings.value(key).value() == color)
+ if (settings.value(key).value() == color) {
return;
+ }
settings.setValue(key, color);
emit colorChanged(counterId, color);
diff --git a/cockatrice/src/client/settings/card_counter_settings.h b/cockatrice/src/client/settings/card_counter_settings.h
index b1d467d67..2ac658177 100644
--- a/cockatrice/src/client/settings/card_counter_settings.h
+++ b/cockatrice/src/client/settings/card_counter_settings.h
@@ -1,8 +1,8 @@
/**
* @file card_counter_settings.h
* @ingroup GameSettings
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef CARD_COUNTER_SETTINGS_H
#define CARD_COUNTER_SETTINGS_H
diff --git a/cockatrice/src/client/settings/shortcut_treeview.h b/cockatrice/src/client/settings/shortcut_treeview.h
index 8d74a6f1e..afaf7e7ed 100644
--- a/cockatrice/src/client/settings/shortcut_treeview.h
+++ b/cockatrice/src/client/settings/shortcut_treeview.h
@@ -1,8 +1,8 @@
/**
* @file shortcut_treeview.h
* @ingroup CoreSettings
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef SHORTCUT_TREEVIEW_H
#define SHORTCUT_TREEVIEW_H
diff --git a/cockatrice/src/client/settings/shortcuts_settings.cpp b/cockatrice/src/client/settings/shortcuts_settings.cpp
index 53c6f6a23..2ff65ab6f 100644
--- a/cockatrice/src/client/settings/shortcuts_settings.cpp
+++ b/cockatrice/src/client/settings/shortcuts_settings.cpp
@@ -64,8 +64,13 @@ ShortcutsSettings::ShortcutsSettings(const QString &settingsPath, QObject *paren
}
}
-/// PR 5079 changes Textbox/unfocusTextBox to Player/unfocusTextBox and tab_game/aFocusChat to Player/aFocusChat.
-/// A migration is necessary to let players keep their already configured shortcuts.
+/**
+ * @brief Migrates legacy shortcut key names to current naming scheme.
+ *
+ * PR 5079 changed Textbox/unfocusTextBox to Player/unfocusTextBox and
+ * tab_game/aFocusChat to Player/aFocusChat. This migration allows players
+ * to keep their already configured shortcuts.
+ */
void ShortcutsSettings::migrateShortcuts()
{
if (QFile(settingsFilePath).exists()) {
@@ -236,9 +241,7 @@ bool ShortcutsSettings::isValid(const QString &name, const QString &sequences) c
return findOverlaps(name, sequences).isEmpty();
}
-/**
- * Checks if the shortcut is a shortcut that is active in all windows
- */
+/** @brief Checks if the shortcut is a shortcut that is active in all windows. */
static bool isAlwaysActiveShortcut(const QString &shortcutName)
{
return shortcutName.startsWith("MainWindow") || shortcutName.startsWith("Tabs");
diff --git a/cockatrice/src/client/settings/shortcuts_settings.h b/cockatrice/src/client/settings/shortcuts_settings.h
index 1de73c165..45e2c4fca 100644
--- a/cockatrice/src/client/settings/shortcuts_settings.h
+++ b/cockatrice/src/client/settings/shortcuts_settings.h
@@ -1,8 +1,8 @@
/**
* @file shortcuts_settings.h
* @ingroup CoreSettings
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef SHORTCUTSSETTINGS_H
#define SHORTCUTSSETTINGS_H
@@ -537,6 +537,9 @@ private:
{"Player/aSetAnnotation", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Set Annotation..."),
parseSequenceString("Alt+N"),
ShortcutGroup::Playing_Area)},
+ {"Player/aReduceLifeByPower", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Reduce Life by Power"),
+ parseSequenceString("Ctrl+Shift+L"),
+ ShortcutGroup::Playing_Area)},
{"Player/aSelectAll", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Select All Cards in Zone"),
parseSequenceString("Ctrl+A"),
ShortcutGroup::Playing_Area)},
@@ -664,6 +667,9 @@ private:
{"Player/aRollDie", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Roll Dice..."),
parseSequenceString("Ctrl+I"),
ShortcutGroup::Gameplay)},
+ {"Player/aFlipCoin", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Flip Coin"),
+ parseSequenceString("Ctrl+Shift+I"),
+ ShortcutGroup::Gameplay)},
{"Player/aShuffle", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Shuffle Library"),
parseSequenceString("Ctrl+S"),
ShortcutGroup::Gameplay)},
diff --git a/cockatrice/src/client/sound_engine.cpp b/cockatrice/src/client/sound_engine.cpp
index 31cb2a35e..e592b5ea0 100644
--- a/cockatrice/src/client/sound_engine.cpp
+++ b/cockatrice/src/client/sound_engine.cpp
@@ -105,8 +105,9 @@ QStringMap &SoundEngine::getAvailableThemes()
dir.setPath(SettingsCache::instance().getDataPath() + "/sounds");
for (const QString &themeName : dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name)) {
- if (!availableThemes.contains(themeName))
+ if (!availableThemes.contains(themeName)) {
availableThemes.insert(themeName, dir.absoluteFilePath(themeName));
+ }
}
// load themes from cockatrice system dir
@@ -121,8 +122,9 @@ QStringMap &SoundEngine::getAvailableThemes()
);
for (const QString &themeName : dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name)) {
- if (!availableThemes.contains(themeName))
+ if (!availableThemes.contains(themeName)) {
availableThemes.insert(themeName, dir.absoluteFilePath(themeName));
+ }
}
return availableThemes;
diff --git a/cockatrice/src/client/sound_engine.h b/cockatrice/src/client/sound_engine.h
index f45cccf7d..0c201523a 100644
--- a/cockatrice/src/client/sound_engine.h
+++ b/cockatrice/src/client/sound_engine.h
@@ -1,8 +1,8 @@
/**
* @file sound_engine.h
* @ingroup Core
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef SOUNDENGINE_H
#define SOUNDENGINE_H
diff --git a/cockatrice/src/filters/deck_filter_string.cpp b/cockatrice/src/filters/deck_filter_string.cpp
index 6b671831d..dd873cfa5 100644
--- a/cockatrice/src/filters/deck_filter_string.cpp
+++ b/cockatrice/src/filters/deck_filter_string.cpp
@@ -88,20 +88,27 @@ static void setupParserRules()
const auto arg = std::any_cast(sv[1]);
const auto op = std::any_cast(sv[0]);
- if (op == ">")
+ if (op == ">") {
return [=](const int s) { return s > arg; };
- if (op == ">=")
+ }
+ if (op == ">=") {
return [=](const int s) { return s >= arg; };
- if (op == "<")
+ }
+ if (op == "<") {
return [=](const int s) { return s < arg; };
- if (op == "<=")
+ }
+ if (op == "<=") {
return [=](const int s) { return s <= arg; };
- if (op == "=")
+ }
+ if (op == "=") {
return [=](const int s) { return s == arg; };
- if (op == ":")
+ }
+ if (op == ":") {
return [=](const int s) { return s == arg; };
- if (op == "!=")
+ }
+ if (op == "!=") {
return [=](const int s) { return s != arg; };
+ }
return [](int) { return false; };
};
diff --git a/cockatrice/src/filters/deck_filter_string.h b/cockatrice/src/filters/deck_filter_string.h
index 1b43d770d..916b629ee 100644
--- a/cockatrice/src/filters/deck_filter_string.h
+++ b/cockatrice/src/filters/deck_filter_string.h
@@ -1,8 +1,8 @@
/**
* @file deck_filter_string.h
* @ingroup DeckStorageWidgets
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef DECK_FILTER_STRING_H
#define DECK_FILTER_STRING_H
diff --git a/cockatrice/src/filters/filter_builder.cpp b/cockatrice/src/filters/filter_builder.cpp
index 7178ce95a..785f753e7 100644
--- a/cockatrice/src/filters/filter_builder.cpp
+++ b/cockatrice/src/filters/filter_builder.cpp
@@ -11,13 +11,15 @@ FilterBuilder::FilterBuilder(QWidget *parent) : QWidget(parent)
{
filterCombo = new QComboBox;
filterCombo->setObjectName("filterCombo");
- for (int i = 0; i < CardFilter::AttrEnd; i++)
+ for (int i = 0; i < CardFilter::AttrEnd; i++) {
filterCombo->addItem(CardFilter::attrName(static_cast(i)), QVariant(i));
+ }
typeCombo = new QComboBox;
typeCombo->setObjectName("typeCombo");
- for (int i = 0; i < CardFilter::TypeEnd; i++)
+ for (int i = 0; i < CardFilter::TypeEnd; i++) {
typeCombo->addItem(CardFilter::typeName(static_cast(i)), QVariant(i));
+ }
QPushButton *ok = new QPushButton(QPixmap("theme:icons/increment"), QString());
ok->setObjectName("ok");
@@ -53,8 +55,9 @@ FilterBuilder::~FilterBuilder()
void FilterBuilder::destroyFilter()
{
- if (fltr)
+ if (fltr) {
delete fltr;
+ }
}
static int comboCurrentIntData(const QComboBox *combo)
@@ -67,8 +70,9 @@ void FilterBuilder::emit_add()
QString txt;
txt = edit->text();
- if (txt.length() < 1)
+ if (txt.length() < 1) {
return;
+ }
destroyFilter();
fltr = new CardFilter(txt, static_cast(comboCurrentIntData(typeCombo)),
diff --git a/cockatrice/src/filters/filter_builder.h b/cockatrice/src/filters/filter_builder.h
index 74872e3cd..98fe3fd02 100644
--- a/cockatrice/src/filters/filter_builder.h
+++ b/cockatrice/src/filters/filter_builder.h
@@ -1,8 +1,8 @@
/**
* @file filter_builder.h
* @ingroup CardDatabaseModelFilters
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef FILTERBUILDER_H
#define FILTERBUILDER_H
diff --git a/cockatrice/src/filters/filter_tree_model.cpp b/cockatrice/src/filters/filter_tree_model.cpp
index f0a02ec79..33b54530e 100644
--- a/cockatrice/src/filters/filter_tree_model.cpp
+++ b/cockatrice/src/filters/filter_tree_model.cpp
@@ -23,8 +23,9 @@ void FilterTreeModel::proxyBeginInsertRow(const FilterTreeNode *node, int i)
int idx;
idx = node->index();
- if (idx >= 0)
+ if (idx >= 0) {
beginInsertRows(createIndex(idx, 0, (void *)node), i, i);
+ }
}
void FilterTreeModel::proxyEndInsertRow(const FilterTreeNode *node, int)
@@ -32,8 +33,9 @@ void FilterTreeModel::proxyEndInsertRow(const FilterTreeNode *node, int)
int idx;
idx = node->index();
- if (idx >= 0)
+ if (idx >= 0) {
endInsertRows();
+ }
}
void FilterTreeModel::proxyBeginRemoveRow(const FilterTreeNode *node, int i)
@@ -41,8 +43,9 @@ void FilterTreeModel::proxyBeginRemoveRow(const FilterTreeNode *node, int i)
int idx;
idx = node->index();
- if (idx >= 0)
+ if (idx >= 0) {
beginRemoveRows(createIndex(idx, 0, (void *)node), i, i);
+ }
}
void FilterTreeModel::proxyEndRemoveRow(const FilterTreeNode *node, int)
@@ -50,8 +53,9 @@ void FilterTreeModel::proxyEndRemoveRow(const FilterTreeNode *node, int)
int idx;
idx = node->index();
- if (idx >= 0)
+ if (idx >= 0) {
endRemoveRows();
+ }
}
FilterTreeNode *FilterTreeModel::indexToNode(const QModelIndex &idx) const
@@ -59,12 +63,14 @@ FilterTreeNode *FilterTreeModel::indexToNode(const QModelIndex &idx) const
void *ip;
FilterTreeNode *node;
- if (!idx.isValid())
+ if (!idx.isValid()) {
return fTree;
+ }
ip = idx.internalPointer();
- if (ip == NULL)
+ if (ip == NULL) {
return fTree;
+ }
node = static_cast(ip);
return node;
@@ -145,14 +151,16 @@ int FilterTreeModel::rowCount(const QModelIndex &parent) const
const FilterTreeNode *node;
int result;
- if (parent.column() > 0)
+ if (parent.column() > 0) {
return 0;
+ }
node = indexToNode(parent);
- if (node)
+ if (node) {
result = node->childCount();
- else
+ } else {
result = 0;
+ }
return result;
}
@@ -166,14 +174,17 @@ QVariant FilterTreeModel::data(const QModelIndex &index, int role) const
{
const FilterTreeNode *node;
- if (!index.isValid())
+ if (!index.isValid()) {
return QVariant();
- if (index.column() >= columnCount())
+ }
+ if (index.column() >= columnCount()) {
return QVariant();
+ }
node = indexToNode(index);
- if (node == NULL)
+ if (node == NULL) {
return QVariant();
+ }
switch (role) {
case Qt::FontRole:
@@ -190,10 +201,11 @@ QVariant FilterTreeModel::data(const QModelIndex &index, int role) const
case Qt::WhatsThisRole:
return node->text();
case Qt::CheckStateRole:
- if (node->isEnabled())
+ if (node->isEnabled()) {
return Qt::Checked;
- else
+ } else {
return Qt::Unchecked;
+ }
default:
return QVariant();
}
@@ -205,22 +217,27 @@ bool FilterTreeModel::setData(const QModelIndex &index, const QVariant &value, i
{
FilterTreeNode *node;
- if (!index.isValid())
+ if (!index.isValid()) {
return false;
- if (index.column() >= columnCount())
+ }
+ if (index.column() >= columnCount()) {
return false;
- if (role != Qt::CheckStateRole)
+ }
+ if (role != Qt::CheckStateRole) {
return false;
+ }
node = indexToNode(index);
- if (node == NULL || node == fTree)
+ if (node == NULL || node == fTree) {
return false;
+ }
Qt::CheckState state = static_cast(value.toInt());
- if (state == Qt::Checked)
+ if (state == Qt::Checked) {
node->enable();
- else
+ } else {
node->disable();
+ }
emit dataChanged(index, index);
return true;
@@ -231,16 +248,19 @@ Qt::ItemFlags FilterTreeModel::flags(const QModelIndex &index) const
const FilterTreeNode *node;
Qt::ItemFlags result;
- if (!index.isValid())
+ if (!index.isValid()) {
return Qt::NoItemFlags;
+ }
node = indexToNode(index);
- if (node == NULL)
+ if (node == NULL) {
return Qt::NoItemFlags;
+ }
result = Qt::ItemIsEnabled;
- if (node == fTree)
+ if (node == fTree) {
return result;
+ }
result |= Qt::ItemIsSelectable;
result |= Qt::ItemIsUserCheckable;
@@ -252,8 +272,9 @@ QModelIndex FilterTreeModel::nodeIndex(const FilterTreeNode *node, int row, int
{
FilterTreeNode *child;
- if (column > 0 || row >= node->childCount())
+ if (column > 0 || row >= node->childCount()) {
return QModelIndex();
+ }
child = node->nodeAt(row);
return createIndex(row, column, child);
@@ -263,12 +284,14 @@ QModelIndex FilterTreeModel::index(int row, int column, const QModelIndex &paren
{
const FilterTreeNode *node;
- if (!hasIndex(row, column, parent))
+ if (!hasIndex(row, column, parent)) {
return QModelIndex();
+ }
node = indexToNode(parent);
- if (node == NULL)
+ if (node == NULL) {
return QModelIndex();
+ }
return nodeIndex(node, row, column);
}
@@ -279,18 +302,21 @@ QModelIndex FilterTreeModel::parent(const QModelIndex &ind) const
FilterTreeNode *parent;
QModelIndex idx;
- if (!ind.isValid())
+ if (!ind.isValid()) {
return QModelIndex();
+ }
node = indexToNode(ind);
- if (node == NULL || node == fTree)
+ if (node == NULL || node == fTree) {
return QModelIndex();
+ }
parent = node->parent();
if (parent) {
int row = parent->index();
- if (row < 0)
+ if (row < 0) {
return QModelIndex();
+ }
idx = createIndex(row, 0, parent);
return idx;
}
@@ -304,18 +330,22 @@ bool FilterTreeModel::removeRows(int row, int count, const QModelIndex &parent)
int i, last;
last = row + count - 1;
- if (!parent.isValid() || count < 1 || row < 0)
+ if (!parent.isValid() || count < 1 || row < 0) {
return false;
+ }
node = indexToNode(parent);
- if (node == NULL || last >= node->childCount())
+ if (node == NULL || last >= node->childCount()) {
return false;
+ }
- for (i = 0; i < count; i++)
+ for (i = 0; i < count; i++) {
node->deleteAt(row);
+ }
- if (node != fTree && node->childCount() < 1)
+ if (node != fTree && node->childCount() < 1) {
return removeRow(parent.row(), parent.parent());
+ }
return true;
}
diff --git a/cockatrice/src/filters/filter_tree_model.h b/cockatrice/src/filters/filter_tree_model.h
index c6666a838..7452f7a61 100644
--- a/cockatrice/src/filters/filter_tree_model.h
+++ b/cockatrice/src/filters/filter_tree_model.h
@@ -1,8 +1,8 @@
/**
* @file filter_tree_model.h
* @ingroup CardDatabaseModelFilters
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef FILTERTREEMODEL_H
#define FILTERTREEMODEL_H
diff --git a/cockatrice/src/filters/syntax_help.h b/cockatrice/src/filters/syntax_help.h
index 7e5ef3e0e..d06fe03e5 100644
--- a/cockatrice/src/filters/syntax_help.h
+++ b/cockatrice/src/filters/syntax_help.h
@@ -2,8 +2,8 @@
* @file syntax_help.h
* @ingroup CardDatabaseModelFilters
* @ingroup DeckStorageWidgets
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef SEARCH_SYNTAX_HELP_H
#define SEARCH_SYNTAX_HELP_H
diff --git a/cockatrice/src/game/abstract_game.cpp b/cockatrice/src/game/abstract_game.cpp
index 9216f9174..5b1b4bff2 100644
--- a/cockatrice/src/game/abstract_game.cpp
+++ b/cockatrice/src/game/abstract_game.cpp
@@ -1,7 +1,7 @@
#include "abstract_game.h"
#include "../interface/widgets/tabs/tab_game.h"
-#include "player/player.h"
+#include "player/player_logic.h"
AbstractGame::AbstractGame(TabGame *_tab) : QObject(_tab), tab(_tab)
{
@@ -24,10 +24,11 @@ AbstractClient *AbstractGame::getClientForPlayer(int playerId) const
}
return gameState->getClients().at(playerId);
- } else if (gameState->getClients().isEmpty())
+ } else if (gameState->getClients().isEmpty()) {
return nullptr;
- else
+ } else {
return gameState->getClients().first();
+ }
}
void AbstractGame::loadReplay(GameReplay *replay)
@@ -43,13 +44,15 @@ void AbstractGame::setActiveCard(CardItem *card)
CardItem *AbstractGame::getCard(int playerId, const QString &zoneName, int cardId) const
{
- Player *player = playerManager->getPlayer(playerId);
- if (!player)
+ PlayerLogic *player = playerManager->getPlayer(playerId);
+ if (!player) {
return nullptr;
+ }
CardZoneLogic *zone = player->getZones().value(zoneName, 0);
- if (!zone)
+ if (!zone) {
return nullptr;
+ }
return zone->getCard(cardId);
}
\ No newline at end of file
diff --git a/cockatrice/src/game/abstract_game.h b/cockatrice/src/game/abstract_game.h
index cb4dbac2a..2441bac2d 100644
--- a/cockatrice/src/game/abstract_game.h
+++ b/cockatrice/src/game/abstract_game.h
@@ -1,8 +1,8 @@
/**
* @file abstract_game.h
* @ingroup GameLogic
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef COCKATRICE_ABSTRACT_GAME_H
#define COCKATRICE_ABSTRACT_GAME_H
diff --git a/cockatrice/src/game/arrow_registry.cpp b/cockatrice/src/game/arrow_registry.cpp
new file mode 100644
index 000000000..e679d2972
--- /dev/null
+++ b/cockatrice/src/game/arrow_registry.cpp
@@ -0,0 +1,48 @@
+#include "arrow_registry.h"
+
+#include "board/arrow_item.h"
+
+void ArrowRegistry::insert(QSharedPointer data, ArrowItem *arrow)
+{
+ const ArrowKey key{data->creatorId, data->id};
+
+ if (auto *existing = take(data->creatorId, data->id)) {
+ existing->delArrow();
+ }
+
+ dataStore.insert(key, data);
+ items.insert(key, arrow);
+ byPlayer[data->creatorId].insert(data->id);
+}
+
+ArrowItem *ArrowRegistry::take(int creatorId, int arrowId)
+{
+ const ArrowKey key{creatorId, arrowId};
+ dataStore.remove(key);
+ auto &playerSet = byPlayer[creatorId];
+ playerSet.remove(arrowId);
+ if (playerSet.isEmpty()) {
+ byPlayer.remove(creatorId);
+ }
+ return items.take(key);
+}
+
+ArrowItem *ArrowRegistry::get(int creatorId, int arrowId) const
+{
+ return items.value(ArrowKey{creatorId, arrowId}, nullptr);
+}
+
+bool ArrowRegistry::contains(int creatorId, int arrowId) const
+{
+ return items.contains(ArrowKey{creatorId, arrowId});
+}
+
+QSet ArrowRegistry::idsForPlayer(int playerId) const
+{
+ return byPlayer.value(playerId);
+}
+
+QList ArrowRegistry::all() const
+{
+ return items.values();
+}
\ No newline at end of file
diff --git a/cockatrice/src/game/arrow_registry.h b/cockatrice/src/game/arrow_registry.h
new file mode 100644
index 000000000..ef98229a2
--- /dev/null
+++ b/cockatrice/src/game/arrow_registry.h
@@ -0,0 +1,43 @@
+#ifndef COCKATRICE_ARROW_REGISTRY_H
+#define COCKATRICE_ARROW_REGISTRY_H
+
+#include "board/arrow_data.h"
+
+#include
+#include
+#include
+
+class ArrowItem;
+
+struct ArrowKey
+{
+ int creatorId;
+ int arrowId;
+
+ bool operator<(const ArrowKey &other) const
+ {
+ if (creatorId != other.creatorId) {
+ return creatorId < other.creatorId;
+ }
+ return arrowId < other.arrowId;
+ }
+};
+
+class ArrowRegistry
+{
+public:
+ void insert(QSharedPointer data, ArrowItem *arrow);
+ ArrowItem *take(int creatorId, int arrowId);
+
+ [[nodiscard]] ArrowItem *get(int creatorId, int arrowId) const;
+ [[nodiscard]] bool contains(int creatorId, int arrowId) const;
+ [[nodiscard]] QSet idsForPlayer(int playerId) const;
+ [[nodiscard]] QList all() const;
+
+private:
+ QMap> dataStore;
+ QMap items;
+ QMap> byPlayer;
+};
+
+#endif
\ No newline at end of file
diff --git a/cockatrice/src/game/board/abstract_card_drag_item.cpp b/cockatrice/src/game/board/abstract_card_drag_item.cpp
index 8e3def4ca..026efd60d 100644
--- a/cockatrice/src/game/board/abstract_card_drag_item.cpp
+++ b/cockatrice/src/game/board/abstract_card_drag_item.cpp
@@ -25,11 +25,12 @@ AbstractCardDragItem::AbstractCardDragItem(AbstractCardItem *_item,
setCursor(Qt::ClosedHandCursor);
setZValue(ZValues::DRAG_ITEM);
}
- if (item->getTapped())
+ if (item->getTapped()) {
setTransform(QTransform()
.translate(CardDimensions::WIDTH_HALF_F, CardDimensions::HEIGHT_HALF_F)
.rotate(90)
.translate(-CardDimensions::WIDTH_HALF_F, -CardDimensions::HEIGHT_HALF_F));
+ }
setCacheMode(DeviceCoordinateCache);
diff --git a/cockatrice/src/game/board/abstract_card_drag_item.h b/cockatrice/src/game/board/abstract_card_drag_item.h
index fe3b87983..1cbeb4fe7 100644
--- a/cockatrice/src/game/board/abstract_card_drag_item.h
+++ b/cockatrice/src/game/board/abstract_card_drag_item.h
@@ -1,8 +1,8 @@
/**
* @file abstract_card_drag_item.h
* @ingroup GameGraphicsCards
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef ABSTRACTCARDDRAGITEM_H
#define ABSTRACTCARDDRAGITEM_H
diff --git a/cockatrice/src/game/board/abstract_card_item.cpp b/cockatrice/src/game/board/abstract_card_item.cpp
index 9ec6ada9a..86b3e27c8 100644
--- a/cockatrice/src/game/board/abstract_card_item.cpp
+++ b/cockatrice/src/game/board/abstract_card_item.cpp
@@ -13,7 +13,7 @@
#include
#include
-AbstractCardItem::AbstractCardItem(QGraphicsItem *parent, const CardRef &cardRef, Player *_owner, int _id)
+AbstractCardItem::AbstractCardItem(QGraphicsItem *parent, const CardRef &cardRef, PlayerLogic *_owner, int _id)
: ArrowTarget(_owner, parent), id(_id), cardRef(cardRef), tapped(false), facedown(false), tapAngle(0),
bgColor(Qt::transparent), isHovered(false), realZValue(0)
{
@@ -85,7 +85,12 @@ const CardInfo &AbstractCardItem::getCardInfo() const
void AbstractCardItem::setRealZValue(qreal _zValue)
{
realZValue = _zValue;
- setZValue(_zValue);
+ // During hover, zValue is overridden to HOVERED_CARD. Layout operations
+ // like reorganizeCards() call setRealZValue() on all cards including the
+ // hovered one — skip setZValue() here to avoid clobbering the override.
+ if (!isHovered) {
+ setZValue(_zValue);
+ }
}
QSizeF AbstractCardItem::getTranslatedSize(QPainter *painter) const
@@ -126,8 +131,9 @@ void AbstractCardItem::paintPicture(QPainter *painter, const QSizeF &translatedS
// don't even spend time trying to load the picture if our size is too small
if (translatedSize.width() > 10) {
CardPictureLoader::getPixmap(translatedPixmap, exactCard, translatedSize.toSize());
- if (translatedPixmap.isNull())
+ if (translatedPixmap.isNull()) {
paintImage = false;
+ }
} else {
paintImage = false;
}
@@ -152,9 +158,9 @@ void AbstractCardItem::paintPicture(QPainter *painter, const QSizeF &translatedS
painter->setBackground(Qt::black);
painter->setBackgroundMode(Qt::OpaqueMode);
QString nameStr;
- if (facedown)
+ if (facedown) {
nameStr = "# " + QString::number(id);
- else {
+ } else {
QString prefix = "";
if (SettingsCache::instance().debug().getShowCardId()) {
prefix = "#" + QString::number(id) + " ";
@@ -181,10 +187,12 @@ void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *
if (isSelected() || isHovered) {
QPen pen;
- if (isHovered)
+ if (isHovered) {
pen.setColor(Qt::yellow);
- if (isSelected())
+ }
+ if (isSelected()) {
pen.setColor(Qt::red);
+ }
pen.setWidth(0); // Cosmetic pen
painter->setPen(pen);
painter->drawPath(shape());
@@ -210,11 +218,20 @@ void AbstractCardItem::setCardRef(const CardRef &_cardRef)
void AbstractCardItem::setHovered(bool _hovered)
{
- if (isHovered == _hovered)
+ if (isHovered == _hovered) {
return;
+ }
- if (_hovered)
+ if (_hovered) {
processHoverEvent();
+ } else {
+ // Mark the hovered card's current scene footprint dirty so overlapped
+ // sibling zones (e.g. StackZone) repaint after the card moves away.
+ if (scene()) {
+ scene()->update(sceneBoundingRect());
+ }
+ }
+
isHovered = _hovered;
setZValue(_hovered ? ZValues::HOVERED_CARD : realZValue);
setScale(_hovered && SettingsCache::instance().getScaleCards() ? 1.1 : 1);
@@ -265,13 +282,14 @@ void AbstractCardItem::cacheBgColor()
void AbstractCardItem::setTapped(bool _tapped, bool canAnimate)
{
- if (tapped == _tapped)
+ if (tapped == _tapped) {
return;
+ }
tapped = _tapped;
- if (SettingsCache::instance().getTapAnimation() && canAnimate)
+ if (SettingsCache::instance().getTapAnimation() && canAnimate) {
static_cast(scene())->registerAnimationItem(this);
- else {
+ } else {
tapAngle = tapped ? 90 : 0;
setTransform(QTransform()
.translate(CardDimensions::WIDTH_HALF_F, CardDimensions::HEIGHT_HALF_F)
@@ -297,17 +315,19 @@ void AbstractCardItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
scene()->clearSelection();
setSelected(true);
}
- if (event->button() == Qt::LeftButton)
+ if (event->button() == Qt::LeftButton) {
setCursor(Qt::ClosedHandCursor);
- else if (event->button() == Qt::MiddleButton)
+ } else if (event->button() == Qt::MiddleButton) {
emit showCardInfoPopup(event->screenPos(), cardRef);
+ }
event->accept();
}
void AbstractCardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
- if (event->button() == Qt::MiddleButton)
+ if (event->button() == Qt::MiddleButton) {
emit deleteCardInfoPopup(cardRef.name);
+ }
// This function ensures the parent function doesn't mess around with our selection.
event->accept();
@@ -323,6 +343,7 @@ QVariant AbstractCardItem::itemChange(QGraphicsItem::GraphicsItemChange change,
if (change == ItemSelectedHasChanged) {
update();
return value;
- } else
+ } else {
return ArrowTarget::itemChange(change, value);
+ }
}
diff --git a/cockatrice/src/game/board/abstract_card_item.h b/cockatrice/src/game/board/abstract_card_item.h
index 7d2c29cae..ed545e1ab 100644
--- a/cockatrice/src/game/board/abstract_card_item.h
+++ b/cockatrice/src/game/board/abstract_card_item.h
@@ -1,7 +1,7 @@
/**
* @file abstract_card_item.h
* @ingroup GameGraphicsCards
- * @brief TODO: Document this.
+ * @brief Base class for graphical card items, providing shared rendering, identity, and interaction logic.
*/
#ifndef ABSTRACTCARDITEM_H
@@ -14,7 +14,7 @@
#include
#include
-class Player;
+class PlayerLogic;
class AbstractCardItem : public ArrowTarget
{
@@ -56,7 +56,7 @@ public:
}
explicit AbstractCardItem(QGraphicsItem *parent = nullptr,
const CardRef &cardRef = {},
- Player *_owner = nullptr,
+ PlayerLogic *_owner = nullptr,
int _id = -1);
~AbstractCardItem() override;
QRectF boundingRect() const override;
@@ -96,6 +96,10 @@ public:
}
void setRealZValue(qreal _zValue);
void setHovered(bool _hovered);
+ bool getIsHovered() const
+ {
+ return isHovered;
+ }
QString getColor() const
{
return color;
diff --git a/cockatrice/src/game/board/abstract_counter.cpp b/cockatrice/src/game/board/abstract_counter.cpp
index 08d19ec8a..18787a0bc 100644
--- a/cockatrice/src/game/board/abstract_counter.cpp
+++ b/cockatrice/src/game/board/abstract_counter.cpp
@@ -2,13 +2,14 @@
#include "../../client/settings/cache_settings.h"
#include "../../interface/widgets/tabs/tab_game.h"
-#include "../player/player.h"
#include "../player/player_actions.h"
+#include "../player/player_logic.h"
#include "translate_counter_name.h"
#include
#include
#include
+#include
#include
#include
#include
@@ -16,24 +17,24 @@
#include
#include
-AbstractCounter::AbstractCounter(Player *_player,
- int _id,
- const QString &_name,
+AbstractCounter::AbstractCounter(CounterState *state,
+ PlayerLogic *_player,
bool _shownInCounterArea,
- int _value,
bool _useNameForShortcut,
QGraphicsItem *parent)
- : QGraphicsItem(parent), player(_player), id(_id), name(_name), value(_value),
- useNameForShortcut(_useNameForShortcut), hovered(false), aDec(nullptr), aInc(nullptr), dialogSemaphore(false),
- deleteAfterDialog(false), shownInCounterArea(_shownInCounterArea)
+ : QGraphicsItem(parent), player(_player), id(state->getId()), name(state->getName()), value(state->getValue()),
+ color(state->getColor()), radius(state->getRadius()), useNameForShortcut(_useNameForShortcut),
+ shownInCounterArea(_shownInCounterArea)
{
setAcceptHoverEvents(true);
- shortcutActive = false;
+ connect(state, &CounterState::valueChanged, this, [this](int, int newValue) {
+ value = newValue;
+ update();
+ });
if (player->getPlayerInfo()->getLocalOrJudge()) {
- QString displayName = TranslateCounterName::getDisplayName(_name);
- menu = new TearOffMenu(displayName);
+ menu = new TearOffMenu(TranslateCounterName::getDisplayName(state->getName()));
aSet = new QAction(this);
connect(aSet, &QAction::triggered, this, &AbstractCounter::setCounter);
menu->addAction(aSet);
@@ -41,16 +42,18 @@ AbstractCounter::AbstractCounter(Player *_player,
for (int i = 10; i >= -10; --i) {
if (i == 0) {
menu->addSeparator();
- } else {
- QAction *aIncrement = new QAction(QString(i < 0 ? "%1" : "+%1").arg(i), this);
- if (i == -1)
- aDec = aIncrement;
- else if (i == 1)
- aInc = aIncrement;
- aIncrement->setData(i);
- connect(aIncrement, &QAction::triggered, this, &AbstractCounter::incrementCounter);
- menu->addAction(aIncrement);
+ continue;
}
+ auto *a = new QAction(QString(i < 0 ? "%1" : "+%1").arg(i), this);
+ if (i == -1) {
+ aDec = a;
+ }
+ if (i == 1) {
+ aInc = a;
+ }
+ a->setData(i);
+ connect(a, &QAction::triggered, this, &AbstractCounter::incrementCounter);
+ menu->addAction(a);
}
} else {
menu = nullptr;
@@ -69,39 +72,35 @@ AbstractCounter::~AbstractCounter()
void AbstractCounter::delCounter()
{
- if (dialogSemaphore)
+ if (dialogSemaphore) {
deleteAfterDialog = true;
- else
+ } else {
deleteLater();
+ }
}
void AbstractCounter::retranslateUi()
{
- if (menu) {
+ if (aSet) {
aSet->setText(tr("&Set counter..."));
}
}
void AbstractCounter::setShortcutsActive()
{
- if (!menu) {
+ if (!menu || !player->getPlayerInfo()->getLocal()) {
return;
}
- if (!player->getPlayerInfo()->getLocal()) {
- return;
- }
-
- ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
+ ShortcutsSettings &sc = SettingsCache::instance().shortcuts();
+ shortcutActive = true;
if (name == "life") {
- shortcutActive = true;
- aSet->setShortcuts(shortcuts.getShortcut("Player/aSet"));
- aDec->setShortcuts(shortcuts.getShortcut("Player/aDec"));
- aInc->setShortcuts(shortcuts.getShortcut("Player/aInc"));
+ aSet->setShortcuts(sc.getShortcut("Player/aSet"));
+ aDec->setShortcuts(sc.getShortcut("Player/aDec"));
+ aInc->setShortcuts(sc.getShortcut("Player/aInc"));
} else if (useNameForShortcut) {
- shortcutActive = true;
- aSet->setShortcuts(shortcuts.getShortcut("Player/aSetCounter_" + name));
- aDec->setShortcuts(shortcuts.getShortcut("Player/aDecCounter_" + name));
- aInc->setShortcuts(shortcuts.getShortcut("Player/aIncCounter_" + name));
+ aSet->setShortcuts(sc.getShortcut("Player/aSetCounter_" + name));
+ aDec->setShortcuts(sc.getShortcut("Player/aDecCounter_" + name));
+ aInc->setShortcuts(sc.getShortcut("Player/aIncCounter_" + name));
}
}
@@ -126,43 +125,32 @@ void AbstractCounter::refreshShortcuts()
}
}
-void AbstractCounter::setValue(int _value)
-{
- value = _value;
- update();
-}
-
void AbstractCounter::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
- if (isUnderMouse() && player->getPlayerInfo()->getLocalOrJudge()) {
- if (event->button() == Qt::MiddleButton || (QApplication::keyboardModifiers() & Qt::ShiftModifier)) {
- if (menu)
- menu->exec(event->screenPos());
- event->accept();
- } else if (event->button() == Qt::LeftButton) {
- Command_IncCounter cmd;
- cmd.set_counter_id(id);
- cmd.set_delta(1);
- player->getPlayerActions()->sendGameCommand(cmd);
- event->accept();
- } else if (event->button() == Qt::RightButton) {
- Command_IncCounter cmd;
- cmd.set_counter_id(id);
- cmd.set_delta(-1);
- player->getPlayerActions()->sendGameCommand(cmd);
- event->accept();
- }
- } else
+ if (!isUnderMouse() || !player->getPlayerInfo()->getLocalOrJudge()) {
event->ignore();
+ return;
+ }
+
+ if (event->button() == Qt::MiddleButton || QApplication::keyboardModifiers() & Qt::ShiftModifier) {
+ if (menu) {
+ menu->exec(event->screenPos());
+ }
+ } else {
+ Command_IncCounter cmd;
+ cmd.set_counter_id(id);
+ cmd.set_delta(event->button() == Qt::LeftButton ? 1 : -1);
+ player->getPlayerActions()->sendGameCommand(cmd);
+ }
+ event->accept();
}
-void AbstractCounter::hoverEnterEvent(QGraphicsSceneHoverEvent * /*event*/)
+void AbstractCounter::hoverEnterEvent(QGraphicsSceneHoverEvent *)
{
hovered = true;
update();
}
-
-void AbstractCounter::hoverLeaveEvent(QGraphicsSceneHoverEvent * /*event*/)
+void AbstractCounter::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
{
hovered = false;
update();
@@ -170,34 +158,36 @@ void AbstractCounter::hoverLeaveEvent(QGraphicsSceneHoverEvent * /*event*/)
void AbstractCounter::incrementCounter()
{
- const int delta = static_cast(sender())->data().toInt();
Command_IncCounter cmd;
cmd.set_counter_id(id);
- cmd.set_delta(delta);
+ cmd.set_delta(static_cast(sender())->data().toInt());
player->getPlayerActions()->sendGameCommand(cmd);
}
void AbstractCounter::setCounter()
{
+ QWidget *parent = nullptr;
+ if (auto *view = scene() ? scene()->views().value(0) : nullptr) {
+ parent = view->window();
+ }
+
dialogSemaphore = true;
- AbstractCounterDialog dialog(name, QString::number(value), player->getGame()->getTab());
- const int ok = dialog.exec();
+ AbstractCounterDialog dlg(name, QString::number(value), parent);
+ const int ok = dlg.exec();
+ dialogSemaphore = false;
if (deleteAfterDialog) {
deleteLater();
return;
}
- dialogSemaphore = false;
-
- if (!ok)
+ if (!ok) {
return;
+ }
Expression exp(value);
- int newValue = static_cast(exp.parse(dialog.textValue()));
-
Command_SetCounter cmd;
cmd.set_counter_id(id);
- cmd.set_value(newValue);
+ cmd.set_value(static_cast(exp.parse(dlg.textValue())));
player->getPlayerActions()->sendGameCommand(cmd);
}
@@ -231,8 +221,9 @@ void AbstractCounterDialog::changeValue(int diff)
{
bool ok;
int curValue = textValue().toInt(&ok);
- if (!ok)
+ if (!ok) {
return;
+ }
curValue += diff;
setTextValue(QString::number(curValue));
}
diff --git a/cockatrice/src/game/board/abstract_counter.h b/cockatrice/src/game/board/abstract_counter.h
index 074650d54..b31bd1aa3 100644
--- a/cockatrice/src/game/board/abstract_counter.h
+++ b/cockatrice/src/game/board/abstract_counter.h
@@ -1,19 +1,20 @@
/**
* @file abstract_counter.h
* @ingroup GameGraphicsPlayers
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef COUNTER_H
#define COUNTER_H
#include "../../interface/widgets/menus/tearoff_menu.h"
#include "../player/menu/abstract_player_component.h"
+#include "counter_state.h"
#include
#include
-class Player;
+class PlayerLogic;
class QAction;
class QKeyEvent;
class QMenu;
@@ -25,22 +26,26 @@ class AbstractCounter : public QObject, public QGraphicsItem, public AbstractPla
Q_INTERFACES(QGraphicsItem)
protected:
- Player *player;
+ PlayerLogic *player;
int id;
QString name;
int value;
- bool useNameForShortcut, hovered;
+ QColor color;
+ int radius;
+ bool hovered = false;
+ bool useNameForShortcut;
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
private:
- QAction *aSet, *aDec, *aInc;
- TearOffMenu *menu;
- bool dialogSemaphore, deleteAfterDialog;
+ QAction *aSet = nullptr, *aDec = nullptr, *aInc = nullptr;
+ TearOffMenu *menu = nullptr;
+ bool dialogSemaphore = false;
+ bool deleteAfterDialog = false;
bool shownInCounterArea;
- bool shortcutActive;
+ bool shortcutActive = false;
private slots:
void refreshShortcuts();
@@ -48,17 +53,14 @@ private slots:
void setCounter();
public:
- AbstractCounter(Player *_player,
- int _id,
- const QString &_name,
- bool _shownInCounterArea,
- int _value,
- bool _useNameForShortcut = false,
+ AbstractCounter(CounterState *state,
+ PlayerLogic *player,
+ bool shownInCounterArea,
+ bool useNameForShortcut = false,
QGraphicsItem *parent = nullptr);
~AbstractCounter() override;
void retranslateUi() override;
- void setValue(int _value);
void setShortcutsActive() override;
void setShortcutsInactive() override;
void delCounter();
@@ -67,7 +69,6 @@ public:
{
return menu;
}
-
int getId() const
{
return id;
@@ -76,14 +77,22 @@ public:
{
return name;
}
- bool getShownInCounterArea() const
+ QColor getColor() const
{
- return shownInCounterArea;
+ return color;
+ }
+ int getRadius() const
+ {
+ return radius;
}
int getValue() const
{
return value;
}
+ bool getShownInCounterArea() const
+ {
+ return shownInCounterArea;
+ }
};
class AbstractCounterDialog : public QInputDialog
diff --git a/cockatrice/src/game/board/arrow_data.cpp b/cockatrice/src/game/board/arrow_data.cpp
new file mode 100644
index 000000000..9e89deed0
--- /dev/null
+++ b/cockatrice/src/game/board/arrow_data.cpp
@@ -0,0 +1,21 @@
+#include "arrow_data.h"
+
+ArrowData ArrowData::fromProto(const ServerInfo_Arrow &arrow, int creatorId, bool isLocalCreator)
+{
+ ArrowData data;
+ data.creatorId = creatorId;
+ data.isLocalCreator = isLocalCreator;
+ data.id = arrow.id();
+ data.startPlayerId = arrow.start_player_id();
+ data.startZone = QString::fromStdString(arrow.start_zone());
+ data.startCardId = arrow.start_card_id();
+ data.targetPlayerId = arrow.target_player_id();
+ data.color = convertColorToQColor(arrow.arrow_color());
+
+ if (arrow.has_target_zone()) {
+ data.targetZone = QString::fromStdString(arrow.target_zone());
+ data.targetCardId = arrow.target_card_id();
+ }
+
+ return data;
+}
\ No newline at end of file
diff --git a/cockatrice/src/game/board/arrow_data.h b/cockatrice/src/game/board/arrow_data.h
new file mode 100644
index 000000000..2752f97e3
--- /dev/null
+++ b/cockatrice/src/game/board/arrow_data.h
@@ -0,0 +1,30 @@
+#ifndef COCKATRICE_ARROW_DATA_H
+#define COCKATRICE_ARROW_DATA_H
+
+#include
+#include
+#include
+#include
+
+struct ArrowData
+{
+ int creatorId = -1;
+ bool isLocalCreator = false;
+ int id = -1;
+ int startPlayerId = -1;
+ QString startZone = "";
+ int startCardId = -1;
+ int targetPlayerId = -1;
+ QString targetZone = "";
+ int targetCardId = -1;
+ QColor color = "";
+
+ static ArrowData fromProto(const ServerInfo_Arrow &arrow, int creatorId, bool isLocalCreator);
+
+ bool isPlayerTargeted() const
+ {
+ return targetZone.isEmpty();
+ }
+};
+
+#endif // COCKATRICE_ARROW_DATA_H
diff --git a/cockatrice/src/game/board/arrow_item.cpp b/cockatrice/src/game/board/arrow_item.cpp
index 60585a774..0b740bc70 100644
--- a/cockatrice/src/game/board/arrow_item.cpp
+++ b/cockatrice/src/game/board/arrow_item.cpp
@@ -2,11 +2,11 @@
#include "arrow_item.h"
#include "../../client/settings/cache_settings.h"
-#include "../player/player.h"
+#include "../../game_graphics/zones/card_zone.h"
#include "../player/player_actions.h"
+#include "../player/player_logic.h"
#include "../player/player_target.h"
#include "../z_values.h"
-#include "../zones/card_zone.h"
#include "card_item.h"
#include
@@ -21,46 +21,49 @@
#include
#include
-ArrowItem::ArrowItem(Player *_player, int _id, ArrowTarget *_startItem, ArrowTarget *_targetItem, const QColor &_color)
- : QGraphicsItem(), player(_player), id(_id), startItem(_startItem), targetItem(_targetItem), targetLocked(false),
- color(_color), fullColor(true)
+ArrowItem::ArrowItem(QSharedPointer _data, ArrowTarget *_startItem, ArrowTarget *_targetItem)
+ : data(std::move(_data)), startItem(_startItem), targetItem(_targetItem)
{
setZValue(ZValues::ARROWS);
- if (startItem)
- startItem->addArrowFrom(this);
- if (targetItem)
- targetItem->addArrowTo(this);
+ auto doUpdate = [this]() {
+ if (startItem && targetItem) {
+ updatePath();
+ }
+ };
- if (startItem && targetItem)
+ if (startItem) {
+ connect(startItem, &ArrowTarget::scenePositionChanged, this, doUpdate);
+ connect(startItem, &QObject::destroyed, this, &ArrowItem::onTargetDestroyed);
+ }
+ if (targetItem) {
+ connect(targetItem, &ArrowTarget::scenePositionChanged, this, doUpdate);
+ connect(targetItem, &QObject::destroyed, this, &ArrowItem::onTargetDestroyed);
+ }
+
+ if (startItem && targetItem) {
updatePath();
+ }
}
-ArrowItem::~ArrowItem()
+void ArrowItem::onTargetDestroyed()
{
+ emit requestDeletion(data->creatorId, data->id);
}
void ArrowItem::delArrow()
{
- if (startItem) {
- startItem->removeArrowFrom(this);
- startItem = 0;
- }
-
if (targetItem) {
targetItem->setBeingPointedAt(false);
- targetItem->removeArrowTo(this);
- targetItem = 0;
}
-
- player->removeArrow(this);
deleteLater();
}
void ArrowItem::updatePath()
{
- if (!targetItem)
+ if (!targetItem) {
return;
+ }
QPointF endPoint = targetItem->mapToScene(
QPointF(targetItem->boundingRect().width() / 2, targetItem->boundingRect().height() / 2));
@@ -75,8 +78,9 @@ void ArrowItem::updatePath(const QPointF &endPoint)
headWidth / qPow(2, 0.5); // aka headWidth / sqrt (2) but this produces a compile error with MSVC++
const double phi = 15;
- if (!startItem)
+ if (!startItem) {
return;
+ }
QPointF startPoint =
startItem->mapToScene(QPointF(startItem->boundingRect().width() / 2, startItem->boundingRect().height() / 2));
@@ -84,9 +88,9 @@ void ArrowItem::updatePath(const QPointF &endPoint)
qreal lineLength = line.length();
prepareGeometryChange();
- if (lineLength < 30)
+ if (lineLength < 30) {
path = QPainterPath();
- else {
+ } else {
QPointF c(lineLength / 2, qTan(phi * M_PI / 180) * lineLength);
QPainterPath centerLine;
@@ -122,24 +126,24 @@ void ArrowItem::updatePath(const QPointF &endPoint)
void ArrowItem::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
{
- QColor paintColor(color);
- if (fullColor)
+ QColor paintColor(data->color);
+ if (fullColor) {
paintColor.setAlpha(200);
- else
+ } else {
paintColor.setAlpha(150);
+ }
painter->setBrush(paintColor);
painter->drawPath(path);
}
void ArrowItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
- if (!player->getPlayerInfo()->getLocal()) {
+ if (!data->isLocalCreator) {
event->ignore();
return;
}
- QList colliding = scene()->items(event->scenePos());
- for (QGraphicsItem *item : colliding) {
+ for (auto *item : scene()->items(event->scenePos())) {
if (qgraphicsitem_cast(item)) {
event->ignore();
return;
@@ -148,95 +152,109 @@ void ArrowItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
event->accept();
if (event->button() == Qt::RightButton) {
- Command_DeleteArrow cmd;
- cmd.set_arrow_id(id);
- player->getPlayerActions()->sendGameCommand(cmd);
+ emit requestDeletion(data->creatorId, data->id);
}
}
-ArrowDragItem::ArrowDragItem(Player *_owner, ArrowTarget *_startItem, const QColor &_color, int _deleteInPhase)
- : ArrowItem(_owner, -1, _startItem, 0, _color), deleteInPhase(_deleteInPhase)
+// ArrowDragItem
+
+ArrowDragItem::ArrowDragItem(PlayerLogic *_owner, ArrowTarget *_startItem, const QColor &_color, int _deleteInPhase)
+ : ArrowItem(QSharedPointer::create(ArrowData{.creatorId = _owner->getPlayerInfo()->getId(),
+ .isLocalCreator = true,
+ .id = -1,
+ .color = _color}),
+ _startItem,
+ nullptr),
+ player(_owner), deleteInPhase(_deleteInPhase)
{
}
-void ArrowDragItem::addChildArrow(ArrowDragItem *childArrow)
+void ArrowDragItem::addChildArrow(ArrowDragItem *child)
{
- childArrows.append(childArrow);
+ childArrows.append(child);
}
void ArrowDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
- // This ensures that if a mouse move event happens after a call to delArrow(),
- // the event will be discarded as it would create some stray pointers.
- if (targetLocked || !startItem)
+ if (targetLocked || !startItem) {
return;
+ }
- QPointF endPos = event->scenePos();
+ const QPointF endPos = event->scenePos();
- QList colliding = scene()->items(endPos);
- ArrowTarget *cursorItem = 0;
+ ArrowTarget *cursorItem = nullptr;
qreal cursorItemZ = -1;
- for (int i = colliding.size() - 1; i >= 0; i--) {
- if (qgraphicsitem_cast(colliding.at(i)) || qgraphicsitem_cast(colliding.at(i))) {
- if (colliding.at(i)->zValue() > cursorItemZ) {
- cursorItem = static_cast(colliding.at(i));
- cursorItemZ = cursorItem->zValue();
- }
+ for (auto *item : scene()->items(endPos)) {
+ ArrowTarget *candidate = nullptr;
+ if (auto *card = qgraphicsitem_cast(item)) {
+ candidate = card;
+ } else if (auto *pt = qgraphicsitem_cast(item)) {
+ candidate = pt;
+ }
+
+ if (candidate && candidate->zValue() > cursorItemZ) {
+ cursorItem = candidate;
+ cursorItemZ = candidate->zValue();
}
}
- if ((cursorItem != targetItem) && targetItem) {
- targetItem->setBeingPointedAt(false);
- targetItem->removeArrowTo(this);
- }
- if (!cursorItem) {
- fullColor = false;
- targetItem = 0;
- updatePath(endPos);
- } else {
- if (cursorItem != targetItem) {
- fullColor = true;
- if (cursorItem != startItem) {
- cursorItem->setBeingPointedAt(true);
- cursorItem->addArrowTo(this);
- }
- targetItem = cursorItem;
+ if (cursorItem != targetItem) {
+ if (targetItem) {
+ disconnect(positionConnection);
+ targetItem->setBeingPointedAt(false);
+ }
+
+ targetItem = cursorItem;
+ fullColor = (cursorItem != nullptr);
+
+ if (cursorItem && cursorItem != startItem) {
+ cursorItem->setBeingPointedAt(true);
+ positionConnection =
+ connect(cursorItem, &ArrowTarget::scenePositionChanged, this, [this]() { updatePath(); });
}
- updatePath();
}
+
+ targetItem ? updatePath() : updatePath(endPos);
update();
- for (ArrowDragItem *child : childArrows) {
+ for (auto *child : childArrows) {
child->mouseMoveEvent(event);
}
}
void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
- if (!startItem)
+ if (!startItem) {
return;
+ }
- if (targetItem && (targetItem != startItem)) {
- CardZoneLogic *startZone = static_cast(startItem)->getZone();
+ if (targetItem && targetItem != startItem) {
+ CardItem *startCard = qgraphicsitem_cast(startItem);
// For now, we can safely assume that the start item is always a card.
// The target item can be a player as well.
- CardItem *startCard = qgraphicsitem_cast(startItem);
- CardItem *targetCard = qgraphicsitem_cast(targetItem);
+ if (!startCard) {
+ delArrow();
+ return;
+ }
+
+ CardZoneLogic *startZone = startCard->getZone();
Command_CreateArrow cmd;
- cmd.mutable_arrow_color()->CopyFrom(convertQColorToColor(color));
+ cmd.mutable_arrow_color()->CopyFrom(convertQColorToColor(data->color));
cmd.set_start_player_id(startZone->getPlayer()->getPlayerInfo()->getId());
cmd.set_start_zone(startZone->getName().toStdString());
cmd.set_start_card_id(startCard->getId());
- if (targetCard) {
+ if (auto *targetCard = qgraphicsitem_cast(targetItem)) {
CardZoneLogic *targetZone = targetCard->getZone();
cmd.set_target_player_id(targetZone->getPlayer()->getPlayerInfo()->getId());
cmd.set_target_zone(targetZone->getName().toStdString());
cmd.set_target_card_id(targetCard->getId());
- } else { // failed to cast target to card, this means it's a player
- PlayerTarget *targetPlayer = qgraphicsitem_cast(targetItem);
+ } else if (auto *targetPlayer = qgraphicsitem_cast(targetItem)) {
cmd.set_target_player_id(targetPlayer->getOwner()->getPlayerInfo()->getId());
+ } else {
+ delArrow();
+ return;
}
// if the card is in hand then we will move the card to stack or table as part of drawing the arrow
@@ -246,10 +264,11 @@ void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
bool playToStack = SettingsCache::instance().getPlayToStack();
if (ci && ((!playToStack && ci->getUiAttributes().tableRow == 3) ||
(playToStack && ci->getUiAttributes().tableRow != 0 &&
- startCard->getZone()->getName() != ZoneNames::STACK)))
+ startCard->getZone()->getName() != ZoneNames::STACK))) {
cmd.set_start_zone(ZoneNames::STACK);
- else
+ } else {
cmd.set_start_zone(playToStack ? ZoneNames::STACK : ZoneNames::TABLE);
+ }
}
if (deleteInPhase != 0) {
@@ -258,111 +277,116 @@ void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
player->getPlayerActions()->sendGameCommand(cmd);
}
- delArrow();
- for (ArrowDragItem *child : childArrows) {
+ delArrow();
+ for (auto *child : childArrows) {
child->mouseReleaseEvent(event);
}
}
+// ArrowAttachItem
ArrowAttachItem::ArrowAttachItem(ArrowTarget *_startItem)
- : ArrowItem(_startItem->getOwner(), -1, _startItem, 0, Qt::green)
+ : ArrowItem(
+ QSharedPointer::create(ArrowData{.creatorId = _startItem->getOwner()->getPlayerInfo()->getId(),
+ .isLocalCreator = true,
+ .id = -1,
+ .color = Qt::green}),
+ _startItem,
+ nullptr),
+ player(_startItem->getOwner())
{
}
-void ArrowAttachItem::addChildArrow(ArrowAttachItem *childArrow)
+void ArrowAttachItem::addChildArrow(ArrowAttachItem *child)
{
- childArrows.append(childArrow);
+ childArrows.append(child);
}
void ArrowAttachItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
- if (targetLocked || !startItem)
+ if (targetLocked || !startItem) {
return;
+ }
- QPointF endPos = event->scenePos();
+ const QPointF endPos = event->scenePos();
- QList colliding = scene()->items(endPos);
- ArrowTarget *cursorItem = 0;
+ ArrowTarget *cursorItem = nullptr;
qreal cursorItemZ = -1;
- for (int i = colliding.size() - 1; i >= 0; i--) {
- if (qgraphicsitem_cast(colliding.at(i))) {
- if (colliding.at(i)->zValue() > cursorItemZ) {
- cursorItem = static_cast(colliding.at(i));
- cursorItemZ = cursorItem->zValue();
+ for (auto *item : scene()->items(endPos)) {
+ if (auto *card = qgraphicsitem_cast(item)) {
+ if (card->zValue() > cursorItemZ) {
+ cursorItem = card;
+ cursorItemZ = card->zValue();
}
}
}
- if ((cursorItem != targetItem) && targetItem) {
- targetItem->setBeingPointedAt(false);
- }
- if (!cursorItem) {
- fullColor = false;
- targetItem = 0;
- updatePath(endPos);
- } else {
- fullColor = true;
- if (cursorItem != startItem) {
- cursorItem->setBeingPointedAt(true);
+ if (cursorItem != targetItem) {
+ if (targetItem) {
+ disconnect(positionConnection);
+ targetItem->setBeingPointedAt(false);
}
+
targetItem = cursorItem;
- updatePath();
+ fullColor = (cursorItem != nullptr);
+
+ if (cursorItem && cursorItem != startItem) {
+ cursorItem->setBeingPointedAt(true);
+ positionConnection =
+ connect(cursorItem, &ArrowTarget::scenePositionChanged, this, [this]() { updatePath(); });
+ }
}
+
+ targetItem ? updatePath() : updatePath(endPos);
update();
- for (ArrowAttachItem *child : childArrows) {
+ for (auto *child : childArrows) {
child->mouseMoveEvent(event);
}
}
-void ArrowAttachItem::attachCards(CardItem *startCard, const CardItem *targetCard)
-{
- // do nothing if target is already attached to another card or is not in play
- if (targetCard->getAttachedTo() || targetCard->getZone()->getName() != ZoneNames::TABLE) {
- return;
- }
-
- CardZoneLogic *startZone = startCard->getZone();
- CardZoneLogic *targetZone = targetCard->getZone();
-
- // move card onto table first if attaching from some other zone
- if (startZone->getName() != ZoneNames::TABLE) {
- player->getPlayerActions()->playCardToTable(startCard, false);
- }
-
- Command_AttachCard cmd;
- cmd.set_start_zone(ZoneNames::TABLE);
- cmd.set_card_id(startCard->getId());
- cmd.set_target_player_id(targetZone->getPlayer()->getPlayerInfo()->getId());
- cmd.set_target_zone(targetZone->getName().toStdString());
- cmd.set_target_card_id(targetCard->getId());
-
- player->getPlayerActions()->sendGameCommand(cmd);
-}
-
void ArrowAttachItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
- if (!startItem)
+ if (!startItem) {
return;
+ }
// Attaching could move startItem under the current cursor position, causing all children to retarget to it right
// before they are processed. Prevent that.
- for (ArrowAttachItem *child : childArrows) {
+ for (auto *child : childArrows) {
child->setTargetLocked(true);
}
- if (targetItem && (targetItem != startItem)) {
- auto startCard = qgraphicsitem_cast(startItem);
- auto targetCard = qgraphicsitem_cast(targetItem);
+ if (targetItem && targetItem != startItem) {
+ auto *startCard = qgraphicsitem_cast(startItem);
+ auto *targetCard = qgraphicsitem_cast(targetItem);
if (startCard && targetCard) {
attachCards(startCard, targetCard);
}
}
delArrow();
-
- for (ArrowAttachItem *child : childArrows) {
+ for (auto *child : childArrows) {
child->mouseReleaseEvent(event);
}
}
+
+void ArrowAttachItem::attachCards(CardItem *startCard, const CardItem *targetCard)
+{
+ if (targetCard->getAttachedTo() || targetCard->getZone()->getName() != ZoneNames::TABLE) {
+ return;
+ }
+
+ // move card onto table first if attaching from some other zone
+ if (startCard->getZone()->getName() != ZoneNames::TABLE) {
+ player->getPlayerActions()->playCardToTable(startCard, false);
+ }
+
+ Command_AttachCard cmd;
+ cmd.set_start_zone(ZoneNames::TABLE);
+ cmd.set_card_id(startCard->getId());
+ cmd.set_target_player_id(targetCard->getZone()->getPlayer()->getPlayerInfo()->getId());
+ cmd.set_target_zone(targetCard->getZone()->getName().toStdString());
+ cmd.set_target_card_id(targetCard->getId());
+ player->getPlayerActions()->sendGameCommand(cmd);
+}
\ No newline at end of file
diff --git a/cockatrice/src/game/board/arrow_item.h b/cockatrice/src/game/board/arrow_item.h
index cb78ee066..0c04c27f8 100644
--- a/cockatrice/src/game/board/arrow_item.h
+++ b/cockatrice/src/game/board/arrow_item.h
@@ -1,40 +1,44 @@
-/**
- * @file arrow_item.h
- * @ingroup GameGraphics
- * @brief TODO: Document this.
- */
-
#ifndef ARROWITEM_H
#define ARROWITEM_H
+#include "arrow_data.h"
+#include "arrow_target.h"
+
#include
+#include
+#include
class CardItem;
class QGraphicsSceneMouseEvent;
-class QMenu;
-class Player;
-class ArrowTarget;
+class PlayerLogic;
class ArrowItem : public QObject, public QGraphicsItem
{
Q_OBJECT
Q_INTERFACES(QGraphicsItem)
+signals:
+ void requestDeletion(int creatorId, int id);
+
private:
QPainterPath path;
- QMenu *menu;
protected:
- Player *player;
- int id;
- ArrowTarget *startItem, *targetItem;
- bool targetLocked;
- QColor color;
- bool fullColor;
+ QSharedPointer data;
+ QPointer startItem;
+ QPointer targetItem;
+ bool targetLocked = false;
+ bool fullColor = true;
+
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
public:
- ArrowItem(Player *_player, int _id, ArrowTarget *_startItem, ArrowTarget *_targetItem, const QColor &color);
- ~ArrowItem() override;
+ ArrowItem(QSharedPointer _data, ArrowTarget *_startItem, ArrowTarget *_targetItem);
+
+ void onTargetDestroyed();
+ void delArrow();
+ void updatePath();
+ void updatePath(const QPointF &endPoint);
+
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
[[nodiscard]] QRectF boundingRect() const override
{
@@ -44,24 +48,13 @@ public:
{
return path;
}
- void updatePath();
- void updatePath(const QPointF &endPoint);
-
[[nodiscard]] int getId() const
{
- return id;
+ return data->id;
}
- [[nodiscard]] Player *getPlayer() const
+ [[nodiscard]] int getCreatorId() const
{
- return player;
- }
- void setStartItem(ArrowTarget *_item)
- {
- startItem = _item;
- }
- void setTargetItem(ArrowTarget *_item)
- {
- targetItem = _item;
+ return data->creatorId;
}
[[nodiscard]] ArrowTarget *getStartItem() const
{
@@ -75,19 +68,20 @@ public:
{
targetLocked = _targetLocked;
}
- void delArrow();
};
class ArrowDragItem : public ArrowItem
{
Q_OBJECT
private:
+ PlayerLogic *player;
int deleteInPhase;
QList childArrows;
+ QMetaObject::Connection positionConnection;
public:
- ArrowDragItem(Player *_owner, ArrowTarget *_startItem, const QColor &_color, int _deleteInPhase);
- void addChildArrow(ArrowDragItem *childArrow);
+ ArrowDragItem(PlayerLogic *_owner, ArrowTarget *_startItem, const QColor &_color, int _deleteInPhase);
+ void addChildArrow(ArrowDragItem *child);
protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
@@ -98,17 +92,18 @@ class ArrowAttachItem : public ArrowItem
{
Q_OBJECT
private:
+ PlayerLogic *player;
QList childArrows;
-
+ QMetaObject::Connection positionConnection;
void attachCards(CardItem *startCard, const CardItem *targetCard);
public:
explicit ArrowAttachItem(ArrowTarget *_startItem);
- void addChildArrow(ArrowAttachItem *childArrow);
+ void addChildArrow(ArrowAttachItem *child);
protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
};
-#endif // ARROWITEM_H
+#endif
\ No newline at end of file
diff --git a/cockatrice/src/game/board/arrow_target.cpp b/cockatrice/src/game/board/arrow_target.cpp
index 2dbd913fa..edf526e4e 100644
--- a/cockatrice/src/game/board/arrow_target.cpp
+++ b/cockatrice/src/game/board/arrow_target.cpp
@@ -1,41 +1,23 @@
#include "arrow_target.h"
-#include "../player/player.h"
+#include "../player/player_logic.h"
#include "arrow_item.h"
-ArrowTarget::ArrowTarget(Player *_owner, QGraphicsItem *parent)
- : AbstractGraphicsItem(parent), owner(_owner), beingPointedAt(false)
+ArrowTarget::ArrowTarget(PlayerLogic *_owner, QGraphicsItem *parent) : AbstractGraphicsItem(parent), owner(_owner)
{
setFlag(ItemSendsScenePositionChanges);
}
-ArrowTarget::~ArrowTarget()
-{
- for (int i = 0; i < arrowsFrom.size(); ++i) {
- arrowsFrom[i]->setStartItem(0);
- arrowsFrom[i]->delArrow();
- }
- for (int i = 0; i < arrowsTo.size(); ++i) {
- arrowsTo[i]->setTargetItem(0);
- arrowsTo[i]->delArrow();
- }
-}
-
void ArrowTarget::setBeingPointedAt(bool _beingPointedAt)
{
beingPointedAt = _beingPointedAt;
update();
}
-QVariant ArrowTarget::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
+QVariant ArrowTarget::itemChange(GraphicsItemChange change, const QVariant &value)
{
- if (change == ItemScenePositionHasChanged && scene()) {
- for (auto *arrow : arrowsFrom)
- arrow->updatePath();
-
- for (auto *arrow : arrowsTo)
- arrow->updatePath();
+ if (change == ItemScenePositionHasChanged) {
+ emit scenePositionChanged();
}
-
- return QGraphicsItem::itemChange(change, value);
-}
+ return AbstractGraphicsItem::itemChange(change, value);
+}
\ No newline at end of file
diff --git a/cockatrice/src/game/board/arrow_target.h b/cockatrice/src/game/board/arrow_target.h
index 55f4ef678..664572705 100644
--- a/cockatrice/src/game/board/arrow_target.h
+++ b/cockatrice/src/game/board/arrow_target.h
@@ -1,8 +1,8 @@
/**
* @file arrow_target.h
* @ingroup GameGraphics
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef ARROWTARGET_H
#define ARROWTARGET_H
@@ -11,24 +11,26 @@
#include
-class Player;
+class PlayerLogic;
class ArrowItem;
class ArrowTarget : public AbstractGraphicsItem
{
Q_OBJECT
protected:
- Player *owner;
+ PlayerLogic *owner;
private:
- bool beingPointedAt;
- QList arrowsFrom, arrowsTo;
+ bool beingPointedAt = false;
+
+signals:
+ void scenePositionChanged();
public:
- explicit ArrowTarget(Player *_owner, QGraphicsItem *parent = nullptr);
- ~ArrowTarget() override;
+ explicit ArrowTarget(PlayerLogic *_owner, QGraphicsItem *parent = nullptr);
+ ~ArrowTarget() override = default;
- [[nodiscard]] Player *getOwner() const
+ [[nodiscard]] PlayerLogic *getOwner() const
{
return owner;
}
@@ -39,32 +41,7 @@ public:
return beingPointedAt;
}
- [[nodiscard]] const QList &getArrowsFrom() const
- {
- return arrowsFrom;
- }
- void addArrowFrom(ArrowItem *arrow)
- {
- arrowsFrom.append(arrow);
- }
- void removeArrowFrom(ArrowItem *arrow)
- {
- arrowsFrom.removeOne(arrow);
- }
- [[nodiscard]] const QList &getArrowsTo() const
- {
- return arrowsTo;
- }
- void addArrowTo(ArrowItem *arrow)
- {
- arrowsTo.append(arrow);
- }
- void removeArrowTo(ArrowItem *arrow)
- {
- arrowsTo.removeOne(arrow);
- }
-
protected:
- QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) override;
+ QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
};
#endif
diff --git a/cockatrice/src/game/board/card_drag_item.cpp b/cockatrice/src/game/board/card_drag_item.cpp
index 5ae56ccba..39fb9a390 100644
--- a/cockatrice/src/game/board/card_drag_item.cpp
+++ b/cockatrice/src/game/board/card_drag_item.cpp
@@ -1,9 +1,9 @@
#include "card_drag_item.h"
+#include "../../game_graphics/zones/card_zone.h"
+#include "../../game_graphics/zones/table_zone.h"
+#include "../../game_graphics/zones/view_zone.h"
#include "../game_scene.h"
-#include "../zones/card_zone.h"
-#include "../zones/table_zone.h"
-#include "../zones/view_zone.h"
#include "card_item.h"
#include
@@ -24,8 +24,9 @@ void CardDragItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
{
AbstractCardDragItem::paint(painter, option, widget);
- if (occupied)
+ if (occupied) {
painter->fillPath(shape(), QColor(200, 0, 0, 100));
+ }
}
void CardDragItem::updatePosition(const QPointF &cursorScenePos)
@@ -38,16 +39,19 @@ void CardDragItem::updatePosition(const QPointF &cursorScenePos)
ZoneViewZone *zoneViewZone = 0;
for (int i = colliding.size() - 1; i >= 0; i--) {
CardZone *temp = qgraphicsitem_cast(colliding.at(i));
- if (!cardZone)
+ if (!cardZone) {
cardZone = temp;
- if (!zoneViewZone)
+ }
+ if (!zoneViewZone) {
zoneViewZone = qobject_cast(temp);
+ }
}
CardZone *cursorZone = 0;
- if (zoneViewZone)
+ if (zoneViewZone) {
cursorZone = zoneViewZone;
- else if (cardZone)
+ } else if (cardZone) {
cursorZone = cardZone;
+ }
// Always update the current zone, even if its null, to cancel the drag
// instead of dropping cards into an non-intuitive location.
@@ -59,8 +63,9 @@ void CardDragItem::updatePosition(const QPointF &cursorScenePos)
QPointF newPos = cursorScenePos - hotSpot;
if (newPos != pos()) {
- for (int i = 0; i < childDrags.size(); i++)
+ for (int i = 0; i < childDrags.size(); i++) {
childDrags[i]->setPos(newPos + childDrags[i]->getHotSpot());
+ }
setPos(newPos);
}
@@ -78,23 +83,27 @@ void CardDragItem::updatePosition(const QPointF &cursorScenePos)
// position.
TableZone *tableZone = qobject_cast(cursorZone);
QPointF closestGridPoint;
- if (tableZone)
+ if (tableZone) {
closestGridPoint = tableZone->closestGridPoint(cursorPosInZone);
- else
+ } else {
closestGridPoint = cursorPosInZone - hotSpot;
+ }
QPointF newPos = zonePos + closestGridPoint;
if (newPos != pos()) {
- for (int i = 0; i < childDrags.size(); i++)
+ for (int i = 0; i < childDrags.size(); i++) {
childDrags[i]->setPos(newPos + childDrags[i]->getHotSpot());
+ }
setPos(newPos);
bool newOccupied = false;
TableZone *table = qobject_cast(cursorZone);
- if (table)
- if (table->getCardFromCoords(closestGridPoint))
+ if (table) {
+ if (table->getCardFromCoords(closestGridPoint)) {
newOccupied = true;
+ }
+ }
if (newOccupied != occupied) {
occupied = newOccupied;
update();
diff --git a/cockatrice/src/game/board/card_drag_item.h b/cockatrice/src/game/board/card_drag_item.h
index 930c6be6f..74d25ad04 100644
--- a/cockatrice/src/game/board/card_drag_item.h
+++ b/cockatrice/src/game/board/card_drag_item.h
@@ -1,8 +1,8 @@
/**
* @file card_drag_item.h
* @ingroup GameGraphicsCards
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef CARDDRAGITEM_H
#define CARDDRAGITEM_H
diff --git a/cockatrice/src/game/board/card_item.cpp b/cockatrice/src/game/board/card_item.cpp
index 62de4a02e..a08194540 100644
--- a/cockatrice/src/game/board/card_item.cpp
+++ b/cockatrice/src/game/board/card_item.cpp
@@ -1,14 +1,14 @@
#include "card_item.h"
#include "../../client/settings/cache_settings.h"
+#include "../../game_graphics/zones/table_zone.h"
+#include "../../game_graphics/zones/view_zone.h"
#include "../../interface/widgets/tabs/tab_game.h"
#include "../game_scene.h"
#include "../phase.h"
-#include "../player/player.h"
#include "../player/player_actions.h"
-#include "../zones/logic/view_zone_logic.h"
-#include "../zones/table_zone.h"
-#include "../zones/view_zone.h"
+#include "../player/player_logic.h"
+#include "../zones/view_zone_logic.h"
#include "arrow_item.h"
#include "card_drag_item.h"
@@ -20,15 +20,19 @@
#include
#include
-CardItem::CardItem(Player *_owner, QGraphicsItem *parent, const CardRef &cardRef, int _cardid, CardZoneLogic *_zone)
- : AbstractCardItem(parent, cardRef, _owner, _cardid), zone(_zone), attacking(false), destroyOnZoneChange(false),
- doesntUntap(false), dragItem(nullptr), attachedTo(nullptr)
+CardItem::CardItem(PlayerLogic *_owner,
+ QGraphicsItem *parent,
+ const CardRef &cardRef,
+ int _cardid,
+ CardZoneLogic *_zone)
+ : AbstractCardItem(parent, cardRef, _owner, _cardid), state(new CardState(this, _zone)), dragItem(nullptr)
{
owner->addCard(this);
connect(&SettingsCache::instance().cardCounters(), &CardCounterSettings::colorChanged, this, [this](int counterId) {
- if (counters.contains(counterId))
+ if (state->getCounters().contains(counterId)) {
update();
+ }
});
}
@@ -47,23 +51,24 @@ void CardItem::prepareDelete()
attachedCards.first()->setAttachedTo(nullptr);
}
- if (attachedTo != nullptr) {
- attachedTo->removeAttachedCard(this);
- attachedTo = nullptr;
+ if (state->getAttachedTo() != nullptr) {
+ state->getAttachedTo()->removeAttachedCard(this);
+ state->setAttachedTo(nullptr);
}
}
void CardItem::deleteLater()
{
prepareDelete();
- if (scene())
+ if (scene()) {
static_cast(scene())->unregisterAnimationItem(this);
+ }
AbstractCardItem::deleteLater();
}
void CardItem::setZone(CardZoneLogic *_zone)
{
- zone = _zone;
+ state->setZone(_zone);
}
void CardItem::retranslateUi()
@@ -78,23 +83,23 @@ void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
AbstractCardItem::paint(painter, option, widget);
int i = 0;
- QMapIterator counterIterator(counters);
+ QMapIterator counterIterator(state->getCounters());
while (counterIterator.hasNext()) {
counterIterator.next();
QColor _color = cardCounterSettings.color(counterIterator.key());
- paintNumberEllipse(counterIterator.value(), 14, _color, i, counters.size(), painter);
+ paintNumberEllipse(counterIterator.value(), 14, _color, i, state->getCounters().size(), painter);
++i;
}
QSizeF translatedSize = getTranslatedSize(painter);
qreal scaleFactor = translatedSize.width() / boundingRect().width();
- if (!pt.isEmpty()) {
+ if (!state->getPT().isEmpty()) {
painter->save();
transformPainter(painter, translatedSize, tapAngle);
- if (!getFaceDown() && pt == exactCard.getInfo().getPowTough()) {
+ if (!getFaceDown() && state->getPT() == exactCard.getInfo().getPowTough()) {
painter->setPen(Qt::white);
} else {
painter->setPen(QColor(255, 150, 0)); // dark orange
@@ -105,11 +110,11 @@ void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
painter->drawText(QRectF(4 * scaleFactor, 4 * scaleFactor, translatedSize.width() - 10 * scaleFactor,
translatedSize.height() - 8 * scaleFactor),
- Qt::AlignRight | Qt::AlignBottom, pt);
+ Qt::AlignRight | Qt::AlignBottom, state->getPT());
painter->restore();
}
- if (!annotation.isEmpty()) {
+ if (!state->getAnnotation().isEmpty()) {
painter->save();
transformPainter(painter, translatedSize, tapAngle);
@@ -119,7 +124,7 @@ void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
painter->drawText(QRectF(4 * scaleFactor, 4 * scaleFactor, translatedSize.width() - 8 * scaleFactor,
translatedSize.height() - 8 * scaleFactor),
- Qt::AlignCenter | Qt::TextWrapAnywhere, annotation);
+ Qt::AlignCenter | Qt::TextWrapAnywhere, state->getAnnotation());
painter->restore();
}
@@ -127,7 +132,7 @@ void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
painter->fillPath(shape(), QBrush(QColor(255, 0, 0, 100)));
}
- if (doesntUntap) {
+ if (state->getDoesntUntap()) {
painter->save();
painter->setRenderHint(QPainter::Antialiasing, false);
@@ -146,69 +151,66 @@ void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
void CardItem::setAttacking(bool _attacking)
{
- attacking = _attacking;
+ state->setAttacking(_attacking);
update();
}
void CardItem::setCounter(int _id, int _value)
{
- if (_value)
- counters.insert(_id, _value);
- else
- counters.remove(_id);
+ state->setCounter(_id, _value);
update();
}
void CardItem::setAnnotation(const QString &_annotation)
{
- annotation = _annotation;
+ state->setAnnotation(_annotation);
update();
}
void CardItem::setDoesntUntap(bool _doesntUntap)
{
- doesntUntap = _doesntUntap;
+ state->setDoesntUntap(_doesntUntap);
update();
}
void CardItem::setPT(const QString &_pt)
{
- pt = _pt;
+ state->setPT(_pt);
update();
}
void CardItem::setAttachedTo(CardItem *_attachedTo)
{
- if (attachedTo != nullptr) {
- attachedTo->removeAttachedCard(this);
+ if (state->getAttachedTo() != nullptr) {
+ state->getAttachedTo()->removeAttachedCard(this);
}
gridPoint.setX(-1);
- attachedTo = _attachedTo;
- if (attachedTo != nullptr) {
+ state->setAttachedTo(_attachedTo);
+ if (state->getAttachedTo() != nullptr) {
// If the zone is being torn down, it might already be null by the time a card tries to un-attach all its
// attached cards
- if (attachedTo->zone == nullptr) {
+ if (state->getAttachedTo()->getZone() == nullptr) {
deleteLater();
} else {
- emit attachedTo->zone->cardAdded(this);
- attachedTo->addAttachedCard(this);
- if (zone != attachedTo->getZone()) {
- attachedTo->getZone()->reorganizeCards();
+ emit state->getAttachedTo()->getZone()->cardAdded(this);
+ state->getAttachedTo()->addAttachedCard(this);
+ if (state->getZone() != state->getAttachedTo()->getZone()) {
+ state->getAttachedTo()->getZone()->reorganizeCards();
}
}
} else {
// If the zone is being torn down, it might already be null by the time a card tries to un-attach all its
// attached cards
- if (zone == nullptr) {
+ if (state->getZone() == nullptr) {
deleteLater();
} else {
- emit zone->cardAdded(this);
+ emit state->getZone()->cardAdded(this);
}
}
- if (zone != nullptr) {
- zone->reorganizeCards();
+ if (state->getZone() != nullptr) {
+ state->getZone()->reorganizeCards();
}
}
@@ -217,28 +219,23 @@ void CardItem::setAttachedTo(CardItem *_attachedTo)
*/
void CardItem::resetState(bool keepAnnotations)
{
- attacking = false;
- counters.clear();
- pt.clear();
- if (!keepAnnotations) {
- annotation.clear();
- }
- attachedTo = 0;
+ state->resetState(keepAnnotations);
attachedCards.clear();
setTapped(false, false);
setDoesntUntap(false);
- if (scene())
+ if (scene()) {
static_cast(scene())->unregisterAnimationItem(this);
+ }
update();
}
void CardItem::processCardInfo(const ServerInfo_Card &_info)
{
- counters.clear();
+ state->clearCounters();
const int counterListSize = _info.counter_list_size();
for (int i = 0; i < counterListSize; ++i) {
const ServerInfo_CardCounter &counterInfo = _info.counter_list(i);
- counters.insert(counterInfo.id(), counterInfo.value());
+ state->insertCounter(counterInfo.id(), counterInfo.value());
}
setId(_info.id());
@@ -275,11 +272,12 @@ void CardItem::deleteDragItem()
void CardItem::drawArrow(const QColor &arrowColor)
{
- if (owner->getGame()->getPlayerManager()->isSpectator())
+ if (owner->getGame()->getPlayerManager()->isSpectator()) {
return;
+ }
auto *game = owner->getGame();
- Player *arrowOwner = game->getPlayerManager()->getActiveLocalPlayer(game->getGameState()->getActivePlayer());
+ PlayerLogic *arrowOwner = game->getPlayerManager()->getActiveLocalPlayer(game->getGameState()->getActivePlayer());
int phase = 0; // 0 means to not set the phase
if (SettingsCache::instance().getDoNotDeleteArrowsInSubPhases()) {
int currentPhase = game->getGameState()->getCurrentPhase();
@@ -291,10 +289,12 @@ void CardItem::drawArrow(const QColor &arrowColor)
for (const auto &item : scene()->selectedItems()) {
CardItem *card = qgraphicsitem_cast(item);
- if (card == nullptr || card == this)
+ if (card == nullptr || card == this) {
continue;
- if (card->getZone() != zone)
+ }
+ if (card->getZone() != state->getZone()) {
continue;
+ }
ArrowDragItem *childArrow = new ArrowDragItem(arrowOwner, card, arrowColor, phase);
scene()->addItem(childArrow);
@@ -304,8 +304,9 @@ void CardItem::drawArrow(const QColor &arrowColor)
void CardItem::drawAttachArrow()
{
- if (owner->getGame()->getPlayerManager()->isSpectator())
+ if (owner->getGame()->getPlayerManager()->isSpectator()) {
return;
+ }
auto *arrow = new ArrowAttachItem(this);
scene()->addItem(arrow);
@@ -313,10 +314,12 @@ void CardItem::drawAttachArrow()
for (const auto &item : scene()->selectedItems()) {
CardItem *card = qgraphicsitem_cast(item);
- if (card == nullptr)
+ if (card == nullptr) {
continue;
- if (card->getZone() != zone)
+ }
+ if (card->getZone() != state->getZone()) {
continue;
+ }
ArrowAttachItem *childArrow = new ArrowAttachItem(card);
scene()->addItem(childArrow);
@@ -328,27 +331,32 @@ void CardItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (event->buttons().testFlag(Qt::RightButton)) {
if ((event->screenPos() - event->buttonDownScreenPos(Qt::RightButton)).manhattanLength() <
- 2 * QApplication::startDragDistance())
+ 2 * QApplication::startDragDistance()) {
return;
+ }
QColor arrowColor = Qt::red;
- if (event->modifiers().testFlag(Qt::ControlModifier))
+ if (event->modifiers().testFlag(Qt::ControlModifier)) {
arrowColor = Qt::yellow;
- else if (event->modifiers().testFlag(Qt::AltModifier))
+ } else if (event->modifiers().testFlag(Qt::AltModifier)) {
arrowColor = Qt::blue;
- else if (event->modifiers().testFlag(Qt::ShiftModifier))
+ } else if (event->modifiers().testFlag(Qt::ShiftModifier)) {
arrowColor = Qt::green;
+ }
drawArrow(arrowColor);
} else if (event->buttons().testFlag(Qt::LeftButton)) {
if ((event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton)).manhattanLength() <
- 2 * QApplication::startDragDistance())
+ 2 * QApplication::startDragDistance()) {
return;
- if (const ZoneViewZoneLogic *view = qobject_cast(zone)) {
- if (view->getRevealZone() && !view->getWriteableRevealZone())
+ }
+ if (const ZoneViewZoneLogic *view = qobject_cast(state->getZone())) {
+ if (view->getRevealZone() && !view->getWriteableRevealZone()) {
return;
- } else if (!owner->getPlayerInfo()->getLocalOrJudge())
+ }
+ } else if (!owner->getPlayerInfo()->getLocalOrJudge()) {
return;
+ }
bool forceFaceDown = event->modifiers().testFlag(Qt::ShiftModifier);
@@ -360,14 +368,16 @@ void CardItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
int childIndex = 0;
for (const auto &item : scene()->selectedItems()) {
CardItem *card = static_cast(item);
- if ((card == this) || (card->getZone() != zone))
+ if ((card == this) || (card->getZone() != state->getZone())) {
continue;
+ }
++childIndex;
QPointF childPos;
- if (zone->getHasCardAttr())
+ if (state->getZone()->getHasCardAttr()) {
childPos = card->pos() - pos();
- else
+ } else {
childPos = QPointF(childIndex * CardDimensions::WIDTH_HALF_F, 0);
+ }
CardDragItem *drag =
new CardDragItem(card, card->getId(), childPos, card->getFaceDown() || forceFaceDown, dragItem);
drag->setPos(dragItem->pos() + childPos);
@@ -380,22 +390,54 @@ void CardItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
void CardItem::playCard(bool faceDown)
{
// Do nothing if the card belongs to another player
- if (!owner->getPlayerInfo()->getLocalOrJudge())
+ if (!owner->getPlayerInfo()->getLocalOrJudge()) {
return;
+ }
- TableZoneLogic *tz = qobject_cast(zone);
- if (tz)
+ TableZoneLogic *tz = qobject_cast(state->getZone());
+ if (tz) {
emit tz->toggleTapped();
- else {
+ } else {
if (SettingsCache::instance().getClickPlaysAllSelected()) {
- faceDown ? zone->getPlayer()->getPlayerActions()->actPlayFacedown()
- : zone->getPlayer()->getPlayerActions()->actPlay();
+ faceDown ? state->getZone()->getPlayer()->getPlayerActions()->actPlayFacedown()
+ : state->getZone()->getPlayer()->getPlayerActions()->actPlay();
} else {
- zone->getPlayer()->getPlayerActions()->playCard(this, faceDown);
+ state->getZone()->getPlayer()->getPlayerActions()->playCard(this, faceDown);
}
}
}
+QVariantList CardItem::parsePT(const QString &pt)
+{
+ QVariantList ptList = QVariantList();
+ if (!pt.isEmpty()) {
+ int sep = pt.indexOf('/');
+ if (sep == 0) {
+ ptList.append(QVariant(pt.mid(1))); // cut off starting '/' and take full string
+ } else {
+ int start = 0;
+ for (;;) {
+ QString item = pt.mid(start, sep - start);
+ if (item.isEmpty()) {
+ ptList.append(QVariant(QString()));
+ } else if (item[0] == '+') {
+ ptList.append(QVariant(item.mid(1).toInt())); // add as int
+ } else if (item[0] == '-') {
+ ptList.append(QVariant(item.toInt())); // add as int
+ } else {
+ ptList.append(QVariant(item)); // add as qstring
+ }
+ if (sep == -1) {
+ break;
+ }
+ start = sep + 1;
+ sep = pt.indexOf('/', start);
+ }
+ }
+ }
+ return ptList;
+}
+
/**
* @brief returns true if the zone is a unwritable reveal zone view (eg a card reveal window). Will return false if zone
* is nullptr.
@@ -416,11 +458,11 @@ static bool isUnwritableRevealZone(CardZoneLogic *zone)
*/
void CardItem::handleClickedToPlay(bool shiftHeld)
{
- if (isUnwritableRevealZone(zone)) {
+ if (isUnwritableRevealZone(state->getZone())) {
if (SettingsCache::instance().getClickPlaysAllSelected()) {
- zone->getPlayer()->getPlayerActions()->actHide();
+ state->getZone()->getPlayer()->getPlayerActions()->actHide();
} else {
- zone->removeCard(this);
+ state->getZone()->removeCard(this);
}
} else {
playCard(shiftHeld);
@@ -462,8 +504,9 @@ bool CardItem::animationEvent()
{
int rotation = ROTATION_DEGREES_PER_FRAME;
bool animationIncomplete = true;
- if (!tapped)
+ if (!tapped) {
rotation *= -1;
+ }
tapAngle += rotation;
if (tapped && (tapAngle > 90)) {
diff --git a/cockatrice/src/game/board/card_item.h b/cockatrice/src/game/board/card_item.h
index da2097a2c..87f9667de 100644
--- a/cockatrice/src/game/board/card_item.h
+++ b/cockatrice/src/game/board/card_item.h
@@ -1,42 +1,37 @@
/**
* @file card_item.h
* @ingroup GameGraphicsCards
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef CARDITEM_H
#define CARDITEM_H
-#include "../zones/logic/card_zone_logic.h"
+#include "../zones/card_zone_logic.h"
#include "abstract_card_item.h"
+#include "card_state.h"
#include
+#include
class CardDatabase;
class CardDragItem;
class CardZone;
class ServerInfo_Card;
-class Player;
+class PlayerLogic;
class QAction;
class QColor;
-const int MAX_COUNTERS_ON_CARD = 999;
const int ROTATION_DEGREES_PER_FRAME = 10;
class CardItem : public AbstractCardItem
{
Q_OBJECT
private:
- CardZoneLogic *zone;
- bool attacking;
- QMap counters;
- QString annotation;
- QString pt;
- bool destroyOnZoneChange;
- bool doesntUntap;
+ CardState *state;
+
QPoint gridPoint;
CardDragItem *dragItem;
- CardItem *attachedTo;
QList attachedCards;
void prepareDelete();
@@ -53,16 +48,20 @@ public:
{
return Type;
}
- explicit CardItem(Player *_owner,
+ explicit CardItem(PlayerLogic *_owner,
QGraphicsItem *parent = nullptr,
const CardRef &cardRef = {},
int _cardid = -1,
CardZoneLogic *_zone = nullptr);
void retranslateUi();
+ [[nodiscard]] CardState *getState() const
+ {
+ return state;
+ }
[[nodiscard]] CardZoneLogic *getZone() const
{
- return zone;
+ return state->getZone();
}
void setZone(CardZoneLogic *_zone);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
@@ -78,50 +77,50 @@ public:
{
return gridPoint;
}
- [[nodiscard]] Player *getOwner() const
+ [[nodiscard]] PlayerLogic *getOwner() const
{
return owner;
}
- void setOwner(Player *_owner)
+ void setOwner(PlayerLogic *_owner)
{
owner = _owner;
}
[[nodiscard]] bool getAttacking() const
{
- return attacking;
+ return state->getAttacking();
}
void setAttacking(bool _attacking);
[[nodiscard]] const QMap &getCounters() const
{
- return counters;
+ return state->getCounters();
}
void setCounter(int _id, int _value);
[[nodiscard]] QString getAnnotation() const
{
- return annotation;
+ return state->getAnnotation();
}
void setAnnotation(const QString &_annotation);
[[nodiscard]] bool getDoesntUntap() const
{
- return doesntUntap;
+ return state->getDoesntUntap();
}
void setDoesntUntap(bool _doesntUntap);
[[nodiscard]] QString getPT() const
{
- return pt;
+ return state->getPT();
}
void setPT(const QString &_pt);
[[nodiscard]] bool getDestroyOnZoneChange() const
{
- return destroyOnZoneChange;
+ return state->getDestroyOnZoneChange();
}
void setDestroyOnZoneChange(bool _destroy)
{
- destroyOnZoneChange = _destroy;
+ state->setDestroyOnZoneChange(_destroy);
}
[[nodiscard]] CardItem *getAttachedTo() const
{
- return attachedTo;
+ return state->getAttachedTo();
}
void setAttachedTo(CardItem *_attachedTo);
void addAttachedCard(CardItem *card)
@@ -146,6 +145,26 @@ public:
void drawAttachArrow();
void playCard(bool faceDown);
+ /**
+ * @brief Parses a string representing a p/t in order to extract the values from it.
+ *
+ * If the string contains '/', the string will be split at the '/' and each side will be parsed separately,
+ * which means the result list will have two elements.
+ *
+ * If '/' is not found, then the entire string is parsed together, which means the result list will
+ * have a single element.
+ *
+ * If either side of the split is empty, there will also only be a single element in the result list.
+ *
+ * This function will attempt to parse each substring as an int first, handling plus and minus prefixes.
+ * If successful, it will put the parsed value into the QVariant as an int.
+ * If failed, it will just put the substring into the QVariant as a QString.
+ *
+ * @param pt The p/t string
+ * @return A QVariantList that can contain one or two elements, where each QVariant can be either int or QString
+ */
+ static QVariantList parsePT(const QString &pt);
+
protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
diff --git a/cockatrice/src/game/board/card_list.h b/cockatrice/src/game/board/card_list.h
index 07be33b32..85a6848b7 100644
--- a/cockatrice/src/game/board/card_list.h
+++ b/cockatrice/src/game/board/card_list.h
@@ -1,8 +1,8 @@
/**
* @file card_list.h
* @ingroup GameLogicCards
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef CARDLIST_H
#define CARDLIST_H
diff --git a/cockatrice/src/game/board/card_state.cpp b/cockatrice/src/game/board/card_state.cpp
new file mode 100644
index 000000000..4319400d7
--- /dev/null
+++ b/cockatrice/src/game/board/card_state.cpp
@@ -0,0 +1,111 @@
+#include "card_state.h"
+
+void CardState::resetState(bool keepAnnotations)
+{
+ attacking = false;
+ counters.clear();
+ pt.clear();
+ if (!keepAnnotations) {
+ annotation.clear();
+ }
+ attachedTo = nullptr;
+}
+
+void CardState::setZone(CardZoneLogic *_zone)
+{
+ if (zone == _zone) {
+ return;
+ }
+
+ zone = _zone;
+ emit zoneChanged(this, zone);
+ emit stateChanged();
+}
+
+void CardState::setAttacking(bool _attacking)
+{
+ if (attacking == _attacking) {
+ return;
+ }
+ attacking = _attacking;
+ emit attackingChanged(_attacking);
+ emit stateChanged();
+}
+
+void CardState::insertCounter(int id, int value)
+{
+ counters.insert(id, value);
+
+ emit countersChanged(counters);
+ emit stateChanged();
+}
+
+void CardState::setCounter(int id, int value)
+{
+ if (value) {
+ counters[id] = value;
+ } else {
+ counters.remove(id);
+ }
+
+ emit countersChanged(counters);
+ emit stateChanged();
+}
+
+void CardState::clearCounters()
+{
+ counters.clear();
+ emit countersChanged(counters);
+ emit stateChanged();
+}
+
+void CardState::setAnnotation(const QString &_annotation)
+{
+ if (annotation == _annotation) {
+ return;
+ }
+ annotation = _annotation;
+ emit annotationChanged(annotation);
+ emit stateChanged();
+}
+
+void CardState::setPT(const QString &_pt)
+{
+ if (pt == _pt) {
+ return;
+ }
+ pt = _pt;
+ emit ptChanged(pt);
+ emit stateChanged();
+}
+
+void CardState::setDoesntUntap(bool _doesntUntap)
+{
+ if (doesntUntap == _doesntUntap) {
+ return;
+ }
+ doesntUntap = _doesntUntap;
+ emit doesntUntapChanged(_doesntUntap);
+ emit stateChanged();
+}
+
+void CardState::setDestroyOnZoneChange(bool _destroyOnZoneChange)
+{
+ if (destroyOnZoneChange == _destroyOnZoneChange) {
+ return;
+ }
+
+ destroyOnZoneChange = _destroyOnZoneChange;
+ emit destroyOnZoneChangeChanged(_destroyOnZoneChange);
+ emit stateChanged();
+}
+
+void CardState::setAttachedTo(CardItem *_attachedTo)
+{
+ if (attachedTo == _attachedTo) {
+ return;
+ }
+ attachedTo = _attachedTo;
+ emit attachedToChanged(_attachedTo);
+ emit stateChanged();
+}
\ No newline at end of file
diff --git a/cockatrice/src/game/board/card_state.h b/cockatrice/src/game/board/card_state.h
new file mode 100644
index 000000000..0498b1aa2
--- /dev/null
+++ b/cockatrice/src/game/board/card_state.h
@@ -0,0 +1,103 @@
+#ifndef COCKATRICE_CARD_STATE_H
+#define COCKATRICE_CARD_STATE_H
+
+#include
+#include
+
+class CardZoneLogic;
+class CardItem;
+class CardState : public QObject
+{
+ Q_OBJECT
+
+private:
+ bool attacking = false;
+ QMap counters;
+ QString annotation;
+ QString pt;
+ bool doesntUntap = false;
+ bool destroyOnZoneChange = false;
+
+ CardItem *attachedTo = nullptr;
+ CardZoneLogic *zone = nullptr;
+
+signals:
+ void stateChanged();
+
+ void attackingChanged(bool newValue);
+ void countersChanged(const QMap &newCounters);
+ void annotationChanged(const QString &newAnnotation);
+ void ptChanged(const QString &newPt);
+ void doesntUntapChanged(bool newValue);
+ void destroyOnZoneChangeChanged(bool newValue);
+ void attachedToChanged(CardItem *newAttachedTo);
+ void zoneChanged(CardState *changedCard, CardZoneLogic *newZone);
+
+public:
+ explicit CardState(QObject *parent, CardZoneLogic *_zone) : QObject(parent), zone(_zone)
+ {
+ }
+
+ void resetState(bool keepAnnotations);
+
+ CardZoneLogic *getZone() const
+ {
+ return zone;
+ }
+
+ void setZone(CardZoneLogic *_zone);
+
+ bool getAttacking() const
+ {
+ return attacking;
+ }
+ void setAttacking(bool _attacking);
+
+ const QMap &getCounters() const
+ {
+ return counters;
+ }
+
+ void insertCounter(int id, int value);
+
+ void setCounter(int id, int value);
+
+ void clearCounters();
+
+ QString getAnnotation() const
+ {
+ return annotation;
+ }
+
+ void setAnnotation(const QString &_annotation);
+
+ QString getPT() const
+ {
+ return pt;
+ }
+
+ void setPT(const QString &_pt);
+
+ bool getDoesntUntap() const
+ {
+ return doesntUntap;
+ }
+
+ void setDoesntUntap(bool _doesntUntap);
+
+ bool getDestroyOnZoneChange() const
+ {
+ return destroyOnZoneChange;
+ }
+
+ void setDestroyOnZoneChange(bool _destroyOnZoneChange);
+
+ CardItem *getAttachedTo() const
+ {
+ return attachedTo;
+ }
+
+ void setAttachedTo(CardItem *_attachedTo);
+};
+
+#endif // COCKATRICE_CARD_STATE_H
diff --git a/cockatrice/src/game/board/counter_general.cpp b/cockatrice/src/game/board/counter_general.cpp
index d68486a1b..5147ede6b 100644
--- a/cockatrice/src/game/board/counter_general.cpp
+++ b/cockatrice/src/game/board/counter_general.cpp
@@ -5,15 +5,8 @@
#include
-GeneralCounter::GeneralCounter(Player *_player,
- int _id,
- const QString &_name,
- const QColor &_color,
- int _radius,
- int _value,
- bool useNameForShortcut,
- QGraphicsItem *parent)
- : AbstractCounter(_player, _id, _name, true, _value, useNameForShortcut, parent), color(_color), radius(_radius)
+GeneralCounter::GeneralCounter(CounterState *state, PlayerLogic *player, bool useNameForShortcut, QGraphicsItem *parent)
+ : AbstractCounter(state, player, true, useNameForShortcut, parent)
{
setCacheMode(DeviceCoordinateCache);
}
diff --git a/cockatrice/src/game/board/counter_general.h b/cockatrice/src/game/board/counter_general.h
index 3db1d7bb4..0a2e882ce 100644
--- a/cockatrice/src/game/board/counter_general.h
+++ b/cockatrice/src/game/board/counter_general.h
@@ -1,8 +1,8 @@
/**
* @file counter_general.h
* @ingroup GameGraphicsPlayers
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef COUNTER_GENERAL_H
#define COUNTER_GENERAL_H
@@ -12,17 +12,10 @@
class GeneralCounter : public AbstractCounter
{
Q_OBJECT
-private:
- QColor color;
- int radius;
public:
- GeneralCounter(Player *_player,
- int _id,
- const QString &_name,
- const QColor &_color,
- int _radius,
- int _value,
+ GeneralCounter(CounterState *state,
+ PlayerLogic *player,
bool useNameForShortcut = false,
QGraphicsItem *parent = nullptr);
QRectF boundingRect() const override;
diff --git a/cockatrice/src/game/board/counter_state.cpp b/cockatrice/src/game/board/counter_state.cpp
new file mode 100644
index 000000000..6da18b662
--- /dev/null
+++ b/cockatrice/src/game/board/counter_state.cpp
@@ -0,0 +1,24 @@
+#include "counter_state.h"
+
+#include
+
+CounterState::CounterState(int id, const QString &name, const QColor &color, int radius, int value, QObject *parent)
+ : QObject(parent), id(id), name(name), color(color), radius(radius), value(value)
+{
+}
+
+CounterState *CounterState::fromProto(const ServerInfo_Counter &counter, QObject *parent)
+{
+ return new CounterState(counter.id(), QString::fromStdString(counter.name()),
+ convertColorToQColor(counter.counter_color()), counter.radius(), counter.count(), parent);
+}
+
+void CounterState::setValue(int newValue)
+{
+ if (newValue == value) {
+ return;
+ }
+ int old = value;
+ value = newValue;
+ emit valueChanged(old, newValue);
+}
\ No newline at end of file
diff --git a/cockatrice/src/game/board/counter_state.h b/cockatrice/src/game/board/counter_state.h
new file mode 100644
index 000000000..0f2f16b55
--- /dev/null
+++ b/cockatrice/src/game/board/counter_state.h
@@ -0,0 +1,51 @@
+#ifndef COCKATRICE_COUNTER_STATE_H
+#define COCKATRICE_COUNTER_STATE_H
+
+#include
+#include
+#include
+#include
+
+class CounterState : public QObject
+{
+ Q_OBJECT
+public:
+ CounterState(int id, const QString &name, const QColor &color, int radius, int value, QObject *parent = nullptr);
+
+ static CounterState *fromProto(const ServerInfo_Counter &counter, QObject *parent = nullptr);
+
+ int getId() const
+ {
+ return id;
+ }
+ QString getName() const
+ {
+ return name;
+ }
+ QColor getColor() const
+ {
+ return color;
+ }
+ int getRadius() const
+ {
+ return radius;
+ }
+ int getValue() const
+ {
+ return value;
+ }
+
+ void setValue(int newValue);
+
+signals:
+ void valueChanged(int oldValue, int newValue);
+
+private:
+ int id;
+ QString name;
+ QColor color;
+ int radius;
+ int value;
+};
+
+#endif // COCKATRICE_COUNTER_STATE_H
diff --git a/cockatrice/src/game/board/translate_counter_name.h b/cockatrice/src/game/board/translate_counter_name.h
index fdb277c11..ba3a94fa5 100644
--- a/cockatrice/src/game/board/translate_counter_name.h
+++ b/cockatrice/src/game/board/translate_counter_name.h
@@ -1,8 +1,8 @@
/**
* @file translate_counter_name.h
* @ingroup GameGraphicsPlayers
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef TRANSLATECOUNTERNAME_H
#define TRANSLATECOUNTERNAME_H
diff --git a/cockatrice/src/game/card_dimensions.h b/cockatrice/src/game/card_dimensions.h
index 255d0bc04..c59a01b48 100644
--- a/cockatrice/src/game/card_dimensions.h
+++ b/cockatrice/src/game/card_dimensions.h
@@ -12,16 +12,16 @@
*/
namespace CardDimensions
{
-/// Card width in pixels
+/** @brief Card width in pixels. */
constexpr int WIDTH = 72;
-/// Card height in pixels
+/** @brief Card height in pixels. */
constexpr int HEIGHT = 102;
-/// Pre-converted for floating-point contexts (Z-value calculations)
+/** @brief Pre-converted for floating-point contexts (Z-value calculations). */
constexpr qreal WIDTH_F = static_cast(WIDTH);
constexpr qreal HEIGHT_F = static_cast(HEIGHT);
-/// Half-dimensions for centering and rotation transforms
+/** @brief Half-dimensions for centering and rotation transforms. */
constexpr qreal WIDTH_HALF_F = WIDTH_F / 2;
constexpr qreal HEIGHT_HALF_F = HEIGHT_F / 2;
} // namespace CardDimensions
diff --git a/cockatrice/src/game/deckview/deck_view.cpp b/cockatrice/src/game/deckview/deck_view.cpp
index 620dfaa5f..ced02c8db 100644
--- a/cockatrice/src/game/deckview/deck_view.cpp
+++ b/cockatrice/src/game/deckview/deck_view.cpp
@@ -24,17 +24,21 @@ void DeckViewCardDragItem::updatePosition(const QPointF &cursorScenePos)
QList colliding = scene()->items(cursorScenePos);
DeckViewCardContainer *cursorZone = 0;
- for (int i = colliding.size() - 1; i >= 0; i--)
- if ((cursorZone = qgraphicsitem_cast(colliding.at(i))))
+ for (int i = colliding.size() - 1; i >= 0; i--) {
+ if ((cursorZone = qgraphicsitem_cast(colliding.at(i)))) {
break;
- if (!cursorZone)
+ }
+ }
+ if (!cursorZone) {
return;
+ }
currentZone = cursorZone;
QPointF newPos = cursorScenePos;
if (newPos != pos()) {
- for (int i = 0; i < childDrags.size(); i++)
+ for (int i = 0; i < childDrags.size(); i++) {
childDrags[i]->setPos(newPos + childDrags[i]->getHotSpot());
+ }
setPos(newPos);
}
}
@@ -104,11 +108,13 @@ void DeckViewCard::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
void DeckViewCard::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if ((event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton)).manhattanLength() <
- 2 * QApplication::startDragDistance())
+ 2 * QApplication::startDragDistance()) {
return;
+ }
- if (static_cast(scene())->getLocked())
+ if (static_cast(scene())->getLocked()) {
return;
+ }
delete dragItem;
dragItem = new DeckViewCardDragItem(this, event->pos());
@@ -120,8 +126,9 @@ void DeckViewCard::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
int j = 0;
for (int i = 0; i < sel.size(); i++) {
auto *c = static_cast(sel.at(i));
- if (c == this)
+ if (c == this) {
continue;
+ }
++j;
auto childPos = QPointF(j * CardDimensions::WIDTH_HALF_F, 0);
auto *drag = new DeckViewCardDragItem(c, childPos, dragItem);
@@ -133,8 +140,9 @@ void DeckViewCard::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
void DeckView::mouseDoubleClickEvent(QMouseEvent *event)
{
- if (static_cast(scene())->getLocked())
+ if (static_cast(scene())->getLocked()) {
return;
+ }
if (event->button() == Qt::LeftButton) {
QList result;
@@ -147,12 +155,13 @@ void DeckView::mouseDoubleClickEvent(QMouseEvent *event)
m.set_card_name(c->getName().toStdString());
m.set_start_zone(zone->getName().toStdString());
- if (zone->getName() == DECK_ZONE_MAIN)
+ if (zone->getName() == DECK_ZONE_MAIN) {
m.set_target_zone(DECK_ZONE_SIDE);
- else if (zone->getName() == DECK_ZONE_SIDE)
+ } else if (zone->getName() == DECK_ZONE_SIDE) {
m.set_target_zone(DECK_ZONE_MAIN);
- else // Trying to move from another zone
+ } else { // Trying to move from another zone
m.set_target_zone(zone->getName().toStdString());
+ }
result.append(m);
}
@@ -232,8 +241,9 @@ QList> DeckViewCardContainer::getRowsAndCols() const
{
QList> result;
QList cardTypeList = cardsByType.uniqueKeys();
- for (int i = 0; i < cardTypeList.size(); ++i)
+ for (int i = 0; i < cardTypeList.size(); ++i) {
result.append(QPair(1, cardsByType.count(cardTypeList[i])));
+ }
return result;
}
@@ -262,8 +272,9 @@ QSizeF DeckViewCardContainer::calculateBoundingRect(const QList>
// Calculate space needed for cards
for (int i = 0; i < rowsAndCols.size(); ++i) {
totalHeight += CardDimensions::HEIGHT_F * rowsAndCols[i].first + paddingY;
- if (CardDimensions::WIDTH_F * rowsAndCols[i].second > totalWidth)
+ if (CardDimensions::WIDTH_F * rowsAndCols[i].second > totalWidth) {
totalWidth = CardDimensions::WIDTH_F * rowsAndCols[i].second;
+ }
}
return QSizeF(getCardTypeTextWidth() + totalWidth, totalHeight + separatorY + paddingY);
@@ -271,8 +282,9 @@ QSizeF DeckViewCardContainer::calculateBoundingRect(const QList>
bool DeckViewCardContainer::sortCardsByName(DeckViewCard *c1, DeckViewCard *c2)
{
- if (c1 && c2)
+ if (c1 && c2) {
return c1->getName() < c2->getName();
+ }
return false;
}
@@ -322,15 +334,17 @@ DeckViewScene::~DeckViewScene()
void DeckViewScene::clearContents()
{
QMapIterator i(cardContainers);
- while (i.hasNext())
+ while (i.hasNext()) {
delete i.next().value();
+ }
cardContainers.clear();
}
void DeckViewScene::setDeck(const DeckList &_deck)
{
- if (deck)
+ if (deck) {
delete deck;
+ }
deck = new DeckList(_deck.writeToString_Native());
rebuildTree();
@@ -342,8 +356,9 @@ void DeckViewScene::rebuildTree()
{
clearContents();
- if (!deck)
+ if (!deck) {
return;
+ }
for (auto *currentZone : deck->getZoneNodes()) {
DeckViewCardContainer *container = cardContainers.value(currentZone->getName(), 0);
@@ -355,8 +370,9 @@ void DeckViewScene::rebuildTree()
for (int j = 0; j < currentZone->size(); j++) {
auto *currentCard = dynamic_cast(currentZone->at(j));
- if (!currentCard)
+ if (!currentCard) {
continue;
+ }
for (int k = 0; k < currentCard->getNumber(); ++k) {
auto *newCard = new DeckViewCard(container, currentCard->toCardRef(), currentZone->getName());
@@ -373,18 +389,21 @@ void DeckViewScene::applySideboardPlan(const QList &plan)
const MoveCard_ToZone &m = plan[i];
DeckViewCardContainer *start = cardContainers.value(QString::fromStdString(m.start_zone()));
DeckViewCardContainer *target = cardContainers.value(QString::fromStdString(m.target_zone()));
- if (!start || !target)
+ if (!start || !target) {
continue;
+ }
DeckViewCard *card = 0;
const QList &cardList = start->getCards();
- for (int j = 0; j < cardList.size(); ++j)
+ for (int j = 0; j < cardList.size(); ++j) {
if (cardList[j]->getName() == QString::fromStdString(m.card_name())) {
card = cardList[j];
break;
}
- if (!card)
+ }
+ if (!card) {
continue;
+ }
start->removeCard(card);
target->addCard(card);
@@ -405,8 +424,9 @@ void DeckViewScene::rearrangeItems()
rowsAndColsList.append(rowsAndCols);
cardCountList.append(QList());
- for (int j = 0; j < rowsAndCols.size(); ++j)
+ for (int j = 0; j < rowsAndCols.size(); ++j) {
cardCountList[i].append(rowsAndCols[j].second);
+ }
}
qreal totalHeight, totalWidth;
@@ -417,23 +437,27 @@ void DeckViewScene::rearrangeItems()
for (int i = 0; i < contList.size(); ++i) {
QSizeF contSize = contList[i]->calculateBoundingRect(rowsAndColsList[i]);
totalHeight += contSize.height() + spacing;
- if (contSize.width() > totalWidth)
+ if (contSize.width() > totalWidth) {
totalWidth = contSize.width();
+ }
}
// We're done when the aspect ratio shifts from too high to too low.
- if (totalWidth / totalHeight <= optimalAspectRatio)
+ if (totalWidth / totalHeight <= optimalAspectRatio) {
break;
+ }
// Find category with highest column count
int maxIndex1 = -1, maxIndex2 = -1, maxCols = 0;
- for (int i = 0; i < rowsAndColsList.size(); ++i)
- for (int j = 0; j < rowsAndColsList[i].size(); ++j)
+ for (int i = 0; i < rowsAndColsList.size(); ++i) {
+ for (int j = 0; j < rowsAndColsList[i].size(); ++j) {
if (rowsAndColsList[i][j].second > maxCols) {
maxIndex1 = i;
maxIndex2 = j;
maxCols = rowsAndColsList[i][j].second;
}
+ }
+ }
// Add row to category
const int maxRows = rowsAndColsList[maxIndex1][maxIndex2].first;
@@ -451,8 +475,9 @@ void DeckViewScene::rearrangeItems()
}
totalWidth = totalHeight * optimalAspectRatio;
- for (int i = 0; i < contList.size(); ++i)
+ for (int i = 0; i < contList.size(); ++i) {
contList[i]->setWidth(totalWidth);
+ }
setSceneRect(QRectF(0, 0, totalWidth, totalHeight));
}
@@ -470,7 +495,7 @@ QList DeckViewScene::getSideboardPlan() const
while (containerIterator.hasNext()) {
DeckViewCardContainer *cont = containerIterator.next().value();
const QList cardList = cont->getCards();
- for (int i = 0; i < cardList.size(); ++i)
+ for (int i = 0; i < cardList.size(); ++i) {
if (cardList[i]->getOriginZone() != cont->getName()) {
MoveCard_ToZone m;
m.set_card_name(cardList[i]->getName().toStdString());
@@ -478,6 +503,7 @@ QList DeckViewScene::getSideboardPlan() const
m.set_target_zone(cont->getName().toStdString());
result.append(m);
}
+ }
}
return result;
}
diff --git a/cockatrice/src/game/deckview/deck_view.h b/cockatrice/src/game/deckview/deck_view.h
index 5abc558bd..f996fd4da 100644
--- a/cockatrice/src/game/deckview/deck_view.h
+++ b/cockatrice/src/game/deckview/deck_view.h
@@ -1,8 +1,8 @@
/**
* @file deck_view.h
* @ingroup Lobby
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef DECKVIEW_H
#define DECKVIEW_H
diff --git a/cockatrice/src/game/deckview/deck_view_container.cpp b/cockatrice/src/game/deckview/deck_view_container.cpp
index 44b2be6d1..cbd6c2bad 100644
--- a/cockatrice/src/game/deckview/deck_view_container.cpp
+++ b/cockatrice/src/game/deckview/deck_view_container.cpp
@@ -251,8 +251,9 @@ void DeckViewContainer::unloadDeck()
void DeckViewContainer::loadLocalDeck()
{
DlgLoadDeck dialog(this);
- if (!dialog.exec())
+ if (!dialog.exec()) {
return;
+ }
loadDeckFromFile(dialog.selectedFiles().at(0));
}
@@ -364,8 +365,9 @@ void DeckViewContainer::sideboardPlanChanged()
{
Command_SetSideboardPlan cmd;
const QList &newPlan = deckView->getSideboardPlan();
- for (const auto &i : newPlan)
+ for (const auto &i : newPlan) {
cmd.add_move_list()->CopyFrom(i);
+ }
parentGame->getGame()->getGameEventHandler()->sendGameCommand(cmd, playerId);
}
@@ -404,8 +406,9 @@ void DeckViewContainer::setSideboardLocked(bool locked)
{
sideboardLockButton->setState(!locked);
deckView->setLocked(readyStartButton->getState() || !sideboardLockButton->getState());
- if (locked)
+ if (locked) {
deckView->resetSideboardPlan();
+ }
}
void DeckViewContainer::setDeck(const DeckList &deck)
diff --git a/cockatrice/src/game/deckview/deck_view_container.h b/cockatrice/src/game/deckview/deck_view_container.h
index 6d685cd79..ec024bace 100644
--- a/cockatrice/src/game/deckview/deck_view_container.h
+++ b/cockatrice/src/game/deckview/deck_view_container.h
@@ -1,8 +1,8 @@
/**
* @file deck_view_container.h
* @ingroup Lobby
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef DECK_VIEW_CONTAINER_H
#define DECK_VIEW_CONTAINER_H
diff --git a/cockatrice/src/game/deckview/tabbed_deck_view_container.h b/cockatrice/src/game/deckview/tabbed_deck_view_container.h
index c34eef1ef..7cfa8c9aa 100644
--- a/cockatrice/src/game/deckview/tabbed_deck_view_container.h
+++ b/cockatrice/src/game/deckview/tabbed_deck_view_container.h
@@ -1,8 +1,8 @@
/**
* @file tabbed_deck_view_container.h
* @ingroup Lobby
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef TABBED_DECK_VIEW_CONTAINER_H
#define TABBED_DECK_VIEW_CONTAINER_H
diff --git a/cockatrice/src/game/dialogs/dlg_create_token.cpp b/cockatrice/src/game/dialogs/dlg_create_token.cpp
index df264f065..11c24b72e 100644
--- a/cockatrice/src/game/dialogs/dlg_create_token.cpp
+++ b/cockatrice/src/game/dialogs/dlg_create_token.cpp
@@ -101,8 +101,9 @@ DlgCreateToken::DlgCreateToken(const QStringList &_predefinedTokens, QWidget *pa
chooseTokenView->resizeColumnToContents(0);
chooseTokenView->setWordWrap(true);
- if (!deckHeaderState.isNull())
+ if (!deckHeaderState.isNull()) {
chooseTokenView->header()->restoreState(deckHeaderState);
+ }
chooseTokenView->header()->setStretchLastSection(false);
chooseTokenView->header()->hideSection(1); // Sets
@@ -185,8 +186,9 @@ void DlgCreateToken::tokenSelectionChanged(const QModelIndex ¤t, const QMo
const QChar cardColor = cardInfo->getColorChar();
colorEdit->setCurrentIndex(colorEdit->findData(cardColor, Qt::UserRole, Qt::MatchFixedString));
ptEdit->setText(cardInfo->getPowTough());
- if (SettingsCache::instance().getAnnotateTokens())
+ if (SettingsCache::instance().getAnnotateTokens()) {
annotationEdit->setText(cardInfo->getText());
+ }
} else {
nameEdit->setText("");
colorEdit->setCurrentIndex(colorEdit->findData(QString(), Qt::UserRole, Qt::MatchFixedString));
diff --git a/cockatrice/src/game/dialogs/dlg_create_token.h b/cockatrice/src/game/dialogs/dlg_create_token.h
index 9a18f1a57..281e161fc 100644
--- a/cockatrice/src/game/dialogs/dlg_create_token.h
+++ b/cockatrice/src/game/dialogs/dlg_create_token.h
@@ -1,8 +1,8 @@
/**
* @file dlg_create_token.h
* @ingroup GameDialogs
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef DLG_CREATETOKEN_H
#define DLG_CREATETOKEN_H
diff --git a/cockatrice/src/game/dialogs/dlg_move_top_cards_until.h b/cockatrice/src/game/dialogs/dlg_move_top_cards_until.h
index 20ba11c5c..ac9d41a94 100644
--- a/cockatrice/src/game/dialogs/dlg_move_top_cards_until.h
+++ b/cockatrice/src/game/dialogs/dlg_move_top_cards_until.h
@@ -1,8 +1,8 @@
/**
* @file dlg_move_top_cards_until.h
* @ingroup GameDialogs
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef DLG_MOVE_TOP_CARDS_UNTIL_H
#define DLG_MOVE_TOP_CARDS_UNTIL_H
diff --git a/cockatrice/src/game/dialogs/dlg_roll_dice.h b/cockatrice/src/game/dialogs/dlg_roll_dice.h
index 69edd0757..15f7dc1ba 100644
--- a/cockatrice/src/game/dialogs/dlg_roll_dice.h
+++ b/cockatrice/src/game/dialogs/dlg_roll_dice.h
@@ -1,8 +1,8 @@
/**
* @file dlg_roll_dice.h
* @ingroup GameDialogs
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef DLG_ROLL_DICE_H
#define DLG_ROLL_DICE_H
diff --git a/cockatrice/src/game/game.h b/cockatrice/src/game/game.h
index 96ebbae4d..ccdb679df 100644
--- a/cockatrice/src/game/game.h
+++ b/cockatrice/src/game/game.h
@@ -1,8 +1,8 @@
/**
* @file game.h
* @ingroup GameLogic
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef COCKATRICE_GAME_H
#define COCKATRICE_GAME_H
diff --git a/cockatrice/src/game/game_event_handler.cpp b/cockatrice/src/game/game_event_handler.cpp
index 42dd49458..629e2f6a1 100644
--- a/cockatrice/src/game/game_event_handler.cpp
+++ b/cockatrice/src/game/game_event_handler.cpp
@@ -36,8 +36,9 @@ GameEventHandler::GameEventHandler(AbstractGame *_game) : QObject(_game), game(_
void GameEventHandler::sendGameCommand(PendingCommand *pend, int playerId)
{
AbstractClient *client = game->getClientForPlayer(playerId);
- if (!client)
+ if (!client) {
return;
+ }
connect(pend, &PendingCommand::finished, this, &GameEventHandler::commandFinished);
client->sendCommand(pend);
@@ -46,8 +47,9 @@ void GameEventHandler::sendGameCommand(PendingCommand *pend, int playerId)
void GameEventHandler::sendGameCommand(const google::protobuf::Message &command, int playerId)
{
AbstractClient *client = game->getClientForPlayer(playerId);
- if (!client)
+ if (!client) {
return;
+ }
PendingCommand *pend = prepareGameCommand(command);
connect(pend, &PendingCommand::finished, this, &GameEventHandler::commandFinished);
@@ -56,8 +58,9 @@ void GameEventHandler::sendGameCommand(const google::protobuf::Message &command,
void GameEventHandler::commandFinished(const Response &response)
{
- if (response.response_code() == Response::RespChatFlood)
+ if (response.response_code() == Response::RespChatFlood) {
emit gameFlooded();
+ }
}
PendingCommand *GameEventHandler::prepareGameCommand(const ::google::protobuf::Message &cmd)
@@ -96,7 +99,7 @@ void GameEventHandler::processGameEventContainer(const GameEventContainer &cont,
if (cont.has_forced_by_judge()) {
auto id = cont.forced_by_judge();
- Player *judgep = game->getPlayerManager()->getPlayers().value(id, nullptr);
+ PlayerLogic *judgep = game->getPlayerManager()->getPlayers().value(id, nullptr);
if (judgep) {
emit setContextJudgeName(judgep->getPlayerInfo()->getName());
} else if (game->getPlayerManager()->getSpectators().contains(id)) {
@@ -117,9 +120,11 @@ void GameEventHandler::processGameEventContainer(const GameEventContainer &cont,
break;
}
} else {
- if ((game->getGameState()->getClients().size() > 1) && (playerId != -1))
- if (game->getGameState()->getClients().at(playerId) != client)
+ if ((game->getGameState()->getClients().size() > 1) && (playerId != -1)) {
+ if (game->getGameState()->getClients().at(playerId) != client) {
continue;
+ }
+ }
switch (eventType) {
case GameEvent::GAME_STATE_CHANGED:
@@ -155,7 +160,7 @@ void GameEventHandler::processGameEventContainer(const GameEventContainer &cont,
break;
default: {
- Player *player = game->getPlayerManager()->getPlayers().value(playerId, 0);
+ PlayerLogic *player = game->getPlayerManager()->getPlayers().value(playerId, 0);
if (!player) {
qCWarning(GameEventHandlerLog) << "unhandled game event: invalid player id";
break;
@@ -208,11 +213,25 @@ void GameEventHandler::handleChatMessageSent(const QString &chatMessage)
sendGameCommand(cmd);
}
-void GameEventHandler::handleArrowDeletion(int arrowId)
+void GameEventHandler::handleArrowDeletion(int creatorId, int arrowId)
{
Command_DeleteArrow cmd;
cmd.set_arrow_id(arrowId);
- sendGameCommand(cmd);
+
+ auto preparedCommand = prepareGameCommand(cmd);
+
+ connect(preparedCommand, &PendingCommand::finished, this, [creatorId, arrowId, this](const Response &response) {
+ handleArrowDeletionFinished(response, creatorId, arrowId);
+ });
+
+ sendGameCommand(preparedCommand);
+}
+
+void GameEventHandler::handleArrowDeletionFinished(const Response &response, int creatorId, int arrowId)
+{
+ if (response.response_code() == Response::RespNameNotFound) {
+ emit arrowDeleted(creatorId, arrowId);
+ }
}
void GameEventHandler::eventSpectatorSay(const Event_GameSay &event,
@@ -256,7 +275,7 @@ void GameEventHandler::eventGameStateChanged(const Event_GameStateChanged &event
emit spectatorJoined(prop);
}
} else {
- Player *player = game->getPlayerManager()->getPlayers().value(playerId, 0);
+ PlayerLogic *player = game->getPlayerManager()->getPlayers().value(playerId, 0);
if (!player) {
player = game->getPlayerManager()->addPlayer(playerId, prop.user_info());
emit playerJoined(prop);
@@ -284,8 +303,9 @@ void GameEventHandler::eventGameStateChanged(const Event_GameStateChanged &event
if (event.game_started() && !game->getGameMetaInfo()->started()) {
game->getGameState()->setResuming(!game->getGameState()->isGameStateKnown());
game->getGameMetaInfo()->setStarted(event.game_started());
- if (game->getGameState()->isGameStateKnown())
+ if (game->getGameState()->isGameStateKnown()) {
emit logGameStart();
+ }
game->getGameState()->setActivePlayer(event.active_player_id());
game->getGameState()->setCurrentPhase(event.active_phase());
} else if (!event.game_started() && game->getGameMetaInfo()->started()) {
@@ -304,9 +324,10 @@ void GameEventHandler::processCardAttachmentsForPlayers(const Event_GameStateCha
const ServerInfo_Player &playerInfo = event.player_list(i);
const ServerInfo_PlayerProperties &prop = playerInfo.properties();
if (!prop.spectator()) {
- Player *player = game->getPlayerManager()->getPlayers().value(prop.player_id(), 0);
- if (!player)
+ PlayerLogic *player = game->getPlayerManager()->getPlayers().value(prop.player_id(), 0);
+ if (!player) {
continue;
+ }
player->processCardAttachment(playerInfo);
}
}
@@ -316,9 +337,10 @@ void GameEventHandler::eventPlayerPropertiesChanged(const Event_PlayerProperties
int eventPlayerId,
const GameEventContext &context)
{
- Player *player = game->getPlayerManager()->getPlayers().value(eventPlayerId, 0);
- if (!player)
+ PlayerLogic *player = game->getPlayerManager()->getPlayers().value(eventPlayerId, 0);
+ if (!player) {
return;
+ }
const ServerInfo_PlayerProperties &prop = event.player_properties();
emit playerPropertiesChanged(prop, eventPlayerId);
@@ -326,8 +348,9 @@ void GameEventHandler::eventPlayerPropertiesChanged(const Event_PlayerProperties
switch (contextType) {
case GameEventContext::READY_START: {
bool ready = prop.ready_start();
- if (player->getPlayerInfo()->getLocal())
+ if (player->getPlayerInfo()->getLocal()) {
emit localPlayerReadyStateChanged(player->getPlayerInfo()->getId(), ready);
+ }
if (ready) {
emit logReadyStart(player);
} else {
@@ -338,9 +361,10 @@ void GameEventHandler::eventPlayerPropertiesChanged(const Event_PlayerProperties
case GameEventContext::CONCEDE: {
player->setConceded(true);
- QMapIterator playerIterator(game->getPlayerManager()->getPlayers());
- while (playerIterator.hasNext())
+ QMapIterator playerIterator(game->getPlayerManager()->getPlayers());
+ while (playerIterator.hasNext()) {
playerIterator.next().value()->updateZones();
+ }
emit logConcede(eventPlayerId);
@@ -349,9 +373,10 @@ void GameEventHandler::eventPlayerPropertiesChanged(const Event_PlayerProperties
case GameEventContext::UNCONCEDE: {
player->setConceded(false);
- QMapIterator playerIterator(game->getPlayerManager()->getPlayers());
- while (playerIterator.hasNext())
+ QMapIterator playerIterator(game->getPlayerManager()->getPlayers());
+ while (playerIterator.hasNext()) {
playerIterator.next().value()->updateZones();
+ }
emit logUnconcede(eventPlayerId);
@@ -389,15 +414,16 @@ 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))
+ if (game->getPlayerManager()->getPlayers().contains(playerId)) {
return;
+ }
if (playerInfo.spectator()) {
game->getPlayerManager()->addSpectator(playerId, playerInfo);
emit logJoinSpectator(playerName);
emit spectatorJoined(playerInfo);
} else {
- Player *newPlayer = game->getPlayerManager()->addPlayer(playerId, playerInfo.user_info());
+ PlayerLogic *newPlayer = game->getPlayerManager()->addPlayer(playerId, playerInfo.user_info());
emit logJoinPlayer(newPlayer);
emit playerJoined(playerInfo);
}
@@ -425,9 +451,10 @@ QString GameEventHandler::getLeaveReason(Event_Leave::LeaveReason reason)
}
void GameEventHandler::eventLeave(const Event_Leave &event, int eventPlayerId, const GameEventContext & /*context*/)
{
- Player *player = game->getPlayerManager()->getPlayers().value(eventPlayerId, 0);
- if (!player)
+ PlayerLogic *player = game->getPlayerManager()->getPlayers().value(eventPlayerId, 0);
+ if (!player) {
return;
+ }
player->clear();
emit playerLeft(eventPlayerId);
@@ -439,9 +466,10 @@ void GameEventHandler::eventLeave(const Event_Leave &event, int eventPlayerId, c
player->deleteLater();
// Rearrange all remaining zones so that attachment relationship updates take place
- QMapIterator playerIterator(game->getPlayerManager()->getPlayers());
- while (playerIterator.hasNext())
+ QMapIterator playerIterator(game->getPlayerManager()->getPlayers());
+ while (playerIterator.hasNext()) {
playerIterator.next().value()->updateZones();
+ }
emitUserEvent();
}
@@ -460,9 +488,10 @@ void GameEventHandler::eventReverseTurn(const Event_ReverseTurn &event,
int eventPlayerId,
const GameEventContext & /*context*/)
{
- Player *player = game->getPlayerManager()->getPlayers().value(eventPlayerId, 0);
- if (!player)
+ PlayerLogic *player = game->getPlayerManager()->getPlayers().value(eventPlayerId, 0);
+ if (!player) {
return;
+ }
emit logTurnReversed(player, event.reversed());
}
@@ -490,9 +519,10 @@ void GameEventHandler::eventSetActivePlayer(const Event_SetActivePlayer &event,
const GameEventContext & /*context*/)
{
game->getGameState()->setActivePlayer(event.active_player_id());
- Player *player = game->getPlayerManager()->getPlayer(event.active_player_id());
- if (!player)
+ PlayerLogic *player = game->getPlayerManager()->getPlayer(event.active_player_id());
+ if (!player) {
return;
+ }
emit logActivePlayer(player);
emitUserEvent();
}
diff --git a/cockatrice/src/game/game_event_handler.h b/cockatrice/src/game/game_event_handler.h
index 302e7a6ff..f47116949 100644
--- a/cockatrice/src/game/game_event_handler.h
+++ b/cockatrice/src/game/game_event_handler.h
@@ -1,8 +1,8 @@
/**
* @file game_event_handler.h
* @ingroup GameLogic
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef COCKATRICE_GAME_EVENT_HANDLER_H
#define COCKATRICE_GAME_EVENT_HANDLER_H
@@ -38,7 +38,7 @@ class Event_Kicked;
class Event_ReverseTurn;
class AbstractGame;
class PendingCommand;
-class Player;
+class PlayerLogic;
inline Q_LOGGING_CATEGORY(GameEventHandlerLog, "game_event_handler");
@@ -60,7 +60,8 @@ public:
void handleActivePhaseChanged(int phase);
void handleGameLeft();
void handleChatMessageSent(const QString &chatMessage);
- void handleArrowDeletion(int arrowId);
+ void handleArrowDeletion(int creatorId, int arrowId);
+ void handleArrowDeletionFinished(const Response &response, int creatorId, int arrowId);
void eventSpectatorSay(const Event_GameSay &event, int eventPlayerId, const GameEventContext &context);
void eventSpectatorLeave(const Event_Leave &event, int eventPlayerId, const GameEventContext &context);
@@ -95,7 +96,7 @@ public slots:
signals:
void emitUserEvent();
void addPlayerToAutoCompleteList(QString playerName);
- void localPlayerDeckSelected(Player *localPlayer, int playerId, ServerInfo_Player playerInfo);
+ void localPlayerDeckSelected(PlayerLogic *localPlayer, int playerId, ServerInfo_Player playerInfo);
void remotePlayerDeckSelected(QString deckList, int playerId, QString playerName);
void remotePlayersDecksSelected(QVector>> opponentDecks);
void localPlayerSideboardLocked(int playerId, bool sideboardLocked);
@@ -112,21 +113,22 @@ signals:
void containerProcessingStarted(GameEventContext context);
void setContextJudgeName(QString judgeName);
void containerProcessingDone();
+ void arrowDeleted(int creatorId, int arrowId);
void logSpectatorSay(ServerInfo_User userInfo, QString message);
void logSpectatorLeave(QString name, QString reason);
void logGameStart();
- void logReadyStart(Player *player);
- void logNotReadyStart(Player *player);
- void logDeckSelect(Player *player, QString deckHash, int sideboardSize);
- void logSideboardLockSet(Player *player, bool sideboardLocked);
- void logConnectionStateChanged(Player *player, bool connected);
+ void logReadyStart(PlayerLogic *player);
+ void logNotReadyStart(PlayerLogic *player);
+ void logDeckSelect(PlayerLogic *player, QString deckHash, int sideboardSize);
+ void logSideboardLockSet(PlayerLogic *player, bool sideboardLocked);
+ void logConnectionStateChanged(PlayerLogic *player, bool connected);
void logJoinSpectator(QString spectatorName);
- void logJoinPlayer(Player *player);
- void logLeave(Player *player, QString reason);
+ void logJoinPlayer(PlayerLogic *player);
+ void logLeave(PlayerLogic *player, QString reason);
void logKicked();
- void logTurnReversed(Player *player, bool reversed);
+ void logTurnReversed(PlayerLogic *player, bool reversed);
void logGameClosed();
- void logActivePlayer(Player *activePlayer);
+ void logActivePlayer(PlayerLogic *activePlayer);
void logActivePhaseChanged(int activePhase);
void logConcede(int playerId);
void logUnconcede(int playerId);
diff --git a/cockatrice/src/game/game_meta_info.h b/cockatrice/src/game/game_meta_info.h
index b5f5bfe4f..cdba1605f 100644
--- a/cockatrice/src/game/game_meta_info.h
+++ b/cockatrice/src/game/game_meta_info.h
@@ -1,8 +1,8 @@
/**
* @file game_meta_info.h
* @ingroup GameLogic
- * @brief TODO: Document this.
*/
+//! \todo Document this file.
#ifndef GAME_META_INFO_H
#define GAME_META_INFO_H
@@ -87,15 +87,17 @@ public:
public slots:
void setStarted(bool s)
{
- if (gameInfo_.started() == s)
+ if (gameInfo_.started() == s) {
return;
+ }
gameInfo_.set_started(s);
emit startedChanged(s);
}
void setSpectatorsOmniscient(bool v)
{
- if (gameInfo_.spectators_omniscient() == v)
+ if (gameInfo_.spectators_omniscient() == v) {
return;
+ }
gameInfo_.set_spectators_omniscient(v);
emit spectatorsOmniscienceChanged(v);
}
diff --git a/cockatrice/src/game/game_scene.cpp b/cockatrice/src/game/game_scene.cpp
index 034ff6947..867869a3f 100644
--- a/cockatrice/src/game/game_scene.cpp
+++ b/cockatrice/src/game/game_scene.cpp
@@ -1,12 +1,13 @@
#include "game_scene.h"
#include "../client/settings/cache_settings.h"
+#include "../game_graphics/zones/select_zone.h"
+#include "../game_graphics/zones/view_zone.h"
+#include "../game_graphics/zones/view_zone_widget.h"
#include "board/card_item.h"
#include "phases_toolbar.h"
-#include "player/player.h"
#include "player/player_graphics_item.h"
-#include "zones/view_zone.h"
-#include "zones/view_zone_widget.h"
+#include "player/player_logic.h"
#include
#include
@@ -54,8 +55,21 @@ GameScene::~GameScene()
*/
void GameScene::retranslateUi()
{
- for (ZoneViewWidget *view : zoneViews)
+ for (ZoneViewWidget *view : zoneViews) {
view->retranslateUi();
+ }
+}
+
+QList GameScene::selectedCards() const
+{
+ QList selectedCards;
+ for (auto item : selectedItems()) {
+ if (auto card = qgraphicsitem_cast(item)) {
+ selectedCards.append(card);
+ }
+ }
+
+ return selectedCards;
}
/**
@@ -64,13 +78,30 @@ void GameScene::retranslateUi()
*
* Connects to the player's sizeChanged signal to recompute layout on resize.
*/
-void GameScene::addPlayer(Player *player)
+void GameScene::addPlayer(PlayerLogic *player)
{
qCInfo(GameScenePlayerAdditionRemovalLog) << "GameScene::addPlayer name=" << player->getPlayerInfo()->getName();
- players << player->getGraphicsItem();
+ playerViews.insert(player->getPlayerInfo()->getId(), player->getGraphicsItem());
addItem(player->getGraphicsItem());
connect(player->getGraphicsItem(), &PlayerGraphicsItem::sizeChanged, this, &GameScene::rearrange);
+
+ connect(player, &PlayerLogic::concededChanged, this, [this](int id, bool conceded) {
+ if (conceded) {
+ clearArrowsForPlayer(id);
+ }
+ rearrange();
+ });
+
+ connect(player, &PlayerLogic::arrowDeleted, this, &GameScene::deleteArrow);
+ connect(player, &PlayerLogic::arrowCreateRequested, this, &GameScene::addArrow);
+ connect(player, &PlayerLogic::arrowDeleteRequested, this, &GameScene::requestArrowDeletion);
+ connect(player, &PlayerLogic::arrowsClearedLocally, this,
+ [this, id = player->getPlayerInfo()->getId()]() { clearArrowsForPlayerLocally(id); });
+
+ connect(player->getPlayerEventHandler(), &PlayerEventHandler::cardZoneChanged, this, &GameScene::onCardZoneChanged);
+
+ rearrange();
}
/**
@@ -79,17 +110,19 @@ void GameScene::addPlayer(Player *player)
*
* Closes any zone views associated with the player and recomputes layout.
*/
-void GameScene::removePlayer(Player *player)
+void GameScene::removePlayer(PlayerLogic *player)
{
qCInfo(GameScenePlayerAdditionRemovalLog) << "GameScene::removePlayer name=" << player->getPlayerInfo()->getName();
+ clearArrowsForPlayer(player->getPlayerInfo()->getId());
+
for (ZoneViewWidget *zone : zoneViews) {
if (zone->getPlayer() == player) {
zone->close();
}
}
- players.removeOne(player->getGraphicsItem());
- removeItem(player->getGraphicsItem());
+ auto *view = playerViews.take(player->getPlayerInfo()->getId());
+ removeItem(view);
rearrange();
}
@@ -164,14 +197,14 @@ void GameScene::processViewSizeChange(const QSize &newSize)
*
* Used to determine rotation and layout order.
*/
-QList GameScene::collectActivePlayers(int &firstPlayerIndex) const
+QList GameScene::collectActivePlayers(int &firstPlayerIndex) const
{
- QList activePlayers;
+ QList activePlayers;
firstPlayerIndex = 0;
bool firstPlayerFound = false;
- for (auto *pgItem : players) {
- Player *p = pgItem->getPlayer();
+ for (auto *pgItem : playerViews.values()) {
+ PlayerLogic *p = pgItem->getPlayer();
if (p && !p->getConceded()) {
activePlayers.append(p);
if (!firstPlayerFound && p->getPlayerInfo()->getLocal()) {
@@ -191,15 +224,17 @@ QList GameScene::collectActivePlayers(int &firstPlayerIndex) const
*
* Applies rotation offset and ensures the list wraps correctly.
*/
-QList GameScene::rotatePlayers(const QList &activePlayers, int firstPlayerIndex) const
+QList GameScene::rotatePlayers(const QList &activePlayers, int firstPlayerIndex) const
{
- QList rotated = activePlayers;
+ QList rotated = activePlayers;
if (!rotated.isEmpty()) {
int totalRotation = firstPlayerIndex + playerRotation;
- while (totalRotation < 0)
+ while (totalRotation < 0) {
totalRotation += rotated.size();
- for (int i = 0; i < totalRotation; ++i)
+ }
+ for (int i = 0; i < totalRotation; ++i) {
rotated.append(rotated.takeFirst());
+ }
}
return rotated;
}
@@ -222,7 +257,7 @@ int GameScene::determineColumnCount(int playerCount)
* - Position players in columns with spacing.
* - Mirror graphics for visual balance.
*/
-QSizeF GameScene::computeSceneSizeAndPlayerLayout(const QList &playersPlaying, int columns)
+QSizeF GameScene::computeSceneSizeAndPlayerLayout(const QList &playersPlaying, int columns)
{
playersByColumn.clear();
@@ -230,7 +265,7 @@ QSizeF GameScene::computeSceneSizeAndPlayerLayout(const QList &players
qreal sceneHeight = 0, sceneWidth = -playerAreaSpacing;
QList columnWidth;
- QListIterator playersIter(playersPlaying);
+ QListIterator playersIter(playersPlaying);
for (int col = 0; col < columns; ++col) {
playersByColumn.append(QList());
columnWidth.append(0);
@@ -238,11 +273,12 @@ QSizeF GameScene::computeSceneSizeAndPlayerLayout(const QList &players
int rowsInColumn = rows - (playersPlaying.size() % columns) * col; // Adjust rows for uneven columns
for (int j = 0; j < rowsInColumn; ++j) {
- Player *player = playersIter.next();
- if (col == 0)
+ PlayerLogic *player = playersIter.next();
+ if (col == 0) {
playersByColumn[col].prepend(player->getGraphicsItem());
- else
+ } else {
playersByColumn[col].append(player->getGraphicsItem());
+ }
auto *pgItem = player->getGraphicsItem();
thisColumnHeight += pgItem->boundingRect().height() + playerAreaSpacing;
@@ -281,8 +317,9 @@ QList GameScene::calculateMinWidthByColumn() const
QList minWidthByColumn;
for (const auto &col : playersByColumn) {
qreal maxWidth = 0;
- for (PlayerGraphicsItem *player : col)
+ for (PlayerGraphicsItem *player : col) {
maxWidth = std::max(maxWidth, player->getMinimumWidth());
+ }
minWidthByColumn.append(maxWidth);
}
return minWidthByColumn;
@@ -330,6 +367,87 @@ void GameScene::resizeColumnsAndPlayers(const QList &minWidthByColumn, qr
}
}
+void GameScene::addArrow(QSharedPointer data)
+{
+ auto *startView = playerViews.value(data->startPlayerId);
+ auto *targetView = playerViews.value(data->targetPlayerId);
+ if (!startView || !targetView) {
+ return;
+ }
+
+ auto *startZone = startView->getPlayer()->getZones().value(data->startZone);
+ if (!startZone) {
+ return;
+ }
+
+ CardItem *startCard = startZone->getCard(data->startCardId);
+ if (!startCard) {
+ return;
+ }
+
+ ArrowTarget *targetItem = nullptr;
+ if (data->isPlayerTargeted()) {
+ targetItem = targetView->getPlayerTarget();
+ } else {
+ if (auto *zone = targetView->getPlayer()->getZones().value(data->targetZone)) {
+ targetItem = zone->getCard(data->targetCardId);
+ }
+ }
+ if (!targetItem) {
+ return;
+ }
+
+ auto *arrow = new ArrowItem(data, startCard, targetItem);
+ addItem(arrow);
+ arrowRegistry.insert(data, arrow);
+ connect(arrow, &ArrowItem::requestDeletion, this, &GameScene::requestArrowDeletion);
+}
+
+void GameScene::deleteArrow(int playerId, int arrowId)
+{
+ if (auto *arrow = arrowRegistry.take(playerId, arrowId)) {
+ arrow->delArrow();
+ }
+}
+
+void GameScene::requestArrowDeletion(int playerId, int arrowId)
+{
+ if (arrowRegistry.contains(playerId, arrowId)) {
+ emit arrowDeletionRequested(playerId, arrowId);
+ }
+}
+
+void GameScene::onCardZoneChanged(CardItem *card, bool sameZone)
+{
+ QList toDelete;
+ for (auto *arrow : arrowRegistry.all()) {
+ if (arrow->getStartItem() == card || arrow->getTargetItem() == card) {
+ if (sameZone) {
+ arrow->updatePath();
+ } else {
+ toDelete.append(arrow);
+ }
+ }
+ }
+ for (auto *arrow : toDelete) {
+ deleteArrow(arrow->getCreatorId(), arrow->getId());
+ }
+}
+
+void GameScene::clearArrowsForPlayer(int playerId)
+{
+ for (int arrowId : arrowRegistry.idsForPlayer(playerId)) {
+ emit requestArrowDeletion(playerId, arrowId);
+ }
+}
+
+void GameScene::clearArrowsForPlayerLocally(int playerId)
+{
+ for (int arrowId : arrowRegistry.idsForPlayer(playerId)) {
+ arrowRegistry.take(playerId, arrowId)->delArrow();
+ }
+}
+
// ---------- Hover Handling ----------
void GameScene::updateHover(const QPointF &scenePos)
@@ -343,18 +461,38 @@ void GameScene::updateHover(const QPointF &scenePos)
void GameScene::updateHoveredCard(CardItem *newCard)
{
- if (hoveredCard && (newCard != hoveredCard))
- hoveredCard->setHovered(false);
- if (newCard && (newCard != hoveredCard))
- newCard->setHovered(true);
+ if (hoveredCard && (newCard != hoveredCard)) {
+ endCardHover(hoveredCard);
+ }
+ if (newCard && (newCard != hoveredCard)) {
+ beginCardHover(newCard);
+ }
hoveredCard = newCard;
}
+void GameScene::beginCardHover(CardItem *card)
+{
+ card->setHovered(true);
+ if (auto *zone = SelectZone::findOwningSelectZone(card)) {
+ zone->escapeClipForHover(card);
+ }
+}
+
+void GameScene::endCardHover(CardItem *card)
+{
+ if (auto *zone = SelectZone::findOwningSelectZone(card)) {
+ zone->restoreClipAfterHover(card);
+ }
+ card->setHovered(false);
+}
+
CardZone *GameScene::findTopmostZone(const QList &items)
{
- for (QGraphicsItem *item : items)
- if (auto *zone = qgraphicsitem_cast(item))
+ for (QGraphicsItem *item : items) {
+ if (auto *zone = qgraphicsitem_cast(item)) {
return zone;
+ }
+ }
return nullptr;
}
@@ -365,14 +503,17 @@ CardItem *GameScene::findTopmostCardInZone(const QList &items,
for (QGraphicsItem *item : items) {
CardItem *card = qgraphicsitem_cast(item);
- if (!card)
+ if (!card) {
continue;
+ }
if (card->getAttachedTo()) {
- if (card->getAttachedTo()->getZone() != zone->getLogic())
+ if (card->getAttachedTo()->getZone() != zone->getLogic()) {
continue;
- } else if (card->getZone() != zone->getLogic())
+ }
+ } else if (card->getZone() != zone->getLogic()) {
continue;
+ }
if (card->getRealZValue() > maxZ) {
maxZ = card->getRealZValue();
@@ -394,7 +535,7 @@ CardItem *GameScene::findTopmostCardInZone(const QList &items,
* If an identical view exists, it is closed. Otherwise, a new ZoneViewWidget is created
* and positioned based on zone type.
*/
-void GameScene::toggleZoneView(Player *player, const QString &zoneName, int numberCards, bool isReversed)
+void GameScene::toggleZoneView(PlayerLogic *player, const QString &zoneName, int numberCards, bool isReversed)
{
for (auto &view : zoneViews) {
ZoneViewZone *temp = view->getZone();
@@ -411,12 +552,13 @@ void GameScene::toggleZoneView(Player *player, const QString &zoneName, int numb
connect(item, &ZoneViewWidget::closePressed, this, &GameScene::removeZoneView);
addItem(item);
- if (zoneName == ZoneNames::GRAVE)
+ if (zoneName == ZoneNames::GRAVE) {
item->setPos(360, 100);
- else if (zoneName == ZoneNames::EXILE)
+ } else if (zoneName == ZoneNames::EXILE) {
item->setPos(380, 120);
- else
+ } else {
item->setPos(340, 80);
+ }
}
/**
@@ -426,7 +568,7 @@ void GameScene::toggleZoneView(Player *player, const QString &zoneName, int numb
* @param cardList List of cards to show.
* @param withWritePermission Whether edits are allowed.
*/
-void GameScene::addRevealedZoneView(Player *player,
+void GameScene::addRevealedZoneView(PlayerLogic *player,
CardZoneLogic *zone,
const QList &cardList,
bool withWritePermission)
@@ -453,8 +595,9 @@ void GameScene::removeZoneView(ZoneViewWidget *item)
*/
void GameScene::clearViews()
{
- while (!zoneViews.isEmpty())
+ while (!zoneViews.isEmpty()) {
zoneViews.first()->close();
+ }
}
/**
@@ -462,8 +605,9 @@ void GameScene::clearViews()
*/
void GameScene::closeMostRecentZoneView()
{
- if (!zoneViews.isEmpty())
+ if (!zoneViews.isEmpty()) {
zoneViews.last()->close();
+ }
}
// ---------- View Transforms ----------
@@ -482,8 +626,11 @@ QTransform GameScene::getViewportTransform() const
bool GameScene::event(QEvent *event)
{
- if (event->type() == QEvent::GraphicsSceneMouseMove)
+ if (event->type() == QEvent::GraphicsSceneMouseMove) {
updateHover(static_cast(event)->scenePos());
+ } else if (event->type() == QEvent::Leave) {
+ updateHoveredCard(nullptr);
+ }
return QGraphicsScene::event(event);
}
@@ -493,25 +640,29 @@ void GameScene::timerEvent(QTimerEvent * /*event*/)
QMutableSetIterator i(cardsToAnimate);
while (i.hasNext()) {
i.next();
- if (!i.value()->animationEvent())
+ if (!i.value()->animationEvent()) {
i.remove();
+ }
}
- if (cardsToAnimate.isEmpty())
+ if (cardsToAnimate.isEmpty()) {
animationTimer->stop();
+ }
}
void GameScene::registerAnimationItem(AbstractCardItem *card)
{
cardsToAnimate.insert(static_cast(card));
- if (!animationTimer->isActive())
+ if (!animationTimer->isActive()) {
animationTimer->start(10, this);
+ }
}
void GameScene::unregisterAnimationItem(AbstractCardItem *card)
{
cardsToAnimate.remove(static_cast(card));
- if (cardsToAnimate.isEmpty())
+ if (cardsToAnimate.isEmpty()) {
animationTimer->stop();
+ }
}
// ---------- Rubber Band ----------
diff --git a/cockatrice/src/game/game_scene.h b/cockatrice/src/game/game_scene.h
index f08e83aa4..567089fc0 100644
--- a/cockatrice/src/game/game_scene.h
+++ b/cockatrice/src/game/game_scene.h
@@ -1,7 +1,10 @@
#ifndef GAMESCENE_H
#define GAMESCENE_H
-#include "zones/logic/card_zone_logic.h"
+#include "arrow_registry.h"
+#include "board/arrow_data.h"
+#include "board/arrow_item.h"
+#include "zones/card_zone_logic.h"
#include
#include
@@ -12,7 +15,7 @@
inline Q_LOGGING_CATEGORY(GameSceneLog, "game_scene");
inline Q_LOGGING_CATEGORY(GameScenePlayerAdditionRemovalLog, "game_scene.player_addition_removal");
-class Player;
+class PlayerLogic;
class PlayerGraphicsItem;
class ZoneViewWidget;
class CardZone;
@@ -41,8 +44,9 @@ private:
static const int playerAreaSpacing = 5; ///< Space between player areas
PhasesToolbar *phasesToolbar; ///< Toolbar showing game phases
- QList players; ///< All player graphics items
+ QMap playerViews; ///< ID lookup for player graphics items
QList> playersByColumn; ///< Players organized by column
+ ArrowRegistry arrowRegistry; ///< ID registry for arrow graphics items
QList zoneViews; ///< Active zone view widgets
QSize viewSize; ///< Current view size
QPointer hoveredCard; ///< Currently hovered card
@@ -56,6 +60,14 @@ private:
*/
void updateHover(const QPointF &scenePos);
+ /**
+ * @brief Activates hover state and escapes the card from its clip container
+ * so hover scaling is visible beyond zone bounds.
+ */
+ void beginCardHover(CardItem *card);
+ /** @brief Deactivates hover state and restores the card to its clip container. */
+ void endCardHover(CardItem *card);
+
public:
/**
* @brief Constructs the GameScene.
@@ -64,23 +76,26 @@ public:
*/
explicit GameScene(PhasesToolbar *_phasesToolbar, QObject *parent = nullptr);
- /** Destructor, cleans up timer and zone views. */
+ /** @brief Destructor, cleans up timer and zone views. */
~GameScene() override;
- /** Updates UI text for all zone views. */
+ /** @brief Updates UI text for all zone views. */
void retranslateUi();
+ /** @brief Gets all selected CardItems. */
+ QList selectedCards() const;
+
/**
* @brief Adds a player to the scene and stores their graphics item.
* @param player Player to add.
*/
- void addPlayer(Player *player);
+ void addPlayer(PlayerLogic *player);
/**
* @brief Removes a player from the scene.
* @param player Player to remove.
*/
- void removePlayer(Player *player);
+ void removePlayer(PlayerLogic *player);
/**
* @brief Adjusts the global rotation offset for player layout.
@@ -88,7 +103,7 @@ public:
*/
void adjustPlayerRotation(int rotationAdjustment);
- /** Recomputes the layout of players and the scene size. */
+ /** @brief Recomputes the layout of players and the scene size. */
void rearrange();
/**
@@ -102,7 +117,7 @@ public:
* @param firstPlayerIndex Output index of first local player.
* @return List of active players.
*/
- QList collectActivePlayers(int &firstPlayerIndex) const;
+ QList