diff --git a/CMakeLists.txt b/CMakeLists.txt index 79eee64..a24fdc5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,8 +12,8 @@ link_directories (${CMAKE_INSTALL_PREFIX}/lib) project (planetblupi) set (PB_VERSION_MAJOR 1) -set (PB_VERSION_MINOR 11) -set (PB_VERSION_PATCH 0) +set (PB_VERSION_MINOR 12) +set (PB_VERSION_PATCH 3) set (PB_VERSION_EXTRA "") set (PB_PRODUCT_NAME "Planet Blupi") set (PB_PACKAGE_NAME "planetblupi") @@ -54,7 +54,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND "${STATIC_BUILD}") endif () if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -DDEBUG") endif () if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release") @@ -141,6 +141,8 @@ if ("${STATIC_BUILD}") pkg_search_module (AVUTIL REQUIRED libavutil) pkg_search_module (SWSCALE REQUIRED libswscale) pkg_search_module (SWRESAMPLE REQUIRED libswresample) + # Statis dependencies for SDL_mixer + pkg_search_module (VORBIS REQUIRED vorbisfile) if (UNIX AND NOT APPLE) pkg_search_module (ALSA REQUIRED alsa) @@ -172,6 +174,7 @@ if ("${STATIC_BUILD}") ${AVUTIL_STATIC_LIBRARIES} ${SWSCALE_STATIC_LIBRARIES} ${SWRESAMPLE_STATIC_LIBRARIES} + ${VORBIS_STATIC_LIBRARIES} ) if (${PB_HTTP_VERSION_CHECK}) @@ -281,10 +284,10 @@ endif () # Copy libwinpthread-1.dll which seems not be linkable statically if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows" AND MINGW) - execute_process (COMMAND cygpath.exe --windows /mingw64 OUTPUT_VARIABLE MINGW64_PATH) - string (REGEX REPLACE "[ \t\n\r]+$" "" MINGW64_PATH "${MINGW64_PATH}") - string (REGEX REPLACE "[\\]" "\\\\\\\\" MINGW64_PATH "${MINGW64_PATH}") - install (FILES "${MINGW64_PATH}\\\\bin\\\\libwinpthread-1.dll" DESTINATION bin) + execute_process (COMMAND cygpath.exe --windows $ENV{MINGW_PREFIX} OUTPUT_VARIABLE MINGW_PATH) + string (REGEX REPLACE "[ \t\n\r]+$" "" MINGW_PATH "${MINGW_PATH}") + string (REGEX REPLACE "[\\]" "\\\\\\\\" MINGW_PATH "${MINGW_PATH}") + install (FILES "${MINGW_PATH}\\\\bin\\\\libwinpthread-1.dll" DESTINATION bin) endif () ######### @@ -316,6 +319,10 @@ if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release" AND "${STATIC_BUILD}") set (CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\planetblupi.exe") set (CPACK_NSIS_URL_INFO_ABOUT "http://www.blupi.org") set (CPACK_NSIS_MUI_FINISHPAGE_RUN "planetblupi") + if (SIGN_APP) + set (CPACK_NSIS_SIGN_UNINSTALLER "sign -a -fd sha1 -t http://time.certum.pl -v") + endif () + include (CPack) find_program (SIGNTOOL_EXECUTABLE signtool) diff --git a/LICENSE b/LICENSE index 71b79ed..dea8bbe 100644 --- a/LICENSE +++ b/LICENSE @@ -6,7 +6,10 @@ This game is linked on some static libraries: GNU/gettext (GPLv3) libcurl (MIT/X derivate) GNU/libiconv (GPLv3) + libogg (own license) libpng (own license) + libsndfile (LGPLv3) + libvorbis (own license) SDL_kitchensink (MIT) SDL2 (zlib license) SDL2_image (zlib license) diff --git a/LICENSE.all b/LICENSE.all index 4f7300a..7c593ef 100644 --- a/LICENSE.all +++ b/LICENSE.all @@ -7,8 +7,11 @@ List of all licenses, concerns Planet Blupi and dependencies * libasound -- https://www.alsa-project.org * libcurl -- https://curl.haxx.se/libcurl/ * GNU/libiconv -- https://www.gnu.org/software/libiconv/ + * libogg -- https://xiph.org/downloads/ * libpng -- http://www.libpng.org/pub/png/libpng.html * libpulse -- https://freedesktop.org/software/pulseaudio/doxygen/ + * libsndfile -- http://www.mega-nerd.com/libsndfile/ + * libvorbis -- https://xiph.org/downloads/ * SDL_kitchensink -- https://github.com/katajakasa/SDL_kitchensink * SDL2 -- https://www.libsdl.org * SDL2_image -- https://www.libsdl.org/projects/SDL_image/ @@ -3117,6 +3120,39 @@ 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 . +###################################################################### +# libogg - LICENSE +###################################################################### + +Copyright (c) 2002, Xiph.org Foundation + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +- Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. + +- Neither the name of the Xiph.org Foundation nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ###################################################################### # libpng - LICENSE ###################################################################### @@ -3301,6 +3337,209 @@ While we attempt to provide a summary here, it is the ultimate responsibility of the packager to ensure the components they use in their build of PulseAudio meets their license requirements. +###################################################################### +# libsndfile - LICENSE +###################################################################### + + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser 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 +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. + +###################################################################### +# libogg - LICENSE +###################################################################### + +Copyright (c) 2002, Xiph.org Foundation + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +- Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. + +- Neither the name of the Xiph.org Foundation nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ###################################################################### # SDL_kitchensink - LICENSE ###################################################################### diff --git a/README-user.md b/README-user.md index 1c4d195..7543bd4 100644 --- a/README-user.md +++ b/README-user.md @@ -1,5 +1,5 @@ -# Planet Blupi (v1.9.x) +# Planet Blupi This version contains over 30 missions and a built in editor, which enables you to construct your own missions. @@ -20,16 +20,28 @@ What ever your screen resolution is, the game "Planet Blupi" always runs in the game by default in windowed mode. Proceed as follows: 1. Quit the game _Planet Blupi_. -2. Open the file `/data/config.json` with a text editor. +2. Open the file `share/planetblupi/data/config.json` with a text editor. 3. Replace `fullscreen: true` by `fullscreen: false`. 4. Save and restart the game. In this mode the screen is no more scrolled if the mouse touches the window border. Use the Keyboard arrows instead. +> It's possible to start the game with `--fullscreen off` instead of editing +> the `config.json` file. + +If the problem persists, maybe you should try to start the game with the software +renderer. Edit the `config.json` file and add `"renderer": "software"` or start +the game with `--renderer software`. + +On Windows, an other possibility exists. You can try to change the driver used +by the software renderer. By default it uses `"direct3d"`, you can change by +`"opengl"` with `"driver": "opengl"` with the `config.json` file or +`--driver opengl` by command line argument. + ## Mouse -Left button: +Left button: This button is always used in three steps: 1. Select a Blupi. @@ -41,7 +53,7 @@ step 1) is not necessary. You may select several Blupis by maintaining the Shift button pressed. -Right button: +Right button: The right button is a shortcut. It orders the selected Blupi to do the most useful operation on the selected spot. @@ -61,6 +73,30 @@ useful operation on the selected spot. When you switch to an other application, the game is automatically paused. +## Music + +The music is provided in OGG and MIDI formats. The OGG variant is prefered +because the render is the same for all platforms. For purist fanboys, it's +possible to enforce the MIDI variant by starting the game with the +`--restore-midi` command line argument. Note that in this case, it's possible +to lose some instruments, it depends of your system. + +> You can edit the `share/planetblupi/data/config.json` file and add an entry +> `"restoremidi": true`, or simply use the new settings available in the global +> settings screen in the game. + +If you want, you can overload all musics with yours by providing OGG or MIDI +music files in your user directory. + +On Windows, type `%APPDATA%\Epsitec SA\Planet Blupi` in the file browser, +on macOS, look at `~/Library/Application Support/Epsitec SA/Planet Blupi`, and +on Linux, look at `~/.local/share/Epsitec SA/Planet Blupi`. + +You can create a `music` sub-directory with your music. For example: +`%LOCALAPPDATA%\Epsitec SA\Planet Blupi\music\music000.ogg`. + +Only 10 musics are supported: `music000` to `music009`. + ## Epsitec SA _Planet Blupi_ is an original creation of [Epsitec SA][1]. diff --git a/resources/data/pl/stories.blp b/resources/data/pl/stories.blp index b1cf16a..e69574f 100644 --- a/resources/data/pl/stories.blp +++ b/resources/data/pl/stories.blp @@ -375,8 +375,8 @@ każdego Blupiego. 1|Cel: 1| 1|Uchroń jednego lub dwóch Blupich -1|przed zarażeniem i znajdź lekarstwo -1|dla zarażonych. +1|przed zarażeniem i znajdź +1|lekarstwo dla zarażonych. 1| 1|Następnie zaprowadź Blupich 1|do domu. @@ -999,7 +999,8 @@ klikania na każdym Blupim. 2|Cel: 2| -2|Blupi musi dotrzeć do swojego domu. +2|Blupi musi dotrzeć do swojego +2|domu. @28 1|Solucja: diff --git a/resources/image/little.png b/resources/image/little.png index 0ee5dba..1b2d9ef 100644 Binary files a/resources/image/little.png and b/resources/image/little.png differ diff --git a/resources/image/setup00.png b/resources/image/setup00.png index b95f5eb..2b2b43e 100644 Binary files a/resources/image/setup00.png and b/resources/image/setup00.png differ diff --git a/resources/linux/application.desktop.in b/resources/linux/application.desktop.in index cda0397..db29df3 100644 --- a/resources/linux/application.desktop.in +++ b/resources/linux/application.desktop.in @@ -6,5 +6,5 @@ GenericName=Video Game Comment=@PB_DESCRIPTION@ Exec=@PB_EXEC@ StartupWMClass=@PB_EXEC@ -Icon=@APPIMAGE_ICON_REF@ +Icon=@PB_ICON_REF@ Categories=Game;StrategyGame; diff --git a/resources/music/music000.ogg b/resources/music/music000.ogg new file mode 100644 index 0000000..5c47708 Binary files /dev/null and b/resources/music/music000.ogg differ diff --git a/resources/music/music001.ogg b/resources/music/music001.ogg new file mode 100644 index 0000000..97d95e6 Binary files /dev/null and b/resources/music/music001.ogg differ diff --git a/resources/music/music002.ogg b/resources/music/music002.ogg new file mode 100644 index 0000000..0a05f53 Binary files /dev/null and b/resources/music/music002.ogg differ diff --git a/resources/music/music003.ogg b/resources/music/music003.ogg new file mode 100644 index 0000000..de58b17 Binary files /dev/null and b/resources/music/music003.ogg differ diff --git a/resources/music/music004.ogg b/resources/music/music004.ogg new file mode 100644 index 0000000..7a19d3e Binary files /dev/null and b/resources/music/music004.ogg differ diff --git a/resources/music/music005.ogg b/resources/music/music005.ogg new file mode 100644 index 0000000..2dd982a Binary files /dev/null and b/resources/music/music005.ogg differ diff --git a/resources/music/music006.ogg b/resources/music/music006.ogg new file mode 100644 index 0000000..057788d Binary files /dev/null and b/resources/music/music006.ogg differ diff --git a/resources/music/music007.ogg b/resources/music/music007.ogg new file mode 100644 index 0000000..8d782f2 Binary files /dev/null and b/resources/music/music007.ogg differ diff --git a/resources/music/music008.ogg b/resources/music/music008.ogg new file mode 100644 index 0000000..b05d67d Binary files /dev/null and b/resources/music/music008.ogg differ diff --git a/resources/music/music009.ogg b/resources/music/music009.ogg new file mode 100644 index 0000000..a9a0714 Binary files /dev/null and b/resources/music/music009.ogg differ diff --git a/resources/nsis/NSIS.template.in b/resources/nsis/NSIS.template.in new file mode 100644 index 0000000..9a6b03d --- /dev/null +++ b/resources/nsis/NSIS.template.in @@ -0,0 +1,1016 @@ +; CPack install script designed for a nmake build + +;-------------------------------- +; You must define these values + + !define VERSION "@CPACK_PACKAGE_VERSION@" + !define PATCH "@CPACK_PACKAGE_VERSION_PATCH@" + !define INST_DIR "@CPACK_TEMPORARY_DIRECTORY@" + +;-------------------------------- +;Variables + + Var MUI_TEMP + Var STARTMENU_FOLDER + Var SV_ALLUSERS + Var START_MENU + Var DO_NOT_ADD_TO_PATH + Var ADD_TO_PATH_ALL_USERS + Var ADD_TO_PATH_CURRENT_USER + Var INSTALL_DESKTOP + Var IS_DEFAULT_INSTALLDIR +;-------------------------------- +;Include Modern UI + + !include "MUI.nsh" + + ;Default installation folder + InstallDir "@CPACK_NSIS_INSTALL_ROOT@\@CPACK_PACKAGE_INSTALL_DIRECTORY@" + +;-------------------------------- +;General +!ifdef INNER + OutFile "${TEMPINSTALLER}.exe" + SetCompress off ; for speed +!else + ; Call makensis again, defining INNER. This writes an installer for us which, when + ; it is invoked, will just write the uninstaller to some location, and then exit. + ; Be sure to substitute the name of this script here. + !tempfile TEMPINSTALLER + !tempfile TEMPUNINSTALLER + !system "$\"makensis$\" /DTEMPINSTALLER=$\"${TEMPINSTALLER}$\" /DTEMPUNINSTALLER=$\"${TEMPUNINSTALLER}$\" /DINNER $\"@CPACK_TEMPORARY_DIRECTORY@/../project.nsi$\"" = 0 + + ; So now run that installer we just created as %TEMP%\tempinstaller.exe. Since it + ; calls quit the return value isn't zero. + + !system "$\"${TEMPINSTALLER}.exe$\"" = 2 + + ; That will have written an uninstaller binary for us. Now we sign it with your + ; favourite code signing tool. + + ;!tempfile INCEXIST + ;!system 'if exist "@CPACK_NSIS_SIGN_UNINSTALLER@" echo !define HAVE_SIGN_UNINST > "${INCEXIST}"' + ;!include "${INCEXIST}" + ;!delfile "${INCEXIST}" + ;!ifdef HAVE_SIGN_UNINST + !system 'signtool @CPACK_NSIS_SIGN_UNINSTALLER@ "${TEMPUNINSTALLER}.exe"' = 0 + ;!endif + + ; Good. Now we can carry on writing the real installer. + + ;Name and file + Name "@CPACK_NSIS_PACKAGE_NAME@" + OutFile "@CPACK_TOPLEVEL_DIRECTORY@/@CPACK_OUTPUT_FILE_NAME@" + + ;Set compression + SetCompressor @CPACK_NSIS_COMPRESSOR@ +!endif + + ;Require administrator access + RequestExecutionLevel admin + +@CPACK_NSIS_DEFINES@ + + !include Sections.nsh + +;--- Component support macros: --- +; The code for the add/remove functionality is from: +; http://nsis.sourceforge.net/Add/Remove_Functionality +; It has been modified slightly and extended to provide +; inter-component dependencies. +Var AR_SecFlags +Var AR_RegFlags +@CPACK_NSIS_SECTION_SELECTED_VARS@ + +; Loads the "selected" flag for the section named SecName into the +; variable VarName. +!macro LoadSectionSelectedIntoVar SecName VarName + SectionGetFlags ${${SecName}} $${VarName} + IntOp $${VarName} $${VarName} & ${SF_SELECTED} ;Turn off all other bits +!macroend + +; Loads the value of a variable... can we get around this? +!macro LoadVar VarName + IntOp $R0 0 + $${VarName} +!macroend + +; Sets the value of a variable +!macro StoreVar VarName IntValue + IntOp $${VarName} 0 + ${IntValue} +!macroend + +!macro InitSection SecName + ; This macro reads component installed flag from the registry and + ;changes checked state of the section on the components page. + ;Input: section index constant name specified in Section command. + + ClearErrors + ;Reading component status from registry + ReadRegDWORD $AR_RegFlags HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@\Components\${SecName}" "Installed" + IfErrors "default_${SecName}" + ;Status will stay default if registry value not found + ;(component was never installed) + IntOp $AR_RegFlags $AR_RegFlags & ${SF_SELECTED} ;Turn off all other bits + SectionGetFlags ${${SecName}} $AR_SecFlags ;Reading default section flags + IntOp $AR_SecFlags $AR_SecFlags & 0xFFFE ;Turn lowest (enabled) bit off + IntOp $AR_SecFlags $AR_RegFlags | $AR_SecFlags ;Change lowest bit + + ; Note whether this component was installed before + !insertmacro StoreVar ${SecName}_was_installed $AR_RegFlags + IntOp $R0 $AR_RegFlags & $AR_RegFlags + + ;Writing modified flags + SectionSetFlags ${${SecName}} $AR_SecFlags + + "default_${SecName}:" + !insertmacro LoadSectionSelectedIntoVar ${SecName} ${SecName}_selected +!macroend + +!macro FinishSection SecName + ; This macro reads section flag set by user and removes the section + ;if it is not selected. + ;Then it writes component installed flag to registry + ;Input: section index constant name specified in Section command. + + SectionGetFlags ${${SecName}} $AR_SecFlags ;Reading section flags + ;Checking lowest bit: + IntOp $AR_SecFlags $AR_SecFlags & ${SF_SELECTED} + IntCmp $AR_SecFlags 1 "leave_${SecName}" + ;Section is not selected: + ;Calling Section uninstall macro and writing zero installed flag + !insertmacro "Remove_${${SecName}}" + WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@\Components\${SecName}" \ + "Installed" 0 + Goto "exit_${SecName}" + + "leave_${SecName}:" + ;Section is selected: + WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@\Components\${SecName}" \ + "Installed" 1 + + "exit_${SecName}:" +!macroend + +!macro RemoveSection_CPack SecName + ; This macro is used to call section's Remove_... macro + ;from the uninstaller. + ;Input: section index constant name specified in Section command. + + !insertmacro "Remove_${${SecName}}" +!macroend + +; Determine whether the selection of SecName changed +!macro MaybeSelectionChanged SecName + !insertmacro LoadVar ${SecName}_selected + SectionGetFlags ${${SecName}} $R1 + IntOp $R1 $R1 & ${SF_SELECTED} ;Turn off all other bits + + ; See if the status has changed: + IntCmp $R0 $R1 "${SecName}_unchanged" + !insertmacro LoadSectionSelectedIntoVar ${SecName} ${SecName}_selected + + IntCmp $R1 ${SF_SELECTED} "${SecName}_was_selected" + !insertmacro "Deselect_required_by_${SecName}" + goto "${SecName}_unchanged" + + "${SecName}_was_selected:" + !insertmacro "Select_${SecName}_depends" + + "${SecName}_unchanged:" +!macroend +;--- End of Add/Remove macros --- + +;-------------------------------- +;Interface Settings + + !define MUI_HEADERIMAGE + !define MUI_ABORTWARNING + +;---------------------------------------- +; based upon a script of "Written by KiCHiK 2003-01-18 05:57:02" +;---------------------------------------- +!verbose 3 +!include "WinMessages.NSH" +!verbose 4 +;==================================================== +; get_NT_environment +; Returns: the selected environment +; Output : head of the stack +;==================================================== +!macro select_NT_profile UN +Function ${UN}select_NT_profile + StrCmp $ADD_TO_PATH_ALL_USERS "1" 0 environment_single + DetailPrint "Selected environment for all users" + Push "all" + Return + environment_single: + DetailPrint "Selected environment for current user only." + Push "current" + Return +FunctionEnd +!macroend +!insertmacro select_NT_profile "" +!insertmacro select_NT_profile "un." +;---------------------------------------------------- +!define NT_current_env 'HKCU "Environment"' +!define NT_all_env 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"' + +!ifndef WriteEnvStr_RegKey + !ifdef ALL_USERS + !define WriteEnvStr_RegKey \ + 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"' + !else + !define WriteEnvStr_RegKey 'HKCU "Environment"' + !endif +!endif + +; AddToPath - Adds the given dir to the search path. +; Input - head of the stack +; Note - Win9x systems requires reboot + +Function AddToPath + Exch $0 + Push $1 + Push $2 + Push $3 + + # don't add if the path doesn't exist + IfFileExists "$0\*.*" "" AddToPath_done + + ReadEnvStr $1 PATH + ; if the path is too long for a NSIS variable NSIS will return a 0 + ; length string. If we find that, then warn and skip any path + ; modification as it will trash the existing path. + StrLen $2 $1 + IntCmp $2 0 CheckPathLength_ShowPathWarning CheckPathLength_Done CheckPathLength_Done + CheckPathLength_ShowPathWarning: + Messagebox MB_OK|MB_ICONEXCLAMATION "Warning! PATH too long installer unable to modify PATH!" + Goto AddToPath_done + CheckPathLength_Done: + Push "$1;" + Push "$0;" + Call StrStr + Pop $2 + StrCmp $2 "" "" AddToPath_done + Push "$1;" + Push "$0\;" + Call StrStr + Pop $2 + StrCmp $2 "" "" AddToPath_done + GetFullPathName /SHORT $3 $0 + Push "$1;" + Push "$3;" + Call StrStr + Pop $2 + StrCmp $2 "" "" AddToPath_done + Push "$1;" + Push "$3\;" + Call StrStr + Pop $2 + StrCmp $2 "" "" AddToPath_done + + Call IsNT + Pop $1 + StrCmp $1 1 AddToPath_NT + ; Not on NT + StrCpy $1 $WINDIR 2 + FileOpen $1 "$1\autoexec.bat" a + FileSeek $1 -1 END + FileReadByte $1 $2 + IntCmp $2 26 0 +2 +2 # DOS EOF + FileSeek $1 -1 END # write over EOF + FileWrite $1 "$\r$\nSET PATH=%PATH%;$3$\r$\n" + FileClose $1 + SetRebootFlag true + Goto AddToPath_done + + AddToPath_NT: + StrCmp $ADD_TO_PATH_ALL_USERS "1" ReadAllKey + ReadRegStr $1 ${NT_current_env} "PATH" + Goto DoTrim + ReadAllKey: + ReadRegStr $1 ${NT_all_env} "PATH" + DoTrim: + StrCmp $1 "" AddToPath_NTdoIt + Push $1 + Call Trim + Pop $1 + StrCpy $0 "$1;$0" + AddToPath_NTdoIt: + StrCmp $ADD_TO_PATH_ALL_USERS "1" WriteAllKey + WriteRegExpandStr ${NT_current_env} "PATH" $0 + Goto DoSend + WriteAllKey: + WriteRegExpandStr ${NT_all_env} "PATH" $0 + DoSend: + SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000 + + AddToPath_done: + Pop $3 + Pop $2 + Pop $1 + Pop $0 +FunctionEnd + + +; RemoveFromPath - Remove a given dir from the path +; Input: head of the stack + +Function un.RemoveFromPath + Exch $0 + Push $1 + Push $2 + Push $3 + Push $4 + Push $5 + Push $6 + + IntFmt $6 "%c" 26 # DOS EOF + + Call un.IsNT + Pop $1 + StrCmp $1 1 unRemoveFromPath_NT + ; Not on NT + StrCpy $1 $WINDIR 2 + FileOpen $1 "$1\autoexec.bat" r + GetTempFileName $4 + FileOpen $2 $4 w + GetFullPathName /SHORT $0 $0 + StrCpy $0 "SET PATH=%PATH%;$0" + Goto unRemoveFromPath_dosLoop + + unRemoveFromPath_dosLoop: + FileRead $1 $3 + StrCpy $5 $3 1 -1 # read last char + StrCmp $5 $6 0 +2 # if DOS EOF + StrCpy $3 $3 -1 # remove DOS EOF so we can compare + StrCmp $3 "$0$\r$\n" unRemoveFromPath_dosLoopRemoveLine + StrCmp $3 "$0$\n" unRemoveFromPath_dosLoopRemoveLine + StrCmp $3 "$0" unRemoveFromPath_dosLoopRemoveLine + StrCmp $3 "" unRemoveFromPath_dosLoopEnd + FileWrite $2 $3 + Goto unRemoveFromPath_dosLoop + unRemoveFromPath_dosLoopRemoveLine: + SetRebootFlag true + Goto unRemoveFromPath_dosLoop + + unRemoveFromPath_dosLoopEnd: + FileClose $2 + FileClose $1 + StrCpy $1 $WINDIR 2 + Delete "$1\autoexec.bat" + CopyFiles /SILENT $4 "$1\autoexec.bat" + Delete $4 + Goto unRemoveFromPath_done + + unRemoveFromPath_NT: + StrCmp $ADD_TO_PATH_ALL_USERS "1" unReadAllKey + ReadRegStr $1 ${NT_current_env} "PATH" + Goto unDoTrim + unReadAllKey: + ReadRegStr $1 ${NT_all_env} "PATH" + unDoTrim: + StrCpy $5 $1 1 -1 # copy last char + StrCmp $5 ";" +2 # if last char != ; + StrCpy $1 "$1;" # append ; + Push $1 + Push "$0;" + Call un.StrStr ; Find `$0;` in $1 + Pop $2 ; pos of our dir + StrCmp $2 "" unRemoveFromPath_done + ; else, it is in path + # $0 - path to add + # $1 - path var + StrLen $3 "$0;" + StrLen $4 $2 + StrCpy $5 $1 -$4 # $5 is now the part before the path to remove + StrCpy $6 $2 "" $3 # $6 is now the part after the path to remove + StrCpy $3 $5$6 + + StrCpy $5 $3 1 -1 # copy last char + StrCmp $5 ";" 0 +2 # if last char == ; + StrCpy $3 $3 -1 # remove last char + + StrCmp $ADD_TO_PATH_ALL_USERS "1" unWriteAllKey + WriteRegExpandStr ${NT_current_env} "PATH" $3 + Goto unDoSend + unWriteAllKey: + WriteRegExpandStr ${NT_all_env} "PATH" $3 + unDoSend: + SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000 + + unRemoveFromPath_done: + Pop $6 + Pop $5 + Pop $4 + Pop $3 + Pop $2 + Pop $1 + Pop $0 +FunctionEnd + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Uninstall sutff +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +########################################### +# Utility Functions # +########################################### + +;==================================================== +; IsNT - Returns 1 if the current system is NT, 0 +; otherwise. +; Output: head of the stack +;==================================================== +; IsNT +; no input +; output, top of the stack = 1 if NT or 0 if not +; +; Usage: +; Call IsNT +; Pop $R0 +; ($R0 at this point is 1 or 0) + +!macro IsNT un +Function ${un}IsNT + Push $0 + ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion + StrCmp $0 "" 0 IsNT_yes + ; we are not NT. + Pop $0 + Push 0 + Return + + IsNT_yes: + ; NT!!! + Pop $0 + Push 1 +FunctionEnd +!macroend +!insertmacro IsNT "" +!insertmacro IsNT "un." + +; StrStr +; input, top of stack = string to search for +; top of stack-1 = string to search in +; output, top of stack (replaces with the portion of the string remaining) +; modifies no other variables. +; +; Usage: +; Push "this is a long ass string" +; Push "ass" +; Call StrStr +; Pop $R0 +; ($R0 at this point is "ass string") + +!macro StrStr un +Function ${un}StrStr +Exch $R1 ; st=haystack,old$R1, $R1=needle + Exch ; st=old$R1,haystack + Exch $R2 ; st=old$R1,old$R2, $R2=haystack + Push $R3 + Push $R4 + Push $R5 + StrLen $R3 $R1 + StrCpy $R4 0 + ; $R1=needle + ; $R2=haystack + ; $R3=len(needle) + ; $R4=cnt + ; $R5=tmp + loop: + StrCpy $R5 $R2 $R3 $R4 + StrCmp $R5 $R1 done + StrCmp $R5 "" done + IntOp $R4 $R4 + 1 + Goto loop +done: + StrCpy $R1 $R2 "" $R4 + Pop $R5 + Pop $R4 + Pop $R3 + Pop $R2 + Exch $R1 +FunctionEnd +!macroend +!insertmacro StrStr "" +!insertmacro StrStr "un." + +Function Trim ; Added by Pelaca + Exch $R1 + Push $R2 +Loop: + StrCpy $R2 "$R1" 1 -1 + StrCmp "$R2" " " RTrim + StrCmp "$R2" "$\n" RTrim + StrCmp "$R2" "$\r" RTrim + StrCmp "$R2" ";" RTrim + GoTo Done +RTrim: + StrCpy $R1 "$R1" -1 + Goto Loop +Done: + Pop $R2 + Exch $R1 +FunctionEnd + +Function ConditionalAddToRegisty + Pop $0 + Pop $1 + StrCmp "$0" "" ConditionalAddToRegisty_EmptyString + WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" \ + "$1" "$0" + ;MessageBox MB_OK "Set Registry: '$1' to '$0'" + DetailPrint "Set install registry entry: '$1' to '$0'" + ConditionalAddToRegisty_EmptyString: +FunctionEnd + +;-------------------------------- + +!ifdef CPACK_USES_DOWNLOAD +Function DownloadFile + IfFileExists $INSTDIR\* +2 + CreateDirectory $INSTDIR + Pop $0 + + ; Skip if already downloaded + IfFileExists $INSTDIR\$0 0 +2 + Return + + StrCpy $1 "@CPACK_DOWNLOAD_SITE@" + + try_again: + NSISdl::download "$1/$0" "$INSTDIR\$0" + + Pop $1 + StrCmp $1 "success" success + StrCmp $1 "Cancelled" cancel + MessageBox MB_OK "Download failed: $1" + cancel: + Return + success: +FunctionEnd +!endif + +;-------------------------------- +; Installation types +@CPACK_NSIS_INSTALLATION_TYPES@ + +;-------------------------------- +; Component sections +@CPACK_NSIS_COMPONENT_SECTIONS@ + +;-------------------------------- +; Define some macro setting for the gui +@CPACK_NSIS_INSTALLER_MUI_ICON_CODE@ +@CPACK_NSIS_INSTALLER_ICON_CODE@ +@CPACK_NSIS_INSTALLER_MUI_WELCOMEFINISH_CODE@ +@CPACK_NSIS_INSTALLER_MUI_UNWELCOMEFINISH_CODE@ +@CPACK_NSIS_INSTALLER_MUI_COMPONENTS_DESC@ +@CPACK_NSIS_INSTALLER_MUI_FINISHPAGE_RUN_CODE@ + +;-------------------------------- +;Pages + !insertmacro MUI_PAGE_WELCOME + + !insertmacro MUI_PAGE_LICENSE "@CPACK_RESOURCE_FILE_LICENSE@" + Page custom InstallOptionsPage + !insertmacro MUI_PAGE_DIRECTORY + + ;Start Menu Folder Page Configuration + !define MUI_STARTMENUPAGE_REGISTRY_ROOT "SHCTX" + !define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" + !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder" + !insertmacro MUI_PAGE_STARTMENU Application $STARTMENU_FOLDER + + @CPACK_NSIS_PAGE_COMPONENTS@ + + !insertmacro MUI_PAGE_INSTFILES + !insertmacro MUI_PAGE_FINISH + +!ifdef INNER + !insertmacro MUI_UNPAGE_CONFIRM + !insertmacro MUI_UNPAGE_INSTFILES +!endif + +;-------------------------------- +;Languages + + !insertmacro MUI_LANGUAGE "English" ;first language is the default language + !insertmacro MUI_LANGUAGE "Albanian" + !insertmacro MUI_LANGUAGE "Arabic" + !insertmacro MUI_LANGUAGE "Basque" + !insertmacro MUI_LANGUAGE "Belarusian" + !insertmacro MUI_LANGUAGE "Bosnian" + !insertmacro MUI_LANGUAGE "Breton" + !insertmacro MUI_LANGUAGE "Bulgarian" + !insertmacro MUI_LANGUAGE "Croatian" + !insertmacro MUI_LANGUAGE "Czech" + !insertmacro MUI_LANGUAGE "Danish" + !insertmacro MUI_LANGUAGE "Dutch" + !insertmacro MUI_LANGUAGE "Estonian" + !insertmacro MUI_LANGUAGE "Farsi" + !insertmacro MUI_LANGUAGE "Finnish" + !insertmacro MUI_LANGUAGE "French" + !insertmacro MUI_LANGUAGE "German" + !insertmacro MUI_LANGUAGE "Greek" + !insertmacro MUI_LANGUAGE "Hebrew" + !insertmacro MUI_LANGUAGE "Hungarian" + !insertmacro MUI_LANGUAGE "Icelandic" + !insertmacro MUI_LANGUAGE "Indonesian" + !insertmacro MUI_LANGUAGE "Irish" + !insertmacro MUI_LANGUAGE "Italian" + !insertmacro MUI_LANGUAGE "Japanese" + !insertmacro MUI_LANGUAGE "Korean" + !insertmacro MUI_LANGUAGE "Kurdish" + !insertmacro MUI_LANGUAGE "Latvian" + !insertmacro MUI_LANGUAGE "Lithuanian" + !insertmacro MUI_LANGUAGE "Luxembourgish" + !insertmacro MUI_LANGUAGE "Macedonian" + !insertmacro MUI_LANGUAGE "Malay" + !insertmacro MUI_LANGUAGE "Mongolian" + !insertmacro MUI_LANGUAGE "Norwegian" + !insertmacro MUI_LANGUAGE "Polish" + !insertmacro MUI_LANGUAGE "Portuguese" + !insertmacro MUI_LANGUAGE "PortugueseBR" + !insertmacro MUI_LANGUAGE "Romanian" + !insertmacro MUI_LANGUAGE "Russian" + !insertmacro MUI_LANGUAGE "Serbian" + !insertmacro MUI_LANGUAGE "SerbianLatin" + !insertmacro MUI_LANGUAGE "SimpChinese" + !insertmacro MUI_LANGUAGE "Slovak" + !insertmacro MUI_LANGUAGE "Slovenian" + !insertmacro MUI_LANGUAGE "Spanish" + !insertmacro MUI_LANGUAGE "Swedish" + !insertmacro MUI_LANGUAGE "Thai" + !insertmacro MUI_LANGUAGE "TradChinese" + !insertmacro MUI_LANGUAGE "Turkish" + !insertmacro MUI_LANGUAGE "Ukrainian" + !insertmacro MUI_LANGUAGE "Welsh" + + +;-------------------------------- +;Reserve Files + + ;These files should be inserted before other files in the data block + ;Keep these lines before any File command + ;Only for solid compression (by default, solid compression is enabled for BZIP2 and LZMA) + + ReserveFile "NSIS.InstallOptions.ini" + !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS + +;-------------------------------- +;Installer Sections + +Section "-Core installation" + ;Use the entire tree produced by the INSTALL target. Keep the + ;list of directories here in sync with the RMDir commands below. + SetOutPath "$INSTDIR" + @CPACK_NSIS_EXTRA_PREINSTALL_COMMANDS@ + @CPACK_NSIS_FULL_INSTALL@ + + ;Store installation folder + WriteRegStr SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "" $INSTDIR + + ;Create uninstaller +!ifndef INNER + ; this packages the signed uninstaller + File "/oname=Uninstall.exe" "${TEMPUNINSTALLER}.exe" +!endif + Push "DisplayName" + Push "@CPACK_NSIS_DISPLAY_NAME@" + Call ConditionalAddToRegisty + Push "DisplayVersion" + Push "@CPACK_PACKAGE_VERSION@" + Call ConditionalAddToRegisty + Push "Publisher" + Push "@CPACK_PACKAGE_VENDOR@" + Call ConditionalAddToRegisty + Push "UninstallString" + Push "$INSTDIR\Uninstall.exe" + Call ConditionalAddToRegisty + Push "NoRepair" + Push "1" + Call ConditionalAddToRegisty + + !ifdef CPACK_NSIS_ADD_REMOVE + ;Create add/remove functionality + Push "ModifyPath" + Push "$INSTDIR\AddRemove.exe" + Call ConditionalAddToRegisty + !else + Push "NoModify" + Push "1" + Call ConditionalAddToRegisty + !endif + + ; Optional registration + Push "DisplayIcon" + Push "$INSTDIR\@CPACK_NSIS_INSTALLED_ICON_NAME@" + Call ConditionalAddToRegisty + Push "HelpLink" + Push "@CPACK_NSIS_HELP_LINK@" + Call ConditionalAddToRegisty + Push "URLInfoAbout" + Push "@CPACK_NSIS_URL_INFO_ABOUT@" + Call ConditionalAddToRegisty + Push "Contact" + Push "@CPACK_NSIS_CONTACT@" + Call ConditionalAddToRegisty + !insertmacro MUI_INSTALLOPTIONS_READ $INSTALL_DESKTOP "NSIS.InstallOptions.ini" "Field 5" "State" + !insertmacro MUI_STARTMENU_WRITE_BEGIN Application + + ;Create shortcuts + CreateDirectory "$SMPROGRAMS\$STARTMENU_FOLDER" +@CPACK_NSIS_CREATE_ICONS@ +@CPACK_NSIS_CREATE_ICONS_EXTRA@ + CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Uninstall.lnk" "$INSTDIR\Uninstall.exe" + + ;Read a value from an InstallOptions INI file + !insertmacro MUI_INSTALLOPTIONS_READ $DO_NOT_ADD_TO_PATH "NSIS.InstallOptions.ini" "Field 2" "State" + !insertmacro MUI_INSTALLOPTIONS_READ $ADD_TO_PATH_ALL_USERS "NSIS.InstallOptions.ini" "Field 3" "State" + !insertmacro MUI_INSTALLOPTIONS_READ $ADD_TO_PATH_CURRENT_USER "NSIS.InstallOptions.ini" "Field 4" "State" + + ; Write special uninstall registry entries + Push "StartMenu" + Push "$STARTMENU_FOLDER" + Call ConditionalAddToRegisty + Push "DoNotAddToPath" + Push "$DO_NOT_ADD_TO_PATH" + Call ConditionalAddToRegisty + Push "AddToPathAllUsers" + Push "$ADD_TO_PATH_ALL_USERS" + Call ConditionalAddToRegisty + Push "AddToPathCurrentUser" + Push "$ADD_TO_PATH_CURRENT_USER" + Call ConditionalAddToRegisty + Push "InstallToDesktop" + Push "$INSTALL_DESKTOP" + Call ConditionalAddToRegisty + + !insertmacro MUI_STARTMENU_WRITE_END + +@CPACK_NSIS_EXTRA_INSTALL_COMMANDS@ + +SectionEnd + +Section "-Add to path" + Push $INSTDIR\bin + StrCmp "@CPACK_NSIS_MODIFY_PATH@" "ON" 0 doNotAddToPath + StrCmp $DO_NOT_ADD_TO_PATH "1" doNotAddToPath 0 + Call AddToPath + doNotAddToPath: +SectionEnd + +;-------------------------------- +; Create custom pages +Function InstallOptionsPage + !insertmacro MUI_HEADER_TEXT "Install Options" "Choose options for installing @CPACK_NSIS_PACKAGE_NAME@" + !insertmacro MUI_INSTALLOPTIONS_DISPLAY "NSIS.InstallOptions.ini" + +FunctionEnd + +;-------------------------------- +; determine admin versus local install +Function un.onInit + + ClearErrors + UserInfo::GetName + IfErrors noLM + Pop $0 + UserInfo::GetAccountType + Pop $1 + StrCmp $1 "Admin" 0 +3 + SetShellVarContext all + ;MessageBox MB_OK 'User "$0" is in the Admin group' + Goto done + StrCmp $1 "Power" 0 +3 + SetShellVarContext all + ;MessageBox MB_OK 'User "$0" is in the Power Users group' + Goto done + + noLM: + ;Get installation folder from registry if available + + done: + +FunctionEnd + +;--- Add/Remove callback functions: --- +!macro SectionList MacroName + ;This macro used to perform operation on multiple sections. + ;List all of your components in following manner here. +@CPACK_NSIS_COMPONENT_SECTION_LIST@ +!macroend + +Section -FinishComponents + ;Removes unselected components and writes component status to registry + !insertmacro SectionList "FinishSection" + +!ifdef CPACK_NSIS_ADD_REMOVE + ; Get the name of the installer executable + System::Call 'kernel32::GetModuleFileNameA(i 0, t .R0, i 1024) i r1' + StrCpy $R3 $R0 + + ; Strip off the last 13 characters, to see if we have AddRemove.exe + StrLen $R1 $R0 + IntOp $R1 $R0 - 13 + StrCpy $R2 $R0 13 $R1 + StrCmp $R2 "AddRemove.exe" addremove_installed + + ; We're not running AddRemove.exe, so install it + CopyFiles $R3 $INSTDIR\AddRemove.exe + + addremove_installed: +!endif +SectionEnd +;--- End of Add/Remove callback functions --- + +;-------------------------------- +; Component dependencies +Function .onSelChange + !insertmacro SectionList MaybeSelectionChanged +FunctionEnd + +;-------------------------------- +;Uninstaller Section + +!ifdef INNER +Section "Uninstall" + ReadRegStr $START_MENU SHCTX \ + "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "StartMenu" + ;MessageBox MB_OK "Start menu is in: $START_MENU" + ReadRegStr $DO_NOT_ADD_TO_PATH SHCTX \ + "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "DoNotAddToPath" + ReadRegStr $ADD_TO_PATH_ALL_USERS SHCTX \ + "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "AddToPathAllUsers" + ReadRegStr $ADD_TO_PATH_CURRENT_USER SHCTX \ + "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "AddToPathCurrentUser" + ;MessageBox MB_OK "Add to path: $DO_NOT_ADD_TO_PATH all users: $ADD_TO_PATH_ALL_USERS" + ReadRegStr $INSTALL_DESKTOP SHCTX \ + "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "InstallToDesktop" + ;MessageBox MB_OK "Install to desktop: $INSTALL_DESKTOP " + +@CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS@ + + ;Remove files we installed. + ;Keep the list of directories here in sync with the File commands above. +@CPACK_NSIS_DELETE_FILES@ +@CPACK_NSIS_DELETE_DIRECTORIES@ + +!ifdef CPACK_NSIS_ADD_REMOVE + ;Remove the add/remove program + Delete "$INSTDIR\AddRemove.exe" +!endif + + ;Remove the uninstaller itself. + Delete "$INSTDIR\Uninstall.exe" + DeleteRegKey SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" + + ;Remove the installation directory if it is empty. + RMDir "$INSTDIR" + + ; Remove the registry entries. + DeleteRegKey SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" + + ; Removes all optional components + !insertmacro SectionList "RemoveSection_CPack" + + !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP + + Delete "$SMPROGRAMS\$MUI_TEMP\Uninstall.lnk" +@CPACK_NSIS_DELETE_ICONS@ +@CPACK_NSIS_DELETE_ICONS_EXTRA@ + + ;Delete empty start menu parent diretories + StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP" + + startMenuDeleteLoop: + ClearErrors + RMDir $MUI_TEMP + GetFullPathName $MUI_TEMP "$MUI_TEMP\.." + + IfErrors startMenuDeleteLoopDone + + StrCmp "$MUI_TEMP" "$SMPROGRAMS" startMenuDeleteLoopDone startMenuDeleteLoop + startMenuDeleteLoopDone: + + ; If the user changed the shortcut, then untinstall may not work. This should + ; try to fix it. + StrCpy $MUI_TEMP "$START_MENU" + Delete "$SMPROGRAMS\$MUI_TEMP\Uninstall.lnk" +@CPACK_NSIS_DELETE_ICONS_EXTRA@ + + ;Delete empty start menu parent diretories + StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP" + + secondStartMenuDeleteLoop: + ClearErrors + RMDir $MUI_TEMP + GetFullPathName $MUI_TEMP "$MUI_TEMP\.." + + IfErrors secondStartMenuDeleteLoopDone + + StrCmp "$MUI_TEMP" "$SMPROGRAMS" secondStartMenuDeleteLoopDone secondStartMenuDeleteLoop + secondStartMenuDeleteLoopDone: + + DeleteRegKey /ifempty SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" + + Push $INSTDIR\bin + StrCmp $DO_NOT_ADD_TO_PATH_ "1" doNotRemoveFromPath 0 + Call un.RemoveFromPath + doNotRemoveFromPath: +SectionEnd +!endif + +;-------------------------------- +; determine admin versus local install +; Is install for "AllUsers" or "JustMe"? +; Default to "JustMe" - set to "AllUsers" if admin or on Win9x +; This function is used for the very first "custom page" of the installer. +; This custom page does not show up visibly, but it executes prior to the +; first visible page and sets up $INSTDIR properly... +; Choose different default installation folder based on SV_ALLUSERS... +; "Program Files" for AllUsers, "My Documents" for JustMe... + +Function .onInit +!ifdef INNER + ; If INNER is defined, then we aren't supposed to do anything except write out + ; the installer. This is better than processing a command line option as it means + ; this entire code path is not present in the final (real) installer. + + WriteUninstaller "${TEMPUNINSTALLER}.exe" + Quit ; just bail out quickly when running the "inner" installer +!endif + StrCmp "@CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL@" "ON" 0 inst + + ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "UninstallString" + StrCmp $0 "" inst + + MessageBox MB_YESNOCANCEL|MB_ICONEXCLAMATION \ + "@CPACK_NSIS_PACKAGE_NAME@ is already installed. $\n$\nDo you want to uninstall the old version before installing the new one?" \ + /SD IDYES IDYES uninst IDNO inst + Abort + +;Run the uninstaller +uninst: + ClearErrors + StrLen $2 "\Uninstall.exe" + StrCpy $3 $0 -$2 # remove "\Uninstall.exe" from UninstallString to get path + ExecWait '"$0" /S _?=$3' ;Do not copy the uninstaller to a temp file + + IfErrors uninst_failed inst +uninst_failed: + MessageBox MB_OK|MB_ICONSTOP "Uninstall failed." + Abort + + +inst: + ; Reads components status for registry + !insertmacro SectionList "InitSection" + + ; check to see if /D has been used to change + ; the install directory by comparing it to the + ; install directory that is expected to be the + ; default + StrCpy $IS_DEFAULT_INSTALLDIR 0 + StrCmp "$INSTDIR" "@CPACK_NSIS_INSTALL_ROOT@\@CPACK_PACKAGE_INSTALL_DIRECTORY@" 0 +2 + StrCpy $IS_DEFAULT_INSTALLDIR 1 + + StrCpy $SV_ALLUSERS "JustMe" + ; if default install dir then change the default + ; if it is installed for JustMe + StrCmp "$IS_DEFAULT_INSTALLDIR" "1" 0 +2 + StrCpy $INSTDIR "$DOCUMENTS\@CPACK_PACKAGE_INSTALL_DIRECTORY@" + + ClearErrors + UserInfo::GetName + IfErrors noLM + Pop $0 + UserInfo::GetAccountType + Pop $1 + StrCmp $1 "Admin" 0 +4 + SetShellVarContext all + ;MessageBox MB_OK 'User "$0" is in the Admin group' + StrCpy $SV_ALLUSERS "AllUsers" + Goto done + StrCmp $1 "Power" 0 +4 + SetShellVarContext all + ;MessageBox MB_OK 'User "$0" is in the Power Users group' + StrCpy $SV_ALLUSERS "AllUsers" + Goto done + + noLM: + StrCpy $SV_ALLUSERS "AllUsers" + ;Get installation folder from registry if available + + done: + StrCmp $SV_ALLUSERS "AllUsers" 0 +3 + StrCmp "$IS_DEFAULT_INSTALLDIR" "1" 0 +2 + StrCpy $INSTDIR "@CPACK_NSIS_INSTALL_ROOT@\@CPACK_PACKAGE_INSTALL_DIRECTORY@" + + StrCmp "@CPACK_NSIS_MODIFY_PATH@" "ON" 0 noOptionsPage + !insertmacro MUI_INSTALLOPTIONS_EXTRACT "NSIS.InstallOptions.ini" + + noOptionsPage: +FunctionEnd diff --git a/resources/nsis/bootstrap.sh b/resources/nsis/bootstrap.sh new file mode 100755 index 0000000..ac61603 --- /dev/null +++ b/resources/nsis/bootstrap.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +mv /C/msys64/mingw64/share/cmake-3.9/Modules/NSIS.template.in /C/msys64/mingw64/share/cmake-3.9/Modules/NSIS.template.in.orig +mv /C/msys64/mingw32/share/cmake-3.9/Modules/NSIS.template.in /C/msys64/mingw32/share/cmake-3.9/Modules/NSIS.template.in.orig +cp $(dirname $0)/NSIS.template.in /C/msys64/mingw64/share/cmake-3.9/Modules/NSIS.template.in +cp $(dirname $0)/NSIS.template.in /C/msys64/mingw32/share/cmake-3.9/Modules/NSIS.template.in diff --git a/resources/po/de.po b/resources/po/de.po index c2267a5..2a07b3e 100644 --- a/resources/po/de.po +++ b/resources/po/de.po @@ -7,15 +7,15 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-09-15 18:34+0200\n" -"PO-Revision-Date: 2017-10-04 23:30+0200\n" +"POT-Creation-Date: 2017-12-14 23:13+0100\n" +"PO-Revision-Date: 2017-12-14 23:15+0100\n" "Last-Translator: \n" "Language-Team: \n" "Language: de\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Generator: Poedit 1.8.11\n" +"X-Generator: Poedit 2.0.5\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" msgid " - FFmpeg (LGPLv2.1)" @@ -39,12 +39,18 @@ msgstr " - libasound (LGPLv2.1)" msgid " - libcurl (MIT/X derivate)" msgstr " - libcurl (MIT/X Derivatlizenz)" +msgid " - libogg and libvorbis (own license)" +msgstr " - libogg and libvorbis (Eigene Lizenz)" + msgid " - libpng (own license)" msgstr " - libpng (Eigene Lizenz)" msgid " - libpulse (LGPLv2.1)" msgstr " - libpulse (LGPLv2.1)" +msgid " - libsndfile (LGPLv3)" +msgstr " - libsndfile (LGPLv3)" + msgid " - zlib (own license)" msgstr " - zlib (Eigene Lizenz)" @@ -283,6 +289,11 @@ msgstr "" "Fentergrösse\n" "anpassen" +msgid "" +"Choose the\n" +"music format" +msgstr "" + msgid "Construct this game" msgstr "Diese Mission konstruieren" @@ -520,6 +531,9 @@ msgstr "Roboterchef" msgid "Medical potion" msgstr "Medikament" +msgid "Midi" +msgstr "Midi" + msgid "Mine" msgstr "Bergwerk" @@ -624,6 +638,9 @@ msgstr "Du kannst jetzt mit den Missionen beginnen." msgid "Occupied ground" msgstr "Untergrund schon besetzt" +msgid "Ogg" +msgstr "Ogg" + msgid "Open another game" msgstr "Gespeicherte Mission öffnen" @@ -839,6 +856,12 @@ msgstr "Bäume" msgid "Tree trunks" msgstr "Baumstämme" +msgid "Use Midi music (original)" +msgstr "" + +msgid "Use Ogg music" +msgstr "" + msgid "Version" msgstr "Version" diff --git a/resources/po/en_US.po b/resources/po/en_US.po index 6c21e84..3fc0705 100644 --- a/resources/po/en_US.po +++ b/resources/po/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-09-15 18:34+0200\n" +"POT-Creation-Date: 2017-12-14 23:13+0100\n" "PO-Revision-Date: 2017-02-27 21:28+0100\n" "Last-Translator: \n" "Language-Team: \n" @@ -39,12 +39,18 @@ msgstr "" msgid " - libcurl (MIT/X derivate)" msgstr "" +msgid " - libogg and libvorbis (own license)" +msgstr "" + msgid " - libpng (own license)" msgstr "" msgid " - libpulse (LGPLv2.1)" msgstr "" +msgid " - libsndfile (LGPLv3)" +msgstr "" + msgid " - zlib (own license)" msgstr "" @@ -237,6 +243,11 @@ msgid "" "window size" msgstr "" +msgid "" +"Choose the\n" +"music format" +msgstr "" + msgid "Construct this game" msgstr "" @@ -465,6 +476,9 @@ msgstr "" msgid "Medical potion" msgstr "" +msgid "Midi" +msgstr "" + msgid "Mine" msgstr "" @@ -567,6 +581,9 @@ msgstr "" msgid "Occupied ground" msgstr "" +msgid "Ogg" +msgstr "" + msgid "Open another game" msgstr "" @@ -769,6 +786,12 @@ msgstr "" msgid "Tree trunks" msgstr "" +msgid "Use Midi music (original)" +msgstr "" + +msgid "Use Ogg music" +msgstr "" + msgid "Version" msgstr "" diff --git a/resources/po/fr.po b/resources/po/fr.po index 90b0d59..77eddb1 100644 --- a/resources/po/fr.po +++ b/resources/po/fr.po @@ -6,15 +6,15 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-09-15 18:34+0200\n" -"PO-Revision-Date: 2017-10-04 23:29+0200\n" +"POT-Creation-Date: 2017-12-14 23:13+0100\n" +"PO-Revision-Date: 2017-12-14 23:14+0100\n" "Last-Translator: Mathieu Schroeter \n" "Language-Team: French \n" "Language: fr\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Generator: Poedit 1.8.11\n" +"X-Generator: Poedit 2.0.5\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" msgid " - FFmpeg (LGPLv2.1)" @@ -38,12 +38,18 @@ msgstr " - libasound (LGPLv2.1)" msgid " - libcurl (MIT/X derivate)" msgstr " - libcurl (dérivée de MIT/X)" +msgid " - libogg and libvorbis (own license)" +msgstr " - libogg and libvorbis (propre licence)" + msgid " - libpng (own license)" msgstr " - libpng (propre licence)" msgid " - libpulse (LGPLv2.1)" msgstr " - libpulse (LGPLv2.1)" +msgid " - libsndfile (LGPLv3)" +msgstr " - libsndfile (LGPLv3)" + msgid " - zlib (own license)" msgstr " - zlib (propre licence)" @@ -281,6 +287,14 @@ msgstr "" "Modifie la taille\n" "de la fenêtre" +msgid "" +"Choose the\n" +"music format" +msgstr "" +"Choisi le\n" +"format de\n" +"la musique" + msgid "Construct this game" msgstr "Construire cette partie" @@ -515,6 +529,9 @@ msgstr "Robot-maître" msgid "Medical potion" msgstr "Potion" +msgid "Midi" +msgstr "Midi" + msgid "Mine" msgstr "Mine de fer" @@ -619,6 +636,9 @@ msgstr "Passe maintenant aux missions." msgid "Occupied ground" msgstr "Terrain occupé" +msgid "Ogg" +msgstr "Ogg" + msgid "Open another game" msgstr "Ouvrir une autre partie" @@ -829,6 +849,12 @@ msgstr "Arbres" msgid "Tree trunks" msgstr "Troncs" +msgid "Use Midi music (original)" +msgstr "Utilise la musique Midi (originale)" + +msgid "Use Ogg music" +msgstr "Utilise la musique Ogg" + msgid "Version" msgstr "Version" diff --git a/resources/po/it.po b/resources/po/it.po index 5886215..ed2cd8b 100644 --- a/resources/po/it.po +++ b/resources/po/it.po @@ -7,15 +7,15 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-09-29 10:21+0200\n" -"PO-Revision-Date: 2017-10-04 17:30+0200\n" +"POT-Creation-Date: 2017-12-14 23:13+0100\n" +"PO-Revision-Date: 2017-12-14 23:15+0100\n" "Last-Translator: \n" "Language-Team: \n" "Language: it\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Generator: Poedit 1.8.11\n" +"X-Generator: Poedit 2.0.5\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" msgid " - FFmpeg (LGPLv2.1)" @@ -39,12 +39,18 @@ msgstr " - libasound (LGPLv2.1)" msgid " - libcurl (MIT/X derivate)" msgstr " - libcurl (MIT/X derivata)" +msgid " - libogg and libvorbis (own license)" +msgstr " - libogg and libvorbis (licensa personale)" + msgid " - libpng (own license)" msgstr " - libpng (licensa personale)" msgid " - libpulse (LGPLv2.1)" msgstr " - libpulse (LGPLv2.1)" +msgid " - libsndfile (LGPLv3)" +msgstr " - libsndfile (LGPLv3)" + msgid " - zlib (own license)" msgstr " - zlib (licensa personale)" @@ -282,6 +288,11 @@ msgstr "" "dimensione\n" "della finestra" +msgid "" +"Choose the\n" +"music format" +msgstr "" + msgid "Construct this game" msgstr "Costruire questa partita" @@ -518,6 +529,9 @@ msgstr "Robot-capo" msgid "Medical potion" msgstr "Pozione" +msgid "Midi" +msgstr "Midi" + msgid "Mine" msgstr "Miniera" @@ -622,6 +636,9 @@ msgstr "Ora passa alle missioni." msgid "Occupied ground" msgstr "Terreno occupato" +msgid "Ogg" +msgstr "Ogg" + msgid "Open another game" msgstr "Apri un'altra partita" @@ -832,6 +849,12 @@ msgstr "Alberi" msgid "Tree trunks" msgstr "Tronchi" +msgid "Use Midi music (original)" +msgstr "" + +msgid "Use Ogg music" +msgstr "" + msgid "Version" msgstr "Versione" diff --git a/resources/po/pl.po b/resources/po/pl.po index d5d084e..fb0c4c8 100644 --- a/resources/po/pl.po +++ b/resources/po/pl.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-10-04 07:04+0200\n" -"PO-Revision-Date: 2017-09-12 20:10+0200\n" +"POT-Creation-Date: 2017-12-14 23:13+0100\n" +"PO-Revision-Date: 2017-12-14 23:15+0100\n" "Last-Translator: tomangelo \n" "Language-Team: TerranovaTeam \n" "Language: pl\n" @@ -17,6 +17,7 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 " "|| n%100>=20) ? 1 : 2);\n" +"X-Generator: Poedit 2.0.5\n" msgid " - FFmpeg (LGPLv2.1)" msgstr " - FFmpeg (LGPLv2.1)" @@ -39,12 +40,18 @@ msgstr " - libasound (LGPLv2.1)" msgid " - libcurl (MIT/X derivate)" msgstr " - libcurl (MIT/X derivate)" +msgid " - libogg and libvorbis (own license)" +msgstr " - libogg and libvorbis (własna licencja)" + msgid " - libpng (own license)" msgstr " - libpng (własna licencja)" msgid " - libpulse (LGPLv2.1)" msgstr " - libpulse (LGPLv2.1)" +msgid " - libsndfile (LGPLv3)" +msgstr " - libsndfile (LGPLv2.1)" + msgid " - zlib (own license)" msgstr " - zlib (własna licencja)" @@ -281,6 +288,11 @@ msgstr "" "Zmień rozmiar\n" "okna" +msgid "" +"Choose the\n" +"music format" +msgstr "" + msgid "Construct this game" msgstr "Edytuj poziom" @@ -515,6 +527,9 @@ msgstr "Mistrz robotów" msgid "Medical potion" msgstr "Lekarstwo" +msgid "Midi" +msgstr "Midi" + msgid "Mine" msgstr "Kopalnia" @@ -543,9 +558,8 @@ msgstr "Wybór muzyki" msgid "Music number 1" msgstr "Muzyka numer 1" -#, fuzzy msgid "Music number 10" -msgstr "Muzyka numer 1" +msgstr "Muzyka numer 10" msgid "Music number 2" msgstr "Muzyka numer 2" @@ -620,6 +634,9 @@ msgstr "Teraz spróbuj swoich sił w misjach" msgid "Occupied ground" msgstr "Teren zajęty" +msgid "Ogg" +msgstr "Ogg" + msgid "Open another game" msgstr "Otwórz poprzednią grę" @@ -830,6 +847,12 @@ msgstr "Drzewo" msgid "Tree trunks" msgstr "Pnie drzew" +msgid "Use Midi music (original)" +msgstr "" + +msgid "Use Ogg music" +msgstr "" + msgid "Version" msgstr "Wersja" diff --git a/resources/po/planetblupi.pot b/resources/po/planetblupi.pot index 5b3b444..0ba97cf 100644 --- a/resources/po/planetblupi.pot +++ b/resources/po/planetblupi.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-10-04 07:04+0200\n" +"POT-Creation-Date: 2017-12-14 23:13+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -551,6 +551,12 @@ msgstr "" msgid "Increase window size" msgstr "" +msgid "Use Ogg music" +msgstr "" + +msgid "Use Midi music (original)" +msgstr "" + msgid "Version" msgstr "" @@ -705,6 +711,17 @@ msgid "" "window size" msgstr "" +msgid "" +"Choose the\n" +"music format" +msgstr "" + +msgid "Midi" +msgstr "" + +msgid "Ogg" +msgstr "" + msgid "You have played Planet Blupi." msgstr "" @@ -729,12 +746,18 @@ msgstr "" msgid " - libcurl (MIT/X derivate)" msgstr "" +msgid " - libogg and libvorbis (own license)" +msgstr "" + msgid " - libpng (own license)" msgstr "" msgid " - libpulse (LGPLv2.1)" msgstr "" +msgid " - libsndfile (LGPLv3)" +msgstr "" + msgid " - SDL_kitchensink (MIT)" msgstr "" diff --git a/src/action.cxx b/src/action.cxx index be6b7ae..764b778 100644 --- a/src/action.cxx +++ b/src/action.cxx @@ -1764,7 +1764,7 @@ static const DescAction action_table[] = {0}, }, { - ACTION_D_PICKAXE, + ACTION_D_SAW, CHBLUPI, { {1, 290}, // e @@ -1839,7 +1839,7 @@ static const DescAction action_table[] = {0}, }, { - ACTION_D_SAW, + ACTION_D_PICKAXE, CHBLUPI, { {8, 290, 290, 304, 304, 290, 290, 292, 292}, // e diff --git a/src/blupi.cxx b/src/blupi.cxx index 08868eb..43d0557 100644 --- a/src/blupi.cxx +++ b/src/blupi.cxx @@ -18,9 +18,11 @@ * along with this program. If not, see http://gnu.org/licenses */ +#include #include #include #include +#include #include #include #include @@ -53,31 +55,24 @@ SDL_Window * g_window; SDL_Renderer * g_renderer; -CEvent * g_pEvent = nullptr; -CPixmap * g_pPixmap = nullptr; // pixmap principal -CSound * g_pSound = nullptr; // sound principal -CMovie * g_pMovie = nullptr; // movie principal -CDecor * g_pDecor = nullptr; -std::thread * g_updateThread = nullptr; +CEvent * g_pEvent = nullptr; +CPixmap * g_pPixmap = nullptr; // pixmap principal +CSound * g_pSound = nullptr; // sound principal +CMovie * g_pMovie = nullptr; // movie principal +CDecor * g_pDecor = nullptr; +std::thread * g_updateThread = nullptr; +std::atomic g_updateAbort (false); bool g_bFullScreen = false; // false si mode de test -Uint8 g_windowScale = 1; +Uint8 g_zoom = 1; Sint32 g_speedRate = 1; Sint32 g_timerInterval = 50; // inverval = 50ms int g_rendererType = 0; bool g_enableRecorder = false; std::string g_playRecord; bool g_restoreBugs = false; // restore original < v1.9 bugs - -enum Settings { - SETTING_FULLSCREEN = 1 << 0, - SETTING_SPEEDRATE = 1 << 1, - SETTING_TIMERINTERVAL = 1 << 2, - SETTING_RENDERER = 1 << 3, - SETTING_ZOOM = 1 << 4, -}; - -static int g_settingsOverload = 0; +bool g_restoreMidi = false; // restore music playback based on midi files +int g_settingsOverload = 0; bool g_bTermInit = false; // initialisation en cours Uint32 g_lastPhase = 999; @@ -152,17 +147,13 @@ ReadConfig () if ( !(g_settingsOverload & SETTING_FULLSCREEN) && j.find ("fullscreen") != j.end ()) - { g_bFullScreen = j["fullscreen"].get (); - if (g_bFullScreen != 0) - g_bFullScreen = 1; - } if (!(g_settingsOverload & SETTING_ZOOM) && j.find ("zoom") != j.end ()) { - g_windowScale = j["zoom"].get (); - if (g_windowScale != 1 && g_windowScale != 2) - g_windowScale = 1; + g_zoom = j["zoom"].get (); + if (g_zoom != 1 && g_zoom != 2) + g_zoom = 1; } if ( @@ -174,6 +165,20 @@ ReadConfig () g_rendererType = SDL_RENDERER_ACCELERATED; } + if ( + !(g_settingsOverload & SETTING_DRIVER) && j.find ("driver") != j.end () && + (!g_rendererType || g_rendererType == SDL_RENDERER_ACCELERATED)) + { + std::string input = j["driver"]; + if (std::regex_match ( + input, std::regex ("direct3d|direct3d11|opengl|opengles2|opengles"))) + SDL_SetHint (SDL_HINT_RENDER_DRIVER, input.c_str ()); + } + + if ( + !(g_settingsOverload & SETTING_MIDI) && j.find ("restoremidi") != j.end ()) + g_restoreMidi = j["restoremidi"].get (); + return true; } @@ -212,27 +217,22 @@ UpdateFrame (void) clip.bottom = POSDRAWY + DIMDRAWY; if (g_pEvent->IsShift ()) // screen shifting - { g_pEvent->DecorAutoShift (); - g_pDecor->Build (clip, posMouse); // build the environment - } - else - { - if (!g_pEvent->GetPause ()) - { - speed = g_pEvent->GetSpeed () * g_speedRate; - for (i = 0; i < speed; i++) - { - g_pDecor->BlupiStep (i == 0); // move all blupi - g_pDecor->MoveStep (i == 0); // move the environment - g_pEvent->DemoStep (); // forward the recording or demo playing - } - } - g_pEvent->DecorAutoShift (); - g_pDecor->Build (clip, posMouse); // build the environment - g_pDecor->NextPhase (1); // rebuild the map sometimes + if (!g_pEvent->GetPause ()) + { + speed = g_pEvent->GetSpeed () * g_speedRate; + for (i = 0; i < speed; i++) + { + g_pDecor->BlupiStep (i == 0); // move all blupi + g_pDecor->MoveStep (i == 0); // move the environment + g_pEvent->DemoStep (); // forward the recording or demo playing + } } + + g_pEvent->DecorAutoShift (); + g_pDecor->Build (clip, posMouse); // build the environment + g_pDecor->NextPhase (1); // rebuild the map sometimes } if (phase == EV_PHASE_BUILD) @@ -320,8 +320,6 @@ FinishObjects (void) static void HandleEvent (const SDL_Event & event) { - Point totalDim, iconDim; - if (!g_pause && g_pEvent != nullptr && g_pEvent->TreatEvent (event)) return; @@ -329,6 +327,9 @@ HandleEvent (const SDL_Event & event) { case SDL_WINDOWEVENT: { +#ifndef DEBUG + Point totalDim, iconDim; + switch (event.window.event) { case SDL_WINDOWEVENT_FOCUS_GAINED: @@ -362,6 +363,7 @@ HandleEvent (const SDL_Event & event) g_pMovie->Pause (); return; } +#endif /* !DEBUG */ break; } @@ -485,6 +487,13 @@ updateCallback (void * ptr, size_t size, size_t nmemb, void * data) return realsize; } + +static int +progressCallback ( + void * userData, double dltotal, double dlnow, double ultotal, double ulnow) +{ + return g_updateAbort ? 1 : 0; +} #endif /* USE_CURL */ static void @@ -504,11 +513,18 @@ CheckForUpdates () curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1); curl_easy_setopt (curl, CURLOPT_FAILONERROR, 1); curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1); + curl_easy_setopt (curl, CURLOPT_TIMEOUT, 20); + curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, 5); curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, updateCallback); curl_easy_setopt (curl, CURLOPT_URL, "http://blupi.org/update/planet.json"); curl_easy_setopt (curl, CURLOPT_WRITEDATA, (void *) &chunk); + + curl_easy_setopt (curl, CURLOPT_NOPROGRESS, 0); + curl_easy_setopt (curl, CURLOPT_PROGRESSDATA, nullptr); + curl_easy_setopt (curl, CURLOPT_PROGRESSFUNCTION, progressCallback); + chunk.status = curl_easy_perform (curl); if (chunk.status) @@ -556,6 +572,12 @@ parseArgs (int argc, char * argv[], bool & exit) {"-r", "--renderer"}, "set a renderer [auto;software;accelerated] (default: auto)", 1}, + {"driver", + {"-d", "--driver"}, + "set a driver [auto;direct3d;direct3d11;opengl;opengles2;opengles] " + "(default: auto, ignored with " + "software renderer)", + 1}, {"enablerecorder", {"-c", "--enable-recorder"}, "enable the recorder feature (F3/F4)", @@ -567,6 +589,10 @@ parseArgs (int argc, char * argv[], bool & exit) {"restorebugs", {"-b", "--restore-bugs"}, "restore funny original bugs of older versions < v1.9", + 0}, + {"restoremidi", + {"-m", "--restore-midi"}, + "restore playback based on MIDI music instead of OGG", 0}}}; argagg::parser_results args; @@ -577,6 +603,7 @@ parseArgs (int argc, char * argv[], bool & exit) catch (const std::exception & e) { std::cerr << e.what () << std::endl; + exit = true; return EXIT_FAILURE; } @@ -615,7 +642,9 @@ parseArgs (int argc, char * argv[], bool & exit) if (args["zoom"]) { - g_windowScale = args["zoom"]; + g_zoom = args["zoom"]; + if (g_zoom != 1 && g_zoom != 2) + g_zoom = 1; g_settingsOverload |= SETTING_ZOOM; } @@ -630,6 +659,17 @@ parseArgs (int argc, char * argv[], bool & exit) g_settingsOverload |= SETTING_RENDERER; } + if ( + args["driver"] && + (!g_rendererType || g_rendererType == SDL_RENDERER_ACCELERATED)) + { + std::string input = args["driver"].as (); + if (std::regex_match ( + input, std::regex ("direct3d|direct3d11|opengl|opengles2|opengles"))) + SDL_SetHint (SDL_HINT_RENDER_DRIVER, input.c_str ()); + g_settingsOverload |= SETTING_DRIVER; + } + if (args["enablerecorder"]) g_enableRecorder = true; @@ -639,6 +679,12 @@ parseArgs (int argc, char * argv[], bool & exit) if (args["restorebugs"]) g_restoreBugs = true; + if (args["restoremidi"]) + { + g_restoreMidi = true; + g_settingsOverload |= SETTING_MIDI; + } + return EXIT_SUCCESS; } @@ -663,9 +709,17 @@ DoInit (int argc, char * argv[], bool & exit) return EXIT_FAILURE; } +#ifdef _WIN32 + /* Fix laggy sounds on Windows by not using winmm driver. */ + SDL_setenv ("SDL_AUDIODRIVER", "directsound", true); +#endif /* _WIN32 */ + auto res = SDL_Init (SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER); if (res < 0) + { + SDL_Log ("Unable to initialize SDL: %s", SDL_GetError ()); return EXIT_FAILURE; + } // Create a window. g_window = SDL_CreateWindow ( @@ -902,10 +956,6 @@ DoInit (int argc, char * argv[], bool & exit) return EXIT_FAILURE; } - // Load all cursors - g_pPixmap->LoadCursors (g_windowScale); - g_pPixmap->ChangeSprite (SPRITE_WAIT); // met le sablier maison - // Create the sound manager. g_pSound = new CSound; if (g_pSound == nullptr) @@ -947,11 +997,19 @@ DoInit (int argc, char * argv[], bool & exit) return EXIT_FAILURE; } + const bool zoom = g_zoom; + g_pEvent->Create (g_pPixmap, g_pDecor, g_pSound, g_pMovie); + + // Load all cursors + g_pPixmap->LoadCursors (g_zoom); + g_pPixmap->ChangeSprite (SPRITE_WAIT); + g_updateThread = new std::thread (CheckForUpdates); - g_pEvent->SetFullScreen (g_bFullScreen); - if (!g_bFullScreen) - g_pEvent->SetWindowSize (g_windowScale); + if (g_bFullScreen) + g_pEvent->SetFullScreen (true); + if (!g_bFullScreen && zoom != g_zoom) + g_pEvent->SetWindowSize (g_zoom); g_pEvent->ChangePhase (EV_PHASE_INTRO1); g_bTermInit = true; @@ -993,15 +1051,20 @@ main (int argc, char * argv[]) break; } + SDL_RemoveTimer (updateTimer); + FinishObjects (); + + if (g_renderer) + SDL_DestroyRenderer (g_renderer); + if (g_window) SDL_DestroyWindow (g_window); - SDL_RemoveTimer (updateTimer); - FinishObjects (); SDL_Quit (); if (g_updateThread) { + g_updateAbort = true; g_updateThread->join (); delete (g_updateThread); } diff --git a/src/blupi.h b/src/blupi.h index 757ea15..1219fa9 100644 --- a/src/blupi.h +++ b/src/blupi.h @@ -31,11 +31,25 @@ class CEvent; extern SDL_Window * g_window; extern SDL_Renderer * g_renderer; extern bool g_bFullScreen; +extern Uint8 g_zoom; extern bool g_restoreBugs; +extern bool g_restoreMidi; extern bool g_enableRecorder; extern std::string g_playRecord; extern CEvent * g_pEvent; +enum Settings { + SETTING_FULLSCREEN = 1 << 0, + SETTING_SPEEDRATE = 1 << 1, + SETTING_TIMERINTERVAL = 1 << 2, + SETTING_RENDERER = 1 << 3, + SETTING_ZOOM = 1 << 4, + SETTING_DRIVER = 1 << 5, + SETTING_MIDI = 1 << 6, +}; + +extern int g_settingsOverload; + struct Point { Sint32 x; Sint32 y; @@ -51,11 +65,11 @@ struct Rect { typedef Uint32 ColorRef; #if defined(_WIN64) -typedef unsigned __int64 WPARAM; -typedef __int64 LPARAM; +typedef unsigned __int64 WParam; +typedef __int64 LParam; #else -typedef Uint32 WPARAM; -typedef Sint32 LPARAM; +typedef Uint32 WParam; +typedef Sint32 LParam; #endif #undef LOWORD diff --git a/src/button.cxx b/src/button.cxx index 7247a63..d31ca01 100644 --- a/src/button.cxx +++ b/src/button.cxx @@ -48,9 +48,7 @@ CButton::CButton () m_toolTips = nullptr; } -CButton::~CButton () -{ -} +CButton::~CButton () {} // Crée un nouveau bouton. diff --git a/src/button.h b/src/button.h index 21fbc1d..a666f35 100644 --- a/src/button.h +++ b/src/button.h @@ -71,7 +71,7 @@ protected: bool m_bEnable; // true si bouton actif bool m_bHide; // true si bouton caché Uint32 m_message; // message envoyé si bouton actionné - Point m_pos; // coin sup/gauche + Point m_pos; // up/left corner Point m_dim; // dimensions Sint32 m_state; // 0=relâché, 1=pressé, +2=survollé Sint32 m_mouseState; // 0=relâché, 1=pressé, +2=survollé diff --git a/src/decblupi.cxx b/src/decblupi.cxx index 06c4c21..d5261b8 100644 --- a/src/decblupi.cxx +++ b/src/decblupi.cxx @@ -728,13 +728,19 @@ CDecor::BlupiInitAction (Sint32 rank, Sint32 action, Sint32 direct) if (m_blupi[rank].action == ACTION_STOP) m_blupi[rank].action = ACTION_D_STOP; - if (m_blupi[rank].action == ACTION_PICKAXE) + if ( + m_blupi[rank].action == ACTION_PICKAXE || + m_blupi[rank].action == ACTION_BUILDSEC || + m_blupi[rank].action == ACTION_BUILDBREF) m_blupi[rank].action = ACTION_D_PICKAXE; if (m_blupi[rank].action == ACTION_BUILD) m_blupi[rank].action = ACTION_D_BUILD; - if (m_blupi[rank].action == ACTION_SAW) + if ( + m_blupi[rank].action == ACTION_SAW || + m_blupi[rank].action == ACTION_BUILDSOURD || + m_blupi[rank].action == ACTION_PIOCHESOURD) m_blupi[rank].action = ACTION_D_SAW; if (m_blupi[rank].action == ACTION_TCHAO) @@ -2008,7 +2014,7 @@ CDecor::GoalNextOp (Sint32 rank, Sint16 * pTable) m_blupi[rank].cel = cel; BlupiPushFog (rank); if (m_blupi[rank].bHili) - SetCoin (cel, true); + SetCorner (cel, true); return true; } @@ -4617,7 +4623,7 @@ CDecor::IsTerminated () m_pSound->PlayImage (SOUND_GOAL, pos); m_winLastHachBlupi = m_nbStatHachBlupi; - if (m_nbStatHachBlupi < m_nbStatHach * 4) + if (m_nbStatHachBlupi < m_nbStatHach * m_term.nbMinBlupi) return 0; // continue; } diff --git a/src/decio.cxx b/src/decio.cxx index 7990a28..1ad8929 100644 --- a/src/decio.cxx +++ b/src/decio.cxx @@ -136,7 +136,7 @@ CDecor::Write (Sint32 rank, bool bUser, Sint32 world, Sint32 time, Sint32 total) pBuffer->majRev = 1; pBuffer->minRev = 5; - pBuffer->celCoin = m_celCoin; + pBuffer->celCoin = m_celCorner; pBuffer->world = world; pBuffer->time = time; pBuffer->totalTime = total; @@ -255,7 +255,7 @@ CDecor::Read ( goto error; } - SetCoin (pBuffer->celCoin); + SetCorner (pBuffer->celCoin); if (bUser) { world = pBuffer->world; @@ -511,7 +511,7 @@ CDecor::Flush () m_celHome.x = 90; m_celHome.y = 98; - SetCoin (m_celHome); + SetCorner (m_celHome); InitAfterBuild (); LoadImages (); } diff --git a/src/decmap.cxx b/src/decmap.cxx index 253e144..9b68ca2 100644 --- a/src/decmap.cxx +++ b/src/decmap.cxx @@ -114,8 +114,8 @@ CDecor::ConvCelToMap (Point cel) { Point pos; - pos.x = (cel.x - m_celCoin.x) - (cel.y - m_celCoin.y); - pos.y = ((cel.x - m_celCoin.x) + (cel.y - m_celCoin.y)) / 2; + pos.x = (cel.x - m_celCorner.x) - (cel.y - m_celCorner.y); + pos.y = ((cel.x - m_celCorner.x) + (cel.y - m_celCorner.y)) / 2; pos.x += (DIMMAPX - MAPCADREX) / 2; pos.y += (DIMMAPY - MAPCADREY) / 2; @@ -136,8 +136,8 @@ CDecor::ConvMapToCel (Point pos) cel.x = pos.y + pos.x / 2; cel.y = pos.y - pos.x / 2; - cel.x += m_celCoin.x; - cel.y += m_celCoin.y; + cel.x += m_celCorner.x; + cel.y += m_celCorner.y; return cel; } @@ -158,7 +158,7 @@ CDecor::MapMove (Point pos) cel = ConvMapToCel (pos); cel.x = cel.x - 10; cel.y = cel.y; - SetCoin (cel); + SetCorner (cel); NextPhase (0); // faudra refaire la carte tout de suite return true; } @@ -406,19 +406,31 @@ static char color_object[] = // clang-format on static char color_deffog[4] = { - MAP_FOG, MAP_FOG, MAP_FOG, MAP_FOG, + MAP_FOG, + MAP_FOG, + MAP_FOG, + MAP_FOG, }; static char color_deftree[4] = { - MAP_TREE, MAP_TREE, MAP_TREE, MAP_TREE, + MAP_TREE, + MAP_TREE, + MAP_TREE, + MAP_TREE, }; static char color_deffloor[4] = { - MAP_HERB1, MAP_HERB1, MAP_HERB1, MAP_HERB1, + MAP_HERB1, + MAP_HERB1, + MAP_HERB1, + MAP_HERB1, }; static char color_fire[4] = { - MAP_FIRE, MAP_FIRE, MAP_FIRE, MAP_FIRE, + MAP_FIRE, + MAP_FIRE, + MAP_FIRE, + MAP_FIRE, }; // Met le contenu d'une cellule dans le bitmap de la carte @@ -560,7 +572,7 @@ CDecor::GenerateMap () } // Dessine le cadre. - cel = m_celCoin; + cel = m_celCorner; pos = ConvCelToMap (cel); for (i = pos.x; i < pos.x + MAPCADREX; i++) diff --git a/src/decmove.cxx b/src/decmove.cxx index 228f7fd..5decaad 100644 --- a/src/decmove.cxx +++ b/src/decmove.cxx @@ -1011,6 +1011,51 @@ CDecor::MoveAddIcons (Point cel, Sint32 rankIcons, bool bContinue) return false; } +/** + * \brief Test if something can burn at a specified cell. + * + * \param[in] cel - Position. + * \returns true if possible. + */ +bool +CDecor::CanBurn (Point cel) +{ + Sint32 channel, icon; + bool canBurn = false; + + cel.x = (cel.x / 2) * 2; + cel.y = (cel.y / 2) * 2; + + const auto cell = m_decor[cel.x / 2][cel.y / 2]; + + channel = cell.objectChannel; + icon = cell.objectIcon; + + canBurn = channel == CHOBJECT && ((icon >= 6 && icon <= 11) // trees ? + || (icon >= 65 && icon <= 71) // palissade ? + || icon == 61 // cabane ? + || icon == 36 // planches ? + || icon == 60 // tomatoes ? + || icon == 63 // eggs ? + || icon == 113 // house ? + || icon == 121 // mine de fer ? + || icon == 122 // mine de fer ? + ); + if (canBurn) + return true; + + // If there is an other object, then no fire. + if (channel >= 0) + return false; + + channel = cell.floorChannel; + icon = cell.floorIcon; + + canBurn = channel == CHFLOOR && (icon == 20 || // herbe foncée ? + (icon >= 59 && icon <= 64)); + return canBurn; +} + /** * \brief Start the fire on a cell. * @@ -1020,45 +1065,11 @@ CDecor::MoveAddIcons (Point cel, Sint32 rankIcons, bool bContinue) bool CDecor::MoveStartFire (Point cel) { - Sint32 channel, icon; - - cel.x = (cel.x / 2) * 2; - cel.y = (cel.y / 2) * 2; - - channel = m_decor[cel.x / 2][cel.y / 2].objectChannel; - icon = m_decor[cel.x / 2][cel.y / 2].objectIcon; - - if ( - channel == CHOBJECT && ((icon >= 6 && icon <= 11) // trees ? - || (icon >= 65 && icon <= 71) // palissade ? - || icon == 61 // cabane ? - || icon == 36 // planches ? - || icon == 60 // tomatoes ? - || icon == 63 // eggs ? - || icon == 113 // house ? - || icon == 121 // mine de fer ? - || icon == 122 // mine de fer ? - )) + if (this->CanBurn (cel)) { - if (!MoveCreate (cel, -1, false, CHOBJECT, -1, -1, -1, 9999, 1, 0, true)) - return false; + cel.x = (cel.x / 2) * 2; + cel.y = (cel.y / 2) * 2; - MoveAddIcons (cel, 1, true); // small fire - m_decor[cel.x / 2][cel.y / 2].fire = 2; - return true; - } - - // If there is an other object, then no fire. - if (channel >= 0) - return false; - - channel = m_decor[cel.x / 2][cel.y / 2].floorChannel; - icon = m_decor[cel.x / 2][cel.y / 2].floorIcon; - - if ( - channel == CHFLOOR && (icon == 20 || // herbe foncée ? - (icon >= 59 && icon <= 64))) // bridge ? - { if (!MoveCreate (cel, -1, false, CHOBJECT, -1, -1, -1, 9999, 1, 0, true)) return false; diff --git a/src/decor.cxx b/src/decor.cxx index 2770f4d..ca2af57 100644 --- a/src/decor.cxx +++ b/src/decor.cxx @@ -119,8 +119,8 @@ CDecor::CDecor () m_pSound = nullptr; m_pUndoDecor = nullptr; - m_celCoin.x = 90; - m_celCoin.y = 98; + m_celCorner.x = 90; + m_celCorner.y = 98; m_celHili.x = -1; m_celOutline1.x = -1; @@ -382,6 +382,11 @@ CDecor::PutFloor (Point cel, Sint32 channel, Sint32 icon) m_decor[cel.x / 2][cel.y / 2].floorChannel = channel; m_decor[cel.x / 2][cel.y / 2].floorIcon = icon; + if ( + !g_restoreBugs && m_decor[cel.x / 2][cel.y / 2].fire && + !this->CanBurn (cel)) + m_decor[cel.x / 2][cel.y / 2].fire = 0; + m_bGroundRedraw = true; //? SubDrapeau(cel); // on pourra de nouveau planter un drapeau @@ -403,6 +408,11 @@ CDecor::PutObject (Point cel, Sint32 channel, Sint32 icon) m_decor[cel.x / 2][cel.y / 2].objectChannel = channel; m_decor[cel.x / 2][cel.y / 2].objectIcon = icon; + if ( + !g_restoreBugs && m_decor[cel.x / 2][cel.y / 2].fire && + !this->CanBurn (cel)) + m_decor[cel.x / 2][cel.y / 2].fire = 0; + SubDrapeau (cel); // on pourra de nouveau planter un drapeau return true; @@ -449,6 +459,29 @@ CDecor::SetFire (Point cel, bool bFire) return true; } +void +CDecor::FixShifting (Sint32 & nbx, Sint32 & nby, Point & iCel, Point & iPos) +{ + if (m_shiftOffset.x < 0) // décalage à droite ? + nbx += 2; + if (m_shiftOffset.y < 0) // décalage en bas ? + nby += 3; + if (m_shiftOffset.x > 0) // décalage à gauche ? + { + nbx += 2; + iCel.x--; + iCel.y++; + iPos = ConvCelToPos (iCel); + } + if (m_shiftOffset.y > 0) // décalage en haut ? + { + nby += 2; + iCel.x--; + iCel.y--; + iPos = ConvCelToPos (iCel); + } +} + // Modifie l'offset pour le shift. void @@ -465,8 +498,8 @@ CDecor::ConvCelToPos (Point cel) { Point pos; - pos.x = ((cel.x - m_celCoin.x) - (cel.y - m_celCoin.y)) * (DIMCELX / 2); - pos.y = ((cel.x - m_celCoin.x) + (cel.y - m_celCoin.y)) * (DIMCELY / 2); + pos.x = ((cel.x - m_celCorner.x) - (cel.y - m_celCorner.y)) * (DIMCELX / 2); + pos.y = ((cel.x - m_celCorner.x) + (cel.y - m_celCorner.y)) * (DIMCELY / 2); pos.x += POSDRAWX + m_shiftOffset.x; pos.y += POSDRAWY + m_shiftOffset.y; @@ -500,8 +533,8 @@ CDecor::ConvPosToCel (Point pos, bool bMap) cel.y -= (DIMCELX * DIMCELY); cel.y /= (DIMCELX * DIMCELY); - cel.x += m_celCoin.x; - cel.y += m_celCoin.y; + cel.x += m_celCorner.x; + cel.y += m_celCorner.y; return cel; } @@ -516,19 +549,19 @@ CDecor::ConvPosToCel2 (Point pos) pos.x -= POSDRAWX + DIMCELX / 2; pos.y -= POSDRAWY; - if (m_celCoin.x % 2 != 0 && m_celCoin.y % 2 == 0) + if (m_celCorner.x % 2 != 0 && m_celCorner.y % 2 == 0) { pos.x += DIMCELX / 2; pos.y += DIMCELY / 2; } - if (m_celCoin.x % 2 == 0 && m_celCoin.y % 2 != 0) + if (m_celCorner.x % 2 == 0 && m_celCorner.y % 2 != 0) { pos.x -= DIMCELX / 2; pos.y += DIMCELY / 2; } - if (m_celCoin.x % 2 != 0 && m_celCoin.y % 2 != 0) + if (m_celCorner.x % 2 != 0 && m_celCorner.y % 2 != 0) pos.y += DIMCELY; cel.x = @@ -539,8 +572,8 @@ CDecor::ConvPosToCel2 (Point pos) cel.y -= (DIMCELX * 2 * DIMCELY * 2); cel.y /= (DIMCELX * 2 * DIMCELY * 2); - cel.x = (cel.x * 2 + m_celCoin.x) / 2 * 2; - cel.y = (cel.y * 2 + m_celCoin.y) / 2 * 2; + cel.x = (cel.x * 2 + m_celCorner.x) / 2 * 2; + cel.y = (cel.y * 2 + m_celCorner.y) / 2 * 2; return cel; } @@ -972,6 +1005,8 @@ CDecor::BuildGround (Rect clip) nby += 2; } + this->FixShifting (nbx, nby, iCel, iPos); + // Construit les sols. mCel = iCel; mPos = iPos; @@ -1112,6 +1147,8 @@ CDecor::Build (Rect clip, Point posMouse) nby += 2; } + this->FixShifting (nbx, nby, iCel, iPos); + // Construit les sols. mCel = iCel; mPos = iPos; @@ -1229,6 +1266,8 @@ CDecor::Build (Rect clip, Point posMouse) // Construit les objets et les blupi. BuildPutBlupi (); // m_rankBlupi[x][y] <- rangs des blupi + this->FixShifting (nbx, nby, iCel, iPos); + mCel = iCel; mPos = iPos; for (j = 0; j < nby + 3; j++) @@ -1435,24 +1474,7 @@ CDecor::Build (Rect clip, Point posMouse) if (!m_bFog) goto term; - if (m_shiftOffset.x < 0) // décalage à droite ? - nbx += 2; - if (m_shiftOffset.y < 0) // décalage en bas ? - nby += 2; - if (m_shiftOffset.x > 0) // décalage à gauche ? - { - nbx += 2; - iCel.x--; - iCel.y++; - iPos = ConvCelToPos (iCel); - } - if (m_shiftOffset.y > 0) // décalage en haut ? - { - nby += 2; - iCel.x--; - iCel.y--; - iPos = ConvCelToPos (iCel); - } + this->FixShifting (nbx, nby, iCel, iPos); mCel = iCel; mPos = iPos; @@ -2985,8 +3007,8 @@ CDecor::GetResHili (Point posMouse) { Sint32 icon; - // Les valeurs `corner == true` correspondent aux objets placés - // au coin inf/droit de la cellule. + // The `corner == true` values are corresponding to the objects + // positionned at the bottom/right corner of the cell. struct object_t { bool corner; const char * text; @@ -3261,33 +3283,33 @@ CDecor::HideTooltips (bool bHide) // Modifie l'origine supérieure/gauche du décor. void -CDecor::SetCoin (Point coin, bool bCenter) +CDecor::SetCorner (Point corner, bool bCenter) { if (bCenter) { - coin.x -= 10; - coin.y -= 2; + corner.x -= 10; + corner.y -= 2; } - if (coin.x < -8) - coin.x = -8; - if (coin.x > MAXCELX - 12) - coin.x = MAXCELX - 12; - if (coin.y < -2) - coin.y = -2; - if (coin.y > MAXCELY - 4) - coin.y = MAXCELY - 4; + if (corner.x < -8) + corner.x = -8; + if (corner.x > MAXCELX - 12) + corner.x = MAXCELX - 12; + if (corner.y < -2) + corner.y = -2; + if (corner.y > MAXCELY - 4) + corner.y = MAXCELY - 4; - m_celCoin = coin; + m_celCorner = corner; m_bGroundRedraw = true; // faudra redessiner les sols m_celHili.x = -1; m_textLastPos.x = -1; // tooltips plus lavable ! } Point -CDecor::GetCoin () +CDecor::GetCorner () { - return m_celCoin; + return m_celCorner; } Point @@ -3312,7 +3334,7 @@ CDecor::MemoPos (Sint32 rank, bool bRecord) if (bRecord) { m_pSound->PlayImage (SOUND_CLOSE, pos); - m_memoPos[rank] = m_celCoin; + m_memoPos[rank] = m_celCorner; } else { @@ -3321,7 +3343,7 @@ CDecor::MemoPos (Sint32 rank, bool bRecord) else { m_pSound->PlayImage (SOUND_GOAL, pos); - SetCoin (m_memoPos[rank], false); + SetCorner (m_memoPos[rank], false); } } } diff --git a/src/decor.h b/src/decor.h index e0fc5b5..70ea98b 100644 --- a/src/decor.h +++ b/src/decor.h @@ -322,6 +322,7 @@ public: Term * GetTerminated (); // DecMove.cpp + bool CanBurn (Point cel); void MoveFlush (); Sint32 MoveMaxFire (); void MoveFixInit (); @@ -381,6 +382,7 @@ public: bool IsCheminFree (Sint32 rank, Point dest, Sint32 button); // Decor.cpp + void FixShifting (Sint32 & nbx, Sint32 & nby, Point & iCel, Point & iPos); void SetShiftOffset (Point offset); Point ConvCelToPos (Point cel); Point ConvPosToCel (Point pos, bool bMap = false); @@ -406,8 +408,8 @@ public: bool GetObject (Point cel, Sint32 & channel, Sint32 & icon); bool SetFire (Point cel, bool bFire); - void SetCoin (Point coin, bool bCenter = false); - Point GetCoin (); + void SetCorner (Point corner, bool bCenter = false); + Point GetCorner (); Point GetHome (); void MemoPos (Sint32 rank, bool bRecord); @@ -467,8 +469,8 @@ protected: Sint16 m_rankBlupi[MAXCELX][MAXCELY]; Blupi m_blupi[MAXBLUPI]; Move m_move[MAXMOVE]; - Point m_celCoin; // cellule sup/gauche - Point m_celHome; // pour touche Home + Point m_celCorner; // cellule sup/gauche + Point m_celHome; // pour touche Home Point m_celHili; Point m_celOutline1; Point m_celOutline2; diff --git a/src/decstat.cxx b/src/decstat.cxx index 057d916..f4e8385 100644 --- a/src/decstat.cxx +++ b/src/decstat.cxx @@ -448,7 +448,9 @@ CDecor::StatisticUpdate () { if (m_blupi[rank].bExist) { - if (m_blupi[rank].perso == 0) // blupi ? + if ( + m_blupi[rank].perso == 0 && m_blupi[rank].action != ACTION_TCHAO && + m_blupi[rank].action != ACTION_BURN) // blupi ? { if (m_blupi[rank].bMalade) table_statistic[STATBLUPIm].nb++; @@ -475,7 +477,7 @@ CDecor::StatisticUpdate () // Hide enemies from the stat when hidden by the fog bool hide = false; - if (this->GetSkill () >= 1) + if (this->GetSkill () >= 1 && this->m_bFog) { auto fogCel = m_blupi[rank].cel; fogCel.x = (fogCel.x / 4) * 4; @@ -974,7 +976,7 @@ CDecor::StatisticDown (Point pos) return false; select: - SetCoin (cel, true); + SetCorner (cel, true); NextPhase (0); // faudra refaire la carte tout de suite return true; } diff --git a/src/def.h b/src/def.h index aeaaecf..24cdb16 100644 --- a/src/def.h +++ b/src/def.h @@ -389,6 +389,13 @@ enum MouseSprites { SPRITE_END = 14, }; +enum ShiftDirection { + DIRECTION_UP = (1 << 0), + DIRECTION_DOWN = (1 << 1), + DIRECTION_LEFT = (1 << 2), + DIRECTION_RIGHT = (1 << 3), +}; + // clang-format off #define EV_OFFSET 0x0400 diff --git a/src/event.cxx b/src/event.cxx index 676ed9c..cf49ae0 100644 --- a/src/event.cxx +++ b/src/event.cxx @@ -1,7 +1,7 @@ /* * This file is part of the planetblupi source code * Copyright (C) 1997, Daniel Roux & EPSITEC SA - * Copyright (C) 2017, Mathieu Schroeter + * Copyright (C) 2017-2018, Mathieu Schroeter * http://epsitec.ch; http://www.blupi.org; http://github.com/blupi-games * * This program is free software: you can redistribute it and/or modify @@ -70,8 +70,12 @@ typedef struct { Sint16 skill; // v1.1 Sint16 language; + // v1.2 + Sint16 musicMidi; + Sint16 fullScreen; + Sint16 zoom; - Sint16 reserve2[92]; + Sint16 reserve2[89]; } DescInfo; // Toutes les premières lettres doivent @@ -1301,7 +1305,7 @@ static Phase table[] = { EV_BUTTON1, 0, {1, 40}, - 170 + 42 * 1, 30 + 42 * 0, + 11, 101, { translate ("No music") }, }, { @@ -1559,6 +1563,18 @@ static Phase table[] = 284 + 40, 330, { translate ("Increase window size") }, }, + { + EV_BUTTON7, + 0, {1, 50}, + 399, 330, + { translate ("Use Ogg music") }, + }, + { + EV_BUTTON8, + 0, {1, 51}, + 399 + 40, 330, + { translate ("Use Midi music (original)") }, + }, { EV_PHASE_INIT, 0, {1, 40}, @@ -1585,8 +1601,6 @@ CEvent::CEvent () { Sint32 i; - m_bFullScreen = false; - m_WindowScale = 1; m_exercice = 0; m_mission = 0; m_private = 0; @@ -1672,6 +1686,8 @@ CEvent::CEvent () m_Lang = m_Languages.begin (); m_updateBlinking = 0; + + this->shiftDirection = 0; } // Destructeur. @@ -1701,25 +1717,22 @@ CEvent::GetMousePos () void CEvent::SetFullScreen (bool bFullScreen) { - if (bFullScreen == m_bFullScreen) - return; - int x, y; SDL_GetMouseState (&x, &y); - x /= m_WindowScale; - y /= m_WindowScale; + x /= g_zoom; + y /= g_zoom; - m_WindowScale = 1; + g_zoom = 1; SDL_SetWindowSize (g_window, LXIMAGE, LYIMAGE); - m_bFullScreen = bFullScreen; + g_bFullScreen = bFullScreen; SDL_SetWindowFullscreen (g_window, bFullScreen ? SDL_WINDOW_FULLSCREEN : 0); SDL_SetWindowBordered (g_window, bFullScreen ? SDL_FALSE : SDL_TRUE); SDL_SetWindowGrab (g_window, bFullScreen ? SDL_TRUE : SDL_FALSE); SDL_SetWindowPosition ( g_window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); - m_pPixmap->LoadCursors (m_WindowScale); + m_pPixmap->LoadCursors (g_zoom); m_pPixmap->ReloadTargetTextures (); /* Force this update before otherwise the coordinates retrieved with @@ -1743,16 +1756,13 @@ CEvent::SetFullScreen (bool bFullScreen) void CEvent::SetWindowSize (Uint8 newScale) { - if (newScale == m_WindowScale) - return; - - auto scale = m_WindowScale; - m_WindowScale = newScale; + auto scale = g_zoom; + g_zoom = newScale; switch (newScale) { case 1: case 2: - SetWindowSize (scale, m_WindowScale); + SetWindowSize (scale, g_zoom); break; default: @@ -1792,12 +1802,6 @@ CEvent::SetWindowSize (Uint8 prevScale, Uint8 newScale) CEvent::PushUserEvent (EV_WARPMOUSE, coord); } -Uint8 -CEvent::GetWindowScale () -{ - return m_WindowScale; -} - // Crée le gestionnaire d'événements. void @@ -2134,16 +2138,23 @@ CEvent::DrawButtons () SetEnable (EV_BUTTON10, bEnable); } + /* Check if both music formats are available */ + auto ogg = this->IsBaseMusicAvailable (1, "ogg"); + auto mid = this->IsBaseMusicAvailable (1, "mid"); + if (m_phase == EV_PHASE_SETTINGS) { SetEnable (EV_BUTTON1, m_Lang != m_Languages.begin ()); SetEnable (EV_BUTTON2, m_Lang != m_Languages.end () - 1); - SetEnable (EV_BUTTON3, !m_bFullScreen); - SetEnable (EV_BUTTON4, m_bFullScreen); + SetEnable (EV_BUTTON3, !g_bFullScreen); + SetEnable (EV_BUTTON4, g_bFullScreen); - SetEnable (EV_BUTTON5, !m_bFullScreen && m_WindowScale > 1); - SetEnable (EV_BUTTON6, !m_bFullScreen && m_WindowScale < 2); + SetEnable (EV_BUTTON5, !g_bFullScreen && g_zoom > 1); + SetEnable (EV_BUTTON6, !g_bFullScreen && g_zoom < 2); + + SetEnable (EV_BUTTON7, g_restoreMidi && mid && ogg); + SetEnable (EV_BUTTON8, !g_restoreMidi && mid && ogg); } assert (m_index >= 0); @@ -2505,7 +2516,7 @@ CEvent::DrawButtons () // Affiche le texte lorsque c'est raté. if (m_phase == EV_PHASE_LOST) { - static char * list[] = { + const char * list[] = { gettext ("You have failed, try again..."), gettext ("No, wrong way ..."), gettext ("Bang, failed again !"), @@ -2521,7 +2532,7 @@ CEvent::DrawButtons () // Affiche le texte lorsque c'est réussi. if (m_phase == EV_PHASE_WIN) { - static char * list[] = { + const char * list[] = { gettext ("Well done !"), gettext ("Yes, great ..."), gettext ("Very good."), gettext ("Excellent..."), gettext ("Mission over..."), @@ -2532,7 +2543,7 @@ CEvent::DrawButtons () DrawText (m_pPixmap, pos, list[GetWorld () % 5]); } - // Affiche le texte lorsque c'est fini. + // Show the ending text when the game is finished. if (m_phase == EV_PHASE_LASTWIN) { char * text; @@ -2549,7 +2560,7 @@ CEvent::DrawButtons () DrawText (m_pPixmap, pos, text); } - // Dessine les réglages. + // Draw the game settings. if (m_phase == EV_PHASE_SETUP || m_phase == EV_PHASE_SETUPp) { DrawTextCenter (gettext ("Global game\nspeed"), 54 + 40 + LXOFFSET, 80); @@ -2604,6 +2615,8 @@ CEvent::DrawButtons () gettext ("Select the\nwindow mode"), 169 + 40 + LXOFFSET, 80); DrawTextCenter ( gettext ("Change the\nwindow size"), 284 + 40 + LXOFFSET, 80); + DrawTextCenter ( + gettext ("Choose the\nmusic format"), 399 + 40 + LXOFFSET, 80); const auto locale = GetLocale (); std::string lang; @@ -2626,20 +2639,26 @@ CEvent::DrawButtons () DrawText (m_pPixmap, pos, lang.c_str ()); const char * text = - m_bFullScreen ? gettext ("Fullscreen") : gettext ("Windowed"); + g_bFullScreen ? gettext ("Fullscreen") : gettext ("Windowed"); lg = GetTextWidth (text); pos.x = (169 + 40) - lg / 2 + LXOFFSET; pos.y = 330 - 20; DrawText (m_pPixmap, pos, text); - if (!m_bFullScreen) + if (!g_bFullScreen) { - snprintf (res, sizeof (res), "%dx", m_WindowScale); + snprintf (res, sizeof (res), "%dx", g_zoom); lg = GetTextWidth (res); pos.x = (284 + 40) - lg / 2 + LXOFFSET; pos.y = 330 - 20; DrawText (m_pPixmap, pos, res); } + + text = (g_restoreMidi && mid) || !ogg ? gettext ("Midi") : gettext ("Ogg"); + lg = GetTextWidth (text); + pos.x = (399 + 40) - lg / 2; + pos.y = 330 - 20; + DrawText (m_pPixmap, pos, text); } // Show the ending text @@ -2668,8 +2687,10 @@ CEvent::DrawButtons () gettext (" - GNU/gettext and GNU/libiconv (GPLv3)"), gettext (" - libasound (LGPLv2.1)"), gettext (" - libcurl (MIT/X derivate)"), + gettext (" - libogg and libvorbis (own license)"), gettext (" - libpng (own license)"), gettext (" - libpulse (LGPLv2.1)"), + gettext (" - libsndfile (LGPLv3)"), gettext (" - SDL_kitchensink (MIT)"), gettext (" - SDL2, SDL2_image and SDL2_mixer (zlib license)"), gettext (" - zlib (own license)"), @@ -2697,7 +2718,7 @@ CEvent::DrawButtons () DrawText (m_pPixmap, pos, text); } - // Affiche le texte lorsqu'il faut insérer le CD-Rom. + // Show the text when the CD-Rom must be inserted (deprecated). if (m_phase == EV_PHASE_INSERT) DrawTextCenter ( gettext ("Insert CD-Rom Planet Blupi and wait a few seconds..."), @@ -2706,15 +2727,19 @@ CEvent::DrawButtons () if (m_phase == EV_PHASE_BUILD) SetEnable (EV_PHASE_UNDO, m_pDecor->IsUndo ()); - // Dessine les tool tips (info bulle). + // Draw the tooltips. if (m_textToolTips[0] != 0) DrawText (m_pPixmap, m_posToolTips, m_textToolTips); return true; } -// Retourne le lutin à utiliser à une position donnée. - +/** + * \brief Return the mouse sprite to use for a position. + * + * \param[in] pos - The position. + * \return the sprite. + */ MouseSprites CEvent::MousePosToSprite (Point pos) { @@ -2730,7 +2755,7 @@ CEvent::MousePosToSprite (Point pos) pos.y <= POSMAPY + DIMMAPY) sprite = SPRITE_MAP; - if (m_bFullScreen && !m_bDemoRec && !m_bDemoPlay && m_scrollSpeed != 0) + if (g_bFullScreen && !m_bDemoRec && !m_bDemoPlay && m_scrollSpeed != 0) { if (pos.x <= 5 && pos.x >= -2) bLeft = true; @@ -2785,8 +2810,11 @@ CEvent::MousePosToSprite (Point pos) return sprite; } -// Gère le lutin de la souris. - +/** + * \brief Main mouse sprite handling. + * + * \param[in] pos - The position. + */ void CEvent::MouseSprite (Point pos) { @@ -2794,8 +2822,11 @@ CEvent::MouseSprite (Point pos) m_pPixmap->ChangeSprite (m_mouseSprite); } -// Met ou enlève le sablier de la souris. - +/** + * \brief Set or remove the waiting mouse sprite. + * + * \param[in] bWait - If waiting. + */ void CEvent::WaitMouse (bool bWait) { @@ -2809,8 +2840,11 @@ CEvent::WaitMouse (bool bWait) m_pPixmap->ChangeSprite (m_mouseSprite); } -// Cache ou montre la souris. - +/** + * \brief Hide or show the mouse. + * + * \param[in] bHide - If hide. + */ void CEvent::HideMouse (bool bHide) { @@ -2831,8 +2865,13 @@ CEvent::HideMouse (bool bHide) m_pPixmap->ChangeSprite (m_mouseSprite); } -// Traite les événements pour tous les boutons. - +/** + * \brief Handle events for buttons. + * + * \param[in] event - The SDL event. + * \param[in] pos - The position. + * \return true if the event is handled. + */ bool CEvent::EventButtons (const SDL_Event & event, Point pos) { @@ -2922,7 +2961,7 @@ CEvent::EventButtons (const SDL_Event & event, Point pos) (event.button.button == SDL_BUTTON_LEFT || event.button.button == SDL_BUTTON_RIGHT)) { - // Montre ou cache les infos tout en haut. + // Show or hide the informations at the top. m_pDecor->SetInfoMode (!m_pDecor->GetInfoMode ()); } } @@ -2945,7 +2984,7 @@ CEvent::EventButtons (const SDL_Event & event, Point pos) (event.button.button == SDL_BUTTON_LEFT || event.button.button == SDL_BUTTON_RIGHT)) { - // Inverse le mode aide dans les infos. + // Reverse the help mode in the informations. m_bInfoHelp = !m_bInfoHelp; if (m_bInfoHelp) @@ -2963,7 +3002,7 @@ CEvent::EventButtons (const SDL_Event & event, Point pos) (event.button.button == SDL_BUTTON_LEFT || event.button.button == SDL_BUTTON_RIGHT)) { - m_pDecor->HideTooltips (true); // plus de tooltips pour décor + m_pDecor->HideTooltips (true); // Remove tooltips for the decor. } if ( event.type == SDL_MOUSEBUTTONUP && @@ -2992,8 +3031,12 @@ CEvent::EventButtons (const SDL_Event & event, Point pos) return false; } -// Indique si la souris est sur un bouton. - +/** + * \brief Notify if the mouse is on a button. + * + * \param[in] pos - The mouse position. + * \return true if the mouse is on a button. + */ bool CEvent::MouseOnButton (Point pos) { @@ -3013,8 +3056,12 @@ CEvent::MouseOnButton (Point pos) return false; } -// Retourne l'index dans table pour une phase donnée. - +/** + * \brief Return the table index for a specific phase. + * + * \param[in] phase - The phase. + * \return the index in `table`. + */ Sint32 CEvent::SearchPhase (Uint32 phase) { @@ -3030,8 +3077,11 @@ CEvent::SearchPhase (Uint32 phase) return -1; } -// Donne le numéro du monde. - +/** + * \brief Return the world number. + * + * \return the number. + */ Sint32 CEvent::GetWorld () { @@ -3043,8 +3093,13 @@ CEvent::GetWorld () return m_mission; } -// Donne le numéro physique du monde. - +/** + * \brief Return the physical world number. + * + * This number should be the same as the filename. + * + * \return the number. + */ Sint32 CEvent::GetPhysicalWorld () { @@ -3067,8 +3122,11 @@ CEvent::GetImageWorld () return 1; } -// Indique si l'aide est disponible. - +/** + * Notify if the help is available. + * + * \return true if available. + */ bool CEvent::IsHelpHide () { @@ -3078,14 +3136,52 @@ CEvent::IsHelpHide () bHide = false; if (m_bSchool || m_bPrivate) { - bHide = true; // pas d'aide pour les exercices + bHide = true; // No help for the exercises. } return bHide; } -// Change de phase. +bool +CEvent::IsBaseMusicAvailable (Sint32 music, const std::string & format) +{ + std::string absolute; + auto filename = + string_format ("music/music%.3d.%s", music - 1, format.c_str ()); + return FileExists (filename, absolute, LOCATION_BASE); +} +std::string +CEvent::GetMusicLocation (Sint32 music) +{ + static const std::string exts[] = {"ogg", "mid"}; + static const Location locs[] = {LOCATION_USER, LOCATION_BASE}; + std::string absolute; + + // Look for music in the user directory, then in the game directory. + for (size_t i = 0; i < countof (locs); ++i) + { + auto filename = string_format ( + "music/music%.3d.%s", music - 1, exts[g_restoreMidi ? 1 : 0].c_str ()); + if (!FileExists (filename, absolute, locs[i])) + filename = string_format ( + "music/music%.3d.%s", music - 1, exts[g_restoreMidi ? 0 : 1].c_str ()); + + if (FileExists (filename, absolute, locs[i])) + break; + + absolute = ""; + } + + return absolute; +} + +/** + * \brief Change the phase. + * + * \param[in] phase - The new phase. + * \return true if the phase has changed. + */ bool CEvent::ChangePhase (Uint32 phase) { @@ -3154,11 +3250,11 @@ CEvent::ChangePhase (Uint32 phase) m_pSound->StopAllSounds (false, &except); } - m_phase = phase; // change de phase + m_phase = phase; // change phase m_index = index; filename = table[m_index].backName; - if (filename.find ("%.3d") != std::string::npos) // "%.3d" dans le nom ? + if (filename.find ("%.3d") != std::string::npos) filename = string_format (table[m_index].backName, GetImageWorld ()); totalDim.x = LXLOGIC; totalDim.y = LYLOGIC; @@ -3168,10 +3264,10 @@ CEvent::ChangePhase (Uint32 phase) CHBACK, filename, totalDim, iconDim, table[m_index].mode, table[m_index].chBackWide)) { - WaitMouse (false); // enlève le sablier + WaitMouse (false); m_tryInsertCount = 40; m_tryPhase = m_phase; - return ChangePhase (EV_PHASE_INSERT); // insérez le CD-Rom ... + return ChangePhase (EV_PHASE_INSERT); // insert the CD-Rom ... } if ( @@ -3196,13 +3292,13 @@ CEvent::ChangePhase (Uint32 phase) { if ( !m_pDecor->Read ( - GetPhysicalWorld (), false, world, time, total) && // lit le monde + GetPhysicalWorld (), false, world, time, total) && // read the world !m_bAccessBuild && !m_bPrivate) { m_tryInsertCount = 40; m_tryPhase = m_phase; - return ChangePhase (EV_PHASE_INSERT); // insérez le CD-Rom ... + return ChangePhase (EV_PHASE_INSERT); // insert the CD-Rom ... } m_pDecor->SetTime (0); m_pDecor->SetTotalTime (0); @@ -3238,7 +3334,7 @@ CEvent::ChangePhase (Uint32 phase) if (m_phase == EV_PHASE_TESTCD) { - if (m_pDecor->Read (0, false, world, time, total)) // lit un monde + if (m_pDecor->Read (0, false, world, time, total)) // read the world { return ChangePhase (EV_PHASE_INIT); // ok } @@ -3246,25 +3342,25 @@ CEvent::ChangePhase (Uint32 phase) { m_tryInsertCount = 40; m_tryPhase = m_phase; - return ChangePhase (EV_PHASE_INSERT); // insérez le CD-Rom ... + return ChangePhase (EV_PHASE_INSERT); // insert the CD-Rom ... } } - m_jauges[0].SetHide (true); // cache les jauges + m_jauges[0].SetHide (true); m_jauges[1].SetHide (true); - CreateButtons (phase); // crée les boutons selon la phase + CreateButtons (phase); // create the buttons accordingly to the phase m_bMenu = false; m_pDecor->HideTooltips (false); m_menu.Delete (); - m_pDecor->BlupiSetArrow (0, false); // enlève toutes les flèches - m_pDecor->ResetHili (); // enlève les mises en évidence + m_pDecor->BlupiSetArrow (0, false); // remove all arrows + m_pDecor->ResetHili (); // remove all highlights if (m_phase == EV_PHASE_PLAY) { m_pDecor->LoadImages (); m_pDecor->SetBuild (false); m_pDecor->EnableFog (true); - m_pDecor->NextPhase (0); // refait la carte tout de suite + m_pDecor->NextPhase (0); // rebuild the map immediatly m_pDecor->StatisticInit (); m_pDecor->TerminatedInit (); } @@ -3273,16 +3369,16 @@ CEvent::ChangePhase (Uint32 phase) { m_bBuildModify = true; SetState (EV_DECOR1, 1); - SetMenu (EV_DECOR1, 0); // herbe - SetMenu (EV_DECOR2, 2); // arbre - SetMenu (EV_DECOR3, 1); // maison - SetMenu (EV_DECOR4, 2); // blupi fort - SetMenu (EV_DECOR5, 1); // feu + SetMenu (EV_DECOR1, 0); // grass + SetMenu (EV_DECOR2, 2); // tree + SetMenu (EV_DECOR3, 1); // house + SetMenu (EV_DECOR4, 2); // strong blupi + SetMenu (EV_DECOR5, 1); // fire m_pDecor->LoadImages (); m_pDecor->SetBuild (true); m_pDecor->EnableFog (false); m_pDecor->BlupiDeselect (); - m_pDecor->NextPhase (0); // refait la carte tout de suite + m_pDecor->NextPhase (0); // rebuild the map immediatly } if (m_phase == EV_PHASE_INFO) @@ -3384,16 +3480,17 @@ CEvent::ChangePhase (Uint32 phase) { if (m_pSound->IsPlayingMusic ()) { - m_pSound->AdaptVolumeMusic (); // adapte le volume + m_pSound->AdaptVolumeMusic (); } else { music = m_pDecor->GetMusic (); if (music > 0) { - filename = string_format ("music/music%.3d.mid", music - 1); + auto absolute = this->GetMusicLocation (music); + m_pSound->StopMusic (); - m_pSound->PlayMusic (filename); + m_pSound->PlayMusic (absolute); } } } @@ -3434,20 +3531,24 @@ CEvent::ChangePhase (Uint32 phase) m_phaseAfterMovie = EV_PHASE_LASTWIN; } - WaitMouse (false); // enlève le sablier + WaitMouse (false); return true; } -// Retourne la phase en cours. - +/** + * \brief Return the current phase. + * + * \return the phase number. + */ Uint32 CEvent::GetPhase () { return m_phase; } -// Essaye de lire le CD-Rom. - +/** + * \brief Try to read the CD-Rom. + */ void CEvent::TryInsert () { @@ -3457,19 +3558,22 @@ CEvent::TryInsert () m_tryInsertCount--; } -// Fait démarrer un film si nécessaire. - +/** + * \brief Start a movie if necessary. + * + * \return true if the movie has started. + */ bool CEvent::MovieToStart () { bool movie = false; - if (m_movieToStart[0] != 0) // y a-t-il un film à démarrer ? + if (m_movieToStart[0] != 0) // is movie available? { if (StartMovie (m_movieToStart)) { movie = true; - m_phase = m_phaseAfterMovie; // prochaine phase normale + m_phase = m_phaseAfterMovie; // the next normal phase } else ChangePhase (m_phaseAfterMovie); @@ -3480,110 +3584,190 @@ CEvent::MovieToStart () return movie; } -// Décale le décor. - +/** + * \brief Shift the decor. + * + * \param[in] dx - Delta x. + * \param[in] dy - Delta y. + */ void CEvent::DecorShift (Sint32 dx, Sint32 dy) { - Point coin; + Point corner; if (m_phase != EV_PHASE_PLAY && m_phase != EV_PHASE_BUILD) return; - coin = m_pDecor->GetCoin (); + corner = m_pDecor->GetCorner (); - coin.x += dx; - coin.y += dy; + corner.x += dx; + corner.y += dy; - m_pDecor->SetCoin (coin); - //? m_pDecor->NextPhase(0); // faudra refaire la carte tout de suite + m_pDecor->SetCorner (corner); } -// Décale le décor lorsque la souris touche un bord. - +/** + * \brief Shift the decor when the mouse is on the sides. + */ void CEvent::DecorAutoShift () { - Sint32 max; + Sint32 max, maxLimit = 4, xMoveFactor = 1, yMoveFactor = 1, vectorFactor = 1; Point offset; + Uint32 dir = 0; + + bool byKeyboard = !!this->shiftDirection; + + if (byKeyboard) + { + dir = this->shiftDirection; + xMoveFactor = 2; + yMoveFactor = 3; + vectorFactor = 2; + if (m_scrollSpeed == 1) + maxLimit = 5; // 4..2..1 + } + else + { + if (m_bDemoRec || m_bDemoPlay) + return; + + switch (m_mouseSprite) + { + case SPRITE_ARROWL: + dir = DIRECTION_LEFT; + break; + + case SPRITE_ARROWR: + dir = DIRECTION_RIGHT; + break; + + case SPRITE_ARROWU: + dir = DIRECTION_UP; + break; + + case SPRITE_ARROWD: + dir = DIRECTION_DOWN; + break; + + case SPRITE_ARROWUL: + dir = DIRECTION_UP | DIRECTION_LEFT; + break; + + case SPRITE_ARROWUR: + dir = DIRECTION_UP | DIRECTION_RIGHT; + break; + + case SPRITE_ARROWDL: + dir = DIRECTION_DOWN | DIRECTION_LEFT; + break; + + case SPRITE_ARROWDR: + dir = DIRECTION_DOWN | DIRECTION_RIGHT; + break; + + default: + break; + } + } m_bShift = false; - if (!m_bFullScreen || m_bDemoRec || m_bDemoPlay || m_scrollSpeed == 0) + if (!byKeyboard && (!g_bFullScreen || m_scrollSpeed == 0)) return; - max = 4 - m_scrollSpeed; // max <- 3..1 + max = maxLimit - m_scrollSpeed; // max <- 3..1 if (m_phase == EV_PHASE_PLAY || m_phase == EV_PHASE_BUILD) { - if (m_shiftPhase == 0) // début du shift ? + if (m_shiftPhase == 0) // start shift ? { - switch (m_mouseSprite) + switch (dir) { - default: - m_shiftOffset.x = 0; - m_shiftOffset.y = 0; - m_shiftVector.x = 0; - m_shiftVector.y = 0; - break; - - case SPRITE_ARROWL: + case DIRECTION_LEFT: m_shiftOffset.x = +2; m_shiftOffset.y = 0; m_shiftVector.x = -1; m_shiftVector.y = +1; break; - case SPRITE_ARROWR: + case DIRECTION_RIGHT: m_shiftOffset.x = -2; m_shiftOffset.y = 0; m_shiftVector.x = +1; m_shiftVector.y = -1; break; - case SPRITE_ARROWU: + case DIRECTION_UP: m_shiftOffset.x = 0; m_shiftOffset.y = +2; m_shiftVector.x = -1; m_shiftVector.y = -1; + if (vectorFactor > 1) + ++vectorFactor; break; - case SPRITE_ARROWD: + case DIRECTION_DOWN: m_shiftOffset.x = 0; m_shiftOffset.y = -2; m_shiftVector.x = +1; m_shiftVector.y = +1; + if (vectorFactor > 1) + ++vectorFactor; break; - case SPRITE_ARROWUL: - m_shiftOffset.x = +1; - m_shiftOffset.y = +1; - m_shiftVector.x = -1; - m_shiftVector.y = 0; - break; - - case SPRITE_ARROWUR: - m_shiftOffset.x = -1; - m_shiftOffset.y = +1; - m_shiftVector.x = 0; - m_shiftVector.y = -1; - break; - - case SPRITE_ARROWDL: - m_shiftOffset.x = +1; - m_shiftOffset.y = -1; - m_shiftVector.x = 0; - m_shiftVector.y = +1; - break; - - case SPRITE_ARROWDR: - m_shiftOffset.x = -1; - m_shiftOffset.y = -1; - m_shiftVector.x = +1; - m_shiftVector.y = 0; + default: + if (dir == (DIRECTION_UP | DIRECTION_LEFT)) + { + m_shiftOffset.x = +1; + m_shiftOffset.y = +1; + m_shiftVector.x = -1; + m_shiftVector.y = 0; + if (vectorFactor > 1) + ++vectorFactor; + } + else if (dir == (DIRECTION_UP | DIRECTION_RIGHT)) + { + m_shiftOffset.x = -1; + m_shiftOffset.y = +1; + m_shiftVector.x = 0; + m_shiftVector.y = -1; + if (vectorFactor > 1) + ++vectorFactor; + } + else if (dir == (DIRECTION_DOWN | DIRECTION_LEFT)) + { + m_shiftOffset.x = +1; + m_shiftOffset.y = -1; + m_shiftVector.x = 0; + m_shiftVector.y = +1; + if (vectorFactor > 1) + ++vectorFactor; + } + else if (dir == (DIRECTION_DOWN | DIRECTION_RIGHT)) + { + m_shiftOffset.x = -1; + m_shiftOffset.y = -1; + m_shiftVector.x = +1; + m_shiftVector.y = 0; + if (vectorFactor > 1) + ++vectorFactor; + } + else + { + m_shiftOffset.x = 0; + m_shiftOffset.y = 0; + m_shiftVector.x = 0; + m_shiftVector.y = 0; + } break; } + m_shiftOffset.x *= xMoveFactor; + m_shiftOffset.y *= yMoveFactor; + m_shiftVector.x *= vectorFactor; + m_shiftVector.y *= vectorFactor; + if (m_shiftVector.x != 0 || m_shiftVector.y != 0) m_shiftPhase = max; } @@ -3597,10 +3781,11 @@ CEvent::DecorAutoShift () offset.y = m_shiftOffset.y * (max - m_shiftPhase) * (DIMCELY / 2 / max); m_pDecor->SetShiftOffset (offset); - if (m_shiftPhase == 0) // dernière phase ? + if (m_shiftPhase == 0) // last phase ? { - offset.x = 0; - offset.y = 0; + this->shiftDirection = 0; + offset.x = 0; + offset.y = 0; m_pDecor->SetShiftOffset (offset); DecorShift (m_shiftVector.x, m_shiftVector.y); } @@ -3608,8 +3793,11 @@ CEvent::DecorAutoShift () } } -// Indique su un shift est en cours. - +/** + * \brief Notify if a shift is doing. + * + * \return true of the shift is doing. + */ bool CEvent::IsShift () { @@ -3668,7 +3856,7 @@ CEvent::PlayDown (Point pos, const SDL_Event & event) if (bMap) { - m_pDecor->SetCoin (cel, true); + m_pDecor->SetCorner (cel, true); m_pDecor->NextPhase (0); // faudra refaire la carte tout de suite return true; } @@ -3726,7 +3914,9 @@ bool CEvent::PlayUp (Point pos) { static Sounds table_sound_boing[] = { - SOUND_BOING1, SOUND_BOING2, SOUND_BOING3, + SOUND_BOING1, + SOUND_BOING2, + SOUND_BOING3, }; m_pDecor->StatisticUp (pos); @@ -4020,20 +4210,26 @@ CEvent::ChangeButtons (Sint32 message) break; case EV_BUTTON5: { - auto scale = m_WindowScale; - if (m_WindowScale > 1) - --m_WindowScale; - SetWindowSize (scale, m_WindowScale); + auto scale = g_zoom; + if (g_zoom > 1) + --g_zoom; + SetWindowSize (scale, g_zoom); break; } case EV_BUTTON6: { - auto scale = m_WindowScale; - if (m_WindowScale < 2) - ++m_WindowScale; - SetWindowSize (scale, m_WindowScale); + auto scale = g_zoom; + if (g_zoom < 2) + ++g_zoom; + SetWindowSize (scale, g_zoom); break; } + case EV_BUTTON7: + g_restoreMidi = false; + break; + case EV_BUTTON8: + g_restoreMidi = true; + break; } } } @@ -4148,7 +4344,7 @@ static Sint32 tableHome[] = { // Modifie le décor lorsque le bouton de la souris est pressé. bool -CEvent::BuildDown (Point pos, Uint16 mod, bool bMix) +CEvent::BuildDown (Point pos, Uint16 mod, const SDL_Event * event, bool bMix) { Point cel; Sint32 menu, channel, icon; @@ -4161,12 +4357,14 @@ CEvent::BuildDown (Point pos, Uint16 mod, bool bMix) pos.y > POSDRAWY + DIMDRAWY) return false; + bool isRightClick = event ? event->button.button == SDL_BUTTON_RIGHT : false; + if (bMix) { m_pDecor->UndoCopy (); // copie le décor pour undo év. } - if (GetState (EV_DECOR1) == 1) // pose d'un sol + if (GetState (EV_DECOR1) == 1 && !isRightClick) // pose d'un sol { cel = m_pDecor->ConvPosToCel2 (pos); menu = GetMenu (EV_DECOR1); @@ -4200,10 +4398,10 @@ CEvent::BuildDown (Point pos, Uint16 mod, bool bMix) } } - if (GetState (EV_DECOR2) == 1) // pose d'un objet + if (GetState (EV_DECOR2) == 1 || isRightClick) // pose d'un objet { cel = m_pDecor->ConvPosToCel2 (pos); - menu = GetMenu (EV_DECOR2); + menu = isRightClick ? 0 : GetMenu (EV_DECOR2); if (!m_pDecor->GetObject (cel, channel, icon)) return false; @@ -4231,10 +4429,10 @@ CEvent::BuildDown (Point pos, Uint16 mod, bool bMix) } } - if (GetState (EV_DECOR3) == 1) // pose d'un batiment + if (GetState (EV_DECOR3) == 1 || isRightClick) // pose d'un batiment { cel = m_pDecor->ConvPosToCel2 (pos); - menu = GetMenu (EV_DECOR3); + menu = isRightClick ? 0 : GetMenu (EV_DECOR3); if (!m_pDecor->GetObject (cel, channel, icon)) return false; @@ -4262,10 +4460,10 @@ CEvent::BuildDown (Point pos, Uint16 mod, bool bMix) } } - if (GetState (EV_DECOR4) == 1) // pose d'un blupi + if (GetState (EV_DECOR4) == 1 || isRightClick) // pose d'un blupi { cel = m_pDecor->ConvPosToCel (pos); - menu = GetMenu (EV_DECOR4); + menu = isRightClick ? 0 : GetMenu (EV_DECOR4); if (menu == 0) // supprime ? m_pDecor->BlupiDelete (cel); @@ -4289,14 +4487,15 @@ CEvent::BuildDown (Point pos, Uint16 mod, bool bMix) m_pDecor->BlupiCreate (cel, ACTION_STOP, DIRECT_S, 4, MAXENERGY); } - if (GetState (EV_DECOR5) == 1) // pose d'une cata + if (GetState (EV_DECOR5) == 1 || isRightClick) // pose d'une cata { cel = m_pDecor->ConvPosToCel2 (pos); - menu = GetMenu (EV_DECOR5); + menu = isRightClick ? 0 : GetMenu (EV_DECOR5); if (menu == 0) // supprime ? m_pDecor->SetFire (cel, false); - if (menu == 1) // ajoute ? + + if (menu == 1 && (g_restoreBugs || m_pDecor->CanBurn (cel))) // ajoute ? m_pDecor->SetFire (cel, true); } @@ -4311,8 +4510,7 @@ bool CEvent::BuildMove (Point pos, Uint16 mod, const SDL_Event & event) { if (event.motion.state & SDL_BUTTON (SDL_BUTTON_LEFT)) // bouton souris pressé - // ? - BuildDown (pos, mod, false); + BuildDown (pos, mod, nullptr, false); if (GetState (EV_DECOR4) == 1) // pose d'un blupi m_pDecor->CelHili (pos, 1); @@ -4332,7 +4530,8 @@ CEvent::StartMovie (const std::string & pFilename) if (!m_bMovie) return false; - if (!m_pMovie->IsExist (pFilename)) + std::string absolute; + if (!FileExists (pFilename, absolute)) return false; HideMouse (true); @@ -4588,7 +4787,7 @@ CEvent::WriteInfo () goto error; info.majRev = 1; - info.minRev = 1; + info.minRev = 2; info.prive = m_private; info.exercice = m_exercice; info.mission = m_mission; @@ -4607,6 +4806,9 @@ CEvent::WriteInfo () info.language = static_cast ( this->GetLanguage () != this->GetStartLanguage () ? this->GetLanguage () : Language::undef); + info.musicMidi = g_restoreMidi; + info.fullScreen = g_bFullScreen; + info.zoom = g_zoom; nb = fwrite (&info, sizeof (info), 1, file); if (nb < 1) @@ -4665,6 +4867,16 @@ CEvent::ReadInfo () this->SetLanguage (static_cast (info.language)); } + if (((info.majRev == 1 && info.minRev >= 2) || info.majRev >= 2)) + { + if (!(g_settingsOverload & SETTING_MIDI)) + g_restoreMidi = !!info.musicMidi; + if (!(g_settingsOverload & SETTING_FULLSCREEN)) + g_bFullScreen = !!info.fullScreen; + if (!(g_settingsOverload & SETTING_ZOOM)) + g_zoom = info.zoom; + } + fclose (file); return true; @@ -4869,10 +5081,10 @@ CEvent::DemoPlayStop () void CEvent::WinToSDLEvent ( - Uint32 msg, WPARAM wParam, LPARAM lParam, SDL_Event & event) + Uint32 msg, WParam wParam, LParam lParam, SDL_Event & event) { -#define GET_X_LPARAM(lp) ((Sint32) (Sint16) LOWORD (lp)) -#define GET_Y_LPARAM(lp) ((Sint32) (Sint16) HIWORD (lp)) +#define GET_X_LParam(lp) ((Sint32) (Sint16) LOWORD (lp)) +#define GET_Y_LParam(lp) ((Sint32) (Sint16) HIWORD (lp)) // clang-format off static const std::unordered_map keycodes = { @@ -4937,8 +5149,8 @@ CEvent::WinToSDLEvent ( msg == EV_LBUTTONDOWN ? SDL_MOUSEBUTTONDOWN : SDL_MOUSEBUTTONUP; event.button.button = SDL_BUTTON_LEFT; // TODO: wParam CTRL or SHIFT - event.button.x = GET_X_LPARAM (lParam); - event.button.y = GET_Y_LPARAM (lParam); + event.button.x = GET_X_LParam (lParam); + event.button.y = GET_Y_LParam (lParam); break; case EV_RBUTTONUP: @@ -4947,15 +5159,15 @@ CEvent::WinToSDLEvent ( msg == EV_RBUTTONDOWN ? SDL_MOUSEBUTTONDOWN : SDL_MOUSEBUTTONUP; event.button.button = SDL_BUTTON_RIGHT; // TODO: wParam CTRL or SHIFT - event.button.x = GET_X_LPARAM (lParam); - event.button.y = GET_Y_LPARAM (lParam); + event.button.x = GET_X_LParam (lParam); + event.button.y = GET_Y_LParam (lParam); break; case EV_MOUSEMOVE: event.type = SDL_MOUSEMOTION; // TODO: wParam CTRL or SHIFT - event.motion.x = GET_X_LPARAM (lParam); - event.motion.y = GET_Y_LPARAM (lParam); + event.motion.x = GET_X_LParam (lParam); + event.motion.y = GET_Y_LParam (lParam); break; } } @@ -4972,8 +5184,8 @@ CEvent::DemoStep () { Uint32 time = 0; Uint32 message = 0; - WPARAM wParam = 0; - LPARAM lParam = 0; + WParam wParam = 0; + LParam lParam = 0; if (m_phase == EV_PHASE_INIT) { @@ -5040,8 +5252,7 @@ CEvent::DemoStep () pos.y = event.motion.y; } - SDL_WarpMouseInWindow ( - g_window, pos.x * m_WindowScale, pos.y * m_WindowScale); + SDL_WarpMouseInWindow (g_window, pos.x * g_zoom, pos.y * g_zoom); } if (m_pDemoBuffer) @@ -5366,28 +5577,36 @@ CEvent::TreatEventBase (const SDL_Event & event) case SDLK_UP: case SDLK_DOWN: { + if (m_phase != EV_PHASE_PLAY && m_phase != EV_PHASE_BUILD) + return true; + + bool left, right, up, down; const Uint8 * state = SDL_GetKeyboardState (nullptr); - if ( - event.key.keysym.sym == SDLK_LEFT || - (!m_bDemoRec && state[SDL_SCANCODE_LEFT])) - DecorShift (-2, 2); - if ( - event.key.keysym.sym == SDLK_RIGHT || - (!m_bDemoRec && state[SDL_SCANCODE_RIGHT])) - DecorShift (2, -2); - if ( - event.key.keysym.sym == SDLK_UP || - (!m_bDemoRec && state[SDL_SCANCODE_UP])) - DecorShift (-3, -3); - if ( - event.key.keysym.sym == SDLK_DOWN || - (!m_bDemoRec && state[SDL_SCANCODE_DOWN])) - DecorShift (3, 3); + + this->shiftDirection = 0; + + left = event.key.keysym.sym == SDLK_LEFT || + (!m_bDemoRec && state[SDL_SCANCODE_LEFT]); + right = event.key.keysym.sym == SDLK_RIGHT || + (!m_bDemoRec && state[SDL_SCANCODE_RIGHT]); + up = event.key.keysym.sym == SDLK_UP || + (!m_bDemoRec && state[SDL_SCANCODE_UP]); + down = event.key.keysym.sym == SDLK_DOWN || + (!m_bDemoRec && state[SDL_SCANCODE_DOWN]); + + if (left) + this->shiftDirection |= DIRECTION_LEFT; + if (right) + this->shiftDirection |= DIRECTION_RIGHT; + if (up) + this->shiftDirection |= DIRECTION_UP; + if (down) + this->shiftDirection |= DIRECTION_DOWN; return true; } case SDLK_HOME: pos = m_pDecor->GetHome (); - m_pDecor->SetCoin (pos); + m_pDecor->SetCorner (pos); return true; case SDLK_SPACE: if (m_bRunMovie) @@ -5510,7 +5729,7 @@ CEvent::TreatEventBase (const SDL_Event & event) return true; if (m_phase == EV_PHASE_BUILD) { - if (BuildDown (pos, m_keymod)) + if (BuildDown (pos, m_keymod, &event)) return true; } if (m_phase == EV_PHASE_PLAY) diff --git a/src/event.h b/src/event.h index fb4e1fb..d327df5 100644 --- a/src/event.h +++ b/src/event.h @@ -1,7 +1,7 @@ /* * This file is part of the planetblupi source code * Copyright (C) 1997, Daniel Roux & EPSITEC SA - * Copyright (C) 2017, Mathieu Schroeter + * Copyright (C) 2017-2018, Mathieu Schroeter * http://epsitec.ch; http://www.blupi.org; http://github.com/blupi-games * * This program is free software: you can redistribute it and/or modify @@ -63,8 +63,8 @@ typedef struct { typedef struct { Sint32 time; Uint32 message; - Uint32 wParam; // WPARAM - Uint32 lParam; // LPARAM + Uint32 wParam; // WParam + Uint32 lParam; // LParam } DemoEvent; struct DemoSDLEvent { @@ -96,16 +96,18 @@ public: Point GetMousePos (); void - Create (CPixmap * pPixmap, CDecor * pDecor, CSound * pSound, CMovie * pMovie); - void SetFullScreen (bool bFullScreen); - Sint32 GetWorld (); - Sint32 GetPhysicalWorld (); - Sint32 GetImageWorld (); - bool IsHelpHide (); - bool ChangePhase (Uint32 phase); - bool MovieToStart (); - Uint32 GetPhase (); - void TryInsert (); + Create (CPixmap * pPixmap, CDecor * pDecor, CSound * pSound, CMovie * pMovie); + void SetFullScreen (bool bFullScreen); + Sint32 GetWorld (); + Sint32 GetPhysicalWorld (); + Sint32 GetImageWorld (); + bool IsHelpHide (); + bool IsBaseMusicAvailable (Sint32 music, const std::string & format); + std::string GetMusicLocation (Sint32 music); + bool ChangePhase (Uint32 phase); + bool MovieToStart (); + Uint32 GetPhase (); + void TryInsert (); Sint32 GetButtonIndex (Sint32 button); Sint32 GetState (Sint32 button); @@ -144,9 +146,8 @@ public: void IntroStep (); - Uint8 GetWindowScale (); - void SetWindowSize (Uint8 newScale); - void SetUpdateVersion (const std::string & version); + void SetWindowSize (Uint8 newScale); + void SetUpdateVersion (const std::string & version); static void PushUserEvent (Sint32 code, void * data = nullptr); @@ -171,7 +172,8 @@ protected: void BuildFloor (Point cel, Sint32 insIcon); void BuildWater (Point cel, Sint32 insIcon); - bool BuildDown (Point pos, Uint16 mod, bool bMix = true); + bool + BuildDown (Point pos, Uint16 mod, const SDL_Event * event, bool bMix = true); bool BuildMove (Point pos, Uint16 mod, const SDL_Event & event); void PrivateLibelle (); @@ -184,7 +186,7 @@ protected: bool DemoPlayStart (const std::string * demoFile = nullptr); void DemoPlayStop (); static void - WinToSDLEvent (Uint32 msg, WPARAM wParam, LPARAM lParam, SDL_Event & event); + WinToSDLEvent (Uint32 msg, WParam wParam, LParam lParam, SDL_Event & event); void DemoRecEvent (const SDL_Event & event); protected: @@ -201,8 +203,6 @@ protected: bool m_bSchool; bool m_bPrivate; bool m_bAccessBuild; - bool m_bFullScreen; - Uint8 m_WindowScale; CPixmap * m_pPixmap; CDecor * m_pDecor; CSound * m_pSound; @@ -270,6 +270,7 @@ protected: Sint32 m_introTime; Sint32 m_updateBlinking; std::string m_updateVersion; + Uint32 shiftDirection; }; ///////////////////////////////////////////////////////////////////////////// diff --git a/src/fifo.cxx b/src/fifo.cxx index 2aed801..b012964 100644 --- a/src/fifo.cxx +++ b/src/fifo.cxx @@ -39,7 +39,8 @@ CPileTriee::~CPileTriee () free (m_data); } -Sint32 CPileTriee::get () +Sint32 +CPileTriee::get () { if (m_out == m_max) return -1; @@ -50,7 +51,8 @@ Sint32 CPileTriee::get () return val; } -void CPileTriee::put (Sint32 pos, Sint32 dist) +void +CPileTriee::put (Sint32 pos, Sint32 dist) { Sint32 i = m_out; Sint32 p, d, m; diff --git a/src/menu.cxx b/src/menu.cxx index 7b966c8..19a242a 100644 --- a/src/menu.cxx +++ b/src/menu.cxx @@ -148,9 +148,7 @@ CMenu::CMenu () // Destructeur. -CMenu::~CMenu () -{ -} +CMenu::~CMenu () {} // Crée un nouveau bouton. @@ -187,9 +185,7 @@ CMenu::Create ( pos = m_pos; pos.x += DIMBUTTONX / 2; pos.y += DIMBUTTONY / 2; - SDL_WarpMouseInWindow ( - g_window, pos.x * m_pEvent->GetWindowScale (), - pos.y * m_pEvent->GetWindowScale ()); + SDL_WarpMouseInWindow (g_window, pos.x * g_zoom, pos.y * g_zoom); } m_selRank = Detect (pos); diff --git a/src/menu.h b/src/menu.h index d3f728c..ccd7c0f 100644 --- a/src/menu.h +++ b/src/menu.h @@ -60,7 +60,7 @@ protected: CDecor * m_pDecor; CSound * m_pSound; CEvent * m_pEvent; - Point m_pos; // coin sup/gauche + Point m_pos; // up/left corner Point m_dim; // dimensions Sint32 m_nbButtons; Point m_nbCel; diff --git a/src/misc.cxx b/src/misc.cxx index 8af0a8e..3884ec7 100644 --- a/src/misc.cxx +++ b/src/misc.cxx @@ -48,7 +48,7 @@ OutputDebug (const char * pMessage) // Conversion de la position de la souris. Point -ConvLongToPos (LPARAM lParam) +ConvLongToPos (LParam lParam) { Point pos; @@ -155,3 +155,33 @@ AddUserPath (std::string & pFilename) pFilename = path; SDL_free (temp); } + +bool +FileExists ( + const std::string & filename, std::string & absolute, enum Location location) +{ + absolute = filename; + FILE * file; + + switch (location) + { + case LOCATION_BASE: + absolute = GetBaseDir () + filename; + break; + + case LOCATION_USER: + AddUserPath (absolute); + break; + + default: + case LOCATION_ABSOLUTE: + break; + } + + file = fopen (absolute.c_str (), "rb"); + if (file == nullptr) + return false; + + fclose (file); + return true; +} diff --git a/src/misc.h b/src/misc.h index 312a824..d1a5c98 100644 --- a/src/misc.h +++ b/src/misc.h @@ -28,7 +28,7 @@ extern void OutputDebug (const char * pMessage); -extern Point ConvLongToPos (LPARAM lParam); +extern Point ConvLongToPos (LParam lParam); extern void InitRandom (); extern Sint32 Random (Sint32 min, Sint32 max); @@ -38,6 +38,11 @@ std::string GetShareDir (); std::string GetLocale (); extern void AddUserPath (std::string & pFilename); +enum Location { LOCATION_ABSOLUTE, LOCATION_BASE, LOCATION_USER }; +bool FileExists ( + const std::string & filename, std::string & absolute, + Location location = LOCATION_BASE); + template std::string string_format (const std::string & format, Args... args) diff --git a/src/movie.cxx b/src/movie.cxx index d411c0d..3b6c54a 100644 --- a/src/movie.cxx +++ b/src/movie.cxx @@ -191,22 +191,6 @@ CMovie::GetEnable () return m_bEnable; } -// Indique si un film existe. - -bool -CMovie::IsExist (const std::string & pFilename) -{ - const auto path = GetBaseDir () + pFilename; - FILE * file; - - file = fopen (path.c_str (), "rb"); - if (file == nullptr) - return false; - - fclose (file); - return true; -} - // Montre un film avi. bool diff --git a/src/path.cxx b/src/path.cxx index 8b35317..9a762b7 100644 --- a/src/path.cxx +++ b/src/path.cxx @@ -170,27 +170,27 @@ CDecor::CheminFillTerrain (Sint32 rank) if (step < but) for (dir = 0; dir < 8; dir++) { - if (CheminTestDirection (rank, pos, dir, next, ampli, cout, action)) - { - last = pos + ampli * next; - if (last < 0 || last >= MAXCELX * MAXCELY) - continue; + if (!CheminTestDirection (rank, pos, dir, next, ampli, cout, action)) + continue; - if (m_cheminWork[last] == 0 || m_cheminWork[last] > step + cout) - { - // marque les cases sautées - for (Sint32 i = 1; i < ampli; i++) - m_cheminWork[pos + i * next] = step + cout - ampli + i; + last = pos + ampli * next; + if (last < 0 || last >= MAXCELX * MAXCELY) + continue; - m_cheminWork[last] = step + cout; + if (m_cheminWork[last] != 0 && m_cheminWork[last] <= step + cout) + continue; - dx = m_blupi[rank].goalCel.x - last % MAXCELX; - dy = m_blupi[rank].goalCel.y - last / MAXCELX; + // marque les cases sautées + for (Sint32 i = 1; i < ampli; i++) + m_cheminWork[pos + i * next] = step + cout - ampli + i; - dist = (Sint32) (dy * dy) + (Sint32) (dx * dx); - fifo.put (last, dist); - } - } + m_cheminWork[last] = step + cout; + + dx = m_blupi[rank].goalCel.x - last % MAXCELX; + dy = m_blupi[rank].goalCel.y - last / MAXCELX; + + dist = (Sint32) (dy * dy) + (Sint32) (dx * dx); + fifo.put (last, dist); } } } diff --git a/src/pixmap.cxx b/src/pixmap.cxx index eb5f902..bde9759 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -275,11 +275,15 @@ CPixmap::Cache ( size_t channel, const std::string & pFilename, Point totalDim, Point iconDim, Mode mode, size_t chBackWide) { - std::string file = GetBaseDir () + pFilename; - SDL_Surface * surface = IMG_Load (file.c_str ()); + std::string file = GetBaseDir () + pFilename; + SDL_Surface * surface = IMG_Load (file.c_str ()); + bool blupiChSet = false; if (channel == CHBLUPI && !m_lpSDLBlupi) + { m_lpSDLBlupi = surface; + blupiChSet = true; + } SDL_Texture * texture = SDL_CreateTextureFromSurface (g_renderer, surface); Uint32 format; @@ -313,13 +317,11 @@ CPixmap::Cache ( SDL_SetTextureBlendMode ( m_SDLTextureInfo[channel].texture, SDL_BLENDMODE_BLEND); } - else - { - SDL_SetRenderTarget (g_renderer, m_SDLTextureInfo[channel].texture); - SDL_SetRenderDrawColor (g_renderer, 0, 0, 0, 0); - SDL_RenderClear (g_renderer); - SDL_SetRenderTarget (g_renderer, nullptr); - } + + SDL_SetRenderTarget (g_renderer, m_SDLTextureInfo[channel].texture); + SDL_SetRenderDrawColor (g_renderer, 0, 0, 0, 0); + SDL_RenderClear (g_renderer); + SDL_SetRenderTarget (g_renderer, nullptr); m_SDLTextureInfo[channel].texMask = channel == CHMASK2 ? texture : nullptr; m_SDLTextureInfo[channel].target = true; @@ -385,7 +387,7 @@ CPixmap::Cache ( if (!m_SDLTextureInfo[channel].texMask) SDL_DestroyTexture (texture); - if (channel != CHBLUPI) + if (!blupiChSet) SDL_FreeSurface (surface); return true; diff --git a/src/progress.cxx b/src/progress.cxx index 6b131aa..9eb049c 100644 --- a/src/progress.cxx +++ b/src/progress.cxx @@ -37,9 +37,7 @@ CJauge::CJauge () m_pSound = nullptr; } -CJauge::~CJauge () -{ -} +CJauge::~CJauge () {} // Crée un nouveau bouton. diff --git a/src/progress.h b/src/progress.h index 99c725e..120ccee 100644 --- a/src/progress.h +++ b/src/progress.h @@ -48,7 +48,7 @@ protected: CDecor * m_pDecor; CSound * m_pSound; bool m_bHide; // true si bouton caché - Point m_pos; // coin sup/gauche + Point m_pos; // up/left corner Point m_dim; // dimensions Sint32 m_type; Sint32 m_level; diff --git a/src/sound.cxx b/src/sound.cxx index 7040dee..2969914 100644 --- a/src/sound.cxx +++ b/src/sound.cxx @@ -84,6 +84,14 @@ CSound::~CSound () Mix_FreeChunk (m_lpSDL[i]); m_lpSDL[i] = nullptr; } + + if (m_pMusic) + { + Mix_FreeMusic (m_pMusic); + m_pMusic = nullptr; + } + + Mix_CloseAudio (); } // Initialisation de DirectSound. @@ -318,17 +326,19 @@ CSound::PlayImage (Sounds channel, Point pos, Sint32 rank) bool CSound::PlayMusic (const std::string & lpszMIDIFilename) { - std::string path = GetBaseDir (); - if (m_midiVolume == 0) return true; + if (lpszMIDIFilename.empty ()) + return false; + Mix_VolumeMusic (MIX_MAX_VOLUME * 100 * m_midiVolume / 20 / 100); m_lastMidiVolume = m_midiVolume; - path += lpszMIDIFilename; + if (m_pMusic) + Mix_FreeMusic (m_pMusic); - m_pMusic = Mix_LoadMUS (path.c_str ()); + m_pMusic = Mix_LoadMUS (lpszMIDIFilename.c_str ()); if (!m_pMusic) { printf ("%s\n", Mix_GetError ()); diff --git a/src/text.cxx b/src/text.cxx index ee2f60c..94759fd 100644 --- a/src/text.cxx +++ b/src/text.cxx @@ -120,7 +120,7 @@ GetCharWidth (const char *& c, Sint32 font) 6, 8, 7, 6, 6, 6, 8, 12, 7, 6, 6, 3, 5, 3, 6, 8, 4, 6, 6, 6, 6, 6, 4, 6, 6, 2, 3, 5, 2, 10, 6, 6, 6, 6, 3, 5, 3, 6, 6, 8, 6, 6, 5, 4, 6, 4, 7, 6, - 3, 5, 5, 5, 5, 4, 4, 6, 3, 4 + 3, 6, 6, 6, 5, 5, 5, 7, 4, 5 }; // clang-format on