Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
400 KB
Referenced Files
None
Subscribers
None
This file is larger than 256 KB, so syntax highlighting was skipped.
diff --git a/data/font/DroidSansFallback.ttf b/data/font/DroidSansFallback.ttf
new file mode 100644
index 0000000..03ceae5
Binary files /dev/null and b/data/font/DroidSansFallback.ttf differ
diff --git a/data/font/License b/data/font/License
index 9d11c8e..d62a22b 100644
--- a/data/font/License
+++ b/data/font/License
@@ -1,10 +1,11 @@
Blokletters-Viltstift.ttf
- License: CC-BY-SA 2.5
- Attribution: http://lefly.vepar.nl/
+ License: CC-BY-SA 2.5
+ Attribution: http://lefly.vepar.nl/
knewave.ttf
- License: Open Font License
+ License: Open Font License
Attribution: _by [Tyler Finck](http://www.sursly.com)_
-freesans.ttf
- License: GNU General Public License v3
+DroidSansFallback.ttf
+ License: Apache License
+ Attribution: http://www.droidfonts.com
diff --git a/data/font/droidsans_final_fixed.ttf b/data/font/droidsans_final_fixed.ttf
deleted file mode 100644
index 826e433..0000000
Binary files a/data/font/droidsans_final_fixed.ttf and /dev/null differ
diff --git a/data/font/freesans.ttf b/data/font/freesans.ttf
deleted file mode 100644
index dde7f32..0000000
Binary files a/data/font/freesans.ttf and /dev/null differ
diff --git a/data/gfx/menu/selection.png b/data/gfx/menu/selection.png
deleted file mode 100644
index 9f31050..0000000
Binary files a/data/gfx/menu/selection.png and /dev/null differ
diff --git a/data/gfx/menu/toolbar.png b/data/gfx/menu/toolbar.png
index 1ca3818..a4e7f85 100644
Binary files a/data/gfx/menu/toolbar.png and b/data/gfx/menu/toolbar.png differ
diff --git a/data/locale/fi.po b/data/locale/fi.po
index 9951466..0bf2a0d 100644
--- a/data/locale/fi.po
+++ b/data/locale/fi.po
@@ -1,816 +1,922 @@
# Finnish translations for meandmyshadow package
# Suomenkielinen käännös meandmyshadow-paketille.
# Copyright (C) 2012 THE meandmyshadow'S COPYRIGHT HOLDER
# This file is distributed under the same license as the meandmyshadow package.
# odamite <odamite@gmail.com>, 2012.
#
msgid ""
msgstr ""
"Project-Id-Version: meandmyshadow 0.4\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2012-05-17 17:44+0300\n"
-"PO-Revision-Date: 2012-05-17 18:32+0200\n"
+"POT-Creation-Date: 2012-05-19 17:30+0300\n"
+"PO-Revision-Date: 2012-05-19 17:30+0200\n"
"Last-Translator: odamite <odamite@gmail.com>\n"
"Language-Team: Finnish\n"
"Language: fi\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
-#: src/Addons.cpp:40
-#: src/TitleMenu.cpp:50
+#: ../src/Addons.cpp:40
+#: ../src/TitleMenu.cpp:50
msgid "Addons"
msgstr "Lisäosat"
-#: src/Addons.cpp:59
+#: ../src/Addons.cpp:58
msgid "Unable to initialize addon menu:"
msgstr "Lisäosavalikkoa ei voi luoda:"
-#: src/Addons.cpp:67
-#: src/Addons.cpp:98
-#: src/LevelSelect.cpp:188
+#: ../src/Addons.cpp:66
+#: ../src/Addons.cpp:115
+#: ../src/LevelEditSelect.cpp:69
+#: ../src/LevelSelect.cpp:186
msgid "Back"
msgstr "Takaisin"
-#: src/Addons.cpp:80
+#: ../src/Addons.cpp:97
msgid "Levels"
msgstr "Kentät"
-#: src/Addons.cpp:81
+#: ../src/Addons.cpp:98
msgid "Level Packs"
msgstr "Kenttäpaketit"
-#: src/Addons.cpp:82
+#: ../src/Addons.cpp:99
msgid "Themes"
msgstr "Teemat"
-#: src/Addons.cpp:102
-#: src/Addons.cpp:580
+#: ../src/Addons.cpp:119
+#: ../src/Addons.cpp:595
msgid "Install"
msgstr "Asenna"
-#: src/Addons.cpp:106
+#: ../src/Addons.cpp:123
msgid "Update"
msgstr "Päivitä"
-#: src/Addons.cpp:385
-#: src/Addons.cpp:402
-#: src/Addons.cpp:419
-#: src/Addons.cpp:446
-#: src/Addons.cpp:463
-#: src/Addons.cpp:477
+#: ../src/Addons.cpp:400
+#: ../src/Addons.cpp:417
+#: ../src/Addons.cpp:434
+#: ../src/Addons.cpp:461
+#: ../src/Addons.cpp:478
+#: ../src/Addons.cpp:492
msgid "ERROR: Unable to download addon!"
msgstr "VIRHE: lisäosaa ei voi ladata!"
-#: src/Addons.cpp:385
-#: src/Addons.cpp:402
-#: src/Addons.cpp:419
-#: src/Addons.cpp:446
-#: src/Addons.cpp:463
-#: src/Addons.cpp:477
+#: ../src/Addons.cpp:400
+#: ../src/Addons.cpp:417
+#: ../src/Addons.cpp:434
+#: ../src/Addons.cpp:461
+#: ../src/Addons.cpp:478
+#: ../src/Addons.cpp:492
msgid "ERROR:"
msgstr "VIRHE:"
-#: src/Addons.cpp:575
+#: ../src/Addons.cpp:590
msgid "Uninstall"
msgstr "Poista"
-#. / TRANSLATORS: Font used in GUI:
-#. / - Use "knewave" for languages using Latin and Latin-derived alphabets
-#. / - "freesans" can be used for non-Latin writing systems
-#: src/Functions.cpp:383
-#: src/Functions.cpp:384
+# TRANSLATORS: Font used in GUI:
+# - Use "knewave" for languages using Latin and Latin-derived alphabets
+# - "freesans" can be used for non-Latin writing systems
+#: ../src/Functions.cpp:457
+#: ../src/Functions.cpp:458
+#: ../src/Functions.cpp:459
msgid "knewave"
msgstr "knewave"
-#. / TRANSLATORS: Font used for normal text:
-#. / - Use "Blokletters-Viltstift" for languages using Latin and Latin-derived alphabets
-#. / - "freesans" can be used for non-Latin writing systems
-#: src/Functions.cpp:388
+#: ../src/Functions.cpp:463
msgid "Blokletters-Viltstift"
msgstr "Blokletters-Viltstift"
-#: src/Functions.cpp:907
-#: src/Functions.cpp:934
-#: src/Functions.cpp:1298
-#: src/InputManager.cpp:196
-#: src/LevelEditor.cpp:1006
-#: src/LevelEditor.cpp:1618
-#: src/LevelEditor.cpp:1675
-#: src/LevelEditor.cpp:1738
-#: src/LevelEditor.cpp:1817
-#: src/LevelEditor.cpp:1922
-#: src/LevelEditor.cpp:1982
-#: src/LevelEditSelect.cpp:139
-#: src/LevelEditSelect.cpp:179
-#: src/LevelEditSelect.cpp:227
+#: ../src/Functions.cpp:983
+#: ../src/Functions.cpp:1010
+#: ../src/Functions.cpp:1374
+#: ../src/InputManager.cpp:196
+#: ../src/LevelEditor.cpp:1017
+#: ../src/LevelEditor.cpp:1630
+#: ../src/LevelEditor.cpp:1687
+#: ../src/LevelEditor.cpp:1750
+#: ../src/LevelEditor.cpp:1830
+#: ../src/LevelEditor.cpp:1936
+#: ../src/LevelEditor.cpp:1996
+#: ../src/LevelEditSelect.cpp:175
+#: ../src/LevelEditSelect.cpp:215
+#: ../src/LevelEditSelect.cpp:263
msgid "OK"
msgstr "OK"
-#: src/Functions.cpp:908
-#: src/Functions.cpp:920
-#: src/Functions.cpp:930
-#: src/Functions.cpp:1302
-#: src/LevelEditor.cpp:1010
-#: src/LevelEditor.cpp:1622
-#: src/LevelEditor.cpp:1679
-#: src/LevelEditor.cpp:1742
-#: src/LevelEditor.cpp:1821
-#: src/LevelEditor.cpp:1926
-#: src/LevelEditor.cpp:1986
-#: src/LevelEditSelect.cpp:143
-#: src/LevelEditSelect.cpp:183
-#: src/LevelEditSelect.cpp:231
-#: src/TitleMenu.cpp:422
+#: ../src/Functions.cpp:984
+#: ../src/Functions.cpp:996
+#: ../src/Functions.cpp:1006
+#: ../src/Functions.cpp:1378
+#: ../src/LevelEditor.cpp:1021
+#: ../src/LevelEditor.cpp:1634
+#: ../src/LevelEditor.cpp:1691
+#: ../src/LevelEditor.cpp:1754
+#: ../src/LevelEditor.cpp:1834
+#: ../src/LevelEditor.cpp:1940
+#: ../src/LevelEditor.cpp:2000
+#: ../src/LevelEditSelect.cpp:179
+#: ../src/LevelEditSelect.cpp:219
+#: ../src/LevelEditSelect.cpp:267
+#: ../src/TitleMenu.cpp:442
msgid "Cancel"
msgstr "Peruuta"
-#: src/Functions.cpp:912
+#: ../src/Functions.cpp:988
msgid "Abort"
msgstr "Pysäytä"
-#: src/Functions.cpp:913
-#: src/Functions.cpp:929
+#: ../src/Functions.cpp:989
+#: ../src/Functions.cpp:1005
msgid "Retry"
msgstr "Uudestaan"
-#: src/Functions.cpp:914
+#: ../src/Functions.cpp:990
msgid "Ignore"
msgstr "Hylkää"
-#: src/Functions.cpp:918
-#: src/Functions.cpp:924
+#: ../src/Functions.cpp:994
+#: ../src/Functions.cpp:1000
msgid "Yes"
msgstr "Kyllä"
-#: src/Functions.cpp:919
-#: src/Functions.cpp:925
+#: ../src/Functions.cpp:995
+#: ../src/Functions.cpp:1001
msgid "No"
msgstr "Ei"
-#. / TRANSLATORS: Filename is coming before this text
-#: src/Functions.cpp:1066
+#: ../src/Functions.cpp:1142
#, c-format
msgid ""
"%s already exists.\n"
"Do you want to overwrite it?"
msgstr ""
"Tiedosto %s on jo olemassa.\n"
"Haluatko korvata sen?"
-#: src/Functions.cpp:1066
+#: ../src/Functions.cpp:1142
msgid "Overwrite Prompt"
msgstr "Ylikirjoitus"
-#: src/Functions.cpp:1087
-#: src/Functions.cpp:1105
+#: ../src/Functions.cpp:1163
+#: ../src/Functions.cpp:1181
#, c-format
msgid "Can't open file %s."
msgstr "Tiedostoa %s ei voi avata."
-#: src/Functions.cpp:1087
-#: src/Functions.cpp:1105
+#: ../src/Functions.cpp:1163
+#: ../src/Functions.cpp:1181
msgid "Error"
msgstr "Virhe"
-#: src/Functions.cpp:1239
+#: ../src/Functions.cpp:1315
msgid "Save File"
msgstr "Tallenna tiedosto"
-#: src/Functions.cpp:1239
+#: ../src/Functions.cpp:1315
msgid "Load File"
msgstr "Avaa tiedosto"
-#: src/Functions.cpp:1243
+#: ../src/Functions.cpp:1319
msgid "Search In"
msgstr "Etsi"
-#: src/Functions.cpp:1253
+#: ../src/Functions.cpp:1329
msgid "File Name"
msgstr "Tiedostonimi"
-#. / TRANSLATORS: Please do not remove %s or %d from your translation:
-#. / - %d means the level number in a levelpack
-#. / - %s means the name of current level
-#: src/Game.cpp:226
-#: src/Game.cpp:821
+#: ../src/Game.cpp:226
+#: ../src/Game.cpp:822
#, c-format
msgid "Level %d %s"
msgstr "Kenttä %d %s"
-#. / TRANSLATORS: Please do not remove %s from your translation:
-#. / - %s will be replaced with current action key
-#: src/Game.cpp:649
+#: ../src/Game.cpp:649
#, c-format
msgid "Press %s key to save the game."
msgstr "Paina %s tallentaaksesi peli."
-#. / TRANSLATORS: Please do not remove %s from your translation:
-#. / - %s will be replaced with current action key
-#: src/Game.cpp:654
+#: ../src/Game.cpp:654
#, c-format
msgid "Press %s key to swap the position of player and shadow."
msgstr "Paina %s vaihtaaksesi pelaajan ja varjon paikkoja"
-#. / TRANSLATORS: Please do not remove %s from your translation:
-#. / - %s will be replaced with current action key
-#: src/Game.cpp:659
+#: ../src/Game.cpp:659
#, c-format
msgid "Press %s key to activate the switch."
msgstr "Paina %s käyttääksesi vipua."
-#. / TRANSLATORS: Please do not remove %s from your translation:
-#. / - %s will be replaced with current action key
-#: src/Game.cpp:664
+#: ../src/Game.cpp:664
#, c-format
msgid "Press %s key to teleport."
msgstr "Paina %s käyttääksesi teleporttia."
-#. / TRANSLATORS: Please do not remove %s from your translation:
-#. / - first %s means currently configured key to restart game
-#. / - Second %s means configured key to load from last save
-#: src/Game.cpp:705
+#: ../src/Game.cpp:705
#, c-format
msgid "Press %s to restart current level or press %s to load the game."
msgstr "Paina %s aloittaaksesi kenttä uudestaan tai paina %s ladataksesi peli."
-#. / TRANSLATORS: Please do not remove %s from your translation:
-#. / - %s will be replaced with currently configured key to restart game
-#: src/Game.cpp:718
+#: ../src/Game.cpp:717
#, c-format
msgid "Press %s to restart current level."
msgstr "Paina %s aloittaaksesi kenttä uudestaan."
-#: src/Game.cpp:733
+#: ../src/Game.cpp:731
msgid "Your shadow has died."
msgstr "Varjosi on kuollut."
-#: src/Game.cpp:773
+#: ../src/Game.cpp:774
#, c-format
msgid "%d recordings"
msgstr "%d nauhoitusta"
-#. / TRANSLATORS: This is caption for finished level
-#: src/Game.cpp:813
+#: ../src/Game.cpp:814
msgid "You've finished:"
msgstr "Pääsit läpi:"
-#. / TRANSLATORS: Please do not remove %-.2f from your translation:
-#. / - %-.2f means time in seconds
-#. / - s is shortened form of a second. Try to keep it so.
-#: src/Game.cpp:969
+#: ../src/Game.cpp:972
#, c-format
msgid "Time: %-.2fs"
msgstr "Aikasi: %-.2fs"
-#. / TRANSLATORS: Please do not remove %-.2f from your translation:
-#. / - %-.2f means time in seconds
-#. / - s is shortened form of a second. Try to keep it so.
-#: src/Game.cpp:975
+#: ../src/Game.cpp:978
#, c-format
msgid "Best time: %-.2fs"
msgstr "Paras aikasi: %-.2fs"
-#: src/Game.cpp:982
+#: ../src/Game.cpp:985
#, c-format
msgid "Target time: %-.2fs"
msgstr "Tavoiteaika: %-.2fs"
-#. / TRANSLATORS: Please do not remove %d from your translation:
-#. / - %d means the number of recordings user has made
-#: src/Game.cpp:989
+#: ../src/Game.cpp:992
#, c-format
msgid "Recordings: %d"
msgstr "Nauhoituksesi: %d"
-#. / TRANSLATORS: Please do not remove %d from your translation:
-#. / - %d means the number of recordings user has made
-#: src/Game.cpp:994
+#: ../src/Game.cpp:997
#, c-format
msgid "Best recordings: %d"
msgstr "Parhaat nauhoituksesi: %d"
-#: src/Game.cpp:1000
+#: ../src/Game.cpp:1003
#, c-format
msgid "Target recordings: %d"
msgstr "Tavoitenauhoitukset: %d"
-#. / TRANSLATORS: Please do not remove %s from your translation:
-#. / - %s will be replaced with name of a prize medal (gold, silver or bronze)
-#: src/Game.cpp:1007
+#: ../src/Game.cpp:1010
#, c-format
msgid "You earned the %s medal"
-msgstr "Olet ansainnut %smitalin"
+msgstr "Ansaitsit %smitalin"
-#: src/Game.cpp:1007
+#: ../src/Game.cpp:1010
msgid "GOLD"
msgstr "kulta"
-#: src/Game.cpp:1007
+#: ../src/Game.cpp:1010
msgid "SILVER"
msgstr "hopea"
-#: src/Game.cpp:1007
+#: ../src/Game.cpp:1010
msgid "BRONZE"
msgstr "pronssi"
-#. / TRANSLATORS: used as return to the level selector menu
-#: src/Game.cpp:1018
+#: ../src/Game.cpp:1021
msgid "Menu"
msgstr "Valikko"
-#. / TRANSLATORS: used as restart level
-#: src/Game.cpp:1024
+#: ../src/Game.cpp:1027
+#: ../src/InputManager.cpp:41
msgid "Restart"
msgstr "Uudestaan"
-#. / TRANSLATORS: used as next level
-#: src/Game.cpp:1030
+#: ../src/Game.cpp:1033
msgid "Next"
msgstr "Seuraava"
-#: src/Game.cpp:1057
+#: ../src/Game.cpp:1060
msgid "Game replay is done."
msgstr "Uusinta loppui."
-#: src/Game.cpp:1057
+#: ../src/Game.cpp:1060
msgid "Game Replay"
msgstr "Uusinta"
-#: src/Game.cpp:1210
-#: src/Game.cpp:1212
+#: ../src/Game.cpp:1213
+#: ../src/Game.cpp:1215
msgid "Congratulations"
msgstr "Onnittelut"
-#: src/Game.cpp:1212
+#: ../src/Game.cpp:1215
msgid "You have finished the levelpack!"
msgstr "Pääsit kenttäpaketin läpi!"
-#: src/InputManager.cpp:163
-#: src/TitleMenu.cpp:410
+#: ../src/InputManager.cpp:40
+msgid "Up (in menu)"
+msgstr "Ylös (valikossa)"
+
+#: ../src/InputManager.cpp:40
+msgid "Down (in menu)"
+msgstr "Alas (valikossa)"
+
+#: ../src/InputManager.cpp:40
+msgid "Left"
+msgstr "Liiku vasemmalle"
+
+#: ../src/InputManager.cpp:40
+msgid "Right"
+msgstr "Liiku oikealle"
+
+#: ../src/InputManager.cpp:40
+msgid "Jump"
+msgstr "Hyppää"
+
+#: ../src/InputManager.cpp:40
+msgid "Action"
+msgstr "Käytä"
+
+#: ../src/InputManager.cpp:40
+msgid "Space (Record)"
+msgstr "Nauhoita"
+
+#: ../src/InputManager.cpp:41
+msgid "Escape"
+msgstr "Takaisin"
+
+#: ../src/InputManager.cpp:41
+msgid "Tab (View shadow/Level prop.)"
+msgstr "Tabulaattori (Varjon näkymä/kentän asetukset)"
+
+#: ../src/InputManager.cpp:41
+msgid "Save game (in editor)"
+msgstr "Tallenna peli (kenttäeditorissa)"
+
+#: ../src/InputManager.cpp:41
+msgid "Load game"
+msgstr "Lataa peli"
+
+#: ../src/InputManager.cpp:41
+msgid "Swap (in editor)"
+msgstr "Vaihda paikkoja (kenttäeditorissa)"
+
+#: ../src/InputManager.cpp:42
+msgid "Teleport (in editor)"
+msgstr "Teleporttaa (kenttäeditorissa)"
+
+#: ../src/InputManager.cpp:42
+msgid "Suicide (in editor)"
+msgstr "Kuole (kenttäeditorissa)"
+
+#: ../src/InputManager.cpp:42
+msgid "Shift (in editor)"
+msgstr "Vaihda paikkaa (kenttäeditorissa)"
+
+#: ../src/InputManager.cpp:42
+msgid "Next block type (in Editor)"
+msgstr "Seuraava palikkatyyppi (kenttäeditorissa)"
+
+#: ../src/InputManager.cpp:43
+msgid "Previous block type (in editor)"
+msgstr "Edellinen palikkatyyppi (kenttäeditorissa)"
+
+#: ../src/InputManager.cpp:43
+msgid "Select (in menu)"
+msgstr "Valitse (valikossa)"
+
+#: ../src/InputManager.cpp:163
+#: ../src/TitleMenu.cpp:430
msgid "Config Keys"
msgstr "Aseta näppäimet"
-#: src/InputManager.cpp:166
+#: ../src/InputManager.cpp:166
msgid "Select an item and press a key to config it."
msgstr "Valitse kohde listasta ja paina näppäintä vaihtaaksesi se."
-#: src/InputManager.cpp:179
+#: ../src/InputManager.cpp:179
msgid "Primary key"
msgstr "Ensisijaiset"
-#: src/InputManager.cpp:180
+#: ../src/InputManager.cpp:180
msgid "Alternative key"
msgstr "Toissijaiset"
-#: src/InputManager.cpp:186
+#: ../src/InputManager.cpp:186
msgid "Unset the key"
msgstr "Tyhjennä valinta"
-#: src/InputManager.cpp:300
+#: ../src/InputManager.cpp:300
msgid "(Not set)"
msgstr "(Ei määritetty)"
-#: src/LevelEditor.cpp:121
+#: ../src/LevelEditor.cpp:121
msgid "Toolbox"
msgstr "Työkalulaatikko"
-#: src/LevelEditor.cpp:518
+#: ../src/LevelEditor.cpp:180
+msgid "Block"
+msgstr "Palikka"
+
+#: ../src/LevelEditor.cpp:180
+msgid "Player Start"
+msgstr "Pelaajan aloituspaikka"
+
+#: ../src/LevelEditor.cpp:180
+msgid "Shadow Start"
+msgstr "Varjon aloituspaikka"
+
+#: ../src/LevelEditor.cpp:181
+msgid "Exit"
+msgstr "Uloskäynti"
+
+#: ../src/LevelEditor.cpp:181
+msgid "Shadow Block"
+msgstr "Varjopalikka"
+
+#: ../src/LevelEditor.cpp:181
+msgid "Spikes"
+msgstr "Piikit"
+
+#: ../src/LevelEditor.cpp:182
+msgid "Checkpoint"
+msgstr "Tallennuspiste"
+
+#: ../src/LevelEditor.cpp:182
+#: ../src/LevelEditSelect.cpp:258
+msgid "Swap"
+msgstr "Vaihda paikkoja"
+
+#: ../src/LevelEditor.cpp:182
+#: ../src/LevelEditor.cpp:1976
+msgid "Fragile"
+msgstr "Hauras palikka"
+
+#: ../src/LevelEditor.cpp:183
+msgid "Moving Block"
+msgstr "Liikkuva palikka"
+
+#: ../src/LevelEditor.cpp:183
+msgid "Moving Shadow Block"
+msgstr "Liikkuva varjopalikka"
+
+#: ../src/LevelEditor.cpp:183
+msgid "Moving Spikes"
+msgstr "Liikkuvat piikit"
+
+#: ../src/LevelEditor.cpp:184
+msgid "Teleporter"
+msgstr "Teleportti"
+
+#: ../src/LevelEditor.cpp:184
+#: ../src/LevelEditor.cpp:1884
+msgid "Button"
+msgstr "Painike"
+
+#: ../src/LevelEditor.cpp:184
+#: ../src/LevelEditor.cpp:1886
+msgid "Switch"
+msgstr "Vipu"
+
+#: ../src/LevelEditor.cpp:185
+msgid "Conveyor Belt"
+msgstr "Liukuhihna"
+
+#: ../src/LevelEditor.cpp:185
+msgid "Shadow Conveyor Belt"
+msgstr "Varjoliukuhihna"
+
+#: ../src/LevelEditor.cpp:185
+msgid "Notification Block"
+msgstr "Kyltti"
+
+#: ../src/LevelEditor.cpp:185
+msgid "Collectable"
+msgstr "Avain"
+
+#: ../src/LevelEditor.cpp:529
msgid "Are you sure you want to quit?"
msgstr "Haluatko varmasti poistua?"
-#: src/LevelEditor.cpp:518
+#: ../src/LevelEditor.cpp:529
msgid "Quit prompt"
msgstr "Poistuminen"
-#: src/LevelEditor.cpp:946
-#: src/LevelEditor.cpp:948
-#: src/LevelEditor.cpp:2595
-#: src/LevelEditor.cpp:2597
+#: ../src/LevelEditor.cpp:957
+#: ../src/LevelEditor.cpp:959
+#: ../src/LevelEditor.cpp:2609
+#: ../src/LevelEditor.cpp:2611
#, c-format
msgid "Level \"%s\" saved"
msgstr "Kenttä \"%s\" tallennettu"
-#: src/LevelEditor.cpp:946
-#: src/LevelEditor.cpp:948
-#: src/LevelEditor.cpp:2595
-#: src/LevelEditor.cpp:2597
+#: ../src/LevelEditor.cpp:957
+#: ../src/LevelEditor.cpp:959
+#: ../src/LevelEditor.cpp:2609
+#: ../src/LevelEditor.cpp:2611
msgid "Saved"
msgstr "Tallennus"
-#: src/LevelEditor.cpp:961
-#: src/LevelEditor.cpp:2718
+#: ../src/LevelEditor.cpp:972
+#: ../src/LevelEditor.cpp:2732
msgid "Level settings"
msgstr "Kentän asetukset"
-#: src/LevelEditor.cpp:965
-#: src/LevelEditSelect.cpp:118
+#: ../src/LevelEditor.cpp:976
+#: ../src/LevelEditSelect.cpp:154
msgid "Name:"
msgstr "Nimi:"
-#: src/LevelEditor.cpp:971
+#: ../src/LevelEditor.cpp:982
msgid "Theme:"
msgstr "Teema:"
-#: src/LevelEditor.cpp:986
+#: ../src/LevelEditor.cpp:997
msgid "Target time (s):"
msgstr "Tavoiteaika:"
-#: src/LevelEditor.cpp:997
+#: ../src/LevelEditor.cpp:1008
msgid "Target recordings:"
msgstr "Tavoite nauhoitusten määräksi:"
-#: src/LevelEditor.cpp:1565
-#: src/LevelEditor.cpp:1781
+#: ../src/LevelEditor.cpp:1576
+#: ../src/LevelEditor.cpp:1793
msgid "Defined"
msgstr "Määritetty"
-#: src/LevelEditor.cpp:1568
-#: src/LevelEditor.cpp:1784
-#: src/LevelEditor.cpp:1865
+#: ../src/LevelEditor.cpp:1579
+#: ../src/LevelEditor.cpp:1796
+#: ../src/LevelEditor.cpp:1878
msgid "None"
msgstr "Määrittämätön"
-#: src/LevelEditor.cpp:1575
+#: ../src/LevelEditor.cpp:1586
msgid "Moving block"
msgstr "Liikkuva palikka"
-#: src/LevelEditor.cpp:1578
+#: ../src/LevelEditor.cpp:1589
msgid "Moving shadow block"
msgstr "Liikkuva varjopalikka"
-#: src/LevelEditor.cpp:1581
+#: ../src/LevelEditor.cpp:1592
msgid "Moving spikes"
msgstr "Liikkuvat piikit"
-#: src/LevelEditor.cpp:1588
-#: src/LevelEditor.cpp:1724
+#: ../src/LevelEditor.cpp:1599
+#: ../src/LevelEditor.cpp:1736
msgid "Enabled"
msgstr "Aktivoitu"
-#: src/LevelEditor.cpp:1594
+#: ../src/LevelEditor.cpp:1605
msgid "Loop"
msgstr "Silmukka"
-#: src/LevelEditor.cpp:1600
+#: ../src/LevelEditor.cpp:1611
msgid "Path"
msgstr "Reitti"
-#: src/LevelEditor.cpp:1659
+#: ../src/LevelEditor.cpp:1671
msgid "Notification block"
msgstr "Kyltti"
-#: src/LevelEditor.cpp:1662
+#: ../src/LevelEditor.cpp:1674
msgid "Enter message here:"
msgstr "Kirjoita viesti tähän:"
-#: src/LevelEditor.cpp:1716
+#: ../src/LevelEditor.cpp:1728
msgid "Shadow Conveyor belt"
msgstr "Varjoliukuhihna"
-#: src/LevelEditor.cpp:1718
+#: ../src/LevelEditor.cpp:1730
msgid "Conveyor belt"
msgstr "Liukuhihna"
-#: src/LevelEditor.cpp:1730
+#: ../src/LevelEditor.cpp:1742
msgid "Enter speed here:"
msgstr "Aseta nopeus:"
-#: src/LevelEditor.cpp:1788
+#: ../src/LevelEditor.cpp:1800
msgid "Portal"
msgstr "Portaali"
-#: src/LevelEditor.cpp:1791
+#: ../src/LevelEditor.cpp:1803
msgid "Activate on touch"
msgstr "Aktivoi koskettaessa"
-#: src/LevelEditor.cpp:1797
-#: src/LevelEditor.cpp:1901
+#: ../src/LevelEditor.cpp:1809
+#: ../src/LevelEditor.cpp:1914
msgid "Targets:"
msgstr "Kohteet:"
-#: src/LevelEditor.cpp:1871
-msgid "Button"
-msgstr "Painike"
-
-#: src/LevelEditor.cpp:1873
-msgid "Switch"
-msgstr "Vipu"
+#: ../src/LevelEditor.cpp:1875
+#, c-format
+msgid "%d Defined"
+msgstr "%d määritelty"
-#: src/LevelEditor.cpp:1878
+#: ../src/LevelEditor.cpp:1891
msgid "Behaviour:"
msgstr "Käytös:"
-#: src/LevelEditor.cpp:1884
+#: ../src/LevelEditor.cpp:1897
msgid "On"
msgstr "Päällä"
-#: src/LevelEditor.cpp:1885
+#: ../src/LevelEditor.cpp:1898
msgid "Off"
msgstr "Pois"
-#: src/LevelEditor.cpp:1886
+#: ../src/LevelEditor.cpp:1899
msgid "Toggle"
msgstr "Kytkin"
-#: src/LevelEditor.cpp:1962
-msgid "Fragile"
-msgstr "Hauras palikka"
-
-#: src/LevelEditor.cpp:1965
+#: ../src/LevelEditor.cpp:1979
msgid "State:"
msgstr "Kunto:"
-#: src/LevelEditor.cpp:1971
+#: ../src/LevelEditor.cpp:1985
msgid "Complete"
msgstr "Kokonainen"
-#: src/LevelEditor.cpp:1972
+#: ../src/LevelEditor.cpp:1986
msgid "One step"
msgstr "Hauras"
-#: src/LevelEditor.cpp:1973
+#: ../src/LevelEditor.cpp:1987
msgid "Two steps"
msgstr "Hauraampi"
-#: src/LevelEditor.cpp:1974
+#: ../src/LevelEditor.cpp:1988
msgid "Gone"
msgstr "Hajonnut"
-#: src/LevelEditor.cpp:2703
+#: ../src/LevelEditor.cpp:2717
msgid "Select"
msgstr "Valitse"
-#: src/LevelEditor.cpp:2706
+#: ../src/LevelEditor.cpp:2720
msgid "Add"
msgstr "Lisää"
-#: src/LevelEditor.cpp:2709
+#: ../src/LevelEditor.cpp:2723
msgid "Delete"
msgstr "Poista"
-#: src/LevelEditor.cpp:2712
+#: ../src/LevelEditor.cpp:2726
msgid "Configure"
msgstr "Muokkaa"
-#: src/LevelEditor.cpp:2715
-#: src/LevelPlaySelect.cpp:49
-#: src/TitleMenu.cpp:47
+#: ../src/LevelEditor.cpp:2729
+#: ../src/LevelPlaySelect.cpp:65
+#: ../src/TitleMenu.cpp:47
msgid "Play"
msgstr "Pelaa"
-#: src/LevelEditor.cpp:2721
+#: ../src/LevelEditor.cpp:2735
msgid "Save level"
msgstr "Tallenna kenttä"
-#: src/LevelEditor.cpp:2724
+#: ../src/LevelEditor.cpp:2738
msgid "Back to menu"
msgstr "Takaisin valikkoon"
-#: src/LevelEditor.cpp:2770
+#: ../src/LevelEditor.cpp:2784
#, c-format
msgid "Movespeed: %s"
msgstr "Nopeus: %s"
-#: src/LevelEditSelect.cpp:41
-#: src/TitleMenu.cpp:49
+#: ../src/LevelEditSelect.cpp:41
+#: ../src/TitleMenu.cpp:49
msgid "Map Editor"
msgstr "Kenttäeditori"
-#: src/LevelEditSelect.cpp:49
+#: ../src/LevelEditSelect.cpp:78
msgid "New Levelpack"
msgstr "Uusi kenttäpaketti"
-#: src/LevelEditSelect.cpp:54
+#: ../src/LevelEditSelect.cpp:83
msgid "Pack Properties"
msgstr "Paketin asetukset"
-#: src/LevelEditSelect.cpp:59
+#: ../src/LevelEditSelect.cpp:88
msgid "Remove Pack"
msgstr "Poista paketti"
-#: src/LevelEditSelect.cpp:64
+#: ../src/LevelEditSelect.cpp:93
msgid "Move Map"
msgstr "Siirrä kenttä"
-#: src/LevelEditSelect.cpp:70
+#: ../src/LevelEditSelect.cpp:99
msgid "Remove Map"
msgstr "Poista kenttä"
-#: src/LevelEditSelect.cpp:75
+#: ../src/LevelEditSelect.cpp:104
msgid "Edit Map"
msgstr "Muokkaa kenttää"
-#: src/LevelEditSelect.cpp:115
+#: ../src/LevelEditSelect.cpp:151
msgid "Properties"
msgstr "Asetukset"
-#: src/LevelEditSelect.cpp:125
+#: ../src/LevelEditSelect.cpp:161
msgid "Description:"
msgstr "Kuvaus:"
-#: src/LevelEditSelect.cpp:132
+#: ../src/LevelEditSelect.cpp:168
msgid "Congratulation text:"
msgstr "Onnittelu:"
-#: src/LevelEditSelect.cpp:167
-#: src/LevelEditSelect.cpp:327
+#: ../src/LevelEditSelect.cpp:203
+#: ../src/LevelEditSelect.cpp:371
msgid "Add level"
msgstr "Lisää kenttä"
-#: src/LevelEditSelect.cpp:170
+#: ../src/LevelEditSelect.cpp:206
msgid "File name:"
msgstr "Tiedostonimi:"
-#: src/LevelEditSelect.cpp:207
+#: ../src/LevelEditSelect.cpp:243
msgid "Move level"
msgstr "Siirrä kenttä"
-#: src/LevelEditSelect.cpp:210
+#: ../src/LevelEditSelect.cpp:246
msgid "Level: "
msgstr "Kenttä:"
-#: src/LevelEditSelect.cpp:214
+#: ../src/LevelEditSelect.cpp:250
msgid "MoveLevel"
msgstr "Siirrä kenttä"
-#: src/LevelEditSelect.cpp:220
+#: ../src/LevelEditSelect.cpp:256
msgid "Before"
msgstr "Ennen"
-#: src/LevelEditSelect.cpp:221
+#: ../src/LevelEditSelect.cpp:257
msgid "After"
msgstr "Jälkeen"
-#: src/LevelEditSelect.cpp:222
-msgid "Swap"
-msgstr "Vaihda paikkaa"
-
-#: src/LevelEditSelect.cpp:395
+#: ../src/LevelEditSelect.cpp:439
msgid "Are you sure?"
msgstr "Oletko varma?"
-#: src/LevelEditSelect.cpp:395
+#: ../src/LevelEditSelect.cpp:439
msgid "Remove prompt"
msgstr "Poista"
-#: src/LevelEditSelect.cpp:535
+#: ../src/LevelEditSelect.cpp:579
msgid "No file name given for the new level."
msgstr "Uudelle kentälle ei annettu nimeä."
-#: src/LevelEditSelect.cpp:535
+#: ../src/LevelEditSelect.cpp:579
msgid "Missing file name"
msgstr "Puuttuva tiedostonimi"
-#: src/LevelEditSelect.cpp:612
+#: ../src/LevelEditSelect.cpp:656
msgid "The entered level number isn't valid!"
msgstr "Kentälle annettu järjestysnumero ei kelpaa!"
-#: src/LevelEditSelect.cpp:612
+#: ../src/LevelEditSelect.cpp:656
msgid "Illegal number"
msgstr "Järjestysnumero"
-#: src/LevelPlaySelect.cpp:43
+#: ../src/LevelPlaySelect.cpp:43
msgid "Select Level"
msgstr "Valitse kenttä"
-#: src/LevelPlaySelect.cpp:80
+#: ../src/LevelPlaySelect.cpp:92
msgid "Choose a level"
msgstr "Valitse kenttä"
-#: src/LevelPlaySelect.cpp:81
-#: src/LevelPlaySelect.cpp:219
-#: src/LevelPlaySelect.cpp:230
+#: ../src/LevelPlaySelect.cpp:93
+#: ../src/LevelPlaySelect.cpp:231
+#: ../src/LevelPlaySelect.cpp:242
msgid "Time:"
msgstr "Aika:"
-#: src/LevelPlaySelect.cpp:82
-#: src/LevelPlaySelect.cpp:228
-#: src/LevelPlaySelect.cpp:231
+#: ../src/LevelPlaySelect.cpp:94
+#: ../src/LevelPlaySelect.cpp:240
+#: ../src/LevelPlaySelect.cpp:243
msgid "Recordings:"
msgstr "Nauhoitukset:"
-#: src/Main.cpp:56
+#: ../src/Main.cpp:56
#, c-format
msgid "Usage: %s [OPTIONS] ...\n"
msgstr "Käyttö: %s [ASETUKSET] ...\n"
-#: src/Main.cpp:57
+#: ../src/Main.cpp:57
msgid "Available options:\n"
msgstr "Saatavilla olevat asetukset:\n"
-#: src/Main.cpp:58
+#: ../src/Main.cpp:58
msgid "Specifies the data directory."
msgstr "Aseta kansio, josta pelin tiedostot haetaan."
-#: src/Main.cpp:59
+#: ../src/Main.cpp:59
msgid "Specifies the user preferences directory."
msgstr "Aseta kansio, josta käyttäjän asetukset haetaan"
-#: src/Main.cpp:60
+#: ../src/Main.cpp:60
msgid "Run the game fullscreen."
msgstr "Aja peli kokoruudulla."
-#: src/Main.cpp:61
+#: ../src/Main.cpp:61
msgid "Run the game windowed."
msgstr "Aja peli ikkunassa."
-#: src/Main.cpp:62
+#: ../src/Main.cpp:62
msgid "Set the music volume."
msgstr "Aseta musiikin äänenvoimakkuus."
-#: src/Main.cpp:63
+#: ../src/Main.cpp:63
msgid "Set the sound volume."
msgstr "Aseta äänien voimakkuus."
-#: src/Main.cpp:64
+#: ../src/Main.cpp:64
msgid "Change a setting to a given value."
msgstr "Vaihda tietty asutus toiseksi."
-#: src/Main.cpp:65
+#: ../src/Main.cpp:65
msgid "Display the version and quit."
msgstr "Näytä versio ja lopeta."
-#: src/Main.cpp:66
+#: ../src/Main.cpp:66
msgid "Display this help message."
msgstr "Näytä tämä ohje."
-#: src/TitleMenu.cpp:48
+#: ../src/TitleMenu.cpp:48
msgid "Options"
msgstr "Asetukset"
-#: src/TitleMenu.cpp:51
-msgid "Exit"
+#: ../src/TitleMenu.cpp:51
+msgid "Quit"
msgstr "Poistu"
-#: src/TitleMenu.cpp:109
+#: ../src/TitleMenu.cpp:109
msgid "Enable internet in order to install addons."
msgstr "Aktivoi internet asentaaksesi lisäosia."
-#: src/TitleMenu.cpp:109
+#: ../src/TitleMenu.cpp:109
msgid "Internet disabled"
msgstr "Internet pois käytöstä"
-#: src/TitleMenu.cpp:186
+#: ../src/TitleMenu.cpp:188
msgid "Settings"
msgstr "Asetukset"
-#: src/TitleMenu.cpp:216
+#: ../src/TitleMenu.cpp:236
msgid "Music"
msgstr "Musiikki"
-#: src/TitleMenu.cpp:224
+#: ../src/TitleMenu.cpp:244
msgid "Sound"
msgstr "Äänet"
-#: src/TitleMenu.cpp:232
+#: ../src/TitleMenu.cpp:252
msgid "Fullscreen"
msgstr "Kokoruutu"
-#: src/TitleMenu.cpp:237
+#: ../src/TitleMenu.cpp:257
msgid "Resolution"
msgstr "Resoluutio"
-#: src/TitleMenu.cpp:319
+#: ../src/TitleMenu.cpp:339
msgid "Language"
msgstr "Kieli"
-#. / TRANSLATORS: as detect user's language automatically
-#: src/TitleMenu.cpp:328
+#: ../src/TitleMenu.cpp:348
msgid "Auto-Detect"
msgstr "Valitse automaattisesti"
-#: src/TitleMenu.cpp:356
+#: ../src/TitleMenu.cpp:376
msgid "Theme"
msgstr "Teema"
-#: src/TitleMenu.cpp:389
+#: ../src/TitleMenu.cpp:409
msgid "Level themes"
msgstr "Kentän teema"
-#: src/TitleMenu.cpp:394
+#: ../src/TitleMenu.cpp:414
msgid "Internet"
msgstr "Internet"
-#: src/TitleMenu.cpp:400
+#: ../src/TitleMenu.cpp:420
msgid "Internet proxy"
msgstr "Internet proxy"
-#. / TRANSLATORS: Used for button which clear any level progress like unlocked levels and highscores.
-#: src/TitleMenu.cpp:417
+#: ../src/TitleMenu.cpp:437
msgid "Clear Progress"
msgstr "Nollaa edistyminen"
-#: src/TitleMenu.cpp:427
+#: ../src/TitleMenu.cpp:447
msgid "Save Changes"
msgstr "Tallenna"
-#: src/TitleMenu.cpp:539
+#: ../src/TitleMenu.cpp:546
msgid "Do you really want to reset level progress?"
msgstr "Haluatko varmasti nollata edistymisesi?"
-#: src/TitleMenu.cpp:539
+#: ../src/TitleMenu.cpp:546
msgid "Warning"
msgstr "Varoitus"
diff --git a/data/locale/messages.pot b/data/locale/messages.pot
index f8ba429..6f9f015 100644
--- a/data/locale/messages.pot
+++ b/data/locale/messages.pot
@@ -1,757 +1,895 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: meandmyshadow 0.4\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2012-05-17 17:44+0300\n"
+"POT-Creation-Date: 2012-05-19 19:44+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
-#: src/Addons.cpp:40 src/TitleMenu.cpp:50
+#: ../src/Addons.cpp:40 ../src/TitleMenu.cpp:50
msgid "Addons"
msgstr ""
-#: src/Addons.cpp:59
+#: ../src/Addons.cpp:58
msgid "Unable to initialize addon menu:"
msgstr ""
-#: src/Addons.cpp:67 src/Addons.cpp:98 src/LevelSelect.cpp:188
+#: ../src/Addons.cpp:66 ../src/Addons.cpp:115 ../src/LevelEditSelect.cpp:69
+#: ../src/LevelSelect.cpp:186
msgid "Back"
msgstr ""
-#: src/Addons.cpp:80
+#: ../src/Addons.cpp:97
msgid "Levels"
msgstr ""
-#: src/Addons.cpp:81
+#: ../src/Addons.cpp:98
msgid "Level Packs"
msgstr ""
-#: src/Addons.cpp:82
+#: ../src/Addons.cpp:99
msgid "Themes"
msgstr ""
-#: src/Addons.cpp:102 src/Addons.cpp:580
+#: ../src/Addons.cpp:119 ../src/Addons.cpp:595
msgid "Install"
msgstr ""
-#: src/Addons.cpp:106
+#: ../src/Addons.cpp:123
msgid "Update"
msgstr ""
-#: src/Addons.cpp:385 src/Addons.cpp:402 src/Addons.cpp:419 src/Addons.cpp:446
-#: src/Addons.cpp:463 src/Addons.cpp:477
+#: ../src/Addons.cpp:400 ../src/Addons.cpp:417 ../src/Addons.cpp:434
+#: ../src/Addons.cpp:461 ../src/Addons.cpp:478 ../src/Addons.cpp:492
msgid "ERROR: Unable to download addon!"
msgstr ""
-#: src/Addons.cpp:385 src/Addons.cpp:402 src/Addons.cpp:419 src/Addons.cpp:446
-#: src/Addons.cpp:463 src/Addons.cpp:477
+#: ../src/Addons.cpp:400 ../src/Addons.cpp:417 ../src/Addons.cpp:434
+#: ../src/Addons.cpp:461 ../src/Addons.cpp:478 ../src/Addons.cpp:492
msgid "ERROR:"
msgstr ""
-#: src/Addons.cpp:575
+#: ../src/Addons.cpp:590
msgid "Uninstall"
msgstr ""
-#. / TRANSLATORS: Font used in GUI:
-#. / - Use "knewave" for languages using Latin and Latin-derived alphabets
-#. / - "freesans" can be used for non-Latin writing systems
-#: src/Functions.cpp:383 src/Functions.cpp:384
+# TRANSLATORS: Font used in GUI:
+# - Use "knewave" for languages using Latin and Latin-derived alphabets
+# - "DroidSansFallback" can be used for non-Latin writing systems
+#: ../src/Functions.cpp:457 ../src/Functions.cpp:458 ../src/Functions.cpp:459
msgid "knewave"
msgstr ""
-#. / TRANSLATORS: Font used for normal text:
-#. / - Use "Blokletters-Viltstift" for languages using Latin and Latin-derived alphabets
-#. / - "freesans" can be used for non-Latin writing systems
-#: src/Functions.cpp:388
+# TRANSLATORS: Font used for normal text:
+# - Use "Blokletters-Viltstift" for languages using Latin and Latin-derived alphabets
+# - "DroidSansFallback" can be used for non-Latin writing systems
+#: ../src/Functions.cpp:463
msgid "Blokletters-Viltstift"
msgstr ""
-#: src/Functions.cpp:907 src/Functions.cpp:934 src/Functions.cpp:1298
-#: src/InputManager.cpp:196 src/LevelEditor.cpp:1006 src/LevelEditor.cpp:1618
-#: src/LevelEditor.cpp:1675 src/LevelEditor.cpp:1738 src/LevelEditor.cpp:1817
-#: src/LevelEditor.cpp:1922 src/LevelEditor.cpp:1982
-#: src/LevelEditSelect.cpp:139 src/LevelEditSelect.cpp:179
-#: src/LevelEditSelect.cpp:227
+#: ../src/Functions.cpp:983 ../src/Functions.cpp:1010
+#: ../src/Functions.cpp:1374 ../src/InputManager.cpp:196
+#: ../src/LevelEditor.cpp:1017 ../src/LevelEditor.cpp:1630
+#: ../src/LevelEditor.cpp:1687 ../src/LevelEditor.cpp:1750
+#: ../src/LevelEditor.cpp:1830 ../src/LevelEditor.cpp:1936
+#: ../src/LevelEditor.cpp:1996 ../src/LevelEditSelect.cpp:175
+#: ../src/LevelEditSelect.cpp:215 ../src/LevelEditSelect.cpp:263
msgid "OK"
msgstr ""
-#: src/Functions.cpp:908 src/Functions.cpp:920 src/Functions.cpp:930
-#: src/Functions.cpp:1302 src/LevelEditor.cpp:1010 src/LevelEditor.cpp:1622
-#: src/LevelEditor.cpp:1679 src/LevelEditor.cpp:1742 src/LevelEditor.cpp:1821
-#: src/LevelEditor.cpp:1926 src/LevelEditor.cpp:1986
-#: src/LevelEditSelect.cpp:143 src/LevelEditSelect.cpp:183
-#: src/LevelEditSelect.cpp:231 src/TitleMenu.cpp:422
+#: ../src/Functions.cpp:984 ../src/Functions.cpp:996 ../src/Functions.cpp:1006
+#: ../src/Functions.cpp:1378 ../src/LevelEditor.cpp:1021
+#: ../src/LevelEditor.cpp:1634 ../src/LevelEditor.cpp:1691
+#: ../src/LevelEditor.cpp:1754 ../src/LevelEditor.cpp:1834
+#: ../src/LevelEditor.cpp:1940 ../src/LevelEditor.cpp:2000
+#: ../src/LevelEditSelect.cpp:179 ../src/LevelEditSelect.cpp:219
+#: ../src/LevelEditSelect.cpp:267 ../src/TitleMenu.cpp:442
msgid "Cancel"
msgstr ""
-#: src/Functions.cpp:912
+#: ../src/Functions.cpp:988
msgid "Abort"
msgstr ""
-#: src/Functions.cpp:913 src/Functions.cpp:929
+#: ../src/Functions.cpp:989 ../src/Functions.cpp:1005
msgid "Retry"
msgstr ""
-#: src/Functions.cpp:914
+#: ../src/Functions.cpp:990
msgid "Ignore"
msgstr ""
-#: src/Functions.cpp:918 src/Functions.cpp:924
+#: ../src/Functions.cpp:994 ../src/Functions.cpp:1000
msgid "Yes"
msgstr ""
-#: src/Functions.cpp:919 src/Functions.cpp:925
+#: ../src/Functions.cpp:995 ../src/Functions.cpp:1001
msgid "No"
msgstr ""
-#. / TRANSLATORS: Filename is coming before this text
-#: src/Functions.cpp:1066
+# TRANSLATORS: Filename is coming before this text
+#: ../src/Functions.cpp:1142
#, c-format
msgid ""
"%s already exists.\n"
"Do you want to overwrite it?"
msgstr ""
-#: src/Functions.cpp:1066
+#: ../src/Functions.cpp:1142
msgid "Overwrite Prompt"
msgstr ""
-#: src/Functions.cpp:1087 src/Functions.cpp:1105
+#: ../src/Functions.cpp:1163 ../src/Functions.cpp:1181
#, c-format
msgid "Can't open file %s."
msgstr ""
-#: src/Functions.cpp:1087 src/Functions.cpp:1105
+#: ../src/Functions.cpp:1163 ../src/Functions.cpp:1181
msgid "Error"
msgstr ""
-#: src/Functions.cpp:1239
+#: ../src/Functions.cpp:1315
msgid "Save File"
msgstr ""
-#: src/Functions.cpp:1239
+#: ../src/Functions.cpp:1315
msgid "Load File"
msgstr ""
-#: src/Functions.cpp:1243
+#: ../src/Functions.cpp:1319
msgid "Search In"
msgstr ""
-#: src/Functions.cpp:1253
+#: ../src/Functions.cpp:1329
msgid "File Name"
msgstr ""
-#. / TRANSLATORS: Please do not remove %s or %d from your translation:
-#. / - %d means the level number in a levelpack
-#. / - %s means the name of current level
-#: src/Game.cpp:226 src/Game.cpp:821
+# TRANSLATORS: Please do not remove %s or %d from your translation:
+# - %d means the level number in a levelpack
+# - %s means the name of current level
+#: ../src/Game.cpp:226 ../src/Game.cpp:820
#, c-format
msgid "Level %d %s"
msgstr ""
-#. / TRANSLATORS: Please do not remove %s from your translation:
-#. / - %s will be replaced with current action key
-#: src/Game.cpp:649
+# TRANSLATORS: Please do not remove %s from your translation:
+# - %s will be replaced with current action key
+#: ../src/Game.cpp:647
#, c-format
msgid "Press %s key to save the game."
msgstr ""
-#. / TRANSLATORS: Please do not remove %s from your translation:
-#. / - %s will be replaced with current action key
-#: src/Game.cpp:654
+# TRANSLATORS: Please do not remove %s from your translation:
+# - %s will be replaced with current action key
+#: ../src/Game.cpp:652
#, c-format
msgid "Press %s key to swap the position of player and shadow."
msgstr ""
-#. / TRANSLATORS: Please do not remove %s from your translation:
-#. / - %s will be replaced with current action key
-#: src/Game.cpp:659
+# TRANSLATORS: Please do not remove %s from your translation:
+# - %s will be replaced with current action key
+#: ../src/Game.cpp:657
#, c-format
msgid "Press %s key to activate the switch."
msgstr ""
-#. / TRANSLATORS: Please do not remove %s from your translation:
-#. / - %s will be replaced with current action key
-#: src/Game.cpp:664
+# TRANSLATORS: Please do not remove %s from your translation:
+# - %s will be replaced with current action key
+#: ../src/Game.cpp:662
#, c-format
msgid "Press %s key to teleport."
msgstr ""
-#. / TRANSLATORS: Please do not remove %s from your translation:
-#. / - first %s means currently configured key to restart game
-#. / - Second %s means configured key to load from last save
-#: src/Game.cpp:705
+# TRANSLATORS: Please do not remove %s from your translation:
+# - first %s means currently configured key to restart game
+# - Second %s means configured key to load from last save
+#: ../src/Game.cpp:703
#, c-format
msgid "Press %s to restart current level or press %s to load the game."
msgstr ""
-#. / TRANSLATORS: Please do not remove %s from your translation:
-#. / - %s will be replaced with currently configured key to restart game
-#: src/Game.cpp:718
+# TRANSLATORS: Please do not remove %s from your translation:
+# - %s will be replaced with currently configured key to restart game
+#: ../src/Game.cpp:715
#, c-format
msgid "Press %s to restart current level."
msgstr ""
-#: src/Game.cpp:733
+#: ../src/Game.cpp:729
msgid "Your shadow has died."
msgstr ""
-#: src/Game.cpp:773
+#: ../src/Game.cpp:772
#, c-format
msgid "%d recordings"
msgstr ""
-#. / TRANSLATORS: This is caption for finished level
-#: src/Game.cpp:813
+# TRANSLATORS: This is caption for finished level
+#: ../src/Game.cpp:812
msgid "You've finished:"
msgstr ""
-#. / TRANSLATORS: Please do not remove %-.2f from your translation:
-#. / - %-.2f means time in seconds
-#. / - s is shortened form of a second. Try to keep it so.
-#: src/Game.cpp:969
+# TRANSLATORS: Please do not remove %-.2f from your translation:
+# - %-.2f means time in seconds
+# - s is shortened form of a second. Try to keep it so.
+#: ../src/Game.cpp:981
#, c-format
msgid "Time: %-.2fs"
msgstr ""
-#. / TRANSLATORS: Please do not remove %-.2f from your translation:
-#. / - %-.2f means time in seconds
-#. / - s is shortened form of a second. Try to keep it so.
-#: src/Game.cpp:975
+# TRANSLATORS: Please do not remove %-.2f from your translation:
+# - %-.2f means time in seconds
+# - s is shortened form of a second. Try to keep it so.
+#: ../src/Game.cpp:990
#, c-format
msgid "Best time: %-.2fs"
msgstr ""
-#: src/Game.cpp:982
+#: ../src/Game.cpp:1001
#, c-format
msgid "Target time: %-.2fs"
msgstr ""
-#. / TRANSLATORS: Please do not remove %d from your translation:
-#. / - %d means the number of recordings user has made
-#: src/Game.cpp:989
+# TRANSLATORS: Please do not remove %d from your translation:
+# - %d means the number of recordings user has made
+#: ../src/Game.cpp:1022
#, c-format
msgid "Recordings: %d"
msgstr ""
-#. / TRANSLATORS: Please do not remove %d from your translation:
-#. / - %d means the number of recordings user has made
-#: src/Game.cpp:994
+# TRANSLATORS: Please do not remove %d from your translation:
+# - %d means the number of recordings user has made
+#: ../src/Game.cpp:1030
#, c-format
msgid "Best recordings: %d"
msgstr ""
-#: src/Game.cpp:1000
+#: ../src/Game.cpp:1040
#, c-format
msgid "Target recordings: %d"
msgstr ""
-#. / TRANSLATORS: Please do not remove %s from your translation:
-#. / - %s will be replaced with name of a prize medal (gold, silver or bronze)
-#: src/Game.cpp:1007
+# TRANSLATORS: Please do not remove %s from your translation:
+# - %s will be replaced with name of a prize medal (gold, silver or bronze)
+#: ../src/Game.cpp:1053
#, c-format
msgid "You earned the %s medal"
msgstr ""
-#: src/Game.cpp:1007
+#: ../src/Game.cpp:1053
msgid "GOLD"
msgstr ""
-#: src/Game.cpp:1007
+#: ../src/Game.cpp:1053
msgid "SILVER"
msgstr ""
-#: src/Game.cpp:1007
+#: ../src/Game.cpp:1053
msgid "BRONZE"
msgstr ""
-#. / TRANSLATORS: used as return to the level selector menu
-#: src/Game.cpp:1018
+# TRANSLATORS: used as return to the level selector menu
+#: ../src/Game.cpp:1068
msgid "Menu"
msgstr ""
-#. / TRANSLATORS: used as restart level
-#: src/Game.cpp:1024
+# TRANSLATORS: used as restart level
+#: ../src/Game.cpp:1075 ../src/InputManager.cpp:41
msgid "Restart"
msgstr ""
-#. / TRANSLATORS: used as next level
-#: src/Game.cpp:1030
+# TRANSLATORS: used as next level
+#: ../src/Game.cpp:1082
msgid "Next"
msgstr ""
-#: src/Game.cpp:1057
+#: ../src/Game.cpp:1122
msgid "Game replay is done."
msgstr ""
-#: src/Game.cpp:1057
+#: ../src/Game.cpp:1122
msgid "Game Replay"
msgstr ""
-#: src/Game.cpp:1210 src/Game.cpp:1212
+#: ../src/Game.cpp:1275 ../src/Game.cpp:1277
msgid "Congratulations"
msgstr ""
-#: src/Game.cpp:1212
+#: ../src/Game.cpp:1277
msgid "You have finished the levelpack!"
msgstr ""
-#: src/InputManager.cpp:163 src/TitleMenu.cpp:410
+#: ../src/InputManager.cpp:40
+msgid "Up (in menu)"
+msgstr ""
+
+#: ../src/InputManager.cpp:40
+msgid "Down (in menu)"
+msgstr ""
+
+#: ../src/InputManager.cpp:40
+msgid "Left"
+msgstr ""
+
+#: ../src/InputManager.cpp:40
+msgid "Right"
+msgstr ""
+
+#: ../src/InputManager.cpp:40
+msgid "Jump"
+msgstr ""
+
+#: ../src/InputManager.cpp:40
+msgid "Action"
+msgstr ""
+
+#: ../src/InputManager.cpp:40
+msgid "Space (Record)"
+msgstr ""
+
+#: ../src/InputManager.cpp:41
+msgid "Escape"
+msgstr ""
+
+#: ../src/InputManager.cpp:41
+msgid "Tab (View shadow/Level prop.)"
+msgstr ""
+
+#: ../src/InputManager.cpp:41
+msgid "Save game (in editor)"
+msgstr ""
+
+#: ../src/InputManager.cpp:41
+msgid "Load game"
+msgstr ""
+
+#: ../src/InputManager.cpp:41
+msgid "Swap (in editor)"
+msgstr ""
+
+#: ../src/InputManager.cpp:42
+msgid "Teleport (in editor)"
+msgstr ""
+
+#: ../src/InputManager.cpp:42
+msgid "Suicide (in editor)"
+msgstr ""
+
+#: ../src/InputManager.cpp:42
+msgid "Shift (in editor)"
+msgstr ""
+
+#: ../src/InputManager.cpp:42
+msgid "Next block type (in Editor)"
+msgstr ""
+
+#: ../src/InputManager.cpp:43
+msgid "Previous block type (in editor)"
+msgstr ""
+
+#: ../src/InputManager.cpp:43
+msgid "Select (in menu)"
+msgstr ""
+
+#: ../src/InputManager.cpp:163 ../src/TitleMenu.cpp:430
msgid "Config Keys"
msgstr ""
-#: src/InputManager.cpp:166
+#: ../src/InputManager.cpp:166
msgid "Select an item and press a key to config it."
msgstr ""
-#: src/InputManager.cpp:179
+#: ../src/InputManager.cpp:179
msgid "Primary key"
msgstr ""
-#: src/InputManager.cpp:180
+#: ../src/InputManager.cpp:180
msgid "Alternative key"
msgstr ""
-#: src/InputManager.cpp:186
+#: ../src/InputManager.cpp:186
msgid "Unset the key"
msgstr ""
-#: src/InputManager.cpp:300
+#: ../src/InputManager.cpp:300
msgid "(Not set)"
msgstr ""
-#: src/LevelEditor.cpp:121
+#: ../src/LevelEditor.cpp:121
msgid "Toolbox"
msgstr ""
-#: src/LevelEditor.cpp:518
+#: ../src/LevelEditor.cpp:180
+msgid "Block"
+msgstr ""
+
+#: ../src/LevelEditor.cpp:180
+msgid "Player Start"
+msgstr ""
+
+#: ../src/LevelEditor.cpp:180
+msgid "Shadow Start"
+msgstr ""
+
+#: ../src/LevelEditor.cpp:181
+msgid "Exit"
+msgstr ""
+
+#: ../src/LevelEditor.cpp:181
+msgid "Shadow Block"
+msgstr ""
+
+#: ../src/LevelEditor.cpp:181
+msgid "Spikes"
+msgstr ""
+
+#: ../src/LevelEditor.cpp:182
+msgid "Checkpoint"
+msgstr ""
+
+#: ../src/LevelEditor.cpp:182 ../src/LevelEditSelect.cpp:258
+msgid "Swap"
+msgstr ""
+
+#: ../src/LevelEditor.cpp:182 ../src/LevelEditor.cpp:1976
+msgid "Fragile"
+msgstr ""
+
+#: ../src/LevelEditor.cpp:183
+msgid "Moving Block"
+msgstr ""
+
+#: ../src/LevelEditor.cpp:183
+msgid "Moving Shadow Block"
+msgstr ""
+
+#: ../src/LevelEditor.cpp:183
+msgid "Moving Spikes"
+msgstr ""
+
+#: ../src/LevelEditor.cpp:184
+msgid "Teleporter"
+msgstr ""
+
+#: ../src/LevelEditor.cpp:184 ../src/LevelEditor.cpp:1884
+msgid "Button"
+msgstr ""
+
+#: ../src/LevelEditor.cpp:184 ../src/LevelEditor.cpp:1886
+msgid "Switch"
+msgstr ""
+
+#: ../src/LevelEditor.cpp:185
+msgid "Conveyor Belt"
+msgstr ""
+
+#: ../src/LevelEditor.cpp:185
+msgid "Shadow Conveyor Belt"
+msgstr ""
+
+#: ../src/LevelEditor.cpp:185
+msgid "Notification Block"
+msgstr ""
+
+#: ../src/LevelEditor.cpp:185
+msgid "Collectable"
+msgstr ""
+
+#: ../src/LevelEditor.cpp:529
msgid "Are you sure you want to quit?"
msgstr ""
-#: src/LevelEditor.cpp:518
+#: ../src/LevelEditor.cpp:529
msgid "Quit prompt"
msgstr ""
-#: src/LevelEditor.cpp:946 src/LevelEditor.cpp:948 src/LevelEditor.cpp:2595
-#: src/LevelEditor.cpp:2597
+#: ../src/LevelEditor.cpp:957 ../src/LevelEditor.cpp:959
+#: ../src/LevelEditor.cpp:2609 ../src/LevelEditor.cpp:2611
#, c-format
msgid "Level \"%s\" saved"
msgstr ""
-#: src/LevelEditor.cpp:946 src/LevelEditor.cpp:948 src/LevelEditor.cpp:2595
-#: src/LevelEditor.cpp:2597
+#: ../src/LevelEditor.cpp:957 ../src/LevelEditor.cpp:959
+#: ../src/LevelEditor.cpp:2609 ../src/LevelEditor.cpp:2611
msgid "Saved"
msgstr ""
-#: src/LevelEditor.cpp:961 src/LevelEditor.cpp:2718
+#: ../src/LevelEditor.cpp:972 ../src/LevelEditor.cpp:2732
msgid "Level settings"
msgstr ""
-#: src/LevelEditor.cpp:965 src/LevelEditSelect.cpp:118
+#: ../src/LevelEditor.cpp:976 ../src/LevelEditSelect.cpp:154
msgid "Name:"
msgstr ""
-#: src/LevelEditor.cpp:971
+#: ../src/LevelEditor.cpp:982
msgid "Theme:"
msgstr ""
-#: src/LevelEditor.cpp:986
+#: ../src/LevelEditor.cpp:997
msgid "Target time (s):"
msgstr ""
-#: src/LevelEditor.cpp:997
+#: ../src/LevelEditor.cpp:1008
msgid "Target recordings:"
msgstr ""
-#: src/LevelEditor.cpp:1565 src/LevelEditor.cpp:1781
+#: ../src/LevelEditor.cpp:1576 ../src/LevelEditor.cpp:1793
msgid "Defined"
msgstr ""
-#: src/LevelEditor.cpp:1568 src/LevelEditor.cpp:1784 src/LevelEditor.cpp:1865
+#: ../src/LevelEditor.cpp:1579 ../src/LevelEditor.cpp:1796
+#: ../src/LevelEditor.cpp:1878
msgid "None"
msgstr ""
-#: src/LevelEditor.cpp:1575
+#: ../src/LevelEditor.cpp:1586
msgid "Moving block"
msgstr ""
-#: src/LevelEditor.cpp:1578
+#: ../src/LevelEditor.cpp:1589
msgid "Moving shadow block"
msgstr ""
-#: src/LevelEditor.cpp:1581
+#: ../src/LevelEditor.cpp:1592
msgid "Moving spikes"
msgstr ""
-#: src/LevelEditor.cpp:1588 src/LevelEditor.cpp:1724
+#: ../src/LevelEditor.cpp:1599 ../src/LevelEditor.cpp:1736
msgid "Enabled"
msgstr ""
-#: src/LevelEditor.cpp:1594
+#: ../src/LevelEditor.cpp:1605
msgid "Loop"
msgstr ""
-#: src/LevelEditor.cpp:1600
+#: ../src/LevelEditor.cpp:1611
msgid "Path"
msgstr ""
-#: src/LevelEditor.cpp:1659
+#: ../src/LevelEditor.cpp:1671
msgid "Notification block"
msgstr ""
-#: src/LevelEditor.cpp:1662
+#: ../src/LevelEditor.cpp:1674
msgid "Enter message here:"
msgstr ""
-#: src/LevelEditor.cpp:1716
+#: ../src/LevelEditor.cpp:1728
msgid "Shadow Conveyor belt"
msgstr ""
-#: src/LevelEditor.cpp:1718
+#: ../src/LevelEditor.cpp:1730
msgid "Conveyor belt"
msgstr ""
-#: src/LevelEditor.cpp:1730
+#: ../src/LevelEditor.cpp:1742
msgid "Enter speed here:"
msgstr ""
-#: src/LevelEditor.cpp:1788
+#: ../src/LevelEditor.cpp:1800
msgid "Portal"
msgstr ""
-#: src/LevelEditor.cpp:1791
+#: ../src/LevelEditor.cpp:1803
msgid "Activate on touch"
msgstr ""
-#: src/LevelEditor.cpp:1797 src/LevelEditor.cpp:1901
+#: ../src/LevelEditor.cpp:1809 ../src/LevelEditor.cpp:1914
msgid "Targets:"
msgstr ""
-#: src/LevelEditor.cpp:1871
-msgid "Button"
-msgstr ""
-
-#: src/LevelEditor.cpp:1873
-msgid "Switch"
+#: ../src/LevelEditor.cpp:1875
+#, c-format
+msgid "%d Defined"
msgstr ""
-#: src/LevelEditor.cpp:1878
+#: ../src/LevelEditor.cpp:1891
msgid "Behaviour:"
msgstr ""
-#: src/LevelEditor.cpp:1884
+#: ../src/LevelEditor.cpp:1897
msgid "On"
msgstr ""
-#: src/LevelEditor.cpp:1885
+#: ../src/LevelEditor.cpp:1898
msgid "Off"
msgstr ""
-#: src/LevelEditor.cpp:1886
+#: ../src/LevelEditor.cpp:1899
msgid "Toggle"
msgstr ""
-#: src/LevelEditor.cpp:1962
-msgid "Fragile"
-msgstr ""
-
-#: src/LevelEditor.cpp:1965
+#: ../src/LevelEditor.cpp:1979
msgid "State:"
msgstr ""
-#: src/LevelEditor.cpp:1971
+#: ../src/LevelEditor.cpp:1985
msgid "Complete"
msgstr ""
-#: src/LevelEditor.cpp:1972
+#: ../src/LevelEditor.cpp:1986
msgid "One step"
msgstr ""
-#: src/LevelEditor.cpp:1973
+#: ../src/LevelEditor.cpp:1987
msgid "Two steps"
msgstr ""
-#: src/LevelEditor.cpp:1974
+#: ../src/LevelEditor.cpp:1988
msgid "Gone"
msgstr ""
-#: src/LevelEditor.cpp:2703
+#: ../src/LevelEditor.cpp:2717
msgid "Select"
msgstr ""
-#: src/LevelEditor.cpp:2706
+#: ../src/LevelEditor.cpp:2720
msgid "Add"
msgstr ""
-#: src/LevelEditor.cpp:2709
+#: ../src/LevelEditor.cpp:2723
msgid "Delete"
msgstr ""
-#: src/LevelEditor.cpp:2712
+#: ../src/LevelEditor.cpp:2726
msgid "Configure"
msgstr ""
-#: src/LevelEditor.cpp:2715 src/LevelPlaySelect.cpp:49 src/TitleMenu.cpp:47
+#: ../src/LevelEditor.cpp:2729 ../src/LevelPlaySelect.cpp:65
+#: ../src/TitleMenu.cpp:47
msgid "Play"
msgstr ""
-#: src/LevelEditor.cpp:2721
+#: ../src/LevelEditor.cpp:2735
msgid "Save level"
msgstr ""
-#: src/LevelEditor.cpp:2724
+#: ../src/LevelEditor.cpp:2738
msgid "Back to menu"
msgstr ""
-#: src/LevelEditor.cpp:2770
+#: ../src/LevelEditor.cpp:2784
#, c-format
msgid "Movespeed: %s"
msgstr ""
-#: src/LevelEditSelect.cpp:41 src/TitleMenu.cpp:49
+#: ../src/LevelEditSelect.cpp:41 ../src/TitleMenu.cpp:49
msgid "Map Editor"
msgstr ""
-#: src/LevelEditSelect.cpp:49
+#: ../src/LevelEditSelect.cpp:78
msgid "New Levelpack"
msgstr ""
-#: src/LevelEditSelect.cpp:54
+#: ../src/LevelEditSelect.cpp:83
msgid "Pack Properties"
msgstr ""
-#: src/LevelEditSelect.cpp:59
+#: ../src/LevelEditSelect.cpp:88
msgid "Remove Pack"
msgstr ""
-#: src/LevelEditSelect.cpp:64
+#: ../src/LevelEditSelect.cpp:93
msgid "Move Map"
msgstr ""
-#: src/LevelEditSelect.cpp:70
+#: ../src/LevelEditSelect.cpp:99
msgid "Remove Map"
msgstr ""
-#: src/LevelEditSelect.cpp:75
+#: ../src/LevelEditSelect.cpp:104
msgid "Edit Map"
msgstr ""
-#: src/LevelEditSelect.cpp:115
+#: ../src/LevelEditSelect.cpp:151
msgid "Properties"
msgstr ""
-#: src/LevelEditSelect.cpp:125
+#: ../src/LevelEditSelect.cpp:161
msgid "Description:"
msgstr ""
-#: src/LevelEditSelect.cpp:132
+#: ../src/LevelEditSelect.cpp:168
msgid "Congratulation text:"
msgstr ""
-#: src/LevelEditSelect.cpp:167 src/LevelEditSelect.cpp:327
+#: ../src/LevelEditSelect.cpp:203 ../src/LevelEditSelect.cpp:371
msgid "Add level"
msgstr ""
-#: src/LevelEditSelect.cpp:170
+#: ../src/LevelEditSelect.cpp:206
msgid "File name:"
msgstr ""
-#: src/LevelEditSelect.cpp:207
+#: ../src/LevelEditSelect.cpp:243
msgid "Move level"
msgstr ""
-#: src/LevelEditSelect.cpp:210
+#: ../src/LevelEditSelect.cpp:246
msgid "Level: "
msgstr ""
-#: src/LevelEditSelect.cpp:214
-msgid "MoveLevel"
-msgstr ""
-
-#: src/LevelEditSelect.cpp:220
+#: ../src/LevelEditSelect.cpp:256
msgid "Before"
msgstr ""
-#: src/LevelEditSelect.cpp:221
+#: ../src/LevelEditSelect.cpp:257
msgid "After"
msgstr ""
-#: src/LevelEditSelect.cpp:222
-msgid "Swap"
-msgstr ""
-
-#: src/LevelEditSelect.cpp:395
+#: ../src/LevelEditSelect.cpp:439
msgid "Are you sure?"
msgstr ""
-#: src/LevelEditSelect.cpp:395
+#: ../src/LevelEditSelect.cpp:439
msgid "Remove prompt"
msgstr ""
-#: src/LevelEditSelect.cpp:535
+#: ../src/LevelEditSelect.cpp:579
msgid "No file name given for the new level."
msgstr ""
-#: src/LevelEditSelect.cpp:535
+#: ../src/LevelEditSelect.cpp:579
msgid "Missing file name"
msgstr ""
-#: src/LevelEditSelect.cpp:612
+#: ../src/LevelEditSelect.cpp:656
msgid "The entered level number isn't valid!"
msgstr ""
-#: src/LevelEditSelect.cpp:612
+#: ../src/LevelEditSelect.cpp:656
msgid "Illegal number"
msgstr ""
-#: src/LevelPlaySelect.cpp:43
+#: ../src/LevelPlaySelect.cpp:43
msgid "Select Level"
msgstr ""
-#: src/LevelPlaySelect.cpp:80
+#: ../src/LevelPlaySelect.cpp:92
msgid "Choose a level"
msgstr ""
-#: src/LevelPlaySelect.cpp:81 src/LevelPlaySelect.cpp:219
-#: src/LevelPlaySelect.cpp:230
+#: ../src/LevelPlaySelect.cpp:93 ../src/LevelPlaySelect.cpp:231
+#: ../src/LevelPlaySelect.cpp:242
msgid "Time:"
msgstr ""
-#: src/LevelPlaySelect.cpp:82 src/LevelPlaySelect.cpp:228
-#: src/LevelPlaySelect.cpp:231
+#: ../src/LevelPlaySelect.cpp:94 ../src/LevelPlaySelect.cpp:240
+#: ../src/LevelPlaySelect.cpp:243
msgid "Recordings:"
msgstr ""
-#: src/Main.cpp:56
+#: ../src/Main.cpp:56
#, c-format
msgid "Usage: %s [OPTIONS] ...\n"
msgstr ""
-#: src/Main.cpp:57
+#: ../src/Main.cpp:57
msgid "Available options:\n"
msgstr ""
-#: src/Main.cpp:58
+#: ../src/Main.cpp:58
msgid "Specifies the data directory."
msgstr ""
-#: src/Main.cpp:59
+#: ../src/Main.cpp:59
msgid "Specifies the user preferences directory."
msgstr ""
-#: src/Main.cpp:60
+#: ../src/Main.cpp:60
msgid "Run the game fullscreen."
msgstr ""
-#: src/Main.cpp:61
+#: ../src/Main.cpp:61
msgid "Run the game windowed."
msgstr ""
-#: src/Main.cpp:62
+#: ../src/Main.cpp:62
msgid "Set the music volume."
msgstr ""
-#: src/Main.cpp:63
+#: ../src/Main.cpp:63
msgid "Set the sound volume."
msgstr ""
-#: src/Main.cpp:64
+#: ../src/Main.cpp:64
msgid "Change a setting to a given value."
msgstr ""
-#: src/Main.cpp:65
+#: ../src/Main.cpp:65
msgid "Display the version and quit."
msgstr ""
-#: src/Main.cpp:66
+#: ../src/Main.cpp:66
msgid "Display this help message."
msgstr ""
-#: src/TitleMenu.cpp:48
+#: ../src/TitleMenu.cpp:48
msgid "Options"
msgstr ""
-#: src/TitleMenu.cpp:51
-msgid "Exit"
+#: ../src/TitleMenu.cpp:51
+msgid "Quit"
msgstr ""
-#: src/TitleMenu.cpp:109
+#: ../src/TitleMenu.cpp:109
msgid "Enable internet in order to install addons."
msgstr ""
-#: src/TitleMenu.cpp:109
+#: ../src/TitleMenu.cpp:109
msgid "Internet disabled"
msgstr ""
-#: src/TitleMenu.cpp:186
+#: ../src/TitleMenu.cpp:188
msgid "Settings"
msgstr ""
-#: src/TitleMenu.cpp:216
+#: ../src/TitleMenu.cpp:236
msgid "Music"
msgstr ""
-#: src/TitleMenu.cpp:224
+#: ../src/TitleMenu.cpp:244
msgid "Sound"
msgstr ""
-#: src/TitleMenu.cpp:232
+#: ../src/TitleMenu.cpp:252
msgid "Fullscreen"
msgstr ""
-#: src/TitleMenu.cpp:237
+#: ../src/TitleMenu.cpp:257
msgid "Resolution"
msgstr ""
-#: src/TitleMenu.cpp:319
+#: ../src/TitleMenu.cpp:339
msgid "Language"
msgstr ""
-#. / TRANSLATORS: as detect user's language automatically
-#: src/TitleMenu.cpp:328
+# TRANSLATORS: as detect user's language automatically
+#: ../src/TitleMenu.cpp:348
msgid "Auto-Detect"
msgstr ""
-#: src/TitleMenu.cpp:356
+#: ../src/TitleMenu.cpp:376
msgid "Theme"
msgstr ""
-#: src/TitleMenu.cpp:389
+#: ../src/TitleMenu.cpp:409
msgid "Level themes"
msgstr ""
-#: src/TitleMenu.cpp:394
+#: ../src/TitleMenu.cpp:414
msgid "Internet"
msgstr ""
-#: src/TitleMenu.cpp:400
+#: ../src/TitleMenu.cpp:420
msgid "Internet proxy"
msgstr ""
-#. / TRANSLATORS: Used for button which clear any level progress like unlocked levels and highscores.
-#: src/TitleMenu.cpp:417
+# TRANSLATORS: Used for button which clear any level progress like unlocked levels and highscores.
+#: ../src/TitleMenu.cpp:437
msgid "Clear Progress"
msgstr ""
-#: src/TitleMenu.cpp:427
+#: ../src/TitleMenu.cpp:447
msgid "Save Changes"
msgstr ""
-#: src/TitleMenu.cpp:539
+#: ../src/TitleMenu.cpp:546
msgid "Do you really want to reset level progress?"
msgstr ""
-#: src/TitleMenu.cpp:539
+#: ../src/TitleMenu.cpp:546
msgid "Warning"
msgstr ""
diff --git a/data/locale/zh_CN.po b/data/locale/zh_CN.po
index 403c268..cd266a1 100644
--- a/data/locale/zh_CN.po
+++ b/data/locale/zh_CN.po
@@ -1,834 +1,834 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: Me and my shadow\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2012-05-17 17:44+0300\n"
"PO-Revision-Date: 2012-05-18 22:02+0800\n"
"Last-Translator: acme_pjz <acme_pjz@hotmail.com>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: \n"
"X-Poedit-Language: Chinese\n"
"X-Poedit-Country: CHINA\n"
"X-Poedit-SourceCharset: utf-8\n"
"X-Poedit-Basepath: .\n"
"X-Poedit-SearchPath-0: F:\\Projects\\meandmyshadow\\src\n"
#: src/Addons.cpp:40
#: src/TitleMenu.cpp:50
msgid "Addons"
msgstr "附加组件"
#: src/Addons.cpp:59
msgid "Unable to initialize addon menu:"
msgstr "不能初始化附加组件菜单:"
#: src/Addons.cpp:67
#: src/Addons.cpp:98
#: src/LevelSelect.cpp:188
msgid "Back"
msgstr "后退"
#: src/Addons.cpp:80
msgid "Levels"
msgstr "关卡列表"
#: src/Addons.cpp:81
msgid "Level Packs"
msgstr "关卡包"
#: src/Addons.cpp:82
msgid "Themes"
msgstr "主题"
#: src/Addons.cpp:102
#: src/Addons.cpp:580
msgid "Install"
msgstr "安装"
#: src/Addons.cpp:106
msgid "Update"
msgstr "升级"
#: src/Addons.cpp:385
#: src/Addons.cpp:402
#: src/Addons.cpp:419
#: src/Addons.cpp:446
#: src/Addons.cpp:463
#: src/Addons.cpp:477
msgid "ERROR: Unable to download addon!"
msgstr "错误:无法下载附加组件"
#: src/Addons.cpp:385
#: src/Addons.cpp:402
#: src/Addons.cpp:419
#: src/Addons.cpp:446
#: src/Addons.cpp:463
#: src/Addons.cpp:477
msgid "ERROR:"
msgstr "错误:"
#: src/Addons.cpp:575
msgid "Uninstall"
msgstr "卸载"
#. / TRANSLATORS: Font used in GUI:
#. / - Use "knewave" for languages using Latin and Latin-derived alphabets
#. / - "freesans" can be used for non-Latin writing systems
#: src/Functions.cpp:383
#: src/Functions.cpp:384
msgid "knewave"
-msgstr "droidsans_final_fixed"
+msgstr "DroidSansFallback"
#. / TRANSLATORS: Font used for normal text:
#. / - Use "Blokletters-Viltstift" for languages using Latin and Latin-derived alphabets
#. / - "freesans" can be used for non-Latin writing systems
#: src/Functions.cpp:388
msgid "Blokletters-Viltstift"
-msgstr "droidsans_final_fixed"
+msgstr "DroidSansFallback"
#: src/Functions.cpp:907
#: src/Functions.cpp:934
#: src/Functions.cpp:1298
#: src/InputManager.cpp:196
#: src/LevelEditor.cpp:1006
#: src/LevelEditor.cpp:1618
#: src/LevelEditor.cpp:1675
#: src/LevelEditor.cpp:1738
#: src/LevelEditor.cpp:1817
#: src/LevelEditor.cpp:1922
#: src/LevelEditor.cpp:1982
#: src/LevelEditSelect.cpp:139
#: src/LevelEditSelect.cpp:179
#: src/LevelEditSelect.cpp:227
msgid "OK"
msgstr "确定"
#: src/Functions.cpp:908
#: src/Functions.cpp:920
#: src/Functions.cpp:930
#: src/Functions.cpp:1302
#: src/LevelEditor.cpp:1010
#: src/LevelEditor.cpp:1622
#: src/LevelEditor.cpp:1679
#: src/LevelEditor.cpp:1742
#: src/LevelEditor.cpp:1821
#: src/LevelEditor.cpp:1926
#: src/LevelEditor.cpp:1986
#: src/LevelEditSelect.cpp:143
#: src/LevelEditSelect.cpp:183
#: src/LevelEditSelect.cpp:231
#: src/TitleMenu.cpp:422
msgid "Cancel"
msgstr "取消"
#: src/Functions.cpp:912
msgid "Abort"
msgstr "终止"
#: src/Functions.cpp:913
#: src/Functions.cpp:929
msgid "Retry"
msgstr "重试"
#: src/Functions.cpp:914
msgid "Ignore"
msgstr "忽略"
#: src/Functions.cpp:918
#: src/Functions.cpp:924
msgid "Yes"
msgstr "是"
#: src/Functions.cpp:919
#: src/Functions.cpp:925
msgid "No"
msgstr "否"
#. / TRANSLATORS: Filename is coming before this text
#: src/Functions.cpp:1066
#, c-format
msgid ""
"%s already exists.\n"
"Do you want to overwrite it?"
msgstr ""
"%s 已经存在。\n"
"你是否想要覆盖它?"
#: src/Functions.cpp:1066
msgid "Overwrite Prompt"
msgstr "文件覆盖提示"
#: src/Functions.cpp:1087
#: src/Functions.cpp:1105
#, c-format
msgid "Can't open file %s."
msgstr "不能打开文件 %s。"
#: src/Functions.cpp:1087
#: src/Functions.cpp:1105
msgid "Error"
msgstr "错误"
#: src/Functions.cpp:1239
msgid "Save File"
msgstr "保存文件"
#: src/Functions.cpp:1239
msgid "Load File"
msgstr "打开文件"
#: src/Functions.cpp:1243
msgid "Search In"
msgstr "查找范围"
#: src/Functions.cpp:1253
msgid "File Name"
msgstr "文件名"
#. / TRANSLATORS: Please do not remove %s or %d from your translation:
#. / - %d means the level number in a levelpack
#. / - %s means the name of current level
#: src/Game.cpp:226
#: src/Game.cpp:821
#, c-format
msgid "Level %d %s"
msgstr "第 %d 关 %s"
#. / TRANSLATORS: Please do not remove %s from your translation:
#. / - %s will be replaced with current action key
#: src/Game.cpp:649
#, c-format
msgid "Press %s key to save the game."
msgstr "按 %s 键来保存游戏。"
#. / TRANSLATORS: Please do not remove %s from your translation:
#. / - %s will be replaced with current action key
#: src/Game.cpp:654
#, c-format
msgid "Press %s key to swap the position of player and shadow."
msgstr "按 %s 键交换你和阴影的位置。"
#. / TRANSLATORS: Please do not remove %s from your translation:
#. / - %s will be replaced with current action key
#: src/Game.cpp:659
#, c-format
msgid "Press %s key to activate the switch."
msgstr "按 %s 键来激活开关。"
#. / TRANSLATORS: Please do not remove %s from your translation:
#. / - %s will be replaced with current action key
#: src/Game.cpp:664
#, c-format
msgid "Press %s key to teleport."
msgstr "按 %s 键传送。"
#. / TRANSLATORS: Please do not remove %s from your translation:
#. / - first %s means currently configured key to restart game
#. / - Second %s means configured key to load from last save
#: src/Game.cpp:705
#, c-format
msgid "Press %s to restart current level or press %s to load the game."
msgstr "按 %s 键重新开始游戏,或者按 %s 键读取进度。"
#. / TRANSLATORS: Please do not remove %s from your translation:
#. / - %s will be replaced with currently configured key to restart game
#: src/Game.cpp:718
#, c-format
msgid "Press %s to restart current level."
msgstr "按 %s 键重新开始游戏。"
#: src/Game.cpp:733
msgid "Your shadow has died."
msgstr "你的阴影死掉了。"
#: src/Game.cpp:773
#, c-format
msgid "%d recordings"
msgstr "记录数 %d"
#. / TRANSLATORS: This is caption for finished level
#: src/Game.cpp:813
msgid "You've finished:"
msgstr "恭喜你完成了:"
#. / TRANSLATORS: Please do not remove %-.2f from your translation:
#. / - %-.2f means time in seconds
#. / - s is shortened form of a second. Try to keep it so.
#: src/Game.cpp:969
#, c-format
msgid "Time: %-.2fs"
msgstr "时间: %-.2f秒"
#. / TRANSLATORS: Please do not remove %-.2f from your translation:
#. / - %-.2f means time in seconds
#. / - s is shortened form of a second. Try to keep it so.
#: src/Game.cpp:975
#, c-format
msgid "Best time: %-.2fs"
msgstr "最佳时间: %-.2f秒"
#: src/Game.cpp:982
#, c-format
msgid "Target time: %-.2fs"
msgstr "目标时间: %-.2f秒"
#. / TRANSLATORS: Please do not remove %d from your translation:
#. / - %d means the number of recordings user has made
#: src/Game.cpp:989
#, c-format
msgid "Recordings: %d"
msgstr "记录次数: %d"
#. / TRANSLATORS: Please do not remove %d from your translation:
#. / - %d means the number of recordings user has made
#: src/Game.cpp:994
#, c-format
msgid "Best recordings: %d"
msgstr "最佳记录次数: %d"
#: src/Game.cpp:1000
#, c-format
msgid "Target recordings: %d"
msgstr "目标记录次数: %d"
#. / TRANSLATORS: Please do not remove %s from your translation:
#. / - %s will be replaced with name of a prize medal (gold, silver or bronze)
#: src/Game.cpp:1007
#, c-format
msgid "You earned the %s medal"
msgstr "你拿到了%s"
#: src/Game.cpp:1007
msgid "GOLD"
msgstr "金牌"
#: src/Game.cpp:1007
msgid "SILVER"
msgstr "银牌"
#: src/Game.cpp:1007
msgid "BRONZE"
msgstr "铜牌"
#. / TRANSLATORS: used as return to the level selector menu
#: src/Game.cpp:1018
msgid "Menu"
msgstr "菜单"
#. / TRANSLATORS: used as restart level
#: src/Game.cpp:1024
msgid "Restart"
msgstr "重新开始"
#. / TRANSLATORS: used as next level
#: src/Game.cpp:1030
msgid "Next"
msgstr "下一关"
#: src/Game.cpp:1057
msgid "Game replay is done."
msgstr "游戏重放已经完成。"
#: src/Game.cpp:1057
msgid "Game Replay"
msgstr "游戏重放"
#: src/Game.cpp:1210
#: src/Game.cpp:1212
msgid "Congratulations"
msgstr "恭喜你"
#: src/Game.cpp:1212
msgid "You have finished the levelpack!"
msgstr "你已经完成了整个关卡包!"
#: src/InputManager.cpp:163
#: src/TitleMenu.cpp:410
msgid "Config Keys"
msgstr "设置按键"
#: src/InputManager.cpp:166
msgid "Select an item and press a key to config it."
msgstr "选择一个项目,然后按键进行设置。"
#: src/InputManager.cpp:179
msgid "Primary key"
msgstr "主按键"
#: src/InputManager.cpp:180
msgid "Alternative key"
msgstr "辅助按键"
#: src/InputManager.cpp:186
msgid "Unset the key"
msgstr "取消设置"
#: src/InputManager.cpp:300
msgid "(Not set)"
msgstr "(未设置)"
#: src/LevelEditor.cpp:121
msgid "Toolbox"
msgstr "工具箱"
#: src/LevelEditor.cpp:518
msgid "Are you sure you want to quit?"
msgstr "你确定要退出吗?"
#: src/LevelEditor.cpp:518
msgid "Quit prompt"
msgstr "退出提示"
#: src/LevelEditor.cpp:946
#: src/LevelEditor.cpp:948
#: src/LevelEditor.cpp:2595
#: src/LevelEditor.cpp:2597
#, c-format
msgid "Level \"%s\" saved"
msgstr "关卡“%s”已保存"
#: src/LevelEditor.cpp:946
#: src/LevelEditor.cpp:948
#: src/LevelEditor.cpp:2595
#: src/LevelEditor.cpp:2597
msgid "Saved"
msgstr "已保存"
#: src/LevelEditor.cpp:961
#: src/LevelEditor.cpp:2718
msgid "Level settings"
msgstr "关卡设置"
#: src/LevelEditor.cpp:965
#: src/LevelEditSelect.cpp:118
msgid "Name:"
msgstr "名称:"
#: src/LevelEditor.cpp:971
msgid "Theme:"
msgstr "主题:"
#: src/LevelEditor.cpp:986
msgid "Target time (s):"
msgstr "目标时间(秒):"
#: src/LevelEditor.cpp:997
msgid "Target recordings:"
msgstr "目标记录数:"
#: src/LevelEditor.cpp:1565
#: src/LevelEditor.cpp:1781
msgid "Defined"
msgstr "已设置"
#: src/LevelEditor.cpp:1568
#: src/LevelEditor.cpp:1784
#: src/LevelEditor.cpp:1865
msgid "None"
msgstr "无"
#: src/LevelEditor.cpp:1575
msgid "Moving block"
msgstr "移动砖块"
#: src/LevelEditor.cpp:1578
msgid "Moving shadow block"
msgstr "移动阴影砖块"
#: src/LevelEditor.cpp:1581
msgid "Moving spikes"
msgstr "移动的刺"
#: src/LevelEditor.cpp:1588
#: src/LevelEditor.cpp:1724
msgid "Enabled"
msgstr "启用"
#: src/LevelEditor.cpp:1594
msgid "Loop"
msgstr "循环"
#: src/LevelEditor.cpp:1600
msgid "Path"
msgstr "路径"
#: src/LevelEditor.cpp:1659
msgid "Notification block"
msgstr "消息方块"
#: src/LevelEditor.cpp:1662
msgid "Enter message here:"
msgstr "输入消息:"
#: src/LevelEditor.cpp:1716
msgid "Shadow Conveyor belt"
msgstr "阴影传送带"
#: src/LevelEditor.cpp:1718
msgid "Conveyor belt"
msgstr "传送带"
#: src/LevelEditor.cpp:1730
msgid "Enter speed here:"
msgstr "输入速度:"
#: src/LevelEditor.cpp:1788
msgid "Portal"
msgstr "传送门"
#: src/LevelEditor.cpp:1791
msgid "Activate on touch"
msgstr "接触时传送"
#: src/LevelEditor.cpp:1797
#: src/LevelEditor.cpp:1901
msgid "Targets:"
msgstr "目标:"
#: src/LevelEditor.cpp:1871
msgid "Button"
msgstr "按钮:"
#: src/LevelEditor.cpp:1873
msgid "Switch"
msgstr "开关:"
#: src/LevelEditor.cpp:1878
msgid "Behaviour:"
msgstr "行为:"
#: src/LevelEditor.cpp:1884
msgid "On"
msgstr "开启"
#: src/LevelEditor.cpp:1885
msgid "Off"
msgstr "关闭"
#: src/LevelEditor.cpp:1886
msgid "Toggle"
msgstr "切换"
#: src/LevelEditor.cpp:1962
msgid "Fragile"
msgstr "易碎砖块"
#: src/LevelEditor.cpp:1965
msgid "State:"
msgstr "状态:"
#: src/LevelEditor.cpp:1971
msgid "Complete"
msgstr "完整的"
#: src/LevelEditor.cpp:1972
msgid "One step"
msgstr "踩了一次"
#: src/LevelEditor.cpp:1973
msgid "Two steps"
msgstr "踩了两次"
#: src/LevelEditor.cpp:1974
msgid "Gone"
msgstr "已经破碎"
#: src/LevelEditor.cpp:2703
msgid "Select"
msgstr "选择"
#: src/LevelEditor.cpp:2706
msgid "Add"
msgstr "添加"
#: src/LevelEditor.cpp:2709
msgid "Delete"
msgstr "删除"
#: src/LevelEditor.cpp:2712
msgid "Configure"
msgstr "设置"
#: src/LevelEditor.cpp:2715
#: src/LevelPlaySelect.cpp:49
#: src/TitleMenu.cpp:47
msgid "Play"
msgstr "开始游戏"
#: src/LevelEditor.cpp:2721
msgid "Save level"
msgstr "保存关卡"
#: src/LevelEditor.cpp:2724
msgid "Back to menu"
msgstr "回主菜单"
#: src/LevelEditor.cpp:2770
#, c-format
msgid "Movespeed: %s"
msgstr "移动速度: %s"
#: src/LevelEditSelect.cpp:41
#: src/TitleMenu.cpp:49
msgid "Map Editor"
msgstr "地图编辑器"
#: src/LevelEditSelect.cpp:49
msgid "New Levelpack"
msgstr "新建关卡包"
#: src/LevelEditSelect.cpp:54
msgid "Pack Properties"
msgstr "关卡包属性"
#: src/LevelEditSelect.cpp:59
msgid "Remove Pack"
msgstr "删除关卡包"
#: src/LevelEditSelect.cpp:64
msgid "Move Map"
msgstr "移动地图"
#: src/LevelEditSelect.cpp:70
msgid "Remove Map"
msgstr "删除地图"
#: src/LevelEditSelect.cpp:75
msgid "Edit Map"
msgstr "编辑地图"
#: src/LevelEditSelect.cpp:115
msgid "Properties"
msgstr "属性"
#: src/LevelEditSelect.cpp:125
msgid "Description:"
msgstr "描述:"
#: src/LevelEditSelect.cpp:132
msgid "Congratulation text:"
msgstr "完成提示:"
#: src/LevelEditSelect.cpp:167
#: src/LevelEditSelect.cpp:327
msgid "Add level"
msgstr "增加关卡"
#: src/LevelEditSelect.cpp:170
msgid "File name:"
msgstr "文件名:"
#: src/LevelEditSelect.cpp:207
msgid "Move level"
msgstr "移动关卡"
#: src/LevelEditSelect.cpp:210
msgid "Level: "
msgstr "关卡:"
#: src/LevelEditSelect.cpp:214
msgid "MoveLevel"
msgstr "移动关卡"
#: src/LevelEditSelect.cpp:220
msgid "Before"
msgstr "之前"
#: src/LevelEditSelect.cpp:221
msgid "After"
msgstr "之后"
#: src/LevelEditSelect.cpp:222
msgid "Swap"
msgstr "交换"
#: src/LevelEditSelect.cpp:395
msgid "Are you sure?"
msgstr "你确定吗?"
#: src/LevelEditSelect.cpp:395
msgid "Remove prompt"
msgstr "删除提示"
#: src/LevelEditSelect.cpp:535
msgid "No file name given for the new level."
msgstr "没有给新关卡指定文件名。"
#: src/LevelEditSelect.cpp:535
msgid "Missing file name"
msgstr "文件名未指定"
#: src/LevelEditSelect.cpp:612
msgid "The entered level number isn't valid!"
msgstr "输入的关卡编号无效!"
#: src/LevelEditSelect.cpp:612
msgid "Illegal number"
msgstr "无效编号"
#: src/LevelPlaySelect.cpp:43
msgid "Select Level"
msgstr "选择关卡"
#: src/LevelPlaySelect.cpp:80
msgid "Choose a level"
msgstr "选择一个关卡"
#: src/LevelPlaySelect.cpp:81
#: src/LevelPlaySelect.cpp:219
#: src/LevelPlaySelect.cpp:230
msgid "Time:"
msgstr "时间:"
#: src/LevelPlaySelect.cpp:82
#: src/LevelPlaySelect.cpp:228
#: src/LevelPlaySelect.cpp:231
msgid "Recordings:"
msgstr "记录次数:"
#: src/Main.cpp:56
#, c-format
msgid "Usage: %s [OPTIONS] ...\n"
msgstr "使用方法: %s [选项] ...\n"
#: src/Main.cpp:57
msgid "Available options:\n"
msgstr "可用的选项:\n"
#: src/Main.cpp:58
msgid "Specifies the data directory."
msgstr "指定数据文件夹。"
#: src/Main.cpp:59
msgid "Specifies the user preferences directory."
msgstr "指定用户设置文件夹。"
#: src/Main.cpp:60
msgid "Run the game fullscreen."
msgstr "使游戏运行在全屏幕模式。"
#: src/Main.cpp:61
msgid "Run the game windowed."
msgstr "使游戏运行在窗口模式。"
#: src/Main.cpp:62
msgid "Set the music volume."
msgstr "设置音乐音量。"
#: src/Main.cpp:63
msgid "Set the sound volume."
msgstr "设置音效音量。"
#: src/Main.cpp:64
msgid "Change a setting to a given value."
msgstr "修改一个设置为指定值。"
#: src/Main.cpp:65
msgid "Display the version and quit."
msgstr "显示程序版本并退出。"
#: src/Main.cpp:66
msgid "Display this help message."
msgstr "显示这个帮助信息。"
#: src/TitleMenu.cpp:48
msgid "Options"
msgstr "选项"
#: src/TitleMenu.cpp:51
msgid "Exit"
msgstr "退出"
#: src/TitleMenu.cpp:109
msgid "Enable internet in order to install addons."
msgstr "启用网络访问,才能下载附加组件。"
#: src/TitleMenu.cpp:109
msgid "Internet disabled"
msgstr "网络已禁用"
#: src/TitleMenu.cpp:186
msgid "Settings"
msgstr "选项"
#: src/TitleMenu.cpp:216
msgid "Music"
msgstr "音乐"
#: src/TitleMenu.cpp:224
msgid "Sound"
msgstr "音效"
#: src/TitleMenu.cpp:232
msgid "Fullscreen"
msgstr "全屏幕"
#: src/TitleMenu.cpp:237
msgid "Resolution"
msgstr "分辨率"
#: src/TitleMenu.cpp:319
msgid "Language"
msgstr "语言"
#. / TRANSLATORS: as detect user's language automatically
#: src/TitleMenu.cpp:328
msgid "Auto-Detect"
msgstr "自动检测"
#: src/TitleMenu.cpp:356
msgid "Theme"
msgstr "主题"
#: src/TitleMenu.cpp:389
msgid "Level themes"
msgstr "默认主题"
#: src/TitleMenu.cpp:394
msgid "Internet"
msgstr "网络"
#: src/TitleMenu.cpp:400
msgid "Internet proxy"
msgstr "网络代理"
#. / TRANSLATORS: Used for button which clear any level progress like unlocked levels and highscores.
#: src/TitleMenu.cpp:417
msgid "Clear Progress"
msgstr "清除进度"
#: src/TitleMenu.cpp:427
msgid "Save Changes"
msgstr "保存变更"
#: src/TitleMenu.cpp:539
msgid "Do you really want to reset level progress?"
msgstr "你确定要清除游戏进度吗?"
#: src/TitleMenu.cpp:539
msgid "Warning"
msgstr "警告"
#~ msgid "Restart needed before the changes have effect."
#~ msgstr "重新启动游戏才能使新的选项生效。"
#~ msgid "Restart needed"
#~ msgstr "需要重新启动"
#~ msgid "Can't open file %d."
#~ msgstr "不能打开文件 %d。"
#~ msgid ""
#~ "Can't load level pack:\n"
#~ "%s"
#~ msgstr ""
#~ "无法打开关卡包:\n"
#~ "%s"
diff --git a/src/Functions.cpp b/src/Functions.cpp
index a90ca2c..044a8fe 100644
--- a/src/Functions.cpp
+++ b/src/Functions.cpp
@@ -1,1403 +1,1403 @@
/****************************************************************************
** Copyright (C) 2011 Luka Horvat <redreaper132 at gmail.com>
** Copyright (C) 2011 Edward Lii <edward_iii at myway.com>
** Copyright (C) 2011 O. Bahri Gordebak <gordebak at gmail.com>
**
**
** This file may be used under the terms of the GNU General Public
** License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#include <stdio.h>
#include <SDL/SDL.h>
#include <SDL/SDL_mixer.h>
#include <SDL/SDL_gfxPrimitives.h>
#include <SDL/SDL_rotozoom.h>
#include <SDL/SDL_syswm.h>
#include <string>
#include "Globals.h"
#include "Functions.h"
#include "FileManager.h"
#include "Objects.h"
#include "Player.h"
#include "GameObjects.h"
#include "LevelPack.h"
#include "TitleMenu.h"
#include "LevelEditSelect.h"
#include "LevelEditor.h"
#include "Game.h"
#include "LevelPlaySelect.h"
#include "Addons.h"
#include "ImageManager.h"
#include "MusicManager.h"
#include "LevelPackManager.h"
#include "ThemeManager.h"
#include "GUIListBox.h"
#include "libs/tinyformat/tinyformat.h"
#include "libs/tinygettext/tinygettext.hpp"
extern "C" {
#include "libs/findlocale/findlocale.h"
}
#ifdef HARDWARE_ACCELERATION
#include <GL/gl.h>
#include <GL/glu.h>
//fix some Windows header bug
#ifndef GL_BGR
#define GL_BGR GL_BGR_EXT
#endif
#ifndef GL_BGRA
#define GL_BGRA GL_BGRA_EXT
#endif
#endif
using namespace std;
#ifdef WIN32
#include <windows.h>
#include <shlobj.h>
#else
#include <strings.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <dirent.h>
#endif
//Workaround for the resizing below 800x600 for X systems.
#ifdef __linux__
#include<X11/Xlib.h>
#include<X11/Xutil.h>
#endif
//Initialise the imagemanager.
//The ImageManager is used to prevent loading images multiple times.
ImageManager imageManager;
//Initialise the musicManager.
//The MusicManager is used to prevent loading music files multiple times and for playing/fading music.
MusicManager musicManager;
//Initialise the levelPackManager.
//The LevelPackManager is used to prevent loading levelpacks multiple times and for the game to know which levelpacks there are.
LevelPackManager levelPackManager;
//Map containing changed settings using command line arguments.
map<string,string> tmpSettings;
//Pointer to the settings object.
//It is used to load and save the settings file and change the settings.
Settings* settings=0;
#ifdef HARDWARE_ACCELERATION
GLuint screenTexture;
#endif
SDL_Surface* loadImage(string file){
//We use the imageManager to load the file.
return imageManager.loadImage(file);
}
void applySurface(int x,int y,SDL_Surface* source,SDL_Surface* dest,SDL_Rect* clip){
//The offset is needed to draw at the right location.
SDL_Rect offset;
offset.x=x;
offset.y=y;
//Let SDL do the drawing of the surface.
SDL_BlitSurface(source,clip,dest,&offset);
}
void drawRect(int x,int y,int w,int h,SDL_Surface* dest,Uint32 color){
//NOTE: We let SDL_gfx render it.
rectangleRGBA(dest,x,y,x+w,y+h,color >> 24,color >> 16,color >> 8,255);
}
//Draw a box with anti-aliased borders using SDL_gfx.
void drawGUIBox(int x,int y,int w,int h,SDL_Surface* dest,Uint32 color){
//Fill content's background color from function parameter
boxRGBA(dest,x+1,y+1,x+w-2,y+h-2,color >> 24,color >> 16,color >> 8,color >> 0);
//Draw first black borders around content and leave 1 pixel in every corner
lineRGBA(dest,x+1,y,x+w-2,y,0,0,0,255);
lineRGBA(dest,x+1,y+h-1,x+w-2,y+h-1,0,0,0,255);
lineRGBA(dest,x,y+1,x,y+h-2,0,0,0,255);
lineRGBA(dest,x+w-1,y+1,x+w-1,y+h-2,0,0,0,255);
//Fill the corners with transperent color to create anti-aliased borders
pixelRGBA(dest,x,y,0,0,0,160);
pixelRGBA(dest,x,y+h-1,0,0,0,160);
pixelRGBA(dest,x+w-1,y,0,0,0,160);
pixelRGBA(dest,x+w-1,y+h-1,0,0,0,160);
//Draw second lighter border around content
rectangleRGBA(dest,x+1,y+1,x+w-2,y+h-2,0,0,0,64);
//Create anti-aliasing in corners of second border
pixelRGBA(dest,x+1,y+1,0,0,0,50);
pixelRGBA(dest,x+1,y+h-2,0,0,0,50);
pixelRGBA(dest,x+w-2,y+1,0,0,0,50);
pixelRGBA(dest,x+w-2,y+h-2,0,0,0,50);
}
void drawLine(int x1,int y1,int x2,int y2,SDL_Surface* dest,Uint32 color){
//NOTE: We let SDL_gfx render it.
lineRGBA(dest,x1,y1,x2,y2,color >> 24,color >> 16,color >> 8,255);
}
void drawLineWithArrow(int x1,int y1,int x2,int y2,SDL_Surface* dest,Uint32 color,int spacing,int offset,int xsize,int ysize){
//Draw line first
drawLine(x1,y1,x2,y2,dest,color);
//calc delta and length
double dx=x2-x1;
double dy=y2-y1;
double length=sqrt(dx*dx+dy*dy);
if(length<0.001) return;
//calc the unit vector
dx/=length; dy/=length;
//Now draw arrows on it
for(double p=offset;p<length;p+=spacing){
drawLine(int(x1+p*dx+0.5),int(y1+p*dy+0.5),
int(x1+(p-xsize)*dx-ysize*dy+0.5),int(y1+(p-xsize)*dy+ysize*dx+0.5),dest,color);
drawLine(int(x1+p*dx+0.5),int(y1+p*dy+0.5),
int(x1+(p-xsize)*dx+ysize*dy+0.5),int(y1+(p-xsize)*dy-ysize*dx+0.5),dest,color);
}
}
bool createScreen(){
//Set the screen_width and height.
SCREEN_WIDTH=atoi(settings->getValue("width").c_str());
SCREEN_HEIGHT=atoi(settings->getValue("height").c_str());
//Update the camera.
camera.w=SCREEN_WIDTH;
camera.h=SCREEN_HEIGHT;
//Boolean if this is the first screen creation.
bool initial=true;
//Check if we should use gl or software rendering.
if(settings->getBoolValue("gl")){
#ifdef HARDWARE_ACCELERATION
SDL_GL_SetAttribute(SDL_GL_RED_SIZE,8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE,8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,16);
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE,32);
SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE,8);
SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE,8);
SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE,8);
SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE,8);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS,0);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);
//Set the video mode.
Uint32 flags=SDL_HWSURFACE | SDL_OPENGL;
if(settings->getBoolValue("fullscreen"))
flags|=SDL_FULLSCREEN;
else if(settings->getBoolValue("resizable"))
flags|=SDL_RESIZABLE;
if(SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,flags)==NULL){
fprintf(stderr,"FATAL ERROR: SDL_SetVideoMode failed\n");
return false;
}
//Delete the old screen.
//Warning: only if previous mode is OpenGL mode.
//NOTE: The previous mode can't switch during runtime.
if(screen){
SDL_FreeSurface(screen);
screen=NULL;
//There was a screen so this isn't the initial screen creation.
initial=false;
}
//Create a screen
screen=SDL_CreateRGBSurface(SDL_HWSURFACE,SCREEN_WIDTH,SCREEN_HEIGHT,32,0x00FF0000,0x0000FF00,0x000000FF,0);
//Create a texture.
glDeleteTextures(1,&screenTexture);
glGenTextures(1,&screenTexture);
//And set up gl correctly.
glClearColor(0, 0, 0, 0);
glClearDepth(1.0f);
glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 1, -1);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_TEXTURE_2D);
glLoadIdentity();
#else
//NOTE: Hardware accelerated rendering requested but compiled without.
cerr<<"FATAL ERROR: Unable to use hardware acceleration (compiled without)."<<endl;
return false;
#endif
}else{
//Set the flags.
Uint32 flags=SDL_HWSURFACE | SDL_DOUBLEBUF;
if(settings->getBoolValue("fullscreen"))
flags|=SDL_FULLSCREEN;
else if(settings->getBoolValue("resizable"))
flags|=SDL_RESIZABLE;
//Check if there already was a screen.
if(screen)
initial=false;
//Create the screen and check if there weren't any errors.
screen=SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,flags);
if(screen==NULL){
fprintf(stderr,"FATAL ERROR: SDL_SetVideoMode failed\n");
return false;
}
}
//Now configure the newly created window.
configureWindow(initial);
//Create the temp surface, just a replica of the screen surface, free the previous one if any.
if(tempSurface)
SDL_FreeSurface(tempSurface);
tempSurface=SDL_CreateRGBSurface(SDL_HWSURFACE|SDL_SRCALPHA,
screen->w,screen->h,screen->format->BitsPerPixel,
screen->format->Rmask,screen->format->Gmask,screen->format->Bmask,0);
//Set the the window caption.
SDL_WM_SetCaption(("Me and My Shadow "+version).c_str(),NULL);
SDL_EnableUNICODE(1);
//Nothing went wrong so return true.
return true;
}
void configureWindow(bool initial){
//We only need to configure the window if it's resizable.
if(!getSettings()->getBoolValue("resizable"))
return;
//Retrieve the WM info from SDL containing the window handle.
struct SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);
SDL_GetWMInfo(&wmInfo);
#ifdef __linux__
//We assume that a linux system running meandmyshadow is also running an Xorg server.
if(wmInfo.subsystem==SDL_SYSWM_X11){
//Create the size hints to give to the window.
XSizeHints* sizeHints;
if(!(sizeHints=XAllocSizeHints())){
cerr<<"ERROR: Unable to allocate memory for XSizeHings."<<endl;
return;
}
//Configure the size hint.
sizeHints->flags=PMinSize;
sizeHints->min_width=800;
sizeHints->min_height=600;
//Set the normal hints of the window.
(void)wmInfo.info.x11.lock_func;
XSetNormalHints(wmInfo.info.x11.display,wmInfo.info.x11.wmwindow,sizeHints);
(void)wmInfo.info.x11.unlock_func;
}else{
//No X11 so an unsupported window manager.
cerr<<"WARNING: Unsupported window manager."<<endl;
}
#elif defined(WIN32)
//TODO: Add windows code
#endif
}
void onVideoResize(){
//Check if the resize event isn't malformd
if(event.resize.w<=0 || event.resize.h<=0)
return;
//Check the size limit
if(event.resize.w<800)
event.resize.w=800;
if(event.resize.h<600)
event.resize.h=600;
//Check if it really resizes
if(SCREEN_WIDTH==event.resize.w && SCREEN_HEIGHT==event.resize.h) return;
char s[32];
//Set the new width and height
sprintf(s,"%d",event.resize.w);
getSettings()->setValue("width",s);
sprintf(s,"%d",event.resize.h);
getSettings()->setValue("height",s);
//Do resizing
if(!createScreen()) return;
//Tell the theme to resize
if(!loadTheme()) return;
//The new resolution is valid.
//Now we can save the settings. (TODO: should we save?)
//saveSettings();
//And let the currentState update it's GUI to the new resolution.
currentState->resize();
}
bool init(){
//Initialze SDL.
if(SDL_Init(SDL_INIT_EVERYTHING)==-1) {
fprintf(stderr,"FATAL ERROR: SDL_Init failed\n");
return false;
}
//Initialze SDL_mixer (audio).
if(Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT,2,512)==-1){
fprintf(stderr,"FATAL ERROR: Mix_OpenAudio failed\n");
return false;
}
//Set the volume.
Mix_Volume(-1,atoi(settings->getValue("sound").c_str()));
//Initialze SDL_ttf (fonts).
if(TTF_Init()==-1){
fprintf(stderr,"FATAL ERROR: TTF_Init failed\n");
return false;
}
//Create the screen.
if(!createScreen())
return false;
//Init tinygettext for translations for the right language
dictionaryManager = new tinygettext::DictionaryManager();
dictionaryManager->add_directory(getDataPath()+"locale");
dictionaryManager->set_charset("UTF-8");
//Check if user have defined own language. If not, find it out for the player using findlocale
string lang=getSettings()->getValue("lang");
if(lang.length()>0){
printf("Locale set by user to %s\n",lang.c_str());
language=lang;
}else{
FL_Locale *locale;
FL_FindLocale(&locale,FL_MESSAGES);
printf("Locale isn't set by user: %s\n",locale->lang);
language=locale->lang;
if(locale->country!=NULL){
language+=string("_")+string(locale->country);
}
if(locale->variant!=NULL){
language+=string("@")+string(locale->variant);
}
FL_FreeLocale(&locale);
}
//Now set the language in the dictionaryManager.
dictionaryManager->set_language(tinygettext::Language::from_name(language));
//Create the types of blocks.
for(int i=0;i<TYPE_MAX;i++){
Game::blockNameMap[Game::blockName[i]]=i;
}
//Nothing went wrong so we return true.
return true;
}
static TTF_Font* loadFont(const char* name,int size){
TTF_Font* tmpFont=TTF_OpenFont((getDataPath()+"font/"+name+".ttf").c_str(),size);
if(tmpFont){
return tmpFont;
}else{
- return TTF_OpenFont((getDataPath()+"font/freesans.ttf").c_str(),size);
+ return TTF_OpenFont((getDataPath()+"font/DroidSansFallback.ttf").c_str(),size);
}
}
bool loadFonts(){
//Load the fonts.
//NOTE: This is a separate method because it will be called separately when re-initing in case of language change.
//First close the fonts if needed.
if(!fontTitle)
TTF_CloseFont(fontTitle);
if(!fontGUI)
TTF_CloseFont(fontGUI);
if(!fontGUISmall)
TTF_CloseFont(fontGUISmall);
if(!fontText)
TTF_CloseFont(fontText);
/// TRANSLATORS: Font used in GUI:
/// - Use "knewave" for languages using Latin and Latin-derived alphabets
- /// - "freesans" can be used for non-Latin writing systems
+ /// - "DroidSansFallback" can be used for non-Latin writing systems
fontTitle=loadFont(_("knewave"),55);
fontGUI=loadFont(_("knewave"),32);
fontGUISmall=loadFont(_("knewave"),24);
/// TRANSLATORS: Font used for normal text:
/// - Use "Blokletters-Viltstift" for languages using Latin and Latin-derived alphabets
- /// - "freesans" can be used for non-Latin writing systems
+ /// - "DroidSansFallback" can be used for non-Latin writing systems
fontText=loadFont(_("Blokletters-Viltstift"),16);
if(fontTitle==NULL || fontGUI==NULL || fontGUISmall==NULL || fontText==NULL){
printf("ERROR: Unable to load fonts! \n");
return false;
}
//Nothing went wrong so return true.
return true;
}
bool loadTheme(){
SDL_Surface *surface;
//Load the menu background.
surface=loadImage(getDataPath()+"gfx/menu/background.png");
if(surface==NULL){
printf("ERROR: Unable to load menu background.\n");
return false;
}
//Check if previous background exists and it's not cached by image manager
if(menuBackground!=NULL && menuBackground!=surface){
SDL_FreeSurface(menuBackground);
}
menuBackground=surface;
//Check if the menu background needs to be scaled.
if(menuBackground->w!=SCREEN_WIDTH || menuBackground->h!=SCREEN_HEIGHT){
menuBackground=zoomSurface(menuBackground,double(SCREEN_WIDTH)/double(menuBackground->w),double(SCREEN_HEIGHT)/double(menuBackground->h),0);
}
//Load the default theme, if it isn't loaded already.
if(objThemes.themeCount()==0){
if(objThemes.appendThemeFromFile(getDataPath()+"themes/Cloudscape/theme.mnmstheme")==NULL){
printf("ERROR: Can't load default theme file\n");
return false;
}
}else{
//Let the themes scale to the new resolution.
objThemes.scaleToScreen();
}
//Everything went fine so return true.
return true;
}
bool loadFiles(){
//Load the music and play it.
if(musicManager.loadMusic((getDataPath()+"music/menu.music")).empty()){
printf("WARNING: Unable to load background music! \n");
}
musicManager.playMusic("menu",false);
//Always load the default music list for fallback.
musicManager.loadMusicList((getDataPath()+"music/default.list"));
//Load the fonts.
if(!loadFonts())
return false;
//Now sum up all the levelpacks.
vector<string> v=enumAllDirs(getDataPath()+"levelpacks/");
for(vector<string>::iterator i=v.begin(); i!=v.end(); ++i){
levelPackManager.loadLevelPack(getDataPath()+"levelpacks/"+*i);
}
v=enumAllDirs(getUserPath(USER_DATA)+"levelpacks/");
for(vector<string>::iterator i=v.begin(); i!=v.end(); ++i){
levelPackManager.loadLevelPack(getUserPath(USER_DATA)+"levelpacks/"+*i);
}
v=enumAllDirs(getUserPath(USER_DATA)+"custom/levelpacks/");
for(vector<string>::iterator i=v.begin(); i!=v.end(); ++i){
levelPackManager.loadLevelPack(getUserPath(USER_DATA)+"custom/levelpacks/"+*i);
}
//Now we add a special levelpack that will contain the levels not in a levelpack.
LevelPack* levelsPack=new LevelPack;
levelsPack->levelpackName="Levels";
LevelPack* customLevelsPack=new LevelPack;
customLevelsPack->levelpackName="Custom Levels";
//List the addon levels and add them one for one.
v=enumAllFiles(getUserPath(USER_DATA)+"levels/");
for(vector<string>::iterator i=v.begin(); i!=v.end(); ++i){
levelsPack->addLevel(getUserPath(USER_DATA)+"levels/"+*i);
levelsPack->setLocked(levelsPack->getLevelCount()-1);
}
//List the custom levels and add them one for one.
v=enumAllFiles(getUserPath(USER_DATA)+"custom/levels/");
for(vector<string>::iterator i=v.begin(); i!=v.end(); ++i){
levelsPack->addLevel(getUserPath(USER_DATA)+"custom/levels/"+*i);
levelsPack->setLocked(levelsPack->getLevelCount()-1);
customLevelsPack->addLevel(getUserPath(USER_DATA)+"custom/levels/"+*i);
customLevelsPack->setLocked(customLevelsPack->getLevelCount()-1);
}
//Add them to the manager.
levelPackManager.addLevelPack(levelsPack);
levelPackManager.addLevelPack(customLevelsPack);
//Load the theme, both menu and default.
if(!loadTheme())
return false;
//Nothing failed so return true.
return true;
}
bool loadSettings(){
settings=new Settings(getUserPath(USER_CONFIG)+"meandmyshadow.cfg");
settings->parseFile();
//Now apply settings changed through command line arguments, if any.
map<string,string>::iterator it;
for(it=tmpSettings.begin();it!=tmpSettings.end();++it){
settings->setValue(it->first,it->second);
}
tmpSettings.clear();
//Always return true?
return true;
}
bool saveSettings(){
settings->save();
//Always return true?
return true;
}
Settings* getSettings(){
return settings;
}
MusicManager* getMusicManager(){
return &musicManager;
}
LevelPackManager* getLevelPackManager(){
return &levelPackManager;
}
void flipScreen(){
if(settings->getBoolValue("gl")){
#ifdef HARDWARE_ACCELERATION
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
//Create a texture from the screen surface.
glBindTexture(GL_TEXTURE_2D,screenTexture);
//Set the texture's stretching properties
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D,0,screen->format->BytesPerPixel,screen->w,screen->h,0,GL_BGRA,GL_UNSIGNED_BYTE,screen->pixels);
glBegin(GL_QUADS);
glTexCoord2i(0,0); glVertex3f(0,0,0);
glTexCoord2i(1,0); glVertex3f(SCREEN_WIDTH,0,0);
glTexCoord2i(1,1); glVertex3f(SCREEN_WIDTH,SCREEN_HEIGHT,0);
glTexCoord2i(0,1); glVertex3f(0,SCREEN_HEIGHT,0);
glEnd();
SDL_GL_SwapBuffers();
#else
//NOTE: Trying to flip the screen using gl while compiled without.
cerr<<"FATAL ERROR: Unable to draw to screen using OpenGL (compiled without)."<<endl;
#endif
}else{
SDL_Flip(screen);
}
}
void clean(){
//We delete the settings.
if(settings){
delete settings;
settings=NULL;
}
//Get rid of the currentstate/
//NOTE: The state is probably already deleted by the changeState function.
if(currentState)
delete currentState;
//Destroy the GUI if present.
if(GUIObjectRoot){
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
//Destroy the imageManager.
imageManager.destroy();
//Destroy the musicManager.
musicManager.destroy();
//Destroy the levelPackManager.
levelPackManager.destroy();
levels=NULL;
//Close the fonts and quit SDL_ttf.
TTF_CloseFont(fontTitle);
TTF_CloseFont(fontGUI);
TTF_CloseFont(fontGUISmall);
TTF_CloseFont(fontText);
TTF_Quit();
//Quit SDL.
SDL_Quit();
//And finally stop audio.
Mix_CloseAudio();
}
void setNextState(int newstate){
//Only change the state when we aren't already exiting.
if(nextState!=STATE_EXIT){
nextState=newstate;
}
}
void changeState(){
//Check if there's a nextState.
if(nextState!=STATE_NULL){
//Delete the currentState.
delete currentState;
currentState=NULL;
//Set the currentState to the nextState.
stateID=nextState;
nextState=STATE_NULL;
//Init the state.
switch(stateID){
case STATE_GAME:
currentState=new Game();
break;
case STATE_MENU:
currentState=new Menu();
break;
case STATE_LEVEL_SELECT:
currentState=new LevelPlaySelect();
break;
case STATE_LEVEL_EDIT_SELECT:
currentState=new LevelEditSelect();
break;
case STATE_LEVEL_EDITOR:
currentState=new LevelEditor();
break;
case STATE_OPTIONS:
currentState=new Options();
break;
case STATE_ADDONS:
currentState=new Addons();
break;
}
//NOTE: STATE_EXIT isn't mentioned, meaning that currentState is null.
//This way the game loop will break and the program will exit.
//Fade out.
int fade=255;
SDL_BlitSurface(screen,NULL,tempSurface,NULL);
while(fade>0){
fade-=17;
if(fade<0)
fade=0;
SDL_FillRect(screen,NULL,0);
SDL_SetAlpha(tempSurface, SDL_SRCALPHA, fade);
SDL_BlitSurface(tempSurface,NULL,screen,NULL);
flipScreen();
SDL_Delay(25);
}
}
}
void musicStoppedHook(){
//We just call the musicStopped method of the MusicManager.
musicManager.musicStopped();
}
bool checkCollision(const SDL_Rect& a,const SDL_Rect& b){
//Check if the left side of box a isn't past the right side of b.
if(a.x>=b.x+b.w){
return false;
}
//Check if the right side of box a isn't left of the left side of b.
if(a.x+a.w<=b.x){
return false;
}
//Check if the top side of box a isn't under the bottom side of b.
if(a.y>=b.y+b.h){
return false;
}
//Check if the bottom side of box a isn't above the top side of b.
if(a.y+a.h<=b.y){
return false;
}
//We have collision.
return true;
}
-void setCamera(const SDL_Rect& r1,const SDL_Rect& r2){
- //SetCamera only works in the Level editor.
- if(stateID==STATE_LEVEL_EDITOR){
+void setCamera(const SDL_Rect& r1,const SDL_Rect& r2){
+ //SetCamera only works in the Level editor and mouse is inside window.
+ if(stateID==STATE_LEVEL_EDITOR&&(SDL_GetAppState()&SDL_APPMOUSEFOCUS)){
//Get the mouse coordinates.
int x,y;
SDL_GetMouseState(&x,&y);
//Make sure we avoid the toolbar.
SDL_Rect mouse={x,y,0,0};
//SDL_Rect toolbar={(SCREEN_WIDTH-460)/2,SCREEN_HEIGHT-50,460,50};
if(checkCollision(mouse,r1))
return;
if(checkCollision(mouse,r2))
return;
//Check if the mouse is near the left edge of the screen.
//Else check if the mouse is near the right edge.
if(x<50){
//We're near the left edge so move the camera.
camera.x-=5;
}else if(x>SCREEN_WIDTH-50){
//We're near the right edge so move the camera.
camera.x+=5;
}
//Check if the mouse is near the top edge of the screen.
//Else check if the mouse is near the bottom edge.
if(y<50){
//We're near the top edge so move the camera.
camera.y-=5;
}else if(y>SCREEN_HEIGHT-50){
//We're near the bottom edge so move the camera.
camera.y+=5;
}
}
}
bool parseArguments(int argc, char** argv){
//Loop through all arguments.
//We start at one since 0 is the command itself.
for(int i=1;i<argc;i++){
string argument=argv[i];
//Check if the argument is the data-dir.
if(argument=="--data-dir"){
//We need a second argument so we increase i.
i++;
if(i>=argc){
printf("ERROR: Missing argument for command '%s'\n\n",argument.c_str());
return false;
}
//Configure the dataPath with the given path.
dataPath=argv[i];
if(!getDataPath().empty()){
char c=dataPath[dataPath.size()-1];
if(c!='/'&&c!='\\') dataPath+="/";
}
}else if(argument=="--user-dir"){
//We need a second argument so we increase i.
i++;
if(i>=argc){
printf("ERROR: Missing argument for command '%s'\n\n",argument.c_str());
return false;
}
//Configure the userPath with the given path.
userPath=argv[i];
if(!userPath.empty()){
char c=userPath[userPath.size()-1];
if(c!='/'&&c!='\\') userPath+="/";
}
}else if(argument=="-f" || argument=="-fullscreen" || argument=="--fullscreen"){
tmpSettings["fullscreen"]="1";
}else if(argument=="-w" || argument=="-windowed" || argument=="--windowed"){
tmpSettings["fullscreen"]="0";
}else if(argument=="-mv" || argument=="-music" || argument=="--music"){
//We need a second argument so we increase i.
i++;
if(i>=argc){
printf("ERROR: Missing argument for command '%s'\n\n",argument.c_str());
return false;
}
//Now set the music volume.
tmpSettings["music"]=argv[i];
}else if(argument=="-sv" || argument=="-sound" || argument=="--sound"){
//We need a second argument so we increase i.
i++;
if(i>=argc){
printf("ERROR: Missing argument for command '%s'\n\n",argument.c_str());
return false;
}
//Now set sound volume.
tmpSettings["sound"]=argv[i];
}else if(argument=="-set" || argument=="--set"){
//We need a second and a third argument so we increase i.
i+=2;
if(i>=argc){
printf("ERROR: Missing argument for command '%s'\n\n",argument.c_str());
return false;
}
//And set the setting.
tmpSettings[argv[i-1]]=argv[i];
}else if(argument=="-v" || argument=="-version" || argument=="--version"){
//Print the version.
printf("Version: '%s'\n\n",version.c_str());
}else if(argument=="-h" || argument=="-help" || argument=="--help"){
//If the help is requested we'll return false without printing an error.
//This way the usage/help text will be printed.
return false;
}else{
//Any other argument is unknow so we return false.
printf("ERROR: Unknown argument %s\n\n",argument.c_str());
return false;
}
}
//If everything went well we can return true.
return true;
}
//Special structure that will recieve the GUIEventCallbacks of the messagebox.
struct msgBoxHandler:public GUIEventCallback{
public:
//Integer containing the ret(urn) value of the messageBox.
int ret;
public:
//Constructor.
msgBoxHandler():ret(0){}
void GUIEventCallback_OnEvent(std::string name,GUIObject* obj,int eventType){
//Make sure it's a click event.
if(eventType==GUIEventClick){
//Set the return value.
ret=obj->value;
//After a click event we can delete the GUI.
if(GUIObjectRoot){
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
}
}
};
msgBoxResult msgBox(string prompt,msgBoxButtons buttons,const string& title){
//Create the event handler.
msgBoxHandler objHandler;
//The GUI objects.
GUIObject* obj;
//We keep a pointer to the original GUIObjectRoot for later.
GUIObject* tmp=GUIObjectRoot;
//Create the GUIObjectRoot, the height and y location is temp.
//It depends on the content what it will be.
GUIObjectRoot=new GUIObject((SCREEN_WIDTH-600)/2,200,600,200,GUIObjectFrame,title.c_str());
//Integer containing the current y location used to grow dynamic depending on the content.
int y=50;
//Now process the prompt.
{
//Pointer to the string.
char* lps=(char*)prompt.c_str();
//Pointer to a character.
char* lp=NULL;
//We keep looping forever.
//The only way out is with the break statement.
for(;;){
//As long as it's still the same sentence we continue.
//It will stop when there's a newline or end of line.
for(lp=lps;*lp!='\n'&&*lp!='\r'&&*lp!=0;lp++);
//Store the character we stopped on. (End or newline)
char c=*lp;
//Set the character in the string to 0, making lps a string containing one sentence.
*lp=0;
//Add a GUIObjectLabel with the sentence.
GUIObjectRoot->childControls.push_back(new GUIObject(0,y,GUIObjectRoot->width,25,GUIObjectLabel,lps,0,true,true,GUIGravityCenter));
//Increase y with 25, about the height of the text.
y+=25;
//Check the stored character if it was a stop.
if(c==0){
//It was so break out of the for loop.
lps=lp;
break;
}
//It wasn't meaning more will follow.
//We set lps to point after the "newline" forming a new string.
lps=lp+1;
}
}
//Add 70 to y to leave some space between the content and the buttons.
y+=70;
//Recalc the size of the message box.
GUIObjectRoot->top=(SCREEN_HEIGHT-y)/2;
GUIObjectRoot->height=y;
//Now we need to add the buttons.
//Integer containing the number of buttons to add.
int count=0;
//Array with the return codes for the buttons.
int value[3]={0};
//Array containing the captation for the buttons.
string button[3]={"","",""};
switch(buttons){
case MsgBoxOKCancel:
count=2;
button[0]=_("OK");value[0]=MsgBoxOK;
button[1]=_("Cancel");value[1]=MsgBoxCancel;
break;
case MsgBoxAbortRetryIgnore:
count=3;
button[0]=_("Abort");value[0]=MsgBoxAbort;
button[1]=_("Retry");value[1]=MsgBoxRetry;
button[2]=_("Ignore");value[2]=MsgBoxIgnore;
break;
case MsgBoxYesNoCancel:
count=3;
button[0]=_("Yes");value[0]=MsgBoxYes;
button[1]=_("No");value[1]=MsgBoxNo;
button[2]=_("Cancel");value[2]=MsgBoxCancel;
break;
case MsgBoxYesNo:
count=2;
button[0]=_("Yes");value[0]=MsgBoxYes;
button[1]=_("No");value[1]=MsgBoxNo;
break;
case MsgBoxRetryCancel:
count=2;
button[0]=_("Retry");value[0]=MsgBoxRetry;
button[1]=_("Cancel");value[1]=MsgBoxCancel;
break;
default:
count=1;
button[0]=_("OK");value[0]=MsgBoxOK;
break;
}
//Now we start making the buttons.
{
//Reduce y so that the buttons fit inside the frame.
y-=40;
double places[3]={0.0};
if(count==1){
places[0]=0.5;
}else if(count==2){
places[0]=0.4;
places[1]=0.6;
}else if(count==3){
places[0]=0.3;
places[1]=0.5;
places[2]=0.7;
}
//Loop to add the buttons.
for(int i=0;i<count;i++){
obj=new GUIObject(GUIObjectRoot->width*places[i],y,-1,36,GUIObjectButton,button[i].c_str(),value[i],true,true,GUIGravityCenter);
obj->eventCallback=&objHandler;
GUIObjectRoot->childControls.push_back(obj);
}
}
//Now we dim the screen and keep the GUI rendering/updating.
SDL_FillRect(tempSurface,NULL,0);
SDL_SetAlpha(tempSurface,SDL_SRCALPHA,155);
SDL_BlitSurface(tempSurface,NULL,screen,NULL);
while(GUIObjectRoot){
while(SDL_PollEvent(&event)){
GUIObjectHandleEvents(true);
//Also check for the return, escape or backspace button.
//escape = KEYUP.
//backspace and return = KEYDOWN.
if(count==1 && ((event.type==SDL_KEYUP && event.key.keysym.sym==SDLK_ESCAPE) ||
(event.type==SDL_KEYDOWN && (event.key.keysym.sym==SDLK_RETURN || event.key.keysym.sym==SDLK_BACKSPACE)))){
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
}
//Render the gui.
if(GUIObjectRoot)
GUIObjectRoot->render();
flipScreen();
SDL_Delay(30);
}
//We're done so set the original GUIObjectRoot back.
GUIObjectRoot=tmp;
//And return the result.
return (msgBoxResult)objHandler.ret;
}
struct fileDialogHandler:public GUIEventCallback{
public:
//The ret(urn) value, true=ok and false=cancel
bool ret;
//Boolean if it's a save dialog.
bool isSave;
//Boolean if the file should be verified.
bool verifyFile;
//Boolean if files should be listed instead of directories.
bool files;
//Pointer to the textfield containing the filename.
GUIObject* txtName;
//Pointer to the listbox containing the different files.
GUIListBox* lstFile;
//The extension the files listed should have.
const char* extension;
//The current filename.
string fileName;
//The current search path.
string path;
//Vector containing the search paths.
vector<string> searchPath;
public:
//Constructor.
fileDialogHandler(bool isSave=false,bool verifyFile=false, bool files=true):ret(false),
isSave(isSave),verifyFile(verifyFile),
files(files),txtName(NULL){}
void GUIEventCallback_OnEvent(std::string name,GUIObject* obj,int eventType){
//Check for the ok event.
if(name=="cmdOK"){
//Get the entered fileName from the text field.
std::string s=txtName->caption;
//If it doesn't contain a slash we need to add the path to the fileName.
if(s.find_first_of("/")==string::npos)
s=path+s;
//If the string empty we return.
if(s.empty() || s.find_first_of("*?")!=string::npos)
return;
//We only need to check for extensions if it isn't a folder dialog.
if(files){
//If there isn't right extension add it.
size_t found=s.find_first_of(".");
if(found!=string::npos)
s.replace(s.begin()+found+1,s.end(),extension);
else if (s.substr(found+1)!=extension)
s.append(string(".")+extension);
}
//Check if we should save or load the file.
//
if(isSave){
//Open the file with read permission to check if it already exists.
FILE* f;
f=fopen(processFileName(s).c_str(),"rb");
//Check if it exists.
if(f){
//Close the file.
fclose(f);
//Let the currentState render once to prevent multiple GUI overlapping and prevent the screen from going black.
currentState->render();
//Prompt the user with a Yes or No question.
/// TRANSLATORS: Filename is coming before this text
if(msgBox(tfm::format(_("%s already exists.\nDo you want to overwrite it?"),s),MsgBoxYesNo,_("Overwrite Prompt"))!=MsgBoxYes){
//He answered no, so we return.
return;
}
}
//Check if we should verify the file.
//Verifying only applies to files not to directories.
if(verifyFile && files){
//Open the file with write permission.
f=fopen(processFileName(s).c_str(),"wb");
//Check if their aren't problems.
if(f){
//Close the file.
fclose(f);
}else{
//Let the currentState render once to prevent multiple GUI overlapping and prevent the screen from going black.
currentState->render();
//The file can't be opened so tell the user.
msgBox(tfm::format(_("Can't open file %s."),s),MsgBoxOKOnly,_("Error"));
return;
}
}
}else if(verifyFile && files){
//We need to verify a file for opening.
FILE *f;
f=fopen(processFileName(s).c_str(),"rb");
//Check if it didn't fail.
if(f){
//Succes, so close the file.
fclose(f);
}else{
//Let the currentState render once to prevent multiple GUI overlapping and prevent the screen from going black.
currentState->render();
//Unable to open file so tell the user.
msgBox(tfm::format(_("Can't open file %s."),s),MsgBoxOKOnly,_("Error"));
return;
}
}
//If we haven't returned then it's fine.
//Set the fileName to the chosen file.
fileName=s;
//Delete the GUI.
if(GUIObjectRoot){
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
//Set return to true.
ret=true;
}else if(name=="cmdCancel"){
//Cancel means we can kill the gui.
if(GUIObjectRoot){
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
}else if(name=="lstFile"){
//Get a pointer to the listbox.
GUIListBox* obj1=lstFile;
//Make sure the option exist and change textfield to it.
if(obj1!=NULL && txtName!=NULL && obj1->value>=0 && obj1->value<(int)obj1->item.size()){
txtName->caption=obj1->item[obj1->value];
}
}else if(name=="lstSearchIn"){
//Get the searchpath listbox.
GUISingleLineListBox *obj1=dynamic_cast<GUISingleLineListBox*>(obj);
//Check if the entry exists.
if(obj1!=NULL && lstFile!=NULL && obj1->value>=0 && obj1->value<(int)searchPath.size()){
//Temp string.
string s;
//Get the new search path.
path=searchPath[obj1->value];
//Make sure it isn't empty.
if(!path.empty()){
//Process the filename.
s=processFileName(path);
}else{
//It's empty so we give the userpath.
s=getUserPath();
}
//Fill the list with files or directories.
if(files) {
lstFile->item=enumAllFiles(s,extension);
}else
lstFile->item=enumAllDirs(s);
//Remove any selection from the list.
lstFile->value=-1;
}
}
}
};
bool fileDialog(string& fileName,const char* title,const char* extension,const char* path,bool isSave,bool verifyFile,bool files){
//Pointer to GUIObject to make the GUI with.
GUIObject* obj;
//Pointer to the current GUIObjectRoot.
//We keep it so we can put it back after closing the fileDialog.
GUIObject* tmp=GUIObjectRoot;
//Create the fileDialogHandler, used for event handling.
fileDialogHandler objHandler(isSave,verifyFile,files);
//Vector containing the pathNames.
vector<string> pathNames;
//Set the extension of the objHandler.
objHandler.extension=extension;
//We now need to splits the given path into multiple path names.
if(path && path[0]){
//The string isn't empty.
//Pointer to the paths string.
char* lp=(char*)path;
//Pointer to the first newline.
char* lps=strchr(lp,'\n');
//Pointer used for checking if their's another newline.
//It will indicate if it's the last set or not.
char* lpe;
//Check for a newline.
if(lps){
//We have newline(s) so loop forever.
//We can only break out of the loop when the string ends.
for(;;){
//Add the first searchpath.
//This is the beginning of the string (lp) to the first newline. (lps)
objHandler.searchPath.push_back(string(lp,lps-lp));
//We should have another newline so search for it.
lpe=strchr(lps+1,'\n');
if(lpe){
//We found it so we add that to the pathname.
pathNames.push_back(string(lps+1,lpe-lps-1));
//And start over again by setting lp to the start of a new set of searchPath/pathName.
lp=lpe+1;
}else{
//There is no newline anymore, meaning the last entry, the rest of the string must be the pathName.
pathNames.push_back(string(lps+1));
//And break out of the loop.
break;
}
//We haven't broken out so search for a newline.
lps=strchr(lp,'\n');
//If there isn't a newline break.
if(!lps)
break;
}
}else{
//There is no newline thus the whole string is the searchPath.
objHandler.searchPath.push_back(path);
}
}else{
//Empty so put an empty string as searchPath.
objHandler.searchPath.push_back(string());
}
//It's time to create the GUI.
//If there are more than one pathNames we need to add a GUISingleLineListBox.
int base_y=pathNames.size()>0?60:20;
//Create the frame.
GUIObjectRoot=new GUIObject(100,100-base_y/2,600,400+base_y,GUIObjectFrame,title?title:(isSave?_("Save File"):_("Load File")));
//Create the search path list box if needed.
if(pathNames.size()>0){
GUIObjectRoot->childControls.push_back(new GUIObject(8,40,184,36,GUIObjectLabel,_("Search In")));
GUISingleLineListBox* obj1=new GUISingleLineListBox(160,40,432,36);
obj1->item=pathNames;
obj1->value=0;
obj1->name="lstSearchIn";
obj1->eventCallback=&objHandler;
GUIObjectRoot->childControls.push_back(obj1);
}
//Add the FileName label and textfield.
GUIObjectRoot->childControls.push_back(new GUIObject(8,20+base_y,184,36,GUIObjectLabel,_("File Name")));
{
//Fill the textbox with the given fileName.
string s=fileName;
if(!isSave){
//But only if it isn't empty.
if(s.empty() && extension && extension[0])
s=string("*.")+string(extension);
}
//Create the textbox and add it to the GUI.
objHandler.txtName=new GUIObject(160,20+base_y,432,36,GUIObjectTextBox,s.c_str());
GUIObjectRoot->childControls.push_back(objHandler.txtName);
}
//Now we add the ListBox containing the files or directories.
{
GUIListBox* obj1=new GUIListBox(8,60+base_y,584,292);
//Get the searchPath.
string s=objHandler.searchPath[0];
//Make sure it isn't empty.
if(!s.empty()){
objHandler.path=s;
s=processFileName(s);
}else{
s=getUserPath();
}
//Check if we should list files or directories.
if(files){
//Fill the list with files.
obj1->item=enumAllFiles(s,extension);
}else{
//Fill the list with directories.
obj1->item=enumAllDirs(s);
}
obj1->name="lstFile";
obj1->eventCallback=&objHandler;
GUIObjectRoot->childControls.push_back(obj1);
objHandler.lstFile=obj1;
}
//Now create the OK and Cancel buttons.
obj=new GUIObject(200,360+base_y,192,36,GUIObjectButton,_("OK"));
obj->name="cmdOK";
obj->eventCallback=&objHandler;
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(400,360+base_y,192,36,GUIObjectButton,_("Cancel"));
obj->name="cmdCancel";
obj->eventCallback=&objHandler;
GUIObjectRoot->childControls.push_back(obj);
//Now we keep rendering and updating the GUI.
SDL_FillRect(tempSurface,NULL,0);
SDL_SetAlpha(tempSurface,SDL_SRCALPHA,155);
SDL_BlitSurface(tempSurface,NULL,screen,NULL);
while(GUIObjectRoot){
while(SDL_PollEvent(&event))
GUIObjectHandleEvents(true);
if(GUIObjectRoot)
GUIObjectRoot->render();
flipScreen();
SDL_Delay(30);
}
//The while loop ended meaning we can restore the previous GUI.
GUIObjectRoot=tmp;
//Now determine what the return value is (and if there is one).
if(objHandler.ret)
fileName=objHandler.fileName;
return objHandler.ret;
}
diff --git a/src/Functions.h b/src/Functions.h
index 58e72d2..4c44587 100644
--- a/src/Functions.h
+++ b/src/Functions.h
@@ -1,237 +1,241 @@
/****************************************************************************
** Copyright (C) 2011 Luka Horvat <redreaper132 at gmail.com>
** Copyright (C) 2011 Edward Lii <edward_iii at myway.com>
** Copyright (C) 2011 O. Bahri Gordebak <gordebak at gmail.com>
**
**
** This file may be used under the terms of the GNU General Public
** License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#ifndef FUNCTIONS_H
#define FUNCTIONS_H
#include "Settings.h"
#include "MusicManager.h"
#include "LevelPackManager.h"
#include "Globals.h"
#include <SDL/SDL.h>
#include <string>
#include <vector>
//gettext function
//message: The message to translate.
//Returns: The translated string or the original string if there is not translation available.
#define _(message) (dictionaryManager!=NULL?dictionaryManager->get_dictionary().translate(message).c_str():std::string(message).c_str())
//gettext function
//dictionaryManager: Pointer to the dictionaryManager to use for the translation.
//message: The message to translate.
//Returns: The translated string or the original string if there is not translation available.
#define _C(dictionaryManager, message) ((dictionaryManager)!=NULL?(dictionaryManager)->get_dictionary().translate(message).c_str():std::string(message).c_str())
+//dummy function for xgettext
+//message: The message to translate.
+//Returns: message parameter
+#define __(message) (message)
//Loads an image.
//file: The image file to load.
//Returns: The SDL_surface containing the image.
SDL_Surface* loadImage(std::string file);
//Method for drawing an SDL_Surface onto another.
//x: The x location to draw the source on the desination.
//y: The y location to draw the source on the desination.
//source: The SDL_Surface to draw.
//dest: The SDL_Surface to draw on.
//clip: Rectangle which part of the source should be drawn.
void applySurface(int x,int y,SDL_Surface* source,SDL_Surface* dest,SDL_Rect* clip);
//Method used to draw an rectangle.
//x: The top left x location of the rectangle.
//y: The top left y location of the rectangle.
//w: The width of the rectangle,
//h: The height of the rectangle.
//dest: The SDL_Surface to draw on.
//color: The color of the rectangle border to draw.
void drawRect(int x,int y,int w,int h,SDL_Surface* dest,Uint32 color=0);
//Method used to draw filled boxes with an anti-alliased border.
//Mostly used for GUI components.
//x: The top left x location of the box.
//y: The top left y location of the box.
//w: The width of the box,
//h: The height of the box.
//dest: The SDL_Surface to draw on.
//alpha: The alpha of the box to draw.
void drawGUIBox(int x,int y,int w,int h,SDL_Surface* dest,Uint32 color);
//Method used to draw a line.
//x1: The x location of the start point.
//y1: The y location of the start point.
//x2: The x location of the end point.
//y2: The y location of the end point.
//dest: The SDL_Surface to draw on.
//color: The color of the line to draw.
void drawLine(int x1,int y1,int x2,int y2,SDL_Surface* dest,Uint32 color=0);
//Method used to draw a line with some arrows on it.
//x1: The x location of the start point.
//y1: The y location of the start point.
//x2: The x location of the end point.
//y2: The y location of the end point.
//dest: The SDL_Surface to draw on.
//color: The color of the line to draw.
//spacing: The spacing between arrows.
//offset: Offset of first arrow relative to the start point.
//xize, ysize: The size of arrow.
void drawLineWithArrow(int x1,int y1,int x2,int y2,SDL_Surface* dest,Uint32 color=0,int spacing=16,int offset=0,int xsize=5,int ysize=5);
//Method that will load the fonts needed for the game.
//NOTE: It's separate from loadFiles(), since it might get called separatly from the code when changing the language.
bool loadFonts();
//Method that will load the default theme again.
//NOTE: It's separate from loadFiles(), since it might get called separatly from the code when changing resolution.
bool loadTheme();
//This method will attempt to create the screen/window.
//NOTE: It's separate from init(), since it might get called separatly from the code when changing resolution.
bool createScreen();
//This method is used to configure the window that is created by createScreen.
//NOTE: It will do it in a WM specific way, so if the wm is unkown it will do nothing.
//initial: Boolean that is true if it's the first time the window is configured.
void configureWindow(bool initial);
//Call this method when receive SDL_VIDEORESIZE event.
void onVideoResize();
//Initialises the game. This is done almost at the beginning of the program.
//It initialises: SDL, SDL_Mixer, SDL_ttf, the screen and the block types.
//Returns: True if everything goes well.
bool init();
//Loads some important files, like the background music and the default theme.
//Returns: True if everything goes well.
bool loadFiles();
//This method will load the settings from the settings file.
//Returns: False if there's an error while loading.
bool loadSettings();
//This method will save the settings to the settings file.
//Returns: False if there's an error while saving.
bool saveSettings();
//Method used to get a pointer to the settings object.
//Returns: A pointer to the settings object.
Settings* getSettings();
//Method used to get a pointer to the MusicManager object.
//Returns: A pointer to the MusicManager object.
MusicManager* getMusicManager();
//Method used to get a pointer to the LevelPackManager object.
//Returns: A pointer to the LevelPackManager object.
LevelPackManager* getLevelPackManager();
//Method that will, depending on the rendering backend, draw the screen surface to the screen.
void flipScreen();
//Method used to clean up before quiting meandmyshadow.
void clean();
//Sets what the nextState will be.
//newstate: Integer containing the id of the newstate.
void setNextState(int newstate);
//Method that will perform the state change.
//It will fade out and in.
void changeState();
//This method is called when music is stopped.
//NOTE: This method is outside the MusicManager because it couldn't be called otherwise.
//Do not call this method anywhere in the code!
void musicStoppedHook();
//Checks collision between two SDL_Rects.
//a: The first rectangle.
//b: The second rectangle.
//Returns: True if the two rectangles collide.
bool checkCollision(const SDL_Rect& a,const SDL_Rect& b);
//This method will check if the mouse is near a screen edge.
//r1: Does nothing if mouse inside this rectange
//r2: Does nothing if mouse inside this rectange
//If so it will move the camera.
//Note: This function only works with the leveleditor.
void setCamera(const SDL_Rect& r1,const SDL_Rect& r2);
//Parse the commandline arguments.
//argc: Integer containing the number of aruguments there are.
//argv: The arguments.
//Returns: False if something goes wrong while parsing.
bool parseArguments(int argc, char** argv);
//From http://en.wikipedia.org/wiki/Clamping_(graphics)
//x: The value to clamp.
//min: The minimum x can be.
//max: The maximum x can be.
//Returns: Integer containing the clamped value.
int inline clamp(int x,int min,int max){
return (x>max)?max:(x<min)?min:x;
}
//Enumeration containing the different messagebox button combinations.
enum msgBoxButtons{
//Only one button with the text OK.
MsgBoxOKOnly=0,
//Two buttons, one saying OK, the other Cancel.
MsgBoxOKCancel=1,
//Three buttons, Abort, Retry, Ignore.
MsgBoxAbortRetryIgnore=2,
//Three buttons, Yes, No or Cancel.
MsgBoxYesNoCancel=3,
//Two buttons, one saying Yes, the other No.
MsgBoxYesNo=4,
//Two buttons, one saying Retry, the other Cancel.
MsgBoxRetryCancel=5,
};
//Enumeration containing the different result that can be retrieved from a messagebox.
//It represents the button that has been pressed.
enum msgBoxResult{
//The OK button.
MsgBoxOK=1,
//The cancel button.
MsgBoxCancel=2,
//The abort button.
MsgBoxAbort=3,
//The retry button.
MsgBoxRetry=4,
//The ignore button.
MsgBoxIgnore=5,
//The yes button.
MsgBoxYes=6,
//The no button.
MsgBoxNo=7,
};
//Method that prompts the user with a notification and/or question.
//prompt: The message the user is prompted with.
//buttons: Which buttons the messagebox should have.
//title: The title of the message box.
//Returns: A msgBoxResult which button has been pressed.
msgBoxResult msgBox(std::string prompt,msgBoxButtons buttons,const std::string& title);
//This method will show a file dialog in which the user can select a file.
//NOTE: It doesn't support entering folders.
//fileName: String that will contain the result, it can also be used to already chose the file.
//title: The title of the fileDialog window.
//extension: The extension the files must have, leave empty for all files.
//path: The path to list the files of.
//isSave: If the dialog is for saving files, and not loading.
//verifyFile: Boolean if the selected should be verified.
//files: Boolean if the fileDialog should display files, if not it will display directories.
bool fileDialog(std::string& fileName,const char* title=NULL,const char* extension=NULL,const char* path=NULL,bool isSave=false,bool verifyFile=false,bool files=true);
#endif
diff --git a/src/GUIListBox.cpp b/src/GUIListBox.cpp
index 437574b..a585425 100644
--- a/src/GUIListBox.cpp
+++ b/src/GUIListBox.cpp
@@ -1,372 +1,376 @@
/****************************************************************************
** Copyright (C) 2011 Luka Horvat <redreaper132 at gmail.com>
** Copyright (C) 2011 Edward Lii <edward_iii at myway.com>
** Copyright (C) 2011 O. Bahri Gordebak <gordebak at gmail.com>
**
**
** This file may be used under the terms of the GNU General Public
** License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "GUIListBox.h"
using namespace std;
GUIListBox::GUIListBox(int left,int top,int width,int height,bool enabled,bool visible):
GUIObject(left,top,width,height,0,NULL,-1,enabled,visible){
//Set the state -1.
state=-1;
//Create the scrollbar and add it to the children.
scrollBar=new GUIScrollBar(0,0,16,0,1,0,0,0,0,0,true,false);
childControls.push_back(scrollBar);
}
bool GUIListBox::handleEvents(int x,int y,bool enabled,bool visible,bool processed){
//Boolean if the event is processed.
bool b=processed;
//The GUIObject is only enabled when he and his parent are enabled.
enabled=enabled && this->enabled;
//The GUIObject is only enabled when he and his parent are enabled.
visible=visible && this->visible;
//Get the absolute position.
x+=left;
y+=top;
//Calculate the scrollbar position.
scrollBar->left=width-16;
scrollBar->height=height;
int m=item.size(),n=(height-4)/24;
if(m>n){
scrollBar->maxValue=m-n;
scrollBar->smallChange=1;
scrollBar->largeChange=n;
scrollBar->visible=true;
b=b||scrollBar->handleEvents(x,y,enabled,visible,b);
}else{
scrollBar->value=0;
scrollBar->maxValue=0;
scrollBar->visible=false;
}
//Set state negative.
state=-1;
//Check if the GUIListBox is visible, enabled and no event has been processed before.
if(enabled&&visible&&!b){
//The mouse location (x=i, y=j) and the mouse button (k).
int i,j;
SDL_GetMouseState(&i,&j);
//Convert the mouse location to a relative location.
i-=x+2;
j-=y+2;
//Check if the mouse is inside the GUIListBox.
if(i>=0&&i<width-4&&j>=0&&j<height-4){
//Calculate the y location with the scrollbar position.
int idx=j/24+scrollBar->value;
//If the entry isn't above the max we have an event.
if(idx>=0&&idx<(int)item.size()){
state=idx;
//Check if the left mouse button is pressed.
if(event.type==SDL_MOUSEBUTTONDOWN && event.button.button==SDL_BUTTON_LEFT && value!=idx){
value=idx;
//If event callback is configured then add an event to the queue.
if(eventCallback){
GUIEvent e={eventCallback,name,this,GUIEventClick};
GUIEventQueue.push_back(e);
}
}
}
//Check for mouse wheel scrolling.
if(event.type==SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_WHEELDOWN && scrollBar->enabled){
scrollBar->value+=4;
if(scrollBar->value > scrollBar->maxValue)
scrollBar->value = scrollBar->maxValue;
}else if(event.type==SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_WHEELUP && scrollBar->enabled){
scrollBar->value-=4;
if(scrollBar->value < 0)
scrollBar->value = 0;
}
}
}
//Process child controls event except for the scrollbar.
//That's why i starts at one.
for(unsigned int i=1;i<childControls.size();i++){
bool b1=childControls[i]->handleEvents(x,y,enabled,visible,b);
//The event is processed when either our or the childs is true (or both).
b=b||b1;
}
return b;
}
-void GUIListBox::render(int x,int y){
+void GUIListBox::render(int x,int y,bool draw){
//Rectangle the size of the GUIObject, used to draw borders.
SDL_Rect r;
//There's no need drawing the GUIObject when it's invisible.
- if(!visible)
+ if(!visible||!draw)
return;
//Get the absolute x and y location.
x+=left;
y+=top;
//Default background opacity
int clr=128;
//TODO: Add hover check?
//Draw the box.
Uint32 color=0xFFFFFFFF|clr;
drawGUIBox(x,y,width,height,screen,color);
//We need to draw the items.
//The number of items.
int m=item.size();
//The number of items that are visible.
int n=(height-4)/24;
//Integer containing the current entry that is being drawn.
int i;
//The y coordinate the current entries reaches.
int j;
//If the number of items is higer than fits on the screen set the begin value (m) to scrollBar->value+n.
if(m>scrollBar->value+n)
m=scrollBar->value+n;
//Loop through the (visible) entries and draw them.
for(i=scrollBar->value,j=y+1;i<m;i++,j+=24){
//The background color for the entry.
int clr=-1;
//If i is the selected entry then give it a light gray background.
if(value==i){
clr=0xDDDDDDFF;
}
//Check if the current entry is selected. If so draw borders around it.
if(state==i)
drawGUIBox(x,j-1,width,25,screen,0x00000000);
//Only draw when clr isn't -1.
if(clr!=-1)
drawGUIBox(x,j-1,width,25,screen,clr);
//Now draw the text.
const char* s=item[i].c_str();
//Make sure the text isn't empty.
if(s && s[0]){
//Render black text.
SDL_Color black={0,0,0,0};
SDL_Surface *bm=TTF_RenderUTF8_Blended(fontText,s,black);
//Calculate the text location, center it vertically.
r.x=x+4;
r.y=j+12-bm->h/2;
//Draw the text and free the rendered surface.
SDL_BlitSurface(bm,NULL,screen,&r);
SDL_FreeSurface(bm);
}
}
//We now need to draw all the children of the GUIObject.
for(unsigned int i=0;i<childControls.size();i++){
- childControls[i]->render(x,y);
+ childControls[i]->render(x,y,draw);
}
}
GUISingleLineListBox::GUISingleLineListBox(int left,int top,int width,int height,bool enabled,bool visible):
GUIObject(left,top,width,height,0,NULL,-1,enabled,visible),animation(0){}
bool GUISingleLineListBox::handleEvents(int x,int y,bool enabled,bool visible,bool processed){
//Boolean if the event is processed.
bool b=processed;
//The GUIObject is only enabled when he and his parent are enabled.
enabled=enabled && this->enabled;
//The GUIObject is only enabled when he and his parent are enabled.
visible=visible && this->visible;
//Get the absolute position.
x+=left;
y+=top;
state&=~0xF;
if(enabled&&visible){
//The mouse location (x=i, y=j) and the mouse button (k).
int i,j,k;
k=SDL_GetMouseState(&i,&j);
//Convert the mouse location to a relative location.
i-=x;
j-=y;
//The selected button.
//0=nothing 1=left 2=right.
int idx=0;
//Check which button the mouse is above.
if(i>=0&&i<width&&j>=0&&j<height){
if(i<26 && i<width/2){
//The left arrow.
idx=1;
}else if(i>=width-26){
//The right arrow.
idx=2;
}
}
//If idx is 0 it means the mous doesn't hover any arrow so reset animation.
if(idx==0)
animation=0;
//Check if there's a mouse button press or not.
if(k&SDL_BUTTON(1)){
if(((state>>4)&0xF)==idx)
state|=idx;
}else{
state|=idx;
}
//Check if there's a mouse press.
if(event.type==SDL_MOUSEBUTTONDOWN && event.button.button==SDL_BUTTON_LEFT && idx){
state=idx|(idx<<4);
}else if(event.type==SDL_MOUSEBUTTONUP && event.button.button==SDL_BUTTON_LEFT && idx && ((state>>4)&0xF)==idx){
int m=(int)item.size();
if(m>0){
if(idx==2){
idx=value+1;
if(idx<0||idx>=m) idx=0;
if(idx!=value){
value=idx;
//If there is an event callback then call it.
if(eventCallback){
GUIEvent e={eventCallback,name,this,GUIEventClick};
GUIEventQueue.push_back(e);
}
}
}else if(idx==1){
idx=value-1;
if(idx<0||idx>=m) idx=m-1;
if(idx!=value){
value=idx;
//If there is an event callback then call it.
if(eventCallback){
GUIEvent e={eventCallback,name,this,GUIEventClick};
GUIEventQueue.push_back(e);
}
}
}
}
}
if(event.type==SDL_MOUSEBUTTONUP) state&=0xF;
}else{
//Set state zero.
state=0;
}
//Also let the children handle their events.
for(unsigned int i=0;i<childControls.size();i++){
bool b1=childControls[i]->handleEvents(x,y,enabled,visible,b);
//The event is processed when either our or the childs is true (or both).
b=b||b1;
}
return b;
}
-void GUISingleLineListBox::render(int x,int y){
+void GUISingleLineListBox::render(int x,int y,bool draw){
//Rectangle the size of the GUIObject, used to draw borders.
SDL_Rect r;
//There's no need drawing the GUIObject when it's invisible.
if(!visible)
return;
//NOTE: logic in the render method since it's the only part that gets called every frame.
if((state&0xF)==0x1 || (state&0xF)==0x2){
animation++;
if(animation>20)
animation=-20;
}
//Get the absolute x and y location.
x+=left;
y+=top;
//Check if the enabled state changed or the caption, if so we need to clear the (old) cache.
if(enabled!=cachedEnabled || item[value].compare(cachedCaption)!=0){
//Free the cache.
SDL_FreeSurface(cache);
cache=NULL;
//And cache the new values.
cachedEnabled=enabled;
cachedCaption=item[value];
}
//Draw the text.
if(value>=0 && value<(int)item.size()){
//Get the text.
const char* lp=item[value].c_str();
//Check if the text is empty or not.
if(lp!=NULL && lp[0]){
if(!cache){
//Render black text.
SDL_Color black={0,0,0,0};
cache=TTF_RenderUTF8_Blended(fontGUI,lp,black);
//If the text is too wide then we change to smaller font (?)
//NOTE: The width is 32px smaller (2x16px for the arrows).
if(cache->w>width-32){
SDL_FreeSurface(cache);
cache=TTF_RenderUTF8_Blended(fontGUISmall,lp,black);
}
}
+ if(draw){
//Center the text both vertically as horizontally.
r.x=x+(width-cache->w)/2;
r.y=y+(height-cache->h)/2;
//Draw the text and free the surface afterwards.
SDL_BlitSurface(cache,NULL,screen,&r);
+ }
}
}
+ if(draw){
//Draw the arrows.
SDL_Rect r2={48,0,16,16};
r.x=x;
if((state&0xF)==0x1)
r.x+=abs(animation/2);
r.y=y+(height-16)/2;
SDL_BlitSurface(bmGUI,&r2,screen,&r);
r2.x=64;
r.x=x+width-16;
if((state&0xF)==0x2)
r.x-=abs(animation/2);
SDL_BlitSurface(bmGUI,&r2,screen,&r);
+ }
//We now need to draw all the children of the GUIObject.
for(unsigned int i=0;i<childControls.size();i++){
- childControls[i]->render(x,y);
+ childControls[i]->render(x,y,draw);
}
}
diff --git a/src/GUIListBox.h b/src/GUIListBox.h
index 455dbea..5ef2a55 100644
--- a/src/GUIListBox.h
+++ b/src/GUIListBox.h
@@ -1,93 +1,93 @@
/****************************************************************************
** Copyright (C) 2011 Luka Horvat <redreaper132 at gmail.com>
** Copyright (C) 2011 Edward Lii <edward_iii at myway.com>
** Copyright (C) 2011 O. Bahri Gordebak <gordebak at gmail.com>
**
**
** This file may be used under the terms of the GNU General Public
** License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#ifndef GUILISTBOX_H
#define GUILISTBOX_H
#include "GUIObject.h"
#include "GUIScrollBar.h"
//GUIObject that displays a list.
//It extends GUIObject because it's a special GUIObject.
class GUIListBox:public GUIObject{
public:
//Vector containing the entries of the list.
std::vector<std::string> item;
private:
//Scrollbar used when there are more entries than fit on the screen.
GUIScrollBar* scrollBar;
public:
//Constructor.
//left: The relative x location of the GUIListBox.
//top: The relative y location of the GUIListBox.
//witdh: The width of the GUIListBox.
//height: The height of the GUIListBox.
//enabled: Boolean if the GUIListBox is enabled or not.
//visible: Boolean if the GUIListBox is visisble or not.
GUIListBox(int left=0,int Top=0,int width=0,int height=0,bool enabled=true,bool visible=true);
//Method used to handle mouse and/or key events.
//x: The x mouse location.
//y: The y mouse location.
//enabled: Boolean if the parent is enabled or not.
//visible: Boolean if the parent is visible or not.
//processed: Boolean if the event has been processed (by the parent) or not.
//Returns: Boolean if the event is processed by the child.
virtual bool handleEvents(int x=0,int y=0,bool enabled=true,bool visible=true,bool processed=false);
//Method that will render the GUIListBox.
//x: The x location to draw the GUIListBox. (x+left)
//y: The y location to draw the GUIListBox. (y+top)
- virtual void render(int x=0,int y=0);
+ virtual void render(int x=0,int y=0,bool draw=true);
};
//GUIObject that displays a list on only one line.
//Instead of clicking the entries of the list you iterate through them.
//It extends GUIObject because it's a special GUIObject.
class GUISingleLineListBox:public GUIObject{
public:
//Vector containing the entries of the list.
std::vector<std::string> item;
//Integer used for the animation of the arrow.
int animation;
public:
//Constructor.
//left: The relative x location of the GUIListBox.
//top: The relative y location of the GUIListBox.
//witdh: The width of the GUIListBox.
//height: The height of the GUIListBox.
//enabled: Boolean if the GUIListBox is enabled or not.
//visible: Boolean if the GUIListBox is visisble or not.
GUISingleLineListBox(int left=0,int top=0,int width=0,int height=0,bool enabled=true,bool visible=true);
//Method used to handle mouse and/or key events.
//x: The x mouse location.
//y: The y mouse location.
//enabled: Boolean if the parent is enabled or not.
//visible: Boolean if the parent is visible or not.
//processed: Boolean if the event has been processed (by the parent) or not.
//Returns: Boolean if the event is processed by the child.
virtual bool handleEvents(int x=0,int y=0,bool enabled=true,bool visible=true,bool processed=false);
//Method that will render the GUIListBox.
//x: The x location to draw the GUIListBox. (x+left)
//y: The y location to draw the GUIListBox. (y+top)
- virtual void render(int x=0,int y=0);
+ virtual void render(int x=0,int y=0,bool draw=true);
};
#endif
diff --git a/src/GUIObject.cpp b/src/GUIObject.cpp
index 0d485c2..af55f7f 100644
--- a/src/GUIObject.cpp
+++ b/src/GUIObject.cpp
@@ -1,508 +1,524 @@
/****************************************************************************
** Copyright (C) 2011 Luka Horvat <redreaper132 at gmail.com>
** Copyright (C) 2011 Edward Lii <edward_iii at myway.com>
** Copyright (C) 2011 O. Bahri Gordebak <gordebak at gmail.com>
**
**
** This file may be used under the terms of the GNU General Public
** License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "GUIObject.h"
#include <iostream>
#include <list>
using namespace std;
//Set the GUIObjectRoot to NULL.
GUIObject* GUIObjectRoot=NULL;
//Initialise the event queue.
list<GUIEvent> GUIEventQueue;
void GUIObjectHandleEvents(bool kill){
//Check if user resizes the window.
if(event.type==SDL_VIDEORESIZE){
onVideoResize();
//Don't let other objects process this event (?)
return;
}
//Make sure that GUIObjectRoot isn't null.
if(GUIObjectRoot)
GUIObjectRoot->handleEvents();
//Check for SDL_QUIT.
if(event.type==SDL_QUIT && kill){
//We get a quit event so enter the exit state.
setNextState(STATE_EXIT);
delete GUIObjectRoot;
GUIObjectRoot=NULL;
return;
}
//Keep calling events until there are none left.
while(!GUIEventQueue.empty()){
//Get one event and remove it from the queue.
GUIEvent e=GUIEventQueue.front();
GUIEventQueue.pop_front();
//If an eventCallback exist call it.
if(e.eventCallback){
e.eventCallback->GUIEventCallback_OnEvent(e.name,e.obj,e.eventType);
}
}
//We empty the event queue just to be sure.
GUIEventQueue.clear();
}
GUIObject::~GUIObject(){
if(cache){
SDL_FreeSurface(cache);
cache=NULL;
}
//We need to delete every child we have.
for(unsigned int i=0;i<childControls.size();i++){
delete childControls[i];
}
//Deleted the childs now empty the childControls vector.
childControls.clear();
}
bool GUIObject::handleEvents(int x,int y,bool enabled,bool visible,bool processed){
//Boolean if the event is processed.
bool b=processed;
//The GUIObject is only enabled when he and his parent are enabled.
enabled=enabled && this->enabled;
//The GUIObject is only enabled when he and his parent are enabled.
visible=visible && this->visible;
//Get the absolute position.
x+=left-gravityX;
y+=top;
//Type specific event handling.
switch(type){
case GUIObjectButton:
//Set state to 0.
state=0;
//Only check for events when the object is both enabled and visible.
if(enabled&&visible){
//The mouse location (x=i, y=j) and the mouse button (k).
int i,j,k;
k=SDL_GetMouseState(&i,&j);
//Check if the mouse is inside the GUIObject.
if(i>=x&&i<x+width&&j>=y&&j<y+height){
//We have hover so set state to one.
state=1;
//Check for a mouse button press.
if(k&SDL_BUTTON(1))
state=2;
//Check if there's a mouse press and the event hasn't been already processed.
if(event.type==SDL_MOUSEBUTTONUP && event.button.button==SDL_BUTTON_LEFT && !b){
//If event callback is configured then add an event to the queue.
if(eventCallback){
GUIEvent e={eventCallback,name,this,GUIEventClick};
GUIEventQueue.push_back(e);
}
//Event has been processed.
b=true;
}
}
}
break;
case GUIObjectCheckBox:
//Set state to 0.
state=0;
//Only check for events when the object is both enabled and visible.
if(enabled&&visible){
//The mouse location (x=i, y=j) and the mouse button (k).
int i,j,k;
k=SDL_GetMouseState(&i,&j);
//Check if the mouse is inside the GUIObject.
if(i>=x&&i<x+width&&j>=y&&j<y+height){
//We have hover so set state to one.
state=1;
//Check for a mouse button press.
if(k&SDL_BUTTON(1))
state=2;
//Check if there's a mouse press and the event hasn't been already processed.
if(event.type==SDL_MOUSEBUTTONUP && event.button.button==SDL_BUTTON_LEFT && !b){
//It's a checkbox so toggle the value.
value=value?0:1;
//If event callback is configured then add an event to the queue.
if(eventCallback){
GUIEvent e={eventCallback,name,this,GUIEventClick};
GUIEventQueue.push_back(e);
}
//Event has been processed.
b=true;
}
}
}
break;
case GUIObjectTextBox:
//NOTE: We don't reset the state to have a "focus" effect.
-
+
//Only check for events when the object is both enabled and visible.
if(enabled&&visible){
//Check if there's a key press and the event hasn't been already processed.
if(state==2 && event.type==SDL_KEYDOWN && !b){
//Get the keycode.
int key=(int)event.key.keysym.unicode;
//Check if the key is supported.
if(key>=32&&key<=126){
//Add the key to the text after the carrot.
caption.insert((size_t)value,1,char(key));
value=clamp(value+1,0,caption.length());
//If there is an event callback then call it.
if(eventCallback){
GUIEvent e={eventCallback,name,this,GUIEventChange};
GUIEventQueue.push_back(e);
}
}else if(event.key.keysym.sym==SDLK_BACKSPACE){
//We need to remove a character so first make sure that there is text.
if(caption.length()>0&&value>0){
//Remove the character before the carrot.
value=clamp(value-1,0,caption.length());
caption.erase((size_t)value,1);
//If there is an event callback then call it.
if(eventCallback){
GUIEvent e={eventCallback,name,this,GUIEventChange};
GUIEventQueue.push_back(e);
}
}
}else if(event.key.keysym.sym==SDLK_DELETE){
//We need to remove a character so first make sure that there is text.
if(caption.length()>0){
//Remove the character after the carrot.
value=clamp(value,0,caption.length());
caption.erase((size_t)value,1);
//If there is an event callback then call it.
if(eventCallback){
GUIEvent e={eventCallback,name,this,GUIEventChange};
GUIEventQueue.push_back(e);
}
}
}else if(event.key.keysym.sym==SDLK_RIGHT){
value=clamp(value+1,0,caption.length());
}else if(event.key.keysym.sym==SDLK_LEFT){
value=clamp(value-1,0,caption.length());
- }
-
+ }
+
//The event has been processed.
b=true;
}
//The mouse location (x=i, y=j) and the mouse button (k).
int i,j,k;
k=SDL_GetMouseState(&i,&j);
//Check if the mouse is inside the GUIObject.
if(i>=x&&i<x+width&&j>=y&&j<y+height){
//We can only increase our state. (nothing->hover->focus).
if(state!=2){
state=1;
}
//Check for a mouse button press.
if(k&SDL_BUTTON(1)){
//We have focus.
state=2;
//TODO Move carrot to place clicked
value=caption.length();
}
}else{
//The mouse is outside the TextBox.
//If we don't have focus but only hover we lose it.
if(state==1){
state=0;
}
//If it's a click event outside the textbox then we blur.
if(event.type==SDL_MOUSEBUTTONUP && event.button.button==SDL_BUTTON_LEFT){
//Set state to 0.
state=0;
}
}
}
break;
}
//Also let the children handle their events.
for(unsigned int i=0;i<childControls.size();i++){
bool b1=childControls[i]->handleEvents(x,y,enabled,visible,b);
//The event is processed when either our or the childs is true (or both).
b=b||b1;
}
return b;
}
-void GUIObject::render(int x,int y){
+void GUIObject::render(int x,int y,bool draw){
//Rectangle the size of the GUIObject, used to draw borders.
SDL_Rect r;
//There's no need drawing the GUIObject when it's invisible.
if(!visible)
return;
//Get the absolute x and y location.
x+=left;
y+=top;
//Check if the enabled state changed or the caption, if so we need to clear the (old) cache.
if(enabled!=cachedEnabled || caption.compare(cachedCaption)!=0 || width<=0){
//Free the cache.
SDL_FreeSurface(cache);
cache=NULL;
//And cache the new values.
cachedEnabled=enabled;
cachedCaption=caption;
//Finally resize the widget
if(autoWidth)
width=-1;
}
//Now do the type specific rendering.
switch(type){
case GUIObjectLabel:
{
//The rectangle is simple.
r.x=x;
r.y=y;
r.w=width;
r.h=height;
//We don't draw a background and/or border since that label is transparent.
//Get the caption and make sure it isn't empty.
const char* lp=caption.c_str();
if(lp!=NULL && lp[0]){
//Render the text using the small font.
if(cache==NULL){
//Color the text will be: black.
SDL_Color black={0,0,0,0};
cache=TTF_RenderUTF8_Blended(fontText,lp,black);
if(width<=0){
width=cache->w;
}
if(gravity==GUIGravityCenter){
gravityX=int((width - cache->w)/2);
}else if(gravity==GUIGravityRight){
gravityX=width - cache->w;
}
}
- //Center the text vertically and draw it to the screen.
- r.y=y+(height - cache->h)/2;
- r.x+=gravityX;
- SDL_BlitSurface(cache,NULL,screen,&r);
+ if(draw){
+ //Center the text vertically and draw it to the screen.
+ r.y=y+(height - cache->h)/2;
+ r.x+=gravityX;
+ SDL_BlitSurface(cache,NULL,screen,&r);
+ }
}
}
break;
case GUIObjectCheckBox:
{
//The rectangle is simple.
r.x=x;
r.y=y;
r.w=width;
r.h=height;
//Get the text.
const char* lp=caption.c_str();
//Make sure it isn't empty.
if(lp!=NULL && lp[0]){
//We render black text.
if(!cache){
SDL_Color black={0,0,0,0};
cache=TTF_RenderUTF8_Blended(fontText,lp,black);
}
- //Calculate the location, center it vertically.
- r.x=x;
- r.y=y+(height - cache->h)/2;
+ if(draw){
+ //Calculate the location, center it vertically.
+ r.x=x;
+ r.y=y+(height - cache->h)/2;
- //Draw the text and free the surface.
- SDL_BlitSurface(cache,NULL,screen,&r);
+ //Draw the text and free the surface.
+ SDL_BlitSurface(cache,NULL,screen,&r);
+ }
}
- //Draw the check (or not).
- SDL_Rect r1={0,0,16,16};
- if(value==1||value==2)
- r1.x=value*16;
- r.x=x+width-20;
- r.y=y+(height-16)/2;
- SDL_BlitSurface(bmGUI,&r1,screen,&r);
+ if(draw){
+ //Draw the check (or not).
+ SDL_Rect r1={0,0,16,16};
+ if(value==1||value==2)
+ r1.x=value*16;
+ r.x=x+width-20;
+ r.y=y+(height-16)/2;
+ SDL_BlitSurface(bmGUI,&r1,screen,&r);
+ }
}
break;
case GUIObjectButton:
{
//Get the text.
const char* lp=caption.c_str();
//Make sure the text isn't empty.
if(lp!=NULL && lp[0]){
if(!cache){
//Draw black text.
SDL_Color black={0,0,0,0};
//Draw in gray when disabled.
if(!enabled)
black.r=black.g=black.b=96;
if(!smallFont)
cache=TTF_RenderUTF8_Blended(fontGUI,lp,black);
else
cache=TTF_RenderUTF8_Blended(fontGUISmall,lp,black);
if(width<=0){
width=cache->w+50;
if(gravity==GUIGravityCenter){
gravityX=int(width/2);
}else if(gravity==GUIGravityRight){
gravityX=width;
}
}
}
- //Center the text both vertically as horizontally.
- r.x=x-gravityX+(width-cache->w)/2;
- r.y=y+(height-cache->h)/2;
+ if(draw){
+ //Center the text both vertically as horizontally.
+ r.x=x-gravityX+(width-cache->w)/2;
+ r.y=y+(height-cache->h)/2;
- //Check if the arrows don't fall of.
- if(cache->w+32<=width){
- //Create a rectangle that selects the right image from bmGUI,
- SDL_Rect r2={64,0,16,16};
- if(state==1){
- applySurface(x-gravityX+(width-cache->w)/2-25,y+(height-cache->h)/2+((cache->h-16)/2),bmGUI,screen,&r2);
- r2.x-=16;
- applySurface(x-gravityX+(width-cache->w)/2+4+cache->w+5,y+(height-cache->h)/2+((cache->h-16)/2),bmGUI,screen,&r2);
- }else if(state==2){
- applySurface(x-gravityX+(width-cache->w)/2-20,y+(height-cache->h)/2+((cache->h-16)/2),bmGUI,screen,&r2);
- r2.x-=16;
- applySurface(x-gravityX+(width-cache->w)/2+4+cache->w,y+(height-cache->h)/2+((cache->h-16)/2),bmGUI,screen,&r2);
+ //Check if the arrows don't fall of.
+ if(cache->w+32<=width){
+ //Create a rectangle that selects the right image from bmGUI,
+ SDL_Rect r2={64,0,16,16};
+ if(state==1){
+ applySurface(x-gravityX+(width-cache->w)/2-25,y+(height-cache->h)/2+((cache->h-16)/2),bmGUI,screen,&r2);
+ r2.x-=16;
+ applySurface(x-gravityX+(width-cache->w)/2+4+cache->w+5,y+(height-cache->h)/2+((cache->h-16)/2),bmGUI,screen,&r2);
+ }else if(state==2){
+ applySurface(x-gravityX+(width-cache->w)/2-20,y+(height-cache->h)/2+((cache->h-16)/2),bmGUI,screen,&r2);
+ r2.x-=16;
+ applySurface(x-gravityX+(width-cache->w)/2+4+cache->w,y+(height-cache->h)/2+((cache->h-16)/2),bmGUI,screen,&r2);
+ }
}
- }
- //Draw the text and free the surface.
- SDL_BlitSurface(cache,NULL,screen,&r);
+ //Draw the text and free the surface.
+ SDL_BlitSurface(cache,NULL,screen,&r);
+ }
}
}
break;
case GUIObjectTextBox:
{
- //Default background opacity
- int clr=50;
- //If hovering or focused make background more visible.
- if(state==1)
- clr=128;
- else if (state==2)
- clr=100;
+ if(draw){
+ //Default background opacity
+ int clr=50;
+ //If hovering or focused make background more visible.
+ if(state==1)
+ clr=128;
+ else if (state==2)
+ clr=100;
- //Draw the box.
- Uint32 color=0xFFFFFF00|clr;
- drawGUIBox(x,y,width,height,screen,color);
+ //Draw the box.
+ Uint32 color=0xFFFFFF00|clr;
+ drawGUIBox(x,y,width,height,screen,color);
+ }
//Get the text.
const char* lp=caption.c_str();
//Make sure it isn't empty.
if(lp!=NULL && lp[0]){
if(!cache){
//Draw the black text.
SDL_Color black={0,0,0,0};
cache=TTF_RenderUTF8_Blended(fontText,lp,black);
}
- //Calculate the location, center it vertically.
- r.x=x+2;
- r.y=y+(height - cache->h)/2;
+ if(draw){
+ //Calculate the location, center it vertically.
+ r.x=x+2;
+ r.y=y+(height - cache->h)/2;
- //Draw the text.
- SDL_Rect tmp={0,0,width-2,25};
- SDL_BlitSurface(cache,&tmp,screen,&r);
- //Only draw the carrot when focus.
- if(state==2){
- r.x=x;
- r.y=y+4;
- r.w=2;
- r.h=height-8;
+ //Draw the text.
+ SDL_Rect tmp={0,0,width-2,25};
+ SDL_BlitSurface(cache,&tmp,screen,&r);
+ //Only draw the carrot when focus.
+ if(state==2){
+ r.x=x;
+ r.y=y+4;
+ r.w=2;
+ r.h=height-8;
- int advance;
- for(int n=0;n<value;n++){
- TTF_GlyphMetrics(fontText,caption[n],NULL,NULL,NULL,NULL,&advance);
- r.x+=advance;
- }
+ int advance;
+ for(int n=0;n<value;n++){
+ TTF_GlyphMetrics(fontText,caption[n],NULL,NULL,NULL,NULL,&advance);
+ r.x+=advance;
+ }
- //Make sure that the carrot is inside the textbox.
- if(r.x<x+width)
- SDL_FillRect(screen,&r,0);
+ //Make sure that the carrot is inside the textbox.
+ if(r.x<x+width)
+ SDL_FillRect(screen,&r,0);
+ }
}
}else{
//Only draw the carrot when focus.
- if(state==2){
+ if(state==2&&draw){
r.x=x+4;
r.y=y+4;
r.w=2;
r.h=height-8;
SDL_FillRect(screen,&r,0);
}
}
}
break;
case GUIObjectFrame:
{
- //Create a rectangle the size of the button and fill it.
- Uint32 color=0xDDDDDDFF;
- drawGUIBox(x,y,width,height,screen,color);
+ if(draw){
+ //Create a rectangle the size of the button and fill it.
+ Uint32 color=0xDDDDDDFF;
+ drawGUIBox(x,y,width,height,screen,color);
+ }
//Get the title text.
const char* lp=caption.c_str();
//Make sure it isn't empty.
if(lp!=NULL && lp[0]){
if(!cache){
//The colors black and white used to render the title with white background.
SDL_Color black={0,0,0,0};
cache=TTF_RenderUTF8_Blended(fontGUI,lp,black);
}
- //Calculate the location, center horizontally and vertically relative to the top.
- r.x=x+(width-cache->w)/2;
- r.y=y+6;
+ if(draw){
+ //Calculate the location, center horizontally and vertically relative to the top.
+ r.x=x+(width-cache->w)/2;
+ r.y=y+6;
- //Draw the text and free the surface.
- SDL_BlitSurface(cache,NULL,screen,&r);
+ //Draw the text and free the surface.
+ SDL_BlitSurface(cache,NULL,screen,&r);
+ }
}
}
break;
}
//We now need to draw all the children of the GUIObject.
for(unsigned int i=0;i<childControls.size();i++){
- childControls[i]->render(x,y);
+ childControls[i]->render(x,y,draw);
}
}
diff --git a/src/GUIObject.h b/src/GUIObject.h
index 3322986..98ab3fd 100644
--- a/src/GUIObject.h
+++ b/src/GUIObject.h
@@ -1,195 +1,196 @@
/****************************************************************************
** Copyright (C) 2011 Luka Horvat <redreaper132 at gmail.com>
** Copyright (C) 2011 Edward Lii <edward_iii at myway.com>
** Copyright (C) 2011 O. Bahri Gordebak <gordebak at gmail.com>
**
**
** This file may be used under the terms of the GNU General Public
** License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#ifndef GUIOBJECT_H
#define GUIOBJECT_H
#include "Globals.h"
#include "Functions.h"
#include "FileManager.h"
#include <string>
#include <vector>
#include <list>
//Ids for the different GUIObject types.
//None is a special type, it has no visual form.
const int GUIObjectNone=0;
//A label used to dispaly text.
const int GUIObjectLabel=1;
//Button which will invoke an event when pressed.
const int GUIObjectButton=2;
//Checkbox which represents a boolean value and can be toggled.
const int GUIObjectCheckBox=3;
//A text box used to enter text.
const int GUIObjectTextBox=5;
//Frame which is like a container.
const int GUIObjectFrame=6;
//Widget gravity properties
const int GUIGravityLeft=0;
const int GUIGravityCenter=1;
const int GUIGravityRight=2;
//The event id's.
//A click event used for e.g. buttons.
const int GUIEventClick=0;
//A change event used for e.g. textboxes.
const int GUIEventChange=1;
class GUIObject;
//Class that is used as event callback.
class GUIEventCallback{
public:
//This method is called when an event is fired.
//name: The name of the event.
//obj: Pointer to the GUIObject which caused this event.
//eventType: The type of event as defined above.
virtual void GUIEventCallback_OnEvent(std::string name,GUIObject* obj,int eventType)=0;
};
//Class containing the
class GUIObject{
public:
//The relative x location of the GUIObject.
int left;
//The relative y location of the GUIObject.
int top;
//The width of the GUIObject.
int width;
//The height of the GUIObject.
int height;
//The type of the GUIObject.
int type;
//The value of the GUIObject.
//It depends on the type of GUIObject what it means.
int value;
//The name of the GUIObject.
std::string name;
//The caption of the GUIObject.
//It depends on the type of GUIObject what it is.
std::string caption;
//Boolean if the GUIObject is enabled.
bool enabled;
//Boolean if the GUIObject is visible.
bool visible;
//Vector containing the children of the GUIObject.
std::vector<GUIObject*> childControls;
//Event callback used to invoke events.
GUIEventCallback* eventCallback;
//Widget's gravity to centering
int gravity;
int gravityX;
bool autoWidth;
//Use small font
bool smallFont;
protected:
//The state of the GUIObject.
//It depends on the type of GUIObject where it's used for.
int state;
//Surface containing some gui images.
SDL_Surface* bmGUI;
//Surface that can be used to cache rendered text.
SDL_Surface* cache;
//String containing the old caption to detect if it changed.
std::string cachedCaption;
//Boolean containing the previous enabled state.
bool cachedEnabled;
public:
//Constructor.
//left: The relative x location of the GUIObject.
//top: The relative y location of the GUIObject.
//witdh: The width of the GUIObject.
//height: The height of the GUIObject.
//type: The type of the GUIObject.
//caption: The text on the GUIObject.
//value: The value of the GUIObject.
//enabled: Boolean if the GUIObject is enabled or not.
//visible: Boolean if the GUIObject is visisble or not.
//gravity: The way the GUIObject needs to be aligned.
GUIObject(int left=0,int top=0,int width=0,int height=0,int type=0,
const char* caption=NULL,int value=0,
bool enabled=true,bool visible=true,int gravity=0):
left(left),top(top),width(width),height(height),
type(type),gravity(gravity),value(value),
enabled(enabled),visible(visible),
eventCallback(NULL),state(0),
cache(NULL),cachedEnabled(enabled),gravityX(0),smallFont(false)
{
//Make sure that caption isn't NULL before setting it.
if(caption){
GUIObject::caption=caption;
//And set the cached caption.
cachedCaption=caption;
}
if(width<=0)
autoWidth=true;
else
autoWidth=false;
//Load the gui images.
bmGUI=loadImage(getDataPath()+"gfx/gui.png");
}
//Destructor.
virtual ~GUIObject();
//Method used to handle mouse and/or key events.
//x: The x mouse location.
//y: The y mouse location.
//enabled: Boolean if the parent is enabled or not.
//visible: Boolean if the parent is visible or not.
//processed: Boolean if the event has been processed (by the parent) or not.
//Returns: Boolean if the event is processed by the child.
virtual bool handleEvents(int x=0,int y=0,bool enabled=true,bool visible=true,bool processed=false);
//Method that will render the GUIObject.
//x: The x location to draw the GUIObject. (x+left)
//y: The y location to draw the GUIObject. (y+top)
- virtual void render(int x=0,int y=0);
+ //draw: Draw widget or just update it without drawing
+ virtual void render(int x=0,int y=0,bool draw=true);
};
//Method used to handle the GUIEvents from the GUIEventQueue.
//kill: Boolean if an SDL_QUIT event may kill the GUIObjectRoot.
void GUIObjectHandleEvents(bool kill=false);
//A structure containing the needed variables to call an event.
struct GUIEvent{
//Event callback used to invoke the event.
GUIEventCallback* eventCallback;
//The name of the event.
std::string name;
//Pointer to the object which invoked the event.
GUIObject* obj;
//The type of event.
int eventType;
};
//List used to queue the gui events.
extern std::list<GUIEvent> GUIEventQueue;
#endif
diff --git a/src/GUIScrollBar.cpp b/src/GUIScrollBar.cpp
index d1c7222..bc5db73 100644
--- a/src/GUIScrollBar.cpp
+++ b/src/GUIScrollBar.cpp
@@ -1,388 +1,388 @@
/****************************************************************************
** Copyright (C) 2011 Luka Horvat <redreaper132 at gmail.com>
** Copyright (C) 2011 Edward Lii <edward_iii at myway.com>
** Copyright (C) 2011 O. Bahri Gordebak <gordebak at gmail.com>
**
**
** This file may be used under the terms of the GNU General Public
** License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "GUIScrollBar.h"
using namespace std;
void GUIScrollBar::calcPos(){
//Floats ...
float f,f1=0.0f,f2;
//The value can't be below the minimum value or above the maximum.
if(value<minValue)
value=minValue;
else if(value>maxValue)
value=maxValue;
//
if(orientation){
f=(float)(top+16);
f2=(float)(height-32);
}else{
f=(float)(left+16);
f2=(float)(width-32);
}
if(largeChange<=0) f2=-1;
if(f2>0){
valuePerPixel = (maxValue - minValue + largeChange) / f2;
if(valuePerPixel > 0.0001f) f1 = largeChange / valuePerPixel;
if(f1 < 4 && f2 > 4){
valuePerPixel = (maxValue - minValue) / (f2 - 4);
f1 = 4;
}
thumbStart = f + (value - minValue) / valuePerPixel;
thumbEnd = thumbStart + f1;
}else{
valuePerPixel = -1;
thumbStart = f;
thumbEnd = f - 1;
}
}
bool GUIScrollBar::handleEvents(int x,int y,bool enabled,bool visible,bool processed){
//Boolean if the event is processed.
bool b=processed;
//The GUIObject is only enabled when he and his parent are enabled.
enabled=enabled && this->enabled;
//The GUIObject is only enabled when he and his parent are enabled.
visible=visible && this->visible;
//Check if the mouse button is released.
if(event.type==SDL_MOUSEBUTTONUP || !(enabled&&visible)){
//It so we have lost any focus at all.
state=0;
}else if(event.type==SDL_MOUSEMOTION || event.type==SDL_MOUSEBUTTONDOWN){
//The mouse button is down and it's moving
int i,j,k,f,f1,f2,f3;
state&=~0xFF;
k=SDL_GetMouseState(&i,&j);
i-=x;
j-=y;
bool bInControl_0;
if(orientation){
f=top;
f1=f+height;
bInControl_0=(i>=left&&i<left+width);
i=j;
}else{
f=left;
f1=f+width;
bInControl_0=(j>=top&&j<top+height);
}
//===
if((state&0x0000FF00)==0x300&&(k&SDL_BUTTON(1))&&event.type==SDL_MOUSEMOTION&&valuePerPixel>0){
//drag thumb
state|=3;
int val = criticalValue + (int)(((float)i - startDragPos) * valuePerPixel + 0.5f);
if(val<minValue) val=minValue;
else if(val>maxValue) val=maxValue;
if(value!=val){
value=val;
changed=true;
}
b=true;
}else if(bInControl_0){
if(valuePerPixel > 0){
f2=f+16;
f3=f1-16;
}else{
f2=f3=(f+f1)/2;
}
if(i<f){ //do nothing
}else if(i<f2){ //-smallchange
state=(state&~0xFF)|1;
if(event.type==SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT) state=(state&~0x0000FF00)|((state&0xFF)<<8);
else if((state&0x0000FF00)&&((state&0xFF)!=((state>>8)&0xFF))) state&=~0xFF;
if(event.type==SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT){
int val=value-smallChange;
if(val<minValue) val=minValue;
if(value!=val){
value=val;
changed=true;
}
timer=8;
}
b=true;
}else if(i>=f3 && i<f1){ //+smallchange
state=(state&~0xFF)|5;
if(event.type==SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT) state=(state&~0x0000FF00)|((state&0xFF)<<8);
else if((state&0x0000FF00)&&((state&0xFF)!=((state>>8)&0xFF))) state&=~0xFF;
if(event.type==SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT){
int val=value+smallChange;
if(val>maxValue) val=maxValue;
if(value!=val){
value=val;
changed=true;
}
timer=8;
}
b=true;
}else if(valuePerPixel<=0){ //do nothing
}else if(i<(int)thumbStart){ //-largechange
state=(state&~0xFF)|2;
if(event.type==SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT) state=(state&~0x0000FF00)|((state&0xFF)<<8);
else if((state&0x0000FF00)&&((state&0xFF)!=((state>>8)&0xFF))) state&=~0xFF;
if(event.type==SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT){
int val=value-largeChange;
if(val<minValue) val=minValue;
if(value!=val){
value=val;
changed=true;
}
timer=8;
}
if(state&0xFF) criticalValue = minValue + (int)(float(i - f2) * valuePerPixel + 0.5f);
b=true;
}else if(i<(int)thumbEnd){ //start drag
state=(state&~0xFF)|3;
if(event.type==SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT) state=(state&~0x0000FF00)|((state&0xFF)<<8);
else if((state&0x0000FF00)&&((state&0xFF)!=((state>>8)&0xFF))) state&=~0xFF;
if(event.type==SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT){
criticalValue=value;
startDragPos = (float)i;
}
b=true;
}else if(i<f3){ //+largechange
state=(state&~0xFF)|4;
if(event.type==SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT) state=(state&~0x0000FF00)|((state&0xFF)<<8);
else if((state&0x0000FF00)&&((state&0xFF)!=((state>>8)&0xFF))) state&=~0xFF;
if(event.type==SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT){
int val=value+largeChange;
if(val>maxValue) val=maxValue;
if(value!=val){
value=val;
changed=true;
}
timer=8;
}
if(state&0xFF) criticalValue = minValue - largeChange + (int)(float(i - f2) * valuePerPixel + 0.5f);
b=true;
}
}
}
//Get the absolute position.
x+=left;
y+=top;
//Also let the children handle their events.
for(unsigned int i=0;i<childControls.size();i++){
bool b1=childControls[i]->handleEvents(x,y,enabled,visible,b);
//The event is processed when either our or the childs is true (or both).
b=b||b1;
}
return b;
}
void GUIScrollBar::renderScrollBarButton(int index,int x1,int y1,int x2,int y2,int srcleft,int srctop){
//Make sure the button isn't inverted.
if(x2<=x1||y2<=y1)
return;
//The color.
int clr=-1;
//Rectangle the size of the button.
SDL_Rect r={x1,y1,x2-x1,y2-y1};
//Check
if((state&0xFF)==index){
if(((state>>8)&0xFF)==index){
//Set the color gray.
clr=0xDDDDDDFF;
}else{
//Set the color to lightgray.
clr=0xFFFFFFFF;
}
}
//Draw a box.
drawGUIBox(r.x,r.y,r.w,r.h,screen,clr);
//Boolean if there should be an image on the button.
bool b;
//The check depends on the orientation.
if(orientation)
b=(y2-y1>=14);
else
b=(x2-x1>=14);
//Check if the image can be drawn.
if(b&&srcleft>=0&&srctop>=0){
//It can thus draw it.
SDL_Rect r1={srcleft,srctop,16,16};
r.x=(x1+x2)/2-8;
r.y=(y1+y2)/2-8;
SDL_BlitSurface(bmGUI,&r1,screen,&r);
}
}
-void GUIScrollBar::render(int x,int y){
+void GUIScrollBar::render(int x,int y,bool draw){
//There's no use in rendering the scrollbar when invisible.
if(!visible)
return;
//Check if the scrollbar is enabled.
if(enabled){
//Check if the state is right.
if((state&0xFF)==((state>>8)&0xFF)){
//Switch the state (change)/
switch(state&0xFF){
case 1:
//It's a small negative change.
//Check if it's time.
if((--timer)<=0){
//Reduce the value.
int val=value-smallChange;
//Make sure it doesn't go too low.
if(val<minValue)
val=minValue;
if(value!=val){
value=val;
changed=true;
}
//Set the time to two.
timer=2;
}
break;
case 2:
//It's a lager negative change.
//Check if it's time.
if((--timer)<=0){
if(value<criticalValue)
state&=~0xFF;
else{
//Reduce the value.
int val=value-largeChange;
//Make sure it doesn't go too low.
if(val<minValue)
val=minValue;
if(value!=val){
value=val;
changed=true;
}
//Set the time to two.
timer=2;
}
}
break;
case 4:
//It's a lager positive change.
//Check if it's time.
if((--timer)<=0){
if(value>criticalValue)
state&=~0xFF;
else{
//Increase the value.
int val=value+largeChange;
//Make sure it doesn't go too high.
if(val>maxValue)
val=maxValue;
if(value!=val){
value=val;
changed=true;
}
//Set the time to two.
timer=2;
}
}
break;
case 5:
//It's a small positive change.
//Check if it's time.
if((--timer)<=0){
//Increase the value.
int val=value+smallChange;
//Make sure ti doesn't go too high.
if(val>maxValue)
val=maxValue;
if(value!=val){
value=val;
changed=true;
}
//Set the time to two.
timer=2;
}
break;
}
}
}
//If the scrollbar changed then invoke a GUIEvent.
if(changed){
if(eventCallback){
GUIEvent e={eventCallback,name,this,GUIEventChange};
GUIEventQueue.push_back(e);
}
changed=false;
}
//We calculate the position since it could have changed.
calcPos();
//Now the actual drawing begins.
- if(orientation){
+ if(orientation&&draw){
//The scrollbar is vertically orientated.
if(valuePerPixel>0){
//There are four buttons so draw them.
renderScrollBarButton(2,x+left,y+top,x+left+width,y+top+height,-1,-1);
renderScrollBarButton(1,x+left,y+top,x+left+width,y+top+16,80,0);
renderScrollBarButton(3,x+left,y-1+(int)thumbStart,x+left+width,y+1+(int)thumbEnd,0,16);
renderScrollBarButton(5,x+left,y+top+height-16,x+left+width,y+top+height,96,0);
}else{
//There are two buttons so draw them.
int f=top+height/2;
renderScrollBarButton(1,x+left,y+top,x+left+width,y+1+f,80,0);
renderScrollBarButton(5,x+left,y+f,x+left+width,y+top+height,96,0);
}
}else{
//The scrollbar is horizontally orientated.
if(valuePerPixel>0){
//There are five buttons so draw them.
renderScrollBarButton(1,x+left,y+top,x+left+16,y+top+height,48,0);
renderScrollBarButton(2,x+left+15,y+top,x+(int)thumbStart,y+top+height,-1,-1);
renderScrollBarButton(3,x-1+(int)thumbStart,y+top,x+1+(int)thumbEnd,y+top+height,16,16);
renderScrollBarButton(4,x+(int)thumbEnd,y+top,x+left+width-15,y+top+height,-1,-1);
renderScrollBarButton(5,x+left+width-16,y+top,x+left+width,y+top+height,64,0);
}else{
//There are two buttons so draw them.
int f=left+width/2;
renderScrollBarButton(1,x+left,y+top,x+1+f,y+top+height,48,0);
renderScrollBarButton(5,x+f,y+top,x+left+width,y+top+height,64,0);
}
}
//Get the absolute position.
x+=left;
y+=top;
//We now need to draw all the children of the GUIObject.
for(unsigned int i=0;i<childControls.size();i++){
- childControls[i]->render(x,y);
+ childControls[i]->render(x,y,draw);
}
}
diff --git a/src/GUIScrollBar.h b/src/GUIScrollBar.h
index 9943d25..8f03bc8 100644
--- a/src/GUIScrollBar.h
+++ b/src/GUIScrollBar.h
@@ -1,96 +1,96 @@
/****************************************************************************
** Copyright (C) 2011 Luka Horvat <redreaper132 at gmail.com>
** Copyright (C) 2011 Edward Lii <edward_iii at myway.com>
** Copyright (C) 2011 O. Bahri Gordebak <gordebak at gmail.com>
**
**
** This file may be used under the terms of the GNU General Public
** License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#ifndef GUISCROLLBAR_H
#define GUISCROLLBAR_H
#include "GUIObject.h"
//Constant integers containing the two possible orientations of the scrollbar.
const int ScrollBarHorizontal=0;
const int ScrollBarVertical=1;
class GUIScrollBar:public GUIObject{
public:
//The minimum value of the scrollbar.
int minValue;
//The maximum value of the scrollbar.
int maxValue;
//The step size when a small step is made.
int smallChange;
//The step size when a large step is made.
int largeChange;
//The orientation of the scrollbar.
int orientation;
private:
//
float thumbStart;
//
float thumbEnd;
float valuePerPixel;
//Float containing the start position when dragging the scrollbar.
float startDragPos;
int criticalValue;
int timer;
//Boolean if the scrollbar position has changed.
bool changed;
//Method that will calculate the position of the scrollbar.
void calcPos();
//Method that will render a scrollbar button.
//index:
//x1:
//y1:
//x2:
//y2:
//srcLeft:
//srcRight:
void renderScrollBarButton(int index,int x1,int y1,int x2,int y2,int srcLeft,int srcTop);
public:
GUIScrollBar(int left=0,int top=0,int width=0,int height=0,int orientation=0,
int value=0,int minValue=0,int maxValue=100,int smallChange=10,int largeChange=50,
bool enabled=true,bool visible=true):
GUIObject(left,top,width,height,0,NULL,value,enabled,visible),
minValue(minValue),maxValue(maxValue),smallChange(smallChange),largeChange(largeChange),orientation(orientation),
criticalValue(0),timer(0),changed(false)
{
//In the constructor we simply call calcPos().
calcPos();
}
//Method used to handle mouse and/or key events.
//x: The x mouse location.
//y: The y mouse location.
//enabled: Boolean if the parent is enabled or not.
//visible: Boolean if the parent is visible or not.
//processed: Boolean if the event has been processed (by the parent) or not.
//Returns: Boolean if the event is processed by the child.
virtual bool handleEvents(int x=0,int y=0,bool enabled=true,bool visible=true,bool processed=false);
//Method that will render the GUIScrollBar.
//x: The x location to draw the GUIObject. (x+left)
//y: The y location to draw the GUIObject. (y+top)
- virtual void render(int x=0,int y=0);
+ virtual void render(int x=0,int y=0,bool draw=true);
};
#endif
diff --git a/src/GUISlider.cpp b/src/GUISlider.cpp
index 6c56c32..84c3b14 100644
--- a/src/GUISlider.cpp
+++ b/src/GUISlider.cpp
@@ -1,289 +1,289 @@
/****************************************************************************
** Copyright (C) 2011 Luka Horvat <redreaper132 at gmail.com>
** Copyright (C) 2011 Edward Lii <edward_iii at myway.com>
** Copyright (C) 2011 O. Bahri Gordebak <gordebak at gmail.com>
**
**
** This file may be used under the terms of the GNU General Public
** License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "GUISlider.h"
using namespace std;
void GUISlider::calcPos(){
//Floats ...
float f,f1=0.0f,f2;
//The value can't be below the minimum value or above the maximum.
if(value<minValue)
value=minValue;
else if(value>maxValue)
value=maxValue;
//
f=(float)(left+1);
f2=(float)(width-2);
if(largeChange<=0) f2=-1;
if(f2>0){
valuePerPixel = (maxValue - minValue + largeChange) / f2;
if(valuePerPixel > 0.0001f) f1 = largeChange / valuePerPixel;
if(f1 < 4 && f2 > 4){
valuePerPixel = (maxValue - minValue) / (f2 - 4);
f1 = 4;
}
thumbStart = f + (value - minValue) / valuePerPixel;
thumbEnd = thumbStart + f1;
}else{
valuePerPixel = -1;
thumbStart = f;
thumbEnd = f - 1;
}
}
bool GUISlider::handleEvents(int x,int y,bool enabled,bool visible,bool processed){
//Boolean if the event is processed.
bool b=processed;
//The GUIObject is only enabled when he and his parent are enabled.
enabled=enabled && this->enabled;
//The GUIObject is only enabled when he and his parent are enabled.
visible=visible && this->visible;
//Check if the mouse button is released.
if(event.type==SDL_MOUSEBUTTONUP || !(enabled&&visible)){
//It so we have lost any focus at all.
state=0;
}else if(event.type==SDL_MOUSEMOTION || event.type==SDL_MOUSEBUTTONDOWN){
//The mouse button is down and it's moving
int i,j,k,f,f1,f2,f3;
state&=~0xFF;
k=SDL_GetMouseState(&i,&j);
i-=x;
j-=y;
bool bInControl_0;
f=left;
f1=f+width;
bInControl_0=(j>=top&&j<top+height);
//===
if((state&0x0000FF00)==0x300&&(k&SDL_BUTTON(1))&&event.type==SDL_MOUSEMOTION&&valuePerPixel>0){
//drag thumb
state|=3;
int val = criticalValue + (int)(((float)i - startDragPos) * valuePerPixel + 0.5f);
if(val<minValue) val=minValue;
else if(val>maxValue) val=maxValue;
if(value!=val){
value=val;
changed=true;
}
b=true;
}else if(bInControl_0){
if(valuePerPixel > 0){
f2=f+16;
f3=f1-16;
}else{
f2=f3=(f+f1)/2;
}
if(i<f){ //do nothing
}else if(valuePerPixel<=0){ //do nothing
}else if(i<(int)thumbStart){ //-largechange
state=(state&~0xFF)|2;
if(event.type==SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT) state=(state&~0x0000FF00)|((state&0xFF)<<8);
else if((state&0x0000FF00)&&((state&0xFF)!=((state>>8)&0xFF))) state&=~0xFF;
if(event.type==SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT){
int val=value-largeChange;
if(val<minValue) val=minValue;
if(value!=val){
value=val;
changed=true;
}
timer=8;
}
if(state&0xFF) criticalValue = minValue + (int)(float(i - f2) * valuePerPixel + 0.5f);
b=true;
}else if(i<(int)thumbEnd){ //start drag
state=(state&~0xFF)|3;
if(event.type==SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT) state=(state&~0x0000FF00)|((state&0xFF)<<8);
else if((state&0x0000FF00)&&((state&0xFF)!=((state>>8)&0xFF))) state&=~0xFF;
if(event.type==SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT){
criticalValue=value;
startDragPos = (float)i;
}
b=true;
}else if(i<f3){ //+largechange
state=(state&~0xFF)|4;
if(event.type==SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT) state=(state&~0x0000FF00)|((state&0xFF)<<8);
else if((state&0x0000FF00)&&((state&0xFF)!=((state>>8)&0xFF))) state&=~0xFF;
if(event.type==SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT){
int val=value+largeChange;
if(val>maxValue) val=maxValue;
if(value!=val){
value=val;
changed=true;
}
timer=8;
}
if(state&0xFF) criticalValue = minValue - largeChange + (int)(float(i - f2) * valuePerPixel + 0.5f);
b=true;
}
}
}
//Get the absolute position.
x+=left;
y+=top;
//Also let the children handle their events.
for(unsigned int i=0;i<childControls.size();i++){
bool b1=childControls[i]->handleEvents(x,y,enabled,visible,b);
//The event is processed when either our or the childs is true (or both).
b=b||b1;
}
return b;
}
void GUISlider::renderScrollBarButton(int index,int x1,int y1,int x2,int y2,int srcleft,int srctop){
//Make sure the button isn't inverted.
if(x2<=x1||y2<=y1)
return;
//The color.
int clr=-1;
//Rectangle the size of the button.
SDL_Rect r={x1,y1,x2-x1,y2-y1};
//Check
if((state&0xFF)==index){
if(((state>>8)&0xFF)==index){
//Set the color gray.
clr=0xDDDDDDFF;
}else{
//Set the color to lightgray.
clr=0xFFFFFFFF;
}
}
//Draw a box.
drawGUIBox(r.x,r.y,r.w,r.h,screen,clr);
//Boolean if there should be an image on the button.
bool b;
b=(x2-x1>=14);
//Check if the image can be drawn.
if(b&&srcleft>=0&&srctop>=0){
//It can thus draw it.
SDL_Rect r1={srcleft,srctop,16,16};
r.x=(x1+x2)/2-8;
r.y=(y1+y2)/2-8;
SDL_BlitSurface(bmGUI,&r1,screen,&r);
}
}
-void GUISlider::render(int x,int y){
+void GUISlider::render(int x,int y,bool draw){
//There's no use in rendering the scrollbar when invisible.
- if(!visible)
+ if(!visible||!draw)
return;
//Check if the scrollbar is enabled.
if(enabled){
//Check if the state is right.
if((state&0xFF)==((state>>8)&0xFF)){
//Switch the state (change)/
switch(state&0xFF){
case 2:
//It's a lager negative change.
//Check if it's time.
if((--timer)<=0){
if(value<criticalValue)
state&=~0xFF;
else{
//Reduce the value.
int val=value-largeChange;
//Make sure it doesn't go too low.
if(val<minValue)
val=minValue;
if(value!=val){
value=val;
changed=true;
}
//Set the time to two.
timer=2;
}
}
break;
case 4:
//It's a lager positive change.
//Check if it's time.
if((--timer)<=0){
if(value>criticalValue)
state&=~0xFF;
else{
//Increase the value.
int val=value+largeChange;
//Make sure it doesn't go too high.
if(val>maxValue)
val=maxValue;
if(value!=val){
value=val;
changed=true;
}
//Set the time to two.
timer=2;
}
}
break;
}
}
}
//If the scrollbar changed then invoke a GUIEvent.
if(changed){
if(eventCallback){
GUIEvent e={eventCallback,name,this,GUIEventChange};
GUIEventQueue.push_back(e);
}
changed=false;
}
//We calculate the position since it could have changed.
calcPos();
//Now the actual drawing begins.
if(valuePerPixel>0){
//Draw the line the slider moves along.
drawGUIBox(x+left,y+top+(height-4)/2,width,4,screen,0);
renderScrollBarButton(2,x-1+(int)thumbStart,y+top+(height/4),x+1+(int)thumbEnd,y+top+(height/4)*3,16,16);
}else{
//There are two buttons so draw them.
int f=left+width/2;
renderScrollBarButton(1,x+left,y+top,x+1+f,y+top+height,48,0);
renderScrollBarButton(5,x+f,y+top,x+left+width,y+top+height,64,0);
}
//Get the absolute position.
x+=left;
y+=top;
//We now need to draw all the children of the GUIObject.
for(unsigned int i=0;i<childControls.size();i++){
- childControls[i]->render(x,y);
+ childControls[i]->render(x,y,draw);
}
}
diff --git a/src/GUISlider.h b/src/GUISlider.h
index 02c3cb1..92081fc 100644
--- a/src/GUISlider.h
+++ b/src/GUISlider.h
@@ -1,88 +1,88 @@
/****************************************************************************
** Copyright (C) 2011 Luka Horvat <redreaper132 at gmail.com>
** Copyright (C) 2011 Edward Lii <edward_iii at myway.com>
** Copyright (C) 2011 O. Bahri Gordebak <gordebak at gmail.com>
**
**
** This file may be used under the terms of the GNU General Public
** License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#ifndef GUISLIDER_H
#define GUISLIDER_H
#include "GUIObject.h"
class GUISlider:public GUIObject{
public:
//The minimum value of the slider.
int minValue;
//The maximum value of the slider.
int maxValue;
//The step size when a large step is made.
int largeChange;
private:
//
float thumbStart;
//
float thumbEnd;
//Float containing the value per pixel factor.
float valuePerPixel;
//Float containing the start position when dragging the scrollbar.
float startDragPos;
int criticalValue;
int timer;
//Boolean if the scrollbar position has changed.
bool changed;
//Method that will calculate the position of the scrollbar.
void calcPos();
//Method that will render a scrollbar button.
//index:
//x1:
//y1:
//x2:
//y2:
//srcLeft:
//srcRight:
void renderScrollBarButton(int index,int x1,int y1,int x2,int y2,int srcLeft,int srcTop);
public:
GUISlider(int left=0,int top=0,int width=0,int height=0,
int value=0,int minValue=0,int maxValue=100,int largeChange=50,
bool enabled=true,bool visible=true):
GUIObject(left,top,width,height,0,NULL,value,enabled,visible),
minValue(minValue),maxValue(maxValue),largeChange(largeChange),
criticalValue(0),timer(0),changed(false)
{
//In the constructor we simply call calcPos().
calcPos();
}
//Method used to handle mouse and/or key events.
//x: The x mouse location.
//y: The y mouse location.
//enabled: Boolean if the parent is enabled or not.
//visible: Boolean if the parent is visible or not.
//processed: Boolean if the event has been processed (by the parent) or not.
//Returns: Boolean if the event is processed by the child.
virtual bool handleEvents(int x=0,int y=0,bool enabled=true,bool visible=true,bool processed=false);
//Method that will render the GUIScrollBar.
//x: The x location to draw the GUIObject. (x+left)
//y: The y location to draw the GUIObject. (y+top)
- virtual void render(int x=0,int y=0);
+ virtual void render(int x=0,int y=0,bool draw=true);
};
#endif
diff --git a/src/GUITextArea.cpp b/src/GUITextArea.cpp
index 8248796..1a3558d 100644
--- a/src/GUITextArea.cpp
+++ b/src/GUITextArea.cpp
@@ -1,334 +1,334 @@
/****************************************************************************
** Copyright (C) 2011 Luka Horvat <redreaper132 at gmail.com>
** Copyright (C) 2011 Edward Lii <edward_iii at myway.com>
** Copyright (C) 2011 O. Bahri Gordebak <gordebak at gmail.com>
**
**
** This file may be used under the terms of the GNU General Public
** License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "GUITextArea.h"
using namespace std;
GUITextArea::GUITextArea(int left,int top,int width,int height,bool enabled,bool visible):
GUIObject(left,top,width,height,0,NULL,-1,enabled,visible){
//Set the state 0.
state=0;
key=-1;
keyHoldTime=0;
keyTime=5;
}
bool GUITextArea::handleEvents(int x,int y,bool enabled,bool visible,bool processed){
//Boolean if the event is processed.
bool b=processed;
//The GUIObject is only enabled when he and his parent are enabled.
enabled=enabled && this->enabled;
//The GUIObject is only enabled when he and his parent are enabled.
visible=visible && this->visible;
//Get the absolute position.
x+=left;
y+=top;
//NOTE: We don't reset the state to have a "focus" effect.
//Only check for events when the object is both enabled and visible.
if(enabled&&visible){
//Check if there's a key press and the event hasn't been already processed.
if(state==2 && event.type==SDL_KEYDOWN && !b){
//Get the keycode.
int key=(int)event.key.keysym.unicode;
//Check if the key is supported.
if(key>=32&&key<=126){
//Add the key to the string.
caption.insert((size_t)value,1,char(key));
value=clamp(value+1,0,caption.length());
//If there is an event callback then call it.
if(eventCallback){
GUIEvent e={eventCallback,name,this,GUIEventChange};
GUIEventQueue.push_back(e);
}
}else if(event.key.keysym.sym==SDLK_BACKSPACE){
//Set the key values correct.
this->key=SDLK_BACKSPACE;
keyHoldTime=0;
keyTime=5;
//Delete one character direct to prevent a lag.
deleteChar(true);
}else if(event.key.keysym.sym==SDLK_DELETE){
//Set the key values correct.
this->key=SDLK_DELETE;
keyHoldTime=0;
keyTime=5;
//Delete one character direct to prevent a lag.
deleteChar(false);
}else if(event.key.keysym.sym==SDLK_RETURN){
//Enter, thus place a newline.
caption+='\n';
value=clamp(value+1,0,caption.length());
//If there is an event callback then call it.
if(eventCallback){
GUIEvent e={eventCallback,name,this,GUIEventChange};
GUIEventQueue.push_back(e);
}
}else if(event.key.keysym.sym==SDLK_RIGHT){
//Set the key values correct.
this->key=SDLK_RIGHT;
keyHoldTime=0;
keyTime=5;
//Move the carrot once to prevent a lag.
value=clamp(value+1,0,caption.length());
}else if(event.key.keysym.sym==SDLK_LEFT){
//Set the key values correct.
this->key=SDLK_LEFT;
keyHoldTime=0;
keyTime=5;
//Move the carrot once to prevent a lag.
value=clamp(value-1,0,caption.length());
}
//The event has been processed.
b=true;
}else if(state==2 && event.type==SDL_KEYUP && !b){
//Check if released key is the same as the holded key.
if(event.key.keysym.sym==key){
//It is so stop the key.
key=-1;
}
}
//The mouse location (x=i, y=j) and the mouse button (k).
int i,j,k;
k=SDL_GetMouseState(&i,&j);
//Check if the mouse is inside the GUIObject.
if(i>=x&&i<x+width&&j>=y&&j<y+height){
//We can only increase our state. (nothing->hover->focus).
if(state!=2){
state=1;
}
//Check for a mouse button press.
if(k&SDL_BUTTON(1)){
//We have focus.
state=2;
//TODO Move carrot to place clicked
value=caption.length();
}
}else{
//The mouse is outside the TextBox.
//If we don't have focus but only hover we lose it.
if(state==1){
state=0;
}
//If it's a click event outside the textbox then we blur.
if(event.type==SDL_MOUSEBUTTONUP && event.button.button==SDL_BUTTON_LEFT){
//Set state to 0.
state=0;
}
}
}
//Process child controls event except for the scrollbar.
//That's why i starts at one.
for(unsigned int i=1;i<childControls.size();i++){
bool b1=childControls[i]->handleEvents(x,y,enabled,visible,b);
//The event is processed when either our or the childs is true (or both).
b=b||b1;
}
return b;
}
void GUITextArea::deleteChar(bool back){
//Boolean if an event should be called.
bool event=false;
//Check if it's backspace or delete.
if(back){
//We need to remove a character so first make sure that there is text.
if(caption.length()>0&&value>0){
//Remove the character before the carrot.
value=clamp(value-1,0,caption.length());
caption.erase((size_t)value,1);
//Set event true.
event=true;
}
}else{
if(caption.length()>0){
//Remove the character after the carrot.
value=clamp(value,0,caption.length());
caption.erase((size_t)value,1);
//Set event true.
event=true;
}
}
//If there is an event callback and a character is removed then call it.
if(event && eventCallback){
GUIEvent e={eventCallback,name,this,GUIEventChange};
GUIEventQueue.push_back(e);
}
}
-void GUITextArea::render(int x,int y){
+void GUITextArea::render(int x,int y,bool draw){
//FIXME: Logic in the render method since that is update constant.
if(key!=-1){
//Increase the key time.
keyHoldTime++;
//Make sure the deletionTime isn't to short.
if(keyHoldTime>=keyTime){
keyHoldTime=0;
keyTime--;
if(keyTime<1)
keyTime=1;
//Now check the which key it was.
switch(key){
case SDLK_BACKSPACE:
deleteChar(true);
break;
case SDLK_DELETE:
deleteChar(false);
break;
case SDLK_LEFT:
value=clamp(value-1,0,caption.length());
break;
case SDLK_RIGHT:
value=clamp(value+1,0,caption.length());
break;
}
}
}
//Rectangle the size of the GUIObject, used to draw borders.
SDL_Rect r;
//There's no need drawing the GUIObject when it's invisible.
- if(!visible)
+ if(!visible||!draw)
return;
//Get the absolute x and y location.
x+=left;
y+=top;
//Default background opacity
int clr=128;
//If hovering or focused make background more visible.
if(state==1)
clr=255;
else if (state==2)
clr=230;
//Draw the box.
Uint32 color=0xFFFFFF00|clr;
drawGUIBox(x,y,width,height,screen,color);
r.x=x+1;
r.y=y+1;
r.w=width-2;
r.h=height-2;
//Pointer to the string.
char* lps=(char*)caption.c_str();
//Pointer to a character.
char* lp=NULL;
//The color black.
SDL_Color black={0,0,0,0};
//The surface that will hold the text.
SDL_Surface* bm=NULL;
//We keep looping forever.
//The only way out is with the break statement.
for(;;){
//As long as it's still the same sentence we continue.
//It will stop when there's a newline or end of line.
for(lp=lps;*lp!='\n'&&*lp!='\r'&&*lp!=0;lp++);
//Store the character we stopped on. (End or newline)
char c=*lp;
//Set the character in the string to 0, making lps a string containing one sentence.
*lp=0;
//Draw the black text.
bm=TTF_RenderUTF8_Blended(fontText,lps,black);
//Draw the text.
SDL_Rect tmp={0,0,width-2,25};
SDL_BlitSurface(bm,&tmp,screen,&r);
//NOTE: We free the surface later.
//Increase y with 25, about the height of the text.
r.y+=25;
//Check the stored character if it was a stop.
if(c==0){
//It was so break out of the for loop.
lps=lp;
break;
}
//It wasn't meaning more will follow.
//We set lps to point after the "newline" forming a new string.
lps=lp+1;
//Restore the character, this way the original string doesn't get destroyed.
*lp=c;
}
//Only draw the carrot when focus.
if(state==2){
r.x=x;
r.y=y+4;
r.w=2;
r.h=20;
//Check for any newlines.
size_t pos=0;
while( (caption.find('\n',pos+1)!=string::npos) && (int(caption.find('\n',pos+1))<value)){
pos=caption.find('\n',pos+1);
r.y+=24;
}
int advance;
for(int n=pos;n<value;n++){
if(caption[n]!='\n'){
TTF_GlyphMetrics(fontText,caption[n],NULL,NULL,NULL,NULL,&advance);
r.x+=advance;
}
}
//Make sure that the carrot is inside the textbox.
if(r.x<x+width)
SDL_FillRect(screen,&r,0);
}
//Anyway we free the bm surface.
if(bm!=NULL)
SDL_FreeSurface(bm);
//We now need to draw all the children of the GUIObject.
for(unsigned int i=0;i<childControls.size();i++){
- childControls[i]->render(x,y);
+ childControls[i]->render(x,y,draw);
}
}
diff --git a/src/GUITextArea.h b/src/GUITextArea.h
index df9998d..72c434f 100644
--- a/src/GUITextArea.h
+++ b/src/GUITextArea.h
@@ -1,63 +1,63 @@
/****************************************************************************
** Copyright (C) 2011 Luka Horvat <redreaper132 at gmail.com>
** Copyright (C) 2011 Edward Lii <edward_iii at myway.com>
** Copyright (C) 2011 O. Bahri Gordebak <gordebak at gmail.com>
**
**
** This file may be used under the terms of the GNU General Public
** License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#ifndef GUITEXTAREA_H
#define GUITEXTAREA_H
#include "GUIObject.h"
//GUIObject that displays a list.
//It extends GUIObject because it's a special GUIObject.
class GUITextArea:public GUIObject{
private:
//Integer containing the key that is holded.
int key;
//Integer containing the time the key is pressed.
int keyHoldTime;
//The time it takes to invoke the key action again.
int keyTime;
//Method that will remove the last character of the text.
//back: Boolean if the key backspace is used. (delete otherwise)
void deleteChar(bool back);
public:
//Constructor.
//left: The relative x location of the GUIListBox.
//top: The relative y location of the GUIListBox.
//witdh: The width of the GUIListBox.
//height: The height of the GUIListBox.
//enabled: Boolean if the GUIListBox is enabled or not.
//visible: Boolean if the GUIListBox is visisble or not.
GUITextArea(int left=0,int Top=0,int width=0,int height=0,bool enabled=true,bool visible=true);
//Method used to handle mouse and/or key events.
//x: The x mouse location.
//y: The y mouse location.
//enabled: Boolean if the parent is enabled or not.
//visible: Boolean if the parent is visible or not.
//processed: Boolean if the event has been processed (by the parent) or not.
//Returns: Boolean if the event is processed by the child.
virtual bool handleEvents(int x=0,int y=0,bool enabled=true,bool visible=true,bool processed=false);
//Method that will render the GUITextArea.
//x: The x location to draw the GUITextArea. (x+left)
//y: The y location to draw the GUITextArea. (y+top)
- virtual void render(int x=0,int y=0);
+ virtual void render(int x=0,int y=0,bool draw=true);
};
#endif
diff --git a/src/Game.cpp b/src/Game.cpp
index b96c655..c3c77fb 100644
--- a/src/Game.cpp
+++ b/src/Game.cpp
@@ -1,1252 +1,1314 @@
/****************************************************************************
** Copyright (C) 2011 Luka Horvat <redreaper132 at gmail.com>
** Copyright (C) 2011 Edward Lii <edward_iii at myway.com>
** Copyright (C) 2011 O. Bahri Gordebak <gordebak at gmail.com>
**
**
** This file may be used under the terms of the GNU General Public
** License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "GameState.h"
#include "Globals.h"
#include "Functions.h"
#include "FileManager.h"
#include "GameObjects.h"
#include "ThemeManager.h"
#include "Objects.h"
#include "Game.h"
#include "TreeStorageNode.h"
#include "POASerializer.h"
#include "InputManager.h"
#include <fstream>
#include <iostream>
#include <sstream>
#include <vector>
#include <map>
#include <algorithm>
#include <locale>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "libs/tinyformat/tinyformat.h"
using namespace std;
const char* Game::blockName[TYPE_MAX]={"Block","PlayerStart","ShadowStart",
"Exit","ShadowBlock","Spikes",
"Checkpoint","Swap","Fragile",
"MovingBlock","MovingShadowBlock","MovingSpikes",
"Teleporter","Button","Switch",
-"ConveyorBelt","ShadowConveyorBelt","NotificationBlock", "Collectable",
+"ConveyorBelt","ShadowConveyorBelt","NotificationBlock", "Collectable"
};
map<string,int> Game::blockNameMap;
string Game::recordFile;
Game::Game(bool loadLevel):isReset(false)
,currentLevelNode(NULL)
,customTheme(NULL)
,background(NULL)
,won(false)
,interlevel(false)
,gameTipIndex(0)
,time(0),timeSaved(0)
,recordings(0),recordingsSaved(0)
,shadowCam(false)
,player(this),shadow(this),objLastCheckPoint(NULL){
saveStateNextTime=false;
loadStateNextTime=false;
//Reserve the memory for the GameObject tips.
memset(bmTips,0,sizeof(bmTips));
action=loadImage(getDataPath()+"gfx/actions.png");
medals=loadImage(getDataPath()+"gfx/medals.png");
collectable=loadImage(getDataPath()+"gfx/collectable.png");
//Check if we should load record file.
if(!recordFile.empty()){
loadRecord(recordFile.c_str());
recordFile.clear();
return;
}
//If we should load the level then load it.
if(loadLevel){
this->loadLevel(levels->getLevelpackPath()+levels->getLevelFile());
levels->saveLevelProgress();
}
}
Game::~Game(){
//Simply call our destroy method.
destroy();
}
void Game::destroy(){
//Loop through the levelObjects and delete them.
for(unsigned int i=0;i<levelObjects.size();i++)
delete levelObjects[i];
//Done now clear the levelObjects vector.
levelObjects.clear();
//Clear the name and the editor data.
levelName.clear();
levelFile.clear();
editorData.clear();
//Loop through the tips.
for(int i=0;i<TYPE_MAX;i++){
//If it exist free the SDL_Surface.
if(bmTips[i])
SDL_FreeSurface(bmTips[i]);
}
memset(bmTips,0,sizeof(bmTips));
//Remove everything from the themeManager.
background=NULL;
if(customTheme)
objThemes.removeTheme();
customTheme=NULL;
//delete current level (if any)
if(currentLevelNode){
delete currentLevelNode;
currentLevelNode=NULL;
}
//Reset the time.
time=timeSaved=0;
recordings=recordingsSaved=0;
}
void Game::loadLevelFromNode(TreeStorageNode* obj,const string& fileName){
//Make sure there's nothing left from any previous levels.
destroy();
//set current level to loaded one.
currentLevelNode=obj;
//Temp var used for block locations.
SDL_Rect box;
//Set the level dimensions to the default, it will probably be changed by the editorData,
//but 800x600 is a fallback.
LEVEL_WIDTH=800;
LEVEL_HEIGHT=600;
currentCollectables=0;
totalCollectables=0;
currentCollectablesSaved=0;
//Load the additional data.
for(map<string,vector<string> >::iterator i=obj->attributes.begin();i!=obj->attributes.end();i++){
if(i->first=="size"){
//We found the size attribute.
if(i->second.size()>=2){
//Set the dimensions of the level.
LEVEL_WIDTH=atoi(i->second[0].c_str());
LEVEL_HEIGHT=atoi(i->second[1].c_str());
}
}else if(i->second.size()>0){
//Any other data will be put into the editorData.
editorData[i->first]=i->second[0];
}
}
//Get the theme.
{
//If a theme is configured then load it.
string theme=processFileName(getSettings()->getValue("theme"));
//Check if it isn't the default theme, because if it is it's already loaded.
if(fileNameFromPath(theme)!="Cloudscape") {
customTheme=objThemes.appendThemeFromFile(theme+"/theme.mnmstheme");
}
//Check if level themes are enabled.
if(getSettings()->getBoolValue("leveltheme")) {
string &s=editorData["theme"];
if(!s.empty()){
customTheme=objThemes.appendThemeFromFile(processFileName(theme)+"/theme.mnmstheme");
}
}
//Set the Appearance of the player and the shadow.
objThemes.getCharacter(false)->createInstance(&player.appearance);
objThemes.getCharacter(true)->createInstance(&shadow.appearance);
}
for(unsigned int i=0;i<obj->subNodes.size();i++){
TreeStorageNode* obj1=obj->subNodes[i];
if(obj1==NULL) continue;
if(obj1->name=="tile" && obj1->value.size()>=3){
int objectType=blockNameMap[obj1->value[0]];
box.x=atoi(obj1->value[1].c_str());
box.y=atoi(obj1->value[2].c_str());
map<string,string> obj;
for(map<string,vector<string> >::iterator i=obj1->attributes.begin();i!=obj1->attributes.end();i++){
if(i->second.size()>0) obj[i->first]=i->second[0];
}
//If the type is collectable, increase the number of totalCollectables
if (objectType==TYPE_COLLECTABLE)
totalCollectables++;
levelObjects.push_back( new Block ( box.x, box.y, objectType, this) );
levelObjects.back()->setEditorData(obj);
}
}
//Set the levelName to the name of the current level.
levelName=editorData["name"];
levelFile=fileName;
//Some extra stuff only needed when not in the levelEditor.
if(stateID!=STATE_LEVEL_EDITOR){
//We create a text with the text "Level <levelno> <levelName>".
//It will be shown in the left bottom corner of the screen.
string s;
if (levels->getLevelCount()>1){
s=tfm::format(_("Level %d %s"),levels->getCurrentLevel()+1,editorData["name"]);
}
SDL_Color fg={0,0,0,0};
bmTips[0]=TTF_RenderUTF8_Blended(fontText,s.c_str(),fg);
- /*if(bmTips[0])
- SDL_SetAlpha(bmTips[0],SDL_SRCALPHA,160);*/
}
//Get the background
background=objThemes.getBackground();
if(background)
background->resetAnimation(true);
}
void Game::loadLevel(string fileName){
//Create a TreeStorageNode that will hold the loaded data.
TreeStorageNode *obj=new TreeStorageNode();
{
POASerializer objSerializer;
string s=fileName;
//Parse the file.
if(!objSerializer.loadNodeFromFile(s.c_str(),obj,true)){
cout<<"Can't load level file "<<s<<endl;
delete obj;
return;
}
}
//Now call another function.
loadLevelFromNode(obj,fileName);
}
void Game::saveRecord(const char* fileName){
//check if current level is NULL (which should be impossible)
if(currentLevelNode==NULL) return;
TreeStorageNode obj;
POASerializer objSerializer;
//put current level to the node.
currentLevelNode->name="map";
obj.subNodes.push_back(currentLevelNode);
//serialize the game record using RLE compression.
#define PUSH_BACK \
if(j>0){ \
if(j>1){ \
sprintf(c,"%d*%d",last,j); \
}else{ \
sprintf(c,"%d",last); \
} \
v.push_back(c); \
}
vector<string> &v=obj.attributes["record"];
vector<int> *record=player.getRecord();
char c[64];
int i,j=0,last;
for(i=0;i<(int)record->size();i++){
int currentKey=(*record)[i];
if(j==0 || currentKey!=last){
PUSH_BACK;
last=currentKey;
j=1;
}else{
j++;
}
}
PUSH_BACK;
#undef PUSH_BACK
#ifdef RECORD_FILE_DEBUG
//add record file debug data.
{
obj.attributes["recordKeyPressLog"].push_back(player.keyPressLog());
vector<SDL_Rect> &playerPosition=player.playerPosition();
string s;
char c[32];
sprintf(c,"%d\n",int(playerPosition.size()));
s=c;
for(unsigned int i=0;i<playerPosition.size();i++){
SDL_Rect& r=playerPosition[i];
sprintf(c,"%d %d\n",r.x,r.y);
s+=c;
}
obj.attributes["recordPlayerPosition"].push_back(s);
}
#endif
//save it
objSerializer.saveNodeToFile(fileName,&obj,true,true);
//remove current level from node to prevent delete it.
obj.subNodes.clear();
}
void Game::loadRecord(const char* fileName){
//Create a TreeStorageNode that will hold the loaded data.
TreeStorageNode obj;
{
POASerializer objSerializer;
string s=fileName;
//Parse the file.
if(!objSerializer.loadNodeFromFile(s.c_str(),&obj,true)){
cout<<"Can't load record file "<<s<<endl;
return;
}
}
//find the node named 'map'.
bool loaded=false;
for(unsigned int i=0;i<obj.subNodes.size();i++){
if(obj.subNodes[i]->name=="map"){
//load the level. (fileName=???)
loadLevelFromNode(obj.subNodes[i],"???");
//remove this node to prevent delete it.
obj.subNodes[i]=NULL;
//over
loaded=true;
break;
}
}
if(!loaded){
cout<<"ERROR: Can't find subnode named 'map' from record file"<<endl;
return;
}
//load the record.
{
vector<int> *record=player.getRecord();
record->clear();
vector<string> &v=obj.attributes["record"];
for(unsigned int i=0;i<v.size();i++){
string &s=v[i];
string::size_type pos=s.find_first_of('*');
if(pos==string::npos){
//1 item only.
int i=atoi(s.c_str());
record->push_back(i);
}else{
//contains many items.
int i=atoi(s.substr(0,pos).c_str());
int j=atoi(s.substr(pos+1).c_str());
for(;j>0;j--){
record->push_back(i);
}
}
}
}
#ifdef RECORD_FILE_DEBUG
//load the debug data
{
vector<string> &v=obj.attributes["recordPlayerPosition"];
vector<SDL_Rect> &playerPosition=player.playerPosition();
playerPosition.clear();
if(!v.empty()){
if(!v[0].empty()){
stringstream st(v[0]);
int m;
st>>m;
for(int i=0;i<m;i++){
SDL_Rect r;
st>>r.x>>r.y;
r.w=0;
r.h=0;
playerPosition.push_back(r);
}
}
}
}
#endif
//play the record.
//TODO: tell the level manager don't save the level progress.
player.playRecord();
shadow.playRecord(); //???
}
/////////////EVENT///////////////
void Game::handleEvents(){
//First of all let the player handle input.
player.handleInput(&shadow);
//Check for an SDL_QUIT event.
if(event.type==SDL_QUIT){
//We need to quit so enter STATE_EXIT.
setNextState(STATE_EXIT);
}
//Check for the escape key.
if(inputMgr.isKeyUpEvent(INPUTMGR_ESCAPE)){
//Escape means we go one level up, to the level select state.
setNextState(STATE_LEVEL_SELECT);
//Save the progress.
levels->saveLevelProgress();
//And change the music back to the menu music.
getMusicManager()->playMusic("menu");
}
//Check if 'r' is pressed.
if(inputMgr.isKeyDownEvent(INPUTMGR_RESTART)){
isReset=true;
}
//Check for the next level buttons when in the interlevel popup.
if(inputMgr.isKeyDownEvent(INPUTMGR_SPACE) || (event.type==SDL_KEYDOWN && (event.key.keysym.sym==SDLK_RETURN || event.key.keysym.sym==SDLK_RCTRL))){
if(interlevel){
//The interlevel popup is shown so we need to delete it.
if(GUIObjectRoot){
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
//Now goto the next level.
gotoNextLevel();
}
}
//Check if tab is pressed.
if(inputMgr.isKeyDownEvent(INPUTMGR_TAB)){
shadowCam=!shadowCam;
}
}
/////////////////LOGIC///////////////////
void Game::logic(){
//Check if we should save/load state.
if(saveStateNextTime){
saveState();
}else if(loadStateNextTime){
loadState();
}
saveStateNextTime=false;
loadStateNextTime=false;
//Add one tick to the time.
time++;
//Let the player store his move, if recording.
player.shadowSetState();
//Let the player give his recording to the shadow, if configured.
player.shadowGiveState(&shadow);
//Let the player jump.
player.jump();
//Let him move.
player.move(levelObjects);
//And let the camera follow him.
if(!shadowCam){
player.setMyCamera();
}else{
shadow.setMyCamera();
}
//Now let the shadow decide his move, if he's playing a recording.
shadow.moveLogic();
//Let the shadow jump.
shadow.jump();
//Let the shadow move.
shadow.move(levelObjects);
//Some levelObjects can move so update them.
for(unsigned int i=0;i<levelObjects.size();i++){
levelObjects[i]->move();
}
//Process any event in the queue.
for(unsigned int idx=0;idx<eventQueue.size();idx++){
//Get the event from the queue.
typeGameObjectEvent &e=eventQueue[idx];
//Check if the it has an id attached to it.
if(e.flags|1){
//Loop through the levelObjects and give them the event if they have the right id.
for(unsigned int i=0;i<levelObjects.size();i++){
if(e.objectType<0 || levelObjects[i]->type==e.objectType){
Block *obj=dynamic_cast<Block*>(levelObjects[i]);
if(obj!=NULL && obj->id==e.id){
levelObjects[i]->onEvent(e.eventType);
}
}
}
}else{
//Loop through the levelObjects and give them the event.
for(unsigned int i=0;i<levelObjects.size();i++){
if(e.objectType<0 || levelObjects[i]->type==e.objectType){
levelObjects[i]->onEvent(e.eventType);
}
}
}
}
//Done processing the events so clear the queue.
eventQueue.clear();
//Check collision and stuff for the shadow and player.
player.otherCheck(&shadow);
//Check if we won.
if(won){
//Check if it's playing from record
if(player.isPlayFromRecord() && !interlevel){
recordingEnded();
}else{
//the string to store auto-save record path.
string bestTimeFilePath,bestRecordingFilePath;
//and if we can't get test path.
bool filePathError=false;
//Set the current level won.
levels->getLevel()->won=true;
if(levels->getLevel()->time==-1 || levels->getLevel()->time>time){
levels->getLevel()->time=time;
//save the best-time game record.
if(bestTimeFilePath.empty()){
getCurrentLevelAutoSaveRecordPath(bestTimeFilePath,bestRecordingFilePath,true);
}
if(bestTimeFilePath.empty()){
cout<<"ERROR: Couldn't get auto-save record file path"<<endl;
filePathError=true;
}else{
saveRecord(bestTimeFilePath.c_str());
}
}
if(levels->getLevel()->recordings==-1 || levels->getLevel()->recordings>recordings){
levels->getLevel()->recordings=recordings;
//save the best-recordings game record.
if(bestRecordingFilePath.empty() && !filePathError){
getCurrentLevelAutoSaveRecordPath(bestTimeFilePath,bestRecordingFilePath,true);
}
if(bestRecordingFilePath.empty()){
cout<<"ERROR: Couldn't get auto-save record file path"<<endl;
filePathError=true;
}else{
saveRecord(bestRecordingFilePath.c_str());
}
}
//Set the next level unlocked if it exists.
if(levels->getCurrentLevel()+1<levels->getLevelCount()){
levels->setLocked(levels->getCurrentLevel()+1);
}
//And save the progress.
levels->saveLevelProgress();
//Now go to the interlevel screen.
replayPlay();
//NOTE: We set isReset false to prevent the user from getting a best time of 0.00s and 0 recordings.
}
}
won=false;
//Check if we should reset.
if(isReset)
reset(false);
isReset=false;
}
/////////////////RENDER//////////////////
void Game::render(){
//First of all render the background.
{
//Get a pointer to the background.
ThemeBackground* bg=background;
//Check if the background is null, but there are themes.
if(bg==NULL && objThemes.themeCount()>0){
//Get the background from the first theme in the stack.
bg=objThemes[0]->getBackground();
}
//Check if the background isn't null.
if(bg){
//It isn't so draw it.
bg->draw(screen);
//And if it's the loaded background then also update the animation.
//FIXME: Updating the animation in the render method?
if(bg==background)
bg->updateAnimation();
}else{
//There's no background so fill the screen with white.
SDL_Rect r={0,0,SCREEN_WIDTH,SCREEN_HEIGHT};
SDL_FillRect(screen,&r,-1);
}
}
//Now we draw the levelObjects.
for(unsigned int o=0; o<levelObjects.size(); o++){
levelObjects[o]->show();
}
//Followed by the player and the shadow.
player.show();
shadow.show();
//Show the levelName if it isn't the level editor.
if(stateID!=STATE_LEVEL_EDITOR && bmTips[0]!=NULL && !interlevel){
drawGUIBox(-2,SCREEN_HEIGHT-bmTips[0]->h-4,bmTips[0]->w+8,bmTips[0]->h+6,screen,0xDDDDDDDD);
applySurface(2,SCREEN_HEIGHT-bmTips[0]->h,bmTips[0],screen,NULL);
}
//Check if there's a tooltip.
//NOTE: gameTipIndex 0 is used for the levelName, 1 for shadow death, 2 for restart text, 3 for restart+checkpoint.
if(gameTipIndex>3 && gameTipIndex<TYPE_MAX){
//Check if there's a tooltip for the type.
if(bmTips[gameTipIndex]==NULL){
//There isn't thus make it.
string s;
string keyCode=inputMgr.getKeyCodeName(inputMgr.getKeyCode(INPUTMGR_ACTION,false));
transform(keyCode.begin(),keyCode.end(),keyCode.begin(),::toupper);
switch(gameTipIndex){
case TYPE_CHECKPOINT:
/// TRANSLATORS: Please do not remove %s from your translation:
/// - %s will be replaced with current action key
s=tfm::format(_("Press %s key to save the game."),keyCode);
break;
case TYPE_SWAP:
/// TRANSLATORS: Please do not remove %s from your translation:
/// - %s will be replaced with current action key
s=tfm::format(_("Press %s key to swap the position of player and shadow."),keyCode);
break;
case TYPE_SWITCH:
/// TRANSLATORS: Please do not remove %s from your translation:
/// - %s will be replaced with current action key
s=tfm::format(_("Press %s key to activate the switch."),keyCode);
break;
case TYPE_PORTAL:
/// TRANSLATORS: Please do not remove %s from your translation:
/// - %s will be replaced with current action key
s=tfm::format(_("Press %s key to teleport."),keyCode);
break;
}
//If we have a string then it's a supported GameObject type.
if(!s.empty()){
SDL_Color fg={0,0,0,0};
bmTips[gameTipIndex]=TTF_RenderUTF8_Blended(fontText,s.c_str(),fg);
}
}
//We already have a gameTip for this type so draw it.
if(bmTips[gameTipIndex]!=NULL){
drawGUIBox(-2,-2,bmTips[gameTipIndex]->w+8,bmTips[gameTipIndex]->h+6,screen,0xDDDDDDDD);
applySurface(2,2,bmTips[gameTipIndex],screen,NULL);
}
}
//Set the gameTip to 0.
gameTipIndex=0;
//Pointer to the sdl surface that will contain a message, if any.
SDL_Surface* bm=NULL;
//Check if the player is dead, meaning we draw a message.
if(player.dead){
//Get user configured restart key
string keyCodeRestart=inputMgr.getKeyCodeName(inputMgr.getKeyCode(INPUTMGR_RESTART,false));
transform(keyCodeRestart.begin(),keyCodeRestart.end(),keyCodeRestart.begin(),::toupper);
//The player is dead, check if there's a state that can be loaded.
if(player.canLoadState()){
//Now check if the tip is already made, if not make it.
if(bmTips[3]==NULL){
//Get user defined key for loading checkpoint
string keyCodeLoad=inputMgr.getKeyCodeName(inputMgr.getKeyCode(INPUTMGR_LOAD,false));
transform(keyCodeLoad.begin(),keyCodeLoad.end(),keyCodeLoad.begin(),::toupper);
//Draw string
SDL_Color fg={0,0,0,0},bg={255,255,255,0};
bmTips[3]=TTF_RenderUTF8_Blended(fontText,
/// TRANSLATORS: Please do not remove %s from your translation:
/// - first %s means currently configured key to restart game
/// - Second %s means configured key to load from last save
tfm::format(_("Press %s to restart current level or press %s to load the game."),
keyCodeRestart,keyCodeLoad).c_str(),
fg);
}
bm=bmTips[3];
}else{
//Now check if the tip is already made, if not make it.
if(bmTips[2]==NULL){
SDL_Color fg={0,0,0,0};
bmTips[2]=TTF_RenderUTF8_Blended(fontText,
/// TRANSLATORS: Please do not remove %s from your translation:
/// - %s will be replaced with currently configured key to restart game
tfm::format(_("Press %s to restart current level."),keyCodeRestart).c_str(),
fg);
}
bm=bmTips[2];
}
}
//Check if the shadow has died (and there's no other notification).
//NOTE: We use the shadow's jumptime as countdown, this variable isn't used when the shadow is dead.
if(shadow.dead && bm==NULL && shadow.jumpTime>0){
//Now check if the tip is already made, if not make it.
if(bmTips[1]==NULL){
SDL_Color fg={0,0,0,0},bg={255,255,255,0};
bmTips[1]=TTF_RenderUTF8_Blended(fontText,
_("Your shadow has died."),
fg);
}
bm=bmTips[1];
//NOTE: Logic in the render loop, we substract the shadow's jumptime by one.
shadow.jumpTime--;
}
//Draw the tip.
if(bm!=NULL){
int x=(SCREEN_WIDTH-bm->w)/2;
int y=32;
drawGUIBox(x-8,y-8,bm->w+16,bm->h+14,screen,0xDDDDDDDD);
applySurface(x,y,bm,screen,NULL);
}
if (currentCollectables<=totalCollectables && totalCollectables!=0){
//Draw the key image in the middle of the screen.
applySurface(SCREEN_WIDTH-collectable->w,SCREEN_HEIGHT-collectable->h,collectable,screen,NULL);
//Temp stringstream just to addup all the text nicely
stringstream temp;
temp << currentCollectables << "/" << totalCollectables;
SDL_Color black={0,0,0,0};
SDL_Rect r;
SDL_Surface* bm=TTF_RenderText_Blended(fontText,temp.str().c_str(),black);
//Aligning the text to the icon of the key
r.x=SCREEN_WIDTH-collectable->w+bm->w;
r.y=SCREEN_HEIGHT-collectable->h-bm->h;
SDL_BlitSurface(bm,NULL,screen,&r);
SDL_FreeSurface(bm);
}
//show time and records used in level editor.
if(stateID==STATE_LEVEL_EDITOR && time>0){
SDL_Color fg={0,0,0,0},bg={255,255,255,0};
SDL_Surface *bm;
int y=SCREEN_HEIGHT;
bm=TTF_RenderUTF8_Shaded(fontText,tfm::format(_("%d recordings"),recordings).c_str(),fg,bg);
SDL_SetAlpha(bm,SDL_SRCALPHA,160);
y-=bm->h;
applySurface(0,y,bm,screen,NULL);
SDL_FreeSurface(bm);
char c[32];
sprintf(c,"%-.2fs",time/40.0f);
bm=TTF_RenderUTF8_Shaded(fontText,c,fg,bg);
SDL_SetAlpha(bm,SDL_SRCALPHA,160);
y-=bm->h;
applySurface(0,y,bm,screen,NULL);
SDL_FreeSurface(bm);
}
//Draw the current action in the upper right corner.
if(player.record){
applySurface(SCREEN_WIDTH-50,0,action,screen,NULL);
}else if(shadow.state!=0){
SDL_Rect r={50,0,50,50};
applySurface(SCREEN_WIDTH-50,0,action,screen,&r);
}
//if the game is play from record then draw something indicates it
if(player.isPlayFromRecord()){
//Dim the screen if interlevel is true.
if(interlevel){
SDL_BlitSurface(screen,NULL,tempSurface,NULL);
SDL_FillRect(screen,NULL,0);
SDL_SetAlpha(tempSurface, SDL_SRCALPHA,220);
SDL_BlitSurface(tempSurface,NULL,screen,NULL);
//Check if the GUI isn't null.
if(GUIObjectRoot){
//==Create first box==
//Create the title
SDL_Color black={0,0,0,0};
SDL_Rect r;
/// TRANSLATORS: This is caption for finished level
SDL_Surface* bm=TTF_RenderUTF8_Blended(fontGUI,_("You've finished:"),black);
//Recreate the level string.
string s;
if (levels->getLevelCount()>0){
/// TRANSLATORS: Please do not remove %s or %d from your translation:
/// - %d means the level number in a levelpack
/// - %s means the name of current level
s=tfm::format(_("Level %d %s"),levels->getCurrentLevel()+1,levelName);
}
SDL_Surface* bm2=TTF_RenderUTF8_Blended(fontText,s.c_str(),black);
//Now draw the first gui box so that it's bigger than longer text.
int width;
if(bm->w>bm2->w)
width=bm->w+32;
else
width=bm2->w+32;
drawGUIBox((SCREEN_WIDTH-width)/2,4,width,68,screen,0xDDDDDDA1);
// Now draw title.
r.x=(SCREEN_WIDTH-bm->w)/2;
r.y=8;
SDL_BlitSurface(bm,NULL,screen,&r);
// And then level name.
r.x=(SCREEN_WIDTH-bm2->w)/2;
r.y=44;
SDL_BlitSurface(bm2,NULL,screen,&r);
//Free drawed texts
SDL_FreeSurface(bm);
SDL_FreeSurface(bm2);
//==Create second box==
//Now draw the second gui box.
drawGUIBox(GUIObjectRoot->left,GUIObjectRoot->top,GUIObjectRoot->width,GUIObjectRoot->height,screen,0xDDDDDDA1);
//Draw the medal.
int medal=GUIObjectRoot->value;
r.x=(medal-1)*30;
r.y=0;
r.w=30;
r.h=30;
applySurface(GUIObjectRoot->left+16,GUIObjectRoot->top+92,medals,screen,&r);
- applySurface(GUIObjectRoot->left+370,GUIObjectRoot->top+92,medals,screen,&r);
+ applySurface(GUIObjectRoot->left+medalX,GUIObjectRoot->top+92,medals,screen,&r);
}
}else if((time & 0x10)==0x10){
SDL_Rect r={50,0,50,50};
applySurface(0,0,action,screen,&r);
applySurface(0,SCREEN_HEIGHT-50,action,screen,&r);
applySurface(SCREEN_WIDTH-50,SCREEN_HEIGHT-50,action,screen,&r);
}
}else if(player.objNotificationBlock){
//If the player is in front of a notification block show the message.
//And it isn't a replay.
std::string &untranslated_message=(dynamic_cast<Block*>(player.objNotificationBlock))->message;
std::string message=_C(levels->getDictionaryManager(),untranslated_message);
std::vector<char> string_data(message.begin(), message.end());
string_data.push_back('\0');
int y = 20;
vector<SDL_Surface*> lines;
//Now process the prompt.
{
//Pointer to the string.
char* lps=&string_data[0];
//Pointer to a character.
char* lp=NULL;
//We keep looping forever.
//The only way out is with the break statement.
for(;;){
//As long as it's still the same sentence we continue.
//It will stop when there's a newline or end of line.
for(lp=lps;*lp!='\n'&&*lp!='\r'&&*lp!=0;lp++);
//Store the character we stopped on. (End or newline)
char c=*lp;
//Set the character in the string to 0, making lps a string containing one sentence.
*lp=0;
//Integer used to center the sentence horizontally.
int x;
TTF_SizeText(fontText,lps,&x,NULL);
x=(SCREEN_WIDTH-200-x)/2;
//Color the text will be: black.
SDL_Color black={0,0,0,0};
lines.push_back(TTF_RenderUTF8_Blended(fontText,lps,black));
//Increase y with 25, about the height of the text.
y+=25;
//Check the stored character if it was a stop.
if(c==0){
//It was so break out of the for loop.
lps=lp;
break;
}
//It wasn't meaning more will follow.
//We set lps to point after the "newline" forming a new string.
lps=lp+1;
}
}
drawGUIBox(100,SCREEN_HEIGHT-y-25,SCREEN_WIDTH-200,y+20,screen,0xDDDDDDA1);
while(!lines.empty()){
SDL_Surface* bm=lines[0];
if(bm!=NULL){
applySurface(100+((SCREEN_WIDTH-200-bm->w)/2),SCREEN_HEIGHT-y,bm,screen,NULL);
SDL_FreeSurface(bm);
}
y-=25;
lines.erase(lines.begin());
}
}
}
void Game::resize(){}
void Game::replayPlay(){
//Reset the number of collectables
currentCollectables=currentCollectablesSaved=0;
interlevel=true;
//Create the gui if it isn't already done.
if(!GUIObjectRoot){
- GUIObjectRoot=new GUIObject((SCREEN_WIDTH-570)/2,SCREEN_HEIGHT-140,570,135,GUIObjectNone);
+ GUIObjectRoot=new GUIObject(0,SCREEN_HEIGHT-140,570,135,GUIObjectNone);
//NOTE: We put the medal in the value of the GUIObjectRoot.
//The different values.
int bestTime=levels->getLevel()->time;
int targetTime=levels->getLevel()->targetTime;
int bestRecordings=levels->getLevel()->recordings;
int targetRecordings=levels->getLevel()->targetRecordings;
int medal=1;
if(targetTime<0){
medal=3;
}else{
if(targetTime<0 || bestTime<=targetTime)
medal++;
if(targetRecordings<0 || bestRecordings<=targetRecordings)
medal++;
}
//Add it to the GUIObjectRoot.
GUIObjectRoot->value=medal;
+
+ int maxWidth=0;
+ int x=20;
+
+ //Is there a target time for this level?
+ int timeY=0;
+ bool isTargetTime=true;
+ if(targetTime<=0){
+ isTargetTime=false;
+ timeY=12;
+ }
//Create the labels with the time and best time.
/// TRANSLATORS: Please do not remove %-.2f from your translation:
/// - %-.2f means time in seconds
/// - s is shortened form of a second. Try to keep it so.
- GUIObject* obj=new GUIObject(20,10,150,36,GUIObjectLabel,tfm::format(_("Time: %-.2fs"),time/40.0f).c_str());
+ GUIObject* obj=new GUIObject(x,10+timeY,-1,36,GUIObjectLabel,tfm::format(_("Time: %-.2fs"),time/40.0f).c_str());
GUIObjectRoot->childControls.push_back(obj);
+
+ obj->render(0,0,false);
+ maxWidth=obj->width;
/// TRANSLATORS: Please do not remove %-.2f from your translation:
/// - %-.2f means time in seconds
/// - s is shortened form of a second. Try to keep it so.
- obj=new GUIObject(20,34,150,36,GUIObjectLabel,tfm::format(_("Best time: %-.2fs"),bestTime/40.0f).c_str());
+ obj=new GUIObject(x,34+timeY,-1,36,GUIObjectLabel,tfm::format(_("Best time: %-.2fs"),bestTime/40.0f).c_str());
GUIObjectRoot->childControls.push_back(obj);
+
+ obj->render(0,0,false);
+ if(obj->width>maxWidth)
+ maxWidth=obj->width;
/// TRANSLATORS: Please do not remove %-.2f from your translation:
/// - %-.2f means time in seconds
/// - s is shortened form of a second. Try to keep it so.
- if(targetTime>=0){
- obj=new GUIObject(20,58,150,36,GUIObjectLabel,tfm::format(_("Target time: %-.2fs"),targetTime/40.0f).c_str());
+ if(isTargetTime){
+ obj=new GUIObject(x,58,-1,36,GUIObjectLabel,tfm::format(_("Target time: %-.2fs"),targetTime/40.0f).c_str());
GUIObjectRoot->childControls.push_back(obj);
+
+ obj->render(0,0,false);
+ if(obj->width>maxWidth)
+ maxWidth=obj->width;
+ }
+
+ x+=maxWidth+20;
+
+ //Is there target recordings for this level?
+ int recsY=0;
+ bool isTargetRecs=true;
+ if(targetRecordings<0){
+ isTargetRecs=false;
+ recsY=12;
}
//Now the ones for the recordings.
/// TRANSLATORS: Please do not remove %d from your translation:
/// - %d means the number of recordings user has made
- obj=new GUIObject(210,10,150,36,GUIObjectLabel,tfm::format(_("Recordings: %d"),recordings).c_str());
+ obj=new GUIObject(x,10+recsY,-1,36,GUIObjectLabel,tfm::format(_("Recordings: %d"),recordings).c_str());
GUIObjectRoot->childControls.push_back(obj);
+
+ obj->render(0,0,false);
+ maxWidth=obj->width;
/// TRANSLATORS: Please do not remove %d from your translation:
/// - %d means the number of recordings user has made
- obj=new GUIObject(210,34,150,36,GUIObjectLabel,tfm::format(_("Best recordings: %d"),bestRecordings).c_str());
+ obj=new GUIObject(x,34+recsY,-1,36,GUIObjectLabel,tfm::format(_("Best recordings: %d"),bestRecordings).c_str());
GUIObjectRoot->childControls.push_back(obj);
+
+ obj->render(0,0,false);
+ if(obj->width>maxWidth)
+ maxWidth=obj->width;
/// TRANSLATORS: Please do not remove %d from your translation:
/// - %d means the number of recordings user has made
- if(targetRecordings>=0){
- obj=new GUIObject(210,58,150,36,GUIObjectLabel,tfm::format(_("Target recordings: %d"),targetRecordings).c_str());
+ if(isTargetRecs){
+ obj=new GUIObject(x,58,-1,36,GUIObjectLabel,tfm::format(_("Target recordings: %d"),targetRecordings).c_str());
GUIObjectRoot->childControls.push_back(obj);
+
+ obj->render(0,0,false);
+ if(obj->width>maxWidth)
+ maxWidth=obj->width;
}
+
+ x+=maxWidth;
//The medal that is earned.
/// TRANSLATORS: Please do not remove %s from your translation:
/// - %s will be replaced with name of a prize medal (gold, silver or bronze)
string s1=tfm::format(_("You earned the %s medal"),(medal>1)?(medal==3)?_("GOLD"):_("SILVER"):_("BRONZE"));
- obj=new GUIObject(48,92,150,36,GUIObjectLabel,s1.c_str());
- //Center it horizontally.
- int width;
- TTF_SizeText(fontText,s1.c_str(),&width,NULL);
- obj->width=width;
- obj->left=(416-width)/2;
+ obj=new GUIObject(50,92,-1,36,GUIObjectLabel,s1.c_str(),0,true,true,GUIGravityCenter);
GUIObjectRoot->childControls.push_back(obj);
+
+ obj->render(0,0,false);
+ if(obj->left+obj->width>x){
+ x=obj->left+obj->width+30;
+ }else{
+ obj->left=20+(x-20-obj->width)/2;
+ }
+
+ medalX=x-24;
//Create the three buttons, Menu, Restart, Next.
/// TRANSLATORS: used as return to the level selector menu
- obj=new GUIObject(570,10,-1,36,GUIObjectButton,_("Menu"),0,true,true,GUIGravityRight);
- obj->name="cmdMenu";
- obj->eventCallback=this;
- GUIObjectRoot->childControls.push_back(obj);
+ GUIObject* b1=new GUIObject(x,10,-1,36,GUIObjectButton,_("Menu"),0,true,true,GUIGravityCenter);
+ b1->name="cmdMenu";
+ b1->eventCallback=this;
+ GUIObjectRoot->childControls.push_back(b1);
+ b1->render(0,0,true);
/// TRANSLATORS: used as restart level
- obj=new GUIObject(570,50,-1,36,GUIObjectButton,_("Restart"),0,true,true,GUIGravityRight);
- obj->name="cmdRestart";
- obj->eventCallback=this;
- GUIObjectRoot->childControls.push_back(obj);
+ GUIObject* b2=new GUIObject(x,50,-1,36,GUIObjectButton,_("Restart"),0,true,true,GUIGravityCenter);
+ b2->name="cmdRestart";
+ b2->eventCallback=this;
+ GUIObjectRoot->childControls.push_back(b2);
+ b2->render(0,0,true);
/// TRANSLATORS: used as next level
- obj=new GUIObject(570,90,-1,36,GUIObjectButton,_("Next"),0,true,true,GUIGravityRight);
- obj->name="cmdNext";
- obj->eventCallback=this;
- GUIObjectRoot->childControls.push_back(obj);
+ GUIObject* b3=new GUIObject(x,90,-1,36,GUIObjectButton,_("Next"),0,true,true,GUIGravityCenter);
+ b3->name="cmdNext";
+ b3->eventCallback=this;
+ GUIObjectRoot->childControls.push_back(b3);
+ b3->render(0,0,true);
+
+ maxWidth=b1->width;
+ if(b2->width>maxWidth)
+ maxWidth=b2->width;
+ if(b3->width>maxWidth)
+ maxWidth=b3->width;
+
+ b1->left=b2->left=b3->left=x+maxWidth/2;
+
+ x+=maxWidth;
+ GUIObjectRoot->width=x;
+ GUIObjectRoot->left=(SCREEN_WIDTH-GUIObjectRoot->width)/2;
}
//We only need to reset a few things so we don't call reset().
for(unsigned int i=0;i<levelObjects.size();i++){
levelObjects[i]->reset(true);
}
//Also reset the background animation, if any.
if(background)
background->resetAnimation(true);
//Make a copy of the playerButtons.
vector<int> recordCopy=player.recordButton;
player.reset(true);
shadow.reset(true);
player.recordButton=recordCopy;
//Now play the recording.
player.playRecord();
}
void Game::recordingEnded(){
//Check if it's a normal replay, if so just stop.
if(!interlevel){
msgBox(_("Game replay is done."),MsgBoxOKOnly,_("Game Replay"));
//Go to the level select menu.
setNextState(STATE_LEVEL_SELECT);
//And change the music back to the menu music.
getMusicManager()->playMusic("menu");
}else{
//Instead of directly replaying we set won true to let the Game handle the replaying at the end of the update cycle.
won=true;
}
}
bool Game::canSaveState(){
return (player.canSaveState() && shadow.canSaveState());
}
bool Game::saveState(){
//Check if the player and shadow can save the current state.
if(player.canSaveState() && shadow.canSaveState()){
//Let the player and the shadow save their state.
player.saveState();
shadow.saveState();
//Save the stats.
timeSaved=time;
recordingsSaved=recordings;
//Save the current collectables
currentCollectablesSaved=currentCollectables;
//Save other state, for example moving blocks.
for(unsigned int i=0;i<levelObjects.size();i++){
levelObjects[i]->saveState();
}
//Also save the background animation, if any.
if(background)
background->saveAnimation();
//Return true.
return true;
}
//We can't save the state so return false.
return false;
}
bool Game::loadState(){
//Check if there's a state that can be loaded.
if(player.canLoadState() && shadow.canLoadState()){
//Let the player and the shadow load their state.
player.loadState();
shadow.loadState();
//Load the stats.
time=timeSaved;
recordings=recordingsSaved;
//Load the current collactbles
currentCollectables=currentCollectablesSaved;
//Load other state, for example moving blocks.
for(unsigned int i=0;i<levelObjects.size();i++){
levelObjects[i]->loadState();
}
//Also load the background animation, if any.
if(background)
background->loadAnimation();
//Return true.
return true;
}
//We can't load the state so return false.
return false;
}
void Game::reset(bool save){
//We need to reset the game so we also reset the player and the shadow.
player.reset(save);
shadow.reset(save);
saveStateNextTime=false;
loadStateNextTime=false;
//Reset the stats.
time=0;
recordings=0;
//Reset the number of collectables
currentCollectables=currentCollectablesSaved=0;
//There is no last checkpoint so set it to NULL.
if(save)
objLastCheckPoint=NULL;
//Reset other state, for example moving blocks.
for(unsigned int i=0;i<levelObjects.size();i++){
levelObjects[i]->reset(save);
}
//Also reset the background animation, if any.
if(background)
background->resetAnimation(save);
//Check if interlevel is true, if so we might need to delete the gui.
if(interlevel){
if(GUIObjectRoot){
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
}
//Also set interlevel to false.
interlevel=false;
}
void Game::broadcastObjectEvent(int eventType,int objectType,const char* id){
//Create a typeGameObjectEvent that can be put into the queue.
typeGameObjectEvent e;
//Set the event type.
e.eventType=eventType;
//Set the object type.
e.objectType=objectType;
//By default flags=0.
e.flags=0;
//Unless there's an id.
if(id){
//Set flags to 0x1 and set the id.
e.flags|=1;
e.id=id;
}
//Add the event to the queue.
eventQueue.push_back(e);
}
void Game::getCurrentLevelAutoSaveRecordPath(std::string &bestTimeFilePath,std::string &bestRecordingFilePath,bool createPath){
levels->getLevelAutoSaveRecordPath(-1,bestTimeFilePath,bestRecordingFilePath,createPath);
}
void Game::gotoNextLevel(){
//Goto the next level.
levels->nextLevel();
//Check if the level exists.
if(levels->getCurrentLevel()<levels->getLevelCount()){
setNextState(STATE_GAME);
//Don't forget the music.
getMusicManager()->pickMusic();
}else{
if(!levels->congratulationText.empty()){
msgBox(_C(levels->getDictionaryManager(),levels->congratulationText),MsgBoxOKOnly,_("Congratulations"));
}else{
msgBox(_("You have finished the levelpack!"),MsgBoxOKOnly,_("Congratulations"));
}
//Now go back to the levelselect screen.
setNextState(STATE_LEVEL_SELECT);
//And set the music back to menu.
getMusicManager()->playMusic("menu");
}
}
void Game::GUIEventCallback_OnEvent(string name,GUIObject* obj,int eventType){
if(name=="cmdMenu"){
setNextState(STATE_LEVEL_SELECT);
//And change the music back to the menu music.
getMusicManager()->playMusic("menu");
}else if(name=="cmdRestart"){
//Clear the gui.
if(GUIObjectRoot){
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
//And reset the game.
//new: we don't need to clear the save game because
//in level replay the game won't be saved
//TODO: it doesn't work; better leave for next release
reset(/*false*/ true);
}else if(name=="cmdNext"){
//No matter what, clear the gui.
if(GUIObjectRoot){
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
//And goto the next level.
gotoNextLevel();
}
}
diff --git a/src/Game.h b/src/Game.h
index d43d814..6420a60 100644
--- a/src/Game.h
+++ b/src/Game.h
@@ -1,212 +1,215 @@
/****************************************************************************
** Copyright (C) 2011 Luka Horvat <redreaper132 at gmail.com>
** Copyright (C) 2011 Edward Lii <edward_iii at myway.com>
** Copyright (C) 2011 O. Bahri Gordebak <gordebak at gmail.com>
**
**
** This file may be used under the terms of the GNU General Public
** License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#ifndef GAME_H
#define GAME_H
#include <SDL/SDL.h>
#include <SDL/SDL_mixer.h>
#include <SDL/SDL_ttf.h>
#include <vector>
#include <map>
#include <string>
#include "GameState.h"
#include "GUIObject.h"
#include "GameObjects.h"
#include "Player.h"
#include "Shadow.h"
//This structure contains variables that make a GameObjectEvent.
struct typeGameObjectEvent{
//The type of event.
int eventType;
//The type of object that should react to the event.
int objectType;
//Flags, 0x1 means use the id.
int flags;
//Blocks with this id should react to the event.
std::string id;
};
class ThemeManager;
class ThemeBackground;
class TreeStorageNode;
class Game : public GameState,public GUIEventCallback{
private:
//Boolean if the game should reset.
bool isReset;
//contains currently played level.
TreeStorageNode* currentLevelNode;
protected:
//Array containing "tooltips" for certain block types.
//It will be shown in the topleft corner of the screen.
SDL_Surface* bmTips[TYPE_MAX];
//SDL_Surface containing the action images (record, play, etc..)
SDL_Surface* action;
//SDL_Surface containing the medal image.
SDL_Surface* medals;
//SDL_Surface containing the collectable image.
SDL_Surface* collectable;
//Vector containing all the levelObjects in the current game.
std::vector<GameObject*> levelObjects;
//The name of the current level.
std::string levelName;
//The path + file of the current level.
std::string levelFile;
//Editor data containing information like name, size, etc...
std::map<std::string,std::string> editorData;
//Vector used to queue the gameObjectEvents.
std::vector<typeGameObjectEvent> eventQueue;
//The themeManager.
ThemeManager* customTheme;
//The themeBackground.
ThemeBackground* background;
//Load a level from node.
//After calling this function the ownership of
//node will transfer to Game class. So don't delete
//the node after calling this function!
virtual void loadLevelFromNode(TreeStorageNode* obj, const std::string& fileName);
public:
//Array used to convert GameObject type->string.
static const char* blockName[TYPE_MAX];
//Map used to convert GameObject string->type.
static std::map<std::string,int> blockNameMap;
//Boolean that is set to true when a game is won.
bool won;
//Boolean that is set to true when we should save game on next logic update.
bool saveStateNextTime;
//Boolean that is set to true when we should load game on next logic update.
bool loadStateNextTime;
//Boolean if the replaying currently done is for the interlevel screen.
bool interlevel;
+
+ //X position of second medal in interlevel popup
+ int medalX;
//Integer containing the current tip index.
int gameTipIndex;
//Integer containing the number of ticks passed since the start of the level.
int time;
//Integer containing the stored value of time.
int timeSaved;
//Integer containing the number of recordings it took to finish.
int recordings;
//Integer containing the stored value of recordings.
int recordingsSaved;
//Integer keeping track of currently obtained collectables
int currentCollectables;
//Integer keeping track of total colletables in the level
int totalCollectables;
//Integer containing the stored value of current collectables
int currentCollectablesSaved;
//Boolean if the camera should follow the shadow or not.
bool shadowCam;
//The player...
Player player;
//... and his shadow.
Shadow shadow;
//warning: weak reference only, may point to invalid location
GameObject *objLastCheckPoint;
//Constructor.
//loadLevel: Boolean if the GameState should load the level.
Game(bool loadLevel=true);
//If this is not empty then when next Game class is created
//it will play this record file.
static std::string recordFile;
//Destructor.
//It will call destroy();
~Game();
//Method used to clean up the GameState.
void destroy();
//Inherited from GameState.
void handleEvents();
void logic();
void render();
void resize();
//This method will load a level.
//fileName: The fileName of the level.
virtual void loadLevel(std::string fileName);
//Method used to broadcast a GameObjectEvent.
//eventType: The type of event.
//objectType: The type of object that should react to the event.
//id: The id of the blocks that should react.
void broadcastObjectEvent(int eventType,int objectType=-1,const char* id=NULL);
//Returns if the player and shadow can save the current state.
bool canSaveState();
//Method used to store the current state.
//This is used for checkpoints.
//Returns: True if it succeeds without problems.
bool saveState();
//Method used to load the stored state.
//This is used for checkpoints.
//Returns: True if it succeeds without problems.
bool loadState();
//Method that will reset the GameState to it's initial state.
//save: Boolean if the saved state should also be delted.
void reset(bool save);
//Save current game record to the file.
//fileName: The filename of the destination file.
void saveRecord(const char* fileName);
//Load game record (and its level) from file and play it.
//fileName: The filename of the recording file.
void loadRecord(const char* fileName);
//Method called by the player (or shadow) when he finished.
void replayPlay();
//Method that gets called when the recording has ended.
void recordingEnded();
//get current level's auto-save record path,
//using current level's MD5, file name and other information.
void getCurrentLevelAutoSaveRecordPath(std::string &bestTimeFilePath,std::string &bestRecordingFilePath,bool createPath);
//Method that will prepare the gamestate for the next level and start it.
//If it's the last level it will show the congratulations text and return to the level select screen.
void gotoNextLevel();
//GUI event handling is done here.
void GUIEventCallback_OnEvent(std::string name,GUIObject* obj,int eventType);
};
#endif
diff --git a/src/InputManager.cpp b/src/InputManager.cpp
index fb45b43..8d2b8be 100644
--- a/src/InputManager.cpp
+++ b/src/InputManager.cpp
@@ -1,443 +1,443 @@
/****************************************************************************
** Copyright (C) 2012 me and my shadow developers
**
**
** This file may be used under the terms of the GNU General Public
** License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "InputManager.h"
#include "Globals.h"
#include "Settings.h"
#include "Functions.h"
#include "GUIObject.h"
#include "GUIListBox.h"
#include <stdlib.h>
#include <stdio.h>
#include <string>
using namespace std;
InputManager inputMgr;
//the order must be the same as InputManagerKeys
static const char* keySettingNames[INPUTMGR_MAX]={
"key_up","key_down","key_left","key_right","key_jump","key_action","key_space",
"key_escape","key_restart","key_tab","key_save","key_load","key_swap",
"key_teleport","key_suicide","key_shift","key_next","key_previous","key_select"
};
//the order must be the same as InputManagerKeys
static const char* keySettingDescription[INPUTMGR_MAX]={
- "Up (in menu)","Down (in menu)","Left","Right","Jump","Action","Space (Record)",
- "Escape","Restart","Tab (View shadow/Level prop.)","Save game (in editor)","Load game","Swap (in editor)",
- "Teleport (in editor)","Suicide (in editor)","Shift (in editor)","Next block type (in Editor)",
- "Previous block type (in editor)", "Select (in menu)"
+ __("Up (in menu)"),__("Down (in menu)"),__("Left"),__("Right"),__("Jump"),__("Action"),__("Space (Record)"),
+ __("Escape"),__("Restart"),__("Tab (View shadow/Level prop.)"),__("Save game (in editor)"),__("Load game"),__("Swap (in editor)"),
+ __("Teleport (in editor)"),__("Suicide (in editor)"),__("Shift (in editor)"),__("Next block type (in Editor)"),
+ __("Previous block type (in editor)"), __("Select (in menu)")
};
class InputDialogHandler:public GUIEventCallback{
private:
//the list box which contains keys.
GUIListBox* listBox;
//the parent object.
InputManager* parent;
//check if it's alternative key
bool isAlternativeKey;
//update specified key config item
void updateConfigItem(int index){
//get the description
- std::string s=keySettingDescription[index];
+ std::string s=_(keySettingDescription[index]);
s+=": ";
//get key code name
int keyCode=parent->getKeyCode((InputManagerKeys)index,isAlternativeKey);
s+=InputManager::getKeyCodeName(keyCode);
//show it
listBox->item[index]=s;
}
public:
//Constructor.
InputDialogHandler(GUIListBox* listBox,InputManager* parent):listBox(listBox),parent(parent),isAlternativeKey(false){
//load the avaliable keys to the list box.
for(int i=0;i<INPUTMGR_MAX;i++){
//get the description
- std::string s=keySettingDescription[i];
+ std::string s=_(keySettingDescription[i]);
s+=": ";
//get key code name
int keyCode=parent->getKeyCode((InputManagerKeys)i,false);
s+=InputManager::getKeyCodeName(keyCode);
//add item
listBox->item.push_back(s);
}
}
//when a key is pressed call this to set the key to currently-selected item
void onKeyDown(int keyCode){
//check if an item is selected.
int index=listBox->value;
if(index<0 || index>=INPUTMGR_MAX) return;
//set it.
parent->setKeyCode((InputManagerKeys)index,keyCode,isAlternativeKey);
updateConfigItem(index);
}
void GUIEventCallback_OnEvent(std::string name,GUIObject* obj,int eventType){
//Make sure it's a click event.
if(eventType==GUIEventClick){
if(name=="cmdOK"){
//config is done, exiting
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}else if(name=="cmdUnset"){
onKeyDown(0);
}else if(name=="lstType"){
isAlternativeKey=(obj->value==1);
for(int i=0;i<INPUTMGR_MAX;i++){
updateConfigItem(i);
}
}
/*else if(name=="cmdEscape"){
//set a key to Escape
//simply call onKeyDown().
onKeyDown(SDLK_ESCAPE);
}*/
}
}
};
int InputManager::getKeyCode(InputManagerKeys key,bool isAlternativeKey){
if(isAlternativeKey) return alternativeKeys[key];
else return keys[key];
}
void InputManager::setKeyCode(InputManagerKeys key,int keyCode,bool isAlternativeKey){
if(isAlternativeKey) alternativeKeys[key]=keyCode;
else keys[key]=keyCode;
}
void InputManager::loadConfig(){
int i;
for(i=0;i<INPUTMGR_MAX;i++){
string s=keySettingNames[i];
keys[i]=atoi(getSettings()->getValue(s).c_str());
s+="2";
alternativeKeys[i]=atoi(getSettings()->getValue(s).c_str());
}
}
void InputManager::saveConfig(){
int i;
char c[32];
for(i=0;i<INPUTMGR_MAX;i++){
string s=keySettingNames[i];
sprintf(c,"%d",keys[i]);
getSettings()->setValue(s,c);
s+="2";
sprintf(c,"%d",alternativeKeys[i]);
getSettings()->setValue(s,c);
}
}
void InputManager::showConfig(){
//Save the old GUI.
GUIObject* tmp=GUIObjectRoot;
//Create the new GUI.
GUIObjectRoot=new GUIObject((SCREEN_WIDTH-600)/2,(SCREEN_HEIGHT-420)/2,600,400,GUIObjectFrame,_("Config Keys"));
GUIObject* obj;
obj=new GUIObject(0,44,600,36,GUIObjectLabel,_("Select an item and press a key to config it."),0,true,true,GUIGravityCenter);
GUIObjectRoot->childControls.push_back(obj);
//The list box.
GUIListBox *listBox=new GUIListBox(20,126,560,220);
//Event handler.
InputDialogHandler handler(listBox,this);
GUIObjectRoot->childControls.push_back(listBox);
//another box to select key type
GUISingleLineListBox *listBox0=new GUISingleLineListBox(120,80,360,36);
listBox0->name="lstType";
listBox0->item.push_back(_("Primary key"));
listBox0->item.push_back(_("Alternative key"));
listBox0->value=0;
listBox0->eventCallback=&handler;
GUIObjectRoot->childControls.push_back(listBox0);
//two buttons
obj=new GUIObject(32,360,-1,36,GUIObjectButton,_("Unset the key"),0,true,true,GUIGravityLeft);
obj->name="cmdUnset";
obj->eventCallback=&handler;
GUIObjectRoot->childControls.push_back(obj);
/*
obj=new GUIObject(20,360,360,36,GUIObjectButton,"Set to ESCAPE key");
obj->name="cmdEscape";
obj->eventCallback=&handler;
GUIObjectRoot->childControls.push_back(obj);
*/
obj=new GUIObject(GUIObjectRoot->width-32,360,-1,36,GUIObjectButton,_("OK"),0,true,true,GUIGravityRight);
obj->name="cmdOK";
obj->eventCallback=&handler;
GUIObjectRoot->childControls.push_back(obj);
//Now we keep rendering and updating the GUI.
SDL_FillRect(tempSurface,NULL,0);
SDL_SetAlpha(tempSurface,SDL_SRCALPHA,155);
SDL_BlitSurface(tempSurface,NULL,screen,NULL);
while(GUIObjectRoot){
while(SDL_PollEvent(&event)){
//check if some key is down.
if(event.type==SDL_KEYDOWN){
handler.onKeyDown(event.key.keysym.sym);
}
//Joystick
else if(event.type==SDL_JOYAXISMOTION){
if(event.jaxis.value>3200){
handler.onKeyDown(0x00010001 | (int(event.jaxis.axis)<<8));
}else if(event.jaxis.value<-3200){
handler.onKeyDown(0x000100FF | (int(event.jaxis.axis)<<8));
}
}
else if(event.type==SDL_JOYBUTTONDOWN){
handler.onKeyDown(0x00020000 | (int(event.jbutton.button)<<8));
}
else if(event.type==SDL_JOYHATMOTION){
if(event.jhat.value & SDL_HAT_LEFT){
handler.onKeyDown(0x00030000 | (int(event.jhat.hat)<<8) | SDL_HAT_LEFT);
}else if(event.jhat.value & SDL_HAT_RIGHT){
handler.onKeyDown(0x00030000 | (int(event.jhat.hat)<<8) | SDL_HAT_RIGHT);
}else if(event.jhat.value & SDL_HAT_UP){
handler.onKeyDown(0x00030000 | (int(event.jhat.hat)<<8) | SDL_HAT_UP);
}else if(event.jhat.value & SDL_HAT_DOWN){
handler.onKeyDown(0x00030000 | (int(event.jhat.hat)<<8) | SDL_HAT_DOWN);
}
}
//now process GUI events.
GUIObjectHandleEvents(true);
}
if(GUIObjectRoot)
GUIObjectRoot->render();
flipScreen();
SDL_Delay(30);
}
//Restore the old GUI.
GUIObjectRoot=tmp;
}
//get key name from key code
std::string InputManager::getKeyCodeName(int keyCode){
char c[64];
if(keyCode>0 && keyCode <0x1000){
//keyboard
char* s=SDL_GetKeyName((SDLKey)keyCode);
if(s!=NULL){
return s;
}else{
sprintf(c,"(Key %d)",keyCode);
return c;
}
}else if(keyCode>0x1000){
//Joystick. first set it to invalid value
sprintf(c,"(Joystick 0x%08X)",keyCode);
//check type
switch((keyCode & 0x00FF0000)>>16){
case 1:
//axis
switch(keyCode & 0xFF){
case 1:
sprintf(c,"Joystick axis %d +",(keyCode & 0x0000FF00)>>8);
break;
case 0xFF:
sprintf(c,"Joystick axis %d -",(keyCode & 0x0000FF00)>>8);
break;
}
break;
case 2:
//button
sprintf(c,"Joystick button %d",(keyCode & 0x0000FF00)>>8);
break;
case 3:
//hat
switch(keyCode & 0xFF){
case SDL_HAT_LEFT:
sprintf(c,"Joystick hat %d left",(keyCode & 0x0000FF00)>>8);
break;
case SDL_HAT_RIGHT:
sprintf(c,"Joystick hat %d right",(keyCode & 0x0000FF00)>>8);
break;
case SDL_HAT_UP:
sprintf(c,"Joystick hat %d up",(keyCode & 0x0000FF00)>>8);
break;
case SDL_HAT_DOWN:
sprintf(c,"Joystick hat %d down",(keyCode & 0x0000FF00)>>8);
break;
}
break;
}
return c;
}else{
//unknown??
return _("(Not set)");
}
}
InputManager::InputManager(){
//clear the array.
for(int i=0;i<INPUTMGR_MAX;i++){
keys[i]=alternativeKeys[i]=keyFlags[i]=0;
}
}
InputManager::~InputManager(){
closeAllJoysticks();
}
int InputManager::getKeyState(int keyCode,int oldState,bool hasEvent){
int state=0;
if(keyCode>0 && keyCode<0x1000){
//keyboard
if(hasEvent){
if(event.type==SDL_KEYDOWN && event.key.keysym.sym==keyCode){
state|=0x2;
}
if(event.type==SDL_KEYUP && event.key.keysym.sym==keyCode){
state|=0x4;
}
}
if(keyCode<SDLK_LAST && SDL_GetKeyState(NULL)[keyCode]){
state|=0x1;
}
}else if(keyCode>0x1000){
//Joystick
int index=(keyCode & 0x0000FF00)>>8;
int value=keyCode & 0xFF;
int i,v;
switch((keyCode & 0x00FF0000)>>16){
case 1:
//axis
if(hasEvent){
if(event.type==SDL_JOYAXISMOTION && event.jaxis.axis==index){
if((value==1 && event.jaxis.value>3200) || (value==0xFF && event.jaxis.value<-3200)){
if((oldState & 0x1)==0) state|=0x2;
}else{
if(oldState & 0x1) state|=0x4;
}
}
}
for(i=0;i<(int)joysticks.size();i++){
v=SDL_JoystickGetAxis(joysticks[i],index);
if((value==1 && v>3200) || (value==0xFF && v<-3200)){
state|=0x1;
break;
}
}
break;
case 2:
//button
if(hasEvent){
if(event.type==SDL_JOYBUTTONDOWN && event.jbutton.button==index){
state|=0x2;
}
if(event.type==SDL_JOYBUTTONUP && event.jbutton.button==index){
state|=0x4;
}
}
for(i=0;i<(int)joysticks.size();i++){
v=SDL_JoystickGetButton(joysticks[i],index);
if(v){
state|=0x1;
break;
}
}
break;
case 3:
//hat
if(hasEvent){
if(event.type==SDL_JOYHATMOTION && event.jhat.hat==index){
if(event.jhat.value & value){
if((oldState & 0x1)==0) state|=0x2;
}else{
if(oldState & 0x1) state|=0x4;
}
}
}
for(i=0;i<(int)joysticks.size();i++){
v=SDL_JoystickGetHat(joysticks[i],index);
if(v & value){
state|=0x1;
break;
}
}
break;
}
}
return state;
}
//update the key state, according to current SDL event, etc.
void InputManager::updateState(bool hasEvent){
for(int i=0;i<INPUTMGR_MAX;i++){
keyFlags[i]=getKeyState(keys[i],keyFlags[i],hasEvent)|getKeyState(alternativeKeys[i],keyFlags[i],hasEvent);
}
}
//check if there is KeyDown event.
bool InputManager::isKeyDownEvent(InputManagerKeys key){
return keyFlags[key]&0x2;
}
//check if there is KeyUp event.
bool InputManager::isKeyUpEvent(InputManagerKeys key){
return keyFlags[key]&0x4;
}
//check if specified key is down.
bool InputManager::isKeyDown(InputManagerKeys key){
return keyFlags[key]&0x1;
}
//open all joysticks.
void InputManager::openAllJoysitcks(){
int i,m;
//First close previous joysticks.
closeAllJoysticks();
//open all joysticks.
m=SDL_NumJoysticks();
for(i=0;i<m;i++){
SDL_Joystick *j=SDL_JoystickOpen(i);
if(j==NULL){
printf("ERROR: Couldn't open Joystick %d\n",i);
}else{
joysticks.push_back(j);
}
}
}
//close all joysticks.
void InputManager::closeAllJoysticks(){
for(int i=0;i<(int)joysticks.size();i++){
SDL_JoystickClose(joysticks[i]);
}
joysticks.clear();
}
diff --git a/src/LevelEditSelect.cpp b/src/LevelEditSelect.cpp
index ab5f1ee..e6a2c20 100644
--- a/src/LevelEditSelect.cpp
+++ b/src/LevelEditSelect.cpp
@@ -1,699 +1,699 @@
/****************************************************************************
** Copyright (C) 2011 Luka Horvat <redreaper132 at gmail.com>
** Copyright (C) 2011 Edward Lii <edward_iii at myway.com>
** Copyright (C) 2011 O. Bahri Gordebak <gordebak at gmail.com>
**
**
** This file may be used under the terms of the GNU General Public
** License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "LevelEditSelect.h"
#include "GameState.h"
#include "Functions.h"
#include "FileManager.h"
#include "Globals.h"
#include "Objects.h"
#include "GUIObject.h"
#include "GUIListBox.h"
#include "GUIScrollBar.h"
#include "InputManager.h"
#include "Game.h"
#include <SDL/SDL_ttf.h>
#include <SDL/SDL.h>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <iostream>
#include "libs/tinyformat/tinyformat.h"
using namespace std;
LevelEditSelect::LevelEditSelect():LevelSelect(_("Map Editor"),LevelPackManager::CUSTOM_PACKS){
//Create the gui.
createGUI(true);
//Set the levelEditGUIObjectRoot.
levelEditGUIObjectRoot=GUIObjectRoot;
//show level list
changePack();
refresh();
}
LevelEditSelect::~LevelEditSelect(){
selectedNumber=NULL;
}
void LevelEditSelect::createGUI(bool initial){
if(initial){
//The levelpack name text field.
levelpackName=new GUIObject(280,104,240,32,GUIObjectTextBox);
levelpackName->eventCallback=this;
levelpackName->visible=false;
GUIObjectRoot->childControls.push_back(levelpackName);
}
if(!initial){
//Remove the previous buttons.
for(int i=0;i<GUIObjectRoot->childControls.size();i++){
if(GUIObjectRoot->childControls[i]->type==GUIObjectButton && GUIObjectRoot->childControls[i]->caption!=_("Back")){
delete GUIObjectRoot->childControls[i];
GUIObjectRoot->childControls.erase(GUIObjectRoot->childControls.begin()+i);
i--;
}
}
}
//Create the six buttons at the bottom of the screen.
GUIObject* obj=new GUIObject(SCREEN_WIDTH*0.02,SCREEN_HEIGHT-120,-1,32,GUIObjectButton,_("New Levelpack"));
obj->name="cmdNewLvlpack";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
propertiesPack=new GUIObject(SCREEN_WIDTH*0.5,SCREEN_HEIGHT-120,-1,32,GUIObjectButton,_("Pack Properties"),0,true,true,GUIGravityCenter);
propertiesPack->name="cmdLvlpackProp";
propertiesPack->eventCallback=this;
GUIObjectRoot->childControls.push_back(propertiesPack);
removePack=new GUIObject(SCREEN_WIDTH*0.98,SCREEN_HEIGHT-120,-1,32,GUIObjectButton,_("Remove Pack"),0,true,true,GUIGravityRight);
removePack->name="cmdRmLvlpack";
removePack->eventCallback=this;
GUIObjectRoot->childControls.push_back(removePack);
move=new GUIObject(SCREEN_WIDTH*0.02,SCREEN_HEIGHT-60,-1,32,GUIObjectButton,_("Move Map"));
move->name="cmdMoveMap";
move->eventCallback=this;
move->enabled=false;
GUIObjectRoot->childControls.push_back(move);
remove=new GUIObject(SCREEN_WIDTH*0.5,SCREEN_HEIGHT-60,-1,32,GUIObjectButton,_("Remove Map"),0,false,true,GUIGravityCenter);
remove->name="cmdRmMap";
remove->eventCallback=this;
GUIObjectRoot->childControls.push_back(remove);
edit=new GUIObject(SCREEN_WIDTH*0.98,SCREEN_HEIGHT-60,-1,32,GUIObjectButton,_("Edit Map"),0,false,true,GUIGravityRight);
edit->name="cmdEdit";
edit->eventCallback=this;
GUIObjectRoot->childControls.push_back(edit);
//Now update widgets (draw them outside of the view) and then check if they overlap
- GUIObjectRoot->render(-SCREEN_WIDTH,-SCREEN_HEIGHT); //FIXME: this is an ugly hack
- if(propertiesPack->left-propertiesPack->gravityX < obj->left+obj->width &&
+ GUIObjectRoot->render(0,0,false);
+ if(propertiesPack->left-propertiesPack->gravityX < obj->left+obj->width ||
propertiesPack->left-propertiesPack->gravityX+propertiesPack->width > removePack->left-removePack->gravityX){
obj->smallFont=true;
obj->width=-1;
propertiesPack->smallFont=true;
propertiesPack->width=-1;
removePack->smallFont=true;
removePack->width=-1;
move->smallFont=true;
move->width=-1;
remove->smallFont=true;
remove->width=-1;
edit->smallFont=true;
edit->width=-1;
}
}
void LevelEditSelect::changePack(){
packName=levelpacks->item[levelpacks->value];
if(packName=="Custom Levels"){
//Disable some levelpack buttons.
propertiesPack->enabled=false;
removePack->enabled=false;
}else{
//Enable some levelpack buttons.
propertiesPack->enabled=true;
removePack->enabled=true;
}
//Set last levelpack.
getSettings()->setValue("lastlevelpack",packName);
//Now let levels point to the right pack.
levels=getLevelPackManager()->getLevelPack(packName);
}
void LevelEditSelect::packProperties(){
//Open a message popup.
//NOTE: We can always point GUIObjectRoot to the main gui by using levelEditGUIObjectRoot.
GUIObjectRoot=new GUIObject((SCREEN_WIDTH-600)/2,(SCREEN_HEIGHT-320)/2,600,320,GUIObjectFrame,_("Properties"));
GUIObject* obj;
obj=new GUIObject(40,50,240,36,GUIObjectLabel,_("Name:"));
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(60,80,480,36,GUIObjectTextBox,packName.c_str());
obj->name="LvlpackName";
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(40,120,240,36,GUIObjectLabel,_("Description:"));
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(60,150,480,36,GUIObjectTextBox,levels->levelpackDescription.c_str());
obj->name="LvlpackDescription";
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(40,190,240,36,GUIObjectLabel,_("Congratulation text:"));
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(60,220,480,36,GUIObjectTextBox,levels->congratulationText.c_str());
obj->name="LvlpackCongratulation";
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(100,320-44,150,36,GUIObjectButton,_("OK"));
obj->name="cfgOK";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(350,320-44,150,36,GUIObjectButton,_("Cancel"));
obj->name="cfgCancel";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
//Dim the screen using the tempSurface.
SDL_FillRect(tempSurface,NULL,0);
SDL_SetAlpha(tempSurface,SDL_SRCALPHA,155);
SDL_BlitSurface(tempSurface,NULL,screen,NULL);
while(GUIObjectRoot){
while(SDL_PollEvent(&event)) GUIObjectHandleEvents(true);
if(GUIObjectRoot) GUIObjectRoot->render();
flipScreen();
SDL_Delay(30);
}
//We're done so set the original GUIObjectRoot back.
GUIObjectRoot=levelEditGUIObjectRoot;
}
void LevelEditSelect::addLevel(){
//Open a message popup.
//NOTE: We can always point GUIObjectRoot to the main gui by using levelEditGUIObjectRoot.
GUIObjectRoot=new GUIObject((SCREEN_WIDTH-600)/2,(SCREEN_HEIGHT-200)/2,600,200,GUIObjectFrame,_("Add level"));
GUIObject* obj;
obj=new GUIObject(40,80,240,36,GUIObjectLabel,_("File name:"));
GUIObjectRoot->childControls.push_back(obj);
char s[64];
sprintf(s,"map%02d.map",levels->getLevelCount()+1);
obj=new GUIObject(300,80,240,36,GUIObjectTextBox,s);
obj->name="LvlFile";
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(100,200-44,150,36,GUIObjectButton,_("OK"));
obj->name="cfgAddOK";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(350,200-44,150,36,GUIObjectButton,_("Cancel"));
obj->name="cfgAddCancel";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
//Dim the screen using the tempSurface.
SDL_FillRect(tempSurface,NULL,0);
SDL_SetAlpha(tempSurface,SDL_SRCALPHA,155);
SDL_BlitSurface(tempSurface,NULL,screen,NULL);
while(GUIObjectRoot){
while(SDL_PollEvent(&event)) GUIObjectHandleEvents(true);
if(GUIObjectRoot) GUIObjectRoot->render();
flipScreen();
SDL_Delay(30);
}
//We're done so set the original GUIObjectRoot back.
GUIObjectRoot=levelEditGUIObjectRoot;
}
void LevelEditSelect::moveLevel(){
//Open a message popup.
//NOTE: We can always point GUIObjectRoot to the main gui by using levelEditGUIObjectRoot.
GUIObjectRoot=new GUIObject((SCREEN_WIDTH-600)/2,(SCREEN_HEIGHT-200)/2,600,200,GUIObjectFrame,_("Move level"));
GUIObject* obj;
obj=new GUIObject(40,80,240,36,GUIObjectLabel,_("Level: "));
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(300,80,240,36,GUIObjectTextBox,"1");
- obj->name=_("MoveLevel");
+ obj->name="MoveLevel";
GUIObjectRoot->childControls.push_back(obj);
obj=new GUISingleLineListBox(40,120,240,36);
obj->name="lstPlacement";
vector<string> v;
v.push_back(_("Before"));
v.push_back(_("After"));
v.push_back(_("Swap"));
(dynamic_cast<GUISingleLineListBox*>(obj))->item=v;
obj->value=0;
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(100,200-44,150,36,GUIObjectButton,_("OK"));
obj->name="cfgMoveOK";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(350,200-44,150,36,GUIObjectButton,_("Cancel"));
obj->name="cfgMoveCancel";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
//Dim the screen using the tempSurface.
SDL_FillRect(tempSurface,NULL,0);
SDL_SetAlpha(tempSurface,SDL_SRCALPHA,155);
SDL_BlitSurface(tempSurface,NULL,screen,NULL);
while(GUIObjectRoot){
while(SDL_PollEvent(&event)) GUIObjectHandleEvents(true);
if(GUIObjectRoot) GUIObjectRoot->render();
flipScreen();
SDL_Delay(30);
}
//We're done so set the original GUIObjectRoot back.
GUIObjectRoot=levelEditGUIObjectRoot;
}
void LevelEditSelect::refresh(){
int m=levels->getLevelCount();
numbers.clear();
//clear the selected level
if(selectedNumber!=NULL){
selectedNumber=NULL;
}
//Disable the level specific buttons.
move->enabled=false;
remove->enabled=false;
edit->enabled=false;
for(int n=0;n<=m;n++){
numbers.push_back(Number());
}
for(int n=0;n<m;n++){
SDL_Rect box={(n%LEVELS_PER_ROW)*64+80,(n/LEVELS_PER_ROW)*64+184,0,0};
numbers[n].init(n,box);
}
SDL_Rect box={(m%LEVELS_PER_ROW)*64+80,(m/LEVELS_PER_ROW)*64+184,0,0};
numbers[m].init("+",box);
m++; //including the "+" button
if(m>LEVELS_DISPLAYED_IN_SCREEN){
levelScrollBar->maxValue=(m-LEVELS_DISPLAYED_IN_SCREEN+LEVELS_PER_ROW-1)/LEVELS_PER_ROW;
levelScrollBar->visible=true;
}else{
levelScrollBar->maxValue=0;
levelScrollBar->visible=false;
}
if(!levels->levelpackDescription.empty()){
levelpackDescription->caption=_C(levels->getDictionaryManager(),levels->levelpackDescription);
int width,height;
TTF_SizeText(fontText,_C(levels->getDictionaryManager(),levels->levelpackDescription),&width,&height);
levelpackDescription->left=(SCREEN_WIDTH-width)/2;
}else{
levelpackDescription->caption="";
}
}
void LevelEditSelect::selectNumber(unsigned int number,bool selected){
if(selected){
levels->setCurrentLevel(number);
setNextState(STATE_LEVEL_EDITOR);
//Pick music from the current music list.
getMusicManager()->pickMusic();
}else{
if(number==numbers.size()-1){
addLevel();
}else if(number>=0 && number<numbers.size()){
selectedNumber=&numbers[number];
//Enable the level specific buttons.
//NOTE: We check if 'remove levelpack' is enabled, if not then it's the Levels levelpack.
if(removePack->enabled)
move->enabled=true;
remove->enabled=true;
edit->enabled=true;
}
}
}
void LevelEditSelect::render(){
//Let the levelselect render.
LevelSelect::render();
}
void LevelEditSelect::resize(){
//Let the levelselect resize.
LevelSelect::resize();
//Create the GUI.
createGUI(false);
}
void LevelEditSelect::renderTooltip(unsigned int number,int dy){
SDL_Color fg={0,0,0};
SDL_Surface* name;
if(number==(unsigned)levels->getLevelCount()){
//Render the name of the level.
name=TTF_RenderUTF8_Blended(fontText,_("Add level"),fg);
}else{
//Render the name of the level.
name=TTF_RenderUTF8_Blended(fontText,_C(levels->getDictionaryManager(),levels->getLevelName(number)),fg);
}
//Check if name isn't null.
if(name==NULL)
return;
//Now draw a square the size of the three texts combined.
SDL_Rect r=numbers[number].box;
r.y-=dy*64;
r.w=name->w;
r.h=name->h;
//Make sure the tooltip doesn't go outside the window.
if(r.y>SCREEN_HEIGHT-200){
r.y-=name->h+4;
}else{
r.y+=numbers[number].box.h+2;
}
if(r.x+r.w>SCREEN_WIDTH-50)
r.x=SCREEN_WIDTH-50-r.w;
//Draw a rectange
Uint32 color=0xFFFFFF00|240;
drawGUIBox(r.x-5,r.y-5,r.w+10,r.h+10,screen,color);
//Calc the position to draw.
SDL_Rect r2=r;
//Now we render the name if the surface isn't null.
if(name!=NULL){
//Draw the name.
SDL_BlitSurface(name,NULL,screen,&r2);
}
//And free the surfaces.
SDL_FreeSurface(name);
}
void LevelEditSelect::GUIEventCallback_OnEvent(std::string name,GUIObject* obj,int eventType){
//NOTE: We check for the levelpack change to enable/disable some levelpack buttons.
if(name=="cmdLvlPack"){
//We call changepack and return to prevent the LevelSelect to undo what we did.
changePack();
refresh();
return;
}
//Let the level select handle his GUI events.
LevelSelect::GUIEventCallback_OnEvent(name,obj,eventType);
//Check for the edit button.
if(name=="cmdNewLvlpack"){
//Clear the current pack name.
packName.clear();
LevelPack* levelpack=new LevelPack;
levels=levelpack;
//Create a new pack.
packProperties();
}else if(name=="cmdLvlpackProp"){
//Show the pack properties.
packProperties();
}else if(name=="cmdRmLvlpack"){
//Show an "are you sure" message.
if(msgBox(_("Are you sure?"),MsgBoxYesNo,_("Remove prompt"))==MsgBoxYes){
//Remove the directory.
if(!removeDirectory(levels->levelpackPath.c_str())){
cerr<<"ERROR: Unable to remove levelpack directory "<<levels->levelpackPath<<endl;
}
//Remove it from the vector (levelpack list).
vector<string>::iterator it;
it=find(levelpacks->item.begin(),levelpacks->item.end(),packName);
if(it!=levelpacks->item.end()){
levelpacks->item.erase(it);
}
//Remove it from the levelpackManager.
getLevelPackManager()->removeLevelPack(packName);
//And call changePack.
levelpacks->value=levelpacks->item.size()-1;
changePack();
refresh();
}
}else if(name=="cmdMoveMap"){
if(selectedNumber!=NULL){
moveLevel();
}
}else if(name=="cmdRmMap"){
if(selectedNumber!=NULL){
if(packName!="Custom Levels"){
if(!removeFile((levels->levelpackPath+"/"+levels->getLevel(selectedNumber->getNumber())->file).c_str())){
cerr<<"ERROR: Unable to remove level "<<(levels->levelpackPath+"/"+levels->getLevel(selectedNumber->getNumber())->file).c_str()<<endl;
}
levels->removeLevel(selectedNumber->getNumber());
levels->saveLevels(levels->levelpackPath+"/levels.lst");
}else{
//This is the levels levelpack so we just remove the file.
if(!removeFile(levels->getLevel(selectedNumber->getNumber())->file.c_str())){
cerr<<"ERROR: Unable to remove level "<<levels->getLevel(selectedNumber->getNumber())->file<<endl;
}
levels->removeLevel(selectedNumber->getNumber());
}
//And refresh the selection screen.
refresh();
}
}else if(name=="cmdEdit"){
if(selectedNumber!=NULL){
levels->setCurrentLevel(selectedNumber->getNumber());
setNextState(STATE_LEVEL_EDITOR);
//Pick music from the current music list.
getMusicManager()->pickMusic();
}
}
//Check for levelpack properties events.
if(name=="cfgOK"){
//Now loop throught the children of the GUIObjectRoot in search of the fields.
for(unsigned int i=0;i<GUIObjectRoot->childControls.size();i++){
if(GUIObjectRoot->childControls[i]->name=="LvlpackName"){
//Check if the name changed.
if(packName!=GUIObjectRoot->childControls[i]->caption){
//Delete the old one.
if(!packName.empty()){
if(!renameDirectory((getUserPath(USER_DATA)+"custom/levelpacks/"+packName).c_str(),(getUserPath(USER_DATA)+"custom/levelpacks/"+GUIObjectRoot->childControls[i]->caption).c_str())){
cerr<<"ERROR: Unable to move levelpack directory "<<(getUserPath(USER_DATA)+"custom/levelpacks/"+packName)<<" to "<<(getUserPath(USER_DATA)+"custom/levelpacks/"+GUIObjectRoot->childControls[i]->caption)<<endl;
}
//Remove the old one from the levelpack manager.
getLevelPackManager()->removeLevelPack(packName);
//And the levelpack list.
vector<string>::iterator it1;
it1=find(levelpacks->item.begin(),levelpacks->item.end(),packName);
if(it1!=levelpacks->item.end()){
levelpacks->item.erase(it1);
if((unsigned)levelpacks->value>levelpacks->item.size())
levelpacks->value=levelpacks->item.size()-1;
}
}else{
if(!createDirectory((getUserPath(USER_DATA)+"custom/levelpacks/"+GUIObjectRoot->childControls[i]->caption).c_str())){
cerr<<"ERROR: Unable to create levelpack directory "<<(getUserPath(USER_DATA)+"custom/levelpacks/"+GUIObjectRoot->childControls[i]->caption)<<endl;
}
if(!createFile((getUserPath(USER_DATA)+"custom/levelpacks/"+GUIObjectRoot->childControls[i]->caption+"/levels.lst").c_str())){
cerr<<"ERROR: Unable to create levelpack file "<<(getUserPath(USER_DATA)+"custom/levelpacks/"+GUIObjectRoot->childControls[i]->caption+"/levels.lst")<<endl;
}
}
//And set the new name.
packName=GUIObjectRoot->childControls[i]->caption;
levels->levelpackName=packName;
levels->levelpackPath=(getUserPath(USER_DATA)+"custom/levelpacks/"+packName+"/");
//Also add the levelpack location
getLevelPackManager()->addLevelPack(levels);
levelpacks->item.push_back(GUIObjectRoot->childControls[i]->caption);
levelpacks->value=levelpacks->item.size()-1;
//And call changePack.
changePack();
}
}
if(GUIObjectRoot->childControls[i]->name=="LvlpackDescription"){
levels->levelpackDescription=GUIObjectRoot->childControls[i]->caption;
}
if(GUIObjectRoot->childControls[i]->name=="LvlpackCongratulation"){
levels->congratulationText=GUIObjectRoot->childControls[i]->caption;
}
}
//Refresh the leveleditselect to show the correct information.
refresh();
//Save the configuration.
levels->saveLevels(getUserPath(USER_DATA)+"custom/levelpacks/"+packName+"/levels.lst");
getSettings()->setValue("lastlevelpack",packName);
//Clear the gui.
if(GUIObjectRoot){
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
}else if(name=="cfgCancel"){
//Check if packName is empty, if so it was a new levelpack and we need to revert to an existing one.
if(packName.empty()){
packName=levelpacks->item[levelpacks->value];
changePack();
}
//Clear the gui.
if(GUIObjectRoot){
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
}
//Check for add level events.
if(name=="cfgAddOK"){
//Check if the file name isn't null.
//Now loop throught the children of the GUIObjectRoot in search of the fields.
for(unsigned int i=0;i<GUIObjectRoot->childControls.size();i++){
if(GUIObjectRoot->childControls[i]->name=="LvlFile"){
if(GUIObjectRoot->childControls[i]->caption.empty()){
msgBox(_("No file name given for the new level."),MsgBoxOKOnly,_("Missing file name"));
return;
}else{
string tmp_caption = GUIObjectRoot->childControls[i]->caption;
//Replace all spaces with a underline.
size_t j;
for(;(j=tmp_caption.find(" "))!=string::npos;){
tmp_caption.replace(j,1,"_");
}
//If there isn't ".map" extension add it.
size_t found=tmp_caption.find_first_of(".");
if(found!=string::npos)
tmp_caption.replace(tmp_caption.begin()+found+1,tmp_caption.end(),"map");
else if (tmp_caption.substr(found+1)!="map")
tmp_caption.append(".map");
/* Create path and file in it */
string path=(levels->levelpackPath+"/"+tmp_caption);
if(packName=="Custom Levels"){
path=(getUserPath(USER_DATA)+"/custom/levels/"+tmp_caption);
}
//First check if the file doesn't exist already.
FILE* f;
f=fopen(path.c_str(),"rb");
//Check if it exists.
if(f){
//Close the file.
fclose(f);
//Let the currentState render once to prevent multiple GUI overlapping and prevent the screen from going black.
currentState->render();
levelEditGUIObjectRoot->render();
//Notify the user.
msgBox(("The file "+tmp_caption+" already exists.").c_str(),MsgBoxOKOnly,"Error");
return;
}
if(!createFile(path.c_str())){
cerr<<"ERROR: Unable to create level file "<<path<<endl;
}
levels->addLevel(path);
if(packName!="Custom Levels")
levels->saveLevels(getUserPath(USER_DATA)+"custom/levelpacks/"+packName+"/levels.lst");
refresh();
//Clear the gui.
if(GUIObjectRoot){
delete GUIObjectRoot;
GUIObjectRoot=NULL;
return;
}
}
}
}
}else if(name=="cfgAddCancel"){
//Clear the gui.
if(GUIObjectRoot){
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
}
//Check for move level events.
if(name=="cfgMoveOK"){
//Check if the entered level number is valid.
//Now loop throught the children of the GUIObjectRoot in search of the fields.
int level=0;
int placement=0;
for(unsigned int i=0;i<GUIObjectRoot->childControls.size();i++){
if(GUIObjectRoot->childControls[i]->name=="MoveLevel"){
level=atoi(GUIObjectRoot->childControls[i]->caption.c_str());
if(level<=0 || level>levels->getLevelCount()){
msgBox(_("The entered level number isn't valid!"),MsgBoxOKOnly,_("Illegal number"));
return;
}
}
if(GUIObjectRoot->childControls[i]->name=="lstPlacement"){
placement=GUIObjectRoot->childControls[i]->value;
}
}
//Now we execute the swap/move.
//Check for the place before.
if(placement==0){
//We place the selected level before the entered level.
levels->moveLevel(selectedNumber->getNumber(),level-1);
}else if(placement==1){
//We place the selected level after the entered level.
if(level<selectedNumber->getNumber())
levels->moveLevel(selectedNumber->getNumber(),level);
else
levels->moveLevel(selectedNumber->getNumber(),level+1);
}else if(placement==2){
//We swap the selected level with the entered level.
levels->swapLevel(selectedNumber->getNumber(),level-1);
}
//And save the change.
if(packName!="Custom Levels")
levels->saveLevels(getUserPath(USER_DATA)+"custom/levelpacks/"+packName+"/levels.lst");
refresh();
//Clear the gui.
if(GUIObjectRoot){
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
}else if(name=="cfgMoveCancel"){
//Clear the gui.
if(GUIObjectRoot){
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
}
}
diff --git a/src/LevelEditor.cpp b/src/LevelEditor.cpp
index 97b82f9..4a3eb8b 100644
--- a/src/LevelEditor.cpp
+++ b/src/LevelEditor.cpp
@@ -1,2994 +1,3008 @@
/****************************************************************************
** Copyright (C) 2011 Luka Horvat <redreaper132 at gmail.com>
** Copyright (C) 2011 Edward Lii <edward_iii at myway.com>
** Copyright (C) 2011 O. Bahri Gordebak <gordebak at gmail.com>
**
**
** This file may be used under the terms of the GNU General Public
** License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "GameState.h"
#include "Globals.h"
#include "Functions.h"
#include "FileManager.h"
#include "GameObjects.h"
#include "ThemeManager.h"
#include "Objects.h"
#include "LevelPack.h"
#include "LevelEditor.h"
#include "TreeStorageNode.h"
#include "POASerializer.h"
#include "GUIListBox.h"
#include "GUITextArea.h"
#include "InputManager.h"
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#ifdef WIN32
#include <windows.h>
#include <shlobj.h>
#else
#include <strings.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <dirent.h>
#endif
#include "libs/tinyformat/tinyformat.h"
using namespace std;
static int levelTime,levelRecordings;
static GUIObject *levelTimeProperty,*levelRecordingsProperty;
/////////////////LevelEditorToolbox////////////////////////
class LevelEditorToolbox{
private:
//The parent object
LevelEditor* parent;
//The position of window
SDL_Rect rect;
//Background surface
SDL_Surface *background;
//GUI image
SDL_Surface *bmGUI;
public:
int startRow,maxRow;
bool visible;
bool dragging;
public:
SDL_Rect getRect(){
return rect;
}
int width(){
return 320;
}
int height(){
return 180;
}
LevelEditorToolbox(LevelEditor* parent){
this->parent=parent;
visible=false;
dragging=false;
//calc row count
startRow=0;
maxRow=(LevelEditor::EDITOR_ORDER_MAX+4)/5;
//set size
rect.w=width();
rect.h=height();
//Load the gui images.
bmGUI=loadImage(getDataPath()+"gfx/gui.png");
//create background and draw somethong on it
background=SDL_CreateRGBSurface(SDL_HWSURFACE,
rect.w,rect.h,screen->format->BitsPerPixel,
screen->format->Rmask,screen->format->Gmask,screen->format->Bmask,0);
//background
drawGUIBox(0,0,rect.w,rect.h,background,0xFFFFFFFFU);
//caption
{
SDL_Rect captionRect={8,8,width()-16,32};
SDL_FillRect(background,&captionRect,0xCCCCCCU);
SDL_Color fg={0,0,0};
SDL_Surface *caption=TTF_RenderUTF8_Blended(fontGUI,_("Toolbox"),fg);
applySurface(captionRect.x+(captionRect.w-caption->w)/2,
captionRect.y+(captionRect.h-caption->h)/2,caption,background,NULL);
SDL_FreeSurface(caption);
}
}
~LevelEditorToolbox(){
SDL_FreeSurface(background);
}
void move(int x,int y){
if(x>SCREEN_WIDTH-rect.w) x=SCREEN_WIDTH-rect.w;
else if(x<0) x=0;
if(y>SCREEN_HEIGHT-rect.h) y=SCREEN_HEIGHT-rect.h;
else if(y<0) y=0;
rect.x=x;
rect.y=y;
}
void render(){
if(visible){
applySurface(rect.x,rect.y,background,screen,NULL);
//get mouse position
int x,y;
SDL_GetMouseState(&x,&y);
SDL_Rect mouse={x,y,0,0};
//draw close button
{
//check highlight
SDL_Rect r={rect.x+rect.w-36,rect.y+12,24,24};
if(checkCollision(mouse,r)){
drawGUIBox(r.x,r.y,r.w,r.h,screen,0x999999FFU);
}
SDL_Rect r1={112,0,16,16};
applySurface(rect.x+rect.w-32,rect.y+16,bmGUI,screen,&r1);
}
//the tool tip of item
SDL_Rect tooltipRect;
string tooltip;
//draw avaliable item
for(int i=0;i<2;i++){
int j=startRow+i;
if(j>=maxRow) j-=maxRow;
for(int k=0;k<5;k++){
int idx=j*5+k;
if(idx<0 || idx>=LevelEditor::EDITOR_ORDER_MAX) break;
SDL_Rect r={rect.x+k*60+10,rect.y+i*60+50,60,60};
//check highlight
if(checkCollision(mouse,r)){
+ //Array containing translateble block names
+ const char* blockNames[TYPE_MAX]={__("Block"),__("Player Start"),__("Shadow Start"),
+ __("Exit"),__("Shadow Block"),__("Spikes"),
+ __("Checkpoint"),__("Swap"),__("Fragile"),
+ __("Moving Block"),__("Moving Shadow Block"),__("Moving Spikes"),
+ __("Teleporter"),__("Button"),__("Switch"),
+ __("Conveyor Belt"),__("Shadow Conveyor Belt"),__("Notification Block"),__("Collectable")
+ };
+
tooltipRect=r;
- tooltip=Game::blockName[LevelEditor::editorTileOrder[idx]];
+ tooltip=_(blockNames[LevelEditor::editorTileOrder[idx]]);
if(parent->currentType==idx){
drawGUIBox(r.x,r.y,r.w,r.h,screen,0x999999FFU);
}else{
SDL_FillRect(screen,&r,0xCCCCCC);
}
}else if(parent->currentType==idx){
drawGUIBox(r.x,r.y,r.w,r.h,screen,0xCCCCCCFFU);
}
ThemeBlock* obj=objThemes.getBlock(LevelEditor::editorTileOrder[idx]);
if(obj){
obj->editorPicture.draw(screen,r.x+5,r.y+5);
}
}
}
//draw tooltip
if(!tooltip.empty()){
//The back and foreground colors.
SDL_Color fg={0,0,0};
//Tool specific text.
SDL_Surface* tip=TTF_RenderUTF8_Blended(fontText,tooltip.c_str(),fg);
//Draw only if there's a tooltip available
if(tip!=NULL){
if(tooltipRect.y+tooltipRect.h+tip->h>SCREEN_HEIGHT-20)
tooltipRect.y-=tip->h;
else
tooltipRect.y+=tooltipRect.h;
if(tooltipRect.x+tip->w>SCREEN_WIDTH-20)
tooltipRect.x=SCREEN_WIDTH-20-tip->w;
//Draw borders around text
Uint32 color=0xFFFFFF00|230;
drawGUIBox(tooltipRect.x-2,tooltipRect.y-2,tip->w+4,tip->h+4,screen,color);
//Draw tooltip's text
SDL_BlitSurface(tip,NULL,screen,&tooltipRect);
SDL_FreeSurface(tip);
}
}
}
}
void handleEvents(){
if(event.type==SDL_MOUSEBUTTONDOWN && event.button.button==SDL_BUTTON_LEFT){
SDL_Rect mouse={event.button.x,event.button.y,0,0};
//Check if close button clicked
{
SDL_Rect r={rect.x+rect.w-36,rect.y+12,24,24};
if(checkCollision(mouse,r)){
visible=false;
+ rect.w=0;
+ rect.h=0;
return;
}
}
//Check if item is clicked
for(int i=0;i<2;i++){
int j=startRow+i;
if(j>=maxRow) j-=maxRow;
for(int k=0;k<5;k++){
int idx=j*5+k;
if(idx<0 || idx>=LevelEditor::EDITOR_ORDER_MAX) break;
SDL_Rect r={rect.x+k*60+10,rect.y+i*60+50,60,60};
//check highlight
if(checkCollision(mouse,r)){
parent->currentType=idx;
return;
}
}
}
//Now begin drag the toolbox
dragging=true;
}
else if(event.type==SDL_MOUSEBUTTONUP && event.button.button==SDL_BUTTON_LEFT){
dragging=false;
}
else if(event.type==SDL_MOUSEMOTION){
if((event.motion.state & SDL_BUTTON_LMASK)==0){
dragging=false;
}else if(dragging){
move(rect.x+event.motion.xrel,rect.y+event.motion.yrel);
}
}
}
};
/////////////////MovingPosition////////////////////////////
MovingPosition::MovingPosition(int x,int y,int time){
this->x=x;
this->y=y;
this->time=time;
}
MovingPosition::~MovingPosition(){}
void MovingPosition::updatePosition(int x,int y){
this->x=x;
this->y=y;
}
/////////////////LEVEL EDITOR//////////////////////////////
LevelEditor::LevelEditor():Game(true){
//Get the target time and recordings.
levelTime=levels->getLevel()->targetTime;
levelRecordings=levels->getLevel()->targetRecordings;
//This will set some default settings.
reset();
//The level is loaded by the game, so do postLoad.
postLoad();
//Load the toolbar.
toolbar=loadImage(getDataPath()+"gfx/menu/toolbar.png");
SDL_Rect tmp={(SCREEN_WIDTH-460)/2,SCREEN_HEIGHT-50,460,50};
toolbarRect=tmp;
toolbox=NULL;
//Load the selectionMark.
selectionMark=loadImage(getDataPath()+"gfx/menu/selection.png");
//Load the movingMark.
movingMark=loadImage(getDataPath()+"gfx/menu/moving.png");
//Create the semi transparent surface.
placement=SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCALPHA,SCREEN_WIDTH,SCREEN_HEIGHT,32,0x000000FF,0x0000FF00,0x00FF0000,0);
SDL_SetColorKey(placement,SDL_SRCCOLORKEY|SDL_RLEACCEL,SDL_MapRGB(placement->format,255,0,255));
SDL_SetAlpha(placement,SDL_SRCALPHA,125);
}
LevelEditor::~LevelEditor(){
//Loop through the levelObjects and delete them.
for(unsigned int i=0;i<levelObjects.size();i++)
delete levelObjects[i];
levelObjects.clear();
selection.clear();
//Free the placement surface.
SDL_FreeSurface(placement);
//Delete the toolbox (if any)
if(toolbox){
delete toolbox;
toolbox=NULL;
}
//Reset the camera.
camera.x=0;
camera.y=0;
}
void LevelEditor::reset(){
//Set some default values.
playMode=false;
tool=ADD;
currentType=0;
pressedShift=false;
pressedLeftMouse=false;
dragging=false;
selectionDrag=false;
dragCenter=NULL;
if(LEVEL_WIDTH<SCREEN_WIDTH)
camera.x=-(SCREEN_WIDTH-LEVEL_WIDTH)/2;
else
camera.x=0;
if(LEVEL_HEIGHT<SCREEN_HEIGHT)
camera.y=-(SCREEN_HEIGHT-LEVEL_HEIGHT)/2;
else
camera.y=0;
cameraXvel=0;
cameraYvel=0;
objectProperty=NULL;
secondObjectProperty=NULL;
configuredObject=NULL;
linking=false;
linkingTrigger=NULL;
currentId=0;
movingBlock=NULL;
moving=false;
movingSpeed=10;
tooltip=-1;
//Set the player and shadow to their starting position.
player.setPosition(player.fx,player.fy);
shadow.setPosition(shadow.fx,shadow.fy);
selection.clear();
clipboard.clear();
triggers.clear();
movingBlocks.clear();
}
void LevelEditor::loadLevelFromNode(TreeStorageNode* obj, const std::string& fileName){
//call the method of base class.
Game::loadLevelFromNode(obj,fileName);
//now do our own stuff.
string s=editorData["time"];
if(s.empty() || !(s[0]>='0' && s[0]<='9')){
levelTime=-1;
}else{
levelTime=atoi(s.c_str());
}
s=editorData["recordings"];
if(s.empty() || !(s[0]>='0' && s[0]<='9')){
levelRecordings=-1;
}else{
levelRecordings=atoi(s.c_str());
}
}
void LevelEditor::saveLevel(string fileName){
//Create the output stream and check if it starts.
std::ofstream save(fileName.c_str());
if(!save) return;
//The dimensions of the level.
int maxX=0;
int maxY=0;
//The storageNode to put the level data in before writing it away.
TreeStorageNode node;
char s[64];
//The name of the level.
if(!levelName.empty()){
node.attributes["name"].push_back(levelName);
//Update the level name in the levelpack.
levels->getLevel()->name=levelName;
}
//The leveltheme.
if(!levelTheme.empty())
node.attributes["theme"].push_back(levelTheme);
//target time and recordings.
{
char c[32];
if(levelTime>=0){
sprintf(c,"%d",levelTime);
node.attributes["time"].push_back(c);
}
if(levelRecordings>=0){
sprintf(c,"%d",levelRecordings);
node.attributes["recordings"].push_back(c);
}
}
//The width of the level.
maxX=LEVEL_WIDTH;
sprintf(s,"%d",maxX);
node.attributes["size"].push_back(s);
//The height of the level.
maxY=LEVEL_HEIGHT;
sprintf(s,"%d",maxY);
node.attributes["size"].push_back(s);
//Loop through the gameObjects and save them.
for(int o=0;o<(signed)levelObjects.size();o++){
int objectType=levelObjects[o]->type;
//Check if it's a legal gameObject type.
if(objectType>=0 && objectType<TYPE_MAX){
TreeStorageNode* obj1=new TreeStorageNode;
node.subNodes.push_back(obj1);
//It's a tile so name the node tile.
obj1->name="tile";
//Write away the type of the gameObject.
sprintf(s,"%d",objectType);
obj1->value.push_back(blockName[objectType]);
//Get the box for the location of the gameObject.
SDL_Rect box=levelObjects[o]->getBox(BoxType_Base);
//Put the location in the storageNode.
sprintf(s,"%d",box.x);
obj1->value.push_back(s);
sprintf(s,"%d",box.y);
obj1->value.push_back(s);
//Loop through the editor data and save it also.
vector<pair<string,string> > obj;
levelObjects[o]->getEditorData(obj);
for(unsigned int i=0;i<obj.size();i++){
if((!obj[i].first.empty()) && (!obj[i].second.empty())){
obj1->attributes[obj[i].first].push_back(obj[i].second);
}
}
}
}
//Create a POASerializer and write away the level node.
POASerializer objSerializer;
objSerializer.writeNode(&node,save,true,true);
}
///////////////EVENT///////////////////
void LevelEditor::handleEvents(){
//Check if we need to quit, if so we enter the exit state.
if(event.type==SDL_QUIT){
setNextState(STATE_EXIT);
}
//If playing/testing we should the game handle the events.
if(playMode){
Game::handleEvents();
//Also check if we should exit the playMode.
if(inputMgr.isKeyDownEvent(INPUTMGR_ESCAPE)){
//Reset the game and disable playMode.
Game::reset(true);
playMode=false;
camera.x=cameraSave.x;
camera.y=cameraSave.y;
//NOTE: To prevent the mouse to still "be pressed" we set it to false.
pressedLeftMouse=false;
}
}else{
//Also check if we should exit the editor.
if(inputMgr.isKeyDownEvent(INPUTMGR_ESCAPE)){
//Before we quit ask a make sure question.
if(msgBox(_("Are you sure you want to quit?"),MsgBoxYesNo,_("Quit prompt"))==MsgBoxYes){
//We exit the level editor.
if(GUIObjectRoot){
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
setNextState(STATE_LEVEL_EDIT_SELECT);
//Play the menu music again.
getMusicManager()->playMusic("menu");
}
}
//Also check if we should exit the editor.
if(inputMgr.isKeyDownEvent(INPUTMGR_SHIFT)){
pressedShift=true;
}
if(inputMgr.isKeyUpEvent(INPUTMGR_SHIFT)){
pressedShift=false;
}
//Check if delete is pressed.
if(event.type==SDL_KEYDOWN && event.key.keysym.sym==SDLK_DELETE){
if(!selection.empty()){
//Loop through the selected game objects.
while(!selection.empty()){
//Remove the objects in the selection.
removeObject(selection[0]);
}
//And clear the selection vector.
selection.clear();
dragCenter=NULL;
selectionDrag=false;
}
}
//Check for copy (Ctrl+c) or cut (Ctrl+x).
if(event.type==SDL_KEYDOWN && (event.key.keysym.sym==SDLK_c || event.key.keysym.sym==SDLK_x) && (event.key.keysym.mod & KMOD_CTRL)){
//Clear the current clipboard.
clipboard.clear();
//Check if the selection isn't empty.
if(!selection.empty()){
//Loop through the selection to find the left-top block.
int x=selection[0]->getBox().x;
int y=selection[0]->getBox().y;
for(unsigned int o=1; o<selection.size(); o++){
if(selection[o]->getBox().x<x || selection[o]->getBox().y<y){
x=selection[o]->getBox().x;
y=selection[o]->getBox().y;
}
}
//Loop through the selection for the actual copying.
for(unsigned int o=0; o<selection.size(); o++){
//Get the editor data of the object.
vector<pair<string,string> > obj;
selection[o]->getEditorData(obj);
//Loop through the editor data and convert it.
map<string,string> objMap;
for(unsigned int i=0;i<obj.size();i++){
objMap[obj[i].first]=obj[i].second;
}
//Add some entries to the map.
char s[64];
sprintf(s,"%d",selection[o]->getBox().x-x);
objMap["x"]=s;
sprintf(s,"%d",selection[o]->getBox().y-y);
objMap["y"]=s;
sprintf(s,"%d",selection[o]->type);
objMap["type"]=s;
//Overwrite the id to prevent triggers, portals, buttons, movingblocks, etc. from malfunctioning.
//We give an empty string as id, which is invalid and thus suitable.
objMap["id"]="";
//Do the same for destination if the type is portal.
if(selection[o]->type==TYPE_PORTAL){
objMap["destination"]="";
}
//And add the map to the clipboard vector.
clipboard.push_back(objMap);
if(event.key.keysym.sym==SDLK_x){
//Cutting means deleting the game object.
removeObject(selection[o]);
o--;
}
}
//Only clear the selection when Ctrl+x;
if(event.key.keysym.sym==SDLK_x){
selection.clear();
dragCenter=NULL;
selectionDrag=false;
}
}
}
//Check for paste (Ctrl+v).
if(event.type==SDL_KEYDOWN && event.key.keysym.sym==SDLK_v && (event.key.keysym.mod & KMOD_CTRL)){
//First make sure that the clipboard isn't empty.
if(!clipboard.empty()){
//Clear the current selection.
selection.clear();
//Get the current mouse location.
int x,y;
SDL_GetMouseState(&x,&y);
x+=camera.x;
y+=camera.y;
//Apply snap to grid.
if(!pressedShift){
snapToGrid(&x,&y);
}else{
x-=25;
y-=25;
}
//Integers containing the diff of the x that occurs when placing a block outside the level size on the top or left.
//We use it to compensate the corrupted x and y locations of the other clipboard blocks.
int diffX=0;
int diffY=0;
//Loop through the clipboard.
for(unsigned int o=0;o<clipboard.size();o++){
Block* block=new Block(0,0,atoi(clipboard[o]["type"].c_str()),this);
block->setPosition(atoi(clipboard[o]["x"].c_str())+x+diffX,atoi(clipboard[o]["y"].c_str())+y+diffY);
block->setEditorData(clipboard[o]);
if(block->getBox().x<0){
//A block on the left side of the level, meaning we need to shift everything.
//First calc the difference.
diffX+=(0-(block->getBox().x));
}
if(block->getBox().y<0){
//A block on the left side of the level, meaning we need to shift everything.
//First calc the difference.
diffY+=(0-(block->getBox().y));
}
//And add the object using the addObject method.
addObject(block);
//Also add the block to the selection.
selection.push_back(block);
}
}
}
//Check if the return button is pressed.
//If so run the configure tool.
if(event.type==SDL_KEYDOWN && event.key.keysym.sym==SDLK_RETURN){
//Get the current mouse location.
int x,y;
SDL_GetMouseState(&x,&y);
//Create the rectangle.
SDL_Rect mouse={x+camera.x,y+camera.y,0,0};
//Loop through the selected game objects.
for(unsigned int o=0; o<levelObjects.size(); o++){
//Check for collision.
if(checkCollision(mouse,levelObjects[o]->getBox())){
tool=CONFIGURE;
//Invoke the onEnterObject.
onEnterObject(levelObjects[o]);
//Break out of the for loop.
break;
}
}
}
//Check for the arrow keys, used for moving the camera when playMode=false.
cameraXvel=0;
cameraYvel=0;
if(inputMgr.isKeyDown(INPUTMGR_RIGHT)){
if(pressedShift){
cameraXvel+=10;
}else{
cameraXvel+=5;
}
}
if(inputMgr.isKeyDown(INPUTMGR_LEFT)){
if(pressedShift){
cameraXvel-=10;
}else{
cameraXvel-=5;
}
}
if(inputMgr.isKeyDown(INPUTMGR_UP)){
if(pressedShift){
cameraYvel-=10;
}else{
cameraYvel-=5;
}
}
if(inputMgr.isKeyDown(INPUTMGR_DOWN)){
if(pressedShift){
cameraYvel+=10;
}else{
cameraYvel+=5;
}
}
//Check if the left mouse button is pressed/holded.
if(event.type==SDL_MOUSEBUTTONDOWN && event.button.button==SDL_BUTTON_LEFT){
pressedLeftMouse=true;
}
if(event.type==SDL_MOUSEBUTTONUP && event.button.button==SDL_BUTTON_LEFT){
pressedLeftMouse=false;
//We also need to check if dragging is true.
if(dragging){
//Set dragging false and call the onDrop event.
dragging=false;
int x,y;
SDL_GetMouseState(&x,&y);
//We call the drop event.
onDrop(x+camera.x,y+camera.y);
}
}
//Check if the mouse is dragging.
if(pressedLeftMouse && event.type==SDL_MOUSEMOTION){
if(abs(event.motion.xrel)+abs(event.motion.yrel)>=2){
//Check if this is the start of the dragging.
if(!dragging){
//The mouse is moved enough so let's set dragging true.
dragging=true;
//Get the current mouse location.
int x,y;
SDL_GetMouseState(&x,&y);
//We call the dragStart event.
onDragStart(x+camera.x,y+camera.y);
}else{
//Dragging was already true meaning we call onDrag() instead of onDragStart().
onDrag(event.motion.xrel,event.motion.yrel);
}
}
}
//Get the current mouse location.
int x,y;
SDL_GetMouseState(&x,&y);
//Create the rectangle.
SDL_Rect mouse={x,y,0,0};
//Check if mouse is in the tool box
bool mouseInToolbox=(toolbox!=NULL && !playMode && tool==ADD && toolbox->visible
&& (toolbox->dragging || checkCollision(mouse,toolbox->getRect())));
//Check if we scroll up, meaning the currentType++;
if((event.type==SDL_MOUSEBUTTONDOWN && event.button.button==SDL_BUTTON_WHEELUP) || inputMgr.isKeyDownEvent(INPUTMGR_NEXT)){
//Only change the current type when using the add tool.
if(tool==ADD){
if(mouseInToolbox){
if((--toolbox->startRow)<0){
toolbox->startRow=toolbox->maxRow-1;
}
}else{
currentType++;
if(currentType>=EDITOR_ORDER_MAX){
currentType=0;
}
}
}
//When in configure mode.
if(tool==CONFIGURE){
movingSpeed++;
//The movingspeed is capped at 100.
if(movingSpeed>100){
movingSpeed=100;
}
}
}
//Check if we scroll down, meaning the currentType--;
if((event.type==SDL_MOUSEBUTTONDOWN && event.button.button==SDL_BUTTON_WHEELDOWN) || inputMgr.isKeyDownEvent(INPUTMGR_PREVIOUS)){
//Only change the current type when using the add tool.
if(tool==ADD){
if(mouseInToolbox){
if((++toolbox->startRow)>=toolbox->maxRow){
toolbox->startRow=0;
}
}else{
currentType--;
if(currentType<0){
currentType=EDITOR_ORDER_MAX-1;
}
}
}
//When in configure mode.
if(tool==CONFIGURE){
movingSpeed--;
if(movingSpeed<=0){
movingSpeed=1;
}
}
}
//Check if we should enter playMode.
if(event.type==SDL_KEYDOWN && event.key.keysym.sym==SDLK_p){
playMode=true;
cameraSave.x=camera.x;
cameraSave.y=camera.y;
}
//Check for tool shortcuts.
if(event.type==SDL_KEYDOWN && event.key.keysym.sym==SDLK_a){
tool=ADD;
}
if(event.type==SDL_KEYDOWN && event.key.keysym.sym==SDLK_s){
tool=SELECT;
}
if(event.type==SDL_KEYDOWN && event.key.keysym.sym==SDLK_d){
//We clear the selection since that can't be used in the deletion tool.
selection.clear();
tool=REMOVE;
}
if(event.type==SDL_KEYDOWN && event.key.keysym.sym==SDLK_w){
tool=CONFIGURE;
}
//Check for certain events.
//First make sure the mouse isn't above the toolbar.
if(checkCollision(mouse,toolbarRect)==false){
//Check if mouse is in the tool box
if(mouseInToolbox){
toolbox->handleEvents();
}else{
//We didn't hit the toolbar so convert the mouse location to ingame location.
mouse.x+=camera.x;
mouse.y+=camera.y;
//Boolean if there's a click event fired.
bool clickEvent=false;
//Check if a mouse button is pressed.
if(event.type==SDL_MOUSEBUTTONDOWN){
//Loop through the objects to check collision.
for(unsigned int o=0; o<levelObjects.size(); o++){
if(checkCollision(levelObjects[o]->getBox(),mouse)==true){
//We have collision meaning that the mouse is above an object.
std::vector<GameObject*>::iterator it;
it=find(selection.begin(),selection.end(),levelObjects[o]);
//Set event true since there's a click event.
clickEvent=true;
//Check if the clicked object is in the selection or not.
bool isSelected=(it!=selection.end());
if(event.button.button==SDL_BUTTON_LEFT){
onClickObject(levelObjects[o],isSelected);
}else if(event.button.button==SDL_BUTTON_RIGHT){
onRightClickObject(levelObjects[o],isSelected);
}
}
}
}
//If event is false then we clicked on void.
if(!clickEvent){
if(event.type==SDL_MOUSEBUTTONDOWN){
if(event.button.button==SDL_BUTTON_LEFT){
//Left mouse button on void.
onClickVoid(mouse.x,mouse.y);
}else if(event.button.button==SDL_BUTTON_RIGHT && tool==CONFIGURE){
//Stop linking.
linking=false;
linkingTrigger=NULL;
//Write the path to the moving block.
if(moving){
std::map<std::string,std::string> editorData;
char s[64], s0[64];
sprintf(s,"%d",int(movingBlocks[movingBlock].size()));
editorData["MovingPosCount"]=s;
//Loop through the positions.
for(unsigned int o=0;o<movingBlocks[movingBlock].size();o++){
sprintf(s0+1,"%d",o);
sprintf(s,"%d",movingBlocks[movingBlock][o].x);
s0[0]='x';
editorData[s0]=s;
sprintf(s,"%d",movingBlocks[movingBlock][o].y);
s0[0]='y';
editorData[s0]=s;
sprintf(s,"%d",movingBlocks[movingBlock][o].time);
s0[0]='t';
editorData[s0]=s;
}
movingBlock->setEditorData(editorData);
//Stop moving.
moving=false;
movingBlock=NULL;
}
}
}
}
}
}
//Check for backspace when moving to remove a movingposition.
if(moving && event.type==SDL_KEYDOWN && event.key.keysym.sym==SDLK_BACKSPACE){
if(movingBlocks[movingBlock].size()>0){
movingBlocks[movingBlock].pop_back();
}
}
//Check for the tab key, level settings.
if(inputMgr.isKeyDownEvent(INPUTMGR_TAB)){
//Show the levelSettings.
levelSettings();
}
//Check if we should a new level. (Ctrl+n)
if(event.type==SDL_KEYDOWN && event.key.keysym.sym==SDLK_n && (event.key.keysym.mod & KMOD_CTRL)){
reset();
loadLevel(getDataPath()+"misc/Empty.map");
}
//Check if we should save the level (Ctrl+s) or save levelpack (Ctrl+Shift+s).
if(event.type==SDL_KEYDOWN && event.key.keysym.sym==SDLK_s && (event.key.keysym.mod & KMOD_CTRL)){
saveLevel(levelFile);
//And give feedback to the user.
if(levelName.empty())
msgBox(tfm::format(_("Level \"%s\" saved"),fileNameFromPath(levelFile)),MsgBoxOKOnly,_("Saved"));
else
msgBox(tfm::format(_("Level \"%s\" saved"),levelName),MsgBoxOKOnly,_("Saved"));
}
}
}
void LevelEditor::levelSettings(){
//It isn't so open a popup asking for a name.
//First delete any existing gui.
if(GUIObjectRoot){
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
GUIObjectRoot=new GUIObject((SCREEN_WIDTH-600)/2,(SCREEN_HEIGHT-300)/2,600,300,GUIObjectFrame,_("Level settings"));
GUIObject* obj;
//NOTE: We reuse the objectProperty and secondProperty.
obj=new GUIObject(40,50,240,36,GUIObjectLabel,_("Name:"));
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(140,50,410,36,GUIObjectTextBox,levelName.c_str());
objectProperty=obj;
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(40,100,240,36,GUIObjectLabel,_("Theme:"));
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(140,100,410,36,GUIObjectTextBox,levelTheme.c_str());
secondObjectProperty=obj;
GUIObjectRoot->childControls.push_back(obj);
//target time and recordings.
{
char c[32];
if(levelTime>=0){
sprintf(c,"%-.2f",levelTime/40.0f);
}else{
c[0]='\0';
}
obj=new GUIObject(40,150,240,36,GUIObjectLabel,_("Target time (s):"));
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(290,150,260,36,GUIObjectTextBox,c);
levelTimeProperty=obj;
GUIObjectRoot->childControls.push_back(obj);
if(levelRecordings>=0){
sprintf(c,"%d",levelRecordings);
}else{
c[0]='\0';
}
obj=new GUIObject(40,200,240,36,GUIObjectLabel,_("Target recordings:"));
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(290,200,260,36,GUIObjectTextBox,c);
levelRecordingsProperty=obj;
GUIObjectRoot->childControls.push_back(obj);
}
//Ok and cancel buttons.
obj=new GUIObject(100,300-44,150,36,GUIObjectButton,_("OK"));
obj->name="lvlSettingsOK";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(350,300-44,150,36,GUIObjectButton,_("Cancel"));
obj->name="lvlSettingsCancel";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
//Now we keep rendering and updating the GUI.
SDL_FillRect(tempSurface,NULL,0);
SDL_SetAlpha(tempSurface,SDL_SRCALPHA,155);
SDL_BlitSurface(tempSurface,NULL,screen,NULL);
while(GUIObjectRoot){
while(SDL_PollEvent(&event))
GUIObjectHandleEvents(true);
if(GUIObjectRoot)
GUIObjectRoot->render();
flipScreen();
SDL_Delay(30);
}
}
void LevelEditor::postLoad(){
//We need to find the triggers.
for(unsigned int o=0;o<levelObjects.size();o++){
//Get the editor data.
vector<pair<string,string> > objMap;
levelObjects[o]->getEditorData(objMap);
//Check for the highest id.
for(unsigned int i=0;i<objMap.size();i++){
if(objMap[i].first=="id"){
unsigned int id=atoi(objMap[i].second.c_str());
if(id>=currentId){
currentId=id+1;
}
}
}
switch(levelObjects[o]->type){
case TYPE_BUTTON:
case TYPE_SWITCH:
{
//Add the object to the triggers vector.
vector<GameObject*> linked;
triggers[levelObjects[o]]=linked;
//Now loop through the levelObjects in search for objects with the same id.
for(unsigned int oo=0;oo<levelObjects.size();oo++){
//Check if it isn't the same object but has the same id.
if(o!=oo && (dynamic_cast<Block*>(levelObjects[o]))->id==(dynamic_cast<Block*>(levelObjects[oo]))->id){
//Add the object to the link vector of the trigger.
triggers[levelObjects[o]].push_back(levelObjects[oo]);
}
}
break;
}
case TYPE_PORTAL:
{
//Add the object to the triggers vector.
vector<GameObject*> linked;
triggers[levelObjects[o]]=linked;
//If the destination is empty we return.
if((dynamic_cast<Block*>(levelObjects[o]))->destination.empty()){
return;
}
//Now loop through the levelObjects in search for objects with the same id as destination.
for(unsigned int oo=0;oo<levelObjects.size();oo++){
//Check if it isn't the same object but has the same id.
if(o!=oo && (dynamic_cast<Block*>(levelObjects[o]))->destination==(dynamic_cast<Block*>(levelObjects[oo]))->id){
//Add the object to the link vector of the trigger.
triggers[levelObjects[o]].push_back(levelObjects[oo]);
}
}
break;
}
case TYPE_MOVING_BLOCK:
case TYPE_MOVING_SHADOW_BLOCK:
case TYPE_MOVING_SPIKES:
{
//Add the object to the movingBlocks vector.
vector<MovingPosition> positions;
movingBlocks[levelObjects[o]]=positions;
//Get the number of entries of the editor data.
int m=objMap.size();
//Check if the editor data isn't empty.
if(m>0){
//Integer containing the positions.
int pos=0;
int currentPos=0;
//Get the number of movingpositions.
pos=atoi(objMap[1].second.c_str());
while(currentPos<pos){
int x=atoi(objMap[currentPos*3+4].second.c_str());
int y=atoi(objMap[currentPos*3+5].second.c_str());
int t=atoi(objMap[currentPos*3+6].second.c_str());
//Create a new movingPosition.
MovingPosition position(x,y,t);
movingBlocks[levelObjects[o]].push_back(position);
//Increase currentPos by one.
currentPos++;
}
}
break;
}
default:
break;
}
}
}
void LevelEditor::snapToGrid(int* x,int* y){
//Check if the x location is negative.
if(*x<0){
*x=-((abs(*x-50)/50)*50);
}else{
*x=(*x/50)*50;
}
//Now the y location.
if(*y<0){
*y=-((abs(*y-50)/50)*50);
}else{
*y=(*y/50)*50;
}
}
void LevelEditor::onClickObject(GameObject* obj,bool selected){
switch(tool){
//NOTE: We put CONFIGURE above ADD and SELECT to use the same method of selection.
//Meaning there's no break at the end of CONFIGURE.
case CONFIGURE:
{
//Check if we are linking.
if(linking){
//Check if the obj is valid to link to.
switch(obj->type){
case TYPE_CONVEYOR_BELT:
case TYPE_SHADOW_CONVEYOR_BELT:
case TYPE_MOVING_BLOCK:
case TYPE_MOVING_SHADOW_BLOCK:
case TYPE_MOVING_SPIKES:
{
//It's only valid when not linking a portal.
if(linkingTrigger->type==TYPE_PORTAL){
//You can't link a portal to moving blocks, etc.
//Stop linking and return.
linkingTrigger=NULL;
linking=false;
return;
}
break;
}
case TYPE_PORTAL:
{
//Make sure that the linkingTrigger is also a portal.
if(linkingTrigger->type!=TYPE_PORTAL){
//The linkingTrigger isn't a portal so stop linking and return.
linkingTrigger=NULL;
linking=false;
return;
}
break;
}
default:
//It isn't valid so stop linking and return.
linkingTrigger=NULL;
linking=false;
return;
break;
}
//Check if the linkingTrigger can handle multiple or only one link.
switch(linkingTrigger->type){
case TYPE_PORTAL:
{
//Portals can only link to one so remove all existing links.
triggers[linkingTrigger].clear();
triggers[linkingTrigger].push_back(obj);
break;
}
default:
{
//The most can handle multiple links.
triggers[linkingTrigger].push_back(obj);
break;
}
}
//Check if it's a portal.
if(linkingTrigger->type==TYPE_PORTAL){
//Portals need to get the id of the other instead of give it's own id.
vector<pair<string,string> > objMap;
obj->getEditorData(objMap);
int m=objMap.size();
if(m>0){
std::map<std::string,std::string> editorData;
char s[64];
sprintf(s,"%d",atoi(objMap[0].second.c_str()));
editorData["destination"]=s;
linkingTrigger->setEditorData(editorData);
}
}else{
//Give the object the same id as the trigger.
vector<pair<string,string> > objMap;
linkingTrigger->getEditorData(objMap);
int m=objMap.size();
if(m>0){
std::map<std::string,std::string> editorData;
char s[64];
sprintf(s,"%d",atoi(objMap[0].second.c_str()));
editorData["id"]=s;
obj->setEditorData(editorData);
}
}
//We return to prevent configuring stuff like conveyor belts, etc...
linking=false;
linkingTrigger=NULL;
return;
}
//If we're moving add a movingposition.
if(moving){
//Get the current mouse location.
int x,y;
SDL_GetMouseState(&x,&y);
x+=camera.x;
y+=camera.y;
//Apply snap to grid.
if(!pressedShift){
snapToGrid(&x,&y);
}else{
x-=25;
y-=25;
}
x-=movingBlock->getBox().x;
y-=movingBlock->getBox().y;
//Calculate the length.
//First get the delta x and y.
int dx,dy;
if(movingBlocks[movingBlock].empty()){
dx=x;
dy=y;
}else{
dx=x-movingBlocks[movingBlock].back().x;
dy=y-movingBlocks[movingBlock].back().y;
}
double length=sqrt(double(dx*dx+dy*dy));
movingBlocks[movingBlock].push_back(MovingPosition(x,y,(int)(length*(10/(double)movingSpeed))));
}
}
case SELECT:
case ADD:
{
//Check if object is already selected.
if(!selected){
//First check if shift is pressed or not.
if(!pressedShift){
//Clear the selection.
selection.clear();
}
//Add the object to the selection.
selection.push_back(obj);
}
break;
}
case REMOVE:
{
//Remove the object.
removeObject(obj);
break;
}
default:
break;
}
}
void LevelEditor::onRightClickObject(GameObject* obj,bool selected){
switch(tool){
case CONFIGURE:
{
//Make sure we aren't doing anything special.
if(moving || linking)
break;
//Check if it's a trigger.
if(obj->type==TYPE_PORTAL || obj->type==TYPE_BUTTON || obj->type==TYPE_SWITCH){
//Set linking true.
linking=true;
linkingTrigger=obj;
}
//Check if it's a moving block.
if(obj->type==TYPE_MOVING_BLOCK || obj->type==TYPE_MOVING_SHADOW_BLOCK || obj->type==TYPE_MOVING_SPIKES){
//Set moving true.
moving=true;
movingBlock=obj;
}
break;
}
case SELECT:
case ADD:
{
//We deselect the object if it's selected.
if(selected){
std::vector<GameObject*>::iterator it;
it=find(selection.begin(),selection.end(),obj);
//Remove the object from selection.
if(it!=selection.end()){
selection.erase(it);
}
}else{
//It wasn't a selected object so switch to configure mode.
//Check if it's the right type of object.
if(obj->type==TYPE_MOVING_BLOCK || obj->type==TYPE_MOVING_SHADOW_BLOCK || obj->type==TYPE_MOVING_SPIKES ||
obj->type==TYPE_PORTAL || obj->type==TYPE_BUTTON || obj->type==TYPE_SWITCH){
tool=CONFIGURE;
onRightClickObject(obj,selected);
}
}
break;
}
default:
break;
}
}
void LevelEditor::onClickVoid(int x,int y){
switch(tool){
case SELECT:
{
//We need to clear the selection.
selection.clear();
break;
}
case ADD:
{
//We need to clear the selection.
selection.clear();
//Now place an object.
//Apply snap to grid.
if(!pressedShift){
snapToGrid(&x,&y);
}else{
x-=25;
y-=25;
}
addObject(new Block(x,y,editorTileOrder[currentType],this));
break;
}
case CONFIGURE:
{
//We need to clear the selection.
selection.clear();
//If we're linking we should stop, user abort.
if(linking){
linking=false;
linkingTrigger=NULL;
//And return.
return;
}
//If we're moving we should add a point.
if(moving){
//Apply snap to grid.
if(!pressedShift){
snapToGrid(&x,&y);
}else{
x-=25;
y-=25;
}
x-=movingBlock->getBox().x;
y-=movingBlock->getBox().y;
//Calculate the length.
//First get the delta x and y.
int dx,dy;
if(movingBlocks[movingBlock].empty()){
dx=x;
dy=y;
}else{
dx=x-movingBlocks[movingBlock].back().x;
dy=y-movingBlocks[movingBlock].back().y;
}
double length=sqrt(double(dx*dx+dy*dy));
movingBlocks[movingBlock].push_back(MovingPosition(x,y,(int)(length*(10/(double)movingSpeed))));
//And return.
return;
}
break;
}
default:
break;
}
}
void LevelEditor::onDragStart(int x,int y){
switch(tool){
case SELECT:
case ADD:
case CONFIGURE:
{
//We can drag the selection so check if the selection isn't empty.
if(!selection.empty()){
//The selection isn't empty so search the dragCenter.
//Create a mouse rectangle.
SDL_Rect mouse={x,y,0,0};
//Loop through the objects to check collision.
for(unsigned int o=0; o<selection.size(); o++){
if(checkCollision(selection[o]->getBox(),mouse)==true){
//We have collision so set the dragCenter.
dragCenter=selection[o];
selectionDrag=true;
}
}
}
break;
}
default:
break;
}
}
void LevelEditor::onDrag(int dx,int dy){
switch(tool){
case REMOVE:
{
//No matter what we delete the item the mouse is above.
//Get the current mouse location.
int x,y;
SDL_GetMouseState(&x,&y);
//Create the rectangle.
SDL_Rect mouse={x+camera.x,y+camera.y,0,0};
//Loop through the objects to check collision.
for(unsigned int o=0; o<levelObjects.size(); o++){
if(checkCollision(levelObjects[o]->getBox(),mouse)==true){
//Remove the object.
removeObject(levelObjects[o]);
}
}
break;
}
default:
break;
}
}
void LevelEditor::onDrop(int x,int y){
switch(tool){
case SELECT:
case ADD:
case CONFIGURE:
{
//Check if the drag center isn't null.
if(dragCenter==NULL) return;
//The location of the dragCenter.
SDL_Rect r=dragCenter->getBox();
//Apply snap to grid.
if(!pressedShift){
snapToGrid(&x,&y);
}else{
x-=25;
y-=25;
}
//Loop through the selection.
for(unsigned int o=0; o<selection.size(); o++){
SDL_Rect r1=selection[o]->getBox();
//We need to place the object at his drop place.
moveObject(selection[o],(r1.x-r.x)+x,(r1.y-r.y)+y);
}
//Make sure the dragCenter is null and set selectionDrag false.
dragCenter=NULL;
selectionDrag=false;
break;
}
default:
break;
}
}
void LevelEditor::onCameraMove(int dx,int dy){
switch(tool){
case REMOVE:
{
//Only delete when the left mouse button is pressed.
if(pressedLeftMouse){
//Get the current mouse location.
int x,y;
SDL_GetMouseState(&x,&y);
//Create the rectangle.
SDL_Rect mouse={x+camera.x,y+camera.y,0,0};
//Loop through the objects to check collision.
for(unsigned int o=0; o<levelObjects.size(); o++){
if(checkCollision(levelObjects[o]->getBox(),mouse)==true){
//Remove the object.
removeObject(levelObjects[o]);
}
}
}
break;
}
default:
break;
}
}
void LevelEditor::onEnterObject(GameObject* obj){
switch(tool){
case CONFIGURE:
{
//Check if the type is an moving block.
if(obj->type==TYPE_MOVING_BLOCK || obj->type==TYPE_MOVING_SHADOW_BLOCK || obj->type==TYPE_MOVING_SPIKES){
//Open a message popup.
//First delete any existing gui.
if(GUIObjectRoot){
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
//Get the properties.
vector<pair<string,string> > objMap;
obj->getEditorData(objMap);
int m=objMap.size();
if(m>0){
//Set the object we configure.
configuredObject=obj;
//Check if the moving block has a path..
string s1;
bool path=false;
if(!movingBlocks[obj].empty()){
s1=_("Defined");
path=true;
}else{
s1=_("None");
}
//Now create the GUI.
string s;
switch(obj->type){
case TYPE_MOVING_BLOCK:
s=_("Moving block");
break;
case TYPE_MOVING_SHADOW_BLOCK:
s=_("Moving shadow block");
break;
case TYPE_MOVING_SPIKES:
s=_("Moving spikes");
break;
}
GUIObjectRoot=new GUIObject((SCREEN_WIDTH-600)/2,(SCREEN_HEIGHT-200)/2,600,200,GUIObjectFrame,s.c_str());
GUIObject* obj;
obj=new GUIObject(70,50,280,36,GUIObjectCheckBox,_("Enabled"),(objMap[2].second!="1"));
obj->name="cfgMovingBlockEnabled";
obj->eventCallback=this;
objectProperty=obj;
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(70,80,280,36,GUIObjectCheckBox,_("Loop"),(objMap[3].second!="0"));
obj->name="cfgMovingBlockLoop";
obj->eventCallback=this;
secondObjectProperty=obj;
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(70,110,280,36,GUIObjectLabel,_("Path"));
GUIObjectRoot->childControls.push_back(obj);
- obj=new GUIObject(330,110,280,36,GUIObjectLabel,s1.c_str());
- GUIObjectRoot->childControls.push_back(obj);
+ GUIObject* label=new GUIObject(330,110,-1,36,GUIObjectLabel,s1.c_str());
+ GUIObjectRoot->childControls.push_back(label);
+ label->render(0,0,false);
if(path){
- obj=new GUIObject(400,110,36,36,GUIObjectButton,"x");
+ obj=new GUIObject(label->left+label->width,110,36,36,GUIObjectButton,"x");
obj->name="cfgMovingBlockClrPath";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
}else{
//NOTE: The '+' is translated 5 pixels down to align with the 'x'.
- obj=new GUIObject(400,115,36,36,GUIObjectButton,"+");
+ obj=new GUIObject(label->left+label->width,115,36,36,GUIObjectButton,"+");
obj->name="cfgMovingBlockMakePath";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
}
- obj=new GUIObject(100,200-44,150,36,GUIObjectButton,_("OK"));
+ obj=new GUIObject(GUIObjectRoot->width*0.3,200-44,-1,36,GUIObjectButton,_("OK"),0,true,true,GUIGravityCenter);
obj->name="cfgMovingBlockOK";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
- obj=new GUIObject(350,200-44,150,36,GUIObjectButton,_("Cancel"));
+ obj=new GUIObject(GUIObjectRoot->width*0.7,200-44,-1,36,GUIObjectButton,_("Cancel"),0,true,true,GUIGravityCenter);
obj->name="cfgCancel";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
//Dim the screen using the tempSurface.
SDL_FillRect(tempSurface,NULL,0);
SDL_SetAlpha(tempSurface,SDL_SRCALPHA,155);
SDL_BlitSurface(tempSurface,NULL,screen,NULL);
while(GUIObjectRoot){
while(SDL_PollEvent(&event)) GUIObjectHandleEvents(true);
if(GUIObjectRoot) GUIObjectRoot->render();
flipScreen();
SDL_Delay(30);
}
}
}
//Check which type of object it is.
if(obj->type==TYPE_NOTIFICATION_BLOCK){
//Open a message popup.
//First delete any existing gui.
if(GUIObjectRoot){
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
//Get the properties.
vector<pair<string,string> > objMap;
obj->getEditorData(objMap);
int m=objMap.size();
if(m>0){
//Set the object we configure.
configuredObject=obj;
//Now create the GUI.
GUIObjectRoot=new GUIObject((SCREEN_WIDTH-600)/2,(SCREEN_HEIGHT-250)/2,600,250,GUIObjectFrame,_("Notification block"));
GUIObject* obj;
obj=new GUIObject(40,50,240,36,GUIObjectLabel,_("Enter message here:"));
GUIObjectRoot->childControls.push_back(obj);
obj=new GUITextArea(50,90,500,100);
string tmp=objMap[1].second.c_str();
//Change \n with the characters '\n'.
while(tmp.find("\\n")!=string::npos){
tmp=tmp.replace(tmp.find("\\n"),2,"\n");
}
obj->caption=tmp.c_str();
//Set the textField.
objectProperty=obj;
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(100,250-44,150,36,GUIObjectButton,_("OK"));
obj->name="cfgNotificationBlockOK";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(350,250-44,150,36,GUIObjectButton,_("Cancel"));
obj->name="cfgCancel";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
//Dim the screen using the tempSurface.
SDL_FillRect(tempSurface,NULL,0);
SDL_SetAlpha(tempSurface,SDL_SRCALPHA,155);
SDL_BlitSurface(tempSurface,NULL,screen,NULL);
while(GUIObjectRoot){
while(SDL_PollEvent(&event)) GUIObjectHandleEvents(true);
if(GUIObjectRoot) GUIObjectRoot->render();
flipScreen();
SDL_Delay(30);
}
}
}
if(obj->type==TYPE_CONVEYOR_BELT || obj->type==TYPE_SHADOW_CONVEYOR_BELT){
//Open a message popup.
//First delete any existing gui.
if(GUIObjectRoot){
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
//Get the properties and check if
vector<pair<string,string> > objMap;
obj->getEditorData(objMap);
int m=objMap.size();
if(m>0){
//Set the object we configure.
configuredObject=obj;
//Now create the GUI.
string s;
if(obj->type==TYPE_CONVEYOR_BELT){
s=_("Shadow Conveyor belt");
}else{
s=_("Conveyor belt");
}
GUIObjectRoot=new GUIObject((SCREEN_WIDTH-600)/2,(SCREEN_HEIGHT-200)/2,600,200,GUIObjectFrame,s.c_str());
GUIObject* obj;
obj=new GUIObject(40,60,220,36,GUIObjectCheckBox,_("Enabled"),(objMap[1].second!="1"));
obj->name="cfgConveyorBlockEnabled";
obj->eventCallback=this;
objectProperty=obj;
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(40,100,240,36,GUIObjectLabel,_("Enter speed here:"));
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(240,100,320,36,GUIObjectTextBox,objMap[2].second.c_str());
//Set the textField.
secondObjectProperty=obj;
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(100,200-44,150,36,GUIObjectButton,_("OK"));
obj->name="cfgConveyorBlockOK";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(350,200-44,150,36,GUIObjectButton,_("Cancel"));
obj->name="cfgCancel";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
//Dim the screen using the tempSurface.
SDL_FillRect(tempSurface,NULL,0);
SDL_SetAlpha(tempSurface,SDL_SRCALPHA,155);
SDL_BlitSurface(tempSurface,NULL,screen,NULL);
while(GUIObjectRoot){
while(SDL_PollEvent(&event)) GUIObjectHandleEvents(true);
if(GUIObjectRoot) GUIObjectRoot->render();
flipScreen();
SDL_Delay(30);
}
}
}
if(obj->type==TYPE_PORTAL){
//Open a message popup.
//First delete any existing gui.
if(GUIObjectRoot){
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
//Get the properties and check if
vector<pair<string,string> > objMap;
obj->getEditorData(objMap);
int m=objMap.size();
if(m>0){
//Set the object we configure.
configuredObject=obj;
//Check how many targets there are for this object.
string s1;
bool target=false;
if(!triggers[obj].empty()){
s1=_("Defined");
target=true;
}else{
s1=_("None");
}
//Now create the GUI.
GUIObjectRoot=new GUIObject((SCREEN_WIDTH-600)/2,(SCREEN_HEIGHT-200)/2,600,200,GUIObjectFrame,_("Portal"));
GUIObject* obj;
obj=new GUIObject(70,60,310,36,GUIObjectCheckBox,_("Activate on touch"),(objMap[1].second=="1"));
obj->name="cfgPortalAutomatic";
obj->eventCallback=this;
objectProperty=obj;
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(70,100,240,36,GUIObjectLabel,_("Targets:"));
GUIObjectRoot->childControls.push_back(obj);
- obj=new GUIObject(360,100,100,36,GUIObjectLabel,s1.c_str());
- GUIObjectRoot->childControls.push_back(obj);
-
- //NOTE: The '+' is translated 5 pixels down to align with the 'x'.
- obj=new GUIObject(460,105,36,36,GUIObjectButton,"+");
- obj->name="cfgPortalLink";
- obj->eventCallback=this;
- GUIObjectRoot->childControls.push_back(obj);
+ GUIObject* label=new GUIObject(360,100,-1,36,GUIObjectLabel,s1.c_str());
+ GUIObjectRoot->childControls.push_back(label);
+ label->render(0,0,false);
//Check if there are targets defined.
if(target){
- obj=new GUIObject(500,100,36,36,GUIObjectButton,"x");
+ obj=new GUIObject(label->left+label->width,100,36,36,GUIObjectButton,"x");
obj->name="cfgPortalUnlink";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
+ }else{
+ //NOTE: The '+' is translated 5 pixels down to align with the 'x'.
+ obj=new GUIObject(label->left+label->width,105,36,36,GUIObjectButton,"+");
+ obj->name="cfgPortalLink";
+ obj->eventCallback=this;
+ GUIObjectRoot->childControls.push_back(obj);
}
obj=new GUIObject(100,200-44,150,36,GUIObjectButton,_("OK"));
obj->name="cfgPortalOK";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(350,200-44,150,36,GUIObjectButton,_("Cancel"));
obj->name="cfgCancel";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
//Dim the screen using the tempSurface.
SDL_FillRect(tempSurface,NULL,0);
SDL_SetAlpha(tempSurface,SDL_SRCALPHA,155);
SDL_BlitSurface(tempSurface,NULL,screen,NULL);
while(GUIObjectRoot){
while(SDL_PollEvent(&event))
GUIObjectHandleEvents(true);
if(GUIObjectRoot)
GUIObjectRoot->render();
flipScreen();
SDL_Delay(30);
}
}
}
if(obj->type==TYPE_BUTTON || obj->type==TYPE_SWITCH){
//Open a message popup.
//First delete any existing gui.
if(GUIObjectRoot){
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
//Get the properties and check if
vector<pair<string,string> > objMap;
obj->getEditorData(objMap);
int m=objMap.size();
if(m>0){
//Set the object we configure.
configuredObject=obj;
//Check how many targets there are for this object.
string s1;
bool targets=false;
if(!triggers[obj].empty()){
- s1=tfm::format("%d Defined",(int)triggers[obj].size());
+ s1=tfm::format(_("%d Defined"),(int)triggers[obj].size());
targets=true;
}else{
s1=_("None");
}
//Now create the GUI.
string s;
if(obj->type==TYPE_BUTTON){
s=_("Button");
}else{
s=_("Switch");
}
GUIObjectRoot=new GUIObject((SCREEN_WIDTH-600)/2,(SCREEN_HEIGHT-200)/2,600,200,GUIObjectFrame,s.c_str());
GUIObject* obj;
obj=new GUIObject(70,60,240,36,GUIObjectLabel,_("Behaviour:"));
GUIObjectRoot->childControls.push_back(obj);
obj=new GUISingleLineListBox(250,60,300,36);
obj->name="lstBehaviour";
vector<string> v;
v.push_back(_("On"));
v.push_back(_("Off"));
v.push_back(_("Toggle"));
(dynamic_cast<GUISingleLineListBox*>(obj))->item=v;
//Get the current behaviour.
if(objMap[1].second=="on"){
obj->value=0;
}else if(objMap[1].second=="off"){
obj->value=1;
}else{
//There's no need to check for the last one, since it's also the default.
obj->value=2;
}
objectProperty=obj;
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(70,100,240,36,GUIObjectLabel,_("Targets:"));
GUIObjectRoot->childControls.push_back(obj);
- obj=new GUIObject(250,100,100,36,GUIObjectLabel,s1.c_str());
- GUIObjectRoot->childControls.push_back(obj);
+ GUIObject* label=new GUIObject(250,100,-1,36,GUIObjectLabel,s1.c_str());
+ GUIObjectRoot->childControls.push_back(label);
+ label->render(0,0,false);
//NOTE: The '+' is translated 5 pixels down to align with the 'x'.
- obj=new GUIObject(350,105,36,36,GUIObjectButton,"+");
+ obj=new GUIObject(label->left+label->width,105,36,36,GUIObjectButton,"+");
obj->name="cfgTriggerLink";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
//Check if there are targets defined.
if(targets){
- obj=new GUIObject(390,100,36,36,GUIObjectButton,"x");
+ obj=new GUIObject(label->left+label->width+40,100,36,36,GUIObjectButton,"x");
obj->name="cfgTriggerUnlink";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
}
obj=new GUIObject(100,200-44,150,36,GUIObjectButton,_("OK"));
obj->name="cfgTriggerOK";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(350,200-44,150,36,GUIObjectButton,_("Cancel"));
obj->name="cfgCancel";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
//Dim the screen using the tempSurface.
SDL_FillRect(tempSurface,NULL,0);
SDL_SetAlpha(tempSurface,SDL_SRCALPHA,155);
SDL_BlitSurface(tempSurface,NULL,screen,NULL);
while(GUIObjectRoot){
while(SDL_PollEvent(&event))
GUIObjectHandleEvents(true);
if(GUIObjectRoot)
GUIObjectRoot->render();
flipScreen();
SDL_Delay(30);
}
}
}
if(obj->type==TYPE_FRAGILE){
//First delete any existing gui.
if(GUIObjectRoot){
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
//Get the properties and check if it contains the state data.
vector<pair<string,string> > objMap;
obj->getEditorData(objMap);
int m=objMap.size();
if(m>0){
//Set the object we configure.
configuredObject=obj;
//Create the GUI.
GUIObjectRoot=new GUIObject((SCREEN_WIDTH-600)/2,(SCREEN_HEIGHT-200)/2,600,200,GUIObjectFrame,_("Fragile"));
GUIObject* obj;
obj=new GUIObject(70,60,240,36,GUIObjectLabel,_("State:"));
GUIObjectRoot->childControls.push_back(obj);
obj=new GUISingleLineListBox(250,60,300,36);
obj->name="lstBehaviour";
vector<string> v;
v.push_back(_("Complete"));
v.push_back(_("One step"));
v.push_back(_("Two steps"));
v.push_back(_("Gone"));
(dynamic_cast<GUISingleLineListBox*>(obj))->item=v;
//Get the current state.
obj->value=atoi(objMap[1].second.c_str());
objectProperty=obj;
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(100,200-44,150,36,GUIObjectButton,_("OK"));
obj->name="cfgFragileOK";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(350,200-44,150,36,GUIObjectButton,_("Cancel"));
obj->name="cfgCancel";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
//Dim the screen using the tempSurface.
SDL_FillRect(tempSurface,NULL,0);
SDL_SetAlpha(tempSurface,SDL_SRCALPHA,155);
SDL_BlitSurface(tempSurface,NULL,screen,NULL);
while(GUIObjectRoot){
while(SDL_PollEvent(&event))
GUIObjectHandleEvents(true);
if(GUIObjectRoot)
GUIObjectRoot->render();
flipScreen();
SDL_Delay(30);
}
}
}
break;
}
default:
break;
}
}
void LevelEditor::addObject(GameObject* obj){
//Increase totalCollectables everytime we add a new collectable
if (obj->type==TYPE_COLLECTABLE) {
totalCollectables++;
}
//If it's a player or shadow start then we need to remove the previous one.
if(obj->type==TYPE_START_PLAYER || obj->type==TYPE_START_SHADOW){
//Loop through the levelObjects.
for(unsigned int o=0; o<levelObjects.size(); o++){
//Check if the type is the same.
if(levelObjects[o]->type==obj->type){
removeObject(levelObjects[o]);
}
}
}
//Add it to the levelObjects.
levelObjects.push_back(obj);
//Check if the object is inside the level dimensions, etc.
//Just call moveObject() to perform this.
moveObject(obj,obj->getBox().x,obj->getBox().y);
//GameObject type specific stuff.
switch(obj->type){
case TYPE_BUTTON:
case TYPE_SWITCH:
case TYPE_PORTAL:
{
//Add the object to the triggers.
vector<GameObject*> linked;
triggers[obj]=linked;
//Give it it's own id.
std::map<std::string,std::string> editorData;
char s[64];
sprintf(s,"%d",currentId);
currentId++;
editorData["id"]=s;
obj->setEditorData(editorData);
break;
}
case TYPE_MOVING_BLOCK:
case TYPE_MOVING_SHADOW_BLOCK:
case TYPE_MOVING_SPIKES:
{
//Add the object to the moving blocks.
vector<MovingPosition> positions;
movingBlocks[obj]=positions;
//Get the editor data.
vector<pair<string,string> > objMap;
obj->getEditorData(objMap);
//Get the number of entries of the editor data.
int m=objMap.size();
//Check if the editor data isn't empty.
if(m>0){
//Integer containing the positions.
int pos=0;
int currentPos=0;
//Get the number of movingpositions.
pos=atoi(objMap[1].second.c_str());
while(currentPos<pos){
int x=atoi(objMap[currentPos*3+4].second.c_str());
int y=atoi(objMap[currentPos*3+5].second.c_str());
int t=atoi(objMap[currentPos*3+6].second.c_str());
//Create a new movingPosition.
MovingPosition position(x,y,t);
movingBlocks[obj].push_back(position);
//Increase currentPos by one.
currentPos++;
}
}
//Give it it's own id.
std::map<std::string,std::string> editorData;
char s[64];
sprintf(s,"%d",currentId);
currentId++;
editorData["id"]=s;
obj->setEditorData(editorData);
break;
}
default:
break;
}
}
void LevelEditor::moveObject(GameObject* obj,int x,int y){
//Set the obj at it's new position.
obj->setPosition(x,y);
//Check if the object is inside the level dimensions.
//If not let the level grow.
if(obj->getBox().x+50>LEVEL_WIDTH){
LEVEL_WIDTH=obj->getBox().x+50;
}
if(obj->getBox().y+50>LEVEL_HEIGHT){
LEVEL_HEIGHT=obj->getBox().y+50;
}
if(obj->getBox().x<0 || obj->getBox().y<0){
//A block on the left (or top) side of the level, meaning we need to shift everything.
//First calc the difference.
int diffx=(0-(obj->getBox().x));
int diffy=(0-(obj->getBox().y));
if(diffx<0) diffx=0;
if(diffy<0) diffy=0;
//Change the level size first.
//The level grows with the difference, 0-(x+50).
LEVEL_WIDTH+=diffx;
LEVEL_HEIGHT+=diffy;
//cout<<"x:"<<diffx<<",y:"<<diffy<<endl; //debug
camera.x+=diffx;
camera.y+=diffy;
//Set the position of player and shadow
//(although it's unnecessary if there is player and shadow start)
player.setPosition(player.getBox().x+diffx,player.getBox().y+diffy);
shadow.setPosition(shadow.getBox().x+diffx,shadow.getBox().y+diffy);
for(unsigned int o=0; o<levelObjects.size(); o++){
//FIXME: shouldn't recuesive call me (to prevent stack overflow bugs)
moveObject(levelObjects[o],levelObjects[o]->getBox().x+diffx,levelObjects[o]->getBox().y+diffy);
}
}
//If the object is a player or shadow start then change the start position of the player or shadow.
if(obj->type==TYPE_START_PLAYER){
//Center the player horizontally.
player.fx=obj->getBox().x+(50-23)/2;
player.fy=obj->getBox().y;
//Now reset the player to get him to it's new start position.
player.reset(true);
}
if(obj->type==TYPE_START_SHADOW){
//Center the shadow horizontally.
shadow.fx=obj->getBox().x+(50-23)/2;
shadow.fy=obj->getBox().y;
//Now reset the shadow to get him to it's new start position.
shadow.reset(true);
}
}
void LevelEditor::removeObject(GameObject* obj){
std::vector<GameObject*>::iterator it;
std::map<GameObject*,vector<GameObject*> >::iterator mapIt;
//Increase totalCollectables everytime we add a new collectable
if (obj->type==TYPE_COLLECTABLE) {
totalCollectables--;
}
//Check if the object is in the selection.
it=find(selection.begin(),selection.end(),obj);
if(it!=selection.end()){
//It is so we delete it.
selection.erase(it);
}
//Check if the object is in the triggers.
mapIt=triggers.find(obj);
if(mapIt!=triggers.end()){
//It is so we remove it.
triggers.erase(mapIt);
}
//Boolean if it could be a target.
if(obj->type==TYPE_MOVING_BLOCK || obj->type==TYPE_MOVING_SHADOW_BLOCK || obj->type==TYPE_MOVING_SPIKES
|| obj->type==TYPE_CONVEYOR_BELT || obj->type==TYPE_SHADOW_CONVEYOR_BELT || obj->type==TYPE_PORTAL){
for(mapIt=triggers.begin();mapIt!=triggers.end();++mapIt){
//Now loop the target vector.
for(unsigned int o=0;o<(*mapIt).second.size();o++){
//Check if the obj is in the target vector.
if((*mapIt).second[o]==obj){
(*mapIt).second.erase(find((*mapIt).second.begin(),(*mapIt).second.end(),obj));
o--;
}
}
}
}
//Check if the object is in the movingObjects.
std::map<GameObject*,vector<MovingPosition> >::iterator movIt;
movIt=movingBlocks.find(obj);
if(movIt!=movingBlocks.end()){
//It is so we remove it.
movingBlocks.erase(movIt);
}
//Now we remove the object from the levelObjects.
it=find(levelObjects.begin(),levelObjects.end(),obj);
if(it!=levelObjects.end()){
levelObjects.erase(it);
}
delete obj;
obj=NULL;
}
void LevelEditor::GUIEventCallback_OnEvent(std::string name,GUIObject* obj,int eventType){
//Check for GUI events.
//Notification block configure events.
if(name=="cfgNotificationBlockOK"){
if(GUIObjectRoot){
//Set the message of the notification block.
std::map<std::string,std::string> editorData;
editorData["message"]=objectProperty->caption;
configuredObject->setEditorData(editorData);
//And delete the GUI.
objectProperty=NULL;
secondObjectProperty=NULL;
configuredObject=NULL;
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
}
//Conveyor belt block configure events.
if(name=="cfgConveyorBlockOK"){
if(GUIObjectRoot){
//Set the message of the notification block.
std::map<std::string,std::string> editorData;
editorData["speed"]=secondObjectProperty->caption;
editorData["disabled"]=(objectProperty->value==0)?"1":"0";
configuredObject->setEditorData(editorData);
//And delete the GUI.
objectProperty=NULL;
secondObjectProperty=NULL;
configuredObject=NULL;
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
}
//Moving block configure events.
if(name=="cfgMovingBlockOK"){
if(GUIObjectRoot){
//Set if the moving block is enabled/disabled.
std::map<std::string,std::string> editorData;
editorData["disabled"]=(objectProperty->value==0)?"1":"0";
editorData["loop"]=(secondObjectProperty->value==1)?"1":"0";
configuredObject->setEditorData(editorData);
//And delete the GUI.
objectProperty=NULL;
secondObjectProperty=NULL;
configuredObject=NULL;
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
}
if(name=="cfgMovingBlockClrPath"){
if(GUIObjectRoot){
//Set the message of the notification block.
std::map<std::string,std::string> editorData;
editorData["MovingPosCount"]="0";
configuredObject->setEditorData(editorData);
std::map<GameObject*,vector<MovingPosition> >::iterator it;
it=movingBlocks.find(configuredObject);
if(it!=movingBlocks.end()){
(*it).second.clear();
}
//And delete the GUI.
objectProperty=NULL;
secondObjectProperty=NULL;
configuredObject=NULL;
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
}
if(name=="cfgMovingBlockMakePath"){
if(GUIObjectRoot){
//Set moving.
moving=true;
movingBlock=configuredObject;
//And delete the GUI.
objectProperty=NULL;
secondObjectProperty=NULL;
configuredObject=NULL;
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
}
//Portal block configure events.
if(name=="cfgPortalOK"){
if(GUIObjectRoot){
//Set the message of the notification block.
std::map<std::string,std::string> editorData;
editorData["automatic"]=(objectProperty->value==1)?"1":"0";
configuredObject->setEditorData(editorData);
//And delete the GUI.
objectProperty=NULL;
secondObjectProperty=NULL;
configuredObject=NULL;
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
}
if(name=="cfgPortalLink"){
//We set linking true.
linking=true;
linkingTrigger=configuredObject;
//And delete the GUI.
objectProperty=NULL;
secondObjectProperty=NULL;
configuredObject=NULL;
if(GUIObjectRoot){
delete GUIObjectRoot;
}
GUIObjectRoot=NULL;
}
if(name=="cfgPortalUnlink"){
std::map<GameObject*,vector<GameObject*> >::iterator it;
it=triggers.find(configuredObject);
if(it!=triggers.end()){
//Remove the targets.
(*it).second.clear();
}
//We reset the destination.
std::map<std::string,std::string> editorData;
editorData["destination"]="";
configuredObject->setEditorData(editorData);
//And delete the GUI.
objectProperty=NULL;
secondObjectProperty=NULL;
configuredObject=NULL;
if(GUIObjectRoot){
delete GUIObjectRoot;
}
GUIObjectRoot=NULL;
}
//Trigger block configure events.
if(name=="cfgTriggerOK"){
if(GUIObjectRoot){
//Set the message of the notification block.
std::map<std::string,std::string> editorData;
editorData["behaviour"]=(dynamic_cast<GUISingleLineListBox*>(objectProperty))->item[objectProperty->value];
configuredObject->setEditorData(editorData);
//And delete the GUI.
objectProperty=NULL;
secondObjectProperty=NULL;
configuredObject=NULL;
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
}
if(name=="cfgTriggerLink"){
//We set linking true.
linking=true;
linkingTrigger=configuredObject;
//And delete the GUI.
objectProperty=NULL;
secondObjectProperty=NULL;
configuredObject=NULL;
if(GUIObjectRoot){
delete GUIObjectRoot;
}
GUIObjectRoot=NULL;
}
if(name=="cfgTriggerUnlink"){
std::map<GameObject*,vector<GameObject*> >::iterator it;
it=triggers.find(configuredObject);
if(it!=triggers.end()){
//Remove the targets.
(*it).second.clear();
}
//We give the trigger a new id to prevent activating unlinked targets.
std::map<std::string,std::string> editorData;
char s[64];
sprintf(s,"%d",currentId);
currentId++;
editorData["id"]=s;
configuredObject->setEditorData(editorData);
//And delete the GUI.
objectProperty=NULL;
secondObjectProperty=NULL;
configuredObject=NULL;
if(GUIObjectRoot){
delete GUIObjectRoot;
}
GUIObjectRoot=NULL;
}
//Fragile configuration.
if(name=="cfgFragileOK"){
std::map<std::string,std::string> editorData;
char s[64];
sprintf(s,"%d",objectProperty->value);
editorData["state"]=s;
configuredObject->setEditorData(editorData);
//And delete the GUI.
objectProperty=NULL;
secondObjectProperty=NULL;
configuredObject=NULL;
if(GUIObjectRoot){
delete GUIObjectRoot;
}
GUIObjectRoot=NULL;
}
//Cancel.
if(name=="cfgCancel"){
if(GUIObjectRoot){
//Delete the GUI.
objectProperty=NULL;
secondObjectProperty=NULL;
configuredObject=NULL;
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
}
//LevelSetting events.
if(name=="lvlSettingsOK"){
levelName=objectProperty->caption;
levelTheme=secondObjectProperty->caption;
//target time and recordings.
string s=levelTimeProperty->caption;
if(s.empty() || !(s[0]>='0' && s[0]<='9')){
levelTime=-1;
}else{
levelTime=int(atof(s.c_str())*40.0+0.5);
}
s=levelRecordingsProperty->caption;
if(s.empty() || !(s[0]>='0' && s[0]<='9')){
levelRecordings=-1;
}else{
levelRecordings=atoi(s.c_str());
}
//And delete the GUI.
if(GUIObjectRoot){
objectProperty=NULL;
secondObjectProperty=NULL;
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
}
if(name=="lvlSettingsCancel"){
if(GUIObjectRoot){
//Delete the GUI.
objectProperty=NULL;
secondObjectProperty=NULL;
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
}
}
////////////////LOGIC////////////////////
void LevelEditor::logic(){
if(playMode){
//PlayMode so let the game do it's logic.
Game::logic();
}else{
//Move the camera.
if(cameraXvel!=0 || cameraYvel!=0){
camera.x+=cameraXvel;
camera.y+=cameraYvel;
//Call the onCameraMove event.
onCameraMove(cameraXvel,cameraYvel);
}
//Move the camera with the mouse.
if(toolbox!=NULL)
setCamera(toolbarRect,toolbox->getRect());
else{
SDL_Rect r={0,0,0,0};
setCamera(toolbarRect,r);
}
//It isn't playMode so the mouse should be checked.
tooltip=-1;
//Get the mouse location.
int k,x,y;
k = SDL_GetMouseState(&x,&y);
SDL_Rect mouse={x,y,0,0};
//We loop through the number of tools + the number of buttons.
for(int t=0; t<NUMBER_TOOLS+6; t++){
SDL_Rect toolRect={(SCREEN_WIDTH-460)/2+(t*40)+((t+1)*10),SCREEN_HEIGHT-45,40,40};
//Check for collision.
if(checkCollision(mouse,toolRect)==true){
//Set the tooltip tool.
tooltip=t;
//Check if there's a mouse click.
if(k==SDL_BUTTON_LEFT){
if(t<NUMBER_TOOLS){
tool=(Tools)t;
//Check if we should show tool box
if(tool==ADD){
//show the tool box
if(toolbox==NULL){
toolbox=new LevelEditorToolbox(this);
}
if(!toolbox->visible){
toolbox->move(toolRect.x,toolRect.y-toolbox->height()-20);
toolbox->visible=true;
}
}
}else{
//The selected button isn't a tool.
//Now check which button it is.
if(t==NUMBER_TOOLS){
playMode=true;
cameraSave.x=camera.x;
cameraSave.y=camera.y;
if(tool==CONFIGURE){
//Also stop linking or moving.
if(linking){
linking=false;
linkingTrigger=NULL;
}
if(moving){
//Write the path to the moving block.
std::map<std::string,std::string> editorData;
char s[64], s0[64];
sprintf(s,"%d",int(movingBlocks[movingBlock].size()));
editorData["MovingPosCount"]=s;
//Loop through the positions.
for(unsigned int o=0;o<movingBlocks[movingBlock].size();o++){
sprintf(s0+1,"%d",o);
sprintf(s,"%d",movingBlocks[movingBlock][o].x);
s0[0]='x';
editorData[s0]=s;
sprintf(s,"%d",movingBlocks[movingBlock][o].y);
s0[0]='y';
editorData[s0]=s;
sprintf(s,"%d",movingBlocks[movingBlock][o].time);
s0[0]='t';
editorData[s0]=s;
}
movingBlock->setEditorData(editorData);
moving=false;
movingBlock=NULL;
}
}
}
if(t==NUMBER_TOOLS+2){
//Open up level settings dialog
levelSettings();
}
if(t==NUMBER_TOOLS+4){
//Go back to the level selection screen of Level Editor
setNextState(STATE_LEVEL_EDIT_SELECT);
//Change the music back to menu music.
getMusicManager()->playMusic("menu");
}
if(t==NUMBER_TOOLS+3){
//Save current level
saveLevel(levelFile);
//And give feedback to the user.
if(levelName.empty())
msgBox(tfm::format(_("Level \"%s\" saved"),fileNameFromPath(levelFile)),MsgBoxOKOnly,_("Saved"));
else
msgBox(tfm::format(_("Level \"%s\" saved"),levelName),MsgBoxOKOnly,_("Saved"));
}
}
}
}
}
}
}
/////////////////RENDER//////////////////////
void LevelEditor::render(){
//Always let the game render the game.
Game::render();
//Only render extra stuff like the toolbar, selection, etc.. when not in playMode.
if(!playMode){
//Render the selectionmarks.
//TODO: Check if block is in sight.
for(unsigned int o=0; o<selection.size(); o++){
//Get the location to draw.
SDL_Rect r=selection[o]->getBox();
r.x-=camera.x;
r.y-=camera.y;
//Draw the selectionMarks.
applySurface(r.x,r.y,selectionMark,screen,NULL);
applySurface(r.x+r.w-5,r.y,selectionMark,screen,NULL);
applySurface(r.x,r.y+r.h-5,selectionMark,screen,NULL);
applySurface(r.x+r.w-5,r.y+r.h-5,selectionMark,screen,NULL);
}
//Clear the placement surface.
SDL_FillRect(placement,NULL,0x00FF00FF);
//Draw the dark areas marking the outside of the level.
SDL_Rect r;
if(camera.x<0){
//Draw left side.
r.x=0;
r.y=0;
r.w=0-camera.x;
r.h=SCREEN_HEIGHT;
SDL_FillRect(placement,&r,0);
}
if(camera.x>LEVEL_WIDTH-SCREEN_WIDTH){
//Draw right side.
r.x=LEVEL_WIDTH-camera.x;
r.y=0;
r.w=SCREEN_WIDTH-(LEVEL_WIDTH-camera.x);
r.h=SCREEN_HEIGHT;
SDL_FillRect(placement,&r,0);
}
if(camera.y<0){
//Draw the top.
r.x=0;
r.y=0;
r.w=SCREEN_WIDTH;
r.h=0-camera.y;
SDL_FillRect(placement,&r,0);
}
if(camera.y>LEVEL_HEIGHT-SCREEN_HEIGHT){
//Draw the bottom.
r.x=0;
r.y=LEVEL_HEIGHT-camera.y;
r.w=SCREEN_WIDTH;
r.h=SCREEN_HEIGHT-(LEVEL_HEIGHT-camera.y);
SDL_FillRect(placement,&r,0);
}
//Check if we should draw on the placement surface.
if(selectionDrag){
showSelectionDrag();
}else{
if(tool==ADD){
showCurrentObject();
}
if(tool==CONFIGURE){
showConfigure();
}
}
//Draw the level borders.
drawRect(-camera.x,-camera.y,LEVEL_WIDTH,LEVEL_HEIGHT,screen);
//Render the placement surface.
applySurface(0,0,placement,screen,NULL);
//Render the hud layer.
renderHUD();
//Render tool box (if any)
if(toolbox!=NULL && !playMode && tool==ADD && toolbox->visible){
toolbox->render();
}
//On top of all render the toolbar.
applySurface((SCREEN_WIDTH-460)/2,SCREEN_HEIGHT-50,toolbar,screen,NULL);
//Now render a tooltip.
if(tooltip>=0){
//The back and foreground colors.
SDL_Color fg={0,0,0};
//Tool specific text.
SDL_Surface* tip=NULL;
switch(tooltip){
case 0:
tip=TTF_RenderUTF8_Blended(fontText,_("Select"),fg);
break;
case 1:
tip=TTF_RenderUTF8_Blended(fontText,_("Add"),fg);
break;
case 2:
tip=TTF_RenderUTF8_Blended(fontText,_("Delete"),fg);
break;
case 3:
tip=TTF_RenderUTF8_Blended(fontText,_("Configure"),fg);
break;
case 4:
tip=TTF_RenderUTF8_Blended(fontText,_("Play"),fg);
break;
case 6:
tip=TTF_RenderUTF8_Blended(fontText,_("Level settings"),fg);
break;
case 7:
tip=TTF_RenderUTF8_Blended(fontText,_("Save level"),fg);
break;
case 8:
tip=TTF_RenderUTF8_Blended(fontText,_("Back to menu"),fg);
break;
default:
break;
}
//Draw only if there's a tooltip available
if(tip!=NULL){
SDL_Rect r={(SCREEN_WIDTH-440)/2+(tooltip*40)+(tooltip*10),SCREEN_HEIGHT-45,40,40};
r.y=SCREEN_HEIGHT-50-tip->h;
if(r.x+tip->w>SCREEN_WIDTH-50)
r.x=SCREEN_WIDTH-50-tip->w;
//Draw borders around text
Uint32 color=0xFFFFFF00|230;
drawGUIBox(r.x-2,r.y-2,tip->w+4,tip->h+4,screen,color);
//Draw tooltip's text
SDL_BlitSurface(tip,NULL,screen,&r);
SDL_FreeSurface(tip);
}
}
//Draw a rectangle around the current tool.
Uint32 color=0xFFFFFF00;
drawGUIBox((SCREEN_WIDTH-440)/2+(tool*40)+(tool*10),SCREEN_HEIGHT-46,42,42,screen,color);
}
}
void LevelEditor::renderHUD(){
//Switch the tool.
switch(tool){
case CONFIGURE:
//If moving show the moving speed in the top right corner.
if(moving){
SDL_Rect r={SCREEN_WIDTH-180,0,180,30};
SDL_FillRect(screen,&r,0);
//Shrink the rectangle by one pixel and fill with white leaving an one pixel border.
r.x+=1;
r.w-=2;
r.h-=1;
SDL_FillRect(screen,&r,0xFFFFFF);
//Now render the text.
SDL_Color black={0,0,0,0};
SDL_Color white={255,255,255,255};
SDL_Surface* bm=TTF_RenderUTF8_Shaded(fontText,tfm::format(_("Movespeed: %s"),movingSpeed).c_str(),black,white);
r.x+=2;
r.y+=2;
//Draw the text and free the surface.
SDL_BlitSurface(bm,NULL,screen,&r);
SDL_FreeSurface(bm);
}
break;
default:
break;
}
}
void LevelEditor::showCurrentObject(){
//Get the current mouse location.
int x,y;
SDL_GetMouseState(&x,&y);
x+=camera.x;
y+=camera.y;
//Check if we should snap the block to grid or not.
if(!pressedShift){
snapToGrid(&x,&y);
}else{
x-=25;
y-=25;
}
//Check if the currentType is a legal type.
if(currentType>=0 && currentType<EDITOR_ORDER_MAX){
ThemeBlock* obj=objThemes.getBlock(editorTileOrder[currentType]);
if(obj){
obj->editorPicture.draw(placement,x-camera.x,y-camera.y);
}
}
}
void LevelEditor::showSelectionDrag(){
//Get the current mouse location.
int x,y;
SDL_GetMouseState(&x,&y);
//Create the rectangle.
x+=camera.x;
y+=camera.y;
//Check if we should snap the block to grid or not.
if(!pressedShift){
snapToGrid(&x,&y);
}else{
x-=25;
y-=25;
}
//Check if the drag center isn't null.
if(dragCenter==NULL) return;
//The location of the dragCenter.
SDL_Rect r=dragCenter->getBox();
//Loop through the selection.
//TODO: Check if block is in sight.
for(unsigned int o=0; o<selection.size(); o++){
ThemeBlock* obj=objThemes.getBlock(selection[o]->type);
if(obj){
SDL_Rect r1=selection[o]->getBox();
obj->editorPicture.draw(placement,(r1.x-r.x)+x-camera.x,(r1.y-r.y)+y-camera.y);
}
}
}
void LevelEditor::showConfigure(){
//arrow animation value. go through 0-65535 and loops.
static unsigned short arrowAnimation=0;
arrowAnimation++;
//Draw the trigger lines.
{
map<GameObject*,vector<GameObject*> >::iterator it;
for(it=triggers.begin();it!=triggers.end();it++){
//Check if the trigger has linked targets.
if(!(*it).second.empty()){
//The location of the trigger.
SDL_Rect r=(*it).first->getBox();
//Loop through the targets.
for(unsigned int o=0;o<(*it).second.size();o++){
//Get the location of the target.
SDL_Rect r1=(*it).second[o]->getBox();
//Draw the line from the center of the trigger to the center of the target.
drawLineWithArrow(r.x-camera.x+25,r.y-camera.y+25,r1.x-camera.x+25,r1.y-camera.y+25,placement,0,32,arrowAnimation%32);
//Also draw two selection marks.
applySurface(r.x-camera.x+25-2,r.y-camera.y+25-2,selectionMark,screen,NULL);
applySurface(r1.x-camera.x+25-2,r1.y-camera.y+25-2,selectionMark,screen,NULL);
}
}
}
//Draw a line to the mouse from the linkingTrigger when linking.
if(linking){
//Get the current mouse location.
int x,y;
SDL_GetMouseState(&x,&y);
//Draw the line from the center of the trigger to mouse.
drawLineWithArrow(linkingTrigger->getBox().x-camera.x+25,linkingTrigger->getBox().y-camera.y+25,x,y,placement,0,32,arrowAnimation%32);
}
}
//Draw the moving positions.
map<GameObject*,vector<MovingPosition> >::iterator it;
for(it=movingBlocks.begin();it!=movingBlocks.end();it++){
//Check if the block has positions.
if(!(*it).second.empty()){
//The location of the moving block.
SDL_Rect block=(*it).first->getBox();
block.x+=25-camera.x;
block.y+=25-camera.y;
//The location of the previous position.
//The first time it's the moving block's position self.
SDL_Rect r=block;
//Loop through the positions.
for(unsigned int o=0;o<(*it).second.size();o++){
//Draw the line from the center of the previous position to the center of the position.
//x and y are the coordinates for the current moving position.
int x=block.x+(*it).second[o].x;
int y=block.y+(*it).second[o].y;
//Check if we need to draw line
double dx=r.x-x;
double dy=r.y-y;
double d=sqrt(dx*dx+dy*dy);
if(d>0.001f){
if(it->second[o].time>0){
//Calculate offset to contain the moving speed.
int offset=int(d*arrowAnimation/it->second[o].time)%32;
drawLineWithArrow(r.x,r.y,x,y,placement,0,32,offset);
}else{
//time==0 ???? so don't draw arrow at all
drawLine(r.x,r.y,x,y,placement);
}
}
//And draw a marker at the end.
applySurface(x-13,y-13,movingMark,screen,NULL);
//Get the box of the previous position.
SDL_Rect tmp={x,y,0,0};
r=tmp;
}
}
}
//Draw a line to the mouse from the previous moving pos.
if(moving){
//Get the current mouse location.
int x,y;
SDL_GetMouseState(&x,&y);
//Check if we should snap the block to grid or not.
if(!pressedShift){
x+=camera.x;
y+=camera.y;
snapToGrid(&x,&y);
x-=camera.x;
y-=camera.y;
}else{
x-=25;
y-=25;
}
int posX,posY;
//Check if there are moving positions for the moving block.
if(!movingBlocks[movingBlock].empty()){
//Draw the line from the center of the previouse moving positions to mouse.
posX=movingBlocks[movingBlock].back().x;
posY=movingBlocks[movingBlock].back().y;
posX-=camera.x;
posY-=camera.y;
posX+=movingBlock->getBox().x;
posY+=movingBlock->getBox().y;
}else{
//Draw the line from the center of the movingblock to mouse.
posX=movingBlock->getBox().x-camera.x;
posY=movingBlock->getBox().y-camera.y;
}
//Calculate offset to contain the moving speed.
int offset=int(double(arrowAnimation)*movingSpeed/10.0)%32;
drawLineWithArrow(posX+25,posY+25,x+25,y+25,placement,0,32,offset);
applySurface(x+12,y+12,movingMark,screen,NULL);
}
}
//Filling the order array
const int LevelEditor::editorTileOrder[EDITOR_ORDER_MAX]={
TYPE_BLOCK,
TYPE_SHADOW_BLOCK,
TYPE_SPIKES,
TYPE_FRAGILE,
TYPE_MOVING_BLOCK,
TYPE_MOVING_SHADOW_BLOCK,
TYPE_MOVING_SPIKES,
TYPE_CONVEYOR_BELT,
TYPE_SHADOW_CONVEYOR_BELT,
TYPE_BUTTON,
TYPE_SWITCH,
TYPE_PORTAL,
TYPE_SWAP,
TYPE_CHECKPOINT,
TYPE_NOTIFICATION_BLOCK,
TYPE_START_PLAYER,
TYPE_START_SHADOW,
TYPE_EXIT,
TYPE_COLLECTABLE
};
diff --git a/src/TitleMenu.cpp b/src/TitleMenu.cpp
index 8d3f3f6..a17e4bb 100644
--- a/src/TitleMenu.cpp
+++ b/src/TitleMenu.cpp
@@ -1,636 +1,636 @@
/****************************************************************************
** Copyright (C) 2011 Luka Horvat <redreaper132 at gmail.com>
** Copyright (C) 2011 Edward Lii <edward_iii at myway.com>
** Copyright (C) 2011 O. Bahri Gordebak <gordebak at gmail.com>
**
**
** This file may be used under the terms of the GNU General Public
** License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "Functions.h"
#include "GameState.h"
#include "Globals.h"
#include "TitleMenu.h"
#include "GUIListBox.h"
#include "InputManager.h"
#include <iostream>
#include <algorithm>
#include <sstream>
#include "libs/tinygettext/tinygettext.hpp"
using namespace std;
/////////////////////////MAIN_MENU//////////////////////////////////
//Integer containing the highlighted/selected menu option.
static int highlight=0;
Menu::Menu(){
highlight=0;
animation=0;
//Load the title image.
title=loadImage(getDataPath()+"gfx/menu/title.png");
//Now render the five entries.
SDL_Color black={0,0,0};
entries[0]=TTF_RenderUTF8_Blended(fontTitle,_("Play"),black);
entries[1]=TTF_RenderUTF8_Blended(fontTitle,_("Options"),black);
entries[2]=TTF_RenderUTF8_Blended(fontTitle,_("Map Editor"),black);
entries[3]=TTF_RenderUTF8_Blended(fontTitle,_("Addons"),black);
- entries[4]=TTF_RenderUTF8_Blended(fontTitle,_("Exit"),black);
+ entries[4]=TTF_RenderUTF8_Blended(fontTitle,_("Quit"),black);
entries[5]=TTF_RenderUTF8_Blended(fontTitle,">",black);
entries[6]=TTF_RenderUTF8_Blended(fontTitle,"<",black);
}
Menu::~Menu(){
//We need to free the five text surfaceses.
for(unsigned int i=0;i<7;i++)
SDL_FreeSurface(entries[i]);
}
void Menu::handleEvents(){
//Get the x and y location of the mouse.
int x,y;
SDL_GetMouseState(&x,&y);
//Calculate which option is highlighted using the location of the mouse.
//Only if mouse is 'doing something'
if(event.type==SDL_MOUSEMOTION || event.type==SDL_MOUSEBUTTONDOWN){
if(x>=200&&x<SCREEN_WIDTH-200&&y>=(SCREEN_HEIGHT-200)/2&&y<(SCREEN_HEIGHT-200)/2+320){
highlight=(y-((SCREEN_HEIGHT-200)/2-64))/64;
}
}
//Down/Up -arrows move highlight
if(inputMgr.isKeyDownEvent(INPUTMGR_DOWN)){
highlight++;
if(highlight>=6)
highlight=5;
}
if(inputMgr.isKeyDownEvent(INPUTMGR_UP)){
highlight--;
if(highlight<1)
highlight=1;
}
//Check if there's a press event.
if((event.type==SDL_MOUSEBUTTONUP && event.button.button==SDL_BUTTON_LEFT) ||
(inputMgr.isKeyUpEvent(INPUTMGR_SELECT))){
//We have one so check which selected/highlighted option needs to be done.
switch(highlight){
case 1:
//Enter the levelSelect state.
setNextState(STATE_LEVEL_SELECT);
break;
case 2:
//Enter the options state.
setNextState(STATE_OPTIONS);
break;
case 3:
//Enter the levelEditor, but first set the level to a default leveledit map.
levelName="";
setNextState(STATE_LEVEL_EDIT_SELECT);
break;
case 4:
//Check if internet is enabled.
if(!getSettings()->getBoolValue("internet")){
msgBox(_("Enable internet in order to install addons."),MsgBoxOKOnly,_("Internet disabled"));
break;
}
//Enter the help state.
setNextState(STATE_ADDONS);
break;
case 5:
//We quit, so we enter the exit state.
setNextState(STATE_EXIT);
break;
}
}
//We also need to quit the menu when escape is pressed.
if(inputMgr.isKeyUpEvent(INPUTMGR_ESCAPE)){
setNextState(STATE_EXIT);
}
//Check if we need to quit, if so we enter the exit state.
if(event.type==SDL_QUIT){
setNextState(STATE_EXIT);
}
}
//Nothing to do here
void Menu::logic(){
animation++;
if(animation>10)
animation=-10;
}
void Menu::render(){
applySurface(0,0,menuBackground,screen,NULL);
//Draw the title.
applySurface((SCREEN_WIDTH-title->w)/2,40,title,screen,NULL);
//Draw the menu entries.
for(unsigned int i=0;i<5;i++){
applySurface((SCREEN_WIDTH-entries[i]->w)/2,(SCREEN_HEIGHT-200)/2+64*i+(64-entries[i]->h)/2,entries[i],screen,NULL);
}
//Check if an option is selected/highlighted.
if(highlight>0){
//Draw the '>' sign, which is entry 5.
int x=(SCREEN_WIDTH-entries[highlight-1]->w)/2-(25-abs(animation)/2)-entries[5]->w;
int y=(SCREEN_HEIGHT-200)/2-64+64*highlight+(64-entries[5]->h)/2;
applySurface(x,y,entries[5],screen,NULL);
//Draw the '<' sign, which is entry 6.
x=(SCREEN_WIDTH-entries[highlight-1]->w)/2+entries[highlight-1]->w+(25-abs(animation)/2);
y=(SCREEN_HEIGHT-200)/2-64+64*highlight+(64-entries[6]->h)/2;
applySurface(x,y,entries[6],screen,NULL);
}
}
void Menu::resize(){}
/////////////////////////OPTIONS_MENU//////////////////////////////////
//Some varables for the options.
static bool fullscreen,leveltheme,internet;
static string themeName,languageName;
static int lastLang,lastRes;
static bool useProxy;
static string internetProxy;
static bool restartFlag;
static _res currentRes;
static vector<_res> resolution_list;
Options::Options(){
//Render the title.
SDL_Color black={0,0,0};
title=TTF_RenderUTF8_Blended(fontTitle,_("Settings"),black);
//Load the jump sound, used for sound volume configuration.
jumpSound=Mix_LoadWAV((getDataPath()+"sfx/jump.wav").c_str());
lastJumpSound=0;
//Set some default settings.
fullscreen=getSettings()->getBoolValue("fullscreen");
languageName=getSettings()->getValue("lang");
themeName=processFileName(getSettings()->getValue("theme"));
leveltheme=getSettings()->getBoolValue("leveltheme");
internet=getSettings()->getBoolValue("internet");
internetProxy=getSettings()->getValue("internet-proxy");
useProxy=!internetProxy.empty();
//Set the restartFlag false.
restartFlag=false;
//Now create the gui.
createGUI();
}
Options::~Options(){
//Delete the GUI.
if(GUIObjectRoot){
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
//Free the title image.
SDL_FreeSurface(title);
//And free the jump sound.
Mix_FreeChunk(jumpSound);
}
void Options::createGUI(){
//Variables for positioning
int x = (SCREEN_WIDTH-540)/2;
int liftY=40; //TODO: This is variable for laziness of maths...
//Create the root element of the GUI.
if(GUIObjectRoot){
delete GUIObjectRoot;
GUIObjectRoot=NULL;
}
GUIObjectRoot=new GUIObject(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,GUIObjectNone);
//Now we create GUIObjects for every option.
GUIObject* obj=new GUIObject(x,150-liftY,240,36,GUIObjectLabel,_("Music"));
GUIObjectRoot->childControls.push_back(obj);
musicSlider=new GUISlider(x+220,150-liftY,256,36,atoi(getSettings()->getValue("music").c_str()),0,128,15);
musicSlider->name="sldMusic";
musicSlider->eventCallback=this;
GUIObjectRoot->childControls.push_back(musicSlider);
obj=new GUIObject(x,190-liftY,240,36,GUIObjectLabel,_("Sound"));
GUIObjectRoot->childControls.push_back(obj);
soundSlider=new GUISlider(x+220,190-liftY,256,36,atoi(getSettings()->getValue("sound").c_str()),0,128,15);
soundSlider->name="sldSound";
soundSlider->eventCallback=this;
GUIObjectRoot->childControls.push_back(soundSlider);
obj=new GUIObject(x,230-liftY,240,36,GUIObjectCheckBox,_("Fullscreen"),fullscreen?1:0);
obj->name="chkFullscreen";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(x,270-liftY,240,36,GUIObjectLabel,_("Resolution"));
obj->name="lstResolution";
GUIObjectRoot->childControls.push_back(obj);
//Create list with many different resolutions
resolutions = new GUISingleLineListBox(x+220,270-liftY,300,36);
resolutions->value=-1;
//Enumerate avaliable resolutions using SDL_ListModes()
//Note: we enumerate fullscreen resolutions because
// windowed resolutions always can be arbitrary
if(resolution_list.empty()){
SDL_Rect **modes=SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE);
if(modes==NULL || ((intptr_t)modes) == -1){
cout<<"Error: Can't enumerate avaliable screen resolutions."
" Use predefined screen resolutions list instead."<<endl;
static const _res predefined_resolution_list[] = {
{800,600},
{1024,600},
{1024,768},
{1152,864},
{1280,720},
{1280,768},
{1280,800},
{1280,960},
{1280,1024},
{1360,768},
{1366,768},
{1440,900},
{1600,900},
{1600,1200},
{1680,1080},
{1920,1080},
{1920,1200},
{2560,1440},
{3840,2160}
};
for(unsigned int i=0;i<sizeof(predefined_resolution_list)/sizeof(_res);i++){
resolution_list.push_back(predefined_resolution_list[i]);
}
}else{
for(unsigned int i=0;modes[i]!=NULL;i++){
//Check if the resolution is big enough
if(modes[i]->w>=800 && modes[i]->h>=600){
_res res={modes[i]->w, modes[i]->h};
resolution_list.push_back(res);
}
}
reverse(resolution_list.begin(),resolution_list.end());
}
}
//Get current resolution from config file. Thus it can be user defined
currentRes.w=atoi(getSettings()->getValue("width").c_str());
currentRes.h=atoi(getSettings()->getValue("height").c_str());
for (int i=0; i<(int)resolution_list.size();i++){
//Create a string from width and height and then add it to list
ostringstream out;
out << resolution_list[i].w << "x" << resolution_list[i].h;
resolutions->item.push_back(out.str());
//Check if current resolution matches, select it
if (resolution_list[i].w==currentRes.w && resolution_list[i].h==currentRes.h){
resolutions->value=i;
}
}
//Add current resolution if it isn't already in the list
if(resolutions->value==-1){
ostringstream out;
out << currentRes.w << "x" << currentRes.h;
resolutions->item.push_back(out.str());
resolutions->value=resolutions->item.size()-1;
}
lastRes=resolutions->value;
GUIObjectRoot->childControls.push_back(resolutions);
obj=new GUIObject(x,310-liftY,240,36,GUIObjectLabel,_("Language"));
obj->name="lstResolution";
GUIObjectRoot->childControls.push_back(obj);
//Create GUI list with available languages
langs = new GUISingleLineListBox(x+220,310-liftY,300,36);
langs->name="lstLanguages";
/// TRANSLATORS: as detect user's language automatically
langs->item.push_back(_("Auto-Detect"));
langValues.push_back("");
langs->item.push_back("English");
langValues.push_back("en");
//Get a list of every available language
set<tinygettext::Language> languages = dictionaryManager->get_languages();
for (set<tinygettext::Language>::iterator s0 = languages.begin(); s0 != languages.end(); ++s0){
//If language in loop is the same in config file, then select it
if (getSettings()->getValue("lang")==s0->str()){
lastLang=distance(languages.begin(),s0)+2;
}
//Add language in loop to list and listbox
langs->item.push_back(s0->get_name());
langValues.push_back(s0->str());
}
//If Auto or English are selected
if(getSettings()->getValue("lang")==""){
lastLang=0;
}else if(getSettings()->getValue("lang")=="en"){
lastLang=1;
}
langs->value=lastLang;
GUIObjectRoot->childControls.push_back(langs);
obj=new GUIObject(x,350-liftY,240,36,GUIObjectLabel,_("Theme"));
obj->name="theme";
GUIObjectRoot->childControls.push_back(obj);
//Create the theme option gui element.
theme=new GUISingleLineListBox(x+220,350-liftY,300,36);
theme->name="lstTheme";
vector<string> v=enumAllDirs(getUserPath(USER_DATA)+"themes/");
for(vector<string>::iterator i = v.begin(); i != v.end(); ++i){
themeLocations[*i]=getUserPath(USER_DATA)+"themes/"+*i;
}
vector<string> v2=enumAllDirs(getDataPath()+"themes/");
for(vector<string>::iterator i = v2.begin(); i != v2.end(); ++i){
themeLocations[*i]=getDataPath()+"themes/"+*i;
}
v.insert(v.end(), v2.begin(), v2.end());
//Try to find the configured theme so we can display it.
int value=-1;
for(vector<string>::iterator i = v.begin(); i != v.end(); ++i){
if(themeLocations[*i]==themeName) {
value=i-v.begin();
}
}
theme->item=v;
if(value==-1)
value=theme->item.size()-1;
theme->value=value;
//NOTE: We call the event handling method to correctly set the themename.
GUIEventCallback_OnEvent("lstTheme",theme,GUIEventChange);
theme->eventCallback=this;
GUIObjectRoot->childControls.push_back(theme);
obj=new GUIObject(x,390-liftY,240,36,GUIObjectCheckBox,_("Level themes"),leveltheme?1:0);
obj->name="chkLeveltheme";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(x,430-liftY,240,36,GUIObjectCheckBox,_("Internet"),internet?1:0);
obj->name="chkInternet";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
//new: proxy settings
obj=new GUIObject(x,470-liftY,240,36,GUIObjectLabel,_("Internet proxy"));
obj->name="chkProxy";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(x+220,470-liftY,300,36,GUIObjectTextBox,internetProxy.c_str());
obj->name="txtProxy";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
//new: key settings
obj=new GUIObject(SCREEN_WIDTH*0.3,SCREEN_HEIGHT-120,-1,36,GUIObjectButton,_("Config Keys"),0,true,true,GUIGravityCenter);
obj->name="cmdKeys";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
//Reset progress settings.
/// TRANSLATORS: Used for button which clear any level progress like unlocked levels and highscores.
obj=new GUIObject(SCREEN_WIDTH*0.7,SCREEN_HEIGHT-120,-1,36,GUIObjectButton,_("Clear Progress"),0,true,true,GUIGravityCenter);
obj->name="cmdReset";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(SCREEN_WIDTH*0.3,SCREEN_HEIGHT-60,-1,36,GUIObjectButton,_("Cancel"),0,true,true,GUIGravityCenter);
obj->name="cmdBack";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
obj=new GUIObject(SCREEN_WIDTH*0.7,SCREEN_HEIGHT-60,-1,36,GUIObjectButton,_("Save Changes"),0,true,true,GUIGravityCenter);
obj->name="cmdSave";
obj->eventCallback=this;
GUIObjectRoot->childControls.push_back(obj);
}
static string convertInt(int i){
stringstream ss;
ss << i;
return ss.str();
}
void Options::GUIEventCallback_OnEvent(std::string name,GUIObject* obj,int eventType){
//Check what type of event it was.
if(eventType==GUIEventClick){
if(name=="cmdBack"){
//TODO: Reset the key changes.
//Reset the music volume.
getMusicManager()->setVolume(atoi(getSettings()->getValue("music").c_str()));
Mix_Volume(-1,atoi(getSettings()->getValue("sound").c_str()));
//And goto the main menu.
setNextState(STATE_MENU);
}else if(name=="cmdSave"){
//Save is pressed thus save
char s[64];
sprintf(s,"%d",soundSlider->value);
getSettings()->setValue("sound",s);
sprintf(s,"%d",musicSlider->value);
getSettings()->setValue("music",s);
getMusicManager()->setEnabled(musicSlider->value>0);
Mix_Volume(-1,soundSlider->value);
getSettings()->setValue("fullscreen",fullscreen?"1":"0");
getSettings()->setValue("leveltheme",leveltheme?"1":"0");
getSettings()->setValue("internet",internet?"1":"0");
getSettings()->setValue("theme",themeName);
if(!useProxy)
internetProxy.clear();
getSettings()->setValue("internet-proxy",internetProxy);
getSettings()->setValue("lang",langValues.at(langs->value));
//Is resolution from the list or is it user defined in config file
if(resolutions->value<(int)resolution_list.size()){
getSettings()->setValue("width",convertInt(resolution_list[resolutions->value].w));
getSettings()->setValue("height",convertInt(resolution_list[resolutions->value].h));
}else{
getSettings()->setValue("width",convertInt(currentRes.w));
getSettings()->setValue("height",convertInt(currentRes.h));
}
//Save the key configuration.
inputMgr.saveConfig();
//Save the settings.
saveSettings();
//Before we return check if some .
if(restartFlag || resolutions->value!=lastRes){
//The resolution changed so we need to recreate the screen.
if(!createScreen()){
//Screen creation failed so set to safe settings.
getSettings()->setValue("fullscreen","0");
getSettings()->setValue("width",convertInt(resolution_list[lastRes].w));
getSettings()->setValue("height",convertInt(resolution_list[lastRes].h));
if(!createScreen()){
//Everything fails so quit.
setNextState(STATE_EXIT);
return;
}
}
//The screen is created, now load the (menu) theme.
if(!loadTheme()){
//Loading the theme failed so quit.
setNextState(STATE_EXIT);
return;
}
}
if(langs->value!=lastLang){
//We set the language.
language=langValues.at(langs->value);
dictionaryManager->set_language(tinygettext::Language::from_name(langValues.at(langs->value)));
//And reload the fonts (in some cases not needed).
if(!loadFonts()){
//Loading failed so quit.
setNextState(STATE_EXIT);
return;
}
}
//Now return to the main menu.
setNextState(STATE_MENU);
}else if(name=="cmdKeys"){
inputMgr.showConfig();
}else if(name=="cmdReset"){
if(msgBox(_("Do you really want to reset level progress?"),MsgBoxYesNo,_("Warning"))==MsgBoxYes){
//We delete the progress folder.
#ifdef WIN32
removeDirectory((getUserPath()+"progress").c_str());
createDirectory((getUserPath()+"progress").c_str());
#else
removeDirectory((getUserPath(USER_DATA)+"/progress").c_str());
createDirectory((getUserPath(USER_DATA)+"/progress").c_str());
#endif
}
return;
}else if(name=="chkFullscreen"){
fullscreen=obj->value?true:false;
//Check if fullscreen changed.
if(fullscreen==getSettings()->getBoolValue("fullscreen")){
//We disable the restart message flag.
restartFlag=false;
}else{
//We set the restart message flag.
restartFlag=true;
}
}else if(name=="chkLeveltheme"){
leveltheme=obj->value?true:false;
}else if(name=="chkInternet"){
internet=obj->value?true:false;
}else if(name=="chkProxy"){
useProxy=obj->value?true:false;
}
}
if(name=="lstTheme"){
if(theme!=NULL && theme->value>=0 && theme->value<(int)theme->item.size()){
//Check if the theme is installed in the data path.
if(themeLocations[theme->item[theme->value]].find(getDataPath())!=string::npos){
themeName="%DATA%/themes/"+fileNameFromPath(themeLocations[theme->item[theme->value]]);
}else if(themeLocations[theme->item[theme->value]].find(getUserPath(USER_DATA))!=string::npos){
themeName="%USER%/themes/"+fileNameFromPath(themeLocations[theme->item[theme->value]]);
}else{
themeName=themeLocations[theme->item[theme->value]];
}
}
}else if(name=="txtProxy"){
internetProxy=obj->caption;
//Check if the internetProxy field is empty.
useProxy=!internetProxy.empty();
}else if(name=="sldMusic"){
getMusicManager()->setEnabled(musicSlider->value>0);
getMusicManager()->setVolume(musicSlider->value);
}else if(name=="sldSound"){
Mix_Volume(-1,soundSlider->value);
if(lastJumpSound==0){
Mix_PlayChannel(-1,jumpSound,0);
lastJumpSound=15;
}
}
}
void Options::handleEvents(){
//Check if we need to quit, if so enter the exit state.
if(event.type==SDL_QUIT){
setNextState(STATE_EXIT);
}
//Check if the escape button is pressed, if so go back to the main menu.
if(inputMgr.isKeyUpEvent(INPUTMGR_ESCAPE)){
setNextState(STATE_MENU);
}
}
void Options::logic(){
//Increase the lastJumpSound variable if needed.
if(lastJumpSound!=0){
lastJumpSound--;
}
}
void Options::render(){
//Render the menu background image.
applySurface(0,0,menuBackground,screen,NULL);
//Now render the title.
applySurface((SCREEN_WIDTH-title->w)/2,40,title,screen,NULL);
//NOTE: The rendering of the GUI is done in Main.
}
void Options::resize(){
//Recreate the gui to fit the new resolution.
createGUI();
}
diff --git a/src/media/playbutton.xcf b/src/media/playbutton.xcf
deleted file mode 100644
index dc9f37e..0000000
Binary files a/src/media/playbutton.xcf and /dev/null differ
diff --git a/tools/messages.pot.sh b/tools/messages.pot.sh
new file mode 100644
index 0000000..f87947a
--- /dev/null
+++ b/tools/messages.pot.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+#automatically get all string from source code
+xgettext -o ../data/locale/messages.pot -c" /" -k_ -k__ --package-name=meandmyshadow --package-version=0.4 ../src/*.cpp
+
+#little hack to get tranlator comments work
+sed -i 's/#. \/ /# /g' ../data/locale/messages.pot

File Metadata

Mime Type
text/x-diff
Expires
Wed, Jun 17, 9:10 PM (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
70296
Default Alt Text
(400 KB)

Event Timeline