summaryrefslogtreecommitdiff
path: root/src/dyetool
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-08-02 16:13:36 +0300
committerAndrei Karas <akaras@inbox.ru>2015-08-03 21:50:05 +0300
commitf651273ebf2a8b11aa01ed1434ecb613177ced6a (patch)
treec51d2bed1476270e27ad95c5a46e15af32eaccdd /src/dyetool
parent30846b7f68f1ad05a0719ae37f75fd2901a6545a (diff)
downloadmanaplus-f651273ebf2a8b11aa01ed1434ecb613177ced6a.tar.gz
manaplus-f651273ebf2a8b11aa01ed1434ecb613177ced6a.tar.bz2
manaplus-f651273ebf2a8b11aa01ed1434ecb613177ced6a.tar.xz
manaplus-f651273ebf2a8b11aa01ed1434ecb613177ced6a.zip
Add gui mode for dyecmd. Now only basic code added.
Diffstat (limited to 'src/dyetool')
-rw-r--r--src/dyetool/actions/actions.cpp109
-rw-r--r--src/dyetool/actions/chat.cpp63
-rw-r--r--src/dyetool/actions/commands.cpp93
-rw-r--r--src/dyetool/actions/move.cpp44
-rw-r--r--src/dyetool/actions/pets.cpp47
-rw-r--r--src/dyetool/actions/statusbar.cpp49
-rw-r--r--src/dyetool/actions/tabs.cpp39
-rw-r--r--src/dyetool/actions/target.cpp38
-rw-r--r--src/dyetool/actions/windows.cpp58
-rw-r--r--src/dyetool/client.cpp748
-rw-r--r--src/dyetool/client.h126
-rw-r--r--src/dyetool/dyemain.cpp7
-rw-r--r--src/dyetool/gui/viewport.cpp290
-rw-r--r--src/dyetool/gui/viewport.h220
14 files changed, 1929 insertions, 2 deletions
diff --git a/src/dyetool/actions/actions.cpp b/src/dyetool/actions/actions.cpp
new file mode 100644
index 000000000..046cd9c97
--- /dev/null
+++ b/src/dyetool/actions/actions.cpp
@@ -0,0 +1,109 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2012-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "actions/actions.h"
+
+#include "actions/actiondef.h"
+
+#include "debug.h"
+
+namespace Actions
+{
+
+impHandlerVoid(emote)
+impHandlerVoid(outfit)
+impHandlerVoid(mouseClick)
+impHandlerVoid(ok)
+impHandlerVoid(shortcut)
+impHandlerVoid(quit)
+impHandlerVoid(dropItem0)
+impHandlerVoid(dropItem)
+impHandlerVoid(dropItemId)
+impHandlerVoid(dropItemInv)
+impHandlerVoid(dropItemIdAll)
+impHandlerVoid(dropItemInvAll)
+impHandlerVoid(heal)
+impHandlerVoid(healmd)
+impHandlerVoid(itenplz)
+impHandlerVoid(setHome)
+impHandlerVoid(magicAttack)
+impHandlerVoid(copyEquippedToOutfit)
+impHandlerVoid(pickup)
+impHandlerVoid(sit)
+impHandlerVoid(screenshot)
+impHandlerVoid(ignoreInput)
+impHandlerVoid(buy)
+impHandlerVoid(sell)
+impHandlerVoid(talk)
+impHandlerVoid(stopAttack)
+impHandlerVoid(untarget)
+impHandlerVoid(attack)
+impHandlerVoid(targetAttack)
+impHandlerVoid(attackHuman)
+impHandlerVoid(safeVideoMode)
+impHandlerVoid(stopSit)
+impHandlerVoid(showKeyboard)
+impHandlerVoid(showWindows)
+impHandlerVoid(openTrade)
+impHandlerVoid(ipcToggle)
+impHandlerVoid(where)
+impHandlerVoid(who)
+impHandlerVoid(cleanGraphics)
+impHandlerVoid(cleanFonts)
+impHandlerVoid(trade)
+impHandlerVoid(priceLoad)
+impHandlerVoid(priceSave)
+impHandlerVoid(cacheInfo)
+impHandlerVoid(disconnect)
+impHandlerVoid(undress)
+impHandlerVoid(dirs)
+impHandlerVoid(uptime)
+impHandlerVoid(dump)
+impHandlerVoid(serverIgnoreAll)
+impHandlerVoid(serverUnIgnoreAll)
+impHandler0(error)
+{
+ exit(0);
+}
+impHandlerVoid(dumpGraphics)
+impHandlerVoid(dumpEnvironment)
+impHandlerVoid(dumpTests)
+impHandlerVoid(dumpOGL)
+impHandlerVoid(dumpGL)
+impHandlerVoid(dumpMods)
+#if defined USE_OPENGL && defined DEBUG_SDLFONT
+impHandlerVoid(testSdlFont)
+#endif
+impHandlerVoid(createItems)
+impHandlerVoid(uploadConfig)
+impHandlerVoid(uploadServerConfig)
+impHandlerVoid(uploadLog)
+impHandlerVoid(mercenaryFire)
+impHandlerVoid(useItem)
+impHandlerVoid(useItemInv)
+impHandlerVoid(invToStorage)
+impHandlerVoid(tradeAdd)
+impHandlerVoid(storageToInv)
+impHandlerVoid(protectItem)
+impHandlerVoid(unprotectItem)
+impHandlerVoid(kick)
+impHandlerVoid(clearDrop)
+
+} // namespace Actions
diff --git a/src/dyetool/actions/chat.cpp b/src/dyetool/actions/chat.cpp
new file mode 100644
index 000000000..70bc09034
--- /dev/null
+++ b/src/dyetool/actions/chat.cpp
@@ -0,0 +1,63 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2012-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "actions/chat.h"
+
+#include "actions/actiondef.h"
+
+#include "debug.h"
+
+namespace Actions
+{
+
+impHandlerVoid(toggleChat)
+impHandlerVoid(prevChatTab)
+impHandlerVoid(nextChatTab)
+impHandlerVoid(closeChatTab)
+impHandlerVoid(closeAllChatTabs)
+impHandlerVoid(ignoreAllWhispers)
+impHandlerVoid(scrollChatUp)
+impHandlerVoid(scrollChatDown)
+impHandlerVoid(msg)
+impHandlerVoid(msgText)
+impHandlerVoid(msg2)
+impHandlerVoid(query)
+impHandlerVoid(clearChatTab)
+impHandlerVoid(createParty)
+impHandlerVoid(createGuild)
+impHandlerVoid(party)
+impHandlerVoid(guild)
+impHandlerVoid(me)
+impHandlerVoid(toggle)
+impHandlerVoid(kickParty)
+impHandlerVoid(kickGuild)
+impHandlerVoid(addText)
+impHandlerVoid(clearChat)
+impHandlerVoid(chatGeneralTab)
+impHandlerVoid(chatDebugTab)
+impHandlerVoid(chatBattleTab)
+impHandlerVoid(chatTradeTab)
+impHandlerVoid(chatLangTab)
+impHandlerVoid(chatGmTab)
+impHandlerVoid(chatPartyTab)
+impHandlerVoid(chatGuildTab)
+impHandlerVoid(hat)
+
+} // namespace Actions
diff --git a/src/dyetool/actions/commands.cpp b/src/dyetool/actions/commands.cpp
new file mode 100644
index 000000000..1820e3038
--- /dev/null
+++ b/src/dyetool/actions/commands.cpp
@@ -0,0 +1,93 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2012-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "actions/commands.h"
+
+#include "actions/actiondef.h"
+
+#include "debug.h"
+
+namespace Actions
+{
+
+impHandlerVoid(chatAnnounce)
+impHandlerVoid(chatIgnore)
+impHandlerVoid(chatUnignore)
+impHandlerVoid(chatErase)
+impHandlerVoid(chatFriend)
+impHandlerVoid(chatDisregard)
+impHandlerVoid(chatNeutral)
+impHandlerVoid(chatBlackList)
+impHandlerVoid(chatEnemy)
+impHandlerVoid(chatNuke)
+impHandlerVoid(chatAdd)
+impHandlerVoid(present)
+impHandlerVoid(printAll)
+impHandlerVoid(move)
+impHandlerVoid(setTarget)
+impHandlerVoid(commandOutfit)
+impHandlerVoid(commandEmote)
+impHandlerVoid(awayMessage)
+impHandlerVoid(pseudoAway)
+impHandlerVoid(follow)
+impHandlerVoid(navigate)
+impHandlerVoid(navigateTo)
+impHandlerVoid(moveCamera)
+impHandlerVoid(imitation)
+impHandlerVoid(sendMail)
+impHandlerVoid(info)
+impHandlerVoid(wait)
+impHandlerVoid(addPriorityAttack)
+impHandlerVoid(addAttack)
+impHandlerVoid(removeAttack)
+impHandlerVoid(addIgnoreAttack)
+impHandlerVoid(setDrop)
+impHandlerVoid(url)
+impHandlerVoid(openUrl)
+impHandlerVoid(execute)
+impHandlerVoid(enableHighlight)
+impHandlerVoid(disableHighlight)
+impHandlerVoid(dontRemoveName)
+impHandlerVoid(removeName)
+impHandlerVoid(disableAway)
+impHandlerVoid(enableAway)
+impHandlerVoid(testParticle)
+impHandlerVoid(talkRaw)
+impHandlerVoid(gm)
+impHandlerVoid(hack)
+impHandlerVoid(debugSpawn)
+impHandlerVoid(serverIgnoreWhisper)
+impHandlerVoid(serverUnIgnoreWhisper)
+impHandlerVoid(setHomunculusName)
+impHandlerVoid(fireHomunculus)
+impHandlerVoid(leaveParty)
+impHandlerVoid(warp)
+impHandlerVoid(homunTalk)
+impHandlerVoid(homunEmote)
+impHandlerVoid(commandHomunEmote)
+impHandlerVoid(createPublicChatRoom)
+impHandlerVoid(joinChatRoom)
+impHandlerVoid(leaveChatRoom)
+impHandlerVoid(confSet)
+impHandlerVoid(serverConfSet)
+impHandlerVoid(confGet)
+impHandlerVoid(serverConfGet)
+
+} // namespace Actions
diff --git a/src/dyetool/actions/move.cpp b/src/dyetool/actions/move.cpp
new file mode 100644
index 000000000..2e1a759fa
--- /dev/null
+++ b/src/dyetool/actions/move.cpp
@@ -0,0 +1,44 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2012-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "actions/move.h"
+
+#include "actions/actiondef.h"
+
+#include "debug.h"
+
+namespace Actions
+{
+
+impHandlerVoid(moveUp)
+impHandlerVoid(moveDown)
+impHandlerVoid(moveLeft)
+impHandlerVoid(moveRight)
+impHandlerVoid(moveForward)
+impHandlerVoid(moveToPoint)
+impHandlerVoid(crazyMoves)
+impHandlerVoid(moveToTarget)
+impHandlerVoid(moveToHome)
+impHandlerVoid(directUp)
+impHandlerVoid(directDown)
+impHandlerVoid(directLeft)
+impHandlerVoid(directRight)
+
+} // namespace Actions
diff --git a/src/dyetool/actions/pets.cpp b/src/dyetool/actions/pets.cpp
new file mode 100644
index 000000000..89b6da30c
--- /dev/null
+++ b/src/dyetool/actions/pets.cpp
@@ -0,0 +1,47 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2012-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "actions/pets.h"
+
+#include "actions/actiondef.h"
+
+#include "debug.h"
+
+namespace Actions
+{
+
+impHandlerVoid(commandEmotePet)
+impHandlerVoid(talkPet)
+impHandlerVoid(setPetName)
+impHandlerVoid(petEmote)
+impHandlerVoid(catchPet)
+impHandlerVoid(petMoveUp)
+impHandlerVoid(petMoveDown)
+impHandlerVoid(petMoveLeft)
+impHandlerVoid(petMoveRight)
+impHandlerVoid(petDirectUp)
+impHandlerVoid(petDirectDown)
+impHandlerVoid(petDirectLeft)
+impHandlerVoid(petDirectRight)
+impHandlerVoid(petAiStart)
+impHandlerVoid(petAiStop)
+impHandlerVoid(petMove)
+
+} // namespace Actions
diff --git a/src/dyetool/actions/statusbar.cpp b/src/dyetool/actions/statusbar.cpp
new file mode 100644
index 000000000..155bf280c
--- /dev/null
+++ b/src/dyetool/actions/statusbar.cpp
@@ -0,0 +1,49 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2012-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "actions/statusbar.h"
+
+#include "actions/actiondef.h"
+
+#include "debug.h"
+
+namespace Actions
+{
+
+impHandlerVoid(switchQuickDrop)
+impHandlerVoid(changeCrazyMove)
+impHandlerVoid(changePickupType)
+impHandlerVoid(changeMoveType)
+impHandlerVoid(changeAttackWeaponType)
+impHandlerVoid(changeAttackType)
+impHandlerVoid(changeTargetingType)
+impHandlerVoid(changeFollowMode)
+impHandlerVoid(changeImitationMode)
+impHandlerVoid(changeMagicAttackType)
+impHandlerVoid(changePvpMode)
+impHandlerVoid(changeMoveToTarget)
+impHandlerVoid(changeGameModifier)
+impHandlerVoid(changeAudio)
+impHandlerVoid(away)
+impHandlerVoid(camera)
+impHandlerVoid(changeMapMode)
+impHandlerVoid(changeTrade)
+
+} // namespace Actions
diff --git a/src/dyetool/actions/tabs.cpp b/src/dyetool/actions/tabs.cpp
new file mode 100644
index 000000000..942de1ba9
--- /dev/null
+++ b/src/dyetool/actions/tabs.cpp
@@ -0,0 +1,39 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2012-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "actions/tabs.h"
+
+#include "actions/actiondef.h"
+
+#include "debug.h"
+
+namespace Actions
+{
+
+impHandlerVoid(prevSocialTab)
+impHandlerVoid(nextSocialTab)
+impHandlerVoid(nextShortcutsTab)
+impHandlerVoid(prevShortcutsTab)
+impHandlerVoid(nextCommandsTab)
+impHandlerVoid(prevCommandsTab)
+impHandlerVoid(nextInvTab)
+impHandlerVoid(prevInvTab)
+
+} // namespace Actions
diff --git a/src/dyetool/actions/target.cpp b/src/dyetool/actions/target.cpp
new file mode 100644
index 000000000..f3ddd3b2a
--- /dev/null
+++ b/src/dyetool/actions/target.cpp
@@ -0,0 +1,38 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2012-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "actions/target.h"
+
+#include "actions/actiondef.h"
+
+#include "debug.h"
+
+namespace Actions
+{
+
+impHandlerVoid(targetPlayer)
+impHandlerVoid(targetMonster)
+impHandlerVoid(targetClosestMonster)
+impHandlerVoid(targetNPC)
+impHandlerVoid(targetMercenary)
+impHandlerVoid(targetPet)
+impHandlerVoid(contextMenu)
+
+} // namespace Actions
diff --git a/src/dyetool/actions/windows.cpp b/src/dyetool/actions/windows.cpp
new file mode 100644
index 000000000..37637a3f1
--- /dev/null
+++ b/src/dyetool/actions/windows.cpp
@@ -0,0 +1,58 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2012-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "actions/windows.h"
+
+#include "actions/actiondef.h"
+
+#include "debug.h"
+
+namespace Actions
+{
+
+impHandlerVoid(setupWindowShow)
+impHandlerVoid(hideWindows)
+impHandlerVoid(helpWindowShow)
+impHandlerVoid(aboutWindowShow)
+impHandlerVoid(statusWindowShow)
+impHandlerVoid(inventoryWindowShow)
+impHandlerVoid(equipmentWindowShow)
+impHandlerVoid(skillDialogShow)
+impHandlerVoid(minimapWindowShow)
+impHandlerVoid(chatWindowShow)
+impHandlerVoid(shortcutWindowShow)
+impHandlerVoid(debugWindowShow)
+impHandlerVoid(socialWindowShow)
+impHandlerVoid(emoteShortcutWindowShow)
+impHandlerVoid(outfitWindowShow)
+impHandlerVoid(shopWindowShow)
+impHandlerVoid(dropShortcutWindowShow)
+impHandlerVoid(killStatsWindowShow)
+impHandlerVoid(spellShortcutWindowShow)
+impHandlerVoid(whoIsOnlineWindowShow)
+impHandlerVoid(didYouKnowWindowShow)
+impHandlerVoid(questsWindowShow)
+impHandlerVoid(bankWindowShow)
+impHandlerVoid(cartWindowShow)
+impHandlerVoid(updaterWindowShow)
+impHandlerVoid(quickWindowShow)
+impHandlerVoid(mailWindowShow)
+
+} // namespace Actions
diff --git a/src/dyetool/client.cpp b/src/dyetool/client.cpp
new file mode 100644
index 000000000..85cf216e2
--- /dev/null
+++ b/src/dyetool/client.cpp
@@ -0,0 +1,748 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "client.h"
+
+#include "chatlogger.h"
+#include "configmanager.h"
+#include "dirs.h"
+#include "dropshortcut.h"
+#include "emoteshortcut.h"
+#include "eventsmanager.h"
+#include "game.h"
+#include "graphicsmanager.h"
+#include "itemshortcut.h"
+#include "party.h"
+#include "settings.h"
+#include "soundmanager.h"
+#include "spellshortcut.h"
+#include "statuseffect.h"
+#include "units.h"
+#include "touchmanager.h"
+
+#include "being/playerinfo.h"
+#include "being/playerrelations.h"
+
+#include "input/inputmanager.h"
+#include "input/joystick.h"
+#include "input/keyboardconfig.h"
+
+#include "gui/dialogsmanager.h"
+#include "gui/gui.h"
+#include "gui/skin.h"
+#include "gui/popupmanager.h"
+#include "gui/windowmanager.h"
+
+#include "gui/widgets/button.h"
+#include "gui/widgets/createwidget.h"
+#include "gui/widgets/desktop.h"
+#include "gui/widgets/windowcontainer.h"
+#include "gui/widgets/window.h"
+
+#include "resources/imagehelper.h"
+#include "resources/resourcemanager.h"
+
+#include "utils/cpu.h"
+#include "utils/delete2.h"
+#include "utils/env.h"
+#include "utils/fuzzer.h"
+#include "utils/gettext.h"
+#include "utils/gettexthelper.h"
+#ifdef ANDROID
+#include "utils/paths.h"
+#endif
+#include "utils/physfstools.h"
+#include "utils/sdlcheckutils.h"
+#include "utils/timer.h"
+
+#include "utils/translation/translationmanager.h"
+
+#include "listeners/errorlistener.h"
+
+#include "configuration.h"
+
+#include "net/ipc.h"
+
+#ifdef WIN32
+#include <SDL_syswm.h>
+#include "utils/specialfolder.h"
+#undef ERROR
+#endif
+
+#ifdef ANDROID
+#ifndef USE_SDL2
+#include <SDL_screenkeyboard.h>
+#include <fstream>
+#endif
+#endif
+
+#include <sys/stat.h>
+
+#include "debug.h"
+
+std::string errorMessage;
+
+Client *client = nullptr;
+
+extern FPSmanager fpsManager;
+
+volatile bool runCounters;
+bool isSafeMode = false;
+int serverVersion = 0;
+unsigned int tmwServerVersion = 0;
+int start_time;
+unsigned int mLastHost = 0;
+unsigned long mSearchHash = 0;
+int textures_count = 0;
+
+Client::Client() :
+ ActionListener(),
+ mCurrentDialog(nullptr),
+ mSetupButton(nullptr),
+ mVideoButton(nullptr),
+ mHelpButton(nullptr),
+ mAboutButton(nullptr),
+ mThemesButton(nullptr),
+ mPerfomanceButton(nullptr),
+#ifdef ANDROID
+ mCloseButton(nullptr),
+#endif
+ mState(STATE_GAME),
+ mOldState(STATE_START),
+ mSkin(nullptr),
+ mButtonPadding(1),
+ mButtonSpacing(3),
+ mPing(0),
+ mConfigAutoSaved(false)
+{
+ WindowManager::init();
+}
+
+void Client::testsInit()
+{
+}
+
+void Client::testsClear()
+{
+}
+
+// +++ need remove duplicate from here
+void Client::gameInit()
+{
+ logger = new Logger;
+
+ // Load branding information
+ if (!settings.options.brandingPath.empty())
+ branding.init(settings.options.brandingPath);
+ branding.setDefaultValues(getBrandingDefaults());
+
+ Dirs::initRootDir();
+ Dirs::initHomeDir();
+
+ // Configure logger
+ if (!settings.options.logFileName.empty())
+ settings.logFileName = settings.options.logFileName;
+ else
+ settings.logFileName = settings.localDataDir + "/manaplus.log";
+ logger->setLogFile(settings.logFileName);
+
+#ifdef USE_FUZZER
+ Fuzzer::init();
+#endif
+ ConfigManager::backupConfig("config.xml");
+ ConfigManager::initConfiguration();
+ paths.setDefaultValues(getPathsDefaults());
+ logger->log("init 4");
+ logger->setDebugLog(config.getBoolValue("debugLog"));
+ logger->setReportUnimplimented(config.getBoolValue("unimplimentedLog"));
+
+ config.incValue("runcount");
+
+#ifndef ANDROID
+ if (settings.options.test.empty())
+ ConfigManager::storeSafeParameters();
+#endif
+
+ const ResourceManager *const resman = ResourceManager::getInstance();
+ if (!resman->setWriteDir(settings.localDataDir))
+ {
+ logger->error(strprintf("%s couldn't be set as home directory! "
+ "Exiting.", settings.localDataDir.c_str()));
+ }
+
+ GettextHelper::initLang();
+
+// chatLogger = new ChatLogger;
+// if (settings.options.chatLogDir.empty())
+// {
+// chatLogger->setBaseLogDir(settings.localDataDir
+// + std::string("/logs/"));
+// }
+// else
+// {
+// chatLogger->setBaseLogDir(settings.options.chatLogDir);
+// }
+
+ logger->setLogToStandardOut(config.getBoolValue("logToStandardOut"));
+
+ // Log the client version
+ logger->log1(FULL_VERSION);
+ logger->log("Start configPath: " + config.getConfigPath());
+
+ Dirs::initScreenshotDir();
+
+ // Initialize SDL
+ logger->log1("Initializing SDL...");
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0)
+ {
+ logger->safeError(strprintf("Could not initialize SDL: %s",
+ SDL_GetError()));
+ }
+ atexit(SDL_Quit);
+
+#ifndef USE_SDL2
+ SDL_EnableUNICODE(1);
+#endif
+ WindowManager::applyKeyRepeat();
+
+ // disable unused SDL events
+#ifndef USE_SDL2
+ SDL_EventState(SDL_VIDEOEXPOSE, SDL_IGNORE);
+#endif
+ SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
+ SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
+
+#ifdef WIN32
+ Dirs::extractDataDir();
+ Dirs::mountDataDir();
+#endif
+
+ WindowManager::setIcon();
+ ConfigManager::checkConfigVersion();
+ logVars();
+ Cpu::detect();
+#if defined(USE_OPENGL)
+#if !defined(ANDROID) && !defined(__APPLE__) && !defined(__native_client__)
+ if (!settings.options.safeMode && settings.options.test.empty()
+ && !config.getBoolValue("videodetected"))
+ {
+ graphicsManager.detectVideoSettings();
+ }
+#endif
+#endif
+ updateEnv();
+ initGraphics();
+
+#ifndef WIN32
+ Dirs::extractDataDir();
+ Dirs::mountDataDir();
+#endif
+
+ Dirs::updateDataPath();
+
+ // Add the main data directories to our PhysicsFS search path
+ if (!settings.options.dataPath.empty())
+ resman->addToSearchPath(settings.options.dataPath, false);
+
+ // Add the local data directory to PhysicsFS search path
+ resman->addToSearchPath(settings.localDataDir, false);
+ TranslationManager::loadCurrentLang();
+
+ WindowManager::initTitle();
+
+ mainGraphics->postInit();
+
+ theme = new Theme;
+ Theme::selectSkin();
+ touchManager.init();
+
+ // Initialize the item and emote shortcuts.
+// for (unsigned f = 0; f < SHORTCUT_TABS; f ++)
+// itemShortcut[f] = new ItemShortcut(f);
+// emoteShortcut = new EmoteShortcut;
+// dropShortcut = new DropShortcut;
+
+ gui = new Gui();
+ gui->postInit(mainGraphics);
+ dialogsManager = new DialogsManager;
+ popupManager = new PopupManager;
+
+ initSoundManager();
+ eventsManager.init();
+
+ // Initialize keyboard
+ keyboard.init();
+ inputManager.init();
+
+ // Initialise player relations
+ Joystick::init();
+ WindowManager::createWindows();
+
+ keyboard.update();
+ if (joystick)
+ joystick->update();
+
+// if (mState != STATE_ERROR)
+// mState = STATE_CHOOSE_SERVER;
+
+ startTimers();
+
+ const int fpsLimit = config.getIntValue("fpslimit");
+ settings.limitFps = fpsLimit > 0;
+
+ SDL_initFramerate(&fpsManager);
+ WindowManager::setFramerate(fpsLimit);
+
+ start_time = static_cast<int>(time(nullptr));
+
+// PlayerInfo::init();
+
+#ifdef ANDROID
+#ifndef USE_SDL2
+ WindowManager::updateScreenKeyboard(SDL_GetScreenKeyboardHeight(nullptr));
+#endif
+#endif
+
+ mSkin = theme->load("windowmenu.xml", "");
+ if (mSkin)
+ {
+ mButtonPadding = mSkin->getPadding();
+ mButtonSpacing = mSkin->getOption("spacing", 3);
+ }
+}
+
+Client::~Client()
+{
+ if (!settings.options.testMode)
+ gameClear();
+ else
+ testsClear();
+}
+
+void Client::initSoundManager()
+{
+ // Initialize sound engine
+ try
+ {
+ if (config.getBoolValue("sound"))
+ soundManager.init();
+
+ soundManager.setSfxVolume(config.getIntValue("sfxVolume"));
+ soundManager.setMusicVolume(config.getIntValue("musicVolume"));
+ }
+ catch (const char *const err)
+ {
+ mState = STATE_ERROR;
+ errorMessage = err;
+ logger->log("Warning: %s", err);
+ }
+ soundManager.playMusic(branding.getValue(
+ "loginMusic", "Magick - Real.ogg"));
+}
+
+void Client::initGraphics()
+{
+ WindowManager::applyVSync();
+ runCounters = config.getBoolValue("packetcounters");
+
+ graphicsManager.initGraphics();
+
+ imageHelper->postInit();
+ getConfigDefaults2(config.getDefaultValues());
+ WindowManager::applyGrabMode();
+ WindowManager::applyGamma();
+
+ mainGraphics->beginDraw();
+}
+
+void Client::gameClear()
+{
+ if (logger)
+ logger->log1("Quitting1");
+
+ eventsManager.shutdown();
+ WindowManager::deleteWindows();
+ if (windowContainer)
+ windowContainer->slowLogic();
+
+ stopTimers();
+
+ delete2(ipc);
+
+ if (logger)
+ logger->log1("Quitting2");
+
+ delete2(mCurrentDialog);
+ delete2(popupManager);
+ delete2(dialogsManager);
+ delete2(gui);
+
+ if (logger)
+ logger->log1("Quitting3");
+
+ graphicsManager.deleteRenderers();
+
+ if (logger)
+ logger->log1("Quitting4");
+
+ XML::cleanupXML();
+
+ if (logger)
+ logger->log1("Quitting5");
+
+ // Shutdown sound
+ soundManager.close();
+
+ if (logger)
+ logger->log1("Quitting6");
+
+ touchManager.clear();
+ ResourceManager::deleteInstance();
+
+ if (logger)
+ logger->log1("Quitting8");
+
+ WindowManager::deleteIcon();
+
+ if (logger)
+ logger->log1("Quitting9");
+
+ delete2(joystick);
+
+ keyboard.deinit();
+
+ if (logger)
+ logger->log1("Quitting10");
+
+ soundManager.shutdown();
+ touchManager.shutdown();
+
+#ifdef DEBUG_CONFIG
+ config.enableKeyLogging();
+#endif
+ config.removeOldKeys();
+ config.write();
+ serverConfig.write();
+
+ config.clear();
+ serverConfig.clear();
+
+ if (logger)
+ logger->log1("Quitting11");
+
+#ifdef USE_PROFILER
+ Perfomance::clear();
+#endif
+
+#ifdef DEBUG_OPENGL_LEAKS
+ if (logger)
+ logger->log("textures left: %d", textures_count);
+#endif
+
+// delete2(chatLogger);
+ TranslationManager::close();
+}
+
+#define ADDBUTTON(var, object) var = object; \
+ x -= var->getWidth() + mButtonSpacing; \
+ var->setPosition(x, mButtonPadding); \
+ top->add(var);
+
+void Client::stateGame()
+{
+ if (!gui)
+ return;
+
+ BasicContainer2 *const top = static_cast<BasicContainer2*>(
+ gui->getTop());
+
+ if (!top)
+ return;
+
+ CREATEWIDGETV(desktop, Desktop, nullptr);
+ top->add(desktop);
+ int x = top->getWidth() - mButtonPadding;
+ ADDBUTTON(mSetupButton, new Button(desktop,
+ // TRANSLATORS: setup tab quick button
+ _("Setup"), "Setup", this))
+ ADDBUTTON(mPerfomanceButton, new Button(desktop,
+ // TRANSLATORS: perfoamance tab quick button
+ _("Performance"), "Perfomance", this))
+ ADDBUTTON(mVideoButton, new Button(desktop,
+ // TRANSLATORS: video tab quick button
+ _("Video"), "Video", this))
+ ADDBUTTON(mThemesButton, new Button(desktop,
+ // TRANSLATORS: theme tab quick button
+ _("Theme"), "Themes", this))
+ ADDBUTTON(mAboutButton, new Button(desktop,
+ // TRANSLATORS: theme tab quick button
+ _("About"), "about", this))
+ ADDBUTTON(mHelpButton, new Button(desktop,
+ // TRANSLATORS: theme tab quick button
+ _("Help"), "help", this))
+#ifdef ANDROID
+ ADDBUTTON(mCloseButton, new Button(desktop,
+ // TRANSLATORS: close quick button
+ _("Close"), "close", this))
+#endif
+ desktop->setSize(mainGraphics->getWidth(),
+ mainGraphics->getHeight());
+}
+
+int Client::gameExec()
+{
+ int lastTickTime = tick_time;
+
+ while (mState != STATE_EXIT)
+ {
+ PROFILER_START();
+ if (eventsManager.handleEvents())
+ continue;
+
+ BLOCK_START("Client::gameExec 4")
+ if (gui)
+ gui->logic();
+ cur_time = static_cast<int>(time(nullptr));
+ int k = 0;
+ while (lastTickTime != tick_time && k < 40)
+ {
+// if (mGame)
+// mGame->logic();
+// else
+ if (gui)
+ gui->handleInput();
+
+ ++lastTickTime;
+ k ++;
+ }
+ soundManager.logic();
+
+ logic_count += k;
+ if (gui)
+ gui->slowLogic();
+// if (mGame)
+// mGame->slowLogic();
+ slowLogic();
+ BLOCK_END("Client::gameExec 4")
+
+ // This is done because at some point tick_time will wrap.
+ lastTickTime = tick_time;
+
+ // Update the screen when application is visible, delay otherwise.
+ if (!WindowManager::getIsMinimized())
+ {
+ frame_count++;
+ if (gui)
+ gui->draw();
+ mainGraphics->updateScreen();
+ }
+ else
+ {
+ SDL_Delay(100);
+ }
+
+ BLOCK_START("~Client::SDL_framerateDelay")
+ if (settings.limitFps)
+ SDL_framerateDelay(&fpsManager);
+ BLOCK_END("~Client::SDL_framerateDelay")
+
+ BLOCK_START("Client::gameExec 6")
+// if (mState == STATE_CONNECT_GAME)
+// {
+// stateConnectGame1();
+// }
+ BLOCK_END("Client::gameExec 6")
+
+ if (mState != mOldState)
+ {
+ BLOCK_START("Client::gameExec 7")
+
+ mOldState = mState;
+
+ // Get rid of the dialog of the previous state
+ delete2(mCurrentDialog);
+
+ // State has changed, while the quitDialog was active, it might
+ // not be correct anymore
+// if (mQuitDialog)
+// {
+// mQuitDialog->scheduleDelete();
+// mQuitDialog = nullptr;
+// }
+ BLOCK_END("Client::gameExec 7")
+
+ BLOCK_START("Client::gameExec 8")
+ switch (mState)
+ {
+ case STATE_GAME:
+ stateGame();
+ break;
+
+ case STATE_LOAD_DATA:
+ {
+ BLOCK_START("Client::gameExec STATE_LOAD_DATA")
+ logger->log1("State: LOAD DATA");
+
+ const ResourceManager *const resman
+ = ResourceManager::getInstance();
+
+ // If another data path has been set,
+ // we don't load any other files...
+ if (settings.options.dataPath.empty())
+ {
+ // Add customdata directory
+ resman->searchAndAddArchives(
+ "customdata/",
+ "zip",
+ false);
+ }
+
+ if (!settings.options.skipUpdate)
+ {
+ resman->searchAndAddArchives(
+ settings.updatesDir + "/local/",
+ "zip",
+ false);
+
+ resman->addToSearchPath(settings.localDataDir
+ + dirSeparator + settings.updatesDir + "/local/",
+ false);
+ }
+
+ logger->log("Init paths");
+ paths.init("paths.xml", UseResman_true);
+ paths.setDefaultValues(getPathsDefaults());
+ TranslationManager::loadCurrentLang();
+
+ if (desktop)
+ desktop->reloadWallpaper();
+
+ mState = STATE_GET_CHARACTERS;
+ BLOCK_END("Client::gameExec STATE_LOAD_DATA")
+ break;
+ }
+ case STATE_START:
+ default:
+ mState = STATE_FORCE_QUIT;
+ break;
+ }
+ BLOCK_END("Client::gameExec 8")
+ }
+ PROFILER_END();
+ }
+
+ return 0;
+}
+
+void Client::action(const ActionEvent &event)
+{
+ std::string tab;
+ const std::string &eventId = event.getId();
+
+ if (eventId == "close")
+ {
+ setState(STATE_FORCE_QUIT);
+ return;
+ }
+ if (eventId == "Setup")
+ {
+ tab.clear();
+ }
+ else if (eventId == "help")
+ {
+ inputManager.executeAction(InputAction::WINDOW_HELP);
+ return;
+ }
+ else if (eventId == "about")
+ {
+ inputManager.executeAction(InputAction::WINDOW_ABOUT);
+ return;
+ }
+ else if (eventId == "Video")
+ {
+ tab = "Video";
+ }
+ else if (eventId == "Themes")
+ {
+ tab = "Theme";
+ }
+ else if (eventId == "Perfomance")
+ {
+ tab = "Perfomance";
+ }
+ else
+ {
+ return;
+ }
+}
+
+void Client::moveButtons(const int width)
+{
+ if (mSetupButton)
+ {
+ int x = width - mSetupButton->getWidth() - mButtonPadding;
+ mSetupButton->setPosition(x, mButtonPadding);
+#ifndef WIN32
+ x -= mPerfomanceButton->getWidth() + mButtonSpacing;
+ mPerfomanceButton->setPosition(x, mButtonPadding);
+
+ x -= mVideoButton->getWidth() + mButtonSpacing;
+ mVideoButton->setPosition(x, mButtonPadding);
+
+ x -= mThemesButton->getWidth() + mButtonSpacing;
+ mThemesButton->setPosition(x, mButtonPadding);
+
+ x -= mAboutButton->getWidth() + mButtonSpacing;
+ mAboutButton->setPosition(x, mButtonPadding);
+
+ x -= mHelpButton->getWidth() + mButtonSpacing;
+ mHelpButton->setPosition(x, mButtonPadding);
+#ifdef ANDROID
+ x -= mCloseButton->getWidth() + mButtonSpacing;
+ mCloseButton->setPosition(x, mButtonPadding);
+#endif
+#endif
+ }
+}
+
+void Client::windowRemoved(const Window *const window)
+{
+ if (mCurrentDialog == window)
+ mCurrentDialog = nullptr;
+}
+
+void Client::logVars()
+{
+#ifdef ANDROID
+ logger->log("APPDIR: %s", getenv("APPDIR"));
+ logger->log("DATADIR2: %s", getSdStoragePath().c_str());
+#endif
+}
+
+void Client::slowLogic()
+{
+}
+
+int Client::testsExec()
+{
+ return 0;
+}
diff --git a/src/dyetool/client.h b/src/dyetool/client.h
new file mode 100644
index 000000000..b0fb4229f
--- /dev/null
+++ b/src/dyetool/client.h
@@ -0,0 +1,126 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef DYETOOL_CLIENT_H
+#define DYETOOL_CLIENT_H
+
+#include "enums/state.h"
+
+#include "listeners/actionlistener.h"
+
+#include "net/serverinfo.h"
+
+#ifdef USE_SDL2
+#include <SDL2_framerate.h>
+#else
+#include <SDL_framerate.h>
+#endif
+
+#include "localconsts.h"
+
+class Button;
+class Desktop;
+class Skin;
+class Window;
+
+extern bool isSafeMode;
+extern int serverVersion;
+extern unsigned int tmwServerVersion;
+extern int start_time;
+extern int textures_count;
+
+extern std::string errorMessage;
+
+/**
+ * The core part of the client. This class initializes all subsystems, runs
+ * the event loop, and shuts everything down again.
+ */
+class Client final : public ActionListener
+{
+ public:
+ Client();
+
+ A_DELETE_COPY(Client)
+
+ ~Client();
+
+ void gameInit();
+
+ void testsInit();
+
+ int gameExec();
+
+ static int testsExec();
+
+ void setState(const State state)
+ { mState = state; }
+
+ State getState() const A_WARN_UNUSED
+ { return mState; }
+
+ void action(const ActionEvent &event) override final;
+
+ void moveButtons(const int width);
+
+ void windowRemoved(const Window *const window);
+
+ void slowLogic();
+
+ private:
+ void stateGame();
+
+ void initSoundManager();
+
+ static void initGraphics();
+
+ void gameClear();
+
+ void testsClear();
+
+ static void logVars();
+
+ Window *mCurrentDialog;
+ Button *mSetupButton;
+ Button *mVideoButton;
+ Button *mHelpButton;
+ Button *mAboutButton;
+ Button *mThemesButton;
+ Button *mPerfomanceButton;
+#ifdef ANDROID
+ Button *mCloseButton;
+#endif
+
+ State mState;
+ State mOldState;
+
+ Skin *mSkin;
+ int mButtonPadding;
+ int mButtonSpacing;
+ int mPing;
+ bool mConfigAutoSaved;
+};
+
+extern Client *client;
+extern unsigned int mLastHost;
+extern unsigned long mSearchHash;
+
+#endif // DYETOOL_CLIENT_H
diff --git a/src/dyetool/dyemain.cpp b/src/dyetool/dyemain.cpp
index 9d20e1df6..1d5f55a6d 100644
--- a/src/dyetool/dyemain.cpp
+++ b/src/dyetool/dyemain.cpp
@@ -21,6 +21,7 @@
#include "logger.h"
#include "graphicsmanager.h"
+#include "maingui.h"
#include "sdlshared.h"
#include "resources/image.h"
@@ -41,8 +42,6 @@
#include "debug.h"
-int serverVersion = 0;
-
static void printHelp()
{
std::cout << _("dyecmd srcfile dyestring dstfile") << std::endl;
@@ -52,6 +51,10 @@ static void printHelp()
int main(int argc, char **argv)
{
+ if (argc == 2)
+ {
+ return mainGui(argc, argv);
+ }
if (argc < 3 || argc > 4)
{
printHelp();
diff --git a/src/dyetool/gui/viewport.cpp b/src/dyetool/gui/viewport.cpp
new file mode 100644
index 000000000..26de44a3a
--- /dev/null
+++ b/src/dyetool/gui/viewport.cpp
@@ -0,0 +1,290 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gui/viewport.h"
+
+#include "actormanager.h"
+#include "configuration.h"
+#include "game.h"
+#include "settings.h"
+#include "sdlshared.h"
+#include "textmanager.h"
+
+#include "enums/resources/map/mapitemtype.h"
+
+#include "resources/map/map.h"
+#include "resources/map/mapitem.h"
+#include "resources/map/speciallayer.h"
+
+#include "being/localplayer.h"
+#include "being/playerinfo.h"
+
+#include "input/inputmanager.h"
+
+#include "gui/gui.h"
+#include "gui/popupmanager.h"
+#include "gui/userpalette.h"
+
+#include "gui/fonts/font.h"
+
+#include "gui/popups/beingpopup.h"
+#include "gui/popups/popupmenu.h"
+#include "gui/popups/textpopup.h"
+
+#include "gui/windows/ministatuswindow.h"
+
+#include "debug.h"
+
+Viewport *viewport = nullptr;
+
+extern volatile int tick_time;
+extern MiniStatusWindow *miniStatusWindow;
+
+Viewport::Viewport() :
+ WindowContainer(nullptr),
+ MouseListener(),
+ mMouseX(0),
+ mMouseY(0),
+ mMap(nullptr),
+ mHoverBeing(nullptr),
+ mHoverItem(nullptr),
+ mHoverSign(nullptr),
+ mScrollRadius(config.getIntValue("ScrollRadius")),
+ mScrollLaziness(config.getIntValue("ScrollLaziness")),
+ mScrollCenterOffsetX(config.getIntValue("ScrollCenterOffsetX")),
+ mScrollCenterOffsetY(config.getIntValue("ScrollCenterOffsetY")),
+ mMousePressX(0),
+ mMousePressY(0),
+ mPixelViewX(0),
+ mPixelViewY(0),
+ mLocalWalkTime(-1),
+ mCameraRelativeX(0),
+ mCameraRelativeY(0),
+ mShowBeingPopup(config.getBoolValue("showBeingPopup")),
+ mSelfMouseHeal(config.getBoolValue("selfMouseHeal")),
+ mEnableLazyScrolling(config.getBoolValue("enableLazyScrolling")),
+ mMouseDirectionMove(config.getBoolValue("mouseDirectionMove")),
+ mLongMouseClick(config.getBoolValue("longmouseclick")),
+ mMouseClicked(false),
+ mPlayerFollowMouse(false)
+{
+ setOpaque(false);
+ addMouseListener(this);
+
+ config.addListener("ScrollLaziness", this);
+ config.addListener("ScrollRadius", this);
+ config.addListener("showBeingPopup", this);
+ config.addListener("selfMouseHeal", this);
+ config.addListener("enableLazyScrolling", this);
+ config.addListener("mouseDirectionMove", this);
+ config.addListener("longmouseclick", this);
+
+ setFocusable(true);
+}
+
+Viewport::~Viewport()
+{
+ config.removeListeners(this);
+ CHECKLISTENERS
+}
+
+void Viewport::setMap(Map *const map A_UNUSED)
+{
+}
+
+void Viewport::draw(Graphics *graphics)
+{
+ BLOCK_START("Viewport::draw 1")
+ static int lastTick = tick_time;
+
+ graphics->setColor(Color(64, 64, 64));
+ graphics->fillRectangle(
+ Rect(0, 0, getWidth(), getHeight()));
+
+ // Avoid freaking out when tick_time overflows
+ if (tick_time < lastTick)
+ lastTick = tick_time;
+
+ // Draw contained widgets
+ WindowContainer::draw(graphics);
+ BLOCK_END("Viewport::draw 1")
+}
+
+void Viewport::safeDraw(Graphics *graphics)
+{
+ Viewport::draw(graphics);
+}
+
+void Viewport::logic()
+{
+ BLOCK_START("Viewport::logic")
+ // Make the player follow the mouse position
+ // if the mouse is dragged elsewhere than in a window.
+ Gui::getMouseState(mMouseX, mMouseY);
+ BLOCK_END("Viewport::logic")
+}
+
+void Viewport::followMouse()
+{
+}
+
+void Viewport::drawDebugPath(Graphics *const graphics A_UNUSED)
+{
+}
+
+bool Viewport::openContextMenu(const MouseEvent &event A_UNUSED)
+{
+ return false;
+}
+
+void Viewport::mousePressed(MouseEvent &event)
+{
+ if (event.getSource() != this || event.isConsumed())
+ return;
+
+ mMouseClicked = true;
+
+ mMousePressX = event.getX();
+ mMousePressY = event.getY();
+ const MouseButtonT eventButton = event.getButton();
+
+ // Right click might open a popup
+ if (eventButton == MouseButton::RIGHT)
+ {
+ if (openContextMenu(event))
+ return;
+ }
+
+ // If a popup is active, just remove it
+ if (popupManager->isPopupMenuVisible())
+ {
+ mPlayerFollowMouse = false;
+ popupManager->hidePopupMenu();
+ return;
+ }
+
+ // Left click can cause different actions
+ if (!mLongMouseClick && eventButton == MouseButton::LEFT)
+ {
+ if (leftMouseAction())
+ {
+ mPlayerFollowMouse = false;
+ return;
+ }
+ }
+}
+
+void Viewport::walkByMouse(const MouseEvent &event A_UNUSED)
+{
+}
+
+void Viewport::mouseDragged(MouseEvent &event)
+{
+ if (event.getSource() != this || event.isConsumed())
+ {
+ mPlayerFollowMouse = false;
+ return;
+ }
+ if (mMouseClicked)
+ {
+ if (abs(event.getX() - mMousePressX) > 32
+ || abs(event.getY() - mMousePressY) > 32)
+ {
+ mPlayerFollowMouse = true;
+ }
+ }
+
+ walkByMouse(event);
+}
+
+void Viewport::mouseReleased(MouseEvent &event)
+{
+ mPlayerFollowMouse = false;
+ mLocalWalkTime = -1;
+ if (mLongMouseClick && mMouseClicked)
+ {
+ mMouseClicked = false;
+ if (event.getSource() != this || event.isConsumed())
+ return;
+ const MouseButtonT eventButton = event.getButton();
+ if (eventButton == MouseButton::LEFT)
+ {
+ // long button press
+ if (gui && gui->isLongPress())
+ {
+ if (openContextMenu(event))
+ {
+ gui->resetClickCount();
+ return;
+ }
+ }
+ else
+ {
+ if (leftMouseAction())
+ return;
+ }
+ walkByMouse(event);
+ }
+ }
+}
+
+void Viewport::optionChanged(const std::string &name)
+{
+ if (name == "ScrollLaziness")
+ mScrollLaziness = config.getIntValue("ScrollLaziness");
+ else if (name == "ScrollRadius")
+ mScrollRadius = config.getIntValue("ScrollRadius");
+ else if (name == "showBeingPopup")
+ mShowBeingPopup = config.getBoolValue("showBeingPopup");
+ else if (name == "selfMouseHeal")
+ mSelfMouseHeal = config.getBoolValue("selfMouseHeal");
+ else if (name == "enableLazyScrolling")
+ mEnableLazyScrolling = config.getBoolValue("enableLazyScrolling");
+ else if (name == "mouseDirectionMove")
+ mMouseDirectionMove = config.getBoolValue("mouseDirectionMove");
+ else if (name == "longmouseclick")
+ mLongMouseClick = config.getBoolValue("longmouseclick");
+}
+
+void Viewport::mouseMoved(MouseEvent &event A_UNUSED)
+{
+}
+
+void Viewport::toggleMapDrawType()
+{
+}
+
+void Viewport::toggleCameraMode()
+{
+}
+
+void Viewport::cleanHoverItems()
+{
+ mHoverBeing = nullptr;
+ mHoverItem = nullptr;
+ mHoverSign = nullptr;
+}
+
+bool Viewport::leftMouseAction()
+{
+ return false;
+}
diff --git a/src/dyetool/gui/viewport.h b/src/dyetool/gui/viewport.h
new file mode 100644
index 000000000..12527d962
--- /dev/null
+++ b/src/dyetool/gui/viewport.h
@@ -0,0 +1,220 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef DYETOOL_GUI_VIEWPORT_H
+#define DYETOOL_GUI_VIEWPORT_H
+
+#include "position.h"
+
+#include "enums/simpletypes/beingid.h"
+
+#include "gui/widgets/windowcontainer.h"
+
+#include "listeners/mouselistener.h"
+
+class ActorSprite;
+class Being;
+class FloorItem;
+class Graphics;
+class Map;
+class MapItem;
+
+/** Delay between two mouse calls when dragging mouse and move the player */
+const int walkingMouseDelay = 500;
+
+/**
+ * The viewport on the map. Displays the current map and handles mouse input
+ * and the popup menu.
+ *
+ * TODO: This class is planned to be extended to allow floating widgets on top
+ * of it such as NPC messages, which are positioned using map pixel
+ * coordinates.
+ */
+class Viewport final : public WindowContainer,
+ public MouseListener,
+ public ConfigListener
+{
+ public:
+ /**
+ * Constructor.
+ */
+ Viewport();
+
+ A_DELETE_COPY(Viewport)
+
+ /**
+ * Destructor.
+ */
+ ~Viewport();
+
+ /**
+ * Sets the map displayed by the viewport.
+ */
+ void setMap(Map *const map);
+
+ /**
+ * Draws the viewport.
+ */
+ void draw(Graphics *graphics) override final A_NONNULL(2);
+
+ void safeDraw(Graphics *graphics) override final A_NONNULL(2);
+
+ /**
+ * Implements player to keep following mouse.
+ */
+ void logic() override final;
+
+ /**
+ * Toggles whether the path debug graphics are shown. normal,
+ * debug with all images and grid, debug with out big images
+ * and with out grid.
+ */
+ void toggleMapDrawType();
+
+ void toggleCameraMode();
+
+ /**
+ * Handles mouse press on map.
+ */
+ void mousePressed(MouseEvent &event) override final;
+
+ /**
+ * Handles mouse move on map
+ */
+ void mouseDragged(MouseEvent &event) override final;
+
+ /**
+ * Handles mouse button release on map.
+ */
+ void mouseReleased(MouseEvent &event) override final;
+
+ /**
+ * Handles mouse move on map.
+ */
+ void mouseMoved(MouseEvent &event) override final;
+
+ /**
+ * A relevant config option changed.
+ */
+ void optionChanged(const std::string &name) override final;
+
+ /**
+ * Returns camera x offset in pixels.
+ */
+ int getCameraX() const A_WARN_UNUSED
+ { return mPixelViewX; }
+
+ /**
+ * Returns camera y offset in pixels.
+ */
+ int getCameraY() const A_WARN_UNUSED
+ { return mPixelViewY; }
+
+ /**
+ * Changes viewpoint by relative pixel coordinates.
+ */
+ void scrollBy(const int x, const int y)
+ { mPixelViewX += x; mPixelViewY += y; }
+
+ /**
+ * Clear all hover item\being etc
+ */
+ void cleanHoverItems();
+
+ Map *getMap() const A_WARN_UNUSED
+ { return mMap; }
+
+ void moveCamera(const int dx, const int dy);
+
+ int getCameraRelativeX() const A_WARN_UNUSED
+ { return mCameraRelativeX; }
+
+ int getCameraRelativeY() const A_WARN_UNUSED
+ { return mCameraRelativeY; }
+
+ void setCameraRelativeX(const int n)
+ { mCameraRelativeX = n; }
+
+ void setCameraRelativeY(const int n)
+ { mCameraRelativeY = n; }
+
+ int mMouseX; /**< Current mouse position in pixels. */
+ int mMouseY; /**< Current mouse position in pixels. */
+
+ private:
+ /**
+ * Finds a path from the player to the mouse, and draws it. This is for
+ * debug purposes.
+ */
+ void drawDebugPath(Graphics *const graphics) A_NONNULL(2);
+
+ /**
+ * Draws the given path.
+ */
+ void drawPath(Graphics *const graphics,
+ const Path &path,
+ const Color &color = Color(255, 0, 0))
+ const A_NONNULL(2);
+
+ bool leftMouseAction();
+
+ bool openContextMenu(const MouseEvent &event);
+
+ void walkByMouse(const MouseEvent &event);
+
+ /**
+ * Make the player go to the mouse position.
+ */
+ void followMouse();
+
+ Map *mMap; /**< The current map. */
+
+ Being *mHoverBeing; /**< Being mouse is currently over. */
+ FloorItem *mHoverItem; /**< FloorItem mouse is currently over. */
+ MapItem *mHoverSign; /**< Map sign mouse is currently over. */
+
+ int mScrollRadius;
+ int mScrollLaziness;
+ int mScrollCenterOffsetX;
+ int mScrollCenterOffsetY;
+ int mMousePressX;
+ int mMousePressY;
+ int mPixelViewX; /**< Current viewpoint in pixels. */
+ int mPixelViewY; /**< Current viewpoint in pixels. */
+
+ int mLocalWalkTime; /**< Timestamp before the next walk can be sent. */
+
+ int mCameraRelativeX;
+ int mCameraRelativeY;
+
+ bool mShowBeingPopup;
+ bool mSelfMouseHeal;
+ bool mEnableLazyScrolling;
+ bool mMouseDirectionMove;
+ bool mLongMouseClick;
+ bool mMouseClicked;
+ bool mPlayerFollowMouse;
+};
+
+extern Viewport *viewport; /**< The viewport. */
+
+#endif // DYETOOL_GUI_VIEWPORT_H