Compare commits
4 Commits
34678665a8
...
88f957b5ed
| Author | SHA1 | Date |
|---|---|---|
|
|
88f957b5ed | |
|
|
547c13ce7f | |
|
|
9ef9318a51 | |
|
|
4afd260bab |
674
LICENSE
|
|
@ -1,674 +0,0 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
|
|
@ -14,23 +14,22 @@ from resources.code_res.game_constants import (
|
|||
FONT_COLOR_STATUS_WIN,
|
||||
FONT_COLOR_TITLE_MAIN,
|
||||
FONT_SIZE_BODY,
|
||||
FONT_SIZE_HEADING,
|
||||
FONT_SIZE_SMALL_MIN,
|
||||
FONT_SIZE_TITLE_LG,
|
||||
OUTCOME_GIF_SIZE,
|
||||
SUBTLE_BORDER,
|
||||
)
|
||||
from resources.code_res.i18n import t
|
||||
from view.widgets.goth_dropdown import GothDropdown
|
||||
from view.widgets.image_button import ImageButton
|
||||
from view.widgets.modal_veil import ModalVeil
|
||||
|
||||
SHOWDOWN_MINI_CARD_SIZE = (48, 70)
|
||||
|
||||
|
||||
class BlackjackResultDialog(tk.Canvas):
|
||||
"""
|
||||
Rahmenloses Gothic-Showdown-Overlay für Blackjack:
|
||||
Hintergrund background_vertical.jpg + box_big.png, Gewinner-Sitze in box_gold_smal.png,
|
||||
übrige Sitze in box_small_purple.png und kompakte Kartenfächer für 768p-Bildschirme.
|
||||
Rahmenloses Gothic-Showdown-Overlay für Blackjack (ohne eingebettetes GIF),
|
||||
immer über allen UI-Leisten platziert und mit abgedunkeltem, gesperrtem Tisch.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
|
|
@ -42,30 +41,31 @@ class BlackjackResultDialog(tk.Canvas):
|
|||
on_next_round,
|
||||
on_back_to_menu,
|
||||
):
|
||||
GothDropdown.close_any_open_popup()
|
||||
top_root = parent.winfo_toplevel()
|
||||
|
||||
hands_list = result_data.get("showdown_hands", [])
|
||||
cols = min(3, max(1, len(hands_list)))
|
||||
rows = (len(hands_list) + 2) // 3 if hands_list else 0
|
||||
|
||||
has_gif = result_data.get("player_won") is not None
|
||||
extra_lines = len(result_data.get("other_gains", []))
|
||||
dlg_w = max(560, min(830, cols * 250 + 64))
|
||||
dlg_h = (
|
||||
(116 if has_gif else 54)
|
||||
58
|
||||
+ (48 if result_data.get("reason_text") else 8)
|
||||
+ (rows * 140 + 28 if rows else 0)
|
||||
+ 92 + min(2, extra_lines) * 20
|
||||
+ (24 if result_data.get("new_level_title") else 0)
|
||||
+ 62
|
||||
)
|
||||
# Sicherstellen, dass das Dialogfenster auch auf 768p-Displays komplett sichtbar bleibt
|
||||
try:
|
||||
max_h = max(460, parent.winfo_toplevel().winfo_height() - 74)
|
||||
max_h = max(420, top_root.winfo_height() - 60)
|
||||
dlg_h = min(dlg_h, max_h)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
super().__init__(
|
||||
parent,
|
||||
top_root,
|
||||
width=dlg_w,
|
||||
height=dlg_h,
|
||||
bg=BG_COLOR,
|
||||
|
|
@ -80,20 +80,17 @@ class BlackjackResultDialog(tk.Canvas):
|
|||
|
||||
self._dlg_w = dlg_w
|
||||
self._dlg_h = dlg_h
|
||||
self._gif_job: str | None = None
|
||||
self._gif_item: int | None = None
|
||||
self._photo_refs: list = []
|
||||
|
||||
self.place(relx=0.5, rely=0.5, anchor="center")
|
||||
self.tk.call("raise", self._w)
|
||||
self._build_scene()
|
||||
self._veil = ModalVeil(top_root, assets, modal_widget=self)
|
||||
|
||||
def _build_scene(self):
|
||||
w, h = self._dlg_w, self._dlg_h
|
||||
cx = w // 2
|
||||
self._photo_refs.clear()
|
||||
|
||||
# 1. Hintergrund + äußerer Zierrahmen box_big.png
|
||||
bg_src = self.assets.raw_bg_vertical or self.assets.raw_bg_horizontal or self.assets.raw_bg
|
||||
if bg_src is not None:
|
||||
bg_ph = ImageTk.PhotoImage(bg_src.resize((w, h), Image.Resampling.LANCZOS))
|
||||
|
|
@ -105,18 +102,9 @@ class BlackjackResultDialog(tk.Canvas):
|
|||
self._photo_refs.append(outer_box)
|
||||
self.create_image(cx, h // 2, image=outer_box, anchor="center")
|
||||
|
||||
cur_y = 20
|
||||
cur_y = 26
|
||||
|
||||
# 2. Win/Lose GIF + Headline
|
||||
p_won = self.data.get("player_won")
|
||||
gif_key = "win_gif" if p_won is True else ("lose_gif" if p_won is False else "")
|
||||
frames = self.assets.get_gif_frames(gif_key, size=(145, 80)) if gif_key else []
|
||||
if frames:
|
||||
self._gif_item = self.create_image(cx, cur_y + 40, image=frames[0], anchor="center")
|
||||
cur_y += 84
|
||||
if len(frames) > 1:
|
||||
self._animate_gif(frames, 0)
|
||||
|
||||
hl_col = (
|
||||
FONT_COLOR_TITLE_MAIN
|
||||
if p_won is True
|
||||
|
|
@ -127,9 +115,8 @@ class BlackjackResultDialog(tk.Canvas):
|
|||
)
|
||||
self._photo_refs.append(hl_ph)
|
||||
self.create_image(cx, cur_y + hl_ph.height() // 2, image=hl_ph, anchor="center")
|
||||
cur_y += hl_ph.height() + 6
|
||||
cur_y += hl_ph.height() + 8
|
||||
|
||||
# 3. Begründung im schmalen Gold-Doppelrahmen
|
||||
reason_txt = self.data.get("reason_text", "")
|
||||
if reason_txt:
|
||||
r_ph = self.assets.get_goth_text_photo(
|
||||
|
|
@ -145,7 +132,6 @@ class BlackjackResultDialog(tk.Canvas):
|
|||
self.create_image(cx, rb_cy, image=r_ph, anchor="center")
|
||||
cur_y += rb_h + 8
|
||||
|
||||
# 4. Showdown-Karten aller Teilnehmer
|
||||
hands_list = self.data.get("showdown_hands", [])
|
||||
if hands_list:
|
||||
sec_ph = self.assets.get_goth_text_photo(
|
||||
|
|
@ -192,7 +178,6 @@ class BlackjackResultDialog(tk.Canvas):
|
|||
self._photo_refs.append(o_ph)
|
||||
self.create_image(sx, sy - seat_h // 2 + 20, image=o_ph, anchor="center")
|
||||
|
||||
# Überlappender Mini-Kartenfächer
|
||||
c_imgs = entry.get("card_images", [])
|
||||
c_photos = []
|
||||
for img_name in c_imgs:
|
||||
|
|
@ -226,7 +211,6 @@ class BlackjackResultDialog(tk.Canvas):
|
|||
|
||||
cur_y += rows * (seat_h + 6) + 6
|
||||
|
||||
# 5. Gold- & XP-Abrechnung
|
||||
self.create_line(36, cur_y, w - 36, cur_y, fill=SUBTLE_BORDER, width=1)
|
||||
cur_y += 10
|
||||
|
||||
|
|
@ -257,13 +241,13 @@ class BlackjackResultDialog(tk.Canvas):
|
|||
if self.data.get("new_level_title"):
|
||||
xp_line = f"{xp_line} • {self.data['new_level_title']}"
|
||||
xp_ph = self.assets.get_goth_text_photo(
|
||||
xp_line, FONT_SIZE_BODY, FONT_COLOR_TITLE_MAIN if self.data.get("new_level_title") else FONT_COLOR_HEADING_SUB,
|
||||
xp_line, FONT_SIZE_BODY,
|
||||
FONT_COLOR_TITLE_MAIN if self.data.get("new_level_title") else FONT_COLOR_HEADING_SUB,
|
||||
max_width=w - 72,
|
||||
)
|
||||
self._photo_refs.append(xp_ph)
|
||||
self.create_image(cx, cur_y + xp_ph.height() // 2, image=xp_ph, anchor="center")
|
||||
|
||||
# 6. Untere Buttons
|
||||
btn_norm = self.assets.raw_btn_default
|
||||
btn_purp = self.assets.raw_btn_purple
|
||||
btn_fire = self.assets.raw_btn_fire or btn_purp
|
||||
|
|
@ -296,19 +280,8 @@ class BlackjackResultDialog(tk.Canvas):
|
|||
)
|
||||
self.create_window(cx, btn_y, window=b_menu, anchor="center")
|
||||
|
||||
def _animate_gif(self, frames: list, idx: int):
|
||||
if not self.winfo_exists() or self._gif_item is None:
|
||||
return
|
||||
self.itemconfigure(self._gif_item, image=frames[idx % len(frames)])
|
||||
self._gif_job = self.after(90, self._animate_gif, frames, (idx + 1) % len(frames))
|
||||
|
||||
def close_dialog(self):
|
||||
if self._gif_job:
|
||||
try:
|
||||
self.after_cancel(self._gif_job)
|
||||
except Exception:
|
||||
pass
|
||||
self._gif_job = None
|
||||
self._veil.release()
|
||||
self._photo_refs.clear()
|
||||
if self.winfo_exists():
|
||||
self.destroy()
|
||||
|
|
|
|||
|
|
@ -1,21 +1,34 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# games/poker/views/poker_result_dialog.py
|
||||
from __future__ import annotations
|
||||
|
||||
import tkinter as tk
|
||||
from models.card import Card
|
||||
from resources.code_res.game_constants import (
|
||||
ACCENT_GOLD, ACCENT_GOTH, CELL_BG, ERROR_FG,
|
||||
FG_COLOR, MODAL_BG, MUTED_FG, SUBTLE_BORDER
|
||||
ACCENT_GOLD,
|
||||
ACCENT_GOTH,
|
||||
CELL_BG,
|
||||
ERROR_FG,
|
||||
FG_COLOR,
|
||||
MODAL_BG,
|
||||
MUTED_FG,
|
||||
SUBTLE_BORDER,
|
||||
)
|
||||
from resources.code_res.i18n import t
|
||||
from view.widgets.goth_dropdown import GothDropdown
|
||||
from view.widgets.image_button import ImageButton
|
||||
from view.widgets.modal_veil import ModalVeil
|
||||
|
||||
POPUP_GIF_SIZE = (145, 80)
|
||||
POPUP_HOLE_CARD_SIZE = (48, 70)
|
||||
POPUP_BOARD_CARD_SIZE = (44, 64)
|
||||
|
||||
|
||||
class PokerResultDialog(tk.Frame):
|
||||
"""Ergebnis-Overlay im einheitlichen BlackjackResultDialog-Stil inkl. Kartenbild-Showdown."""
|
||||
"""
|
||||
Ergebnis-Overlay für Texas Hold'em (ohne eingebettetes GIF),
|
||||
immer über allen UI-Leisten platziert und mit abgedunkeltem, gesperrtem Tisch.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
parent,
|
||||
|
|
@ -25,45 +38,50 @@ class PokerResultDialog(tk.Frame):
|
|||
on_next_round,
|
||||
on_back_to_menu,
|
||||
):
|
||||
GothDropdown.close_any_open_popup()
|
||||
top_root = parent.winfo_toplevel()
|
||||
|
||||
super().__init__(
|
||||
parent, bg=MODAL_BG, padx=26, pady=18,
|
||||
highlightthickness=2, highlightbackground=ACCENT_GOTH
|
||||
top_root,
|
||||
bg=MODAL_BG,
|
||||
padx=26,
|
||||
pady=18,
|
||||
highlightthickness=2,
|
||||
highlightbackground=ACCENT_GOTH,
|
||||
)
|
||||
self.assets = assets
|
||||
self.sounds = sounds
|
||||
self.data = result_data
|
||||
self.on_next_round = on_next_round
|
||||
self.on_back_to_menu = on_back_to_menu
|
||||
self._gif_job = None
|
||||
self._card_photos = []
|
||||
|
||||
self.place(relx=0.5, rely=0.5, anchor="center")
|
||||
self.lift()
|
||||
self._build()
|
||||
self._veil = ModalVeil(top_root, assets, modal_widget=self)
|
||||
|
||||
def _build(self):
|
||||
self.gif_lbl = tk.Label(self, bg=MODAL_BG, bd=0)
|
||||
self.gif_lbl.pack(pady=(0, 4))
|
||||
|
||||
p_won = self.data.get("player_won")
|
||||
if p_won is True:
|
||||
self._start_gif("win_gif")
|
||||
elif p_won is False:
|
||||
self._start_gif("lose_gif")
|
||||
|
||||
headline_color = ACCENT_GOLD if p_won else (
|
||||
MUTED_FG if p_won is None else ERROR_FG
|
||||
)
|
||||
tk.Label(
|
||||
self, text=self.data["headline"],
|
||||
font=("Georgia", 16, "bold"), fg=headline_color, bg=MODAL_BG,
|
||||
wraplength=680, justify="center"
|
||||
self,
|
||||
text=self.data["headline"],
|
||||
font=("Georgia", 16, "bold"),
|
||||
fg=headline_color,
|
||||
bg=MODAL_BG,
|
||||
wraplength=680,
|
||||
justify="center",
|
||||
).pack(pady=(2, 10))
|
||||
|
||||
# --- Karten-Aufdeckung: Gemeinschaftskarten + alle Sitze mit Kartenbildern ---
|
||||
reveal_box = tk.Frame(
|
||||
self, bg=CELL_BG, padx=12, pady=8,
|
||||
highlightthickness=1, highlightbackground=SUBTLE_BORDER
|
||||
self,
|
||||
bg=CELL_BG,
|
||||
padx=12,
|
||||
pady=8,
|
||||
highlightthickness=1,
|
||||
highlightbackground=SUBTLE_BORDER,
|
||||
)
|
||||
reveal_box.pack(fill="x", pady=(0, 10))
|
||||
|
||||
|
|
@ -72,8 +90,11 @@ class PokerResultDialog(tk.Frame):
|
|||
b_row = tk.Frame(reveal_box, bg=CELL_BG)
|
||||
b_row.pack(pady=(0, 6))
|
||||
tk.Label(
|
||||
b_row, text=f"{t('pk_board_title')}:",
|
||||
font=("Georgia", 9, "bold"), fg=MUTED_FG, bg=CELL_BG
|
||||
b_row,
|
||||
text=f"{t('pk_board_title')}:",
|
||||
font=("Georgia", 9, "bold"),
|
||||
fg=MUTED_FG,
|
||||
bg=CELL_BG,
|
||||
).pack(side="left", padx=(0, 8))
|
||||
|
||||
for s_suit, s_rank in board_raw:
|
||||
|
|
@ -94,15 +115,22 @@ class PokerResultDialog(tk.Frame):
|
|||
|
||||
border_c = ACCENT_GOLD if is_win else (SUBTLE_BORDER if not folded else "#3a252a")
|
||||
s_card = tk.Frame(
|
||||
seats_row, bg="#191521", padx=8, pady=5,
|
||||
highlightthickness=2 if is_win else 1, highlightbackground=border_c
|
||||
seats_row,
|
||||
bg="#191521",
|
||||
padx=8,
|
||||
pady=5,
|
||||
highlightthickness=2 if is_win else 1,
|
||||
highlightbackground=border_c,
|
||||
)
|
||||
s_card.grid(row=idx // 6, column=idx % 6, padx=4, pady=2, sticky="nsew")
|
||||
|
||||
name_col = ACCENT_GOLD if is_win else (MUTED_FG if folded else ACCENT_GOTH)
|
||||
tk.Label(
|
||||
s_card, text=entry["name"],
|
||||
font=("Georgia", 9, "bold"), fg=name_col, bg="#191521"
|
||||
s_card,
|
||||
text=entry["name"],
|
||||
font=("Georgia", 9, "bold"),
|
||||
fg=name_col,
|
||||
bg="#191521",
|
||||
).pack()
|
||||
|
||||
c_frame = tk.Frame(s_card, bg="#191521", height=POPUP_HOLE_CARD_SIZE[1] + 2)
|
||||
|
|
@ -116,15 +144,22 @@ class PokerResultDialog(tk.Frame):
|
|||
|
||||
combo_col = "#7be08a" if is_win else (ERROR_FG if folded else FG_COLOR)
|
||||
tk.Label(
|
||||
s_card, text=entry["combo_text"],
|
||||
font=("Helvetica", 8, "bold"), fg=combo_col, bg="#191521",
|
||||
wraplength=112, justify="center"
|
||||
s_card,
|
||||
text=entry["combo_text"],
|
||||
font=("Helvetica", 8, "bold"),
|
||||
fg=combo_col,
|
||||
bg="#191521",
|
||||
wraplength=112,
|
||||
justify="center",
|
||||
).pack()
|
||||
|
||||
# --- Gewinn / Verlust & XP Box (identisch zu BlackjackResultDialog) ---
|
||||
info_box = tk.Frame(
|
||||
self, bg=CELL_BG, padx=20, pady=10,
|
||||
highlightthickness=1, highlightbackground=SUBTLE_BORDER
|
||||
self,
|
||||
bg=CELL_BG,
|
||||
padx=20,
|
||||
pady=10,
|
||||
highlightthickness=1,
|
||||
highlightbackground=SUBTLE_BORDER,
|
||||
)
|
||||
info_box.pack(fill="x", pady=(0, 12))
|
||||
|
||||
|
|
@ -144,54 +179,57 @@ class PokerResultDialog(tk.Frame):
|
|||
tk.Frame(info_box, bg=SUBTLE_BORDER, height=1).pack(fill="x", pady=8)
|
||||
|
||||
tk.Label(
|
||||
info_box, text=t("bj_popup_xp_earned", self.data["xp_gained"]),
|
||||
font=("Helvetica", 11, "bold"), fg=ACCENT_GOTH, bg=CELL_BG,
|
||||
info_box,
|
||||
text=t("bj_popup_xp_earned", self.data["xp_gained"]),
|
||||
font=("Helvetica", 11, "bold"),
|
||||
fg=ACCENT_GOTH,
|
||||
bg=CELL_BG,
|
||||
).pack(pady=1)
|
||||
|
||||
if self.data.get("new_level_title"):
|
||||
tk.Label(
|
||||
info_box, text=self.data["new_level_title"],
|
||||
font=("Georgia", 11, "bold"), fg=ACCENT_GOLD, bg=CELL_BG,
|
||||
info_box,
|
||||
text=self.data["new_level_title"],
|
||||
font=("Georgia", 11, "bold"),
|
||||
fg=ACCENT_GOLD,
|
||||
bg=CELL_BG,
|
||||
).pack(pady=(3, 0))
|
||||
|
||||
# --- Buttons ---
|
||||
btn_row = tk.Frame(self, bg=MODAL_BG)
|
||||
btn_row.pack(fill="x", pady=(4, 0))
|
||||
|
||||
btn_norm = self.assets.raw_btn_default
|
||||
btn_purp = self.assets.raw_btn_purple
|
||||
btn_fire = self.assets.raw_btn_fire or btn_purp
|
||||
|
||||
if self.data.get("can_continue", True):
|
||||
ImageButton(
|
||||
btn_row, t("bj_popup_next_round_btn"),
|
||||
self.assets.raw_btn, self.assets.raw_btn_active,
|
||||
self._handle_next, sound_mgr=self.sounds, width=200, height=40, font=("Helvetica", 10, "bold")
|
||||
btn_row,
|
||||
t("bj_popup_next_round_btn"),
|
||||
btn_fire,
|
||||
btn_fire,
|
||||
self._handle_next,
|
||||
sound_mgr=self.sounds,
|
||||
width=200,
|
||||
height=38,
|
||||
style="fire",
|
||||
).pack(side="left", padx=(0, 10))
|
||||
|
||||
if self.data.get("can_leave_menu", True):
|
||||
ImageButton(
|
||||
btn_row, t("bj_popup_to_menu_btn"),
|
||||
self.assets.raw_sel, self.assets.raw_sel_active,
|
||||
self._handle_menu, sound_mgr=self.sounds, width=170, height=40, font=("Helvetica", 10, "bold")
|
||||
btn_row,
|
||||
t("bj_popup_to_menu_btn"),
|
||||
btn_norm,
|
||||
btn_purp,
|
||||
self._handle_menu,
|
||||
sound_mgr=self.sounds,
|
||||
width=170,
|
||||
height=38,
|
||||
style="amethyst",
|
||||
).pack(side="right")
|
||||
|
||||
def _start_gif(self, key: str):
|
||||
frames = self.assets.get_gif_frames(key, size=POPUP_GIF_SIZE)
|
||||
if not frames:
|
||||
return
|
||||
|
||||
def _step(idx=0):
|
||||
if not self.gif_lbl.winfo_exists():
|
||||
return
|
||||
self.gif_lbl.configure(image=frames[idx])
|
||||
self._gif_job = self.after(90, _step, (idx + 1) % len(frames))
|
||||
|
||||
_step(0)
|
||||
|
||||
def close_dialog(self):
|
||||
if self._gif_job:
|
||||
try:
|
||||
self.after_cancel(self._gif_job)
|
||||
except Exception:
|
||||
pass
|
||||
self._gif_job = None
|
||||
self._veil.release()
|
||||
if self.winfo_exists():
|
||||
self.destroy()
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,266 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# games/solitaire/base/card_hover_zoom.py
|
||||
from __future__ import annotations
|
||||
|
||||
import tkinter as tk
|
||||
from typing import Callable
|
||||
|
||||
from games.solitaire.base.solitaire_card import SolitaireCard
|
||||
from resources.code_res.game_constants import ACCENT_GOLD, BORDER_COLOR
|
||||
|
||||
|
||||
class CardHoverZoom:
|
||||
"""
|
||||
Subtile Karten-Hervorhebung im Stil von Microsoft Solitaire:
|
||||
Hebt die Karte unter dem Mauszeiger leicht vergrößert und nach oben versetzt hervor,
|
||||
behält aber strikt die Stapel-Reihenfolge (Z-Order) bei, sodass alle Karten, die in
|
||||
einer Kaskade auf ihr liegen, weiterhin vollständig sichtbar bleiben.
|
||||
"""
|
||||
|
||||
ZOOM_FACTOR = 1.12 # Dezente Verbreitung/Vergrößerung unter den Folgekarten
|
||||
PEEK_UP_PX = 8 # Leichtes Anheben nach oben, damit Wert & Symbol frei herausschauen
|
||||
HOVER_DELAY_MS = 45
|
||||
TAG = "sol_hover_zoom"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
root: tk.Misc,
|
||||
canvas: tk.Canvas,
|
||||
assets,
|
||||
probe_fn: Callable[[int, int], dict | tuple | None],
|
||||
can_show_fn: Callable[[], bool] | None = None,
|
||||
):
|
||||
self._root = root
|
||||
self._canvas = canvas
|
||||
self._assets = assets
|
||||
self._probe_fn = probe_fn
|
||||
self._can_show_fn = can_show_fn
|
||||
|
||||
self._after_job: str | None = None
|
||||
self._active_target_id: tuple | None = None
|
||||
self._pending_info: dict | None = None
|
||||
self._last_pointer_xy: tuple[int, int] | None = None
|
||||
self._zoom_photo_ref = None
|
||||
|
||||
self._canvas.bind("<Motion>", self._on_motion, add="+")
|
||||
self._canvas.bind("<Leave>", self._on_leave, add="+")
|
||||
self._canvas.bind("<ButtonPress-1>", self._on_press_clear, add="+")
|
||||
self._canvas.bind("<ButtonPress-3>", self._on_press_clear, add="+")
|
||||
|
||||
@staticmethod
|
||||
def _normalize_probe(raw: dict | tuple | None) -> dict | None:
|
||||
if raw is None:
|
||||
return None
|
||||
if isinstance(raw, dict):
|
||||
return raw
|
||||
if isinstance(raw, tuple) and len(raw) >= 4:
|
||||
card, cx, cy, base_sz = raw[:4]
|
||||
under_tag = raw[4] if len(raw) >= 5 else None
|
||||
return {
|
||||
"card": card,
|
||||
"x": cx,
|
||||
"y": cy,
|
||||
"size": base_sz,
|
||||
"under_tag": under_tag,
|
||||
}
|
||||
return None
|
||||
|
||||
def cancel(self):
|
||||
"""Räumt Timer und aktive Hervorhebung restlos ab."""
|
||||
self._cancel_timer()
|
||||
self._clear_drawn()
|
||||
self._active_target_id = None
|
||||
self._pending_info = None
|
||||
|
||||
def refresh_after_redraw(self):
|
||||
"""Stellt nach einem Hintergrund-Redraw (z. B. Uhr-Tick) die Hervorhebung sauber wieder her."""
|
||||
if self._active_target_id is None or self._last_pointer_xy is None:
|
||||
return
|
||||
if self._can_show_fn is not None and not self._can_show_fn():
|
||||
self.cancel()
|
||||
return
|
||||
px, py = self._last_pointer_xy
|
||||
info = self._normalize_probe(self._probe_fn(px, py))
|
||||
if info is None:
|
||||
self.cancel()
|
||||
return
|
||||
card: SolitaireCard = info["card"]
|
||||
target_id = (
|
||||
card.suit,
|
||||
card.rank,
|
||||
card.deck_id,
|
||||
info["x"],
|
||||
info["y"],
|
||||
info.get("under_tag"),
|
||||
)
|
||||
if target_id == self._active_target_id:
|
||||
self._render_zoom(info)
|
||||
else:
|
||||
self.cancel()
|
||||
|
||||
def _cancel_timer(self):
|
||||
if self._after_job is not None:
|
||||
try:
|
||||
self._root.after_cancel(self._after_job)
|
||||
except Exception:
|
||||
pass
|
||||
self._after_job = None
|
||||
|
||||
def _clear_drawn(self):
|
||||
try:
|
||||
if self._canvas.winfo_exists():
|
||||
self._canvas.delete(self.TAG)
|
||||
except Exception:
|
||||
pass
|
||||
self._zoom_photo_ref = None
|
||||
|
||||
def _on_leave(self, _event=None):
|
||||
self._last_pointer_xy = None
|
||||
self.cancel()
|
||||
|
||||
def _on_press_clear(self, _event=None):
|
||||
self.cancel()
|
||||
|
||||
def _on_motion(self, event):
|
||||
# Während Drag & Drop niemals einblenden
|
||||
if event.state & 0x0100:
|
||||
self.cancel()
|
||||
return
|
||||
|
||||
self._last_pointer_xy = (event.x, event.y)
|
||||
|
||||
if self._can_show_fn is not None and not self._can_show_fn():
|
||||
self.cancel()
|
||||
return
|
||||
|
||||
info = self._normalize_probe(self._probe_fn(event.x, event.y))
|
||||
if info is None:
|
||||
self.cancel()
|
||||
return
|
||||
|
||||
card: SolitaireCard = info["card"]
|
||||
if not card.face_up:
|
||||
self.cancel()
|
||||
return
|
||||
|
||||
target_id = (
|
||||
card.suit,
|
||||
card.rank,
|
||||
card.deck_id,
|
||||
info["x"],
|
||||
info["y"],
|
||||
info.get("under_tag"),
|
||||
)
|
||||
if target_id == self._active_target_id:
|
||||
return
|
||||
|
||||
self._cancel_timer()
|
||||
self._clear_drawn()
|
||||
self._active_target_id = None
|
||||
self._pending_info = info
|
||||
try:
|
||||
self._after_job = self._root.after(self.HOVER_DELAY_MS, self._show_pending)
|
||||
except Exception:
|
||||
self._after_job = None
|
||||
|
||||
def _show_pending(self):
|
||||
self._after_job = None
|
||||
if self._pending_info is None:
|
||||
return
|
||||
if self._can_show_fn is not None and not self._can_show_fn():
|
||||
self._pending_info = None
|
||||
return
|
||||
if not self._canvas.winfo_exists():
|
||||
return
|
||||
|
||||
info = self._pending_info
|
||||
card: SolitaireCard = info["card"]
|
||||
self._active_target_id = (
|
||||
card.suit,
|
||||
card.rank,
|
||||
card.deck_id,
|
||||
info["x"],
|
||||
info["y"],
|
||||
info.get("under_tag"),
|
||||
)
|
||||
self._render_zoom(info)
|
||||
|
||||
def _render_zoom(self, info: dict):
|
||||
self._clear_drawn()
|
||||
card: SolitaireCard = info["card"]
|
||||
card_x: int = info["x"]
|
||||
card_y: int = info["y"]
|
||||
bw, bh = info["size"]
|
||||
under_tag: str | None = info.get("under_tag")
|
||||
|
||||
if bw < 24 or bh < 32:
|
||||
return
|
||||
|
||||
zw = max(bw + 8, int(round(bw * self.ZOOM_FACTOR)))
|
||||
zh = max(bh + 12, int(round(bh * self.ZOOM_FACTOR)))
|
||||
|
||||
cw = max(1, self._canvas.winfo_width())
|
||||
ch = max(1, self._canvas.winfo_height())
|
||||
|
||||
# Horizontal mittig auf der Spalte, vertikal leicht nach oben gelupft ("Peek"),
|
||||
# damit Rang & Farbe über den aufliegenden Folgekarten klar hervortreten
|
||||
zx = card_x - (zw - bw) // 2
|
||||
if under_tag:
|
||||
zy = card_y - self.PEEK_UP_PX - (zh - bh) // 3
|
||||
else:
|
||||
zy = card_y - (zh - bh) // 2
|
||||
|
||||
pad = 6
|
||||
zx = max(pad, min(max(pad, cw - zw - pad), zx))
|
||||
zy = max(pad, min(max(pad, ch - zh - pad), zy))
|
||||
|
||||
photo = self._assets.get_card_photo(card.filename, size=(zw, zh))
|
||||
if photo is None:
|
||||
return
|
||||
self._zoom_photo_ref = photo
|
||||
|
||||
# 1. Dezenter dunkler Schlagschatten
|
||||
self._canvas.create_rectangle(
|
||||
zx + 4,
|
||||
zy + 5,
|
||||
zx + zw + 4,
|
||||
zy + zh + 5,
|
||||
fill="#07050c",
|
||||
outline="",
|
||||
tags=(self.TAG,),
|
||||
)
|
||||
# 2. Leicht vergrößerte Karte
|
||||
self._canvas.create_image(
|
||||
zx,
|
||||
zy,
|
||||
image=photo,
|
||||
anchor="nw",
|
||||
tags=(self.TAG,),
|
||||
)
|
||||
# 3. Goldener Hervorhebungs-Rahmen
|
||||
self._canvas.create_rectangle(
|
||||
zx - 2,
|
||||
zy - 2,
|
||||
zx + zw + 2,
|
||||
zy + zh + 2,
|
||||
outline=ACCENT_GOLD,
|
||||
width=2,
|
||||
tags=(self.TAG,),
|
||||
)
|
||||
self._canvas.create_rectangle(
|
||||
zx - 3,
|
||||
zy - 3,
|
||||
zx + zw + 3,
|
||||
zy + zh + 3,
|
||||
outline=BORDER_COLOR,
|
||||
width=1,
|
||||
tags=(self.TAG,),
|
||||
)
|
||||
|
||||
# Entscheidend: Liegen in der Kaskade weitere Karten auf dieser Karte,
|
||||
# sortieren wir die Hervorhebung direkt UNTER die nächste Karte ein!
|
||||
if under_tag and self._canvas.find_withtag(under_tag):
|
||||
try:
|
||||
self._canvas.tag_lower(self.TAG, under_tag)
|
||||
except tk.TclError:
|
||||
pass
|
||||
|
|
@ -15,12 +15,13 @@ from resources.code_res.game_constants import (
|
|||
)
|
||||
from view.widgets.goth_dropdown import GothDropdown
|
||||
from view.widgets.image_button import ImageButton
|
||||
from view.widgets.modal_veil import ModalVeil
|
||||
|
||||
|
||||
class SolitaireModalDialog(tk.Canvas):
|
||||
"""
|
||||
Rahmenloses Gothic-Modal auf background_vertical.jpg + box_big.png
|
||||
für Wiederaufnahme-, Aufgeben-, Deadlock- und Sieg-Dialoge (inkl. win.gif) in Solitaire.
|
||||
Rahmenloses Gothic-Modal (ohne eingebettetes GIF), das über allen UI-Elementen
|
||||
schwebt, das Spielfeld dahinter abdunkelt und alle übrigen Buttons sperrt.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
|
|
@ -30,12 +31,12 @@ class SolitaireModalDialog(tk.Canvas):
|
|||
body_txt: str,
|
||||
buttons: list[tuple[str, str, object, bool] | tuple[str, str, object]],
|
||||
is_danger: bool = False,
|
||||
gif_key: str = "",
|
||||
gif_key: str = "", # abwärtskompatibel ignoriert (Animation läuft vorab)
|
||||
):
|
||||
GothDropdown.close_any_open_popup()
|
||||
frames = ctx.assets.get_gif_frames(gif_key, size=(150, 84)) if gif_key else []
|
||||
_ = gif_key
|
||||
dlg_w = 590 if len(buttons) >= 3 else 500
|
||||
dlg_h = 355 if frames else 268
|
||||
dlg_h = 268
|
||||
|
||||
super().__init__(
|
||||
ctx.root,
|
||||
|
|
@ -49,28 +50,10 @@ class SolitaireModalDialog(tk.Canvas):
|
|||
self._dlg_w = dlg_w
|
||||
self._dlg_h = dlg_h
|
||||
self._photo_refs: list[ImageTk.PhotoImage] = []
|
||||
self._gif_job: str | None = None
|
||||
self._gif_item: int | None = None
|
||||
|
||||
self.place(relx=0.5, rely=0.52, anchor="center")
|
||||
self.bind("<Destroy>", self._on_destroy)
|
||||
self._build_scene(title_txt, body_txt, buttons, is_danger, frames)
|
||||
|
||||
def _on_destroy(self, event=None):
|
||||
if event is not None and event.widget is not self:
|
||||
return
|
||||
if self._gif_job is not None:
|
||||
try:
|
||||
self.after_cancel(self._gif_job)
|
||||
except Exception:
|
||||
pass
|
||||
self._gif_job = None
|
||||
|
||||
def _animate_gif(self, frames: list, idx: int):
|
||||
if not self.winfo_exists() or self._gif_item is None:
|
||||
return
|
||||
self.itemconfigure(self._gif_item, image=frames[idx % len(frames)])
|
||||
self._gif_job = self.after(90, self._animate_gif, frames, (idx + 1) % len(frames))
|
||||
self.place(relx=0.5, rely=0.5, anchor="center")
|
||||
self._build_scene(title_txt, body_txt, buttons, is_danger)
|
||||
self._veil = ModalVeil(ctx.root, ctx.assets, modal_widget=self)
|
||||
|
||||
def _build_scene(
|
||||
self,
|
||||
|
|
@ -78,7 +61,6 @@ class SolitaireModalDialog(tk.Canvas):
|
|||
body_txt: str,
|
||||
buttons: list,
|
||||
is_danger: bool,
|
||||
frames: list,
|
||||
):
|
||||
w, h = self._dlg_w, self._dlg_h
|
||||
assets = self.ctx.assets
|
||||
|
|
@ -94,15 +76,7 @@ class SolitaireModalDialog(tk.Canvas):
|
|||
self._photo_refs.append(box_ph)
|
||||
self.create_image(w // 2, h // 2, image=box_ph, anchor="center")
|
||||
|
||||
cur_y = 26
|
||||
if frames:
|
||||
self._gif_item = self.create_image(w // 2, cur_y + 42, image=frames[0], anchor="center")
|
||||
cur_y += 92
|
||||
if len(frames) > 1:
|
||||
self._animate_gif(frames, 0)
|
||||
else:
|
||||
cur_y = 38
|
||||
|
||||
cur_y = 38
|
||||
t_col = FONT_COLOR_STATUS_LOSS if is_danger else FONT_COLOR_TITLE_MAIN
|
||||
clean_body = str(body_txt or "").replace("•", "-")
|
||||
t_ph = assets.get_goth_text_photo(title_txt, FONT_SIZE_TITLE_LG - 4, t_col, max_width=w - 64)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,75 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# games/solitaire/base/solitaire_tap_prefs.py
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlite3
|
||||
|
||||
from models.database import Database
|
||||
|
||||
TAP_TO_MOVE_SETTING_KEY = "sol_single_tap_to_move"
|
||||
SINGLE_TAP_MAX_HOLD_SEC = 0.28
|
||||
|
||||
_single_tap_cache: bool | None = None
|
||||
|
||||
|
||||
def _get_user_db_path() -> str:
|
||||
for attr in ("USER_DB_PATH", "DB_PATH", "_user_db_path", "db_path"):
|
||||
val = getattr(Database, attr, None)
|
||||
if isinstance(val, str) and val.strip():
|
||||
return val
|
||||
return "user_data.db"
|
||||
|
||||
|
||||
def _load_persisted_flag(default: bool = False) -> bool:
|
||||
try:
|
||||
with sqlite3.connect(_get_user_db_path()) as conn:
|
||||
conn.execute(
|
||||
"CREATE TABLE IF NOT EXISTS app_settings ("
|
||||
"key TEXT PRIMARY KEY, "
|
||||
"val TEXT NOT NULL"
|
||||
")"
|
||||
)
|
||||
row = conn.execute(
|
||||
"SELECT val FROM app_settings WHERE key = ?",
|
||||
(TAP_TO_MOVE_SETTING_KEY,),
|
||||
).fetchone()
|
||||
if row is not None:
|
||||
return str(row[0]).strip().lower() in ("1", "true", "yes", "on")
|
||||
except Exception:
|
||||
pass
|
||||
return default
|
||||
|
||||
|
||||
def _save_persisted_flag(enabled: bool) -> None:
|
||||
try:
|
||||
with sqlite3.connect(_get_user_db_path()) as conn:
|
||||
conn.execute(
|
||||
"CREATE TABLE IF NOT EXISTS app_settings ("
|
||||
"key TEXT PRIMARY KEY, "
|
||||
"val TEXT NOT NULL"
|
||||
")"
|
||||
)
|
||||
conn.execute(
|
||||
"INSERT OR REPLACE INTO app_settings (key, val) VALUES (?, ?)",
|
||||
(TAP_TO_MOVE_SETTING_KEY, "1" if enabled else "0"),
|
||||
)
|
||||
conn.commit()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def is_single_tap_to_move_enabled() -> bool:
|
||||
"""Gibt zurück, ob 'Einfacher Klick zum Schieben' aktiv ist (mit In-Memory-Cache)."""
|
||||
global _single_tap_cache
|
||||
if _single_tap_cache is None:
|
||||
_single_tap_cache = _load_persisted_flag(default=False)
|
||||
return _single_tap_cache
|
||||
|
||||
|
||||
def set_single_tap_to_move_enabled(enabled: bool, persist: bool = True) -> None:
|
||||
"""Aktiviert/deaktiviert 'Einfacher Klick zum Schieben' und speichert es optional in user_data.db."""
|
||||
global _single_tap_cache
|
||||
state = bool(enabled)
|
||||
_single_tap_cache = state
|
||||
if persist:
|
||||
_save_persisted_flag(state)
|
||||
|
|
@ -6,10 +6,14 @@ import time
|
|||
import tkinter as tk
|
||||
|
||||
from games.solitaire.base.card_animator import CardFlightAnimator
|
||||
from games.solitaire.base.card_hover_zoom import CardHoverZoom
|
||||
from games.solitaire.base.solitaire_bottom_bar import SolitaireBottomBar
|
||||
from games.solitaire.base.solitaire_core import SolitaireCard
|
||||
from games.solitaire.base.solitaire_modal_dialog import SolitaireModalDialog
|
||||
from games.solitaire.base.solitaire_stats_view import SolitaireStatsView
|
||||
from games.solitaire.base.solitaire_tap_prefs import (
|
||||
SINGLE_TAP_MAX_HOLD_SEC,
|
||||
is_single_tap_to_move_enabled,
|
||||
)
|
||||
from games.solitaire.base.solitaire_theme import SolitaireTableBgRenderer
|
||||
from games.solitaire.freecell.models.freecell_engine import FreeCellEngine
|
||||
from models.database import Database
|
||||
|
|
@ -17,7 +21,6 @@ from models.progression import Progression
|
|||
from resources.code_res.game_constants import (
|
||||
ACCENT_GOLD,
|
||||
ACCENT_GOTH,
|
||||
BG_COLOR,
|
||||
BORDER_COLOR,
|
||||
CELL_BG,
|
||||
FONT_COLOR_TITLE_MAIN,
|
||||
|
|
@ -34,6 +37,7 @@ from resources.code_res.game_constants import (
|
|||
TABLE_BG,
|
||||
)
|
||||
from resources.code_res.i18n import t
|
||||
from view.widgets.endgame_fx_overlay import EndgameFxOverlay
|
||||
from view.widgets.image_button import ImageButton
|
||||
|
||||
GAME_FOLDER_ID = "solitaire/freecell"
|
||||
|
|
@ -87,6 +91,8 @@ class FreeCellTableView:
|
|||
self._bind_ids: list[tuple[str, str]] = []
|
||||
self._auto_running = False
|
||||
self.animator: CardFlightAnimator | None = None
|
||||
self.hover_zoom: CardHoverZoom | None = None
|
||||
self._fx_overlay: EndgameFxOverlay | None = None
|
||||
self._bg_renderer = SolitaireTableBgRenderer(self.ctx.assets.res)
|
||||
self._frame_bot_pad: int = 18
|
||||
self._canvas_ui_refs: list = []
|
||||
|
|
@ -120,6 +126,15 @@ class FreeCellTableView:
|
|||
d_mult = SOLITAIRE_DIFFICULTIES.get(self.difficulty, SOLITAIRE_DIFFICULTIES[1])["xp_mult"]
|
||||
return self.cfg["xp_mult"] * d_mult
|
||||
|
||||
def _is_ui_locked(self) -> bool:
|
||||
return (
|
||||
self.engine.won
|
||||
or self._game_concluded
|
||||
or self._auto_running
|
||||
or (self._modal_overlay is not None)
|
||||
or (self._fx_overlay is not None)
|
||||
)
|
||||
|
||||
def _canvas_alive(self) -> bool:
|
||||
if not self._alive:
|
||||
return False
|
||||
|
|
@ -128,6 +143,74 @@ class FreeCellTableView:
|
|||
except Exception:
|
||||
return False
|
||||
|
||||
def _can_show_hover_zoom(self) -> bool:
|
||||
if not self._canvas_alive():
|
||||
return False
|
||||
if self._is_ui_locked() or self._dragging or self._press_info is not None:
|
||||
return False
|
||||
if not self._window_active:
|
||||
return False
|
||||
if self.animator is not None and self.animator.is_active:
|
||||
return False
|
||||
return True
|
||||
|
||||
def _hover_card_probe(self, x: int, y: int) -> dict | None:
|
||||
cw, ch = self.card_size
|
||||
|
||||
for fc_i in range(4):
|
||||
fx = self._fc_x[fc_i]
|
||||
if fx <= x <= fx + cw and self._top_y <= y <= self._top_y + ch:
|
||||
c = self.engine.freecells[fc_i]
|
||||
if c is not None and c.face_up:
|
||||
return {
|
||||
"card": c,
|
||||
"x": fx,
|
||||
"y": self._top_y,
|
||||
"size": self.card_size,
|
||||
"under_tag": None,
|
||||
}
|
||||
return None
|
||||
|
||||
for f_idx in range(4):
|
||||
fx = self._found_x[f_idx]
|
||||
if fx <= x <= fx + cw and self._top_y <= y <= self._top_y + ch:
|
||||
pile = self.engine.foundations[f_idx]
|
||||
if pile and pile[-1].face_up:
|
||||
return {
|
||||
"card": pile[-1],
|
||||
"x": fx,
|
||||
"y": self._top_y,
|
||||
"size": self.card_size,
|
||||
"under_tag": None,
|
||||
}
|
||||
return None
|
||||
|
||||
for col_idx in range(8):
|
||||
rects = self._tableau_card_rects[col_idx]
|
||||
col_cards = self.engine.tableau[col_idx]
|
||||
for c_idx in range(len(rects) - 1, -1, -1):
|
||||
if c_idx >= len(col_cards):
|
||||
continue
|
||||
x1, y1, x2, y2 = rects[c_idx]
|
||||
if x1 <= x <= x2 and y1 <= y <= y2:
|
||||
card = col_cards[c_idx]
|
||||
if not card.face_up:
|
||||
return None
|
||||
next_tag = (
|
||||
f"fc_tab_{col_idx}_{c_idx + 1}"
|
||||
if (c_idx + 1) < len(col_cards)
|
||||
else None
|
||||
)
|
||||
return {
|
||||
"card": card,
|
||||
"x": x1,
|
||||
"y": y1,
|
||||
"size": self.card_size,
|
||||
"under_tag": next_tag,
|
||||
}
|
||||
|
||||
return None
|
||||
|
||||
def _play_table_music(self):
|
||||
for method_name in ("play_ingame_music", "play_table_music"):
|
||||
fn = getattr(self.ctx.sounds, method_name, None)
|
||||
|
|
@ -161,6 +244,11 @@ class FreeCellTableView:
|
|||
def _cleanup_timers(self):
|
||||
self._alive = False
|
||||
self.engine.pause_timer()
|
||||
if self._fx_overlay is not None:
|
||||
self._fx_overlay.cancel()
|
||||
self._fx_overlay = None
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
if self.animator is not None:
|
||||
self.animator.cancel()
|
||||
for job in (
|
||||
|
|
@ -207,7 +295,13 @@ class FreeCellTableView:
|
|||
except Exception:
|
||||
return
|
||||
|
||||
should_run = has_focus and (self._modal_overlay is None) and (not self.engine.won)
|
||||
should_run = (
|
||||
has_focus
|
||||
and (self._modal_overlay is None)
|
||||
and (self._fx_overlay is None)
|
||||
and (not self._game_concluded)
|
||||
and (not self.engine.won)
|
||||
)
|
||||
prev_paused = self.engine.is_timer_paused
|
||||
self._window_active = has_focus
|
||||
|
||||
|
|
@ -220,7 +314,7 @@ class FreeCellTableView:
|
|||
|
||||
if prev_paused != self.engine.is_timer_paused:
|
||||
self._update_hud_text()
|
||||
if self.animator is None or not self.animator.is_active:
|
||||
if (self.animator is None or not self.animator.is_active) and self._fx_overlay is None:
|
||||
self.redraw()
|
||||
|
||||
def _build_ui(self):
|
||||
|
|
@ -230,18 +324,14 @@ class FreeCellTableView:
|
|||
|
||||
self.topbar = self.ctx.build_game_topbar(
|
||||
self.ctx.root,
|
||||
t(GAME_TITLE_KEY),
|
||||
on_game_menu=self._back_to_game_menu,
|
||||
on_stats=self._open_stats,
|
||||
stats_endpoint=GAME_FOLDER_ID,
|
||||
stats_enabled=True,
|
||||
extra_right_text="",
|
||||
on_lang_refresh=self._refresh_lang,
|
||||
)
|
||||
|
||||
self.hud_var = tk.StringVar(value="")
|
||||
self.status_var = tk.StringVar(value="")
|
||||
|
||||
# Untere Gothic-Leiste mit box_gold_double Rahmen unter dem Spielfeld
|
||||
self.bottom_bar = SolitaireBottomBar(self.ctx.root, self.ctx, self.hud_var, self.status_var)
|
||||
self.bottom_bar.pack(fill="x", side="bottom", padx=14, pady=(4, 10))
|
||||
|
||||
|
|
@ -275,13 +365,21 @@ class FreeCellTableView:
|
|||
btn_norm, btn_purp, self._on_new_or_forfeit_clicked,
|
||||
sound_mgr=self.ctx.sounds, width=104, height=32, style="amethyst",
|
||||
)
|
||||
self.bottom_bar.set_buttons([
|
||||
self.undo_btn, self.undo_all_btn, self.hint_btn, self.auto_btn, self.new_btn
|
||||
])
|
||||
self.bottom_bar.set_buttons(
|
||||
[self.undo_btn, self.undo_all_btn, self.hint_btn, self.auto_btn],
|
||||
overflow_buttons=[self.new_btn],
|
||||
)
|
||||
|
||||
self.canvas = tk.Canvas(self.ctx.root, bg=TABLE_BG, bd=0, highlightthickness=0)
|
||||
self.canvas.pack(fill="both", expand=True, padx=14, pady=(4, 2))
|
||||
self.animator = CardFlightAnimator(self.ctx.root, self.canvas)
|
||||
self.hover_zoom = CardHoverZoom(
|
||||
self.ctx.root,
|
||||
self.canvas,
|
||||
self.ctx.assets,
|
||||
probe_fn=self._hover_card_probe,
|
||||
can_show_fn=self._can_show_hover_zoom,
|
||||
)
|
||||
|
||||
self.canvas.bind("<Configure>", self._on_canvas_configure)
|
||||
self.canvas.bind("<Destroy>", self._on_canvas_destroy)
|
||||
|
|
@ -301,6 +399,8 @@ class FreeCellTableView:
|
|||
self._update_hud_text()
|
||||
|
||||
def _on_undo_shortcut(self, _event=None):
|
||||
if self._fx_overlay is not None or self._game_concluded:
|
||||
return "break"
|
||||
if self.engine.can_undo and not self._auto_running:
|
||||
if self._modal_overlay is not None:
|
||||
self._close_active_modal()
|
||||
|
|
@ -309,6 +409,8 @@ class FreeCellTableView:
|
|||
return "break"
|
||||
|
||||
def _on_undo_all_shortcut(self, _event=None):
|
||||
if self._fx_overlay is not None or self._game_concluded:
|
||||
return "break"
|
||||
if self.engine.can_undo_all and not self._auto_running:
|
||||
if self._modal_overlay is not None:
|
||||
self._close_active_modal()
|
||||
|
|
@ -341,28 +443,8 @@ class FreeCellTableView:
|
|||
resume_state_json=state_json,
|
||||
)
|
||||
|
||||
def _open_stats(self):
|
||||
if self.animator:
|
||||
self.animator.flush()
|
||||
self.engine.pause_timer()
|
||||
self._save_progress()
|
||||
state_json = self.engine.to_json()
|
||||
self._cleanup_timers()
|
||||
SolitaireStatsView(
|
||||
self.ctx,
|
||||
game_folder=GAME_FOLDER_ID,
|
||||
game_title_key=GAME_TITLE_KEY,
|
||||
on_back=lambda: FreeCellTableView(
|
||||
self.ctx,
|
||||
variant_key=self.variant_key,
|
||||
difficulty=self.difficulty,
|
||||
on_back_to_menu=self.on_back_to_menu,
|
||||
resume_state_json=state_json,
|
||||
),
|
||||
).show()
|
||||
|
||||
def _back_to_game_menu(self):
|
||||
if self._auto_running:
|
||||
if self._auto_running or self._fx_overlay is not None:
|
||||
return
|
||||
if self.animator:
|
||||
self.animator.flush()
|
||||
|
|
@ -387,7 +469,12 @@ class FreeCellTableView:
|
|||
self._check_window_focus()
|
||||
self._update_hud_text()
|
||||
|
||||
if self.engine.has_timer_started and not self.engine.is_timer_paused and not self.engine.won:
|
||||
if (
|
||||
self.engine.has_timer_started
|
||||
and not self.engine.is_timer_paused
|
||||
and not self.engine.won
|
||||
and not self._game_concluded
|
||||
):
|
||||
self._checkpoint_ticks += 1
|
||||
if self._checkpoint_ticks >= self.CHECKPOINT_TICKS:
|
||||
self._checkpoint_ticks = 0
|
||||
|
|
@ -403,10 +490,13 @@ class FreeCellTableView:
|
|||
return
|
||||
try:
|
||||
elapsed_str = Database.format_seconds(self.engine.get_elapsed_seconds())
|
||||
paused_tag = t("sol_hud_paused_tag") if (self.engine.is_timer_paused and not self.engine.won) else ""
|
||||
paused_tag = (
|
||||
t("sol_hud_paused_tag")
|
||||
if (self.engine.is_timer_paused and not self.engine.won and not self._game_concluded)
|
||||
else ""
|
||||
)
|
||||
diff_label = t(f"sol_diff_short_{self.difficulty}")
|
||||
new_hud = t("sol_hud_stats", self.engine.score, self.engine.moves, elapsed_str, paused_tag, diff_label)
|
||||
# Nur schreiben, wenn sich der Text tatsächlich geändert hat!
|
||||
if self.hud_var.get() != new_hud:
|
||||
self.hud_var.set(new_hud)
|
||||
except Exception:
|
||||
|
|
@ -415,13 +505,17 @@ class FreeCellTableView:
|
|||
def _sync_buttons(self):
|
||||
if not self._canvas_alive():
|
||||
return
|
||||
locked = self.engine.won or self._auto_running or (self._modal_overlay is not None)
|
||||
locked = self._is_ui_locked()
|
||||
self.undo_btn.set_enabled((not locked) and self.engine.can_undo)
|
||||
self.undo_all_btn.set_enabled((not locked) and self.engine.can_undo_all)
|
||||
self.hint_btn.set_enabled(not locked)
|
||||
self.auto_btn.set_enabled((not locked) and self.engine.can_auto_complete())
|
||||
self.new_btn.set_enabled(not self._auto_running)
|
||||
new_lbl = t("sol_btn_forfeit") if (self.engine.moves > 0 and not self.engine.won) else t("sol_btn_new_deal")
|
||||
self.new_btn.set_enabled((not self._auto_running) and (self._fx_overlay is None) and (self._modal_overlay is None))
|
||||
new_lbl = (
|
||||
t("sol_btn_forfeit")
|
||||
if (self.engine.moves > 0 and not self.engine.won and not self._game_concluded)
|
||||
else t("sol_btn_new_deal")
|
||||
)
|
||||
prev_w = self.new_btn.pixel_width
|
||||
self.new_btn.set_text(new_lbl)
|
||||
if self.new_btn.pixel_width != prev_w:
|
||||
|
|
@ -488,6 +582,8 @@ class FreeCellTableView:
|
|||
duration_ms: int = 115,
|
||||
after_cb=None,
|
||||
) -> bool:
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
if self.animator:
|
||||
self.animator.flush()
|
||||
before_pos = self._snapshot_card_positions()
|
||||
|
|
@ -536,8 +632,10 @@ class FreeCellTableView:
|
|||
return True
|
||||
|
||||
def _on_canvas_configure(self, _event=None):
|
||||
if not self._canvas_alive():
|
||||
if not self._canvas_alive() or self._fx_overlay is not None:
|
||||
return
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
if self.animator:
|
||||
self.animator.flush()
|
||||
if self._resize_job is not None:
|
||||
|
|
@ -563,7 +661,7 @@ class FreeCellTableView:
|
|||
|
||||
def _recompute_and_draw(self):
|
||||
self._resize_job = None
|
||||
if not self._canvas_alive():
|
||||
if not self._canvas_alive() or self._fx_overlay is not None:
|
||||
return
|
||||
cw = max(680, self.canvas.winfo_width())
|
||||
ch = max(420, self.canvas.winfo_height())
|
||||
|
|
@ -662,9 +760,11 @@ class FreeCellTableView:
|
|||
):
|
||||
if not self._canvas_alive():
|
||||
return
|
||||
bg_ids = set(self.canvas.find_withtag("table_bg_slice"))
|
||||
keep_ids = set(self.canvas.find_withtag("table_bg_slice")) | set(
|
||||
self.canvas.find_withtag("modal_dim_veil")
|
||||
)
|
||||
for item_id in self.canvas.find_all():
|
||||
if item_id not in bg_ids:
|
||||
if item_id not in keep_ids:
|
||||
self.canvas.delete(item_id)
|
||||
self._canvas_ui_refs.clear()
|
||||
cw, ch = self.card_size
|
||||
|
|
@ -694,7 +794,6 @@ class FreeCellTableView:
|
|||
|
||||
hint = self._active_hint
|
||||
|
||||
# 1. Obere linke Hälfte: 4 Freie Zellen
|
||||
for fc_i in range(4):
|
||||
fx = self._fc_x[fc_i]
|
||||
fc_hl = ACCENT_GOTH if fc_i in valid_drag_fc else None
|
||||
|
|
@ -711,9 +810,8 @@ class FreeCellTableView:
|
|||
if c is not None and self._card_key(c) in hidden:
|
||||
c = None
|
||||
if c is not None:
|
||||
self._draw_card_at(c, fx, self._top_y, highlight_color=fc_hl)
|
||||
self._draw_card_at(c, fx, self._top_y, tags=(f"fc_cell_{fc_i}",), highlight_color=fc_hl)
|
||||
|
||||
# 2. Obere rechte Hälfte: 4 Foundations
|
||||
for f_idx, suit in enumerate(SUITS):
|
||||
fx = self._found_x[f_idx]
|
||||
sym = SUIT_SYMBOLS[suit]
|
||||
|
|
@ -728,9 +826,8 @@ class FreeCellTableView:
|
|||
pile = pile[:-1]
|
||||
pile = [c for c in pile if self._card_key(c) not in hidden]
|
||||
if pile:
|
||||
self._draw_card_at(pile[-1], fx, self._top_y, highlight_color=f_hl)
|
||||
self._draw_card_at(pile[-1], fx, self._top_y, tags=(f"fc_found_{f_idx}",), highlight_color=f_hl)
|
||||
|
||||
# 3. Untere Reihe: 8 Tableau-Spalten
|
||||
self._tableau_card_rects = [[] for _ in range(8)]
|
||||
|
||||
for col_idx in range(8):
|
||||
|
|
@ -765,16 +862,23 @@ class FreeCellTableView:
|
|||
elif hint.get("dst_col") == col_idx and is_last:
|
||||
c_hl = ACCENT_GOLD
|
||||
|
||||
self._draw_card_at(card, tx, cur_y, highlight_color=c_hl)
|
||||
self._draw_card_at(
|
||||
card,
|
||||
tx,
|
||||
cur_y,
|
||||
tags=(f"fc_tab_{col_idx}_{c_idx}",),
|
||||
highlight_color=c_hl,
|
||||
)
|
||||
next_y = ys[c_idx + 1] if not is_last else (cur_y + ch)
|
||||
self._tableau_card_rects[col_idx].append((tx, cur_y, tx + cw, next_y))
|
||||
|
||||
# Pause-Banner mit box_purple + Old London statt Standard-Rechteck
|
||||
if (
|
||||
self.engine.has_timer_started
|
||||
and not self._window_active
|
||||
and not self.engine.won
|
||||
and not self._game_concluded
|
||||
and self._modal_overlay is None
|
||||
and self._fx_overlay is None
|
||||
):
|
||||
p_ph = self.ctx.assets.get_goth_text_photo(
|
||||
t("sol_canvas_paused_banner"), FONT_SIZE_BODY, FONT_COLOR_TITLE_MAIN
|
||||
|
|
@ -787,6 +891,16 @@ class FreeCellTableView:
|
|||
self.canvas.create_image(pcx, pcy, image=box_ph, anchor="center")
|
||||
self.canvas.create_image(pcx, pcy, image=p_ph, anchor="center")
|
||||
|
||||
if self.canvas.find_withtag("modal_dim_veil"):
|
||||
self.canvas.tag_raise("modal_dim_veil")
|
||||
|
||||
if (
|
||||
self.hover_zoom is not None
|
||||
and exclude_source is None
|
||||
and not hidden
|
||||
):
|
||||
self.hover_zoom.refresh_after_redraw()
|
||||
|
||||
self._sync_buttons()
|
||||
|
||||
def _hit_test(self, x: int, y: int) -> dict | None:
|
||||
|
|
@ -839,7 +953,9 @@ class FreeCellTableView:
|
|||
return None
|
||||
|
||||
def _on_mouse_down(self, event):
|
||||
if self.engine.won or self._auto_running or self._modal_overlay is not None:
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
if self._is_ui_locked():
|
||||
return
|
||||
if self.animator and self.animator.is_active:
|
||||
self.animator.flush()
|
||||
|
|
@ -853,15 +969,18 @@ class FreeCellTableView:
|
|||
self.engine.start_timer_if_needed()
|
||||
self._update_hud_text()
|
||||
hit["start_xy"] = (event.x, event.y)
|
||||
hit["press_ts"] = time.monotonic()
|
||||
self._press_info = hit
|
||||
|
||||
def _on_mouse_move(self, event):
|
||||
if not self._press_info:
|
||||
if not self._press_info or self._fx_overlay is not None:
|
||||
return
|
||||
sx, sy = self._press_info["start_xy"]
|
||||
if not self._dragging:
|
||||
if abs(event.x - sx) < self.DRAG_THRESHOLD_PX and abs(event.y - sy) < self.DRAG_THRESHOLD_PX:
|
||||
return
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
self._dragging = True
|
||||
self._drag_last_xy = (sx, sy)
|
||||
self.redraw(exclude_source=self._press_info)
|
||||
|
|
@ -933,6 +1052,13 @@ class FreeCellTableView:
|
|||
|
||||
def _handle_click(self, info: dict):
|
||||
now = time.monotonic()
|
||||
if is_single_tap_to_move_enabled():
|
||||
hold_sec = now - info.get("press_ts", now)
|
||||
self._last_click_target = None
|
||||
if hold_sec <= SINGLE_TAP_MAX_HOLD_SEC:
|
||||
self._smart_auto_move(info)
|
||||
return
|
||||
|
||||
target_id = (info["zone"], info.get("col", -1), info.get("idx", -1))
|
||||
if self._last_click_target == target_id and (now - self._last_click_ts) <= self.DOUBLE_CLICK_SEC:
|
||||
self._last_click_target = None
|
||||
|
|
@ -942,7 +1068,9 @@ class FreeCellTableView:
|
|||
self._last_click_target = target_id
|
||||
|
||||
def _on_right_click(self, event):
|
||||
if self.engine.won or self._auto_running or self._modal_overlay is not None:
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
if self._is_ui_locked():
|
||||
return
|
||||
if self.animator and self.animator.is_active:
|
||||
self.animator.flush()
|
||||
|
|
@ -1089,13 +1217,13 @@ class FreeCellTableView:
|
|||
self._check_deadlock_and_prompt()
|
||||
|
||||
def _check_deadlock_and_prompt(self):
|
||||
if self.engine.won or self._auto_running or self._modal_overlay is not None:
|
||||
if self._is_ui_locked():
|
||||
return
|
||||
if not self.engine.has_any_meaningful_move():
|
||||
self._show_deadlock_modal()
|
||||
|
||||
def _on_undo(self):
|
||||
if self.engine.won or self._auto_running or self._modal_overlay is not None:
|
||||
if self._is_ui_locked():
|
||||
return
|
||||
self._clear_hint()
|
||||
|
||||
|
|
@ -1108,7 +1236,7 @@ class FreeCellTableView:
|
|||
self._run_animated_action(self.engine.undo, duration_ms=105, after_cb=finish_undo)
|
||||
|
||||
def _on_undo_all(self):
|
||||
if self.engine.won or self._auto_running or self._modal_overlay is not None:
|
||||
if self._is_ui_locked():
|
||||
return
|
||||
if self.animator:
|
||||
self.animator.flush()
|
||||
|
|
@ -1129,7 +1257,7 @@ class FreeCellTableView:
|
|||
self._active_hint = None
|
||||
|
||||
def _on_hint(self):
|
||||
if self.engine.won or self._auto_running or self._modal_overlay is not None:
|
||||
if self._is_ui_locked():
|
||||
return
|
||||
if self.animator:
|
||||
self.animator.flush()
|
||||
|
|
@ -1149,11 +1277,11 @@ class FreeCellTableView:
|
|||
def _expire_hint(self):
|
||||
self._hint_job = None
|
||||
self._active_hint = None
|
||||
if self._canvas_alive():
|
||||
if self._canvas_alive() and self._fx_overlay is None:
|
||||
self.redraw()
|
||||
|
||||
def _start_auto_complete(self):
|
||||
if not self.engine.can_auto_complete() or self._auto_running:
|
||||
if not self.engine.can_auto_complete() or self._is_ui_locked():
|
||||
return
|
||||
if self.animator:
|
||||
self.animator.flush()
|
||||
|
|
@ -1196,11 +1324,11 @@ class FreeCellTableView:
|
|||
self._save_progress()
|
||||
|
||||
def _on_new_or_forfeit_clicked(self):
|
||||
if self._auto_running or self._modal_overlay is not None:
|
||||
if self._auto_running or self._modal_overlay is not None or self._fx_overlay is not None:
|
||||
return
|
||||
if self.animator:
|
||||
self.animator.flush()
|
||||
if self.engine.won or self.engine.moves == 0:
|
||||
if self.engine.won or self._game_concluded or self.engine.moves == 0:
|
||||
self._game_concluded = False
|
||||
self.engine.new_game(difficulty=self.difficulty)
|
||||
self._save_progress()
|
||||
|
|
@ -1219,42 +1347,95 @@ class FreeCellTableView:
|
|||
return max(2, int(round(win_xp * SOLO_FORFEIT_XP_RATIO)))
|
||||
|
||||
def _execute_forfeit(self, penalty: int, go_menu: bool):
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
pid = self.ctx.profile["id"]
|
||||
prog = Database.get_game_progress(pid, GAME_FOLDER_ID)
|
||||
floor_xp = Progression.get_creator_spirit_v_floor_xp() if prog["ever_reached_deity"] else 0
|
||||
|
||||
self._game_concluded = True
|
||||
self.engine.pause_timer()
|
||||
dur = self.engine.get_elapsed_seconds()
|
||||
Database.delete_game_state(pid, GAME_FOLDER_ID)
|
||||
Database.record_game_result(
|
||||
pid,
|
||||
variant_key=self.variant_key,
|
||||
won=False,
|
||||
duration_sec=self.engine.get_elapsed_seconds(),
|
||||
duration_sec=dur,
|
||||
points_gained=0,
|
||||
)
|
||||
updated = Database.adjust_game_points(pid, GAME_FOLDER_ID, -penalty, min_floor_xp=floor_xp)
|
||||
deducted = max(0, prog["total_points"] - updated["total_points"])
|
||||
self.topbar.level_label.configure(text="")
|
||||
self.topbar.update_level_xp_text()
|
||||
self.ctx.sounds.play("lose")
|
||||
|
||||
if self._modal_overlay is not None:
|
||||
self._modal_overlay.destroy()
|
||||
try:
|
||||
self._modal_overlay.destroy()
|
||||
except Exception:
|
||||
pass
|
||||
self._modal_overlay = None
|
||||
|
||||
if go_menu:
|
||||
self._cleanup_timers()
|
||||
if callable(self.on_back_to_menu):
|
||||
self.on_back_to_menu(t("sol_loss_xp", deducted), False)
|
||||
else:
|
||||
self._sync_buttons()
|
||||
|
||||
def _after_lose_fx():
|
||||
self._fx_overlay = None
|
||||
if not self._canvas_alive():
|
||||
return
|
||||
self._show_defeat_result_modal(deducted, dur, prefer_menu=go_menu)
|
||||
|
||||
self._fx_overlay = EndgameFxOverlay.play(
|
||||
self.ctx.root,
|
||||
self.ctx.assets,
|
||||
outcome="lose",
|
||||
on_continue=_after_lose_fx,
|
||||
target_canvas=self.canvas,
|
||||
)
|
||||
self._sync_buttons()
|
||||
|
||||
def _show_defeat_result_modal(self, deducted: int, dur: float, prefer_menu: bool):
|
||||
lines = [
|
||||
t(
|
||||
"sol_win_summary",
|
||||
self.engine.score,
|
||||
self.engine.moves,
|
||||
Database.format_seconds(dur),
|
||||
t(f"sol_diff_short_{self.difficulty}"),
|
||||
),
|
||||
t("sol_loss_xp", deducted),
|
||||
]
|
||||
|
||||
def play_again():
|
||||
self._close_active_modal()
|
||||
self._game_concluded = False
|
||||
self.engine.new_game(difficulty=self.difficulty)
|
||||
self._check_window_focus()
|
||||
self._save_progress()
|
||||
self.status_var.set(t("sol_loss_xp", deducted))
|
||||
self.status_var.set("")
|
||||
self.ctx.sounds.play("deal")
|
||||
self.redraw()
|
||||
|
||||
def to_menu():
|
||||
self._close_active_modal()
|
||||
self._cleanup_timers()
|
||||
if callable(self.on_back_to_menu):
|
||||
self.on_back_to_menu(t("sol_loss_xp", deducted), False)
|
||||
|
||||
self._modal_overlay = SolitaireModalDialog(
|
||||
self.ctx,
|
||||
title_txt=t("sol_forfeit_title"),
|
||||
body_txt="\n".join(lines),
|
||||
is_danger=True,
|
||||
buttons=[
|
||||
(t("sol_play_again_btn"), "amethyst" if prefer_menu else "fire", play_again),
|
||||
(t("bj_popup_to_menu_btn"), "fire" if prefer_menu else "amethyst", to_menu),
|
||||
],
|
||||
)
|
||||
self._sync_buttons()
|
||||
|
||||
def _show_deadlock_modal(self):
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
self.engine.pause_timer()
|
||||
self._save_progress()
|
||||
penalty = self._compute_forfeit_penalty()
|
||||
|
|
@ -1281,6 +1462,8 @@ class FreeCellTableView:
|
|||
self._sync_buttons()
|
||||
|
||||
def _show_forfeit_modal(self):
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
self.engine.pause_timer()
|
||||
self._save_progress()
|
||||
penalty = self._compute_forfeit_penalty()
|
||||
|
|
@ -1299,7 +1482,10 @@ class FreeCellTableView:
|
|||
self._sync_buttons()
|
||||
|
||||
def _handle_victory(self):
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
self._game_concluded = True
|
||||
self.engine.pause_timer()
|
||||
pid = self.ctx.profile["id"]
|
||||
Database.delete_game_state(pid, GAME_FOLDER_ID)
|
||||
dur = self.engine.get_elapsed_seconds()
|
||||
|
|
@ -1320,9 +1506,24 @@ class FreeCellTableView:
|
|||
duration_sec=dur,
|
||||
points_gained=xp_earned,
|
||||
)
|
||||
self.topbar.level_label.configure(text="")
|
||||
self.topbar.update_level_xp_text()
|
||||
self.ctx.sounds.play("win")
|
||||
self._show_victory_modal(xp_earned, old_lvl, new_lvl, dur)
|
||||
self._sync_buttons()
|
||||
|
||||
def _after_win_fx():
|
||||
self._fx_overlay = None
|
||||
if not self._canvas_alive():
|
||||
return
|
||||
self._show_victory_modal(xp_earned, old_lvl, new_lvl, dur)
|
||||
|
||||
self._fx_overlay = EndgameFxOverlay.play(
|
||||
self.ctx.root,
|
||||
self.ctx.assets,
|
||||
outcome="win",
|
||||
on_continue=_after_win_fx,
|
||||
target_canvas=self.canvas,
|
||||
)
|
||||
self._sync_buttons()
|
||||
|
||||
def _show_victory_modal(self, xp_earned: int, old_lvl: int, new_lvl: int, dur: float):
|
||||
lines = [
|
||||
|
|
@ -1349,6 +1550,7 @@ class FreeCellTableView:
|
|||
self.redraw()
|
||||
|
||||
def to_menu():
|
||||
self._close_active_modal()
|
||||
self._cleanup_timers()
|
||||
if callable(self.on_back_to_menu):
|
||||
self.on_back_to_menu()
|
||||
|
|
@ -1357,7 +1559,6 @@ class FreeCellTableView:
|
|||
self.ctx,
|
||||
title_txt=t("sol_win_title"),
|
||||
body_txt="\n".join(lines),
|
||||
gif_key="win_gif",
|
||||
buttons=[
|
||||
(t("sol_play_again_btn"), "fire", play_again),
|
||||
(t("bj_popup_to_menu_btn"), "amethyst", to_menu),
|
||||
|
|
|
|||
|
|
@ -6,10 +6,14 @@ import time
|
|||
import tkinter as tk
|
||||
|
||||
from games.solitaire.base.card_animator import CardFlightAnimator
|
||||
from games.solitaire.base.card_hover_zoom import CardHoverZoom
|
||||
from games.solitaire.base.solitaire_bottom_bar import SolitaireBottomBar
|
||||
from games.solitaire.base.solitaire_core import SolitaireCard
|
||||
from games.solitaire.base.solitaire_modal_dialog import SolitaireModalDialog
|
||||
from games.solitaire.base.solitaire_stats_view import SolitaireStatsView
|
||||
from games.solitaire.base.solitaire_tap_prefs import (
|
||||
SINGLE_TAP_MAX_HOLD_SEC,
|
||||
is_single_tap_to_move_enabled,
|
||||
)
|
||||
from games.solitaire.base.solitaire_theme import SolitaireTableBgRenderer
|
||||
from games.solitaire.klondike.models.klondike_engine import KlondikeEngine
|
||||
from models.database import Database
|
||||
|
|
@ -17,7 +21,6 @@ from models.progression import Progression
|
|||
from resources.code_res.game_constants import (
|
||||
ACCENT_GOLD,
|
||||
ACCENT_GOTH,
|
||||
BG_COLOR,
|
||||
BORDER_COLOR,
|
||||
CELL_BG,
|
||||
ERROR_FG,
|
||||
|
|
@ -34,6 +37,7 @@ from resources.code_res.game_constants import (
|
|||
TABLE_BG,
|
||||
)
|
||||
from resources.code_res.i18n import t
|
||||
from view.widgets.endgame_fx_overlay import EndgameFxOverlay
|
||||
from view.widgets.image_button import ImageButton
|
||||
|
||||
GAME_FOLDER_ID = "solitaire/klondike"
|
||||
|
|
@ -93,6 +97,8 @@ class KlondikeTableView:
|
|||
self._bind_ids: list[tuple[str, str]] = []
|
||||
self._auto_running = False
|
||||
self.animator: CardFlightAnimator | None = None
|
||||
self.hover_zoom: CardHoverZoom | None = None
|
||||
self._fx_overlay: EndgameFxOverlay | None = None
|
||||
self._bg_renderer = SolitaireTableBgRenderer(self.ctx.assets.res)
|
||||
self._frame_bot_pad: int = 18
|
||||
self._canvas_ui_refs: list = []
|
||||
|
|
@ -104,6 +110,7 @@ class KlondikeTableView:
|
|||
self._tableau_y: int = 188
|
||||
self._tableau_card_rects: list[list[tuple[int, int, int, int]]] = [[] for _ in range(7)]
|
||||
self._waste_top_rect: tuple[int, int, int, int] | None = None
|
||||
self._waste_shown_entries: list[tuple[SolitaireCard, int, int, int, int, str | None]] = []
|
||||
|
||||
self._press_info: dict | None = None
|
||||
self._dragging: bool = False
|
||||
|
|
@ -125,6 +132,15 @@ class KlondikeTableView:
|
|||
d_mult = SOLITAIRE_DIFFICULTIES.get(self.difficulty, SOLITAIRE_DIFFICULTIES[1])["xp_mult"]
|
||||
return self.cfg["xp_mult"] * d_mult
|
||||
|
||||
def _is_ui_locked(self) -> bool:
|
||||
return (
|
||||
self.engine.won
|
||||
or self._game_concluded
|
||||
or self._auto_running
|
||||
or (self._modal_overlay is not None)
|
||||
or (self._fx_overlay is not None)
|
||||
)
|
||||
|
||||
def _canvas_alive(self) -> bool:
|
||||
if not self._alive:
|
||||
return False
|
||||
|
|
@ -133,6 +149,75 @@ class KlondikeTableView:
|
|||
except Exception:
|
||||
return False
|
||||
|
||||
def _can_show_hover_zoom(self) -> bool:
|
||||
if not self._canvas_alive():
|
||||
return False
|
||||
if self._is_ui_locked() or self._dragging or self._press_info is not None:
|
||||
return False
|
||||
if not self._window_active:
|
||||
return False
|
||||
if self.animator is not None and self.animator.is_active:
|
||||
return False
|
||||
return True
|
||||
|
||||
def _hover_card_probe(self, x: int, y: int) -> dict | None:
|
||||
cw, ch = self.card_size
|
||||
|
||||
# 1. Sichtbarer Waste-Fächer (von oben nach unten prüfen, damit 3er-Fächer einzeln greifen)
|
||||
for w_card, x1, y1, x2, y2, next_tag in reversed(self._waste_shown_entries):
|
||||
if x1 <= x <= x2 and y1 <= y <= y2:
|
||||
if w_card.face_up:
|
||||
return {
|
||||
"card": w_card,
|
||||
"x": x1,
|
||||
"y": y1,
|
||||
"size": self.card_size,
|
||||
"under_tag": next_tag,
|
||||
}
|
||||
return None
|
||||
|
||||
# 2. Foundations (Spalten 3..6)
|
||||
for f_idx in range(4):
|
||||
fx = self._col_x[3 + f_idx]
|
||||
if fx <= x <= fx + cw and self._top_y <= y <= self._top_y + ch:
|
||||
pile = self.engine.foundations[f_idx]
|
||||
if pile and pile[-1].face_up:
|
||||
return {
|
||||
"card": pile[-1],
|
||||
"x": fx,
|
||||
"y": self._top_y,
|
||||
"size": self.card_size,
|
||||
"under_tag": None,
|
||||
}
|
||||
return None
|
||||
|
||||
# 3. Tableau-Spalten (nur aufgedeckte Karten, verdeckte Karten ignorieren)
|
||||
for col_idx in range(7):
|
||||
rects = self._tableau_card_rects[col_idx]
|
||||
col_cards = self.engine.tableau[col_idx]
|
||||
for c_idx in range(len(rects) - 1, -1, -1):
|
||||
if c_idx >= len(col_cards):
|
||||
continue
|
||||
x1, y1, x2, y2 = rects[c_idx]
|
||||
if x1 <= x <= x2 and y1 <= y <= y2:
|
||||
card = col_cards[c_idx]
|
||||
if not card.face_up:
|
||||
return None
|
||||
next_tag = (
|
||||
f"kl_tab_{col_idx}_{c_idx + 1}"
|
||||
if (c_idx + 1) < len(col_cards)
|
||||
else None
|
||||
)
|
||||
return {
|
||||
"card": card,
|
||||
"x": x1,
|
||||
"y": y1,
|
||||
"size": self.card_size,
|
||||
"under_tag": next_tag,
|
||||
}
|
||||
|
||||
return None
|
||||
|
||||
def _play_table_music(self):
|
||||
for method_name in ("play_ingame_music", "play_table_music"):
|
||||
fn = getattr(self.ctx.sounds, method_name, None)
|
||||
|
|
@ -166,6 +251,11 @@ class KlondikeTableView:
|
|||
def _cleanup_timers(self):
|
||||
self._alive = False
|
||||
self.engine.pause_timer()
|
||||
if self._fx_overlay is not None:
|
||||
self._fx_overlay.cancel()
|
||||
self._fx_overlay = None
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
if self.animator is not None:
|
||||
self.animator.cancel()
|
||||
for job in (
|
||||
|
|
@ -212,7 +302,13 @@ class KlondikeTableView:
|
|||
except Exception:
|
||||
return
|
||||
|
||||
should_run = has_focus and (self._modal_overlay is None) and (not self.engine.won)
|
||||
should_run = (
|
||||
has_focus
|
||||
and (self._modal_overlay is None)
|
||||
and (self._fx_overlay is None)
|
||||
and (not self._game_concluded)
|
||||
and (not self.engine.won)
|
||||
)
|
||||
prev_paused = self.engine.is_timer_paused
|
||||
self._window_active = has_focus
|
||||
|
||||
|
|
@ -225,7 +321,7 @@ class KlondikeTableView:
|
|||
|
||||
if prev_paused != self.engine.is_timer_paused:
|
||||
self._update_hud_text()
|
||||
if self.animator is None or not self.animator.is_active:
|
||||
if (self.animator is None or not self.animator.is_active) and self._fx_overlay is None:
|
||||
self.redraw()
|
||||
|
||||
def _build_ui(self):
|
||||
|
|
@ -235,18 +331,14 @@ class KlondikeTableView:
|
|||
|
||||
self.topbar = self.ctx.build_game_topbar(
|
||||
self.ctx.root,
|
||||
t(GAME_TITLE_KEY),
|
||||
on_game_menu=self._back_to_game_menu,
|
||||
on_stats=self._open_stats,
|
||||
stats_endpoint=GAME_FOLDER_ID,
|
||||
stats_enabled=True,
|
||||
extra_right_text="",
|
||||
on_lang_refresh=self._refresh_lang,
|
||||
)
|
||||
|
||||
self.hud_var = tk.StringVar(value="")
|
||||
self.status_var = tk.StringVar(value="")
|
||||
|
||||
# Untere Gothic-Leiste mit box_gold_double Rahmen unter dem Spielfeld
|
||||
self.bottom_bar = SolitaireBottomBar(self.ctx.root, self.ctx, self.hud_var, self.status_var)
|
||||
self.bottom_bar.pack(fill="x", side="bottom", padx=14, pady=(4, 10))
|
||||
|
||||
|
|
@ -280,13 +372,21 @@ class KlondikeTableView:
|
|||
btn_norm, btn_purp, self._on_new_or_forfeit_clicked,
|
||||
sound_mgr=self.ctx.sounds, width=104, height=32, style="amethyst",
|
||||
)
|
||||
self.bottom_bar.set_buttons([
|
||||
self.undo_btn, self.undo_all_btn, self.hint_btn, self.auto_btn, self.new_btn
|
||||
])
|
||||
self.bottom_bar.set_buttons(
|
||||
[self.undo_btn, self.undo_all_btn, self.hint_btn, self.auto_btn],
|
||||
overflow_buttons=[self.new_btn],
|
||||
)
|
||||
|
||||
self.canvas = tk.Canvas(self.ctx.root, bg=TABLE_BG, bd=0, highlightthickness=0)
|
||||
self.canvas.pack(fill="both", expand=True, padx=14, pady=(4, 2))
|
||||
self.animator = CardFlightAnimator(self.ctx.root, self.canvas)
|
||||
self.hover_zoom = CardHoverZoom(
|
||||
self.ctx.root,
|
||||
self.canvas,
|
||||
self.ctx.assets,
|
||||
probe_fn=self._hover_card_probe,
|
||||
can_show_fn=self._can_show_hover_zoom,
|
||||
)
|
||||
|
||||
self.canvas.bind("<Configure>", self._on_canvas_configure)
|
||||
self.canvas.bind("<Destroy>", self._on_canvas_destroy)
|
||||
|
|
@ -306,6 +406,8 @@ class KlondikeTableView:
|
|||
self._update_hud_text()
|
||||
|
||||
def _on_undo_shortcut(self, _event=None):
|
||||
if self._fx_overlay is not None or self._game_concluded:
|
||||
return "break"
|
||||
if self.engine.can_undo and not self._auto_running:
|
||||
if self._modal_overlay is not None:
|
||||
self._close_active_modal()
|
||||
|
|
@ -314,6 +416,8 @@ class KlondikeTableView:
|
|||
return "break"
|
||||
|
||||
def _on_undo_all_shortcut(self, _event=None):
|
||||
if self._fx_overlay is not None or self._game_concluded:
|
||||
return "break"
|
||||
if self.engine.can_undo_all and not self._auto_running:
|
||||
if self._modal_overlay is not None:
|
||||
self._close_active_modal()
|
||||
|
|
@ -346,30 +450,8 @@ class KlondikeTableView:
|
|||
resume_state_json=state_json,
|
||||
)
|
||||
|
||||
def _open_stats(self):
|
||||
if self.animator:
|
||||
self.animator.flush()
|
||||
self.engine.pause_timer()
|
||||
self._save_progress()
|
||||
state_json = self.engine.to_json()
|
||||
variants = Database.get_variants_for_filter(GAME_FOLDER_ID)
|
||||
cur_vid = next((v["id"] for v in variants if v["variant_key"] == self.variant_key), None)
|
||||
self._cleanup_timers()
|
||||
SolitaireStatsView(
|
||||
self.ctx,
|
||||
game_folder=GAME_FOLDER_ID,
|
||||
game_title_key=GAME_TITLE_KEY,
|
||||
on_back=lambda: KlondikeTableView(
|
||||
self.ctx,
|
||||
variant_key=self.variant_key,
|
||||
difficulty=self.difficulty,
|
||||
on_back_to_menu=self.on_back_to_menu,
|
||||
resume_state_json=state_json,
|
||||
),
|
||||
).show(preselect_variant_id=cur_vid)
|
||||
|
||||
def _back_to_game_menu(self):
|
||||
if self._auto_running:
|
||||
if self._auto_running or self._fx_overlay is not None:
|
||||
return
|
||||
if self.animator:
|
||||
self.animator.flush()
|
||||
|
|
@ -394,7 +476,12 @@ class KlondikeTableView:
|
|||
self._check_window_focus()
|
||||
self._update_hud_text()
|
||||
|
||||
if self.engine.has_timer_started and not self.engine.is_timer_paused and not self.engine.won:
|
||||
if (
|
||||
self.engine.has_timer_started
|
||||
and not self.engine.is_timer_paused
|
||||
and not self.engine.won
|
||||
and not self._game_concluded
|
||||
):
|
||||
self._checkpoint_ticks += 1
|
||||
if self._checkpoint_ticks >= self.CHECKPOINT_TICKS:
|
||||
self._checkpoint_ticks = 0
|
||||
|
|
@ -410,10 +497,13 @@ class KlondikeTableView:
|
|||
return
|
||||
try:
|
||||
elapsed_str = Database.format_seconds(self.engine.get_elapsed_seconds())
|
||||
paused_tag = t("sol_hud_paused_tag") if (self.engine.is_timer_paused and not self.engine.won) else ""
|
||||
paused_tag = (
|
||||
t("sol_hud_paused_tag")
|
||||
if (self.engine.is_timer_paused and not self.engine.won and not self._game_concluded)
|
||||
else ""
|
||||
)
|
||||
diff_label = t(f"sol_diff_short_{self.difficulty}")
|
||||
new_hud = t("sol_hud_stats", self.engine.score, self.engine.moves, elapsed_str, paused_tag, diff_label)
|
||||
# Nur schreiben, wenn sich der Text tatsächlich geändert hat!
|
||||
if self.hud_var.get() != new_hud:
|
||||
self.hud_var.set(new_hud)
|
||||
except Exception:
|
||||
|
|
@ -422,13 +512,17 @@ class KlondikeTableView:
|
|||
def _sync_buttons(self):
|
||||
if not self._canvas_alive():
|
||||
return
|
||||
locked = self.engine.won or self._auto_running or (self._modal_overlay is not None)
|
||||
locked = self._is_ui_locked()
|
||||
self.undo_btn.set_enabled((not locked) and self.engine.can_undo)
|
||||
self.undo_all_btn.set_enabled((not locked) and self.engine.can_undo_all)
|
||||
self.hint_btn.set_enabled(not locked)
|
||||
self.auto_btn.set_enabled((not locked) and self.engine.can_auto_complete())
|
||||
self.new_btn.set_enabled(not self._auto_running)
|
||||
new_lbl = t("sol_btn_forfeit") if (self.engine.moves > 0 and not self.engine.won) else t("sol_btn_new_deal")
|
||||
self.new_btn.set_enabled((not self._auto_running) and (self._fx_overlay is None) and (self._modal_overlay is None))
|
||||
new_lbl = (
|
||||
t("sol_btn_forfeit")
|
||||
if (self.engine.moves > 0 and not self.engine.won and not self._game_concluded)
|
||||
else t("sol_btn_new_deal")
|
||||
)
|
||||
prev_w = self.new_btn.pixel_width
|
||||
self.new_btn.set_text(new_lbl)
|
||||
if self.new_btn.pixel_width != prev_w:
|
||||
|
|
@ -523,6 +617,8 @@ class KlondikeTableView:
|
|||
duration_ms: int = 115,
|
||||
after_cb=None,
|
||||
) -> bool:
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
if self.animator:
|
||||
self.animator.flush()
|
||||
before_pos = self._snapshot_card_positions()
|
||||
|
|
@ -571,8 +667,10 @@ class KlondikeTableView:
|
|||
return True
|
||||
|
||||
def _on_canvas_configure(self, _event=None):
|
||||
if not self._canvas_alive():
|
||||
if not self._canvas_alive() or self._fx_overlay is not None:
|
||||
return
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
if self.animator:
|
||||
self.animator.flush()
|
||||
if self._resize_job is not None:
|
||||
|
|
@ -598,7 +696,7 @@ class KlondikeTableView:
|
|||
|
||||
def _recompute_and_draw(self):
|
||||
self._resize_job = None
|
||||
if not self._canvas_alive():
|
||||
if not self._canvas_alive() or self._fx_overlay is not None:
|
||||
return
|
||||
cw = max(640, self.canvas.winfo_width())
|
||||
ch = max(420, self.canvas.winfo_height())
|
||||
|
|
@ -707,9 +805,11 @@ class KlondikeTableView:
|
|||
):
|
||||
if not self._canvas_alive():
|
||||
return
|
||||
bg_ids = set(self.canvas.find_withtag("table_bg_slice"))
|
||||
keep_ids = set(self.canvas.find_withtag("table_bg_slice")) | set(
|
||||
self.canvas.find_withtag("modal_dim_veil")
|
||||
)
|
||||
for item_id in self.canvas.find_all():
|
||||
if item_id not in bg_ids:
|
||||
if item_id not in keep_ids:
|
||||
self.canvas.delete(item_id)
|
||||
self._canvas_ui_refs.clear()
|
||||
cw, ch = self.card_size
|
||||
|
|
@ -751,7 +851,7 @@ class KlondikeTableView:
|
|||
)
|
||||
|
||||
if vis_stock:
|
||||
self._draw_card_at(vis_stock[-1], sx, self._top_y, highlight_color=stock_hl)
|
||||
self._draw_card_at(vis_stock[-1], sx, self._top_y, tags=("kl_stock",), highlight_color=stock_hl)
|
||||
cycles_left = max(0, self.engine.MAX_STAGNANT_CYCLES - self.engine.stagnant_cycles)
|
||||
if self.engine.redeal_limit is not None:
|
||||
rd_left = max(0, self.engine.redeal_limit - self.engine.redeals_used)
|
||||
|
|
@ -766,7 +866,7 @@ class KlondikeTableView:
|
|||
fill=ACCENT_GOLD,
|
||||
)
|
||||
|
||||
# 2. Waste (Spalte 1)
|
||||
# 2. Waste (Spalte 1) inkl. Z-Order-Tags für den 3er-Fächer
|
||||
wx = self._col_x[1]
|
||||
self._draw_slot(wx, self._top_y)
|
||||
waste_cards = list(self.engine.waste)
|
||||
|
|
@ -775,6 +875,7 @@ class KlondikeTableView:
|
|||
waste_cards = [c for c in waste_cards if self._card_key(c) not in hidden]
|
||||
|
||||
self._waste_top_rect = None
|
||||
self._waste_shown_entries = []
|
||||
if waste_cards:
|
||||
visible_n = min(3, len(waste_cards)) if self.engine.draw_count == 3 else 1
|
||||
shown = waste_cards[-visible_n:]
|
||||
|
|
@ -787,7 +888,13 @@ class KlondikeTableView:
|
|||
if (is_top and hint and hint.get("type") in ("waste_to_foundation", "waste_to_tableau"))
|
||||
else None
|
||||
)
|
||||
self._draw_card_at(w_card, cx, self._top_y, highlight_color=w_hl)
|
||||
w_tag = f"kl_waste_{idx}"
|
||||
next_w_tag = f"kl_waste_{idx + 1}" if not is_top else None
|
||||
self._draw_card_at(w_card, cx, self._top_y, tags=(w_tag,), highlight_color=w_hl)
|
||||
hit_x2 = (cx + cw) if is_top else (cx + fan_dx)
|
||||
self._waste_shown_entries.append(
|
||||
(w_card, cx, self._top_y, hit_x2, self._top_y + ch, next_w_tag)
|
||||
)
|
||||
if is_top:
|
||||
self._waste_top_rect = (cx, self._top_y, cx + cw, self._top_y + ch)
|
||||
|
||||
|
|
@ -808,9 +915,11 @@ class KlondikeTableView:
|
|||
f_pile = f_pile[:-1]
|
||||
f_pile = [c for c in f_pile if self._card_key(c) not in hidden]
|
||||
if f_pile:
|
||||
self._draw_card_at(f_pile[-1], fx, self._top_y, highlight_color=f_hl)
|
||||
self._draw_card_at(
|
||||
f_pile[-1], fx, self._top_y, tags=(f"kl_found_{f_idx}",), highlight_color=f_hl
|
||||
)
|
||||
|
||||
# 4. Tableau (Spalten 0..6)
|
||||
# 4. Tableau (Spalten 0..6) mit Z-Order-Tags pro Karte
|
||||
self._tableau_card_rects = [[] for _ in range(7)]
|
||||
|
||||
for col_idx in range(7):
|
||||
|
|
@ -845,7 +954,13 @@ class KlondikeTableView:
|
|||
elif hint.get("dst_col") == col_idx and is_last:
|
||||
c_hl = ACCENT_GOLD
|
||||
|
||||
self._draw_card_at(card, tx, cur_y, highlight_color=c_hl)
|
||||
self._draw_card_at(
|
||||
card,
|
||||
tx,
|
||||
cur_y,
|
||||
tags=(f"kl_tab_{col_idx}_{c_idx}",),
|
||||
highlight_color=c_hl,
|
||||
)
|
||||
next_y = ys[c_idx + 1] if not is_last else (cur_y + ch)
|
||||
self._tableau_card_rects[col_idx].append((tx, cur_y, tx + cw, next_y))
|
||||
|
||||
|
|
@ -854,7 +969,9 @@ class KlondikeTableView:
|
|||
self.engine.has_timer_started
|
||||
and not self._window_active
|
||||
and not self.engine.won
|
||||
and not self._game_concluded
|
||||
and self._modal_overlay is None
|
||||
and self._fx_overlay is None
|
||||
):
|
||||
p_ph = self.ctx.assets.get_goth_text_photo(
|
||||
t("sol_canvas_paused_banner"), FONT_SIZE_BODY, FONT_COLOR_TITLE_MAIN
|
||||
|
|
@ -867,6 +984,16 @@ class KlondikeTableView:
|
|||
self.canvas.create_image(pcx, pcy, image=box_ph, anchor="center")
|
||||
self.canvas.create_image(pcx, pcy, image=p_ph, anchor="center")
|
||||
|
||||
if self.canvas.find_withtag("modal_dim_veil"):
|
||||
self.canvas.tag_raise("modal_dim_veil")
|
||||
|
||||
if (
|
||||
self.hover_zoom is not None
|
||||
and exclude_source is None
|
||||
and not hidden
|
||||
):
|
||||
self.hover_zoom.refresh_after_redraw()
|
||||
|
||||
self._sync_buttons()
|
||||
|
||||
def _hit_test(self, x: int, y: int) -> dict | None:
|
||||
|
|
@ -919,7 +1046,9 @@ class KlondikeTableView:
|
|||
return None
|
||||
|
||||
def _on_mouse_down(self, event):
|
||||
if self.engine.won or self._auto_running or self._modal_overlay is not None:
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
if self._is_ui_locked():
|
||||
return
|
||||
if self.animator and self.animator.is_active:
|
||||
self.animator.flush()
|
||||
|
|
@ -933,15 +1062,18 @@ class KlondikeTableView:
|
|||
self.engine.start_timer_if_needed()
|
||||
self._update_hud_text()
|
||||
hit["start_xy"] = (event.x, event.y)
|
||||
hit["press_ts"] = time.monotonic()
|
||||
self._press_info = hit
|
||||
|
||||
def _on_mouse_move(self, event):
|
||||
if not self._press_info or self._press_info.get("zone") == "stock":
|
||||
if not self._press_info or self._press_info.get("zone") == "stock" or self._fx_overlay is not None:
|
||||
return
|
||||
sx, sy = self._press_info["start_xy"]
|
||||
if not self._dragging:
|
||||
if abs(event.x - sx) < self.DRAG_THRESHOLD_PX and abs(event.y - sy) < self.DRAG_THRESHOLD_PX:
|
||||
return
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
self._dragging = True
|
||||
self._drag_last_xy = (sx, sy)
|
||||
self.redraw(exclude_source=self._press_info)
|
||||
|
|
@ -1032,6 +1164,13 @@ class KlondikeTableView:
|
|||
return
|
||||
|
||||
now = time.monotonic()
|
||||
if is_single_tap_to_move_enabled():
|
||||
hold_sec = now - info.get("press_ts", now)
|
||||
self._last_click_target = None
|
||||
if hold_sec <= SINGLE_TAP_MAX_HOLD_SEC:
|
||||
self._smart_auto_move(info)
|
||||
return
|
||||
|
||||
target_id = (zone, info.get("col", -1), info.get("idx", -1))
|
||||
if self._last_click_target == target_id and (now - self._last_click_ts) <= self.DOUBLE_CLICK_SEC:
|
||||
self._last_click_target = None
|
||||
|
|
@ -1041,7 +1180,9 @@ class KlondikeTableView:
|
|||
self._last_click_target = target_id
|
||||
|
||||
def _on_right_click(self, event):
|
||||
if self.engine.won or self._auto_running or self._modal_overlay is not None:
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
if self._is_ui_locked():
|
||||
return
|
||||
if self.animator and self.animator.is_active:
|
||||
self.animator.flush()
|
||||
|
|
@ -1150,13 +1291,13 @@ class KlondikeTableView:
|
|||
self._check_deadlock_and_prompt()
|
||||
|
||||
def _check_deadlock_and_prompt(self):
|
||||
if self.engine.won or self._auto_running or self._modal_overlay is not None:
|
||||
if self._is_ui_locked():
|
||||
return
|
||||
if not self.engine.has_any_meaningful_move():
|
||||
self._show_deadlock_modal()
|
||||
|
||||
def _on_undo(self):
|
||||
if self.engine.won or self._auto_running or self._modal_overlay is not None:
|
||||
if self._is_ui_locked():
|
||||
return
|
||||
self._clear_hint()
|
||||
|
||||
|
|
@ -1169,7 +1310,7 @@ class KlondikeTableView:
|
|||
self._run_animated_action(self.engine.undo, duration_ms=105, after_cb=finish_undo)
|
||||
|
||||
def _on_undo_all(self):
|
||||
if self.engine.won or self._auto_running or self._modal_overlay is not None:
|
||||
if self._is_ui_locked():
|
||||
return
|
||||
if self.animator:
|
||||
self.animator.flush()
|
||||
|
|
@ -1190,7 +1331,7 @@ class KlondikeTableView:
|
|||
self._active_hint = None
|
||||
|
||||
def _on_hint(self):
|
||||
if self.engine.won or self._auto_running or self._modal_overlay is not None:
|
||||
if self._is_ui_locked():
|
||||
return
|
||||
if self.animator:
|
||||
self.animator.flush()
|
||||
|
|
@ -1210,11 +1351,11 @@ class KlondikeTableView:
|
|||
def _expire_hint(self):
|
||||
self._hint_job = None
|
||||
self._active_hint = None
|
||||
if self._canvas_alive():
|
||||
if self._canvas_alive() and self._fx_overlay is None:
|
||||
self.redraw()
|
||||
|
||||
def _start_auto_complete(self):
|
||||
if not self.engine.can_auto_complete() or self._auto_running:
|
||||
if not self.engine.can_auto_complete() or self._is_ui_locked():
|
||||
return
|
||||
if self.animator:
|
||||
self.animator.flush()
|
||||
|
|
@ -1257,11 +1398,11 @@ class KlondikeTableView:
|
|||
self._save_progress()
|
||||
|
||||
def _on_new_or_forfeit_clicked(self):
|
||||
if self._auto_running or self._modal_overlay is not None:
|
||||
if self._auto_running or self._modal_overlay is not None or self._fx_overlay is not None:
|
||||
return
|
||||
if self.animator:
|
||||
self.animator.flush()
|
||||
if self.engine.won or self.engine.moves == 0:
|
||||
if self.engine.won or self._game_concluded or self.engine.moves == 0:
|
||||
self._game_concluded = False
|
||||
self.engine.new_game(draw_count=self.cfg["draw_count"], difficulty=self.difficulty)
|
||||
self._save_progress()
|
||||
|
|
@ -1280,42 +1421,95 @@ class KlondikeTableView:
|
|||
return max(2, int(round(win_xp * SOLO_FORFEIT_XP_RATIO)))
|
||||
|
||||
def _execute_forfeit(self, penalty: int, go_menu: bool):
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
pid = self.ctx.profile["id"]
|
||||
prog = Database.get_game_progress(pid, GAME_FOLDER_ID)
|
||||
floor_xp = Progression.get_creator_spirit_v_floor_xp() if prog["ever_reached_deity"] else 0
|
||||
|
||||
self._game_concluded = True
|
||||
self.engine.pause_timer()
|
||||
dur = self.engine.get_elapsed_seconds()
|
||||
Database.delete_game_state(pid, GAME_FOLDER_ID)
|
||||
Database.record_game_result(
|
||||
pid,
|
||||
variant_key=self.variant_key,
|
||||
won=False,
|
||||
duration_sec=self.engine.get_elapsed_seconds(),
|
||||
duration_sec=dur,
|
||||
points_gained=0,
|
||||
)
|
||||
updated = Database.adjust_game_points(pid, GAME_FOLDER_ID, -penalty, min_floor_xp=floor_xp)
|
||||
deducted = max(0, prog["total_points"] - updated["total_points"])
|
||||
self.topbar.level_label.configure(text="")
|
||||
self.topbar.update_level_xp_text()
|
||||
self.ctx.sounds.play("lose")
|
||||
|
||||
if self._modal_overlay is not None:
|
||||
self._modal_overlay.destroy()
|
||||
try:
|
||||
self._modal_overlay.destroy()
|
||||
except Exception:
|
||||
pass
|
||||
self._modal_overlay = None
|
||||
|
||||
if go_menu:
|
||||
self._cleanup_timers()
|
||||
if callable(self.on_back_to_menu):
|
||||
self.on_back_to_menu(t("sol_loss_xp", deducted), False)
|
||||
else:
|
||||
self._sync_buttons()
|
||||
|
||||
def _after_lose_fx():
|
||||
self._fx_overlay = None
|
||||
if not self._canvas_alive():
|
||||
return
|
||||
self._show_defeat_result_modal(deducted, dur, prefer_menu=go_menu)
|
||||
|
||||
self._fx_overlay = EndgameFxOverlay.play(
|
||||
self.ctx.root,
|
||||
self.ctx.assets,
|
||||
outcome="lose",
|
||||
on_continue=_after_lose_fx,
|
||||
target_canvas=self.canvas,
|
||||
)
|
||||
self._sync_buttons()
|
||||
|
||||
def _show_defeat_result_modal(self, deducted: int, dur: float, prefer_menu: bool):
|
||||
lines = [
|
||||
t(
|
||||
"sol_win_summary",
|
||||
self.engine.score,
|
||||
self.engine.moves,
|
||||
Database.format_seconds(dur),
|
||||
t(f"sol_diff_short_{self.difficulty}"),
|
||||
),
|
||||
t("sol_loss_xp", deducted),
|
||||
]
|
||||
|
||||
def play_again():
|
||||
self._close_active_modal()
|
||||
self._game_concluded = False
|
||||
self.engine.new_game(draw_count=self.cfg["draw_count"], difficulty=self.difficulty)
|
||||
self._check_window_focus()
|
||||
self._save_progress()
|
||||
self.status_var.set(t("sol_loss_xp", deducted))
|
||||
self.status_var.set("")
|
||||
self.ctx.sounds.play("deal")
|
||||
self.redraw()
|
||||
|
||||
def to_menu():
|
||||
self._close_active_modal()
|
||||
self._cleanup_timers()
|
||||
if callable(self.on_back_to_menu):
|
||||
self.on_back_to_menu(t("sol_loss_xp", deducted), False)
|
||||
|
||||
self._modal_overlay = SolitaireModalDialog(
|
||||
self.ctx,
|
||||
title_txt=t("sol_forfeit_title"),
|
||||
body_txt="\n".join(lines),
|
||||
is_danger=True,
|
||||
buttons=[
|
||||
(t("sol_play_again_btn"), "amethyst" if prefer_menu else "fire", play_again),
|
||||
(t("bj_popup_to_menu_btn"), "fire" if prefer_menu else "amethyst", to_menu),
|
||||
],
|
||||
)
|
||||
self._sync_buttons()
|
||||
|
||||
def _show_deadlock_modal(self):
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
self.engine.pause_timer()
|
||||
self._save_progress()
|
||||
penalty = self._compute_forfeit_penalty()
|
||||
|
|
@ -1342,6 +1536,8 @@ class KlondikeTableView:
|
|||
self._sync_buttons()
|
||||
|
||||
def _show_forfeit_modal(self):
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
self.engine.pause_timer()
|
||||
self._save_progress()
|
||||
penalty = self._compute_forfeit_penalty()
|
||||
|
|
@ -1360,7 +1556,10 @@ class KlondikeTableView:
|
|||
self._sync_buttons()
|
||||
|
||||
def _handle_victory(self):
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
self._game_concluded = True
|
||||
self.engine.pause_timer()
|
||||
pid = self.ctx.profile["id"]
|
||||
Database.delete_game_state(pid, GAME_FOLDER_ID)
|
||||
dur = self.engine.get_elapsed_seconds()
|
||||
|
|
@ -1381,9 +1580,24 @@ class KlondikeTableView:
|
|||
duration_sec=dur,
|
||||
points_gained=xp_earned,
|
||||
)
|
||||
self.topbar.level_label.configure(text="")
|
||||
self.topbar.update_level_xp_text()
|
||||
self.ctx.sounds.play("win")
|
||||
self._show_victory_modal(xp_earned, old_lvl, new_lvl, dur)
|
||||
self._sync_buttons()
|
||||
|
||||
def _after_win_fx():
|
||||
self._fx_overlay = None
|
||||
if not self._canvas_alive():
|
||||
return
|
||||
self._show_victory_modal(xp_earned, old_lvl, new_lvl, dur)
|
||||
|
||||
self._fx_overlay = EndgameFxOverlay.play(
|
||||
self.ctx.root,
|
||||
self.ctx.assets,
|
||||
outcome="win",
|
||||
on_continue=_after_win_fx,
|
||||
target_canvas=self.canvas,
|
||||
)
|
||||
self._sync_buttons()
|
||||
|
||||
def _show_victory_modal(self, xp_earned: int, old_lvl: int, new_lvl: int, dur: float):
|
||||
lines = [
|
||||
|
|
@ -1410,6 +1624,7 @@ class KlondikeTableView:
|
|||
self.redraw()
|
||||
|
||||
def to_menu():
|
||||
self._close_active_modal()
|
||||
self._cleanup_timers()
|
||||
if callable(self.on_back_to_menu):
|
||||
self.on_back_to_menu()
|
||||
|
|
@ -1418,7 +1633,6 @@ class KlondikeTableView:
|
|||
self.ctx,
|
||||
title_txt=t("sol_win_title"),
|
||||
body_txt="\n".join(lines),
|
||||
gif_key="win_gif",
|
||||
buttons=[
|
||||
(t("sol_play_again_btn"), "fire", play_again),
|
||||
(t("bj_popup_to_menu_btn"), "amethyst", to_menu),
|
||||
|
|
|
|||
|
|
@ -6,10 +6,14 @@ import time
|
|||
import tkinter as tk
|
||||
|
||||
from games.solitaire.base.card_animator import CardFlightAnimator
|
||||
from games.solitaire.base.card_hover_zoom import CardHoverZoom
|
||||
from games.solitaire.base.solitaire_bottom_bar import SolitaireBottomBar
|
||||
from games.solitaire.base.solitaire_core import SolitaireCard
|
||||
from games.solitaire.base.solitaire_modal_dialog import SolitaireModalDialog
|
||||
from games.solitaire.base.solitaire_stats_view import SolitaireStatsView
|
||||
from games.solitaire.base.solitaire_tap_prefs import (
|
||||
SINGLE_TAP_MAX_HOLD_SEC,
|
||||
is_single_tap_to_move_enabled,
|
||||
)
|
||||
from games.solitaire.base.solitaire_theme import SolitaireTableBgRenderer
|
||||
from games.solitaire.spider_solitaire.models.spider_engine import SpiderEngine
|
||||
from models.database import Database
|
||||
|
|
@ -17,7 +21,6 @@ from models.progression import Progression
|
|||
from resources.code_res.game_constants import (
|
||||
ACCENT_GOLD,
|
||||
ACCENT_GOTH,
|
||||
BG_COLOR,
|
||||
BORDER_COLOR,
|
||||
CELL_BG,
|
||||
ERROR_FG,
|
||||
|
|
@ -32,6 +35,7 @@ from resources.code_res.game_constants import (
|
|||
TABLE_BG,
|
||||
)
|
||||
from resources.code_res.i18n import t
|
||||
from view.widgets.endgame_fx_overlay import EndgameFxOverlay
|
||||
from view.widgets.image_button import ImageButton
|
||||
|
||||
GAME_FOLDER_ID = "solitaire/spider_solitaire"
|
||||
|
|
@ -86,6 +90,8 @@ class SpiderTableView:
|
|||
self._resize_job: str | None = None
|
||||
self._bind_ids: list[tuple[str, str]] = []
|
||||
self.animator: CardFlightAnimator | None = None
|
||||
self.hover_zoom: CardHoverZoom | None = None
|
||||
self._fx_overlay: EndgameFxOverlay | None = None
|
||||
self._bg_renderer = SolitaireTableBgRenderer(self.ctx.assets.res)
|
||||
self._frame_bot_pad: int = 18
|
||||
self._canvas_ui_refs: list = []
|
||||
|
|
@ -118,6 +124,14 @@ class SpiderTableView:
|
|||
d_mult = SOLITAIRE_DIFFICULTIES.get(self.difficulty, SOLITAIRE_DIFFICULTIES[1])["xp_mult"]
|
||||
return self.cfg["xp_mult"] * d_mult
|
||||
|
||||
def _is_ui_locked(self) -> bool:
|
||||
return (
|
||||
self.engine.won
|
||||
or self._game_concluded
|
||||
or (self._modal_overlay is not None)
|
||||
or (self._fx_overlay is not None)
|
||||
)
|
||||
|
||||
def _canvas_alive(self) -> bool:
|
||||
if not self._alive:
|
||||
return False
|
||||
|
|
@ -126,6 +140,62 @@ class SpiderTableView:
|
|||
except Exception:
|
||||
return False
|
||||
|
||||
def _can_show_hover_zoom(self) -> bool:
|
||||
if not self._canvas_alive():
|
||||
return False
|
||||
if self._is_ui_locked() or self._dragging or self._press_info is not None:
|
||||
return False
|
||||
if not self._window_active:
|
||||
return False
|
||||
if self.animator is not None and self.animator.is_active:
|
||||
return False
|
||||
return True
|
||||
|
||||
def _hover_card_probe(self, x: int, y: int) -> dict | None:
|
||||
cw, ch = self.card_size
|
||||
|
||||
# 1. Abgeschlossene Sequenzen oben rechts (Spalten 2..9)
|
||||
for r_slot in range(min(8, len(self.engine.completed_runs))):
|
||||
rx = self._col_x[2 + r_slot]
|
||||
if rx <= x <= rx + cw and self._top_y <= y <= self._top_y + ch:
|
||||
run = self.engine.completed_runs[r_slot]
|
||||
if run and run[0].face_up:
|
||||
return {
|
||||
"card": run[0],
|
||||
"x": rx,
|
||||
"y": self._top_y,
|
||||
"size": self.card_size,
|
||||
"under_tag": None,
|
||||
}
|
||||
return None
|
||||
|
||||
# 2. 10 Tableau-Spalten (alle offenen Karten, auch nicht-ziehbare)
|
||||
for col_idx in range(10):
|
||||
rects = self._tableau_card_rects[col_idx]
|
||||
col_cards = self.engine.tableau[col_idx]
|
||||
for c_idx in range(len(rects) - 1, -1, -1):
|
||||
if c_idx >= len(col_cards):
|
||||
continue
|
||||
x1, y1, x2, y2 = rects[c_idx]
|
||||
if x1 <= x <= x2 and y1 <= y <= y2:
|
||||
card = col_cards[c_idx]
|
||||
if not card.face_up:
|
||||
return None
|
||||
next_tag = (
|
||||
f"sp_tab_{col_idx}_{c_idx + 1}"
|
||||
if (c_idx + 1) < len(col_cards)
|
||||
else None
|
||||
)
|
||||
return {
|
||||
"card": card,
|
||||
"x": x1,
|
||||
"y": y1,
|
||||
"size": self.card_size,
|
||||
"under_tag": next_tag,
|
||||
}
|
||||
|
||||
return None
|
||||
|
||||
def _play_table_music(self):
|
||||
for method_name in ("play_ingame_music", "play_table_music"):
|
||||
fn = getattr(self.ctx.sounds, method_name, None)
|
||||
|
|
@ -159,6 +229,11 @@ class SpiderTableView:
|
|||
def _cleanup_timers(self):
|
||||
self._alive = False
|
||||
self.engine.pause_timer()
|
||||
if self._fx_overlay is not None:
|
||||
self._fx_overlay.cancel()
|
||||
self._fx_overlay = None
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
if self.animator is not None:
|
||||
self.animator.cancel()
|
||||
for job in (
|
||||
|
|
@ -204,7 +279,13 @@ class SpiderTableView:
|
|||
except Exception:
|
||||
return
|
||||
|
||||
should_run = has_focus and (self._modal_overlay is None) and (not self.engine.won)
|
||||
should_run = (
|
||||
has_focus
|
||||
and (self._modal_overlay is None)
|
||||
and (self._fx_overlay is None)
|
||||
and (not self._game_concluded)
|
||||
and (not self.engine.won)
|
||||
)
|
||||
prev_paused = self.engine.is_timer_paused
|
||||
self._window_active = has_focus
|
||||
|
||||
|
|
@ -217,7 +298,7 @@ class SpiderTableView:
|
|||
|
||||
if prev_paused != self.engine.is_timer_paused:
|
||||
self._update_hud_text()
|
||||
if self.animator is None or not self.animator.is_active:
|
||||
if (self.animator is None or not self.animator.is_active) and self._fx_overlay is None:
|
||||
self.redraw()
|
||||
|
||||
def _build_ui(self):
|
||||
|
|
@ -227,18 +308,14 @@ class SpiderTableView:
|
|||
|
||||
self.topbar = self.ctx.build_game_topbar(
|
||||
self.ctx.root,
|
||||
t(GAME_TITLE_KEY),
|
||||
on_game_menu=self._back_to_game_menu,
|
||||
on_stats=self._open_stats,
|
||||
stats_endpoint=GAME_FOLDER_ID,
|
||||
stats_enabled=True,
|
||||
extra_right_text="",
|
||||
on_lang_refresh=self._refresh_lang,
|
||||
)
|
||||
|
||||
self.hud_var = tk.StringVar(value="")
|
||||
self.status_var = tk.StringVar(value="")
|
||||
|
||||
# Untere Gothic-Leiste mit box_gold_double Rahmen unter dem Spielfeld
|
||||
self.bottom_bar = SolitaireBottomBar(self.ctx.root, self.ctx, self.hud_var, self.status_var)
|
||||
self.bottom_bar.pack(fill="x", side="bottom", padx=14, pady=(4, 10))
|
||||
|
||||
|
|
@ -266,13 +343,21 @@ class SpiderTableView:
|
|||
btn_norm, btn_purp, self._on_new_or_forfeit_clicked,
|
||||
sound_mgr=self.ctx.sounds, width=104, height=32, style="amethyst",
|
||||
)
|
||||
self.bottom_bar.set_buttons([
|
||||
self.undo_btn, self.undo_all_btn, self.hint_btn, self.new_btn
|
||||
])
|
||||
self.bottom_bar.set_buttons(
|
||||
[self.undo_btn, self.undo_all_btn, self.hint_btn],
|
||||
overflow_buttons=[self.new_btn],
|
||||
)
|
||||
|
||||
self.canvas = tk.Canvas(self.ctx.root, bg=TABLE_BG, bd=0, highlightthickness=0)
|
||||
self.canvas.pack(fill="both", expand=True, padx=14, pady=(4, 2))
|
||||
self.animator = CardFlightAnimator(self.ctx.root, self.canvas)
|
||||
self.hover_zoom = CardHoverZoom(
|
||||
self.ctx.root,
|
||||
self.canvas,
|
||||
self.ctx.assets,
|
||||
probe_fn=self._hover_card_probe,
|
||||
can_show_fn=self._can_show_hover_zoom,
|
||||
)
|
||||
|
||||
self.canvas.bind("<Configure>", self._on_canvas_configure)
|
||||
self.canvas.bind("<Destroy>", self._on_canvas_destroy)
|
||||
|
|
@ -292,6 +377,8 @@ class SpiderTableView:
|
|||
self._update_hud_text()
|
||||
|
||||
def _on_undo_shortcut(self, _event=None):
|
||||
if self._fx_overlay is not None or self._game_concluded:
|
||||
return "break"
|
||||
if self.engine.can_undo:
|
||||
if self._modal_overlay is not None:
|
||||
self._close_active_modal()
|
||||
|
|
@ -300,6 +387,8 @@ class SpiderTableView:
|
|||
return "break"
|
||||
|
||||
def _on_undo_all_shortcut(self, _event=None):
|
||||
if self._fx_overlay is not None or self._game_concluded:
|
||||
return "break"
|
||||
if self.engine.can_undo_all:
|
||||
if self._modal_overlay is not None:
|
||||
self._close_active_modal()
|
||||
|
|
@ -332,29 +421,9 @@ class SpiderTableView:
|
|||
resume_state_json=state_json,
|
||||
)
|
||||
|
||||
def _open_stats(self):
|
||||
if self.animator:
|
||||
self.animator.flush()
|
||||
self.engine.pause_timer()
|
||||
self._save_progress()
|
||||
state_json = self.engine.to_json()
|
||||
variants = Database.get_variants_for_filter(GAME_FOLDER_ID)
|
||||
cur_vid = next((v["id"] for v in variants if v["variant_key"] == self.variant_key), None)
|
||||
self._cleanup_timers()
|
||||
SolitaireStatsView(
|
||||
self.ctx,
|
||||
game_folder=GAME_FOLDER_ID,
|
||||
game_title_key=GAME_TITLE_KEY,
|
||||
on_back=lambda: SpiderTableView(
|
||||
self.ctx,
|
||||
variant_key=self.variant_key,
|
||||
difficulty=self.difficulty,
|
||||
on_back_to_menu=self.on_back_to_menu,
|
||||
resume_state_json=state_json,
|
||||
),
|
||||
).show(preselect_variant_id=cur_vid)
|
||||
|
||||
def _back_to_game_menu(self):
|
||||
if self._fx_overlay is not None:
|
||||
return
|
||||
if self.animator:
|
||||
self.animator.flush()
|
||||
self.engine.pause_timer()
|
||||
|
|
@ -378,7 +447,12 @@ class SpiderTableView:
|
|||
self._check_window_focus()
|
||||
self._update_hud_text()
|
||||
|
||||
if self.engine.has_timer_started and not self.engine.is_timer_paused and not self.engine.won:
|
||||
if (
|
||||
self.engine.has_timer_started
|
||||
and not self.engine.is_timer_paused
|
||||
and not self.engine.won
|
||||
and not self._game_concluded
|
||||
):
|
||||
self._checkpoint_ticks += 1
|
||||
if self._checkpoint_ticks >= self.CHECKPOINT_TICKS:
|
||||
self._checkpoint_ticks = 0
|
||||
|
|
@ -394,10 +468,13 @@ class SpiderTableView:
|
|||
return
|
||||
try:
|
||||
elapsed_str = Database.format_seconds(self.engine.get_elapsed_seconds())
|
||||
paused_tag = t("sol_hud_paused_tag") if (self.engine.is_timer_paused and not self.engine.won) else ""
|
||||
paused_tag = (
|
||||
t("sol_hud_paused_tag")
|
||||
if (self.engine.is_timer_paused and not self.engine.won and not self._game_concluded)
|
||||
else ""
|
||||
)
|
||||
diff_label = t(f"sol_diff_short_{self.difficulty}")
|
||||
new_hud = t("sol_hud_stats", self.engine.score, self.engine.moves, elapsed_str, paused_tag, diff_label)
|
||||
# Nur schreiben, wenn sich der Text tatsächlich geändert hat!
|
||||
if self.hud_var.get() != new_hud:
|
||||
self.hud_var.set(new_hud)
|
||||
except Exception:
|
||||
|
|
@ -406,11 +483,16 @@ class SpiderTableView:
|
|||
def _sync_buttons(self):
|
||||
if not self._canvas_alive():
|
||||
return
|
||||
locked = self.engine.won or (self._modal_overlay is not None)
|
||||
locked = self._is_ui_locked()
|
||||
self.undo_btn.set_enabled((not locked) and self.engine.can_undo)
|
||||
self.undo_all_btn.set_enabled((not locked) and self.engine.can_undo_all)
|
||||
self.hint_btn.set_enabled(not locked)
|
||||
new_lbl = t("sol_btn_forfeit") if (self.engine.moves > 0 and not self.engine.won) else t("sol_btn_new_deal")
|
||||
self.new_btn.set_enabled((self._fx_overlay is None) and (self._modal_overlay is None))
|
||||
new_lbl = (
|
||||
t("sol_btn_forfeit")
|
||||
if (self.engine.moves > 0 and not self.engine.won and not self._game_concluded)
|
||||
else t("sol_btn_new_deal")
|
||||
)
|
||||
prev_w = self.new_btn.pixel_width
|
||||
self.new_btn.set_text(new_lbl)
|
||||
if self.new_btn.pixel_width != prev_w:
|
||||
|
|
@ -498,6 +580,8 @@ class SpiderTableView:
|
|||
duration_ms: int = 120,
|
||||
after_cb=None,
|
||||
) -> bool:
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
if self.animator:
|
||||
self.animator.flush()
|
||||
before_pos = self._snapshot_card_positions()
|
||||
|
|
@ -546,8 +630,10 @@ class SpiderTableView:
|
|||
return True
|
||||
|
||||
def _on_canvas_configure(self, _event=None):
|
||||
if not self._canvas_alive():
|
||||
if not self._canvas_alive() or self._fx_overlay is not None:
|
||||
return
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
if self.animator:
|
||||
self.animator.flush()
|
||||
if self._resize_job is not None:
|
||||
|
|
@ -573,7 +659,7 @@ class SpiderTableView:
|
|||
|
||||
def _recompute_and_draw(self):
|
||||
self._resize_job = None
|
||||
if not self._canvas_alive():
|
||||
if not self._canvas_alive() or self._fx_overlay is not None:
|
||||
return
|
||||
cw = max(720, self.canvas.winfo_width())
|
||||
ch = max(440, self.canvas.winfo_height())
|
||||
|
|
@ -679,9 +765,11 @@ class SpiderTableView:
|
|||
):
|
||||
if not self._canvas_alive():
|
||||
return
|
||||
bg_ids = set(self.canvas.find_withtag("table_bg_slice"))
|
||||
keep_ids = set(self.canvas.find_withtag("table_bg_slice")) | set(
|
||||
self.canvas.find_withtag("modal_dim_veil")
|
||||
)
|
||||
for item_id in self.canvas.find_all():
|
||||
if item_id not in bg_ids:
|
||||
if item_id not in keep_ids:
|
||||
self.canvas.delete(item_id)
|
||||
self._canvas_ui_refs.clear()
|
||||
cw, ch = self.card_size
|
||||
|
|
@ -725,7 +813,9 @@ class SpiderTableView:
|
|||
hl = stock_hl if is_top_pack else None
|
||||
if is_top_pack and not can_deal_now and deal_reason == "empty_column":
|
||||
hl = ERROR_FG
|
||||
self._draw_card_at(vis_packs[0][0], px, self._top_y, highlight_color=hl)
|
||||
self._draw_card_at(
|
||||
vis_packs[0][0], px, self._top_y, tags=(f"sp_stock_{slot_i}",), highlight_color=hl
|
||||
)
|
||||
|
||||
last_px = self._stock_pack_x(len(vis_packs) - 1)
|
||||
self._stock_bbox = (sx0, self._top_y, last_px + cw, self._top_y + ch)
|
||||
|
|
@ -746,9 +836,11 @@ class SpiderTableView:
|
|||
run = self.engine.completed_runs[r_slot]
|
||||
vis_run = [c for c in run if self._card_key(c) not in hidden]
|
||||
if vis_run:
|
||||
self._draw_card_at(vis_run[0], rx, self._top_y, highlight_color=ACCENT_GOLD)
|
||||
self._draw_card_at(
|
||||
vis_run[0], rx, self._top_y, tags=(f"sp_run_{r_slot}",), highlight_color=ACCENT_GOLD
|
||||
)
|
||||
|
||||
# 3. Untere Reihe: 10 Tableau-Spalten
|
||||
# 3. Untere Reihe: 10 Tableau-Spalten mit Z-Order-Tags pro Karte
|
||||
self._tableau_card_rects = [[] for _ in range(10)]
|
||||
need_fill_warning = bool(self.engine.stock_deals) and self.engine.has_empty_column()
|
||||
|
||||
|
|
@ -793,6 +885,7 @@ class SpiderTableView:
|
|||
card,
|
||||
tx,
|
||||
cur_y,
|
||||
tags=(f"sp_tab_{col_idx}_{c_idx}",),
|
||||
highlight_color=c_hl,
|
||||
dim_non_movable=(card.face_up and c_idx < movable_from),
|
||||
)
|
||||
|
|
@ -804,7 +897,9 @@ class SpiderTableView:
|
|||
self.engine.has_timer_started
|
||||
and not self._window_active
|
||||
and not self.engine.won
|
||||
and not self._game_concluded
|
||||
and self._modal_overlay is None
|
||||
and self._fx_overlay is None
|
||||
):
|
||||
p_ph = self.ctx.assets.get_goth_text_photo(
|
||||
t("sol_canvas_paused_banner"), FONT_SIZE_BODY, FONT_COLOR_TITLE_MAIN
|
||||
|
|
@ -817,6 +912,16 @@ class SpiderTableView:
|
|||
self.canvas.create_image(pcx, pcy, image=box_ph, anchor="center")
|
||||
self.canvas.create_image(pcx, pcy, image=p_ph, anchor="center")
|
||||
|
||||
if self.canvas.find_withtag("modal_dim_veil"):
|
||||
self.canvas.tag_raise("modal_dim_veil")
|
||||
|
||||
if (
|
||||
self.hover_zoom is not None
|
||||
and exclude_source is None
|
||||
and not hidden
|
||||
):
|
||||
self.hover_zoom.refresh_after_redraw()
|
||||
|
||||
self._sync_buttons()
|
||||
|
||||
def _hit_test(self, x: int, y: int) -> dict | None:
|
||||
|
|
@ -845,7 +950,9 @@ class SpiderTableView:
|
|||
return None
|
||||
|
||||
def _on_mouse_down(self, event):
|
||||
if self.engine.won or self._modal_overlay is not None:
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
if self._is_ui_locked():
|
||||
return
|
||||
if self.animator and self.animator.is_active:
|
||||
self.animator.flush()
|
||||
|
|
@ -859,15 +966,18 @@ class SpiderTableView:
|
|||
self.engine.start_timer_if_needed()
|
||||
self._update_hud_text()
|
||||
hit["start_xy"] = (event.x, event.y)
|
||||
hit["press_ts"] = time.monotonic()
|
||||
self._press_info = hit
|
||||
|
||||
def _on_mouse_move(self, event):
|
||||
if not self._press_info or self._press_info.get("zone") == "stock":
|
||||
if not self._press_info or self._press_info.get("zone") == "stock" or self._fx_overlay is not None:
|
||||
return
|
||||
sx, sy = self._press_info["start_xy"]
|
||||
if not self._dragging:
|
||||
if abs(event.x - sx) < self.DRAG_THRESHOLD_PX and abs(event.y - sy) < self.DRAG_THRESHOLD_PX:
|
||||
return
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
self._dragging = True
|
||||
self._drag_last_xy = (sx, sy)
|
||||
self.redraw(exclude_source=self._press_info)
|
||||
|
|
@ -958,6 +1068,13 @@ class SpiderTableView:
|
|||
return
|
||||
|
||||
now = time.monotonic()
|
||||
if is_single_tap_to_move_enabled():
|
||||
hold_sec = now - info.get("press_ts", now)
|
||||
self._last_click_target = None
|
||||
if hold_sec <= SINGLE_TAP_MAX_HOLD_SEC:
|
||||
self._smart_auto_move(info)
|
||||
return
|
||||
|
||||
target_id = (info["zone"], info.get("col", -1), info.get("idx", -1))
|
||||
if self._last_click_target == target_id and (now - self._last_click_ts) <= self.DOUBLE_CLICK_SEC:
|
||||
self._last_click_target = None
|
||||
|
|
@ -967,7 +1084,9 @@ class SpiderTableView:
|
|||
self._last_click_target = target_id
|
||||
|
||||
def _on_right_click(self, event):
|
||||
if self.engine.won or self._modal_overlay is not None:
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
if self._is_ui_locked():
|
||||
return
|
||||
if self.animator and self.animator.is_active:
|
||||
self.animator.flush()
|
||||
|
|
@ -1057,13 +1176,13 @@ class SpiderTableView:
|
|||
self._check_deadlock_and_prompt()
|
||||
|
||||
def _check_deadlock_and_prompt(self):
|
||||
if self.engine.won or self._modal_overlay is not None:
|
||||
if self._is_ui_locked():
|
||||
return
|
||||
if not self.engine.has_any_meaningful_move():
|
||||
self._show_deadlock_modal()
|
||||
|
||||
def _on_undo(self):
|
||||
if self.engine.won or self._modal_overlay is not None:
|
||||
if self._is_ui_locked():
|
||||
return
|
||||
self._clear_hint()
|
||||
|
||||
|
|
@ -1076,7 +1195,7 @@ class SpiderTableView:
|
|||
self._run_animated_action(self.engine.undo, duration_ms=110, after_cb=finish_undo)
|
||||
|
||||
def _on_undo_all(self):
|
||||
if self.engine.won or self._modal_overlay is not None:
|
||||
if self._is_ui_locked():
|
||||
return
|
||||
if self.animator:
|
||||
self.animator.flush()
|
||||
|
|
@ -1097,7 +1216,7 @@ class SpiderTableView:
|
|||
self._active_hint = None
|
||||
|
||||
def _on_hint(self):
|
||||
if self.engine.won or self._modal_overlay is not None:
|
||||
if self._is_ui_locked():
|
||||
return
|
||||
if self.animator:
|
||||
self.animator.flush()
|
||||
|
|
@ -1117,15 +1236,15 @@ class SpiderTableView:
|
|||
def _expire_hint(self):
|
||||
self._hint_job = None
|
||||
self._active_hint = None
|
||||
if self._canvas_alive():
|
||||
if self._canvas_alive() and self._fx_overlay is None:
|
||||
self.redraw()
|
||||
|
||||
def _on_new_or_forfeit_clicked(self):
|
||||
if self._modal_overlay is not None:
|
||||
if self._modal_overlay is not None or self._fx_overlay is not None:
|
||||
return
|
||||
if self.animator:
|
||||
self.animator.flush()
|
||||
if self.engine.won or self.engine.moves == 0:
|
||||
if self.engine.won or self._game_concluded or self.engine.moves == 0:
|
||||
self._game_concluded = False
|
||||
self.engine.new_game(variant_key=self.variant_key, difficulty=self.difficulty)
|
||||
self._save_progress()
|
||||
|
|
@ -1144,42 +1263,95 @@ class SpiderTableView:
|
|||
return max(2, int(round(win_xp * SOLO_FORFEIT_XP_RATIO)))
|
||||
|
||||
def _execute_forfeit(self, penalty: int, go_menu: bool):
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
pid = self.ctx.profile["id"]
|
||||
prog = Database.get_game_progress(pid, GAME_FOLDER_ID)
|
||||
floor_xp = Progression.get_creator_spirit_v_floor_xp() if prog["ever_reached_deity"] else 0
|
||||
|
||||
self._game_concluded = True
|
||||
self.engine.pause_timer()
|
||||
dur = self.engine.get_elapsed_seconds()
|
||||
Database.delete_game_state(pid, GAME_FOLDER_ID)
|
||||
Database.record_game_result(
|
||||
pid,
|
||||
variant_key=self.variant_key,
|
||||
won=False,
|
||||
duration_sec=self.engine.get_elapsed_seconds(),
|
||||
duration_sec=dur,
|
||||
points_gained=0,
|
||||
)
|
||||
updated = Database.adjust_game_points(pid, GAME_FOLDER_ID, -penalty, min_floor_xp=floor_xp)
|
||||
deducted = max(0, prog["total_points"] - updated["total_points"])
|
||||
self.topbar.level_label.configure(text="")
|
||||
self.topbar.update_level_xp_text()
|
||||
self.ctx.sounds.play("lose")
|
||||
|
||||
if self._modal_overlay is not None:
|
||||
self._modal_overlay.destroy()
|
||||
try:
|
||||
self._modal_overlay.destroy()
|
||||
except Exception:
|
||||
pass
|
||||
self._modal_overlay = None
|
||||
|
||||
if go_menu:
|
||||
self._cleanup_timers()
|
||||
if callable(self.on_back_to_menu):
|
||||
self.on_back_to_menu(t("sol_loss_xp", deducted), False)
|
||||
else:
|
||||
self._sync_buttons()
|
||||
|
||||
def _after_lose_fx():
|
||||
self._fx_overlay = None
|
||||
if not self._canvas_alive():
|
||||
return
|
||||
self._show_defeat_result_modal(deducted, dur, prefer_menu=go_menu)
|
||||
|
||||
self._fx_overlay = EndgameFxOverlay.play(
|
||||
self.ctx.root,
|
||||
self.ctx.assets,
|
||||
outcome="lose",
|
||||
on_continue=_after_lose_fx,
|
||||
target_canvas=self.canvas,
|
||||
)
|
||||
self._sync_buttons()
|
||||
|
||||
def _show_defeat_result_modal(self, deducted: int, dur: float, prefer_menu: bool):
|
||||
lines = [
|
||||
t(
|
||||
"sol_win_summary",
|
||||
self.engine.score,
|
||||
self.engine.moves,
|
||||
Database.format_seconds(dur),
|
||||
t(f"sol_diff_short_{self.difficulty}"),
|
||||
),
|
||||
t("sol_loss_xp", deducted),
|
||||
]
|
||||
|
||||
def play_again():
|
||||
self._close_active_modal()
|
||||
self._game_concluded = False
|
||||
self.engine.new_game(variant_key=self.variant_key, difficulty=self.difficulty)
|
||||
self._check_window_focus()
|
||||
self._save_progress()
|
||||
self.status_var.set(t("sol_loss_xp", deducted))
|
||||
self.status_var.set("")
|
||||
self.ctx.sounds.play("deal")
|
||||
self.redraw()
|
||||
|
||||
def to_menu():
|
||||
self._close_active_modal()
|
||||
self._cleanup_timers()
|
||||
if callable(self.on_back_to_menu):
|
||||
self.on_back_to_menu(t("sol_loss_xp", deducted), False)
|
||||
|
||||
self._modal_overlay = SolitaireModalDialog(
|
||||
self.ctx,
|
||||
title_txt=t("sol_forfeit_title"),
|
||||
body_txt="\n".join(lines),
|
||||
is_danger=True,
|
||||
buttons=[
|
||||
(t("sol_play_again_btn"), "amethyst" if prefer_menu else "fire", play_again),
|
||||
(t("bj_popup_to_menu_btn"), "fire" if prefer_menu else "amethyst", to_menu),
|
||||
],
|
||||
)
|
||||
self._sync_buttons()
|
||||
|
||||
def _show_deadlock_modal(self):
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
self.engine.pause_timer()
|
||||
self._save_progress()
|
||||
penalty = self._compute_forfeit_penalty()
|
||||
|
|
@ -1206,6 +1378,8 @@ class SpiderTableView:
|
|||
self._sync_buttons()
|
||||
|
||||
def _show_forfeit_modal(self):
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
self.engine.pause_timer()
|
||||
self._save_progress()
|
||||
penalty = self._compute_forfeit_penalty()
|
||||
|
|
@ -1224,7 +1398,10 @@ class SpiderTableView:
|
|||
self._sync_buttons()
|
||||
|
||||
def _handle_victory(self):
|
||||
if self.hover_zoom is not None:
|
||||
self.hover_zoom.cancel()
|
||||
self._game_concluded = True
|
||||
self.engine.pause_timer()
|
||||
pid = self.ctx.profile["id"]
|
||||
Database.delete_game_state(pid, GAME_FOLDER_ID)
|
||||
dur = self.engine.get_elapsed_seconds()
|
||||
|
|
@ -1245,9 +1422,24 @@ class SpiderTableView:
|
|||
duration_sec=dur,
|
||||
points_gained=xp_earned,
|
||||
)
|
||||
self.topbar.level_label.configure(text="")
|
||||
self.topbar.update_level_xp_text()
|
||||
self.ctx.sounds.play("win")
|
||||
self._show_victory_modal(xp_earned, old_lvl, new_lvl, dur)
|
||||
self._sync_buttons()
|
||||
|
||||
def _after_win_fx():
|
||||
self._fx_overlay = None
|
||||
if not self._canvas_alive():
|
||||
return
|
||||
self._show_victory_modal(xp_earned, old_lvl, new_lvl, dur)
|
||||
|
||||
self._fx_overlay = EndgameFxOverlay.play(
|
||||
self.ctx.root,
|
||||
self.ctx.assets,
|
||||
outcome="win",
|
||||
on_continue=_after_win_fx,
|
||||
target_canvas=self.canvas,
|
||||
)
|
||||
self._sync_buttons()
|
||||
|
||||
def _show_victory_modal(self, xp_earned: int, old_lvl: int, new_lvl: int, dur: float):
|
||||
lines = [
|
||||
|
|
@ -1274,6 +1466,7 @@ class SpiderTableView:
|
|||
self.redraw()
|
||||
|
||||
def to_menu():
|
||||
self._close_active_modal()
|
||||
self._cleanup_timers()
|
||||
if callable(self.on_back_to_menu):
|
||||
self.on_back_to_menu()
|
||||
|
|
@ -1282,7 +1475,6 @@ class SpiderTableView:
|
|||
self.ctx,
|
||||
title_txt=t("sol_win_title"),
|
||||
body_txt="\n".join(lines),
|
||||
gif_key="win_gif",
|
||||
buttons=[
|
||||
(t("sol_play_again_btn"), "fire", play_again),
|
||||
(t("bj_popup_to_menu_btn"), "amethyst", to_menu),
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ class ResourceManager:
|
|||
self.root_dir = root_dir
|
||||
self.res_dir = root_dir / "resources"
|
||||
self.images_dir = self.res_dir / "images"
|
||||
self.win_lose_dir = self.images_dir / "win_lose"
|
||||
self.game_icons_dir = self.images_dir / GAME_ICONS_SUBDIR
|
||||
self.cards_base_dir = self.images_dir / "cards"
|
||||
self.sounds_dir = self.res_dir / "sounds"
|
||||
|
|
@ -35,6 +36,14 @@ class ResourceManager:
|
|||
filename = UI_IMAGES.get(key_or_filename, key_or_filename)
|
||||
return self.images_dir / filename
|
||||
|
||||
def get_win_lose_gif_path(self, filename_or_stem: str) -> Path:
|
||||
name = (
|
||||
filename_or_stem
|
||||
if filename_or_stem.lower().endswith(".gif")
|
||||
else f"{filename_or_stem}.gif"
|
||||
)
|
||||
return self.win_lose_dir / name
|
||||
|
||||
def get_game_icon_path(self, game_folder: str) -> Path | None:
|
||||
icon_file = GAME_ICON_MAP.get(game_folder)
|
||||
if not icon_file:
|
||||
|
|
|
|||
|
|
@ -438,4 +438,24 @@ INSERT OR REPLACE INTO base_i18n (key, lang, val) VALUES
|
|||
('stats_view_topbar', 'DE', 'Spiel-Statistiken ({0})'),
|
||||
('stats_view_topbar', 'EN', 'Game Statistics ({0})'),
|
||||
('xp_next_level', 'DE', '{0} / {1} XP bis Lv. {2}'),
|
||||
('xp_next_level', 'EN', '{0} / {1} XP to Lv. {2}');
|
||||
('xp_next_level', 'EN', '{0} / {1} XP to Lv. {2}'),
|
||||
('settings_hover_help_desc', 'DE', 'Erklärungen beim Überfahren von Aktions-Buttons'),
|
||||
('settings_hover_help_desc', 'EN', 'Display explanations when hovering action buttons'),
|
||||
('settings_hover_help_title', 'DE', 'Hilfetexte bei Buttons anzeigen'),
|
||||
('settings_hover_help_title', 'EN', 'Show Help Texts on Button Hover'),
|
||||
('settings_lang_btn_toggle', 'DE', 'Deutsch - EN'),
|
||||
('settings_lang_btn_toggle', 'EN', 'English - DE'),
|
||||
('settings_lang_desc', 'DE', 'Anzeigesprache wechseln'),
|
||||
('settings_lang_desc', 'EN', 'Switch display language'),
|
||||
('settings_lang_title', 'DE', 'Sprache'),
|
||||
('settings_lang_title', 'EN', 'Language'),
|
||||
('settings_single_tap_desc', 'DE', 'Solitaire: Kurzer Klick schiebt Karten automatisch (Halten/Ziehen bleibt frei)'),
|
||||
('settings_single_tap_desc', 'EN', 'Solitaire: Quick click auto-moves cards (hold & drag remain unaffected)'),
|
||||
('settings_single_tap_title', 'DE', 'Einfacher Klick zum Schieben'),
|
||||
('settings_single_tap_title', 'EN', 'Single tap to move'),
|
||||
('settings_subtitle', 'DE', 'Sprache, Bedienhilfen & Klangkulisse'),
|
||||
('settings_subtitle', 'EN', 'Language, UI Helpers & Audio'),
|
||||
('settings_title', 'DE', 'Einstellungen'),
|
||||
('settings_title', 'EN', 'Settings'),
|
||||
('endgame_click_continue', 'DE', 'Klicken zum Fortfahren'),
|
||||
('endgame_click_continue', 'EN', 'Click anywhere to continue');
|
||||
|
After Width: | Height: | Size: 137 KiB |
|
After Width: | Height: | Size: 128 KiB |
|
After Width: | Height: | Size: 125 KiB |
|
After Width: | Height: | Size: 127 KiB |
|
After Width: | Height: | Size: 130 KiB |
|
After Width: | Height: | Size: 141 KiB |
|
After Width: | Height: | Size: 162 KiB |
|
After Width: | Height: | Size: 147 KiB |
|
After Width: | Height: | Size: 140 KiB |
|
After Width: | Height: | Size: 126 KiB |
|
After Width: | Height: | Size: 107 KiB |
|
After Width: | Height: | Size: 110 KiB |
|
After Width: | Height: | Size: 116 KiB |
|
After Width: | Height: | Size: 118 KiB |
|
After Width: | Height: | Size: 151 KiB |
|
After Width: | Height: | Size: 154 KiB |
|
After Width: | Height: | Size: 142 KiB |
|
After Width: | Height: | Size: 141 KiB |
|
After Width: | Height: | Size: 131 KiB |
|
After Width: | Height: | Size: 112 KiB |
|
After Width: | Height: | Size: 116 KiB |
|
After Width: | Height: | Size: 124 KiB |
|
After Width: | Height: | Size: 125 KiB |
|
After Width: | Height: | Size: 157 KiB |
|
After Width: | Height: | Size: 158 KiB |
|
After Width: | Height: | Size: 147 KiB |
|
After Width: | Height: | Size: 143 KiB |
|
After Width: | Height: | Size: 134 KiB |
|
After Width: | Height: | Size: 112 KiB |
|
After Width: | Height: | Size: 113 KiB |
|
After Width: | Height: | Size: 124 KiB |
|
After Width: | Height: | Size: 129 KiB |
|
After Width: | Height: | Size: 154 KiB |
|
After Width: | Height: | Size: 153 KiB |
|
After Width: | Height: | Size: 152 KiB |
|
After Width: | Height: | Size: 141 KiB |
|
Before Width: | Height: | Size: 467 KiB |
|
Before Width: | Height: | Size: 937 KiB |
|
After Width: | Height: | Size: 174 KiB |
|
After Width: | Height: | Size: 182 KiB |
|
After Width: | Height: | Size: 135 KiB |
|
After Width: | Height: | Size: 172 KiB |
|
|
@ -26,7 +26,6 @@ from resources.code_res.game_constants import (
|
|||
PLAYING_CARD_SIZE,
|
||||
)
|
||||
|
||||
# Anteil der Ecke im hochauflösenden Quellbild (erfasst das volle Eck-Ornament)
|
||||
BOX_SOURCE_CORNER_RATIO = {
|
||||
"box_big": 0.16,
|
||||
"box_gold_small": 0.24,
|
||||
|
|
@ -35,7 +34,6 @@ BOX_SOURCE_CORNER_RATIO = {
|
|||
"dropdown_box": 0.085,
|
||||
}
|
||||
|
||||
# Ziel-Eckgröße im UI: (relativer_anteil_an_kleinerer_zielkante, min_px, max_px)
|
||||
BOX_TARGET_CORNER_SPEC = {
|
||||
"box_big": (0.14, 18, 46),
|
||||
"box_gold_small": (0.22, 14, 34),
|
||||
|
|
@ -48,10 +46,6 @@ _ALL_CAPS_WORD_RE = re.compile(r"\b[A-ZÄÖÜ]{4,}\b")
|
|||
|
||||
|
||||
def _clean_box_matte_fast(pil_img: Image.Image | None, hollow_center: bool = True) -> Image.Image | None:
|
||||
"""
|
||||
Entfernt opake schwarze JPEG-Ränder (und bei Rahmen-Boxen auch das schwarze Innenfeld)
|
||||
komplett in C-Geschwindigkeit via ImageChops + ImageDraw.floodfill (< 1 ms).
|
||||
"""
|
||||
if pil_img is None:
|
||||
return None
|
||||
rgba = pil_img.convert("RGBA")
|
||||
|
|
@ -85,7 +79,6 @@ class AssetManager:
|
|||
self.root_dir = root_dir
|
||||
self.res = ResourceManager(root_dir)
|
||||
|
||||
# --- Caches ---
|
||||
self._tk_cache: dict = {}
|
||||
self._pil_cache: dict = {}
|
||||
self._raw_card_cache: dict[str, Image.Image | None] = {}
|
||||
|
|
@ -93,7 +86,6 @@ class AssetManager:
|
|||
self._bg_scaled_key: tuple[bool, int, int] | None = None
|
||||
self._bg_scaled_pil: Image.Image | None = None
|
||||
|
||||
# --- Hintergründe & Spieltische ---
|
||||
self.raw_bg_horizontal = self._load_ui_flexible("bg_horizontal", "background_horizontal")
|
||||
self.raw_bg_vertical = self._load_ui_flexible("bg_vertical", "background_vertical")
|
||||
self.raw_bg = self.raw_bg_horizontal or self._load_ui_flexible("background", "background")
|
||||
|
|
@ -101,12 +93,10 @@ class AssetManager:
|
|||
self.raw_general_table = None
|
||||
self.raw_poker_table = self._load_ui_flexible("poker_table", "poker_table")
|
||||
|
||||
# --- Buttons (Default, Amethyst-Hover, Feuer-Highlight) ---
|
||||
self.raw_btn_default = self._load_ui_flexible("btn_default", "button")
|
||||
self.raw_btn_purple = self._load_ui_flexible("btn_purple", "button_highlighted_purple")
|
||||
self.raw_btn_fire = self._load_ui_flexible("btn_fire", "button_highlighted_fire")
|
||||
|
||||
# --- Transparente Zierrahmen (9-Slice, einmalig beim Start in C freigestellt) ---
|
||||
self.raw_boxes: dict[str, Image.Image | None] = {
|
||||
"box_big": _clean_box_matte_fast(
|
||||
self._load_ui_flexible("box_big", "box_big"), hollow_center=True
|
||||
|
|
@ -126,7 +116,6 @@ class AssetManager:
|
|||
}
|
||||
self.raw_chat_frame = self.raw_boxes["box_big"]
|
||||
|
||||
# --- Formular-Assets (Input & geteiltes Dropdown) ---
|
||||
self.raw_input = self._load_ui_flexible("input_field", "input")
|
||||
self.raw_dropdown_closed = self._load_ui_flexible("dropdown_closed", "dropdown_closed")
|
||||
self.raw_dropdown_closed_btn = self._load_ui_flexible("dropdown_closed_btn", "dropdown_closed_button")
|
||||
|
|
@ -139,10 +128,8 @@ class AssetManager:
|
|||
self.raw_dropdown_box = self.raw_boxes["dropdown_box"]
|
||||
self.raw_dropdown_selection = self._load_ui_flexible("dropdown_selection", "dropdown_selection")
|
||||
|
||||
# Einmaliges Screen-bewusstes Vorskalieren (behält 4K auf großen Screens, entlastet 1080p/Chromebook)
|
||||
self._optimize_raw_for_display()
|
||||
|
||||
# Abwärtskompatible Aliase nach evtl. Vorskalierung setzen
|
||||
self.raw_btn = self.raw_btn_fire or self.raw_btn_default
|
||||
self.raw_btn_active = self.raw_btn_fire or self.raw_btn_purple
|
||||
self.raw_sel = self.raw_btn_default
|
||||
|
|
@ -177,10 +164,6 @@ class AssetManager:
|
|||
return None
|
||||
|
||||
def _optimize_raw_for_display(self):
|
||||
"""
|
||||
Hält auf 4K/Ultrawide (>= 2500px) die volle Originalauflösung, dampft aber auf
|
||||
kleineren Displays (z. B. 1080p Chromebook) überdimensionierte Rohbilder einmalig vor.
|
||||
"""
|
||||
try:
|
||||
r = tk._default_root
|
||||
sw = r.winfo_screenwidth() if r else 1920
|
||||
|
|
@ -188,7 +171,6 @@ class AssetManager:
|
|||
except Exception:
|
||||
sw, sh = 1920, 1080
|
||||
|
||||
# Button-Rohlinge müssen auf keinem Display höher als 160px sein (UI-Buttons sind 32..46px hoch)
|
||||
btn_cap_h = 200 if max(sw, sh) >= 2500 else 130
|
||||
for attr in ("raw_btn_default", "raw_btn_purple", "raw_btn_fire"):
|
||||
img = getattr(self, attr, None)
|
||||
|
|
@ -211,7 +193,7 @@ class AssetManager:
|
|||
setattr(self, attr, img.resize((nw, nh), Image.Resampling.LANCZOS))
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# ZENTRALER HINTERGRUND-CACHE (1x Resize für Topbar, Menüs & Tische)
|
||||
# ZENTRALER HINTERGRUND-CACHE & MODAL-ABDUNKLUNG
|
||||
# ------------------------------------------------------------------
|
||||
def get_window_bg_pil(self, rw: int, rh: int) -> Image.Image | None:
|
||||
rw, rh = max(64, int(rw)), max(64, int(rh))
|
||||
|
|
@ -224,7 +206,6 @@ class AssetManager:
|
|||
if src is None:
|
||||
return None
|
||||
|
||||
# RGB statt RGBA für den opaken Vollbild-Hintergrund spart 25% RAM & X11-Transferzeit
|
||||
rgb_src = src.convert("RGB") if src.mode != "RGB" else src
|
||||
self._bg_scaled_pil = rgb_src.resize((rw, rh), Image.Resampling.BILINEAR)
|
||||
self._bg_scaled_key = key
|
||||
|
|
@ -246,7 +227,6 @@ class AssetManager:
|
|||
if base is None:
|
||||
return None
|
||||
|
||||
# Ring-Cleanup für alte Fenstergrößen
|
||||
if len(self._tk_cache) > 360:
|
||||
stale = [k for k in self._tk_cache if isinstance(k, tuple) and k and k[0] == "bg_patch"]
|
||||
for k in stale[:-12]:
|
||||
|
|
@ -257,6 +237,24 @@ class AssetManager:
|
|||
self._tk_cache[tk_key] = photo
|
||||
return photo
|
||||
|
||||
def get_dim_veil_photo(
|
||||
self, width: int, height: int, alpha: int = 148
|
||||
) -> ImageTk.PhotoImage:
|
||||
"""
|
||||
Erzeugt einen halbtransparenten RGBA-Abdunklungsschleier für gesperrte Spieltische,
|
||||
sodass Karten und Tischdetails darunter gedimmt/ausgegraut sichtbar bleiben.
|
||||
"""
|
||||
w, h = max(8, int(width)), max(8, int(height))
|
||||
a = max(0, min(240, int(alpha)))
|
||||
tk_key = ("dim_veil", w, h, a)
|
||||
if tk_key not in self._tk_cache:
|
||||
stale = [k for k in self._tk_cache if isinstance(k, tuple) and k and k[0] == "dim_veil"]
|
||||
for k in stale[:-6]:
|
||||
self._tk_cache.pop(k, None)
|
||||
veil_pil = Image.new("RGBA", (w, h), (10, 8, 16, a))
|
||||
self._tk_cache[tk_key] = ImageTk.PhotoImage(veil_pil)
|
||||
return self._tk_cache[tk_key]
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# FONT-LOADER & OLD-LONDON TEXT-RENDERER (PIL RGBA)
|
||||
# ------------------------------------------------------------------
|
||||
|
|
@ -315,7 +313,6 @@ class AssetManager:
|
|||
sx = shadow_offset[0] if (has_shadow and shadow_offset) else 0
|
||||
sy = shadow_offset[1] if (has_shadow and shadow_offset) else 0
|
||||
|
||||
# C-Fast-Path ohne künstliches Letter-Spacing (1 einziger FreeType-Durchlauf für die ganze Zeile!)
|
||||
if letter_spacing == 0:
|
||||
if has_shadow:
|
||||
draw.text((x + sx, y + sy), line, font=font, fill=FONT_SHADOW_COLOR)
|
||||
|
|
@ -463,7 +460,7 @@ class AssetManager:
|
|||
return self._tk_cache[tk_key]
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# 9-SLICE RAHMEN-SCALER FÜR TRANSPARENTE BOXEN (fein herunterskaliert!)
|
||||
# 9-SLICE RAHMEN-SCALER FÜR TRANSPARENTE BOXEN
|
||||
# ------------------------------------------------------------------
|
||||
def get_9slice_pil(
|
||||
self,
|
||||
|
|
@ -497,7 +494,6 @@ class AssetManager:
|
|||
|
||||
out = Image.new("RGBA", (tw, th), (0, 0, 0, 0))
|
||||
|
||||
# 4 Ecken sauber mit LANCZOS herunterskalieren, gerade Kanten schnell mit BILINEAR
|
||||
tl = src.crop((0, 0, sc, sc)).resize((dc, dc), Image.Resampling.LANCZOS)
|
||||
tr = src.crop((sw - sc, 0, sw, sc)).resize((dc, dc), Image.Resampling.LANCZOS)
|
||||
bl = src.crop((0, sh - sc, sc, sh)).resize((dc, dc), Image.Resampling.LANCZOS)
|
||||
|
|
@ -546,14 +542,9 @@ class AssetManager:
|
|||
return self._tk_cache.get(tk_key)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# KARTEN, BANNER & GIFS (Punkt 4: Vorgedampfter Rohkarten-Cache!)
|
||||
# KARTEN, BANNER & WIN/LOSE-GIFS MIT ALPHA-KANAL
|
||||
# ------------------------------------------------------------------
|
||||
def _get_raw_card_pil(self, path: Path | None) -> Image.Image | None:
|
||||
"""
|
||||
Lädt jede Spielkarte nur EINMALIG von der Platte und dampft riesige Vorlagen
|
||||
mit LANCZOS auf max. 340px Breite vor (reicht selbst für 4K-Spieltische locker aus
|
||||
und beschleunigt alle anschließenden Karten-Resizes um den Faktor ~5x!).
|
||||
"""
|
||||
if not path:
|
||||
return None
|
||||
key = str(path)
|
||||
|
|
@ -599,7 +590,7 @@ class AssetManager:
|
|||
def get_gif_frames(self, key_or_filename: str, size=OUTCOME_GIF_SIZE) -> list[ImageTk.PhotoImage]:
|
||||
cache_key = ("gif", key_or_filename, size)
|
||||
if cache_key not in self._tk_cache:
|
||||
frames = []
|
||||
frames: list[ImageTk.PhotoImage] = []
|
||||
path = self.res.get_ui_image_path(key_or_filename)
|
||||
if path.is_file():
|
||||
try:
|
||||
|
|
@ -617,15 +608,53 @@ class AssetManager:
|
|||
self._tk_cache[cache_key] = frames
|
||||
return self._tk_cache[cache_key]
|
||||
|
||||
def get_win_lose_gif_sequence(
|
||||
self, stem_or_filename: str, size: tuple[int, int]
|
||||
) -> tuple[list[ImageTk.PhotoImage], list[int]]:
|
||||
"""
|
||||
Lädt transparente RGBA-GIFs aus resources/images/win_lose/ inklusive ihrer
|
||||
echten Frame-Dauern (ms) und cacht sie für verzögerungsfreie Partikel-Spawns.
|
||||
"""
|
||||
tw, th = max(24, int(size[0])), max(24, int(size[1]))
|
||||
cache_key = ("win_lose_gif", stem_or_filename, (tw, th))
|
||||
if cache_key in self._tk_cache:
|
||||
return self._tk_cache[cache_key]
|
||||
|
||||
raw_pil_key = ("win_lose_raw_pil", stem_or_filename)
|
||||
if raw_pil_key not in self._pil_cache:
|
||||
raw_frames: list[Image.Image] = []
|
||||
raw_durs: list[int] = []
|
||||
path = self.res.get_win_lose_gif_path(stem_or_filename)
|
||||
if path.is_file():
|
||||
try:
|
||||
with Image.open(path) as gif:
|
||||
idx = 0
|
||||
while True:
|
||||
dur = int(gif.info.get("duration", 65) or 65)
|
||||
dur = max(35, min(200, dur))
|
||||
raw_frames.append(gif.copy().convert("RGBA"))
|
||||
raw_durs.append(dur)
|
||||
idx += 1
|
||||
gif.seek(idx)
|
||||
except EOFError:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
self._pil_cache[raw_pil_key] = (raw_frames, raw_durs)
|
||||
|
||||
src_frames, src_durs = self._pil_cache[raw_pil_key]
|
||||
tk_frames = [
|
||||
ImageTk.PhotoImage(fr.resize((tw, th), Image.Resampling.LANCZOS))
|
||||
for fr in src_frames
|
||||
]
|
||||
result = (tk_frames, list(src_durs))
|
||||
self._tk_cache[cache_key] = result
|
||||
return result
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# STARTUP-PRELOADER: Lädt Karten, Fonts, Boxen & Standard-Buttons vorab
|
||||
# STARTUP-PRELOADER
|
||||
# ------------------------------------------------------------------
|
||||
def preload_startup_assets(self, init_win_size: tuple[int, int] = (1280, 760), on_step=None):
|
||||
"""
|
||||
Wird einmalig beim Programmstart aufgerufen, damit im laufenden Betrieb
|
||||
(z. B. beim Erstellen von Goldbeuteln, Menüwechseln oder Spielstart)
|
||||
keinerlei Disk-I/O oder Erst-Dekodierung mehr blockiert.
|
||||
"""
|
||||
from resources.code_res.game_constants import SUITS, RANKS
|
||||
from resources.code_res.i18n import t
|
||||
from view.widgets.image_button import ImageButton, _trim_button_art
|
||||
|
|
@ -635,19 +664,16 @@ class AssetManager:
|
|||
if callable(on_step):
|
||||
on_step(msg)
|
||||
|
||||
# 1. Alle genutzten Font-Größen in FreeType vorwärmen
|
||||
_notify("Fonts...")
|
||||
for px in (14, 15, 16, 18, 20, 22, 24, 26, 30, 34, 38):
|
||||
self.get_pil_font(px, alternate=False)
|
||||
|
||||
# 2. Fenster-Hintergrund für Startgröße vorberechnen
|
||||
_notify("Background...")
|
||||
w, h = max(800, init_win_size[0]), max(600, init_win_size[1])
|
||||
self.get_bg_patch_photo(w, h, 0, 0, w, h)
|
||||
if self.raw_title is not None:
|
||||
self.get_proportional_photo("title_main_header", self.raw_title, 265)
|
||||
|
||||
# 3. Button- & Dropdown-Rohlinge vorab trimmen + Topbar-Standardbuttons cachen
|
||||
_notify("UI Controls...")
|
||||
for raw_b in (self.raw_btn_default, self.raw_btn_purple, self.raw_btn_fire):
|
||||
if raw_b is not None:
|
||||
|
|
@ -662,7 +688,6 @@ class AssetManager:
|
|||
if raw_dd is not None:
|
||||
_trim_outer_black_bbox(raw_dd)
|
||||
|
||||
# Häufigste Topbar-Buttons im globalen _BTN_PHOTO_CACHE vorbacken
|
||||
dummy_root = tk._default_root
|
||||
if dummy_root is not None and self.raw_btn_default is not None:
|
||||
common_specs = [
|
||||
|
|
@ -681,7 +706,6 @@ class AssetManager:
|
|||
tmp._ensure_hover()
|
||||
tmp.destroy()
|
||||
|
||||
# 4. Komplette 52er Kartendecks + Kartenrücken einmalig von Disk in _raw_card_cache laden
|
||||
_notify("Cards...")
|
||||
for suit in SUITS:
|
||||
for rank in RANKS:
|
||||
|
|
@ -694,7 +718,6 @@ class AssetManager:
|
|||
if bp and bp.is_file():
|
||||
self._get_raw_card_pil(bp)
|
||||
|
||||
# 5. Ergebnis-GIFs vorab dekodieren
|
||||
_notify("Animations...")
|
||||
for gif_key in ("win_gif", "lose_gif", "draw_gif"):
|
||||
self.get_gif_frames(gif_key)
|
||||
for wl_name in ("firework_start", "bat_explosion", "pumpkin_explosion", "foul_pumpkin"):
|
||||
self.get_win_lose_gif_sequence(wl_name, (170, 170))
|
||||
|
|
@ -5,6 +5,10 @@ from __future__ import annotations
|
|||
import tkinter as tk
|
||||
from PIL import Image, ImageTk
|
||||
|
||||
from games.solitaire.base.solitaire_tap_prefs import (
|
||||
is_single_tap_to_move_enabled,
|
||||
set_single_tap_to_move_enabled,
|
||||
)
|
||||
from resources.code_res.game_constants import (
|
||||
BG_COLOR,
|
||||
FONT_COLOR_BODY_DEFAULT,
|
||||
|
|
@ -35,14 +39,15 @@ def is_german_active() -> bool:
|
|||
|
||||
class AudioSettingsDialog(tk.Canvas):
|
||||
"""
|
||||
Rahmenloses Gothic-Einstellungs-Overlay:
|
||||
Rahmenloses Gothic-Einstellungs-Overlay (768p-kompatibel):
|
||||
- Sprache wechseln (DE / EN)
|
||||
- Animierter Switch: 'Hilfe Texte bei Buttons Anzeigen' / 'Show Help Texts on Button Hover'
|
||||
- Animierter Switch: 'Hilfetexte bei Buttons anzeigen' / 'Show Help Texts on Button Hover'
|
||||
- Animierter Switch: 'Einfacher Klick zum Schieben' / 'Single tap to move'
|
||||
- Zwei Audio-Schieberegler (Ambiance & Soundeffekte)
|
||||
"""
|
||||
|
||||
DLG_W = 500
|
||||
DLG_H = 604
|
||||
DLG_H = 656
|
||||
|
||||
@classmethod
|
||||
def open(
|
||||
|
|
@ -114,7 +119,6 @@ class AudioSettingsDialog(tk.Canvas):
|
|||
self._sliders.clear()
|
||||
|
||||
w, h = self.DLG_W, self.DLG_H
|
||||
is_de = is_german_active()
|
||||
|
||||
# 1. Hochformat-Hintergrund + box_big.png Zierrahmen
|
||||
bg_src = self.assets.raw_bg_vertical or self.assets.raw_bg_horizontal or self.assets.raw_bg
|
||||
|
|
@ -130,39 +134,45 @@ class AudioSettingsDialog(tk.Canvas):
|
|||
self.create_image(w // 2, h // 2, image=outer_box, anchor="center")
|
||||
|
||||
# 2. Titel & Untertitel
|
||||
dlg_title = "Einstellungen" if is_de else "Settings"
|
||||
dlg_sub = (
|
||||
"Sprache, Bedienhilfen & Klangkulisse"
|
||||
if is_de
|
||||
else "Language, UI Helpers & Audio"
|
||||
)
|
||||
|
||||
title_ph = self.assets.get_goth_text_photo(
|
||||
dlg_title,
|
||||
t("settings_title"),
|
||||
size_px=FONT_SIZE_TITLE_LG - 2,
|
||||
color=FONT_COLOR_TITLE_MAIN,
|
||||
max_width=w - 60,
|
||||
)
|
||||
sub_ph = self.assets.get_goth_text_photo(
|
||||
dlg_sub,
|
||||
t("settings_subtitle"),
|
||||
size_px=FONT_SIZE_SMALL_MIN,
|
||||
color=FONT_COLOR_BODY_MUTED,
|
||||
max_width=w - 70,
|
||||
)
|
||||
self._photo_refs.extend([title_ph, sub_ph])
|
||||
self.create_image(w // 2, 40, image=title_ph, anchor="center")
|
||||
self.create_image(w // 2, 70, image=sub_ph, anchor="center")
|
||||
self.create_image(w // 2, 36, image=title_ph, anchor="center")
|
||||
self.create_image(w // 2, 64, image=sub_ph, anchor="center")
|
||||
|
||||
# 3. Sprach-Box
|
||||
self._create_language_box(cy=128, is_de=is_de)
|
||||
self._create_language_box(cy=118)
|
||||
|
||||
# 4. Hover-Hilfetext-Switch-Box (mit animiertem GothSwitch)
|
||||
self._create_hover_help_switch_box(cy=214, is_de=is_de)
|
||||
# 4. Zwei Bedienhilfe-Switches (Hover-Hilfetexte & Einfacher Klick zum Schieben)
|
||||
self._create_switch_box(
|
||||
cy=196,
|
||||
title_txt=t("settings_hover_help_title"),
|
||||
desc_txt=t("settings_hover_help_desc"),
|
||||
initial_state=is_button_hover_help_enabled(),
|
||||
on_toggle=lambda state: set_button_hover_help_enabled(state, persist=True),
|
||||
)
|
||||
self._create_switch_box(
|
||||
cy=274,
|
||||
title_txt=t("settings_single_tap_title"),
|
||||
desc_txt=t("settings_single_tap_desc"),
|
||||
initial_state=is_single_tap_to_move_enabled(),
|
||||
on_toggle=lambda state: set_single_tap_to_move_enabled(state, persist=True),
|
||||
)
|
||||
|
||||
# 5. Zwei Audio-Slider-Boxen
|
||||
self._create_goth_slider(
|
||||
key="amb",
|
||||
cy=320,
|
||||
cy=372,
|
||||
label_txt=t("audio_ambiance_label"),
|
||||
desc_txt=t("audio_ambiance_desc"),
|
||||
initial_vol=self.sound_mgr.ambiance_volume,
|
||||
|
|
@ -170,7 +180,7 @@ class AudioSettingsDialog(tk.Canvas):
|
|||
)
|
||||
self._create_goth_slider(
|
||||
key="sfx",
|
||||
cy=438,
|
||||
cy=482,
|
||||
label_txt=t("audio_sfx_label"),
|
||||
desc_txt=t("audio_sfx_desc"),
|
||||
initial_vol=self.sound_mgr.menu_volume,
|
||||
|
|
@ -204,15 +214,15 @@ class AudioSettingsDialog(tk.Canvas):
|
|||
height=40,
|
||||
style="fire",
|
||||
)
|
||||
self.create_window(42, h - 46, window=btn_test, anchor="w")
|
||||
self.create_window(w - 42, h - 46, window=btn_done, anchor="e")
|
||||
self.create_window(42, h - 44, window=btn_test, anchor="w")
|
||||
self.create_window(w - 42, h - 44, window=btn_done, anchor="e")
|
||||
|
||||
self.bind("<ButtonPress-1>", self._on_mouse_down)
|
||||
self.bind("<B1-Motion>", self._on_mouse_drag)
|
||||
self.bind("<ButtonRelease-1>", lambda _e: setattr(self, "_dragging_key", None))
|
||||
|
||||
def _create_language_box(self, cy: int, is_de: bool):
|
||||
box_w, box_h = self.DLG_W - 72, 74
|
||||
def _create_language_box(self, cy: int):
|
||||
box_w, box_h = self.DLG_W - 72, 68
|
||||
cx = self.DLG_W // 2
|
||||
x_left = cx - box_w // 2 + 22
|
||||
x_right = cx + box_w // 2 - 20
|
||||
|
|
@ -222,33 +232,29 @@ class AudioSettingsDialog(tk.Canvas):
|
|||
self._photo_refs.append(sec_box)
|
||||
self.create_image(cx, cy, image=sec_box, anchor="center")
|
||||
|
||||
lang_heading = "Sprache" if is_de else "Language"
|
||||
lang_desc = "Anzeigesprache wechseln" if is_de else "Switch display language"
|
||||
|
||||
lbl_ph = self.assets.get_goth_text_photo(
|
||||
lang_heading,
|
||||
t("settings_lang_title"),
|
||||
size_px=FONT_SIZE_HEADING - 4,
|
||||
color=FONT_COLOR_BODY_DEFAULT,
|
||||
align="left",
|
||||
)
|
||||
desc_ph = self.assets.get_goth_text_photo(
|
||||
lang_desc,
|
||||
t("settings_lang_desc"),
|
||||
size_px=FONT_SIZE_SMALL_MIN,
|
||||
color=FONT_COLOR_BODY_MUTED,
|
||||
max_width=box_w - 180,
|
||||
align="left",
|
||||
)
|
||||
self._photo_refs.extend([lbl_ph, desc_ph])
|
||||
self.create_image(x_left, cy - 12, image=lbl_ph, anchor="w")
|
||||
self.create_image(x_left, cy + 13, image=desc_ph, anchor="w")
|
||||
self.create_image(x_left, cy - 11, image=lbl_ph, anchor="w")
|
||||
self.create_image(x_left, cy + 12, image=desc_ph, anchor="w")
|
||||
|
||||
btn_norm = self.assets.raw_btn_default
|
||||
btn_purp = self.assets.raw_btn_purple
|
||||
lang_btn_txt = "Deutsch - EN" if is_de else "English - DE"
|
||||
|
||||
btn_lang = ImageButton(
|
||||
self,
|
||||
lang_btn_txt,
|
||||
t("settings_lang_btn_toggle"),
|
||||
btn_norm,
|
||||
btn_purp,
|
||||
self._handle_language_toggle,
|
||||
|
|
@ -260,8 +266,15 @@ class AudioSettingsDialog(tk.Canvas):
|
|||
)
|
||||
self.create_window(x_right, cy, window=btn_lang, anchor="e")
|
||||
|
||||
def _create_hover_help_switch_box(self, cy: int, is_de: bool):
|
||||
box_w, box_h = self.DLG_W - 72, 76
|
||||
def _create_switch_box(
|
||||
self,
|
||||
cy: int,
|
||||
title_txt: str,
|
||||
desc_txt: str,
|
||||
initial_state: bool,
|
||||
on_toggle,
|
||||
):
|
||||
box_w, box_h = self.DLG_W - 72, 70
|
||||
cx = self.DLG_W // 2
|
||||
x_left = cx - box_w // 2 + 22
|
||||
x_right = cx + box_w // 2 - 20
|
||||
|
|
@ -271,36 +284,25 @@ class AudioSettingsDialog(tk.Canvas):
|
|||
self._photo_refs.append(sec_box)
|
||||
self.create_image(cx, cy, image=sec_box, anchor="center")
|
||||
|
||||
sw_title = (
|
||||
"Hilfe Texte bei Buttons Anzeigen"
|
||||
if is_de
|
||||
else "Show Help Texts on Button Hover"
|
||||
)
|
||||
sw_desc = (
|
||||
"Erklärungen beim Überfahren von Aktions-Buttons"
|
||||
if is_de
|
||||
else "Display explanations when hovering action buttons"
|
||||
)
|
||||
|
||||
lbl_ph = self.assets.get_goth_text_photo(
|
||||
sw_title,
|
||||
title_txt,
|
||||
size_px=FONT_SIZE_BODY + 1,
|
||||
color=FONT_COLOR_BODY_DEFAULT,
|
||||
max_width=box_w - 144,
|
||||
align="left",
|
||||
)
|
||||
desc_ph = self.assets.get_goth_text_photo(
|
||||
sw_desc,
|
||||
desc_txt,
|
||||
size_px=FONT_SIZE_SMALL_MIN,
|
||||
color=FONT_COLOR_BODY_MUTED,
|
||||
max_width=box_w - 144,
|
||||
align="left",
|
||||
)
|
||||
self._photo_refs.extend([lbl_ph, desc_ph])
|
||||
self.create_image(x_left, cy - 12, image=lbl_ph, anchor="w")
|
||||
self.create_image(x_left, cy + 14, image=desc_ph, anchor="w")
|
||||
self.create_image(x_left, cy - 11, image=lbl_ph, anchor="w")
|
||||
self.create_image(x_left, cy + 13, image=desc_ph, anchor="w")
|
||||
|
||||
sw_w, sw_h = 92, 40
|
||||
sw_w, sw_h = 92, 38
|
||||
sw_cx = x_right - sw_w // 2
|
||||
patch_ph = self._crop_dialog_bg_patch(sw_cx, cy, sw_w, sw_h)
|
||||
if patch_ph is not None:
|
||||
|
|
@ -308,8 +310,8 @@ class AudioSettingsDialog(tk.Canvas):
|
|||
|
||||
switch_wgt = GothSwitch(
|
||||
self,
|
||||
value=is_button_hover_help_enabled(),
|
||||
on_change=lambda state: set_button_hover_help_enabled(state, persist=True),
|
||||
value=initial_state,
|
||||
on_change=on_toggle,
|
||||
sound_mgr=self.sound_mgr,
|
||||
width=sw_w,
|
||||
height=sw_h,
|
||||
|
|
@ -345,7 +347,7 @@ class AudioSettingsDialog(tk.Canvas):
|
|||
initial_vol: float,
|
||||
on_change,
|
||||
):
|
||||
box_w, box_h = self.DLG_W - 72, 104
|
||||
box_w, box_h = self.DLG_W - 72, 98
|
||||
cx = self.DLG_W // 2
|
||||
x_left = cx - box_w // 2 + 22
|
||||
x_right = cx + box_w // 2 - 22
|
||||
|
|
@ -369,12 +371,12 @@ class AudioSettingsDialog(tk.Canvas):
|
|||
align="left",
|
||||
)
|
||||
self._photo_refs.extend([lbl_ph, desc_ph])
|
||||
self.create_image(x_left, cy - 28, image=lbl_ph, anchor="w")
|
||||
self.create_image(x_left, cy - 4, image=desc_ph, anchor="w")
|
||||
self.create_image(x_left, cy - 26, image=lbl_ph, anchor="w")
|
||||
self.create_image(x_left, cy - 3, image=desc_ph, anchor="w")
|
||||
|
||||
pct_item = self.create_image(x_right, cy - 28, anchor="e")
|
||||
pct_item = self.create_image(x_right, cy - 26, anchor="e")
|
||||
|
||||
track_y = cy + 26
|
||||
track_y = cy + 24
|
||||
track_x1 = x_left + 4
|
||||
track_x2 = x_right - 4
|
||||
self.create_rectangle(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,381 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# view/widgets/endgame_fx_overlay.py
|
||||
from __future__ import annotations
|
||||
|
||||
import random
|
||||
import time
|
||||
import tkinter as tk
|
||||
from collections import deque
|
||||
|
||||
from resources.code_res.game_constants import (
|
||||
FONT_COLOR_TITLE_MAIN,
|
||||
FONT_SIZE_SMALL_MIN,
|
||||
)
|
||||
from resources.code_res.i18n import t
|
||||
from view.widgets.modal_veil import ModalVeil
|
||||
|
||||
|
||||
class EndgameFxOverlay:
|
||||
"""
|
||||
Vorschalt-Animation bei Spielende über dem gesperrten, abgedunkelten Spieltisch:
|
||||
- Sieg ('win'): 'firework_start.gif' unten links + zufällig über den Bildschirm
|
||||
verteilte 'bat_explosion.gif' & 'pumpkin_explosion.gif' an wechselnden Punkten.
|
||||
- Niederlage ('lose'): 'foul_pumpkin.gif' zufällig über den Bildschirm verteilt.
|
||||
- Erst nach einem Klick (oder Space/Enter/Esc) geht es weiter zum Ergebnis-Screen.
|
||||
"""
|
||||
|
||||
GRACE_SEC = 0.20
|
||||
FX_TAG = "endgame_fx_item"
|
||||
HINT_TAG = "endgame_fx_hint"
|
||||
_SEQ = 0
|
||||
|
||||
@classmethod
|
||||
def play(
|
||||
cls,
|
||||
root: tk.Misc,
|
||||
assets,
|
||||
outcome: str | bool | None,
|
||||
on_continue,
|
||||
target_canvas: tk.Canvas | None = None,
|
||||
) -> "EndgameFxOverlay | None":
|
||||
if outcome is True:
|
||||
mode = "win"
|
||||
elif outcome is False:
|
||||
mode = "lose"
|
||||
elif isinstance(outcome, str) and outcome.lower() in ("win", "lose"):
|
||||
mode = outcome.lower()
|
||||
else:
|
||||
on_continue()
|
||||
return None
|
||||
|
||||
return cls(root, assets, mode, on_continue, target_canvas=target_canvas)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
root: tk.Misc,
|
||||
assets,
|
||||
mode: str,
|
||||
on_continue,
|
||||
target_canvas: tk.Canvas | None = None,
|
||||
):
|
||||
EndgameFxOverlay._SEQ += 1
|
||||
self._id = EndgameFxOverlay._SEQ
|
||||
self.root = root.winfo_toplevel()
|
||||
self.assets = assets
|
||||
self.mode = mode
|
||||
self.on_continue = on_continue
|
||||
|
||||
self._finished = False
|
||||
self._armed_press = False
|
||||
self._start_ts = time.monotonic()
|
||||
self._jobs: set[str] = set()
|
||||
self._active_spots: dict[int, tuple[int, int, int]] = {}
|
||||
self._recent_spots: deque[tuple[int, int]] = deque(maxlen=5)
|
||||
self._photo_refs: list = []
|
||||
|
||||
self._click_tag = f"EndgameClickTag_{self._id}"
|
||||
self._tagged_widgets: list[tk.Misc] = []
|
||||
|
||||
self._veil = ModalVeil(
|
||||
self.root,
|
||||
self.assets,
|
||||
modal_widget=None,
|
||||
target_canvas=target_canvas,
|
||||
dim_alpha=136,
|
||||
)
|
||||
self.canvas = self._veil.canvas
|
||||
|
||||
if self.canvas is None or not self._has_any_frames():
|
||||
self._veil.release()
|
||||
self.on_continue()
|
||||
return
|
||||
|
||||
self._install_click_catcher()
|
||||
self._draw_continue_banner()
|
||||
self._start_choreography()
|
||||
|
||||
def _has_any_frames(self) -> bool:
|
||||
probe_name = "firework_start" if self.mode == "win" else "foul_pumpkin"
|
||||
frames, _ = self.assets.get_win_lose_gif_sequence(probe_name, (160, 160))
|
||||
return bool(frames)
|
||||
|
||||
def _schedule(self, delay_ms: int, fn, *args) -> str | None:
|
||||
if self._finished:
|
||||
return None
|
||||
job_holder: list[str] = []
|
||||
|
||||
def _wrapped():
|
||||
if job_holder:
|
||||
self._jobs.discard(job_holder[0])
|
||||
if not self._finished and self._canvas_ok():
|
||||
fn(*args)
|
||||
|
||||
try:
|
||||
jid = self.root.after(max(1, int(delay_ms)), _wrapped)
|
||||
job_holder.append(jid)
|
||||
self._jobs.add(jid)
|
||||
return jid
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
def _canvas_ok(self) -> bool:
|
||||
try:
|
||||
return bool(self.canvas is not None and self.canvas.winfo_exists())
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# KLICK-FÄNGER ÜBER DEM GESAMTEN FENSTER
|
||||
# ------------------------------------------------------------------
|
||||
def _install_click_catcher(self):
|
||||
for seq in ("<Enter>", "<Motion>", "<B1-Motion>", "<Double-Button-1>", "<MouseWheel>"):
|
||||
self.root.bind_class(self._click_tag, seq, lambda _e: "break")
|
||||
self.root.bind_class(self._click_tag, "<ButtonPress-1>", self._on_press)
|
||||
self.root.bind_class(self._click_tag, "<ButtonRelease-1>", self._on_release)
|
||||
self.root.bind_class(self._click_tag, "<ButtonPress-3>", self._on_press)
|
||||
self.root.bind_class(self._click_tag, "<ButtonRelease-3>", self._on_release)
|
||||
self.root.bind_class(self._click_tag, "<KeyPress>", self._on_key)
|
||||
|
||||
self._tag_tree(self.root)
|
||||
|
||||
def _tag_tree(self, node: tk.Misc):
|
||||
try:
|
||||
tags = list(node.bindtags())
|
||||
if self._click_tag not in tags:
|
||||
node.bindtags((self._click_tag, *tags))
|
||||
self._tagged_widgets.append(node)
|
||||
for child in node.winfo_children():
|
||||
self._tag_tree(child)
|
||||
except tk.TclError:
|
||||
pass
|
||||
|
||||
def _on_press(self, _event=None):
|
||||
if (time.monotonic() - self._start_ts) >= self.GRACE_SEC:
|
||||
self._armed_press = True
|
||||
return "break"
|
||||
|
||||
def _on_release(self, _event=None):
|
||||
if self._armed_press and (time.monotonic() - self._start_ts) >= self.GRACE_SEC:
|
||||
self.finish()
|
||||
return "break"
|
||||
|
||||
def _on_key(self, event):
|
||||
if (time.monotonic() - self._start_ts) >= self.GRACE_SEC:
|
||||
if event.keysym in ("space", "Return", "KP_Enter", "Escape"):
|
||||
self.finish()
|
||||
return "break"
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# HINWEIS-BANNER ("Klicken zum Fortfahren")
|
||||
# ------------------------------------------------------------------
|
||||
def _draw_continue_banner(self):
|
||||
if not self._canvas_ok():
|
||||
return
|
||||
cw = max(320, self.canvas.winfo_width())
|
||||
ch = max(240, self.canvas.winfo_height())
|
||||
|
||||
txt_ph = self.assets.get_goth_text_photo(
|
||||
t("endgame_click_continue"),
|
||||
FONT_SIZE_SMALL_MIN + 2,
|
||||
FONT_COLOR_TITLE_MAIN,
|
||||
)
|
||||
bw = txt_ph.width() + 54
|
||||
bh = max(38, txt_ph.height() + 14)
|
||||
box_ph = self.assets.get_box_photo("box_purple", (bw, bh))
|
||||
self._photo_refs.extend([txt_ph, box_ph] if box_ph else [txt_ph])
|
||||
|
||||
cx = cw // 2
|
||||
cy = ch - bh // 2 - 14
|
||||
if box_ph:
|
||||
self.canvas.create_image(cx, cy, image=box_ph, anchor="center", tags=(self.FX_TAG, self.HINT_TAG))
|
||||
self.canvas.create_image(cx, cy, image=txt_ph, anchor="center", tags=(self.FX_TAG, self.HINT_TAG))
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# WIN / LOSE PARTIKEL-CHOREOGRAFIE
|
||||
# ------------------------------------------------------------------
|
||||
def _start_choreography(self):
|
||||
if self.mode == "win":
|
||||
self._launch_firework_bottom_left()
|
||||
self._schedule(260, self._win_explosion_wave, True)
|
||||
else:
|
||||
self._schedule(50, self._lose_pumpkin_wave, True)
|
||||
|
||||
def _launch_firework_bottom_left(self):
|
||||
if self._finished or not self._canvas_ok():
|
||||
return
|
||||
cw = max(320, self.canvas.winfo_width())
|
||||
ch = max(240, self.canvas.winfo_height())
|
||||
fw_sz = max(175, min(285, int(min(cw, ch) * 0.38)))
|
||||
frames, durs = self.assets.get_win_lose_gif_sequence("firework_start", (fw_sz, fw_sz))
|
||||
if not frames:
|
||||
return
|
||||
|
||||
item_id = self.canvas.create_image(
|
||||
14, ch,
|
||||
image=frames[0],
|
||||
anchor="sw",
|
||||
tags=(self.FX_TAG,),
|
||||
)
|
||||
self.canvas.tag_raise(self.HINT_TAG)
|
||||
|
||||
def _step_fw(idx: int):
|
||||
if self._finished or not self._canvas_ok():
|
||||
return
|
||||
if idx >= len(frames):
|
||||
try:
|
||||
self.canvas.delete(item_id)
|
||||
except Exception:
|
||||
pass
|
||||
# Neue Salve nach kurzer Feuerpause starten
|
||||
self._schedule(780, self._launch_firework_bottom_left)
|
||||
return
|
||||
self.canvas.itemconfigure(item_id, image=frames[idx])
|
||||
self._schedule(durs[idx], _step_fw, idx + 1)
|
||||
|
||||
self._schedule(durs[0], _step_fw, 1)
|
||||
|
||||
def _pick_random_spot(self, size_px: int, avoid_bottom_left: bool) -> tuple[int, int]:
|
||||
cw = max(360, self.canvas.winfo_width())
|
||||
ch = max(260, self.canvas.winfo_height())
|
||||
half = size_px // 2
|
||||
x_min = half + 18
|
||||
x_max = max(x_min + 20, cw - half - 18)
|
||||
y_min = half + 14
|
||||
y_max = max(y_min + 20, ch - half - 64)
|
||||
|
||||
best_xy = (random.randint(x_min, x_max), random.randint(y_min, y_max))
|
||||
min_dist_sq = int((size_px * 0.78) ** 2)
|
||||
|
||||
for _ in range(18):
|
||||
rx = random.randint(x_min, x_max)
|
||||
ry = random.randint(y_min, y_max)
|
||||
|
||||
# Unten links Platz für die Raketen-Abschussrampe lassen
|
||||
if avoid_bottom_left and rx < int(cw * 0.28) and ry > int(ch * 0.56):
|
||||
continue
|
||||
|
||||
too_close = False
|
||||
for ax, ay, _asz in self._active_spots.values():
|
||||
if (rx - ax) ** 2 + (ry - ay) ** 2 < min_dist_sq:
|
||||
too_close = True
|
||||
break
|
||||
if not too_close:
|
||||
for px, py in self._recent_spots:
|
||||
if (rx - px) ** 2 + (ry - py) ** 2 < int(min_dist_sq * 0.65):
|
||||
too_close = True
|
||||
break
|
||||
|
||||
if not too_close:
|
||||
best_xy = (rx, ry)
|
||||
break
|
||||
|
||||
self._recent_spots.append(best_xy)
|
||||
return best_xy
|
||||
|
||||
def _spawn_one_shot_sprite(self, gif_name: str, scale_factor: float, avoid_bottom_left: bool):
|
||||
if self._finished or not self._canvas_ok():
|
||||
return
|
||||
cw = max(360, self.canvas.winfo_width())
|
||||
ch = max(260, self.canvas.winfo_height())
|
||||
sz = max(125, min(250, int(min(cw, ch) * scale_factor)))
|
||||
frames, durs = self.assets.get_win_lose_gif_sequence(gif_name, (sz, sz))
|
||||
if not frames:
|
||||
return
|
||||
|
||||
sx, sy = self._pick_random_spot(sz, avoid_bottom_left=avoid_bottom_left)
|
||||
item_id = self.canvas.create_image(
|
||||
sx, sy,
|
||||
image=frames[0],
|
||||
anchor="center",
|
||||
tags=(self.FX_TAG,),
|
||||
)
|
||||
self._active_spots[item_id] = (sx, sy, sz)
|
||||
self.canvas.tag_raise(self.HINT_TAG)
|
||||
|
||||
def _step_sprite(idx: int):
|
||||
if self._finished or not self._canvas_ok():
|
||||
return
|
||||
if idx >= len(frames):
|
||||
self._active_spots.pop(item_id, None)
|
||||
try:
|
||||
self.canvas.delete(item_id)
|
||||
except Exception:
|
||||
pass
|
||||
return
|
||||
self.canvas.itemconfigure(item_id, image=frames[idx])
|
||||
self._schedule(durs[idx], _step_sprite, idx + 1)
|
||||
|
||||
self._schedule(durs[0], _step_sprite, 1)
|
||||
|
||||
def _win_explosion_wave(self, initial_burst: bool = False):
|
||||
if self._finished or not self._canvas_ok():
|
||||
return
|
||||
scales = (0.24, 0.29, 0.34)
|
||||
if initial_burst:
|
||||
for extra_delay in (0, 140):
|
||||
chosen = random.choice(("bat_explosion", "pumpkin_explosion"))
|
||||
sc = random.choice(scales)
|
||||
if extra_delay == 0:
|
||||
self._spawn_one_shot_sprite(chosen, sc, avoid_bottom_left=True)
|
||||
else:
|
||||
self._schedule(extra_delay, self._spawn_one_shot_sprite, chosen, sc, True)
|
||||
elif len(self._active_spots) < 4:
|
||||
chosen = random.choice(("bat_explosion", "pumpkin_explosion"))
|
||||
self._spawn_one_shot_sprite(chosen, random.choice(scales), avoid_bottom_left=True)
|
||||
|
||||
self._schedule(random.randint(250, 420), self._win_explosion_wave, False)
|
||||
|
||||
def _lose_pumpkin_wave(self, initial_burst: bool = False):
|
||||
if self._finished or not self._canvas_ok():
|
||||
return
|
||||
scales = (0.23, 0.28, 0.33)
|
||||
if initial_burst:
|
||||
self._spawn_one_shot_sprite("foul_pumpkin", 0.29, avoid_bottom_left=False)
|
||||
self._schedule(190, self._spawn_one_shot_sprite, "foul_pumpkin", 0.24, False)
|
||||
elif len(self._active_spots) < 3:
|
||||
self._spawn_one_shot_sprite("foul_pumpkin", random.choice(scales), avoid_bottom_left=False)
|
||||
|
||||
self._schedule(random.randint(330, 510), self._lose_pumpkin_wave, False)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# SAUBERES AUFRÄUMEN & ÜBERGANG ZUM RESULT-SCREEN
|
||||
# ------------------------------------------------------------------
|
||||
def cancel(self):
|
||||
self._cleanup_only()
|
||||
|
||||
def _cleanup_only(self):
|
||||
if self._finished:
|
||||
return
|
||||
self._finished = True
|
||||
|
||||
for jid in list(self._jobs):
|
||||
try:
|
||||
self.root.after_cancel(jid)
|
||||
except Exception:
|
||||
pass
|
||||
self._jobs.clear()
|
||||
self._active_spots.clear()
|
||||
self._photo_refs.clear()
|
||||
|
||||
if self._canvas_ok():
|
||||
try:
|
||||
self.canvas.delete(self.FX_TAG)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
for w in self._tagged_widgets:
|
||||
try:
|
||||
if w.winfo_exists():
|
||||
tags = [tg for tg in w.bindtags() if tg != self._click_tag]
|
||||
w.bindtags(tuple(tags))
|
||||
except Exception:
|
||||
pass
|
||||
self._tagged_widgets.clear()
|
||||
self._veil.release()
|
||||
|
||||
def finish(self):
|
||||
if self._finished:
|
||||
return
|
||||
self._cleanup_only()
|
||||
if callable(self.on_continue):
|
||||
self.on_continue()
|
||||
|
|
@ -0,0 +1,218 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# view/widgets/modal_veil.py
|
||||
from __future__ import annotations
|
||||
|
||||
import tkinter as tk
|
||||
|
||||
|
||||
class ModalVeil:
|
||||
"""
|
||||
Universeller Modal-Blocker & Abdunklungs-Schleier:
|
||||
- Legt einen halbtransparenten RGBA-Schleier über das aktive Spielfeld-Canvas,
|
||||
sodass Karten/Chips darunter ausgegraut sichtbar bleiben.
|
||||
- Hebt das übergebene Modal-Fenster über alle UI-Leisten (Topbar, Bottom-Bar, Tisch).
|
||||
- Blockiert sämtliche Klicks, Hover-Events und Tastenkürzel außerhalb des Modals.
|
||||
"""
|
||||
|
||||
_SEQ_COUNTER = 0
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
root: tk.Misc,
|
||||
assets,
|
||||
modal_widget: tk.Widget | None = None,
|
||||
target_canvas: tk.Canvas | None = None,
|
||||
dim_alpha: int = 148,
|
||||
):
|
||||
ModalVeil._SEQ_COUNTER += 1
|
||||
self._id = ModalVeil._SEQ_COUNTER
|
||||
self.root = root.winfo_toplevel()
|
||||
self.assets = assets
|
||||
self.modal_widget = modal_widget
|
||||
self.dim_alpha = dim_alpha
|
||||
self._veil_tag = f"modal_dim_veil_{self._id}"
|
||||
self._block_tag = f"ModalBlockTag_{self._id}"
|
||||
self._released = False
|
||||
self._tagged_widgets: list[tk.Misc] = []
|
||||
self._cfg_bind_id: str | None = None
|
||||
self._resize_job: str | None = None
|
||||
|
||||
self.canvas = target_canvas or self._find_play_canvas()
|
||||
self._draw_veil()
|
||||
self._install_input_lock()
|
||||
|
||||
if self.modal_widget is not None:
|
||||
tk.Widget.tkraise(self.modal_widget)
|
||||
self.modal_widget.bind("<Destroy>", self._on_modal_destroy, add="+")
|
||||
|
||||
try:
|
||||
self._cfg_bind_id = self.root.bind("<Configure>", self._on_root_configure, add="+")
|
||||
except tk.TclError:
|
||||
self._cfg_bind_id = None
|
||||
|
||||
def _find_play_canvas(self) -> tk.Canvas | None:
|
||||
best: tk.Canvas | None = None
|
||||
best_area = 0
|
||||
candidates = list(self.root.winfo_children())
|
||||
for child in list(candidates):
|
||||
if isinstance(child, tk.Frame):
|
||||
candidates.extend(child.winfo_children())
|
||||
|
||||
for w in candidates:
|
||||
if w is self.modal_widget or not isinstance(w, tk.Canvas):
|
||||
continue
|
||||
try:
|
||||
if not w.winfo_ismapped():
|
||||
continue
|
||||
cw, ch = w.winfo_width(), w.winfo_height()
|
||||
except tk.TclError:
|
||||
continue
|
||||
if ch < 150:
|
||||
continue
|
||||
area = cw * ch
|
||||
if area > best_area:
|
||||
best_area = area
|
||||
best = w
|
||||
return best
|
||||
|
||||
def _is_inside_modal(self, widget: tk.Misc | None) -> bool:
|
||||
if self.modal_widget is None or widget is None:
|
||||
return False
|
||||
cur: tk.Misc | None = widget
|
||||
while cur is not None:
|
||||
if cur is self.modal_widget:
|
||||
return True
|
||||
cur = getattr(cur, "master", None)
|
||||
return False
|
||||
|
||||
def _consume_event(self, event):
|
||||
if self._is_inside_modal(getattr(event, "widget", None)):
|
||||
return None
|
||||
return "break"
|
||||
|
||||
def _install_input_lock(self):
|
||||
blocked_seqs = (
|
||||
"<ButtonPress-1>",
|
||||
"<ButtonRelease-1>",
|
||||
"<ButtonPress-2>",
|
||||
"<ButtonPress-3>",
|
||||
"<ButtonRelease-3>",
|
||||
"<Double-Button-1>",
|
||||
"<B1-Motion>",
|
||||
"<Enter>",
|
||||
"<Motion>",
|
||||
"<MouseWheel>",
|
||||
"<KeyPress>",
|
||||
)
|
||||
for seq in blocked_seqs:
|
||||
try:
|
||||
self.root.bind_class(self._block_tag, seq, self._consume_event)
|
||||
except tk.TclError:
|
||||
pass
|
||||
|
||||
self._apply_block_tag_recursive(self.root)
|
||||
|
||||
def _apply_block_tag_recursive(self, node: tk.Misc):
|
||||
if node is self.modal_widget:
|
||||
return
|
||||
try:
|
||||
tags = list(node.bindtags())
|
||||
if self._block_tag not in tags:
|
||||
node.bindtags((self._block_tag, *tags))
|
||||
self._tagged_widgets.append(node)
|
||||
for child in node.winfo_children():
|
||||
self._apply_block_tag_recursive(child)
|
||||
except tk.TclError:
|
||||
pass
|
||||
|
||||
def _draw_veil(self):
|
||||
if self._released or self.canvas is None or self.assets is None:
|
||||
return
|
||||
try:
|
||||
if not self.canvas.winfo_exists():
|
||||
return
|
||||
cw = max(64, self.canvas.winfo_width())
|
||||
ch = max(64, self.canvas.winfo_height())
|
||||
self.canvas.delete(self._veil_tag)
|
||||
veil_ph = self.assets.get_dim_veil_photo(cw, ch, alpha=self.dim_alpha)
|
||||
self.canvas.create_image(
|
||||
0, 0,
|
||||
image=veil_ph,
|
||||
anchor="nw",
|
||||
tags=("modal_dim_veil", self._veil_tag),
|
||||
)
|
||||
self.canvas.tag_raise(self._veil_tag)
|
||||
except tk.TclError:
|
||||
pass
|
||||
|
||||
def _on_root_configure(self, _event=None):
|
||||
if self._released:
|
||||
return
|
||||
if self.modal_widget is not None:
|
||||
try:
|
||||
if self.modal_widget.winfo_exists():
|
||||
tk.Widget.tkraise(self.modal_widget)
|
||||
except tk.TclError:
|
||||
pass
|
||||
if self._resize_job is not None:
|
||||
try:
|
||||
self.root.after_cancel(self._resize_job)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
self._resize_job = self.root.after(60, self._refresh_after_resize)
|
||||
except Exception:
|
||||
self._resize_job = None
|
||||
|
||||
def _refresh_after_resize(self):
|
||||
self._resize_job = None
|
||||
if self._released:
|
||||
return
|
||||
self._draw_veil()
|
||||
self._apply_block_tag_recursive(self.root)
|
||||
if self.modal_widget is not None:
|
||||
try:
|
||||
if self.modal_widget.winfo_exists():
|
||||
tk.Widget.tkraise(self.modal_widget)
|
||||
except tk.TclError:
|
||||
pass
|
||||
|
||||
def _on_modal_destroy(self, event=None):
|
||||
if event is not None and event.widget is not self.modal_widget:
|
||||
return
|
||||
self.release()
|
||||
|
||||
def release(self):
|
||||
if self._released:
|
||||
return
|
||||
self._released = True
|
||||
|
||||
if self._resize_job is not None:
|
||||
try:
|
||||
self.root.after_cancel(self._resize_job)
|
||||
except Exception:
|
||||
pass
|
||||
self._resize_job = None
|
||||
|
||||
if self._cfg_bind_id is not None:
|
||||
try:
|
||||
self.root.unbind("<Configure>", self._cfg_bind_id)
|
||||
except Exception:
|
||||
pass
|
||||
self._cfg_bind_id = None
|
||||
|
||||
if self.canvas is not None:
|
||||
try:
|
||||
if self.canvas.winfo_exists():
|
||||
self.canvas.delete(self._veil_tag)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
for w in self._tagged_widgets:
|
||||
try:
|
||||
if w.winfo_exists():
|
||||
tags = [t for t in w.bindtags() if t != self._block_tag]
|
||||
w.bindtags(tuple(tags))
|
||||
except Exception:
|
||||
pass
|
||||
self._tagged_widgets.clear()
|
||||