From fa035c2fd70945a0b12143ce9b81284d8d24d13b Mon Sep 17 00:00:00 2001 From: Björn Steinbrink Date: Wed, 1 Nov 2006 15:12:22 +0000 Subject: Added CMake support --- data/graphics/gui/CMakeLists.txt | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 data/graphics/gui/CMakeLists.txt (limited to 'data/graphics/gui/CMakeLists.txt') diff --git a/data/graphics/gui/CMakeLists.txt b/data/graphics/gui/CMakeLists.txt new file mode 100644 index 00000000..87585226 --- /dev/null +++ b/data/graphics/gui/CMakeLists.txt @@ -0,0 +1,45 @@ +SET (FILES + attack_target.png + bg_quad_dis.png + browserfont.png + button_disabled.png + buttonhi.png + button.png + buttonpress.png + checkbox.png + deepbox.png + fixedfont.png + hits_blue.png + hits_red.png + hits_yellow.png + hscroll_left_default.png + hscroll_left_highlight.png + hscroll_left_pressed.png + hscroll_right_default.png + hscroll_right_highlight.png + hscroll_right_pressed.png + menuitemD.png + menuitemF.png + menuitemN.png + menuitemP.png + mouse.png + radioin.png + radioout.png + resize.png + rpgfont_wider.png + sansserif8.png + selection.png + slider.png + thickborder.png + vscroll_blue.png + vscroll_down_default.png + vscroll_down_highlight.png + vscroll_down_pressed.png + vscroll_grey.png + vscroll_red.png + vscroll_up_default.png + vscroll_up_highlight.png + vscroll_up_pressed.png + ) + +INSTALL(FILES ${FILES} DESTINATION ${DATA_DIR}/graphics/gui) -- cgit v1.2.3-70-g09d2 From 5614b5c18c2c4d3540d776293c3d50b6ea2fe333 Mon Sep 17 00:00:00 2001 From: Björn Steinbrink Date: Fri, 13 Apr 2007 15:31:26 +0000 Subject: Added target cursor graphics to the set of files to be installed. --- ChangeLog | 5 +++++ data/graphics/gui/CMakeLists.txt | 2 ++ 2 files changed, 7 insertions(+) (limited to 'data/graphics/gui/CMakeLists.txt') diff --git a/ChangeLog b/ChangeLog index d2add310..f833350d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-04-13 Björn Steinbrink + + * data/graphics/gui/CMakeLists.txt: Added target cursor graphics to + the set of files to be installed. + 2007-03-24 Bjørn Lindeijer * src/main.cpp: Changed the order of network message handling and diff --git a/data/graphics/gui/CMakeLists.txt b/data/graphics/gui/CMakeLists.txt index 87585226..1549b2b4 100644 --- a/data/graphics/gui/CMakeLists.txt +++ b/data/graphics/gui/CMakeLists.txt @@ -30,6 +30,8 @@ SET (FILES sansserif8.png selection.png slider.png + target-cursor-blue.png + target-cursor-red.png thickborder.png vscroll_blue.png vscroll_down_default.png -- cgit v1.2.3-70-g09d2 From a353543dd4da3c489a84f6f17125fdd0e1be2349 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Mon, 4 Jun 2007 21:48:47 +0000 Subject: Merged 0.0 changes from revision 3234 to 3317 to trunk. --- ChangeLog | 465 ++++++++++++++++++++++++++++- NEWS | 16 + README | 3 +- data/graphics/gui/CMakeLists.txt | 8 +- data/graphics/gui/Makefile.am | 6 + data/graphics/gui/target-cursor-blue-l.png | Bin 0 -> 23803 bytes data/graphics/gui/target-cursor-blue-m.png | Bin 0 -> 18439 bytes data/graphics/gui/target-cursor-blue-s.png | Bin 0 -> 8353 bytes data/graphics/gui/target-cursor-blue.png | Bin 8353 -> 0 bytes data/graphics/gui/target-cursor-red-l.png | Bin 0 -> 25586 bytes data/graphics/gui/target-cursor-red-m.png | Bin 0 -> 17950 bytes data/graphics/gui/target-cursor-red-s.png | Bin 0 -> 8361 bytes data/graphics/gui/target-cursor-red.png | Bin 8361 -> 0 bytes data/help/changes.txt | 147 ++++----- data/help/header.txt | 2 +- docs/Makefile.am | 3 +- src/CMakeLists.txt | 14 + src/Makefile.am | 16 +- src/animatedsprite.cpp | 24 ++ src/animatedsprite.h | 12 + src/animationparticle.cpp | 51 ++++ src/animationparticle.h | 49 +++ src/being.cpp | 122 +++++--- src/being.h | 36 ++- src/engine.cpp | 7 + src/game.cpp | 24 +- src/graphics.cpp | 2 - src/gui/buy.cpp | 117 +++----- src/gui/buy.h | 6 + src/gui/chat.cpp | 4 +- src/gui/chat.h | 4 +- src/gui/debugwindow.cpp | 10 + src/gui/debugwindow.h | 1 + src/gui/inventorywindow.cpp | 7 +- src/gui/sell.cpp | 159 +++++----- src/gui/sell.h | 6 + src/gui/updatewindow.cpp | 7 +- src/gui/viewport.cpp | 108 ++++--- src/gui/viewport.h | 20 +- src/gui/widgets/resizegrip.cpp | 65 ++++ src/gui/widgets/resizegrip.h | 61 ++++ src/gui/window.cpp | 185 ++++++++---- src/gui/window.h | 66 ++-- src/imageparticle.cpp | 69 +++++ src/imageparticle.h | 61 ++++ src/main.cpp | 26 +- src/map.cpp | 23 ++ src/map.h | 25 +- src/monster.cpp | 6 + src/monster.h | 3 + src/net/beinghandler.cpp | 17 +- src/openglgraphics.cpp | 24 +- src/particle.cpp | 370 +++++++++++++++++++++++ src/particle.h | 288 ++++++++++++++++++ src/particleemitter.cpp | 327 ++++++++++++++++++++ src/particleemitter.h | 120 ++++++++ src/resources/animation.h | 2 +- src/resources/image.cpp | 25 +- src/resources/mapreader.cpp | 24 ++ src/resources/monsterdb.cpp | 21 ++ src/resources/monsterinfo.h | 14 +- src/simpleanimation.cpp | 85 ++++++ src/simpleanimation.h | 15 +- src/sprite.h | 16 + src/textparticle.cpp | 64 ++++ src/textparticle.h | 53 ++++ src/utils/fastsqrt.h | 24 ++ src/utils/minmax.h | 47 +++ src/utils/wingettimeofday.h | 226 +++++++------- src/utils/xml.cpp | 23 ++ src/utils/xml.h | 11 + 71 files changed, 3240 insertions(+), 602 deletions(-) create mode 100644 data/graphics/gui/target-cursor-blue-l.png create mode 100644 data/graphics/gui/target-cursor-blue-m.png create mode 100644 data/graphics/gui/target-cursor-blue-s.png delete mode 100644 data/graphics/gui/target-cursor-blue.png create mode 100644 data/graphics/gui/target-cursor-red-l.png create mode 100644 data/graphics/gui/target-cursor-red-m.png create mode 100644 data/graphics/gui/target-cursor-red-s.png delete mode 100644 data/graphics/gui/target-cursor-red.png create mode 100644 src/animationparticle.cpp create mode 100644 src/animationparticle.h create mode 100644 src/gui/widgets/resizegrip.cpp create mode 100644 src/gui/widgets/resizegrip.h create mode 100644 src/imageparticle.cpp create mode 100644 src/imageparticle.h create mode 100644 src/particle.cpp create mode 100644 src/particle.h create mode 100644 src/particleemitter.cpp create mode 100644 src/particleemitter.h create mode 100644 src/textparticle.cpp create mode 100644 src/textparticle.h create mode 100644 src/utils/fastsqrt.h create mode 100644 src/utils/minmax.h (limited to 'data/graphics/gui/CMakeLists.txt') diff --git a/ChangeLog b/ChangeLog index 61aef963..63aaa1eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,162 @@ +2007-06-03 David Athay + + * src/main.cpp, src/game.cpp: Fixed screenshot taking on OSX. + +2007-06-03 Bjørn Lindeijer + + * src/CMakeLists.txt, src/Makefile.am, docs/Makefile.am: Added some + files to be included with the release. + * src/utils/fastsqrt.h: Fixed warning about strict-aliasing rules. + * src/Makefile.am: Don't die on warnings by default. + * src/resources/image.cpp: Fixed image loading in software mode to not + check for alpha layer when images aren't 32-bit. + * src/graphics.cpp, src/graphics.h, src/imageparticle.cpp: Removed + drawImageTransparent from Graphics class, should be set on image. + * src/imageparticle.h, src/particleemitter.h, src/particle.h, + src/particleemitter.cpp, src/particle.cpp, src/imageparticle.cpp: Have + ParticleEmitter load a possible particle image early on and don't + cause a crash when the image can't be found. + +2007-06-02 Bjørn Lindeijer + + * src/winver.h, README, NEWS, CMakeLists.txt, configure.ac, + data/help/changes.txt, data/help/header.txt: Updated version and + release date and summarized changes. + * src/gui/chat.h, src/gui/chat.cpp: Changed color of chat messages in + OpenGL mode from orange to black. + * src/gui/sell.cpp, src/gui/buy.h, src/gui/buy.cpp, src/gui/sell.h: + Some cleanup of buy/sell dialog code. + +2007-06-01 Bjørn Lindeijer + + * data/graphics/gui/CMakeLists.txt, data/graphics/gui/Makefile.am: + Added target cursors to installed files. + +2007-05-31 Philipp Sehmisch + + * data/maps/new_16-1.tmx.gz: Fixed an inconsistency with the neighbor + map (no new walkmap required). + +2007-05-23 Bjørn Lindeijer + + * src/gui/sell.cpp, src/gui/buy.cpp, src/being.cpp: A bunch of + lingering syntactical changes. + * src/gui/viewport.cpp: Added a missing include and fixed a bug with + cleaning up target cursor animations. + +2007-05-23 Philipp Sehmisch + + * src/gui/viewport.cpp, + data/graphics/gui/target-cursor-blue-s.png, + data/graphics/gui/target-cursor-blue-m.png, + data/graphics/gui/target-cursor-blue-l.png, + data/graphics/gui/target-cursor-red-s.png, + data/graphics/gui/target-cursor-red-m.png, + data/graphics/gui/target-cursor-red-l.png: Replaced target cursor + graphics with higher quality ones by Pauan. + * src/particle.cpp: Made bouncing particles immune against death by + ground contact and removed a nonsensical debugging log message. Made + text splash effects fade out. + * src/textparticle.cpp: Implemented fading in and out for text + particles. + * src/being.cpp, src/particle.cpp, src/particle.h, + src/textparticle.cpp, src/textparticle.h: The color values of text + particles are now stored in 3 integers instead of a Guichan color + structure. + +2007-05-20 Eugenio Favalli + + * tmw.cbp: Updated Code::Blocks project file. + +2007-05-20 Philipp Sehmisch + + * src/gui/buy.cpp, src/gui/sell.cpp: Unified some differences between + buy and sell dialog. Money label now shows money after transaction + instead of current money. + * src/gui/sell.cpp: Fixed the amount-not-reset-when-using-scrollwheel + bug. + * src/being.h, src/gui/viewport.cpp, src/gui/viewport.h: Added 3 + different target cursor sizes. + * src/monster.h, src/monster.cpp, src/resources/monsterdb.cpp, + scr/resources/monsterinfo.h, data/monsters.xml: Target cursor size for + monster is read from the monsters.xml. + * data/graphics/gui/target-cursor-blue-s.png, + data/graphics/gui/target-cursor-blue-m.png, + data/graphics/gui/target-cursor-blue-l.png, + data/graphics/gui/target-cursor-red-s.png, + data/graphics/gui/target-cursor-red-m.png, + data/graphics/gui/target-cursor-red-l.png: Added temporary + placeholders for small and large target cursors until better versions + based on the original SVG are available. + +2007-05-08 Philipp Sehmisch + + * data/graphics/sprites/monster-bat.png, + data/graphics/sprites/monster-bat.xml, + data/graphics/sprites/monster-flower.xml, + data/graphics/sprites/monster-fluffy.xml, + data/graphics/sprites/monster-fluffy.png, + data/graphics/sprites/monster-goblin-fire.xml, + data/graphics/sprites/monster-maggot-giant.xml, + data/graphics/sprites/monster-maggot.xml, + data/graphics/sprites/monster-mountsnake.xml, + data/graphics/sprites/monster-mushroom-red.xml, + data/graphics/sprites/monster-mushroom-spiky.xml, + data/graphics/sprites/monster-pinkie.xml, + data/graphics/sprites/monster-scorpion-black.xml, + data/graphics/sprites/monster-scorpion-red.png, + data/graphics/sprites/monster-scorpion-red.xml, + data/graphics/sprites/monster-skull-poison.xml, + data/graphics/sprites/monster-slime-green.xml, + data/graphics/sprites/monster-slime-red.xml, + data/graphics/sprites/monster-slime-rudolph.xml, + data/graphics/sprites/monster-slime-santa.png, + data/graphics/sprites/monster-slime-santa.xml, + data/graphics/sprites/monster-slime-yellow.xml, + data/graphics/sprites/monster-snake-cave.png, + data/graphics/sprites/monster-snake-cave.xml, + data/graphics/sprites/monster-snake.xml, + data/graphics/sprites/monster-spider.xml: + Adjusted offsets of monster sprites (thanks to Pauan for finding out + the correct offsets - I just subtracted 6 of all x offsets to take the + new position of the target circle in account) and committed some + modifications at some monster graphics by Pauan. + +2007-05-02 Philipp Sehmisch + + * src/sprite.h, src/being.cpp, src/being.h, src/animatedsprite.cpp, + src/animatedsprite.h: Added methods to get the width and height of the + graphical representation of a sprite. + * src/gui/viewport.cpp: Fixed positioning of monster names and target + circles. + +2007-05-02 Philipp Sehmisch + + * src/particle.cpp: Fixed a compiler warning. + +2007-05-02 Björn Steinbrink + + * src/Makefile.am: Add the new particle subclasses to the automake + configuration. + * src/imageparticle.h, src/textparticle.h, src/particle.h, + src/animationparticle.h, src/CMakeLists.txt, src/particleemitter.cpp, + src/animationparticle.cpp, src/particle.cpp, src/imageparticle.cpp, + src/textparticle.cpp, src/utils/xml.cpp, src/utils/xml.h: Split the + particle class into subclasses based on their appearance. + +2007-04-24 Philipp Sehmisch + + * src/particle.cpp, src/particle.h: Some minor code cleanups, speed + optimizations and a bit of documentation. + +2007-04-23 Philipp Sehmisch + + * data/graphics/particles/flame.particle.xml, + data/graphics/particles/blaze.png: Added two files I forgot with the + last commit. + * src/resources/mapreader.cpp, src/particle.cpp, + src/particleemitter.cpp: Using XML child node iteration macro. + 2007-04-22 Björn Steinbrink * CMake/Modules/FindENet.cmake: Fixed ENet status always being set to @@ -10,11 +169,74 @@ * src/resources/itemdb.cpp: Made the parameter checks more terse and manageable. +2007-04-19 Philipp Sehmisch + + * src/resources/mapreader.cpp: Emitter positions are now read from map + files. + * src/engine.cpp: Removed the player follow effect used for testing. + * data/maps/new_4-1.tmx.gz, data/maps/new_5-1.tmx.gz: Added flame + effect to all lamps on the cave maps + * data/maps/new_9-1.tmx.gz: Added waterfall effect to the upper right + corner of NW woodland map. + +2007-04-15 Bjørn Lindeijer + + * src/openglgraphics.cpp: Rely on default 0 value for z axis. + * src/CMakeLists.txt, src/gui/window.cpp, src/gui/widgets, + src/gui/widgets/resizegrip.cpp, src/gui/widgets/resizegrip.h, + src/gui/inventorywindow.cpp, src/gui/window.h, src/Makefile.am: + Reimplemented window resizing. It is now once again possible to resize + windows using their borders (except for the top one, since that's the + title bar for Guichan) and the resize grip in the bottom right is much + easier to grab. + * src/gui/window.cpp: Increased minimum window height and fixed a + problem with setting window content size which was introduced with the + new resize grip. + 2007-04-13 Björn Steinbrink * data/graphics/gui/CMakeLists.txt: Added target cursor graphics to the set of files to be installed. +2007-04-05 Eugenio Favalli + + * src/main.cpp: Unified storage of configuration, updates and + screenshots in home directory. + +2007-04-03 Philipp Sehmisch + + * data/graphics/items/generic-easteregg-blue.png, + data/graphics/items/generic-easteregg-green.png, + data/graphics/items/generic-easteregg-pink.png, + data/graphics/items/generic-easteregg-red.png, + data/graphics/items/generic-easteregg-teal.png, + data/graphics/items/generic-easteregg-yellow.png, + data/items.xml: Added six different easter egg item graphics for the + easter event. Item IDs are 1208 - 1213. + * data/graphics/sprites/npcs.png: Added bunny girl npc for the easter + event. + +2007-04-01 Philipp Sehmisch + + * src/game.cpp: Screenshots are no longer saved directly in the users + home directory on UNIX systems but in the sub folder /.tmw/. A chatlog + message about the success of the screenshot saving does appear now. + Based on a patch by Patrick "the-me" Matthäi. + +2007-03-27 Bjørn Lindeijer + + * src/main.cpp: Icon loading doesn't necessarily succeed, so better + not crash when it doesn't. + +2007-03-25 Philipp Sehmisch + + * src/particle.cpp, src/particle.h, src/particleemitter.cpp, + src/particleemitter.h: Improved programming style and documentation + and added some small tweaks. + * src/engine.cpp, src/map.cpp, src/map.h, src/resources/mapreader.cpp: + Prepared getting the emitter positions from the map file by storing + them in the Map class and setting them up from the MapReader. + 2007-03-24 Bjørn Lindeijer * src/main.cpp: Changed the order of network message handling and @@ -49,6 +271,16 @@ src/net/charserverhandler.h, src/net/charserverhandler.cpp: Made sure the character creation dialog doesn't close when creation failed. +2007-03-22 Philipp Sehmisch + + * src/simpleanimation.cpp, src/simpleanimation.h: Added new + constructor for simple animation that allows to build the animation + based on an xmlNodePtr pointing to an node. + * src/particle.cpp, src/particle.h: Added support for and + childtags for effect root particles. + * data/graphics/particles/playerglow.particle.xml: New player follow + effect that demonstrates an animated root particle with an emitter. + 2007-03-22 Bjørn Lindeijer * src/gui/login.cpp, src/gui/login.h, src/gui/register.h, @@ -84,6 +316,11 @@ src/resources/resourcemanager.cpp, src/resources/spriteset.cpp, src/resources/spritedef.h: Renamed Spriteset to ImageSet. +2007-03-20 Philipp Sehmisch + + * src/gui/updatewindow.cpp: Cancel button is now disabled after + downloading is finished. + 2007-03-20 David Athay * src/gui/viewport.cpp: Fixed target cursor animation, and changed @@ -160,6 +397,8 @@ * src/simpleanimation.cpp, src/simpleanimation.h, src/CmakeLists.txt, src/Makefile.am: Added a simple animation class that hosts a looping animation without the action and direction stuff from AnimatedSprite. + * src/particle.cpp, src/particle.h, src/particleemitter.cpp: Used said + simple animation class for animated particles. 2007-03-12 Bjørn Lindeijer @@ -171,6 +410,14 @@ * src/map.cpp, src/gui/viewport.cpp: Fixed a bug that made the engine not draw the last row and column of the map. +2007-03-09 Philipp Sehmisch + + * src/particle.cpp: Reimplemented physics mode that uses the default + square root function as fallback for systems where the fastInvSqrt + function doesn't work properly. + * src/particle.cpp, src/particle.h: Some performance optimizations + suggested by Rogier "Avaniel" Polak. + 2007-03-09 Bjørn Lindeijer * data/graphics/gui/target-cursor-blue.png, @@ -221,6 +468,10 @@ data/sfx/pinkie-hit1.ogg, data/sfx/pinkie-miss1.ogg, data/monsters.xml: New sound effects by Cosmostrator. +2007-02-25 Philipp Sehmisch + + * src/particle.h, src/particleemitter.h: Just some documentation work. + 2007-02-25 Bjørn Lindeijer * src/CMakeLists.txt: Updated CMake file. @@ -247,6 +498,12 @@ size and data type. * src/logindata.h: Added a clear function. +2007-02-22 Philipp Sehmisch + + * src/particle.cpp, src/particle.h, src/particleemitter.cpp, + src/particleemitter.h: Added new particle property "bounce" that makes + particles bounce off the ground and use it with the damage numbers. + 2007-02-21 Philipp Sehmisch * src/gui/char-server.cpp, src/gui/updatewindow.cpp, src/gui/main.cpp, @@ -286,6 +543,16 @@ * src/winver.h, README, configure.ac, data/help/header.txt, NEWS, CMakeLists.txt: Changed version to 0.0.22.2. +2007-02-15 Philipp Sehmisch + + * src/engine.cpp: The name conflict problem with Guichan seems to be + solved with version 0.6.1. + * src/particle.cpp, src/particle.h, src/particleemitter.cpp, + src/particleemitter.h: Added support for animated particles. + * data/graphics/particles/playerglow.particle.xml: Created a new + player follow particle that spawns a swarm of animated bats that + follow the player. + 2007-02-13 Philipp Sehmisch * src/gui/register.cpp, src/logindata.h, src/main.cpp: Fixed the _M/_F @@ -306,8 +573,36 @@ 2007-02-10 Philipp Sehmisch - * src/gui/viewport.cpp: Fixed the bug in the scrolling limitation that made - it possible to scroll outside of the map in the south and east. + * src/gui/viewport.cpp: Fixed the bug in the scrolling limitation that + made it possible to scroll outside of the map in the south and east. + +2007-02-09 Philipp Sehmisch + + * src/particle.cpp: Fixed a misspelled include and another + optimisation at the vector calculation. + +2007-02-08 Philipp Sehmisch + + * src/particle.cpp, src/utils/fastsqrt.h: Added a faster function to + calculate square roots and using it for hypotenuse calculations. + Thanks to Rogier aka Avaniel for finding the function. + +2007-02-07 Philipp Sehmisch + + * src/particle.cpp, src/particle.h, src/particleemitter.cpp: Renamed + Particle::MAX_PARTICLES to Particle::maxCount and read the value from + config ("particleMaxCount") + * src/particle.cpp: Added fast physics mode that replaces the + trigonometric calculations made for calculating the acceleration by + much less cpu intense but also less accurate formulas. To enable it + set the config option "particleFastPhysics" to "1". + * src/particle.cpp: Added the config option "particleEmitterSkip" that + allows to reduces the output of the emitters by making them spawn + particles only every n-th game tick. + * src/graphics.cpp, src/graphics.h: Added a new method + "drawImageTransparent" to the graphic engine that blits an image with + an alpha factor. + * src/particle.cpp: Using new drawImageTransparent method. 2007-02-04 Bjørn Lindeijer @@ -357,6 +652,35 @@ Defence: 12, Weight: 120. * data/graphics/sprites/chest-cotton-female.png: Huh? Shouldn't this be on svn for ages? + * src/particle.cpp, src/particle.h, src/particleemitter.cpp, + src/particleemitter.h: Implemented die-distance (particles are deleted + when they reached a certain proximity to their target) + * src/particle.cpp: Fixed a bug in the acceleration vector calculation. + * src/particle.cpp, src/particle.h: Fixed a problem with particles with + unlimited lifetime and fade-in. + * data/graphics/particles/playerglow.particle.xml: And again a new + player follow particle. This time it demonstrates die-distance and the + fixed acceleration vector calculation. + * src/engine.cpp, data/graphics/particles/snow.particle.xml, + data/graphics/particles/snowflake.png: I can't stand the begging + anymore. Now it snows in the snow area... and the forest... and the + desert... and under the earth... and indoors... Are you happy now, + Rotonen and Elven? ;-) + * src/particle.cpp: Removed some debug log messages. + * src/being.cpp: Avoided crash when attempting to control an invalid + particle. + * src/particle.cpp, src/particle.h, src/particleemitter.cpp, + src/particleemitter.h: Cleaned the includes up. + +2007-01-31 Philipp Sehmisch + + * src/particle.cpp, src/particle.h, src/particleemitter.cpp, + src/particleemitter.h: Changed some variable names. + * data/graphics/particles/waterfall.particle.xml, + data/graphics/particles/waterfall-a.png: New waterfall with Modanungs + waterfall particle. + * src/particle.cpp: forgot to remove a svn conflict marker and changed + the order of initialisations to fix some compiler warnings. 2007-01-30 Eugenio Favalli @@ -373,6 +697,54 @@ src/resources/mapreader.h, src/resources/music.h: Some trivial documentation work. Fixes all Doxygen warnings. +2007-01-30 Philipp Sehmisch + + * src/net/beinghandler.cpp, + data/graphics/particles/skillup.particle.xml: Added different particle + effect for job levelup. + * src/particle.cpp, src/particle.h, src/particleemitter.cpp, + src/particleemitter.h: Renamed "alphafade" to "fade-out", added new + property "fade-in". + * data/graphics/particles/playerglow.particle.xml: Added a new player + effect (a fire) demonstrating how to use fade-in and fade-out to fade + one color into another. + +2007-01-29 Philipp Sehmisch + + * src/particle.cpp, src/particle.h, src/particleemitter.cpp, + src/particleemitter.h: Added a new particle property "alphafade" that + makes the particles fade into alpha before their lifetime ends. + * src/particle.cpp, src/particle.h: fixed an issue with particles that + have a lifetime of 0 and an issue with the momentum property. + * data/graphics/particles/waterfall.particle.xml, + data/graphics/particles/fog-medium-white-a.png, + data/graphics/particles/fog-medium-white-b.png, + data/graphics/particles/fog-medium-white-c.png: Added fog to the + waterfall effect demonstrating the new alphafade feature. + +2007-01-28 Philipp Sehmisch + + * src/utils/xml.cpp, src/utils/xml.h, src/particleemitter.cpp: Most + values are now read as floating point values from the emitter files. + * data/graphics/particles/fountain.particle.xml, + data/graphics/particles/hit.particle.xml, + data/graphics/particles/playerglow.particle.xml: Changed some values + as floating point values. Made the player follow effect magenta to + improve the visibility of the hit effects. + * src/engine.cpp, data/graphics/particles/waterfall.particle.xml: + Removed the fountain and added a waterfall instead. + * src/particle.h: Corrected the drawing order of the particles in + relation to the other sprites. + * src/gui/debugwindow.cpp, src/gui/debugwindow.h: Added particle count + to debug window. + * src/particle.cpp: Allowed momentum without acceleration and + implement the acceleration properly. + * src/utils/minmax.h, src/particleemitter.cpp, src/particleemitter.h: + Added a structure to hold a pair of numeric minimum and maximum values + and used it to store all numeric emitter properties. + * src/utils/randbetween.h: Removed (the functionality is now in struct + MinMax) + 2007-01-28 Bjørn Lindeijer * src/gui/char_select.h, src/net/messagein.h, @@ -383,6 +755,39 @@ * data/maps/new_8-1.tmx.gz, data/maps/new_11-1.tmx.gz: Map fixes by Pauan. +2007-01-27 Bjørn Lindeijer + + * src/gui/shoplistbox.cpp: Fixed compilation against Guichan 0.6.1. + * src/utils/randbetween.h: Fixed integer overflow causing the + randBetween function not to work properly on Linux. + +2007-01-27 Philipp Sehmisch + + * src/net/beinghandler.cpp: Fixed a compiler issue. + * src/particle.cpp, src/particle.h, src/particleemitter.cpp, + src/particleemitter.h, src/engine.cpp: Emitter data is read from + external xml files. Reimplemented target-based particles with the + difference that they don't target beings or locations but other + particles (at the moment the host particle of the effect). + * src/being.cpp: Beings now move controlled particles to their center + instead of their upper left corner. + * data/graphics/particles/orb*: Added a bunch of new particles. + * data/graphics/particles/fountain.particle.xml: Reimplementation of + the fountain effect in XML. + * data/graphics/particles/playerglow.particle.xml: New effect that + spawns orbs that orbit around the origin. + * src/being.cpp, data/graphics/particles/hit.particle.xml: Added + particle effect on hit. + * src/net/beinghandler.cpp, + data/graphics/particles/levelup.particle.xml: Added particle effect on + levelup (own or other player). + +2007-01-24 Philipp Sehmisch + + * src/particle.cpp: Initialized all variables of the particles in the + constructor. + * src/particleemitter.cpp, src/particleemitter.h: minor cleanups. + 2007-01-23 Bjørn Lindeijer * src/gui/shoplistbox.cpp, docs/INSTALL/win32.txt, INSTALL, NEWS: @@ -393,6 +798,39 @@ * src/gui/updatewindow.cpp: Identify ourselves when requesting files from the update server. +2007-01-22 Philipp Sehmisch + + * src/being.cpp, src/being.h, src/particle.cpp, src/particle.h + src/particleemitter.cpp, src/particleemitter.h, src/engine.cpp: + Particle effects are now created in child particles of the root + particle. Particle emitters have no longer a being they check every + frame. Instead beings have the ability to take control of particles. + +2007-01-19 Philipp Sehmisch + + * src/particle.cpp, src/particle.h, src/particleemitter.cpp, + src/particleemitter.h: Implemented emitters that follow a being. + * src/engine.cpp: Added an emitter that follows the local player. + * src/particle.cpp: Fixed the crash on exit (reason was that the + mSpriteIterator wasn't initialized in every case) + +2007-01-18 Bjørn Lindeijer + + * src/properties.h, src/being.cpp, src/beingmanager.h, src/sound.h, + src/gui/window.h, src/sound.cpp, src/main.h, src/being.h, + src/resources/soundeffect.h, src/resources/image.h, + src/resources/mapreader.h, src/resources/music.h: Some trivial + documentation work. Fixes all Doxygen warnings. + * src/particle.h, src/particle.cpp, src/CMakeLists.txt, + src/Makefile.am: Fixed compilation issues on Linux. + * src/gui/char_select.h, src/net/messagein.h, + src/net/messagehandler.h, src/net/network.h, src/net/connection.h, + src/net/messageout.h, src/utils/xml.h, src/main.h, + src/resources/monsterdb.h, src/resources/itemdb.h, + src/resources/equipmentdb.h: Some work on documentation. + * data/maps/new_8-1.tmx.gz, data/maps/new_11-1.tmx.gz: Map fixes by + Pauan. + 2007-01-17 Eugenio Favalli * docs/win32-release.txt, src/gui/register.cpp, src/main.cpp: Changed @@ -408,6 +846,12 @@ * data/help/header.txt, NEWS, README: Updated release date. +2007-01-15 Philipp Sehmisch + + * src/game.cpp, src/particle.cpp, src/particle.h, + src/particleemitter.h: Made the particle count global and more + performant. + 2007-01-14 Eugenio Favalli * src/gui/updatewindow.cpp, src/main.cpp, tmw.cbp: Fixed windows @@ -448,6 +892,17 @@ * src/winver.h, configure.ac, data/help/header.txt, NEWS, README, CMakeLists.txt: Updated version to 0.0.22.1. +2007-01-14 Philipp Sehmisch + + * src/particle.cpp, src/particle.h; src/particleemitter.cpp, + src/particleemitter.h, src/utils/randbetween.h: + Implemented particle engine. + * src/engine.cpp, src/game.cpp: added calls to the particle engine + * data/graphics/particles/*: added a bunch of particle graphics for + testing purpose. + * particleengine-todo.txt: Added particle engine todo list (please + omit when merging) + 2007-01-13 Bjørn Lindeijer * data/graphics/sprites/Makefile.am, @@ -1298,7 +1753,7 @@ 2006-10-12 Yohann Ferreira * debian/rules, debian/tmw-data.install, debian/tmw-data.dirs, - debian/tmw-music.install, debian/changelog: Updating debian files for + debian/tmw-music.install, debian/changelog: Updating Debian files for bug fixing. 2006-10-12 Frode Lindeijer @@ -1473,7 +1928,7 @@ * src/animation.h, src/animatedsprite.h, data/graphics/sprites/weapon.xml: Some modifications at the animation system. No more "undefined action foo" warnings in the tmw.log. Not - visible actions must now be declared explicitely. + visible actions must now be declared explicitly. * data/graphics/images/ambient/sandstorm.png, data/graphics/images/ambient/clouds.png: Improved quality of the overlay graphics. @@ -1892,7 +2347,7 @@ with more distinctive names. (no, i won't list all 114) * src/itemmanager.cpp, data/items.xml: Replaced indices on the item spriteset with filenames. added names and descriptions for all missing - items. Changed names and dascriptions of some items. + items. Changed names and descriptions of some items. * src/engine.cpp: Removed global item spriteset. * src/floor_item.cpp, src/floor_item.h, src/iteminfo.cpp, src/iteminfo.h, src/equipmentwindow.cpp, src/equipmentwindow.h, diff --git a/NEWS b/NEWS index 5281cf78..9529ae1b 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,19 @@ +0.0.23 (3 June 2007) +- Added a particle engine along with some particle effects +- Added a cursor to indicate targeted enemy +- Added new program icon +- Added a man page for UNIX like systems +- Added the --version command line parameter +- Improved MacOS X release +- Screenshots are now saved in the .tmw directory on UNIX like systems +- Magic pink is no longer used for transparency (fixes issues with that on Mac) +- Fixed difficulties with resizing windows +- Fixed misleading error message when connecting fails +- Fixed wrong error message when account name already exists +- Fixed crash when deleting a character +- Fixed error message when creating a new character fails +- Fixed updating problem when using scrollwheel to change shop selection + 0.0.22.2 (17 February 2007) - Updated to work with Guichan 0.6.1 - Changed to new default server (server.themanaworld.org) diff --git a/README b/README index 2d6f07b1..39677e1e 100644 --- a/README +++ b/README @@ -1,8 +1,7 @@ THE MANA WORLD ============== - Version: 0.0.22.2 Date: 17/02/2007 - + Version: 0.1.0 Date: XX/XX/2007 Development team: - See AUTHORS file for a list diff --git a/data/graphics/gui/CMakeLists.txt b/data/graphics/gui/CMakeLists.txt index 1549b2b4..5a02d7f1 100644 --- a/data/graphics/gui/CMakeLists.txt +++ b/data/graphics/gui/CMakeLists.txt @@ -30,8 +30,12 @@ SET (FILES sansserif8.png selection.png slider.png - target-cursor-blue.png - target-cursor-red.png + target-cursor-blue-l.png + target-cursor-blue-m.png + target-cursor-blue-s.png + target-cursor-red-l.png + target-cursor-red-m.png + target-cursor-red-s.png thickborder.png vscroll_blue.png vscroll_down_default.png diff --git a/data/graphics/gui/Makefile.am b/data/graphics/gui/Makefile.am index c0e0655b..a37e1196 100644 --- a/data/graphics/gui/Makefile.am +++ b/data/graphics/gui/Makefile.am @@ -33,6 +33,12 @@ gui_DATA = \ sansserif8.png \ selection.png \ slider.png \ + target-cursor-blue-l.png \ + target-cursor-blue-m.png \ + target-cursor-blue-s.png \ + target-cursor-red-l.png \ + target-cursor-red-m.png \ + target-cursor-red-s.png \ thickborder.png \ vscroll_blue.png \ vscroll_down_default.png \ diff --git a/data/graphics/gui/target-cursor-blue-l.png b/data/graphics/gui/target-cursor-blue-l.png new file mode 100644 index 00000000..77cdf4b6 Binary files /dev/null and b/data/graphics/gui/target-cursor-blue-l.png differ diff --git a/data/graphics/gui/target-cursor-blue-m.png b/data/graphics/gui/target-cursor-blue-m.png new file mode 100644 index 00000000..c0107357 Binary files /dev/null and b/data/graphics/gui/target-cursor-blue-m.png differ diff --git a/data/graphics/gui/target-cursor-blue-s.png b/data/graphics/gui/target-cursor-blue-s.png new file mode 100644 index 00000000..3e81c75d Binary files /dev/null and b/data/graphics/gui/target-cursor-blue-s.png differ diff --git a/data/graphics/gui/target-cursor-blue.png b/data/graphics/gui/target-cursor-blue.png deleted file mode 100644 index 3e81c75d..00000000 Binary files a/data/graphics/gui/target-cursor-blue.png and /dev/null differ diff --git a/data/graphics/gui/target-cursor-red-l.png b/data/graphics/gui/target-cursor-red-l.png new file mode 100644 index 00000000..76d2101b Binary files /dev/null and b/data/graphics/gui/target-cursor-red-l.png differ diff --git a/data/graphics/gui/target-cursor-red-m.png b/data/graphics/gui/target-cursor-red-m.png new file mode 100644 index 00000000..e2ab79c2 Binary files /dev/null and b/data/graphics/gui/target-cursor-red-m.png differ diff --git a/data/graphics/gui/target-cursor-red-s.png b/data/graphics/gui/target-cursor-red-s.png new file mode 100644 index 00000000..09195f44 Binary files /dev/null and b/data/graphics/gui/target-cursor-red-s.png differ diff --git a/data/graphics/gui/target-cursor-red.png b/data/graphics/gui/target-cursor-red.png deleted file mode 100644 index 09195f44..00000000 Binary files a/data/graphics/gui/target-cursor-red.png and /dev/null differ diff --git a/data/help/changes.txt b/data/help/changes.txt index f8a3eb67..dd062e49 100644 --- a/data/help/changes.txt +++ b/data/help/changes.txt @@ -3,99 +3,56 @@ ##3 === RECENT CHANGES === - 0.0.21 (17 September 2006) - - Added item pickup messages to the chat dialog - - Added XP bar to ministatus in the top left - - Added configurable smooth and lazy scrolling - - Added option to turn off the joystick - - Added --playername option for automatic character picking - - Added --configfile option for specifying which configuration file to use - - Added shortcut and middle mouse button for targetting nearest monster - - Added support for map effect overlays - - Fixed FPS limiter - - Fixed updating system on Windows - - Fixed player animations going out of sync on changing equipment or hairstyle - - Fixed SDL_image configure check on some systems by first checking for libpng - - Fixed big memory leak when using OpenGL - - Updated to work with Guichan 0.5.0 (older versions no longer supported) - - 0.0.20 (24 July 2006) - - Added new hairstyle, and some fixes to the old ones - - Added slider to set FPS limit - - Added visible equipments - - Added new maps and monsters - - Added female characters - - Implemented a new animation system - - Updated the updating system - - Reduced size of textures to stay within the limits of some OpenGL drivers - - Fixed connection not being shut down completely in case of an error - - Fixed min size of a window when resizing - - Fixed some maps issues - - Some fixes to monsters and player graphics - - Minor bug fixes and lots of code cleanups - - 0.0.19 (6 March 2006) - - - Added --username, --password and --defaults command line options - - Improved login sequence - - Enabled 3 slots to create players - - Improved setup window and added a joystick calibration tool - - Some maps fixes - - Reorganized and improved network code - - Fixed some bugs - - Made the player walk to items prior to picking them up - - Added new playerset - - Lots of cleanups and code re-roganization - - 0.0.18.1 (30 December 2005) - - - Fixed a drawing glitch with high tiles at the bottom of the screen - - Fixed glitches caused by fading out the damage display - - 0.0.18 (20 December 2005) - - - Added new items, npcs, tilesets, maps and monsters - - Non blocking connection at startup - - Enabled monster emotions - - Client version is now displayed during login - - Fixed setup window behaviour - - Fixed a Windows crash issue - - Fixed ScrollArea and BrowserBox behaviour - - Code cleanups - - 0.0.17 (10 October 2005) - - - Added remembering of window position and sizes - - Added taking screenshot with Alt+P - - Added notice about the player being overweight - - Added time to chat messages - - Added messagebox on error for MacOS X - - Added new network layer based on SDL_net - - Added proper error message for when the map server goes offline - - Added more international characters to fixed and rpg fonts - - Improved damage text font, shadow is now translucent - - Improved GUI layout, new profile window - - Improved support for building on FreeBSD and MacOS X - - Improved tile engine to fix graphics glitches and make mapping easier - - Rearranged keyboard shortcuts - - Fixed items on map to be removed on map switch - - Fixed OpenGL checkbox in the setup window to be usable - - Cleaned up a lot of code - - 0.0.16 (04 September 2005) - - - Added inn and casino - - Improved status window - - Improved OpenGL support - - Removed lot of bugs - - Code cleanups - - 0.0.15 (31 July 2005) - - - Added dynamic updating of client data - - Added much better font for chat and names - - Added option not to use the custom mouse cursor - - Added joystick support - - Improved mouse attack by not walking while pressing shift - - Fixed items being shown as equipped in inventory although they are not + 0.0.23 (3 June 2007) + - Added a particle engine along with some particle effects + - Added a cursor to indicate targeted enemy + - Added new program icon + - Added a man page for UNIX like systems + - Added the --version command line parameter + - Improved MacOS X release + - Screenshots are now saved in the .tmw directory on UNIX like systems + - Magic pink is no longer used for transparency (fixes issues with that on Mac) + - Fixed difficulties with resizing windows + - Fixed misleading error message when connecting fails + - Fixed wrong error message when account name already exists + - Fixed crash when deleting a character + - Fixed error message when creating a new character fails + - Fixed updating problem when using scrollwheel to change shop selection + + 0.0.22.2 (17 February 2007) + - Updated to work with Guichan 0.6.1 + - Changed to new default server (server.themanaworld.org) + - Changed custom mouse cursor + - Fixed the issue where _M or _F is appended to the username + - Fixed problem with Cancel button in update dialog + + 0.0.22.1 (15 January 2007) + - Updated to work with Guichan 0.6.0 (older versions no longer supported) + - Fixed mouse coordinates in debug window + - Fixed clicking on GUI to cause the player to start walking sometimes + + 0.0.22 (24 December 2006) + - Added support for female-specific equipment graphics + - Added support for monster sounds + - Added item icons to buy/sell dialogs + - Enhanced character select dialog to show equipment + - Changed to new update host (http://updates.themanaworld.org) + - Worked around a Guichan exception thrown for mice with many buttons + - Changed mouse walk to keep following mouse while button is held down + - Extended font support for Ã¥ and Ã… + - Disabled RLE compression on all surfaces in software mode + - Fixed joystick setting not to show disabled when it's actually enabled + - Fixed money field to no longer hide below the bottom of the window + - Fixed pathfinding to allow walking through beings when they block your path + - Fixed an issue with NPC dialogs staying open after player respawn + + 0.0.21.1 (30 October 2006) + - Reload wallpaper after loading updates + - Added support for gzip compressed map layer data + - Added support for building with CMake + - Added slider to setup dialog for configuring overlay effect + - Fixed excessive unnecessary reloading of sprites + - Fixed problem with OpenGL related redefinition + - Fixed problems with hiding windows using h + - Fixed trade window positioning diff --git a/data/help/header.txt b/data/help/header.txt index 7311c111..b10ed991 100644 --- a/data/help/header.txt +++ b/data/help/header.txt @@ -2,7 +2,7 @@ ##1 T H E M A N A W O R L D ##1 ========================================== - ##2Version:##6 0.0.22.2 ##2Date:##317 February 2007 + ##2Version:##6 0.0.23 ##2Date:##33 June 2007 ##2 Website: http://themanaworld.org diff --git a/docs/Makefile.am b/docs/Makefile.am index 8b57d5bb..1ee9a9a6 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -1,6 +1,7 @@ man6_MANS = tmw.6 -EXTRA_DIST = packages.txt \ +EXTRA_DIST = $(man6_MANS) \ + packages.txt \ FAQ.txt \ HACKING.txt \ SOURCE/tmwdox.sh \ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e28e235e..7a4da70d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -47,6 +47,8 @@ MARK_AS_ADVANCED(SDL_INCLUDE_DIR) MARK_AS_ADVANCED(SDL_LIBRARY) SET(SRCS + gui/widgets/resizegrip.cpp + gui/widgets/resizegrip.h gui/box.cpp gui/box.h gui/browserbox.cpp @@ -275,11 +277,15 @@ SET(SRCS utils/base64.cpp utils/base64.h utils/dtor.h + utils/fastsqrt.h + utils/minmax.h utils/tostring.h utils/xml.cpp utils/xml.h animatedsprite.cpp animatedsprite.h + animationparticle.cpp + animationparticle.h being.cpp being.h beingmanager.cpp @@ -304,6 +310,8 @@ SET(SRCS graphics.cpp graphics.h guichanfwd.h + imageparticle.cpp + imageparticle.h inventory.cpp inventory.h item.cpp @@ -326,6 +334,10 @@ SET(SRCS npc.h openglgraphics.cpp openglgraphics.h + particle.cpp + particle.h + particleemitter.cpp + particleemitter.h player.cpp player.h properties.h @@ -335,6 +347,8 @@ SET(SRCS sound.cpp sound.h sprite.h + textparticle.cpp + textparticle.h tileset.h ) diff --git a/src/Makefile.am b/src/Makefile.am index f1f51b79..92c1b1b2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,6 +3,8 @@ AUTOMAKE_OPTIONS = subdir-objects bin_PROGRAMS = tmw tmw_SOURCES = gui/widgets/dropdown.cpp \ gui/widgets/dropdown.h \ + gui/widgets/resizegrip.cpp \ + gui/widgets/resizegrip.h \ gui/browserbox.cpp \ gui/browserbox.h \ gui/buddywindow.cpp \ @@ -229,11 +231,15 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \ utils/base64.cpp \ utils/base64.h \ utils/dtor.h \ + utils/fastsqrt.h \ + utils/minmax.h \ utils/tostring.h \ utils/xml.cpp \ utils/xml.h \ animatedsprite.cpp \ animatedsprite.h \ + animationparticle.cpp \ + animationparticle.h \ being.cpp \ being.h \ beingmanager.cpp \ @@ -258,6 +264,8 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \ graphics.cpp \ graphics.h \ guichanfwd.h \ + imageparticle.cpp \ + imageparticle.h \ inventory.cpp \ inventory.h \ item.cpp \ @@ -280,15 +288,21 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \ npc.h \ openglgraphics.cpp\ openglgraphics.h \ + particle.cpp \ + particle.h \ + particleemitter.cpp \ + particleemitter.h \ player.cpp \ player.h \ properties.h \ serverinfo.h \ simpleanimation.cpp \ - simpleanimation.h \ + simpleanimation.h \ sound.cpp \ sound.h \ sprite.h \ + textparticle.cpp \ + textparticle.h \ tileset.h # set the include path found by configure diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index 7260a512..c1e89ff0 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -197,3 +197,27 @@ AnimatedSprite::setDirection(SpriteDirection direction) } } } + +int +AnimatedSprite::getWidth() const +{ + if (mFrame) + { + return mFrame->image->getWidth(); + } + else { + return 0; + } +} + +int +AnimatedSprite::getHeight() const +{ + if (mFrame) + { + return mFrame->image->getHeight(); + } + else { + return 0; + } +} diff --git a/src/animatedsprite.h b/src/animatedsprite.h index 2257c0f0..42c0a743 100644 --- a/src/animatedsprite.h +++ b/src/animatedsprite.h @@ -85,6 +85,18 @@ class AnimatedSprite bool draw(Graphics* graphics, int posX, int posY) const; + /** + * gets the width in pixels of the image of the current frame + */ + int + getWidth() const; + + /** + * gets the height in pixels of the image of the current frame + */ + int + getHeight() const; + /** * Sets the direction. */ diff --git a/src/animationparticle.cpp b/src/animationparticle.cpp new file mode 100644 index 00000000..30c33da7 --- /dev/null +++ b/src/animationparticle.cpp @@ -0,0 +1,51 @@ +/* + * The Mana World + * Copyright 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "animationparticle.h" + +#include "graphics.h" +#include "simpleanimation.h" + +AnimationParticle::AnimationParticle(Map *map, Animation *animation): + ImageParticle(map, 0), + mAnimation(new SimpleAnimation(animation)) +{ +} + +AnimationParticle::AnimationParticle(Map *map, xmlNodePtr animationNode): + ImageParticle(map, 0), + mAnimation(new SimpleAnimation(animationNode)) +{ +} + +AnimationParticle::~AnimationParticle() +{ + delete mAnimation; +} + +bool AnimationParticle::update() +{ + mAnimation->update(10); // particle engine is updated every 10ms + mImage = mAnimation->getCurrentImage(); + + return Particle::update(); +} diff --git a/src/animationparticle.h b/src/animationparticle.h new file mode 100644 index 00000000..054b1b73 --- /dev/null +++ b/src/animationparticle.h @@ -0,0 +1,49 @@ +/* + * The Mana World + * Copyright 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef _ANIMATION_PARTICLE +#define _ANIMATION_PARTICLE + +#include + +#include "imageparticle.h" + +class Animation; +class Map; +class SimpleAnimation; + +class AnimationParticle : public ImageParticle +{ + public: + AnimationParticle(Map *map, Animation *animation); + + AnimationParticle(Map *map, xmlNodePtr animationNode); + + ~AnimationParticle(); + + virtual bool update(); + + private: + SimpleAnimation *mAnimation; /**< Used animation for this particle */ +}; + +#endif diff --git a/src/being.cpp b/src/being.cpp index 682daddb..7ba9ddb9 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -32,12 +32,16 @@ #include "graphics.h" #include "log.h" #include "map.h" +#include "particle.h" #include "resources/resourcemanager.h" #include "resources/imageset.h" #include "gui/gui.h" +#include "resources/resourcemanager.h" +#include "resources/imageset.h" + #include "utils/dtor.h" #include "utils/tostring.h" @@ -61,7 +65,6 @@ Being::Being(Uint16 id, Uint16 job, Map *map): mMap(NULL), mHairStyle(0), mHairColor(0), mSpeechTime(0), - mDamageTime(0), mPx(0), mPy(0), mSprites(VECTOREND_SPRITE, NULL), mEquipmentSpriteIDs(VECTOREND_SPRITE, 0) @@ -85,6 +88,13 @@ Being::~Being() clearPath(); setMap(NULL); + for ( std::list::iterator i = mChildParticleEffects.begin(); + i != mChildParticleEffects.end(); + i++) + { + (*i)->kill(); + } + instances--; if (instances == 0) @@ -292,8 +302,32 @@ Being::setSpeech(const std::string &text, Uint32 time) void Being::takeDamage(int amount) { - mDamage = amount ? toString(amount) : "miss"; - mDamageTime = 300; + gcn::Font* font; + std::string damage = amount ? toString(amount) : "miss"; + + // Selecting the right color + if (damage == "miss") + { + font = hitYellowFont; + } + else + { + // hit particle effect + controlParticle(particleEngine->addEffect("graphics/particles/hit.particle.xml", 0, 0)); + + if (getType() == MONSTER) + { + font = hitBlueFont; + } + else + { + font = hitRedFont; + } + } + + // show damage number + particleEngine->addTextSplashEffect(damage, 255, 255, 255, font, + mPx + 16, mPy + 16); } void @@ -318,6 +352,19 @@ Being::setMap(Map *map) { mSpriteIterator = mMap->addSprite(this); } + + //clear particle effect list because child particles became invalid + mChildParticleEffects.clear(); +} + +void +Being::controlParticle(Particle *particle) +{ + if (particle) + { + particle->disableAutoDelete(); //the effect may not die without the beings permission or we segvault + mChildParticleEffects.push_back(particle); + } } void @@ -465,10 +512,6 @@ Being::logic() if (mSpeechTime > 0) mSpeechTime--; - // Reduce the time that damage is still displayed - if (mDamageTime > 0) - mDamageTime--; - // Update pixel coordinates mPx = mX - 16 + getXOffset(); mPy = mY - 16 + getYOffset(); @@ -489,6 +532,14 @@ Being::logic() mSprites[i]->update(tick_time * 10); } } + + //Update particle effects + for ( std::list::iterator i = mChildParticleEffects.begin(); + i != mChildParticleEffects.end(); + i++) + { + (*i)->setPosition((float)mPx + 16.0f, (float)mPy + 32.0f); + } } void @@ -531,37 +582,6 @@ Being::drawSpeech(Graphics *graphics, int offsetX, int offsetY) graphics->setColor(gcn::Color(255, 255, 255)); graphics->drawText(mSpeech, px + 18, py - 60, gcn::Graphics::CENTER); } - - // Draw damage above this being - if (mDamageTime > 0 && mDamageTime < 275) - { - // Selecting the right color - if (mDamage == "miss") - { - graphics->setFont(hitYellowFont); - } - else if (getType() == MONSTER) - { - graphics->setFont(hitBlueFont); - } - else - { - graphics->setFont(hitRedFont); - } - - int textY = (getType() == MONSTER) ? 32 : 70; - int ft = 150 - mDamageTime; - float a = (ft > 0) ? 1.0 - ft / 150.0 : 1.0; - - graphics->setColor(gcn::Color(255, 255, 255, (int)(255 * a))); - graphics->drawText(mDamage, - px + 16, - py - textY - (300 - mDamageTime) / 10, - gcn::Graphics::CENTER); - - // Reset alpha value - graphics->setColor(gcn::Color(255, 255, 255)); - } } Being::Type @@ -632,3 +652,29 @@ int Being::getOffset(int step) const return offset; } + + +int +Being::getWidth() const +{ + if (mSprites[BASE_SPRITE]) + { + return mSprites[BASE_SPRITE]->getWidth(); + } + else { + return 0; + } +} + + +int +Being::getHeight() const +{ + if (mSprites[BASE_SPRITE]) + { + return mSprites[BASE_SPRITE]->getHeight(); + } + else { + return 0; + } +} diff --git a/src/being.h b/src/being.h index 332f1b4a..8820c30a 100644 --- a/src/being.h +++ b/src/being.h @@ -42,6 +42,7 @@ class Item; class Map; class Graphics; class ImageSet; +class Particle; /** * A position along a being's path. @@ -97,6 +98,13 @@ class Being : public Sprite VECTOREND_SPRITE }; + enum TargetCursorSize { + TC_SMALL = 0, + TC_MEDIUM, + TC_LARGE, + NUM_TC + }; + /** * Directions, to be used as bitmask values @@ -359,8 +367,33 @@ class Being : public Sprite int getYOffset() const { return getOffset(mStepY); } + /** + * Returns the horizontal size of the current base sprite of the being + */ + virtual int + getWidth() const; + + /** + * Returns the vertical size of the current base sprite of the being + */ + virtual int + getHeight() const; + + /** + * Returns the required size of a target cursor for this being + */ + virtual Being::TargetCursorSize + getTargetCursorSize() const + { return TC_MEDIUM; } + std::auto_ptr mEquipment; + /** + * Take control of a particle + */ + void + controlParticle(Particle *particle); + protected: /** * Sets the new path for this being. @@ -380,14 +413,13 @@ class Being : public Sprite Path mPath; std::string mSpeech; - std::string mDamage; Uint16 mHairStyle, mHairColor; Uint32 mSpeechTime; - Uint32 mDamageTime; Sint32 mPx, mPy; /**< Pixel coordinates */ std::vector mSprites; std::vector mEquipmentSpriteIDs; + std::list mChildParticleEffects; private: int diff --git a/src/engine.cpp b/src/engine.cpp index 31bec9ff..3b5fb403 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -35,6 +35,7 @@ #include "localplayer.h" #include "log.h" #include "map.h" +#include "particle.h" #include "sound.h" #include "gui/gui.h" @@ -63,6 +64,7 @@ void Engine::changeMap(const std::string &mapPath) floorItemManager->clear(); beingManager->clear(); + particleEngine->clear(); // Store full map path in global var map_path = "maps/" + mapPath; @@ -83,8 +85,12 @@ void Engine::changeMap(const std::string &mapPath) } minimap->setMapImage(mapImage); beingManager->setMap(newMap); + particleEngine->setMap(newMap); viewport->setMap(newMap); + // Initialize map-based particle effects + newMap->initializeParticleEffects(particleEngine); + // Start playing new music file when necessary std::string oldMusic = ""; @@ -106,5 +112,6 @@ void Engine::changeMap(const std::string &mapPath) void Engine::logic() { beingManager->logic(); + particleEngine->update(); gui->logic(); } diff --git a/src/game.cpp b/src/game.cpp index ba4e2b9d..1afc530b 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -41,6 +41,7 @@ #include "localplayer.h" #include "log.h" #include "npc.h" +#include "particle.h" #include "gui/buy.h" #include "gui/buysell.h" @@ -121,6 +122,8 @@ BeingManager *beingManager = NULL; FloorItemManager *floorItemManager = NULL; ChannelManager *channelManager = NULL; +Particle *particleEngine = NULL; + const int MAX_TIME = 10000; /** @@ -242,6 +245,9 @@ Game::Game(): floorItemManager = new FloorItemManager(); channelManager = new ChannelManager(); + particleEngine = new Particle(NULL); + particleEngine->setupEngine(); + // Initialize timers tick_time = 0; mLogicCounterId = SDL_AddTimer(10, nextTick, NULL); //Logic counter @@ -286,6 +292,7 @@ Game::~Game() delete floorItemManager; delete channelManager; delete joystick; + delete particleEngine; beingManager = NULL; floorItemManager = NULL; @@ -308,7 +315,9 @@ bool saveScreenshot(SDL_Surface *screenshot) screenshotCount++; filename.str(""); #if (defined __USE_UNIX98 || defined __FreeBSD__ || defined __APPLE__) - filename << PHYSFS_getUserDir() << "/"; + filename << PHYSFS_getUserDir() << ".tmw/"; +#elif defined __APPLE__ + filename << PHYSFS_getUserDir() << "Desktop/"; #endif filename << "TMW_Screenshot_" << screenshotCount << ".png"; testExists.open(filename.str().c_str(), std::ios::in); @@ -316,7 +325,18 @@ bool saveScreenshot(SDL_Surface *screenshot) testExists.close(); } while (!found); - return ImageWriter::writePNG(screenshot, filename.str()); + if (ImageWriter::writePNG(screenshot, filename.str())) + { + std::stringstream chatlogentry; + chatlogentry << "Screenshot saved to " << filename.str().c_str(); + chatWindow->chatLog(chatlogentry.str(), BY_SERVER); + return true; + } + else + { + chatWindow->chatLog("Saving screenshot failed!", BY_SERVER); + return false; + } } void Game::optionChanged(const std::string &name) diff --git a/src/graphics.cpp b/src/graphics.cpp index f007470a..1e31f903 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -136,8 +136,6 @@ bool Graphics::drawImage(Image *image, int srcX, int srcY, int dstX, int dstY, srcX += image->mBounds.x; srcY += image->mBounds.y; - - SDL_Rect dstRect; SDL_Rect srcRect; dstRect.x = dstX; dstRect.y = dstY; diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index cb07da22..2a8616f8 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -111,27 +111,21 @@ void BuyDialog::setMoney(int amount) { mMoney = amount; mShopItemList->setPlayersMoney(amount); - mMoneyLabel->setCaption("Price: 0 GP / " + toString(mMoney) + " GP"); - mMoneyLabel->adjustSize(); + + updateButtonsAndLabels(); } void BuyDialog::reset() { mShopItems->clear(); + mShopItemList->adjustSize(); mMoney = 0; mSlider->setValue(0.0); - mAmountItems = 0; // Reset Previous Selected Items to prevent failing asserts mShopItemList->setSelected(-1); - mIncreaseButton->setEnabled(false); - mDecreaseButton->setEnabled(false); - mQuantityLabel->setCaption("0"); - mQuantityLabel->adjustSize(); - mMoneyLabel->setCaption("Price: 0 GP / " + toString(mMoney) + " GP"); - mMoneyLabel->adjustSize(); - mItemDescLabel->setCaption(""); - mItemEffectLabel->setCaption(""); + + updateButtonsAndLabels(); } void BuyDialog::addItem(short id, int price) @@ -151,45 +145,36 @@ void BuyDialog::action(const gcn::ActionEvent &event) } // The following actions require a valid selection - if (selectedItem < 0 || selectedItem >= int(mShopItems->getNumberOfElements())) + if (selectedItem < 0 || + selectedItem >= (int) mShopItems->getNumberOfElements()) { return; } - bool updateButtonsAndLabels = false; - if (event.getId() == "slider") { mAmountItems = (int)(mSlider->getValue() * mMaxItems); - updateButtonsAndLabels = true; + updateButtonsAndLabels(); } - else if (event.getId() == "+") + else if (event.getId() == "+" && mAmountItems < mMaxItems) { - if (mAmountItems < mMaxItems) { - mAmountItems++; - } else { - mAmountItems = mMaxItems; - } + mAmountItems++; - mSlider->setValue(double(mAmountItems)/double(mMaxItems)); - updateButtonsAndLabels = true; + mSlider->setValue((double) mAmountItems / (double) mMaxItems); + updateButtonsAndLabels(); } - else if (event.getId() == "-") + else if (event.getId() == "-" && mAmountItems > 0) { - if (mAmountItems > 0) { - mAmountItems--; - } else { - mAmountItems = 0; - } + mAmountItems--; - mSlider->setValue(double(mAmountItems)/double(mMaxItems)); - updateButtonsAndLabels = true; + mSlider->setValue((double) mAmountItems / (double) mMaxItems); + updateButtonsAndLabels(); } // TODO: Actually we'd have a bug elsewhere if this check for the number // of items to be bought ever fails, Bertram removed the assertions, is // there a better way to ensure this fails in an _obivous_ way in C++? - else if (event.getId() == "buy" && (mAmountItems > 0 && - mAmountItems <= mMaxItems)) + else if (event.getId() == "buy" && mAmountItems > 0 && + mAmountItems <= mMaxItems) { // XXX Convert for new server /* @@ -199,38 +184,15 @@ void BuyDialog::action(const gcn::ActionEvent &event) outMsg.writeShort(mShopItems->at(selectedItem).id); */ - // update money ! + // Update money and adjust the max number of items that can be bought mMoney -= mAmountItems * mShopItems->at(selectedItem).price; - // Update number of items that can be bought at max mMaxItems -= mAmountItems; - if (!mMaxItems) { - mSlider->setEnabled(false); - } - // Reset selection mAmountItems = 0; - mSlider->setValue(0); - - updateButtonsAndLabels = true; - } + mSlider->setValue(0.0); - // If anything has changed, we have to update the buttons and labels - if (updateButtonsAndLabels) - { - // Update buttons - mIncreaseButton->setEnabled(mAmountItems < mMaxItems); - mDecreaseButton->setEnabled(mAmountItems > 0); - mBuyButton->setEnabled(mAmountItems > 0); - - // Update labels - mQuantityLabel->setCaption(toString(mAmountItems)); - mQuantityLabel->adjustSize(); - - int price = mAmountItems * mShopItems->at(selectedItem).price; - mMoneyLabel->setCaption("Price: " + toString(price) + " GP / " - + toString(mMoney) + " GP" ); - mMoneyLabel->adjustSize(); + updateButtonsAndLabels(); } } @@ -238,17 +200,16 @@ void BuyDialog::selectionChanged(const SelectionEvent &event) { // Reset amount of items and update labels mAmountItems = 0; - mSlider->setValue(0); - mQuantityLabel->setCaption("0"); - mQuantityLabel->adjustSize(); - mMoneyLabel->setCaption("Price: 0 GP / " + toString(mMoney) + " GP"); - mMoneyLabel->adjustSize(); + mSlider->setValue(0.0); - // Disable buttons for buying and decreasing - mBuyButton->setEnabled(false); - mDecreaseButton->setEnabled(false); + updateButtonsAndLabels(); +} +void +BuyDialog::updateButtonsAndLabels() +{ int selectedItem = mShopItemList->getSelected(); + int price = 0; if (selectedItem > -1) { @@ -259,16 +220,32 @@ void BuyDialog::selectionChanged(const SelectionEvent &event) // Calculate how many the player can afford mMaxItems = mMoney / mShopItems->at(selectedItem).price; + if (mAmountItems > mMaxItems) + { + mAmountItems = mMaxItems; + } + + // Calculate price of pending purchase + price = mAmountItems * mShopItems->at(selectedItem).price; } else { mItemDescLabel->setCaption("Description:"); mItemEffectLabel->setCaption("Effect:"); mMaxItems = 0; + mAmountItems = 0; } - // When at least one item can be bought, enable the slider and the - // increase button - mIncreaseButton->setEnabled(mMaxItems > 0); + // Enable or disable buttons and slider + mIncreaseButton->setEnabled(mAmountItems < mMaxItems); + mDecreaseButton->setEnabled(mAmountItems > 0); + mBuyButton->setEnabled(mAmountItems > 0); mSlider->setEnabled(mMaxItems > 0); + + // Update quantity and money labels + mQuantityLabel->setCaption(toString(mAmountItems)); + mQuantityLabel->adjustSize(); + mMoneyLabel->setCaption("Price: " + toString(price) + " GP / " + + toString(mMoney - price) + " GP" ); + mMoneyLabel->adjustSize(); } diff --git a/src/gui/buy.h b/src/gui/buy.h index 13116b6e..7834a434 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -92,6 +92,12 @@ class BuyDialog : public Window, public gcn::ActionListener, SelectionListener */ std::string getElementAt(int i); + /** + * Updates the state of buttons and labels. + */ + void + updateButtonsAndLabels(); + private: gcn::Button *mBuyButton; gcn::Button *mQuitButton; diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index eb6b7612..48df9efe 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -160,7 +160,7 @@ ChatWindow::chatLog(std::string line, int own, std::string channelName) break; case BY_OTHER: tmp.nick += CAT_NORMAL; - lineColor = "##4"; // Equiv. to BrowserBox::ORANGE + lineColor = "##0"; // Equiv. to BrowserBox::BLACK break; case BY_SERVER: tmp.nick += std::string("Server: "); @@ -195,7 +195,7 @@ ChatWindow::chatLog(std::string line, int own, std::string channelName) // We look if the Vertical Scroll Bar is set at the max before // adding a row, otherwise the max will always be a row higher // at comparison. - if (mScrollArea->getVerticalScrollAmount() == mScrollArea->getVerticalMaxScroll() ) + if (mScrollArea->getVerticalScrollAmount() == mScrollArea->getVerticalMaxScroll()) { mTextOutput->addRow(line); mScrollArea->setVerticalScrollAmount(mScrollArea->getVerticalMaxScroll()); diff --git a/src/gui/chat.h b/src/gui/chat.h index c7e51ebf..6f9b91fe 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -168,13 +168,13 @@ class ChatWindow : public Window, public gcn::ActionListener, /* * Determines whether to send a command or an ordinary message, then - * contructs packets & sends them + * contructs packets & sends them. * * @param nick The character's name to display in front. * @param msg The message text which is to be send. * * NOTE: - * the nickname is required by the server, if not specified + * The nickname is required by the server, if not specified * the message may not be sent unless a command was intended * which requires another packet to be constructed! you can * achieve this by putting a slash ("/") infront of the diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 563f380f..ebf7d974 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -33,6 +33,7 @@ #include "../game.h" #include "../engine.h" +#include "../particle.h" #include "../map.h" #include "../utils/tostring.h" @@ -58,6 +59,9 @@ DebugWindow::DebugWindow(): mTileMouseLabel = new gcn::Label("[Mouse: 0, 0]"); mTileMouseLabel->setPosition(100, 0); + mParticleCountLabel = new gcn::Label("[Particle count: 0]"); + mParticleCountLabel->setPosition(100, 60); + Button *closeButton = new Button("Close", "close", this); closeButton->setPosition(5, 60); @@ -65,6 +69,7 @@ DebugWindow::DebugWindow(): add(mMusicFileLabel); add(mMapFileLabel); add(mTileMouseLabel); + add(mParticleCountLabel); add(closeButton); } @@ -97,6 +102,11 @@ DebugWindow::logic() mMapFileLabel->setCaption(minimap); mMapFileLabel->adjustSize(); } + + mParticleCountLabel->setCaption("[Particle count: " + + toString(Particle::particleCount) + +"]"); + mParticleCountLabel->adjustSize(); } void diff --git a/src/gui/debugwindow.h b/src/gui/debugwindow.h index 4fd33d83..d082b2ca 100644 --- a/src/gui/debugwindow.h +++ b/src/gui/debugwindow.h @@ -58,6 +58,7 @@ class DebugWindow : public Window, public gcn::ActionListener private: gcn::Label *mMusicFileLabel, *mMapFileLabel; gcn::Label *mTileMouseLabel, *mFPSLabel; + gcn::Label *mParticleCountLabel; }; #endif diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 44d042a6..2018c75a 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -165,8 +165,8 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event) if (!item) return; - /* Convert relative to the window coordinates to - * absolute screen coordinates. + /* Convert relative to the window coordinates to absolute screen + * coordinates. */ int mx = event.getX() + getX(); int my = event.getY() + getY(); @@ -178,7 +178,8 @@ void InventoryWindow::mouseDragged(gcn::MouseEvent &event) { int tmpWidth = getWidth(), tmpHeight = getHeight(); Window::mouseDragged(event); - if (getWidth() != tmpWidth || getHeight() != tmpHeight) { + if (getWidth() != tmpWidth || getHeight() != tmpHeight) + { updateWidgets(); } } diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index c9878c84..478371b1 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -88,7 +88,7 @@ SellDialog::SellDialog(): quitButton->setPosition(208, 186); mShopItemList->setActionEventId("item"); - mSlider->setActionEventId("mSlider"); + mSlider->setActionEventId("slider"); mShopItemList->setPriceCheck(false); @@ -119,20 +119,11 @@ void SellDialog::reset() { mShopItems->clear(); mSlider->setValue(0.0); - mAmountItems = 0; - - mQuantityLabel->setCaption("0"); - mQuantityLabel->adjustSize(); - mMoneyLabel->setCaption("Money: 0 GP / Total: " - + toString(mPlayerMoney) + " GP"); - mMoneyLabel->adjustSize(); - mItemDescLabel->setCaption(""); - mItemEffectLabel->setCaption(""); - // Reset Previous Selected Items to prevent failing asserts + // Reset previous selected item to prevent failing asserts mShopItemList->setSelected(-1); - mIncreaseButton->setEnabled(false); - mDecreaseButton->setEnabled(false); + + updateButtonsAndLabels(); } void SellDialog::addItem(Item *item, int price) @@ -162,25 +153,7 @@ void SellDialog::action(const gcn::ActionEvent &event) { mAmountItems = 0; mSlider->setValue(0); - mDecreaseButton->setEnabled(false); - mSellButton->setEnabled(false); - - mQuantityLabel->adjustSize(); - mMoneyLabel->setCaption("Money: 0 GP / Total: " - + toString(mPlayerMoney) + " GP"); - mMoneyLabel->adjustSize(); - - if (selectedItem > -1) { - mSlider->setEnabled(true); - mIncreaseButton->setEnabled(true); - mMaxItems = mShopItems->at(selectedItem).quantity; - mQuantityLabel->setCaption("0 / " + toString(mMaxItems)); - } else { - mSlider->setEnabled(false); - mIncreaseButton->setEnabled(false); - mQuantityLabel->setCaption("0"); - } - mQuantityLabel->adjustSize(); + updateButtonsAndLabels(); } else if (event.getId() == "quit") { @@ -189,40 +162,35 @@ void SellDialog::action(const gcn::ActionEvent &event) } // The following actions require a valid item selection - if (selectedItem == -1 || selectedItem >= int(mShopItems->getNumberOfElements())) { + if (selectedItem == -1 || + selectedItem >= (int) mShopItems->getNumberOfElements()) + { return; } - bool updateButtonsAndLabels = false; - - if (event.getId() == "mSlider") + if (event.getId() == "slider") { - mAmountItems = (int)(mSlider->getValue() * mMaxItems); - - updateButtonsAndLabels = true; + mAmountItems = (int) (mSlider->getValue() * mMaxItems); + updateButtonsAndLabels(); } - else if (event.getId() == "+") + else if (event.getId() == "+" && mAmountItems < mMaxItems) { - assert(mAmountItems < mMaxItems); mAmountItems++; - mSlider->setValue(double(mAmountItems)/double(mMaxItems)); - updateButtonsAndLabels = true; + mSlider->setValue((double) mAmountItems /(double) mMaxItems); + updateButtonsAndLabels(); } - else if (event.getId() == "-") + else if (event.getId() == "-" && mAmountItems > 0) { - assert(mAmountItems > 0); mAmountItems--; - mSlider->setValue(double(mAmountItems)/double(mMaxItems)); - - updateButtonsAndLabels = true; + mSlider->setValue((double) mAmountItems / (double) mMaxItems); + updateButtonsAndLabels(); } - else if (event.getId() == "sell") + else if (event.getId() == "sell" && mAmountItems > 0 + && mAmountItems <= mMaxItems) { // Attempt sell - assert(mAmountItems > 0 && mAmountItems <= mMaxItems); - // XXX Convert for new server /* MessageOut outMsg(CMSG_NPC_SELL_REQUEST); @@ -236,60 +204,77 @@ void SellDialog::action(const gcn::ActionEvent &event) mPlayerMoney += (mAmountItems * mShopItems->at(selectedItem).price); mAmountItems = 0; mSlider->setValue(0); - mSlider->setEnabled(mMaxItems != 0); - - // All were sold - if (!mMaxItems) { + if (!mMaxItems) + { + // All were sold mShopItemList->setSelected(-1); - mShopItems->getShop()->erase(mShopItems->getShop()->begin() + selectedItem); + mShopItems->getShop()->erase( + mShopItems->getShop()->begin() + selectedItem); + } + else + { + // Update only when there are items left, the entry doesn't exist + // otherwise and can't be updated + updateButtonsAndLabels(); } - - // Update only when there are items left, the entry doesn't exist - // otherwise and can't be updated - updateButtonsAndLabels = bool(mMaxItems); - } - - // If anything changed, we need to update the buttons and labels - if (updateButtonsAndLabels) - { - // Update labels - mQuantityLabel->setCaption(toString(mAmountItems) + " / " + toString(mMaxItems)); - mQuantityLabel->adjustSize(); - - int price = mAmountItems * mShopItems->at(selectedItem).price; - mMoneyLabel->setCaption("Money: " + toString(price) + " GP / Total: " - + toString(price + mPlayerMoney) + " GP"); - mMoneyLabel->adjustSize(); - - // Update Buttons - mSellButton->setEnabled(mAmountItems > 0); - mDecreaseButton->setEnabled(mAmountItems > 0); - mIncreaseButton->setEnabled(mAmountItems < mMaxItems); } } void SellDialog::selectionChanged(const SelectionEvent &event) +{ + // Reset amount of items and update labels + mAmountItems = 0; + mSlider->setValue(0); + + updateButtonsAndLabels(); +} + +void SellDialog::setMoney(int amount) +{ + mPlayerMoney = amount; + mShopItemList->setPlayersMoney(amount); +} + +void +SellDialog::updateButtonsAndLabels() { int selectedItem = mShopItemList->getSelected(); + int income = 0; if (selectedItem > -1) { - const ItemInfo &info = - ItemDB::get(mShopItems->at(selectedItem).id); + mMaxItems = mShopItems->at(selectedItem).quantity; + if (mAmountItems > mMaxItems) + { + mAmountItems = mMaxItems; + } + income = mAmountItems * mShopItems->at(selectedItem).price; + + const ItemInfo &info = ItemDB::get(mShopItems->at(selectedItem).id); mItemDescLabel->setCaption("Description: " + info.getDescription()); mItemEffectLabel->setCaption("Effect: " + info.getEffect()); } else { - mItemDescLabel->setCaption("Description"); - mItemEffectLabel->setCaption("Effect"); + mMaxItems = 0; + mAmountItems = 0; + mItemDescLabel->setCaption("Description:"); + mItemEffectLabel->setCaption("Effect:"); } -} -void SellDialog::setMoney(int amount) -{ - mPlayerMoney = amount; - mShopItemList->setPlayersMoney(amount); + // Update Buttons and slider + mSellButton->setEnabled(mAmountItems > 0); + mDecreaseButton->setEnabled(mAmountItems > 0); + mIncreaseButton->setEnabled(mAmountItems < mMaxItems); + mSlider->setEnabled(selectedItem > -1); + + // Update the quantity and money labels + mQuantityLabel->setCaption( + toString(mAmountItems) + " / " + toString(mMaxItems)); + mQuantityLabel->adjustSize(); + mMoneyLabel->setCaption("Money: " + toString(income) + " GP / Total: " + + toString(mPlayerMoney + income) + " GP"); + mMoneyLabel->adjustSize(); } diff --git a/src/gui/sell.h b/src/gui/sell.h index 68bd7b8b..b8385a6f 100644 --- a/src/gui/sell.h +++ b/src/gui/sell.h @@ -82,6 +82,12 @@ class SellDialog : public Window, gcn::ActionListener, SelectionListener */ void setMoney(int amount); + /** + * Updates the state of buttons and labels. + */ + void + updateButtonsAndLabels(); + private: gcn::Button *mSellButton; gcn::Button *mIncreaseButton; diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index d8130cd3..ed75e5b3 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -157,6 +157,7 @@ void UpdaterWindow::setLabel(const std::string &str) void UpdaterWindow::enable() { + mCancelButton->setEnabled(false); mPlayButton->setEnabled(true); mPlayButton->requestFocus(); } @@ -168,11 +169,7 @@ void UpdaterWindow::action(const gcn::ActionEvent &event) // Register the user cancel mUserCancel = true; // Skip the updating process - if (mDownloadStatus == UPDATE_COMPLETE) - { - state = STATE_EXIT; - } - else + if (mDownloadStatus != UPDATE_COMPLETE) { mDownloadStatus = UPDATE_ERROR; } diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index f3e9031c..2af1d960 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -41,10 +41,13 @@ #include "../resources/animation.h" #include "../resources/monsterinfo.h" #include "../resources/resourcemanager.h" +#include "../resources/image.h" #include "../resources/imageset.h" #include "../utils/tostring.h" +#include + Viewport::Viewport(): mMap(0), mViewX(0.0f), @@ -67,37 +70,62 @@ Viewport::Viewport(): mPopupMenu = new PopupMenu(); // Load target cursors + loadTargetCursor("graphics/gui/target-cursor-blue-s.png", 44, 35, + false, Being::TC_SMALL); + loadTargetCursor("graphics/gui/target-cursor-red-s.png", 44, 35, + true, Being::TC_SMALL); + loadTargetCursor("graphics/gui/target-cursor-blue-m.png", 62, 44, + false, Being::TC_MEDIUM); + loadTargetCursor("graphics/gui/target-cursor-red-m.png", 62, 44, + true, Being::TC_MEDIUM); + loadTargetCursor("graphics/gui/target-cursor-blue-l.png", 82, 60, + false, Being::TC_LARGE); + loadTargetCursor("graphics/gui/target-cursor-red-l.png", 82, 60, + true, Being::TC_LARGE); +} + +void +Viewport::loadTargetCursor(std::string filename, int width, int height, + bool outRange, Being::TargetCursorSize size) +{ + assert(size > -1); + assert(size < 3); + + ImageSet* currentImageSet; + SimpleAnimation* currentCursor; + ResourceManager *resman = ResourceManager::getInstance(); - mInRangeImages = resman->getImageSet( - "graphics/gui/target-cursor-blue.png", 44, 35); - mOutRangeImages = resman->getImageSet( - "graphics/gui/target-cursor-red.png", 44, 35); - Animation *animInRange = new Animation(); - Animation *animOutRange = new Animation(); - - for (unsigned int i = 0; i < mInRangeImages->size(); ++i) + + currentImageSet = resman->getImageSet(filename, width, height); + Animation *anim = new Animation(); + for (unsigned int i = 0; i < currentImageSet->size(); ++i) { - animInRange->addFrame(mInRangeImages->get(i), 75, 0, 0); + anim->addFrame(currentImageSet->get(i), 75, 0, 0); } + currentCursor = new SimpleAnimation(anim); - for (unsigned int j = 0; j < mOutRangeImages->size(); ++j) + if (outRange) { - animOutRange->addFrame(mOutRangeImages->get(j), 75, 0, 0); + mOutRangeImages[size] = currentImageSet; + mTargetCursorOutRange[size] = currentCursor; + } + else { + mInRangeImages[size] = currentImageSet; + mTargetCursorInRange[size] = currentCursor; } - - mTargetCursorInRange = new SimpleAnimation(animInRange); - mTargetCursorOutRange = new SimpleAnimation(animOutRange); } Viewport::~Viewport() { delete mPopupMenu; - delete mTargetCursorInRange; - delete mTargetCursorOutRange; - - mInRangeImages->decRef(); - mOutRangeImages->decRef(); + for (int i = Being::TC_SMALL; i < Being::NUM_TC; i++) + { + delete mTargetCursorInRange[i]; + delete mTargetCursorOutRange[i]; + mInRangeImages[i]->decRef(); + mOutRangeImages[i]->decRef(); + } } void @@ -259,8 +287,11 @@ Viewport::logic() mWalkTime = player_node->mWalkTime; } - mTargetCursorInRange->update(10); - mTargetCursorOutRange->update(10); + for (int i = 0; i < 3; i++) + { + mTargetCursorInRange[i]->update(10); + mTargetCursorOutRange[i]->update(10); + } } void @@ -270,26 +301,31 @@ Viewport::drawTargetCursor(Graphics *graphics) Being *target = player_node->getTarget(); if (target) { + // Calculate target circle position + // Find whether target is in range int rangeX = abs(target->mX - player_node->mX); int rangeY = abs(target->mY - player_node->mY); int attackRange = player_node->getAttackRange(); - // Draw the target cursor, which one depends if the target is in range + // Get the correct target cursors graphic + Being::TargetCursorSize cursorSize = target->getTargetCursorSize(); + Image* targetCursor; if (rangeX > attackRange || rangeY > attackRange) { - // Draw the out of range cursor - graphics->drawImage(mTargetCursorOutRange->getCurrentImage(), - target->getPixelX() - mCameraX, - target->getPixelY() - mCameraY); + targetCursor = mTargetCursorOutRange[cursorSize]->getCurrentImage(); } - else - { - // Draw the in range cursor - graphics->drawImage(mTargetCursorInRange->getCurrentImage(), - target->getPixelX() - mCameraX, - target->getPixelY() - mCameraY); + else { + targetCursor = mTargetCursorInRange[cursorSize]->getCurrentImage(); } + + // Draw the target cursor at the correct position + int posX = target->getPixelX() + 16 - + targetCursor->getWidth() / 2 - mCameraX; + int posY = target->getPixelY() + 16 - + targetCursor->getHeight() / 2 - mCameraY; + + graphics->drawImage(targetCursor, posX, posY); } } @@ -304,10 +340,10 @@ Viewport::drawTargetName(Graphics *graphics) graphics->setColor(gcn::Color(255, 32, 32)); const MonsterInfo &mi = static_cast(target)->getInfo(); - graphics->drawText(mi.getName(), - target->getPixelX() - mCameraX + 15, - target->getPixelY() - mCameraY - 42, - gcn::Graphics::CENTER); + int posX = target->getPixelX() + 16 - mCameraX; + int posY = target->getPixelY() + 16 - target->getHeight() - mCameraY; + + graphics->drawText(mi.getName(), posX, posY, gcn::Graphics::CENTER); } } diff --git a/src/gui/viewport.h b/src/gui/viewport.h index 84efeff3..22d0f249 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -29,9 +29,9 @@ #include "windowcontainer.h" #include "../configlistener.h" +#include "../being.h" class Map; -class Being; class FloorItem; class ImageSet; class Item; @@ -141,6 +141,13 @@ class Viewport : public WindowContainer, public gcn::MouseListener, */ void showPopup(int x, int y, Being *being); + /** + * Helper function for loading target cursors + */ + void + loadTargetCursor(std::string filename, int width, int height, + bool outRange, Being::TargetCursorSize size); + /** * Draws range based target cursor */ @@ -164,14 +171,17 @@ class Viewport : public WindowContainer, public gcn::MouseListener, int mCameraY; /**< Current viewpoint in tiles. */ bool mShowDebugPath; /**< Show a path from player to pointer. */ - ImageSet *mInRangeImages; /**< Images of in range target cursor. */ - ImageSet *mOutRangeImages; /**< Images of out of range target cursor.*/ + /** Images of in range target cursor. */ + ImageSet *mInRangeImages[Being::NUM_TC]; + + /** Images of out of range target cursor. */ + ImageSet *mOutRangeImages[Being::NUM_TC]; /** Animated in range target cursor. */ - SimpleAnimation *mTargetCursorInRange; + SimpleAnimation *mTargetCursorInRange[Being::NUM_TC]; /** Animated out of range target cursor. */ - SimpleAnimation *mTargetCursorOutRange; + SimpleAnimation *mTargetCursorOutRange[Being::NUM_TC]; bool mPlayerFollowMouse; int mWalkTime; diff --git a/src/gui/widgets/resizegrip.cpp b/src/gui/widgets/resizegrip.cpp new file mode 100644 index 00000000..50a6fce4 --- /dev/null +++ b/src/gui/widgets/resizegrip.cpp @@ -0,0 +1,65 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#include "resizegrip.h" + +#include + +#include "../../graphics.h" + +#include "../../resources/image.h" +#include "../../resources/resourcemanager.h" + +Image *ResizeGrip::gripImage = 0; +int ResizeGrip::mInstances = 0; + +ResizeGrip::ResizeGrip() +{ + if (mInstances == 0) + { + // Load the grip image + ResourceManager *resman = ResourceManager::getInstance(); + gripImage = resman->getImage("graphics/gui/resize.png"); + } + + mInstances++; + + setWidth(gripImage->getWidth() + 2); + setHeight(gripImage->getHeight() + 2); +} + +ResizeGrip::~ResizeGrip() +{ + mInstances--; + + if (mInstances == 0) + { + gripImage->decRef(); + } +} + +void +ResizeGrip::draw(gcn::Graphics *graphics) +{ + dynamic_cast(graphics)->drawImage(gripImage, 0, 0); +} diff --git a/src/gui/widgets/resizegrip.h b/src/gui/widgets/resizegrip.h new file mode 100644 index 00000000..04be3db3 --- /dev/null +++ b/src/gui/widgets/resizegrip.h @@ -0,0 +1,61 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef _TMW_RESIZEGRIP_H +#define _TMW_RESIZEGRIP_H + +#include + +class Image; + +/** + * Resize grip. The resize grip is part of a resizable Window. It relies on the + * fact that uncaught mouse events are automatically routed to the parent + * window. + * + * \ingroup GUI + */ +class ResizeGrip : public gcn::Widget +{ + public: + /** + * Constructor. + */ + ResizeGrip(); + + /** + * Destructor. + */ + ~ResizeGrip(); + + /** + * Draws the resize grip. + */ + void draw(gcn::Graphics *graphics); + + private: + static Image *gripImage; /**< Resize grip image */ + static int mInstances; /**< Number of resize grip instances */ +}; + +#endif diff --git a/src/gui/window.cpp b/src/gui/window.cpp index bb60c6ff..8a052bba 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -24,10 +24,13 @@ #include "window.h" #include +#include #include "gccontainer.h" #include "windowcontainer.h" +#include "widgets/resizegrip.h" + #include "../configlistener.h" #include "../configuration.h" #include "../graphics.h" @@ -36,11 +39,10 @@ #include "../resources/image.h" #include "../resources/resourcemanager.h" -ConfigListener *Window::windowConfigListener = NULL; -WindowContainer *Window::windowContainer = NULL; +ConfigListener *Window::windowConfigListener = 0; +WindowContainer *Window::windowContainer = 0; int Window::instances = 0; ImageRect Window::border; -Image *Window::resizeGrip; class WindowConfigListener : public ConfigListener { @@ -54,16 +56,16 @@ class WindowConfigListener : public ConfigListener Window::Window(const std::string& caption, bool modal, Window *parent): gcn::Window(caption), + mGrip(0), mParent(parent), mWindowName("window"), - mSnapSize(8), mShowTitle(true), mModal(modal), mResizable(false), - mMouseResize(false), + mMouseResize(0), mSticky(false), mMinWinWidth(100), - mMinWinHeight(28), + mMinWinHeight(40), mMaxWinWidth(INT_MAX), mMaxWinHeight(INT_MAX) { @@ -87,7 +89,6 @@ Window::Window(const std::string& caption, bool modal, Window *parent): border.grid[6] = dBorders->getSubImage(0, 15, 4, 4); border.grid[7] = dBorders->getSubImage(4, 15, 3, 4); border.grid[8] = dBorders->getSubImage(7, 15, 4, 4); - resizeGrip = resman->getImage("graphics/gui/resize.png"); dBorders->decRef(); windowConfigListener = new WindowConfigListener(); // Send GUI alpha changed for initialization @@ -151,10 +152,10 @@ Window::~Window() delete border.grid[6]; delete border.grid[7]; delete border.grid[8]; - resizeGrip->decRef(); } delete mChrome; + delete mGrip; } void Window::setWindowContainer(WindowContainer *wc) @@ -162,22 +163,15 @@ void Window::setWindowContainer(WindowContainer *wc) windowContainer = wc; } -void Window::draw(gcn::Graphics* graphics) +void Window::draw(gcn::Graphics *graphics) { - Graphics *g = (Graphics*)graphics; + Graphics *g = static_cast(graphics); g->drawImageRect(0, 0, getWidth(), getHeight(), border); - // Draw grip - if (mResizable) - { - g->drawImage(Window::resizeGrip, - getWidth() - resizeGrip->getWidth(), - getHeight() - resizeGrip->getHeight()); - } - // Draw title - if (mShowTitle) { + if (mShowTitle) + { graphics->setFont(getFont()); graphics->drawText(getCaption(), 7, 5, gcn::Graphics::LEFT); } @@ -188,13 +182,13 @@ void Window::draw(gcn::Graphics* graphics) void Window::setContentWidth(int width) { mChrome->setWidth(width); - resizeToContent(); + setWidth(width + 2 * getPadding()); } void Window::setContentHeight(int height) { mChrome->setHeight(height); - resizeToContent(); + setHeight(height + getPadding() + getTitleBarHeight()); } void Window::setContentSize(int width, int height) @@ -203,6 +197,37 @@ void Window::setContentSize(int width, int height) setContentHeight(height); } +void Window::setWidth(int width) +{ + gcn::Window::setWidth(width); + + if (mGrip) + { + mGrip->setX(getWidth() - mGrip->getWidth() - getChildrenArea().x); + } +} + +void Window::setHeight(int height) +{ + gcn::Window::setHeight(height); + + if (mGrip) + { + mGrip->setY(getHeight() - mGrip->getHeight() - getChildrenArea().y); + } +} + +void Window::setDimension(const gcn::Rectangle &dimension) +{ + gcn::Window::setDimension(dimension); + + if (mGrip) + { + mGrip->setX(getWidth() - mGrip->getWidth() - getChildrenArea().x); + mGrip->setY(getHeight() - mGrip->getHeight() - getChildrenArea().y); + } +} + void Window::setLocationRelativeTo(gcn::Widget *widget) { int wx, wy; @@ -238,6 +263,19 @@ void Window::setMaxHeight(unsigned int height) void Window::setResizable(bool r) { mResizable = r; + + if (mResizable) + { + mGrip = new ResizeGrip(); + mGrip->setX(getWidth() - mGrip->getWidth() - getChildrenArea().x); + mGrip->setY(getHeight() - mGrip->getHeight() - getChildrenArea().y); + gcn::Window::add(mGrip); + } + else + { + delete mGrip; + mGrip = 0; + } } bool Window::isResizable() @@ -287,15 +325,27 @@ void Window::mousePressed(gcn::MouseEvent &event) // Let Guichan move window to top and figure out title bar drag gcn::Window::mousePressed(event); - int x = event.getX(); - int y = event.getY(); + const int x = event.getX(); + const int y = event.getY(); + mMouseResize = 0; - // Activate resizing if the left mouse button was pressed on the grip - mMouseResize = - isResizable() && - event.getButton() == gcn::MouseEvent::LEFT && - getGripDimension().isPointInRect(x, y) && - !getChildrenArea().isPointInRect(x, y); + // Activate resizing handles as appropriate + if (event.getSource() == this && isResizable() && + event.getButton() == gcn::MouseEvent::LEFT && + !getChildrenArea().isPointInRect(x, y)) + { + mMouseResize |= (x > getWidth() - resizeBorderWidth) ? RIGHT : + (x < resizeBorderWidth) ? LEFT : 0; + mMouseResize |= (y > getHeight() - resizeBorderWidth) ? BOTTOM : + (y < resizeBorderWidth) ? TOP : 0; + } + else if (event.getSource() == mGrip) + { + mDragOffsetX = x + mGrip->getX(); + mDragOffsetY = y + mGrip->getY(); + mMouseResize |= BOTTOM | RIGHT; + mIsMoving = false; + } } void Window::mouseDragged(gcn::MouseEvent &event) @@ -303,20 +353,47 @@ void Window::mouseDragged(gcn::MouseEvent &event) // Let Guichan handle title bar drag gcn::Window::mouseDragged(event); - // Keep guichan window inside screen - int newX = std::max(0, getX()); - int newY = std::max(0, getY()); - newX = std::min(windowContainer->getWidth() - getWidth(), newX); - newY = std::min(windowContainer->getHeight() - getHeight(), newY); - setPosition(newX, newY); + // Keep guichan window inside screen when it may be moved + if (isMovable() && mIsMoving) + { + int newX = std::max(0, getX()); + int newY = std::max(0, getY()); + newX = std::min(windowContainer->getWidth() - getWidth(), newX); + newY = std::min(windowContainer->getHeight() - getHeight(), newY); + setPosition(newX, newY); + } if (mMouseResize && !mIsMoving) { + const int dx = event.getX() - mDragOffsetX + + ((event.getSource() == mGrip) ? mGrip->getX() : 0); + const int dy = event.getY() - mDragOffsetY + + ((event.getSource() == mGrip) ? mGrip->getY() : 0); gcn::Rectangle newDim = getDimension(); - // We're dragging bottom right - newDim.width += event.getX() - mDragOffsetX; - newDim.height += event.getY() - mDragOffsetY; + if (mMouseResize & (TOP | BOTTOM)) + { + int newHeight = newDim.height + ((mMouseResize & TOP) ? -dy : dy); + newDim.height = std::min(mMaxWinHeight, + std::max(mMinWinHeight, newHeight)); + + if (mMouseResize & TOP) + { + newDim.y -= newDim.height - getHeight(); + } + } + + if (mMouseResize & (LEFT | RIGHT)) + { + int newWidth = newDim.width + ((mMouseResize & LEFT) ? -dx : dx); + newDim.width = std::min(mMaxWinWidth, + std::max(mMinWinWidth, newWidth)); + + if (mMouseResize & LEFT) + { + newDim.x -= newDim.width - getWidth(); + } + } // Keep guichan window inside screen (supports resizing any side) if (newDim.x < 0) @@ -338,29 +415,16 @@ void Window::mouseDragged(gcn::MouseEvent &event) newDim.height = windowContainer->getHeight() - newDim.y; } - // Keep the window at least its minimum size - if (newDim.width < mMinWinWidth) - { - newDim.width = mMinWinWidth; - } - else if (newDim.width > mMaxWinWidth) - { - newDim.width = mMaxWinWidth; - } - - if (newDim.height < mMinWinHeight) + // Update mouse offset when dragging bottom or right border + if (mMouseResize & BOTTOM) { - newDim.height = mMinWinHeight; + mDragOffsetY += newDim.height - getHeight(); } - else if (newDim.height > mMaxWinHeight) + if (mMouseResize & RIGHT) { - newDim.height = mMaxWinHeight; + mDragOffsetX += newDim.width - getWidth(); } - // Update mouse offset when dragging bottom or right border - mDragOffsetX += newDim.width - getWidth(); - mDragOffsetY += newDim.height - getHeight(); - // Set the new window and content dimensions setDimension(newDim); const gcn::Rectangle area = getChildrenArea(); @@ -368,15 +432,6 @@ void Window::mouseDragged(gcn::MouseEvent &event) } } -gcn::Rectangle -Window::getGripDimension() -{ - return gcn::Rectangle(getWidth() - resizeGrip->getWidth(), - getHeight() - resizeGrip->getHeight(), - getWidth(), - getHeight()); -} - void Window::loadWindowState() { diff --git a/src/gui/window.h b/src/gui/window.h index 31c260cf..03248908 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -30,11 +30,10 @@ class ConfigListener; class GCContainer; -class Image; class ImageRect; +class ResizeGrip; class WindowContainer; - /** * A window. This window can be dragged around and has a title bar. Windows are * invisible by default. @@ -99,6 +98,21 @@ class Window : public gcn::Window */ void setContentSize(int width, int height); + /** + * Sets the width of this window. + */ + void setWidth(int width); + + /** + * Sets the height of this window. + */ + void setHeight(int height); + + /** + * Sets the position and size of this window. + */ + void setDimension(const gcn::Rectangle &dimension); + /** * Sets the location relative to the given widget. */ @@ -168,16 +182,15 @@ class Window : public gcn::Window void scheduleDelete(); /** - * Window dragging and resizing mouse related. These methods also makes - * sure the window is not dragged/resized outside of the screen. + * Starts window resizing when appropriate. */ void mousePressed(gcn::MouseEvent &event); - void mouseDragged(gcn::MouseEvent &event); /** - * Gets the position of the resize grip. + * Implements window resizing and makes sure the window is not + * dragged/resized outside of the screen. */ - gcn::Rectangle getGripDimension(); + void mouseDragged(gcn::MouseEvent &event); /** * Sets the name of the window. This is not the window title. @@ -214,37 +227,50 @@ class Window : public gcn::Window */ virtual void resetToDefaultSize(); + enum ResizeHandles + { + TOP = 0x01, + RIGHT = 0x02, + BOTTOM = 0x04, + LEFT = 0x08 + }; + protected: - GCContainer *mChrome; /**< Contained container */ + GCContainer *mChrome; /**< Contained container */ + ResizeGrip *mGrip; /**< Resize grip */ Window *mParent; /**< The parent window */ std::string mWindowName; /**< Name of the window */ - int mSnapSize; /**< Snap distance to window edge */ bool mShowTitle; /**< Window has a title bar */ bool mModal; /**< Window is modal */ - bool mResizable; /**< Window can be resized */ - bool mMouseResize; /**< Window is being resized */ - bool mSticky; /**< Window resists minimzation */ - int mMinWinWidth; /**< Minimum window width */ - int mMinWinHeight; /**< Minimum window height */ - int mMaxWinWidth; /**< Maximum window width */ - int mMaxWinHeight; /**< Maximum window height */ + bool mResizable; /**< Window can be resized */ + int mMouseResize; /**< Window is being resized */ + bool mSticky; /**< Window resists minimization */ + int mMinWinWidth; /**< Minimum window width */ + int mMinWinHeight; /**< Minimum window height */ + int mMaxWinWidth; /**< Maximum window width */ + int mMaxWinHeight; /**< Maximum window height */ int mDefaultX; /**< Default window X position */ int mDefaultY; /**< Default window Y position */ int mDefaultWidth; /**< Default window width */ int mDefaultHeight; /**< Default window height */ /** The window container windows add themselves to. */ - static WindowContainer* windowContainer; + static WindowContainer *windowContainer; /** - * The config listener that listens to changes relevant to all - * windows + * The config listener that listens to changes relevant to all windows. */ static ConfigListener *windowConfigListener; static int instances; /**< Number of Window instances */ static ImageRect border; /**< The window border and background */ - static Image *resizeGrip; /**< The grip to resize window */ + + /** + * The width of the resize border. Is independent of the actual window + * border width, and determines mostly the size of the corner area + * where two borders are moved at the same time. + */ + static const int resizeBorderWidth = 10; }; #endif diff --git a/src/imageparticle.cpp b/src/imageparticle.cpp new file mode 100644 index 00000000..35cc21ad --- /dev/null +++ b/src/imageparticle.cpp @@ -0,0 +1,69 @@ +/* + * The Mana World + * Copyright 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#include "imageparticle.h" + +#include "graphics.h" + +#include "resources/image.h" + +ImageParticle::ImageParticle(Map *map, Image *image): + Particle(map), + mImage(image) +{ + mImage->incRef(); +} + +ImageParticle::~ImageParticle() +{ + mImage->decRef(); +} + +void ImageParticle::draw(Graphics *graphics, int offsetX, int offsetY) const +{ + if (!mAlive) + return; + + int screenX = (int) mPosX + offsetX - mImage->getWidth() / 2; + int screenY = (int) mPosY - (int) mPosZ + offsetY - mImage->getHeight()/2; + + // Check if on screen + if (screenX + mImage->getWidth() < 0 || + screenX > graphics->getWidth() || + screenY + mImage->getHeight() < 0 || + screenY > graphics->getHeight()) + { + return; + } + + float alphafactor = 1.0f; + + if (mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut) + alphafactor *= (float) mLifetimeLeft / (float) mFadeOut; + + if (mLifetimePast < mFadeIn) + alphafactor *= (float) mLifetimePast / (float) mFadeIn; + + mImage->setAlpha(alphafactor); + graphics->drawImage(mImage, screenX, screenY); +} diff --git a/src/imageparticle.h b/src/imageparticle.h new file mode 100644 index 00000000..0ad515cc --- /dev/null +++ b/src/imageparticle.h @@ -0,0 +1,61 @@ +/* + * The Mana World + * Copyright 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef _IMAGEPARTICLE_H +#define _IMAGEPARTICLE_H + +#include "particle.h" + +class Image; +class Map; + +/** + * A particle that uses an image for its visualization. + */ +class ImageParticle : public Particle +{ + public: + /** + * Constructor. The image is reference counted by this particle. + * + * @param map the map this particle appears on + * @param image an Image instance, may not be NULL + */ + ImageParticle(Map *map, Image *image); + + /** + * Destructor. + */ + ~ImageParticle(); + + /** + * Draws the particle image + */ + virtual void + draw(Graphics *graphics, int offsetX, int offsetY) const; + + protected: + Image *mImage; /**< The image used for this particle. */ +}; + +#endif diff --git a/src/main.cpp b/src/main.cpp index bbbf0fd1..58c563ab 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,7 +40,7 @@ #include -#if (defined __USE_UNIX98 || defined __FreeBSD__ || defined __APPLE__) +#ifndef WIN32 #include #include #endif @@ -148,21 +148,21 @@ struct Options */ void initHomeDir() { -#if !(defined __USE_UNIX98 || defined __FreeBSD__ || defined __APPLE__) - homeDir = "."; -#else homeDir = std::string(PHYSFS_getUserDir()) + "/.tmw"; - +#if defined WIN32 + if (!CreateDirectory(homeDir.c_str(), 0) && + GetLastError() != ERROR_ALREADY_EXISTS) +#else // Checking if /home/user/.tmw folder exists. if ((mkdir(homeDir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) && (errno != EEXIST)) +#endif { std::cout << homeDir - << " can't be made, but it doesn't exist! Exiting." + << " can't be created, but it doesn't exist! Exiting." << std::endl; exit(1); } -#endif } /** @@ -236,11 +236,17 @@ void initEngine() static SDL_SysWMinfo pInfo; SDL_GetWMInfo(&pInfo); HICON icon = LoadIcon(GetModuleHandle(NULL), "A"); - SetClassLong(pInfo.window, GCL_HICON, (LONG) icon); + if (icon) + { + SetClassLong(pInfo.window, GCL_HICON, (LONG) icon); + } #else SDL_Surface *icon = IMG_Load(TMW_DATADIR "data/icons/tmw.png"); - SDL_SetAlpha(icon, SDL_SRCALPHA, SDL_ALPHA_OPAQUE); - SDL_WM_SetIcon(icon, NULL); + if (icon) + { + SDL_SetAlpha(icon, SDL_SRCALPHA, SDL_ALPHA_OPAQUE); + SDL_WM_SetIcon(icon, NULL); + } #endif ResourceManager *resman = ResourceManager::getInstance(); diff --git a/src/map.cpp b/src/map.cpp index a6beb951..ac570627 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -29,6 +29,7 @@ #include "beingmanager.h" #include "game.h" #include "graphics.h" +#include "particle.h" #include "sprite.h" #include "tileset.h" @@ -530,3 +531,25 @@ Map::findPath(int startX, int startY, int destX, int destY) return path; } + +void +Map::addParticleEffect (std::string effectFile, int x, int y) +{ + ParticleEffectData newEffect; + newEffect.file = effectFile; + newEffect.x = x; + newEffect.y = y; + particleEffects.push_back(newEffect); +} + +void +Map::initializeParticleEffects(Particle* particleEngine) +{ + for (std::list::iterator i = particleEffects.begin(); + i != particleEffects.end(); + i++ + ) + { + particleEngine->addEffect(i->file, i->x, i->y); + } +} diff --git a/src/map.h b/src/map.h index c8a6fdb3..17772847 100644 --- a/src/map.h +++ b/src/map.h @@ -32,8 +32,9 @@ class AmbientOverlay; class Graphics; class Image; -class Tileset; +class Particle; class Sprite; +class Tileset; struct PATH_NODE; @@ -185,6 +186,17 @@ class Map : public Properties void removeSprite(SpriteIterator iterator); + /** + * Adds a particle effect + */ + void addParticleEffect (std::string effectFile, int x, int y); + + /** + * Initializes all added particle effects + */ + void + initializeParticleEffects(Particle* particleEngine); + private: /** * Converts a global tile id to the Image* pointing to the associated @@ -220,10 +232,19 @@ class Map : public Properties // Pathfinding members int mOnClosedList, mOnOpenList; - //overlay Data + // Overlay Data std::list mOverlays; float mLastScrollX; float mLastScrollY; + + // Particle effect data + struct ParticleEffectData + { + std::string file; + int x; + int y; + }; + std::list particleEffects; }; #endif diff --git a/src/monster.cpp b/src/monster.cpp index bea5b7a5..768bf16a 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -93,6 +93,12 @@ Monster::handleAttack() sound.playSfx(mi.getSound(EVENT_HIT)); } +Being::TargetCursorSize +Monster::getTargetCursorSize() const +{ + return getInfo().getTargetCursorSize(); +} + const MonsterInfo& Monster::getInfo() const { diff --git a/src/monster.h b/src/monster.h index 39bbf3d7..4915520d 100644 --- a/src/monster.h +++ b/src/monster.h @@ -37,6 +37,9 @@ class Monster : public Being virtual Type getType() const; + virtual TargetCursorSize + getTargetCursorSize() const; + /** * Handles an attack of another being by this monster. Plays a hit or * miss sound when appropriate. diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index 53746671..f82a0fa8 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -34,6 +34,7 @@ #include "../localplayer.h" #include "../log.h" #include "../main.h" +#include "../particle.h" #include "../sound.h" const int EMOTION_TIME = 150; /**< Duration of emotion icon */ @@ -240,13 +241,23 @@ void BeingHandler::handleMessage(MessageIn &msg) break; case SMSG_BEING_LEVELUP: - if ((Uint32) msg.readLong() == player_node->getId()) { + id = (Uint32) msg->readLong(); + + if (id == player_node->getId()) { logger->log("Level up"); sound.playSfx("sfx/levelup.ogg"); - } else { + } + else { logger->log("Someone else went level up"); } - msg.readLong(); // type + Particle *levelupFX; + if (msg->readLong() == 0) { // type + levelupFX = particleEngine->addEffect("graphics/particles/levelup.particle.xml", 0, 0); + } + else { + levelupFX = particleEngine->addEffect("graphics/particles/skillup.particle.xml", 0, 0); + } + beingManager->findBeing(id)->controlParticle(levelupFX); break; case SMSG_BEING_EMOTION: diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index ec6c1ee3..f4cda0b9 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -261,7 +261,7 @@ void OpenGLGraphics::drawPoint(int x, int y) setTexturingAndBlending(false); glBegin(GL_POINTS); - glVertex3i(x, y, 0); + glVertex2i(x, y); glEnd(); } @@ -270,12 +270,12 @@ void OpenGLGraphics::drawLine(int x1, int y1, int x2, int y2) setTexturingAndBlending(false); glBegin(GL_LINES); - glVertex3f(x1 + 0.5f, y1 + 0.5f, 0); - glVertex3f(x2 + 0.5f, y2 + 0.5f, 0); + glVertex2f(x1 + 0.5f, y1 + 0.5f); + glVertex2f(x2 + 0.5f, y2 + 0.5f); glEnd(); glBegin(GL_POINTS); - glVertex3f(x2 + 0.5f, y2 + 0.5f, 0); + glVertex2f(x2 + 0.5f, y2 + 0.5f); glEnd(); } @@ -329,10 +329,10 @@ void OpenGLGraphics::drawRectangle(const gcn::Rectangle& rect, bool filled) setTexturingAndBlending(false); glBegin(filled ? GL_QUADS : GL_LINE_LOOP); - glVertex3f(rect.x + offset, rect.y + offset, 0); - glVertex3f(rect.x + rect.width - offset, rect.y + offset, 0); - glVertex3f(rect.x + rect.width - offset, rect.y + rect.height - offset, 0); - glVertex3f(rect.x + offset, rect.y + rect.height - offset, 0); + glVertex2f(rect.x + offset, rect.y + offset); + glVertex2f(rect.x + rect.width - offset, rect.y + offset); + glVertex2f(rect.x + rect.width - offset, rect.y + rect.height - offset); + glVertex2f(rect.x + offset, rect.y + rect.height - offset); glEnd(); } @@ -344,16 +344,16 @@ void OpenGLGraphics::drawTexedQuad(int x, int y, int w, int h, // Draw a textured quad glBegin(GL_QUADS); glTexCoord2f(texX1, texY1); - glVertex3i(x, y, 0); + glVertex2i(x, y); glTexCoord2f(texX2, texY1); - glVertex3i(x + w, y, 0); + glVertex2i(x + w, y); glTexCoord2f(texX2, texY2); - glVertex3i(x + w, y + h, 0); + glVertex2i(x + w, y + h); glTexCoord2f(texX1, texY2); - glVertex3i(x, y + h, 0); + glVertex2i(x, y + h); glEnd(); } diff --git a/src/particle.cpp b/src/particle.cpp new file mode 100644 index 00000000..509c20ee --- /dev/null +++ b/src/particle.cpp @@ -0,0 +1,370 @@ +/* + * The Mana World + * Copyright 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#include "particle.h" + +#include + +#include "animationparticle.h" +#include "configuration.h" +#include "imageparticle.h" +#include "log.h" +#include "map.h" +#include "particleemitter.h" +#include "textparticle.h" + +#include "resources/resourcemanager.h" + +#include "utils/dtor.h" +#include "utils/fastsqrt.h" +#include "utils/xml.h" + +class Graphics; +class Image; + +int Particle::particleCount = 0; +int Particle::maxCount = 0; +int Particle::fastPhysics = 0; +int Particle::emitterSkip = 1; +const float Particle::PARTICLE_SKY = 800.0f; + +Particle::Particle(Map *map): + mAlive(true), + mPosX(0.0f), mPosY(0.0f), mPosZ(0.0f), + mLifetimeLeft(-1), + mLifetimePast(0), + mFadeOut(0), + mFadeIn(0), + mAutoDelete(true), + mMap(map), + mVectorX(0.0f), mVectorY(0.0f), mVectorZ(0.0f), + mGravity(0.0f), + mRandomnes(0), + mBounce(0.0f), + mTarget(NULL), + mAcceleration(0.0f), + mInvDieDistance(-1.0f), + mMomentum(1.0f) +{ + Particle::particleCount++; + if (mMap) setSpriteIterator(mMap->addSprite(this)); +} + + +void +Particle::setupEngine() +{ + Particle::maxCount = (int)config.getValue("particleMaxCount", 3000); + Particle::fastPhysics = (int)config.getValue("particleFastPhysics", 0); + Particle::emitterSkip = (int)config.getValue("particleEmitterSkip", 0) + 1; + disableAutoDelete(); + logger->log("Particle engine set up"); +} + +bool +Particle::update() +{ + if (!mMap) return false; + + if (mLifetimeLeft == 0) + { + mAlive = false; + } + + if (mAlive) + { + // Update child emitters + if (mLifetimePast%Particle::emitterSkip == 0) + { + for ( EmitterIterator e = mChildEmitters.begin(); + e != mChildEmitters.end(); + e++ + ) + { + Particles newParticles = (*e)->createParticles(); + for ( ParticleIterator p = newParticles.begin(); + p != newParticles.end(); + p++ + ) + { + (*p)->moveBy(mPosX, mPosY, mPosZ); + mChildParticles.push_back (*p); + } + } + } + + if (mMomentum != 1.0f) + { + mVectorX *= mMomentum; + mVectorY *= mMomentum; + mVectorZ *= mMomentum; + } + + if (mTarget && mAcceleration != 0.0f) + { + float distX = mPosX - mTarget->getPosX(); + float distY = mPosY - mTarget->getPosY(); + float distZ = mPosZ - mTarget->getPosZ(); + float invHypotenuse; + + switch(Particle::fastPhysics) + { + case 1: + invHypotenuse = fastInvSqrt( + distX * distX + distY * distY + distZ * distZ); + break; + case 2: + invHypotenuse = 2.0f / + fabs(distX) + fabs(distY) + fabs(distZ); + break; + default: + invHypotenuse = 1.0f / sqrt( + distX * distX + distY * distY + distZ * distZ); + break; + } + + if (invHypotenuse) + { + if (mInvDieDistance > 0.0f && invHypotenuse > mInvDieDistance) + { + mAlive = false; + } + float accFactor = invHypotenuse * mAcceleration; + mVectorX -= distX * accFactor; + mVectorY -= distY * accFactor; + mVectorZ -= distZ * accFactor; + } + } + + if (mRandomnes > 0) + { + mVectorX += (rand()%mRandomnes - rand()%mRandomnes) / 1000.0f; + mVectorY += (rand()%mRandomnes - rand()%mRandomnes) / 1000.0f; + mVectorZ += (rand()%mRandomnes - rand()%mRandomnes) / 1000.0f; + } + + mVectorZ -= mGravity; + + // Update position + mPosX += mVectorX; + mPosY += mVectorY; + mPosZ += mVectorZ; + + // Update other stuff + if (mLifetimeLeft > 0) + { + mLifetimeLeft--; + } + mLifetimePast++; + + if (mPosZ > PARTICLE_SKY || mPosZ < 0.0f) + { + if (mBounce > 0.0f) + { + mPosZ *= -mBounce; + mVectorX *= mBounce; + mVectorY *= mBounce; + mVectorZ *= -mBounce; + } + else { + mAlive = false; + } + } + } + + // Update child particles + for ( ParticleIterator p = mChildParticles.begin(); + p != mChildParticles.end(); + + ) + { + if ((*p)->update()) + { + p++; + } else { + delete (*p); + p = mChildParticles.erase(p); + } + } + + if (!mAlive && mChildParticles.empty() && mAutoDelete) + { + return false; + } + + return true; +} + + +void Particle::draw(Graphics *graphics, int offsetX, int offsetY) const +{ +} + + +Particle* +Particle::addEffect(std::string particleEffectFile, int pixelX, int pixelY) +{ + Particle *newParticle = NULL; + + // XML parser initialisation stuff + int size; + ResourceManager *resman = ResourceManager::getInstance(); + char *data = (char*) resman->loadFile(particleEffectFile.c_str(), size); + + if (!data) { + logger->log("Warning: Particle engine could not find %s !", + particleEffectFile.c_str()); + return NULL; + } + + xmlDocPtr doc = xmlParseMemory(data, size); + free(data); + + if (!doc) { + logger->log("Warning: Particle engine found syntax error in %s!", + particleEffectFile.c_str()); + return NULL; + } + + xmlNodePtr rootNode = xmlDocGetRootElement(doc); + if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "effect")) + { + logger->log("Warning: %s is not a valid particle effect definition file!", + particleEffectFile.c_str()); + return NULL; + } + + // Parse particles + for_each_xml_child_node(effectChildNode, rootNode) + { + // We're only interested in particles + if (!xmlStrEqual(effectChildNode->name, BAD_CAST "particle")) + continue; + + // Determine the exact particle type + xmlNodePtr node; + + // Animation + if ((node = XML::findFirstChildByName( + effectChildNode, "animation"))) { + newParticle = new AnimationParticle(mMap, node); + } + // Image + else if ((node = XML::findFirstChildByName( + effectChildNode, "image"))) { + Image *img= resman->getImage((const char*) + node->xmlChildrenNode->content); + + newParticle = new ImageParticle(mMap, img); + } + // Other + else { + newParticle = new Particle(mMap); + } + + // Read and set the basic properties of the particle + int offsetX = XML::getProperty(effectChildNode, "position-x", 0); + int offsetY = XML::getProperty(effectChildNode, "position-y", 0); + int offsetZ = XML::getProperty(effectChildNode, "position-z", 0); + + int particleX = (int)mPosX + pixelX + offsetX; + int particleY = (int)mPosY + pixelY + offsetY; + int particleZ = (int)mPosZ + offsetZ; + + int lifetime = XML::getProperty(effectChildNode, "lifetime", -1); + + newParticle->setPosition(particleX, particleY, particleZ); + newParticle->setLifetime(lifetime); + + // Look for additional emitters for this particle + for_each_xml_child_node(emitterNode, effectChildNode) + { + if (!xmlStrEqual(emitterNode->name, BAD_CAST "emitter")) + continue; + + ParticleEmitter *newEmitter; + newEmitter = new ParticleEmitter(emitterNode, newParticle, mMap); + newParticle->addEmitter(newEmitter); + } + + mChildParticles.push_back(newParticle); + } + + return newParticle; +} + + +Particle* +Particle::addTextSplashEffect(std::string text, + int colorR, int colorG, int colorB, + gcn::Font *font, int x, int y) +{ + Particle *newParticle = new TextParticle(mMap, text, colorR, colorG, colorB, + font); + newParticle->setPosition(x, y, 0); + newParticle->setVector ( ((rand()%100) - 50) / 200.0f, // X vector + ((rand()%100) - 50) / 200.0f, // Y vector + ((rand()%100) / 200.0f) + 4.0f // Z vector + ); + newParticle->setGravity(0.1f); + newParticle->setBounce(0.5f); + newParticle->setLifetime(200); + newParticle->setFadeOut(100); + + mChildParticles.push_back(newParticle); + + return newParticle; +} + + +void +Particle::setMap(Map *map) +{ + mMap = map; + if (mMap) setSpriteIterator(mMap->addSprite(this)); + + // TODO: Create map emitters based on emitter data in map data +} + + +Particle::~Particle() +{ + // Remove from map sprite list + if (mMap) mMap->removeSprite(mSpriteIterator); + // Delete child emitters and child particles + clear(); + Particle::particleCount--; +} + + +void +Particle::clear() +{ + std::for_each(mChildEmitters.begin(), mChildEmitters.end(), + make_dtor(mChildEmitters)); + mChildEmitters.clear(); + + std::for_each(mChildParticles.begin(), mChildParticles.end(), + make_dtor(mChildParticles)); + mChildParticles.clear(); +} diff --git a/src/particle.h b/src/particle.h new file mode 100644 index 00000000..7a747a5f --- /dev/null +++ b/src/particle.h @@ -0,0 +1,288 @@ +/* + * The Mana World + * Copyright 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef _PARTICLE_H +#define _PARTICLE_H + +#include +#include + +#include + +#include "guichanfwd.h" +#include "sprite.h" + + +class Map; +class Particle; +class ParticleEmitter; + +typedef std::list Particles; +typedef Particles::iterator ParticleIterator; +typedef std::list Emitters; +typedef Emitters::iterator EmitterIterator; + +/** + * A particle spawned by a ParticleEmitter. + */ +class Particle : public Sprite +{ + public: + static const float PARTICLE_SKY; /**< Maximum Z position of particles */ + static int fastPhysics; /**< Mode of squareroot calculation */ + static int particleCount; /**< Current number of particles */ + static int maxCount; /**< Maximum number of particles */ + static int emitterSkip; /**< Duration of pause between two emitter updates in ticks */ + + /** + * Constructor. + * + * @param map the map this particle will add itself to, may be NULL + */ + Particle(Map *map); + + /** + * Destructor. + */ + ~Particle(); + + /** + * Deletes all child particles and emitters + */ + void + clear(); + + /** + * Gives a particle the properties of an engine root particle and loads + * the particle-related config settings + */ + void + setupEngine(); + + /** + * Updates particle position, returns false when the particle should + * be deleted + */ + virtual bool + update(); + + /** + * Draws the particle image + */ + virtual void + draw(Graphics *graphics, int offsetX, int offsetY) const; + + /** + * Necessary for sorting with the other sprites + */ + virtual int + getPixelY() const + { + return (int)(mPosY + mPosZ) - 64; + }; + + /* + Basic Particle properties: + */ + + /** + * Sets the map the particle is on. + */ + void setMap(Map *map); + + /** + * Creates a child particle that hosts some emitters described in the + * particleEffectFile. + */ + Particle* + addEffect(std::string particleEffectFile, int pixelX, int pixelY); + + /** + * Creates a standalone text particle. + */ + Particle* + addTextSplashEffect(std::string text, int colorR, int colorG, int colorB, + gcn::Font *font, int x, int y); + + /** + * Adds an emitter to the particle. + */ + void + addEmitter (ParticleEmitter* emitter) + { mChildEmitters.push_back(emitter); } + + /** + * Sets the position in 3 dimensional space in pixels relative to map + */ + void + setPosition(float x, float y, float z) + { mPosX = x; mPosY = y; mPosZ = z; } + + /** + * Sets the position in 2 dimensional space in pixels relative to map + */ + void + setPosition(float x, float y) + { mPosX = x; mPosY = y; } + + float getPosX() const + { return mPosX; } + + float getPosY() const + { return mPosY; } + + float getPosZ() const + { return mPosZ; } + + /** + * Changes the particle position relative + */ + void + moveBy(float x, float y, float z) + { mPosX += x; mPosY += y; mPosZ += z; } + + /** + * Sets the time in game ticks until the particle is destroyed. + */ + void + setLifetime(int lifetime) + { mLifetimeLeft = lifetime; mLifetimePast = 0; } + + /** + * Sets the age of the pixel in game ticks where the particle has + * faded in completely + */ + void + setFadeOut (int fadeOut) + { mFadeOut = fadeOut; } + + /** + * Sets the remaining particle lifetime where the particle starts to + * fade out + */ + void + setFadeIn (int fadeIn) + { mFadeIn = fadeIn; } + + /** + * Sets the sprite iterator of the particle on the current map to make + * it easier to remove the particle from the map when it is destroyed + */ + void + setSpriteIterator(std::list::iterator spriteIterator) + { mSpriteIterator = spriteIterator; } + + /** + * Gets the sprite iterator of the particle on the current map + */ + std::list::iterator + getSpriteIterator() const + { return mSpriteIterator; } + + /** + * Sets the current velocity in 3 dimensional space + */ + void + setVector(float x, float y, float z) + { mVectorX = x; mVectorY = y; mVectorZ = z; } + + /** + * Sets the downward acceleration + */ + void + setGravity(float g) + { mGravity = g; } + + /** + * Sets the ammount of random vector changes + */ + void + setRandomnes(int r) + { mRandomnes = r; } + + /** + * Sets the ammount of velocity particles retain after + * hitting the ground. + */ + void + setBounce(float bouncieness) + { mBounce = bouncieness; } + + /** + * Makes the particle move toward another particle with a + * given acceleration and momentum + */ + void setDestination(Particle *target, float accel, float moment) + { mTarget = target; mAcceleration = accel; mMomentum = moment; } + + /** + * Sets the distance in pixel the particle can come near the target + * particle before it is destroyed. Does only make sense after a + * target particle has been set using setDestination. + */ + void setDieDistance(float dist) + { mInvDieDistance = 1.0f / dist; } + + /** + * Manually marks the particle for deletion + */ + void kill() + { mAlive = false; mAutoDelete = true; } + + /** + * After calling this function the particle will only request + * deletion when kill() is called + */ + void disableAutoDelete() + { mAutoDelete = false; } + + protected: + bool mAlive; /**< Is the particle supposed to be drawn and updated?*/ + float mPosX, mPosY, mPosZ; /**< Position in 3 dimensonal space - pixel based relative to map */ + int mLifetimeLeft; /**< Lifetime left in game ticks*/ + int mLifetimePast; /**< Age of the particle in game ticks*/ + int mFadeOut; /**< Lifetime in game ticks left where fading out begins*/ + int mFadeIn; /**< Age in game ticks where fading in is finished*/ + + private: + // generic properties + bool mAutoDelete; /**< May the particle request its deletion by the parent particle?*/ + Map *mMap; /**< Map the particle is on*/ + std::list::iterator mSpriteIterator; /**< iterator of the particle on the current map */ + Emitters mChildEmitters; /**< List of child emitters*/ + Particles mChildParticles; /**< List of particles controlled by this particle*/ + //dynamic particle + float mVectorX, mVectorY, mVectorZ; /**< Speed in 3 dimensional space in pixels per game-tick */ + float mGravity; /**< Downward acceleration in pixels per game-tick²*/ + int mRandomnes; /**< Ammount of random vector change*/ + float mBounce; /**< How much the particle bounces off when hitting the ground*/ + //follow-point particles + Particle *mTarget; /**< The particle that attracts this particle*/ + float mAcceleration; /**< Acceleration towards the target particle in pixels per game-tick²*/ + float mInvDieDistance; /**< Distance in pixels from the target particle that causes the destruction of the particle*/ + float mMomentum; /**< How much speed the particle retains after each game tick*/ +}; + +extern Particle *particleEngine; + +#endif diff --git a/src/particleemitter.cpp b/src/particleemitter.cpp new file mode 100644 index 00000000..2387c652 --- /dev/null +++ b/src/particleemitter.cpp @@ -0,0 +1,327 @@ +/* + * The Mana World + * Copyright 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#include "particleemitter.h" + +#include "animationparticle.h" +#include "imageparticle.h" +#include "log.h" +#include "particle.h" + +#include "resources/animation.h" +#include "resources/image.h" +#include "resources/resourcemanager.h" +#include "resources/imageset.h" + +#include + +#define SIN45 0.707106781f +#define DEG_RAD_FACTOR 0.017453293f + +ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map *map): + mParticleImage(0) +{ + mMap = map; + mParticleTarget = target; + + //initializing default values + mParticlePosX.set(0.0f); + mParticlePosY.set(0.0f); + mParticlePosZ.set(0.0f); + mParticleAngleHorizontal.set(0.0f); + mParticleAngleVertical.set(0.0f); + mParticlePower.set(0.0f); + mParticleGravity.set(0.0f); + mParticleRandomnes.set(0); + mParticleBounce.set(0.0f); + mParticleAcceleration.set(0.0f); + mParticleDieDistance.set(-1.0f); + mParticleMomentum.set(1.0f); + mParticleLifetime.set(-1); + mParticleFadeOut.set(0); + mParticleFadeIn.set(0); + mOutput.set(1); + + for_each_xml_child_node(propertyNode, emitterNode) + { + if (xmlStrEqual(propertyNode->name, BAD_CAST "property")) + { + std::string name = XML::getProperty(propertyNode, "name", ""); + + if (name == "position-x") + { + mParticlePosX = readMinMax(propertyNode, 0.0f); + } + else if (name == "position-y") + { + + mParticlePosY = readMinMax(propertyNode, 0.0f); + } + else if (name == "position-z") + { + mParticlePosZ = readMinMax(propertyNode, 0.0f); + } + else if (name == "image") + { + std::string image = XML::getProperty(propertyNode, "value", ""); + // Don't leak when multiple images are defined + if (image != "" && !mParticleImage) + { + ResourceManager *resman = ResourceManager::getInstance(); + mParticleImage = resman->getImage(image); + } + } + else if (name == "horizontal-angle") + { + mParticleAngleHorizontal = readMinMax(propertyNode, 0.0f); + mParticleAngleHorizontal.minVal *= DEG_RAD_FACTOR; + mParticleAngleHorizontal.maxVal *= DEG_RAD_FACTOR; + } + else if (name == "vertical-angle") + { + mParticleAngleVertical = readMinMax(propertyNode, 0.0f); + mParticleAngleVertical.minVal *= DEG_RAD_FACTOR; + mParticleAngleVertical.maxVal *= DEG_RAD_FACTOR; + } + else if (name == "power") + { + mParticlePower = readMinMax(propertyNode, 0.0f); + } + else if (name == "gravity") + { + mParticleGravity = readMinMax(propertyNode, 0.0f); + } + else if (name == "randomnes") + { + mParticleRandomnes = readMinMax(propertyNode, 0); + } + else if (name == "bounce") + { + mParticleBounce = readMinMax(propertyNode, 0.0f); + } + else if (name == "lifetime") + { + mParticleLifetime = readMinMax(propertyNode, 0); + mParticleLifetime.minVal += 1; + } + else if (name == "output") + { + mOutput = readMinMax(propertyNode, 0); + mOutput.maxVal +=1; + } + else if (name == "acceleration") + { + mParticleAcceleration = readMinMax(propertyNode, 0.0f); + } + else if (name == "die-distance") + { + mParticleDieDistance = readMinMax(propertyNode, 0.0f); + } + else if (name == "momentum") + { + mParticleMomentum = readMinMax(propertyNode, 1.0f); + } + else if (name == "fade-out") + { + mParticleFadeOut = readMinMax(propertyNode, 0); + } + else if (name == "fade-in") + { + mParticleFadeIn = readMinMax(propertyNode, 0); + } + else + { + logger->log("Particle Engine: Warning, unknown emitter property \"%s\"", + name.c_str() + ); + } + } + else if (xmlStrEqual(propertyNode->name, BAD_CAST "emitter")) + { + ParticleEmitter newEmitter(propertyNode, mParticleTarget, map); + mParticleChildEmitters.push_back(newEmitter); + } + else if (xmlStrEqual(propertyNode->name, BAD_CAST "animation")) + { + ImageSet *imageset = ResourceManager::getInstance()->getImageSet( + XML::getProperty(propertyNode, "imageset", ""), + XML::getProperty(propertyNode, "width", 0), + XML::getProperty(propertyNode, "height", 0) + ); + + // Get animation frames + for_each_xml_child_node(frameNode, propertyNode) + { + int delay = XML::getProperty(frameNode, "delay", 0); + int offsetX = XML::getProperty(frameNode, "offsetX", 0); + int offsetY = XML::getProperty(frameNode, "offsetY", 0); + offsetY -= imageset->getHeight() - 32; + offsetX -= imageset->getWidth() / 2 - 16; + + if (xmlStrEqual(frameNode->name, BAD_CAST "frame")) + { + int index = XML::getProperty(frameNode, "index", -1); + + if (index < 0) + { + logger->log("No valid value for 'index'"); + continue; + } + + Image *img = imageset->get(index); + + if (!img) + { + logger->log("No image at index " + (index)); + continue; + } + + mParticleAnimation.addFrame(img, delay, offsetX, offsetY); + } + else if (xmlStrEqual(frameNode->name, BAD_CAST "sequence")) + { + int start = XML::getProperty(frameNode, "start", -1); + int end = XML::getProperty(frameNode, "end", -1); + + if (start < 0 || end < 0) + { + logger->log("No valid value for 'start' or 'end'"); + continue; + } + + while (end >= start) + { + Image *img = imageset->get(start); + + if (!img) + { + logger->log("No image at index " + + (start)); + continue; + } + + mParticleAnimation.addFrame(img, delay, offsetX, offsetY); + start++; + } + } + else if (xmlStrEqual(frameNode->name, BAD_CAST "end")) + { + mParticleAnimation.addTerminator(); + } + } // for frameNode + } + } +} + + +ParticleEmitter::~ParticleEmitter() +{ + if (mParticleImage) + { + mParticleImage->decRef(); + } +} + + +template MinMax +ParticleEmitter::readMinMax(xmlNodePtr propertyNode, T def) +{ + MinMax retval; + + def = (T)XML::getFloatProperty(propertyNode, "value", (double)def); + retval.set ( (T)XML::getFloatProperty(propertyNode, "min", (double)def), + (T)XML::getFloatProperty(propertyNode, "max", (double)def) + ); + + return retval; +} + + +std::list +ParticleEmitter::createParticles() +{ + std::list newParticles; + + for (int i = mOutput.value(); i > 0; i--) + { + // Limit maximum particles + if (Particle::particleCount > Particle::maxCount) break; + + Particle *newParticle; + if (mParticleImage) + { + newParticle = new ImageParticle(mMap, mParticleImage); + } + else if (mParticleAnimation.getLength() > 0) + { + Animation *newAnimation = new Animation(mParticleAnimation); + newParticle = new AnimationParticle(mMap, newAnimation); + } + else + { + newParticle = new Particle(mMap); + } + + + newParticle->setPosition( + mParticlePosX.value(), + mParticlePosY.value(), + mParticlePosZ.value() + ); + + float angleH = mParticleAngleHorizontal.value(); + float angleV = mParticleAngleVertical.value(); + float power = mParticlePower.value(); + newParticle->setVector( + cos(angleH) * cos(angleV) * power, + sin(angleH) * cos(angleV) * SIN45 * power, + sin(angleV) * SIN45 * power + ); + + newParticle->setRandomnes(mParticleRandomnes.value()); + newParticle->setGravity(mParticleGravity.value()); + newParticle->setBounce(mParticleBounce.value()); + + newParticle->setDestination(mParticleTarget, + mParticleAcceleration.value(), + mParticleMomentum.value() + ); + newParticle->setDieDistance(mParticleDieDistance.value()); + + newParticle->setLifetime(mParticleLifetime.value()); + newParticle->setFadeOut(mParticleFadeOut.value()); + newParticle->setFadeIn(mParticleFadeIn.value()); + + for ( std::list::iterator i = mParticleChildEmitters.begin(); + i != mParticleChildEmitters.end(); + i++ + ) + { + newParticle->addEmitter(new ParticleEmitter(*i)); + } + + newParticles.push_back(newParticle); + } + + return newParticles; +} diff --git a/src/particleemitter.h b/src/particleemitter.h new file mode 100644 index 00000000..ca6d8622 --- /dev/null +++ b/src/particleemitter.h @@ -0,0 +1,120 @@ +/* + * The Mana World + * Copyright 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef _PARTICLEEMITTER_H +#define _PARTICLEEMITTER_H + +#include + +#include "utils/xml.h" +#include "utils/minmax.h" + +#include "resources/animation.h" + +class Image; +class Map; +class Particle; + +/** + * Every Particle can have one or more particle emitters that create new + * particles when they are updated + */ +class ParticleEmitter +{ + public: + /** + * Constructor. + */ + ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map *map); + + /** + * Destructor. + */ + ~ParticleEmitter(); + + /** + * Spawns new particles + * @return: a list of created particles + */ + std::list createParticles(); + + /** + * Sets the target of the particles that are created + */ + void + setTarget(Particle *target) + { mParticleTarget = target; }; + + private: + template MinMax readMinMax(xmlNodePtr propertyNode, T def); + + /** + * initial position of particles: + */ + MinMax mParticlePosX, mParticlePosY, mParticlePosZ; + + /** + * initial vector of particles: + */ + MinMax mParticleAngleHorizontal, mParticleAngleVertical; + + /** + * Initial velocity of particles + */ + MinMax mParticlePower; + + /* + * Vector changing of particles: + */ + MinMax mParticleGravity; + MinMax mParticleRandomnes; + MinMax mParticleBounce; + + /* + * Properties of targeting particles: + */ + Particle *mParticleTarget; + MinMax mParticleAcceleration; + MinMax mParticleDieDistance; + MinMax mParticleMomentum; + + /* + * Behavior over time of the particles: + */ + MinMax mParticleLifetime; + MinMax mParticleFadeOut; + MinMax mParticleFadeIn; + + Map *mMap; /**< Map the particles are spawned on */ + + MinMax mOutput; /**< Number of particles spawned per update */ + + Image *mParticleImage; /**< Particle image, if used */ + + /** Filename of particle animation file */ + Animation mParticleAnimation; + + /** List of emitters the spawned particles are equipped with */ + std::list mParticleChildEmitters; +}; +#endif diff --git a/src/resources/animation.h b/src/resources/animation.h index d0d11c69..aad93cda 100644 --- a/src/resources/animation.h +++ b/src/resources/animation.h @@ -54,7 +54,7 @@ class Animation Animation(); /** - * Appends a new animation at the end of the sequence + * Appends a new animation at the end of the sequence. */ void addFrame(Image *image, unsigned int delay, int offsetX, int offsetY); diff --git a/src/resources/image.cpp b/src/resources/image.cpp index a27783d4..d7d4e64b 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -187,19 +187,22 @@ Image* Image::load(void *buffer, unsigned int bufferSize, bool hasAlpha = false; - // Figure out whether the image uses its alpha layer - for (int i = 0; i < tmpImage->w * tmpImage->h; ++i) + if (tmpImage->format->BitsPerPixel == 32) { - Uint8 r, g, b, a; - SDL_GetRGBA( - ((Uint32*) tmpImage->pixels)[i], - tmpImage->format, - &r, &g, &b, &a); - - if (a != 255) + // Figure out whether the image uses its alpha layer + for (int i = 0; i < tmpImage->w * tmpImage->h; ++i) { - hasAlpha = true; - break; + Uint8 r, g, b, a; + SDL_GetRGBA( + ((Uint32*) tmpImage->pixels)[i], + tmpImage->format, + &r, &g, &b, &a); + + if (a != 255) + { + hasAlpha = true; + break; + } } } diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index fda8916d..2230cb6a 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -231,6 +231,30 @@ MapReader::readMap(xmlNodePtr node, const std::string &path) { readProperties(childNode, map); } + else if (xmlStrEqual(childNode->name, BAD_CAST "objectgroup")) + { + for_each_xml_child_node(objectNode, childNode) + { + if (xmlStrEqual(objectNode->name, BAD_CAST "object")) + { + std::string objName = XML::getProperty(objectNode, "name", ""); + std::string objType = XML::getProperty(objectNode, "type", ""); + int objX = XML::getProperty(objectNode, "x", 0); + int objY = XML::getProperty(objectNode, "y", 0); + + logger->log("- Loading object name: %s type: %s at %d:%d", + objName.c_str(), objType.c_str(), objX, objY); + if (objType == "PARTICLE_EFFECT") + { + map->addParticleEffect(objName, objX, objY); + } + else + { + logger->log(" Warning: Unknown object type"); + } + } + } + } } map->initializeOverlays(); diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp index ac3ac3bc..89afc549 100644 --- a/src/resources/monsterdb.cpp +++ b/src/resources/monsterdb.cpp @@ -83,6 +83,27 @@ MonsterDB::load() currentInfo->setName (XML::getProperty(monsterNode, "name", "unnamed")); + std::string targetCursor; + targetCursor = XML::getProperty(monsterNode, "targetCursor", "medium"); + if (targetCursor == "small") + { + currentInfo->setTargetCursorSize(Being::TC_SMALL); + } + else if (targetCursor == "medium") + { + currentInfo->setTargetCursorSize(Being::TC_MEDIUM); + } + else if (targetCursor == "large") + { + currentInfo->setTargetCursorSize(Being::TC_LARGE); + } + else + { + logger->log("MonsterDB: Unknown target cursor type \"%s\" for %s - using medium sized one", + targetCursor.c_str(), currentInfo->getName().c_str()); + currentInfo->setTargetCursorSize(Being::TC_MEDIUM); + } + //iterate s and s for_each_xml_child_node(spriteNode, monsterNode) { diff --git a/src/resources/monsterinfo.h b/src/resources/monsterinfo.h index 05d4c014..d2a0a2c8 100644 --- a/src/resources/monsterinfo.h +++ b/src/resources/monsterinfo.h @@ -28,6 +28,9 @@ #include #include +#include "../being.h" + + enum SoundEvent { EVENT_HIT, @@ -62,7 +65,11 @@ class MonsterInfo setSprite(std::string filename) { mSprite = filename; } void - addSound (SoundEvent event, std::string filename); + setTargetCursorSize(Being::TargetCursorSize targetCursorSize) + { mTargetCursorSize = targetCursorSize; } + + void + addSound(SoundEvent event, std::string filename); const std::string& getName () const { return mName; }; @@ -70,13 +77,16 @@ class MonsterInfo const std::string& getSprite () const { return mSprite; }; + const Being::TargetCursorSize + getTargetCursorSize() const { return mTargetCursorSize; } + std::string getSound (SoundEvent event) const; private: std::string mName; std::string mSprite; - + Being::TargetCursorSize mTargetCursorSize; std::map* > mSounds; }; diff --git a/src/simpleanimation.cpp b/src/simpleanimation.cpp index 5fc35bcd..18e732ef 100644 --- a/src/simpleanimation.cpp +++ b/src/simpleanimation.cpp @@ -23,6 +23,91 @@ #include "simpleanimation.h" +#include "graphics.h" +#include "log.h" + +#include "resources/image.h" +#include "resources/resourcemanager.h" +#include "resources/imageset.h" + + +SimpleAnimation::SimpleAnimation(xmlNodePtr animationNode): + mAnimationTime(0), + mAnimationPhase(0) +{ + mAnimation = new Animation(); + + ImageSet *imageset = ResourceManager::getInstance()->getImageSet( + XML::getProperty(animationNode, "imageset", ""), + XML::getProperty(animationNode, "width", 0), + XML::getProperty(animationNode, "height", 0) + ); + + // Get animation frames + for ( xmlNodePtr frameNode = animationNode->xmlChildrenNode; + frameNode != NULL; + frameNode = frameNode->next) + { + int delay = XML::getProperty(frameNode, "delay", 0); + int offsetX = XML::getProperty(frameNode, "offsetX", 0); + int offsetY = XML::getProperty(frameNode, "offsetY", 0); + offsetY -= imageset->getHeight() - 32; + offsetX -= imageset->getWidth() / 2 - 16; + + if (xmlStrEqual(frameNode->name, BAD_CAST "frame")) + { + int index = XML::getProperty(frameNode, "index", -1); + + if (index < 0) + { + logger->log("No valid value for 'index'"); + continue; + } + + Image *img = imageset->get(index); + + if (!img) + { + logger->log("No image at index " + (index)); + continue; + } + + mAnimation->addFrame(img, delay, offsetX, offsetY); + } + else if (xmlStrEqual(frameNode->name, BAD_CAST "sequence")) + { + int start = XML::getProperty(frameNode, "start", -1); + int end = XML::getProperty(frameNode, "end", -1); + + if (start < 0 || end < 0) + { + logger->log("No valid value for 'start' or 'end'"); + continue; + } + + while (end >= start) + { + Image *img = imageset->get(start); + + if (!img) + { + logger->log("No image at index " + + (start)); + continue; + } + + mAnimation->addFrame(img, delay, offsetX, offsetY); + start++; + } + } + else if (xmlStrEqual(frameNode->name, BAD_CAST "end")) + { + mAnimation->addTerminator(); + } + } + + mCurrentFrame = mAnimation->getFrame(0); +} void SimpleAnimation::update(unsigned int timePassed) { diff --git a/src/simpleanimation.h b/src/simpleanimation.h index a56c31da..561c540d 100644 --- a/src/simpleanimation.h +++ b/src/simpleanimation.h @@ -26,7 +26,10 @@ #include "resources/animation.h" +#include "utils/xml.h" + class Frame; +class Graphics; /** * This class is a leightweight alternative to the AnimatedSprite class. @@ -35,6 +38,9 @@ class Frame; class SimpleAnimation { public: + /** + * Creates a simple animation with an already created animation. + */ SimpleAnimation(Animation *animation): mAnimation(animation), mAnimationTime(0), @@ -42,6 +48,11 @@ class SimpleAnimation mCurrentFrame(mAnimation->getFrame(0)) {}; + /** + * Creates a simple animation that creates its animation from XML Data. + */ + SimpleAnimation(xmlNodePtr animationNode); + ~SimpleAnimation(); void update(unsigned int timePassed); @@ -55,10 +66,10 @@ class SimpleAnimation /** Time in game ticks the current frame is shown. */ unsigned int mAnimationTime; - /** Index of current animation frame. */ + /** Index of current animation phase. */ unsigned int mAnimationPhase; - /** Current animation frame. */ + /** Current animation phase. */ Frame *mCurrentFrame; }; diff --git a/src/sprite.h b/src/sprite.h index 51811149..89780519 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -49,6 +49,22 @@ class Sprite virtual void draw(Graphics *graphics, int offsetX, int offsetY) const = 0; + /** + * Returns the horizontal size of the sprites graphical representation + * in pixels or 0 when it is undefined. + */ + virtual int + getWidth() const + { return 0; } + + /** + * Returns the vertical size of the sprites graphical representation + * in pixels or 0 when it is undefined. + */ + virtual int + getHeight() const + { return 0; } + /** * Returns the pixel Y coordinate of the sprite. */ diff --git a/src/textparticle.cpp b/src/textparticle.cpp new file mode 100644 index 00000000..dd01d2fe --- /dev/null +++ b/src/textparticle.cpp @@ -0,0 +1,64 @@ +/* + * The Mana World + * Copyright 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#include "textparticle.h" + +#include "graphics.h" + +TextParticle::TextParticle(Map *map, const std::string &text, + int colorR, int colorG, int colorB, gcn::Font *font): + Particle(map), + mText(text), + mTextFont(font), + mColorR(colorR), + mColorG(colorG), + mColorB(colorB) +{ +} + +void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const +{ + if (!mAlive) + return; + + int screenX = (int)mPosX + offsetX; + int screenY = (int)mPosY - int(mPosZ) + offsetY; + + int alpha = 255; + + if (mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut) + { + alpha *= mLifetimeLeft; + alpha /= mFadeOut; + }; + + if (mLifetimePast < mFadeIn) + { + alpha *= mLifetimePast; + alpha /= mFadeIn; + } + + graphics->setFont(mTextFont); + graphics->setColor(gcn::Color (mColorR, mColorG, mColorB, alpha)); + graphics->drawText(mText, screenX, screenY, gcn::Graphics::CENTER); +} diff --git a/src/textparticle.h b/src/textparticle.h new file mode 100644 index 00000000..b365c885 --- /dev/null +++ b/src/textparticle.h @@ -0,0 +1,53 @@ +/* + * The Mana World + * Copyright 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef _TEXTPARTICLE_H +#define _TEXTPARTICLE_H + +#include "particle.h" + +#include + +#include "guichanfwd.h" + +class TextParticle : public Particle +{ + public: + TextParticle(Map *map, const std::string &text, + int colorR, int colorG, int colorB, gcn::Font *font); + /** + * Draws the particle image + */ + virtual void + draw(Graphics *graphics, int offsetX, int offsetY) const; + + // hack to improve text visibility + virtual int getPixelY() const { return (int)(mPosY + mPosZ); } + + private: + std::string mText; /**< Text of the particle */ + gcn::Font *mTextFont; /**< Font used for drawing the text */ + int mColorR, mColorG, mColorB; /**< Color used for drawing the text */ +}; + +#endif diff --git a/src/utils/fastsqrt.h b/src/utils/fastsqrt.h new file mode 100644 index 00000000..8da1d354 --- /dev/null +++ b/src/utils/fastsqrt.h @@ -0,0 +1,24 @@ +/* A very fast function to calculate the approximate inverse square root of a + * floating point value and a helper function that uses it for getting the + * normal squareroot. For an explanation of the inverse squareroot function + * read: + * http://www.math.purdue.edu/~clomont/Math/Papers/2003/InvSqrt.pdf + * + * Unfortunately the original creator of this function seems to be unknown. + */ + +float fastInvSqrt(float x) +{ + union { int i; float x; } tmp; + float xhalf = 0.5f * x; + tmp.x = x; + tmp.i = 0x5f375a86 - (tmp.i >> 1); + x = tmp.x; + x = x * (1.5f - xhalf * x * x); + return x; +} + +float fastSqrt(float x) +{ + return 1.0f / fastInvSqrt(x); +} diff --git a/src/utils/minmax.h b/src/utils/minmax.h new file mode 100644 index 00000000..1add2b7e --- /dev/null +++ b/src/utils/minmax.h @@ -0,0 +1,47 @@ +/* + * The Mana World + * Copyright 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/** + * Returns a random numeric value that is larger than or equal min and smaller + * than max + */ + +template struct MinMax +{ + void set(T min, T max) + { + minVal=min; maxVal=max; + } + + void set(T val) + { + set(val, val); + } + + T value() + { + return (T)(minVal + (maxVal - minVal) * (rand() / ((double) RAND_MAX + 1))); + } + + T minVal; + T maxVal; +}; diff --git a/src/utils/wingettimeofday.h b/src/utils/wingettimeofday.h index a5537f39..28afb7e5 100644 --- a/src/utils/wingettimeofday.h +++ b/src/utils/wingettimeofday.h @@ -1,113 +1,113 @@ -/* - * The Mana World - * Copyright 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id$ - */ - -#ifndef _TMW_WINGETTIMEOFDAY_H_ -#define _TMW_WINGETTIMEOFDAY_H_ - -#ifdef WIN32 - -#include - -/* - * the function gettimeofday() is available on UNIX but not on windows. - * this header defines a windows implementation as a - * GetSystemTimeAsFileTime() wrapper. - */ - -int gettimeofday(struct timeval* tv, void *tz) -/*--------------------------------------------------------------- - * Copyright (c) 1999,2000,2001,2002,2003 - * The Board of Trustees of the University of Illinois - * All Rights Reserved. - *--------------------------------------------------------------- - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software (Iperf) and associated - * documentation files (the "Software"), to deal in the Software - * without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit - * persons to whom the Software is furnished to do - * so, subject to the following conditions: - * - * - * Redistributions of source code must retain the above - * copyright notice, this list of conditions and - * the following disclaimers. - * - * - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimers in the documentation and/or other materials - * provided with the distribution. - * - * - * Neither the names of the University of Illinois, NCSA, - * nor the names of its contributors may be used to endorse - * or promote products derived from this Software without - * specific prior written permission. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTIBUTORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * ________________________________________________________________ - * National Laboratory for Applied Network Research - * National Center for Supercomputing Applications - * University of Illinois at Urbana-Champaign - * http://www.ncsa.uiuc.edu - * ________________________________________________________________ - * - * gettimeofday.c - * by Mark Gates - * ------------------------------------------------------------------- - * A (hack) implementation of gettimeofday for Windows. - * Since I send sec/usec in UDP packets, this made the most sense. - * ------------------------------------------------------------------- */ -{ - FILETIME time; - double timed; - - GetSystemTimeAsFileTime( &time ); - - // Apparently Win32 has units of 1e-7 sec (tenths of microsecs) - // 4294967296 is 2^32, to shift high word over - // 11644473600 is the number of seconds between - // the Win32 epoch 1601-Jan-01 and the Unix epoch 1970-Jan-01 - // Tests found floating point to be 10x faster than 64bit int math. - - timed = ((time.dwHighDateTime * 4294967296e-7) - 11644473600.0) + - (time.dwLowDateTime * 1e-7); - - tv->tv_sec = (long) timed; - tv->tv_usec = (long) ((timed - tv->tv_sec) * 1e6); - - return 0; -} - - -#endif // WIN32 -#endif +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef _TMW_WINGETTIMEOFDAY_H_ +#define _TMW_WINGETTIMEOFDAY_H_ + +#ifdef WIN32 + +#include + +/* + * the function gettimeofday() is available on UNIX but not on windows. + * this header defines a windows implementation as a + * GetSystemTimeAsFileTime() wrapper. + */ + +int gettimeofday(struct timeval* tv, void *tz) +/*--------------------------------------------------------------- + * Copyright (c) 1999,2000,2001,2002,2003 + * The Board of Trustees of the University of Illinois + * All Rights Reserved. + *--------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software (Iperf) and associated + * documentation files (the "Software"), to deal in the Software + * without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit + * persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * + * Redistributions of source code must retain the above + * copyright notice, this list of conditions and + * the following disclaimers. + * + * + * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimers in the documentation and/or other materials + * provided with the distribution. + * + * + * Neither the names of the University of Illinois, NCSA, + * nor the names of its contributors may be used to endorse + * or promote products derived from this Software without + * specific prior written permission. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTIBUTORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * ________________________________________________________________ + * National Laboratory for Applied Network Research + * National Center for Supercomputing Applications + * University of Illinois at Urbana-Champaign + * http://www.ncsa.uiuc.edu + * ________________________________________________________________ + * + * gettimeofday.c + * by Mark Gates + * ------------------------------------------------------------------- + * A (hack) implementation of gettimeofday for Windows. + * Since I send sec/usec in UDP packets, this made the most sense. + * ------------------------------------------------------------------- */ +{ + FILETIME time; + double timed; + + GetSystemTimeAsFileTime( &time ); + + // Apparently Win32 has units of 1e-7 sec (tenths of microsecs) + // 4294967296 is 2^32, to shift high word over + // 11644473600 is the number of seconds between + // the Win32 epoch 1601-Jan-01 and the Unix epoch 1970-Jan-01 + // Tests found floating point to be 10x faster than 64bit int math. + + timed = ((time.dwHighDateTime * 4294967296e-7) - 11644473600.0) + + (time.dwLowDateTime * 1e-7); + + tv->tv_sec = (long) timed; + tv->tv_usec = (long) ((timed - tv->tv_sec) * 1e6); + + return 0; +} + + +#endif // WIN32 +#endif diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp index 7c917dc0..e30450f0 100644 --- a/src/utils/xml.cpp +++ b/src/utils/xml.cpp @@ -39,6 +39,20 @@ namespace XML return ret; } + double + getFloatProperty(xmlNodePtr node, const char* name, double def) + { + double &ret = def; + + xmlChar *prop = xmlGetProp(node, BAD_CAST name); + if (prop) { + ret = atof((char*)prop); + xmlFree(prop); + } + + return ret; + } + std::string getProperty(xmlNodePtr node, const char *name, const std::string &def) { @@ -51,4 +65,13 @@ namespace XML return def; } + + xmlNodePtr findFirstChildByName(xmlNodePtr parent, const char *name) + { + for_each_xml_child_node(child, parent) + if (xmlStrEqual(child->name, BAD_CAST name)) + return child; + + return NULL; + } } diff --git a/src/utils/xml.h b/src/utils/xml.h index db4c264a..ef3bad3d 100644 --- a/src/utils/xml.h +++ b/src/utils/xml.h @@ -39,11 +39,22 @@ namespace XML int getProperty(xmlNodePtr node, const char *name, int def); + /** + * Gets an floating point property from an xmlNodePtr. + */ + double + getFloatProperty(xmlNodePtr node, const char *name, double def); + /** * Gets a string property from an xmlNodePtr. */ std::string getProperty(xmlNodePtr node, const char *name, const std::string &def); + + /** + * Finds the first child node with the given name + */ + xmlNodePtr findFirstChildByName(xmlNodePtr parent, const char *name); } #define for_each_xml_child_node(var, parent) \ -- cgit v1.2.3-70-g09d2 From 1a9320fafb23940d0463e6f384713d0f99fc0c61 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Wed, 19 Sep 2007 17:28:33 +0000 Subject: Merged 0.0 changes from revision 3362 to 3580 to trunk. --- ChangeLog | 306 ++++++++++++++++++++++++++++++- data/graphics/gui/CMakeLists.txt | 4 + data/graphics/gui/Makefile.am | 4 + data/graphics/gui/close_button.png | Bin 0 -> 650 bytes data/graphics/gui/hits_yellow.png | Bin 356 -> 894 bytes data/graphics/gui/item_shortcut_bgr.png | Bin 0 -> 1026 bytes data/graphics/gui/mouse.png | Bin 1134 -> 4508 bytes data/graphics/gui/unknown-item.png | Bin 0 -> 540 bytes data/graphics/images/login_wallpaper.png | Bin 215527 -> 643307 bytes src/CMakeLists.txt | 22 ++- src/Makefile.am | 38 ++-- src/animationparticle.cpp | 3 +- src/being.cpp | 90 ++------- src/being.h | 42 +---- src/game.cpp | 179 ++++++++++-------- src/gui/button.cpp | 20 +- src/gui/button.h | 10 +- src/gui/buy.cpp | 125 ++++++++----- src/gui/buy.h | 10 +- src/gui/char_select.cpp | 12 +- src/gui/char_select.h | 31 ++-- src/gui/chat.cpp | 10 +- src/gui/debugwindow.cpp | 14 +- src/gui/debugwindow.h | 9 +- src/gui/equipmentwindow.cpp | 1 + src/gui/gui.cpp | 45 +++-- src/gui/gui.h | 43 +++-- src/gui/inventorywindow.cpp | 13 +- src/gui/inventorywindow.h | 11 +- src/gui/itemcontainer.cpp | 4 + src/gui/itemshortcutcontainer.cpp | 224 ++++++++++++++++++++++ src/gui/itemshortcutcontainer.h | 115 ++++++++++++ src/gui/itemshortcutwindow.cpp | 74 ++++++++ src/gui/itemshortcutwindow.h | 69 +++++++ src/gui/menuwindow.cpp | 12 +- src/gui/popupmenu.cpp | 6 - src/gui/selectionlistener.h | 16 +- src/gui/sell.cpp | 127 +++++++------ src/gui/sell.h | 16 +- src/gui/setup.cpp | 10 +- src/gui/setup_keyboard.cpp | 187 +++++++++++++++++++ src/gui/setup_keyboard.h | 84 +++++++++ src/gui/shoplistbox.cpp | 20 +- src/gui/skill.cpp | 6 +- src/gui/skill.h | 1 - src/gui/status.cpp | 6 +- src/gui/status.h | 3 +- src/gui/updatewindow.cpp | 4 +- src/gui/viewport.cpp | 25 +-- src/gui/viewport.h | 13 -- src/gui/window.cpp | 198 +++++++++++++++++--- src/gui/window.h | 99 +++++++++- src/gui/windowlistener.h | 86 +++++++++ src/imageparticle.cpp | 8 +- src/itemshortcut.cpp | 87 +++++++++ src/itemshortcut.h | 130 +++++++++++++ src/keyboardconfig.cpp | 144 +++++++++++++++ src/keyboardconfig.h | 185 +++++++++++++++++++ src/localplayer.cpp | 43 ++++- src/localplayer.h | 22 +++ src/main.cpp | 19 +- src/monster.cpp | 10 +- src/net/beinghandler.cpp | 84 +++++---- src/net/chathandler.cpp | 2 + src/net/inventoryhandler.cpp | 2 + src/net/playerhandler.cpp | 3 +- src/particle.cpp | 96 +++++----- src/particle.h | 112 +++++------ src/particleemitter.cpp | 30 ++- src/player.cpp | 50 ++--- src/player.h | 3 - src/resources/equipmentdb.cpp | 156 ---------------- src/resources/equipmentdb.h | 55 ------ src/resources/equipmentinfo.h | 52 ------ src/resources/itemdb.cpp | 126 ++++++++++--- src/resources/iteminfo.cpp | 86 ++++++++- src/resources/iteminfo.h | 118 +++++++----- src/resources/mapreader.cpp | 2 +- src/resources/monsterdb.cpp | 8 +- src/resources/monsterinfo.cpp | 12 +- src/resources/monsterinfo.h | 16 +- src/resources/spritedef.h | 4 +- src/textparticle.cpp | 11 +- src/textparticle.h | 17 +- src/utils/fastsqrt.h | 2 + src/utils/minmax.h | 1 + src/utils/trim.h | 53 ++++++ src/vector.h | 134 ++++++++++++++ tools/adler32.c | 67 +++++++ 89 files changed, 3257 insertions(+), 1140 deletions(-) create mode 100644 data/graphics/gui/close_button.png create mode 100644 data/graphics/gui/item_shortcut_bgr.png create mode 100644 data/graphics/gui/unknown-item.png create mode 100644 src/gui/itemshortcutcontainer.cpp create mode 100644 src/gui/itemshortcutcontainer.h create mode 100644 src/gui/itemshortcutwindow.cpp create mode 100644 src/gui/itemshortcutwindow.h create mode 100644 src/gui/setup_keyboard.cpp create mode 100644 src/gui/setup_keyboard.h create mode 100644 src/gui/windowlistener.h create mode 100644 src/itemshortcut.cpp create mode 100644 src/itemshortcut.h create mode 100644 src/keyboardconfig.cpp create mode 100644 src/keyboardconfig.h delete mode 100644 src/resources/equipmentdb.cpp delete mode 100644 src/resources/equipmentdb.h delete mode 100644 src/resources/equipmentinfo.h create mode 100644 src/utils/trim.h create mode 100644 src/vector.h create mode 100644 tools/adler32.c (limited to 'data/graphics/gui/CMakeLists.txt') diff --git a/ChangeLog b/ChangeLog index 082c9b94..d0e43d40 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,19 @@ * src/gui/button.cpp: Fixed improper const qualifier. +2007-09-12 Bjørn Lindeijer + + * data/items.xml, data/equipment.xml: Added temporary weapon IDs below + 256 to use as view-ID in eAthena's item DB. + * src/gui/shoplistbox.cpp, src/gui/buy.h, src/gui/buy.cpp: Allowed + selection of items that cannot be afforded, so that their descriptions + are still accessible. Also made sure the player's money value of + ShopItemList gets updated. + +2007-09-11 Eugenio Favalli + + * src/gui/chat.cpp, tmw.cbp: Fixed admin commands. + 2007-09-10 Eugenio Favalli * configure.ac, data/fonts/dejavusans.ttf, @@ -18,17 +31,103 @@ * po/LINGUAS: Added German to the list of available languages. * po/de.po: Fixed two syntax errors preventing compilation. -2007-08-27 Matthias Hartmann +2007-09-08 Philipp Sehmisch + + * data/graphics/particles/aniblaze.png, + data/graphics/particles/cookingfire.particle.xml, + data/graphics/particles/fireplace.particle.xml, + data/graphics/particles/flame.particle.xml: Improved fire effects by + using animated particles. - * po/de.po: Added german translation. +2007-09-06 Philipp Sehmisch + + * src/animationparticle.cpp, src/imageparticle.cpp: Fixed animated + particles. + +2007-09-01 Bjørn Lindeijer + + * src/Makefile.am: Fixed the entry for windowlistener.h. + +2007-08-30 Bjørn Lindeijer + + * src/localplayer.cpp, src/player.cpp, src/main.cpp, src/being.cpp, + src/CMakeLists.txt, src/Makefile.am, src/resources/iteminfo.h, + src/resources/equipmentdb.h, src/resources/equipmentinfo.h, + src/resources/itemdb.cpp, src/resources/iteminfo.cpp, + src/resources/equipmentdb.cpp, src/resources/equipmentinfo.cpp, + src/resources/spritedef.h, src/being.h, data/items.xml, + data/equipment.xml: Merged equipment database with items database and + got rid of the unused item art attribute. + * src/net/beinghandler.cpp, src/net/charserverhandler.cpp: Removed the + now unnecessary multiplication of weapon IDs with 10000. + * src/resources/iteminfo.cpp, data/graphics/items/unknown.png: Added + fallback item icon and use it for unknown items or when item image + fails to load. + * NEWS: Updated with changes since last update. + * data/items.xml, data/equipment.xml: Reverted equipment database and + included original low-ID items in items.xml for compatibility with + eAthena, which doesn't support View ID to come above 255. + * src/resources/itemdb.cpp: Accept items without a name. + +2007-08-29 Bjørn Lindeijer + + * src/gui/sell.cpp, src/gui/inventorywindow.cpp, src/gui/sell.h: Made + sell dialog resizable and tweaked inventory resize code a bit. + * data/items.xml: Fixed typo in chainmail description. + +2007-08-28 Bjørn Lindeijer + + * src/gui/window.cpp, src/gui/inventorywindow.h, + src/gui/selectionlistener.h, src/gui/buy.h, + src/gui/itemshortcutwindow.cpp, src/gui/inventorywindow.cpp, + src/gui/buy.cpp, src/gui/window.h, src/gui/windowlistener.h, + src/gui/itemshortcutwindow.h, src/CMakeLists.txt, src/Makefile.am: + Made buy dialog resizable and added a WindowListener class for + listening for window resize and move events. + * src/textparticle.h, src/particle.h, src/CMakeLists.txt, + src/particle.cpp, src/imageparticle.cpp, src/vector.h, + src/textparticle.cpp, src/Makefile.am: Added Vector class and used it + in the particle engine. + +2007-08-27 Bjørn Lindeijer + + * src/engine.cpp, src/resources/mapreader.cpp: Made client search for + both compressed and non-compressed map files. 2007-08-27 Eugenio Favalli + * src/game.cpp: Assigned unused emotions to Alt +/-. (applied a patch + by Quiche_on_a_leash). + * data/maps/new_1-1.tmx, data/maps/new_1-1.tmx.gz, + data/maps/new_10-1.tmx, data/maps/new_10-1.tmx.gz, + data/maps/new_11-1.tmx, data/maps/new_11-1.tmx.gz, + data/maps/new_12-1.tmx, data/maps/new_12-1.tmx.gz, + data/maps/new_13-1.tmx, data/maps/new_13-1.tmx.gz, + data/maps/new_14-1.tmx, data/maps/new_14-1.tmx.gz, + data/maps/new_15-1.tmx, data/maps/new_15-1.tmx.gz, + data/maps/new_16-1.tmx, data/maps/new_16-1.tmx.gz, + data/maps/new_17-1.tmx, data/maps/new_17-1.tmx.gz, + data/maps/new_18-1.tmx, data/maps/new_18-1.tmx.gz, + data/maps/new_19-1.tmx, data/maps/new_19-1.tmx.gz, + data/maps/new_2-1.tmx, data/maps/new_2-1.tmx.gz, + data/maps/new_20-1.tmx, data/maps/new_20-1.tmx.gz, + data/maps/new_3-1.tmx, data/maps/new_3-1.tmx.gz, + data/maps/new_4-1.tmx, data/maps/new_4-1.tmx.gz, + data/maps/new_5-1.tmx, data/maps/new_5-1.tmx.gz, + data/maps/new_6-1.tmx, data/maps/new_6-1.tmx.gz, + data/maps/new_7-1.tmx, data/maps/new_7-1.tmx.gz, + data/maps/new_8-1.tmx, data/maps/new_8-1.tmx.gz, + data/maps/new_9-1.tmx, data/maps/new_9-1.tmx.gz: Replaced compressed + maps with layer compressed maps. * data/maps/new_1-1.tmx.gz: Added test npcs. * src/openglgraphics.cpp, tmw.cbp: Fixed compilation with old OpenGL headers. * po/it.po: Updated italian translation. +2007-08-27 Matthias Hartmann + + * po/de.po: Added German translation. + 2007-08-27 Guillaume Melquiond * src/gui/chat.h, src/gui/chat.cpp: Added "/admin" chat command for @@ -36,6 +135,11 @@ * src/engine.cpp, src/resources/mapreader.cpp: Ported patch from 0.0, in order to support missing extensions and uncompressed maps. +2007-08-26 Eugenio Favalli + + * src/gui/updatewindow.cpp, src/main.cpp, tmw.cbp: Removed home dir + from config file to avoid encoding issues. + 2007-08-26 Guillaume Melquiond * src/gui/button.cpp: Fixed incorrect button dimensions, as they mess @@ -58,10 +162,103 @@ for rectangle OpenGL textures when available, in order to reduce video memory usage. +2007-08-24 Bjørn Lindeijer + + * src/gui/gui.h, src/gui/gui.cpp: Removed useless logic method and + reverted mouse cursor to non-static since there can be only one Gui + instance so there is no point in supporting a shared resource. + * src/gui/window.cpp, src/gui/gui.h: Removed unnecessary + Gui::isCustomCursor method. + * src/gui/char_select.h, src/gui/char_select.cpp, src/utils/trim.h: + Added trimming of name for new character creation. + * src/net/chathandler.cpp: Added trimming of chat messages appearing + above players. + * src/gui/window.cpp, src/gui/window.h: Improved resize mouse cursor + indication, removing duplicated code and fixing indicator above resize + grip. + +2007-08-23 Bjørn Lindeijer + + * src/gui/viewport.h, src/gui/viewport.cpp: Removed two useless popup + related methods. + * src/gui/debugwindow.h, src/gui/debugwindow.cpp: Use generic close + button functionality. + * src/particle.h, src/particleemitter.cpp, src/particle.cpp: Renamed + Particle::mVector to Particle::mVelocity for clarity. + * src/localplayer.cpp, src/gui/ministatus.cpp, src/gui/status.cpp, + src/being.cpp, src/net/charserverhandler.cpp, + src/net/playerhandler.cpp, src/localplayer.h, src/being.h: Changed XP + gaining effect to appear on the player instead. + * data/graphics/gui/hits_yellow.png: Restored shadow of yellow font. + +2007-08-22 Bjørn Lindeijer + + * src/gui/itemshortcutcontainer.h: Fixed compiler warning. + * src/CMakeLists.txt, src/Makefile.am: Updated source lists. + * data/graphics/gui/CMakeLists.txt, data/graphics/gui/Makefile.am: + Added close button and item shortcut backgrounds to files that will be + installed. + * src/gui/itemshortcutcontainer.cpp: Make sure mGridWidth and + mGridHeight are initialized properly (fixes arithmetic exception in + ItemShortcutContainer::draw). + * src/keyboardconfig.cpp: Changed default sitting key back to 's'. + * src/net/equipmenthandler.cpp: Removed a line that attempted to set + the player's weapon sprite with each kind of equipment. Seems to work + fine without as well. + * src/gui/chat.cpp, src/utils/trim.h, src/CMakeLists.txt, + src/Makefile.am: Added trimming of chat messages. + +2007-08-22 Philipp Sehmisch + + * data/graphics/sprites/chest-lightplatemail-male.png, + data/graphics/sprites/chest-lightplatemail-female.png, + data/graphics/items/armor-chest-lightplatemail.png, + data/graphics/tiles/woodland_indoor_x2.png: Another color correction + at the light platemail (looks more metalic now) + * data/maps/new_18-1.tmx.gz, data/maps/new_19-1.tmx.gz, + data/images/minimap_new_18-1.png, data/images/minimap_new_19-1.png: + Removed a tree that prevented people from sitting on one of the + benches properly. Added correct minimap to woodland village and + surrounding. + +2007-08-22 Joshua Langley + + * data/graphics/gui/item_shortcut_bgr.png, src/game.cpp, + src/gui/gui.cpp, src/gui/itemcontainer.cpp, + src/gui/itemshortcutcontainer.cpp, src/gui/itemshortcutcontainer.h, + src/gui/itemshortcutwindow.cpp, src/gui/itemshortcutwindow.h, + src/gui/menuwindow.cpp, src/gui/setup_keyboard.cpp, src/gui/window.h, + src/itemshortcut.cpp, src/itemshortcut.h, src/keyboardconfig.cpp, + src/keyboardconfig.h, src/localplayer.cpp, src/localplayer.h, + src/main.cpp, src/net/inventoryhandler.cpp, src/utils/tostring.h, + tmw.cbp: Added item shortcut bar. + +2007-08-20 Joshua Langley + + * data/graphics/gui/mouse.png, src/gui/equipmentwindow.cpp, + src/gui/gui.cpp, src/gui/gui.h, src/gui/inventorywindow.cpp, + src/gui/setup.cpp, src/gui/skill.cpp, src/gui/skill.h, + src/gui/status.cpp, src/gui/window.cpp, src/gui/window.h, + data/graphics/gui/close_button.png: Added close button functionality, + resize cursor cues. + * data/graphics/gui/hits_yellow.png, src/being.cpp, src/being.h, + src/gui/gui.cpp, src/localplayer.cpp, src/localplayer.h, + src/net/charserverhandler.cpp, src/net/playerhandler.cpp, + src/particle.cpp, src/particle.h: Added monster killed xp notification + effect. + 2007-08-19 Bjørn Lindeijer - * src/CMakeLists.txt: Updated CMake file. * data/equipment.xml: Fixed typo in female light plate mail. + * NEWS: Updated with changes since 0.0.23. + * src/CMakeLists.txt: Updated CMake file. + +2007-08-19 Joshua Langley + + * src/keyboardconfig.cpp, src/keyboardconfig.h: Minor cleanup. + * src/gui/buy.cpp, src/gui/sell.cpp: Buy/sell fixed minimum quantity. + * src/gui/setup_keyboard.cpp, src/gui/setup_keyboard.h: Fixed bug - + reverts unassigned key. 2007-08-19 Guillaume Melquiond @@ -73,6 +270,23 @@ src/net/playerhandler.cpp, src/localplayer.h: Adapted to new server handling of character attributes. +2007-08-17 Bjørn Lindeijer + + * tools/adler32.c: Added little program for calculating adler32 + checksums of files. + * src/gui/setup_keyboard.cpp: Fixed compile issue related to array + bound not being an integer constant. + +2007-08-15 Philipp Sehmisch + + * data/graphics/sprites/npcs.png, data/graphics/sprites/npc.xml: + Added farmer NPC for woodland village. + +2007-08-14 Eugenio Favalli + + * src/gui/popupmenu.cpp, src/gui/viewport.cpp, src/gui/viewport.h, + tmw.cbp: Fixed popup menu requiring one more click after being used. + 2007-08-14 Guillaume Melquiond * src/net/messagein.h, src/net/messagein.cpp: Fixed error-prone @@ -111,6 +325,15 @@ * src/gui/npclistdialog.cpp, src/gui/npclistdialog.h, src/net/npchandler.cpp: Removed colon in NPC choice messages. +2007-08-09 Philipp Sehmisch + + * data/graphics/sprites/chest-lightplatemail-male.png, + data/graphics/sprites/chest-lightplatemail-female.png, + data/graphics/items/armor-chest-lightplatemail.png, + data/graphics/tiles/woodland_indoor_x2.png: Gave the platemail + armor a blue tint. Looks less boring and makes recoloring through + hue shifting possible. + 2007-08-09 Guillaume Melquiond * po/POTFILES.in: Updated list of translatable source files. @@ -133,9 +356,29 @@ data/graphics/images/EquipBackground.png: Re-designed equipment window, un-equip created. +2007-08-08 Philipp Sehmisch + + * data/graphics/particles/cookingfire.particle.xml, + data/graphics/particles/fireplace.particle.xml, + data/maps/new_20-1.tmx.gz: Added particle effects and music to the + woodland village indoor map. + * data/maps/new_19-1.tmx.gz: Added overlay effect and music to + woodland village outdoor map. + * data/maps/new_18-1.tmx.gz: Fixed some collision map errors and added + music and overlay effect to the surrounding of the woodland village. + +2007-08-07 Philipp Sehmisch + + * data/graphics/sprites/npcs.png: Added two new NPCs and gave some + of the older NPCs a makeover to look more like the style of the new + playerset. + * data/maps/new_20-1.tmx.gz: Corrected a few mapping errors in the + new woodland village. + * data/items.xml: Tweaked description and values of the scythe. + 2007-08-07 Guillaume Melquiond - * po/Makevars, src/main.cpp: Replaced PACKAGE by tmw to reduce + * po/Makevars, src/main.cpp: Replaced PACKAGE by tmw to reduce preprocessing hell. Set gettext charset to utf8. * src/gui/menuwindow.cpp, src/gui/connection.cpp, src/gui/register.cpp, src/gui/equipmentwindow.cpp, @@ -172,6 +415,14 @@ Makefile.am, autogen.sh: Used autopoint for generating gettext environment, and removed conflicting files. +2007-08-05 Philipp Sehmisch + + * data/graphics/tiles/woodland_indoor.png, + data/graphics/tiles/woodland_indoor_x2.png, + data/graphics/tiles/woodland_indoor_x3.png: Added woodland + village indoor tilesets. + * data/maps/new_20-1.tmx.gz: Added woodland village indoor map. + 2007-08-05 Guillaume Melquiond * configure.ac, Makefile.am, po, src/Makefile.am, src/main.cpp, @@ -222,12 +473,22 @@ src/gui/itemcontainer.cpp, src/gui/checkbox.cpp, src/gui/minimap.cpp, src/gui/scrollarea.cpp, src/gui/popupmenu.cpp: Removed useless yet costly dynamic casts. - -2007-07-25 Guillaume Melquiond - * src/net/beinghandler.cpp, src/net/protocol.h: Added being speed to protocol. +2007-07-25 Joshua Langley + + * src/gui/setup.cpp, src/gui/setup_keyboard.cpp, + src/gui/setup_keyboard.h, src/keyboardconfig.cpp, + src/keyboardconfig.h, src/main.cpp: Minor changes to keyboard config, + keyboard setup gui re-designed. + +2007-07-24 Bjørn Lindeijer + + * src/CMakeLists.txt, src/Makefile.am: Added setup_keyboard.* and + keyboardconfig.* to the list of source files. + * src/keyboardconfig.h: Fixed initialization order. + 2007-07-23 Eugenio Favalli * data/maps/new_1-1.tar.gz, data/maps/new_3-1.tar.gz: Fixed warp @@ -247,8 +508,21 @@ * data/maps/new_1-1.tar.gz: Fixed insecure filenames. +2007-07-17 Joshua Langley + + * src/game.cpp: Only one key per function. + * src/main.cpp: Keyboard configuration included. + * src/gui/button.cpp, src/gui/button.h: Default constructor and + init function added. + * src/gui/setup.cpp: Keyboard setup tab added. + * src/gui/setup_keyboard.cpp, src/gui/setup_keyboard.h: Add to project + file, it is the keyboard setup tab. + * src/keyboardconfig.cpp, src/keyboardconfig.h: Add to project file, + the main keyboard config operations. + 2007-07-16 Eugenio Favalli + * data/items.xml: Fixed description of silk headband. * data/maps/new_1-1.tar.gz, data/maps/new_3-1.tar.gz: Added warp and spawn areas. @@ -262,6 +536,24 @@ * src/net/beinghandler.cpp, src/net/beinghandler.h, src/net/protocol.h: Added support for visible equipment. +2007-07-11 Philipp Sehmisch + + * src/resources/monsterdb.cpp, src/resources/monsterinfo.cpp, + src/resources/monsterinfo.h, src/monster.cpp: Renamed SoundEvent + to MonsterSoundEvent. + * src/resources/equipmentdb.cpp, src/resources/equipmentinfo.cpp, + src/resources/equipmentinfo.h: EquipmentDB now holds the type of + attack animation and the sounds of weapons. + * src/being.cpp. src/being.h, src/localplayer.cpp, + src/net/beinghandler.cpp, src/net/charserverhandler.cpp, + src/net/equipmenthandler.cpp, src/player.cpp, src/player.h: The + type of weapon player characters are using is now set using + setVisibleEquipment() instead of setWeapon() or setWeaponById(). + * src/CMakeLists.txt, src/Makefile.AM, tmw.cbp, The Mana World.dev: + Updated project files and buildscripts. + * data/graphics/images/login-wallpaper.png: Replaced login wallpaper + with a new one by Irukard. + 2007-07-11 Bjørn Lindeijer * src/gui/window.cpp: Fixed resizing windows by their resize grip. diff --git a/data/graphics/gui/CMakeLists.txt b/data/graphics/gui/CMakeLists.txt index 5a02d7f1..649e0917 100644 --- a/data/graphics/gui/CMakeLists.txt +++ b/data/graphics/gui/CMakeLists.txt @@ -7,6 +7,7 @@ SET (FILES button.png buttonpress.png checkbox.png + close_button.png deepbox.png fixedfont.png hits_blue.png @@ -18,6 +19,8 @@ SET (FILES hscroll_right_default.png hscroll_right_highlight.png hscroll_right_pressed.png + item_shortcut_bgr.png + mouse.png menuitemD.png menuitemF.png menuitemN.png @@ -37,6 +40,7 @@ SET (FILES target-cursor-red-m.png target-cursor-red-s.png thickborder.png + unknown-item.png vscroll_blue.png vscroll_down_default.png vscroll_down_highlight.png diff --git a/data/graphics/gui/Makefile.am b/data/graphics/gui/Makefile.am index 92e4f3bb..7287d717 100644 --- a/data/graphics/gui/Makefile.am +++ b/data/graphics/gui/Makefile.am @@ -10,6 +10,7 @@ gui_DATA = \ buttonhi.png \ buttonpress.png \ checkbox.png \ + close_button.png \ deepbox.png \ equip_bg.png \ fixedfont.png \ @@ -22,6 +23,8 @@ gui_DATA = \ hscroll_right_default.png \ hscroll_right_highlight.png \ hscroll_right_pressed.png \ + item_shortcut_bgr.png \ + mouse.png \ menuitemD.png \ menuitemF.png \ menuitemN.png \ @@ -41,6 +44,7 @@ gui_DATA = \ target-cursor-red-m.png \ target-cursor-red-s.png \ thickborder.png \ + unknown-item.png \ vscroll_blue.png \ vscroll_down_default.png \ vscroll_down_highlight.png \ diff --git a/data/graphics/gui/close_button.png b/data/graphics/gui/close_button.png new file mode 100644 index 00000000..f87cc2a9 Binary files /dev/null and b/data/graphics/gui/close_button.png differ diff --git a/data/graphics/gui/hits_yellow.png b/data/graphics/gui/hits_yellow.png index f917bc67..d77b7c05 100644 Binary files a/data/graphics/gui/hits_yellow.png and b/data/graphics/gui/hits_yellow.png differ diff --git a/data/graphics/gui/item_shortcut_bgr.png b/data/graphics/gui/item_shortcut_bgr.png new file mode 100644 index 00000000..e878fc7a Binary files /dev/null and b/data/graphics/gui/item_shortcut_bgr.png differ diff --git a/data/graphics/gui/mouse.png b/data/graphics/gui/mouse.png index 2eeb0e51..84dc2ad1 100644 Binary files a/data/graphics/gui/mouse.png and b/data/graphics/gui/mouse.png differ diff --git a/data/graphics/gui/unknown-item.png b/data/graphics/gui/unknown-item.png new file mode 100644 index 00000000..9201d688 Binary files /dev/null and b/data/graphics/gui/unknown-item.png differ diff --git a/data/graphics/images/login_wallpaper.png b/data/graphics/images/login_wallpaper.png index 54692dfd..7af4f913 100644 Binary files a/data/graphics/images/login_wallpaper.png and b/data/graphics/images/login_wallpaper.png differ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fa19cfb5..96338338 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -97,6 +97,12 @@ SET(SRCS gui/item_amount.h gui/itemcontainer.cpp gui/itemcontainer.h + gui/itemshortcutcontainer.cpp + gui/itemshortcutcontainer.h + gui/itemshortcutwindow.cpp + gui/itemshortcutwindow.h + gui/item_amount.cpp + gui/item_amount.h gui/linkhandler.h gui/listbox.cpp gui/listbox.h @@ -143,6 +149,8 @@ SET(SRCS gui/setup.h gui/setup_joystick.cpp gui/setup_joystick.h + gui/setup_keyboard.cpp + gui/setup_keyboard.h gui/setuptab.h gui/setup_video.cpp gui/setup_video.h @@ -170,12 +178,13 @@ SET(SRCS gui/updatewindow.h gui/vbox.cpp gui/vbox.h - gui/windowcontainer.cpp - gui/windowcontainer.h gui/viewport.cpp gui/viewport.h gui/window.cpp gui/window.h + gui/windowcontainer.cpp + gui/windowcontainer.h + gui/windowlistener.h gui/widgets/dropdown.cpp gui/widgets/dropdown.h net/beinghandler.cpp @@ -239,9 +248,6 @@ SET(SRCS resources/buddylist.h resources/animation.cpp resources/animation.h - resources/equipmentdb.cpp - resources/equipmentdb.h - resources/equipmentinfo.h resources/image.cpp resources/image.h resources/imagewriter.cpp @@ -281,6 +287,7 @@ SET(SRCS utils/strprintf.cpp utils/strprintf.h utils/tostring.h + utils/trim.h utils/xml.cpp utils/xml.h animatedsprite.cpp @@ -317,8 +324,12 @@ SET(SRCS inventory.h item.cpp item.h + itemshortcut.cpp + itemshortcut.h joystick.cpp joystick.h + keyboardconfig.cpp + keyboardconfig.h localplayer.cpp localplayer.h lockedarray.h @@ -351,6 +362,7 @@ SET(SRCS textparticle.cpp textparticle.h tileset.h + vector.h ) ADD_EXECUTABLE(tmw ${SRCS}) diff --git a/src/Makefile.am b/src/Makefile.am index 7006f66e..2f29e299 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,6 +5,8 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \ gui/widgets/dropdown.h \ gui/widgets/resizegrip.cpp \ gui/widgets/resizegrip.h \ + gui/box.h \ + gui/box.cpp \ gui/browserbox.cpp \ gui/browserbox.h \ gui/buddywindow.cpp \ @@ -39,12 +41,20 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \ gui/gccontainer.h \ gui/gui.cpp \ gui/gui.h \ + gui/hbox.h \ + gui/hbox.cpp \ gui/help.cpp \ gui/help.h \ + gui/inttextbox.h \ + gui/inttextbox.cpp \ gui/inventorywindow.cpp \ gui/inventorywindow.h \ gui/itemcontainer.cpp \ gui/itemcontainer.h \ + gui/itemshortcutcontainer.cpp \ + gui/itemshortcutcontainer.h \ + gui/itemshortcutwindow.cpp \ + gui/itemshortcutwindow.h \ gui/item_amount.cpp \ gui/item_amount.h \ gui/linkhandler.h \ @@ -95,6 +105,8 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \ gui/setup.h \ gui/setup_joystick.cpp \ gui/setup_joystick.h \ + gui/setup_keyboard.cpp \ + gui/setup_keyboard.h \ gui/setuptab.h \ gui/setup_video.cpp \ gui/setup_video.h \ @@ -118,22 +130,17 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \ gui/trade.h \ gui/unregisterdialog.cpp \ gui/unregisterdialog.h \ + gui/updatewindow.h \ + gui/updatewindow.cpp \ + gui/vbox.h \ + gui/vbox.cpp \ gui/viewport.cpp \ gui/viewport.h \ gui/window.cpp \ gui/window.h \ gui/windowcontainer.cpp \ gui/windowcontainer.h \ - gui/inttextbox.h \ - gui/inttextbox.cpp \ - gui/box.h \ - gui/box.cpp \ - gui/vbox.h \ - gui/vbox.cpp \ - gui/hbox.h \ - gui/hbox.cpp \ - gui/updatewindow.h \ - gui/updatewindow.cpp \ + gui/windowlistener.h \ net/beinghandler.h \ net/beinghandler.cpp \ net/buysellhandler.h \ @@ -193,9 +200,6 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \ resources/ambientoverlay.h \ resources/animation.cpp \ resources/animation.h \ - resources/equipmentdb.cpp \ - resources/equipmentdb.h \ - resources/equipmentinfo.h \ resources/image.cpp \ resources/image.h \ resources/imageloader.cpp \ @@ -235,6 +239,7 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \ utils/strprintf.h \ utils/strprintf.cpp \ utils/tostring.h \ + utils/trim.h \ utils/xml.cpp \ utils/xml.h \ animatedsprite.cpp \ @@ -271,8 +276,12 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \ inventory.h \ item.cpp \ item.h \ + itemshortcut.cpp \ + itemshortcut.h \ joystick.cpp \ joystick.h \ + keyboardconfig.cpp \ + keyboardconfig.h \ localplayer.cpp \ localplayer.h \ lockedarray.h \ @@ -304,7 +313,8 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \ sprite.h \ textparticle.cpp \ textparticle.h \ - tileset.h + tileset.h \ + vector.h # set the include path found by configure INCLUDES = \ diff --git a/src/animationparticle.cpp b/src/animationparticle.cpp index 30c33da7..c79a5bc4 100644 --- a/src/animationparticle.cpp +++ b/src/animationparticle.cpp @@ -26,7 +26,7 @@ #include "simpleanimation.h" AnimationParticle::AnimationParticle(Map *map, Animation *animation): - ImageParticle(map, 0), + ImageParticle(map, NULL), mAnimation(new SimpleAnimation(animation)) { } @@ -40,6 +40,7 @@ AnimationParticle::AnimationParticle(Map *map, xmlNodePtr animationNode): AnimationParticle::~AnimationParticle() { delete mAnimation; + mImage = NULL; } bool AnimationParticle::update() diff --git a/src/being.cpp b/src/being.cpp index bdb27384..81bed667 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -36,12 +36,10 @@ #include "resources/resourcemanager.h" #include "resources/imageset.h" +#include "resources/iteminfo.h" #include "gui/gui.h" -#include "resources/resourcemanager.h" -#include "resources/imageset.h" - #include "utils/dtor.h" #include "utils/tostring.h" @@ -58,11 +56,11 @@ Being::Being(Uint16 id, Uint16 job, Map *map): mEquipment(new Equipment()), mId(id), mSex(2), - mWeapon(0), mWalkSpeed(150), mSpeedModifier(1024), mSpriteDirection(DIRECTION_DOWN), mDirection(DOWN), mMap(NULL), + mEquippedWeapon(NULL), mHairStyle(0), mHairColor(0), mSpeechTime(0), mPx(0), mPy(0), @@ -302,7 +300,7 @@ Being::setSpeech(const std::string &text, Uint32 time) void Being::takeDamage(int amount) { - gcn::Font* font; + gcn::Font *font; std::string damage = amount ? toString(amount) : "miss"; // Selecting the right color @@ -312,8 +310,9 @@ Being::takeDamage(int amount) } else { - // hit particle effect - controlParticle(particleEngine->addEffect("graphics/particles/hit.particle.xml", 0, 0)); + // Hit particle effect + controlParticle(particleEngine->addEffect( + "graphics/particles/hit.particle.xml", 0, 0)); if (getType() == MONSTER) { @@ -325,7 +324,7 @@ Being::takeDamage(int amount) } } - // show damage number + // Show damage number particleEngine->addTextSplashEffect(damage, 255, 255, 255, font, mPx + 16, mPy + 16); } @@ -340,7 +339,7 @@ void Being::setMap(Map *map) { // Remove sprite from potential previous map - if (mMap != NULL) + if (mMap) { mMap->removeSprite(mSpriteIterator); } @@ -348,12 +347,12 @@ Being::setMap(Map *map) mMap = map; // Add sprite to potential new map - if (mMap != NULL) + if (mMap) { mSpriteIterator = mMap->addSprite(this); } - //clear particle effect list because child particles became invalid + // Clear particle effect list because child particles became invalid mChildParticleEffects.clear(); } @@ -362,7 +361,8 @@ Being::controlParticle(Particle *particle) { if (particle) { - particle->disableAutoDelete(); //the effect may not die without the beings permission or we segvault + // The effect may not die without the beings permission or we segfault + particle->disableAutoDelete(); mChildParticleEffects.push_back(particle); } } @@ -380,20 +380,12 @@ Being::setAction(Action action) currentAction = ACTION_SIT; break; case ATTACK: - switch (getWeapon()) + if (mEquippedWeapon) { - case 3: - currentAction = ACTION_ATTACK; - break; - case 2: - currentAction = ACTION_ATTACK_BOW; - break; - case 1: - currentAction = ACTION_ATTACK_STAB; - break; - case 0: - currentAction = ACTION_ATTACK; - break; + currentAction = mEquippedWeapon->getAttackType(); + } + else { + currentAction = ACTION_ATTACK; } for (int i = 0; i < VECTOREND_SPRITE; i++) { @@ -533,11 +525,9 @@ Being::logic() } } - //Update particle effects - for ( std::list::iterator i = mChildParticleEffects.begin(); - i != mChildParticleEffects.end(); - - ) + // Update particle effects + for (std::list::iterator i = mChildParticleEffects.begin(); + i != mChildParticleEffects.end();) { (*i)->setPosition((float)mPx + 16.0f, (float)mPy + 32.0f); if (!(*i)->isAlive()) @@ -599,46 +589,6 @@ Being::getType() const return UNKNOWN; } -void -Being::setWeaponById(Uint16 weapon) -{ - //TODO: Use an external file to map weapon IDs to weapon types - switch (weapon) - { - case 529: // iron arrows - case 1199: // arrows - break; - - case 623: //scythe - setWeapon(3); - break; - - case 1200: // bow - case 530: // short bow - case 545: // forest bow - setWeapon(2); - break; - - case 521: // sharp knife - /* UNCOMMENT TO TEST SHARP KNIFE AS SCYTHE - * setWeapon(3) - * break; - */ - case 522: // dagger - case 536: // short sword - case 1201: // knife - setWeapon(1); - break; - - case 0: // unequip - setWeapon(0); - break; - - default: - logger->log("Not a weapon: %d", weapon); - } -} - int Being::getOffset(int step) const { // Check whether we're walking in the requested direction diff --git a/src/being.h b/src/being.h index afb3cb8b..fadf9656 100644 --- a/src/being.h +++ b/src/being.h @@ -38,6 +38,7 @@ class AnimatedSprite; class Equipment; +class ItemInfo; class Item; class Map; class Graphics; @@ -161,8 +162,7 @@ class Being : public Sprite void setSpeech(const std::string &text, Uint32 time); /** - * Puts a damage bubble above this being for the specified amount of - * time. + * Puts a damage bubble above this being. * * @param amount The amount of damage. */ @@ -266,27 +266,6 @@ class Being : public Sprite */ virtual Type getType() const; - /** - * Gets the weapon picture id. - */ - Uint16 getWeapon() const { return mWeapon; } - - /** - * Sets the weapon picture id. - * - * @param weapon the picture id - */ - virtual void - setWeapon(Uint16 weapon) { mWeapon = weapon; } - - /** - * Sets the weapon picture id with the weapon id. - * - * @param weapon the weapon id - */ - void - setWeaponById(Uint16 weapon); - /** * Gets the walk speed. */ @@ -380,30 +359,26 @@ class Being : public Sprite getHeight() const; /** - * Returns the required size of a target cursor for this being + * Returns the required size of a target cursor for this being. */ - virtual Being::TargetCursorSize - getTargetCursorSize() const + virtual Being::TargetCursorSize getTargetCursorSize() const { return TC_MEDIUM; } std::auto_ptr mEquipment; /** - * Take control of a particle + * Take control of a particle. */ - void - controlParticle(Particle *particle); + void controlParticle(Particle *particle); protected: /** * Sets the new path for this being. */ - void - setPath(const Path &path, int mod = 1024); + void setPath(const Path &path, int mod = 1024); Uint16 mId; /**< Unique being id */ Uint8 mSex; /**< Character's gender */ - Uint16 mWeapon; /**< Weapon picture id */ Uint16 mWalkSpeed; /**< Walking speed */ Uint16 mSpeedModifier; /**< Modifier to keep course on sync (1024 = normal speed) */ Uint8 mSpriteDirection; /**< Facing direction */ @@ -411,6 +386,9 @@ class Being : public Sprite Map *mMap; /**< Map on which this being resides */ SpriteIterator mSpriteIterator; + /** Engine-related infos about weapon. */ + const ItemInfo* mEquippedWeapon; + Path mPath; std::string mSpeech; Uint16 mHairStyle, mHairColor; diff --git a/src/game.cpp b/src/game.cpp index 495f9a8d..a40bfa28 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -37,7 +37,9 @@ #include "engine.h" #include "flooritemmanager.h" #include "graphics.h" +#include "itemshortcut.h" #include "joystick.h" +#include "keyboardconfig.h" #include "localplayer.h" #include "log.h" #include "npc.h" @@ -53,6 +55,7 @@ #include "gui/gui.h" #include "gui/help.h" #include "gui/inventorywindow.h" +#include "gui/itemshortcutwindow.h" #include "gui/menuwindow.h" #include "gui/minimap.h" #include "gui/ministatus.h" @@ -116,6 +119,7 @@ TradeWindow *tradeWindow; //BuddyWindow *buddyWindow; HelpWindow *helpWindow; DebugWindow *debugWindow; +ItemShortcutWindow *itemShortcutWindow; BeingManager *beingManager = NULL; FloorItemManager *floorItemManager = NULL; @@ -181,6 +185,7 @@ void createGuiWindows() //buddyWindow = new BuddyWindow(); helpWindow = new HelpWindow(); debugWindow = new DebugWindow(); + itemShortcutWindow = new ItemShortcutWindow(); // Initialize window positions //chargeDialog->setPosition( @@ -193,6 +198,7 @@ void createGuiWindows() chatWindow->setVisible(true); miniStatusWindow->setVisible(true); menuWindow->setVisible(true); + itemShortcutWindow->setVisible(true); } /** @@ -220,6 +226,7 @@ void destroyGuiWindows() //delete buddyWindow; delete helpWindow; delete debugWindow; + delete itemShortcutWindow; } Game::Game(): @@ -420,6 +427,14 @@ void Game::handleInput() { gcn::Window *requestedWindow = NULL; + if (setupWindow->isVisible() && + keyboard.getNewKeyIndex() > keyboard.KEY_NO_VALUE) + { + keyboard.setNewKey((int) event.key.keysym.sym); + keyboard.callbackNewKey(); + keyboard.setNewKeyIndex(keyboard.KEY_NO_VALUE); + return; + } switch (event.key.keysym.sym) { case SDLK_F1: @@ -473,65 +488,7 @@ void Game::handleInput() used = true; } break; - - // Hide certain windows - case SDLK_h: - if (!chatWindow->isFocused()) - { - statusWindow->setVisible(false); - inventoryWindow->setVisible(false); - skillDialog->setVisible(false); - setupWindow->setVisible(false); - equipmentWindow->setVisible(false); - helpWindow->setVisible(false); - debugWindow->setVisible(false); - } - break; - - // Picking up items on the floor - case SDLK_g: - case SDLK_z: - if (!chatWindow->isFocused()) - { - Uint16 x = player_node->mX / 32, y = player_node->mY / 32; - FloorItem *item = floorItemManager->findByCoordinates(x, y); - - // If none below the player, try the tile in front of - // the player - if (!item) - { - // Temporary until tile-based picking is removed. - switch (player_node->getSpriteDirection()) - { - case DIRECTION_UP : --y; break; - case DIRECTION_DOWN : ++y; break; - case DIRECTION_LEFT : --x; break; - case DIRECTION_RIGHT: ++x; break; - default: break; - } - - item = floorItemManager->findByCoordinates(x, y); - } - - if (item) - player_node->pickUp(item); - - used = true; - } - break; - - // attacking - // TODO: Reimplement attacking with joystick buttons - // (old code allowed permanent attacking and not 1 attack - // with each button push) - // I would like to do this but i don't own a joystick. - case SDLK_LCTRL: - case SDLK_RCTRL: - player_node->attack(); - used = true; - break; - - // Quitting confirmation dialog + // Quitting confirmation dialog case SDLK_ESCAPE: if (!quitDialog) { @@ -547,6 +504,74 @@ void Game::handleInput() break; } + if (keyboard.isEnabled() && !chatWindow->isFocused()) + { + const int tKey = keyboard.getKeyIndex(event.key.keysym.sym); + // Checks if any item shortcut is pressed. + for (int i = KeyboardConfig::KEY_SHORTCUT_0; + i <= KeyboardConfig::KEY_SHORTCUT_9; + i++) + { + if (tKey == i) { + itemShortcut->useItem( + i - KeyboardConfig::KEY_SHORTCUT_0); + break; + } + } + switch (tKey) { + case KeyboardConfig::KEY_PICKUP: + { + Uint16 x = player_node->mX / 32; + Uint16 y = player_node->mY / 32; + FloorItem *item = + floorItemManager->findByCoordinates(x, y); + + // If none below the player, try the tile in front + // of the player + if (!item) + { + // Temporary until tile-based picking is + // removed. + switch (player_node->getSpriteDirection()) + { + case DIRECTION_UP : --y; break; + case DIRECTION_DOWN : ++y; break; + case DIRECTION_LEFT : --x; break; + case DIRECTION_RIGHT: ++x; break; + default: break; + } + + item = + floorItemManager->findByCoordinates(x, y); + } + + if (item) + player_node->pickUp(item); + + used = true; + } + break; + case KeyboardConfig::KEY_SIT: + // Player sit action + player_node->toggleSit(); + used = true; + break; + case KeyboardConfig::KEY_HIDE_WINDOWS: + // Hide certain windows + if (!chatWindow->isFocused()) + { + statusWindow->setVisible(false); + inventoryWindow->setVisible(false); + skillDialog->setVisible(false); + setupWindow->setVisible(false); + equipmentWindow->setVisible(false); + helpWindow->setVisible(false); + debugWindow->setVisible(false); + } + break; + } + } + if (requestedWindow) { requestedWindow->setVisible(!requestedWindow->isVisible()); @@ -563,19 +588,14 @@ void Game::handleInput() { switch (event.key.keysym.sym) { - case SDLK_s: - // Player sit action - player_node->toggleSit(); - used = true; - break; - case SDLK_p: // Screenshot (picture, hence the p) { SDL_Surface *screenshot = graphics->getScreenshot(); if (!saveScreenshot(screenshot)) { - logger->log("Error: could not save Screenshot."); + logger->log( + "Error: could not save Screenshot."); } SDL_FreeSurface(screenshot); } @@ -606,6 +626,8 @@ void Game::handleInput() case SDLK_8: emotion = 8; break; case SDLK_9: emotion = 9; break; case SDLK_0: emotion = 10; break; + case SDLK_MINUS: emotion = 11; break; + case SDLK_EQUALS: emotion = 12; break; default: emotion = 0; break; } @@ -638,41 +660,41 @@ void Game::handleInput() } } // End while - + // If the user is configuring the keys then don't respond. + if (!keyboard.isEnabled()) + { + return; + } // Moving player around if (player_node->mAction != Being::DEAD && current_npc == 0 && !chatWindow->isFocused()) { // Get the state of the keyboard keys - Uint8* keys; - keys = SDL_GetKeyState(NULL); + keyboard.refreshActiveKeys(); Uint16 x = player_node->mX / 32, y = player_node->mY / 32; unsigned char direction = 0; // Translate pressed keys to movement and direction - if (keys[SDLK_UP] || keys[SDLK_KP8] || - keys[SDLK_KP7] || keys[SDLK_KP9] || + if ( keyboard.isKeyActive(keyboard.KEY_MOVE_UP) || joystick && joystick->isUp()) { direction |= Being::UP; } - else if (keys[SDLK_DOWN] || keys[SDLK_KP2] || - keys[SDLK_KP1] || keys[SDLK_KP3] || + else if ( keyboard.isKeyActive(keyboard.KEY_MOVE_DOWN) || joystick && joystick->isDown()) { direction |= Being::DOWN; } - if (keys[SDLK_LEFT] || keys[SDLK_KP4] || - keys[SDLK_KP1] || keys[SDLK_KP7] || + + if ( keyboard.isKeyActive(keyboard.KEY_MOVE_LEFT) || joystick && joystick->isLeft()) { direction |= Being::LEFT; } - else if (keys[SDLK_RIGHT] || keys[SDLK_KP6] || - keys[SDLK_KP3] || keys[SDLK_KP9] || + else if ( keyboard.isKeyActive(keyboard.KEY_MOVE_RIGHT) || joystick && joystick->isRight()) { direction |= Being::RIGHT; @@ -681,7 +703,8 @@ void Game::handleInput() player_node->setWalkingDir(direction); // Target the nearest monster if 'a' pressed - if (keys[SDLK_a]) + if ( keyboard.isKeyActive(keyboard.KEY_TARGET_CLOSEST) ) + //if (keys[SDLK_a]) { Being *target = beingManager->findNearestLivingBeing(x, y, 20, Being::MONSTER); diff --git a/src/gui/button.cpp b/src/gui/button.cpp index 4e236c33..0379ebc0 100644 --- a/src/gui/button.cpp +++ b/src/gui/button.cpp @@ -60,10 +60,25 @@ static ButtonData const data[BUTTON_COUNT] = { ImageRect Button::button[BUTTON_COUNT]; +Button::Button(): + mIsLogged(false) +{ + init(); +} + Button::Button(const std::string& caption, const std::string &actionEventId, gcn::ActionListener *listener): gcn::Button(caption), mIsLogged(false) +{ + init(); + setActionEventId(actionEventId); + if (listener) { + addActionListener(listener); + } +} + +void Button::init() { setBorderSize(0); @@ -91,12 +106,7 @@ Button::Button(const std::string& caption, const std::string &actionEventId, btn[mode]->decRef(); } } - mInstances++; - setActionEventId(actionEventId); - if (listener) { - addActionListener(listener); - } } Button::~Button() diff --git a/src/gui/button.h b/src/gui/button.h index eb73e311..d12173b2 100644 --- a/src/gui/button.h +++ b/src/gui/button.h @@ -38,7 +38,13 @@ class ImageRect; class Button : public gcn::Button { public: /** - * Constructor, sets the caption of the button to the given string. + * Default constructor. + */ + Button(); + + /** + * Constructor, sets the caption of the button to the given string and + * adds the given action listener. */ Button(const std::string& caption, const std::string &actionEventId, gcn::ActionListener *listener); @@ -60,6 +66,8 @@ class Button : public gcn::Button { { mIsLogged = enable; } private: + void init(); + static ImageRect button[4]; /**< Button state graphics */ static int mInstances; /**< Number of button instances */ bool mIsLogged; /**< Makes the button appear pressed all the time */ diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 6cfe5e18..bbf2102e 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -28,6 +28,7 @@ #include "button.h" #include "scrollarea.h" #include "shop.h" +#include "shoplistbox.h" #include "slider.h" #include "../npc.h" @@ -35,11 +36,15 @@ #include "../resources/itemdb.h" #include "../utils/tostring.h" - BuyDialog::BuyDialog(): Window("Buy"), mMoney(0), mAmountItems(0), mMaxItems(0) { + setResizable(true); + setMinWidth(260); + setMinHeight(230); + setDefaultSize(0, 0, 260, 230); + mShopItems = new ShopItems; mShopItemList = new ShopListBox(mShopItems, mShopItems); @@ -54,32 +59,15 @@ BuyDialog::BuyDialog(): mItemDescLabel = new gcn::Label("Description:"); mItemEffectLabel = new gcn::Label("Effect:"); - setContentSize(260, 210); - mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); - mScrollArea->setDimension(gcn::Rectangle(5, 5, 250, 110)); - mShopItemList->setDimension(gcn::Rectangle(5, 5, 238, 110)); - - mSlider->setDimension(gcn::Rectangle(5, 120, 200, 10)); - mSlider->setEnabled(false); - - mQuantityLabel->setPosition(215, 120); - mMoneyLabel->setPosition(5, 130); - - mIncreaseButton->setPosition(40, 186); mIncreaseButton->setSize(20, 20); - mIncreaseButton->setEnabled(false); - - mDecreaseButton->setPosition(10, 186); mDecreaseButton->setSize(20, 20); - mDecreaseButton->setEnabled(false); + mQuantityLabel->setWidth(60); - mBuyButton->setPosition(180, 186); + mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + mIncreaseButton->setEnabled(false); + mDecreaseButton->setEnabled(false); mBuyButton->setEnabled(false); - - mQuitButton->setPosition(212, 186); - - mItemEffectLabel->setDimension(gcn::Rectangle(5, 150, 240, 14)); - mItemDescLabel->setDimension(gcn::Rectangle(5, 169, 240, 14)); + mSlider->setEnabled(false); mShopItemList->setActionEventId("item"); mSlider->setActionEventId("slider"); @@ -98,6 +86,8 @@ BuyDialog::BuyDialog(): add(mItemDescLabel); add(mItemEffectLabel); + addWindowListener(this); + loadWindowState("Buy"); setLocationRelativeTo(getParent()); } @@ -118,13 +108,12 @@ void BuyDialog::reset() { mShopItems->clear(); mShopItemList->adjustSize(); - mMoney = 0; - mSlider->setValue(0.0); - // Reset Previous Selected Items to prevent failing asserts + // Reset previous selected items to prevent failing asserts mShopItemList->setSelected(-1); + mSlider->setValue(0); - updateButtonsAndLabels(); + setMoney(0); } void BuyDialog::addItem(int id, int amount, int price) @@ -141,6 +130,7 @@ void BuyDialog::action(const gcn::ActionEvent &event) { setVisible(false); current_npc = 0; + return; } // The following actions require a valid selection @@ -152,21 +142,19 @@ void BuyDialog::action(const gcn::ActionEvent &event) if (event.getId() == "slider") { - mAmountItems = (int)(mSlider->getValue() * mMaxItems); + mAmountItems = (int) mSlider->getValue(); updateButtonsAndLabels(); } else if (event.getId() == "+" && mAmountItems < mMaxItems) { mAmountItems++; - - mSlider->setValue((double) mAmountItems / (double) mMaxItems); + mSlider->setValue(mAmountItems); updateButtonsAndLabels(); } - else if (event.getId() == "-" && mAmountItems > 0) + else if (event.getId() == "-" && mAmountItems > 1) { mAmountItems--; - - mSlider->setValue((double) mAmountItems / (double) mMaxItems); + mSlider->setValue(mAmountItems); updateButtonsAndLabels(); } // TODO: Actually we'd have a bug elsewhere if this check for the number @@ -178,25 +166,69 @@ void BuyDialog::action(const gcn::ActionEvent &event) Net::GameServer::Player::tradeWithNPC (mShopItems->at(selectedItem).id, mAmountItems); - // Update money and adjust the max number of items that can be bought - mMoney -= mAmountItems * mShopItems->at(selectedItem).price; - mMaxItems -= mAmountItems; - // Reset selection - mAmountItems = 0; - mSlider->setValue(0.0); + mAmountItems = 1; + mSlider->setValue(1); + mSlider->gcn::Slider::setScale(1, mMaxItems); - updateButtonsAndLabels(); + // Update money and adjust the max number of items that can be bought + mMaxItems -= mAmountItems; + setMoney(mMoney - mAmountItems * mShopItems->at(selectedItem).price); } } void BuyDialog::selectionChanged(const SelectionEvent &event) { + // Reset amount of items and update labels - mAmountItems = 0; - mSlider->setValue(0.0); + mAmountItems = 1; + mSlider->setValue(1); updateButtonsAndLabels(); + mSlider->gcn::Slider::setScale(1, mMaxItems); +} + +void BuyDialog::windowResized(const WindowEvent &event) +{ + gcn::Rectangle area = getChildrenArea(); + int width = area.width; + int height = area.height; + + mDecreaseButton->setPosition(8, height - 8 - mDecreaseButton->getHeight()); + mIncreaseButton->setPosition( + mDecreaseButton->getX() + mDecreaseButton->getWidth() + 5, + mDecreaseButton->getY()); + + mQuitButton->setPosition( + width - 8 - mQuitButton->getWidth(), + height - 8 - mQuitButton->getHeight()); + mBuyButton->setPosition( + mQuitButton->getX() - 5 - mBuyButton->getWidth(), + mQuitButton->getY()); + + mItemDescLabel->setDimension(gcn::Rectangle(8, + mBuyButton->getY() - 5 - mItemDescLabel->getHeight(), + width - 16, + mItemDescLabel->getHeight())); + mItemEffectLabel->setDimension(gcn::Rectangle(8, + mItemDescLabel->getY() - 5 - mItemEffectLabel->getHeight(), + width - 16, + mItemEffectLabel->getHeight())); + mMoneyLabel->setDimension(gcn::Rectangle(8, + mItemEffectLabel->getY() - 5 - mMoneyLabel->getHeight(), + width - 16, + mMoneyLabel->getHeight())); + + mQuantityLabel->setPosition( + width - mQuantityLabel->getWidth() - 8, + mMoneyLabel->getY() - 5 - mQuantityLabel->getHeight()); + mSlider->setDimension(gcn::Rectangle(8, + mQuantityLabel->getY(), + mQuantityLabel->getX() - 8 - 8, + 10)); + + mScrollArea->setDimension(gcn::Rectangle(8, 8, width - 16, + mSlider->getY() - 5 - 8)); } void @@ -232,14 +264,13 @@ BuyDialog::updateButtonsAndLabels() // Enable or disable buttons and slider mIncreaseButton->setEnabled(mAmountItems < mMaxItems); - mDecreaseButton->setEnabled(mAmountItems > 0); + mDecreaseButton->setEnabled(mAmountItems > 1); mBuyButton->setEnabled(mAmountItems > 0); - mSlider->setEnabled(mMaxItems > 0); + mSlider->setEnabled(mMaxItems > 1); // Update quantity and money labels - mQuantityLabel->setCaption(toString(mAmountItems)); - mQuantityLabel->adjustSize(); + mQuantityLabel->setCaption( + toString(mAmountItems) + " / " + toString(mMaxItems)); mMoneyLabel->setCaption("Price: " + toString(price) + " GP / " + toString(mMoney - price) + " GP" ); - mMoneyLabel->adjustSize(); } diff --git a/src/gui/buy.h b/src/gui/buy.h index 875deef9..63d25583 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -28,11 +28,11 @@ #include "window.h" #include "selectionlistener.h" -#include "shoplistbox.h" #include "../guichanfwd.h" class ShopItems; +class ShopListBox; class ListBox; /** @@ -40,7 +40,8 @@ class ListBox; * * \ingroup Interface */ -class BuyDialog : public Window, public gcn::ActionListener, SelectionListener +class BuyDialog : public Window, public gcn::ActionListener, SelectionListener, + WindowListener { public: /** @@ -98,6 +99,11 @@ class BuyDialog : public Window, public gcn::ActionListener, SelectionListener void updateButtonsAndLabels(); + /** + * Called whenever the window is resized. + */ + void windowResized(const WindowEvent &event); + private: gcn::Button *mBuyButton; gcn::Button *mQuitButton; diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index d752cdb3..e8381bef 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -48,6 +48,7 @@ #include "../utils/gettext.h" #include "../utils/strprintf.h" #include "../utils/tostring.h" +#include "../utils/trim.h" // Defined in main.cpp, used here for setting the char create dialog extern CharServerHandler charServerHandler; @@ -255,11 +256,6 @@ bool CharSelectDialog::selectByName(const std::string &name) return false; } -std::string CharSelectDialog::getName() -{ - return mNameLabel->getCaption(); -} - CharCreateDialog::CharCreateDialog(Window *parent, int slot): Window(_("Create Character"), true, parent), mSlot(slot) { @@ -410,10 +406,12 @@ CharCreateDialog::action(const gcn::ActionEvent &event) } } -const std::string& +std::string CharCreateDialog::getName() { - return mNameField->getText(); + std::string name = mNameField->getText(); + trim(name); + return name; } void CharCreateDialog::UpdateSliders() diff --git a/src/gui/char_select.h b/src/gui/char_select.h index 9d9184ea..5d0b42fa 100644 --- a/src/gui/char_select.h +++ b/src/gui/char_select.h @@ -60,11 +60,6 @@ class CharSelectDialog : public Window, public gcn::ActionListener bool selectByName(const std::string &name); - /** - * Returns name of selected player - */ - std::string getName(); - private: LockedArray *mCharInfo; @@ -114,22 +109,28 @@ class CharCreateDialog : public Window, public gcn::ActionListener */ ~CharCreateDialog(); - void - action(const gcn::ActionEvent &event); - - const std::string& - getName(); + void action(const gcn::ActionEvent &event); /** * Unlocks the dialog, enabling the create character button again. */ - void - unlock(); + void unlock(); private: int getDistributedPoints(); + void UpdateSliders(); + /** + * Returns the name of the character to create. + */ + std::string getName(); + + /** + * Communicate character creation to the server. + */ + void attemptCharCreate(); + gcn::TextField *mNameField; gcn::Label *mNameLabel; gcn::Button *mNextHairColorButton; @@ -154,12 +155,6 @@ class CharCreateDialog : public Window, public gcn::ActionListener static const int mMaxPoints = 70; int mUsedPoints; - - - /** - * Communicate character creation to the server. - */ - void attemptCharCreate(); }; #endif diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index ba7c7f02..4ed8bb97 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -44,6 +44,7 @@ #include "../net/gameserver/player.h" #include "../utils/dtor.h" +#include "../utils/trim.h" ChatWindow::ChatWindow(): Window(), @@ -125,7 +126,7 @@ void ChatWindow::chatLog(std::string line, int own, std::string channelName) { // Delete overhead from the end of the list - while ((int)mChatlog.size() > mItemsKeep) { + while ((int) mChatlog.size() > mItemsKeep) { mChatlog.pop_back(); } @@ -142,12 +143,15 @@ ChatWindow::chatLog(std::string line, int own, std::string channelName) own = BY_SERVER; } - int pos = line.find(" : "); - if (pos > 0) { + std::string::size_type pos = line.find(" : "); + if (pos != std::string::npos) { tmp.nick = line.substr(0, pos); line.erase(0, pos + 3); } + // Trim whitespace + trim(line); + std::string lineColor = "##0"; // Equiv. to BrowserBox::BLACK switch (own) { case BY_GM: diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 11ad37c2..884cdf7e 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -42,6 +42,7 @@ DebugWindow::DebugWindow(): Window("Debug") { setResizable(true); + setCloseButton(true); setDefaultSize(0, 0, 400, 100); loadWindowState("Debug"); @@ -60,15 +61,11 @@ DebugWindow::DebugWindow(): mParticleCountLabel = new gcn::Label("[Particle count: 0]"); mParticleCountLabel->setPosition(100, 60); - Button *closeButton = new Button("Close", "close", this); - closeButton->setPosition(5, 60); - add(mFPSLabel); add(mMusicFileLabel); add(mMapFileLabel); add(mTileMouseLabel); add(mParticleCountLabel); - add(closeButton); } void @@ -106,12 +103,3 @@ DebugWindow::logic() +"]"); mParticleCountLabel->adjustSize(); } - -void -DebugWindow::action(const gcn::ActionEvent &event) -{ - if (event.getId() == "close") - { - setVisible(false); - } -} diff --git a/src/gui/debugwindow.h b/src/gui/debugwindow.h index d082b2ca..9b6f2017 100644 --- a/src/gui/debugwindow.h +++ b/src/gui/debugwindow.h @@ -33,11 +33,11 @@ #include "../guichanfwd.h" /** - * The chat window. + * The debug window. * * \ingroup Interface */ -class DebugWindow : public Window, public gcn::ActionListener +class DebugWindow : public Window { public: /** @@ -50,11 +50,6 @@ class DebugWindow : public Window, public gcn::ActionListener */ void logic(); - /** - * Performs action. - */ - void action(const gcn::ActionEvent &event); - private: gcn::Label *mMusicFileLabel, *mMapFileLabel; gcn::Label *mTileMouseLabel, *mFPSLabel; diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 5e835985..c86a27fc 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -59,6 +59,7 @@ EquipmentWindow::EquipmentWindow(Equipment *equipment): mBackground(NULL), mSelected(-1) { + setCloseButton(true); setDefaultSize(5, 195, 216, 260); loadWindowState("Equipment"); diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index dc51054c..97dd4d44 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -42,7 +42,7 @@ #include "../graphics.h" #include "../log.h" -#include "../resources/image.h" +#include "../resources/imageset.h" #include "../resources/resourcemanager.h" #include "../resources/imageloader.h" @@ -77,8 +77,9 @@ class GuiConfigListener : public ConfigListener }; Gui::Gui(Graphics *graphics): - mMouseCursor(NULL), - mCustomCursor(false) + mCustomCursor(false), + mMouseCursors(NULL), + mCursorType(CURSOR_POINTER) { logger->log("Initializing GUI..."); // Set graphics @@ -106,7 +107,7 @@ Gui::Gui(Graphics *graphics): // Set global font try { - mGuiFont = new TrueTypeFont("data/fonts/dejavusans.ttf", 12); + mGuiFont = new TrueTypeFont("data/fonts/dejavusans.ttf", 11); } catch (gcn::Exception e) { @@ -139,7 +140,7 @@ Gui::Gui(Graphics *graphics): hitBlueFont = new gcn::ImageFont("graphics/gui/hits_blue.png", "0123456789"); hitYellowFont = new gcn::ImageFont("graphics/gui/hits_yellow.png", - "mis"); + "0123456789misxp "); } catch (gcn::Exception e) { @@ -169,8 +170,8 @@ Gui::~Gui() delete hitBlueFont; delete hitYellowFont; - if (mMouseCursor) { - mMouseCursor->decRef(); + if (mMouseCursors) { + mMouseCursors->decRef(); } delete mGuiFont; @@ -181,12 +182,6 @@ Gui::~Gui() delete guiInput; } -void -Gui::logic() -{ - gcn::Gui::logic(); -} - void Gui::draw() { @@ -196,11 +191,13 @@ Gui::draw() int mouseX, mouseY; Uint8 button = SDL_GetMouseState(&mouseX, &mouseY); - if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS || button & SDL_BUTTON(1)) - && mCustomCursor) + if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS || button & SDL_BUTTON(1)) && + mCustomCursor) { - static_cast(mGraphics)-> - drawImage(mMouseCursor, mouseX - 5, mouseY - 2); + static_cast(mGraphics)->drawImage( + mMouseCursors->get(mCursorType), + mouseX - 15, + mouseY - 17); } mGraphics->popClipArea(); @@ -220,9 +217,11 @@ Gui::setUseCustomCursor(bool customCursor) // Load the mouse cursor ResourceManager *resman = ResourceManager::getInstance(); - mMouseCursor = resman->getImage("graphics/gui/mouse.png"); - if (!mMouseCursor) { - logger->error("Unable to load mouse cursor."); + mMouseCursors = + resman->getImageSet("graphics/gui/mouse.png", 40, 40); + + if (!mMouseCursors) { + logger->error("Unable to load mouse cursors."); } } else @@ -231,9 +230,9 @@ Gui::setUseCustomCursor(bool customCursor) SDL_ShowCursor(SDL_ENABLE); // Unload the mouse cursor - if (mMouseCursor) { - mMouseCursor->decRef(); - mMouseCursor = NULL; + if (mMouseCursors) { + mMouseCursors->decRef(); + mMouseCursors = NULL; } } } diff --git a/src/gui/gui.h b/src/gui/gui.h index 5f2cc810..1e4b9348 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -30,7 +30,7 @@ class GuiConfigListener; class Graphics; -class Image; +class ImageSet; class Viewport; /** @@ -59,36 +59,49 @@ class Gui : public gcn::Gui */ ~Gui(); - /** - * Works around Guichan bug - */ - void - logic(); - /** * Draws the whole Gui by calling draw functions down in the * Gui hierarchy. It also draws the mouse pointer. */ - void - draw(); + void draw(); /** - * Return game font + * Return game font. */ - gcn::Font* - getFont() { return mGuiFont; } + gcn::Font* getFont() const + { return mGuiFont; } /** * Sets whether a custom cursor should be rendered. */ - void - setUseCustomCursor(bool customCursor); + void setUseCustomCursor(bool customCursor); + + /** + * Sets which cursor should be used. + */ + void setCursorType(int index) + { mCursorType = index; } + + /** + * Cursors are in graphic order from left to right. + * CURSOR_POINTER should be left untouched. + * CURSOR_TOTAL should always be last. + */ + enum { + CURSOR_POINTER = 0, + CURSOR_RESIZE_ACROSS, + CURSOR_RESIZE_DOWN, + CURSOR_RESIZE_DOWN_LEFT, + CURSOR_RESIZE_DOWN_RIGHT, + CURSOR_TOTAL + }; private: GuiConfigListener *mConfigListener; gcn::Font *mGuiFont; /**< The global GUI font */ - Image *mMouseCursor; /**< Mouse cursor image */ bool mCustomCursor; /**< Show custom cursor */ + ImageSet *mMouseCursors; /**< Mouse cursor images */ + int mCursorType; }; extern Gui *gui; /**< The GUI system */ diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 085ab188..1e62b130 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -51,6 +51,7 @@ InventoryWindow::InventoryWindow(): mSplit(false) { setResizable(true); + setCloseButton(true); setMinWidth(240); setMinHeight(172); // If you adjust these defaults, don't forget to adjust the trade window's. @@ -69,7 +70,6 @@ InventoryWindow::InventoryWindow(): mItems->addSelectionListener(this); mInvenScroll = new ScrollArea(mItems); - mInvenScroll->setPosition(8, 8); mItemNameLabel = new gcn::Label(strprintf(_("Name: %s"), "")); mItemDescriptionLabel = new gcn::Label( @@ -100,8 +100,8 @@ InventoryWindow::InventoryWindow(): mSplitButton->setWidth(48); } + addWindowListener(this); loadWindowState("Inventory"); - updateContentSize(); } InventoryWindow::~InventoryWindow() @@ -130,7 +130,6 @@ void InventoryWindow::logic() mWeightLabel->setCaption( strprintf(_("Total Weight: %d - Maximum Weight: %d"), player_node->getTotalWeight(), player_node->getMaxWeight())); - mWeightLabel->adjustSize(); } void InventoryWindow::action(const gcn::ActionEvent &event) @@ -215,7 +214,7 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event) } } -void InventoryWindow::updateContentSize() +void InventoryWindow::windowResized(const WindowEvent &event) { const gcn::Rectangle area = getChildrenArea(); @@ -260,8 +259,7 @@ Item* InventoryWindow::getItem() return mItems->getItem(); } -void -InventoryWindow::keyPressed(gcn::KeyEvent &event) +void InventoryWindow::keyPressed(gcn::KeyEvent &event) { switch (event.getKey().getValue()) { @@ -271,8 +269,7 @@ InventoryWindow::keyPressed(gcn::KeyEvent &event) } } -void -InventoryWindow::keyReleased(gcn::KeyEvent &event) +void InventoryWindow::keyReleased(gcn::KeyEvent &event) { switch (event.getKey().getValue()) { diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h index 37ef0406..a9fdadf2 100644 --- a/src/gui/inventorywindow.h +++ b/src/gui/inventorywindow.h @@ -29,8 +29,9 @@ #include -#include "window.h" #include "selectionlistener.h" +#include "window.h" +#include "windowlistener.h" #include "../guichanfwd.h" @@ -45,7 +46,8 @@ class ItemContainer; class InventoryWindow : public Window, public gcn::ActionListener, public gcn::KeyListener, - public SelectionListener + public SelectionListener, + public WindowListener { public: /** @@ -92,7 +94,10 @@ class InventoryWindow : public Window, */ void selectionChanged(const SelectionEvent &event); - void updateContentSize(); /**< Updates widgets size/position. */ + /** + * Called whenever the window is resized. + */ + void windowResized(const WindowEvent &event); private: void updateButtons(); /**< Updates button states. */ diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index b032bd49..bddf7cee 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -30,6 +30,7 @@ #include "../graphics.h" #include "../inventory.h" #include "../item.h" +#include "../itemshortcut.h" #include "../localplayer.h" #include "../resources/image.h" @@ -38,6 +39,9 @@ #include "../utils/tostring.h" +// TODO: Add support for adding items to the item shortcut window (global +// itemShortcut). + static const int BOX_WIDTH = 36; static const int BOX_HEIGHT = 44; diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp new file mode 100644 index 00000000..1943ef93 --- /dev/null +++ b/src/gui/itemshortcutcontainer.cpp @@ -0,0 +1,224 @@ +/* + * The Mana World + * Copyright 2007 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "itemshortcutcontainer.h" + +#include "../graphics.h" +#include "../item.h" +#include "../itemshortcut.h" +#include "../keyboardconfig.h" + +#include "../resources/image.h" +#include "../resources/resourcemanager.h" + +#include "../utils/tostring.h" + +ItemShortcutContainer::ItemShortcutContainer(): + mGridWidth(1), + mGridHeight(1), + mItemClicked(false), + mItemMoved(NULL) +{ + addMouseListener(this); + + ResourceManager *resman = ResourceManager::getInstance(); + + mBackgroundImg = resman->getImage("graphics/gui/item_shortcut_bgr.png"); + mMaxItems = itemShortcut->getItemCount(); + + mBoxHeight = 42; + mBoxWidth = 36; +} + +ItemShortcutContainer::~ItemShortcutContainer() +{ + mBackgroundImg->decRef(); +} + +void +ItemShortcutContainer::logic() +{ + gcn::Widget::logic(); + + int i = itemShortcut->getItemCount(); + + if (i != mMaxItems) + { + mMaxItems = i; + setWidth(getWidth()); + } +} + +void +ItemShortcutContainer::draw(gcn::Graphics *graphics) +{ + Graphics *g = static_cast(graphics); + + for (int i = 0; i < mMaxItems; i++) + { + const int itemX = (i % mGridWidth) * mBoxWidth; + const int itemY = (i / mGridWidth) * mBoxHeight; + + g->drawImage(mBackgroundImg, itemX, itemY); + + // Draw item keyboard shortcut. + const char *key = SDL_GetKeyName( + (SDLKey) keyboard.getKeyValue(keyboard.KEY_SHORTCUT_0+i)); + g->drawText(key, itemX + 2, itemY + 2, gcn::Graphics::LEFT); + + Item *item = itemShortcut->getItem(i); + if (item) { + // Draw item icon. + Image* image = item->getInfo().getImage(); + if (image) { + g->drawImage(image, itemX, itemY); + g->drawText( + toString(item->getQuantity()), + itemX + mBoxWidth / 2, + itemY + mBoxHeight - 14, + gcn::Graphics::CENTER); + } + } + } + if (mItemMoved) + { + // Draw the item image being dragged by the cursor. + Image* image = mItemMoved->getInfo().getImage(); + if (image) + { + const int tPosX = mCursorPosX - (image->getWidth() / 2); + const int tPosY = mCursorPosY - (image->getHeight() / 2); + + g->drawImage(image, tPosX, tPosY); + g->drawText( + toString(mItemMoved->getQuantity()), + tPosX + mBoxWidth / 2, + tPosY + mBoxHeight - 14, + gcn::Graphics::CENTER); + } + } +} + +void +ItemShortcutContainer::setWidth(int width) +{ + gcn::Widget::setWidth(width); + + mGridWidth = getWidth() / mBoxWidth; + if (mGridWidth < 1) { + mGridWidth = 1; + } + + setHeight((mMaxItems / mGridWidth + + (mMaxItems % mGridWidth > 0 ? 1 : 0)) * mBoxHeight); + + mGridHeight = getHeight() / mBoxHeight; + if (mGridHeight < 1) { + mGridHeight = 1; + } +} + +void +ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event) +{ + if (event.getButton() == gcn::MouseEvent::LEFT) { + if (!mItemMoved && mItemClicked) { + const int index = getIndexFromGrid(event.getX(), event.getY()); + if (index == -1) { + return; + } + Item *item = itemShortcut->getItem(index); + if (item) + { + mItemMoved = item; + itemShortcut->removeItem(index); + } + } + if (mItemMoved) { + mCursorPosX = event.getX(); + mCursorPosY = event.getY(); + } + } +} + +void +ItemShortcutContainer::mousePressed(gcn::MouseEvent &event) +{ + const int index = getIndexFromGrid(event.getX(), event.getY()); + if (index == -1) { + return; + } + + // Stores the selected item if theirs one. + if (itemShortcut->isItemSelected()) { + itemShortcut->setItem(index); + itemShortcut->setItemSelected(NULL); + } + else if (itemShortcut->getItem(index)) { + mItemClicked = true; + } +} + +void +ItemShortcutContainer::mouseReleased(gcn::MouseEvent &event) +{ + if (event.getButton() == gcn::MouseEvent::LEFT) + { + if (itemShortcut->isItemSelected()) + { + itemShortcut->setItemSelected(NULL); + } + const int index = getIndexFromGrid(event.getX(), event.getY()); + if (index == -1) { + mItemMoved = NULL; + return; + } + if (mItemMoved) { + itemShortcut->setItems(index, mItemMoved); + mItemMoved = NULL; + } + else if (itemShortcut->getItem(index) && mItemClicked) + { + itemShortcut->useItem(index); + } + if (mItemClicked) { + mItemClicked = false; + } + } +} + +int +ItemShortcutContainer::getIndexFromGrid(int pointX, int pointY) const +{ + const gcn::Rectangle tRect = gcn::Rectangle( + 0, 0, mGridWidth * mBoxWidth, mGridHeight * mBoxHeight); + if (!tRect.isPointInRect(pointX, pointY)) { + return -1; + } + const int index = ((pointY / mBoxHeight) * mGridWidth) + + pointX / mBoxWidth; + if (index >= mMaxItems) + { + return -1; + } + return index; +} diff --git a/src/gui/itemshortcutcontainer.h b/src/gui/itemshortcutcontainer.h new file mode 100644 index 00000000..4b154cbb --- /dev/null +++ b/src/gui/itemshortcutcontainer.h @@ -0,0 +1,115 @@ +/* + * The Mana World + * Copyright 2007 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef _TMW_ITEMSHORTCUTCONTAINER_H__ +#define _TMW_ITEMSHORTCUTCONTAINER_H__ + +#include +#include + +#include + +class Image; +class Item; + +/** + * An item shortcut container. Used to quickly use items. + * + * \ingroup GUI + */ +class ItemShortcutContainer : public gcn::Widget, public gcn::MouseListener +{ + public: + /** + * Constructor. Initializes the graphic. + */ + ItemShortcutContainer(); + + /** + * Destructor. + */ + virtual ~ItemShortcutContainer(); + + /** + * Handles the logic of the ItemContainer + */ + void logic(); + + /** + * Draws the items. + */ + void draw(gcn::Graphics *graphics); + + /** + * Sets the width of the container. This is used to determine the new + * height of the container. + */ + void setWidth(int width); + + /** + * Handles mouse when dragged. + */ + void mouseDragged(gcn::MouseEvent &event); + + /** + * Handles mouse when pressed. + */ + void mousePressed(gcn::MouseEvent &event); + + /** + * Handles mouse release. + */ + void mouseReleased(gcn::MouseEvent &event); + + + int getMaxItems() + { return mMaxItems; } + + int getBoxWidth() + { return mBoxWidth; } + + int getBoxHeight() + { return mBoxHeight; } + + private: + /** + * Gets the index from the grid provided the point is in an item box. + * + * @param pointX X coordinate of the point. + * @param pointY Y coordinate of the point. + * @return index on success, -1 on failure. + */ + int getIndexFromGrid(int pointX, int pointY) const; + + Image *mBackgroundImg; + + int mMaxItems; + int mBoxWidth; + int mBoxHeight; + int mCursorPosX, mCursorPosY; + int mGridWidth, mGridHeight; + bool mItemClicked; + Item *mItemMoved; + +}; + +#endif diff --git a/src/gui/itemshortcutwindow.cpp b/src/gui/itemshortcutwindow.cpp new file mode 100644 index 00000000..dd97a7db --- /dev/null +++ b/src/gui/itemshortcutwindow.cpp @@ -0,0 +1,74 @@ +/* + * The Mana World + * Copyright 2007 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "itemshortcutwindow.h" + +#include "itemshortcutcontainer.h" +#include "scrollarea.h" + +static const int SCROLL_PADDING = 0; + +ItemShortcutWindow::ItemShortcutWindow() +{ + // no title presented, title bar is padding so window can be moved. + gcn::Window::setTitleBarHeight(gcn::Window::getPadding()); + setShowTitle(false); + setResizable(true); + setDefaultSize(758, 174, 42, 426); + + mItems = new ItemShortcutContainer(); + + int border = SCROLL_PADDING * 2 + getPadding() * 2; + setMinWidth(mItems->getBoxWidth() + border); + setMinHeight(mItems->getBoxHeight() + border); + setMaxWidth(mItems->getBoxWidth() * mItems->getMaxItems() + border); + setMaxHeight(mItems->getBoxHeight() * mItems->getMaxItems() + border); + + mInvenScroll = new ScrollArea(mItems); + mInvenScroll->setPosition(SCROLL_PADDING, SCROLL_PADDING); + mInvenScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + + add(mInvenScroll); + + addWindowListener(this); + loadWindowState("ItemShortcut"); +} + +ItemShortcutWindow::~ItemShortcutWindow() +{ + delete mItems; + delete mInvenScroll; +} + +void ItemShortcutWindow::logic() +{ + Window::logic(); +} + +void ItemShortcutWindow::windowResized(const WindowEvent &event) +{ + const gcn::Rectangle area = getChildrenArea(); + + mInvenScroll->setSize( + area.width - SCROLL_PADDING, + area.height - SCROLL_PADDING); +} diff --git a/src/gui/itemshortcutwindow.h b/src/gui/itemshortcutwindow.h new file mode 100644 index 00000000..83bc348d --- /dev/null +++ b/src/gui/itemshortcutwindow.h @@ -0,0 +1,69 @@ +/* + * The Mana World + * Copyright 2007 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef _TMW_ITEMSHORTCUTWINDOW_H +#define _TMW_ITEMSHORTCUTWINDOW_H + +#include "window.h" +#include "windowlistener.h" + +#include "../guichanfwd.h" + +class ItemShortcutContainer; + +/** + * Inventory dialog. + * + * \ingroup Interface + */ +class ItemShortcutWindow : public Window, WindowListener +{ + public: + /** + * Constructor. + */ + ItemShortcutWindow(); + + /** + * Destructor. + */ + ~ItemShortcutWindow(); + + /** + * Logic (updates buttons and weight information). + */ + void logic(); + + /** + * Called whenever the window is resized. + */ + void windowResized(const WindowEvent &event); + + private: + ItemShortcutContainer *mItems; + + gcn::ScrollArea *mInvenScroll; +}; + +extern ItemShortcutWindow *itemShortcutWindow; + +#endif diff --git a/src/gui/menuwindow.cpp b/src/gui/menuwindow.cpp index bfa2f1f2..8d4d184d 100644 --- a/src/gui/menuwindow.cpp +++ b/src/gui/menuwindow.cpp @@ -37,6 +37,7 @@ extern Window *inventoryWindow; extern Window *equipmentWindow; extern Window *skillDialog; extern Window *statusWindow; +extern Window *itemShortcutWindow; namespace { struct MenuWindowListener : public gcn::ActionListener @@ -62,6 +63,7 @@ MenuWindow::MenuWindow(): N_("Equipment"), N_("Inventory"), N_("Skills"), + N_("Shortcut"), N_("Setup"), 0 }; @@ -109,14 +111,20 @@ void MenuWindowListener::action(const gcn::ActionEvent &event) { window = skillDialog; } + else if (event.getId() == "Shortcut") + { + window = itemShortcutWindow; + } else if (event.getId() == "Setup") { window = setupWindow; } - if (window) { + if (window) + { window->setVisible(!window->isVisible()); - if (window->isVisible()) { + if (window->isVisible()) + { window->requestMoveToTop(); } } diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 48bbd3d0..aeb6637d 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -200,12 +200,6 @@ void PopupMenu::handleLink(const std::string& link) setVisible(false); - /* - * This is need cause of a bug in guichan that leave - * the focus on the popup menu even if is not visible. - */ - _getFocusHandler()->focusNone(); - mBeing = NULL; mFloorItem = NULL; mItem = NULL; diff --git a/src/gui/selectionlistener.h b/src/gui/selectionlistener.h index b39672b5..917a4871 100644 --- a/src/gui/selectionlistener.h +++ b/src/gui/selectionlistener.h @@ -25,33 +25,23 @@ #define _TMW_SELECTIONLISTENER_H__ #include +#include /** * An event that characterizes a change in the current selection. * * \ingroup GUI */ -class SelectionEvent +class SelectionEvent : public gcn::Event { public: /** * Constructor. */ SelectionEvent(gcn::Widget *source): - mSource(source) + gcn::Event(source) { } - - /** - * The widget from which the event originated. - */ - gcn::Widget* getSource() const - { - return mSource; - } - - private: - gcn::Widget *mSource; }; /** diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index b601d70c..5f1011c1 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -44,58 +44,44 @@ SellDialog::SellDialog(): Window("Sell"), mMaxItems(0), mAmountItems(0) { + setResizable(true); + setMinWidth(260); + setMinHeight(230); + setDefaultSize(0, 0, 260, 230); + mShopItems = new ShopItems(); mShopItemList = new ShopListBox(mShopItems, mShopItems); - ScrollArea *scrollArea = new ScrollArea(mShopItemList); + mScrollArea = new ScrollArea(mShopItemList); mSlider = new Slider(1.0); mQuantityLabel = new gcn::Label("0"); mMoneyLabel = new gcn::Label("Money: 0 GP / Total: 0 GP"); - mItemDescLabel = new gcn::Label("Description:"); - mItemEffectLabel = new gcn::Label("Effect:"); mIncreaseButton = new Button("+", "+", this); mDecreaseButton = new Button("-", "-", this); mSellButton = new Button("Sell", "sell", this); - Button *quitButton = new Button("Quit", "quit", this); - mSellButton->setEnabled(false); - - setContentSize(260, 210); - scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); - scrollArea->setDimension(gcn::Rectangle(5, 5, 250, 110)); - mShopItemList->setDimension(gcn::Rectangle(5, 5, 238, 110)); - - mSlider->setDimension(gcn::Rectangle(5, 120, 200, 10)); - mSlider->setEnabled(false); - - mQuantityLabel->setPosition(215, 120); + mQuitButton = new Button("Quit", "quit", this); + mItemDescLabel = new gcn::Label("Description:"); + mItemEffectLabel = new gcn::Label("Effect:"); - mIncreaseButton->setPosition(40, 186); mIncreaseButton->setSize(20, 20); - mIncreaseButton->setEnabled(false); - - mDecreaseButton->setPosition(10, 186); mDecreaseButton->setSize(20, 20); - mDecreaseButton->setEnabled(false); + mQuantityLabel->setWidth(60); - mMoneyLabel->setPosition(5, 130); - mItemEffectLabel->setDimension(gcn::Rectangle(5, 150, 240, 14)); - mItemDescLabel->setDimension(gcn::Rectangle(5, 169, 240, 14)); - - mSellButton->setPosition(175, 186); + mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + mIncreaseButton->setEnabled(false); + mDecreaseButton->setEnabled(false); mSellButton->setEnabled(false); + mSlider->setEnabled(false); - quitButton->setPosition(208, 186); - + mShopItemList->setPriceCheck(false); mShopItemList->setActionEventId("item"); mSlider->setActionEventId("slider"); - mShopItemList->setPriceCheck(false); - mShopItemList->addActionListener(this); mShopItemList->addSelectionListener(this); mSlider->addActionListener(this); - add(scrollArea); + add(mScrollArea); add(mSlider); add(mQuantityLabel); add(mMoneyLabel); @@ -104,8 +90,10 @@ SellDialog::SellDialog(): add(mIncreaseButton); add(mDecreaseButton); add(mSellButton); - add(quitButton); + add(mQuitButton); + addWindowListener(this); + loadWindowState("Sell"); setLocationRelativeTo(getParent()); } @@ -117,7 +105,7 @@ SellDialog::~SellDialog() void SellDialog::reset() { mShopItems->clear(); - mSlider->setValue(0.0); + mSlider->setValue(0); // Reset previous selected item to prevent failing asserts mShopItemList->setSelected(-1); @@ -135,16 +123,11 @@ void SellDialog::action(const gcn::ActionEvent &event) { int selectedItem = mShopItemList->getSelected(); - if (event.getId() == "item") - { - mAmountItems = 0; - mSlider->setValue(0); - updateButtonsAndLabels(); - } - else if (event.getId() == "quit") + if (event.getId() == "quit") { setVisible(false); current_npc = 0; + return; } // The following actions require a valid item selection @@ -156,21 +139,19 @@ void SellDialog::action(const gcn::ActionEvent &event) if (event.getId() == "slider") { - mAmountItems = (int) (mSlider->getValue() * mMaxItems); + mAmountItems = (int) mSlider->getValue(); updateButtonsAndLabels(); } else if (event.getId() == "+" && mAmountItems < mMaxItems) { mAmountItems++; - - mSlider->setValue((double) mAmountItems /(double) mMaxItems); + mSlider->setValue(mAmountItems); updateButtonsAndLabels(); } - else if (event.getId() == "-" && mAmountItems > 0) + else if (event.getId() == "-" && mAmountItems > 1) { mAmountItems--; - - mSlider->setValue((double) mAmountItems / (double) mMaxItems); + mSlider->setValue(mAmountItems); updateButtonsAndLabels(); } else if (event.getId() == "sell" && mAmountItems > 0 @@ -182,8 +163,7 @@ void SellDialog::action(const gcn::ActionEvent &event) mMaxItems -= mAmountItems; mShopItems->getShop()->at(selectedItem).quantity = mMaxItems; mPlayerMoney += (mAmountItems * mShopItems->at(selectedItem).price); - mAmountItems = 0; - mSlider->setValue(0); + mAmountItems = 1; if (!mMaxItems) { @@ -194,6 +174,7 @@ void SellDialog::action(const gcn::ActionEvent &event) } else { + mSlider->gcn::Slider::setScale(1, mMaxItems); // Update only when there are items left, the entry doesn't exist // otherwise and can't be updated updateButtonsAndLabels(); @@ -204,10 +185,54 @@ void SellDialog::action(const gcn::ActionEvent &event) void SellDialog::selectionChanged(const SelectionEvent &event) { // Reset amount of items and update labels - mAmountItems = 0; + mAmountItems = 1; mSlider->setValue(0); updateButtonsAndLabels(); + mSlider->gcn::Slider::setScale(1, mMaxItems); +} + +void SellDialog::windowResized(const WindowEvent &event) +{ + gcn::Rectangle area = getChildrenArea(); + int width = area.width; + int height = area.height; + + mDecreaseButton->setPosition(8, height - 8 - mDecreaseButton->getHeight()); + mIncreaseButton->setPosition( + mDecreaseButton->getX() + mDecreaseButton->getWidth() + 5, + mDecreaseButton->getY()); + + mQuitButton->setPosition( + width - 8 - mQuitButton->getWidth(), + height - 8 - mQuitButton->getHeight()); + mSellButton->setPosition( + mQuitButton->getX() - 5 - mSellButton->getWidth(), + mQuitButton->getY()); + + mItemDescLabel->setDimension(gcn::Rectangle(8, + mSellButton->getY() - 5 - mItemDescLabel->getHeight(), + width - 16, + mItemDescLabel->getHeight())); + mItemEffectLabel->setDimension(gcn::Rectangle(8, + mItemDescLabel->getY() - 5 - mItemEffectLabel->getHeight(), + width - 16, + mItemEffectLabel->getHeight())); + mMoneyLabel->setDimension(gcn::Rectangle(8, + mItemEffectLabel->getY() - 5 - mMoneyLabel->getHeight(), + width - 16, + mMoneyLabel->getHeight())); + + mQuantityLabel->setPosition( + width - mQuantityLabel->getWidth() - 8, + mMoneyLabel->getY() - 5 - mQuantityLabel->getHeight()); + mSlider->setDimension(gcn::Rectangle(8, + mQuantityLabel->getY(), + mQuantityLabel->getX() - 8 - 8, + 10)); + + mScrollArea->setDimension(gcn::Rectangle(8, 8, width - 16, + mSlider->getY() - 5 - 8)); } void SellDialog::setMoney(int amount) @@ -246,15 +271,13 @@ SellDialog::updateButtonsAndLabels() // Update Buttons and slider mSellButton->setEnabled(mAmountItems > 0); - mDecreaseButton->setEnabled(mAmountItems > 0); + mDecreaseButton->setEnabled(mAmountItems > 1); mIncreaseButton->setEnabled(mAmountItems < mMaxItems); - mSlider->setEnabled(selectedItem > -1); + mSlider->setEnabled(mMaxItems > 1); // Update the quantity and money labels mQuantityLabel->setCaption( toString(mAmountItems) + " / " + toString(mMaxItems)); - mQuantityLabel->adjustSize(); mMoneyLabel->setCaption("Money: " + toString(income) + " GP / Total: " + toString(mPlayerMoney + income) + " GP"); - mMoneyLabel->adjustSize(); } diff --git a/src/gui/sell.h b/src/gui/sell.h index fc42fd1c..d1e2ddd2 100644 --- a/src/gui/sell.h +++ b/src/gui/sell.h @@ -28,6 +28,7 @@ #include "window.h" #include "selectionlistener.h" +#include "windowlistener.h" #include "../guichanfwd.h" @@ -40,7 +41,8 @@ class ShopListBox; * * \ingroup Interface */ -class SellDialog : public Window, gcn::ActionListener, SelectionListener +class SellDialog : public Window, gcn::ActionListener, SelectionListener, + WindowListener { public: /** @@ -77,22 +79,28 @@ class SellDialog : public Window, gcn::ActionListener, SelectionListener */ void selectionChanged(const SelectionEvent &event); + /** + * Called whenever the window is resized. + */ + void windowResized(const WindowEvent &event); + /** * Gives Player's Money amount */ void setMoney(int amount); + private: /** * Updates the state of buttons and labels. */ - void - updateButtonsAndLabels(); + void updateButtonsAndLabels(); - private: gcn::Button *mSellButton; + gcn::Button *mQuitButton; gcn::Button *mIncreaseButton; gcn::Button *mDecreaseButton; ShopListBox *mShopItemList; + gcn::ScrollArea *mScrollArea; gcn::Label *mMoneyLabel; gcn::Label *mItemDescLabel; gcn::Label *mItemEffectLabel; diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 3ea19059..6a13232a 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -27,6 +27,7 @@ #include "setup_audio.h" #include "setup_joystick.h" #include "setup_video.h" +#include "setup_keyboard.h" #include "tabbedcontainer.h" #include "../utils/dtor.h" @@ -43,7 +44,8 @@ extern Window *skillDialog; Setup::Setup(): Window(_("Setup")) { - int width = 230; + setCloseButton(true); + int width = 250; int height = 245; setContentSize(width, height); @@ -59,7 +61,7 @@ Setup::Setup(): } TabbedContainer *panel = new TabbedContainer(); - panel->setDimension(gcn::Rectangle(5, 5, 220, 205)); + panel->setDimension(gcn::Rectangle(5, 5, 250, 205)); panel->setOpaque(false); SetupTab *tab; @@ -76,6 +78,10 @@ Setup::Setup(): panel->addTab(tab, _("Joystick")); mTabs.push_back(tab); + tab = new Setup_Keyboard(); + panel->addTab(tab, "Keyboard"); + mTabs.push_back(tab); + add(panel); setLocationRelativeTo(getParent()); diff --git a/src/gui/setup_keyboard.cpp b/src/gui/setup_keyboard.cpp new file mode 100644 index 00000000..e88080b5 --- /dev/null +++ b/src/gui/setup_keyboard.cpp @@ -0,0 +1,187 @@ +/* + * The Mana World + * Copyright 2007 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#include "setup_keyboard.h" + +#include +#include + +#include "button.h" +#include "listbox.h" +#include "ok_dialog.h" +#include "scrollarea.h" + +#include "../configuration.h" +#include "../keyboardconfig.h" + +#include "../utils/tostring.h" + +#include + +/** + * The list model for key function list. + * + * \ingroup Interface + */ +class KeyListModel : public gcn::ListModel +{ + public: + /** + * Returns the number of elements in container. + */ + int getNumberOfElements() { return keyboard.KEY_TOTAL; } + + /** + * Returns element from container. + */ + std::string getElementAt(int i) { return mKeyFunctions[i]; } + + /** + * Sets element from container. + */ + void setElementAt(int i, std::string caption) + { + mKeyFunctions[i] = caption; + } + + private: + std::string mKeyFunctions[KeyboardConfig::KEY_TOTAL]; +}; + +Setup_Keyboard::Setup_Keyboard(): + mKeyListModel(new KeyListModel()), + mKeyList(new ListBox(mKeyListModel)), + mKeySetting(false) +{ + keyboard.setSetupKeyboard(this); + setOpaque(false); + + refreshKeys(); + + mKeyList->setDimension(gcn::Rectangle(0, 0, 185, 140)); + mKeyList->addActionListener(this); + mKeyList->setSelected(-1); + + ScrollArea *scrollArea = new ScrollArea(mKeyList); + scrollArea->setDimension(gcn::Rectangle(10, 10, 200, 140)); + add(scrollArea); + + mAssignKeyButton = new Button("Assign", "assign", this); + mAssignKeyButton->setPosition(165, 155); + mAssignKeyButton->addActionListener(this); + mAssignKeyButton->setEnabled(false); + add(mAssignKeyButton); + + mMakeDefaultButton = new Button("Default", "makeDefault", this); + mMakeDefaultButton->setPosition(10, 155); + mMakeDefaultButton->addActionListener(this); + add(mMakeDefaultButton); +} + +Setup_Keyboard::~Setup_Keyboard() +{ + delete mKeyList; + delete mKeyListModel; + + delete mAssignKeyButton; + delete mMakeDefaultButton; +} + +void Setup_Keyboard::apply() +{ + keyUnresolved(); + + if (keyboard.hasConflicts()) + { + new OkDialog("Key Conflict(s) Detected.", + "Resolve them, or gameplay may result in strange behaviour."); + } + keyboard.setEnabled(true); + keyboard.store(); +} + +void Setup_Keyboard::cancel() +{ + keyUnresolved(); + + keyboard.retrieve(); + keyboard.setEnabled(true); + + refreshKeys(); +} + +void Setup_Keyboard::action(const gcn::ActionEvent &event) +{ + if (event.getSource() == mKeyList) + { + if (!mKeySetting) { + mAssignKeyButton->setEnabled(true); + } + } + else if (event.getId() == "assign") + { + mKeySetting = true; + mAssignKeyButton->setEnabled(false); + keyboard.setEnabled(false); + int i(mKeyList->getSelected()); + keyboard.setNewKeyIndex(i); + mKeyListModel->setElementAt(i, keyboard.getKeyCaption(i) + ": ?"); + } + else if (event.getId() == "makeDefault") + { + keyboard.makeDefault(); + refreshKeys(); + } +} + +void Setup_Keyboard::refreshAssignedKey(int index) +{ + std::string caption; + char *temp = SDL_GetKeyName( + (SDLKey) keyboard.getKeyValue(index)); + caption = keyboard.getKeyCaption(index) + ": " + toString(temp); + mKeyListModel->setElementAt(index, caption); +} + +void Setup_Keyboard::newKeyCallback(int index) +{ + mKeySetting = false; + refreshAssignedKey(index); + mAssignKeyButton->setEnabled(true); +} + +void Setup_Keyboard::refreshKeys() +{ + for(int i = 0; i < keyboard.KEY_TOTAL; i++) + { + refreshAssignedKey(i); + } +} + +void Setup_Keyboard::keyUnresolved() +{ + if (mKeySetting) { + newKeyCallback(keyboard.getNewKeyIndex()); + keyboard.setNewKeyIndex(keyboard.KEY_NO_VALUE); + } +} diff --git a/src/gui/setup_keyboard.h b/src/gui/setup_keyboard.h new file mode 100644 index 00000000..b72e8746 --- /dev/null +++ b/src/gui/setup_keyboard.h @@ -0,0 +1,84 @@ +/* + * The Mana World + * Copyright 2007 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef _TMW_GUI_SETUP_KEYBOARD_H +#define _TMW_GUI_SETUP_KEYBOARD_H + +#include "setuptab.h" +#include "button.h" +#include "../guichanfwd.h" + +#include + + +#include + +class Setup_Keyboard : public SetupTab, public gcn::ActionListener +{ + public: + /** + * Constructor + */ + Setup_Keyboard(); + + /** + * Destructor + */ + ~Setup_Keyboard(); + + void apply(); + void cancel(); + + void action(const gcn::ActionEvent &event); + + /** + * Get an update on the assigned key. + */ + void refreshAssignedKey(int index); + + /** + * The callback function when a new key has been pressed. + */ + void newKeyCallback(int index); + + /** + * Shorthand method to update all the keys. + */ + void refreshKeys(); + + /** + * If a key function is unresolved, then this reverts it. + */ + void keyUnresolved(); + + private: + class KeyListModel *mKeyListModel; + gcn::ListBox *mKeyList; + + gcn::Button *mAssignKeyButton; + gcn::Button *mMakeDefaultButton; + + bool mKeySetting; /**< flag to check if key being set. */ +}; + +#endif diff --git a/src/gui/shoplistbox.cpp b/src/gui/shoplistbox.cpp index 0e2ea6d3..ae787ab7 100644 --- a/src/gui/shoplistbox.cpp +++ b/src/gui/shoplistbox.cpp @@ -129,24 +129,8 @@ void ShopListBox::mousePressed(gcn::MouseEvent &event) { if (event.getButton() == gcn::MouseEvent::LEFT) { - bool enoughMoney = false; - int y = event.getY(); - - if (mShopItems && mPriceCheck) - { - if (mPlayerMoney >= mShopItems->at(y / mRowHeight).price) - enoughMoney = true; - } - else // Old Behaviour - { - enoughMoney = true; - } - - if (enoughMoney) - { - setSelected(y / mRowHeight); - generateAction(); - } + setSelected(event.getY() / mRowHeight); + generateAction(); } } diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index 884b3744..d5cfe76a 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -63,22 +63,18 @@ const char *skill_db[] = { SkillDialog::SkillDialog(): Window("Skills") { + setCloseButton(true); setDefaultSize(windowContainer->getWidth() - 255, 25, 240, 240); mSkillListBox = new ListBox(this); ScrollArea *skillScrollArea = new ScrollArea(mSkillListBox); - mCloseButton = new Button("Close", "close", this); mSkillListBox->setActionEventId("skill"); skillScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); skillScrollArea->setDimension(gcn::Rectangle(5, 5, 230, 180)); - mCloseButton->setPosition( - skillScrollArea->getX() + skillScrollArea->getWidth() - mCloseButton->getWidth(), - 210); add(skillScrollArea); - add(mCloseButton); mSkillListBox->addActionListener(this); diff --git a/src/gui/skill.h b/src/gui/skill.h index b8794e35..f1a14d50 100644 --- a/src/gui/skill.h +++ b/src/gui/skill.h @@ -71,7 +71,6 @@ class SkillDialog : public Window, public gcn::ActionListener, private: gcn::ListBox *mSkillListBox; - gcn::Button *mCloseButton; std::vector mSkillList; }; diff --git a/src/gui/status.cpp b/src/gui/status.cpp index 7da3b905..323a6b16 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -39,6 +39,7 @@ StatusWindow::StatusWindow(LocalPlayer *player): mPlayer(player) { setResizable(true); + setCloseButton(true); setDefaultSize((windowContainer->getWidth() - 365) / 2, (windowContainer->getHeight() - 255) / 2, 365, 280); loadWindowState("Status"); @@ -219,7 +220,7 @@ void StatusWindow::update() mHpBar->setColor(0, 171, 34); // Green } - mHpBar->setProgress((float)hp / maxHp); + mHpBar->setProgress((float) hp / maxHp); // Stats Part // ---------- @@ -235,7 +236,8 @@ void StatusWindow::update() int statusPoints = mPlayer->getAttributeIncreasePoints(); // Update labels - for (int i = 0; i < 7; i++) { + for (int i = 0; i < 7; i++) + { mStatsLabel[i]->setCaption(attrNames[i]); mStatsDisplayLabel[i]->setCaption( strprintf("%d / %d", diff --git a/src/gui/status.h b/src/gui/status.h index 40d25a2a..62cd8805 100644 --- a/src/gui/status.h +++ b/src/gui/status.h @@ -41,7 +41,8 @@ class ProgressBar; * * \ingroup Interface */ -class StatusWindow : public Window, public gcn::ActionListener { +class StatusWindow : public Window, public gcn::ActionListener +{ public: /** * Constructor. diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index ed75e5b3..5d81bb9c 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -46,6 +46,8 @@ #include "../resources/resourcemanager.h" +extern std::string homeDir; + /** * Calculates the Alder-32 checksum for the given file. */ @@ -119,7 +121,7 @@ UpdaterWindow::UpdaterWindow(): mUpdateHost = config.getValue("updatehost", "http://updates.themanaworld.org"); - mBasePath = config.getValue("homeDir", "."); + mBasePath = homeDir; // Try to download the updates list download(); diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 2af1d960..4c6b04a2 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -55,8 +55,7 @@ Viewport::Viewport(): mCameraX(0), mCameraY(0), mShowDebugPath(false), - mPlayerFollowMouse(false), - mPopupActive(false) + mPlayerFollowMouse(false) { setOpaque(false); addMouseListener(this); @@ -372,21 +371,20 @@ Viewport::mousePressed(gcn::MouseEvent &event) if ((being = beingManager->findBeing(tilex, tiley)) && being->getType() != Being::LOCALPLAYER) { - showPopup(event.getX(), event.getY(), being); + mPopupMenu->showPopup(event.getX(), event.getY(), being); return; } else if((floorItem = floorItemManager->findByCoordinates(tilex, tiley))) { - showPopup(event.getX(), event.getY(), floorItem); + mPopupMenu->showPopup(event.getX(), event.getY(), floorItem); return; } } // If a popup is active, just remove it - if (mPopupActive) + if (mPopupMenu->isVisible()) { mPopupMenu->setVisible(false); - mPopupActive = false; return; } @@ -450,21 +448,6 @@ void Viewport::showPopup(int x, int y, Item *item) { mPopupMenu->showPopup(x, y, item); - mPopupActive = true; -} - -void -Viewport::showPopup(int x, int y, FloorItem *floorItem) -{ - mPopupMenu->showPopup(x, y, floorItem); - mPopupActive = true; -} - -void -Viewport::showPopup(int x, int y, Being *being) -{ - mPopupMenu->showPopup(x, y, being); - mPopupActive = true; } void diff --git a/src/gui/viewport.h b/src/gui/viewport.h index 22d0f249..eeb31bae 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -129,18 +129,6 @@ class Viewport : public WindowContainer, public gcn::MouseListener, getCameraY() { return mCameraY; } private: - /** - * Shows a popup for a floor item. - * TODO Find some way to get rid of FloorItem here - */ - void showPopup(int x, int y, FloorItem *floorItem); - - /** - * Shows a popup for a being. - * TODO Find some way to get rid of Being here - */ - void showPopup(int x, int y, Being *being); - /** * Helper function for loading target cursors */ @@ -187,7 +175,6 @@ class Viewport : public WindowContainer, public gcn::MouseListener, int mWalkTime; PopupMenu *mPopupMenu; /**< Popup menu. */ - bool mPopupActive; }; #endif diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 84f4466c..17447009 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -26,6 +26,7 @@ #include #include +#include "gui.h" #include "gccontainer.h" #include "windowcontainer.h" @@ -42,7 +43,9 @@ ConfigListener *Window::windowConfigListener = 0; WindowContainer *Window::windowContainer = 0; int Window::instances = 0; +int Window::mouseResize = 0; ImageRect Window::border; +Image *Window::closeImage = NULL; class WindowConfigListener : public ConfigListener { @@ -60,7 +63,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent): mParent(parent), mModal(modal), mResizable(false), - mMouseResize(0), + mCloseButton(false), mSticky(false), mMinWinWidth(100), mMinWinHeight(40), @@ -88,6 +91,8 @@ Window::Window(const std::string& caption, bool modal, Window *parent): border.grid[7] = dBorders->getSubImage(4, 15, 3, 4); border.grid[8] = dBorders->getSubImage(7, 15, 4, 4); dBorders->decRef(); + closeImage = resman->getImage("graphics/gui/close_button.png"); + windowConfigListener = new WindowConfigListener(); // Send GUI alpha changed for initialization windowConfigListener->optionChanged("guialpha"); @@ -110,6 +115,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent): if (mModal) { + gui->setCursorType(Gui::CURSOR_POINTER); requestModalFocus(); } @@ -153,6 +159,7 @@ Window::~Window() delete border.grid[6]; delete border.grid[7]; delete border.grid[8]; + closeImage->decRef(); } delete mChrome; @@ -173,11 +180,19 @@ void Window::draw(gcn::Graphics *graphics) // Draw title if (getTitleBarHeight()) { - graphics->setColor(gcn::Color(0, 0, 0)); - graphics->setFont(getFont()); - graphics->drawText(getCaption(), 7, 5, gcn::Graphics::LEFT); + g->setColor(gcn::Color(0, 0, 0)); + g->setFont(getFont()); + g->drawText(getCaption(), 7, 5, gcn::Graphics::LEFT); } + // Draw Close Button + if (mCloseButton) + { + g->drawImage(closeImage, + getWidth() - closeImage->getWidth() - getPadding(), + getPadding() + ); + } drawChildren(graphics); } @@ -207,6 +222,8 @@ void Window::setWidth(int width) { mGrip->setX(getWidth() - mGrip->getWidth() - getChildrenArea().x); } + + fireWindowEvent(WindowEvent(this, WindowEvent::WINDOW_RESIZED)); } void Window::setHeight(int height) @@ -217,6 +234,8 @@ void Window::setHeight(int height) { mGrip->setY(getHeight() - mGrip->getHeight() - getChildrenArea().y); } + + fireWindowEvent(WindowEvent(this, WindowEvent::WINDOW_RESIZED)); } void Window::setDimension(const gcn::Rectangle &dimension) @@ -228,6 +247,27 @@ void Window::setDimension(const gcn::Rectangle &dimension) mGrip->setX(getWidth() - mGrip->getWidth() - getChildrenArea().x); mGrip->setY(getHeight() - mGrip->getHeight() - getChildrenArea().y); } + + fireWindowEvent(WindowEvent(this, WindowEvent::WINDOW_RESIZED)); + fireWindowEvent(WindowEvent(this, WindowEvent::WINDOW_MOVED)); +} + +void Window::setPosition(int x, int y) +{ + gcn::Window::setPosition(x, y); + fireWindowEvent(WindowEvent(this, WindowEvent::WINDOW_MOVED)); +} + +void Window::setX(int x) +{ + gcn::Window::setX(x); + fireWindowEvent(WindowEvent(this, WindowEvent::WINDOW_MOVED)); +} + +void Window::setY(int y) +{ + gcn::Window::setY(y); + fireWindowEvent(WindowEvent(this, WindowEvent::WINDOW_MOVED)); } void Window::setLocationRelativeTo(gcn::Widget *widget) @@ -280,6 +320,11 @@ void Window::setResizable(bool r) } } +void Window::setCloseButton(bool flag) +{ + mCloseButton = flag; +} + bool Window::isResizable() { return mResizable; @@ -327,27 +372,73 @@ void Window::mousePressed(gcn::MouseEvent &event) // Let Guichan move window to top and figure out title bar drag gcn::Window::mousePressed(event); - const int x = event.getX(); - const int y = event.getY(); - mMouseResize = 0; + if (event.getButton() == gcn::MouseEvent::LEFT) + { + const int x = event.getX(); + const int y = event.getY(); + + // Handle close button + if (mCloseButton) + { + gcn::Rectangle closeButtonRect( + getWidth() - closeImage->getWidth() - getPadding(), + getPadding(), + closeImage->getWidth(), + closeImage->getHeight()); + + if (closeButtonRect.isPointInRect(x, y)) + { + setVisible(false); + } + } + + // Handle window resizing + mouseResize = getResizeHandles(event); + } +} + +void Window::mouseReleased(gcn::MouseEvent &event) +{ + if (mResizable && mouseResize) + { + mouseResize = 0; + gui->setCursorType(Gui::CURSOR_POINTER); + } + + // This should be the responsibility of Guichan (and is from 0.8.0 on) + mIsMoving = false; +} - // Activate resizing handles as appropriate - if (event.getSource() == this && isResizable() && - event.getButton() == gcn::MouseEvent::LEFT && - !getChildrenArea().isPointInRect(x, y)) +void Window::mouseExited(gcn::MouseEvent &event) +{ + if (mResizable && !mouseResize) { - mMouseResize |= (x > getWidth() - resizeBorderWidth) ? RIGHT : - (x < resizeBorderWidth) ? LEFT : 0; - mMouseResize |= (y > getHeight() - resizeBorderWidth) ? BOTTOM : - (y < resizeBorderWidth) ? TOP : 0; + gui->setCursorType(Gui::CURSOR_POINTER); } - else if (event.getSource() == mGrip && - event.getButton() == gcn::MouseEvent::LEFT) +} + +void Window::mouseMoved(gcn::MouseEvent &event) +{ + int resizeHandles = getResizeHandles(event); + + // Changes the custom mouse cursor based on it's current position. + switch (resizeHandles) { - mDragOffsetX = x; - mDragOffsetY = y; - mMouseResize |= BOTTOM | RIGHT; - mIsMoving = false; + case BOTTOM | RIGHT: + gui->setCursorType(Gui::CURSOR_RESIZE_DOWN_RIGHT); + break; + case BOTTOM | LEFT: + gui->setCursorType(Gui::CURSOR_RESIZE_DOWN_LEFT); + break; + case BOTTOM: + gui->setCursorType(Gui::CURSOR_RESIZE_DOWN); + break; + case RIGHT: + case LEFT: + gui->setCursorType(Gui::CURSOR_RESIZE_ACROSS); + break; + default: + gui->setCursorType(Gui::CURSOR_POINTER); } } @@ -366,31 +457,31 @@ void Window::mouseDragged(gcn::MouseEvent &event) setPosition(newX, newY); } - if (mMouseResize && !mIsMoving) + if (mouseResize && !mIsMoving) { const int dx = event.getX() - mDragOffsetX; const int dy = event.getY() - mDragOffsetY; gcn::Rectangle newDim = getDimension(); - if (mMouseResize & (TOP | BOTTOM)) + if (mouseResize & (TOP | BOTTOM)) { - int newHeight = newDim.height + ((mMouseResize & TOP) ? -dy : dy); + int newHeight = newDim.height + ((mouseResize & TOP) ? -dy : dy); newDim.height = std::min(mMaxWinHeight, std::max(mMinWinHeight, newHeight)); - if (mMouseResize & TOP) + if (mouseResize & TOP) { newDim.y -= newDim.height - getHeight(); } } - if (mMouseResize & (LEFT | RIGHT)) + if (mouseResize & (LEFT | RIGHT)) { - int newWidth = newDim.width + ((mMouseResize & LEFT) ? -dx : dx); + int newWidth = newDim.width + ((mouseResize & LEFT) ? -dx : dx); newDim.width = std::min(mMaxWinWidth, std::max(mMinWinWidth, newWidth)); - if (mMouseResize & LEFT) + if (mouseResize & LEFT) { newDim.x -= newDim.width - getWidth(); } @@ -417,11 +508,11 @@ void Window::mouseDragged(gcn::MouseEvent &event) } // Update mouse offset when dragging bottom or right border - if (mMouseResize & BOTTOM) + if (mouseResize & BOTTOM) { mDragOffsetY += newDim.height - getHeight(); } - if (mMouseResize & RIGHT) + if (mouseResize & RIGHT) { mDragOffsetX += newDim.width - getWidth(); } @@ -469,3 +560,50 @@ void Window::resetToDefaultSize() setContentSize(mDefaultWidth, mDefaultHeight); updateContentSize(); } + +int Window::getResizeHandles(gcn::MouseEvent &event) +{ + int resizeHandles = 0; + const int y = event.getY(); + + if (mResizable && y > (int) mTitleBarHeight) + { + const int x = event.getX(); + + if (!getChildrenArea().isPointInRect(x, y) && + event.getSource() == this) + { + resizeHandles |= (x > getWidth() - resizeBorderWidth) ? RIGHT : + (x < resizeBorderWidth) ? LEFT : 0; + resizeHandles |= (y > getHeight() - resizeBorderWidth) ? BOTTOM : + (y < resizeBorderWidth) ? TOP : 0; + } + + if (event.getSource() == mGrip) + { + mDragOffsetX = x; + mDragOffsetY = y; + resizeHandles |= BOTTOM | RIGHT; + } + } + + return resizeHandles; +} + +void Window::fireWindowEvent(const WindowEvent &event) +{ + WindowListeners::iterator i_end = mListeners.end(); + WindowListeners::iterator i = mListeners.begin(); + + switch (event.getType()) + { + case WindowEvent::WINDOW_MOVED: + for (; i != i_end; ++i) + { (*i)->windowMoved(event); } + break; + case WindowEvent::WINDOW_RESIZED: + for (; i != i_end; ++i) + { (*i)->windowResized(event); } + break; + } +} diff --git a/src/gui/window.h b/src/gui/window.h index 1ba23fb2..ab266422 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -28,11 +28,14 @@ #include "../guichanfwd.h" +#include "windowlistener.h" + class ConfigListener; class GCContainer; class ImageRect; class ResizeGrip; class WindowContainer; +class Image; /** * A window. This window can be dragged around and has a title bar. Windows are @@ -119,16 +122,36 @@ class Window : public gcn::Window */ void setDimension(const gcn::Rectangle &dimension); + /** + * Sets the position of this window. + */ + void setPosition(int x, int y); + + /** + * Sets the window x coordinate. + */ + void setX(int x); + + /** + * Sets the window y coordinate. + */ + void setY(int y); + /** * Sets the location relative to the given widget. */ void setLocationRelativeTo(gcn::Widget *widget); /** - * Sets whether of not the window can be resized. + * Sets whether or not the window can be resized. */ void setResizable(bool resize); + /** + * Sets whether or not the window has a close button. + */ + void setCloseButton(bool flag); + /** * Returns whether the window can be resized. */ @@ -155,9 +178,14 @@ class Window : public gcn::Window void setMaxHeight(unsigned int height); /** - * Sets whether the window is sticky. - * A sticky window will not have its visibility set to false - * on a general setVisible(false) call. + * Sets flag to show a title or not. + */ + void setShowTitle(bool flag) + { mShowTitle = flag; } + + /** + * Sets whether the window is sticky. A sticky window will not have + * its visibility set to false on a general setVisible(false) call. */ void setSticky(bool sticky); @@ -167,10 +195,9 @@ class Window : public gcn::Window bool isSticky(); /** - * Overloads window setVisible by guichan to allow sticky window - * Handling + * Overloads window setVisible by Guichan to allow sticky window + * handling. */ - void setVisible(bool visible); /** @@ -198,6 +225,24 @@ class Window : public gcn::Window */ void mouseDragged(gcn::MouseEvent &event); + /** + * Implements custom cursor image changing context, based on mouse + * relative position. + */ + void mouseMoved(gcn::MouseEvent &event); + + /** + * When the mouse button has been let go, this ensures that the mouse + * custom cursor is restored back to it's standard image. + */ + void mouseReleased(gcn::MouseEvent &event); + + /** + * When the mouse leaves the window this ensures that the custom cursor + * is restored back to it's standard image. + */ + void mouseExited(gcn::MouseEvent &event); + /** * Read the x, y, and width and height for resizables in the config * based on the given string. @@ -216,11 +261,25 @@ class Window : public gcn::Window int defaultWidth, int defaultHeight); /** - * Reset the win pos and size to default. - * Don't forget to set defaults first. + * Reset the win pos and size to default. Don't forget to set defaults + * first. */ void resetToDefaultSize(); + /** + * Adds a listener to the list that's notified when the window is + * moved or resized. + */ + void addWindowListener(WindowListener *listener) + { mListeners.push_back(listener); } + + /** + * Removes a listener from the list that's notified when the window is + * moved or resized. + */ + void removeWindowListener(WindowListener *listener) + { mListeners.remove(listener); } + enum ResizeHandles { TOP = 0x01, @@ -233,13 +292,23 @@ class Window : public gcn::Window static WindowContainer *windowContainer; private: + /** + * Determines if the mouse is in a resize area and returns appropriate + * resize handles. Also initializes drag offset in case the resize + * grip is used. + * + * @see ResizeHandles + */ + int getResizeHandles(gcn::MouseEvent &event); + GCContainer *mChrome; /**< Contained container */ ResizeGrip *mGrip; /**< Resize grip */ Window *mParent; /**< The parent window */ std::string mConfigName; /**< Name used for saving window-related data */ + bool mShowTitle; /**< Window has a title bar */ bool mModal; /**< Window is modal */ bool mResizable; /**< Window can be resized */ - int mMouseResize; /**< Window is being resized */ + bool mCloseButton; /**< Window has a close button */ bool mSticky; /**< Window resists minimization */ int mMinWinWidth; /**< Minimum window width */ int mMinWinHeight; /**< Minimum window height */ @@ -255,8 +324,10 @@ class Window : public gcn::Window */ static ConfigListener *windowConfigListener; + static int mouseResize; /**< Active resize handles */ static int instances; /**< Number of Window instances */ static ImageRect border; /**< The window border and background */ + static Image *closeImage; /**< Close Button Image */ /** * The width of the resize border. Is independent of the actual window @@ -264,6 +335,14 @@ class Window : public gcn::Window * where two borders are moved at the same time. */ static const int resizeBorderWidth = 10; + + private: + /** + * Sends out a window event to the list of selection listeners. + */ + void fireWindowEvent(const WindowEvent &event); + + WindowListeners mListeners; }; #endif diff --git a/src/gui/windowlistener.h b/src/gui/windowlistener.h new file mode 100644 index 00000000..08aab71d --- /dev/null +++ b/src/gui/windowlistener.h @@ -0,0 +1,86 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef _TMW_WINDOW_LISTENER_H_ +#define _TMW_WINDOW_LISTENER_H_ + +#include +#include + +/** + * An event that characterizes a window move or resize. + * + * \ingroup GUI + */ +class WindowEvent : public gcn::Event +{ + public: + /** + * Constructor. + */ + WindowEvent(gcn::Window *source, int type): + gcn::Event(source) + { + mType = type; + } + + /** + * Returns the event type. + */ + int getType() const + { return mType; } + + enum WindowEventType + { + WINDOW_MOVED, + WINDOW_RESIZED + }; +}; + +/** + * The listener that's notified when a window is moved or resized. + * + * \ingroup GUI + */ +class WindowListener +{ + public: + /** + * Virtual destructor. + */ + virtual ~WindowListener() {} + + /** + * Called whenever the window is moved. + */ + virtual void windowMoved(const WindowEvent &event) {} + + /** + * Called whenever the window is resized. + */ + virtual void windowResized(const WindowEvent &event) {} +}; + +typedef std::list WindowListeners; + +#endif diff --git a/src/imageparticle.cpp b/src/imageparticle.cpp index 35cc21ad..17581a2a 100644 --- a/src/imageparticle.cpp +++ b/src/imageparticle.cpp @@ -31,12 +31,12 @@ ImageParticle::ImageParticle(Map *map, Image *image): Particle(map), mImage(image) { - mImage->incRef(); + if (mImage) mImage->incRef(); } ImageParticle::~ImageParticle() { - mImage->decRef(); + if (mImage) mImage->decRef(); } void ImageParticle::draw(Graphics *graphics, int offsetX, int offsetY) const @@ -44,8 +44,8 @@ void ImageParticle::draw(Graphics *graphics, int offsetX, int offsetY) const if (!mAlive) return; - int screenX = (int) mPosX + offsetX - mImage->getWidth() / 2; - int screenY = (int) mPosY - (int) mPosZ + offsetY - mImage->getHeight()/2; + int screenX = (int) mPos.x + offsetX - mImage->getWidth() / 2; + int screenY = (int) mPos.y - (int)mPos.z + offsetY - mImage->getHeight()/2; // Check if on screen if (screenX + mImage->getWidth() < 0 || diff --git a/src/itemshortcut.cpp b/src/itemshortcut.cpp new file mode 100644 index 00000000..8a514c7e --- /dev/null +++ b/src/itemshortcut.cpp @@ -0,0 +1,87 @@ +/* + * The Mana World + * Copyright 2007 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "itemshortcut.h" + +#include "localplayer.h" +#include "configuration.h" + +#include "utils/tostring.h" + +ItemShortcut::ItemShortcut *itemShortcut; + +ItemShortcut::ItemShortcut(): + mItemSelected(NULL) +{ + for (int i = 0; i < SHORTCUT_ITEMS; i++) + { + mItems[i] = NULL; + } +} + +ItemShortcut::~ItemShortcut() +{ + save(); +} + +void ItemShortcut::load() +{ + for (int i = 0; i < SHORTCUT_ITEMS; i++) + { + int itemId = (int) config.getValue("itemShortcut" + toString(i), -1); + + if (itemId != -1) + { + ItemPtr item = player_node->searchForItem(itemId); + if (item) + { + mItems[i] = item; + } + } + } +} + +void ItemShortcut::save() +{ + for (int i = 0; i < SHORTCUT_ITEMS; i++) + { + if (mItems[i]) + { + config.setValue("shortcut" + toString(i), mItems[i]->getId()); + } + else + { + config.setValue("shortcut" + toString(i), -1); + } + } +} + +void ItemShortcut::useItem(int index) +{ + if (mItems[index]) + { + if (mItems[index]->getQuantity()) { + // TODO: Fix this (index vs. pointer mismatch) + //player_node->useItem(mItems[index]); + } + } +} diff --git a/src/itemshortcut.h b/src/itemshortcut.h new file mode 100644 index 00000000..d211c7f3 --- /dev/null +++ b/src/itemshortcut.h @@ -0,0 +1,130 @@ +/* + * The Mana World + * Copyright 2007 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef _TMW_ITEMSHORTCUT_H__ +#define _TMW_ITEMSHORTCUT_H__ + +#include "item.h" + +#define SHORTCUT_ITEMS 10 + +/** + * The item pointer + */ +typedef Item* ItemPtr; + +class ItemShortcut +{ + public: + /** + * Constructor. + */ + ItemShortcut(); + + /** + * Destructor. + */ + ~ItemShortcut(); + + /** + * Load the configuration information. + */ + void load(); + + /** + * Returns the shortcut item specified by the index. + * + * @param index Index of the shortcut item. + */ + ItemPtr getItem(int index) const + { return mItems[index]; } + + /** + * Returns the amount of shortcut items. + */ + int getItemCount() const + { return SHORTCUT_ITEMS; } + + /** + * Returns the item that is currently selected. + */ + ItemPtr getItemSelected() const + { return mItemSelected; } + + /** + * Adds the selected item to the items specified by the index. + * + * @param index Index of the items. + */ + void setItem(int index) + { mItems[index] = mItemSelected; } + + /** + * Adds an item to the items store specified by the index. + * + * @param index Index of the items. + * @param item Item to store. + */ + void setItems(int index, Item *item) + { mItems[index] = item; } + + /** + * Set the item that is selected. + * + * @param item The item that is to be assigned. + */ + void setItemSelected(ItemPtr item) + { mItemSelected = item; } + + /** + * A flag to check if the item is selected. + */ + bool isItemSelected() + { return (mItemSelected) ? true : false; } + + /** + * Remove a item from the shortcut. + */ + void removeItem(int index) + { mItems[index] = NULL; } + + /** + * Try to use the item specified by the index. + * + * @param index Index of the item shortcut. + */ + void useItem(int index); + + private: + /** + * Save the configuration information. + */ + void save(); + + ItemPtr mItems[SHORTCUT_ITEMS]; /**< the items stored */ + ItemPtr mItemSelected; /**< the item held by cursor */ + +}; + +extern ItemShortcut *itemShortcut; + +#endif diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp new file mode 100644 index 00000000..271961c8 --- /dev/null +++ b/src/keyboardconfig.cpp @@ -0,0 +1,144 @@ +/* + * The Mana World + * Copyright 2007 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#include "keyboardconfig.h" +#include "configuration.h" +#include "log.h" + +#include + +#include "gui/setup_keyboard.h" + +struct KeyData +{ + const char *configField; + int defaultValue; + const char *caption; +}; + +// keyData must be in same order as enum keyAction. +static KeyData const keyData[KeyboardConfig::KEY_TOTAL] = { + {"keyMoveUp", SDLK_UP, "Move Up"}, + {"keyMoveDown", SDLK_DOWN, "Move Down"}, + {"keyMoveLeft", SDLK_LEFT, "Move Left"}, + {"keyMoveRight", SDLK_RIGHT, "Move Right"}, + {"keyAttack", SDLK_LCTRL, "Attack"}, + {"keyTarget", SDLK_LSHIFT, "Target"}, + {"keyTargetClosest", SDLK_a, "Target Closest"}, + {"keyPickup", SDLK_z, "Pickup"}, + {"keyHideWindows", SDLK_h, "Hide Windows"}, + {"keyBeingSit", SDLK_s, "Sit"}, + {"keyShortcut0", SDLK_0, "Item Shortcut 0"}, + {"keyShortcut1", SDLK_1, "Item Shortcut 1"}, + {"keyShortcut2", SDLK_2, "Item Shortcut 2"}, + {"keyShortcut3", SDLK_3, "Item Shortcut 3"}, + {"keyShortcut4", SDLK_4, "Item Shortcut 4"}, + {"keyShortcut5", SDLK_5, "Item Shortcut 5"}, + {"keyShortcut6", SDLK_6, "Item Shortcut 6"}, + {"keyShortcut7", SDLK_7, "Item Shortcut 7"}, + {"keyShortcut8", SDLK_8, "Item Shortcut 8"}, + {"keyShortcut9", SDLK_9, "Item Shortcut 9"} +}; + +void KeyboardConfig::init() +{ + for (int i = 0; i < KEY_TOTAL; i++) + { + mKey[i].configField = keyData[i].configField; + mKey[i].defaultValue = keyData[i].defaultValue; + mKey[i].caption = keyData[i].caption; + mKey[i].value = KEY_NO_VALUE; + } + mNewKeyIndex = KEY_NO_VALUE; + mEnabled = true; + + retrieve(); +} + +void KeyboardConfig::retrieve() +{ + for (int i = 0; i < KEY_TOTAL; i++) + { + mKey[i].value = (int) config.getValue( + mKey[i].configField, mKey[i].defaultValue); + } +} + +void KeyboardConfig::store() +{ + for (int i = 0; i < KEY_TOTAL; i++) + { + config.setValue(mKey[i].configField, mKey[i].value); + } +} + +void KeyboardConfig::makeDefault() +{ + for (int i = 0; i < KEY_TOTAL; i++) + { + mKey[i].value = mKey[i].defaultValue; + } +} + +bool KeyboardConfig::hasConflicts() +{ + int i, j; + for (i = 0; i < KEY_TOTAL; i++) + { + for (j = 0; j < KEY_TOTAL; j++) + { + if (i != j && mKey[i].value == mKey[j].value) + { + return true; + } + } + } + return false; +} + +void KeyboardConfig::callbackNewKey() +{ + mSetupKey->newKeyCallback(mNewKeyIndex); +} + +int KeyboardConfig::getKeyIndex(int keyValue) const +{ + for (int i = 0; i < KEY_TOTAL; i++) + { + if(keyValue == mKey[i].value) + { + return i; + } + } + return KEY_NO_VALUE; +} + +bool KeyboardConfig::isKeyActive(int index) +{ + return mActiveKeys[ mKey[index].value]; +} + +void KeyboardConfig::refreshActiveKeys() +{ + mActiveKeys = SDL_GetKeyState(NULL); +} diff --git a/src/keyboardconfig.h b/src/keyboardconfig.h new file mode 100644 index 00000000..46394fa5 --- /dev/null +++ b/src/keyboardconfig.h @@ -0,0 +1,185 @@ +/* + * The Mana World + * Copyright 2007 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef _TMW_KEYBOARDCONFIG_H +#define _TMW_KEYBOARDCONFIG_H + +#include + +#include "gui/setup_keyboard.h" + +#include + +/** + * Each key represents a key function. Such as 'Move up', 'Attack' etc. + */ +struct KeyFunction +{ + const char* configField; /** Field index that is in the config file. */ + int defaultValue; /** The default key value used. */ + std::string caption; /** The caption value for the key function. */ + int value; /** The actual value that is used. */ +}; + +class KeyboardConfig +{ + public: + /** + * Initializes the keyboard config explicitly. + */ + void init(); + + /** + * Retrieve the key values from config file. + */ + void retrieve(); + + /** + * Store the key values to config file. + */ + void store(); + + /** + * Make the keys their default values. + */ + void makeDefault(); + + /** + * Determines if any key assignments are the same as each other. + */ + bool hasConflicts(); + + /** + * Calls a function back so the key re-assignment(s) can be seen. + */ + void callbackNewKey(); + + /** + * Obtain the value stored in memory. + */ + int getKeyValue(int index) const + { return mKey[index].value; } + + /** + * Get the index of the new key to be assigned. + */ + int getNewKeyIndex() const + { return mNewKeyIndex; } + + /** + * Get the enable flag, which will stop the user from doing actions. + */ + bool isEnabled() const + { return mEnabled; } + + /** + * Get the key caption, providing more meaning to the user. + */ + const std::string &getKeyCaption(int index) const + { return mKey[index].caption; } + + /** + * Get the key function index by providing the keys value. + */ + int getKeyIndex(int keyValue) const; + + /** + * Set the enable flag, which will stop the user from doing actions. + */ + void setEnabled(bool flag) + { mEnabled = flag; } + + /** + * Set the index of the new key to be assigned. + */ + void setNewKeyIndex(int value) + { mNewKeyIndex = value; } + + /** + * Set the value of the new key. + */ + void setNewKey(int value) + { mKey[mNewKeyIndex].value = value; } + + /** + * Set a reference to the key setup window. + */ + void setSetupKeyboard(Setup_Keyboard *setupKey) + { mSetupKey = setupKey; } + + /** + * Checks if the key is active, by providing the key function index. + */ + bool isKeyActive(int index); + + /** + * Takes a snapshot of all the active keys. + */ + void refreshActiveKeys(); + + /** + * All the key functions. + * KEY_NO_VALUE is used in initialization, and should be unchanged. + * KEY_TOTAL should always be last (used as a conditional in loops). + * The key assignment view gets arranged according to the order of + * these values. + */ + enum KeyAction { + KEY_NO_VALUE = -1, + KEY_MOVE_UP, + KEY_MOVE_DOWN, + KEY_MOVE_LEFT, + KEY_MOVE_RIGHT, + KEY_ATTACK, + KEY_TARGET, + KEY_TARGET_CLOSEST, + KEY_PICKUP, + KEY_HIDE_WINDOWS, + KEY_SIT, + KEY_SHORTCUT_0, + KEY_SHORTCUT_1, + KEY_SHORTCUT_2, + KEY_SHORTCUT_3, + KEY_SHORTCUT_4, + KEY_SHORTCUT_5, + KEY_SHORTCUT_6, + KEY_SHORTCUT_7, + KEY_SHORTCUT_8, + KEY_SHORTCUT_9, + KEY_TOTAL + }; + + private: + int mNewKeyIndex; /**< Index of new key to be assigned */ + bool mEnabled; /**< Flag to respond to key input */ + + Setup_Keyboard *mSetupKey; /**< Reference to setup window */ + + KeyFunction mKey[KEY_TOTAL]; /**< Pointer to all the key data */ + + Uint8 *mActiveKeys; /**< Stores a list of all the keys */ +}; + +extern KeyboardConfig keyboard; + +#endif diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 95e7a478..f4ad7587 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -29,11 +29,19 @@ #include "inventory.h" #include "item.h" #include "main.h" +#include "particle.h" #include "sound.h" #include "log.h" #include "net/gameserver/player.h" +#include "gui/gui.h" + +#include "net/messageout.h" +#include "net/protocol.h" + +#include "utils/tostring.h" + LocalPlayer *player_node = NULL; LocalPlayer::LocalPlayer(): @@ -46,6 +54,7 @@ LocalPlayer::LocalPlayer(): mLevel(1), mMoney(0), mTotalWeight(1), mMaxWeight(1), mHP(1), mMaxHP(1), + mXp(0), mTarget(NULL), mPickUpTarget(NULL), mTrading(false), mLastAction(-1), mWalkingDir(0), @@ -112,6 +121,17 @@ LocalPlayer::moveInvItem(Item *item, int newIndex) item->getInvIndex(), newIndex, item->getQuantity()); } +Item* LocalPlayer::searchForItem(int itemId) +{ + for (int i = 0; i < INVENTORY_SIZE; i++) + { + if (itemId == mInventory->getItem(i)->getId()) { + return mInventory->getItem(i); + } + } + return NULL; +} + void LocalPlayer::equipItem(Item *item) { Net::GameServer::Player::equip(item->getInvIndex()); @@ -302,10 +322,14 @@ void LocalPlayer::attack() setAction(ATTACK); - if (getWeapon() == 2) - sound.playSfx("sfx/bow_shoot_1.ogg"); - else + if (mEquippedWeapon) + { + std::string soundFile = mEquippedWeapon->getSound(EQUIP_EVENT_STRIKE); + if (soundFile != "") sound.playSfx(soundFile); + } + else { sound.playSfx("sfx/fist-swish.ogg"); + } Net::GameServer::Player::attack(getSpriteDirection()); } @@ -329,3 +353,16 @@ void LocalPlayer::raiseAttribute(size_t attr) mAttributeBase.at(attr)++; // TODO: Inform the server about our desire to raise the attribute } + +void LocalPlayer::setXp(int xp) +{ + if (mMap && xp > mXp) + { + const std::string text = toString(xp - mXp) + " xp"; + + // Show XP number + particleEngine->addTextRiseFadeOutEffect(text, hitYellowFont, + mPx + 16, mPy - 16); + } + mXp = xp; +} diff --git a/src/localplayer.h b/src/localplayer.h index 4f38fdad..ff7bf0b7 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -151,6 +151,14 @@ class LocalPlayer : public Player */ void moveInvItem(Item *item, int newIndex); + /** + * Searches for the specified item by it's identification. + * + * @param itemId The id of the item to be searched. + * @return Item found on success, NULL on failure. + */ + Item* searchForItem(int itemId); + /** * Equips an item. */ @@ -237,6 +245,19 @@ class LocalPlayer : public Player int getHP() const { return mHP; } + /** + * Sets the amount of XP. Shows XP gaining effect if the player is on + * a map. + */ + void setXp(int xp); + + /** + * Returns the amount of experience points. + */ + int getXp() const { return mXp; } + + Uint32 mCharId; + int getMaxHP() const { return mMaxHP; } @@ -298,6 +319,7 @@ class LocalPlayer : public Player int mMaxWeight; int mHP; int mMaxHP; + int mXp; /**< Experience points. */ Being *mTarget; FloorItem *mPickUpTarget; diff --git a/src/main.cpp b/src/main.cpp index 1f4eafde..30fb7c1c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -48,8 +48,10 @@ #endif #include "configuration.h" +#include "keyboardconfig.h" #include "game.h" #include "graphics.h" +#include "itemshortcut.h" #include "lockedarray.h" #include "localplayer.h" #include "log.h" @@ -84,7 +86,6 @@ #include "net/gameserver/gameserver.h" -#include "resources/equipmentdb.h" #include "resources/image.h" #include "resources/itemdb.h" #include "resources/monsterdb.h" @@ -108,6 +109,7 @@ Music *bgm; Configuration config; /**< XML file configuration reader */ Logger *logger; /**< Log object */ +KeyboardConfig keyboard; Net::Connection *accountServerConnection = 0; Net::Connection *gameServerConnection = 0; @@ -189,7 +191,6 @@ void initConfiguration(const Options &options) config.setValue("fpslimit", 0); config.setValue("updatehost", "http://updates.themanaworld.org"); config.setValue("customcursor", 1); - config.setValue("homeDir", homeDir); // Checking if the configuration file exists... otherwise create it with // default options. @@ -319,6 +320,9 @@ void initEngine() // Initialize for drawing graphics->_beginDraw(); + // Initialize the item shortcuts. + itemShortcut = new ItemShortcut(); + gui = new Gui(graphics); state = STATE_CHOOSE_SERVER; /**< Initial game state */ @@ -337,12 +341,19 @@ void initEngine() errorMessage = err; logger->log("Warning: %s", err); } + + // Initialize keyboard + keyboard.init(); } /** Clear the engine */ void exit_engine() { + // Before config.write() since it writes the shortcuts to the config + delete itemShortcut; + config.write(); + delete gui; delete graphics; @@ -353,7 +364,6 @@ void exit_engine() sound.close(); // Unload XML databases - EquipmentDB::unload(); ItemDB::unload(); MonsterDB::unload(); @@ -457,7 +467,6 @@ void loadUpdates() const std::string updatesFile = "updates/resources2.txt"; ResourceManager *resman = ResourceManager::getInstance(); std::vector lines = resman->loadTextFile(updatesFile); - std::string homeDir = config.getValue("homeDir", ""); for (unsigned int i = 0; i < lines.size(); ++i) { @@ -895,7 +904,6 @@ int main(int argc, char *argv[]) false); // Load XML databases - EquipmentDB::load(); ItemDB::load(); MonsterDB::load(); state = STATE_LOGIN; @@ -1039,7 +1047,6 @@ int main(int argc, char *argv[]) } } } - } catch (...) { diff --git a/src/monster.cpp b/src/monster.cpp index 768bf16a..2522a3e1 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -57,7 +57,7 @@ Monster::setAction(Action action) break; case DEAD: currentAction = ACTION_DEAD; - sound.playSfx(getInfo().getSound(EVENT_DIE)); + sound.playSfx(getInfo().getSound(MONSTER_EVENT_DIE)); break; case ATTACK: currentAction = ACTION_ATTACK; @@ -87,10 +87,10 @@ Monster::handleAttack() const MonsterInfo &mi = getInfo(); - // TODO: It's not possible to determine hit or miss here, so this stuff probably needs - // to be moved somewhere else. We may lose synchronization between attack animation and - // the sound, unless we adapt the protocol... - sound.playSfx(mi.getSound(EVENT_HIT)); + // TODO: It's not possible to determine hit or miss here, so this stuff + // probably needs to be moved somewhere else. We may lose synchronization + // between attack animation and the sound, unless we adapt the protocol... + sound.playSfx(mi.getSound(MONSTER_EVENT_HIT)); } Being::TargetCursorSize diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index 87972212..b88d443e 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -114,7 +114,7 @@ void BeingHandler::handleMessage(MessageIn &msg) dstBeing = beingManager->findBeing(id); - if (dstBeing == NULL) + if (!dstBeing) { // Being with id >= 110000000 and job 0 are better // known as ghosts, so don't create those. @@ -138,30 +138,32 @@ void BeingHandler::handleMessage(MessageIn &msg) dstBeing->setWalkSpeed(speed); dstBeing->mJob = job; - dstBeing->setHairStyle(msg.readShort()); - dstBeing->setWeapon(msg.readShort()); + dstBeing->setHairStyle(msg->readShort()); + dstBeing->setVisibleEquipment( + Being::WEAPON_SPRITE, msg->readShort()); dstBeing->setVisibleEquipment( - Being::BOTTOMCLOTHES_SPRITE, msg.readShort()); + Being::BOTTOMCLOTHES_SPRITE, msg->readShort()); if (msg.getId() == SMSG_BEING_MOVE) { msg.readLong(); // server tick } - msg.readShort(); // shield - dstBeing->setVisibleEquipment(Being::HAIT_SPRITE, msg.readShort()); - dstBeing->setVisibleEquipment( - Being::TOPCLOTHES_SPRITE, msg.readShort()); - dstBeing->setHairColor(msg.readShort()); - msg.readShort(); // unknown - msg.readShort(); // head dir - msg.readShort(); // guild - msg.readShort(); // unknown - msg.readShort(); // unknown - msg.readShort(); // manner - msg.readShort(); // karma - msg.readByte(); // unknown - dstBeing->setSex(1 - msg.readByte()); // sex + msg->readShort(); // shield + headTop = msg->readShort(); + headMid = msg->readShort(); + dstBeing->setVisibleEquipment(Being::HAT_SPRITE, headTop); + dstBeing->setVisibleEquipment(Being::TOPCLOTHES_SPRITE, headMid); + dstBeing->setHairColor(msg->readShort()); + msg->readShort(); // unknown + msg->readShort(); // head dir + msg->readShort(); // guild + msg->readShort(); // unknown + msg->readShort(); // unknown + msg->readShort(); // manner + msg->readShort(); // karma + msg->readByte(); // unknown + dstBeing->setSex(1 - msg->readByte()); // sex if (msg.getId() == SMSG_BEING_MOVE) { @@ -256,10 +258,12 @@ void BeingHandler::handleMessage(MessageIn &msg) } Particle *levelupFX; if (msg->readLong() == 0) { // type - levelupFX = particleEngine->addEffect("graphics/particles/levelup.particle.xml", 0, 0); + levelupFX = particleEngine->addEffect( + "graphics/particles/levelup.particle.xml", 0, 0); } else { - levelupFX = particleEngine->addEffect("graphics/particles/skillup.particle.xml", 0, 0); + levelupFX = particleEngine->addEffect( + "graphics/particles/skillup.particle.xml", 0, 0); } beingManager->findBeing(id)->controlParticle(levelupFX); break; @@ -289,28 +293,26 @@ void BeingHandler::handleMessage(MessageIn &msg) dstBeing->setHairStyle(id); break; case 2: - dstBeing->setWeapon(id); + dstBeing->setVisibleEquipment(Being::WEAPON_SPRITE, id); break; case 3: // Change lower headgear for eAthena, pants for us dstBeing->setVisibleEquipment( - Being::BOTTOMCLOTHES_SPRITE, - id); + Being::BOTTOMCLOTHES_SPRITE, id); break; case 4: // Change upper headgear for eAthena, hat for us dstBeing->setVisibleEquipment( - Being::HAT_SPRITE, - id); + Being::HAT_SPRITE, id); break; case 5: // Change middle headgear for eathena, armor for us dstBeing->setVisibleEquipment( - Being::TOPCLOTHES_SPRITE, - id); + Being::TOPCLOTHES_SPRITE, id); break; case 6: dstBeing->setHairColor(id); break; default: - logger->log("c3: %i\n", id); // unsupported + logger->log("SMSG_BEING_CHANGE_LOOKS: unsupported type: " + "%d, id: %d", type, id); break; } } @@ -336,17 +338,18 @@ void BeingHandler::handleMessage(MessageIn &msg) dstBeing = beingManager->findBeing(id); - if (dstBeing == NULL) + if (!dstBeing) { dstBeing = beingManager->createBeing(id, job); } dstBeing->setWalkSpeed(speed); dstBeing->mJob = job; - dstBeing->setHairStyle(msg.readShort()); - dstBeing->setWeaponById(msg.readShort()); // item id 1 - msg.readShort(); // item id 2 - headBottom = msg.readShort(); + dstBeing->setHairStyle(msg->readShort()); + dstBeing->setVisibleEquipment( + Being::WEAPON_SPRITE, msg->readShort()); + msg->readShort(); // item id 2 + headBottom = msg->readShort(); if (msg.getId() == SMSG_PLAYER_MOVE) { @@ -407,9 +410,9 @@ void BeingHandler::handleMessage(MessageIn &msg) case 0x0119: // Change in players look - logger->log("0x0119 %li %i %i %x %i\n", msg.readLong(), - msg.readShort(), msg.readShort(), msg.readShort(), - msg.readByte()); + logger->log("0x0119 %i %i %i %x %i", msg->readLong(), + msg->readShort(), msg->readShort(), msg->readShort(), + msg->readByte()); break; */ } @@ -428,11 +431,9 @@ static void handleLooks(Being *being, MessageIn &msg) if (mask & (1 << 7)) { // The equipment has to be cleared first. - being->setWeaponById(0); for (int i = 0; i < nb_slots; ++i) { - if (slots[i] != Being::WEAPON_SPRITE) - being->setVisibleEquipment(slots[i], 0); + being->setVisibleEquipment(slots[i], 0); } } @@ -441,10 +442,7 @@ static void handleLooks(Being *being, MessageIn &msg) { if (!(mask & (1 << i))) continue; int id = msg.readShort(); - if (slots[i] != Being::WEAPON_SPRITE) - being->setVisibleEquipment(slots[i], id); - else - being->setWeaponById(id); + being->setVisibleEquipment(slots[i], id); } } diff --git a/src/net/chathandler.cpp b/src/net/chathandler.cpp index 3efe3174..afdc2ab5 100644 --- a/src/net/chathandler.cpp +++ b/src/net/chathandler.cpp @@ -37,6 +37,7 @@ #include "../gui/chat.h" #include "../utils/tostring.h" +#include "../utils/trim.h" extern Being *player_node; @@ -167,6 +168,7 @@ void ChatHandler::handleMessage(MessageIn &msg) chatMsg = msg.readString(chatMsgLength); chatWindow->chatLog(chatMsg, BY_OTHER); chatMsg.erase(0, chatMsg.find(" : ", 0) + 3); + trim(chatMsg); being->setSpeech(chatMsg, SPEECH_TIME); break; diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp index 354dd685..de74e8f5 100644 --- a/src/net/inventoryhandler.cpp +++ b/src/net/inventoryhandler.cpp @@ -31,6 +31,7 @@ #include "../equipment.h" #include "../inventory.h" #include "../item.h" +#include "../itemshortcut.h" #include "../localplayer.h" #include "../gui/chat.h" @@ -77,6 +78,7 @@ void InventoryHandler::handleMessage(MessageIn &msg) it->setQuantity(amount); } }; + itemShortcut->load(); break; } } diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index b94b5128..afaeca69 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -133,7 +133,8 @@ void PlayerHandler::handleMessage(MessageIn &msg) } else { - logger->log("Warning: server wants to update unknown attribute %d to %d", stat, value); + logger->log("Warning: server wants to update unknown " + "attribute %d to %d", stat, value); } } } break; diff --git a/src/particle.cpp b/src/particle.cpp index 805da102..148bbf6f 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -52,14 +52,12 @@ const float Particle::PARTICLE_SKY = 800.0f; Particle::Particle(Map *map): mAlive(true), - mPosX(0.0f), mPosY(0.0f), mPosZ(0.0f), mLifetimeLeft(-1), mLifetimePast(0), mFadeOut(0), mFadeIn(0), mAutoDelete(true), mMap(map), - mVectorX(0.0f), mVectorY(0.0f), mVectorZ(0.0f), mGravity(0.0f), mRandomnes(0), mBounce(0.0f), @@ -109,7 +107,7 @@ Particle::update() p++ ) { - (*p)->moveBy(mPosX, mPosY, mPosZ); + (*p)->moveBy(mPos.x, mPos.y, mPos.z); mChildParticles.push_back (*p); } } @@ -117,31 +115,28 @@ Particle::update() if (mMomentum != 1.0f) { - mVectorX *= mMomentum; - mVectorY *= mMomentum; - mVectorZ *= mMomentum; + mVelocity *= mMomentum; } if (mTarget && mAcceleration != 0.0f) { - float distX = (mPosX - mTarget->getPosX()) * SIN45; - float distY = mPosY - mTarget->getPosY(); - float distZ = mPosZ - mTarget->getPosZ(); + Vector dist = mPos - mTarget->getPosition(); + dist.x *= SIN45; float invHypotenuse; - switch(Particle::fastPhysics) + switch (Particle::fastPhysics) { case 1: invHypotenuse = fastInvSqrt( - distX * distX + distY * distY + distZ * distZ); + dist.x * dist.x + dist.y * dist.y + dist.z * dist.z); break; case 2: invHypotenuse = 2.0f / - fabs(distX) + fabs(distY) + fabs(distZ); + fabs(dist.x) + fabs(dist.y) + fabs(dist.z); break; default: invHypotenuse = 1.0f / sqrt( - distX * distX + distY * distY + distZ * distZ); + dist.x * dist.x + dist.y * dist.y + dist.z * dist.z); break; } @@ -152,25 +147,23 @@ Particle::update() mAlive = false; } float accFactor = invHypotenuse * mAcceleration; - mVectorX -= distX * accFactor; - mVectorY -= distY * accFactor; - mVectorZ -= distZ * accFactor; + mVelocity -= dist * accFactor; } } if (mRandomnes > 0) { - mVectorX += (rand()%mRandomnes - rand()%mRandomnes) / 1000.0f; - mVectorY += (rand()%mRandomnes - rand()%mRandomnes) / 1000.0f; - mVectorZ += (rand()%mRandomnes - rand()%mRandomnes) / 1000.0f; + mVelocity.x += (rand()%mRandomnes - rand()%mRandomnes) / 1000.0f; + mVelocity.y += (rand()%mRandomnes - rand()%mRandomnes) / 1000.0f; + mVelocity.z += (rand()%mRandomnes - rand()%mRandomnes) / 1000.0f; } - mVectorZ -= mGravity; + mVelocity.z -= mGravity; // Update position - mPosX += mVectorX; - mPosY += mVectorY * SIN45; - mPosZ += mVectorZ * SIN45; + mPos.x += mVelocity.x; + mPos.y += mVelocity.y * SIN45; + mPos.z += mVelocity.z * SIN45; // Update other stuff if (mLifetimeLeft > 0) @@ -179,14 +172,13 @@ Particle::update() } mLifetimePast++; - if (mPosZ > PARTICLE_SKY || mPosZ < 0.0f) + if (mPos.z > PARTICLE_SKY || mPos.z < 0.0f) { if (mBounce > 0.0f) { - mPosZ *= -mBounce; - mVectorX *= mBounce; - mVectorY *= mBounce; - mVectorZ *= -mBounce; + mPos.z *= -mBounce; + mVelocity *= mBounce; + mVelocity.z = -mVelocity.z; } else { mAlive = false; @@ -195,10 +187,8 @@ Particle::update() } // Update child particles - for ( ParticleIterator p = mChildParticles.begin(); - p != mChildParticles.end(); - - ) + for (ParticleIterator p = mChildParticles.begin(); + p != mChildParticles.end();) { if ((*p)->update()) { @@ -217,14 +207,9 @@ Particle::update() return true; } - -void Particle::draw(Graphics *graphics, int offsetX, int offsetY) const -{ -} - - Particle* -Particle::addEffect(std::string particleEffectFile, int pixelX, int pixelY) +Particle::addEffect(const std::string &particleEffectFile, + int pixelX, int pixelY) { Particle *newParticle = NULL; @@ -289,9 +274,9 @@ Particle::addEffect(std::string particleEffectFile, int pixelX, int pixelY) int offsetY = XML::getProperty(effectChildNode, "position-y", 0); int offsetZ = XML::getProperty(effectChildNode, "position-z", 0); - int particleX = (int)mPosX + pixelX + offsetX; - int particleY = (int)mPosY + pixelY + offsetY; - int particleZ = (int)mPosZ + offsetZ; + int particleX = (int) mPos.x + pixelX + offsetX; + int particleY = (int) mPos.y + pixelY + offsetY; + int particleZ = (int) mPos.z + offsetZ; int lifetime = XML::getProperty(effectChildNode, "lifetime", -1); @@ -317,17 +302,16 @@ Particle::addEffect(std::string particleEffectFile, int pixelX, int pixelY) Particle* -Particle::addTextSplashEffect(std::string text, +Particle::addTextSplashEffect(const std::string &text, int colorR, int colorG, int colorB, gcn::Font *font, int x, int y) { Particle *newParticle = new TextParticle(mMap, text, colorR, colorG, colorB, font); newParticle->setPosition(x, y, 0); - newParticle->setVector ( ((rand()%100) - 50) / 200.0f, // X vector - ((rand()%100) - 50) / 200.0f, // Y vector - ((rand()%100) / 200.0f) + 4.0f // Z vector - ); + newParticle->setVelocity(((rand() % 100) - 50) / 200.0f, // X + ((rand() % 100) - 50) / 200.0f, // Y + ((rand() % 100) / 200.0f) + 4.0f); // Z newParticle->setGravity(0.1f); newParticle->setBounce(0.5f); newParticle->setLifetime(200); @@ -338,14 +322,28 @@ Particle::addTextSplashEffect(std::string text, return newParticle; } +Particle* +Particle::addTextRiseFadeOutEffect(const std::string &text, gcn::Font *font, + int x, int y) +{ + Particle *newParticle = new TextParticle(mMap, text, 255, 255, 255, font); + newParticle->setPosition(x, y, 0); + newParticle->setVelocity(0.0f, 0.0f, 0.5f); + newParticle->setGravity(0.0015f); + newParticle->setLifetime(300); + newParticle->setFadeOut(50); + newParticle->setFadeIn(200); + + mChildParticles.push_back(newParticle); + + return newParticle; +} void Particle::setMap(Map *map) { mMap = map; if (mMap) setSpriteIterator(mMap->addSprite(this)); - - // TODO: Create map emitters based on emitter data in map data } diff --git a/src/particle.h b/src/particle.h index 9e9223c7..dd7c5ee2 100644 --- a/src/particle.h +++ b/src/particle.h @@ -31,7 +31,7 @@ #include "guichanfwd.h" #include "sprite.h" - +#include "vector.h" class Map; class Particle; @@ -67,43 +67,37 @@ class Particle : public Sprite ~Particle(); /** - * Deletes all child particles and emitters + * Deletes all child particles and emitters. */ void clear(); /** * Gives a particle the properties of an engine root particle and loads - * the particle-related config settings + * the particle-related config settings. */ void setupEngine(); /** * Updates particle position, returns false when the particle should - * be deleted + * be deleted. */ virtual bool update(); /** - * Draws the particle image + * Draws the particle image. */ virtual void - draw(Graphics *graphics, int offsetX, int offsetY) const; + draw(Graphics *graphics, int offsetX, int offsetY) const {} /** - * Necessary for sorting with the other sprites + * Necessary for sorting with the other sprites. */ virtual int getPixelY() const - { - return (int)(mPosY + mPosZ) - 64; - }; - - /* - Basic Particle properties: - */ + { return (int) (mPos.y + mPos.z) - 64; } /** * Sets the map the particle is on. @@ -115,15 +109,24 @@ class Particle : public Sprite * particleEffectFile. */ Particle* - addEffect(std::string particleEffectFile, int pixelX, int pixelY); + addEffect(const std::string &particleEffectFile, + int pixelX, int pixelY); /** * Creates a standalone text particle. */ Particle* - addTextSplashEffect(std::string text, int colorR, int colorG, int colorB, + addTextSplashEffect(const std::string &text, + int colorR, int colorG, int colorB, gcn::Font *font, int x, int y); + /** + * Creates a standalone text particle. + */ + Particle* + addTextRiseFadeOutEffect(const std::string &text, gcn::Font *font, + int x, int y); + /** * Adds an emitter to the particle. */ @@ -132,34 +135,31 @@ class Particle : public Sprite { mChildEmitters.push_back(emitter); } /** - * Sets the position in 3 dimensional space in pixels relative to map + * Sets the position in 3 dimensional space in pixels relative to map. */ void setPosition(float x, float y, float z) - { mPosX = x; mPosY = y; mPosZ = z; } + { mPos.x = x; mPos.y = y; mPos.z = z; } /** - * Sets the position in 2 dimensional space in pixels relative to map + * Sets the position in 2 dimensional space in pixels relative to map. */ void setPosition(float x, float y) - { mPosX = x; mPosY = y; } - - float getPosX() const - { return mPosX; } + { mPos.x = x; mPos.y = y; } - float getPosY() const - { return mPosY; } - - float getPosZ() const - { return mPosZ; } + /** + * Returns the particle position. + */ + const Vector& getPosition() const + { return mPos; } /** * Changes the particle position relative */ void moveBy(float x, float y, float z) - { mPosX += x; mPosY += y; mPosZ += z; } + { mPos.x += x; mPos.y += y; mPos.z += z; } /** * Sets the time in game ticks until the particle is destroyed. @@ -170,48 +170,48 @@ class Particle : public Sprite /** * Sets the age of the pixel in game ticks where the particle has - * faded in completely + * faded in completely. */ void - setFadeOut (int fadeOut) + setFadeOut(int fadeOut) { mFadeOut = fadeOut; } /** * Sets the remaining particle lifetime where the particle starts to - * fade out + * fade out. */ void - setFadeIn (int fadeIn) + setFadeIn(int fadeIn) { mFadeIn = fadeIn; } /** * Sets the sprite iterator of the particle on the current map to make - * it easier to remove the particle from the map when it is destroyed + * it easier to remove the particle from the map when it is destroyed. */ void setSpriteIterator(std::list::iterator spriteIterator) { mSpriteIterator = spriteIterator; } /** - * Gets the sprite iterator of the particle on the current map + * Gets the sprite iterator of the particle on the current map. */ std::list::iterator getSpriteIterator() const { return mSpriteIterator; } /** - * Sets the current velocity in 3 dimensional space + * Sets the current velocity in 3 dimensional space. */ void - setVector(float x, float y, float z) - { mVectorX = x; mVectorY = y; mVectorZ = z; } + setVelocity(float x, float y, float z) + { mVelocity.x = x; mVelocity.y = y; mVelocity.z = z; } /** - * Sets the downward acceleration + * Sets the downward acceleration. */ void - setGravity(float g) - { mGravity = g; } + setGravity(float gravity) + { mGravity = gravity; } /** * Sets the ammount of random vector changes @@ -237,8 +237,8 @@ class Particle : public Sprite /** * Sets the distance in pixel the particle can come near the target - * particle before it is destroyed. Does only make sense after a - * target particle has been set using setDestination. + * particle before it is destroyed. Does only make sense after a target + * particle has been set using setDestination. */ void setDieDistance(float dist) { mInvDieDistance = 1.0f / dist; } @@ -247,7 +247,7 @@ class Particle : public Sprite { return mAlive; } /** - * Manually marks the particle for deletion + * Manually marks the particle for deletion. */ void kill() { mAlive = false; mAutoDelete = true; } @@ -261,7 +261,7 @@ class Particle : public Sprite protected: bool mAlive; /**< Is the particle supposed to be drawn and updated?*/ - float mPosX, mPosY, mPosZ; /**< Position in 3 dimensonal space - pixel based relative to map */ + Vector mPos; /**< Position in pixels relative to map. */ int mLifetimeLeft; /**< Lifetime left in game ticks*/ int mLifetimePast; /**< Age of the particle in game ticks*/ int mFadeOut; /**< Lifetime in game ticks left where fading out begins*/ @@ -269,17 +269,19 @@ class Particle : public Sprite private: // generic properties - bool mAutoDelete; /**< May the particle request its deletion by the parent particle?*/ - Map *mMap; /**< Map the particle is on*/ + bool mAutoDelete; /**< May the particle request its deletion by the parent particle? */ + Map *mMap; /**< Map the particle is on. */ std::list::iterator mSpriteIterator; /**< iterator of the particle on the current map */ - Emitters mChildEmitters; /**< List of child emitters*/ - Particles mChildParticles; /**< List of particles controlled by this particle*/ - //dynamic particle - float mVectorX, mVectorY, mVectorZ; /**< Speed in 3 dimensional space in pixels per game-tick */ - float mGravity; /**< Downward acceleration in pixels per game-tick²*/ - int mRandomnes; /**< Ammount of random vector change*/ - float mBounce; /**< How much the particle bounces off when hitting the ground*/ - //follow-point particles + Emitters mChildEmitters; /**< List of child emitters. */ + Particles mChildParticles; /**< List of particles controlled by this particle */ + + // dynamic particle + Vector mVelocity; /**< Speed in pixels per game-tick. */ + float mGravity; /**< Downward acceleration in pixels per game-tick. */ + int mRandomnes; /**< Ammount of random vector change */ + float mBounce; /**< How much the particle bounces off when hitting the ground */ + + // follow-point particles Particle *mTarget; /**< The particle that attracts this particle*/ float mAcceleration; /**< Acceleration towards the target particle in pixels per game-tick²*/ float mInvDieDistance; /**< Distance in pixels from the target particle that causes the destruction of the particle*/ diff --git a/src/particleemitter.cpp b/src/particleemitter.cpp index 60a98cc5..035882b6 100644 --- a/src/particleemitter.cpp +++ b/src/particleemitter.cpp @@ -248,10 +248,9 @@ ParticleEmitter::readMinMax(xmlNodePtr propertyNode, T def) { MinMax retval; - def = (T)XML::getFloatProperty(propertyNode, "value", (double)def); - retval.set ( (T)XML::getFloatProperty(propertyNode, "min", (double)def), - (T)XML::getFloatProperty(propertyNode, "max", (double)def) - ); + def = (T) XML::getFloatProperty(propertyNode, "value", (double) def); + retval.set((T) XML::getFloatProperty(propertyNode, "min", (double) def), + (T) XML::getFloatProperty(propertyNode, "max", (double) def)); return retval; } @@ -284,19 +283,17 @@ ParticleEmitter::createParticles() newParticle->setPosition( - mParticlePosX.value(), - mParticlePosY.value(), - mParticlePosZ.value() - ); + mParticlePosX.value(), + mParticlePosY.value(), + mParticlePosZ.value()); float angleH = mParticleAngleHorizontal.value(); float angleV = mParticleAngleVertical.value(); float power = mParticlePower.value(); - newParticle->setVector( - cos(angleH) * cos(angleV) * power, - sin(angleH) * cos(angleV) * power, - sin(angleV) * power - ); + newParticle->setVelocity( + cos(angleH) * cos(angleV) * power, + sin(angleH) * cos(angleV) * power, + sin(angleV) * power); newParticle->setRandomnes(mParticleRandomnes.value()); newParticle->setGravity(mParticleGravity.value()); @@ -312,10 +309,9 @@ ParticleEmitter::createParticles() newParticle->setFadeOut(mParticleFadeOut.value()); newParticle->setFadeIn(mParticleFadeIn.value()); - for ( std::list::iterator i = mParticleChildEmitters.begin(); - i != mParticleChildEmitters.end(); - i++ - ) + for (std::list::iterator i = mParticleChildEmitters.begin(); + i != mParticleChildEmitters.end(); + i++) { newParticle->addEmitter(new ParticleEmitter(*i)); } diff --git a/src/player.cpp b/src/player.cpp index d3c27aa0..b63dcd5b 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -28,7 +28,8 @@ #include "graphics.h" #include "log.h" -#include "resources/equipmentdb.h" +#include "resources/itemdb.h" +#include "resources/iteminfo.h" #include "utils/tostring.h" @@ -37,7 +38,6 @@ Player::Player(Uint16 id, Uint16 job, Map *map): Being(id, job, map) { - setWeapon(0); } Being::Type @@ -93,8 +93,8 @@ Player::setSex(Uint8 sex) if (i != HAIR_SPRITE && mEquipmentSpriteIDs.at(i) != 0) { AnimatedSprite *newEqSprite = new AnimatedSprite( - "graphics/sprites/" + EquipmentDB::get( - mEquipmentSpriteIDs.at(i))->getSprite(sex)); + "graphics/sprites/" + ItemDB::get( + mEquipmentSpriteIDs.at(i)).getSprite(sex)); delete mSprites[i]; mSprites[i] = newEqSprite; } @@ -102,39 +102,6 @@ Player::setSex(Uint8 sex) } } -void -Player::setWeapon(Uint16 weapon) -{ - if (weapon != mWeapon) - { - AnimatedSprite *newWeaponSprite = NULL; - - switch (weapon) - { - case 0: - newWeaponSprite = - new AnimatedSprite("graphics/sprites/weapon-fist.xml"); - break; - case 1: - newWeaponSprite = - new AnimatedSprite("graphics/sprites/weapon-dagger.xml"); - break; - case 2: - newWeaponSprite = - new AnimatedSprite("graphics/sprites/weapon-bow.xml"); - break; - case 3: - newWeaponSprite = - new AnimatedSprite("graphics/sprites/weapon-scythe.xml"); - break; - } - - delete mSprites[WEAPON_SPRITE]; - mSprites[WEAPON_SPRITE] = newWeaponSprite; - } - Being::setWeapon(weapon); -} - void Player::setHairColor(Uint16 color) { @@ -189,11 +156,11 @@ Player::setVisibleEquipment(Uint8 slot, int id) if (mSex == 0) { equipmentSprite = new AnimatedSprite( - "graphics/sprites/" + EquipmentDB::get(id)->getSprite(0)); + "graphics/sprites/" + ItemDB::get(id).getSprite(0)); } else { equipmentSprite = new AnimatedSprite( - "graphics/sprites/" + EquipmentDB::get(id)->getSprite(1)); + "graphics/sprites/" + ItemDB::get(id).getSprite(1)); } equipmentSprite->setDirection(getSpriteDirection()); @@ -201,6 +168,11 @@ Player::setVisibleEquipment(Uint8 slot, int id) delete mSprites[slot]; mSprites[slot] = equipmentSprite; + if (slot == WEAPON_SPRITE) + { + mEquippedWeapon = &ItemDB::get(id); + } + setAction(mAction); } diff --git a/src/player.h b/src/player.h index 8aa84992..2c06bfba 100644 --- a/src/player.h +++ b/src/player.h @@ -59,9 +59,6 @@ class Player : public Being virtual void setVisibleEquipment(Uint8 slot, int id); - - virtual void - setWeapon(Uint16 weapon); }; #endif diff --git a/src/resources/equipmentdb.cpp b/src/resources/equipmentdb.cpp deleted file mode 100644 index 38ac6415..00000000 --- a/src/resources/equipmentdb.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/* - * The Mana World - * Copyright 2006 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id$ - */ - -#include "equipmentdb.h" - -#include "resourcemanager.h" - -#include "../log.h" - -#include "../utils/dtor.h" -#include "../utils/xml.h" - -namespace -{ - EquipmentDB::EquipmentInfos mEquipmentInfos; - EquipmentInfo mUnknown; - bool mLoaded = false; -} - -void -EquipmentDB::load() -{ - if (mLoaded) - return; - - logger->log("Initializing equipment database..."); - mUnknown.setSprite("error.xml", 0); - mUnknown.setSprite("error.xml", 1); - - ResourceManager *resman = ResourceManager::getInstance(); - int size; - char *data = (char*)resman->loadFile("equipment.xml", size); - - if (!data) - { - logger->error("Equipment Database: Could not find equipment.xml!"); - } - - xmlDocPtr doc = xmlParseMemory(data, size); - free(data); - - if (!doc) - { - logger->error("Equipment Database: Error while parsing equipment database (equipment.xml)!"); - } - - xmlNodePtr rootNode = xmlDocGetRootElement(doc); - if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "equipments")) - { - logger->error("Equipment Database: equipment.xml is not a valid database file!"); - } - - //iterate s - for_each_xml_child_node(equipmentNode, rootNode) - { - if (!xmlStrEqual(equipmentNode->name, BAD_CAST "equipment")) - { - continue; - } - - EquipmentInfo *currentInfo = new EquipmentInfo(); - - currentInfo->setSlot (XML::getProperty(equipmentNode, "slot", 0)); - - //iterate s - for_each_xml_child_node(spriteNode, equipmentNode) - { - if (!xmlStrEqual(spriteNode->name, BAD_CAST "sprite")) - { - continue; - } - - std::string gender = XML::getProperty(spriteNode, "gender", "unisex"); - std::string filename = (const char*) spriteNode->xmlChildrenNode->content; - - if (gender == "male" || gender == "unisex") - { - currentInfo->setSprite(filename, 0); - } - - if (gender == "female" || gender == "unisex") - { - currentInfo->setSprite(filename, 1); - } - } - - setEquipment( XML::getProperty(equipmentNode, "id", 0), - currentInfo); - } - - mLoaded = true; -} - -void -EquipmentDB::unload() -{ - // kill EquipmentInfos - for_each ( mEquipmentInfos.begin(), mEquipmentInfos.end(), - make_dtor(mEquipmentInfos)); - mEquipmentInfos.clear(); - - mLoaded = false; -} - -EquipmentInfo* -EquipmentDB::get(int id) -{ - if (!mLoaded) { - logger->error("Error: Equipment database used before initialization!"); - } - - EquipmentInfoIterator i = mEquipmentInfos.find(id); - - if (i == mEquipmentInfos.end() ) - { - logger->log("EquipmentDB: Error, unknown equipment ID# %d", id); - return &mUnknown; - } - else - { - return i->second; - } -} - -void -EquipmentDB::setEquipment(int id, EquipmentInfo* equipmentInfo) -{ - if (mEquipmentInfos.find(id) != mEquipmentInfos.end()) { - logger->log("Warning: Equipment Piece with ID %d defined multiple times", - id); - delete equipmentInfo; - } - else { - mEquipmentInfos[id] = equipmentInfo; - }; -} diff --git a/src/resources/equipmentdb.h b/src/resources/equipmentdb.h deleted file mode 100644 index 1c1db7d1..00000000 --- a/src/resources/equipmentdb.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * The Mana World - * Copyright 2006 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id$ - */ - -#ifndef _TMW_EQUIPMENT_DB_H -#define _TMW_EQUIPMENT_DB_H - -#include - -#include "equipmentinfo.h" - -/** - * Equipment information database. - */ -namespace EquipmentDB -{ - /** - * Loads the equipment info from Items.xml - */ - void load(); - - /** - * Frees equipment data - */ - void unload(); - - void setEquipment(int id, EquipmentInfo* equipmentInfo); - - EquipmentInfo* get(int id); - - // Equipment database types - typedef std::map EquipmentInfos; - typedef EquipmentInfos::iterator EquipmentInfoIterator; -} - -#endif diff --git a/src/resources/equipmentinfo.h b/src/resources/equipmentinfo.h deleted file mode 100644 index 75ed1b8a..00000000 --- a/src/resources/equipmentinfo.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * The Mana World - * Copyright 2006 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id: - */ - -#ifndef _TMW_EQUIPMENTINFO_H_ -#define _TMW_EQUIPMENTINFO_H_ - -#include -#include - -class EquipmentInfo -{ - public: - EquipmentInfo(): - mSlot (0) - { - }; - - void - setSlot (int slot) { mSlot = slot; }; - - const std::string& - getSprite(int gender) {return animationFiles[gender]; }; - - void - setSprite(std::string animationFile, int gender) {animationFiles[gender] = animationFile; }; - - private: - int mSlot; //not used at the moment but maybe useful on our own server - std::map animationFiles; -}; - -#endif diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 7b16339c..18952ae9 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -18,9 +18,11 @@ * along with The Mana World; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: + * $Id$ */ +#include + #include "itemdb.h" #include @@ -36,10 +38,13 @@ namespace { ItemDB::ItemInfos mItemInfos; - ItemInfo mUnknown; + ItemInfo *mUnknown; bool mLoaded = false; } +// Forward declarations +static void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node); +static void loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node); void ItemDB::load() { @@ -47,11 +52,16 @@ void ItemDB::load() return; logger->log("Initializing item database..."); - mUnknown.setName("Unknown item"); + + mUnknown = new ItemInfo(); + mUnknown->setName("Unknown item"); + mUnknown->setImage(""); + mUnknown->setSprite("error.xml", 0); + mUnknown->setSprite("error.xml", 1); ResourceManager *resman = ResourceManager::getInstance(); int size; - char *data = (char*)resman->loadFile("items.xml", size); + char *data = (char*) resman->loadFile("items.xml", size); if (!data) { logger->error("ItemDB: Could not find items.xml!"); @@ -73,48 +83,66 @@ void ItemDB::load() for_each_xml_child_node(node, rootNode) { - if (!xmlStrEqual(node->name, BAD_CAST "item")) { + if (!xmlStrEqual(node->name, BAD_CAST "item")) continue; - } int id = XML::getProperty(node, "id", 0); - int art = XML::getProperty(node, "art", 0); + + if (id == 0) + { + logger->log("ItemDB: Invalid or missing item ID in items.xml!"); + continue; + } + else if (mItemInfos.find(id) != mItemInfos.end()) + { + logger->log("ItemDB: Redefinition of item ID %d", id); + } + int type = XML::getProperty(node, "type", 0); int weight = XML::getProperty(node, "weight", 0); + int view = XML::getProperty(node, "view", 0); int slot = XML::getProperty(node, "slot", 0); std::string name = XML::getProperty(node, "name", ""); std::string image = XML::getProperty(node, "image", ""); std::string description = XML::getProperty(node, "description", ""); std::string effect = XML::getProperty(node, "effect", ""); + std::string attackType = XML::getProperty(node, "attacktype", ""); - if (id && name != "") + if (id) { ItemInfo *itemInfo = new ItemInfo(); itemInfo->setImage(image); - itemInfo->setArt(art); - itemInfo->setName(name); + itemInfo->setName((name == "") ? "Unnamed" : name); itemInfo->setDescription(description); itemInfo->setEffect(effect); itemInfo->setType(type); + itemInfo->setView(view); itemInfo->setWeight(weight); itemInfo->setSlot(slot); - mItemInfos[id] = itemInfo; - } + itemInfo->setAttackType(attackType); + + for_each_xml_child_node(itemChild, node) + { + if (xmlStrEqual(itemChild->name, BAD_CAST "sprite")) + { + loadSpriteRef(itemInfo, itemChild); + } + else if (xmlStrEqual(itemChild->name, BAD_CAST "sound")) + { + loadSoundRef(itemInfo, itemChild); + } + } - if (id == 0) - { - logger->log("ItemDB: An item has no ID in items.xml!"); + mItemInfos[id] = itemInfo; } #define CHECK_PARAM(param, error_value) \ if (param == error_value) \ - logger->log("ItemDB: Missing" #param " parameter for item %i! %s", \ - id, name.c_str()) + logger->log("ItemDB: Missing " #param " attribute for item %i!",id) CHECK_PARAM(name, ""); CHECK_PARAM(image, ""); - // CHECK_PARAM(art, 0); // CHECK_PARAM(description, ""); // CHECK_PARAM(effect, ""); // CHECK_PARAM(type, 0); @@ -131,19 +159,65 @@ void ItemDB::load() void ItemDB::unload() { - for (ItemInfoIterator i = mItemInfos.begin(); i != mItemInfos.end(); i++) - { - delete i->second; - } - mItemInfos.clear(); + logger->log("Unloading item database..."); + + delete mUnknown; + mUnknown = NULL; + for_each(mItemInfos.begin(), mItemInfos.end(), make_dtor(mItemInfos)); + mItemInfos.clear(); mLoaded = false; } -const ItemInfo& -ItemDB::get(int id) +const ItemInfo& ItemDB::get(int id) { + assert(mLoaded); + ItemInfoIterator i = mItemInfos.find(id); - return (i != mItemInfos.end()) ? *(i->second) : mUnknown; + if (i == mItemInfos.end()) + { + logger->log("ItemDB: Error, unknown item ID# %d", id); + return *mUnknown; + } + else + { + return *(i->second); + } +} + +void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node) +{ + std::string gender = XML::getProperty(node, "gender", "unisex"); + std::string filename = (const char*) node->xmlChildrenNode->content; + + if (gender == "male" || gender == "unisex") + { + itemInfo->setSprite(filename, 0); + } + + if (gender == "female" || gender == "unisex") + { + itemInfo->setSprite(filename, 1); + } +} + +void loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node) +{ + std::string event = XML::getProperty(node, "event", ""); + std::string filename = (const char*) node->xmlChildrenNode->content; + + if (event == "hit") + { + itemInfo->addSound(EQUIP_EVENT_HIT, filename); + } + else if (event == "strike") + { + itemInfo->addSound(EQUIP_EVENT_STRIKE, filename); + } + else + { + logger->log("ItemDB: Ignoring unknown sound event '%s'", + event.c_str()); + } } diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp index 3a41c657..b5b25ac0 100644 --- a/src/resources/iteminfo.cpp +++ b/src/resources/iteminfo.cpp @@ -25,11 +25,11 @@ #include "resourcemanager.h" #include "image.h" - +#include "itemdb.h" ItemInfo::~ItemInfo() { - if (mImage != NULL) + if (mImage) { mImage->decRef(); } @@ -38,19 +38,87 @@ ItemInfo::~ItemInfo() void ItemInfo::setImage(const std::string &image) { + if (mImage) + { + mImage->decRef(); + } + + ResourceManager *resman = ResourceManager::getInstance(); mImageName = "graphics/items/" + image; + mImage = ResourceManager::getInstance()->getImage(mImageName); - if (mImageName != "") + if (!mImage) { - if (mImage != NULL) - { - mImage->decRef(); - } + mImage = resman->getImage("graphics/gui/unknown-item.png"); + } +} - mImage = ResourceManager::getInstance()->getImage(mImageName); +const std::string& +ItemInfo::getSprite(int gender) const +{ + if (mView) + { + // Forward the request to the item defining how to view this item + return ItemDB::get(mView).getSprite(gender); } else { - mImage = NULL; + static const std::string empty = ""; + std::map::const_iterator i = + mAnimationFiles.find(gender); + + return (i != mAnimationFiles.end()) ? i->second : empty; + } +} + +void +ItemInfo::setAttackType(const std::string &attackType) +{ + if (attackType == "swing") + { + mAttackType = ACTION_ATTACK_SWING; + } + else if (attackType == "stab") + { + mAttackType = ACTION_ATTACK_STAB; + } + else if (attackType == "bow") + { + mAttackType = ACTION_ATTACK_BOW; } + else if (attackType == "throw") + { + mAttackType = ACTION_ATTACK_THROW; + } + else if (attackType == "none") + { + mAttackType = ACTION_DEFAULT; + } + else + { + mAttackType = ACTION_ATTACK; + } +} + +void +ItemInfo::addSound(EquipmentSoundEvent event, const std::string &filename) +{ + if (mSounds.find(event) == mSounds.end()) + { + mSounds[event] = new std::vector; + } + + mSounds[event]->push_back("sfx/" + filename); +} + + +const std::string& +ItemInfo::getSound(EquipmentSoundEvent event) const +{ + static const std::string empty = ""; + std::map*>::const_iterator i; + i = mSounds.find(event); + + return (i == mSounds.end()) ? empty : + i->second->at(rand() % i->second->size()); } diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index e4f851bb..4fd1638e 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -24,12 +24,23 @@ #ifndef _TMW_ITEMINFO_H_ #define _TMW_ITEMINFO_H_ +#include #include +#include + +#include "spritedef.h" class Image; +enum EquipmentSoundEvent +{ + EQUIP_EVENT_STRIKE, + EQUIP_EVENT_HIT +}; + /** - * Defines a class for storing item infos. + * Defines a class for storing item infos. This includes information used when + * the item is equipped. */ class ItemInfo { @@ -40,10 +51,11 @@ class ItemInfo ItemInfo(): mImageName(""), mImage(NULL), - mArt(0), mType(0), mWeight(0), - mSlot(0) + mView(0), + mSlot(0), + mAttackType(ACTION_DEFAULT) { } @@ -52,73 +64,89 @@ class ItemInfo */ ~ItemInfo(); - void - setArt(short art) { mArt = art; } + void setName(const std::string &name) + { mName = name; } - short - getArt() const { return mArt; } + const std::string& getName() const + { return mName; } - void - setName(const std::string &name) { mName = name; } + void setImage(const std::string &image); - const std::string& - getName() const { return mName; } + Image* getImage() const + { return mImage; } - void - setImage(const std::string &image); + void setDescription(const std::string &description) + { mDescription = description; } - Image* - getImage() const { return mImage; } + const std::string& getDescription() const + { return mDescription; } - void - setDescription(const std::string &description) - { - mDescription = description; - } + void setEffect(const std::string &effect) + { mEffect = effect; } const std::string& - getDescription() const { return mDescription; } + getEffect() const { return mEffect; } - void - setEffect(const std::string &effect) { mEffect = effect; } + void setType(short type) + { mType = type; } - const std::string& - getEffect() const { return mEffect; } + short getType() const + { return mType; } + + void setWeight(short weight) + { mWeight = weight; } + + short getWeight() const + { return mWeight; } + + void setView(int view) + { mView = view; } + + void setSlot(char slot) + { mSlot = slot; } - void - setType(short type) { mType = type; } + char getSlot() const + { return mSlot; } - short - getType() const { return mType; } + void setSprite(const std::string &animationFile, int gender) + { mAnimationFiles[gender] = animationFile; } - void - setWeight(short weight) { mWeight = weight; } + const std::string& getSprite(int gender) const; - short - getWeight() const { return mWeight; } + void setAttackType(const std::string &attackType); - void - setSlot(char slot) { mSlot = slot; } + const SpriteAction getAttackType() const + { return mAttackType; } - char - getSlot() const { return mSlot; } + void addSound(EquipmentSoundEvent event, const std::string &filename); + + const std::string& getSound(EquipmentSoundEvent event) const; protected: - std::string mImageName; + std::string mImageName; /**< The filename of the icon image. */ /* TODO (BL): I do not think the item info should keep a reference to * the item icon. It would probably be better if this was kept in the * Item class, so that the images can be lazily instantiated and also * unloaded when no longer used. */ - Image *mImage; - short mArt; + Image *mImage; /**< The loaded icon image. */ std::string mName; - std::string mDescription; - std::string mEffect; - short mType; - short mWeight; - char mSlot; + std::string mDescription; /**< Short description. */ + std::string mEffect; /**< Description of effects. */ + short mType; /**< Item type (never used). */ + short mWeight; /**< Weight in grams. */ + int mView; /**< Item ID of how this item looks. */ + + // Equipment related members + char mSlot; /**< Equipment slot. */ + SpriteAction mAttackType; /**< Attack type, in case of weapon. */ + + /** Maps gender to sprite filenames. */ + std::map mAnimationFiles; + + /** Stores the names of sounds to be played at certain event. */ + std::map* > mSounds; }; #endif diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 260d5aa9..940ded36 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -156,7 +156,7 @@ MapReader::readMap(const std::string &filename) if (buffer == NULL) { - logger->log("Map file not found (%s)\n", filename.c_str()); + logger->log("Map file not found (%s)", filename.c_str()); return NULL; } diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp index 339ed6ba..f4864eea 100644 --- a/src/resources/monsterdb.cpp +++ b/src/resources/monsterdb.cpp @@ -120,19 +120,19 @@ MonsterDB::load() if (event == "hit") { - currentInfo->addSound(EVENT_HIT, filename); + currentInfo->addSound(MONSTER_EVENT_HIT, filename); } else if (event == "miss") { - currentInfo->addSound(EVENT_MISS, filename); + currentInfo->addSound(MONSTER_EVENT_MISS, filename); } else if (event == "hurt") { - currentInfo->addSound(EVENT_HURT, filename); + currentInfo->addSound(MONSTER_EVENT_HURT, filename); } else if (event == "die") { - currentInfo->addSound(EVENT_DIE, filename); + currentInfo->addSound(MONSTER_EVENT_DIE, filename); } else { diff --git a/src/resources/monsterinfo.cpp b/src/resources/monsterinfo.cpp index 2a59419e..2e896237 100644 --- a/src/resources/monsterinfo.cpp +++ b/src/resources/monsterinfo.cpp @@ -33,15 +33,15 @@ MonsterInfo::MonsterInfo(): MonsterInfo::~MonsterInfo() { - //kill vectors in mSoundEffects - for_each ( mSounds.begin(), mSounds.end(), - make_dtor(mSounds)); + // kill vectors in mSoundEffects + for_each (mSounds.begin(), mSounds.end(), + make_dtor(mSounds)); mSounds.clear(); } void -MonsterInfo::addSound (SoundEvent event, std::string filename) +MonsterInfo::addSound(MonsterSoundEvent event, std::string filename) { if (mSounds.find(event) == mSounds.end()) { @@ -53,9 +53,9 @@ MonsterInfo::addSound (SoundEvent event, std::string filename) std::string -MonsterInfo::getSound (SoundEvent event) const +MonsterInfo::getSound(MonsterSoundEvent event) const { - std::map* >::const_iterator i; + std::map* >::const_iterator i; i = mSounds.find(event); diff --git a/src/resources/monsterinfo.h b/src/resources/monsterinfo.h index aa7db9f0..c9fbd4c9 100644 --- a/src/resources/monsterinfo.h +++ b/src/resources/monsterinfo.h @@ -31,12 +31,12 @@ #include "../being.h" -enum SoundEvent +enum MonsterSoundEvent { - EVENT_HIT, - EVENT_MISS, - EVENT_HURT, - EVENT_DIE + MONSTER_EVENT_HIT, + MONSTER_EVENT_MISS, + MONSTER_EVENT_HURT, + MONSTER_EVENT_DIE }; /** @@ -69,7 +69,7 @@ class MonsterInfo { mTargetCursorSize = targetCursorSize; } void - addSound(SoundEvent event, std::string filename); + addSound(MonsterSoundEvent event, std::string filename); const std::string& getName () const { return mName; }; @@ -81,13 +81,13 @@ class MonsterInfo getTargetCursorSize() const { return mTargetCursorSize; } std::string - getSound (SoundEvent event) const; + getSound(MonsterSoundEvent event) const; private: std::string mName; std::string mSprite; Being::TargetCursorSize mTargetCursorSize; - std::map* > mSounds; + std::map* > mSounds; }; #endif diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h index 6d335b02..55d7f459 100644 --- a/src/resources/spritedef.h +++ b/src/resources/spritedef.h @@ -24,11 +24,11 @@ #ifndef _TMW_SPRITEDEF_H #define _TMW_SPRITEDEF_H -#include "resource.h" - #include #include +#include "resource.h" + #include class Action; diff --git a/src/textparticle.cpp b/src/textparticle.cpp index dd01d2fe..4bc859cd 100644 --- a/src/textparticle.cpp +++ b/src/textparticle.cpp @@ -26,7 +26,8 @@ #include "graphics.h" TextParticle::TextParticle(Map *map, const std::string &text, - int colorR, int colorG, int colorB, gcn::Font *font): + int colorR, int colorG, int colorB, + gcn::Font *font): Particle(map), mText(text), mTextFont(font), @@ -41,8 +42,8 @@ void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const if (!mAlive) return; - int screenX = (int)mPosX + offsetX; - int screenY = (int)mPosY - int(mPosZ) + offsetY; + int screenX = (int) mPos.x + offsetX; + int screenY = (int) mPos.y - (int) mPos.z + offsetY; int alpha = 255; @@ -50,7 +51,7 @@ void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const { alpha *= mLifetimeLeft; alpha /= mFadeOut; - }; + } if (mLifetimePast < mFadeIn) { @@ -59,6 +60,6 @@ void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const } graphics->setFont(mTextFont); - graphics->setColor(gcn::Color (mColorR, mColorG, mColorB, alpha)); + graphics->setColor(gcn::Color(mColorR, mColorG, mColorB, alpha)); graphics->drawText(mText, screenX, screenY, gcn::Graphics::CENTER); } diff --git a/src/textparticle.h b/src/textparticle.h index b365c885..34badb57 100644 --- a/src/textparticle.h +++ b/src/textparticle.h @@ -33,21 +33,26 @@ class TextParticle : public Particle { public: + /** + * Constructor. + */ TextParticle(Map *map, const std::string &text, - int colorR, int colorG, int colorB, gcn::Font *font); + int colorR, int colorG, int colorB, + gcn::Font *font); /** - * Draws the particle image + * Draws the particle image. */ virtual void draw(Graphics *graphics, int offsetX, int offsetY) const; // hack to improve text visibility - virtual int getPixelY() const { return (int)(mPosY + mPosZ); } + virtual int getPixelY() const + { return (int) (mPos.y + mPos.z); } private: - std::string mText; /**< Text of the particle */ - gcn::Font *mTextFont; /**< Font used for drawing the text */ - int mColorR, mColorG, mColorB; /**< Color used for drawing the text */ + std::string mText; /**< Text of the particle. */ + gcn::Font *mTextFont; /**< Font used for drawing the text. */ + int mColorR, mColorG, mColorB; /**< Color used for drawing the text. */ }; #endif diff --git a/src/utils/fastsqrt.h b/src/utils/fastsqrt.h index 78768149..b7b036e9 100644 --- a/src/utils/fastsqrt.h +++ b/src/utils/fastsqrt.h @@ -5,6 +5,8 @@ * http://www.math.purdue.edu/~clomont/Math/Papers/2003/InvSqrt.pdf * * Unfortunately the original creator of this function seems to be unknown. + * + * $Id$ */ float fastInvSqrt(float x) diff --git a/src/utils/minmax.h b/src/utils/minmax.h index 27eb2565..ea6ad9e0 100644 --- a/src/utils/minmax.h +++ b/src/utils/minmax.h @@ -18,6 +18,7 @@ * along with The Mana World; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * + * $Id$ */ /** diff --git a/src/utils/trim.h b/src/utils/trim.h new file mode 100644 index 00000000..1b5311e6 --- /dev/null +++ b/src/utils/trim.h @@ -0,0 +1,53 @@ +/* + * The Mana World + * Copyright 2007 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef _TMW_UTILS_TRIM_H_ +#define _TMW_UTILS_TRIM_H_ + +#include + +/** + * Trims spaces off the end and the beginning of the given string. + * + * @param str the string to trim spaces off + */ +static void trim(std::string &str) +{ + std::string::size_type pos = str.find_last_not_of(' '); + if (pos != std::string::npos) + { + str.erase(pos + 1); + pos = str.find_first_not_of(' '); + if (pos != std::string::npos) + { + str.erase(0, pos); + } + } + else + { + // There is nothing else but whitespace in the string + str.clear(); + } +} + +#endif diff --git a/src/vector.h b/src/vector.h new file mode 100644 index 00000000..7a5da241 --- /dev/null +++ b/src/vector.h @@ -0,0 +1,134 @@ +/* + * The Mana World + * Copyright 2007 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef _TMW_VECTOR_H_ +#define _TMW_VECTOR_H_ + +/** + * Vector class. Represents either a 3D point in space, a velocity or a force. + * Provides several convenient operator overloads. + */ +class Vector +{ + public: + /** + * Constructor. + */ + Vector(): + x(0.0f), + y(0.0f), + z(0.0f) + {} + + /** + * Constructor. + */ + Vector(float x, float y, float z): + x(x), + y(y), + z(z) + {} + + /** + * Copy constructor. + */ + Vector(const Vector &v): + x(v.x), + y(v.y), + z(v.z) + {} + + /** + * Scale vector operator. + */ + Vector operator*(float c) const + { + return Vector(x * c, + y * c, + z * c); + } + + /** + * In-place scale vector operator. + */ + void operator*=(float c) + { + x *= c; + y *= c; + z *= c; + } + + /** + * Scale vector operator. + */ + Vector operator/(float c) const + { + return Vector(x / c, + y / c, + z / c); + } + + /** + * Add vector operator. + */ + Vector operator+(const Vector &v) const + { + return Vector(x + v.x, + y + v.y, + z + v.z); + } + + /** + * In-place add vector operator. + */ + void operator+=(const Vector &v) + { + x += v.x; + y += v.y; + z += v.z; + } + + /** + * Substract vector operator. + */ + Vector operator-(const Vector &v) const + { + return Vector(x - v.x, + y - v.y, + z - v.z); + } + + /** + * In-place substract vector operator. + */ + void operator-=(const Vector &v) + { + x -= v.x; + y -= v.y; + z -= v.z; + } + + float x, y, z; +}; + +#endif diff --git a/tools/adler32.c b/tools/adler32.c new file mode 100644 index 00000000..4e851713 --- /dev/null +++ b/tools/adler32.c @@ -0,0 +1,67 @@ +/* + * adler32.c (c) 2006 Bjorn Lindeijer + * License: GPL, v2 or later + * + * Calculates Adler-32 checksums for all files passed as argument. + * + * Usage: adler32 [file]... + */ + +#include +#include + +/** + * Calculates the Adler-32 checksum for the given file. + */ +unsigned long fadler32(FILE *file) +{ + // Obtain file size + fseek(file, 0, SEEK_END); + long fileSize = ftell(file); + rewind(file); + + // Calculate Adler-32 checksum + char *buffer = (char*) malloc(fileSize); + fread(buffer, 1, fileSize, file); + unsigned long adler = adler32(0L, Z_NULL, 0); + adler = adler32(adler, (Bytef*) buffer, fileSize); + free(buffer); + + return adler; +} + +/** + * Prints out usage and exists. + */ +void print_usage() +{ + printf("Usage: adler32 [file]...\n"); + exit(0); +} + +int main(int argc, char *argv[]) +{ + int i; /**< Loops through arguments. */ + + if (argc == 1) + { + print_usage(); + } + + for (i = 1; i < argc; ++i) + { + FILE *file = fopen(argv[i], "r"); + + if (!file) + { + printf("Error while opening '%s' for reading!\n", argv[i]); + exit(1); + } + + unsigned long adler = fadler32(file); + printf("%s %lx\n", argv[i], adler); + fclose(file); + } + + return 0; +} -- cgit v1.2.3-70-g09d2 From e063ed2b10f1eae5b592e3edb2116f50f7395b55 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Tue, 4 Mar 2008 18:44:24 +0000 Subject: Accepted patch by roderic to fix building/installing with CMake. --- ChangeLog | 6 ++++++ data/CMakeLists.txt | 1 + data/fonts/CMakeLists.txt | 6 ++++++ data/graphics/gui/CMakeLists.txt | 2 +- src/CMakeLists.txt | 12 ++++++++++++ 5 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 data/fonts/CMakeLists.txt (limited to 'data/graphics/gui/CMakeLists.txt') diff --git a/ChangeLog b/ChangeLog index 5b433fe5..79a8d489 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-03-04 Bjørn Lindeijer + + * src/CMakeLists.txt, data/graphics/gui/CMakeLists.txt, + data/fonts/CMakeLists.txt, data/CMakeLists.txt: Accepted patch by + roderic to fix building/installing with CMake. + 2008-03-03 Philipp Sehmisch * src/localplayer.h: Added natural HP regeneration diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt index 3c482b49..d5e9e88e 100644 --- a/data/CMakeLists.txt +++ b/data/CMakeLists.txt @@ -3,3 +3,4 @@ SET(DATA_DIR ${PKG_DATADIR}/data) ADD_SUBDIRECTORY(graphics) ADD_SUBDIRECTORY(help) ADD_SUBDIRECTORY(icons) +ADD_SUBDIRECTORY(fonts) diff --git a/data/fonts/CMakeLists.txt b/data/fonts/CMakeLists.txt new file mode 100644 index 00000000..dc22e031 --- /dev/null +++ b/data/fonts/CMakeLists.txt @@ -0,0 +1,6 @@ +SET (FILES + dejavusans.ttf + ) + +INSTALL(FILES ${FILES} DESTINATION ${DATA_DIR}/fonts) + diff --git a/data/graphics/gui/CMakeLists.txt b/data/graphics/gui/CMakeLists.txt index 649e0917..252348e5 100644 --- a/data/graphics/gui/CMakeLists.txt +++ b/data/graphics/gui/CMakeLists.txt @@ -9,6 +9,7 @@ SET (FILES checkbox.png close_button.png deepbox.png + equip_bg.png fixedfont.png hits_blue.png hits_red.png @@ -20,7 +21,6 @@ SET (FILES hscroll_right_highlight.png hscroll_right_pressed.png item_shortcut_bgr.png - mouse.png menuitemD.png menuitemF.png menuitemN.png diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4d774f1b..9cda186d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -91,6 +91,10 @@ SET(SRCS gui/gccontainer.h gui/gui.cpp gui/gui.h + gui/guildlistbox.cpp + gui/guildlistbox.h + gui/guildwindow.cpp + gui/guildwindow.h gui/hbox.cpp gui/hbox.h gui/help.cpp @@ -174,6 +178,8 @@ SET(SRCS gui/tabbedcontainer.h gui/textbox.cpp gui/textbox.h + gui/textdialog.cpp + gui/textdialog.h gui/textfield.cpp gui/textfield.h gui/trade.cpp @@ -203,6 +209,8 @@ SET(SRCS net/chathandler.h net/connection.cpp net/connection.h + net/guildhandler.cpp + net/guildhandler.h net/internal.cpp net/internal.h net/inventoryhandler.cpp @@ -236,6 +244,8 @@ SET(SRCS net/accountserver/internal.h net/chatserver/chatserver.cpp net/chatserver/chatserver.h + net/chatserver/guild.cpp + net/chatserver/guild.h net/chatserver/internal.cpp net/chatserver/internal.h net/gameserver/gameserver.cpp @@ -322,6 +332,8 @@ SET(SRCS graphics.cpp graphics.h guichanfwd.h + guild.cpp + guild.h imageparticle.cpp imageparticle.h inventory.cpp -- cgit v1.2.3-70-g09d2 From 843cfe68a7dc43f14522f80725627599c949b70d Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 20 Apr 2008 16:24:06 +0000 Subject: Merged revisions 3962-3983,3985-3999,4001-4021 via svnmerge from https://themanaworld.svn.sourceforge.net/svnroot/themanaworld/tmw/branches/0.0 ........ r3962 | crush_tmw | 2008-03-09 16:35:00 +0100 (Sun, 09 Mar 2008) | 1 line Applied some patches by peavey related to chatlog and the quit dialog. ........ r3968 | umperio | 2008-03-11 14:56:47 +0100 (Tue, 11 Mar 2008) | 1 line Removed unused image. ........ r3969 | b_lindeijer | 2008-03-11 17:44:20 +0100 (Tue, 11 Mar 2008) | 2 lines Also removed unused image from the files to be installed. ........ r4006 | crush_tmw | 2008-03-26 00:28:05 +0100 (Wed, 26 Mar 2008) | 1 line Initialized some uninitialized variables (patch by peavey). ........ r4008 | b_lindeijer | 2008-03-27 15:51:10 +0100 (Thu, 27 Mar 2008) | 2 lines Applied patch by peavey and added his name to the ChangeLog some more. ........ r4010 | b_lindeijer | 2008-03-30 16:06:14 +0200 (Sun, 30 Mar 2008) | 2 lines Updated configure.ac for tmwdata split (patch by peavey). ........ r4018 | crush_tmw | 2008-04-01 03:02:30 +0200 (Tue, 01 Apr 2008) | 1 line Added makefile for TMXCopy by jaxad. ........ r4019 | crush_tmw | 2008-04-01 03:34:29 +0200 (Tue, 01 Apr 2008) | 1 line compilation fixes suggested by peavey. ........ r4020 | crush_tmw | 2008-04-01 03:37:51 +0200 (Tue, 01 Apr 2008) | 1 line renaming makefile to Makefile ........ r4021 | crush_tmw | 2008-04-01 03:38:35 +0200 (Tue, 01 Apr 2008) | 1 line renaming makefile to Makefile ........ --- ChangeLog | 40 +++++++++++++++++++++++++++++++----- configure.ac | 2 -- data/graphics/gui/CMakeLists.txt | 1 - data/graphics/gui/Makefile.am | 1 - data/graphics/gui/attack_target.png | Bin 359 -> 0 bytes src/game.cpp | 3 ++- src/gui/chat.cpp | 23 +++++++++++++++------ src/gui/scrollarea.cpp | 4 ++-- src/gui/viewport.cpp | 1 + src/openglgraphics.cpp | 2 +- tools/tmxcopy/Makefile | 18 ++++++++++++++++ tools/tmxcopy/zlibutils.cpp | 1 + 12 files changed, 77 insertions(+), 19 deletions(-) delete mode 100644 data/graphics/gui/attack_target.png create mode 100644 tools/tmxcopy/Makefile (limited to 'data/graphics/gui/CMakeLists.txt') diff --git a/ChangeLog b/ChangeLog index 58e8c72c..4e672369 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,7 @@ 2008-04-19 Yohann Ferreira - * src/gui/char_select.cpp: Made the client clean characters information - to avoid a freeze at relogin with another account. + * src/gui/char_select.cpp: Made the client clean characters + information to avoid a freeze at relogin with another account. 2008-04-19 Dennis Friis @@ -168,11 +168,25 @@ * data/test.lua: Removed the +100 offset of NPC IDs (relict from eAthena) +2008-03-30 Dennis Friis + + * configure.ac: Updated for tmwdata split. + 2008-03-28 David Athay * tmw.cbp, src/gui/guildwindow.cpp, src/gui/shop.cpp: Updated project file and added some headers to help compiling on gcc 4.3. +2008-03-27 Dennis Friis + + * src/gui/progressbar.cpp, src/gui/scrollarea.cpp: Revert progress bar + changes and initialize mWalkTime. + +2008-03-26 Dennis Friis + + * src/gui/progressbar.cpp, src/localplayer.cpp: Initialized some + uninitialized variables. + 2008-03-24 Bjørn Lindeijer * src/main.h: Updated default account server name. @@ -211,6 +225,15 @@ src/net/chatserver.cpp, src/net/chatserver.h: Added ability to quit guilds. +2008-03-11 Bjørn Lindeijer + + * data/graphics/gui/CMakeLists.txt, data/graphics/gui/Makefile.am: + Removed unused image here too. + +2008-03-11 Eugenio Favalli + + * data/graphics/gui/attack_target.png: Removed unused image. + 2008-03-09 Philipp Sehmisch * src/particle.cpp, src/particle.h, src/particleemitter.cpp, @@ -230,10 +253,17 @@ data/graphics/sprites/scorpion.xml: Gave the tail attack of the scorpion a custom animation and a particle effect. +2008-03-09 Dennis Friis + + * src/game.cpp: Pressing escape in the quit dialog closes the dialog. + * src/gui/chat.cpp, src/gui/chat.h: Fixed a bug with chat messages + without a sender which include semicolons. + * src/chat.cpp: Added "/clear" command to clear chat window. + 2008-03-08 Philipp Sehmisch * tools/tmxcopy/main.cpp, tools/tmxcopy/main.map.cpp, - tools/tmxcopy/plibutils.cpp: Fixed some width/height mixups in + tools/tmxcopy/zlibutils.cpp: Fixed some width/height mixups in TMXCopy. 2008-03-07 Bjørn Lindeijer @@ -1004,7 +1034,7 @@ * src/gui/textfield.cpp: Fixed a windows compilation problem caused by a define macro of the Windows API that conflicts - with a guichan identifier. + with a guichan identifier. 2007-10-27 Guillaume Melquiond @@ -2289,7 +2319,7 @@ 2007-03-16 Philipp Sehmisch * src/gui/char_select.cpp, src/net/accountserver/account.cpp, - src/net/accountserver/account.hpp: Implemented 7 atribute system + src/net/accountserver/account.hpp: Implemented 7 attribute system in character creation. 2007-03-14 Bjørn Lindeijer diff --git a/configure.ac b/configure.ac index 1ee6dfb7..506ef0f7 100755 --- a/configure.ac +++ b/configure.ac @@ -113,8 +113,6 @@ data/Makefile data/graphics/Makefile data/graphics/gui/Makefile data/graphics/images/Makefile -data/graphics/images/ambient/Makefile -data/graphics/tiles/Makefile data/help/Makefile data/icons/Makefile docs/Makefile diff --git a/data/graphics/gui/CMakeLists.txt b/data/graphics/gui/CMakeLists.txt index 252348e5..4a5ea7e5 100644 --- a/data/graphics/gui/CMakeLists.txt +++ b/data/graphics/gui/CMakeLists.txt @@ -1,5 +1,4 @@ SET (FILES - attack_target.png bg_quad_dis.png browserfont.png button_disabled.png diff --git a/data/graphics/gui/Makefile.am b/data/graphics/gui/Makefile.am index 7287d717..724631fe 100644 --- a/data/graphics/gui/Makefile.am +++ b/data/graphics/gui/Makefile.am @@ -2,7 +2,6 @@ guidir = $(pkgdatadir)/data/graphics/gui gui_DATA = \ - attack_target.png \ bg_quad_dis.png \ browserfont.png \ button.png \ diff --git a/data/graphics/gui/attack_target.png b/data/graphics/gui/attack_target.png deleted file mode 100644 index b1306f97..00000000 Binary files a/data/graphics/gui/attack_target.png and /dev/null differ diff --git a/src/game.cpp b/src/game.cpp index fcbc5aba..039a1916 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -540,10 +540,11 @@ void Game::handleInput() if (!quitDialog) { quitDialog = new QuitDialog(&done, &quitDialog); + quitDialog->requestMoveToTop(); } else { - quitDialog->requestMoveToTop(); + quitDialog->action(gcn::ActionEvent(NULL, "cancel")); } break; diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index d490853c..a9f3b931 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -120,9 +120,13 @@ ChatWindow::logic() void ChatWindow::chatLog(std::string line, int own, const std::string &channelName) { + // Trim whitespace + trim(line); + CHATLOG tmp; tmp.own = own; tmp.nick = ""; + tmp.text = line; BrowserBox *output = mChannelOutput[channelName]; ScrollArea *scroll = mChannelScroll[channelName]; @@ -136,12 +140,9 @@ ChatWindow::chatLog(std::string line, int own, const std::string &channelName) std::string::size_type pos = line.find(" : "); if (pos != std::string::npos) { tmp.nick = line.substr(0, pos); - line.erase(0, pos + 3); + tmp.text = line.substr(pos + 3); } - // Trim whitespace - trim(line); - std::string lineColor = "##0"; // Equiv. to BrowserBox::BLACK switch (own) { case BY_GM: @@ -157,10 +158,13 @@ ChatWindow::chatLog(std::string line, int own, const std::string &channelName) lineColor = "##0"; // Equiv. to BrowserBox::BLACK break; case BY_SERVER: - tmp.nick += "Server: "; + tmp.nick = "Server: "; + tmp.text = line; lineColor = "##7"; // Equiv. to BrowserBox::PINK break; case BY_LOGGER: + tmp.nick = ""; + tmp.text = line; lineColor = "##8"; // Equiv. to BrowserBox::GREY break; } @@ -179,7 +183,7 @@ ChatWindow::chatLog(std::string line, int own, const std::string &channelName) << (int)((t / 60) % 60) << "] "; - line = lineColor + timeStr.str() + tmp.nick + line; + line = lineColor + timeStr.str() + tmp.nick + tmp.text; // We look if the Vertical Scroll Bar is set at the max before // adding a row, otherwise the max will always be a row higher @@ -314,6 +318,7 @@ void ChatWindow::chatSend(std::string const &nick, std::string const &msg, chatLog("/join > Join an already registered channel", BY_SERVER, channelName); chatLog("/quit > Leave a channel", BY_SERVER, channelName); chatLog("/admin > Send a command to the server (GM only)", BY_SERVER, channelName); + chatLog("/clear > Clears this window", BY_SERVER); } else if (command == "where") { @@ -365,6 +370,12 @@ void ChatWindow::chatSend(std::string const &nick, std::string const &msg, { Net::GameServer::Player::say("/" + arg); } + else if (command == "clear") + { + BrowserBox *output = mChannelOutput[channelName]; + if (output) + output->clearRows(); + } else { chatLog("Unknown command", BY_SERVER, channelName); diff --git a/src/gui/scrollarea.cpp b/src/gui/scrollarea.cpp index 97384fa3..9c88f8e3 100644 --- a/src/gui/scrollarea.cpp +++ b/src/gui/scrollarea.cpp @@ -86,8 +86,8 @@ void ScrollArea::init() // Load the background skin ResourceManager *resman = ResourceManager::getInstance(); Image *textbox = resman->getImage("graphics/gui/deepbox.png"); - int bggridx[4] = {0, 3, 28, 31}; - int bggridy[4] = {0, 3, 28, 31}; + const int bggridx[4] = {0, 3, 28, 31}; + const int bggridy[4] = {0, 3, 28, 31}; int a = 0, x, y; for (y = 0; y < 3; y++) { diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index a8fd452c..819cb761 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -57,6 +57,7 @@ Viewport::Viewport(): mViewY(0.0f), mShowDebugPath(false), mPlayerFollowMouse(false), + mWalkTime(0), mLocalWalkTime(-1) { setOpaque(false); diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index 92ce2fe9..76efe380 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -354,7 +354,7 @@ void OpenGLGraphics::setTexturingAndBlending(bool enable) void OpenGLGraphics::drawRectangle(const gcn::Rectangle& rect, bool filled) { - float offset = filled ? 0 : 0.5f; + const float offset = filled ? 0 : 0.5f; setTexturingAndBlending(false); diff --git a/tools/tmxcopy/Makefile b/tools/tmxcopy/Makefile new file mode 100644 index 00000000..732dec36 --- /dev/null +++ b/tools/tmxcopy/Makefile @@ -0,0 +1,18 @@ +CC=g++ +CFLAGS=-c `pkg-config --cflags libxml-2.0` +LDFLAGS=`pkg-config --libs libxml-2.0` +SOURCES=base64.cpp main.cpp map.cpp xmlutils.cpp zlibutils.cpp +OBJECTS=$(SOURCES:.cpp=.o) +EXECUTABLE=tmxcopy + +all: $(SOURCES) $(EXECUTABLE) + make clean + +$(EXECUTABLE): $(OBJECTS) + $(CC) $(LDFLAGS) $(OBJECTS) -o $@ + +.cpp.o: + $(CC) $(CFLAGS) $< -o $@ + +clean: + rm -f *.o diff --git a/tools/tmxcopy/zlibutils.cpp b/tools/tmxcopy/zlibutils.cpp index 9145f459..39c19aee 100644 --- a/tools/tmxcopy/zlibutils.cpp +++ b/tools/tmxcopy/zlibutils.cpp @@ -119,3 +119,4 @@ compressMemory(unsigned char *in, unsigned int inLength, assert (ret == Z_OK); } +*/ -- cgit v1.2.3-70-g09d2 From 489720742590352ac60c14f7d770fc9b26bf6865 Mon Sep 17 00:00:00 2001 From: Roderic Morris Date: Tue, 1 Jul 2008 16:25:16 +0000 Subject: fix build files --- ChangeLog | 5 +++++ data/graphics/gui/CMakeLists.txt | 4 ++++ src/CMakeLists.txt | 4 ++++ src/Makefile.am | 2 +- 4 files changed, 14 insertions(+), 1 deletion(-) (limited to 'data/graphics/gui/CMakeLists.txt') diff --git a/ChangeLog b/ChangeLog index dfc5c292..b40e18dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-07-01 Roderic Morris + + * data/graphics/gui/CMakeLists.txt, src/CMakeLists.txt, src/Makefile.am: + Add new files to CMakeLists, add missing backslash to Makefile. + 2008-07-01 Philipp Sehmisch * data/gui/window.cpp, data/gui/window.hpp, data/graphics/gui/default.png, diff --git a/data/graphics/gui/CMakeLists.txt b/data/graphics/gui/CMakeLists.txt index 4a5ea7e5..99ddb715 100644 --- a/data/graphics/gui/CMakeLists.txt +++ b/data/graphics/gui/CMakeLists.txt @@ -8,8 +8,10 @@ SET (FILES checkbox.png close_button.png deepbox.png + default.png equip_bg.png fixedfont.png + gui.xml hits_blue.png hits_red.png hits_yellow.png @@ -32,6 +34,8 @@ SET (FILES sansserif8.png selection.png slider.png + speech_bubble.png + speechbubble.xml target-cursor-blue-l.png target-cursor-blue-m.png target-cursor-blue-s.png diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 80d0a17a..ce322bdc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -115,6 +115,8 @@ SET(SRCS gui/item_amount.h gui/itemcontainer.cpp gui/itemcontainer.h + gui/itempopup.cpp + gui/itempopup.h gui/itemshortcutcontainer.cpp gui/itemshortcutcontainer.h gui/itemshortcutwindow.cpp @@ -181,6 +183,8 @@ SET(SRCS gui/skill.h gui/slider.cpp gui/slider.h + gui/speechbubble.cpp + gui/speechbubble.h gui/status.cpp gui/status.h gui/textbox.cpp diff --git a/src/Makefile.am b/src/Makefile.am index a64cd502..2fb1f148 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -66,7 +66,7 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \ gui/itemcontainer.cpp \ gui/itemcontainer.h \ gui/itempopup.cpp \ - gui/itempopup.h + gui/itempopup.h \ gui/itemshortcutcontainer.cpp \ gui/itemshortcutcontainer.h \ gui/itemshortcutwindow.cpp \ -- cgit v1.2.3-70-g09d2 From bf2502c372e7126a26445c97b4333e780f94b77c Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Tue, 19 Aug 2008 18:54:36 +0000 Subject: Don't forget to install tab.png --- ChangeLog | 5 +++++ data/graphics/gui/CMakeLists.txt | 1 + data/graphics/gui/Makefile.am | 1 + 3 files changed, 7 insertions(+) (limited to 'data/graphics/gui/CMakeLists.txt') diff --git a/ChangeLog b/ChangeLog index fccb53bb..cab63fc0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-08-19 Bjørn Lindeijer + + * data/graphics/gui/CMakeLists.txt, data/graphics/gui/Makefile.am: + Don't forget to install tab.png. + 2008-08-17 Roderic Morris * src/gui/skill.cpp, src/gui/skill.h, src/gui/icon.h, diff --git a/data/graphics/gui/CMakeLists.txt b/data/graphics/gui/CMakeLists.txt index 99ddb715..e9ccdab0 100644 --- a/data/graphics/gui/CMakeLists.txt +++ b/data/graphics/gui/CMakeLists.txt @@ -36,6 +36,7 @@ SET (FILES slider.png speech_bubble.png speechbubble.xml + tab.png target-cursor-blue-l.png target-cursor-blue-m.png target-cursor-blue-s.png diff --git a/data/graphics/gui/Makefile.am b/data/graphics/gui/Makefile.am index 6b3ad6ae..fb6c304a 100644 --- a/data/graphics/gui/Makefile.am +++ b/data/graphics/gui/Makefile.am @@ -40,6 +40,7 @@ gui_DATA = \ slider.png \ speech_bubble.png \ speechbubble.xml \ + tab.png \ target-cursor-blue-l.png \ target-cursor-blue-m.png \ target-cursor-blue-s.png \ -- cgit v1.2.3-70-g09d2 From 8b766aeb57b3d47d7676e4ca8c55db86a69e647e Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Tue, 19 Aug 2008 20:03:00 +0000 Subject: Also install tabselected.png, circle-green.png and circle-gray.png --- ChangeLog | 3 ++- data/graphics/gui/CMakeLists.txt | 3 +++ data/graphics/gui/Makefile.am | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) (limited to 'data/graphics/gui/CMakeLists.txt') diff --git a/ChangeLog b/ChangeLog index cab63fc0..5421bd59 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,8 @@ 2008-08-19 Bjørn Lindeijer * data/graphics/gui/CMakeLists.txt, data/graphics/gui/Makefile.am: - Don't forget to install tab.png. + Don't forget to install tab.png, tabselected.png, circle-green.png and + circle-gray.png. 2008-08-17 Roderic Morris diff --git a/data/graphics/gui/CMakeLists.txt b/data/graphics/gui/CMakeLists.txt index e9ccdab0..7b12c70c 100644 --- a/data/graphics/gui/CMakeLists.txt +++ b/data/graphics/gui/CMakeLists.txt @@ -6,6 +6,8 @@ SET (FILES button.png buttonpress.png checkbox.png + circle-gray.png + circle-green.png close_button.png deepbox.png default.png @@ -37,6 +39,7 @@ SET (FILES speech_bubble.png speechbubble.xml tab.png + tabselected.png target-cursor-blue-l.png target-cursor-blue-m.png target-cursor-blue-s.png diff --git a/data/graphics/gui/Makefile.am b/data/graphics/gui/Makefile.am index fb6c304a..e859c201 100644 --- a/data/graphics/gui/Makefile.am +++ b/data/graphics/gui/Makefile.am @@ -9,6 +9,8 @@ gui_DATA = \ buttonhi.png \ buttonpress.png \ checkbox.png \ + circle-gray.png \ + circle-green.png \ close_button.png \ deepbox.png \ default.png \ @@ -41,6 +43,7 @@ gui_DATA = \ speech_bubble.png \ speechbubble.xml \ tab.png \ + tabselected.png \ target-cursor-blue-l.png \ target-cursor-blue-m.png \ target-cursor-blue-s.png \ -- cgit v1.2.3-70-g09d2