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 <http://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
<http://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
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
Chip's Workshop 2 is a cross-platform level editor program for the game Chip's Challenge.
It has been tested on Linux and Windows, and should also work on Mac systems.
Bug reports
Chip's Workshop is still in the beta phase, and so it is likely to have quite a few bugs.
If something doesn't seem to work properly, please report the problem to
chipw@chrise.me.uk.
Getting started
When you run the Chip's Workshop program, you will be presented with an empty level editor window.
If you wish to create a new level set, choose New from the File menu.
To add your first level, click the + button on the left.
If you wish to open a level set, choose Open from the File menu.
You will be presented with a file dialog. When you open a file, no level will be initially
selected. Select the level you wish to edit in the list on the left.
Placing tiles
The level map appears to the right. If you move the mouse cursor over the map, the status bar at the bottom of the window will show
the coordinates of your location, and information about the tiles at that position.
To select a tile to place, click the Tiles tab at the bottom-left.
You may then choose the tile you want from the list. Then, click on the level map where you want to place the new tile.
The tile you place will, by default, become the only one in its location.
A map location may in fact contain up to two tiles: A "creature", and a "non-creature".
Chip, all monsters and blocks are considered to be creatures; all other tiles are non-creatures.
To place both tiles in a location, simply hold down the Shift key while placing the second tile.
It will automatically go into the correct layer for its type.
Use the "empty" tile to erase previously placed tiles.
By default, it will erase both tiles in the selected location.
If you wish to erase only the creature tile, hold down the Control key.
If you wish to erase only the non-creature tile, hold down the Shift key.
Connecting buttons
Trap and clone buttons need to be connected to their targets with wires in order to function.
When a trap or clone machine is placed, it is automatically selected (indicated by being displayed inverted).
Buttons placed of the appropriate type will then be automatically wired to the selected target.
Wires will, by default, be drawn on the level map, and you can see a list of wires connected to a tile by moving the mouse over it
and looking in the status bar.
If you wish to add or remove a wire later, choose the appropriate wire type (trap or clone) from the tile selector.
To add wires, click first on the trap or clone machine, then on each button that you wish to connect to it.
To remove the wires connected to a tile, hold down the Control key and click on the tile.
If you have a middle mouse button, you may alternatively hold down the Shift key and click with the middle mouse button to add wires,
or hold down the Control and Shift keys and click with the middle mouse button to remove wires.
This method can be used without first selecting the wire from the tile selector.
Map area selection
If you choose the "rectangle select" tool from the tile selector, you may click and drag to select a rectangular area of the level map.
To deselect the current area, hold down the Control key and click.
While an area is selected, any tiles placed within it will be applied to all selected locations.
This can be useful for filling a large area of the map with tiles such as water.
If you have a middle mouse button, you may use this for selection rather than choosing the "rectangle select" tool.
Level management
To view a list of all levels in the level set, click the Levels tab at the bottom-left of the window.
Click on a level in the list to select it for editing.
Use the + button above the list to create a new level.
If you wish to delete the current level, use the - button.
The ^ and v buttons may be used to change the order of the levels in the level set.
The ... button opens the level properties dialog. This can also be opened from the Edit menu.
This dialog enables you to change various level options, including the title, the password (click the button to randomly generate one),
the number of chips required (the number of chips in the level is automatically displayed below), the time limit (use 0 for no limit),
and the level hint.
You can also select the rule set that the level set is designed to be played in.
Note that this will be applied to all levels in the set.
If your level set is playable in both MS and Lynx rule sets, choose MS here.
Copy and paste
Entire levels and individual areas of the map may be transferred using the clipboard.
To copy an entire level to the clipboard, select it in the level list, ensure that no area of the map is selected, then choose Copy from the Edit menu.
To paste a level from the clipboard, select the level after which you want to insert it, then choose Paste from the Edit menu.
To copy a map area to the clipboard, select it and then choose Copy from the Edit menu.
To paste a map area from the clipboard, select the top-left corner of the destination area, then choose Paste from the Edit menu.
Cut may be used to remove the level or map area from its present location once it has been copied to the clipboard.
Undo and redo
You may reverse modifications to the level set by choosing Undo from the Edit menu.
You may reapply modifications that have been removed in this way by choosing Redo.
Customising the display
The View menu may be used to change various display options:
Show wires - uncheck this if the wires are obstructing your view of the level.
Show upper layer - uncheck this to hide the top tile from each location to provide a better view of buried tiles.
Select tileset - use this to choose a different set of tile images.
Scale tiles - use this to adjust the size of the tiles.
You can also create multiple windows for the same level set, each of which can have different view settings, and a different level selected.
Read-only mode
If you wish to view a level set without the risk of making accidental changes, you may turn on Read-only mode from the Edit menu.
Caution: Read-only selection is not supported directly from the file selector, although a checkbox may erroneously appear.
File management
The File menu enables you to create or open a new level set or save the current level set.
The default filename extension for saving level sets is set to ".ccl" - this is exactly the same file format as Microsoft Chip's
Challenge .dat files, but is more distinctive.
You can have multiple documents open at once, so opening a new level set will not cause the currently open one to close.
Note that the Close option on the File menu will close all editor windows for the current level set.
The Quit option will close all currently open level sets.
Playtesting
When working on a level, it is often helpful to be able to quickly start the game to see the effects of a change.
The Playtest menu allows you to start playing the currently selected level directly from the editor.
Currently this only works with Tile World, or other programs with the same command line interface.
In particular, chips.exe is not supported.
Caution: Solutions and scores achieved during playtesting will not be saved.
You must start the game in the normal manner from outside the editor if you wish to record solutions or keep track of scores.
Before you can start playtesting, you must set up a profile with the details of the program to use.
To do this, choose Configure from the Playtest menu, and then click Add in the dialog box that appears.
Enter a name for this playtesting option (this name will appear in the Playtest menu) and select the program to run.
You can also select a rule set that will be used for playtesting when this option is chosen.
Once you have entered the settings, you can use the Test button to see whether they work.
If the settings are correct, a simple level called TEST will open in the game.
When you are ready, click OK to add the playtesting profile to the list.
It is possible to add several profiles to the list, for instance one for the MS rule set and one for the Lynx rule set.
Note that when clicking Add, the currently selected profile (if any) will be copied into the dialog.
This may help when adding multiple similar profiles.
When finished, click OK to save the profiles.
Now you can start playtesting the current level by choosing the desired profile from the Playtest menu.
To start the game more quickly, you may use the keyboard shortcut Alt+P followed by the number of the profile to use.
Advanced options
Direct layer placement
The right mouse button can be used to create invalid combinations of tiles, such as a tile buried underneath a non-creature,
or a stack of two creatures.
By default, clicking with the right mouse button will cause the selected tile to be placed on the lower map layer, without affecting
the upper layer.
Hold down Shift to place the tile on the upper layer instead.
Stationary monsters
When a monster is selected, you may hold down the Control key while placing it to create an invalid stationary monster tile.
This looks like a normal monster, and will be fatal to Chip if he steps on it, but it will not move.
Note: This facility should not be used for making normal traps or clone machines.
Monster list editor
From the Edit menu, you can open the Monster list editor.
The current monster movement list will be shown at the top; the controls below can be used to edit the monster order, or add and remove monsters
from the list.
The bottom list shows locations containing monster tiles which have no entry on the monster list; if you select one of these, the coordinates will
automatically be filled in next to the Add button, ready to be added to the list.
Invalid wires
You may create a wire of either type between arbitrary map locations by selecting the wire type, holding down the Shift key and clicking with the
right mouse button where the "target" end of the wire should be, then releasing Shift and clicking with the right mouse button where the
"button" end of the wire should be. To place multiple wires of the same type in the same direction between the same two tiles, additionally
hold down the Control key.
Invalid tile IDs
Various tile ID codes can be placed into the level map which do not actually represent a real tile. Some of these can have corresponding images.
Chip's Workshop designates these as "[XX] invalid", where XX is the hexadecimal representation of the tile ID, followed by a description
of the image commonly associated with the ID, where there is one.
If you wish to place these invalid tile codes in your own levels, you may select any 8-bit tile code from the "IDs" tab on the left.
Advanced properties
The level properties dialog allows you to adjust a couple of extra values in the level set file:
Rule set:
You can enter a number, in decimal, octal (prefixed with 0) or hexadecimal (prefixed with 0x).
This will then be stored in the first 4 bytes of the level set file.
Internal level number:
This is the level number field appearing at the start of the level's data in the level set file.
It should generally be left equal to the position of the level in the sequence.
Licence terms
Chip's Workshop 2.0.6 is Copyright 2008-2011 Christopher Elsby.
This program is free software: you can redistribute it and/or modify
it under the terms of version 3 of the GNU General Public License as
published by the Free Software Foundation.
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.
chipw-2.0.6/AUTHORS 0000644 0001750 0001750 00000000146 11672412350 010624 0000000 0000000 Chip's Workshop code and documentation:
Christopher Elsby
Tile images:
Michael Hansen
Anders Kaseorg
chipw-2.0.6/missing 0000755 0001750 0001750 00000025577 11672412350 011172 0000000 0000000 #! /bin/sh
# Common stub for a few missing GNU programs while installing.
scriptversion=2006-05-10.23
# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006
# Free Software Foundation, Inc.
# Originally by Fran,cois Pinard , 1996.
# 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 2, 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
if test $# -eq 0; then
echo 1>&2 "Try \`$0 --help' for more information"
exit 1
fi
run=:
sed_output='s/.* --output[ =]\([^ ]*\).*/\1/p'
sed_minuso='s/.* -o \([^ ]*\).*/\1/p'
# In the cases where this matters, `missing' is being run in the
# srcdir already.
if test -f configure.ac; then
configure_ac=configure.ac
else
configure_ac=configure.in
fi
msg="missing on your system"
case $1 in
--run)
# Try to run requested program, and just exit if it succeeds.
run=
shift
"$@" && exit 0
# Exit code 63 means version mismatch. This often happens
# when the user try to use an ancient version of a tool on
# a file that requires a minimum version. In this case we
# we should proceed has if the program had been absent, or
# if --run hadn't been passed.
if test $? = 63; then
run=:
msg="probably too old"
fi
;;
-h|--h|--he|--hel|--help)
echo "\
$0 [OPTION]... PROGRAM [ARGUMENT]...
Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
error status if there is no known handling for PROGRAM.
Options:
-h, --help display this help and exit
-v, --version output version information and exit
--run try to run the given command, and emulate it if it fails
Supported PROGRAM values:
aclocal touch file \`aclocal.m4'
autoconf touch file \`configure'
autoheader touch file \`config.h.in'
autom4te touch the output file, or create a stub one
automake touch all \`Makefile.in' files
bison create \`y.tab.[ch]', if possible, from existing .[ch]
flex create \`lex.yy.c', if possible, from existing .c
help2man touch the output file
lex create \`lex.yy.c', if possible, from existing .c
makeinfo touch the output file
tar try tar, gnutar, gtar, then tar without non-portable flags
yacc create \`y.tab.[ch]', if possible, from existing .[ch]
Send bug reports to ."
exit $?
;;
-v|--v|--ve|--ver|--vers|--versi|--versio|--version)
echo "missing $scriptversion (GNU Automake)"
exit $?
;;
-*)
echo 1>&2 "$0: Unknown \`$1' option"
echo 1>&2 "Try \`$0 --help' for more information"
exit 1
;;
esac
# Now exit if we have it, but it failed. Also exit now if we
# don't have it and --version was passed (most likely to detect
# the program).
case $1 in
lex|yacc)
# Not GNU programs, they don't have --version.
;;
tar)
if test -n "$run"; then
echo 1>&2 "ERROR: \`tar' requires --run"
exit 1
elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
exit 1
fi
;;
*)
if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
# We have it, but it failed.
exit 1
elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
# Could not run --version or --help. This is probably someone
# running `$TOOL --version' or `$TOOL --help' to check whether
# $TOOL exists and not knowing $TOOL uses missing.
exit 1
fi
;;
esac
# If it does not exist, or fails to run (possibly an outdated version),
# try to emulate it.
case $1 in
aclocal*)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified \`acinclude.m4' or \`${configure_ac}'. You might want
to install the \`Automake' and \`Perl' packages. Grab them from
any GNU archive site."
touch aclocal.m4
;;
autoconf)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified \`${configure_ac}'. You might want to install the
\`Autoconf' and \`GNU m4' packages. Grab them from any GNU
archive site."
touch configure
;;
autoheader)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified \`acconfig.h' or \`${configure_ac}'. You might want
to install the \`Autoconf' and \`GNU m4' packages. Grab them
from any GNU archive site."
files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}`
test -z "$files" && files="config.h"
touch_files=
for f in $files; do
case $f in
*:*) touch_files="$touch_files "`echo "$f" |
sed -e 's/^[^:]*://' -e 's/:.*//'`;;
*) touch_files="$touch_files $f.in";;
esac
done
touch $touch_files
;;
automake*)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.
You might want to install the \`Automake' and \`Perl' packages.
Grab them from any GNU archive site."
find . -type f -name Makefile.am -print |
sed 's/\.am$/.in/' |
while read f; do touch "$f"; done
;;
autom4te)
echo 1>&2 "\
WARNING: \`$1' is needed, but is $msg.
You might have modified some files without having the
proper tools for further handling them.
You can get \`$1' as part of \`Autoconf' from any GNU
archive site."
file=`echo "$*" | sed -n "$sed_output"`
test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
if test -f "$file"; then
touch $file
else
test -z "$file" || exec >$file
echo "#! /bin/sh"
echo "# Created by GNU Automake missing as a replacement of"
echo "# $ $@"
echo "exit 0"
chmod +x $file
exit 1
fi
;;
bison|yacc)
echo 1>&2 "\
WARNING: \`$1' $msg. You should only need it if
you modified a \`.y' file. You may need the \`Bison' package
in order for those modifications to take effect. You can get
\`Bison' from any GNU archive site."
rm -f y.tab.c y.tab.h
if test $# -ne 1; then
eval LASTARG="\${$#}"
case $LASTARG in
*.y)
SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
if test -f "$SRCFILE"; then
cp "$SRCFILE" y.tab.c
fi
SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
if test -f "$SRCFILE"; then
cp "$SRCFILE" y.tab.h
fi
;;
esac
fi
if test ! -f y.tab.h; then
echo >y.tab.h
fi
if test ! -f y.tab.c; then
echo 'main() { return 0; }' >y.tab.c
fi
;;
lex|flex)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified a \`.l' file. You may need the \`Flex' package
in order for those modifications to take effect. You can get
\`Flex' from any GNU archive site."
rm -f lex.yy.c
if test $# -ne 1; then
eval LASTARG="\${$#}"
case $LASTARG in
*.l)
SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
if test -f "$SRCFILE"; then
cp "$SRCFILE" lex.yy.c
fi
;;
esac
fi
if test ! -f lex.yy.c; then
echo 'main() { return 0; }' >lex.yy.c
fi
;;
help2man)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified a dependency of a manual page. You may need the
\`Help2man' package in order for those modifications to take
effect. You can get \`Help2man' from any GNU archive site."
file=`echo "$*" | sed -n "$sed_output"`
test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
if test -f "$file"; then
touch $file
else
test -z "$file" || exec >$file
echo ".ab help2man is required to generate this page"
exit 1
fi
;;
makeinfo)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified a \`.texi' or \`.texinfo' file, or any other file
indirectly affecting the aspect of the manual. The spurious
call might also be the consequence of using a buggy \`make' (AIX,
DU, IRIX). You might want to install the \`Texinfo' package or
the \`GNU make' package. Grab either from any GNU archive site."
# The file to touch is that specified with -o ...
file=`echo "$*" | sed -n "$sed_output"`
test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
if test -z "$file"; then
# ... or it is the one specified with @setfilename ...
infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
file=`sed -n '
/^@setfilename/{
s/.* \([^ ]*\) *$/\1/
p
q
}' $infile`
# ... or it is derived from the source name (dir/f.texi becomes f.info)
test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info
fi
# If the file does not exist, the user really needs makeinfo;
# let's fail without touching anything.
test -f $file || exit 1
touch $file
;;
tar)
shift
# We have already tried tar in the generic part.
# Look for gnutar/gtar before invocation to avoid ugly error
# messages.
if (gnutar --version > /dev/null 2>&1); then
gnutar "$@" && exit 0
fi
if (gtar --version > /dev/null 2>&1); then
gtar "$@" && exit 0
fi
firstarg="$1"
if shift; then
case $firstarg in
*o*)
firstarg=`echo "$firstarg" | sed s/o//`
tar "$firstarg" "$@" && exit 0
;;
esac
case $firstarg in
*h*)
firstarg=`echo "$firstarg" | sed s/h//`
tar "$firstarg" "$@" && exit 0
;;
esac
fi
echo 1>&2 "\
WARNING: I can't seem to be able to run \`tar' with the given arguments.
You may want to install GNU tar or Free paxutils, or check the
command line arguments."
exit 1
;;
*)
echo 1>&2 "\
WARNING: \`$1' is needed, and is $msg.
You might have modified some files without having the
proper tools for further handling them. Check the \`README' file,
it often tells you about the needed prerequisites for installing
this package. You may also peek at any GNU archive site, in case
some other package would contain this missing \`$1' program."
exit 1
;;
esac
exit 0
# Local variables:
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-end: "$"
# End:
chipw-2.0.6/ChangeLog 0000644 0001750 0001750 00000004060 11672412350 011325 0000000 0000000 2011-12-15: version 2.0.6
* Fixed size type mismatch in ListMenuManager on 64-bit systems.
* Changed character encoding used for level titles, passwords and hints in Unicode builds from UTF-8 to ISO-8859-1.
* Added checks to avoid segmentation fault when character encoding conversion fails.
2010-08-12: version 2.0.5.1
* Added playtesting support (using Tile World)
* Added rule set selector (replacing "Magic number" field)
* Fixed crash-on-exit on Windows with recent versions of wxWidgets
* Changed license to GPLv3
2009-03-01: version 2.0.4.2
* Removed recognition of meta key
* Added undo/redo support
* Fixed minor bug in monster list
* Separated frame from view
* Made frame appear on startup, rather than initial dialog
* Added acknowledgement of pgchip's usage of tile 0x38 as an ice block
* Tileset now uses black, not tile 0x38, for out-of-range tiles
* Basic tile rotation support
* Monsters etc. rearranged in tile selector so that right = clockwise
* Separate modes for wire placement and map region selection
* Slots in tile selector now used for these modes
* Added copy/paste support (compatible with ChipEdit)
* Fixed file loading when wxUSE_STD_IOSTREAM is not set
2008-04-27: version 2.0.3.1
* Fixed typo causing compile failure when wxWidgets streams are in use
* No changes to runtime behaviour except for version number
2008-04-24: version 2.0.3
* Added sort button to monster list
* Fixed a drawing bug when disabling wire display
* Improved compatibility with wxWidgets 2.6
2008-04-21: version 2.0.2
* Graphical tile selector
* Mouse button functionality changed somewhat
* Map selection and filling with tiles added
* Steps made towards undo/redo
2008-04-11: version 2.0.1
* Minor bug-fix release
* Title bar and map selection are now properly updated when a level is selected
* Limits on tile size to avoid crashes at very high sizes
2008-04-10: version 2.0.0
* First release
* Map editing
* Level properties editing
* Monster list editing
* Level set support
* MSCC level set data format
* Tile World small/masked tileset image format
* CCEdit tileset format
chipw-2.0.6/src/ 0000755 0001750 0001750 00000000000 11672412354 010426 5 0000000 0000000 chipw-2.0.6/src/listmenumgr.h 0000644 0001750 0001750 00000005104 11672412350 013061 0000000 0000000 // Chip's Workshop - a level editor for Chip's Challenge.
// Copyright 2008-2011 Christopher Elsby
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License as
// published by the Free Software Foundation.
//
// 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 .
#ifndef CHIPW_LISTMENUMGR_H_INCLUDED
#define CHIPW_LISTMENUMGR_H_INCLUDED
#include
#include
#include
class wxMenu;
namespace ChipW {
class ListMenuManager {
public:
ListMenuManager(int newidmin, int newidmax, wxString newemptytext) : idmin(newidmin), idmax(newidmax), emptytext(newemptytext) { }
virtual ~ListMenuManager() { }
// Adds the current list to the given menu at its current end.
// The menu will then be automatically updated whenever the list changes.
// The menu *must* be detached before it is deleted.
void AddMenu(wxMenu* menu);
// Stops automatically updating the given menu.
// This must be called before the menu is deleted.
void DetachMenu(wxMenu* menu) {menus.erase(menu);}
// Returns the current list.
const std::vector& GetMenuItems() const {return items;}
// Changes the list, updating all attached menus.
void SetMenuItems(std::vector newitems);
// Returns the lowest window ID available for use by the list.
int GetIdMin() const {return idmin;}
// Returns the highest window ID available for use by the list.
int GetIdMax() const {return idmax;}
// Returns the maximum allowed length of the list.
unsigned int GetMaxLength() const {return idmin > idmax ? 0 : idmax - idmin + 1;}
// Checks whether the given ID is available for use by the list.
bool HasId(int id) const {return id >= idmin && id <= idmax;}
// Checks whether the given ID is currently in use by the list.
bool IsIdActive(int id) const {return id < idmin + (int) items.size();}
// Returns the string used for a placeholder item when the list is empty.
const wxString& GetEmptyText() const {return emptytext;}
private:
int idmin, idmax;
wxString emptytext;
std::set menus;
std::vector items;
};
}
#endif // !CHIPW_LISTMENUMGR_H_INCLUDED
chipw-2.0.6/src/levelset.h 0000644 0001750 0001750 00000003762 11672412350 012346 0000000 0000000 // Chip's Workshop - a level editor for Chip's Challenge.
// Copyright 2008-2011 Christopher Elsby
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License as
// published by the Free Software Foundation.
//
// 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 .
#ifndef CHIPW_LEVELSET_H_INCLUDED
#define CHIPW_LEVELSET_H_INCLUDED
#include
#include
#include
#include
#include
#include "level.h"
namespace ChipW {
class LevelMonitor;
class LevelSet {
public:
LevelSet();
~LevelSet();
void SetMonitor(LevelMonitor* mon);
void RemoveMonitor();
void RemoveMonitor(LevelMonitor* mon);
wxUint16 GetLevelCount() const {return levels.size();}
CountedPtr GetLevel(wxUint16 index) {return index < levels.size() ? levels[index] : NULL;}
const Level* GetLevel(wxUint16 index) const {return index < levels.size() ? levels[index] : NULL;}
wxUint16 FindLevel(const Level* level) const;
wxUint16 FindLevelByNumber(wxUint16 levnum) const;
wxUint16 FindLevelByPassword(const std::string& psw) const;
bool InsertLevel(CountedPtr level, wxUint16 index = 65535, bool renumber = true);
CountedPtr CreateLevel(wxUint16 index = 65535, bool renumber = true);
void RemoveLevel(wxUint16 index, bool renumber = true);
void RemoveAllLevels();
bool Save_MSCC(std::ostream& stream) const;
bool Load_MSCC(std::istream& stream);
wxUint32 ruleset;
private:
LevelMonitor* monitor;
std::vector > levels;
};
}
#endif // !CHIPW_LEVELSET_H_INCLUDED
chipw-2.0.6/src/sdidocframe.cpp 0000644 0001750 0001750 00000011210 11672412350 013321 0000000 0000000 // Chip's Workshop - a level editor for Chip's Challenge.
// Copyright 2008-2011 Christopher Elsby
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License as
// published by the Free Software Foundation.
//
// 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 .
#include "global.h"
#include "sdidocframe.h"
#include
#include
#include
#include
namespace ChipW {
IMPLEMENT_CLASS(SDIDocFrame, wxFrame)
BEGIN_EVENT_TABLE(SDIDocFrame, wxFrame)
EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, SDIDocFrame::OnMRUFile)
EVT_ACTIVATE(SDIDocFrame::OnActivate)
EVT_CLOSE(SDIDocFrame::OnCloseWindow)
EVT_MENU(wxID_EXIT, SDIDocFrame::OnExit)
END_EVENT_TABLE()
SDIDocFrame::SDIDocFrame()
: mgr(NULL), view(NULL)
{
}
SDIDocFrame::SDIDocFrame(wxDocManager* manager, wxFrame* parent, wxWindowID id, const wxString& title, const wxPoint& pos,
const wxSize& size, long style, const wxString& name)
: mgr(NULL), view(NULL)
{
Create(manager, parent, id, title, pos, size, style, name);
}
SDIDocFrame::SDIDocFrame(wxView* newview, wxFrame* parent, wxWindowID id, const wxString& title, const wxPoint& pos,
const wxSize& size, long style, const wxString& name)
: mgr(NULL), view(NULL)
{
Create(newview, parent, id, title, pos, size, style, name);
}
bool SDIDocFrame::Create(wxDocManager* manager, wxFrame* parent, wxWindowID id, const wxString& title, const wxPoint& pos,
const wxSize& size, long style, const wxString& name)
{
if(!wxFrame::Create(parent, id, title, pos, size, style, name))
return false;
mgr = manager;
view = NULL;
return true;
}
bool SDIDocFrame::Create(wxView* newview, wxFrame* parent, wxWindowID id, const wxString& title, const wxPoint& pos,
const wxSize& size, long style, const wxString& name)
{
if(!wxFrame::Create(parent, id, title, pos, size, style, name))
return false;
view = newview;
if(view != NULL) {
mgr = view->GetDocumentManager();
view->SetFrame(this);
}
return true;
}
bool SDIDocFrame::Destroy() {
view = NULL;
mgr = NULL;
return wxFrame::Destroy();
}
wxDocument* SDIDocFrame::GetDocument() const {
if(view == NULL)
return NULL;
return view->GetDocument();
}
bool SDIDocFrame::ProcessEvent(wxEvent& event) {
if(view != NULL) {
view->Activate(true);
if(view->ProcessEvent(event))
return true;
}
if(mgr != NULL && mgr->ProcessEvent(event))
return true;
return wxFrame::ProcessEvent(event);
}
void SDIDocFrame::OnMRUFile(wxCommandEvent& event) {
if(mgr == NULL)
return;
int n = event.GetId() - wxID_FILE1;
wxString filename(mgr->GetHistoryFile(n));
if(filename.empty())
return;
if(wxFile::Exists(filename)) {
if(!mgr->CreateDocument(filename, wxDOC_SILENT)) {
mgr->RemoveFileFromHistory(n);
wxLogError(_("The file '%s' couldn't be opened.\nIt has been removed from the most recently used files list."),
filename.c_str());
}
} else {
mgr->RemoveFileFromHistory(n);
wxLogError(_("The file '%s' doesn't exist and couldn't be opened.\nIt has been removed from the most recently used files list."),
filename.c_str());
}
}
void SDIDocFrame::OnActivate(wxActivateEvent& event) {
wxFrame::OnActivate(event);
if(view != NULL)
view->Activate(event.GetActive());
}
void SDIDocFrame::OnCloseWindow(wxCloseEvent& event) {
if(view != NULL) {
if(event.CanVeto() && !view->Close(false)) {
event.Veto();
return;
}
view->Activate(false);
delete view;
view = NULL;
}
mgr = NULL;
Destroy();
}
void SDIDocFrame::OnExit(wxCommandEvent& event) {
// To exit, we close all documents. This might be vetoed, if a document has unsaved changes and the user chooses Cancel.
if(mgr != NULL && !mgr->CloseDocuments(false))
return;
// If this frame has no view, it will not be closed by the document manager, so we need to close it here.
if(view == NULL)
Close();
// Clear pointers as the objects might become invalid.
view = NULL;
// Allow further exit handling elsewhere.
event.Skip();
}
}
chipw-2.0.6/src/levelpropertiesdlg.h 0000644 0001750 0001750 00000002502 11672412350 014425 0000000 0000000 // Chip's Workshop - a level editor for Chip's Challenge.
// Copyright 2008-2011 Christopher Elsby
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License as
// published by the Free Software Foundation.
//
// 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 .
#ifndef CHIPW_LEVELPROPERTIESDLG_H_INCLUDED
#define CHIPW_LEVELPROPERTIESDLG_H_INCLUDED
#include
#include
#include
class wxTextCtrl;
namespace ChipW {
class LevelPropertiesDialog : public wxDialog {
public:
LevelPropertiesDialog(wxWindow* parent, bool readonly);
wxString title;
wxString psw;
wxString chips;
wxString countedchips;
wxString time;
wxString hint;
wxString levnum;
wxUint32 ruleset;
private:
void OnCommand(wxCommandEvent& event);
wxTextCtrl* pswbox;
DECLARE_EVENT_TABLE()
};
}
#endif // !CHIPW_LEVELPROPERTIESDLG_H_INCLUDED
chipw-2.0.6/src/leveleditview.cpp 0000644 0001750 0001750 00000157276 11672412350 013740 0000000 0000000 // Chip's Workshop - a level editor for Chip's Challenge.
// Copyright 2008-2011 Christopher Elsby
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License as
// published by the Free Software Foundation.
//
// 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 .
#include "global.h"
#include "leveleditview.h"
#include "levelsetdoc.h"
#include "leveleditframe.h"
#include "level.h"
#include "tileset.h"
#include "levelupdatehint.h"
#include "levelpropertiesdlg.h"
#include "monsterlistdlg.h"
#include "bufferscroll.h"
#include "leveleditids.h"
#include "apppaths.h"
#include "leveldataobj.h"
#include "app.h"
#include "playtestmgr.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
namespace ChipW {
class LevelMapWindow : public BufferedScrolledWindow {
public:
LevelMapWindow(wxWindow* parent, LevelEditView* newview) : BufferedScrolledWindow(parent), view(newview) { }
virtual void OnDraw(wxDC& dc) {if(view != NULL) view->OnDraw(&dc);}
void OnMouse(wxMouseEvent& event) {if(view != NULL) view->OnMouse(event);}
LevelEditView* view;
private:
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(LevelMapWindow, BufferedScrolledWindow)
EVT_MOUSE_EVENTS(LevelMapWindow::OnMouse)
END_EVENT_TABLE()
class TileSelectWindow : public BufferedScrolledWindow {
public:
TileSelectWindow(wxWindow* parent, LevelEditView* newview) : BufferedScrolledWindow(parent), view(newview) { }
virtual void OnDraw(wxDC& dc) {if(view != NULL) view->DrawTileSelector(&dc);}
void OnMouse(wxMouseEvent& event) {if(view != NULL) view->OnMouse(event);}
LevelEditView* view;
private:
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(TileSelectWindow, BufferedScrolledWindow)
EVT_MOUSE_EVENTS(TileSelectWindow::OnMouse)
END_EVENT_TABLE()
const int TILESEL_WIDTH = 6;
const int TILESEL_HEIGHT = 20;
const LevelEditView::Tool TOOL_NONE = LevelEditView::TOOL_NONE;
const LevelEditView::Tool TOOL_RECTSELECT = LevelEditView::TOOL_RECTSELECT;
const LevelEditView::Tool TOOL_TRAPWIRE = LevelEditView::TOOL_TRAPWIRE;
const LevelEditView::Tool TOOL_CLONEWIRE = LevelEditView::TOOL_CLONEWIRE;
const LevelEditView::Tool tileselgrid[TILESEL_WIDTH * TILESEL_HEIGHT] = {
// TOOL_RECTSELECT, TOOL_NONE, TOOL_NONE, TOOL_NONE, TOOL_NONE, TOOL_NONE, TOOL_NONE
TILE_FLOOR, TILE_WALL_BLUE_FAKE, TILE_WALL_INV, TILE_BUTTON_TOGGLE, TILE_WALL_TOGGLE_OFF, /*TOOL_NONE,*/TOOL_RECTSELECT,
TILE_WALL, TILE_WALL_BLUE, TILE_WALL_INV_SHOWS, TILE_WALL_POPUP, TILE_WALL_TOGGLE_ON, /*TOOL_NONE,*/TOOL_NONE,
TILE_WALL_SE, TILE_WALL_W, TILE_WALL_N, TILE_WALL_E, TILE_WALL_S, /*TOOL_NONE,*/TOOL_NONE,
TILE_EXIT, TILE_CHIP_W, TILE_CHIP_N, TILE_CHIP_E, TILE_CHIP_S, /*TOOL_NONE,*/TOOL_NONE,
TILE_SOCKET, TILE_DOOR_B, TILE_DOOR_R, TILE_DOOR_Y, TILE_DOOR_G, /*TOOL_NONE,*/TOOL_NONE,
TILE_COMPUTERCHIP, TILE_KEY_B, TILE_KEY_R, TILE_KEY_Y, TILE_KEY_G, /*TOOL_NONE,*/TOOL_NONE,
TILE_BOMB, TILE_WATER, TILE_BOOTS_WATER, TILE_FIRE, TILE_BOOTS_FIRE, /*TOOL_NONE,*/TOOL_NONE,
TILE_THIEF, TILE_FORCE_RAND, TILE_BOOTS_FORCE, TILE_ICE, TILE_BOOTS_ICE, /*TOOL_NONE,*/TOOL_NONE,
TILE_GRAVEL, TILE_FORCE_E, TILE_FORCE_S, TILE_ICE_CURVE_SE, TILE_ICE_CURVE_SW, /*TOOL_NONE,*/TOOL_NONE,
TILE_DIRT, TILE_FORCE_N, TILE_FORCE_W, TILE_ICE_CURVE_NE, TILE_ICE_CURVE_NW, /*TOOL_NONE,*/TOOL_NONE,
TILE_BLOCK, TILE_BLOCK_W, TILE_BLOCK_N, TILE_BLOCK_E, TILE_BLOCK_S, /*TOOL_NONE,*/TOOL_NONE,
TILE_HINT, TILE_BUG_W, TILE_BUG_N, TILE_BUG_E, TILE_BUG_S, /*TOOL_NONE,*/TOOL_NONE,
TILE_TELEPORT, TILE_PARAMECIUM_W, TILE_PARAMECIUM_N, TILE_PARAMECIUM_E, TILE_PARAMECIUM_S, /*TOOL_NONE,*/TOOL_NONE,
TILE_TRAP, TILE_GLIDER_W, TILE_GLIDER_N, TILE_GLIDER_E, TILE_GLIDER_S, /*TOOL_NONE,*/TOOL_NONE,
TOOL_TRAPWIRE, TILE_BALL_W, TILE_BALL_N, TILE_BALL_E, TILE_BALL_S, /*TOOL_NONE,*/TOOL_NONE,
TILE_BUTTON_TRAP, TILE_FIREBALL_W, TILE_FIREBALL_N, TILE_FIREBALL_E, TILE_FIREBALL_S, /*TOOL_NONE,*/TOOL_NONE,
TILE_BUTTON_TANK, TILE_TANK_W, TILE_TANK_N, TILE_TANK_E, TILE_TANK_S, /*TOOL_NONE,*/TOOL_NONE,
TILE_BUTTON_CLONE, TILE_WALKER_W, TILE_WALKER_N, TILE_WALKER_E, TILE_WALKER_S, /*TOOL_NONE,*/TOOL_NONE,
TOOL_CLONEWIRE, TILE_BLOB_W, TILE_BLOB_N, TILE_BLOB_E, TILE_BLOB_S, /*TOOL_NONE,*/TOOL_NONE,
TILE_CLONER, TILE_TEETH_W, TILE_TEETH_N, TILE_TEETH_E, TILE_TEETH_S, /*TOOL_NONE,*/TOOL_NONE,
};
IMPLEMENT_DYNAMIC_CLASS(LevelEditView, wxView)
BEGIN_EVENT_TABLE(LevelEditView, wxView)
EVT_MENU(-1, LevelEditView::OnCommand)
EVT_BUTTON(-1, LevelEditView::OnCommand)
EVT_UPDATE_UI(-1, LevelEditView::OnUpdateUI)
EVT_LISTBOX(-1, LevelEditView::OnListBox)
EVT_LISTBOX_DCLICK(-1, LevelEditView::OnListBox)
EVT_IDLE(LevelEditView::OnIdle)
END_EVENT_TABLE()
Tileset LevelEditView::defaulttileset;
bool LevelEditView::loadeddefaulttileset = false;
LevelEditView::LevelEditView()
: level(NULL), selx(32), sely(32), selw(0), selh(0), clickx(32), clicky(32), readonly(false), showwires(true), showupper(true),
activebutton(wxMOUSE_BTN_NONE), buttonswap(false), idleredraw(DRAW_NONE),
mapwin(NULL), statusbar(NULL), mapbmp(NULL), levellist(NULL), tilelist(NULL), tilesel(NULL)
{
}
LevelEditView::~LevelEditView() {
delete mapbmp;
if(mapwin != NULL)
mapwin->view = NULL;
if(tilesel != NULL)
tilesel->view = NULL;
}
bool LevelEditView::OnCreate(wxDocument* doc, long flags) {
if(!wxView::OnCreate(doc, flags))
return false;
// Frame.
wxWindow* frame = GetFrame();
if(frame == NULL) {
frame = LevelEditFrame::GetSpareOrNew(this);
SetFrame(frame);
}
// Status bar.
if(frame->IsKindOf(CLASSINFO(wxFrame)))
statusbar = ((wxFrame*) frame)->GetStatusBar();
// Main splitter window.
wxSplitterWindow* splitter = new wxSplitterWindow(frame, -1, wxDefaultPosition, wxDefaultSize, wxSP_3D | wxSP_LIVE_UPDATE);
// Tabs on left.
wxPanel* notebookpanel = new wxPanel(splitter);
wxSizer* notebookpanelsizer = new wxBoxSizer(wxVERTICAL);
wxNotebook* notebook = new wxNotebook(notebookpanel, -1, wxDefaultPosition, wxDefaultSize, wxNB_BOTTOM);
// Level list.
if(doc != NULL && doc->IsKindOf(CLASSINFO(LevelSetDoc))) {
wxPanel* levellistpanel = new wxPanel(notebook);
wxSizer* levellistpanelsizer = new wxBoxSizer(wxVERTICAL);
wxSizer* buttonsizer = new wxBoxSizer(wxHORIZONTAL);
buttonsizer->Add(new wxButton(levellistpanel, wxID_ADD, wxT("+"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT), 1, wxGROW);
buttonsizer->Add(new wxButton(levellistpanel, wxID_REMOVE, wxT("-"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT), 1, wxGROW);
buttonsizer->Add(new wxButton(levellistpanel, wxID_UP, wxT("^"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT), 1, wxGROW);
buttonsizer->Add(new wxButton(levellistpanel, wxID_DOWN, wxT("v"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT), 1, wxGROW);
buttonsizer->Add(new wxButton(levellistpanel, wxID_PROPERTIES, wxT("..."), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT), 1, wxGROW);
levellistpanelsizer->Add(buttonsizer, 0, wxALL | wxGROW, 5);
levellist = new wxListBox(levellistpanel, -1);
levellistpanelsizer->Add(levellist, 1, wxGROW);
levellistpanel->SetSizerAndFit(levellistpanelsizer);
notebook->AddPage(levellistpanel, wxT("Levels"));
}
// Tile selector.
tilesel = new TileSelectWindow(notebook, this);
tilesel->SetBackgroundColour(wxColour(102, 102, 102));
notebook->AddPage(tilesel, wxT("Tiles"));
// Tile list.
wxPanel* tilelistpanel = new wxPanel(notebook);
wxSizer* tilelistpanelsizer = new wxBoxSizer(wxVERTICAL);
tilelist = new wxListBox(tilelistpanel, -1);
for(Tool tool = TOOL_MIN; tool <= TOOL_MAX; ++tool)
tilelist->Append(GetToolName(tool, true));
tilelist->SetSelection(0);
tilelistpanelsizer->Add(tilelist, 1, wxGROW);
tilelistpanel->SetSizerAndFit(tilelistpanelsizer);
notebook->AddPage(tilelistpanel, wxT("IDs"));
// Set notebook panel sizer.
notebookpanelsizer->Add(notebook, 1, wxGROW);
notebookpanel->SetSizerAndFit(notebookpanelsizer);
// Level map on right.
mapwin = new LevelMapWindow(splitter, this);
mapwin->SetBackgroundColour(wxColour(102, 102, 102));
// Set up splitter.
splitter->SetMinimumPaneSize(20);
splitter->SplitVertically(notebookpanel, mapwin, 150);
// Display the frame.
splitter->SetSize(frame->GetClientSize());
frame->Show();
frame->Raise();
return true;
}
void LevelEditView::OnChangeFilename() {
if(GetDocument() != NULL && GetFrame() != NULL) {
wxString name;
GetDocument()->GetPrintableName(name);
wxString title = wxT("Chip's Workshop");
if(name)
title += wxT(" - ") + name;
if(level != NULL && !level->title.empty())
title += wxT(" (") + wxString(level->title.c_str(), wxConvISO8859_1) + wxT(")");
if(GetFrame()->IsKindOf(CLASSINFO(wxTopLevelWindow)))
((wxTopLevelWindow*) GetFrame())->SetTitle(title);
else
GetFrame()->SetLabel(title);
}
}
bool LevelEditView::OnClose(bool delwin) {
if(GetDocument() != NULL && GetDocument()->GetViews().size() < 2 && !GetDocument()->Close())
return false;
Activate(false);
if(mapwin != NULL)
mapwin->view = NULL;
mapwin = NULL;
if(tilesel != NULL)
tilesel->view = NULL;
tilesel = NULL;
levellist = NULL;
tilelist = NULL;
statusbar = NULL;
delete mapbmp;
mapbmp = NULL;
if(delwin && GetFrame() != NULL) {
wxWindow* frame = GetFrame();
SetFrame(NULL);
frame->Destroy();
}
return true;
}
void LevelEditView::OnActivateView(bool activate, wxView *activeView, wxView *deactiveView) {
if(activate && wxTheApp != NULL && GetFrame() != NULL)
wxTheApp->SetTopWindow(GetFrame());
}
void LevelEditView::OnCommand(wxCommandEvent& event) {
LevelSetDoc* doc = GetLevelSetDoc();
LevelSet* levelset = NULL;
if(doc != NULL)
levelset = doc->GetLevelSet();
LevelUpdateHint hint;
switch(event.GetId()) {
case wxID_ADD:
if(!readonly && doc != NULL && levelset != NULL) {
CountedPtr oldlevel = level;
CountedPtr newlevel = new Level;
SetLevel(newlevel);
if(!doc->InsertLevel(newlevel, levelset->FindLevel(level) + 1))
SetLevel(oldlevel);
}
#if 0
if(!readonly && levelset != NULL) {
CountedPtr newlevel = new Level;
if(levelset->InsertLevel(newlevel)) {
SetLevel(newlevel);
hint.type = LevelUpdateHint::CREATE;
hint.level = newlevel;
SendUpdate(&hint);
}
}
#endif
break;
case wxID_REMOVE:
if(!readonly && doc != NULL && level != NULL) {
if(wxMessageBox(wxT("Are you sure you want to delete this level?"), wxT("Delete level"), wxYES_NO | wxICON_QUESTION) != wxYES)
break;
doc->RemoveLevel(level);
}
#if 0
if(!readonly && levelset != NULL && level != NULL) {
wxUint16 index = levelset->FindLevel(level);
if(index < levelset->GetLevelCount()) {
if(wxMessageBox(wxT("Are you sure you want to delete this level?"), wxT("Delete level"), wxYES_NO | wxICON_QUESTION) != wxYES)
break;
levelset->RemoveLevel(index, true);
hint.type = LevelUpdateHint::DESTROY;
hint.level = level;
SendUpdate(&hint);
}
}
#endif
break;
case wxID_UP:
if(!readonly && levelset != NULL && level != NULL && doc != NULL) {
wxUint16 index = levelset->FindLevel(level);
if(index > 0 && index < levelset->GetLevelCount()) {
doc->MoveLevel(level, index - 1);
#if 0
levelset->InsertLevel(level, index - 1);
hint.type = LevelUpdateHint::LIST;
hint.level = level;
SendUpdate(&hint);
#endif
}
}
break;
case wxID_DOWN:
if(!readonly && levelset != NULL && level != NULL && doc != NULL) {
wxUint16 index = levelset->FindLevel(level);
if(levelset->GetLevelCount() > 0 && index < levelset->GetLevelCount() - 1) {
doc->MoveLevel(level, index + 1);
#if 0
levelset->InsertLevel(level, index + 1);
hint.type = LevelUpdateHint::LIST;
hint.level = level;
SendUpdate(&hint);
#endif
}
}
break;
case wxID_PROPERTIES:
if(level != NULL && doc != NULL && levelset != NULL) {
LevelPropertiesDialog dlg(GetFrame(), readonly);
dlg.title << wxString(level->title.c_str(), wxConvISO8859_1);
dlg.psw << wxString(level->psw.c_str(), wxConvISO8859_1);
dlg.chips << level->chips;
dlg.countedchips << level->CountChips();
dlg.time << level->time;
dlg.hint << wxString(level->hint.c_str(), wxConvISO8859_1);
dlg.levnum << level->levelnumber;
// dlg.ruleset << levelset->ruleset;
dlg.ruleset = levelset->ruleset;
if(dlg.ShowModal() == wxID_OK && !readonly) {
unsigned long ul;
std::string title = level->title;
{
const wxWX2MBbuf str = dlg.title.mb_str(wxConvISO8859_1);
if(str != NULL)
title = str;
else
wxLogError(wxT("Failed to set level title."));
}
std::string psw = level->psw;
{
const wxWX2MBbuf str = dlg.psw.mb_str(wxConvISO8859_1);
if(str != NULL)
psw = str;
else
wxLogError(wxT("Failed to set level password."));
}
wxUint16 chips = level->chips;
if(dlg.chips.ToULong(&ul) && ul < 65536)
chips = ul;
else
wxLogError(wxT("Failed to set chips required."));
wxUint16 time = level->time;
if(dlg.time.ToULong(&ul) && ul < 65536)
time = ul;
else
wxLogError(wxT("Failed to set time limit."));
std::string hint = level->hint;
{
const wxWX2MBbuf str = dlg.hint.mb_str(wxConvISO8859_1);
if(str != NULL)
hint = str;
else
wxLogError(wxT("Failed to set level hint."));
}
wxUint16 levelnumber = level->levelnumber;
if(dlg.levnum.ToULong(&ul) && ul < 65536)
levelnumber = ul;
else
wxLogError(wxT("Failed to set level number."));
#if 0
wxUint32 ruleset = levelset->ruleset;
if(dlg.ruleset.ToULong(&ul))
ruleset = ul;
else
wxLogError(wxT("Failed to set rule set."));
#endif
wxUint32 ruleset = dlg.ruleset;
doc->SetLevelProperties(level, title, psw, chips, time, hint, levelnumber, ruleset);
#if 0
hint.type = LevelUpdateHint::LIST;
hint.level = level;
SendUpdate(&hint);
#endif
}
}
break;
case ID_EDIT_MONSTERS:
if(level != NULL && doc != NULL) {
MonsterListDialog dlg(GetFrame(), level, readonly);
if(dlg.ShowModal() == wxID_OK && !readonly)
doc->SetLevelMonsters(level, dlg.GetMonsterList());
#if 0
{
level->monsters = dlg.GetMonsterList();
hint.type = LevelUpdateHint::MONSTER;
hint.level = level;
SendUpdate(&hint);
}
#endif
}
break;
case ID_EDIT_WIRES:
break;
case ID_CLEARSELTILES:
if(!readonly && level != NULL) {
if(doc != NULL)
doc->FinishLevelChangeCommand();
DoTileActionSel(TILE_FLOOR, wxT("placetile")/*, hint*/);
if(doc != NULL)
doc->FinishLevelChangeCommand();
#if 0
if(hint.type != LevelUpdateHint::NONE)
SendUpdate(&hint);
#endif
}
break;
case ID_SHOWWIRES:
showwires = !showwires;
AddIdleRedraw(DRAW_MAP);
break;
case ID_SHOWUPPER:
showupper = !showupper;
hint.type = LevelUpdateHint::TILE;
hint.level = level;
OnUpdate(this, &hint);
break;
case wxID_CUT:
case wxID_COPY:
if((event.GetId() != wxID_CUT || !readonly) && level != NULL && wxTheClipboard != NULL) {
if(HasSelection()) {
LevelSectionDataObject* sectdataobj = new LevelSectionDataObject;
if(!sectdataobj->SetSection(level, selx, sely, selw, selh)) {
wxLogError(wxT("Failed to copy map section."));
delete sectdataobj;
break;
}
if(!wxTheClipboard->Open()) {
wxLogError(wxT("Failed to open the clipboard."));
delete sectdataobj;
break;
}
wxTheClipboard->SetData(sectdataobj);
wxTheClipboard->Close();
if(event.GetId() == wxID_CUT) {
if(doc != NULL)
doc->FinishLevelChangeCommand();
DoTileActionSel(TILE_FLOOR, wxT("placetile"));
if(doc != NULL)
doc->FinishLevelChangeCommand();
}
} else {
LevelsDataObject* levdataobj = new LevelsDataObject;
if(!levdataobj->AddLevel(level)) {
wxLogError(wxT("Failed to copy level."));
delete levdataobj;
break;
}
if(!wxTheClipboard->Open()) {
wxLogError(wxT("Failed to open the clipboard."));
delete levdataobj;
break;
}
wxTheClipboard->SetData(levdataobj);
wxTheClipboard->Close();
if(event.GetId() == wxID_CUT && doc != NULL)
doc->RemoveLevel(level);
}
}
break;
case wxID_PASTE:
if(wxTheClipboard != NULL) {
LevelSectionDataObject* sectdataobj = new LevelSectionDataObject;
LevelsDataObject* levdataobj = new LevelsDataObject;
wxDataObjectComposite dataobj;
dataobj.Add(sectdataobj, HasSelection());
dataobj.Add(levdataobj, !HasSelection());
if(!wxTheClipboard->Open()) {
wxLogError(wxT("Failed to open the clipboard."));
break;
}
bool success = wxTheClipboard->GetData(dataobj);
wxTheClipboard->Close();
if(!success) {
wxBell();
break;
}
if(sectdataobj->HasData()) {
if(level == NULL || !HasSelection()) {
wxMessageBox(wxT("Please select the top-left corner of the destination area, then choose paste."), wxT("Paste map section"));
break;
}
if(doc != NULL)
doc->FinishLevelChangeCommand();
if(!sectdataobj->PasteToLevel(level, selx, sely)) {
if(doc != NULL)
doc->CancelLevelChangeCommand();
wxBell();
break;
}
if(doc != NULL)
doc->FinishLevelChangeCommand();
SetSelection(selx, sely, sectdataobj->GetWidth(), sectdataobj->GetHeight());
} else if(levdataobj->HasData() && doc != NULL) {
std::vector > levels;
if(!levdataobj->GetLevels(levels) || levels.empty()) {
wxBell();
break;
}
wxUint16 index = levelset->FindLevel(level) + 1;
CountedPtr oldlevel = level;
SetLevel(levels.front());
if(!doc->InsertLevels(levels, index)) {
SetLevel(oldlevel);
wxBell();
}
} else {
wxBell();
}
break;
}
case ID_SETTILESET:
{
wxConfigBase* config = wxConfigBase::Get();
wxString filename = GetDataDir() + wxT("/tilesets/default");
if(config != NULL)
config->Read(wxT("Tileset"), &filename);
wxFileName filenameobj(filename);
filename = wxFileSelector(wxT("Choose a tileset"), filenameobj.GetPath(), filenameobj.GetFullName(), wxT(""), wxT("*"),
#if wxCHECK_VERSION(2, 8, 0)
wxFD_OPEN | wxFD_FILE_MUST_EXIST,
#else
wxOPEN | wxFILE_MUST_EXIST,
#endif
GetFrame());
if(filename.empty())
break;
Tileset newtileset(filename);
if(!newtileset.IsOk()) {
wxLogError(wxT("Failed to open tileset."));
break;
}
if(SetTileset(newtileset)) {
defaulttileset = tileset;
if(config != NULL) {
config->Write(wxT("Tileset"), filename);
config->DeleteEntry(wxT("TileWidth"));
config->DeleteEntry(wxT("TileHeight"));
}
hint.type = LevelUpdateHint::TILE;
hint.level = level;
OnUpdate(this, &hint);
}
break;
}
case ID_SETTILESIZE:
{
wxString sizestr;
sizestr << GetTileW() << wxT("x") << GetTileH();
wxString prompt;
prompt << wxT("Enter the tile size in pixels.\n");
prompt << wxT("The native tile size of the tileset is ") << tileset.GetNativeTileWidth();
prompt << wxT("x") << tileset.GetNativeTileHeight() << wxT(".");
sizestr = wxGetTextFromUser(prompt, wxT("Scale tiles"), sizestr, GetFrame());
sizestr.Replace(wxT(" "), wxT(""));
if(!sizestr.empty()) {
long width, height;
sizestr.MakeLower();
size_t pos = sizestr.find(wxT("x"));
if(pos < sizestr.size()) {
if(pos == 0 || pos == sizestr.size() - 1 || !wxString(sizestr.substr(0, pos)).ToLong(&width) || width <= 0 ||
!wxString(sizestr.substr(pos + 1)).ToLong(&height) || height <= 0) {
wxLogError(wxT("Invalid tile size."));
break;
}
} else {
if(!sizestr.ToLong(&width) || width <= 0) {
wxLogError(wxT("Invalid tile size."));
break;
}
height = width;
}
if(SetTileSize(width, height)) {
defaulttileset = tileset;
wxConfigBase* config = wxConfigBase::Get();
if(config != NULL) {
config->Write(wxT("TileWidth"), width);
config->Write(wxT("TileHeight"), height);
}
hint.type = LevelUpdateHint::TILE;
hint.level = level;
OnUpdate(this, &hint);
}
}
break;
}
case ID_READONLY:
readonly = !readonly;
break;
case ID_SWAPBUTTONS:
buttonswap = !buttonswap;
if(activebutton == wxMOUSE_BTN_RIGHT || activebutton == wxMOUSE_BTN_MIDDLE)
activebutton = wxMOUSE_BTN_NONE;
break;
case ID_ROTATE_TILE_ANTICLOCKWISE:
case ID_ROTATE_TILE_CLOCKWISE:
{
if(HasSelectedTile()) {
Tile sel = GetSelectedTile();
Tile rotated = ReorientateTile(sel, (event.GetId() == ID_ROTATE_TILE_CLOCKWISE) ? REORIENTATE_ROTATE_CLOCKWISE : REORIENTATE_ROTATE_ANTICLOCKWISE);
if(rotated == TILE_INVALID && sel != TILE_INVALID)
wxBell();
else
SetSelectedTile(rotated);
}
break;
}
case ID_NEWVIEW:
NewView();
break;
case ID_CLOSEVIEW:
Close();
break;
default:
{
PlayTestManager* playtestmgr = wxGetApp().GetPlayTestManager();
if(playtestmgr != NULL && playtestmgr->HasId(event.GetId())) {
if(levelset != NULL) {
const PlayTestType& playtesttype = playtestmgr->GetTypes()[event.GetId() - playtestmgr->GetIdMin()];
if(!playtesttype.Launch(*levelset, level == NULL ? 1 : level->levelnumber))
wxLogError(wxT("Playtesting failed."));
// If playtesting started successfully, the process object will delete itself when finished.
}
} else {
event.Skip();
}
}
}
}
void LevelEditView::OnUpdateUI(wxUpdateUIEvent& event) {
LevelSet* levelset = GetLevelSet();
switch(event.GetId()) {
case wxID_ADD:
event.Enable(!readonly && levelset != NULL);
break;
case wxID_REMOVE:
event.Enable(!readonly && level != NULL && levelset != NULL);
break;
case wxID_UP:
event.Enable(!readonly && level != NULL && levelset != NULL && levelset->FindLevel(level) > 0);
break;
case wxID_DOWN:
event.Enable(!readonly && level != NULL && levelset != NULL && levelset->FindLevel(level) + 1 < levelset->GetLevelCount());
break;
case wxID_PROPERTIES:
case ID_EDIT_MONSTERS:
case ID_EDIT_WIRES:
event.Enable(level != NULL);
break;
case ID_CLEARSELTILES:
event.Enable(!readonly && HasSelection());
break;
case ID_ROTATE_TILE_ANTICLOCKWISE:
case ID_ROTATE_TILE_CLOCKWISE:
event.Enable(HasSelectedTile());
break;
case ID_SHOWWIRES:
event.Enable(true);
event.Check(showwires);
break;
case ID_SHOWUPPER:
event.Enable(true);
event.Check(showupper);
break;
case wxID_CUT:
if(readonly) {
event.Enable(false);
break;
}
// Pass through to wxID_COPY
case wxID_COPY:
event.Enable(level != NULL && wxTheClipboard != NULL);
break;
case wxID_PASTE:
event.Enable(wxTheClipboard != NULL && (
wxTheClipboard->IsSupported(LevelSectionDataObject::GetDataFormat()) ||
wxTheClipboard->IsSupported(LevelsDataObject::GetDataFormat())
));
break;
case ID_READONLY:
event.Enable(true);
event.Check(readonly);
break;
case ID_SWAPBUTTONS:
event.Enable(true);
event.Check(buttonswap);
break;
default:
{
PlayTestManager* playtestmgr = wxGetApp().GetPlayTestManager();
if(playtestmgr != NULL && playtestmgr->HasId(event.GetId()))
event.Enable(playtestmgr->IsIdActive(event.GetId()) && levelset != NULL);
else
event.Skip();
}
}
}
LevelEditView* LevelEditView::NewView(CountedPtr newlevel) {
LevelEditView* newview = new LevelEditView;
newview->SetDocument(GetDocument());
if(!newview->OnCreate(GetDocument(), 0)) {
delete newview;
return NULL;
}
newview->SetLevel(newlevel);
newview->SetTileset(tileset);
newview->OnUpdate(this);
return newview;
}
void LevelEditView::OnListBox(wxCommandEvent& event) {
if(event.GetEventObject() == NULL)
return;
if(event.GetEventObject() == levellist) {
if(event.GetClientData() != NULL) {
CountedPtr newlevel = (Level*) event.GetClientData();
if(event.GetEventType() == wxEVT_COMMAND_LISTBOX_DOUBLECLICKED) {
NewView(newlevel);
} else {
SetLevel(newlevel);
AddIdleRedraw(DRAW_MAP);
OnChangeFilename();
}
}
}
}
void LevelEditView::SetLevel(CountedPtr newlevel) {
if(newlevel != level) {
level = newlevel;
delete mapbmp;
mapbmp = NULL;
ClearSelection();
}
}
LevelSetDoc* LevelEditView::GetLevelSetDoc() const {
if(GetDocument() == NULL || !GetDocument()->IsKindOf(CLASSINFO(LevelSetDoc)))
return NULL;
return (LevelSetDoc*) GetDocument();
}
LevelSet* LevelEditView::GetLevelSet() const {
if(GetLevelSetDoc() == NULL)
return NULL;
return GetLevelSetDoc()->GetLevelSet();
}
bool LevelEditView::SetTileset(const Tileset& tiles) {
tileset = tiles;
delete mapbmp;
mapbmp = NULL;
if(mapwin != NULL) {
mapwin->SetScrollbars(GetTileW(), GetTileH(), 32, 32);
mapwin->Refresh();
}
if(tilesel != NULL) {
tilesel->SetScrollbars(GetTileW(), GetTileH(), TILESEL_WIDTH, TILESEL_HEIGHT);
tilesel->Refresh();
}
return true;
}
bool LevelEditView::SetTileSize(wxCoord w, wxCoord h) {
return tileset.Resize(w, h) && SetTileset(tileset);
}
wxString LevelEditView::GetToolName(Tool tool, bool hexcode) {
if(IsTile(tool))
return GetTileName(tool, hexcode);
switch(tool) {
case TOOL_RECTSELECT:
return wxT("rectangle select");
case TOOL_TRAPWIRE:
return wxT("trap wire");
case TOOL_CLONEWIRE:
return wxT("clone wire");
}
return wxT("");
}
LevelEditView::Tool LevelEditView::GetSelectedTool() const {
if(tilelist != NULL && tilelist->GetSelection() >= TOOL_MIN && tilelist->GetSelection() <= TOOL_MAX)
return tilelist->GetSelection();
return TOOL_NONE;
}
bool LevelEditView::SetSelectedTool(Tool tool) {
if(tilelist == NULL)
return false;
tilelist->SetSelection(tool);
if(tilesel != NULL)
tilesel->Refresh();
return true;
}
void LevelEditView::SetSelection(wxUint32 x, wxUint32 y, wxUint32 w, wxUint32 h) {
if(x == selx && y == sely && w == selw && h == selh)
return;
if(mapwin != NULL) {
wxCoord x1, y1, x2, y2;
mapwin->CalcScrolledPosition(selx * GetTileW(), sely * GetTileH(), &x1, &y1);
mapwin->CalcScrolledPosition(x * GetTileW(), y * GetTileH(), &x2, &y2);
wxRegion region(x1, y1, selw * GetTileW(), selh * GetTileH());
region.Xor(x2, y2, w * GetTileW(), h * GetTileH());
wxDC* dc = NewClientDC();
dc->SetClippingRegion(region);
DrawSelection(dc, 0, 0, 32, 32);
delete dc;
}
selx = x;
sely = y;
selw = w;
selh = h;
AddIdleRedraw(DRAW_WIRES);
}
void LevelEditView::SetStatusText(const wxString& text, int i) {
if(statusbar != NULL)
statusbar->SetStatusText(text, i);
}
bool LevelEditView::InitTileset() {
if(tileset.IsOk())
return true;
if(!loadeddefaulttileset) {
wxConfigBase* config = wxConfigBase::Get();
long defaulttilew = -1, defaulttileh = -1;
if(config != NULL) {
config->Read(wxT("TileWidth"), &defaulttilew);
config->Read(wxT("TileHeight"), &defaulttileh);
}
wxString filename = GetDataDir() + wxT("/tilesets/default");
if(config != NULL)
config->Read(wxT("Tileset"), &filename);
defaulttileset.LoadFile(filename, defaulttilew, defaulttileh);
loadeddefaulttileset = true;
}
if(defaulttileset.IsOk())
SetTileset(defaulttileset);
return tileset.IsOk();
}
wxDC* LevelEditView::NewClientDC() {
if(mapwin == NULL)
return NULL;
wxDC* dc = new wxClientDC(mapwin);
mapwin->DoPrepareDC(*dc);
return dc;
}
void LevelEditView::OnDraw(wxDC* dc) {
if(dc == NULL || level == NULL || !InitTileset())
return;
wxMemoryDC* dc2 = NULL;
if(mapbmp == NULL) {
mapbmp = new wxBitmap(32 * GetTileW(), 32 * GetTileH());
dc2 = new wxMemoryDC;
if(dc2 != NULL) {
dc2->SelectObject(*mapbmp);
tileset.DrawLevel(level, dc2, 0, 0, showupper);
}
} else {
dc2 = new wxMemoryDC;
if(dc2 != NULL)
dc2->SelectObject(*mapbmp);
}
dc->Blit(0, 0, mapbmp->GetWidth(), mapbmp->GetHeight(), dc2, 0, 0);
delete dc2;
DrawSelection(dc);
DrawWires(dc);
}
void LevelEditView::DrawSelection(wxDC* dc, wxUint32 x, wxUint32 y, wxUint32 w, wxUint32 h) {
if(x < 32 && y < 32 && w > 0 && h > 0) {
int origfunc = dc->GetLogicalFunction();
dc->SetLogicalFunction(wxINVERT);
dc->SetPen(*wxTRANSPARENT_PEN);
dc->SetBrush(*wxBLACK_BRUSH);
dc->DrawRectangle(x * GetTileW(), y * GetTileH(), w * GetTileW(), h * GetTileH());
dc->SetBrush(wxNullBrush);
dc->SetPen(wxNullPen);
dc->SetLogicalFunction(origfunc);
}
}
void LevelEditView::DrawWires(wxDC* dc, bool force) {
if((force || showwires) && level != NULL) {
if(!level->trapwires.empty()) {
wxPen pen(wxColour(116, 96, 0));
dc->SetPen(pen);
for(std::list::const_iterator it = level->trapwires.begin(); it != level->trapwires.end(); ++it) {
dc->DrawLine((wxCoord) it->buttonx * GetTileW() + GetTileW() / 2, (wxCoord) it->buttony * GetTileH() + GetTileH() / 2,
(wxCoord) it->targetx * GetTileW() + GetTileW() / 2, (wxCoord) it->targety * GetTileH() + GetTileH() / 2);
}
dc->SetPen(wxNullPen);
}
if(!level->clonewires.empty()) {
wxPen pen(wxColour(200, 0, 0));
dc->SetPen(pen);
for(std::list::const_iterator it = level->clonewires.begin(); it != level->clonewires.end(); ++it) {
dc->DrawLine((wxCoord) it->buttonx * GetTileW() + GetTileW() / 2, (wxCoord) it->buttony * GetTileH() + GetTileH() / 2,
(wxCoord) it->targetx * GetTileW() + GetTileW() / 2, (wxCoord) it->targety * GetTileH() + GetTileH() / 2);
}
dc->SetPen(wxNullPen);
}
}
}
void LevelEditView::DrawTileSelector(wxDC* dc) {
if(dc == NULL || !InitTileset())
return;
wxCoord x, y;
wxCoord trapwirex = 0, trapwirey = 0, clonewirex = 0, clonewirey = 0;
for(y = 0; y < TILESEL_HEIGHT; ++y) {
for(x = 0; x < TILESEL_WIDTH; ++x) {
if(IsTile(tileselgrid[x + TILESEL_WIDTH * y])) {
tileset.DrawPair(tileselgrid[x + TILESEL_WIDTH * y], TILE_FLOOR, dc, x * GetTileW(), y * GetTileH());
} else if(tileselgrid[x + TILESEL_WIDTH * y] == TOOL_TRAPWIRE) {
tileset.DrawPair(TILE_FLOOR, TILE_FLOOR, dc, x * GetTileW(), y * GetTileH());
trapwirex = x;
trapwirey = y;
} else if(tileselgrid[x + TILESEL_WIDTH * y] == TOOL_CLONEWIRE) {
tileset.DrawPair(TILE_FLOOR, TILE_FLOOR, dc, x * GetTileW(), y * GetTileH());
clonewirex = x;
clonewirey = y;
} else if(tileselgrid[x + TILESEL_WIDTH * y] == TOOL_RECTSELECT) {
//tileset.DrawPair(TILE_FLOOR, TILE_FLOOR, dc, x * GetTileW(), y * GetTileH());
dc->SetPen(*wxTRANSPARENT_PEN);
dc->SetBrush(*wxWHITE_BRUSH);
dc->DrawRectangle(x * GetTileW(), y * GetTileH(), GetTileW(), GetTileH());
dc->SetBrush(wxNullBrush);
dc->SetPen(wxNullPen);
dc->SetPen(*wxBLACK_DASHED_PEN);
dc->SetBrush(*wxTRANSPARENT_BRUSH);
dc->DrawRectangle(x * GetTileW() + GetTileW() / 4, y * GetTileH() + GetTileH() / 4, GetTileW() / 2, GetTileH() / 2);
dc->SetBrush(wxNullBrush);
dc->SetPen(wxNullPen);
} else {
continue;
}
if(tilelist != NULL && tilelist->IsSelected(tileselgrid[x + TILESEL_WIDTH * y])) {
int origfunc = dc->GetLogicalFunction();
dc->SetLogicalFunction(wxINVERT);
dc->SetPen(*wxTRANSPARENT_PEN);
dc->SetBrush(*wxBLACK_BRUSH);
dc->DrawRectangle((wxCoord) x * GetTileW(), (wxCoord) y * GetTileH(), GetTileW(), GetTileH());
dc->SetBrush(wxNullBrush);
dc->SetPen(wxNullPen);
dc->SetLogicalFunction(origfunc);
}
}
}
{
wxPen pen(wxColour(116, 96, 0));
dc->SetPen(pen);
dc->DrawLine( trapwirex * GetTileW() + GetTileW() / 2, (trapwirey - 1) * GetTileH() + GetTileH() / 2,
trapwirex * GetTileW() + GetTileW() / 2, (trapwirey + 1) * GetTileH() + GetTileH() / 2);
dc->SetPen(wxNullPen);
}
{
wxPen pen(wxColour(200, 0, 0));
dc->SetPen(pen);
dc->DrawLine( clonewirex * GetTileW() + GetTileW() / 2, (clonewirey - 1) * GetTileH() + GetTileH() / 2,
clonewirex * GetTileW() + GetTileW() / 2, (clonewirey + 1) * GetTileH() + GetTileH() / 2);
dc->SetPen(wxNullPen);
}
}
#if 0
void LevelEditView::SendUpdate(wxObject* hint, bool self, bool modify) {
if(self)
OnUpdate(this, hint);
wxDocument* doc = GetDocument();
if(doc != NULL) {
if(modify)
doc->Modify(true);
doc->UpdateAllViews(this, hint);
}
}
#endif
void LevelEditView::Refresh() {
if(mapwin != NULL)
mapwin->Refresh();
if(tilesel != NULL)
tilesel->Refresh();
}
void LevelEditView::OnUpdate(wxView* sender, wxObject* hint) {
LevelUpdateHint* lhint = NULL;
if(hint != NULL && hint->IsKindOf(CLASSINFO(LevelUpdateHint)))
lhint = (LevelUpdateHint*) hint;
if((lhint == NULL || lhint->type == LevelUpdateHint::CREATE || lhint->type == LevelUpdateHint::LIST || lhint->type == LevelUpdateHint::DESTROY) &&
levellist != NULL && GetDocument() != NULL && GetDocument()->IsKindOf(CLASSINFO(LevelSetDoc))) {
LevelSet* levelset = ((LevelSetDoc*) GetDocument())->GetLevelSet();
wxString* choices = new wxString[levelset->GetLevelCount()];
CountedPtr lev;
wxUint16 i;
for(i = 0; i < levelset->GetLevelCount(); ++i) {
lev = levelset->GetLevel(i);
choices[i] << lev->levelnumber << wxT(". ") << wxString(lev->title.c_str(), wxConvISO8859_1);
}
levellist->Set(levelset->GetLevelCount(), choices);
delete[] choices;
int sel = wxNOT_FOUND;
for(i = 0; i < levellist->GetCount(); ++i) {
lev = levelset->GetLevel(i);
levellist->SetClientData(i, lev);
if(lev == level)
sel = i;
}
levellist->SetSelection(sel);
OnChangeFilename();
}
if(lhint == NULL) {
delete mapbmp;
mapbmp = NULL;
AddIdleRedraw(DRAW_ALL);
} else if(lhint->level == level || lhint->level == NULL) {
if(lhint->type == LevelUpdateHint::TILE && lhint->x < 32 && lhint->y < 32) {
if(mapbmp != NULL && level != NULL && tileset.IsOk() && mapwin != NULL) {
// Only redraw the specific tile that has been changed.
wxMemoryDC dc2;
dc2.SelectObject(*mapbmp);
Tile upper, lower;
if(showupper) {
upper = level->GetUpperTile(lhint->x, lhint->y);
lower = level->GetLowerTile(lhint->x, lhint->y);
} else {
upper = level->GetLowerTile(lhint->x, lhint->y);
lower = TILE_FLOOR;
}
tileset.DrawPair(upper, lower, &dc2, lhint->x * GetTileW(), lhint->y * GetTileH());
wxDC* dc = NewClientDC();
if(dc != NULL) {
dc->Blit(lhint->x * GetTileW(), lhint->y * GetTileH(), GetTileW(), GetTileH(), &dc2, lhint->x * GetTileW(), lhint->y * GetTileH());
if(IsInSelection(lhint->x, lhint->y))
DrawSelection(dc, lhint->x, lhint->y);
delete dc;
AddIdleRedraw(DRAW_WIRES);
}
} else {
AddIdleRedraw(DRAW_MAP);
}
} else if(lhint->type == LevelUpdateHint::WIRE) {
if(showwires)
AddIdleRedraw(DRAW_MAP); // If a wire is removed, the tiles it was drawn over need redrawing.
} else if(lhint->type == LevelUpdateHint::DESTROY) {
level = NULL;
delete mapbmp;
mapbmp = NULL;
AddIdleRedraw(DRAW_MAP);
} else if(lhint->type == LevelUpdateHint::CREATE || lhint->type == LevelUpdateHint::TILE) {
delete mapbmp;
mapbmp = NULL;
AddIdleRedraw(DRAW_MAP);
}
}
wxView::OnUpdate(sender, hint);
}
void LevelEditView::OnIdle(wxIdleEvent& event) {
event.Skip();
DrawSpec draw = idleredraw;
idleredraw = DRAW_NONE; // In case of reentrance.
if(draw == DRAW_NONE) {
} else if(draw == DRAW_WIRES) {
wxDC* dc = NewClientDC();
DrawWires(dc);
delete dc;
} else if(draw == DRAW_MAP) {
if(mapwin != NULL)
mapwin->Refresh();
} else {
Refresh();
}
}
void LevelEditView::OnMouse(wxMouseEvent& event) {
event.Skip(); // Allow normal processing to take place.
if(event.GetEventObject() == NULL) {
// This is included in case tilesel or mapwin is NULL.
} else if(event.GetEventObject() == tilesel) {
int x = TILESEL_WIDTH, y = TILESEL_HEIGHT;
if(GetTileW() > 0 && GetTileH() > 0) {
tilesel->GetViewStart(&x, &y);
x += event.GetX() / GetTileW();
y += event.GetY() / GetTileH();
}
Tool hover = TOOL_NONE;
if(x < TILESEL_WIDTH && y < TILESEL_HEIGHT)
hover = tileselgrid[x + y * TILESEL_WIDTH];
if(event.ButtonDown() && hover != TOOL_NONE)
SetSelectedTool(hover);
Tool sel = GetSelectedTool();
wxString status;
status << wxT("[Selected: ") << GetToolName(sel) << wxT("]");
if(hover != TOOL_NONE)
status << wxT(" [Cursor: ") << GetToolName(hover) << wxT("]");
SetStatusText(status);
} else if(event.GetEventObject() == mapwin) {
if(level == NULL)
return;
int origx = 32, origy = 32;
if(GetTileW() > 0 && GetTileH() > 0) {
mapwin->GetViewStart(&origx, &origy);
origx += event.GetX() / GetTileW();
origy += event.GetY() / GetTileH();
}
Tool sel = GetSelectedTool();
wxString status;
status << wxT("[Selected: ") << GetToolName(sel) << wxT("]");
if(readonly)
status << wxT(" [READ ONLY]");
status << wxT(" (") << origx << wxT(", ") << origy << wxT(") - ");
if(origx < 0)
origx = 32;
if(origy < 0)
origy = 32;
wxUint32 x = origx, y = origy;
#if 0
LevelUpdateHint hint;
hint.level = level;
hint.x = x;
hint.y = y;
#endif
if(event.ButtonDown()) {
activebutton = event.GetButton();
if(GetLevelSetDoc() != NULL)
GetLevelSetDoc()->FinishLevelChangeCommand();
}
if(event.ButtonUp()) {
activebutton = wxMOUSE_BTN_NONE;
if(GetLevelSetDoc() != NULL)
GetLevelSetDoc()->FinishLevelChangeCommand();
} else if(activebutton == wxMOUSE_BTN_LEFT) {
if(!event.LeftIsDown() || event.RightIsDown() || event.MiddleIsDown())
activebutton = wxMOUSE_BTN_NONE;
} else if(activebutton == wxMOUSE_BTN_RIGHT) {
if(event.LeftIsDown() || !event.RightIsDown() || event.MiddleIsDown())
activebutton = wxMOUSE_BTN_NONE;
} else if(activebutton == wxMOUSE_BTN_MIDDLE) {
if(event.LeftIsDown() || event.RightIsDown() || !event.MiddleIsDown())
activebutton = wxMOUSE_BTN_NONE;
}
if(activebutton == wxMOUSE_BTN_NONE)
clickx = clicky = 32;
if(x < 32 && y < 32 && (event.ButtonDown() || event.Dragging())) {
wxConfigBase* config = wxConfigBase::Get();
wxString combo;
if(sel == TOOL_TRAPWIRE || sel == TOOL_CLONEWIRE)
combo << wxT("Wire");
else if(sel == TOOL_RECTSELECT)
combo << wxT("Select");
if(event.ControlDown())
combo << wxT("Control");
if(event.ShiftDown())
combo << wxT("Shift");
if(event.AltDown())
combo << wxT("Alt");
#if 0 // Apparently some systems treat Num Lock as Meta, causing trouble...
if(event.MetaDown())
combo << wxT("Meta");
#endif
if(activebutton == wxMOUSE_BTN_LEFT)
combo << wxT("Left");
else if(activebutton == wxMOUSE_BTN_RIGHT)
combo << (buttonswap ? wxT("Middle") : wxT("Right"));
else if(activebutton == wxMOUSE_BTN_MIDDLE)
combo << (buttonswap ? wxT("Right") : wxT("Middle"));
else
combo.clear();
wxString action;
if(combo == wxT("Left"))
action = wxT("PlaceTile");
else if(combo == wxT("ControlLeft"))
action = wxT("PlaceTileSpecial");
else if(combo == wxT("ShiftLeft"))
action = wxT("PlaceTileCombine");
else if(combo == wxT("ControlShiftLeft"))
action = wxT("PlaceTileCombineSpecial");
else if(combo == wxT("Right"))
action = wxT("PlaceTileLower");
else if(combo == wxT("ControlRight"))
action = wxT("PlaceTileLowerSpecial");
else if(combo == wxT("ShiftRight"))
action = wxT("PlaceTileUpper");
else if(combo == wxT("ControlShiftRight"))
action = wxT("PlaceTileUpperSpecial");
else if(combo == wxT("SelectLeft") || combo == wxT("SelectMiddle"))
action = wxT("Select");
else if(combo == wxT("SelectControlLeft") || combo == wxT("SelectControlMiddle"))
action = wxT("ClearSelect");
else if(combo == wxT("WireLeft") || combo == wxT("WireShiftMiddle"))
action = wxT("PlaceWire");
else if(combo == wxT("WireControlLeft") || combo == wxT("WireControlShiftMiddle"))
action = wxT("ClearWires");
else if(combo == wxT("WireRight"))
action = wxT("ForceWire");
else if(combo == wxT("WireControlRight"))
action = wxT("ForceWireDup");
else if(combo == wxT("WireShiftRight"))
action = wxT("SelectSingle");
else if(combo == wxT("WireControlShiftRight"))
action = wxT("SelectSingle");
else if(combo == wxT("Middle") || combo == wxT("WireMiddle"))
action = wxT("RectSelect");
else if(combo == wxT("ControlMiddle") || combo == wxT("WireControlMiddle"))
action = wxT("ClearSelect");
else if(combo == wxT("ShiftMiddle") || combo == wxT("SelectShiftMiddle"))
action = wxT("PlaceWire");
else if(combo == wxT("ControlShiftMiddle") || combo == wxT("SelectControlShiftMiddle"))
action = wxT("ClearWires");
if(config != NULL && !combo.empty())
config->Read(wxT("EditorMouseControls/") + combo, &action);
action.MakeLower();
if(action == wxT("forcewiredup") && !event.ButtonDown())
action = wxT("forcewire");
bool hadaction = false;
if((selw > 1 || selh > 1) && x >= selx && x < selx + selw && y >= sely && y < sely + selh && IsTile(sel) && action.substr(0, 9) == wxT("placetile")) {
hadaction = DoTileActionSel(sel, action/*, hint*/);
// hint.x = 32;
// hint.y = 32;
} else {
hadaction = DoTileAction(x, y, sel, action/*, hint*/);
}
if(hadaction && config != NULL && !config->Exists(wxT("EditorMouseControls/Version")))
config->Write(wxT("EditorMouseControls/Version"), (long) 1);
}
status << level->GetTileDescription(x, y);
SetStatusText(status);
#if 0
if(hint.type != LevelUpdateHint::NONE) {
OnUpdate(this, &hint);
if(GetDocument() != NULL) {
GetDocument()->Modify(true);
GetDocument()->UpdateAllViews(this, &hint);
}
}
#endif
}
}
bool LevelEditView::DoTileAction(wxUint32 x, wxUint32 y, wxUint32 tile, wxString action/*, LevelUpdateHint& hint*/, bool single) {
if(level == NULL)
return false;
bool hadaction = false;
bool placed = false;
bool special = false;
WireRecord wire;
wire.buttonx = x;
wire.buttony = y;
wire.targetx = selx;
wire.targety = sely;
if(action.size() >= 7 && action.substr(action.size() - 7) == wxT("special")) {
special = true;
action.erase(action.size() - 7);
}
if(action == wxT("placetile") && IsTile(tile)) {
hadaction = true;
if(!readonly) {
if(tile == TILE_FLOOR && special)
placed = level->RemoveProperUpper(x, y);
else
placed = level->PlaceTileOnly(x, y, tile, !special);
}
} else if(action == wxT("placetilecombine") && IsTile(tile)) {
hadaction = true;
if(!readonly)
placed = level->PlaceTileAuto(x, y, tile, !special);
} else if(action == wxT("placetilelower") && IsTile(tile)) {
hadaction = true;
if(!readonly)
placed = level->PlaceTileLower(x, y, tile, !special);
} else if(action == wxT("placetileupper") && IsTile(tile)) {
hadaction = true;
if(!readonly)
placed = level->PlaceTileUpper(x, y, tile, !special);
#if 0
} else if((tile == TOOL_TRAPWIRE || tile == TOOL_CLONEWIRE) && (action == wxT("placetile") || action == wxT("cleartile"))) {
hadaction = true;
if(IsTileWireable(level->GetUpperTile(x, y))) {
tile = level->GetUpperTile(x, y);
placed = !readonly;
} else if(IsTileWireable(level->GetLowerTile(x, y))) {
tile = level->GetLowerTile(x, y);
placed = !readonly;
}
special = (action == wxT("cleartile"));
#endif
// FIXME: Make sure the line below has correct parenthesisation.
} else if((action == wxT("rectselect") || (action == wxT("select") && tile == TOOL_RECTSELECT)) && !special) {
hadaction = true;
if(clickx >= 32 || clicky >= 32) {
clickx = x;
clicky = y;
}
wxUint32 newselx, newsely, newselw, newselh;
if((unsigned int) x < clickx) {
newselx = x;
newselw = 1 + clickx - x;
} else {
newselx = clickx;
newselw = 1 + x - clickx;
}
if((unsigned int) y < clicky) {
newsely = y;
newselh = 1 + clicky - y;
} else {
newsely = clicky;
newselh = 1 + y - clicky;
}
SetSelection(newselx, newsely, newselw, newselh);
} else if(action == wxT("clearselect") && !special) {
hadaction = true;
ClearSelection();
} else if(action == wxT("selectsingle") && !special) {
hadaction = true;
SetSelection(x, y);
} else if((action == wxT("forcewire") || action == wxT("forcewiredup")) && !special && selw == 1 && selh == 1) {
if(tile == TOOL_TRAPWIRE) {
hadaction = true;
if(!readonly)
level->AddTrapWire(wire, action == wxT("forcewiredup"));
} else if(tile == TOOL_CLONEWIRE) {
hadaction = true;
if(!readonly)
level->AddCloneWire(wire, action == wxT("forcewiredup"));
}
} else if(action == wxT("placewire") && !special) {
if((tile != TOOL_CLONEWIRE && level->HasTile(x, y, TILE_TRAP)) || (tile != TOOL_TRAPWIRE && level->HasCloner(x, y))) {
hadaction = true;
SetSelection(x, y);
} else if(selw == 1 && selh == 1) {
if(tile != TOOL_CLONEWIRE && level->HasTile(x, y, TILE_BUTTON_TRAP) && level->HasTile(selx, sely, TILE_TRAP)) {
hadaction = true;
if(!readonly)
level->SetTrapWire(wire);
}
if(tile != TOOL_TRAPWIRE && level->HasTile(x, y, TILE_BUTTON_CLONE) && level->HasCloner(selx, sely)) {
hadaction = true;
if(!readonly)
level->SetCloneWire(wire);
}
}
} else if(action == wxT("clearwires") && !special) {
hadaction = true;
if(!readonly)
level->RemoveWire(x, y, tile != TOOL_CLONEWIRE, tile != TOOL_CLONEWIRE, tile != TOOL_TRAPWIRE, tile != TOOL_TRAPWIRE);
}
if(placed) {
if(special) {
if(!readonly)
level->RemoveWire(x, y, tile);
} else if(single && (tile == TILE_TRAP || tile == TILE_CLONER)) {
SetSelection(x, y);
} else if(selw == 1 && selh == 1) {
if(tile == TILE_BUTTON_TRAP && level->HasTile(selx, sely, TILE_TRAP)) {
if(!readonly) {
// level->RemoveWire(x, y, tile);
level->SetTrapWire(wire);
}
} else if(tile == TILE_BUTTON_CLONE && level->HasCloner(selx, sely)) {
if(!readonly) {
// level->RemoveWire(x, y, tile);
level->SetCloneWire(wire);
}
} else {
ClearSelection();
}
#if 0
} else if(HasSelection()) {
ClearSelection();
}
#endif
} else if(/*HasSelection() &&*/ (x < selx || x >= selx + selw || y < sely || y >= sely + selh)) {
ClearSelection();
}
}
return hadaction;
}
bool LevelEditView::DoTileActionSel(wxUint32 tile, wxString action/*, LevelUpdateHint& hint*/) {
if(selx >= 32 || sely >= 32 || selw < 1 || selh < 1)
return false;
if(selw == 1 && selh == 1)
return DoTileAction(selx, sely, tile, action/*, hint*/, true);
bool hadaction = false;
for(wxUint32 y = sely; y < sely + selh; ++y) {
for(wxUint32 x = selx; x < selx + selw; ++x) {
if(DoTileAction(x, y, tile, action/*, hint*/, false))
hadaction = true;
}
}
return hadaction;
}
}
chipw-2.0.6/src/levelchange.cpp 0000644 0001750 0001750 00000006747 11672412350 013341 0000000 0000000 // Chip's Workshop - a level editor for Chip's Challenge.
// Copyright 2008-2011 Christopher Elsby
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License as
// published by the Free Software Foundation.
//
// 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 .
#include "global.h"
#include "levelchange.h"
#include "level.h"
namespace ChipW {
bool LevelChange::Do(CountedPtr level, bool reverse) {
if(reverse != isdone)
return true;
if(level == NULL)
return false;
if(!PerformChange(level, reverse))
return false;
isdone = !reverse;
if(level->GetMonitor() != NULL)
level->GetMonitor()->OnLevelChange(level, this, false, reverse);
return true;
}
bool LevelChangeTile::PerformChange(CountedPtr level, bool reverse) {
if(level == NULL || x >= 32 || y >= 32)
return false;
if(type != UPPER && type != LOWER)
return false;
Tile& tile = ((type == UPPER) ? level->upper : level->lower)[x + 32 * y];
if(tile != (reverse ? after : before))
return false;
tile = (reverse ? before : after);
return true;
}
bool LevelChangeMonster::PerformChange(CountedPtr level, bool reverse) {
if(level == NULL)
return false;
if(type == DELMONSTER)
reverse = !reverse;
else if(type != ADDMONSTER)
return false;
std::list& list = level->monsters;
std::list::iterator it;
wxUint32 i;
if(reverse) {
// Remove.
if(index >= list.size())
return false;
it = list.begin();
for(i = 0; i < index; ++i)
++it;
if(*it != record)
return false;
list.erase(it);
} else {
// Add.
if(index > list.size())
return false;
if(index == list.size()) {
list.push_back(record);
} else {
it = list.begin();
for(i = 0; i < index; ++i)
++it;
list.insert(it, record);
}
}
return true;
}
bool LevelChangeWire::PerformChange(CountedPtr level, bool reverse) {
if(level == NULL)
return false;
if(type == DELTRAPWIRE || type == DELCLONEWIRE)
reverse = !reverse;
else if(type != ADDTRAPWIRE && type != ADDCLONEWIRE)
return false;
std::list& list = ((type == ADDTRAPWIRE || type == DELTRAPWIRE) ? level->trapwires : level->clonewires);
std::list::iterator it;
wxUint32 i;
if(reverse) {
// Remove.
if(index >= list.size())
return false;
it = list.begin();
for(i = 0; i < index; ++i)
++it;
if(*it != record)
return false;
list.erase(it);
} else {
// Add.
if(index > list.size())
return false;
if(index == list.size()) {
list.push_back(record);
} else {
it = list.begin();
for(i = 0; i < index; ++i)
++it;
list.insert(it, record);
}
}
return true;
}
}
chipw-2.0.6/src/refcount.h 0000644 0001750 0001750 00000006337 11672412350 012351 0000000 0000000 // Chip's Workshop - a level editor for Chip's Challenge.
// Copyright 2008-2011 Christopher Elsby
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License as
// published by the Free Software Foundation.
//
// 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 .
#ifndef CHIPW_REFCOUNT_H_INCLUDED
#define CHIPW_REFCOUNT_H_INCLUDED
#ifdef CHIPW_DEBUG_REFCOUNT
#include
#endif
#include
namespace ChipW {
class RefCounted {
public:
RefCounted() : id(++nextid) {
#ifdef CHIPW_DEBUG_REFCOUNT
std::cout << "Object " << id << " created." << std::endl;
#endif
}
virtual ~RefCounted() {
#ifdef CHIPW_DEBUG_REFCOUNT
std::cout << "Object " << id << " destroyed." << std::endl;
#endif
}
void RefAdd() {if(refcount.n >= 0) ++refcount.n;
#ifdef CHIPW_DEBUG_REFCOUNT
if(refcount.n == 1) std::cout << typeid(*this).name() << " " << id << " referenced to " << refcount.n << "." << std::endl;
#endif
}
static void RefAdd(RefCounted* obj) {if(obj != NULL) obj->RefAdd();}
void RefStatic() {refcount.n = -1;}
bool RefRemove() {if(refcount.n > 0) --refcount.n;
#ifdef CHIPW_DEBUG_REFCOUNT
//std::cout << typeid(*this).name() << " " << id << " unreferenced to " << refcount.n << "." << std::endl;
#endif
return refcount.n == 0;}
void RefDel() {if(RefRemove()) delete this;}
void AssertDel() {if(RefRemove()) delete this; else wxLogError(wxT("Object had trailing references."));}
static void RefDel(RefCounted* obj) {if(obj != NULL) obj->RefDel();}
long GetRefCount() const {return refcount.n;}
void SetRefCount(long nrefs) {refcount.n = nrefs;}
private:
// This sub-object is used so that a class depending on automatic memberwise copy
// does not copy the reference count.
struct RefCount {
RefCount() : n(0) { }
RefCount(const RefCount& copy) : n(0) { }
RefCount& operator=(const RefCount& copy) {return *this;}
long n;
};
RefCount refcount;
long id;
static long nextid;
};
inline void RefAdd(RefCounted* obj) {if(obj != NULL) obj->RefAdd();}
inline void RefDel(RefCounted* obj) {if(obj != NULL) obj->RefDel();}
template
class CountedPtr {
public:
CountedPtr(T* ob = NULL) : obj(ob) {RefAdd(obj);}
CountedPtr(const CountedPtr& copy) : obj(copy.obj) {RefAdd(obj);}
~CountedPtr() {RefDel(obj);}
CountedPtr& operator=(T* ob) {RefAdd(ob); RefDel(obj); obj = ob; return *this;}
CountedPtr& operator=(const CountedPtr& copy) {RefAdd(copy.obj); RefDel(obj); obj = copy.obj; return *this;}
operator T*() const {return obj;}
T& operator*() const {return *obj;}
T* operator->() const {return obj;}
bool operator!() const {return !obj;}
T* Steal() {T* ob = obj; obj = NULL; return ob;}
private:
T* obj;
};
}
#endif // !defined(CHIPW_REFCOUNT_H_INCLUDED)
chipw-2.0.6/src/wxtostdstream.h 0000644 0001750 0001750 00000013645 11672412350 013454 0000000 0000000 // Chip's Workshop - a level editor for Chip's Challenge.
// Copyright 2008-2011 Christopher Elsby
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License as
// published by the Free Software Foundation.
//
// 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 .
#ifndef CHIPW_WXTOSTDSTREAM_H_INCLUDED
#define CHIPW_WXTOSTDSTREAM_H_INCLUDED
#include
#include
#include
#include
namespace ChipW {
template >
class basic_wxstreambuf : public std::basic_streambuf {
public:
typedef charT char_type;
typedef traits traits_type;
typedef typename traits::int_type int_type;
typedef typename traits::pos_type pos_type;
typedef typename traits::off_type off_type;
explicit basic_wxstreambuf(wxOutputStream* out = NULL, wxInputStream* in = NULL)
: wxout(out), wxin(in), inputbuffer(traits::eof()) { }
explicit basic_wxstreambuf(wxInputStream* in)
: wxout(NULL), wxin(in), inputbuffer(traits::eof()) { }
wxOutputStream* GetWXOut() const {return wxout;}
wxInputStream* GetWXIn() const {return wxin;}
void SetWXOut(wxOutputStream* out) {wxout = out;}
void SetWXIn(wxInputStream* in) {wxin = in;}
protected:
virtual basic_wxstreambuf* setbuf(char_type* s, std::streamsize n) {return NULL;}
virtual int_type underflow();
virtual int_type uflow();
virtual int_type overflow(int_type c = traits::eof());
virtual std::streamsize xsgetn(char_type* s, std::streamsize n);
virtual std::streamsize xsputn(const char_type* s, std::streamsize n);
private:
wxOutputStream* wxout;
wxInputStream* wxin;
int_type inputbuffer; // Needed for underflow().
};
typedef basic_wxstreambuf wxstreambuf;
template >
class basic_owxstream : public std::basic_ostream {
public:
explicit basic_owxstream(wxOutputStream* out = NULL) : std::basic_ostream(&buf), buf(out) { }
wxOutputStream* GetWXOut() const {return buf.GetWXOut();}
void SetWXOut(wxOutputStream* out) {buf.SetWXOut(out);}
private:
basic_wxstreambuf buf;
};
typedef basic_owxstream owxstream;
template >
class basic_iwxstream : public std::basic_istream {
public:
explicit basic_iwxstream(wxInputStream* in = NULL) : std::basic_istream(&buf), buf(in) { }
wxInputStream* GetWXIn() const {return buf.GetWXIn();}
void SetWXIn(wxInputStream* in) {buf.SetWXIn(in);}
private:
basic_wxstreambuf buf;
};
typedef basic_iwxstream iwxstream;
template >
class basic_wxstream : public std::basic_iostream {
public:
explicit basic_wxstream(wxOutputStream* out = NULL, wxInputStream* in = NULL) : std::basic_iostream(&buf), buf(out, in) { }
explicit basic_wxstream(wxInputStream* in) : std::basic_iostream(&buf), buf(in) { }
wxOutputStream* GetWXOut() const {return buf.GetWXOut();}
void SetWXOut(wxOutputStream* out) {buf.SetWXOut(out);}
wxInputStream* GetWXIn() const {return buf.GetWXIn();}
void SetWXIn(wxInputStream* in) {buf.SetWXIn(in);}
private:
basic_wxstreambuf buf;
};
typedef basic_wxstream wxstream;
template
typename basic_wxstreambuf::int_type basic_wxstreambuf::underflow() {
if(inputbuffer == traits::eof()) {
if(wxin == NULL || !wxin->IsOk() || wxin->Eof())
return traits::eof();
char_type buf;
wxin->Read(&buf, sizeof(char_type));
if(wxin->LastRead() < sizeof(char_type))
return traits::eof();
inputbuffer = buf;
}
return inputbuffer;
}
template
typename basic_wxstreambuf::int_type basic_wxstreambuf::uflow() {
int_type result = underflow();
inputbuffer = traits::eof();
return result;
}
template
typename basic_wxstreambuf::int_type basic_wxstreambuf::overflow(basic_wxstreambuf::int_type c) {
if(c == traits::eof())
return 0;
if(wxout == NULL || !wxout->IsOk())
return traits::eof();
char_type buf = c;
wxout->Write(&buf, sizeof(char_type));
if(wxout->LastWrite() < sizeof(char_type))
return traits::eof();
return 0;
}
template
std::streamsize basic_wxstreambuf::xsgetn(basic_wxstreambuf::char_type* s, std::streamsize n) {
if(s == NULL || n < 1)
return 0;
std::streamsize result = 0;
if(inputbuffer != traits::eof()) {
*s = inputbuffer;
inputbuffer = traits::eof();
++s;
--n;
++result;
}
if(wxin == NULL || !wxin->IsOk() || wxin->Eof())
return result;
wxin->Read(s, n * sizeof(char_type));
result += wxin->LastRead() / sizeof(char_type);
return result;
}
template
std::streamsize basic_wxstreambuf::xsputn(const basic_wxstreambuf::char_type* s, std::streamsize n) {
if(s == NULL || wxout == NULL || !wxout->IsOk())
return 0;
wxout->Write(s, n * sizeof(char_type));
return wxout->LastWrite() / sizeof(char_type);
}
}
#endif // !CHIPW_WXTOSTDSTREAM_H_INCLUDED
chipw-2.0.6/src/playtestproc.h 0000644 0001750 0001750 00000002344 11672412350 013247 0000000 0000000 // Chip's Workshop - a level editor for Chip's Challenge.
// Copyright 2008-2011 Christopher Elsby
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License as
// published by the Free Software Foundation.
//
// 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 .
#ifndef CHIPW_PLAYTESTPROC_H_INCLUDED
#define CHIPW_PLAYTESTPROC_H_INCLUDED
#include
#include
#include
namespace ChipW {
class LevelSet;
class PlayTestProcess : public wxProcess {
public:
PlayTestProcess();
~PlayTestProcess();
static wxString GetArgumentQuoted(wxString arg);
bool Launch(wxString gamecmd, const LevelSet& levelset, wxUint16 levelnumber = 1, wxString workingdir = wxEmptyString);
private:
wxString tmpfilename;
};
}
#endif // !CHIPW_PLAYTESTPROC_H_INCLUDED
chipw-2.0.6/src/leveleditids.h 0000644 0001750 0001750 00000002333 11672412350 013171 0000000 0000000 // Chip's Workshop - a level editor for Chip's Challenge.
// Copyright 2008-2011 Christopher Elsby
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License as
// published by the Free Software Foundation.
//
// 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 .
#ifndef CHIPW_LEVELEDITIDS_H_INCLUDED
#define CHIPW_LEVELEDITIDS_H_INCLUDED
namespace ChipW {
enum {
ID_SHOWWIRES = wxID_HIGHEST + 1,
ID_SHOWUPPER,
ID_SETTILESET,
ID_SETTILESIZE,
ID_EDIT_MONSTERS,
ID_EDIT_WIRES,
ID_CLEARSELTILES,
ID_READONLY,
ID_SWAPBUTTONS,
ID_NEWVIEW,
ID_CLOSEVIEW,
ID_ROTATE_TILE_ANTICLOCKWISE,
ID_ROTATE_TILE_CLOCKWISE,
ID_PLAYTEST_CONFIG,
ID_PLAYTEST_MIN,
ID_PLAYTEST_MAX = ID_PLAYTEST_MIN + 8,
};
}
#endif // !CHIPW_LEVELEDITIDS_H_INCLUDED
chipw-2.0.6/src/app.h 0000644 0001750 0001750 00000003547 11672412350 011304 0000000 0000000 // Chip's Workshop - a level editor for Chip's Challenge.
// Copyright 2008-2011 Christopher Elsby
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License as
// published by the Free Software Foundation.
//
// 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 .
#ifndef CHIPW_APP_H_INCLUDED
#define CHIPW_APP_H_INCLUDED
#include
#include
#include
class wxDocManager;
namespace ChipW {
class PlayTestManager;
class App : public wxApp {
public:
App();
virtual bool OnInit();
virtual void OnInitCmdLine(wxCmdLineParser& parser);
virtual bool OnCmdLineParsed(wxCmdLineParser& parser);
virtual int OnExit();
// Get the playtest menu manager.
PlayTestManager* GetPlayTestManager() const {return playtestmgr;}
// Register a temporary file to be deleted on program exit.
void RegisterTmpFile(wxString filename) {tmpfiles.insert(filename);}
// Unregister a temporary file so that it will not be deleted on program exit.
void UnregisterTmpFile(wxString filename) {tmpfiles.erase(filename);}
// Deletes and unregisters the given temporary file if it is currently registered.
void RemoveTmpFile(wxString filename);
private:
void OnCommand(wxCommandEvent& event);
wxDocManager* docmgr;
PlayTestManager* playtestmgr;
bool autostart;
std::set tmpfiles;
DECLARE_EVENT_TABLE()
};
}
DECLARE_APP(ChipW::App)
#endif // !CHIPW_APP_H_INCLUDED
chipw-2.0.6/src/playtestmgr.cpp 0000644 0001750 0001750 00000007345 11672412350 013432 0000000 0000000 // Chip's Workshop - a level editor for Chip's Challenge.
// Copyright 2008-2011 Christopher Elsby
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License as
// published by the Free Software Foundation.
//
// 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 .
#include "global.h"
#include "playtestmgr.h"
#include "leveleditids.h"
#include "ruleset.h"
#include
namespace ChipW {
PlayTestManager::PlayTestManager()
: ListMenuManager(ID_PLAYTEST_MIN, ID_PLAYTEST_MAX, wxT("Not configured"))
{
LoadTypes();
}
void PlayTestManager::SetTypes(std::vector newtypes, bool saveconfig) {
std::vector newmenuitems(newtypes.size());
for(size_t i = 0; i < newtypes.size(); ++i)
newmenuitems[i] = newtypes[i].name;
SetMenuItems(newmenuitems);
types.swap(newtypes);
if(saveconfig)
SaveTypes();
}
std::vector PlayTestManager::GetConfTypes() {
wxConfigBase* config = wxConfigBase::Get();
if(config == NULL)
return std::vector();
wxString prefix = wxT("PlayTestProfiles/");
long count = config->Read(prefix + wxT("Count"), 0L);
if(config->Read(prefix + wxT("ConfigVersion"), 2L) < 2)
count = 0;
std::vector types(count);
for(unsigned int i = 0; i < types.size(); ++i) {
wxString profileprefix = prefix;
profileprefix << wxT("Profile") << (i + 1) << wxT("/");
config->Read(profileprefix + wxT("Name"), &types[i].name);
config->Read(profileprefix + wxT("Program"), &types[i].program);
config->Read(profileprefix + wxT("Arguments"), &types[i].arguments);
config->Read(profileprefix + wxT("WorkingDirectory"), &types[i].workingdir);
config->Read(profileprefix + wxT("OverrideRuleSet"), &types[i].ruleset.hasruleset);
if(types[i].ruleset.hasruleset)
types[i].ruleset.ruleset = (RuleSetId) config->Read(profileprefix + wxT("RuleSetId"), (long) types[i].ruleset.ruleset);
}
return types;
}
void PlayTestManager::SetConfTypes(const std::vector& types) {
wxConfigBase* config = wxConfigBase::Get();
if(config == NULL)
return;
wxString prefix = wxT("PlayTestProfiles/");
config->Write(prefix + wxT("ConfigVersion"), 2L);
unsigned int oldcount = config->Read(prefix + wxT("Count"), 0L);
config->Write(prefix + wxT("Count"), (long) types.size());
unsigned int i;
for(i = 0; i < types.size(); ++i) {
wxString profileprefix = prefix;
profileprefix << wxT("Profile") << (i + 1) << wxT("/");
config->Write(profileprefix + wxT("ConfigVersion"), 2L);
config->Write(profileprefix + wxT("Name"), types[i].name);
config->Write(profileprefix + wxT("Program"), types[i].program);
config->Write(profileprefix + wxT("Arguments"), types[i].arguments);
config->Write(profileprefix + wxT("WorkingDirectory"), types[i].workingdir);
config->Write(profileprefix + wxT("OverrideRuleSet"), types[i].ruleset.hasruleset);
if(types[i].ruleset.hasruleset)
config->Write(profileprefix + wxT("RuleSetId"), (long) types[i].ruleset.ruleset);
}
for(; i < oldcount; ++i) {
wxString profilegroup = prefix;
profilegroup << wxT("Profile") << (i + 1);
config->DeleteGroup(profilegroup);
}
}
}
chipw-2.0.6/src/leveleditframe.cpp 0000644 0001750 0001750 00000020507 11672412350 014042 0000000 0000000 // Chip's Workshop - a level editor for Chip's Challenge.
// Copyright 2008-2011 Christopher Elsby
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License as
// published by the Free Software Foundation.
//
// 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 .
#include "global.h"
#include "leveleditframe.h"
#include "leveleditids.h"
#include "app.h"
#include "playtestmgr.h"
#include
#include
namespace ChipW {
IMPLEMENT_CLASS(LevelEditFrame, SDIDocFrame)
BEGIN_EVENT_TABLE(LevelEditFrame, SDIDocFrame)
EVT_MENU(-1, LevelEditFrame::OnCommand)
EVT_BUTTON(-1, LevelEditFrame::OnCommand)
EVT_UPDATE_UI(-1, LevelEditFrame::OnUpdateUI)
END_EVENT_TABLE()
std::map > LevelEditFrame::spare;
LevelEditFrame* LevelEditFrame::GetSpareOrNew(wxView* view) {
LevelEditFrame* result = NULL;
wxDocManager* manager = NULL;
if(view != NULL)
manager = view->GetDocumentManager();
if(manager != NULL) {
std::map >::iterator it = spare.find(manager);
if(it != spare.end()) {
if(!it->second.empty()) {
result = it->second.back();
it->second.pop_back();
}
if(it->second.empty())
spare.erase(it);
}
}
if(result == NULL)
return new LevelEditFrame(view);
result->SetView(view);
return result;
}
LevelEditFrame::~LevelEditFrame() {
ListMenuManager* playtestmgr = wxGetApp().GetPlayTestManager();
if(playtestmgr != NULL)
playtestmgr->DetachMenu(playtestmenu);
if(GetDocumentManager() != NULL) {
std::map >::iterator it = spare.find(GetDocumentManager());
if(it != spare.end()) {
for(std::vector::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) {
if(*it2 == this) {
it->second.erase(it2);
break;
}
}
if(it->second.empty())
spare.erase(it);
}
}
}
bool LevelEditFrame::Create(wxDocManager* manager, wxFrame* parent, bool isspare) {
if(!SDIDocFrame::Create(manager, parent, -1, wxT("Chip's Workshop"), wxDefaultPosition, wxSize(800, 600), wxDEFAULT_FRAME_STYLE | wxMAXIMIZE))
return false;
if(!CreateMenuBar())
return false;
CreateStatusBar();
if(isspare && manager != NULL)
spare[manager].push_back(this);
return true;
}
bool LevelEditFrame::Create(wxView* newview, wxFrame* parent) {
if(!SDIDocFrame::Create(newview, parent, -1, wxT("Chip's Workshop"), wxDefaultPosition, wxSize(800, 600), wxDEFAULT_FRAME_STYLE | wxMAXIMIZE))
return false;
if(!CreateMenuBar())
return false;
CreateStatusBar();
return true;
}
bool LevelEditFrame::CreateMenuBar() {
wxMenuBar* menubar = new wxMenuBar;
// File menu.
wxMenu* menu = new wxMenu;
menu->Append(wxID_NEW, wxT("&New...\tCtrl+N"), wxT("Create a new document."));
menu->Append(wxID_OPEN, wxT("&Open...\tCtrl+O"), wxT("Open a file."));
menu->AppendSeparator();
menu->Append(wxID_SAVE, wxT("&Save...\tCtrl+S"), wxT("Save the current document."));
menu->Append(wxID_SAVEAS, wxT("Save &As..."), wxT("Save the current document to a new file."));
menu->Append(wxID_CLOSE, wxT("&Close...\tCtrl+W"), wxT("Close the current document."));
menu->AppendSeparator();
menu->Append(wxID_EXIT, wxT("E&xit...\tCtrl+Q"), wxT("Exit the program, closing all open documents."));
menubar->Append(menu, wxT("&File"));
// Edit menu.
menu = new wxMenu;
menu->Append(wxID_UNDO, wxT("&Undo\tCtrl+Z"), wxT("Undo the last action."));
menu->Append(wxID_REDO, wxT("&Redo\tCtrl+Y"), wxT("Redo the last undone action."));
menu->AppendSeparator();
menu->Append(wxID_CUT, wxT("Cu&t\tCtrl+X"), wxT("Move the selection to the clipboard."));
menu->Append(wxID_COPY, wxT("&Copy\tCtrl+C"), wxT("Copy the selection to the clipboard."));
menu->Append(wxID_PASTE, wxT("&Paste\tCtrl+V"), wxT("Insert the contents of the clipboard."));
#if 0
menu->AppendSeparator();
menu->AppendCheckItem(ID_SWAPBUTTONS, wxT("&Swap secondary mouse buttons\tCtrl+1"),
wxT("Switch the functions of the right and middle mouse buttons."));
#endif
menu->AppendSeparator();
menu->Append(wxID_PROPERTIES, wxT("&Properties...\tCtrl+P"), wxT("View or adjust the level properties."));
menu->Append(ID_EDIT_MONSTERS, wxT("&Monsters...\tCtrl+M"), wxT("View or adjust the monster list."));
// menu->Append(ID_EDIT_WIRES, wxT("&Wires...\tCtrl+W"), wxT("View or adjust the wire list."));
menu->AppendSeparator();
menu->Append(ID_CLEARSELTILES, wxT("Clear selecte&d tiles\tDel"), wxT("Remove all tiles in the selected area."));
menu->AppendSeparator();
menu->Append(ID_ROTATE_TILE_ANTICLOCKWISE, wxT("Rotate tile antic&lockwise\tCtrl+Left"), wxT("Rotate the currently chosen tile anticlockwise."));
menu->Append(ID_ROTATE_TILE_CLOCKWISE, wxT("Rotate tile cl&ockwise\tCtrl+Right"), wxT("Rotate the currently chosen tile clockwise."));
menu->AppendSeparator();
menu->AppendCheckItem(ID_READONLY, wxT("Re&ad only\tCtrl+R"), wxT("Toggle the ability to edit the level."));
menubar->Append(menu, wxT("&Edit"));
// Playtest menu.
playtestmenu = new wxMenu;
playtestmenu->Append(ID_PLAYTEST_CONFIG, wxT("&Configure..."), wxT("Choose programs for playtesting."));
playtestmenu->AppendSeparator();
ListMenuManager* playtestmgr = wxGetApp().GetPlayTestManager();
if(playtestmgr != NULL)
playtestmgr->AddMenu(playtestmenu);
menubar->Append(playtestmenu, wxT("&Playtest"));
// View menu.
menu = new wxMenu;
menu->AppendCheckItem(ID_SHOWWIRES, wxT("Show &wires\tCtrl+2"), wxT("Toggle the display of wires."));
menu->AppendCheckItem(ID_SHOWUPPER, wxT("Show &upper layer\tCtrl+3"), wxT("Toggle the display of the upper layer of tiles."));
menu->AppendSeparator();
menu->Append(ID_SETTILESET, wxT("Select &tileset...\tCtrl+T"), wxT("Select the tileset for displaying the level map."));
menu->Append(ID_SETTILESIZE, wxT("&Scale tiles...\tCtrl+Shift+T"), wxT("Change the size of display of the tiles."));
menu->AppendSeparator();
menu->Append(ID_NEWVIEW, wxT("&New window\tCtrl+Shift+N"), wxT("Open a new window for the current document."));
menu->Append(ID_CLOSEVIEW, wxT("&Close window...\tCtrl+Shift+W"), wxT("Close the current window."));
menubar->Append(menu, wxT("&View"));
// Help menu.
menu = new wxMenu;
menu->Append(wxID_HELP_CONTENTS, wxT("&User's guide\tF1"), wxT("Open the program help file."));
menu->Append(wxID_ABOUT, wxT("&About..."), wxT("Display the program version number and copyright information."));
menubar->Append(menu, wxT("&Help"));
// Set the menu bar.
SetMenuBar(menubar);
return true;
}
void LevelEditFrame::OnCommand(wxCommandEvent& event) {
switch(event.GetId()) {
case ID_CLOSEVIEW:
Close();
break;
default:
event.Skip();
}
}
void LevelEditFrame::OnUpdateUI(wxUpdateUIEvent& event) {
switch(event.GetId()) {
case ID_SWAPBUTTONS:
case wxID_CUT:
case wxID_COPY:
case wxID_PASTE:
case wxID_PROPERTIES:
case ID_EDIT_MONSTERS:
case ID_EDIT_WIRES:
case ID_CLEARSELTILES:
case ID_ROTATE_TILE_ANTICLOCKWISE:
case ID_ROTATE_TILE_CLOCKWISE:
case ID_READONLY:
case ID_SHOWWIRES:
case ID_SHOWUPPER:
case ID_SETTILESET:
case ID_SETTILESIZE:
case ID_NEWVIEW:
event.Enable(GetView() != NULL);
break;
default:
{
ListMenuManager* playtestmgr = wxGetApp().GetPlayTestManager();
if(playtestmgr != NULL && playtestmgr->HasId(event.GetId()))
event.Enable(playtestmgr->IsIdActive(event.GetId()) && GetView() != NULL);
else
event.Skip();
}
}
}
}
chipw-2.0.6/src/levelupdatehint.h 0000644 0001750 0001750 00000003117 11672412350 013712 0000000 0000000 // Chip's Workshop - a level editor for Chip's Challenge.
// Copyright 2008-2011 Christopher Elsby
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License as
// published by the Free Software Foundation.
//
// 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 .
#ifndef CHIPW_LEVELUPDATEHINT_H_INCLUDED
#define CHIPW_LEVELUPDATEHINT_H_INCLUDED
#include
#include
#include "level.h"
namespace ChipW {
class LevelUpdateHint : public wxObject {
public:
enum Type {
NONE,
MONSTER, // Change of monster status of tile (x, y).
WIRE, // Change of wires at (x, y) (and potential change in monsters).
TILE, // Change of tile (x, y) in level (and potential change in wires/monster); whole map if invalid x or y.
LIST, // Change of level list.
CREATE, // Creation of level.
DESTROY, // Deletion of level.
};
LevelUpdateHint() : type(NONE), level(NULL), x(0xFFFFFFFF), y(0xFFFFFFFF) { }
Type type;
CountedPtr level;
wxUint32 x, y;
private:
DECLARE_DYNAMIC_CLASS(LevelUpdateHint)
};
}
#endif // !CHIPW_LEVELUPDATEHINT_H_INCLUDED
chipw-2.0.6/src/levelpropertiesdlg.cpp 0000644 0001750 0001750 00000013322 11672412350 014762 0000000 0000000 // Chip's Workshop - a level editor for Chip's Challenge.
// Copyright 2008-2011 Christopher Elsby
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License as
// published by the Free Software Foundation.
//
// 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 .
#include "global.h"
#include "levelpropertiesdlg.h"
#include "level.h"
#include "valruleset.h"
#include
#include
#include
#include
#include
#include
#include
namespace ChipW {
BEGIN_EVENT_TABLE(LevelPropertiesDialog, wxDialog)
EVT_BUTTON(-1, LevelPropertiesDialog::OnCommand)
END_EVENT_TABLE()
enum {
ID_RANDPSW = wxID_HIGHEST + 1,
};
LevelPropertiesDialog::LevelPropertiesDialog(wxWindow* parent, bool readonly)
: wxDialog(parent, -1, wxT("Level properties"), wxDefaultPosition, wxDefaultSize), pswbox(NULL)
{
wxArrayString allowedChars;
{
allowedChars.Alloc(255);
char str[2];
str[1] = 0;
for(str[0] = 1; str[0] != (char) 256; ++str[0])
allowedChars.Add(wxString(str, wxConvISO8859_1));
#if 0 // Debug code to test safety of caller when faced with invalid characters.
allowedChars.Add(wxString("\xE2\x82\xAC", wxConvUTF8)); // Euro sign, not in ISO-8859-1
#endif
}
long style = readonly ? wxTE_READONLY : 0;
wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
wxFlexGridSizer* settingsizer = new wxFlexGridSizer(2);
settingsizer->Add(new wxStaticText(this, -1, wxT("Title:")), 0, wxALL | wxALIGN_RIGHT, 5);
{
wxTextValidator val(wxFILTER_INCLUDE_CHAR_LIST, &title);
val.SetIncludes(allowedChars);
settingsizer->Add(new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, style,
val), 0, wxALL | wxGROW, 5);
}
if(readonly) {
settingsizer->Add(new wxStaticText(this, -1, wxT("Password:")), 0, wxALL | wxALIGN_RIGHT, 5);
} else {
settingsizer->Add(new wxButton(this, ID_RANDPSW, wxT("Password:"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT),
0, wxALL | wxALIGN_RIGHT, 5);
}
{
wxTextValidator val(wxFILTER_INCLUDE_CHAR_LIST, &psw);
val.SetIncludes(allowedChars);
settingsizer->Add(pswbox = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, style,
val), 0, wxALL | wxGROW, 5);
}
settingsizer->Add(new wxStaticText(this, -1, wxT("Chips required:")), 0, wxALL | wxALIGN_RIGHT, 5);
settingsizer->Add(new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, style,
wxTextValidator(wxFILTER_NUMERIC, &chips)), 0, wxALL | wxGROW, 5);
settingsizer->Add(new wxStaticText(this, -1, wxT("Chips in level:")), 0, wxALL | wxALIGN_RIGHT, 5);
settingsizer->Add(new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_READONLY,
wxTextValidator(wxFILTER_NUMERIC, &countedchips)), 0, wxALL | wxGROW, 5);
settingsizer->Add(new wxStaticText(this, -1, wxT("Time limit:")), 0, wxALL | wxALIGN_RIGHT, 5);
settingsizer->Add(new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, style,
wxTextValidator(wxFILTER_NUMERIC, &time)), 0, wxALL | wxGROW, 5);
settingsizer->Add(new wxStaticText(this, -1, wxT("Hint:")), 0, wxALL | wxALIGN_RIGHT, 5);
{
wxTextValidator val(wxFILTER_INCLUDE_CHAR_LIST, &hint);
val.SetIncludes(allowedChars);
settingsizer->Add(new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, style,
val), 0, wxALL | wxGROW, 5);
}
settingsizer->AddGrowableCol(1);
sizer->Add(settingsizer, 0, wxGROW);
sizer->Add(new wxStaticText(this, -1, wxT("Rule set (applies to the whole level set; choose MS to support both MS and Lynx):")),
0, wxALL, 5);
RuleSetValidator valruleset(&ruleset);
if(readonly) {
sizer->Add(new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, style,
valruleset), 0, wxALL | wxGROW, 5);
} else {
sizer->Add(new wxComboBox(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, valruleset.GetChoices(), wxCB_DROPDOWN,
valruleset), 0, wxALL | wxGROW, 5);
}
sizer->Add(new wxStaticText(this, -1, wxT("Internal level number - do not change unless you know what you are doing!")),
0, wxALL, 5);
sizer->Add(new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, style,
wxTextValidator(wxFILTER_NUMERIC, &levnum)), 0, wxALL | wxGROW, 5);
#if 0
wxBoxSizer* buttonsizer = new wxBoxSizer(wxHORIZONTAL);
wxButton* okbutton = new wxButton(this, wxID_OK, wxT("&OK"));
okbutton->SetDefault();
buttonsizer->Add(okbutton, 0, wxALL, 5);
buttonsizer->Add(new wxButton(this, wxID_CANCEL, wxT("&Cancel")), 0, wxALL, 5);
#endif
wxSizer* buttonsizer = CreateButtonSizer(wxOK | wxCANCEL);
if(buttonsizer != NULL)
sizer->Add(buttonsizer, 0, wxGROW);
SetSizerAndFit(sizer);
}
#if !wxCHECK_VERSION(2, 8, 0)
#define ChangeValue SetValue
#endif
void LevelPropertiesDialog::OnCommand(wxCommandEvent& event) {
switch(event.GetId()) {
case ID_RANDPSW:
if(pswbox != NULL) {
std::string randpsw = Level::RandPsw();
pswbox->ChangeValue(wxString(randpsw.c_str(), wxConvISO8859_1));
}
break;
default:
event.Skip();
}
}
}
chipw-2.0.6/src/bufferscroll.cpp 0000644 0001750 0001750 00000003237 11672412350 013543 0000000 0000000 // Chip's Workshop - a level editor for Chip's Challenge.
// Copyright 2008-2011 Christopher Elsby
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License as
// published by the Free Software Foundation.
//
// 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 .
#include "global.h"
#include "bufferscroll.h"
#include
namespace ChipW {
BEGIN_EVENT_TABLE(BufferedScrolledWindow, wxScrolledWindow)
EVT_PAINT(BufferedScrolledWindow::OnPaint)
END_EVENT_TABLE()
BufferedScrolledWindow::BufferedScrolledWindow() {
}
BufferedScrolledWindow::BufferedScrolledWindow(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
long style, const wxString& name) {
Create(parent, id, pos, size, style, name);
}
bool BufferedScrolledWindow::Create(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
long style, const wxString& name) {
if(!wxScrolledWindow::Create(parent, id, pos, size, style, name))
return false;
SetBackgroundStyle(wxBG_STYLE_CUSTOM);
return true;
}
void BufferedScrolledWindow::OnPaint(wxPaintEvent& event) {
wxBufferedPaintDC dc(this);
dc.SetBackground(wxBrush(GetBackgroundColour()));
dc.Clear();
DoPrepareDC(dc);
OnDraw(dc);
}
}
chipw-2.0.6/src/monsterlistdlg.cpp 0000644 0001750 0001750 00000035516 11672412350 014132 0000000 0000000 // Chip's Workshop - a level editor for Chip's Challenge.
// Copyright 2008-2011 Christopher Elsby
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License as
// published by the Free Software Foundation.
//
// 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 .
#include "global.h"
#include "monsterlistdlg.h"
#include "level.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
namespace ChipW {
namespace {
class MonsterRecordData : public wxClientData, public MonsterRecord {
public:
MonsterRecordData() { }
MonsterRecordData(const MonsterRecord& copy) {x = copy.x; y = copy.y;}
MonsterRecordData& operator=(const MonsterRecord& copy) {x = copy.x; y = copy.y; return *this;}
};
}
enum {
ID_SORT = wxID_HIGHEST + 1,
};
BEGIN_EVENT_TABLE(MonsterListDialog, wxDialog)
EVT_BUTTON(-1, MonsterListDialog::OnCommand)
EVT_UPDATE_UI(-1, MonsterListDialog::OnUpdateUI)
EVT_LISTBOX(-1, MonsterListDialog::OnListBox)
END_EVENT_TABLE()
MonsterListDialog::MonsterListDialog(wxWindow* parent, CountedPtr lev, bool isreadonly)
: wxDialog(parent, -1, wxT("Monster list"), wxDefaultPosition, wxDefaultSize),
level(lev), readonly(isreadonly), monsterlist(NULL), unaddedlist(NULL), add_x(NULL), add_y(NULL)
{
wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
sizer->Add(new wxStaticText(this, -1, wxT("Monster movement list:")), 0, wxALL, 5);
monsterlist = new wxListBox(this, -1, wxDefaultPosition, wxSize(50, 100));
sizer->Add(monsterlist, 1, wxALL | wxGROW, 5);
wxBoxSizer* listbuttonsizer = new wxBoxSizer(wxHORIZONTAL);
listbuttonsizer->Add(new wxButton(this, wxID_REMOVE, wxT("Remove")), 1, wxALL | wxGROW, 5);
listbuttonsizer->Add(new wxButton(this, wxID_UP, wxT("&Up")), 1, wxALL | wxGROW, 5);
listbuttonsizer->Add(new wxButton(this, wxID_DOWN, wxT("&Down")), 1, wxALL | wxGROW, 5);
listbuttonsizer->Add(new wxButton(this, ID_SORT, wxT("&Sort")), 1, wxALL | wxGROW, 5);
sizer->Add(listbuttonsizer, 0, wxGROW);
wxBoxSizer* addsizer = new wxBoxSizer(wxHORIZONTAL);
addsizer->Add(new wxStaticText(this, -1, wxT("x:")), 0, wxALL, 5);
add_x = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC));
addsizer->Add(add_x, 1, wxALL, 5);
addsizer->Add(new wxStaticText(this, -1, wxT("y:")), 0, wxALL, 5);
add_y = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC));
addsizer->Add(add_y, 1, wxALL, 5);
addsizer->Add(new wxButton(this, wxID_ADD, wxT("Add")), 0, wxALL | wxGROW, 5);
sizer->Add(addsizer, 0, wxGROW);
sizer->Add(new wxStaticText(this, -1, wxT("Stationary monsters:")), 0, wxALL, 5);
unaddedlist = new wxListBox(this, -1, wxDefaultPosition, wxSize(50, 100));
sizer->Add(unaddedlist, 1, wxALL | wxGROW, 5);
#if 0
wxBoxSizer* buttonsizer = new wxBoxSizer(wxHORIZONTAL);
wxButton* okbutton = new wxButton(this, wxID_OK, wxT("&OK"));
okbutton->SetDefault();
buttonsizer->Add(okbutton, 0, wxALL, 5);
buttonsizer->Add(new wxButton(this, wxID_CANCEL, wxT("&Cancel")), 0, wxALL, 5);
#endif
wxSizer* buttonsizer = CreateButtonSizer(wxOK | wxCANCEL);
if(buttonsizer != NULL)
sizer->Add(buttonsizer, 0, wxGROW);
SetSizerAndFit(sizer);
if(level != NULL) {
wxString str;
std::set records;
for(std::list::const_iterator it = level->monsters.begin(); it != level->monsters.end(); ++it) {
str.clear();
str << wxT("(") << (int) it->x << wxT(", ") << (int) it->y << wxT(") - ") << level->GetMonsterDescription(it->x, it->y);
monsterlist->Append(str, new MonsterRecordData(*it));
records.insert(*it);
}
MonsterRecord record;
for(record.y = 0; record.y < 32; ++record.y) {
for(record.x = 0; record.x < 32; ++record.x) {
if(level->HasMonsterTile(record.x, record.y) && !records.count(record)) {
str.clear();
str << wxT("(") << (int) record.x << wxT(", ") << (int) record.y << wxT(") - ");
str << level->GetMonsterDescription(record.x, record.y);
unaddedlist->Append(str, new MonsterRecordData(record));
}
}
}
}
}
#if 0
void MonsterListDialog::UpdateLevel() {
if(readonly || level == NULL || monsterlist == NULL)
return;
level->monsters.clear();
for(unsigned int pos = 0; pos < monsterlist->GetCount(); ++pos) {
if(monsterlist->GetClientObject(pos) != NULL)
level->monsters.push_back(*((MonsterRecordData*) monsterlist->GetClientObject(pos)));
}
}
#endif
std::list MonsterListDialog::GetMonsterList() const {
std::list monsters;
if(monsterlist != NULL && monsterlist->GetCount() >= 1) {
unsigned int count = monsterlist->GetCount();
for(unsigned int pos = 0; pos < count; ++pos) {
if(monsterlist->GetClientObject(pos) != NULL)
monsters.push_back(*((MonsterRecordData*) monsterlist->GetClientObject(pos)));
}
}
return monsters;
}
void MonsterListDialog::OnCommand(wxCommandEvent& event) {
switch(event.GetId()) {
case wxID_ADD:
{
if(readonly || monsterlist == NULL || add_x == NULL || add_y == NULL)
break;
unsigned long x, y;
if(!add_x->GetValue().ToULong(&x) || !add_y->GetValue().ToULong(&y)) {
wxMessageBox(wxT("Invalid coordinates."), wxT("Add monster"), wxOK | wxICON_ERROR, this);
break;
}
if(x > 255 || y > 255) {
wxMessageBox(wxT("Only coordinates from 0 to 255 can be stored in the monster list."), wxT("Add monster"), wxOK | wxICON_ERROR, this);
break;
}
wxString str;
str << wxT("(") << x << wxT(", ") << y << wxT(")");
if(x >= 32 || y >= 32) {
if(wxMessageBox(wxT("This point is outside the level map! Are you sure you want to add an invalid monster record for it?"),
wxT("Add monster"), wxYES_NO | wxICON_QUESTION) != wxYES)
break;
} else if(level != NULL && !level->HasMonsterTile(x, y)) {
if(wxMessageBox(wxT("There is no monster at ") + str + wxT("! Are you sure you want to add an invalid monster record for it?"),
wxT("Add monster"), wxYES_NO | wxICON_QUESTION) != wxYES)
break;
}
str << wxT(" - ") << level->GetMonsterDescription(x, y);
int n = monsterlist->FindString(str);
if(n >= 0 && monsterlist->GetCount() >= 1 && ((unsigned int) n) < ((unsigned int) monsterlist->GetCount())) {
if(wxMessageBox(wxT("There is already a monster record for this location! Are you sure you want to add a duplicate record?"),
wxT("Add monster"), wxYES_NO | wxICON_QUESTION) != wxYES)
break;
}
MonsterRecordData* data = new MonsterRecordData;
data->x = x;
data->y = y;
unsigned int pos = 0;
if(monsterlist->GetCount() >= 1) {
unsigned int count = monsterlist->GetCount();
for(pos = 0; pos < count; ++pos) {
if(monsterlist->GetClientObject(pos) != NULL && *data <= *((MonsterRecordData*) monsterlist->GetClientObject(pos)))
break;
}
}
monsterlist->Insert(str, pos, data);
monsterlist->SetSelection(pos);
if(unaddedlist != NULL) {
n = unaddedlist->FindString(str);
if(n >= 0 && unaddedlist->GetCount() >= 1 && ((unsigned int) n) < ((unsigned int) unaddedlist->GetCount()))
unaddedlist->Delete(n);
}
break;
}
case wxID_REMOVE:
{
if(readonly || monsterlist == NULL)
break;
int n = monsterlist->GetSelection();
if(n < 0 || monsterlist->GetCount() < 1 || ((unsigned int) n) >= ((unsigned int) monsterlist->GetCount()))
break;
wxString str = monsterlist->GetString(n);
MonsterRecordData* data = NULL;
if(monsterlist->GetClientObject(n) != NULL)
data = new MonsterRecordData(*((MonsterRecordData*) monsterlist->GetClientObject(n)));
monsterlist->Delete(n);
if(unaddedlist != NULL && level != NULL && data != NULL && !str.empty() && level->HasMonsterTile(data->x, data->y) &&
monsterlist->FindString(str) == wxNOT_FOUND) {
unsigned int pos = 0;
if(unaddedlist->GetCount() > 0) {
unsigned int count = unaddedlist->GetCount();
for(pos = 0; pos < count; ++pos) {
if(unaddedlist->GetClientObject(pos) != NULL && *data <= *((MonsterRecordData*) unaddedlist->GetClientObject(pos)))
break;
}
}
unaddedlist->Insert(str, pos, data);
unaddedlist->SetSelection(pos);
if(add_x != NULL) {
wxString x;
x << (int) data->x;
add_x->SetValue(x);
}
if(add_y != NULL) {
wxString y;
y << (int) data->y;
add_y->SetValue(y);
}
} else {
delete data;
}
break;
}
case wxID_UP:
{
if(readonly || monsterlist == NULL)
break;
int n = monsterlist->GetSelection();
if(n < 1 || monsterlist->GetCount() < 1 || ((unsigned int) n) >= ((unsigned int) monsterlist->GetCount()))
break;
wxString str = monsterlist->GetString(n);
MonsterRecordData* data = NULL;
if(monsterlist->GetClientObject(n) != NULL)
data = new MonsterRecordData(*((MonsterRecordData*) monsterlist->GetClientObject(n)));
monsterlist->Delete(n);
monsterlist->Insert(str, n - 1, data);
monsterlist->SetSelection(n - 1);
break;
}
case wxID_DOWN:
{
if(readonly || monsterlist == NULL)
break;
int n = monsterlist->GetSelection();
if(n < 0 || monsterlist->GetCount() < 1 || ((unsigned int) n) >= ((unsigned int) monsterlist->GetCount() - 1))
break;
wxString str = monsterlist->GetString(n);
MonsterRecordData* data = NULL;
if(monsterlist->GetClientObject(n) != NULL)
data = new MonsterRecordData(*((MonsterRecordData*) monsterlist->GetClientObject(n)));
monsterlist->Delete(n);
monsterlist->Insert(str, n + 1, data);
monsterlist->SetSelection(n + 1);
break;
}
case ID_SORT:
{
if(readonly || monsterlist == NULL || monsterlist->GetCount() < 1)
break;
bool dosel = false;
MonsterRecord sel;
MonsterRecordData* data;
if(monsterlist->GetSelection() >= 0 && ((unsigned int) monsterlist->GetSelection()) < ((unsigned int) monsterlist->GetCount())) {
data = (MonsterRecordData*) monsterlist->GetClientObject(monsterlist->GetSelection());
if(data != NULL) {
sel = *data;
dosel = true;
}
}
std::priority_queue, std::greater > monsters;
unsigned int n;
for(n = 0; n < (unsigned int) monsterlist->GetCount(); ++n) {
data = (MonsterRecordData*) monsterlist->GetClientObject(n);
if(data != NULL)
monsters.push(*data);
}
monsterlist->Clear();
while(!monsters.empty()) {
wxString str;
str << wxT("(") << monsters.top().x << wxT(", ") << monsters.top().y << wxT(") - ");
str << level->GetMonsterDescription(monsters.top().x, monsters.top().y);
monsterlist->Append(str, new MonsterRecordData(monsters.top()));
if(dosel && sel == monsters.top() && monsterlist->GetCount() >= 1)
monsterlist->SetSelection(monsterlist->GetCount() - 1);
monsters.pop();
}
break;
}
default:
event.Skip();
}
}
void MonsterListDialog::OnUpdateUI(wxUpdateUIEvent& event) {
switch(event.GetId()) {
case wxID_ADD:
{
event.Enable(false);
if(readonly || monsterlist == NULL || add_x == NULL || add_y == NULL)
break;
unsigned long x, y;
if(!add_x->GetValue().ToULong(&x) || !add_y->GetValue().ToULong(&y))
break;
if(x > 255 || y > 255)
break;
event.Enable(true);
break;
}
case wxID_REMOVE:
{
event.Enable(false);
if(readonly || monsterlist == NULL)
break;
int n = monsterlist->GetSelection();
if(n < 0 || monsterlist->GetCount() < 1 || ((unsigned int) n) >= ((unsigned int) monsterlist->GetCount()))
break;
event.Enable(true);
break;
}
case wxID_UP:
{
event.Enable(false);
if(readonly || monsterlist == NULL)
break;
int n = monsterlist->GetSelection();
if(n < 1 || monsterlist->GetCount() < 1 || ((unsigned int) n) >= ((unsigned int) monsterlist->GetCount()))
break;
event.Enable(true);
break;
}
case wxID_DOWN:
{
event.Enable(false);
if(readonly || monsterlist == NULL)
break;
int n = monsterlist->GetSelection();
if(n < 0 || monsterlist->GetCount() < 1 || ((unsigned int) n) >= ((unsigned int) monsterlist->GetCount() - 1))
break;
event.Enable(true);
break;
}
case ID_SORT:
{
event.Enable(!readonly && monsterlist != NULL);
break;
}
default:
event.Skip();
}
}
#if !wxCHECK_VERSION(2, 8, 0)
#define ChangeValue SetValue
#endif
void MonsterListDialog::OnListBox(wxCommandEvent& event) {
if(event.GetEventObject() == NULL)
return;
if(event.GetEventObject() == unaddedlist) {
if(event.GetClientObject() != NULL) {
MonsterRecordData* data = (MonsterRecordData*) event.GetClientObject();
if(add_x != NULL) {
wxString x;
x << (int) data->x;
add_x->ChangeValue(x);
}
if(add_y != NULL) {
wxString y;
y << (int) data->y;
add_y->ChangeValue(y);
}
}
}
}
}
chipw-2.0.6/src/playtestdlg.h 0000644 0001750 0001750 00000003523 11672412350 013052 0000000 0000000 // Chip's Workshop - a level editor for Chip's Challenge.
// Copyright 2008-2011 Christopher Elsby
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License as
// published by the Free Software Foundation.
//
// 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 .
#ifndef CHIPW_PLAYTESTDLG_H_INCLUDED
#define CHIPW_PLAYTESTDLG_H_INCLUDED
#include "playtesttype.h"
#include "listeditdlg.h"
#include
#include
#include
class wxTextCtrl;
namespace ChipW {
class PlayTestDialog : public wxDialog {
public:
PlayTestDialog(wxWindow* parent);
PlayTestType type;
private:
void OnCommand(wxCommandEvent& event);
wxTextCtrl* progbox;
wxTextCtrl* argbox;
wxTextCtrl* dirbox;
DECLARE_EVENT_TABLE()
};
class PlayTestListEditItem : public ListEditItem {
public:
PlayTestListEditItem() { }
PlayTestListEditItem(const PlayTestType& newtype) : type(newtype) { }
virtual wxString GetSummaryText() const;
virtual bool Edit(wxWindow* parent);
virtual ListEditItem* CreateCopy() const;
PlayTestType type;
private:
DECLARE_DYNAMIC_CLASS(PlayTestListEditItem)
};
class PlayTestListEditDialog : public ListEditDialog {
public:
PlayTestListEditDialog(wxWindow* parent, const std::vector& types, unsigned int maxlen = (unsigned int) -1);
std::vector GetTypes() const;
};
}
#endif // !CHIPW_PLAYTESTDLG_H_INCLUDED
chipw-2.0.6/src/monsterlistdlg.h 0000644 0001750 0001750 00000002743 11672412350 013573 0000000 0000000 // Chip's Workshop - a level editor for Chip's Challenge.
// Copyright 2008-2011 Christopher Elsby
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License as
// published by the Free Software Foundation.
//
// 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 .
#ifndef CHIPW_MONSTERLISTDLG_H_INCLUDED
#define CHIPW_MONSTERLISTDLG_H_INCLUDED
#include
#include
#include
#include "level.h"
class wxListBox;
class wxTextCtrl;
namespace ChipW {
class MonsterListDialog : public wxDialog {
public:
MonsterListDialog(wxWindow* parent, CountedPtr lev, bool isreadonly);
// void UpdateLevel();
std::list GetMonsterList() const;
private:
void OnCommand(wxCommandEvent& event);
void OnUpdateUI(wxUpdateUIEvent& event);
void OnListBox(wxCommandEvent& event);
CountedPtr level;
bool readonly;
wxListBox* monsterlist;
wxListBox* unaddedlist;
wxTextCtrl* add_x;
wxTextCtrl* add_y;
DECLARE_EVENT_TABLE()
};
}
#endif // !CHIPW_MONSTERLISTDLG_H_INCLUDED
chipw-2.0.6/src/valruleset.h 0000644 0001750 0001750 00000004117 11672412350 012704 0000000 0000000 // Chip's Workshop - a level editor for Chip's Challenge.
// Copyright 2008-2011 Christopher Elsby
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License as
// published by the Free Software Foundation.
//
// 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 .
#ifndef CHIPW_VALRULESET_H_INCLUDED
#define CHIPW_VALRULESET_H_INCLUDED
#include "ruleset.h"
#include
#include
#include
#include
namespace ChipW {
class RuleSetValidator : public wxValidator {
public:
RuleSetValidator(RuleSetId* newptrruleset) : allownone(false), ptrhasruleset(NULL), ptrruleset(newptrruleset) { }
RuleSetValidator(const wxString& newnonetext = wxEmptyString, RuleSetOrNone* newptrval = NULL)
: allownone(true), nonetext(newnonetext), ptrhasruleset(newptrval == NULL ? NULL : &newptrval->hasruleset),
ptrruleset(newptrval == NULL ? NULL : &newptrval->ruleset) { }
RuleSetValidator(const RuleSetValidator& newval) : allownone(false), ptrhasruleset(NULL), ptrruleset(NULL) {Copy(newval);}
RuleSetValidator& operator=(const RuleSetValidator& newval) {Copy(newval); return *this;}
bool Copy(const RuleSetValidator& newval);
virtual wxObject* Clone() const {return new RuleSetValidator(*this);}
virtual bool TransferFromWindow();
virtual bool TransferToWindow();
virtual bool Validate(wxWindow* parent);
wxArrayString GetChoices() const;
private:
bool GetWindowText(wxString& text) const;
bool SetWindowText(const wxString& text) const;
bool allownone;
wxString nonetext;
bool* ptrhasruleset;
RuleSetId* ptrruleset;
};
}
#endif // !CHIPW_VALRULESET_H_INCLUDED
chipw-2.0.6/src/playtestproc.cpp 0000644 0001750 0001750 00000011223 11672412350 013576 0000000 0000000 // Chip's Workshop - a level editor for Chip's Challenge.
// Copyright 2008-2011 Christopher Elsby
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License as
// published by the Free Software Foundation.
//
// 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 .
#include "global.h"
#include "playtestproc.h"
#include "wxtostdstream.h"
#include "app.h"
#include "levelset.h"
#include
#include
#include
#include
#include
namespace ChipW {
PlayTestProcess::PlayTestProcess() {
}
PlayTestProcess::~PlayTestProcess() {
// Delete the temporary file.
if(!tmpfilename.empty())
wxGetApp().RemoveTmpFile(tmpfilename);
}
wxString PlayTestProcess::GetArgumentQuoted(wxString arg) {
// It's platform dependent and wxWidgets does not provide a way to do it which works across all supported versions......
#ifdef __WXMSW__
// Looks like we are on Windows.
// Infuriatingly, we need to escape exactly the following with backslashes:
// * Double quotes
// * Runs of backslashes immediately before double quotes
// So, we scan backwards for double quotes, count the run of backslashes before each one, then add the correct number for escaping.
size_t pos = arg.size();
while(pos > 0) {
// Find the next quote.
pos = arg.rfind(wxT('"'), pos - 1);
if(pos >= arg.size())
break;
// We always escape the quote itself.
size_t escapecount = 1;
// Now scan for preceding backslashes.
while(pos > 0 && arg[pos - 1] == '\\') {
++escapecount;
--pos;
}
// pos is now on either the quote itself or the start of a preceding run of backslashes,
// so inserting the appropriate number of backslashes here will give correct escaping.
arg.insert(pos, escapecount, '\\');
}
#else
// Assume it's like Unix, though (FIXME) there are probably others.
// Escape backslashes with backslashes.
arg.Replace(wxT("\\"), wxT("\\\\"));
// Escape double quotes with backslashes.
arg.Replace(wxT("\""), wxT("\\\""));
#endif
// Put the whole thing in double quotes.
return wxT("\"") + arg + wxT("\"");
}
bool PlayTestProcess::Launch(wxString gamecmd, const LevelSet& levelset, wxUint16 levelnumber, wxString workingdir) {
if(!tmpfilename.empty())
return false;
// Save the levelset to a temporary file.
{
// Obtain name for temporary file and open it.
wxFile tmpfile;
tmpfilename = wxFileName::CreateTempFileName(wxT("chipw-tmp-"), &tmpfile);
if(tmpfilename.empty()) {
wxLogError(wxT("Failed to obtain temporary filename."));
return false;
}
// Register the temporary file with the App object.
// This means that it will be deleted when ChipW exits even if the game process is still running.
// This might upset the game process, but that is better than leaving temporary files around.
wxGetApp().RegisterTmpFile(tmpfilename);
if(!tmpfile.IsOpened()) {
wxLogError(wxT("Failed to open temporary file."));
return false;
}
// Write the levelset data.
{
wxFileOutputStream wxstream(tmpfile);
{
owxstream stream(&wxstream);
if(!levelset.Save_MSCC(stream)) {
wxLogError(wxT("Failed to save levelset to temporary file."));
return false;
}
}
}
}
// Enter the appropriate directory.
wxString oldworkingdir;
if(!workingdir.empty()) {
oldworkingdir = wxGetCwd();
if(!wxSetWorkingDirectory(workingdir)) {
wxLogError(wxT("Failed to set working directory."));
return false;
}
}
// Add command line arguments.
gamecmd << wxT(" ") << GetArgumentQuoted(tmpfilename) << wxT(" ") << levelnumber;
// Start the game process.
bool success = wxExecute(gamecmd, wxEXEC_ASYNC, this);
if(!success)
wxLogError(wxT("Failed to start game process."));
// Restore the working directory.
if(!oldworkingdir.empty())
wxSetWorkingDirectory(oldworkingdir);
// Return.
return success;
}
}
chipw-2.0.6/src/levelupdatehint.cpp 0000644 0001750 0001750 00000001504 11672412350 014243 0000000 0000000 // Chip's Workshop - a level editor for Chip's Challenge.
// Copyright 2008-2011 Christopher Elsby
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License as
// published by the Free Software Foundation.
//
// 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 .
#include "global.h"
#include "levelupdatehint.h"
namespace ChipW {
IMPLEMENT_DYNAMIC_CLASS(LevelUpdateHint, wxObject)
}
chipw-2.0.6/src/playtesttype.h 0000644 0001750 0001750 00000003454 11672412350 013270 0000000 0000000 // Chip's Workshop - a level editor for Chip's Challenge.
// Copyright 2008-2011 Christopher Elsby
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License as
// published by the Free Software Foundation.
//
// 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 .
#ifndef CHIPW_PLAYTESTTYPE_H_INCLUDED
#define CHIPW_PLAYTESTTYPE_H_INCLUDED
#include "ruleset.h"
#include
#include
namespace ChipW {
class PlayTestProcess;
class LevelSet;
class PlayTestType {
public:
// Constructors.
PlayTestType(wxString newname = wxT(""), wxString newprogram = GetDefaultProgram(), wxString newarguments = GetDefaultArguments(),
wxString newworkingdir = wxT(""), const RuleSetOrNone& newruleset = RuleSetOrNone::NONE)
: name(newname), program(newprogram), arguments(newarguments), workingdir(newworkingdir), ruleset(newruleset) { }
// Starts playtesting the specified levelset, returning the process object on success and NULL on failure.
PlayTestProcess* Launch(const LevelSet& levelset, wxUint16 levelnumber = 1) const;
// Defaults.
static wxString GetDefaultProgram();
static wxString GetDefaultArguments();
// Settings.
wxString name;
wxString program;
wxString arguments;
wxString workingdir;
RuleSetOrNone ruleset;
private:
static int defaultprog;
};
}
#endif // !CHIPW_PLAYTESTTYPE_H_INCLUDED
chipw-2.0.6/src/leveldataobj.cpp 0000644 0001750 0001750 00000025667 11672412350 013522 0000000 0000000 // Chip's Workshop - a level editor for Chip's Challenge.
// Copyright 2008-2011 Christopher Elsby
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License as
// published by the Free Software Foundation.
//
// 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 .
#include "global.h"
#include "leveldataobj.h"
#include "level.h"
#include
#include
#include "binstream.h"
namespace ChipW {
// LevelsDataObject
wxDataFormat LevelsDataObject::GetDataFormat() {
return wxT("CHIPEDIT LEVELS");
}
bool LevelsDataObject::AddLevel(const Level* level) {
if(level == NULL)
return false;
std::ostringstream stream;
if(!level->Save_SubMSCC(stream, false))
return false;
if(stream.str().size() > 65535)
return false;
msccdata.push_back(stream.str());
return true;
}
bool LevelsDataObject::GetLevels(std::vector >& levels) const {
std::vector >::size_type origsize = levels.size();
levels.reserve(levels.size() + msccdata.size());
CountedPtr level = NULL;
for(std::list::const_iterator it = msccdata.begin(); it != msccdata.end(); ++it) {
std::istringstream stream(*it);
level = new Level;
if(it->size() > 65535 || !level->Load_SubMSCC(stream, false, it->size())) {
levels.resize(origsize);
return false;
}
levels.push_back(level);
}
return true;
}
size_t LevelsDataObject::GetDataSize() const {
size_t result = 4; // Uint32 level count
result += 6 * msccdata.size(); // Uint16 level data size + 4 unused bytes, for each level
for(std::list::const_reverse_iterator it = msccdata.rbegin(); it != msccdata.rend(); ++it)
result += it->size();
return result;
}
bool LevelsDataObject::GetDataHere(void* buf) const {
// wxPrintf(wxT("Trying to copy from LevelsDataObject\n"));
char* bufptr = (char*) buf;
std::list::const_reverse_iterator it;
// Level count.
*((wxUint32*) bufptr) = wxUINT32_SWAP_ON_BE((wxUint32) msccdata.size());
bufptr += 4;
// Level data sizes and filler bytes.
// The levels are stored in reverse order because that is how ChipEdit does it.
for(it = msccdata.rbegin(); it != msccdata.rend(); ++it) {
*((wxUint16*) bufptr) = wxUINT16_SWAP_ON_BE((wxUint16) it->size());
bufptr += 2;
*((wxUint32*) bufptr) = 0;
bufptr += 4;
}
// Level data.
for(it = msccdata.rbegin(); it != msccdata.rend(); ++it) {
std::memcpy(bufptr, it->data(), it->size());
bufptr += it->size();
}
return true;
}
bool LevelsDataObject::SetData(size_t len, const void* buf) {
// wxPrintf(wxT("Trying to paste into LevelsDataObject\n"));
const char* bufptr = (const char*) buf;
msccdata.clear();
// Level count.
if(len < 4)
return false;
wxUint32 levelcount = wxUINT32_SWAP_ON_BE(*((const wxUint32*) bufptr));
if(levelcount > 65535)
return false;
bufptr += 4;
len -= 4;
// Level data sizes and filler bytes.
std::list leveldatasizes;
while(levelcount > 0) {
if(len < 6)
return false;
leveldatasizes.push_back(wxUINT16_SWAP_ON_BE(*((const wxUint16*) bufptr)));
bufptr += 6;
len -= 6;
--levelcount;
}
// Level data.
CountedPtr level = NULL;
for(std::list::const_iterator it = leveldatasizes.begin(); it != leveldatasizes.end(); ++it) {
if(len < *it)
return false;
msccdata.push_front(std::string(bufptr, *it)); // push_front because the levels are copied in reverse order
bufptr += *it;
len -= *it;
}
return true;
}
// LevelSectionDataObject
wxDataFormat LevelSectionDataObject::GetDataFormat() {
return wxT("CHIPEDIT MAPSECT");
}
bool LevelSectionDataObject::SetSection(const Level* level, wxUint32 x, wxUint32 y, wxUint32 w, wxUint32 h) {
if(level == NULL)
return false;
// Create a level object for the selected map section.
Level tmplevel;
tmplevel.RefStatic();
tmplevel.levelnumber = level->levelnumber;
tmplevel.time = level->time;
tmplevel.chips = level->chips;
tmplevel.title = level->title;
tmplevel.hint = level->hint;
tmplevel.psw = level->psw;
for(wxUint32 x1 = 0; x1 < w; ++x1) {
for(wxUint32 y1 = 0; y1 < h; ++y1) {
if(!tmplevel.PlaceTileUpper(x1, y1, level->GetUpperTile(x + x1, y + y1), false))
return false;
if(!tmplevel.PlaceTileLower(x1, y1, level->GetLowerTile(x + x1, y + y1), false))
return false;
}
}
MonsterRecord tmpmon;
std::list::const_iterator monit;
for(monit = level->monsters.begin(); monit != level->monsters.end(); ++monit) {
if(monit->x >= x && monit->x < x + w && monit->y >= y && monit->y < y + h) {
tmpmon.x = monit->x - x;
tmpmon.y = monit->y - y;
tmplevel.monsters.push_back(tmpmon);
}
}
WireRecord tmpwire;
std::list::const_iterator wireit;
for(wireit = level->trapwires.begin(); wireit != level->trapwires.end(); ++wireit) {
if(wireit->buttonx >= x && wireit->buttonx < x + w && wireit->buttony >= y && wireit->buttony < y + h
&& wireit->targetx >= x && wireit->targetx < x + w && wireit->targety >= y && wireit->targety < y + h) {
tmpwire.buttonx = wireit->buttonx - x;
tmpwire.buttony = wireit->buttony - y;
tmpwire.targetx = wireit->targetx - x;
tmpwire.targety = wireit->targety - y;
tmplevel.trapwires.push_back(tmpwire);
}
}
for(wireit = level->clonewires.begin(); wireit != level->clonewires.end(); ++wireit) {
if(wireit->buttonx >= x && wireit->buttonx < x + w && wireit->buttony >= y && wireit->buttony < y + h
&& wireit->targetx >= x && wireit->targetx < x + w && wireit->targety >= y && wireit->targety < y + h) {
tmpwire.buttonx = wireit->buttonx - x;
tmpwire.buttony = wireit->buttony - y;
tmpwire.targetx = wireit->targetx - x;
tmpwire.targety = wireit->targety - y;
tmplevel.clonewires.push_back(tmpwire);
}
}
// Convert it to MSCC format.
std::ostringstream stream;
if(!tmplevel.Save_SubMSCC(stream, false))
return false;
if(stream.str().size() > 65535)
return false;
msccdata = stream.str();
width = w;
height = h;
return true;
}
bool LevelSectionDataObject::PasteToLevel(CountedPtr target, wxUint32 x, wxUint32 y) const {
if(target == NULL)
return false;
if(msccdata.size() > 65535)
return false;
Level tmplevel;
tmplevel.RefStatic();
std::istringstream stream(msccdata);
if(!tmplevel.Load_SubMSCC(stream, false, msccdata.size()))
return false;
wxUint32 w = ((x + width > 32) ? (32 - x) : width);
wxUint32 h = ((y + height > 32) ? (32 - y) : height);
for(wxUint32 x1 = 0; x1 < w; ++x1) {
for(wxUint32 y1 = 0; y1 < h; ++y1) {
if(!target->ClearTile(x + x1, y + y1))
return false;
if(!target->PlaceTileUpper(x + x1, y + y1, tmplevel.GetUpperTile(x1, y1), false))
return false;
if(!target->PlaceTileLower(x + x1, y + y1, tmplevel.GetLowerTile(x1, y1), false))
return false;
}
}
std::list::const_iterator monit;
for(monit = tmplevel.monsters.begin(); monit != tmplevel.monsters.end(); ++monit) {
if(monit->x < w && monit->y < h) {
if(!target->AddMonster(x + monit->x, y + monit->y, true))
return false;
}
}
WireRecord tmpwire;
std::list::const_iterator wireit;
for(wireit = tmplevel.trapwires.begin(); wireit != tmplevel.trapwires.end(); ++wireit) {
if(wireit->buttonx < w && wireit->buttony < h && wireit->targetx < w && wireit->targety < h) {
tmpwire.buttonx = wireit->buttonx + x;
tmpwire.buttony = wireit->buttony + y;
tmpwire.targetx = wireit->targetx + x;
tmpwire.targety = wireit->targety + y;
if(!target->AddTrapWire(tmpwire, true))
return false;
}
}
for(wireit = tmplevel.clonewires.begin(); wireit != tmplevel.clonewires.end(); ++wireit) {
if(wireit->buttonx < w && wireit->buttony < h && wireit->targetx < w && wireit->targety < h) {
tmpwire.buttonx = wireit->buttonx + x;
tmpwire.buttony = wireit->buttony + y;
tmpwire.targetx = wireit->targetx + x;
tmpwire.targety = wireit->targety + y;
if(!target->AddCloneWire(tmpwire, true))
return false;
}
}
return true;
}
size_t LevelSectionDataObject::GetDataSize() const {
return 14 // Uint32 width + Uint32 height + Uint16 level data size + 4 unused bytes
+ msccdata.size();
}
bool LevelSectionDataObject::GetDataHere(void* buf) const {
// wxPrintf(wxT("Trying to copy from LevelSectionDataObject\n"));
char* bufptr = (char*) buf;
// Width.
*((wxUint32*) bufptr) = wxUINT32_SWAP_ON_BE(width);
bufptr += 4;
// Height.
*((wxUint32*) bufptr) = wxUINT32_SWAP_ON_BE(height);
bufptr += 4;
// Level data size.
*((wxUint16*) bufptr) = wxUINT16_SWAP_ON_BE((wxUint16) msccdata.size());
bufptr += 2;
// Filler bytes.
*((wxUint32*) bufptr) = 0;
bufptr += 4;
// Level data.
std::memcpy(bufptr, msccdata.data(), msccdata.size());
bufptr += msccdata.size();
return true;
}
bool LevelSectionDataObject::SetData(size_t len, const void* buf) {
// wxPrintf(wxT("Trying to paste into LevelSectionDataObject\n"));
const char* bufptr = (const char*) buf;
width = 0;
height = 0;
// Width.
if(len < 4)
return false;
wxUint32 w = wxUINT32_SWAP_ON_BE(*((const wxUint32*) bufptr));
if(w > 32)
return false;
bufptr += 4;
len -= 4;
// Height.
if(len < 4)
return false;
wxUint32 h = wxUINT32_SWAP_ON_BE(*((const wxUint32*) bufptr));
if(h > 32)
return false;
bufptr += 4;
len -= 4;
// Level data size and filler bytes.
if(len < 6)
return false;
wxUint16 leveldatasize = wxUINT16_SWAP_ON_BE(*((const wxUint16*) bufptr));
bufptr += 6;
len -= 6;
// Level data.
if(len < leveldatasize)
return false;
msccdata.assign(bufptr, leveldatasize);
bufptr += leveldatasize;
len -= leveldatasize;
width = w;
height = h;
return true;
}
}
chipw-2.0.6/src/bufferscroll.h 0000644 0001750 0001750 00000002766 11672412350 013216 0000000 0000000 // Chip's Workshop - a level editor for Chip's Challenge.
// Copyright 2008-2011 Christopher Elsby
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License as
// published by the Free Software Foundation.
//
// 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 .
#ifndef CHIPW_BUFFERSCROLL_H_INCLUDED
#define CHIPW_BUFFERSCROLL_H_INCLUDED
#include
#include
namespace ChipW {
class BufferedScrolledWindow : public wxScrolledWindow {
public:
BufferedScrolledWindow();
BufferedScrolledWindow(wxWindow* parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
long style = wxHSCROLL | wxVSCROLL, const wxString& name = wxT("scrolledWindow"));
bool Create(wxWindow* parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
long style = wxHSCROLL | wxVSCROLL, const wxString& name = wxT("scrolledWindow"));
private:
void OnPaint(wxPaintEvent& event);
DECLARE_EVENT_TABLE()
};
}
#endif // !CHIPW_BUFFERSCROLL_H_INCLUDED
chipw-2.0.6/src/app.cpp 0000644 0001750 0001750 00000013111 11672412350 011623 0000000 0000000 // Chip's Workshop - a level editor for Chip's Challenge.
// Copyright 2008-2011 Christopher Elsby
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License as
// published by the Free Software Foundation.
//
// 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 .
#include "global.h"
#include "app.h"
#include "levelsetdoc.h"
#include "leveleditview.h"
#include "leveleditframe.h"
#include "leveleditids.h"
#include "playtestmgr.h"
#include "playtestdlg.h"
#include "help.h"
#include
#include
#include
#include
//#include
#include
#include
#include
#include
#include
#include
IMPLEMENT_APP(ChipW::App)
namespace ChipW {
long RefCounted::nextid = 0;
BEGIN_EVENT_TABLE(App, wxApp)
EVT_MENU(-1, App::OnCommand)
EVT_BUTTON(-1, App::OnCommand)
END_EVENT_TABLE()
App::App()
: docmgr(NULL), autostart(false)
{
}
bool App::OnInit() {
SetAppName(wxT("ChipW"));
SetVendorName(wxT("Glarbex"));
std::srand(std::time(NULL));
wxInitAllImageHandlers();
playtestmgr = new PlayTestManager;
docmgr = new wxDocManager;
new wxDocTemplate(docmgr, wxT("Level set"), wxT("*.ccl;*.dat"), wxT(""), wxT("ccl"), wxT("Level set"), wxT("Level editor"),
CLASSINFO(LevelSetDoc), CLASSINFO(LevelEditView));
if(!wxApp::OnInit())
return false;
if(!autostart) {
#if 0
wxString choices[2];
choices[0] = wxT("Create a new levelset");
choices[1] = wxT("Open an existing levelset");
int choice = wxGetSingleChoiceIndex(wxT("Welcome to Chip's Workshop! What would you like to do?"), wxT("Chip's Workshop"), 2, choices);
switch(choice) {
case 0:
docmgr->CreateDocument(wxEmptyString, wxDOC_NEW);
break;
case 1:
docmgr->CreateDocument(wxEmptyString, 0);
break;
}
#endif
LevelEditFrame* frame = new LevelEditFrame(docmgr);
frame->Show();
}
// return !docmgr->GetDocuments().empty();
return true;
}
void App::OnInitCmdLine(wxCmdLineParser& parser) {
wxApp::OnInitCmdLine(parser);
parser.SetLogo(wxT("Chip's Workshop " VERSION " Copyright 2008-2011 Christopher Elsby\nCompiled with ") wxVERSION_STRING);
parser.AddSwitch(wxT("v"), wxT("version"), wxT("show the version number and copyright notice"));
parser.AddParam(wxT("file"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE);
}
bool App::OnCmdLineParsed(wxCmdLineParser& parser) {
if(!wxApp::OnCmdLineParsed(parser))
return false;
if(parser.Found(wxT("v")))
{
wxFprintf(stderr, wxT("Chip's Workshop %s Copyright 2008-2011 Christopher Elsby\n"
"Compiled with %s\n"), wxT(VERSION), wxVERSION_STRING);
return false;
}
autostart = (parser.GetParamCount() > 0);
if(docmgr != NULL) {
for(size_t n = 0; n < parser.GetParamCount(); ++n)
docmgr->CreateDocument(parser.GetParam(n), wxDOC_SILENT);
}
return true;
}
int App::OnExit() {
// Delete temporary files.
for(std::set::const_iterator it = tmpfiles.begin(); it != tmpfiles.end(); ++it) {
if(!it->empty())
wxRemoveFile(*it);
}
tmpfiles.clear();
delete docmgr;
docmgr = NULL;
delete playtestmgr;
playtestmgr = NULL;
delete wxConfigBase::Set(NULL);
return 0;
}
void App::RemoveTmpFile(wxString filename) {
std::set::iterator it = tmpfiles.find(filename);
if(it != tmpfiles.end()) {
if(filename.empty() || wxRemoveFile(filename))
tmpfiles.erase(it);
}
}
void App::OnCommand(wxCommandEvent& event) {
switch(event.GetId()) {
case wxID_ABOUT:
wxMessageBox(
wxT("Chip's Workshop " VERSION "\nCopyright 2008-2011 Christopher Elsby\nCompiled on " __DATE__ " " __TIME__ ".\n"
"Compiled with ") wxVERSION_STRING wxT(".\n"
"The included tile images are by Anders Kaseorg and Michael Hansen.\n"
"This program is free software: you can redistribute it and/or modify it "
"under the terms of version 3 of the GNU General Public License "
"as published by the Free Software Foundation.\n"
"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.\n"
"You should have received a copy of the GNU General Public License "
"along with this program. If not, see ."
), wxT("About Chip's Workshop"), wxOK);
break;
case wxID_HELP_CONTENTS:
case wxID_HELP:
LaunchHelp();
break;
case ID_PLAYTEST_CONFIG:
if(playtestmgr != NULL) {
PlayTestListEditDialog dlg(NULL, playtestmgr->GetTypes(), playtestmgr->GetMaxLength());
if(dlg.ShowModal() == wxID_OK)
playtestmgr->SetTypes(dlg.GetTypes());
break;
}
default:
event.Skip();
}
}
}
chipw-2.0.6/src/listeditdlg.h 0000644 0001750 0001750 00000005660 11672412350 013032 0000000 0000000 // Chip's Workshop - a level editor for Chip's Challenge.
// Copyright 2008-2011 Christopher Elsby
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License as
// published by the Free Software Foundation.
//
// 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 .
#ifndef CHIPW_LISTEDITDLG_H_INCLUDED
#define CHIPW_LISTEDITDLG_H_INCLUDED
#include
#include
#include
#include
#include
#include
class wxListBox;
class wxWindow;
namespace ChipW {
// Abstract class to represent an item in the list.
class ListEditItem : public wxObject {
public:
virtual ~ListEditItem() { }
// Returns the text to represent the item in the list editor.
virtual wxString GetSummaryText() const = 0;
// Runs a modal dialog to edit the item and returns whether OK was chosen.
virtual bool Edit(wxWindow* parent) = 0;
// Returns a new item using this one as a template.
// This is used when the Add button is clicked with this item selected.
// Name attributes should generally be adjusted (e.g. "Name" -> "Copy of Name").
// If NULL is returned, a new object will be created as if there were no item selected.
virtual ListEditItem* CreateCopy() const {return NULL;}
protected:
ListEditItem() { }
private:
DECLARE_ABSTRACT_CLASS(ListEditItem)
};
class ListEditDialog : public wxDialog {
public:
// Constructor.
ListEditDialog(wxWindow* parent, wxWindowID id, const wxString& title, wxClassInfo* newitemtype, unsigned int newmaxlen = (unsigned int) -1);
// Destructor.
virtual ~ListEditDialog();
// Gets the number of items.
unsigned int GetItemCount() const;
// Gets the specified item.
ListEditItem* GetItem(unsigned int i) const;
// Adds an item, which will then be deleted by this dialog object.
void AddItem(ListEditItem* newitem);
void AddItem(ListEditItem* newitem, unsigned int pos);
// Deletes an item.
void DeleteItem(unsigned int i);
// Updates the summary text of an item.
void UpdateItemSummary(unsigned int i);
// Removes an item without deleting it, and returns it.
ListEditItem* RemoveItem(unsigned int i);
// Creates and returns a new item.
ListEditItem* GetNewItem(bool copyfromsel = true) const;
private:
void OnCommand(wxCommandEvent& event);
void OnUpdateUI(wxUpdateUIEvent& event);
wxClassInfo* itemtype;
wxListBox* listbox;
unsigned int maxlen;
DECLARE_EVENT_TABLE()
};
}
#endif // !CHIPW_LISTEDITDLG_H_INCLUDED
chipw-2.0.6/src/levelset.cpp 0000644 0001750 0001750 00000011440 11672412350 012671 0000000 0000000 // Chip's Workshop - a level editor for Chip's Challenge.
// Copyright 2008-2011 Christopher Elsby
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License as
// published by the Free Software Foundation.
//
// 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 .
#include "global.h"
#include "levelset.h"
#include "level.h"
#include "binstream.h"
#include "ruleset.h"
#include
#include
#include
#include
namespace ChipW {
LevelSet::LevelSet()
: ruleset(RULESET_DEFAULT), monitor(NULL)
{
}
LevelSet::~LevelSet() {
RemoveAllLevels();
}
void LevelSet::SetMonitor(LevelMonitor* mon) {
monitor = mon;
for(std::vector >::const_iterator it = levels.begin(); it != levels.end(); ++it) {
if(*it != NULL)
(*it)->SetMonitor(mon);
}
}
void LevelSet::RemoveMonitor() {
monitor = NULL;
for(std::vector >::const_iterator it = levels.begin(); it != levels.end(); ++it) {
if(*it != NULL)
(*it)->RemoveMonitor();
}
}
void LevelSet::RemoveMonitor(LevelMonitor* mon) {
if(monitor == mon)
monitor = NULL;
for(std::vector >::const_iterator it = levels.begin(); it != levels.end(); ++it) {
if(*it != NULL)
(*it)->RemoveMonitor(mon);
}
}
wxUint16 LevelSet::FindLevel(const Level* level) const {
wxUint16 i;
for(i = 0; i < levels.size(); ++i) {
if(levels[i] == level)
break;
}
return i;
}
wxUint16 LevelSet::FindLevelByNumber(wxUint16 levnum) const {
wxUint16 i;
for(i = 0; i < levels.size(); ++i) {
if(levels[i]->levelnumber == levnum)
break;
}
return i;
}
wxUint16 LevelSet::FindLevelByPassword(const std::string& psw) const {
wxUint16 i;
for(i = 0; i < levels.size(); ++i) {
if(levels[i]->psw == psw)
break;
}
return i;
}
bool LevelSet::InsertLevel(CountedPtr level, wxUint16 index, bool renumber) {
if(level == NULL)
return false;
RemoveLevel(FindLevel(level), renumber);
if(levels.size() >= 65535)
return false;
if(renumber) {
if(levels.empty())
level->levelnumber = 0;
else if(index >= levels.size())
level->levelnumber = levels.back()->levelnumber;
else
level->levelnumber = levels[index]->levelnumber - 1;
}
if(index < levels.size()) {
levels.insert(levels.begin() + index, level);
} else {
index = levels.size();
levels.push_back(level);
}
if(renumber) {
while(index < levels.size()) {
++levels[index]->levelnumber;
++index;
}
}
level->SetMonitor(monitor);
return true;
}
CountedPtr