MMapper icon indicating copy to clipboard operation
MMapper copied to clipboard

Token Manager (Qt6): default checkboxes unchecked; token size 32px

Open Sunnyl75 opened this issue 2 months ago • 1 comments

Updates Token Manager to Qt 6. Sets checkboxes default to unchecked and tokenSizeComboBox default to 32 px. Built and validated in alt CI; identical commits here.

Summary by Sourcery

Introduce full token management and rendering for characters in both group and map views, including custom overrides, ghost tokens for removed NPCs, and new user preferences defaulting to 32px icons.

New Features:

  • Add TokenManager to load, cache, and upload custom character tokens from a tokens directory
  • Allow setting or clearing individual character icons via context menu in the group widget
  • Render tokens in the group list and map canvas with support for ghost tokens of removed NPCs

Enhancements:

  • Refactor GroupModel to use helper functions for display and tooltip roles and extract insertion logic
  • Introduce GhostRegistry to track removed NPC positions and render ghost icons on the map
  • Extend CGroupChar and CharacterBatch to pass display names for token lookup and rendering

Build:

  • Include tokenmanager.cpp and tokenmanager.h in the build sources

Documentation:

  • Update README to point to the wiki build instructions

Sunnyl75 avatar Oct 22 '25 04:10 Sunnyl75

Reviewer's Guide

This PR adds a new TokenManager to handle custom character icons, integrates token rendering into the group list and map (including NPC ghost tokens), introduces new group preferences (show/hide tokens, map tokens, NPC ghosts, and configurable token size with defaults unchecked and 32px), refactors GroupModel character insertion/removal to use a helper and ghost registry, and updates build and docs accordingly.

Sequence diagram for updating character token and map rendering

sequenceDiagram
    actor User
    participant GroupWidget
    participant TokenManager
    participant MapCanvas
    User->>GroupWidget: Set icon for character
    GroupWidget->>TokenManager: getToken(key)
    GroupWidget->>GroupWidget: slot_updateLabels()
    GroupWidget->>MapCanvas: sig_characterUpdated(character)
    MapCanvas->>TokenManager: getToken(key)
    MapCanvas->>MapCanvas: slot_requestUpdate()
    MapCanvas->>MapCanvas: paintCharacters() (uses token icon)

Entity relationship diagram for new group manager settings

erDiagram
    GROUP_MANAGER_SETTINGS {
        bool showTokens
        bool showMapTokens
        int tokenIconSize
        bool showNpcGhosts
        QMap tokenOverrides
    }
    TOKEN_OVERRIDES {
        QString characterName
        QString tokenKey
    }
    GROUP_MANAGER_SETTINGS ||--o{ TOKEN_OVERRIDES : contains

Class diagram for new and updated token management classes

classDiagram
class TokenManager {
  +QPixmap getToken(key: QString)
  +static QString overrideFor(displayName: QString)
  +const QMap<QString, QString> &availableFiles()
  +MMTextureId textureIdFor(key: QString)
  +MMTextureId uploadNow(key: QString, px: QPixmap)
  +void rememberUpload(key: QString, id: MMTextureId, tex: SharedMMTexture)
  +SharedMMTexture textureById(id: MMTextureId) const
  -void scanDirectories()
  -QMap<QString, QString> m_availableFiles
  -QFileSystemWatcher m_watcher
  -QMap<QString, QString> m_tokenPathCache
  -QPixmap m_fallbackPixmap
  -QHash<QString, MMTextureId> m_textureCache
  -QVector<SharedMMTexture> m_ownedTextures
}
class CGroupChar {
  -QString m_characterToken
  +QString getDisplayName() const
  +void setCharacterToken(tokenPath: QString)
  +const QString &getCharacterToken() const
  +inline bool isMount() const
}
class GhostInfo {
  +QString tokenKey
}
class GhostRegistry {
}

TokenManager <.. CGroupChar : uses
CGroupChar <.. GhostRegistry : used for ghost tokens
GhostRegistry <.. GhostInfo : contains

File-Level Changes

Change Details Files
Add TokenManager for loading, caching and uploading token pixmaps and textures
  • Implement TokenManager singleton with directory scanning, override lookup and QFileSystemWatcher
  • Add pixmap fetch, normalization of keys, and fallback handling
  • Expose textureIdFor, uploadNow, rememberUpload, textureById APIs
  • Register tokenmanager.cpp/h in CMakeLists
src/group/tokenmanager.cpp
src/group/tokenmanager.h
CMakeLists.txt
Integrate tokens into group list UI with context menu actions
  • Pass TokenManager to GroupModel and extract decoration logic into makeDisplayRole/makeTooltipRole
  • Use tm->getToken to display icon column and adjust dataForCharacter implementation
  • Add Set & Use Default icon actions to GroupWidget context menu
  • Adjust table icon size and row height based on tokenIconSize config
src/group/groupwidget.cpp
src/group/groupwidget.h
Render map tokens and NPC ghost tokens in CharacterBatch
  • Extend drawCharacter and drawBox to accept dispName and queue token quads
  • Upload and bind textures for tokens under colored overlay
  • Introduce GhostRegistry and use g_ghosts to render ghost tokens on map
  • Clear and manage m_charTokenQuads and m_charTokenKeys buffers
src/display/Characters.cpp
src/display/Characters.h
src/display/GhostRegistry.h
Add and wire new group preferences for token visibility, map tokens, NPC ghosts, and token size
  • Add showTokens, showMapTokens, showNpcGhosts, tokenIconSize, tokenOverrides to Configuration::GroupManagerSettings
  • Read/write these new keys in configuration.cpp
  • Add checkboxes and tokenSizeComboBox in GroupPage with default unchecked and 32px selection
  • Emit sig_groupSettingsChanged on state changes
src/preferences/grouppage.cpp
src/preferences/grouppage.h
src/configuration/configuration.cpp
src/configuration/configuration.h
Refactor GroupModel character insertion/removal and introduce ghost handling helper
  • Extract insertNewCharactersInto helper to simplify NPC sorting logic
  • Replace manual insertion in setCharacters with helper call
  • On removeCharacterById, store a ghost entry for NPCs when showNpcGhosts is enabled
src/group/groupwidget.cpp
Miscellaneous build updates and documentation tweaks
  • Include display/GhostRegistry.h in main target sources
  • Update README link for build instructions
  • Trigger CI via README change
README.md
CMakeLists.txt

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an issue from a review comment by replying to it. You can also reply to a review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull request title to generate a title at any time. You can also comment @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment @sourcery-ai summary on the pull request to (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

  • Contact our support team for questions or feedback.
  • Visit our documentation for detailed guides and information.
  • Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.

sourcery-ai[bot] avatar Oct 22 '25 04:10 sourcery-ai[bot]