summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCards
AgeCommit message (Collapse)Author
2023-01-06LibCards+Games: Make `CardGame::add_stack()` fallibleSam Atkins
And while we're at it, handle the CardStack allocation (and failure thereof) internally.
2023-01-06LibCards: Support "previewing" cards that may be covered by other cardsTimothy Flynn
For example, in Solitaire, the vertical normal stacks cover the suit of all but the topmost card in the stack. To see the suit of covered cards the user currently has to move the cards on top of them out of the way. This adds an API for games to set a card at a location to be previewed, which will draw that card on top of all other cards without moving it.
2023-01-06LibCards+Solitaire: Elevate card highlight management to the card stackTimothy Flynn
Instead of indicating which individual cards should be highlighted, card games now indicate which stack is highlighted. This lets the stack draw empty stacks with a highlight (e.g. the Foundation stack in Solitaire). If the stack is non-empty, the stack can delegate highlighting to the top-most card.
2023-01-06LibCards: Draw the inside of card highlight rects with rounded cornersTimothy Flynn
Currently, the outside of the card highlight has rounded corners, but the inside has square corners. It looks a bit more polished if they are both rounded.
2023-01-05LibCards: Add a helper to create an action to open Cards SettingsTimothy Flynn
This is a useful shortcut to open the settings from within the game rather than having to go through the system menu.
2023-01-05LibCards: Support highlighting cards of interestTimothy Flynn
For example, in Solitaire, when dragging a card around, it's common for other implementations to highlight the card underneath the dragged card if that other card is a valid drop target. This implementation will draw a rounded rectangle within the edges of the highlighted card, using a rudimentary complementary color of the board background color.
2023-01-05LibGfx: Avoid rounding/truncating glyph positions till blittingMacDue
This keeps some overloads that accept ints to avoid adding calls to .to_type<float>() all over the place.
2023-01-03LibGfx: Make Font::width() return a floatAndreas Kling
2022-12-07Meta+Userland: Pass Gfx::IntPoint by valueMacDue
This is just two ints or 8 bytes or the size of the reference on x86_64 or AArch64.
2022-12-07Meta+Userland: Pass Gfx::Color by valueMacDue
Gfx::Color is always 4 bytes (it's just a wrapper over u32) it's less work just to pass the color directly. This also updates IPCCompiler to prevent from generating Gfx::Color const &, which makes replacement easier.
2022-12-06AK+Everywhere: Rename String to DeprecatedStringLinus Groh
We have a new, improved string type coming up in AK (OOM aware, no null state), and while it's going to use UTF-8, the name UTF8String is a mouthful - so let's free up the String name by renaming the existing class. Making the old one have an annoying name will hopefully also help with quick adoption :^)
2022-11-01Everywhere: Mark dependencies of most targets as PRIVATETim Schumacher
Otherwise, we end up propagating those dependencies into targets that link against that library, which creates unnecessary link-time dependencies. Also included are changes to readd now missing dependencies to tools that actually need them.
2022-11-01Everywhere: Explicitly link all binaries against the LibC targetTim Schumacher
Even though the toolchain implicitly links against -lc, it does not know where it should get LibC from except for the sysroot. In the case of Clang this causes it to pick up the LibC stub instead, which might be slightly outdated and feature missing symbols. This is currently not an issue that manifests because we pass through the dependency on LibC and other libraries by accident, which causes CMake to link against the LibC target (instead of just the library), and thus points the linker at the build output directory. Since we are looking to fix that in the upcoming commits, let's make sure that everything will still be able to find the proper LibC first.
2022-10-10LibCards+Games: Remove concept of a CardStack being focusedSam Atkins
This was only used for asking the stack if it is the one we are moving cards from. We now have a better way to do that, by comparing against `CardGame::moving_cards_source_stack()`, which doesn't require manually telling a stack that it is/isn't focused.
2022-10-10LibCards: If dropping cards over multiple valid stacks, pick the closestSam Atkins
Previously, dropping a card that overlapped multiple stacks that could accept it, would always choose the stack that came first in the stacks list, usually the leftmost one. This would feel very odd if the card was only slightly overlapping the left stack, and 90% over the right one. So now, we keep looking for closer stacks even once we've found a valid one. There may be an option that feels even better, based on the position of the card being dragged and the card on top of the stack we're dropping onto, but this already fixes the issue and feels very nice. :^)
2022-10-10LibCards: Add support for card draggingSam Atkins
Solitaire and Spider have almost identical code for dragging cards from one stack to another, so it makes sense to move that here. But using the term "moving" for them, instead of "focused" which (to me at least) was not clear what it meant.
2022-10-10LibCards+Games: Move `mark_intersecting_stacks_dirty()` to CardGameSam Atkins
As part of this, made a const overload for `Card::rect()`. We need the non-const one too as it's used for modifying the position of a card that's being dragged. I plan on changing that soon but we'll see.
2022-10-10LibCards+Spider: Move `ensure_top_card_is_visible()` logic to CardStackSam Atkins
2022-10-10LibCards: Fix some minor clang-tidy issuesSam Atkins
2022-10-10LibCards: Combine CardStack constructorsSam Atkins
And while I'm at it, clarify the name of `associated_stack` to `covered_stack`. It's used in exactly one way, so we can make the code clearer by giving it a less generic name.
2022-10-10LibCards+Games: Rename "draw" methods to "paint" for claritySam Atkins
"Draw" is already a card-game term so using it for graphics was confusing me a lot!
2022-10-10LibCards+Games: Make CardGame responsible for managing CardStacksSam Atkins
Just moving some code around really.
2022-10-10LibCards+Games: Move "create a deck" logic to LibCardsSam Atkins
`create_standard_deck()` is the usual 52-card deck, but more custom setups (such as Spider's multiples-of-one-suit) can be created by passing suit counts to `create_deck()`.
2022-08-22LibCards: Remove card-back-image scalingSam Atkins
This was giving wonky results with images that do not fill the entire card - and it's also unnecessary, since the Buggie image we have been using, and the two I will be adding, are all small enough to not need scaling anyway. :^)
2022-08-22LibCards: Make the card back image configurableSam Atkins
`CardPainter::set_background_image_path()` immediately repaints the card back and inverted card back bitmaps if they exist, so users just need to `update()` that part of the screen. This is handled automatically by `CardGame`, but other users will have to do this manually.
2022-08-22LibCards: Centralise card bitmap creationSam Atkins
Instead of each card being responsible for painting its own bitmaps, we now have a CardPainter which is responsible for this. It paints a given card the first time it is requested, and then re-uses that bitmap when requested in the future. This saves memory for duplicate cards (such as in Spider where several sets of the same suit are used) or unused ones (for example, the inverted cards which are only used by Hearts). It also means we don't throw away bitmaps and then re-create identical ones when starting a new game. We get some nice memory savings from this: | | Before | After | Before (Virtual) | After (Virtual) | |:----------|---------:|---------:|-----------------:|----------------:| | Hearts | 12.2 MiB | 9.3 MiB | 25.1 MiB | 22.2 MiB | | Spider | 12.1 MiB | 10.1 MiB | 29.2 MiB | 22.9 MiB | | Solitaire | 16.4 MiB | 9.0 MiB | 25.0 MiB | 21.9 MiB | All these measurements taken from x86_64 build, from a fresh launch of each game after the animation has finished, but without making any moves. The Hearts value will go up once inverted cards start being requested.
2022-08-22LibCards+Games: Replace card "value" int with a Rank enumSam Atkins
Because `card->value() == 11` is a lot less clear than `card->rank() == Cards::Rank::Queen`, and also safer. Put this, along with the `Suit` enum, in the `Cards` namespace directly instead of inside `Cards::Card`. Slightly less typing that way.
2022-08-22LibCards: Add a CardGame base classSam Atkins
For now, the only feature of this is that it sets the background colour from the `Games::Cards::BackgroundColor` config value. Later, other card game configuration and shared behaviour can go here, to save duplicating it in each game.
2022-07-12Everywhere: Add sv suffix to strings relying on StringView(char const*)sin-ack
Each of these strings would previously rely on StringView's char const* constructor overload, which would call __builtin_strlen on the string. Since we now have operator ""sv, we can replace these with much simpler versions. This opens the door to being able to remove StringView(char const*). No functional changes.
2022-04-09LibGfx: Move other font-related files to LibGfx/Font/Simon Wanner
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2022-03-18LibCards+Games: Change name of card type to card suitLenny Maiorani
Playing cards have a `suit` such as `hearts`/`diamonds`, not a `type`. Make the internal naming consistent with the way playing cards are typically named.
2022-03-18Libraries: Change enums to enum classes in LibCardsLenny Maiorani
2022-03-10Libraries: Use default constructors/destructors in LibCardsLenny Maiorani
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules "The compiler is more likely to get the default semantics right and you cannot implement these functions better than the compiler."
2022-03-04Libraries: Make CharacterBitmap instances at compile-timeLenny Maiorani
`CharacterBitmap` instances are generated at run-time and put on the heap, but they can be created in a `constexpr` context and stored in static memory. Also, remove additional `width` and `height` `static` values in favor of using the `constexpr` member functions of `CharacterBitmap`. These changes also include the removal of some initialization code which tests if the `CharacterBitmap` is created since it is always created and removes function-local `static` values which cause run-time branches to ensure it is initialized each time the function is called.
2021-11-17AK: Convert AK::Format formatting helpers to returning ErrorOr<void>Andreas Kling
This isn't a complete conversion to ErrorOr<void>, but a good chunk. The end goal here is to propagate buffer allocation failures to the caller, and allow the use of TRY() with formatting functions.
2021-11-08LibGfx: Use ErrorOr<T> for Bitmap::try_create()Andreas Kling
Another one that was used in a fajillion places.
2021-11-08LibGfx: Use ErrorOr<T> for Bitmap::try_load_from_file()Andreas Kling
This was used in a lot of places, so this patch makes liberal use of ErrorOr<T>::release_value_but_fixme_should_propagate_errors().
2021-11-08LibGfx: Use ErrorOr<T> for Bitmap::clone()Andreas Kling
2021-07-21LibGfx: Use "try_" prefix for static factory functionsAndreas Kling
Also mark them as [[nodiscard]].
2021-06-24LibCards: Support non-alternating colour patience gamesJamie Mansfield
This introduces a new MovementType concept to LibCards, starting the process to allow other patience games to be implemented using it - that differ more substantially from Klondike in logic. This is currently used for two purposes: 1. to verify that the 'grabbed' stack of cards is valid* (sequential and correct colours) and 2. to allow 'grabbed' stacks to be pushed onto same-colour, either-colour, or alternating-colour stacks * Klondike doesn't need this logic, as per how the game works any 'grabbed' selection is guaranteed to be valid.
2021-06-04LibCards: Draw card stack background when the entire stack is movingTimothy Flynn
The stack background should be painted when the entire stack is being dragged, rather than just the top card. Fixes #7786. Regressed in 2b762ef94075b8a6e1ae8dd61e535b6b6cf7c064.
2021-06-04Solitaire+LibCards: Draw card stacks with rounded cornersTimothy Flynn
Now that the cards have rounded corners, draw the stack box behind the cards with rounded corners as well. This way, the corner of the stack box doesn't peek out from behind the cards. The caveat here is that the "play" card stack now needs to hold a reference to the "waste" stack beneath it so it knows when not to draw its background on top of the waste stack. To faciliate that, the array of card stacks is now a NonnullRefPtrVector so the play stack can store a smart pointer to the waste stack (instead of a raw pointer or reference).
2021-06-04LibCards: Don't draw the first card smaller than the othersGunnar Beutner
2021-06-03LibCards: Draw cards with rounded card cornersDavid Isaksson
closes #7412
2021-05-26Hearts: Highlight cards when an invalid play is attemptedGunnar Beutner
This briefly inverts the selected card when the user attempts to make an invalid play.
2021-05-22LibCards: Fix alignment for the card labelsGunnar Beutner
Previously the code didn't take into account that the label for the "10" card is larger than for the other cards.
2021-05-22LibCards: Correct a spelling mistakeGunnar Beutner
2021-05-21Games: Add HeartsGunnar Beutner
2021-05-21Solitaire: Move cards functionality into LibCardsGunnar Beutner