From feee96b61b8effb160b00484e156b8cc9caf219b Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 9 Aug 2011 02:49:59 +0300 Subject: Add perfomance setup tab. Move some settings from video to perfomance tab. --- src/CMakeLists.txt | 2 ++ src/Makefile.am | 2 ++ src/gui/setup.cpp | 4 ++- src/gui/setup_video.cpp | 96 +++++++++++-------------------------------------- src/gui/setup_video.h | 10 ------ 5 files changed, 28 insertions(+), 86 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4d230c18f..ff9c75770 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -315,6 +315,8 @@ SET(SRCS gui/setup_chat.h gui/setup_keyboard.cpp gui/setup_keyboard.h + gui/setup_perfomance.cpp + gui/setup_perfomance.h gui/setup_players.cpp gui/setup_players.h gui/setup_video.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 18ae560b8..ba04b5f2b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -318,6 +318,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ gui/setup_chat.h \ gui/setup_keyboard.cpp \ gui/setup_keyboard.h \ + gui/setup_perfomance.cpp \ + gui/setup_perfomance.h \ gui/setup_players.cpp \ gui/setup_players.h \ gui/setup_video.cpp \ diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 33ff6ddb7..129914ad8 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -27,14 +27,15 @@ #include "main.h" #include "gui/setup_audio.h" +#include "gui/setup_chat.h" #include "gui/setup_colors.h" #include "gui/setup_joystick.h" #include "gui/setup_other.h" #include "gui/setup_theme.h" #include "gui/setup_keyboard.h" +#include "gui/setup_perfomance.h" #include "gui/setup_players.h" #include "gui/setup_video.h" -#include "gui/setup_chat.h" #include "gui/widgets/button.h" #include "gui/widgets/label.h" @@ -88,6 +89,7 @@ Setup::Setup(): mTabs.push_back(new Setup_Video); mTabs.push_back(new Setup_Audio); + mTabs.push_back(new Setup_Perfomance); mTabs.push_back(new Setup_Joystick); mTabs.push_back(new Setup_Keyboard); mTabs.push_back(new Setup_Colors); diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 3e5c56f64..d73a9e1bb 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -274,24 +274,17 @@ const char *Setup_Video::particleDetailToString(int detail) Setup_Video::Setup_Video(): mFullScreenEnabled(config.getBoolValue("screen")), mOpenGLEnabled(config.getIntValue("opengl")), - mHwAccelEnabled(config.getBoolValue("hwaccel")), mCustomCursorEnabled(config.getBoolValue("customcursor")), mParticleEffectsEnabled(config.getBoolValue("particleeffects")), mPickupChatEnabled(config.getBoolValue("showpickupchat")), mPickupParticleEnabled(config.getBoolValue("showpickupparticle")), - mOpacity(config.getFloatValue("guialpha")), mFps(config.getIntValue("fpslimit")), mAltFps(config.getIntValue("altfpslimit")), - mAlphaCache(config.getBoolValue("alphaCache")), - mEnableMapReduce(config.getBoolValue("enableMapReduce")), - mAdjustPerfomance(config.getBoolValue("adjustPerfomance")), - mBeingOpacity(config.getBoolValue("beingopacity")), mSpeechMode(static_cast( config.getIntValue("speech"))), mModeListModel(new ModeListModel), mModeList(new ListBox(mModeListModel)), mFsCheckBox(new CheckBox(_("Full screen"), mFullScreenEnabled)), - mHwAccelCheckBox(new CheckBox(_("Hw acceleration"), mHwAccelEnabled)), mCustomCursorCheckBox(new CheckBox(_("Custom cursor"), mCustomCursorEnabled)), mParticleEffectsCheckBox(new CheckBox(_("Particle effects"), @@ -302,13 +295,6 @@ Setup_Video::Setup_Video(): // TRANSLATORS: Refers to "Show own name" mPickupParticleCheckBox(new CheckBox(_("as particle"), mPickupParticleEnabled)), - mAlphaCacheCheckBox(new CheckBox(_("Enable opacity cache"), mAlphaCache)), - mEnableMapReduceCheckBox(new CheckBox(_("Enable map reduce"), - mEnableMapReduce)), - mAdjustPerfomanceCheckBox(new CheckBox(_("Auto adjust perfomance"), - mAdjustPerfomance)), - mBeingOpacityCheckBox(new CheckBox(_("Show beings transparency"), - mBeingOpacity)), mSpeechSlider(new Slider(0, 3)), mSpeechLabel(new Label("")), mAlphaSlider(new Slider(0.1, 1.0)), @@ -348,8 +334,6 @@ Setup_Video::Setup_Video(): mAlphaSlider->setValue(mOpacity); mAlphaSlider->setWidth(90); - mAlphaCacheCheckBox->setEnabled(mOpenGLDropDown->getSelected() == 0); - mEnableMapReduceCheckBox->setEnabled(mOpenGLDropDown->getSelected() == 0); mFpsLabel->setCaption(mFps > 0 ? toString(mFps) : _("None")); mFpsLabel->setWidth(60); @@ -381,9 +365,6 @@ Setup_Video::Setup_Video(): mOverlayDetailField->setActionEventId("overlaydetailfield"); mParticleDetailSlider->setActionEventId("particledetailslider"); mParticleDetailField->setActionEventId("particledetailfield"); - mAlphaCacheCheckBox->setActionEventId("alphaCache"); - mEnableMapReduceCheckBox->setActionEventId("enableMapReduce"); - mAdjustPerfomanceCheckBox->setActionEventId("adjustPerfomance"); mOpenGLDropDown->setActionEventId("opengl"); mModeList->addActionListener(this); @@ -402,10 +383,6 @@ Setup_Video::Setup_Video(): mParticleDetailField->addKeyListener(this); mOpenGLDropDown->addActionListener(this); - mAlphaCacheCheckBox->addKeyListener(this); - mEnableMapReduceCheckBox->addKeyListener(this); - mAdjustPerfomanceCheckBox->addKeyListener(this); - mSpeechLabel->setCaption(speechModeToString(mSpeechMode)); mSpeechSlider->setValue(mSpeechMode); @@ -422,45 +399,40 @@ Setup_Video::Setup_Video(): place(0, 0, scrollArea, 1, 5).setPadding(2); place(0, 5, mOpenGLDropDown, 1); - place(0, 6, mHwAccelCheckBox, 6); - place(0, 7, mAlphaCacheCheckBox, 6); - place(0, 8, mEnableMapReduceCheckBox, 6); +// place(0, 6, mHwAccelCheckBox, 6); place(1, 0, mFsCheckBox, 2); place(1, 1, mCustomCursorCheckBox, 3); - place(1, 2, mBeingOpacityCheckBox); - place(1, 3, mParticleEffectsCheckBox, 2); - - place(1, 4, mPickupNotifyLabel, 4); + place(1, 2, mParticleEffectsCheckBox, 2); - place(1, 5, mPickupChatCheckBox, 1); - place(2, 5, mPickupParticleCheckBox, 2); + place(1, 3, mPickupNotifyLabel, 4); - place(0, 9, mAdjustPerfomanceCheckBox, 6); + place(1, 4, mPickupChatCheckBox, 1); + place(2, 4, mPickupParticleCheckBox, 2); - place(0, 10, mAlphaSlider); - place(1, 10, alphaLabel, 3); + place(0, 6, mAlphaSlider); + place(1, 6, alphaLabel, 3); - place(0, 11, mFpsSlider); - place(1, 11, mFpsCheckBox).setPadding(3); - place(2, 11, mFpsLabel).setPadding(1); + place(0, 7, mFpsSlider); + place(1, 7, mFpsCheckBox).setPadding(3); + place(2, 7, mFpsLabel).setPadding(1); - place(0, 12, mAltFpsSlider); - place(1, 12, mAltFpsLabel).setPadding(3); + place(0, 8, mAltFpsSlider); + place(1, 8, mAltFpsLabel).setPadding(3); - place(0, 13, mSpeechSlider); - place(1, 13, speechLabel); - place(2, 13, mSpeechLabel, 3).setPadding(2); + place(0, 9, mSpeechSlider); + place(1, 9, speechLabel); + place(2, 9, mSpeechLabel, 3).setPadding(2); - place(0, 14, mOverlayDetailSlider); - place(1, 14, overlayDetailLabel); - place(2, 14, mOverlayDetailField, 3).setPadding(2); + place(0, 10, mOverlayDetailSlider); + place(1, 10, overlayDetailLabel); + place(2, 10, mOverlayDetailField, 3).setPadding(2); - place(0, 15, mParticleDetailSlider); - place(1, 15, particleDetailLabel); - place(2, 15, mParticleDetailField, 3).setPadding(2); + place(0, 11, mParticleDetailSlider); + place(1, 11, particleDetailLabel); + place(2, 11, mParticleDetailField, 3).setPadding(2); int width = 600; @@ -551,33 +523,20 @@ void Setup_Video::apply() mAltFpsSlider->setEnabled(mAltFps > 0); - config.setValue("hwaccel", mHwAccelCheckBox->isSelected()); - // FPS change config.setValue("fpslimit", mFps); config.setValue("altfpslimit", mAltFps); - config.setValue("alphaCache", mAlphaCacheCheckBox->isSelected()); - config.setValue("enableMapReduce", mEnableMapReduceCheckBox->isSelected()); - config.setValue("adjustPerfomance", - mAdjustPerfomanceCheckBox->isSelected()); - config.setValue("beingopacity", mBeingOpacityCheckBox->isSelected()); - // We sync old and new values at apply time mFullScreenEnabled = config.getBoolValue("screen"); mCustomCursorEnabled = config.getBoolValue("customcursor"); mParticleEffectsEnabled = config.getBoolValue("particleeffects"); - mAlphaCache = config.getBoolValue("alphaCache"); - mEnableMapReduce = config.getBoolValue("enableMapReduce"); - mAdjustPerfomance = config.getBoolValue("adjustPerfomance"); - mBeingOpacity = config.getBoolValue("beingopacity"); mSpeechMode = static_cast( config.getIntValue("speech")); mOpacity = config.getFloatValue("guialpha"); mOverlayDetail = config.getIntValue("OverlayDetail"); mOpenGLEnabled = config.getIntValue("opengl"); - mHwAccelEnabled = config.getBoolValue("hwaccel"); mPickupChatEnabled = config.getBoolValue("showpickupchat"); mPickupParticleEnabled = config.getBoolValue("showpickupparticle"); } @@ -587,7 +546,6 @@ void Setup_Video::cancel() mFpsCheckBox->setSelected(mFps > 0); mFsCheckBox->setSelected(mFullScreenEnabled); mOpenGLDropDown->setSelected(mOpenGLEnabled); - mHwAccelCheckBox->setSelected(mHwAccelEnabled); mCustomCursorCheckBox->setSelected(mCustomCursorEnabled); mParticleEffectsCheckBox->setSelected(mParticleEffectsEnabled); mFpsSlider->setValue(mFps); @@ -595,10 +553,6 @@ void Setup_Video::cancel() mAltFpsSlider->setValue(mAltFps); mAltFpsSlider->setEnabled(mAltFps > 0); mSpeechSlider->setValue(mSpeechMode); - mAlphaCacheCheckBox->setSelected(mAlphaCache); - mEnableMapReduceCheckBox->setSelected(mEnableMapReduce); - mAdjustPerfomanceCheckBox->setSelected(mAdjustPerfomance); - mBeingOpacityCheckBox->setSelected(mBeingOpacity); mAlphaSlider->setValue(mOpacity); mOverlayDetailSlider->setValue(mOverlayDetail); mParticleDetailSlider->setValue(mParticleDetail); @@ -618,17 +572,11 @@ void Setup_Video::cancel() config.setValue("customcursor", mCustomCursorEnabled); config.setValue("particleeffects", mParticleEffectsEnabled); config.setValue("speech", static_cast(mSpeechMode)); - config.setValue("alphaCache", mAlphaCache); - config.setValue("enableMapReduce", mEnableMapReduce); - config.setValue("adjustPerfomance", mAdjustPerfomance); - config.setValue("beingopacity", mBeingOpacity); config.setValue("guialpha", mOpacity); Image::setEnableAlpha(mOpacity != 1.0f); config.setValue("opengl", mOpenGLEnabled); - config.setValue("hwaccel", mHwAccelEnabled); config.setValue("showpickupchat", mPickupChatEnabled); config.setValue("showpickupparticle", mPickupParticleEnabled); - mAlphaCacheCheckBox->setEnabled(mOpenGLDropDown->getSelected() == 0); } void Setup_Video::action(const gcn::ActionEvent &event) @@ -764,8 +712,6 @@ void Setup_Video::action(const gcn::ActionEvent &event) else if (id == "opengl") { bool isSoftware = (mOpenGLDropDown->getSelected() == 0); - mAlphaCacheCheckBox->setEnabled(isSoftware); - mEnableMapReduceCheckBox->setEnabled(isSoftware); } } diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h index 9533877fb..509deb2fd 100644 --- a/src/gui/setup_video.h +++ b/src/gui/setup_video.h @@ -55,7 +55,6 @@ class Setup_Video : public SetupTab, public gcn::KeyListener private: bool mFullScreenEnabled; int mOpenGLEnabled; - bool mHwAccelEnabled; bool mCustomCursorEnabled; bool mParticleEffectsEnabled; bool mPickupChatEnabled; @@ -63,10 +62,6 @@ class Setup_Video : public SetupTab, public gcn::KeyListener float mOpacity; int mFps; int mAltFps; - bool mAlphaCache; - bool mEnableMapReduce; - bool mAdjustPerfomance; - bool mBeingOpacity; Being::Speech mSpeechMode; ModeListModel *mModeListModel; @@ -83,7 +78,6 @@ class Setup_Video : public SetupTab, public gcn::KeyListener gcn::ListBox *mModeList; gcn::CheckBox *mFsCheckBox; gcn::DropDown *mOpenGLDropDown; - gcn::CheckBox *mHwAccelCheckBox; gcn::CheckBox *mCustomCursorCheckBox; gcn::CheckBox *mParticleEffectsCheckBox; @@ -91,10 +85,6 @@ class Setup_Video : public SetupTab, public gcn::KeyListener gcn::CheckBox *mPickupChatCheckBox; gcn::CheckBox *mPickupParticleCheckBox; - gcn::CheckBox *mAlphaCacheCheckBox; - gcn::CheckBox *mEnableMapReduceCheckBox; - gcn::CheckBox *mAdjustPerfomanceCheckBox; - gcn::CheckBox *mBeingOpacityCheckBox; gcn::Slider *mSpeechSlider; gcn::Label *mSpeechLabel; gcn::Slider *mAlphaSlider; -- cgit v1.2.3-70-g09d2 From 08e646812a6881552141bed7cdb6f05f8b81dd0f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 9 Aug 2011 03:07:41 +0300 Subject: Fix copyright headers. Add missing copyrights and fix program name. --- src/chatlog.cpp | 6 +++--- src/chatlog.h | 4 ++-- src/dropshortcut.cpp | 5 +++-- src/dropshortcut.h | 5 +++-- src/gui/botcheckerwindow.cpp | 5 +++-- src/gui/botcheckerwindow.h | 5 +++-- src/gui/editdialog.cpp | 5 +++-- src/gui/editdialog.h | 5 +++-- src/gui/killstats.cpp | 5 +++-- src/gui/killstats.h | 5 +++-- src/gui/setup_chat.cpp | 4 ++-- src/gui/setup_chat.h | 4 ++-- src/gui/setup_other.cpp | 4 ++-- src/gui/setup_other.h | 4 ++-- src/gui/setup_theme.cpp | 5 +++-- src/gui/setup_theme.h | 5 +++-- src/gui/spellpopup.cpp | 5 +++-- src/gui/spellpopup.h | 5 +++-- src/gui/statuspopup.cpp | 5 +++-- src/gui/statuspopup.h | 5 +++-- src/gui/textcommandeditor.cpp | 5 +++-- src/gui/textcommandeditor.h | 5 +++-- src/gui/textpopup.cpp | 4 ++-- src/gui/textpopup.h | 4 ++-- src/gui/whoisonline.cpp | 5 +++-- src/gui/whoisonline.h | 5 +++-- src/gui/widgets/dropshortcutcontainer.cpp | 5 +++-- src/gui/widgets/dropshortcutcontainer.h | 5 +++-- src/gui/widgets/inventoryfilter.cpp | 4 ++-- src/gui/widgets/inventoryfilter.h | 4 ++-- src/gui/widgets/spellshortcutcontainer.cpp | 5 +++-- src/gui/widgets/spellshortcutcontainer.h | 5 +++-- src/main.h | 6 ------ src/net/beinghandler.h | 5 +++-- src/spellmanager.cpp | 5 +++-- src/spellmanager.h | 5 +++-- src/spellshortcut.cpp | 5 +++-- src/spellshortcut.h | 5 +++-- src/textcommand.cpp | 4 ++-- src/textcommand.h | 5 +++-- 40 files changed, 107 insertions(+), 85 deletions(-) (limited to 'src') diff --git a/src/chatlog.cpp b/src/chatlog.cpp index b0ff14479..99fe317c6 100644 --- a/src/chatlog.cpp +++ b/src/chatlog.cpp @@ -1,10 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 The ManaPlus Developers * - * This file is part of The Mana World. + * 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 diff --git a/src/chatlog.h b/src/chatlog.h index c3e8b2e27..2e9545b04 100644 --- a/src/chatlog.h +++ b/src/chatlog.h @@ -1,10 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009-2010 The Mana Developers * Copyright (C) 2011 The ManaPlus Developers * Copyright (C) 2009-2010 Andrei Karas * - * This file is part of The Mana World. + * 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 diff --git a/src/dropshortcut.cpp b/src/dropshortcut.cpp index ef67fca12..48eed92bc 100644 --- a/src/dropshortcut.cpp +++ b/src/dropshortcut.cpp @@ -1,9 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 ManaPlus developers * - * This file is part of The Mana World. + * 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 diff --git a/src/dropshortcut.h b/src/dropshortcut.h index ffaf40ccf..31c20677d 100644 --- a/src/dropshortcut.h +++ b/src/dropshortcut.h @@ -1,9 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 ManaPlus developers * - * This file is part of The Mana World. + * 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 diff --git a/src/gui/botcheckerwindow.cpp b/src/gui/botcheckerwindow.cpp index ac845adc1..aa44df2f3 100644 --- a/src/gui/botcheckerwindow.cpp +++ b/src/gui/botcheckerwindow.cpp @@ -1,9 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 ManaPlus developers * - * This file is part of The Mana World. + * 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 diff --git a/src/gui/botcheckerwindow.h b/src/gui/botcheckerwindow.h index e378fffb0..a69781865 100644 --- a/src/gui/botcheckerwindow.h +++ b/src/gui/botcheckerwindow.h @@ -1,9 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 ManaPlus developers * - * This file is part of The Mana World. + * 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 diff --git a/src/gui/editdialog.cpp b/src/gui/editdialog.cpp index bb80f07ed..da1d98e81 100644 --- a/src/gui/editdialog.cpp +++ b/src/gui/editdialog.cpp @@ -1,9 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 ManaPlus developers * - * This file is part of The Mana World. + * 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 diff --git a/src/gui/editdialog.h b/src/gui/editdialog.h index 55947b23d..dc0d1cc63 100644 --- a/src/gui/editdialog.h +++ b/src/gui/editdialog.h @@ -1,9 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 ManaPlus developers * - * This file is part of The Mana World. + * 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 diff --git a/src/gui/killstats.cpp b/src/gui/killstats.cpp index 95e16127a..05a265da7 100644 --- a/src/gui/killstats.cpp +++ b/src/gui/killstats.cpp @@ -1,9 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 ManaPlus developers * - * This file is part of The Mana World. + * 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 diff --git a/src/gui/killstats.h b/src/gui/killstats.h index 3c7679ca9..ff2a8f010 100644 --- a/src/gui/killstats.h +++ b/src/gui/killstats.h @@ -1,9 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 ManaPlus developers * - * This file is part of The Mana World. + * 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 diff --git a/src/gui/setup_chat.cpp b/src/gui/setup_chat.cpp index 7db61542a..bdba4df7a 100644 --- a/src/gui/setup_chat.cpp +++ b/src/gui/setup_chat.cpp @@ -1,10 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas * Copyright (C) 2011 The ManaPlus Developers * - * This file is part of The Mana World. + * 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 diff --git a/src/gui/setup_chat.h b/src/gui/setup_chat.h index 0b69984c8..402235d99 100644 --- a/src/gui/setup_chat.h +++ b/src/gui/setup_chat.h @@ -1,10 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas * Copyright (C) 2011 The ManaPlus Developers * - * This file is part of The Mana World. + * 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 diff --git a/src/gui/setup_other.cpp b/src/gui/setup_other.cpp index ac047e34b..3675da4ca 100644 --- a/src/gui/setup_other.cpp +++ b/src/gui/setup_other.cpp @@ -1,10 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas * Copyright (C) 2011 The ManaPlus Developers * - * This file is part of The Mana World. + * 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 diff --git a/src/gui/setup_other.h b/src/gui/setup_other.h index 945a2de46..a13bf4ba3 100644 --- a/src/gui/setup_other.h +++ b/src/gui/setup_other.h @@ -1,10 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas * Copyright (C) 2011 The ManaPlus Developers * - * This file is part of The Mana World. + * 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 diff --git a/src/gui/setup_theme.cpp b/src/gui/setup_theme.cpp index 515e15611..42ed0205c 100644 --- a/src/gui/setup_theme.cpp +++ b/src/gui/setup_theme.cpp @@ -1,9 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2010 Andrei Karas + * Copyright (C) 2011 ManaPlus developers * - * This file is part of The Mana World. + * 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 diff --git a/src/gui/setup_theme.h b/src/gui/setup_theme.h index 0d141c0a5..1952a88c6 100644 --- a/src/gui/setup_theme.h +++ b/src/gui/setup_theme.h @@ -1,9 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 ManaPlus developers * - * This file is part of The Mana World. + * 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 diff --git a/src/gui/spellpopup.cpp b/src/gui/spellpopup.cpp index e867ec4e8..86aeb2206 100644 --- a/src/gui/spellpopup.cpp +++ b/src/gui/spellpopup.cpp @@ -1,10 +1,11 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2008 The Legend of Mazzeroth Development Team * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 ManaPlus developers * - * This file is part of The Mana World. + * 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 diff --git a/src/gui/spellpopup.h b/src/gui/spellpopup.h index 1b14e0e4c..69c47bf45 100644 --- a/src/gui/spellpopup.h +++ b/src/gui/spellpopup.h @@ -1,10 +1,11 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2008 The Legend of Mazzeroth Development Team * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 ManaPlus developers * - * This file is part of The Mana World. + * 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 diff --git a/src/gui/statuspopup.cpp b/src/gui/statuspopup.cpp index c4216013a..08400a916 100644 --- a/src/gui/statuspopup.cpp +++ b/src/gui/statuspopup.cpp @@ -1,10 +1,11 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2008 The Legend of Mazzeroth Development Team * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 ManaPlus developers * - * This file is part of The Mana World. + * 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 diff --git a/src/gui/statuspopup.h b/src/gui/statuspopup.h index d633fb1f6..802b077a6 100644 --- a/src/gui/statuspopup.h +++ b/src/gui/statuspopup.h @@ -1,10 +1,11 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2008 The Legend of Mazzeroth Development Team * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 ManaPlus developers * - * This file is part of The Mana World. + * 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 diff --git a/src/gui/textcommandeditor.cpp b/src/gui/textcommandeditor.cpp index b3a1440e1..1f1273600 100644 --- a/src/gui/textcommandeditor.cpp +++ b/src/gui/textcommandeditor.cpp @@ -1,9 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 ManaPlus developers * - * This file is part of The Mana World. + * 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 diff --git a/src/gui/textcommandeditor.h b/src/gui/textcommandeditor.h index cb88b8160..236c42320 100644 --- a/src/gui/textcommandeditor.h +++ b/src/gui/textcommandeditor.h @@ -1,9 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 ManaPlus developers * - * This file is part of The Mana World. + * 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 diff --git a/src/gui/textpopup.cpp b/src/gui/textpopup.cpp index 4114706a6..7f1e0e6b8 100644 --- a/src/gui/textpopup.cpp +++ b/src/gui/textpopup.cpp @@ -1,11 +1,11 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2008 The Legend of Mazzeroth Development Team * Copyright (C) 2008-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers * Copyright (C) 2011 The ManaPlus Developers * - * This file is part of The Mana World. + * 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 diff --git a/src/gui/textpopup.h b/src/gui/textpopup.h index 898b53555..9ac041389 100644 --- a/src/gui/textpopup.h +++ b/src/gui/textpopup.h @@ -1,11 +1,11 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2008 The Legend of Mazzeroth Development Team * Copyright (C) 2008-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers * Copyright (C) 2011 The ManaPlus Developers * - * This file is part of The Mana World. + * 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 diff --git a/src/gui/whoisonline.cpp b/src/gui/whoisonline.cpp index 9c1a71478..99da53c66 100644 --- a/src/gui/whoisonline.cpp +++ b/src/gui/whoisonline.cpp @@ -1,9 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 ManaPlus developers * - * This file is part of The Mana World. + * 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 diff --git a/src/gui/whoisonline.h b/src/gui/whoisonline.h index 644121d08..72063b183 100644 --- a/src/gui/whoisonline.h +++ b/src/gui/whoisonline.h @@ -1,9 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 ManaPlus developers * - * This file is part of The Mana World. + * 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 diff --git a/src/gui/widgets/dropshortcutcontainer.cpp b/src/gui/widgets/dropshortcutcontainer.cpp index 257f4837c..92f02c78f 100644 --- a/src/gui/widgets/dropshortcutcontainer.cpp +++ b/src/gui/widgets/dropshortcutcontainer.cpp @@ -1,9 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 ManaPlus developers * - * This file is part of The Mana World. + * 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 diff --git a/src/gui/widgets/dropshortcutcontainer.h b/src/gui/widgets/dropshortcutcontainer.h index 77de914ea..723b215cf 100644 --- a/src/gui/widgets/dropshortcutcontainer.h +++ b/src/gui/widgets/dropshortcutcontainer.h @@ -1,9 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 ManaPlus developers * - * This file is part of The Mana World. + * 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 diff --git a/src/gui/widgets/inventoryfilter.cpp b/src/gui/widgets/inventoryfilter.cpp index a220fdb98..563e37b8c 100644 --- a/src/gui/widgets/inventoryfilter.cpp +++ b/src/gui/widgets/inventoryfilter.cpp @@ -1,8 +1,8 @@ /* - * The Mana Client + * The ManaPlus Client * Copyright (C) 2011 The ManaPlus Developers * - * This file is part of The Mana Client. + * 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 diff --git a/src/gui/widgets/inventoryfilter.h b/src/gui/widgets/inventoryfilter.h index da7b7af1e..be69489a8 100644 --- a/src/gui/widgets/inventoryfilter.h +++ b/src/gui/widgets/inventoryfilter.h @@ -1,9 +1,9 @@ /* - * The Mana Client + * The ManaPlus Client * Copyright (C) 2009-2010 The Mana Developers * Copyright (C) 2011 The ManaPlus Developers * - * This file is part of The Mana Client. + * 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 diff --git a/src/gui/widgets/spellshortcutcontainer.cpp b/src/gui/widgets/spellshortcutcontainer.cpp index 0f4814429..872ed16c7 100644 --- a/src/gui/widgets/spellshortcutcontainer.cpp +++ b/src/gui/widgets/spellshortcutcontainer.cpp @@ -1,9 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 ManaPlus developers * - * This file is part of The Mana World. + * 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 diff --git a/src/gui/widgets/spellshortcutcontainer.h b/src/gui/widgets/spellshortcutcontainer.h index 28016cbad..2155e2a8b 100644 --- a/src/gui/widgets/spellshortcutcontainer.h +++ b/src/gui/widgets/spellshortcutcontainer.h @@ -1,9 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 ManaPlus developers * - * This file is part of The Mana World. + * 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 diff --git a/src/main.h b/src/main.h index dbe9b3142..35a25fc02 100644 --- a/src/main.h +++ b/src/main.h @@ -26,12 +26,6 @@ /** * \mainpage * - * \section Introduction Introduction - * - * This is the documentation for the Mana client (http://manasource.org). It is - * always a work in progress, with the intent to make it easier for new - * developers to grow familiar with the source code. - * * \section General General information * * During the game, the current Map is displayed by the main Viewport, which diff --git a/src/net/beinghandler.h b/src/net/beinghandler.h index 89f972e6d..07279b148 100644 --- a/src/net/beinghandler.h +++ b/src/net/beinghandler.h @@ -1,8 +1,9 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2004 The Mana World Development Team + * Copyright (C) 2011 ManaPlus developers * - * This file is part of The Mana World. + * 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 diff --git a/src/spellmanager.cpp b/src/spellmanager.cpp index 29b99a9a0..13b8e7b69 100644 --- a/src/spellmanager.cpp +++ b/src/spellmanager.cpp @@ -1,9 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 ManaPlus developers * - * This file is part of The Mana World. + * 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 diff --git a/src/spellmanager.h b/src/spellmanager.h index 931302e37..651ada56c 100644 --- a/src/spellmanager.h +++ b/src/spellmanager.h @@ -1,9 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 ManaPlus developers * - * This file is part of The Mana World. + * 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 diff --git a/src/spellshortcut.cpp b/src/spellshortcut.cpp index 8a8e55c21..2c5bd253d 100644 --- a/src/spellshortcut.cpp +++ b/src/spellshortcut.cpp @@ -1,9 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 ManaPlus developers. * - * This file is part of The Mana World. + * 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 diff --git a/src/spellshortcut.h b/src/spellshortcut.h index 99f899eaa..4d59384bd 100644 --- a/src/spellshortcut.h +++ b/src/spellshortcut.h @@ -1,9 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 ManaPlus developers * - * This file is part of The Mana World. + * 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 diff --git a/src/textcommand.cpp b/src/textcommand.cpp index 836b3c653..665668c7e 100644 --- a/src/textcommand.cpp +++ b/src/textcommand.cpp @@ -1,9 +1,9 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas * - * This file is part of The Mana World. + * 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 diff --git a/src/textcommand.h b/src/textcommand.h index dbd621901..5ddbe824d 100644 --- a/src/textcommand.h +++ b/src/textcommand.h @@ -1,9 +1,10 @@ /* - * The Mana World + * The ManaPlus Client * Copyright (C) 2009 The Mana World Development Team * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 ManaPlus developers * - * This file is part of The Mana World. + * 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 -- cgit v1.2.3-70-g09d2 From 7d52a82733acb8f9e328392d8b4c3aef22cf3d96 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 9 Aug 2011 03:46:04 +0300 Subject: Add new perfomance parameters. --- src/compoundsprite.cpp | 32 +++++++++++++++++++++++--------- src/compoundsprite.h | 4 ++++ src/defaults.cpp | 3 +++ src/gui/setup_video.cpp | 4 ---- 4 files changed, 30 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/compoundsprite.cpp b/src/compoundsprite.cpp index 1642416ea..99fae4f88 100644 --- a/src/compoundsprite.cpp +++ b/src/compoundsprite.cpp @@ -21,6 +21,7 @@ #include "compoundsprite.h" +#include "configuration.h" #include "game.h" #include "graphics.h" #ifdef USE_OPENGL @@ -52,6 +53,9 @@ CompoundSprite::CompoundSprite(): mNeedsRedraw(false) { mAlpha = 1.0f; + mEnableAlphaFix = config.getBoolValue("enableAlphaFix"); + mDisableAdvBeingCaching = config.getBoolValue("disableAdvBeingCaching"); + mDisableBeingCaching = config.getBoolValue("disableBeingCaching"); } CompoundSprite::~CompoundSprite() @@ -406,7 +410,7 @@ void CompoundSprite::setAlpha(float alpha) { if (alpha != mAlpha) { - if (Image::mUseOpenGL == 0 && size() > 3) + if (mEnableAlphaFix && Image::mUseOpenGL == 0 && size() > 3) { SpriteConstIterator it, it_end; for (it = begin(), it_end = end(); it != it_end; ++ it) @@ -426,18 +430,28 @@ void CompoundSprite::updateImages() const return; #endif - if (size() <= 3) - return; - mNeedsRedraw = false; - if (updateFromCache()) - return; + if (!mDisableBeingCaching) + { + if (size() <= 3) + return; + + if (!mDisableAdvBeingCaching) + { + if (updateFromCache()) + return; - redraw(); + redraw(); - if (mImage) - initCurrentCacheItem(); + if (mImage) + initCurrentCacheItem(); + } + else + { + redraw(); + } + } } bool CompoundSprite::updateFromCache() const diff --git a/src/compoundsprite.h b/src/compoundsprite.h index 0841bcfb8..2211cb80c 100644 --- a/src/compoundsprite.h +++ b/src/compoundsprite.h @@ -135,6 +135,10 @@ private: mutable int mOffsetX, mOffsetY; mutable bool mNeedsRedraw; + + bool mEnableAlphaFix; + bool mDisableAdvBeingCaching; + bool mDisableBeingCaching; }; #endif // COMPOUNDSPRITE_H diff --git a/src/defaults.cpp b/src/defaults.cpp index 7b5f5255a..f779d4111 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -210,6 +210,9 @@ DefaultsData* getConfigDefaults() AddDEF(configData, "showPlayersStatus", true); AddDEF(configData, "beingopacity", false); AddDEF(configData, "adjustPerfomance", true); + AddDEF(configData, "enableAlphaFix", false); + AddDEF(configData, "disableAdvBeingCaching", false); + AddDEF(configData, "disableBeingCaching", false); return configData; } diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index d73a9e1bb..046e8e7a7 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -709,10 +709,6 @@ void Setup_Video::action(const gcn::ActionEvent &event) mAltFpsSlider->setValue(mAltFps); mAltFpsSlider->setEnabled(mAltFps > 0); } - else if (id == "opengl") - { - bool isSoftware = (mOpenGLDropDown->getSelected() == 0); - } } void Setup_Video::externalUpdated() -- cgit v1.2.3-70-g09d2 From 2381f6e964b228b30b735b7452d2234a4de9874f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 9 Aug 2011 04:24:29 +0300 Subject: Fix loading opacity settings in setup dialog. --- src/gui/setup_video.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 046e8e7a7..8979a81e1 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -278,6 +278,7 @@ Setup_Video::Setup_Video(): mParticleEffectsEnabled(config.getBoolValue("particleeffects")), mPickupChatEnabled(config.getBoolValue("showpickupchat")), mPickupParticleEnabled(config.getBoolValue("showpickupparticle")), + mOpacity(config.getFloatValue("guialpha")), mFps(config.getIntValue("fpslimit")), mAltFps(config.getIntValue("altfpslimit")), mSpeechMode(static_cast( -- cgit v1.2.3-70-g09d2 From 7c42da72cde5a43dfd3894da44935da223d59436 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 9 Aug 2011 23:24:25 +0300 Subject: Add option to enable/disable reorder sprites feature. --- src/being.cpp | 5 +++++ src/being.h | 1 + src/defaults.cpp | 1 + 3 files changed, 7 insertions(+) (limited to 'src') diff --git a/src/being.cpp b/src/being.cpp index 47e1f03fc..cd616fc67 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -196,6 +196,7 @@ bool Being::mShowOwnHP = false; bool Being::mShowGender = false; bool Being::mShowLevel = false; bool Being::mShowPlayersStatus = false; +bool Being::mEnableReorderSprites = true; std::list beingInfoCache; @@ -1750,6 +1751,7 @@ void Being::reReadConfig() mShowGender = config.getBoolValue("showgender"); mShowLevel = config.getBoolValue("showlevel"); mShowPlayersStatus = config.getBoolValue("showPlayersStatus"); + mEnableReorderSprites = config.getBoolValue("enableReorderSprites"); mUpdateConfigTime = cur_time; } @@ -2073,6 +2075,9 @@ void Being::resetCounters() void Being::recalcSpritesOrder() { + if (!mEnableReorderSprites) + return; + // logger->log("recalcSpritesOrder"); unsigned sz = static_cast(size()); if (sz < 1) diff --git a/src/being.h b/src/being.h index 092e324e4..76c968451 100644 --- a/src/being.h +++ b/src/being.h @@ -873,6 +873,7 @@ class Being : public ActorSprite, public ConfigListener static bool mShowGender; static bool mShowLevel; static bool mShowPlayersStatus; + static bool mEnableReorderSprites; unsigned int mMoveTime; unsigned int mAttackTime; diff --git a/src/defaults.cpp b/src/defaults.cpp index f779d4111..3824aafc9 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -213,6 +213,7 @@ DefaultsData* getConfigDefaults() AddDEF(configData, "enableAlphaFix", false); AddDEF(configData, "disableAdvBeingCaching", false); AddDEF(configData, "disableBeingCaching", false); + AddDEF(configData, "enableReorderSprites", true); return configData; } -- cgit v1.2.3-70-g09d2 From 2baeff01037773180803cd2c7cb65a6afef6159f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 9 Aug 2011 23:28:50 +0300 Subject: Add missing files. --- src/gui/setup_perfomance.cpp | 95 ++++++++++++++++++++++++++++++++++++++++++++ src/gui/setup_perfomance.h | 44 ++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 src/gui/setup_perfomance.cpp create mode 100644 src/gui/setup_perfomance.h (limited to 'src') diff --git a/src/gui/setup_perfomance.cpp b/src/gui/setup_perfomance.cpp new file mode 100644 index 000000000..0d5458cc4 --- /dev/null +++ b/src/gui/setup_perfomance.cpp @@ -0,0 +1,95 @@ +/* + * The ManaPlus Client + * Copyright (C) 2009 The Mana World Development Team + * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "gui/setup_perfomance.h" + +#include "gui/chatwindow.h" +#include "gui/editdialog.h" +#include "gui/setupitem.h" + +#include "gui/widgets/button.h" +#include "gui/widgets/chattab.h" +#include "gui/widgets/checkbox.h" +#include "gui/widgets/inttextfield.h" +#include "gui/widgets/label.h" +#include "gui/widgets/layouthelper.h" +#include "gui/widgets/scrollarea.h" + +#include "configuration.h" +#include "localplayer.h" +#include "log.h" + +#include "utils/gettext.h" + +#include "debug.h" + +Setup_Perfomance::Setup_Perfomance() +{ + setName(_("Perfomance")); + + // Do the layout + LayoutHelper h(this); + ContainerPlacer place = h.getPlacer(0, 0); + place(0, 0, mScroll, 10, 10); + + new SetupItemLabel(_("Better perfomance (enable for better perfomance)"), "", this); + + new SetupItemCheckBox(_("Auto adjust perfomance"), "", + "adjustPerfomance", this, "adjustPerfomanceEvent"); + + new SetupItemCheckBox(_("Show beings transparency"), "", + "beingopacity", this, "beingopacityEvent"); + + new SetupItemCheckBox(_("Hw acceleration"), "", + "hwaccel", this, "hwaccelEvent"); + + new SetupItemCheckBox(_("Enable opacity cache (Software, can " + "use many memory)"), "", "alphaCache", this, "alphaCacheEvent"); + + new SetupItemCheckBox(_("Enable map reduce (Software)"), "", + "enableMapReduce", this, "enableMapReduceEvent"); + + new SetupItemLabel(_("Better quality (disable for better perfomance)"), "", this); + + new SetupItemCheckBox(_("Enable alpha channel fix (Software, can be very slow)"), + "Can slow down drawing", "enableAlphaFix", + this, "enableAlphaFixEvent"); + + new SetupItemCheckBox(_("Enable reorder sprites."), "", + "enableReorderSprites", this, "enableReorderSpritesEvent"); + + new SetupItemLabel(_("Small memory (enable for lower memory usage)"), "", this); + + new SetupItemCheckBox(_("Disable advanced beings caching (Software)"), "", + "disableAdvBeingCaching", this, "disableAdvBeingCachingEvent"); + + new SetupItemCheckBox(_("Disable beings caching (Software)"), "", + "disableBeingCaching", this, "disableBeingCachingEvent"); + + setDimension(gcn::Rectangle(0, 0, 550, 350)); +} + +void Setup_Perfomance::apply() +{ + SetupTabScroll::apply(); +} diff --git a/src/gui/setup_perfomance.h b/src/gui/setup_perfomance.h new file mode 100644 index 000000000..f355c9691 --- /dev/null +++ b/src/gui/setup_perfomance.h @@ -0,0 +1,44 @@ +/* + * The ManaPlus Client + * Copyright (C) 2009 The Mana World Development Team + * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef GUI_SETUP_PERFOMANCE_H +#define GUI_SETUP_PERFOMANCE_H + +#include "guichanfwd.h" + +#include "gui/widgets/setuptabscroll.h" + +#include + +class IntTextField; +class EditDialog; + +class Setup_Perfomance : public SetupTabScroll +{ + public: + Setup_Perfomance(); + + void apply(); +}; + +#endif -- cgit v1.2.3-70-g09d2 From 7455b856a59be26725f9bd1285f256dbddea5335 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 9 Aug 2011 23:44:12 +0300 Subject: Fix code style. --- src/gui/setup_perfomance.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/gui/setup_perfomance.cpp b/src/gui/setup_perfomance.cpp index 0d5458cc4..eaadc7c3a 100644 --- a/src/gui/setup_perfomance.cpp +++ b/src/gui/setup_perfomance.cpp @@ -52,7 +52,8 @@ Setup_Perfomance::Setup_Perfomance() ContainerPlacer place = h.getPlacer(0, 0); place(0, 0, mScroll, 10, 10); - new SetupItemLabel(_("Better perfomance (enable for better perfomance)"), "", this); + new SetupItemLabel(_("Better perfomance (enable for better perfomance)"), + "", this); new SetupItemCheckBox(_("Auto adjust perfomance"), "", "adjustPerfomance", this, "adjustPerfomanceEvent"); @@ -69,16 +70,18 @@ Setup_Perfomance::Setup_Perfomance() new SetupItemCheckBox(_("Enable map reduce (Software)"), "", "enableMapReduce", this, "enableMapReduceEvent"); - new SetupItemLabel(_("Better quality (disable for better perfomance)"), "", this); + new SetupItemLabel(_("Better quality (disable for better perfomance)"), + "", this); - new SetupItemCheckBox(_("Enable alpha channel fix (Software, can be very slow)"), - "Can slow down drawing", "enableAlphaFix", + new SetupItemCheckBox(_("Enable alpha channel fix (Software, can " + "be very slow)"), "Can slow down drawing", "enableAlphaFix", this, "enableAlphaFixEvent"); new SetupItemCheckBox(_("Enable reorder sprites."), "", "enableReorderSprites", this, "enableReorderSpritesEvent"); - new SetupItemLabel(_("Small memory (enable for lower memory usage)"), "", this); + new SetupItemLabel(_("Small memory (enable for lower memory usage)"), + "", this); new SetupItemCheckBox(_("Disable advanced beings caching (Software)"), "", "disableAdvBeingCaching", this, "disableAdvBeingCachingEvent"); -- cgit v1.2.3-70-g09d2 From c103e91ff6de05dbfce097dea7b516dbabd8e634 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 10 Aug 2011 00:03:52 +0300 Subject: Rename setup_players to setup_relations. --- manaplus.cbp | 4 +- src/CMakeLists.txt | 4 +- src/Makefile.am | 4 +- src/gui/setup.cpp | 4 +- src/gui/setup_players.cpp | 581 -------------------------------------------- src/gui/setup_players.h | 112 --------- src/gui/setup_relations.cpp | 581 ++++++++++++++++++++++++++++++++++++++++++++ src/gui/setup_relations.h | 112 +++++++++ 8 files changed, 701 insertions(+), 701 deletions(-) delete mode 100644 src/gui/setup_players.cpp delete mode 100644 src/gui/setup_players.h create mode 100644 src/gui/setup_relations.cpp create mode 100644 src/gui/setup_relations.h (limited to 'src') diff --git a/manaplus.cbp b/manaplus.cbp index 538555c7b..8c4028aaf 100644 --- a/manaplus.cbp +++ b/manaplus.cbp @@ -236,8 +236,8 @@ - - + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ff9c75770..2e05d5c69 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -317,8 +317,8 @@ SET(SRCS gui/setup_keyboard.h gui/setup_perfomance.cpp gui/setup_perfomance.h - gui/setup_players.cpp - gui/setup_players.h + gui/setup_relations.cpp + gui/setup_relations.h gui/setup_video.cpp gui/setup_video.h gui/sdlfont.cpp diff --git a/src/Makefile.am b/src/Makefile.am index ba04b5f2b..3871825e0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -320,8 +320,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ gui/setup_keyboard.h \ gui/setup_perfomance.cpp \ gui/setup_perfomance.h \ - gui/setup_players.cpp \ - gui/setup_players.h \ + gui/setup_relations.cpp \ + gui/setup_relations.h \ gui/setup_video.cpp \ gui/setup_video.h \ gui/sdlfont.cpp \ diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 129914ad8..e45bbb571 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -34,7 +34,7 @@ #include "gui/setup_theme.h" #include "gui/setup_keyboard.h" #include "gui/setup_perfomance.h" -#include "gui/setup_players.h" +#include "gui/setup_relations.h" #include "gui/setup_video.h" #include "gui/widgets/button.h" @@ -94,7 +94,7 @@ Setup::Setup(): mTabs.push_back(new Setup_Keyboard); mTabs.push_back(new Setup_Colors); mTabs.push_back(new Setup_Chat); - mTabs.push_back(new Setup_Players); + mTabs.push_back(new Setup_Relations); mTabs.push_back(new Setup_Theme); mTabs.push_back(new Setup_Other); diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp deleted file mode 100644 index 67ec053ea..000000000 --- a/src/gui/setup_players.cpp +++ /dev/null @@ -1,581 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2008-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 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 . - */ - -#include "gui/setup_players.h" - -#include "actorspritemanager.h" -#include "configuration.h" -#include "localplayer.h" -#include "log.h" - -#include "gui/editdialog.h" -#include "gui/okdialog.h" - -#include "gui/widgets/button.h" -#include "gui/widgets/checkbox.h" -#include "gui/widgets/dropdown.h" -#include "gui/widgets/label.h" -#include "gui/widgets/layouthelper.h" -#include "gui/widgets/scrollarea.h" -#include "gui/widgets/table.h" -#include "gui/widgets/textfield.h" - -#include "utils/dtor.h" -#include "utils/gettext.h" - -#include -#include - -#define COLUMNS_NR 2 // name plus listbox -#define NAME_COLUMN 0 -#define RELATION_CHOICE_COLUMN 1 - -#define ROW_HEIGHT 12 -// The following column widths really shouldn't be hardcoded but should scale with the size of the widget... except -// that, right now, the widget doesn't exactly scale either. -#define NAME_COLUMN_WIDTH 230 -#define RELATION_CHOICE_COLUMN_WIDTH 80 - -#define WIDGET_AT(row, column) (((row) * COLUMNS_NR) + column) - -#include "debug.h" - -static const char *table_titles[COLUMNS_NR] = -{ - N_("Name"), - N_("Relation") -}; - -static const char *RELATION_NAMES[PlayerRelation::RELATIONS_NR] = -{ - N_("Neutral"), - N_("Friend"), - N_("Disregarded"), - N_("Ignored"), - N_("Erased") -}; - -class PlayerRelationListModel : public gcn::ListModel -{ -public: - virtual ~PlayerRelationListModel() { } - - virtual int getNumberOfElements() - { - return PlayerRelation::RELATIONS_NR; - } - - virtual std::string getElementAt(int i) - { - if (i >= getNumberOfElements() || i < 0) - return ""; - return gettext(RELATION_NAMES[i]); - } -}; - -class PlayerTableModel : public TableModel -{ -public: - PlayerTableModel() : - mPlayers(NULL), - mListModel(new PlayerRelationListModel) - { - playerRelationsUpdated(); - } - - virtual ~PlayerTableModel() - { - freeWidgets(); - delete mListModel; - mListModel = 0; - delete mPlayers; - mPlayers = 0; - } - - virtual int getRows() const - { - if (mPlayers) - return static_cast(mPlayers->size()); - else - return 0; - } - - virtual int getColumns() const - { - return COLUMNS_NR; - } - - virtual int getRowHeight() const - { - return ROW_HEIGHT; - } - - virtual int getColumnWidth(int index) const - { - if (index == NAME_COLUMN) - return NAME_COLUMN_WIDTH; - else - return RELATION_CHOICE_COLUMN_WIDTH; - } - - virtual void playerRelationsUpdated() - { - signalBeforeUpdate(); - - freeWidgets(); - std::vector *player_names = player_relations.getPlayers(); - - if (!player_names) - return; - - delete mPlayers; - mPlayers = player_names; - - // set up widgets - for (unsigned int r = 0; r < player_names->size(); ++r) - { - std::string name = (*player_names)[r]; - gcn::Widget *widget = new Label(name); - mWidgets.push_back(widget); - - gcn::DropDown *choicebox = new DropDown(mListModel); - choicebox->setSelected(player_relations.getRelation(name)); - mWidgets.push_back(choicebox); - } - - signalAfterUpdate(); - } - - virtual void updateModelInRow(int row) - { - gcn::DropDown *choicebox = static_cast( - getElementAt(row, RELATION_CHOICE_COLUMN)); - player_relations.setRelation(getPlayerAt(row), - static_cast( - choicebox->getSelected())); - } - - - virtual gcn::Widget *getElementAt(int row, int column) const - { - return mWidgets[WIDGET_AT(row, column)]; - } - - virtual void freeWidgets() - { - delete mPlayers; - mPlayers = 0; - - delete_all(mWidgets); - mWidgets.clear(); - } - - std::string getPlayerAt(int index) const - { - return (*mPlayers)[index]; - } - -protected: - std::vector *mPlayers; - std::vector mWidgets; - PlayerRelationListModel *mListModel; -}; - -/** - * Class for choosing one of the various `what to do when ignoring a player' options - */ -class IgnoreChoicesListModel : public gcn::ListModel -{ -public: - virtual ~IgnoreChoicesListModel() { } - - virtual int getNumberOfElements() - { - return static_cast(player_relations.getPlayerIgnoreStrategies() - ->size()); - } - - virtual std::string getElementAt(int i) - { - if (i >= getNumberOfElements() || i < 0) - return _("???"); - - return (*player_relations.getPlayerIgnoreStrategies()) - [i]->mDescription; - } -}; - -#define ACTION_DELETE "delete" -#define ACTION_OLD "old" -#define ACTION_TABLE "table" -#define ACTION_STRATEGY "strategy" -#define ACTION_WHISPER_TAB "whisper tab" -#define ACTION_SHOW_GENDER "show gender" -#define ACTION_SHOW_LEVEL "show level" -#define ACTION_TARGET_DEAD "target dead" -#define ACTION_SHOW_OWN_NAME "show own name" -#define ACTION_SECURE_TRADES "secure trades" -#define ACTION_UNSECURE "unsecure" -#define ACTION_EDIT_UNSECURE "edit unsecure" -#define ACTION_EDIT_UNSECURE_OK "edit unsecure ok" - -Setup_Players::Setup_Players(): - mPlayerTableTitleModel(new StaticTableModel(1, COLUMNS_NR)), - mPlayerTableModel(new PlayerTableModel), - mPlayerTable(new GuiTable(mPlayerTableModel)), - mPlayerTitleTable(new GuiTable(mPlayerTableTitleModel)), - mPlayerScrollArea(new ScrollArea(mPlayerTable)), - mDefaultTrading(new CheckBox(_("Allow trading"), - player_relations.getDefault() & PlayerRelation::TRADE)), - mDefaultWhisper(new CheckBox(_("Allow whispers"), - player_relations.getDefault() & PlayerRelation::WHISPER)), - mDeleteButton(new Button(_("Delete"), ACTION_DELETE, this)), - mOldButton(new Button(_("Old"), ACTION_OLD, this)), - mWhisperTab(config.getBoolValue("whispertab")), - mWhisperTabCheckBox(new CheckBox(_("Put all whispers in tabs"), - mWhisperTab)), - mShowGender(config.getBoolValue("showgender")), - mShowGenderCheckBox(new CheckBox(_("Show gender"), mShowGender)), - mShowLevel(config.getBoolValue("showlevel")), - mShowOwnName(config.getBoolValue("showownname")), - mTargetDead(config.getBoolValue("targetDeadPlayers")), - mSecureTrades(config.getBoolValue("securetrades")), - mUnsecureChars(config.getStringValue("unsecureChars")), - mVisibleNamesEnabled(config.getBoolValue("visiblenames")), - mShowPlayersStatus(config.getBoolValue("showPlayersStatus")), - mEditDialog(0) -{ - setName(_("Players")); - - mPlayerTable->setOpaque(false); - - mPlayerTableTitleModel->fixColumnWidth(NAME_COLUMN, NAME_COLUMN_WIDTH); - mPlayerTableTitleModel->fixColumnWidth(RELATION_CHOICE_COLUMN, - RELATION_CHOICE_COLUMN_WIDTH); - mPlayerTitleTable->setBackgroundColor(gcn::Color(0xbf, 0xbf, 0xbf)); - - mIgnoreActionChoicesModel = new IgnoreChoicesListModel; - mIgnoreActionChoicesBox = new DropDown(mIgnoreActionChoicesModel); - - for (int i = 0; i < COLUMNS_NR; i++) - { - mPlayerTableTitleModel->set(0, i, - new Label(gettext(table_titles[i]))); - } - - mPlayerTitleTable->setLinewiseSelection(true); - - mPlayerScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); - mPlayerTable->setActionEventId(ACTION_TABLE); - mPlayerTable->setLinewiseSelection(true); - mPlayerTable->addActionListener(this); - - gcn::Label *ignore_action_label = new Label(_("When ignoring:")); - - mIgnoreActionChoicesBox->setActionEventId(ACTION_STRATEGY); - mIgnoreActionChoicesBox->addActionListener(this); - - int ignore_strategy_index = 0; // safe default - - if (player_relations.getPlayerIgnoreStrategy()) - { - ignore_strategy_index = player_relations.getPlayerIgnoreStrategyIndex( - player_relations.getPlayerIgnoreStrategy()->mShortName); - if (ignore_strategy_index < 0) - ignore_strategy_index = 0; - } - mIgnoreActionChoicesBox->setSelected(ignore_strategy_index); - mIgnoreActionChoicesBox->adjustHeight(); - - mWhisperTabCheckBox->setActionEventId(ACTION_WHISPER_TAB); - mWhisperTabCheckBox->addActionListener(this); - - mShowGenderCheckBox->setActionEventId(ACTION_SHOW_GENDER); - mShowGenderCheckBox->addActionListener(this); - - mShowLevelCheckBox = new CheckBox(_("Show level"), mShowLevel); - mShowLevelCheckBox->setActionEventId(ACTION_SHOW_LEVEL); - mShowLevelCheckBox->addActionListener(this); - - mShowOwnNameCheckBox = new CheckBox(_("Show own name"), mShowOwnName); - mShowOwnNameCheckBox->setActionEventId(ACTION_SHOW_OWN_NAME); - mShowOwnNameCheckBox->addActionListener(this); - - mTargetDeadCheckBox = new CheckBox(_("Target dead players"), mTargetDead); - mTargetDeadCheckBox->setActionEventId(ACTION_TARGET_DEAD); - mTargetDeadCheckBox->addActionListener(this); - - mSecureTradesCheckBox = new CheckBox(_("Secure trades"), mSecureTrades); - mSecureTradesCheckBox->setActionEventId(ACTION_SECURE_TRADES); - mSecureTradesCheckBox->addActionListener(this); - - mUnsecureCharsLabel = new Label(_("Unsecure chars in names")); - mUnsecureCharsField = new TextField(mUnsecureChars, - true, this, ACTION_UNSECURE); - mUnsecureCharsButton = new Button(_("Edit"), ACTION_EDIT_UNSECURE, this); - - mVisibleNamesCheckBox = new CheckBox(_("Visible names"), - mVisibleNamesEnabled); - mVisibleNamesCheckBox->setActionEventId("visiblenames"); - mVisibleNamesCheckBox->addActionListener(this); - - mShowPlayersStatusCheckBox = new CheckBox(_("Show statuses"), - mShowPlayersStatus); - mShowPlayersStatusCheckBox->setActionEventId("showPlayersStatus"); - mShowPlayersStatusCheckBox->addActionListener(this); - - reset(); - - // Do the layout - LayoutHelper h(this); - ContainerPlacer place = h.getPlacer(0, 0); - - place(0, 0, mPlayerTitleTable, 6); - place(0, 1, mPlayerScrollArea, 6, 4).setPadding(2); - place(0, 5, mDeleteButton); - place(0, 6, mShowGenderCheckBox, 3).setPadding(2); - place(0, 7, mShowLevelCheckBox, 3).setPadding(2); - place(0, 8, mShowOwnNameCheckBox, 3).setPadding(2); - place(1, 5, mOldButton, 1); - place(3, 5, ignore_action_label, 1); - place(4, 5, mIgnoreActionChoicesBox, 2).setPadding(2); - place(3, 6, mDefaultTrading, 3); - place(3, 7, mDefaultWhisper, 3); - place(3, 8, mSecureTradesCheckBox, 3); - place(3, 9, mUnsecureCharsLabel, 3); - place(3, 10, mUnsecureCharsField, 2); - place(3, 11, mShowPlayersStatusCheckBox, 2); - place(5, 10, mUnsecureCharsButton, 1); - place(0, 9, mWhisperTabCheckBox, 3).setPadding(4); - place(0, 10, mTargetDeadCheckBox, 3).setPadding(4); - place(0, 11, mVisibleNamesCheckBox, 3).setPadding(4); - - player_relations.addListener(this); - - setDimension(gcn::Rectangle(0, 0, 500, 350)); -} - -Setup_Players::~Setup_Players() -{ - player_relations.removeListener(this); - delete mIgnoreActionChoicesModel; - mIgnoreActionChoicesModel = 0; -} - - -void Setup_Players::reset() -{ - // We now have to search through the list of ignore choices to find the - // current selection. We could use an index into the table of config - // options in player_relations instead of strategies to sidestep this. - int selection = 0; - for (unsigned int i = 0; - i < player_relations.getPlayerIgnoreStrategies()->size(); - ++i) - if ((*player_relations.getPlayerIgnoreStrategies())[i] == - player_relations.getPlayerIgnoreStrategy()) - { - - selection = i; - break; - } - - mIgnoreActionChoicesBox->setSelected(selection); -} - -void Setup_Players::apply() -{ - player_relations.store(); - - unsigned int old_default_relations = player_relations.getDefault() & - ~(PlayerRelation::TRADE | - PlayerRelation::WHISPER); - player_relations.setDefault(old_default_relations - | (mDefaultTrading->isSelected() ? - PlayerRelation::TRADE : 0) - | (mDefaultWhisper->isSelected() ? - PlayerRelation::WHISPER : 0)); - config.setValue("whispertab", mWhisperTab); - config.setValue("showlevel", mShowLevel); - config.setValue("showownname", mShowOwnName); - config.setValue("targetDeadPlayers", mTargetDead); - config.setValue("showgender", mShowGender); - config.setValue("securetrades", mSecureTrades); - config.setValue("unsecureChars", mUnsecureCharsField->getText()); - config.setValue("visiblenames", mVisibleNamesEnabled); - config.setValue("showPlayersStatus", mShowPlayersStatus); - - if (actorSpriteManager) - actorSpriteManager->updatePlayerNames(); - - if (player_node) - player_node->setCheckNameSetting(true); -} - -void Setup_Players::cancel() -{ - mWhisperTab = config.getBoolValue("whispertab"); - mWhisperTabCheckBox->setSelected(mWhisperTab); - mShowGender = config.getBoolValue("showgender"); - mShowGenderCheckBox->setSelected(mShowGender); - mShowLevel = config.getBoolValue("showlevel"); - mShowLevelCheckBox->setSelected(mShowLevel); - mShowOwnName = config.getBoolValue("showownname"); - mShowOwnNameCheckBox->setSelected(mShowOwnName); - mTargetDead = config.getBoolValue("targetDeadPlayers"); - mTargetDeadCheckBox->setSelected(mTargetDead); - mSecureTrades = config.getBoolValue("securetrades"); - mSecureTradesCheckBox->setSelected(mSecureTrades); - mUnsecureChars = config.getStringValue("unsecureChars"); - mUnsecureCharsField->setText(mUnsecureChars); - mVisibleNamesEnabled = config.getBoolValue("visiblenames"); - mVisibleNamesCheckBox->setSelected(mVisibleNamesEnabled); - mShowPlayersStatus = config.getBoolValue("showPlayersStatus"); - mShowPlayersStatusCheckBox->setSelected(mShowPlayersStatus); -} - -void Setup_Players::action(const gcn::ActionEvent &event) -{ - if (event.getId() == ACTION_TABLE) - { - // temporarily eliminate ourselves: we are fully aware of this change, - // so there is no need for asynchronous updates. (In fact, thouse - // might destroy the widet that triggered them, which would be rather - // embarrassing.) - player_relations.removeListener(this); - - int row = mPlayerTable->getSelectedRow(); - if (row >= 0) - mPlayerTableModel->updateModelInRow(row); - - player_relations.addListener(this); - - } - else if (event.getId() == ACTION_DELETE) - { - int player_index = mPlayerTable->getSelectedRow(); - - if (player_index < 0) - return; - - std::string name = mPlayerTableModel->getPlayerAt(player_index); - - player_relations.removePlayer(name); - } - else if (event.getId() == ACTION_OLD) - { - player_relations.load(true); - updateAll(); - } - else if (event.getId() == ACTION_STRATEGY) - { - PlayerIgnoreStrategy *s = - (*player_relations.getPlayerIgnoreStrategies())[ - mIgnoreActionChoicesBox->getSelected()]; - - player_relations.setPlayerIgnoreStrategy(s); - } - else if (event.getId() == ACTION_WHISPER_TAB) - { - mWhisperTab = mWhisperTabCheckBox->isSelected(); - } - else if (event.getId() == ACTION_SHOW_GENDER) - { - mShowGender = mShowGenderCheckBox->isSelected(); - } - else if (event.getId() == ACTION_SHOW_LEVEL) - { - mShowLevel = mShowLevelCheckBox->isSelected(); - } - else if (event.getId() == ACTION_SHOW_OWN_NAME) - { - mShowOwnName = mShowOwnNameCheckBox->isSelected(); - } - else if (event.getId() == ACTION_TARGET_DEAD) - { - mTargetDead = mTargetDeadCheckBox->isSelected(); - } - else if (event.getId() == ACTION_SECURE_TRADES) - { - mSecureTrades = mSecureTradesCheckBox->isSelected(); - } - else if (event.getId() == ACTION_EDIT_UNSECURE) - { - mEditDialog = new EditDialog(_("Unsecure chars in names"), - mUnsecureCharsField->getText(), ACTION_EDIT_UNSECURE_OK); - mEditDialog->addActionListener(this); - } - else if (event.getId() == ACTION_EDIT_UNSECURE_OK) - { - mUnsecureCharsField->setText(mEditDialog->getMsg()); - } - else if (event.getId() == ACTION_UNSECURE) - { - mUnsecureChars = mUnsecureCharsField->getText(); - } - else if (event.getId() == "visiblenames") - { - mVisibleNamesEnabled = mVisibleNamesCheckBox->isSelected(); - } - else if (event.getId() == "showPlayersStatus") - { - mShowPlayersStatus = mShowPlayersStatusCheckBox->isSelected(); - } -} - -void Setup_Players::updatedPlayer(const std::string &name A_UNUSED) -{ - mPlayerTableModel->playerRelationsUpdated(); - mDefaultTrading->setSelected( - player_relations.getDefault() & PlayerRelation::TRADE); - mDefaultWhisper->setSelected( - player_relations.getDefault() & PlayerRelation::WHISPER); - if (player_node) - player_node->updateName(); -} - -void Setup_Players::updateAll() -{ - PlayerTableModel *model = new PlayerTableModel(); - mPlayerTable->setModel(model); - delete mPlayerTableModel; - mPlayerTableModel = model; - int ignore_strategy_index = 0; // safe default - - if (player_relations.getPlayerIgnoreStrategy()) - { - ignore_strategy_index = player_relations.getPlayerIgnoreStrategyIndex( - player_relations.getPlayerIgnoreStrategy()->mShortName); - if (ignore_strategy_index < 0) - ignore_strategy_index = 0; - } - mIgnoreActionChoicesBox->setSelected(ignore_strategy_index); - mIgnoreActionChoicesBox->adjustHeight(); - reset(); -} -void Setup_Players::externalUpdated() -{ - mDefaultTrading->setSelected( - player_relations.getDefault() & PlayerRelation::TRADE); - mDefaultWhisper->setSelected( - player_relations.getDefault() & PlayerRelation::WHISPER); -} \ No newline at end of file diff --git a/src/gui/setup_players.h b/src/gui/setup_players.h deleted file mode 100644 index 9f35d1600..000000000 --- a/src/gui/setup_players.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2008-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 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 . - */ - -#ifndef GUI_SETUP_PLAYERS_H -#define GUI_SETUP_PLAYERS_H - -#include "guichanfwd.h" -#include "playerrelations.h" - -#include "gui/widgets/setuptab.h" - -#include - -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - -class EditDialog; -class GuiTable; -class PlayerTableModel; -class StaticTableModel; - -class Setup_Players : public SetupTab, - public PlayerRelationsListener -{ -public: - Setup_Players(); - virtual ~Setup_Players(); - - void apply(); - void cancel(); - - void reset(); - - void action(const gcn::ActionEvent &event); - - virtual void updatedPlayer(const std::string &name); - - virtual void updateAll(); - - virtual void externalUpdated(); - -private: - StaticTableModel *mPlayerTableTitleModel; - PlayerTableModel *mPlayerTableModel; - GuiTable *mPlayerTable; - GuiTable *mPlayerTitleTable; - gcn::ScrollArea *mPlayerScrollArea; - - gcn::CheckBox *mDefaultTrading; - gcn::CheckBox *mDefaultWhisper; - - gcn::Button *mDeleteButton; - gcn::Button *mOldButton; - - gcn::ListModel *mIgnoreActionChoicesModel; - gcn::DropDown *mIgnoreActionChoicesBox; - - bool mWhisperTab; - gcn::CheckBox *mWhisperTabCheckBox; - - bool mShowGender; - gcn::CheckBox *mShowGenderCheckBox; - - bool mShowLevel; - gcn::CheckBox *mShowLevelCheckBox; - - bool mShowOwnName; - gcn::CheckBox *mShowOwnNameCheckBox; - - bool mTargetDead; - gcn::CheckBox *mTargetDeadCheckBox; - - bool mSecureTrades; - gcn::CheckBox *mSecureTradesCheckBox; - - gcn::Label *mUnsecureCharsLabel; - gcn::TextField *mUnsecureCharsField; - gcn::Button *mUnsecureCharsButton; - std::string mUnsecureChars; - - bool mVisibleNamesEnabled; - gcn::CheckBox *mVisibleNamesCheckBox; - - bool mShowPlayersStatus; - gcn::CheckBox *mShowPlayersStatusCheckBox; - - EditDialog *mEditDialog; -}; - -#endif diff --git a/src/gui/setup_relations.cpp b/src/gui/setup_relations.cpp new file mode 100644 index 000000000..04bfa2343 --- /dev/null +++ b/src/gui/setup_relations.cpp @@ -0,0 +1,581 @@ +/* + * The ManaPlus Client + * Copyright (C) 2008-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 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 . + */ + +#include "gui/setup_relations.h" + +#include "actorspritemanager.h" +#include "configuration.h" +#include "localplayer.h" +#include "log.h" + +#include "gui/editdialog.h" +#include "gui/okdialog.h" + +#include "gui/widgets/button.h" +#include "gui/widgets/checkbox.h" +#include "gui/widgets/dropdown.h" +#include "gui/widgets/label.h" +#include "gui/widgets/layouthelper.h" +#include "gui/widgets/scrollarea.h" +#include "gui/widgets/table.h" +#include "gui/widgets/textfield.h" + +#include "utils/dtor.h" +#include "utils/gettext.h" + +#include +#include + +#define COLUMNS_NR 2 // name plus listbox +#define NAME_COLUMN 0 +#define RELATION_CHOICE_COLUMN 1 + +#define ROW_HEIGHT 12 +// The following column widths really shouldn't be hardcoded but should scale with the size of the widget... except +// that, right now, the widget doesn't exactly scale either. +#define NAME_COLUMN_WIDTH 230 +#define RELATION_CHOICE_COLUMN_WIDTH 80 + +#define WIDGET_AT(row, column) (((row) * COLUMNS_NR) + column) + +#include "debug.h" + +static const char *table_titles[COLUMNS_NR] = +{ + N_("Name"), + N_("Relation") +}; + +static const char *RELATION_NAMES[PlayerRelation::RELATIONS_NR] = +{ + N_("Neutral"), + N_("Friend"), + N_("Disregarded"), + N_("Ignored"), + N_("Erased") +}; + +class PlayerRelationListModel : public gcn::ListModel +{ +public: + virtual ~PlayerRelationListModel() { } + + virtual int getNumberOfElements() + { + return PlayerRelation::RELATIONS_NR; + } + + virtual std::string getElementAt(int i) + { + if (i >= getNumberOfElements() || i < 0) + return ""; + return gettext(RELATION_NAMES[i]); + } +}; + +class PlayerTableModel : public TableModel +{ +public: + PlayerTableModel() : + mPlayers(NULL), + mListModel(new PlayerRelationListModel) + { + playerRelationsUpdated(); + } + + virtual ~PlayerTableModel() + { + freeWidgets(); + delete mListModel; + mListModel = 0; + delete mPlayers; + mPlayers = 0; + } + + virtual int getRows() const + { + if (mPlayers) + return static_cast(mPlayers->size()); + else + return 0; + } + + virtual int getColumns() const + { + return COLUMNS_NR; + } + + virtual int getRowHeight() const + { + return ROW_HEIGHT; + } + + virtual int getColumnWidth(int index) const + { + if (index == NAME_COLUMN) + return NAME_COLUMN_WIDTH; + else + return RELATION_CHOICE_COLUMN_WIDTH; + } + + virtual void playerRelationsUpdated() + { + signalBeforeUpdate(); + + freeWidgets(); + std::vector *player_names = player_relations.getPlayers(); + + if (!player_names) + return; + + delete mPlayers; + mPlayers = player_names; + + // set up widgets + for (unsigned int r = 0; r < player_names->size(); ++r) + { + std::string name = (*player_names)[r]; + gcn::Widget *widget = new Label(name); + mWidgets.push_back(widget); + + gcn::DropDown *choicebox = new DropDown(mListModel); + choicebox->setSelected(player_relations.getRelation(name)); + mWidgets.push_back(choicebox); + } + + signalAfterUpdate(); + } + + virtual void updateModelInRow(int row) + { + gcn::DropDown *choicebox = static_cast( + getElementAt(row, RELATION_CHOICE_COLUMN)); + player_relations.setRelation(getPlayerAt(row), + static_cast( + choicebox->getSelected())); + } + + + virtual gcn::Widget *getElementAt(int row, int column) const + { + return mWidgets[WIDGET_AT(row, column)]; + } + + virtual void freeWidgets() + { + delete mPlayers; + mPlayers = 0; + + delete_all(mWidgets); + mWidgets.clear(); + } + + std::string getPlayerAt(int index) const + { + return (*mPlayers)[index]; + } + +protected: + std::vector *mPlayers; + std::vector mWidgets; + PlayerRelationListModel *mListModel; +}; + +/** + * Class for choosing one of the various `what to do when ignoring a player' options + */ +class IgnoreChoicesListModel : public gcn::ListModel +{ +public: + virtual ~IgnoreChoicesListModel() { } + + virtual int getNumberOfElements() + { + return static_cast(player_relations.getPlayerIgnoreStrategies() + ->size()); + } + + virtual std::string getElementAt(int i) + { + if (i >= getNumberOfElements() || i < 0) + return _("???"); + + return (*player_relations.getPlayerIgnoreStrategies()) + [i]->mDescription; + } +}; + +#define ACTION_DELETE "delete" +#define ACTION_OLD "old" +#define ACTION_TABLE "table" +#define ACTION_STRATEGY "strategy" +#define ACTION_WHISPER_TAB "whisper tab" +#define ACTION_SHOW_GENDER "show gender" +#define ACTION_SHOW_LEVEL "show level" +#define ACTION_TARGET_DEAD "target dead" +#define ACTION_SHOW_OWN_NAME "show own name" +#define ACTION_SECURE_TRADES "secure trades" +#define ACTION_UNSECURE "unsecure" +#define ACTION_EDIT_UNSECURE "edit unsecure" +#define ACTION_EDIT_UNSECURE_OK "edit unsecure ok" + +Setup_Relations::Setup_Relations(): + mPlayerTableTitleModel(new StaticTableModel(1, COLUMNS_NR)), + mPlayerTableModel(new PlayerTableModel), + mPlayerTable(new GuiTable(mPlayerTableModel)), + mPlayerTitleTable(new GuiTable(mPlayerTableTitleModel)), + mPlayerScrollArea(new ScrollArea(mPlayerTable)), + mDefaultTrading(new CheckBox(_("Allow trading"), + player_relations.getDefault() & PlayerRelation::TRADE)), + mDefaultWhisper(new CheckBox(_("Allow whispers"), + player_relations.getDefault() & PlayerRelation::WHISPER)), + mDeleteButton(new Button(_("Delete"), ACTION_DELETE, this)), + mOldButton(new Button(_("Old"), ACTION_OLD, this)), + mWhisperTab(config.getBoolValue("whispertab")), + mWhisperTabCheckBox(new CheckBox(_("Put all whispers in tabs"), + mWhisperTab)), + mShowGender(config.getBoolValue("showgender")), + mShowGenderCheckBox(new CheckBox(_("Show gender"), mShowGender)), + mShowLevel(config.getBoolValue("showlevel")), + mShowOwnName(config.getBoolValue("showownname")), + mTargetDead(config.getBoolValue("targetDeadPlayers")), + mSecureTrades(config.getBoolValue("securetrades")), + mUnsecureChars(config.getStringValue("unsecureChars")), + mVisibleNamesEnabled(config.getBoolValue("visiblenames")), + mShowPlayersStatus(config.getBoolValue("showPlayersStatus")), + mEditDialog(0) +{ + setName(_("Relations")); + + mPlayerTable->setOpaque(false); + + mPlayerTableTitleModel->fixColumnWidth(NAME_COLUMN, NAME_COLUMN_WIDTH); + mPlayerTableTitleModel->fixColumnWidth(RELATION_CHOICE_COLUMN, + RELATION_CHOICE_COLUMN_WIDTH); + mPlayerTitleTable->setBackgroundColor(gcn::Color(0xbf, 0xbf, 0xbf)); + + mIgnoreActionChoicesModel = new IgnoreChoicesListModel; + mIgnoreActionChoicesBox = new DropDown(mIgnoreActionChoicesModel); + + for (int i = 0; i < COLUMNS_NR; i++) + { + mPlayerTableTitleModel->set(0, i, + new Label(gettext(table_titles[i]))); + } + + mPlayerTitleTable->setLinewiseSelection(true); + + mPlayerScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + mPlayerTable->setActionEventId(ACTION_TABLE); + mPlayerTable->setLinewiseSelection(true); + mPlayerTable->addActionListener(this); + + gcn::Label *ignore_action_label = new Label(_("When ignoring:")); + + mIgnoreActionChoicesBox->setActionEventId(ACTION_STRATEGY); + mIgnoreActionChoicesBox->addActionListener(this); + + int ignore_strategy_index = 0; // safe default + + if (player_relations.getPlayerIgnoreStrategy()) + { + ignore_strategy_index = player_relations.getPlayerIgnoreStrategyIndex( + player_relations.getPlayerIgnoreStrategy()->mShortName); + if (ignore_strategy_index < 0) + ignore_strategy_index = 0; + } + mIgnoreActionChoicesBox->setSelected(ignore_strategy_index); + mIgnoreActionChoicesBox->adjustHeight(); + + mWhisperTabCheckBox->setActionEventId(ACTION_WHISPER_TAB); + mWhisperTabCheckBox->addActionListener(this); + + mShowGenderCheckBox->setActionEventId(ACTION_SHOW_GENDER); + mShowGenderCheckBox->addActionListener(this); + + mShowLevelCheckBox = new CheckBox(_("Show level"), mShowLevel); + mShowLevelCheckBox->setActionEventId(ACTION_SHOW_LEVEL); + mShowLevelCheckBox->addActionListener(this); + + mShowOwnNameCheckBox = new CheckBox(_("Show own name"), mShowOwnName); + mShowOwnNameCheckBox->setActionEventId(ACTION_SHOW_OWN_NAME); + mShowOwnNameCheckBox->addActionListener(this); + + mTargetDeadCheckBox = new CheckBox(_("Target dead players"), mTargetDead); + mTargetDeadCheckBox->setActionEventId(ACTION_TARGET_DEAD); + mTargetDeadCheckBox->addActionListener(this); + + mSecureTradesCheckBox = new CheckBox(_("Secure trades"), mSecureTrades); + mSecureTradesCheckBox->setActionEventId(ACTION_SECURE_TRADES); + mSecureTradesCheckBox->addActionListener(this); + + mUnsecureCharsLabel = new Label(_("Unsecure chars in names")); + mUnsecureCharsField = new TextField(mUnsecureChars, + true, this, ACTION_UNSECURE); + mUnsecureCharsButton = new Button(_("Edit"), ACTION_EDIT_UNSECURE, this); + + mVisibleNamesCheckBox = new CheckBox(_("Visible names"), + mVisibleNamesEnabled); + mVisibleNamesCheckBox->setActionEventId("visiblenames"); + mVisibleNamesCheckBox->addActionListener(this); + + mShowPlayersStatusCheckBox = new CheckBox(_("Show statuses"), + mShowPlayersStatus); + mShowPlayersStatusCheckBox->setActionEventId("showPlayersStatus"); + mShowPlayersStatusCheckBox->addActionListener(this); + + reset(); + + // Do the layout + LayoutHelper h(this); + ContainerPlacer place = h.getPlacer(0, 0); + + place(0, 0, mPlayerTitleTable, 6); + place(0, 1, mPlayerScrollArea, 6, 4).setPadding(2); + place(0, 5, mDeleteButton); + place(0, 6, mShowGenderCheckBox, 3).setPadding(2); + place(0, 7, mShowLevelCheckBox, 3).setPadding(2); + place(0, 8, mShowOwnNameCheckBox, 3).setPadding(2); + place(1, 5, mOldButton, 1); + place(3, 5, ignore_action_label, 1); + place(4, 5, mIgnoreActionChoicesBox, 2).setPadding(2); + place(3, 6, mDefaultTrading, 3); + place(3, 7, mDefaultWhisper, 3); + place(3, 8, mSecureTradesCheckBox, 3); + place(3, 9, mUnsecureCharsLabel, 3); + place(3, 10, mUnsecureCharsField, 2); + place(3, 11, mShowPlayersStatusCheckBox, 2); + place(5, 10, mUnsecureCharsButton, 1); + place(0, 9, mWhisperTabCheckBox, 3).setPadding(4); + place(0, 10, mTargetDeadCheckBox, 3).setPadding(4); + place(0, 11, mVisibleNamesCheckBox, 3).setPadding(4); + + player_relations.addListener(this); + + setDimension(gcn::Rectangle(0, 0, 500, 350)); +} + +Setup_Relations::~Setup_Relations() +{ + player_relations.removeListener(this); + delete mIgnoreActionChoicesModel; + mIgnoreActionChoicesModel = 0; +} + + +void Setup_Relations::reset() +{ + // We now have to search through the list of ignore choices to find the + // current selection. We could use an index into the table of config + // options in player_relations instead of strategies to sidestep this. + int selection = 0; + for (unsigned int i = 0; + i < player_relations.getPlayerIgnoreStrategies()->size(); + ++i) + if ((*player_relations.getPlayerIgnoreStrategies())[i] == + player_relations.getPlayerIgnoreStrategy()) + { + + selection = i; + break; + } + + mIgnoreActionChoicesBox->setSelected(selection); +} + +void Setup_Relations::apply() +{ + player_relations.store(); + + unsigned int old_default_relations = player_relations.getDefault() & + ~(PlayerRelation::TRADE | + PlayerRelation::WHISPER); + player_relations.setDefault(old_default_relations + | (mDefaultTrading->isSelected() ? + PlayerRelation::TRADE : 0) + | (mDefaultWhisper->isSelected() ? + PlayerRelation::WHISPER : 0)); + config.setValue("whispertab", mWhisperTab); + config.setValue("showlevel", mShowLevel); + config.setValue("showownname", mShowOwnName); + config.setValue("targetDeadPlayers", mTargetDead); + config.setValue("showgender", mShowGender); + config.setValue("securetrades", mSecureTrades); + config.setValue("unsecureChars", mUnsecureCharsField->getText()); + config.setValue("visiblenames", mVisibleNamesEnabled); + config.setValue("showPlayersStatus", mShowPlayersStatus); + + if (actorSpriteManager) + actorSpriteManager->updatePlayerNames(); + + if (player_node) + player_node->setCheckNameSetting(true); +} + +void Setup_Relations::cancel() +{ + mWhisperTab = config.getBoolValue("whispertab"); + mWhisperTabCheckBox->setSelected(mWhisperTab); + mShowGender = config.getBoolValue("showgender"); + mShowGenderCheckBox->setSelected(mShowGender); + mShowLevel = config.getBoolValue("showlevel"); + mShowLevelCheckBox->setSelected(mShowLevel); + mShowOwnName = config.getBoolValue("showownname"); + mShowOwnNameCheckBox->setSelected(mShowOwnName); + mTargetDead = config.getBoolValue("targetDeadPlayers"); + mTargetDeadCheckBox->setSelected(mTargetDead); + mSecureTrades = config.getBoolValue("securetrades"); + mSecureTradesCheckBox->setSelected(mSecureTrades); + mUnsecureChars = config.getStringValue("unsecureChars"); + mUnsecureCharsField->setText(mUnsecureChars); + mVisibleNamesEnabled = config.getBoolValue("visiblenames"); + mVisibleNamesCheckBox->setSelected(mVisibleNamesEnabled); + mShowPlayersStatus = config.getBoolValue("showPlayersStatus"); + mShowPlayersStatusCheckBox->setSelected(mShowPlayersStatus); +} + +void Setup_Relations::action(const gcn::ActionEvent &event) +{ + if (event.getId() == ACTION_TABLE) + { + // temporarily eliminate ourselves: we are fully aware of this change, + // so there is no need for asynchronous updates. (In fact, thouse + // might destroy the widet that triggered them, which would be rather + // embarrassing.) + player_relations.removeListener(this); + + int row = mPlayerTable->getSelectedRow(); + if (row >= 0) + mPlayerTableModel->updateModelInRow(row); + + player_relations.addListener(this); + + } + else if (event.getId() == ACTION_DELETE) + { + int player_index = mPlayerTable->getSelectedRow(); + + if (player_index < 0) + return; + + std::string name = mPlayerTableModel->getPlayerAt(player_index); + + player_relations.removePlayer(name); + } + else if (event.getId() == ACTION_OLD) + { + player_relations.load(true); + updateAll(); + } + else if (event.getId() == ACTION_STRATEGY) + { + PlayerIgnoreStrategy *s = + (*player_relations.getPlayerIgnoreStrategies())[ + mIgnoreActionChoicesBox->getSelected()]; + + player_relations.setPlayerIgnoreStrategy(s); + } + else if (event.getId() == ACTION_WHISPER_TAB) + { + mWhisperTab = mWhisperTabCheckBox->isSelected(); + } + else if (event.getId() == ACTION_SHOW_GENDER) + { + mShowGender = mShowGenderCheckBox->isSelected(); + } + else if (event.getId() == ACTION_SHOW_LEVEL) + { + mShowLevel = mShowLevelCheckBox->isSelected(); + } + else if (event.getId() == ACTION_SHOW_OWN_NAME) + { + mShowOwnName = mShowOwnNameCheckBox->isSelected(); + } + else if (event.getId() == ACTION_TARGET_DEAD) + { + mTargetDead = mTargetDeadCheckBox->isSelected(); + } + else if (event.getId() == ACTION_SECURE_TRADES) + { + mSecureTrades = mSecureTradesCheckBox->isSelected(); + } + else if (event.getId() == ACTION_EDIT_UNSECURE) + { + mEditDialog = new EditDialog(_("Unsecure chars in names"), + mUnsecureCharsField->getText(), ACTION_EDIT_UNSECURE_OK); + mEditDialog->addActionListener(this); + } + else if (event.getId() == ACTION_EDIT_UNSECURE_OK) + { + mUnsecureCharsField->setText(mEditDialog->getMsg()); + } + else if (event.getId() == ACTION_UNSECURE) + { + mUnsecureChars = mUnsecureCharsField->getText(); + } + else if (event.getId() == "visiblenames") + { + mVisibleNamesEnabled = mVisibleNamesCheckBox->isSelected(); + } + else if (event.getId() == "showPlayersStatus") + { + mShowPlayersStatus = mShowPlayersStatusCheckBox->isSelected(); + } +} + +void Setup_Relations::updatedPlayer(const std::string &name A_UNUSED) +{ + mPlayerTableModel->playerRelationsUpdated(); + mDefaultTrading->setSelected( + player_relations.getDefault() & PlayerRelation::TRADE); + mDefaultWhisper->setSelected( + player_relations.getDefault() & PlayerRelation::WHISPER); + if (player_node) + player_node->updateName(); +} + +void Setup_Relations::updateAll() +{ + PlayerTableModel *model = new PlayerTableModel(); + mPlayerTable->setModel(model); + delete mPlayerTableModel; + mPlayerTableModel = model; + int ignore_strategy_index = 0; // safe default + + if (player_relations.getPlayerIgnoreStrategy()) + { + ignore_strategy_index = player_relations.getPlayerIgnoreStrategyIndex( + player_relations.getPlayerIgnoreStrategy()->mShortName); + if (ignore_strategy_index < 0) + ignore_strategy_index = 0; + } + mIgnoreActionChoicesBox->setSelected(ignore_strategy_index); + mIgnoreActionChoicesBox->adjustHeight(); + reset(); +} +void Setup_Relations::externalUpdated() +{ + mDefaultTrading->setSelected( + player_relations.getDefault() & PlayerRelation::TRADE); + mDefaultWhisper->setSelected( + player_relations.getDefault() & PlayerRelation::WHISPER); +} diff --git a/src/gui/setup_relations.h b/src/gui/setup_relations.h new file mode 100644 index 000000000..eab3c7661 --- /dev/null +++ b/src/gui/setup_relations.h @@ -0,0 +1,112 @@ +/* + * The ManaPlus Client + * Copyright (C) 2008-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 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 . + */ + +#ifndef GUI_SETUP_RELATIONS_H +#define GUI_SETUP_RELATIONS_H + +#include "guichanfwd.h" +#include "playerrelations.h" + +#include "gui/widgets/setuptab.h" + +#include + +#ifdef __GNUC__ +#define A_UNUSED __attribute__ ((unused)) +#else +#define A_UNUSED +#endif + +class EditDialog; +class GuiTable; +class PlayerTableModel; +class StaticTableModel; + +class Setup_Relations : public SetupTab, + public PlayerRelationsListener +{ +public: + Setup_Relations(); + virtual ~Setup_Relations(); + + void apply(); + void cancel(); + + void reset(); + + void action(const gcn::ActionEvent &event); + + virtual void updatedPlayer(const std::string &name); + + virtual void updateAll(); + + virtual void externalUpdated(); + +private: + StaticTableModel *mPlayerTableTitleModel; + PlayerTableModel *mPlayerTableModel; + GuiTable *mPlayerTable; + GuiTable *mPlayerTitleTable; + gcn::ScrollArea *mPlayerScrollArea; + + gcn::CheckBox *mDefaultTrading; + gcn::CheckBox *mDefaultWhisper; + + gcn::Button *mDeleteButton; + gcn::Button *mOldButton; + + gcn::ListModel *mIgnoreActionChoicesModel; + gcn::DropDown *mIgnoreActionChoicesBox; + + bool mWhisperTab; + gcn::CheckBox *mWhisperTabCheckBox; + + bool mShowGender; + gcn::CheckBox *mShowGenderCheckBox; + + bool mShowLevel; + gcn::CheckBox *mShowLevelCheckBox; + + bool mShowOwnName; + gcn::CheckBox *mShowOwnNameCheckBox; + + bool mTargetDead; + gcn::CheckBox *mTargetDeadCheckBox; + + bool mSecureTrades; + gcn::CheckBox *mSecureTradesCheckBox; + + gcn::Label *mUnsecureCharsLabel; + gcn::TextField *mUnsecureCharsField; + gcn::Button *mUnsecureCharsButton; + std::string mUnsecureChars; + + bool mVisibleNamesEnabled; + gcn::CheckBox *mVisibleNamesCheckBox; + + bool mShowPlayersStatus; + gcn::CheckBox *mShowPlayersStatusCheckBox; + + EditDialog *mEditDialog; +}; + +#endif -- cgit v1.2.3-70-g09d2 From 038355b1192fe2e6b00e29e1e20cbf9d535c99aa Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 10 Aug 2011 01:09:28 +0300 Subject: Add players setup tab. Move all player related settings from relation tab to players tab. --- manaplus.cbp | 2 + src/CMakeLists.txt | 2 + src/Makefile.am | 2 + src/gui/setup.cpp | 3 + src/gui/setup_chat.cpp | 3 + src/gui/setup_players.cpp | 84 ++++++++++++++++++++++++++ src/gui/setup_players.h | 44 ++++++++++++++ src/gui/setup_relations.cpp | 144 +------------------------------------------- src/gui/setup_relations.h | 31 ---------- 9 files changed, 141 insertions(+), 174 deletions(-) create mode 100644 src/gui/setup_players.cpp create mode 100644 src/gui/setup_players.h (limited to 'src') diff --git a/manaplus.cbp b/manaplus.cbp index 8c4028aaf..e31f4fee9 100644 --- a/manaplus.cbp +++ b/manaplus.cbp @@ -236,6 +236,8 @@ + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2e05d5c69..9a9d09f97 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -319,6 +319,8 @@ SET(SRCS gui/setup_perfomance.h gui/setup_relations.cpp gui/setup_relations.h + gui/setup_players.cpp + gui/setup_players.h gui/setup_video.cpp gui/setup_video.h gui/sdlfont.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 3871825e0..76010cb73 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -320,6 +320,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ gui/setup_keyboard.h \ gui/setup_perfomance.cpp \ gui/setup_perfomance.h \ + gui/setup_players.cpp \ + gui/setup_players.h \ gui/setup_relations.cpp \ gui/setup_relations.h \ gui/setup_video.cpp \ diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index e45bbb571..d73212d48 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -34,6 +34,7 @@ #include "gui/setup_theme.h" #include "gui/setup_keyboard.h" #include "gui/setup_perfomance.h" +#include "gui/setup_players.h" #include "gui/setup_relations.h" #include "gui/setup_video.h" @@ -86,6 +87,7 @@ Setup::Setup(): mPanel = new TabbedArea; mPanel->setDimension(gcn::Rectangle(5, 5, width - 10, height - 40)); + mPanel->enableScrollButtons(true); mTabs.push_back(new Setup_Video); mTabs.push_back(new Setup_Audio); @@ -94,6 +96,7 @@ Setup::Setup(): mTabs.push_back(new Setup_Keyboard); mTabs.push_back(new Setup_Colors); mTabs.push_back(new Setup_Chat); + mTabs.push_back(new Setup_Players); mTabs.push_back(new Setup_Relations); mTabs.push_back(new Setup_Theme); mTabs.push_back(new Setup_Other); diff --git a/src/gui/setup_chat.cpp b/src/gui/setup_chat.cpp index bdba4df7a..621f62810 100644 --- a/src/gui/setup_chat.cpp +++ b/src/gui/setup_chat.cpp @@ -93,6 +93,9 @@ Setup_Chat::Setup_Chat() new SetupItemLabel(_("Tabs"), "", this); + new SetupItemCheckBox(_("Put all whispers in tabs"), "", + "whispertab", this, "whispertabEvent"); + new SetupItemCheckBox(_("Log magic messages in debug tab"), "", "showMagicInDebug", this, "showMagicInDebugEvent"); diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp new file mode 100644 index 000000000..7490135cd --- /dev/null +++ b/src/gui/setup_players.cpp @@ -0,0 +1,84 @@ +/* + * The ManaPlus Client + * Copyright (C) 2009 The Mana World Development Team + * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "gui/setup_players.h" + +#include "gui/chatwindow.h" +#include "gui/editdialog.h" +#include "gui/setupitem.h" + +#include "gui/widgets/button.h" +#include "gui/widgets/chattab.h" +#include "gui/widgets/checkbox.h" +#include "gui/widgets/inttextfield.h" +#include "gui/widgets/label.h" +#include "gui/widgets/layouthelper.h" +#include "gui/widgets/scrollarea.h" + +#include "configuration.h" +#include "localplayer.h" +#include "log.h" + +#include "utils/gettext.h" + +#include "debug.h" + +Setup_Players::Setup_Players() +{ + setName(_("Players")); + + LayoutHelper h(this); + ContainerPlacer place = h.getPlacer(0, 0); + place(0, 0, mScroll, 10, 10); + + new SetupItemCheckBox(_("Show gender"), "", + "showgender", this, "showgenderEvent"); + + new SetupItemCheckBox(_("Show level"), "", + "showlevel", this, "showlevelEvent"); + + new SetupItemCheckBox(_("Show own name"), "", + "showownname", this, "showownnameEvent"); + + new SetupItemCheckBox(_("Target dead players"), "", + "targetDeadPlayers", this, "targetDeadPlayersEvent"); + + new SetupItemCheckBox(_("Visible names"), "", + "visiblenames", this, "visiblenamesEvent"); + + new SetupItemCheckBox(_("Secure trades"), "", + "securetrades", this, "securetradesEvent"); + + new SetupItemTextField(_("Unsecure chars in names"), "", + "unsecureChars", this, "unsecureCharsEvent"); + + new SetupItemCheckBox(_("Show statuses"), "", + "showPlayersStatus", this, "showPlayersStatusEvent"); + + setDimension(gcn::Rectangle(0, 0, 550, 350)); +} + +void Setup_Players::apply() +{ + SetupTabScroll::apply(); +} diff --git a/src/gui/setup_players.h b/src/gui/setup_players.h new file mode 100644 index 000000000..c9ce7b3b3 --- /dev/null +++ b/src/gui/setup_players.h @@ -0,0 +1,44 @@ +/* + * The ManaPlus Client + * Copyright (C) 2009 The Mana World Development Team + * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef GUI_SETUP_PLAYERS_H +#define GUI_SETUP_PLAYERS_H + +#include "guichanfwd.h" + +#include "gui/widgets/setuptabscroll.h" + +#include + +class IntTextField; +class EditDialog; + +class Setup_Players : public SetupTabScroll +{ + public: + Setup_Players(); + + void apply(); +}; + +#endif diff --git a/src/gui/setup_relations.cpp b/src/gui/setup_relations.cpp index 04bfa2343..646d47550 100644 --- a/src/gui/setup_relations.cpp +++ b/src/gui/setup_relations.cpp @@ -229,14 +229,6 @@ public: #define ACTION_TABLE "table" #define ACTION_STRATEGY "strategy" #define ACTION_WHISPER_TAB "whisper tab" -#define ACTION_SHOW_GENDER "show gender" -#define ACTION_SHOW_LEVEL "show level" -#define ACTION_TARGET_DEAD "target dead" -#define ACTION_SHOW_OWN_NAME "show own name" -#define ACTION_SECURE_TRADES "secure trades" -#define ACTION_UNSECURE "unsecure" -#define ACTION_EDIT_UNSECURE "edit unsecure" -#define ACTION_EDIT_UNSECURE_OK "edit unsecure ok" Setup_Relations::Setup_Relations(): mPlayerTableTitleModel(new StaticTableModel(1, COLUMNS_NR)), @@ -249,20 +241,7 @@ Setup_Relations::Setup_Relations(): mDefaultWhisper(new CheckBox(_("Allow whispers"), player_relations.getDefault() & PlayerRelation::WHISPER)), mDeleteButton(new Button(_("Delete"), ACTION_DELETE, this)), - mOldButton(new Button(_("Old"), ACTION_OLD, this)), - mWhisperTab(config.getBoolValue("whispertab")), - mWhisperTabCheckBox(new CheckBox(_("Put all whispers in tabs"), - mWhisperTab)), - mShowGender(config.getBoolValue("showgender")), - mShowGenderCheckBox(new CheckBox(_("Show gender"), mShowGender)), - mShowLevel(config.getBoolValue("showlevel")), - mShowOwnName(config.getBoolValue("showownname")), - mTargetDead(config.getBoolValue("targetDeadPlayers")), - mSecureTrades(config.getBoolValue("securetrades")), - mUnsecureChars(config.getStringValue("unsecureChars")), - mVisibleNamesEnabled(config.getBoolValue("visiblenames")), - mShowPlayersStatus(config.getBoolValue("showPlayersStatus")), - mEditDialog(0) + mOldButton(new Button(_("Old"), ACTION_OLD, this)) { setName(_("Relations")); @@ -306,43 +285,6 @@ Setup_Relations::Setup_Relations(): mIgnoreActionChoicesBox->setSelected(ignore_strategy_index); mIgnoreActionChoicesBox->adjustHeight(); - mWhisperTabCheckBox->setActionEventId(ACTION_WHISPER_TAB); - mWhisperTabCheckBox->addActionListener(this); - - mShowGenderCheckBox->setActionEventId(ACTION_SHOW_GENDER); - mShowGenderCheckBox->addActionListener(this); - - mShowLevelCheckBox = new CheckBox(_("Show level"), mShowLevel); - mShowLevelCheckBox->setActionEventId(ACTION_SHOW_LEVEL); - mShowLevelCheckBox->addActionListener(this); - - mShowOwnNameCheckBox = new CheckBox(_("Show own name"), mShowOwnName); - mShowOwnNameCheckBox->setActionEventId(ACTION_SHOW_OWN_NAME); - mShowOwnNameCheckBox->addActionListener(this); - - mTargetDeadCheckBox = new CheckBox(_("Target dead players"), mTargetDead); - mTargetDeadCheckBox->setActionEventId(ACTION_TARGET_DEAD); - mTargetDeadCheckBox->addActionListener(this); - - mSecureTradesCheckBox = new CheckBox(_("Secure trades"), mSecureTrades); - mSecureTradesCheckBox->setActionEventId(ACTION_SECURE_TRADES); - mSecureTradesCheckBox->addActionListener(this); - - mUnsecureCharsLabel = new Label(_("Unsecure chars in names")); - mUnsecureCharsField = new TextField(mUnsecureChars, - true, this, ACTION_UNSECURE); - mUnsecureCharsButton = new Button(_("Edit"), ACTION_EDIT_UNSECURE, this); - - mVisibleNamesCheckBox = new CheckBox(_("Visible names"), - mVisibleNamesEnabled); - mVisibleNamesCheckBox->setActionEventId("visiblenames"); - mVisibleNamesCheckBox->addActionListener(this); - - mShowPlayersStatusCheckBox = new CheckBox(_("Show statuses"), - mShowPlayersStatus); - mShowPlayersStatusCheckBox->setActionEventId("showPlayersStatus"); - mShowPlayersStatusCheckBox->addActionListener(this); - reset(); // Do the layout @@ -352,22 +294,11 @@ Setup_Relations::Setup_Relations(): place(0, 0, mPlayerTitleTable, 6); place(0, 1, mPlayerScrollArea, 6, 4).setPadding(2); place(0, 5, mDeleteButton); - place(0, 6, mShowGenderCheckBox, 3).setPadding(2); - place(0, 7, mShowLevelCheckBox, 3).setPadding(2); - place(0, 8, mShowOwnNameCheckBox, 3).setPadding(2); place(1, 5, mOldButton, 1); place(3, 5, ignore_action_label, 1); place(4, 5, mIgnoreActionChoicesBox, 2).setPadding(2); place(3, 6, mDefaultTrading, 3); place(3, 7, mDefaultWhisper, 3); - place(3, 8, mSecureTradesCheckBox, 3); - place(3, 9, mUnsecureCharsLabel, 3); - place(3, 10, mUnsecureCharsField, 2); - place(3, 11, mShowPlayersStatusCheckBox, 2); - place(5, 10, mUnsecureCharsButton, 1); - place(0, 9, mWhisperTabCheckBox, 3).setPadding(4); - place(0, 10, mTargetDeadCheckBox, 3).setPadding(4); - place(0, 11, mVisibleNamesCheckBox, 3).setPadding(4); player_relations.addListener(this); @@ -414,15 +345,6 @@ void Setup_Relations::apply() PlayerRelation::TRADE : 0) | (mDefaultWhisper->isSelected() ? PlayerRelation::WHISPER : 0)); - config.setValue("whispertab", mWhisperTab); - config.setValue("showlevel", mShowLevel); - config.setValue("showownname", mShowOwnName); - config.setValue("targetDeadPlayers", mTargetDead); - config.setValue("showgender", mShowGender); - config.setValue("securetrades", mSecureTrades); - config.setValue("unsecureChars", mUnsecureCharsField->getText()); - config.setValue("visiblenames", mVisibleNamesEnabled); - config.setValue("showPlayersStatus", mShowPlayersStatus); if (actorSpriteManager) actorSpriteManager->updatePlayerNames(); @@ -433,24 +355,6 @@ void Setup_Relations::apply() void Setup_Relations::cancel() { - mWhisperTab = config.getBoolValue("whispertab"); - mWhisperTabCheckBox->setSelected(mWhisperTab); - mShowGender = config.getBoolValue("showgender"); - mShowGenderCheckBox->setSelected(mShowGender); - mShowLevel = config.getBoolValue("showlevel"); - mShowLevelCheckBox->setSelected(mShowLevel); - mShowOwnName = config.getBoolValue("showownname"); - mShowOwnNameCheckBox->setSelected(mShowOwnName); - mTargetDead = config.getBoolValue("targetDeadPlayers"); - mTargetDeadCheckBox->setSelected(mTargetDead); - mSecureTrades = config.getBoolValue("securetrades"); - mSecureTradesCheckBox->setSelected(mSecureTrades); - mUnsecureChars = config.getStringValue("unsecureChars"); - mUnsecureCharsField->setText(mUnsecureChars); - mVisibleNamesEnabled = config.getBoolValue("visiblenames"); - mVisibleNamesCheckBox->setSelected(mVisibleNamesEnabled); - mShowPlayersStatus = config.getBoolValue("showPlayersStatus"); - mShowPlayersStatusCheckBox->setSelected(mShowPlayersStatus); } void Setup_Relations::action(const gcn::ActionEvent &event) @@ -494,52 +398,6 @@ void Setup_Relations::action(const gcn::ActionEvent &event) player_relations.setPlayerIgnoreStrategy(s); } - else if (event.getId() == ACTION_WHISPER_TAB) - { - mWhisperTab = mWhisperTabCheckBox->isSelected(); - } - else if (event.getId() == ACTION_SHOW_GENDER) - { - mShowGender = mShowGenderCheckBox->isSelected(); - } - else if (event.getId() == ACTION_SHOW_LEVEL) - { - mShowLevel = mShowLevelCheckBox->isSelected(); - } - else if (event.getId() == ACTION_SHOW_OWN_NAME) - { - mShowOwnName = mShowOwnNameCheckBox->isSelected(); - } - else if (event.getId() == ACTION_TARGET_DEAD) - { - mTargetDead = mTargetDeadCheckBox->isSelected(); - } - else if (event.getId() == ACTION_SECURE_TRADES) - { - mSecureTrades = mSecureTradesCheckBox->isSelected(); - } - else if (event.getId() == ACTION_EDIT_UNSECURE) - { - mEditDialog = new EditDialog(_("Unsecure chars in names"), - mUnsecureCharsField->getText(), ACTION_EDIT_UNSECURE_OK); - mEditDialog->addActionListener(this); - } - else if (event.getId() == ACTION_EDIT_UNSECURE_OK) - { - mUnsecureCharsField->setText(mEditDialog->getMsg()); - } - else if (event.getId() == ACTION_UNSECURE) - { - mUnsecureChars = mUnsecureCharsField->getText(); - } - else if (event.getId() == "visiblenames") - { - mVisibleNamesEnabled = mVisibleNamesCheckBox->isSelected(); - } - else if (event.getId() == "showPlayersStatus") - { - mShowPlayersStatus = mShowPlayersStatusCheckBox->isSelected(); - } } void Setup_Relations::updatedPlayer(const std::string &name A_UNUSED) diff --git a/src/gui/setup_relations.h b/src/gui/setup_relations.h index eab3c7661..a6627a06d 100644 --- a/src/gui/setup_relations.h +++ b/src/gui/setup_relations.h @@ -76,37 +76,6 @@ private: gcn::ListModel *mIgnoreActionChoicesModel; gcn::DropDown *mIgnoreActionChoicesBox; - - bool mWhisperTab; - gcn::CheckBox *mWhisperTabCheckBox; - - bool mShowGender; - gcn::CheckBox *mShowGenderCheckBox; - - bool mShowLevel; - gcn::CheckBox *mShowLevelCheckBox; - - bool mShowOwnName; - gcn::CheckBox *mShowOwnNameCheckBox; - - bool mTargetDead; - gcn::CheckBox *mTargetDeadCheckBox; - - bool mSecureTrades; - gcn::CheckBox *mSecureTradesCheckBox; - - gcn::Label *mUnsecureCharsLabel; - gcn::TextField *mUnsecureCharsField; - gcn::Button *mUnsecureCharsButton; - std::string mUnsecureChars; - - bool mVisibleNamesEnabled; - gcn::CheckBox *mVisibleNamesCheckBox; - - bool mShowPlayersStatus; - gcn::CheckBox *mShowPlayersStatusCheckBox; - - EditDialog *mEditDialog; }; #endif -- cgit v1.2.3-70-g09d2 From 22c81087c05cf216c8ab0ff29c82677db96e9ed7 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 10 Aug 2011 04:00:18 +0300 Subject: Fix crash in server dialog if press load button more than one time. --- src/gui/serverdialog.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index 140e4b629..41b0076e1 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -124,6 +124,9 @@ std::string ServersListModel::getElementAt(int elementIndex) void ServersListModel::setVersionString(int index, const std::string &version) { + if (index >= mVersionStrings.size()) + return; + if (version.empty()) { mVersionStrings[index] = VersionString(0, ""); @@ -604,6 +607,13 @@ void ServerDialog::downloadServerList() if (listFile.empty()) listFile = "http://manasource.org/serverlist.xml"; + if (mDownload) + { + mDownload->cancel(); + delete mDownload; + mDownload = 0; + } + mDownload = new Net::Download(this, listFile, &downloadUpdate); mDownload->setFile(mDir + "/serverlist.xml"); mDownload->start(); @@ -702,7 +712,6 @@ void ServerDialog::loadServers(bool addNew) break; } } - if (!found && addNew) mServers.push_back(server); } -- cgit v1.2.3-70-g09d2 From dd5a317dbfdb24d905ade4ebea458e370619f61f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 11 Aug 2011 03:03:53 +0300 Subject: Save whisper tabs state to configuration after each change. Before was only after correct game disconnect. --- src/client.cpp | 2 -- src/game.cpp | 2 -- src/gui/popupmenu.cpp | 12 ++++++++++++ src/gui/quitdialog.cpp | 8 ++------ src/gui/quitdialog.h | 1 - 5 files changed, 14 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/client.cpp b/src/client.cpp index 01543d8be..092f81a93 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -1289,8 +1289,6 @@ int Client::exec() case STATE_ERROR: logger->log1("State: ERROR"); logger->log("Error: %s\n", errorMessage.c_str()); - if (chatWindow) - chatWindow->saveState(); mCurrentDialog = new OkDialog(_("Error"), errorMessage); mCurrentDialog->addActionListener(&errorListener); mCurrentDialog = NULL; // OkDialog deletes itself diff --git a/src/game.cpp b/src/game.cpp index 9a5128f37..40b6896b7 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -532,8 +532,6 @@ void Game::logic() map->saveExtraLayer(); } Client::closeDialogs(); - if (chatWindow) - chatWindow->saveState(); disconnectedDialog = new OkDialog(_("Network Error"), errorMessage, false); disconnectedDialog->addActionListener(&errorListener); diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 79618ad04..9cf9e536e 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -1245,26 +1245,38 @@ void PopupMenu::handleLink(const std::string &link, else if (link == "enable highlight" && mTab) { mTab->setAllowHighlight(true); + if (chatWindow) + chatWindow->saveState(); } else if (link == "disable highlight" && mTab) { mTab->setAllowHighlight(false); + if (chatWindow) + chatWindow->saveState(); } else if (link == "dont remove name" && mTab) { mTab->setRemoveNames(false); + if (chatWindow) + chatWindow->saveState(); } else if (link == "remove name" && mTab) { mTab->setRemoveNames(true); + if (chatWindow) + chatWindow->saveState(); } else if (link == "disable away" && mTab) { mTab->setNoAway(true); + if (chatWindow) + chatWindow->saveState(); } else if (link == "enable away" && mTab) { mTab->setNoAway(false); + if (chatWindow) + chatWindow->saveState(); } else if (link == "remove attack" && being) { diff --git a/src/gui/quitdialog.cpp b/src/gui/quitdialog.cpp index 28a3332bf..f66872b5d 100644 --- a/src/gui/quitdialog.cpp +++ b/src/gui/quitdialog.cpp @@ -53,7 +53,6 @@ QuitDialog::QuitDialog(QuitDialog** pointerToMe): mForceQuit = new RadioButton(_("Quit"), "quitdialog"); mLogoutQuit = new RadioButton(_("Quit"), "quitdialog"); - mSaveState = new CheckBox(_("Save state"), true); mSwitchAccountServer = new RadioButton(_("Switch server"), "quitdialog"); mSwitchCharacter = new RadioButton(_("Switch character"), "quitdialog"); mOkButton = new Button(_("OK"), "ok", this); @@ -91,9 +90,8 @@ QuitDialog::QuitDialog(QuitDialog** pointerToMe): place = getPlacer(0, 1); - place(0, 0, mSaveState, 3); - place(1, 1, mOkButton, 1); - place(2, 1, mCancelButton, 1); + place(1, 0, mOkButton, 1); + place(2, 0, mCancelButton, 1); reflowLayout(200, 0); setLocationRelativeTo(getParent()); @@ -133,8 +131,6 @@ void QuitDialog::action(const gcn::ActionEvent &event) if (map) map->saveExtraLayer(); } - if (chatWindow && mSaveState->isSelected()) - chatWindow->saveState(); if (mForceQuit->isSelected()) { diff --git a/src/gui/quitdialog.h b/src/gui/quitdialog.h index d68910596..380a85528 100644 --- a/src/gui/quitdialog.h +++ b/src/gui/quitdialog.h @@ -65,7 +65,6 @@ class QuitDialog : public Window, public gcn::ActionListener, std::vector mOptions; gcn::RadioButton *mLogoutQuit; - gcn::CheckBox *mSaveState; gcn::RadioButton *mForceQuit; gcn::RadioButton *mSwitchAccountServer; gcn::RadioButton *mSwitchCharacter; -- cgit v1.2.3-70-g09d2 From 69c4bf1494b19ca3b3333effff83086b0f0b87fd Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 11 Aug 2011 03:43:22 +0300 Subject: Remove some unused code. --- src/net/ea/inventoryhandler.cpp | 6 +++--- src/resources/itemdb.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/net/ea/inventoryhandler.cpp b/src/net/ea/inventoryhandler.cpp index acd674d12..2e52b85ff 100644 --- a/src/net/ea/inventoryhandler.cpp +++ b/src/net/ea/inventoryhandler.cpp @@ -275,7 +275,7 @@ void InventoryHandler::processPlayerStorageEquip(Net::MessageIn &msg) void InventoryHandler::processPlayerInventoryAdd(Net::MessageIn &msg) { int index, amount, itemId, equipType, refine; - int cards[4], itemType; +// int cards[4], itemType; unsigned char identified; int floorId; @@ -296,9 +296,9 @@ void InventoryHandler::processPlayerInventoryAdd(Net::MessageIn &msg) msg.readInt8(); // attribute refine = msg.readInt8(); for (int i = 0; i < 4; i++) - cards[i] = msg.readInt16(); + msg.readInt16(); // cards[i] equipType = msg.readInt16(); - itemType = msg.readInt8(); + msg.readInt8(); // itemType const ItemInfo &itemInfo = ItemDB::get(itemId); diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 2d14ba687..7919145bd 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -213,7 +213,7 @@ void ItemDB::load() std::string attackAction = XML::getProperty(node, "attack-action", ""); std::string drawBefore = XML::getProperty(node, "drawBefore", ""); std::string drawAfter = XML::getProperty(node, "drawAfter", ""); - std::string removeSprite = XML::getProperty(node, "removeSprite", ""); +// std::string removeSprite = XML::getProperty(node, "removeSprite", ""); std::string colors; if (serverVersion >= 1) colors = XML::getProperty(node, "colors", ""); -- cgit v1.2.3-70-g09d2 From 44e80c70513022b6c378f64d6bf5d25dda7b0e7f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 11 Aug 2011 21:25:16 +0300 Subject: Fix saving opened tabs state. --- src/commandhandler.cpp | 16 ++++++++++++++-- src/gui/chatwindow.cpp | 14 +++++--------- src/gui/setup.cpp | 3 +++ src/gui/widgets/avatarlistbox.cpp | 6 ++++-- 4 files changed, 26 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index b87dcf583..dc9a4d1bf 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -403,8 +403,14 @@ void CommandHandler::handleMsg(const std::string &args, ChatTab *tab) void CommandHandler::handleQuery(const std::string &args, ChatTab *tab) { - if (chatWindow && chatWindow->addWhisperTab(args, true)) - return; + if (chatWindow) + { + if (chatWindow->addWhisperTab(args, true)) + { + chatWindow->saveState(); + return; + } + } tab->chatLog(strprintf(_("Cannot create a whisper tab for nick \"%s\"! " "It either already exists, or is you."), @@ -736,14 +742,20 @@ void CommandHandler::handleCloseAll(const std::string &args A_UNUSED, ChatTab *tab A_UNUSED) { if (chatWindow) + { chatWindow->removeAllWhispers(); + chatWindow->saveState(); + } } void CommandHandler::handleIgnoreAll(const std::string &args A_UNUSED, ChatTab *tab A_UNUSED) { if (chatWindow) + { chatWindow->ignoreAllWhispers(); + chatWindow->saveState(); + } } void CommandHandler::handleOutfit(const std::string &args, diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index c266374ef..1ef3139db 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -215,6 +215,7 @@ ChatWindow::ChatWindow(): ChatWindow::~ChatWindow() { + saveState(); config.setValue("ReturnToggles", mReturnToggles); removeAllWhispers(); delete mItemLinkHandler; @@ -935,7 +936,11 @@ void ChatWindow::whisper(const std::string &nick, if (i != mWhispers.end()) tab = i->second; else if (config.getBoolValue("whispertab")) + { tab = addWhisperTab(nick); + if (tab) + saveState(); + } if (tab) { @@ -1414,15 +1419,6 @@ void ChatWindow::loadState() tab->setRemoveNames((flags & 2) / 2); tab->setNoAway((flags & 4) / 4); } - serverConfig.deleteKey("chatWhisper" + toString(num)); - serverConfig.deleteKey("chatWhisperFlags" + toString(num)); - num ++; - } - - while (num < 50) - { - serverConfig.deleteKey("chatWhisper" + toString(num)); - serverConfig.deleteKey("chatWhisperFlags" + toString(num)); num ++; } } diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index d73212d48..0b40d8c01 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -22,6 +22,7 @@ #include "gui/setup.h" +#include "chatwindow.h" #include "configuration.h" #include "game.h" #include "main.h" @@ -149,6 +150,8 @@ void Setup::action(const gcn::ActionEvent &event) } else if (event.getId() == "Store") { + if (chatWindow) + chatWindow->saveState(); config.write(); serverConfig.write(); } diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp index 748e038e2..5ac6721a5 100644 --- a/src/gui/widgets/avatarlistbox.cpp +++ b/src/gui/widgets/avatarlistbox.cpp @@ -366,8 +366,10 @@ void AvatarListBox::mousePressed(gcn::MouseEvent &event) { if (ava->getType() == AVATAR_PLAYER && chatWindow) { - chatWindow->addWhisperTab(model->getAvatarAt(selected) - ->getName(), true); + ChatTab *tab = chatWindow->addWhisperTab( + model->getAvatarAt(selected)->getName(), true); + if (chatWindow && tab) + chatWindow->saveState(); } } } -- cgit v1.2.3-70-g09d2 From fca4273667f15afba055d3c296094f2f41c7ae91 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 12 Aug 2011 01:53:54 +0300 Subject: Add ability to add comments to npcs. --- src/being.cpp | 41 +++++++++++++++++++++++++++++++++-------- src/being.h | 4 ++-- src/client.cpp | 13 +++++++++++++ src/client.h | 3 +++ src/game.cpp | 2 +- src/gui/beingpopup.cpp | 6 ++++++ src/gui/popupmenu.cpp | 24 +++++++++++++++++++----- src/gui/popupmenu.h | 5 +++++ src/gui/viewport.cpp | 3 ++- 9 files changed, 84 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/being.cpp b/src/being.cpp index cd616fc67..b6f06a75a 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -263,7 +263,7 @@ Being::Being(int id, Type type, Uint16 subtype, Map *map): if (mType == PLAYER) mShowName = config.getBoolValue("visiblenames"); - else + else if (mType != NPC) mGotComment = true; config.addListener("visiblenames", this); @@ -2363,13 +2363,26 @@ void Being::updateComment() return; mGotComment = true; - mComment = loadComment(mName); + mComment = loadComment(mName, mType); } -std::string Being::loadComment(const std::string &name) +std::string Being::loadComment(const std::string &name, int type) { - std::string str = Client::getUsersDirectory() - + stringToHexPath(name) + "/comment.txt"; + std::string str; + switch (type) + { + case PLAYER: + str = Client::getUsersDirectory(); + break; + case NPC: + str = Client::getNpcsDirectory(); + break; + default: + return ""; + } + + str += stringToHexPath(name) + "/comment.txt"; + logger->log("load from: %s", str.c_str()); std::vector lines; ResourceManager *resman = ResourceManager::getInstance(); @@ -2383,10 +2396,22 @@ std::string Being::loadComment(const std::string &name) } void Being::saveComment(const std::string &name, - const std::string &comment) + const std::string &comment, int type) { - std::string dir = Client::getUsersDirectory() - + stringToHexPath(name); + std::string dir; + switch (type) + { + case PLAYER: + dir = Client::getUsersDirectory(); + break; + case NPC: + dir = Client::getNpcsDirectory(); + break; + default: + return; + } + dir += stringToHexPath(name); + logger->log("save to: %s", dir.c_str()); ResourceManager *resman = ResourceManager::getInstance(); resman->saveTextFile(dir, "comment.txt", name + "\n" + comment); } diff --git a/src/being.h b/src/being.h index 76c968451..2c37ffeb5 100644 --- a/src/being.h +++ b/src/being.h @@ -741,10 +741,10 @@ class Being : public ActorSprite, public ConfigListener static void clearCache(); - static std::string loadComment(const std::string &name); + static std::string loadComment(const std::string &name, int type); static void saveComment(const std::string &name, - const std::string &comment); + const std::string &comment, int type); bool isAdvanced() { return mAdvanced; } diff --git a/src/client.cpp b/src/client.cpp index 092f81a93..022bc07d5 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -240,6 +240,7 @@ Client::Client(const Options &options): mOptions(options), mServerConfigDir(""), mUsersDir(""), + mNpcsDir(""), mRootDir(""), mCurrentDialog(0), mQuitDialog(0), @@ -1917,6 +1918,13 @@ void Client::initUsersDir() logger->error(strprintf(_("%s doesn't exist and can't be created! " "Exiting."), mUsersDir.c_str())); } + + mNpcsDir = Client::getServerConfigDirectory() + "/npcs/"; + if (mkdir_r(mNpcsDir.c_str())) + { + logger->error(strprintf(_("%s doesn't exist and can't be created! " + "Exiting."), mNpcsDir.c_str())); + } } void Client::initPacketLimiter() @@ -2137,6 +2145,11 @@ const std::string Client::getUsersDirectory() return instance()->mUsersDir; } +const std::string Client::getNpcsDirectory() +{ + return instance()->mNpcsDir; +} + void Client::setGuiAlpha(float n) { instance()->mGuiAlpha = n; diff --git a/src/client.h b/src/client.h index 75b3c03fe..986e06cfb 100644 --- a/src/client.h +++ b/src/client.h @@ -226,6 +226,8 @@ public: static const std::string getUsersDirectory(); + static const std::string getNpcsDirectory(); + static bool getIsMinimized() { return instance()->mIsMinimized; } @@ -303,6 +305,7 @@ private: std::string mScreenshotDir; std::string mServerConfigDir; std::string mUsersDir; + std::string mNpcsDir; std::string mRootDir; std::string mServerName; diff --git a/src/game.cpp b/src/game.cpp index 40b6896b7..05fb88048 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -556,7 +556,7 @@ void Game::adjustPerfomance() { mNextAdjustTime = cur_time + adjustDelay; } - else if (mNextAdjustTime < cur_time) + else if (mNextAdjustTime < (unsigned)cur_time) { mNextAdjustTime = cur_time + adjustDelay; diff --git a/src/gui/beingpopup.cpp b/src/gui/beingpopup.cpp index e5dc602a0..8d7b26c1b 100644 --- a/src/gui/beingpopup.cpp +++ b/src/gui/beingpopup.cpp @@ -89,6 +89,12 @@ void BeingPopup::show(int x, int y, Being *b) b->updateComment(); + if (b->getType() == Being::NPC && b->getComment().empty()) + { + setVisible(false); + return; + } + mBeingName->setCaption(b->getName() + b->getGenderSignWithSpace()); if (gui) { diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 9cf9e536e..14a326e41 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -22,6 +22,7 @@ #include "gui/popupmenu.h" +#include "actorsprite.h" #include "actorspritemanager.h" #include "being.h" #include "dropshortcut.h" @@ -94,7 +95,8 @@ PopupMenu::PopupMenu(): mSpell(0), mDialog(0), mButton(0), - mNick("") + mNick(""), + mType(Being::UNKNOWN) { mBrowserBox = new BrowserBox; mBrowserBox->setPosition(4, 4); @@ -105,6 +107,7 @@ PopupMenu::PopupMenu(): mRenameListener.setDialog(0); mPlayerListener.setNick(""); mPlayerListener.setDialog(0); + mPlayerListener.setType(Being::UNKNOWN); add(mBrowserBox); } @@ -116,6 +119,7 @@ void PopupMenu::showPopup(int x, int y, Being *being) mBeingId = being->getId(); mNick = being->getName(); + mType = being->getType(); mBrowserBox->clearRows(); const std::string &name = mNick; @@ -278,6 +282,8 @@ void PopupMenu::showPopup(int x, int y, Being *being) mBrowserBox->addRow(strprintf("@@sell|%s@@", _("Sell"))); mBrowserBox->addRow("##3---"); mBrowserBox->addRow(strprintf("@@move|%s@@", _("Move"))); + mBrowserBox->addRow(strprintf("@@addcomment|%s@@", + _("Add comment"))); break; case ActorSprite::MONSTER: @@ -359,6 +365,7 @@ void PopupMenu::showPlayerPopup(int x, int y, std::string nick) mNick = nick; mBeingId = 0; + mType = Being::PLAYER; mBrowserBox->clearRows(); const std::string &name = mNick; @@ -599,6 +606,7 @@ void PopupMenu::showChatPopup(int x, int y, ChatTab *tab) { mBeingId = being->getId(); mNick = being->getName(); + mType = being->getType(); mBrowserBox->addRow(strprintf("@@trade|%s@@", _("Trade"))); mBrowserBox->addRow(strprintf("@@attack|%s@@", _("Attack"))); @@ -728,6 +736,7 @@ void PopupMenu::showChatPopup(int x, int y, ChatTab *tab) else { mNick = name; + mType = Being::PLAYER; mBrowserBox->addRow(strprintf( "@@addcomment|%s@@", _("Add comment"))); mBrowserBox->addRow("##3---"); @@ -768,6 +777,7 @@ void PopupMenu::showChangePos(int x, int y) mItem = 0; mMapItem = 0; mNick = ""; + mType = Being::UNKNOWN; setVisible(false); } } @@ -1220,6 +1230,7 @@ void PopupMenu::handleLink(const std::string &link, _("Comment: ")); mPlayerListener.setDialog(dialog); mPlayerListener.setNick(mNick); + mPlayerListener.setType(mType); if (being) { @@ -1228,7 +1239,7 @@ void PopupMenu::handleLink(const std::string &link, } else { - dialog->setText(Being::loadComment(mNick)); + dialog->setText(Being::loadComment(mNick, mType)); } dialog->setActionEventId("ok"); dialog->addActionListener(&mPlayerListener); @@ -1560,6 +1571,7 @@ void PopupMenu::handleLink(const std::string &link, mItemColor = 1; mMapItem = 0; mNick = ""; + mType = Being::UNKNOWN; } void PopupMenu::showPopup(Window *parent, int x, int y, Item *item, @@ -1870,6 +1882,7 @@ void PopupMenu::showAttackMonsterPopup(int x, int y, std::string name, return; mNick = name; + mType = Being::MONSTER; mBrowserBox->clearRows(); @@ -2001,7 +2014,8 @@ void RenameListener::action(const gcn::ActionEvent &event) PlayerListener::PlayerListener() : mNick(""), - mDialog(0) + mDialog(0), + mType(Being::UNKNOWN) { } @@ -2011,10 +2025,10 @@ void PlayerListener::action(const gcn::ActionEvent &event) { std::string comment = mDialog->getText(); Being* being = actorSpriteManager->findBeingByName( - mNick, Being::PLAYER); + mNick, (ActorSprite::Type)mType); if (being) being->setComment(comment); - Being::saveComment(mNick, comment); + Being::saveComment(mNick, comment, mType); } mDialog = 0; } diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h index afa4bdfa2..3a7f27d4b 100644 --- a/src/gui/popupmenu.h +++ b/src/gui/popupmenu.h @@ -78,9 +78,13 @@ class PlayerListener : public gcn::ActionListener void setDialog(TextDialog *dialog) { mDialog = dialog; } + void setType(int type) + { mType = type; } + private: std::string mNick; TextDialog *mDialog; + int mType; }; /** @@ -171,6 +175,7 @@ class PopupMenu : public Popup, public LinkHandler TextDialog *mDialog; Button *mButton; std::string mNick; + int mType; /** * Shared code for the various showPopup functions. diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index ba8414699..2ca59f524 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -684,7 +684,8 @@ void Viewport::mouseMoved(gcn::MouseEvent &event A_UNUSED) const int y = getMouseY() + static_cast(mPixelViewY); mHoverBeing = actorSpriteManager->findBeingByPixel(x, y, true); - if (mHoverBeing && mHoverBeing->getType() == Being::PLAYER) + if (mHoverBeing && (mHoverBeing->getType() == Being::PLAYER + || mHoverBeing->getType() == Being::NPC)) { mTextPopup->setVisible(false); if (mShowBeingPopup) -- cgit v1.2.3-70-g09d2 From 383b667c30665377ee5bd5c1167530eb44ce4571 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 12 Aug 2011 03:24:12 +0300 Subject: Allow hide setup window by pressing key "Setup window". --- src/game.cpp | 306 ++++++++++++++++++++++++++++-------------------------- src/gui/setup.cpp | 9 +- src/gui/setup.h | 2 + 3 files changed, 167 insertions(+), 150 deletions(-) (limited to 'src') diff --git a/src/game.cpp b/src/game.cpp index 05fb88048..4332c8e11 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1039,174 +1039,184 @@ void Game::handleInput() if (keyboard.isEnabled() && !chatWindow->isInputFocused() && !NpcDialog::isAnyInputFocused() - && !setupWindow->isVisible() && !player_node->getAwayMode() && !keyboard.isKeyActive(keyboard.KEY_TARGET)) { const int tKey = keyboard.getKeyIndex(event.key.keysym.sym); - // Do not activate shortcuts if tradewindow is visible - if (itemShortcutWindow && !tradeWindow->isVisible() - && !setupWindow->isVisible()) + if (setupWindow->isVisible()) { - int num = itemShortcutWindow->getTabIndex(); - if (num >= 0 && num < SHORTCUT_TABS) + if (tKey == KeyboardConfig::KEY_WINDOW_SETUP) { - // Checks if any item shortcut is pressed. - for (int i = KeyboardConfig::KEY_SHORTCUT_1; - i <= KeyboardConfig::KEY_SHORTCUT_20; - i++) + setupWindow->doCancel(); + used = true; + } + } + else + { + // Do not activate shortcuts if tradewindow is visible + if (itemShortcutWindow && !tradeWindow->isVisible() + && !setupWindow->isVisible()) + { + int num = itemShortcutWindow->getTabIndex(); + if (num >= 0 && num < SHORTCUT_TABS) { - if (tKey == i && !used) + // Checks if any item shortcut is pressed. + for (int i = KeyboardConfig::KEY_SHORTCUT_1; + i <= KeyboardConfig::KEY_SHORTCUT_20; + i ++) { - itemShortcut[num]->useItem( - i - KeyboardConfig::KEY_SHORTCUT_1); - break; + if (tKey == i && !used) + { + itemShortcut[num]->useItem( + i - KeyboardConfig::KEY_SHORTCUT_1); + break; + } } } } - } - switch (tKey) - { - case KeyboardConfig::KEY_PICKUP: - player_node->pickUpItems(); - used = true; - break; - case KeyboardConfig::KEY_SIT: - // Player sit action - if (keyboard.isKeyActive(keyboard.KEY_EMOTE)) - player_node->updateSit(); - else - player_node->toggleSit(); - used = true; - break; - case KeyboardConfig::KEY_HIDE_WINDOWS: - // Hide certain windows - if (!chatWindow->isInputFocused()) - { - statusWindow->setVisible(false); - inventoryWindow->setVisible(false); - shopWindow->setVisible(false); - skillDialog->setVisible(false); - setupWindow->setVisible(false); - equipmentWindow->setVisible(false); - helpWindow->setVisible(false); - debugWindow->setVisible(false); - outfitWindow->setVisible(false); - dropShortcutWindow->setVisible(false); - spellShortcutWindow->setVisible(false); - botCheckerWindow->setVisible(false); - socialWindow->setVisible(false); - } - break; - case KeyboardConfig::KEY_WINDOW_STATUS: - requestedWindow = statusWindow; - break; - case KeyboardConfig::KEY_WINDOW_INVENTORY: - requestedWindow = inventoryWindow; - break; - case KeyboardConfig::KEY_WINDOW_SHOP: - requestedWindow = shopWindow; - break; - case KeyboardConfig::KEY_WINDOW_EQUIPMENT: - requestedWindow = equipmentWindow; - break; - case KeyboardConfig::KEY_WINDOW_SKILL: - requestedWindow = skillDialog; - break; - case KeyboardConfig::KEY_WINDOW_KILLS: - requestedWindow = killStats; - break; - case KeyboardConfig::KEY_WINDOW_MINIMAP: - minimap->toggle(); - break; - case KeyboardConfig::KEY_WINDOW_CHAT: - requestedWindow = chatWindow; - break; - case KeyboardConfig::KEY_WINDOW_SHORTCUT: - requestedWindow = itemShortcutWindow; - break; - case KeyboardConfig::KEY_WINDOW_SETUP: - requestedWindow = setupWindow; - break; - case KeyboardConfig::KEY_WINDOW_DEBUG: - requestedWindow = debugWindow; - break; - case KeyboardConfig::KEY_WINDOW_SOCIAL: - requestedWindow = socialWindow; - break; - case KeyboardConfig::KEY_WINDOW_EMOTE_SHORTCUT: - requestedWindow = emoteShortcutWindow; - break; - case KeyboardConfig::KEY_WINDOW_OUTFIT: - requestedWindow = outfitWindow; - break; - case KeyboardConfig::KEY_WINDOW_DROP: - requestedWindow = dropShortcutWindow; - break; - case KeyboardConfig::KEY_WINDOW_SPELLS: - requestedWindow = spellShortcutWindow; - break; - case KeyboardConfig::KEY_WINDOW_BOT_CHECKER: - requestedWindow = botCheckerWindow; - break; - case KeyboardConfig::KEY_WINDOW_ONLINE: - requestedWindow = whoIsOnline; - break; - case KeyboardConfig::KEY_SCREENSHOT: - // Screenshot (picture, hence the p) - saveScreenshot(); - used = true; - break; - case KeyboardConfig::KEY_PATHFIND: - // Find path to mouse (debug purpose) - if (!player_node->getDisableGameModifiers()) - { - if (viewport) - viewport->toggleDebugPath(); - if (miniStatusWindow) - miniStatusWindow->updateStatus(); - if (mCurrentMap) - mCurrentMap->redrawMap(); - used = true; - } - break; - case KeyboardConfig::KEY_TRADE: + switch (tKey) { - // Toggle accepting of incoming trade requests - unsigned int deflt = player_relations.getDefault(); - if (deflt & PlayerRelation::TRADE) - { - localChatTab->chatLog( - _("Ignoring incoming trade requests"), - BY_SERVER); - deflt &= ~PlayerRelation::TRADE; - } - else + case KeyboardConfig::KEY_PICKUP: + player_node->pickUpItems(); + used = true; + break; + case KeyboardConfig::KEY_SIT: + // Player sit action + if (keyboard.isKeyActive(keyboard.KEY_EMOTE)) + player_node->updateSit(); + else + player_node->toggleSit(); + used = true; + break; + case KeyboardConfig::KEY_HIDE_WINDOWS: + // Hide certain windows + if (!chatWindow->isInputFocused()) + { + statusWindow->setVisible(false); + inventoryWindow->setVisible(false); + shopWindow->setVisible(false); + skillDialog->setVisible(false); + setupWindow->setVisible(false); + equipmentWindow->setVisible(false); + helpWindow->setVisible(false); + debugWindow->setVisible(false); + outfitWindow->setVisible(false); + dropShortcutWindow->setVisible(false); + spellShortcutWindow->setVisible(false); + botCheckerWindow->setVisible(false); + socialWindow->setVisible(false); + } + break; + case KeyboardConfig::KEY_WINDOW_STATUS: + requestedWindow = statusWindow; + break; + case KeyboardConfig::KEY_WINDOW_INVENTORY: + requestedWindow = inventoryWindow; + break; + case KeyboardConfig::KEY_WINDOW_SHOP: + requestedWindow = shopWindow; + break; + case KeyboardConfig::KEY_WINDOW_EQUIPMENT: + requestedWindow = equipmentWindow; + break; + case KeyboardConfig::KEY_WINDOW_SKILL: + requestedWindow = skillDialog; + break; + case KeyboardConfig::KEY_WINDOW_KILLS: + requestedWindow = killStats; + break; + case KeyboardConfig::KEY_WINDOW_MINIMAP: + minimap->toggle(); + break; + case KeyboardConfig::KEY_WINDOW_CHAT: + requestedWindow = chatWindow; + break; + case KeyboardConfig::KEY_WINDOW_SHORTCUT: + requestedWindow = itemShortcutWindow; + break; + case KeyboardConfig::KEY_WINDOW_SETUP: + requestedWindow = setupWindow; + break; + case KeyboardConfig::KEY_WINDOW_DEBUG: + requestedWindow = debugWindow; + break; + case KeyboardConfig::KEY_WINDOW_SOCIAL: + requestedWindow = socialWindow; + break; + case KeyboardConfig::KEY_WINDOW_EMOTE_SHORTCUT: + requestedWindow = emoteShortcutWindow; + break; + case KeyboardConfig::KEY_WINDOW_OUTFIT: + requestedWindow = outfitWindow; + break; + case KeyboardConfig::KEY_WINDOW_DROP: + requestedWindow = dropShortcutWindow; + break; + case KeyboardConfig::KEY_WINDOW_SPELLS: + requestedWindow = spellShortcutWindow; + break; + case KeyboardConfig::KEY_WINDOW_BOT_CHECKER: + requestedWindow = botCheckerWindow; + break; + case KeyboardConfig::KEY_WINDOW_ONLINE: + requestedWindow = whoIsOnline; + break; + case KeyboardConfig::KEY_SCREENSHOT: + // Screenshot (picture, hence the p) + saveScreenshot(); + used = true; + break; + case KeyboardConfig::KEY_PATHFIND: + // Find path to mouse (debug purpose) + if (!player_node->getDisableGameModifiers()) + { + if (viewport) + viewport->toggleDebugPath(); + if (miniStatusWindow) + miniStatusWindow->updateStatus(); + if (mCurrentMap) + mCurrentMap->redrawMap(); + used = true; + } + break; + case KeyboardConfig::KEY_TRADE: { - localChatTab->chatLog( - _("Accepting incoming trade requests"), - BY_SERVER); - deflt |= PlayerRelation::TRADE; - } + // Toggle accepting of incoming trade requests + unsigned int deflt = player_relations.getDefault(); + if (deflt & PlayerRelation::TRADE) + { + localChatTab->chatLog( + _("Ignoring incoming trade requests"), + BY_SERVER); + deflt &= ~PlayerRelation::TRADE; + } + else + { + localChatTab->chatLog( + _("Accepting incoming trade requests"), + BY_SERVER); + deflt |= PlayerRelation::TRADE; + } - player_relations.setDefault(deflt); + player_relations.setDefault(deflt); - used = true; + used = true; + } + break; + default: + break; } - break; - default: - break; } - } - if (requestedWindow) - { - requestedWindow->setVisible(!requestedWindow->isVisible()); - if (requestedWindow->isVisible()) - requestedWindow->requestMoveToTop(); - used = true; + if (requestedWindow) + { + requestedWindow->setVisible(!requestedWindow->isVisible()); + if (requestedWindow->isVisible()) + requestedWindow->requestMoveToTop(); + used = true; + } } } // Active event diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 0b40d8c01..690871189 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -145,8 +145,7 @@ void Setup::action(const gcn::ActionEvent &event) } else if (event.getId() == "Cancel") { - setVisible(false); - for_each(mTabs.begin(), mTabs.end(), std::mem_fun(&SetupTab::cancel)); + doCancel(); } else if (event.getId() == "Store") { @@ -189,4 +188,10 @@ void Setup::registerWindowForReset(Window *window) mWindowsToReset.push_back(window); } +void Setup::doCancel() +{ + setVisible(false); + for_each(mTabs.begin(), mTabs.end(), std::mem_fun(&SetupTab::cancel)); +} + Setup *setupWindow; diff --git a/src/gui/setup.h b/src/gui/setup.h index ad5ba53d9..cdaf7db99 100644 --- a/src/gui/setup.h +++ b/src/gui/setup.h @@ -71,6 +71,8 @@ class Setup : public Window, public gcn::ActionListener void clearWindowsForReset() { mWindowsToReset.clear(); } + void doCancel(); + private: std::list mTabs; std::list mWindowsToReset; -- cgit v1.2.3-70-g09d2 From 2d45a2ca5480ae0fdc03a807787f622444830d44 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 12 Aug 2011 03:47:28 +0300 Subject: Rename file names log and chatlog to correct logger and chatlogger. --- manaplus.cbp | 8 +- src/CMakeLists.txt | 8 +- src/Makefile.am | 8 +- src/actorsprite.cpp | 2 +- src/actorspritemanager.cpp | 2 +- src/animatedsprite.cpp | 2 +- src/being.cpp | 2 +- src/chatlog.cpp | 204 --------------------------- src/chatlog.h | 79 ----------- src/chatlogger.cpp | 204 +++++++++++++++++++++++++++ src/chatlogger.h | 79 +++++++++++ src/client.cpp | 2 +- src/commandhandler.cpp | 2 +- src/configuration.cpp | 2 +- src/effectmanager.cpp | 2 +- src/filefilter.txt | 2 + src/game.cpp | 2 +- src/graphics.cpp | 2 +- src/gui/changeemaildialog.cpp | 2 +- src/gui/changepassworddialog.cpp | 2 +- src/gui/charselectdialog.cpp | 2 +- src/gui/connectiondialog.cpp | 2 +- src/gui/didyouknowwindow.cpp | 2 +- src/gui/emotepopup.cpp | 2 +- src/gui/gui.cpp | 2 +- src/gui/helpwindow.cpp | 2 +- src/gui/minimap.cpp | 2 +- src/gui/outfitwindow.cpp | 2 +- src/gui/palette.h | 2 +- src/gui/popupmenu.cpp | 2 +- src/gui/register.cpp | 2 +- src/gui/sdlfont.cpp | 2 +- src/gui/serverdialog.cpp | 4 +- src/gui/setup_audio.cpp | 2 +- src/gui/setup_chat.cpp | 2 +- src/gui/setup_other.cpp | 2 +- src/gui/setup_perfomance.cpp | 2 +- src/gui/setup_players.cpp | 2 +- src/gui/setup_relations.cpp | 2 +- src/gui/setup_theme.cpp | 2 +- src/gui/setup_video.cpp | 2 +- src/gui/setupitem.cpp | 2 +- src/gui/skilldialog.cpp | 2 +- src/gui/socialwindow.cpp | 2 +- src/gui/specialswindow.cpp | 2 +- src/gui/theme.cpp | 2 +- src/gui/unregisterdialog.cpp | 2 +- src/gui/updatewindow.cpp | 2 +- src/gui/userpalette.cpp | 2 +- src/gui/widgets/battletab.cpp | 4 +- src/gui/widgets/browserbox.cpp | 2 +- src/gui/widgets/button.cpp | 2 +- src/gui/widgets/chattab.cpp | 4 +- src/gui/widgets/desktop.cpp | 2 +- src/gui/widgets/emoteshortcutcontainer.cpp | 2 +- src/gui/widgets/inventoryfilter.cpp | 2 +- src/gui/widgets/itemcontainer.cpp | 2 +- src/gui/widgets/layout.cpp | 2 +- src/gui/widgets/popup.cpp | 2 +- src/gui/widgets/scrollarea.cpp | 2 +- src/gui/widgets/spellshortcutcontainer.cpp | 2 +- src/gui/widgets/tab.cpp | 2 +- src/gui/widgets/tabbedarea.cpp | 2 +- src/gui/widgets/textfield.cpp | 2 +- src/gui/widgets/tradetab.cpp | 4 +- src/gui/widgets/whispertab.cpp | 4 +- src/gui/widgets/window.cpp | 2 +- src/inventory.cpp | 2 +- src/joystick.cpp | 2 +- src/keyboardconfig.cpp | 2 +- src/localplayer.cpp | 2 +- src/log.cpp | 217 ----------------------------- src/log.h | 110 --------------- src/logger.cpp | 217 +++++++++++++++++++++++++++++ src/logger.h | 110 +++++++++++++++ src/main.cpp | 2 +- src/map.cpp | 2 +- src/mumblemanager.cpp | 2 +- src/net/download.cpp | 2 +- src/net/ea/beinghandler.cpp | 2 +- src/net/ea/charserverhandler.cpp | 2 +- src/net/ea/chathandler.cpp | 2 +- src/net/ea/gamehandler.cpp | 2 +- src/net/ea/gui/guildtab.cpp | 2 +- src/net/ea/gui/partytab.cpp | 2 +- src/net/ea/guildhandler.cpp | 2 +- src/net/ea/inventoryhandler.cpp | 2 +- src/net/ea/inventoryhandler.h | 2 +- src/net/ea/loginhandler.cpp | 2 +- src/net/ea/partyhandler.cpp | 2 +- src/net/ea/playerhandler.cpp | 2 +- src/net/ea/specialhandler.cpp | 2 +- src/net/ea/tradehandler.cpp | 2 +- src/net/manaserv/attributes.cpp | 2 +- src/net/manaserv/beinghandler.cpp | 2 +- src/net/manaserv/charhandler.cpp | 2 +- src/net/manaserv/connection.cpp | 2 +- src/net/manaserv/effecthandler.cpp | 2 +- src/net/manaserv/guildhandler.cpp | 2 +- src/net/manaserv/inventoryhandler.cpp | 2 +- src/net/manaserv/itemhandler.cpp | 2 +- src/net/manaserv/loginhandler.cpp | 2 +- src/net/manaserv/network.cpp | 2 +- src/net/manaserv/partyhandler.cpp | 2 +- src/net/manaserv/playerhandler.cpp | 2 +- src/net/messagein.cpp | 2 +- src/net/messageout.cpp | 2 +- src/net/tmwa/adminhandler.cpp | 2 +- src/net/tmwa/beinghandler.cpp | 2 +- src/net/tmwa/charserverhandler.cpp | 2 +- src/net/tmwa/chathandler.cpp | 2 +- src/net/tmwa/gamehandler.cpp | 2 +- src/net/tmwa/generalhandler.cpp | 2 +- src/net/tmwa/gui/guildtab.cpp | 2 +- src/net/tmwa/gui/partytab.cpp | 2 +- src/net/tmwa/guildhandler.cpp | 2 +- src/net/tmwa/inventoryhandler.cpp | 2 +- src/net/tmwa/inventoryhandler.h | 2 +- src/net/tmwa/loginhandler.cpp | 2 +- src/net/tmwa/messagein.cpp | 2 +- src/net/tmwa/messageout.cpp | 2 +- src/net/tmwa/network.cpp | 2 +- src/net/tmwa/partyhandler.cpp | 2 +- src/net/tmwa/playerhandler.cpp | 2 +- src/net/tmwa/specialhandler.cpp | 2 +- src/net/tmwa/tradehandler.cpp | 2 +- src/opengl1graphics.cpp | 2 +- src/openglgraphics.cpp | 2 +- src/particle.cpp | 2 +- src/particleemitter.cpp | 2 +- src/playerinfo.cpp | 2 +- src/properties.h | 2 +- src/resources/animation.cpp | 2 +- src/resources/beinginfo.cpp | 2 +- src/resources/colordb.cpp | 2 +- src/resources/dye.cpp | 2 +- src/resources/emotedb.cpp | 2 +- src/resources/image.cpp | 2 +- src/resources/imageset.cpp | 2 +- src/resources/imagewriter.cpp | 2 +- src/resources/itemdb.cpp | 2 +- src/resources/mapdb.cpp | 2 +- src/resources/mapreader.cpp | 2 +- src/resources/monsterdb.cpp | 2 +- src/resources/music.cpp | 2 +- src/resources/npcdb.cpp | 2 +- src/resources/resource.cpp | 2 +- src/resources/resourcemanager.cpp | 2 +- src/resources/soundeffect.cpp | 2 +- src/resources/specialdb.cpp | 2 +- src/resources/spritedef.cpp | 2 +- src/resources/wallpaper.cpp | 2 +- src/simpleanimation.cpp | 2 +- src/sound.cpp | 2 +- src/spellmanager.cpp | 2 +- src/spellshortcut.h | 2 +- src/statuseffect.cpp | 2 +- src/units.cpp | 2 +- src/utils/mutex.h | 2 +- src/utils/xml.cpp | 2 +- 160 files changed, 777 insertions(+), 775 deletions(-) delete mode 100644 src/chatlog.cpp delete mode 100644 src/chatlog.h create mode 100644 src/chatlogger.cpp create mode 100644 src/chatlogger.h delete mode 100644 src/log.cpp delete mode 100644 src/log.h create mode 100644 src/logger.cpp create mode 100644 src/logger.h (limited to 'src') diff --git a/manaplus.cbp b/manaplus.cbp index e31f4fee9..020e65357 100644 --- a/manaplus.cbp +++ b/manaplus.cbp @@ -117,8 +117,8 @@ - - + + @@ -410,8 +410,8 @@ - - + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9a9d09f97..a48c4f28a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -472,8 +472,8 @@ SET(SRCS being.h spellmanager.cpp spellmanager.h - chatlog.cpp - chatlog.h + chatlogger.cpp + chatlogger.h client.cpp client.h channel.cpp @@ -532,8 +532,8 @@ SET(SRCS listener.h localplayer.cpp localplayer.h - log.cpp - log.h + logger.cpp + logger.h main.cpp main.h map.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 76010cb73..c1287e06c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -479,8 +479,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ being.h \ spellmanager.cpp \ spellmanager.h \ - chatlog.cpp \ - chatlog.h \ + chatlogger.cpp \ + chatlogger.h \ client.cpp \ client.h \ channel.cpp \ @@ -539,8 +539,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ listener.h \ localplayer.cpp \ localplayer.h \ - log.cpp \ - log.h \ + logger.cpp \ + logger.h \ main.cpp \ main.h \ map.cpp\ diff --git a/src/actorsprite.cpp b/src/actorsprite.cpp index 5f71c6bbb..848e84e0f 100644 --- a/src/actorsprite.cpp +++ b/src/actorsprite.cpp @@ -26,7 +26,7 @@ #include "effectmanager.h" #include "imagesprite.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "simpleanimation.h" #include "sound.h" #include "statuseffect.h" diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp index 61534c340..e8244bc30 100644 --- a/src/actorspritemanager.cpp +++ b/src/actorspritemanager.cpp @@ -24,7 +24,7 @@ #include "configuration.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "main.h" #include "playerinfo.h" #include "playerrelations.h" diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index 41aabf60c..7414c94bc 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -23,7 +23,7 @@ #include "animatedsprite.h" #include "graphics.h" -#include "log.h" +#include "logger.h" #include "resources/action.h" #include "resources/animation.h" diff --git a/src/being.cpp b/src/being.cpp index b6f06a75a..7c2a6bf40 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -31,7 +31,7 @@ #include "guild.h" #include "item.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "map.h" #include "particle.h" #include "party.h" diff --git a/src/chatlog.cpp b/src/chatlog.cpp deleted file mode 100644 index 99fe317c6..000000000 --- a/src/chatlog.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2009-2010 Andrei Karas - * Copyright (C) 2011 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, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "chatlog.h" - -#include -#include -#include - -#include -#include -#include - -#ifdef WIN32 -#include -#elif defined __APPLE__ -#include -#endif - -#include "log.h" -#include "configuration.h" - -#include "utils/stringutils.h" - -#include "debug.h" - -ChatLogger::ChatLogger() -{ -} - -ChatLogger::~ChatLogger() -{ - if (mLogFile.is_open()) - mLogFile.close(); -} - -void ChatLogger::setLogFile(const std::string &logFilename) -{ - if (mLogFile.is_open()) - mLogFile.close(); - - mLogFile.open(logFilename.c_str(), std::ios_base::app); - - if (!mLogFile.is_open()) - { - std::cout << "Warning: error while opening " << logFilename << - " for writing.\n"; - } -} - -void ChatLogger::setLogDir(const std::string &logDir) -{ - mLogDir = logDir; - - if (mLogFile.is_open()) - mLogFile.close(); - - DIR *dir = opendir(mLogDir.c_str()); - if (!dir) - makeDir(mLogDir); - else - closedir(dir); -} - -void ChatLogger::log(std::string str) -{ - std::string dateStr = getDateString(); - if (!mLogFile.is_open() || dateStr != mLogDate) - { - mLogDate = dateStr; - setLogFile(strprintf("%s/%s/#General_%s.log", mLogDir.c_str(), - mServerName.c_str(), dateStr.c_str())); - } - - str = removeColors(str); - writeTo(mLogFile, str); -} - -void ChatLogger::log(std::string name, std::string str) -{ - std::ofstream logFile; - logFile.open(strprintf("%s/%s/%s_%s.log", mLogDir.c_str(), - mServerName.c_str(), secureName(name).c_str(), - getDateString().c_str()).c_str(), std::ios_base::app); - - if (!logFile.is_open()) - return; - - str = removeColors(str); - writeTo(logFile, str); - - if (logFile.is_open()) - logFile.close(); -} - -std::string ChatLogger::getDateString() const -{ - std::string date; - - time_t rawtime; - struct tm *timeinfo; - char buffer [81]; - - time (&rawtime); - timeinfo = localtime(&rawtime); - - strftime(buffer, 79, "%y-%m-%d", timeinfo); - date = buffer; - return date; -} - -std::string ChatLogger::secureName(std::string &name) const -{ - for (unsigned int f = 0; f < name.length(); f ++) - { - if (name[f] < '0' && name[f] > '9' && name[f] < 'a' && name[f] > 'z' - && name[f] < 'A' && name[f] > 'Z' - && name[f] != '-' && name[f] != '+' && name[f] != '=' - && name[f] != '.' && name[f] != ',' && name[f] != ')' - && name[f] != '(' && name[f] != '[' && name[f] != ']') - { - name[f] = '_'; - } - } - return name; -} - -void ChatLogger::writeTo(std::ofstream &file, const std::string &str) const -{ - file << str << std::endl; -} - -void ChatLogger::setServerName(const std::string &serverName) -{ - mServerName = serverName; - if (mServerName == "") - mServerName = config.getStringValue("MostUsedServerName0"); - - if (mLogFile.is_open()) - mLogFile.close(); - - secureName(mServerName); - if (mLogDir != "") - { - DIR *dir = opendir((mLogDir + "/" + mServerName).c_str()); - if (!dir) - makeDir(mLogDir + "/" + mServerName); - else - closedir(dir); - } -} - -void ChatLogger::makeDir(const std::string &dir) -{ -#ifdef WIN32 - mkdir(dir.c_str()); -#else - mkdir(dir.c_str(), 0750); -#endif -} - -void ChatLogger::loadLast(std::string name, std::list &list, - unsigned n) -{ - std::ifstream logFile; - - logFile.open(strprintf("%s/%s/%s_%s.log", mLogDir.c_str(), - mServerName.c_str(), secureName(name).c_str(), - getDateString().c_str()).c_str(), std::ios::in); - - if (!logFile.is_open()) - return; - - char line[710]; - while (logFile.getline(line, 700)) - { - list.push_back(line); - if (list.size() > n) - list.pop_front(); - } - - if (logFile.is_open()) - logFile.close(); -} diff --git a/src/chatlog.h b/src/chatlog.h deleted file mode 100644 index 2e9545b04..000000000 --- a/src/chatlog.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers - * Copyright (C) 2009-2010 Andrei Karas - * - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef M_CHATLOG_H -#define M_CHATLOG_H - -#include -#include - -class ChatLogger -{ - public: - /** - * Constructor. - */ - ChatLogger(); - - /** - * Destructor, closes log file. - */ - ~ChatLogger(); - - void setLogDir(const std::string &logDir); - - /** - * Enters a message in the log. The message will be timestamped. - */ - void log(std::string str); - - void log(std::string name, std::string str); - - void loadLast(std::string name, std::list &list, - unsigned n); - - std::string getDateString() const; - - std::string secureName(std::string &str) const; - - void setServerName(const std::string &serverName); - - private: - /** - * Sets the file to log to and opens it - */ - void setLogFile(const std::string &logFilename); - - void writeTo(std::ofstream &file, const std::string &str) const; - - void makeDir(const std::string &dir); - - std::ofstream mLogFile; - std::string mLogDir; - std::string mServerName; - std::string mLogDate; -}; - -extern ChatLogger *chatLogger; - -#endif diff --git a/src/chatlogger.cpp b/src/chatlogger.cpp new file mode 100644 index 000000000..067265138 --- /dev/null +++ b/src/chatlogger.cpp @@ -0,0 +1,204 @@ +/* + * The ManaPlus Client + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "chatlogger.h" + +#include +#include +#include + +#include +#include +#include + +#ifdef WIN32 +#include +#elif defined __APPLE__ +#include +#endif + +#include "logger.h" +#include "configuration.h" + +#include "utils/stringutils.h" + +#include "debug.h" + +ChatLogger::ChatLogger() +{ +} + +ChatLogger::~ChatLogger() +{ + if (mLogFile.is_open()) + mLogFile.close(); +} + +void ChatLogger::setLogFile(const std::string &logFilename) +{ + if (mLogFile.is_open()) + mLogFile.close(); + + mLogFile.open(logFilename.c_str(), std::ios_base::app); + + if (!mLogFile.is_open()) + { + std::cout << "Warning: error while opening " << logFilename << + " for writing.\n"; + } +} + +void ChatLogger::setLogDir(const std::string &logDir) +{ + mLogDir = logDir; + + if (mLogFile.is_open()) + mLogFile.close(); + + DIR *dir = opendir(mLogDir.c_str()); + if (!dir) + makeDir(mLogDir); + else + closedir(dir); +} + +void ChatLogger::log(std::string str) +{ + std::string dateStr = getDateString(); + if (!mLogFile.is_open() || dateStr != mLogDate) + { + mLogDate = dateStr; + setLogFile(strprintf("%s/%s/#General_%s.log", mLogDir.c_str(), + mServerName.c_str(), dateStr.c_str())); + } + + str = removeColors(str); + writeTo(mLogFile, str); +} + +void ChatLogger::log(std::string name, std::string str) +{ + std::ofstream logFile; + logFile.open(strprintf("%s/%s/%s_%s.log", mLogDir.c_str(), + mServerName.c_str(), secureName(name).c_str(), + getDateString().c_str()).c_str(), std::ios_base::app); + + if (!logFile.is_open()) + return; + + str = removeColors(str); + writeTo(logFile, str); + + if (logFile.is_open()) + logFile.close(); +} + +std::string ChatLogger::getDateString() const +{ + std::string date; + + time_t rawtime; + struct tm *timeinfo; + char buffer [81]; + + time (&rawtime); + timeinfo = localtime(&rawtime); + + strftime(buffer, 79, "%y-%m-%d", timeinfo); + date = buffer; + return date; +} + +std::string ChatLogger::secureName(std::string &name) const +{ + for (unsigned int f = 0; f < name.length(); f ++) + { + if (name[f] < '0' && name[f] > '9' && name[f] < 'a' && name[f] > 'z' + && name[f] < 'A' && name[f] > 'Z' + && name[f] != '-' && name[f] != '+' && name[f] != '=' + && name[f] != '.' && name[f] != ',' && name[f] != ')' + && name[f] != '(' && name[f] != '[' && name[f] != ']') + { + name[f] = '_'; + } + } + return name; +} + +void ChatLogger::writeTo(std::ofstream &file, const std::string &str) const +{ + file << str << std::endl; +} + +void ChatLogger::setServerName(const std::string &serverName) +{ + mServerName = serverName; + if (mServerName == "") + mServerName = config.getStringValue("MostUsedServerName0"); + + if (mLogFile.is_open()) + mLogFile.close(); + + secureName(mServerName); + if (mLogDir != "") + { + DIR *dir = opendir((mLogDir + "/" + mServerName).c_str()); + if (!dir) + makeDir(mLogDir + "/" + mServerName); + else + closedir(dir); + } +} + +void ChatLogger::makeDir(const std::string &dir) +{ +#ifdef WIN32 + mkdir(dir.c_str()); +#else + mkdir(dir.c_str(), 0750); +#endif +} + +void ChatLogger::loadLast(std::string name, std::list &list, + unsigned n) +{ + std::ifstream logFile; + + logFile.open(strprintf("%s/%s/%s_%s.log", mLogDir.c_str(), + mServerName.c_str(), secureName(name).c_str(), + getDateString().c_str()).c_str(), std::ios::in); + + if (!logFile.is_open()) + return; + + char line[710]; + while (logFile.getline(line, 700)) + { + list.push_back(line); + if (list.size() > n) + list.pop_front(); + } + + if (logFile.is_open()) + logFile.close(); +} diff --git a/src/chatlogger.h b/src/chatlogger.h new file mode 100644 index 000000000..2e9545b04 --- /dev/null +++ b/src/chatlogger.h @@ -0,0 +1,79 @@ +/* + * The ManaPlus Client + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2009-2010 Andrei Karas + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef M_CHATLOG_H +#define M_CHATLOG_H + +#include +#include + +class ChatLogger +{ + public: + /** + * Constructor. + */ + ChatLogger(); + + /** + * Destructor, closes log file. + */ + ~ChatLogger(); + + void setLogDir(const std::string &logDir); + + /** + * Enters a message in the log. The message will be timestamped. + */ + void log(std::string str); + + void log(std::string name, std::string str); + + void loadLast(std::string name, std::list &list, + unsigned n); + + std::string getDateString() const; + + std::string secureName(std::string &str) const; + + void setServerName(const std::string &serverName); + + private: + /** + * Sets the file to log to and opens it + */ + void setLogFile(const std::string &logFilename); + + void writeTo(std::ofstream &file, const std::string &str) const; + + void makeDir(const std::string &dir); + + std::ofstream mLogFile; + std::string mLogDir; + std::string mServerName; + std::string mLogDate; +}; + +extern ChatLogger *chatLogger; + +#endif diff --git a/src/client.cpp b/src/client.cpp index 022bc07d5..e85c5b08f 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -23,7 +23,7 @@ #include "client.h" #include "main.h" -#include "chatlog.h" +#include "chatlogger.h" #include "configuration.h" #include "dropshortcut.h" #include "emoteshortcut.h" diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index dc9a4d1bf..f650ac8d1 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -27,7 +27,7 @@ #include "channel.h" #include "game.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "main.h" #include "gui/chatwindow.h" diff --git a/src/configuration.cpp b/src/configuration.cpp index 7d1f41fe5..2524d6b93 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -23,7 +23,7 @@ #include "configuration.h" #include "configlistener.h" -#include "log.h" +#include "logger.h" #include "utils/paths.h" #include "utils/stringutils.h" diff --git a/src/effectmanager.cpp b/src/effectmanager.cpp index bb54ced99..36e7aac16 100644 --- a/src/effectmanager.cpp +++ b/src/effectmanager.cpp @@ -21,7 +21,7 @@ #include "being.h" #include "effectmanager.h" -#include "log.h" +#include "logger.h" #include "particle.h" #include "sound.h" diff --git a/src/filefilter.txt b/src/filefilter.txt index b2b1e7d0c..0dde8e90c 100644 --- a/src/filefilter.txt +++ b/src/filefilter.txt @@ -1,5 +1,6 @@ ~ RULE_3_1_A_do_not_start_filename_with_underbar ~ RULE_3_2_CD_do_not_use_special_characters_in_filename +~ RULE_3_2_F_use_representitive_classname_for_cpp_filename ~ RULE_3_2_H_do_not_use_uppercase_for_c_filename ~ RULE_3_3_A_start_function_name_with_lowercase_unix ~ RULE_4_1_A_B_use_space_for_indentation @@ -23,3 +24,4 @@ ~ RULE_8_1_A_provide_file_info_comment ~ RULE_9_1_A_do_not_use_hardcorded_include_path ~ RULE_9_2_D_use_reentrant_function + diff --git a/src/game.cpp b/src/game.cpp index 4332c8e11..4967231b0 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -42,7 +42,7 @@ #include "joystick.h" #include "keyboardconfig.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "map.h" #include "particle.h" #include "playerrelations.h" diff --git a/src/graphics.cpp b/src/graphics.cpp index 6a6760c36..a86ac7fd0 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -25,7 +25,7 @@ #include "graphics.h" #include "graphicsvertexes.h" -#include "log.h" +#include "logger.h" #include "map.h" #include "resources/image.h" diff --git a/src/gui/changeemaildialog.cpp b/src/gui/changeemaildialog.cpp index d424fff91..c24624bc2 100644 --- a/src/gui/changeemaildialog.cpp +++ b/src/gui/changeemaildialog.cpp @@ -23,7 +23,7 @@ #include "gui/changeemaildialog.h" #include "client.h" -#include "log.h" +#include "logger.h" #include "gui/register.h" #include "gui/okdialog.h" diff --git a/src/gui/changepassworddialog.cpp b/src/gui/changepassworddialog.cpp index dc640841a..30012ae52 100644 --- a/src/gui/changepassworddialog.cpp +++ b/src/gui/changepassworddialog.cpp @@ -23,7 +23,7 @@ #include "changepassworddialog.h" #include "client.h" -#include "log.h" +#include "logger.h" #include "gui/register.h" #include "gui/okdialog.h" diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp index 264df06e3..28c7a083c 100644 --- a/src/gui/charselectdialog.cpp +++ b/src/gui/charselectdialog.cpp @@ -26,7 +26,7 @@ #include "game.h" #include "localplayer.h" #include "units.h" -#include "log.h" +#include "logger.h" #include "gui/changeemaildialog.h" #include "gui/changepassworddialog.h" diff --git a/src/gui/connectiondialog.cpp b/src/gui/connectiondialog.cpp index 157398297..da98ea5ac 100644 --- a/src/gui/connectiondialog.cpp +++ b/src/gui/connectiondialog.cpp @@ -22,7 +22,7 @@ #include "connectiondialog.h" -#include "log.h" +#include "logger.h" #include "gui/widgets/button.h" #include "gui/widgets/label.h" diff --git a/src/gui/didyouknowwindow.cpp b/src/gui/didyouknowwindow.cpp index 03188907f..4d89bd924 100644 --- a/src/gui/didyouknowwindow.cpp +++ b/src/gui/didyouknowwindow.cpp @@ -22,7 +22,7 @@ #include "gui/didyouknowwindow.h" -#include "log.h" +#include "logger.h" #include "gui/gui.h" #include "gui/setup.h" diff --git a/src/gui/emotepopup.cpp b/src/gui/emotepopup.cpp index 3a754d0e3..348a97952 100644 --- a/src/gui/emotepopup.cpp +++ b/src/gui/emotepopup.cpp @@ -28,7 +28,7 @@ #include "emoteshortcut.h" #include "graphics.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "gui/theme.h" diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 0bea1d0d7..3e4ec764f 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -35,7 +35,7 @@ #include "configlistener.h" #include "configuration.h" #include "graphics.h" -#include "log.h" +#include "logger.h" #include "resources/image.h" #include "resources/imageset.h" diff --git a/src/gui/helpwindow.cpp b/src/gui/helpwindow.cpp index ae0a432ea..368049389 100644 --- a/src/gui/helpwindow.cpp +++ b/src/gui/helpwindow.cpp @@ -22,7 +22,7 @@ #include "gui/helpwindow.h" -#include "log.h" +#include "logger.h" #include "gui/gui.h" #include "gui/setup.h" diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index 5022f9210..c735eec82 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -27,7 +27,7 @@ #include "configuration.h" #include "graphics.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "map.h" #include "gui/userpalette.h" diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp index 9dd41a643..09e75856f 100644 --- a/src/gui/outfitwindow.cpp +++ b/src/gui/outfitwindow.cpp @@ -28,7 +28,7 @@ #include "inventory.h" #include "item.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "playerinfo.h" #include "gui/chatwindow.h" diff --git a/src/gui/palette.h b/src/gui/palette.h index 9409bfc06..1cebe236f 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -24,7 +24,7 @@ #ifndef PALETTE_H #define PALETTE_H -#include "log.h" +#include "logger.h" #include "utils/stringutils.h" #include diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 14a326e41..86ddfda53 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -32,7 +32,7 @@ #include "item.h" #include "itemshortcut.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "map.h" #include "party.h" #include "playerinfo.h" diff --git a/src/gui/register.cpp b/src/gui/register.cpp index 80ddb7469..913c958f2 100644 --- a/src/gui/register.cpp +++ b/src/gui/register.cpp @@ -24,7 +24,7 @@ #include "client.h" #include "configuration.h" -#include "log.h" +#include "logger.h" #include "gui/logindialog.h" #include "gui/okdialog.h" diff --git a/src/gui/sdlfont.cpp b/src/gui/sdlfont.cpp index a0f8699f8..8dd7f929d 100644 --- a/src/gui/sdlfont.cpp +++ b/src/gui/sdlfont.cpp @@ -25,7 +25,7 @@ #include "client.h" #include "graphics.h" -#include "log.h" +#include "logger.h" #include "main.h" #include "resources/image.h" diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index 41b0076e1..37870a87f 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -22,10 +22,10 @@ #include "gui/serverdialog.h" -#include "chatlog.h" +#include "chatlogger.h" #include "client.h" #include "configuration.h" -#include "log.h" +#include "logger.h" #include "main.h" #include "gui/gui.h" diff --git a/src/gui/setup_audio.cpp b/src/gui/setup_audio.cpp index 28e6d8cfa..1737e9004 100644 --- a/src/gui/setup_audio.cpp +++ b/src/gui/setup_audio.cpp @@ -23,7 +23,7 @@ #include "gui/setup_audio.h" #include "configuration.h" -#include "log.h" +#include "logger.h" #include "sound.h" #include "gui/okdialog.h" diff --git a/src/gui/setup_chat.cpp b/src/gui/setup_chat.cpp index 621f62810..7ce44a552 100644 --- a/src/gui/setup_chat.cpp +++ b/src/gui/setup_chat.cpp @@ -37,7 +37,7 @@ #include "configuration.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "utils/gettext.h" diff --git a/src/gui/setup_other.cpp b/src/gui/setup_other.cpp index 3675da4ca..3b603a8ee 100644 --- a/src/gui/setup_other.cpp +++ b/src/gui/setup_other.cpp @@ -29,7 +29,7 @@ #include "gui/widgets/scrollarea.h" #include "configuration.h" -#include "log.h" +#include "logger.h" #include "utils/gettext.h" diff --git a/src/gui/setup_perfomance.cpp b/src/gui/setup_perfomance.cpp index eaadc7c3a..583f2909a 100644 --- a/src/gui/setup_perfomance.cpp +++ b/src/gui/setup_perfomance.cpp @@ -37,7 +37,7 @@ #include "configuration.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "utils/gettext.h" diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp index 7490135cd..d2664adbd 100644 --- a/src/gui/setup_players.cpp +++ b/src/gui/setup_players.cpp @@ -37,7 +37,7 @@ #include "configuration.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "utils/gettext.h" diff --git a/src/gui/setup_relations.cpp b/src/gui/setup_relations.cpp index 646d47550..93887b133 100644 --- a/src/gui/setup_relations.cpp +++ b/src/gui/setup_relations.cpp @@ -25,7 +25,7 @@ #include "actorspritemanager.h" #include "configuration.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "gui/editdialog.h" #include "gui/okdialog.h" diff --git a/src/gui/setup_theme.cpp b/src/gui/setup_theme.cpp index 42ed0205c..7a2c66595 100644 --- a/src/gui/setup_theme.cpp +++ b/src/gui/setup_theme.cpp @@ -37,7 +37,7 @@ #include "configuration.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "utils/gettext.h" diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 8979a81e1..03b485097 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -26,7 +26,7 @@ #include "game.h" #include "graphics.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "main.h" #include "particle.h" diff --git a/src/gui/setupitem.cpp b/src/gui/setupitem.cpp index 182501e72..defdb4005 100644 --- a/src/gui/setupitem.cpp +++ b/src/gui/setupitem.cpp @@ -22,7 +22,7 @@ #include "configuration.h" #include "main.h" -#include "log.h" +#include "logger.h" #include "gui/editdialog.h" diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index 5b47a5494..896f06cab 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -22,7 +22,7 @@ #include "gui/skilldialog.h" -#include "log.h" +#include "logger.h" #include "playerinfo.h" #include "configuration.h" diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index adcfe4d70..e3aa69b30 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -25,7 +25,7 @@ #include "guild.h" #include "keyboardconfig.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "map.h" #include "party.h" diff --git a/src/gui/specialswindow.cpp b/src/gui/specialswindow.cpp index 1c41752f3..a5d95c7ff 100644 --- a/src/gui/specialswindow.cpp +++ b/src/gui/specialswindow.cpp @@ -21,7 +21,7 @@ #include "gui/specialswindow.h" -#include "log.h" +#include "logger.h" #include "gui/setup.h" #include "gui/theme.h" diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index 92613a3b3..056eafc0f 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -26,7 +26,7 @@ #include "client.h" #include "configuration.h" -#include "log.h" +#include "logger.h" #include "resources/dye.h" #include "resources/image.h" diff --git a/src/gui/unregisterdialog.cpp b/src/gui/unregisterdialog.cpp index 8f845e746..568e0613e 100644 --- a/src/gui/unregisterdialog.cpp +++ b/src/gui/unregisterdialog.cpp @@ -23,7 +23,7 @@ #include "gui/unregisterdialog.h" #include "client.h" -#include "log.h" +#include "logger.h" #include "gui/okdialog.h" #include "gui/register.h" diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index eb5471e2a..895c99121 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -24,7 +24,7 @@ #include "client.h" #include "configuration.h" -#include "log.h" +#include "logger.h" #include "main.h" #include "gui/sdlinput.h" diff --git a/src/gui/userpalette.cpp b/src/gui/userpalette.cpp index 40dddc4f1..eac9559ef 100644 --- a/src/gui/userpalette.cpp +++ b/src/gui/userpalette.cpp @@ -25,7 +25,7 @@ #include "configuration.h" #include "client.h" -#include "log.h" +#include "logger.h" #include "gui/gui.h" diff --git a/src/gui/widgets/battletab.cpp b/src/gui/widgets/battletab.cpp index e72c78ee0..c5500e801 100644 --- a/src/gui/widgets/battletab.cpp +++ b/src/gui/widgets/battletab.cpp @@ -22,10 +22,10 @@ #include "gui/widgets/battletab.h" -#include "chatlog.h" +#include "chatlogger.h" #include "commandhandler.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "main.h" #include "gui/theme.h" diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index 140a72770..7df70bd04 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -25,7 +25,7 @@ #include "client.h" #include "graphics.h" -#include "log.h" +#include "logger.h" #include "utils/stringutils.h" diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index 0570630c3..2d9678a53 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -26,7 +26,7 @@ #include "configuration.h" #include "graphics.h" #include "graphicsvertexes.h" -#include "log.h" +#include "logger.h" #include "gui/palette.h" #include "gui/theme.h" diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index 42a39a20f..e27af8b25 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -23,11 +23,11 @@ #include "gui/widgets/chattab.h" #include "actorspritemanager.h" -#include "chatlog.h" +#include "chatlogger.h" #include "commandhandler.h" #include "configuration.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "sound.h" #include "gui/widgets/browserbox.h" diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp index 3ade3b37f..cfb757638 100644 --- a/src/gui/widgets/desktop.cpp +++ b/src/gui/widgets/desktop.cpp @@ -22,7 +22,7 @@ #include "configuration.h" #include "graphics.h" -#include "log.h" +#include "logger.h" #include "main.h" #include "gui/palette.h" diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp index bb5af4b1c..5bb972adc 100644 --- a/src/gui/widgets/emoteshortcutcontainer.cpp +++ b/src/gui/widgets/emoteshortcutcontainer.cpp @@ -29,7 +29,7 @@ #include "itemshortcut.h" #include "keyboardconfig.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "gui/palette.h" #include "gui/textpopup.h" diff --git a/src/gui/widgets/inventoryfilter.cpp b/src/gui/widgets/inventoryfilter.cpp index 563e37b8c..795f0d31e 100644 --- a/src/gui/widgets/inventoryfilter.cpp +++ b/src/gui/widgets/inventoryfilter.cpp @@ -23,7 +23,7 @@ #include "gui/widgets/horizontcontainer.h" #include "gui/widgets/radiobutton.h" -#include "log.h" +#include "logger.h" #include "debug.h" diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index 7818432f8..b79f26226 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -27,7 +27,7 @@ #include "item.h" #include "itemshortcut.h" #include "dropshortcut.h" -#include "log.h" +#include "logger.h" #include "gui/chatwindow.h" #include "gui/itempopup.h" diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp index 274c17d61..382d169dc 100644 --- a/src/gui/widgets/layout.cpp +++ b/src/gui/widgets/layout.cpp @@ -22,7 +22,7 @@ #include "gui/widgets/layout.h" -#include "log.h" +#include "logger.h" #include diff --git a/src/gui/widgets/popup.cpp b/src/gui/widgets/popup.cpp index ea51c146a..38088770b 100644 --- a/src/gui/widgets/popup.cpp +++ b/src/gui/widgets/popup.cpp @@ -26,7 +26,7 @@ #include "configuration.h" #include "graphics.h" #include "graphicsvertexes.h" -#include "log.h" +#include "logger.h" #include "gui/theme.h" #include "gui/viewport.h" diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index df39854da..08f0b5a70 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -26,7 +26,7 @@ #include "configuration.h" #include "graphics.h" #include "graphicsvertexes.h" -#include "log.h" +#include "logger.h" #include "gui/theme.h" diff --git a/src/gui/widgets/spellshortcutcontainer.cpp b/src/gui/widgets/spellshortcutcontainer.cpp index 872ed16c7..8d5b563bb 100644 --- a/src/gui/widgets/spellshortcutcontainer.cpp +++ b/src/gui/widgets/spellshortcutcontainer.cpp @@ -40,7 +40,7 @@ #include "keyboardconfig.h" #include "localplayer.h" #include "spellmanager.h" -#include "log.h" +#include "logger.h" #include "resources/image.h" #include "textcommand.h" diff --git a/src/gui/widgets/tab.cpp b/src/gui/widgets/tab.cpp index 1b548a6a3..b7d6b4458 100644 --- a/src/gui/widgets/tab.cpp +++ b/src/gui/widgets/tab.cpp @@ -26,7 +26,7 @@ #include "configuration.h" #include "graphics.h" #include "graphicsvertexes.h" -#include "log.h" +#include "logger.h" #include "gui/palette.h" #include "gui/theme.h" diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp index d3539a115..940dad12a 100644 --- a/src/gui/widgets/tabbedarea.cpp +++ b/src/gui/widgets/tabbedarea.cpp @@ -25,7 +25,7 @@ #include "gui/widgets/scrollarea.h" #include "gui/widgets/tab.h" -#include "log.h" +#include "logger.h" #include diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index d3108a77f..f80039650 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -25,7 +25,7 @@ #include "client.h" #include "configuration.h" #include "graphics.h" -#include "log.h" +#include "logger.h" #include "gui/palette.h" #include "gui/sdlinput.h" diff --git a/src/gui/widgets/tradetab.cpp b/src/gui/widgets/tradetab.cpp index 99a145d86..deec2aea6 100644 --- a/src/gui/widgets/tradetab.cpp +++ b/src/gui/widgets/tradetab.cpp @@ -22,10 +22,10 @@ #include "gui/widgets/tradetab.h" -#include "chatlog.h" +#include "chatlogger.h" #include "commandhandler.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "gui/theme.h" diff --git a/src/gui/widgets/whispertab.cpp b/src/gui/widgets/whispertab.cpp index bee30b969..c99c4e0c5 100644 --- a/src/gui/widgets/whispertab.cpp +++ b/src/gui/widgets/whispertab.cpp @@ -22,10 +22,10 @@ #include "gui/widgets/whispertab.h" -#include "chatlog.h" +#include "chatlogger.h" #include "commandhandler.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "gui/theme.h" diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 14448ea86..9a7c689e6 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -25,7 +25,7 @@ #include "client.h" #include "configuration.h" #include "graphicsvertexes.h" -#include "log.h" +#include "logger.h" #include "gui/gui.h" #include "gui/palette.h" diff --git a/src/inventory.cpp b/src/inventory.cpp index 3ff40374a..acd35efdd 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -22,7 +22,7 @@ #include "inventory.h" #include "item.h" -#include "log.h" +#include "logger.h" #include "net/inventoryhandler.h" #include "net/net.h" diff --git a/src/joystick.cpp b/src/joystick.cpp index f1255c4c0..8f808a2d1 100644 --- a/src/joystick.cpp +++ b/src/joystick.cpp @@ -22,7 +22,7 @@ #include "configuration.h" #include "joystick.h" -#include "log.h" +#include "logger.h" #include diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp index 8ad38ab76..bf58c518a 100644 --- a/src/keyboardconfig.cpp +++ b/src/keyboardconfig.cpp @@ -20,7 +20,7 @@ #include "configuration.h" #include "keyboardconfig.h" -#include "log.h" +#include "logger.h" #include "gui/sdlinput.h" #include "gui/setup_keyboard.h" diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 0310bb8ad..a9e9d1f21 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -31,7 +31,7 @@ #include "guild.h" #include "item.h" #include "keyboardconfig.h" -#include "log.h" +#include "logger.h" #include "map.h" #include "party.h" #include "particle.h" diff --git a/src/log.cpp b/src/log.cpp deleted file mode 100644 index 9bcf1ea4f..000000000 --- a/src/log.cpp +++ /dev/null @@ -1,217 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 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 . - */ - -#include -#include - -#include "log.h" - -#include "configuration.h" - -#include "gui/widgets/chattab.h" - -#ifdef WIN32 -#include -#elif defined __APPLE__ -#include -#elif __linux__ || __linux -#include -#endif - -#include - -#include "debug.h" - -Logger::Logger(): - mLogToStandardOut(true), - mChatWindow(NULL), - mDebugLog(false) -{ -} - -Logger::~Logger() -{ - if (mLogFile.is_open()) - { - mLogFile.close(); - } -} - -void Logger::setLogFile(const std::string &logFilename) -{ - if (mLogFile.is_open()) - mLogFile.close(); - - mLogFile.open(logFilename.c_str(), std::ios_base::trunc); - - if (!mLogFile.is_open()) - { - std::cout << "Warning: error while opening " << logFilename << - " for writing.\n"; - } -} - -void Logger::log(std::string str) -{ - log("%s", str.c_str()); -} - -void Logger::dlog(std::string str) -{ - if (!mDebugLog) - return; - - // Get the current system time - timeval tv; - gettimeofday(&tv, NULL); - - // Print the log entry - std::stringstream timeStr; - timeStr << "[" - << ((((tv.tv_sec / 60) / 60) % 24 < 10) ? "0" : "") - << static_cast(((tv.tv_sec / 60) / 60) % 24) - << ":" - << (((tv.tv_sec / 60) % 60 < 10) ? "0" : "") - << static_cast((tv.tv_sec / 60) % 60) - << ":" - << ((tv.tv_sec % 60 < 10) ? "0" : "") - << static_cast(tv.tv_sec % 60) - << "." - << (((tv.tv_usec / 10000) % 100) < 10 ? "0" : "") - << static_cast((tv.tv_usec / 10000) % 100) - << "] "; - - if (mLogFile.is_open()) - mLogFile << timeStr.str() << str << std::endl; - - if (mLogToStandardOut) - std::cout << timeStr.str() << str << std::endl; - - if (mChatWindow && debugChatTab) - debugChatTab->chatLog(str, BY_LOGGER); -} - -void Logger::log1(const char *buf) -{ - // Get the current system time - timeval tv; - gettimeofday(&tv, NULL); - - // Print the log entry - std::stringstream timeStr; - timeStr << "[" - << ((((tv.tv_sec / 60) / 60) % 24 < 10) ? "0" : "") - << static_cast(((tv.tv_sec / 60) / 60) % 24) - << ":" - << (((tv.tv_sec / 60) % 60 < 10) ? "0" : "") - << static_cast((tv.tv_sec / 60) % 60) - << ":" - << ((tv.tv_sec % 60 < 10) ? "0" : "") - << static_cast(tv.tv_sec % 60) - << "." - << (((tv.tv_usec / 10000) % 100) < 10 ? "0" : "") - << static_cast((tv.tv_usec / 10000) % 100) - << "] "; - - if (mLogFile.is_open()) - mLogFile << timeStr.str() << buf << std::endl; - - if (mLogToStandardOut) - std::cout << timeStr.str() << buf << std::endl; - - if (mChatWindow && debugChatTab) - debugChatTab->chatLog(buf, BY_LOGGER); -} - -void Logger::log(const char *log_text, ...) -{ - unsigned size = 1024; - char* buf = 0; - if (strlen(log_text) * 3> size) - size = static_cast(strlen(log_text) * 3); - - buf = new char[size + 1]; - va_list ap; - - // Use a temporary buffer to fill in the variables - va_start(ap, log_text); - vsnprintf(buf, size, log_text, ap); - buf[size] = 0; - va_end(ap); - - // Get the current system time - timeval tv; - gettimeofday(&tv, NULL); - - // Print the log entry - std::stringstream timeStr; - timeStr << "[" - << ((((tv.tv_sec / 60) / 60) % 24 < 10) ? "0" : "") - << static_cast(((tv.tv_sec / 60) / 60) % 24) - << ":" - << (((tv.tv_sec / 60) % 60 < 10) ? "0" : "") - << static_cast((tv.tv_sec / 60) % 60) - << ":" - << ((tv.tv_sec % 60 < 10) ? "0" : "") - << static_cast(tv.tv_sec % 60) - << "." - << (((tv.tv_usec / 10000) % 100) < 10 ? "0" : "") - << static_cast((tv.tv_usec / 10000) % 100) - << "] "; - - if (mLogFile.is_open()) - mLogFile << timeStr.str() << buf << std::endl; - - if (mLogToStandardOut) - std::cout << timeStr.str() << buf << std::endl; - - if (mChatWindow && debugChatTab) - debugChatTab->chatLog(buf, BY_LOGGER); - - // Delete temporary buffer - delete[] buf; -} - -void Logger::error(const std::string &error_text) -{ - log("Error: %s", error_text.c_str()); -#ifdef WIN32 - MessageBox(NULL, error_text.c_str(), "Error", MB_ICONERROR | MB_OK); -#elif defined __APPLE__ -// Str255 msg; -// CFStringRef error; -// error = CFStringCreateWithCString(NULL, -// error_text.c_str(), -// kCFStringEncodingMacRoman); -// CFStringGetPascalString(error, msg, 255, kCFStringEncodingMacRoman); -// StandardAlert(kAlertStopAlert, -// (const unsigned char*)"\pError", -// (ConstStr255Param) msg, NULL, NULL); -#elif defined __linux__ || __linux - std::cerr << "Error: " << error_text << std::endl; - std::string msg = "xmessage \"" + error_text + "\""; - system(msg.c_str()); -#else - std::cerr << "Error: " << error_text << std::endl; -#endif - exit(1); -} diff --git a/src/log.h b/src/log.h deleted file mode 100644 index b8517f696..000000000 --- a/src/log.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 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 . - */ - -#ifndef M_LOG_H -#define M_LOG_H - -#include "main.h" -#include - -class ChatWindow; - -#ifdef ENABLEDEBUGLOG -#define DEBUGLOG(msg) logger->dlog(msg) -#else -#define DEBUGLOG(msg) {} -#endif - -/** - * The Log Class : Useful to write debug or info messages - */ -class Logger -{ - public: - /** - * Constructor. - */ - Logger(); - - /** - * Destructor, closes log file. - */ - ~Logger(); - - /** - * Sets the file to log to and opens it - */ - void setLogFile(const std::string &logFilename); - - /** - * Sets whether the log should be written to standard output. - */ - void setLogToStandardOut(bool value) { mLogToStandardOut = value; } - - /** - * Enables logging to chat window - */ - void setChatWindow(ChatWindow *window) { mChatWindow = window; } - - /** - * Enters a message in the log. The message will be timestamped. - */ - void log(const char *log_text, ...) -#ifdef __GNUC__ - __attribute__((__format__(__printf__, 2, 3))) -#endif - ; - - /** - * Enters a message in the log. The message will be timestamped. - */ - void log1(const char *log_text); - - /** - * Enters a message in the log. The message will be timestamped. - */ - void log(std::string str); - - /** - * Enters debug message in the log. The message will be timestamped. - */ - void dlog(std::string str); - - void setDebugLog(bool n) - { mDebugLog = n; } - - /** - * Log an error and quit. The error will pop-up on Windows and Mac, and - * will be printed to standard error everywhere else. - */ - void error(const std::string &error_text) __attribute__ ((noreturn)); - - private: - std::ofstream mLogFile; - bool mLogToStandardOut; - ChatWindow *mChatWindow; - bool mDebugLog; -}; - -extern Logger *logger; - -#endif diff --git a/src/logger.cpp b/src/logger.cpp new file mode 100644 index 000000000..6790d622a --- /dev/null +++ b/src/logger.cpp @@ -0,0 +1,217 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 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 . + */ + +#include +#include + +#include "logger.h" + +#include "configuration.h" + +#include "gui/widgets/chattab.h" + +#ifdef WIN32 +#include +#elif defined __APPLE__ +#include +#elif __linux__ || __linux +#include +#endif + +#include + +#include "debug.h" + +Logger::Logger(): + mLogToStandardOut(true), + mChatWindow(NULL), + mDebugLog(false) +{ +} + +Logger::~Logger() +{ + if (mLogFile.is_open()) + { + mLogFile.close(); + } +} + +void Logger::setLogFile(const std::string &logFilename) +{ + if (mLogFile.is_open()) + mLogFile.close(); + + mLogFile.open(logFilename.c_str(), std::ios_base::trunc); + + if (!mLogFile.is_open()) + { + std::cout << "Warning: error while opening " << logFilename << + " for writing.\n"; + } +} + +void Logger::log(std::string str) +{ + log("%s", str.c_str()); +} + +void Logger::dlog(std::string str) +{ + if (!mDebugLog) + return; + + // Get the current system time + timeval tv; + gettimeofday(&tv, NULL); + + // Print the log entry + std::stringstream timeStr; + timeStr << "[" + << ((((tv.tv_sec / 60) / 60) % 24 < 10) ? "0" : "") + << static_cast(((tv.tv_sec / 60) / 60) % 24) + << ":" + << (((tv.tv_sec / 60) % 60 < 10) ? "0" : "") + << static_cast((tv.tv_sec / 60) % 60) + << ":" + << ((tv.tv_sec % 60 < 10) ? "0" : "") + << static_cast(tv.tv_sec % 60) + << "." + << (((tv.tv_usec / 10000) % 100) < 10 ? "0" : "") + << static_cast((tv.tv_usec / 10000) % 100) + << "] "; + + if (mLogFile.is_open()) + mLogFile << timeStr.str() << str << std::endl; + + if (mLogToStandardOut) + std::cout << timeStr.str() << str << std::endl; + + if (mChatWindow && debugChatTab) + debugChatTab->chatLog(str, BY_LOGGER); +} + +void Logger::log1(const char *buf) +{ + // Get the current system time + timeval tv; + gettimeofday(&tv, NULL); + + // Print the log entry + std::stringstream timeStr; + timeStr << "[" + << ((((tv.tv_sec / 60) / 60) % 24 < 10) ? "0" : "") + << static_cast(((tv.tv_sec / 60) / 60) % 24) + << ":" + << (((tv.tv_sec / 60) % 60 < 10) ? "0" : "") + << static_cast((tv.tv_sec / 60) % 60) + << ":" + << ((tv.tv_sec % 60 < 10) ? "0" : "") + << static_cast(tv.tv_sec % 60) + << "." + << (((tv.tv_usec / 10000) % 100) < 10 ? "0" : "") + << static_cast((tv.tv_usec / 10000) % 100) + << "] "; + + if (mLogFile.is_open()) + mLogFile << timeStr.str() << buf << std::endl; + + if (mLogToStandardOut) + std::cout << timeStr.str() << buf << std::endl; + + if (mChatWindow && debugChatTab) + debugChatTab->chatLog(buf, BY_LOGGER); +} + +void Logger::log(const char *log_text, ...) +{ + unsigned size = 1024; + char* buf = 0; + if (strlen(log_text) * 3> size) + size = static_cast(strlen(log_text) * 3); + + buf = new char[size + 1]; + va_list ap; + + // Use a temporary buffer to fill in the variables + va_start(ap, log_text); + vsnprintf(buf, size, log_text, ap); + buf[size] = 0; + va_end(ap); + + // Get the current system time + timeval tv; + gettimeofday(&tv, NULL); + + // Print the log entry + std::stringstream timeStr; + timeStr << "[" + << ((((tv.tv_sec / 60) / 60) % 24 < 10) ? "0" : "") + << static_cast(((tv.tv_sec / 60) / 60) % 24) + << ":" + << (((tv.tv_sec / 60) % 60 < 10) ? "0" : "") + << static_cast((tv.tv_sec / 60) % 60) + << ":" + << ((tv.tv_sec % 60 < 10) ? "0" : "") + << static_cast(tv.tv_sec % 60) + << "." + << (((tv.tv_usec / 10000) % 100) < 10 ? "0" : "") + << static_cast((tv.tv_usec / 10000) % 100) + << "] "; + + if (mLogFile.is_open()) + mLogFile << timeStr.str() << buf << std::endl; + + if (mLogToStandardOut) + std::cout << timeStr.str() << buf << std::endl; + + if (mChatWindow && debugChatTab) + debugChatTab->chatLog(buf, BY_LOGGER); + + // Delete temporary buffer + delete[] buf; +} + +void Logger::error(const std::string &error_text) +{ + log("Error: %s", error_text.c_str()); +#ifdef WIN32 + MessageBox(NULL, error_text.c_str(), "Error", MB_ICONERROR | MB_OK); +#elif defined __APPLE__ +// Str255 msg; +// CFStringRef error; +// error = CFStringCreateWithCString(NULL, +// error_text.c_str(), +// kCFStringEncodingMacRoman); +// CFStringGetPascalString(error, msg, 255, kCFStringEncodingMacRoman); +// StandardAlert(kAlertStopAlert, +// (const unsigned char*)"\pError", +// (ConstStr255Param) msg, NULL, NULL); +#elif defined __linux__ || __linux + std::cerr << "Error: " << error_text << std::endl; + std::string msg = "xmessage \"" + error_text + "\""; + system(msg.c_str()); +#else + std::cerr << "Error: " << error_text << std::endl; +#endif + exit(1); +} diff --git a/src/logger.h b/src/logger.h new file mode 100644 index 000000000..b8517f696 --- /dev/null +++ b/src/logger.h @@ -0,0 +1,110 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 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 . + */ + +#ifndef M_LOG_H +#define M_LOG_H + +#include "main.h" +#include + +class ChatWindow; + +#ifdef ENABLEDEBUGLOG +#define DEBUGLOG(msg) logger->dlog(msg) +#else +#define DEBUGLOG(msg) {} +#endif + +/** + * The Log Class : Useful to write debug or info messages + */ +class Logger +{ + public: + /** + * Constructor. + */ + Logger(); + + /** + * Destructor, closes log file. + */ + ~Logger(); + + /** + * Sets the file to log to and opens it + */ + void setLogFile(const std::string &logFilename); + + /** + * Sets whether the log should be written to standard output. + */ + void setLogToStandardOut(bool value) { mLogToStandardOut = value; } + + /** + * Enables logging to chat window + */ + void setChatWindow(ChatWindow *window) { mChatWindow = window; } + + /** + * Enters a message in the log. The message will be timestamped. + */ + void log(const char *log_text, ...) +#ifdef __GNUC__ + __attribute__((__format__(__printf__, 2, 3))) +#endif + ; + + /** + * Enters a message in the log. The message will be timestamped. + */ + void log1(const char *log_text); + + /** + * Enters a message in the log. The message will be timestamped. + */ + void log(std::string str); + + /** + * Enters debug message in the log. The message will be timestamped. + */ + void dlog(std::string str); + + void setDebugLog(bool n) + { mDebugLog = n; } + + /** + * Log an error and quit. The error will pop-up on Windows and Mac, and + * will be printed to standard error everywhere else. + */ + void error(const std::string &error_text) __attribute__ ((noreturn)); + + private: + std::ofstream mLogFile; + bool mLogToStandardOut; + ChatWindow *mChatWindow; + bool mDebugLog; +}; + +extern Logger *logger; + +#endif diff --git a/src/main.cpp b/src/main.cpp index faeedadaa..5c13b10ec 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,7 +25,7 @@ #include "utils/gettext.h" #include "client.h" -#include "log.h" +#include "logger.h" #include diff --git a/src/map.cpp b/src/map.cpp index 8225aded1..700f6d0d2 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -27,7 +27,7 @@ #include "configuration.h" #include "graphics.h" #include "graphicsvertexes.h" -#include "log.h" +#include "logger.h" #include "particle.h" #include "simpleanimation.h" #include "tileset.h" diff --git a/src/mumblemanager.cpp b/src/mumblemanager.cpp index 456606406..a9a8146b6 100644 --- a/src/mumblemanager.cpp +++ b/src/mumblemanager.cpp @@ -3,7 +3,7 @@ #include "mumblemanager.h" #include "configuration.h" -#include "log.h" +#include "logger.h" #include "utils/mathutils.h" diff --git a/src/net/download.cpp b/src/net/download.cpp index c93f33c21..93417197e 100644 --- a/src/net/download.cpp +++ b/src/net/download.cpp @@ -22,7 +22,7 @@ #include "net/download.h" #include "configuration.h" -#include "log.h" +#include "logger.h" #include "main.h" #include "utils/stringutils.h" diff --git a/src/net/ea/beinghandler.cpp b/src/net/ea/beinghandler.cpp index ee070593f..06e86f8a4 100644 --- a/src/net/ea/beinghandler.cpp +++ b/src/net/ea/beinghandler.cpp @@ -31,7 +31,7 @@ #include "guild.h" #include "keyboardconfig.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "party.h" #include "playerrelations.h" #include "configuration.h" diff --git a/src/net/ea/charserverhandler.cpp b/src/net/ea/charserverhandler.cpp index c69d8a5be..a0e5b392a 100644 --- a/src/net/ea/charserverhandler.cpp +++ b/src/net/ea/charserverhandler.cpp @@ -23,7 +23,7 @@ #include "net/ea/charserverhandler.h" #include "client.h" -#include "log.h" +#include "logger.h" #include "gui/charcreatedialog.h" #include "gui/okdialog.h" diff --git a/src/net/ea/chathandler.cpp b/src/net/ea/chathandler.cpp index ea9d17798..c188a2204 100644 --- a/src/net/ea/chathandler.cpp +++ b/src/net/ea/chathandler.cpp @@ -27,7 +27,7 @@ #include "configuration.h" #include "localplayer.h" #include "playerrelations.h" -#include "log.h" +#include "logger.h" #include "gui/chatwindow.h" #include "gui/shopwindow.h" diff --git a/src/net/ea/gamehandler.cpp b/src/net/ea/gamehandler.cpp index 0b6b8a040..04c13572f 100644 --- a/src/net/ea/gamehandler.cpp +++ b/src/net/ea/gamehandler.cpp @@ -26,7 +26,7 @@ #include "event.h" #include "game.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "gui/okdialog.h" diff --git a/src/net/ea/gui/guildtab.cpp b/src/net/ea/gui/guildtab.cpp index 037885fd1..ab030be83 100644 --- a/src/net/ea/gui/guildtab.cpp +++ b/src/net/ea/gui/guildtab.cpp @@ -22,7 +22,7 @@ #include "net/ea/gui/guildtab.h" -#include "chatlog.h" +#include "chatlogger.h" #include "commandhandler.h" #include "guild.h" #include "localplayer.h" diff --git a/src/net/ea/gui/partytab.cpp b/src/net/ea/gui/partytab.cpp index 02e0910a7..23eab361c 100644 --- a/src/net/ea/gui/partytab.cpp +++ b/src/net/ea/gui/partytab.cpp @@ -22,7 +22,7 @@ #include "net/ea/gui/partytab.h" -#include "chatlog.h" +#include "chatlogger.h" #include "commandhandler.h" #include "localplayer.h" #include "party.h" diff --git a/src/net/ea/guildhandler.cpp b/src/net/ea/guildhandler.cpp index bb5cbe94b..0210a76ff 100644 --- a/src/net/ea/guildhandler.cpp +++ b/src/net/ea/guildhandler.cpp @@ -25,7 +25,7 @@ #include "guild.h" #include "event.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "gui/socialwindow.h" diff --git a/src/net/ea/inventoryhandler.cpp b/src/net/ea/inventoryhandler.cpp index 2e52b85ff..d921b5e2a 100644 --- a/src/net/ea/inventoryhandler.cpp +++ b/src/net/ea/inventoryhandler.cpp @@ -24,7 +24,7 @@ #include "inventory.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "gui/ministatus.h" diff --git a/src/net/ea/inventoryhandler.h b/src/net/ea/inventoryhandler.h index 1f1f8d296..4be4ddaa6 100644 --- a/src/net/ea/inventoryhandler.h +++ b/src/net/ea/inventoryhandler.h @@ -25,7 +25,7 @@ #include "equipment.h" #include "inventory.h" -#include "log.h" +#include "logger.h" #include "playerinfo.h" #include "gui/inventorywindow.h" diff --git a/src/net/ea/loginhandler.cpp b/src/net/ea/loginhandler.cpp index 51502895c..9f7a5f07d 100644 --- a/src/net/ea/loginhandler.cpp +++ b/src/net/ea/loginhandler.cpp @@ -23,7 +23,7 @@ #include "net/ea/loginhandler.h" #include "client.h" -#include "log.h" +#include "logger.h" #include "configuration.h" #include "utils/dtor.h" diff --git a/src/net/ea/partyhandler.cpp b/src/net/ea/partyhandler.cpp index f720f9f96..045a2332b 100644 --- a/src/net/ea/partyhandler.cpp +++ b/src/net/ea/partyhandler.cpp @@ -22,7 +22,7 @@ #include "actorspritemanager.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "gui/socialwindow.h" diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp index 05b6cf9e3..4198c14ad 100644 --- a/src/net/ea/playerhandler.cpp +++ b/src/net/ea/playerhandler.cpp @@ -22,7 +22,7 @@ #include "net/ea/playerhandler.h" -#include "log.h" +#include "logger.h" #include "party.h" #include "playerinfo.h" #include "units.h" diff --git a/src/net/ea/specialhandler.cpp b/src/net/ea/specialhandler.cpp index 33fea3b27..4f0f22aed 100644 --- a/src/net/ea/specialhandler.cpp +++ b/src/net/ea/specialhandler.cpp @@ -22,7 +22,7 @@ #include "net/ea/specialhandler.h" -#include "log.h" +#include "logger.h" #include "localplayer.h" #include "playerinfo.h" diff --git a/src/net/ea/tradehandler.cpp b/src/net/ea/tradehandler.cpp index 36a5f8811..a03782db2 100644 --- a/src/net/ea/tradehandler.cpp +++ b/src/net/ea/tradehandler.cpp @@ -25,7 +25,7 @@ #include "event.h" #include "inventory.h" #include "item.h" -#include "log.h" +#include "logger.h" #include "playerinfo.h" #include "playerrelations.h" diff --git a/src/net/manaserv/attributes.cpp b/src/net/manaserv/attributes.cpp index b48cc9eff..25c75f9d8 100644 --- a/src/net/manaserv/attributes.cpp +++ b/src/net/manaserv/attributes.cpp @@ -21,7 +21,7 @@ #include "net/manaserv/attributes.h" -#include "log.h" +#include "logger.h" #include "playerinfo.h" #include "gui/statuswindow.h" diff --git a/src/net/manaserv/beinghandler.cpp b/src/net/manaserv/beinghandler.cpp index 23aae1f56..d14cdcadf 100644 --- a/src/net/manaserv/beinghandler.cpp +++ b/src/net/manaserv/beinghandler.cpp @@ -27,7 +27,7 @@ #include "client.h" #include "game.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "particle.h" #include "gui/okdialog.h" diff --git a/src/net/manaserv/charhandler.cpp b/src/net/manaserv/charhandler.cpp index c2611c64b..3b2306feb 100644 --- a/src/net/manaserv/charhandler.cpp +++ b/src/net/manaserv/charhandler.cpp @@ -24,7 +24,7 @@ #include "client.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "gui/charcreatedialog.h" #include "gui/okdialog.h" diff --git a/src/net/manaserv/connection.cpp b/src/net/manaserv/connection.cpp index 7f51aeb98..33d6f28cf 100644 --- a/src/net/manaserv/connection.cpp +++ b/src/net/manaserv/connection.cpp @@ -22,7 +22,7 @@ #include "net/manaserv/connection.h" -#include "log.h" +#include "logger.h" #include "net/manaserv/internal.h" #include "net/manaserv/messageout.h" diff --git a/src/net/manaserv/effecthandler.cpp b/src/net/manaserv/effecthandler.cpp index 3979a0fde..92cf66302 100644 --- a/src/net/manaserv/effecthandler.cpp +++ b/src/net/manaserv/effecthandler.cpp @@ -24,7 +24,7 @@ #include "actorspritemanager.h" #include "effectmanager.h" -#include "log.h" +#include "logger.h" #include "net/messagein.h" diff --git a/src/net/manaserv/guildhandler.cpp b/src/net/manaserv/guildhandler.cpp index dc3dbc616..306a15be4 100644 --- a/src/net/manaserv/guildhandler.cpp +++ b/src/net/manaserv/guildhandler.cpp @@ -24,7 +24,7 @@ #include "event.h" #include "guild.h" -#include "log.h" +#include "logger.h" #include "localplayer.h" #include "channel.h" #include "channelmanager.h" diff --git a/src/net/manaserv/inventoryhandler.cpp b/src/net/manaserv/inventoryhandler.cpp index 5e38354fb..ce837b5e1 100644 --- a/src/net/manaserv/inventoryhandler.cpp +++ b/src/net/manaserv/inventoryhandler.cpp @@ -38,7 +38,7 @@ #include "resources/iteminfo.h" -#include "log.h" // <<< REMOVE ME! +#include "logger.h" // <<< REMOVE ME! extern Net::InventoryHandler *inventoryHandler; diff --git a/src/net/manaserv/itemhandler.cpp b/src/net/manaserv/itemhandler.cpp index 0afd12d21..89826a33f 100644 --- a/src/net/manaserv/itemhandler.cpp +++ b/src/net/manaserv/itemhandler.cpp @@ -29,7 +29,7 @@ #include "game.h" #include "map.h" -#include "log.h" +#include "logger.h" namespace ManaServ { diff --git a/src/net/manaserv/loginhandler.cpp b/src/net/manaserv/loginhandler.cpp index e6109ca28..bf823562f 100644 --- a/src/net/manaserv/loginhandler.cpp +++ b/src/net/manaserv/loginhandler.cpp @@ -23,7 +23,7 @@ #include "net/manaserv/loginhandler.h" #include "client.h" -#include "log.h" +#include "logger.h" #include "net/logindata.h" diff --git a/src/net/manaserv/network.cpp b/src/net/manaserv/network.cpp index e0ab7af78..53e83e4ec 100644 --- a/src/net/manaserv/network.cpp +++ b/src/net/manaserv/network.cpp @@ -22,7 +22,7 @@ #include "net/manaserv/network.h" -#include "log.h" +#include "logger.h" #include "net/manaserv/connection.h" #include "net/manaserv/internal.h" diff --git a/src/net/manaserv/partyhandler.cpp b/src/net/manaserv/partyhandler.cpp index 0e6af4578..987a40dc5 100644 --- a/src/net/manaserv/partyhandler.cpp +++ b/src/net/manaserv/partyhandler.cpp @@ -23,7 +23,7 @@ #include "net/manaserv/partyhandler.h" #include "event.h" -#include "log.h" +#include "logger.h" #include "localplayer.h" #include "gui/socialwindow.h" diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp index ca7fe511f..3dfddb436 100644 --- a/src/net/manaserv/playerhandler.cpp +++ b/src/net/manaserv/playerhandler.cpp @@ -27,7 +27,7 @@ #include "effectmanager.h" #include "game.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "particle.h" #include "playerinfo.h" #include "configuration.h" diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp index 8b5f2eee3..5bfeefdb6 100644 --- a/src/net/messagein.cpp +++ b/src/net/messagein.cpp @@ -24,7 +24,7 @@ #include "net/packetcounters.h" -#include "log.h" +#include "logger.h" #include "net.h" #include "utils/stringutils.h" diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp index 3cdcb42e0..a8b66f5ae 100644 --- a/src/net/messageout.cpp +++ b/src/net/messageout.cpp @@ -24,7 +24,7 @@ #include "net/packetcounters.h" -#include "log.h" +#include "logger.h" #include "utils/stringutils.h" diff --git a/src/net/tmwa/adminhandler.cpp b/src/net/tmwa/adminhandler.cpp index a0d996dbf..a332b04fa 100644 --- a/src/net/tmwa/adminhandler.cpp +++ b/src/net/tmwa/adminhandler.cpp @@ -28,7 +28,7 @@ #include "being.h" #include "event.h" #include "game.h" -#include "log.h" +#include "logger.h" #include "playerrelations.h" #include "net/chathandler.h" diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp index d6f67f716..17503a406 100644 --- a/src/net/tmwa/beinghandler.cpp +++ b/src/net/tmwa/beinghandler.cpp @@ -29,7 +29,7 @@ #include "guild.h" #include "keyboardconfig.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "party.h" #include "playerrelations.h" #include "configuration.h" diff --git a/src/net/tmwa/charserverhandler.cpp b/src/net/tmwa/charserverhandler.cpp index fe803dc62..7aa68e617 100644 --- a/src/net/tmwa/charserverhandler.cpp +++ b/src/net/tmwa/charserverhandler.cpp @@ -24,7 +24,7 @@ #include "client.h" #include "configuration.h" -#include "log.h" +#include "logger.h" #include "gui/charcreatedialog.h" diff --git a/src/net/tmwa/chathandler.cpp b/src/net/tmwa/chathandler.cpp index 0f23f6412..90acf0f90 100644 --- a/src/net/tmwa/chathandler.cpp +++ b/src/net/tmwa/chathandler.cpp @@ -29,7 +29,7 @@ #include "game.h" #include "localplayer.h" #include "playerrelations.h" -#include "log.h" +#include "logger.h" #include "gui/chatwindow.h" #include "gui/shopwindow.h" diff --git a/src/net/tmwa/gamehandler.cpp b/src/net/tmwa/gamehandler.cpp index cc0a37c57..242e9f9de 100644 --- a/src/net/tmwa/gamehandler.cpp +++ b/src/net/tmwa/gamehandler.cpp @@ -26,7 +26,7 @@ #include "event.h" #include "game.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "net/messagein.h" #include "net/messageout.h" diff --git a/src/net/tmwa/generalhandler.cpp b/src/net/tmwa/generalhandler.cpp index 3e46fa66b..746cb6620 100644 --- a/src/net/tmwa/generalhandler.cpp +++ b/src/net/tmwa/generalhandler.cpp @@ -24,7 +24,7 @@ #include "client.h" #include "configuration.h" -#include "log.h" +#include "logger.h" #include "gui/charselectdialog.h" #include "gui/inventorywindow.h" diff --git a/src/net/tmwa/gui/guildtab.cpp b/src/net/tmwa/gui/guildtab.cpp index 99b775089..05a93bff8 100644 --- a/src/net/tmwa/gui/guildtab.cpp +++ b/src/net/tmwa/gui/guildtab.cpp @@ -22,7 +22,7 @@ #include "net/tmwa/gui/guildtab.h" -#include "chatlog.h" +#include "chatlogger.h" #include "commandhandler.h" #include "guild.h" #include "localplayer.h" diff --git a/src/net/tmwa/gui/partytab.cpp b/src/net/tmwa/gui/partytab.cpp index d15f4754f..373fcca31 100644 --- a/src/net/tmwa/gui/partytab.cpp +++ b/src/net/tmwa/gui/partytab.cpp @@ -22,7 +22,7 @@ #include "net/tmwa/gui/partytab.h" -#include "chatlog.h" +#include "chatlogger.h" #include "commandhandler.h" #include "localplayer.h" #include "party.h" diff --git a/src/net/tmwa/guildhandler.cpp b/src/net/tmwa/guildhandler.cpp index 43583971f..640a6fd78 100644 --- a/src/net/tmwa/guildhandler.cpp +++ b/src/net/tmwa/guildhandler.cpp @@ -23,7 +23,7 @@ #include "actorspritemanager.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "playerinfo.h" #include "net/tmwa/messagein.h" diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp index ae79f6842..14a15e59f 100644 --- a/src/net/tmwa/inventoryhandler.cpp +++ b/src/net/tmwa/inventoryhandler.cpp @@ -22,7 +22,7 @@ #include "net/tmwa/inventoryhandler.h" -#include "log.h" +#include "logger.h" #include "net/messagein.h" diff --git a/src/net/tmwa/inventoryhandler.h b/src/net/tmwa/inventoryhandler.h index 405bacc43..9a0978bd0 100644 --- a/src/net/tmwa/inventoryhandler.h +++ b/src/net/tmwa/inventoryhandler.h @@ -23,7 +23,7 @@ #ifndef NET_TA_INVENTORYHANDLER_H #define NET_TA_INVENTORYHANDLER_H -#include "log.h" +#include "logger.h" #include "net/net.h" diff --git a/src/net/tmwa/loginhandler.cpp b/src/net/tmwa/loginhandler.cpp index 15ed2f27c..029c379a0 100644 --- a/src/net/tmwa/loginhandler.cpp +++ b/src/net/tmwa/loginhandler.cpp @@ -23,7 +23,7 @@ #include "net/tmwa/loginhandler.h" #include "client.h" -#include "log.h" +#include "logger.h" #include "configuration.h" #include "net/messagein.h" diff --git a/src/net/tmwa/messagein.cpp b/src/net/tmwa/messagein.cpp index 6e2fcc187..fb1986597 100644 --- a/src/net/tmwa/messagein.cpp +++ b/src/net/tmwa/messagein.cpp @@ -24,7 +24,7 @@ #include "net/packetcounters.h" -#include "log.h" +#include "logger.h" #include "utils/stringutils.h" diff --git a/src/net/tmwa/messageout.cpp b/src/net/tmwa/messageout.cpp index a904b6bbb..6071e0ab6 100644 --- a/src/net/tmwa/messageout.cpp +++ b/src/net/tmwa/messageout.cpp @@ -26,7 +26,7 @@ #include "net/tmwa/network.h" -#include "log.h" +#include "logger.h" #include "utils/stringutils.h" diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp index c2049d3cc..8ecf04d36 100644 --- a/src/net/tmwa/network.cpp +++ b/src/net/tmwa/network.cpp @@ -22,7 +22,7 @@ #include "net/tmwa/network.h" -#include "log.h" +#include "logger.h" #include "net/messagehandler.h" #include "net/messagein.h" diff --git a/src/net/tmwa/partyhandler.cpp b/src/net/tmwa/partyhandler.cpp index 5bbf8baf3..7f942a206 100644 --- a/src/net/tmwa/partyhandler.cpp +++ b/src/net/tmwa/partyhandler.cpp @@ -22,7 +22,7 @@ #include "actorspritemanager.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "net/messagein.h" diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index f20ea64a0..c34c661e8 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -22,7 +22,7 @@ #include "net/tmwa/playerhandler.h" -#include "log.h" +#include "logger.h" #include "net/messagein.h" diff --git a/src/net/tmwa/specialhandler.cpp b/src/net/tmwa/specialhandler.cpp index b175368bd..509c5ecd1 100644 --- a/src/net/tmwa/specialhandler.cpp +++ b/src/net/tmwa/specialhandler.cpp @@ -22,7 +22,7 @@ #include "net/tmwa/specialhandler.h" -#include "log.h" +#include "logger.h" #include "net/messagein.h" diff --git a/src/net/tmwa/tradehandler.cpp b/src/net/tmwa/tradehandler.cpp index 108b544a0..2280079ea 100644 --- a/src/net/tmwa/tradehandler.cpp +++ b/src/net/tmwa/tradehandler.cpp @@ -23,7 +23,7 @@ #include "net/tmwa/tradehandler.h" #include "item.h" -#include "log.h" +#include "logger.h" #include "playerinfo.h" #include "net/messagein.h" diff --git a/src/opengl1graphics.cpp b/src/opengl1graphics.cpp index d40784aff..e93066b96 100644 --- a/src/opengl1graphics.cpp +++ b/src/opengl1graphics.cpp @@ -26,7 +26,7 @@ #include "opengl1graphics.h" #include "graphicsvertexes.h" -#include "log.h" +#include "logger.h" #include "resources/image.h" diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index 6081fa6b3..f918a5c0d 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -26,7 +26,7 @@ #include "graphicsvertexes.h" #include "openglgraphics.h" -#include "log.h" +#include "logger.h" #include "resources/image.h" diff --git a/src/particle.cpp b/src/particle.cpp index eca9307ea..7d7a73e9a 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -27,7 +27,7 @@ #include "configuration.h" #include "resources/dye.h" #include "imageparticle.h" -#include "log.h" +#include "logger.h" #include "map.h" #include "particle.h" #include "particleemitter.h" diff --git a/src/particleemitter.cpp b/src/particleemitter.cpp index c04b1b36f..caa48a795 100644 --- a/src/particleemitter.cpp +++ b/src/particleemitter.cpp @@ -22,7 +22,7 @@ #include "animationparticle.h" #include "imageparticle.h" -#include "log.h" +#include "logger.h" #include "particle.h" #include "particleemitter.h" #include "rotationalparticle.h" diff --git a/src/playerinfo.cpp b/src/playerinfo.cpp index 72b091244..3bb196921 100644 --- a/src/playerinfo.cpp +++ b/src/playerinfo.cpp @@ -26,7 +26,7 @@ #include "event.h" #include "inventory.h" #include "listener.h" -#include "log.h" +#include "logger.h" #include "resources/itemdb.h" #include "resources/iteminfo.h" diff --git a/src/properties.h b/src/properties.h index c65e30c22..19354b9ab 100644 --- a/src/properties.h +++ b/src/properties.h @@ -23,7 +23,7 @@ #ifndef PROPERTIES_H #define PROPERTIES_H -#include "log.h" +#include "logger.h" #include #include #include diff --git a/src/resources/animation.cpp b/src/resources/animation.cpp index ea7f44199..32b57b3b1 100644 --- a/src/resources/animation.cpp +++ b/src/resources/animation.cpp @@ -22,7 +22,7 @@ #include "resources/animation.h" -#include "log.h" +#include "logger.h" #include "utils/dtor.h" diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp index 6b4f57d81..8beea420d 100644 --- a/src/resources/beinginfo.cpp +++ b/src/resources/beinginfo.cpp @@ -22,7 +22,7 @@ #include "resources/beinginfo.h" -#include "log.h" +#include "logger.h" #include "utils/dtor.h" #include "utils/gettext.h" diff --git a/src/resources/colordb.cpp b/src/resources/colordb.cpp index 72a5e4023..ed8c934dc 100644 --- a/src/resources/colordb.cpp +++ b/src/resources/colordb.cpp @@ -21,7 +21,7 @@ #include "resources/colordb.h" #include "client.h" -#include "log.h" +#include "logger.h" #include "utils/xml.h" diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp index fe7d4bcac..a782b6ec1 100644 --- a/src/resources/dye.cpp +++ b/src/resources/dye.cpp @@ -22,7 +22,7 @@ #include "resources/dye.h" -#include "log.h" +#include "logger.h" #include #include diff --git a/src/resources/emotedb.cpp b/src/resources/emotedb.cpp index 85a2993dd..b7f7d7901 100644 --- a/src/resources/emotedb.cpp +++ b/src/resources/emotedb.cpp @@ -21,7 +21,7 @@ #include "resources/emotedb.h" #include "animatedsprite.h" -#include "log.h" +#include "logger.h" #include "utils/xml.h" #include "configuration.h" diff --git a/src/resources/image.cpp b/src/resources/image.cpp index b1f83e258..802f2ee12 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -31,7 +31,7 @@ #endif #include "client.h" -#include "log.h" +#include "logger.h" #include "main.h" #include "utils/stringutils.h" diff --git a/src/resources/imageset.cpp b/src/resources/imageset.cpp index 1d41c6e63..5cf3e7d82 100644 --- a/src/resources/imageset.cpp +++ b/src/resources/imageset.cpp @@ -22,7 +22,7 @@ #include "resources/imageset.h" -#include "log.h" +#include "logger.h" #include "resources/image.h" diff --git a/src/resources/imagewriter.cpp b/src/resources/imagewriter.cpp index 5d0bd9d94..e6f3c8c27 100644 --- a/src/resources/imagewriter.cpp +++ b/src/resources/imagewriter.cpp @@ -22,7 +22,7 @@ #include "resources/imagewriter.h" -#include "log.h" +#include "logger.h" #if defined __OpenBSD__ #include diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 7919145bd..e60127997 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -23,7 +23,7 @@ #include "resources/itemdb.h" #include "client.h" -#include "log.h" +#include "logger.h" #include "resources/iteminfo.h" #include "resources/resourcemanager.h" diff --git a/src/resources/mapdb.cpp b/src/resources/mapdb.cpp index e8aeaf168..e7288e039 100644 --- a/src/resources/mapdb.cpp +++ b/src/resources/mapdb.cpp @@ -23,7 +23,7 @@ #include "configuration.h" #include "client.h" -#include "log.h" +#include "logger.h" #include "utils/xml.h" diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 35267533f..70c45054f 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -23,7 +23,7 @@ #include "resources/mapreader.h" #include "configuration.h" -#include "log.h" +#include "logger.h" #include "map.h" #include "tileset.h" diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp index 7a0494fc9..dbf9d3e9a 100644 --- a/src/resources/monsterdb.cpp +++ b/src/resources/monsterdb.cpp @@ -22,7 +22,7 @@ #include "resources/monsterdb.h" -#include "log.h" +#include "logger.h" #include "net/net.h" diff --git a/src/resources/music.cpp b/src/resources/music.cpp index ccd1d9280..5ae9a2202 100644 --- a/src/resources/music.cpp +++ b/src/resources/music.cpp @@ -22,7 +22,7 @@ #include "resources/music.h" -#include "log.h" +#include "logger.h" #include "debug.h" diff --git a/src/resources/npcdb.cpp b/src/resources/npcdb.cpp index 49eab5bf2..d04a2518f 100644 --- a/src/resources/npcdb.cpp +++ b/src/resources/npcdb.cpp @@ -22,7 +22,7 @@ #include "resources/npcdb.h" -#include "log.h" +#include "logger.h" #include "resources/beinginfo.h" diff --git a/src/resources/resource.cpp b/src/resources/resource.cpp index 6e986272a..b180712c1 100644 --- a/src/resources/resource.cpp +++ b/src/resources/resource.cpp @@ -23,7 +23,7 @@ #include "resources/resource.h" #include "client.h" -#include "log.h" +#include "logger.h" #include "resources/resourcemanager.h" diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 92c18fa2a..ee325e253 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -24,7 +24,7 @@ #include "client.h" #include "configuration.h" -#include "log.h" +#include "logger.h" #include "main.h" #include "resources/dye.h" diff --git a/src/resources/soundeffect.cpp b/src/resources/soundeffect.cpp index a01bf21a0..49e7adc31 100644 --- a/src/resources/soundeffect.cpp +++ b/src/resources/soundeffect.cpp @@ -22,7 +22,7 @@ #include "resources/soundeffect.h" -#include "log.h" +#include "logger.h" #include "debug.h" diff --git a/src/resources/specialdb.cpp b/src/resources/specialdb.cpp index 4ab5e2a91..573ffb2a3 100644 --- a/src/resources/specialdb.cpp +++ b/src/resources/specialdb.cpp @@ -21,7 +21,7 @@ #include "resources/specialdb.h" -#include "log.h" +#include "logger.h" #include "utils/dtor.h" #include "utils/xml.h" diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp index b6addba77..dee93e1e7 100644 --- a/src/resources/spritedef.cpp +++ b/src/resources/spritedef.cpp @@ -22,7 +22,7 @@ #include "resources/spritedef.h" -#include "log.h" +#include "logger.h" #include "resources/action.h" #include "resources/animation.h" diff --git a/src/resources/wallpaper.cpp b/src/resources/wallpaper.cpp index 397b87993..09c9f2a04 100644 --- a/src/resources/wallpaper.cpp +++ b/src/resources/wallpaper.cpp @@ -23,7 +23,7 @@ #include "resources/wallpaper.h" #include "resources/resourcemanager.h" -#include "log.h" +#include "logger.h" #include "utils/stringutils.h" #include "configuration.h" diff --git a/src/simpleanimation.cpp b/src/simpleanimation.cpp index e3591f30c..4736b2e57 100644 --- a/src/simpleanimation.cpp +++ b/src/simpleanimation.cpp @@ -23,7 +23,7 @@ #include "simpleanimation.h" #include "graphics.h" -#include "log.h" +#include "logger.h" #include "utils/stringutils.h" diff --git a/src/sound.cpp b/src/sound.cpp index 92a5eaa6f..0a3c75d11 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -24,7 +24,7 @@ #include "configuration.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "sound.h" #include "resources/resourcemanager.h" diff --git a/src/spellmanager.cpp b/src/spellmanager.cpp index 13b8e7b69..a79388350 100644 --- a/src/spellmanager.cpp +++ b/src/spellmanager.cpp @@ -25,7 +25,7 @@ #include "being.h" #include "configuration.h" -#include "log.h" +#include "logger.h" #include "localplayer.h" #include "playerinfo.h" diff --git a/src/spellshortcut.h b/src/spellshortcut.h index 4d59384bd..047ccdef3 100644 --- a/src/spellshortcut.h +++ b/src/spellshortcut.h @@ -25,7 +25,7 @@ #define SPELLSHORTCUT_H #include "spellmanager.h" -#include "log.h" +#include "logger.h" #include "utils/stringutils.h" class TextCommand; diff --git a/src/statuseffect.cpp b/src/statuseffect.cpp index 27e351a45..dccf21f46 100644 --- a/src/statuseffect.cpp +++ b/src/statuseffect.cpp @@ -22,7 +22,7 @@ #include "statuseffect.h" -#include "log.h" +#include "logger.h" #include "sound.h" #include "gui/widgets/chattab.h" diff --git a/src/units.cpp b/src/units.cpp index ee0647e2e..db9faadd1 100644 --- a/src/units.cpp +++ b/src/units.cpp @@ -22,7 +22,7 @@ #include "units.h" -#include "log.h" +#include "logger.h" #include "utils/stringutils.h" #include "utils/xml.h" diff --git a/src/utils/mutex.h b/src/utils/mutex.h index f23ddc2aa..03dac2e7a 100644 --- a/src/utils/mutex.h +++ b/src/utils/mutex.h @@ -23,7 +23,7 @@ #ifndef MUTEX_H #define MUTEX_H -#include "log.h" +#include "logger.h" #include diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp index b31b60ee1..89457a4e8 100644 --- a/src/utils/xml.cpp +++ b/src/utils/xml.cpp @@ -22,7 +22,7 @@ #include "utils/xml.h" -#include "log.h" +#include "logger.h" #include "resources/resourcemanager.h" -- cgit v1.2.3-70-g09d2 From 29cde4fff20d12e076ba7a58d32d9b797ec1fb7a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 12 Aug 2011 03:54:03 +0300 Subject: Rename file name updatewindow to correct updaterwindow. --- manaplus.cbp | 4 +- src/CMakeLists.txt | 4 +- src/Makefile.am | 4 +- src/client.cpp | 2 +- src/gui/updaterwindow.cpp | 706 ++++++++++++++++++++++++++++++++++++++++++++++ src/gui/updaterwindow.h | 213 ++++++++++++++ src/gui/updatewindow.cpp | 706 ---------------------------------------------- src/gui/updatewindow.h | 213 -------------- 8 files changed, 926 insertions(+), 926 deletions(-) create mode 100644 src/gui/updaterwindow.cpp create mode 100644 src/gui/updaterwindow.h delete mode 100644 src/gui/updatewindow.cpp delete mode 100644 src/gui/updatewindow.h (limited to 'src') diff --git a/manaplus.cbp b/manaplus.cbp index 020e65357..de71b2947 100644 --- a/manaplus.cbp +++ b/manaplus.cbp @@ -276,8 +276,8 @@ - - + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a48c4f28a..8a0135790 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -349,8 +349,8 @@ SET(SRCS gui/tradewindow.h gui/unregisterdialog.cpp gui/unregisterdialog.h - gui/updatewindow.cpp - gui/updatewindow.h + gui/updaterwindow.cpp + gui/updaterwindow.h gui/userpalette.cpp gui/userpalette.h gui/viewport.cpp diff --git a/src/Makefile.am b/src/Makefile.am index c1287e06c..e6d84e016 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -352,8 +352,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ gui/tradewindow.h \ gui/unregisterdialog.cpp \ gui/unregisterdialog.h \ - gui/updatewindow.cpp \ - gui/updatewindow.h \ + gui/updaterwindow.cpp \ + gui/updaterwindow.h \ gui/userpalette.cpp \ gui/userpalette.h \ gui/viewport.cpp \ diff --git a/src/client.cpp b/src/client.cpp index e85c5b08f..cc3c384f7 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -61,7 +61,7 @@ #include "gui/setup.h" #include "gui/theme.h" #include "gui/unregisterdialog.h" -#include "gui/updatewindow.h" +#include "gui/updaterwindow.h" #include "gui/userpalette.h" #include "gui/worldselectdialog.h" diff --git a/src/gui/updaterwindow.cpp b/src/gui/updaterwindow.cpp new file mode 100644 index 000000000..7534b12a9 --- /dev/null +++ b/src/gui/updaterwindow.cpp @@ -0,0 +1,706 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 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 . + */ + +#include "gui/updaterwindow.h" + +#include "client.h" +#include "configuration.h" +#include "logger.h" +#include "main.h" + +#include "gui/sdlinput.h" + +#include "gui/widgets/browserbox.h" +#include "gui/widgets/button.h" +#include "gui/widgets/label.h" +#include "gui/widgets/layout.h" +#include "gui/widgets/progressbar.h" +#include "gui/widgets/scrollarea.h" + +#include "net/download.h" +#include "net/logindata.h" + +#include "resources/resourcemanager.h" + +#include "utils/gettext.h" +#include "utils/stringutils.h" +#include "utils/xml.h" + +#include +#include + +#include + +#include "debug.h" + +const std::string xmlUpdateFile = "resources.xml"; +const std::string txtUpdateFile = "resources2.txt"; + +std::vector loadXMLFile(const std::string &fileName); +std::vector loadTxtFile(const std::string &fileName); + +/** + * Load the given file into a vector of updateFiles. + */ +std::vector loadXMLFile(const std::string &fileName) +{ + std::vector files; + XML::Document doc(fileName, false); + xmlNodePtr rootNode = doc.rootNode(); + + if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "updates")) + { + logger->log("Error loading update file: %s", fileName.c_str()); + return files; + } + + for_each_xml_child_node(fileNode, rootNode) + { + // Ignore all tags except for the "update" tags + if (!xmlStrEqual(fileNode->name, BAD_CAST "update")) + continue; + + updateFile file; + file.name = XML::getProperty(fileNode, "file", ""); + file.hash = XML::getProperty(fileNode, "hash", ""); + file.type = XML::getProperty(fileNode, "type", "data"); + file.desc = XML::getProperty(fileNode, "description", ""); + if (XML::getProperty(fileNode, "required", "yes") == "yes") + file.required = true; + else + file.required = false; + + files.push_back(file); + } + + return files; +} + +std::vector loadTxtFile(const std::string &fileName) +{ + std::vector files; + std::ifstream fileHandler; + fileHandler.open(fileName.c_str(), std::ios::in); + + if (fileHandler.is_open()) + { + while (fileHandler.good()) + { + char name[256], hash[50]; + fileHandler.getline(name, 256, ' '); + fileHandler.getline(hash, 50); + + updateFile thisFile; + thisFile.name = name; + thisFile.hash = hash; + thisFile.type = "data"; + thisFile.required = true; + thisFile.desc = ""; + + if (!thisFile.name.empty()) + files.push_back(thisFile); + } + } + else + { + logger->log("Error loading update file: %s", fileName.c_str()); + } + fileHandler.close(); + + return files; +} + +UpdaterWindow::UpdaterWindow(const std::string &updateHost, + const std::string &updatesDir, + bool applyUpdates, + int updateType): + Window(_("Updating...")), + mDownloadStatus(UPDATE_NEWS), + mUpdateHost(updateHost), + mUpdatesDir(updatesDir), + mCurrentFile("news.txt"), + mDownloadProgress(0.0f), + mCurrentChecksum(0), + mStoreInMemory(true), + mDownloadComplete(true), + mUserCancel(false), + mDownloadedBytes(0), + mMemoryBuffer(NULL), + mDownload(NULL), + mUpdateIndex(0), + mLoadUpdates(applyUpdates), + mUpdateType(updateType) +{ + mBrowserBox = new BrowserBox; + mScrollArea = new ScrollArea(mBrowserBox); + mLabel = new Label(_("Connecting...")); + mProgressBar = new ProgressBar(0.0, 310, 20); + mCancelButton = new Button(_("Cancel"), "cancel", this); + mPlayButton = new Button(_("Play"), "play", this); + + mProgressBar->setSmoothProgress(false); + mBrowserBox->setOpaque(false); + mPlayButton->setEnabled(false); + + ContainerPlacer place; + place = getPlacer(0, 0); + + place(0, 0, mScrollArea, 5, 3).setPadding(3); + place(0, 3, mLabel, 5); + place(0, 4, mProgressBar, 5); + place(3, 5, mCancelButton); + place(4, 5, mPlayButton); + + reflowLayout(450, 400); + + Layout &layout = getLayout(); + layout.setRowHeight(0, Layout::AUTO_SET); + + addKeyListener(this); + + center(); + setVisible(true); + mCancelButton->requestFocus(); + + // Try to download the updates list + download(); +} + +UpdaterWindow::~UpdaterWindow() +{ + if (mLoadUpdates) + loadUpdates(); + + if (mDownload) + { + mDownload->cancel(); + + delete mDownload; + mDownload = 0; + } + free(mMemoryBuffer); +} + +void UpdaterWindow::setProgress(float p) +{ + // Do delayed progress bar update, since Guichan isn't thread-safe + MutexLocker lock(&mDownloadMutex); + mDownloadProgress = p; +} + +void UpdaterWindow::setLabel(const std::string &str) +{ + // Do delayed label text update, since Guichan isn't thread-safe + MutexLocker lock(&mDownloadMutex); + mNewLabelCaption = str; +} + +void UpdaterWindow::enable() +{ + mCancelButton->setEnabled(false); + mPlayButton->setEnabled(true); + mPlayButton->requestFocus(); + + if (mUpdateType & LoginData::Upd_Close) + Client::setState(STATE_LOAD_DATA); +} + +void UpdaterWindow::action(const gcn::ActionEvent &event) +{ + if (event.getId() == "cancel") + { + // Register the user cancel + mUserCancel = true; + // Skip the updating process + if (mDownloadStatus != UPDATE_COMPLETE) + { + mDownload->cancel(); + mDownloadStatus = UPDATE_ERROR; + } + } + else if (event.getId() == "play") + { + Client::setState(STATE_LOAD_DATA); + } +} + +void UpdaterWindow::keyPressed(gcn::KeyEvent &keyEvent) +{ + gcn::Key key = keyEvent.getKey(); + + if (key.getValue() == Key::ESCAPE) + { + action(gcn::ActionEvent(NULL, mCancelButton->getActionEventId())); + Client::setState(STATE_WORLD_SELECT); + } + else if (key.getValue() == Key::ENTER) + { + if (mDownloadStatus == UPDATE_COMPLETE || + mDownloadStatus == UPDATE_ERROR) + { + action(gcn::ActionEvent(NULL, mPlayButton->getActionEventId())); + } + else + { + action(gcn::ActionEvent(NULL, mCancelButton->getActionEventId())); + } + } +} + +void UpdaterWindow::loadNews() +{ + if (!mMemoryBuffer) + { + logger->log1("Couldn't load news"); + return; + } + + // Reallocate and include terminating 0 character + mMemoryBuffer = static_cast(realloc( + mMemoryBuffer, mDownloadedBytes + 1)); + + mMemoryBuffer[mDownloadedBytes] = '\0'; + + mBrowserBox->clearRows(); + + // Tokenize and add each line separately + char *line = strtok(mMemoryBuffer, "\n"); + while (line) + { + mBrowserBox->addRow(line); + line = strtok(NULL, "\n"); + } + + // Free the memory buffer now that we don't need it anymore + free(mMemoryBuffer); + mMemoryBuffer = NULL; + mDownloadedBytes = 0; + + mScrollArea->setVerticalScrollAmount(0); +} + +void UpdaterWindow::loadPatch() +{ + if (!mMemoryBuffer) + { + logger->log1("Couldn't load patch"); + return; + } + + // Reallocate and include terminating 0 character + mMemoryBuffer = static_cast( + realloc(mMemoryBuffer, mDownloadedBytes + 1)); + mMemoryBuffer[mDownloadedBytes] = '\0'; + + std::string version; + + // Tokenize and add each line separately + char *line = strtok(mMemoryBuffer, "\n"); + if (line) + { + version = line; + if (version > CHECK_VERSION) + { + mBrowserBox->addRow("", true); + mBrowserBox->addRow(" ##1http://manaplus.evolonline.org/", true); + mBrowserBox->addRow("##1You can download it from", true); + mBrowserBox->addRow("##1ManaPlus updated.", true); + } + else + { + mBrowserBox->addRow("You have latest client version.", true); + } + } + + // Free the memory buffer now that we don't need it anymore + free(mMemoryBuffer); + mMemoryBuffer = NULL; + mDownloadedBytes = 0; + + mScrollArea->setVerticalScrollAmount(0); +} + +int UpdaterWindow::updateProgress(void *ptr, DownloadStatus status, + size_t dt, size_t dn) +{ + UpdaterWindow *uw = reinterpret_cast(ptr); + if (!uw) + return -1; + + if (status == DOWNLOAD_STATUS_COMPLETE) + { + uw->mDownloadComplete = true; + } + else if (status == DOWNLOAD_STATUS_ERROR || + status == DOWNLOAD_STATUS_CANCELLED) + { + if (uw->mDownloadStatus == UPDATE_COMPLETE) + { // ignoring error in last state (was UPDATE_PATCH) + uw->mDownloadStatus = UPDATE_COMPLETE; + uw->mDownloadComplete = true; + free(uw->mMemoryBuffer); + uw->mMemoryBuffer = NULL; + } + else + { + uw->mDownloadStatus = UPDATE_ERROR; + } + } + + if (!dt) + dt = 1; + + float progress = static_cast(dn) / + static_cast(dt); + + if (progress != progress) + progress = 0.0f; // check for NaN + if (progress < 0.0f) + progress = 0.0f; // no idea how this could ever happen, + // but why not check for it anyway. + if (progress > 1.0f) + progress = 1.0f; + + uw->setLabel(uw->mCurrentFile + " (" + + toString(static_cast(progress * 100)) + "%)"); + + uw->setProgress(progress); + + if (Client::getState() != STATE_UPDATE + || uw->mDownloadStatus == UPDATE_ERROR) + { + // If the action was canceled return an error code to stop the mThread + return -1; + } + + return 0; +} + +size_t UpdaterWindow::memoryWrite(void *ptr, size_t size, + size_t nmemb, void *stream) +{ + UpdaterWindow *uw = reinterpret_cast(stream); + size_t totalMem = size * nmemb; + uw->mMemoryBuffer = static_cast(realloc(uw->mMemoryBuffer, + uw->mDownloadedBytes + totalMem)); + if (uw->mMemoryBuffer) + { + memcpy(&(uw->mMemoryBuffer[uw->mDownloadedBytes]), ptr, totalMem); + uw->mDownloadedBytes += static_cast(totalMem); + } + + return totalMem; +} + +void UpdaterWindow::download() +{ + if (mDownload) + { + mDownload->cancel(); + delete mDownload; + } + if (mDownloadStatus == UPDATE_PATCH) + { + mDownload = new Net::Download(this, + "http://manaplus.evolonline.org/update/" + mCurrentFile, + updateProgress, true); + } + else + { + mDownload = new Net::Download(this, mUpdateHost + "/" + mCurrentFile, + updateProgress); + } + + if (mStoreInMemory) + { + mDownload->setWriteFunction(UpdaterWindow::memoryWrite); + } + else + { + if (mDownloadStatus == UPDATE_RESOURCES) + { + mDownload->setFile(mUpdatesDir + "/" + mCurrentFile, + mCurrentChecksum); + } + else + { + mDownload->setFile(mUpdatesDir + "/" + mCurrentFile); + } + } + + if (mDownloadStatus != UPDATE_RESOURCES) + mDownload->noCache(); + + setLabel(mCurrentFile + " (0%)"); + mDownloadComplete = false; + + // TODO: check return + mDownload->start(); +} + +void UpdaterWindow::loadUpdates() +{ + ResourceManager *resman = ResourceManager::getInstance(); + + if (mUpdateFiles.empty()) + { // updates not downloaded + mUpdateFiles = loadXMLFile(mUpdatesDir + "/" + xmlUpdateFile); + if (mUpdateFiles.empty()) + { + logger->log("Warning this server does not have a" + " %s file falling back to %s", xmlUpdateFile.c_str(), + txtUpdateFile.c_str()); + mUpdateFiles = loadTxtFile(mUpdatesDir + "/" + txtUpdateFile); + } + } + + std::string fixPath = mUpdatesDir + "/fix"; + for (mUpdateIndex = 0; mUpdateIndex < mUpdateFiles.size(); mUpdateIndex++) + { + UpdaterWindow::addUpdateFile(resman, mUpdatesDir, fixPath, + mUpdateFiles[mUpdateIndex].name, false); + } +} + +void UpdaterWindow::loadLocalUpdates(std::string dir) +{ + ResourceManager *resman = ResourceManager::getInstance(); + + std::vector updateFiles + = loadXMLFile(dir + "/" + xmlUpdateFile); + + if (updateFiles.empty()) + { + logger->log("Warning this server does not have a" + " %s file falling back to %s", xmlUpdateFile.c_str(), + txtUpdateFile.c_str()); + updateFiles = loadTxtFile(dir + "/" + txtUpdateFile); + } + + std::string fixPath = dir + "/fix"; + for (unsigned int updateIndex = 0; + updateIndex < updateFiles.size(); updateIndex++) + { + UpdaterWindow::addUpdateFile(resman, dir, fixPath, + updateFiles[updateIndex].name, false); + } +} + +void UpdaterWindow::addUpdateFile(ResourceManager *resman, std::string path, + std::string fixPath, std::string file, + bool append) +{ + if (!append) + resman->addToSearchPath(path + "/" + file, append); + + const std::string fixFile = fixPath + "/" + file; + struct stat statbuf; + if (!stat(fixFile.c_str(), &statbuf)) + resman->addToSearchPath(fixFile, append); + + if (append) + resman->addToSearchPath(path + "/" + file, append); +} + +void UpdaterWindow::logic() +{ + // Update Scroll logic + mScrollArea->logic(); + + // Synchronize label caption when necessary + { + MutexLocker lock(&mDownloadMutex); + + if (mLabel->getCaption() != mNewLabelCaption) + { + mLabel->setCaption(mNewLabelCaption); + mLabel->adjustSize(); + } + + mProgressBar->setProgress(mDownloadProgress); + if (mUpdateFiles.size() && mUpdateIndex <= mUpdateFiles.size()) + { + mProgressBar->setText(strprintf("%d/%d", + mUpdateIndex + 1, (int)mUpdateFiles.size() + 1)); + } + else + { + mProgressBar->setText(""); + } + } + + switch (mDownloadStatus) + { + case UPDATE_ERROR: + // TODO: Only send complete sentences to gettext + mBrowserBox->addRow(""); + mBrowserBox->addRow(_("##1 The update process is incomplete.")); + // TRANSLATORS: Continues "you try again later.". + mBrowserBox->addRow(_("##1 It is strongly recommended that")); + // TRANSLATORS: Begins "It is strongly recommended that". + mBrowserBox->addRow(_("##1 you try again later.")); + + mBrowserBox->addRow(mDownload->getError()); + mScrollArea->setVerticalScrollAmount( + mScrollArea->getVerticalMaxScroll()); + mDownloadStatus = UPDATE_COMPLETE; + break; + case UPDATE_NEWS: + if (mDownloadComplete) + { + // Parse current memory buffer as news and dispose of the data + loadNews(); + + mCurrentFile = xmlUpdateFile; + mStoreInMemory = false; + mDownloadStatus = UPDATE_LIST; + download(); // download() changes mDownloadComplete to false + } + break; + case UPDATE_PATCH: + if (mDownloadComplete) + { + // Parse current memory buffer as news and dispose of the data + loadPatch(); + +/* + mCurrentFile = "news.txt"; + mStoreInMemory = true; + mDownloadStatus = UPDATE_NEWS; + download(); // download() changes mDownloadComplete to false +*/ + mDownloadStatus = UPDATE_COMPLETE; + } + break; + + case UPDATE_LIST: + if (mDownloadComplete) + { + if (mCurrentFile == xmlUpdateFile) + { + mUpdateFiles = loadXMLFile( + mUpdatesDir + "/" + xmlUpdateFile); + + if (mUpdateFiles.empty()) + { + logger->log("Warning this server does not have a %s" + " file falling back to %s", + xmlUpdateFile.c_str(), + txtUpdateFile.c_str()); + + // If the resources.xml file fails, + // fall back onto a older version + mCurrentFile = txtUpdateFile; + mStoreInMemory = false; + mDownloadStatus = UPDATE_LIST; + download(); + break; + } + } + else if (mCurrentFile == txtUpdateFile) + { + mUpdateFiles = loadTxtFile( + mUpdatesDir + "/" + txtUpdateFile); + } + mStoreInMemory = false; + mDownloadStatus = UPDATE_RESOURCES; + } + break; + case UPDATE_RESOURCES: + if (mDownloadComplete) + { + if (mUpdateIndex < mUpdateFiles.size()) + { + updateFile thisFile = mUpdateFiles[mUpdateIndex]; + if (!thisFile.required) + { + // This statement checks to see if the file type + // is music, and if download-music is true + // If it fails, this statement returns true, + // and results in not downloading the file + // Else it will ignore the break, + // and download the file. + + if (!(thisFile.type == "music" + && config.getBoolValue("download-music"))) + { + mUpdateIndex++; + break; + } + } + mCurrentFile = thisFile.name; + std::string checksum; + checksum = thisFile.hash; + std::stringstream ss(checksum); + ss >> std::hex >> mCurrentChecksum; + + std::ifstream temp( + (mUpdatesDir + "/" + mCurrentFile).c_str()); + + if (!temp.is_open() || !validateFile(mUpdatesDir + "/" + + mCurrentFile, mCurrentChecksum)) + { + temp.close(); + download(); + } + else + { + temp.close(); + logger->log("%s already here", mCurrentFile.c_str()); + } + mUpdateIndex++; + } + else + { + // Download of updates completed +// mDownloadStatus = UPDATE_COMPLETE; + mCurrentFile = "latest.txt"; + mStoreInMemory = true; + mDownloadStatus = UPDATE_PATCH; + download(); // download() changes + // mDownloadComplete to false + } + } + break; + case UPDATE_COMPLETE: + enable(); + setLabel(_("Completed")); + break; + case UPDATE_IDLE: + break; + default: + logger->log("UpdaterWindow::logic unknown status: " + + toString(static_cast(mDownloadStatus))); + break; + } +} + +bool UpdaterWindow::validateFile(std::string filePath, unsigned long hash) +{ + FILE *file = fopen(filePath.c_str(), "rb"); + if (!file) + return false; + + unsigned long adler = Net::Download::fadler32(file); + fclose(file); + return adler == hash; +} diff --git a/src/gui/updaterwindow.h b/src/gui/updaterwindow.h new file mode 100644 index 000000000..a1dc556d5 --- /dev/null +++ b/src/gui/updaterwindow.h @@ -0,0 +1,213 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 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 . + */ + +#ifndef UPDATERWINDOW_H +#define UPDATERWINDOW_H + +#include "gui/widgets/window.h" + +#include "net/download.h" + +#include "utils/mutex.h" + +#include +#include + +#include +#include + +class BrowserBox; +class Button; +class ProgressBar; +class ResourceManager; +class ScrollArea; + +struct updateFile +{ + public: + std::string name; + std::string hash; + std::string type; + bool required; + std::string desc; +}; + +/** + * Update progress window GUI + * + * \ingroup GUI + */ +class UpdaterWindow : public Window, public gcn::ActionListener, + public gcn::KeyListener +{ + public: + /** + * Constructor. + * + * @param updateHost Host where to get the updated files. + * @param updatesDir Directory where to store updates (should be absolute + * and already created). + * @param applyUpdates If true, the update window will pass the updates to teh + * resource manager + */ + UpdaterWindow(const std::string &updateHost, + const std::string &updatesDir, + bool applyUpdates, int updateType); + + /** + * Destructor + */ + ~UpdaterWindow(); + + /** + * Set's progress bar status + */ + void setProgress(float p); + + /** + * Set's label above progress + */ + void setLabel(const std::string &); + + /** + * Enables play button + */ + void enable(); + + /** + * Loads and display news. Assumes the news file contents have been loaded + * into the memory buffer. + */ + void loadNews(); + + void loadPatch(); + + void action(const gcn::ActionEvent &event); + + void keyPressed(gcn::KeyEvent &keyEvent); + + void logic(); + + static void loadLocalUpdates(std::string dir); + + static void addUpdateFile(ResourceManager *resman, std::string path, + std::string fixPath, std::string file, + bool append); + + int updateState; + +private: + void download(); + + /** + * Loads the updates this window has gotten into the resource manager + */ + void loadUpdates(); + + + /** + * A download callback for progress updates. + */ + static int updateProgress(void *ptr, DownloadStatus status, + size_t dt, size_t dn); + + /** + * A libcurl callback for writing to memory. + */ + static size_t memoryWrite(void *ptr, size_t size, size_t nmemb, + void *stream); + + bool validateFile(std::string filePath, unsigned long hash); + + enum UpdateDownloadStatus + { + UPDATE_ERROR = 0, + UPDATE_IDLE, + UPDATE_LIST, + UPDATE_COMPLETE, + UPDATE_NEWS, + UPDATE_RESOURCES, + UPDATE_PATCH + }; + + /** Status of the current download. */ + UpdateDownloadStatus mDownloadStatus; + + /** Host where we get the updated files. */ + std::string mUpdateHost; + + /** Place where the updates are stored (absolute path). */ + std::string mUpdatesDir; + + /** The file currently downloading. */ + std::string mCurrentFile; + + /** The new label caption to be set in the logic method. */ + std::string mNewLabelCaption; + + /** The new progress value to be set in the logic method. */ + float mDownloadProgress; + + /** The mutex used to guard access to mNewLabelCaption and mDownloadProgress. */ + Mutex mDownloadMutex; + + /** The Adler32 checksum of the file currently downloading. */ + unsigned long mCurrentChecksum; + + /** A flag to indicate whether to use a memory buffer or a regular file. */ + bool mStoreInMemory; + + /** Flag that show if current download is complete. */ + bool mDownloadComplete; + + /** Flag that show if the user has canceled the update. */ + bool mUserCancel; + + /** Byte count currently downloaded in mMemoryBuffer. */ + int mDownloadedBytes; + + /** Buffer for files downloaded to memory. */ + char *mMemoryBuffer; + + /** Download handle. */ + Net::Download *mDownload; + + /** List of files to download. */ + std::vector mUpdateFiles; + + /** Index of the file to be downloaded. */ + unsigned int mUpdateIndex; + + /** Tells ~UpdaterWindow() if it should load updates */ + bool mLoadUpdates; + + int mUpdateType; + + gcn::Label *mLabel; /**< Progress bar caption. */ + Button *mCancelButton; /**< Button to stop the update process. */ + Button *mPlayButton; /**< Button to start playing. */ + ProgressBar *mProgressBar; /**< Update progress bar. */ + BrowserBox *mBrowserBox; /**< Box to display news. */ + ScrollArea *mScrollArea; /**< Used to scroll news box. */ +}; + +#endif diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp deleted file mode 100644 index 895c99121..000000000 --- a/src/gui/updatewindow.cpp +++ /dev/null @@ -1,706 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 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 . - */ - -#include "gui/updatewindow.h" - -#include "client.h" -#include "configuration.h" -#include "logger.h" -#include "main.h" - -#include "gui/sdlinput.h" - -#include "gui/widgets/browserbox.h" -#include "gui/widgets/button.h" -#include "gui/widgets/label.h" -#include "gui/widgets/layout.h" -#include "gui/widgets/progressbar.h" -#include "gui/widgets/scrollarea.h" - -#include "net/download.h" -#include "net/logindata.h" - -#include "resources/resourcemanager.h" - -#include "utils/gettext.h" -#include "utils/stringutils.h" -#include "utils/xml.h" - -#include -#include - -#include - -#include "debug.h" - -const std::string xmlUpdateFile = "resources.xml"; -const std::string txtUpdateFile = "resources2.txt"; - -std::vector loadXMLFile(const std::string &fileName); -std::vector loadTxtFile(const std::string &fileName); - -/** - * Load the given file into a vector of updateFiles. - */ -std::vector loadXMLFile(const std::string &fileName) -{ - std::vector files; - XML::Document doc(fileName, false); - xmlNodePtr rootNode = doc.rootNode(); - - if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "updates")) - { - logger->log("Error loading update file: %s", fileName.c_str()); - return files; - } - - for_each_xml_child_node(fileNode, rootNode) - { - // Ignore all tags except for the "update" tags - if (!xmlStrEqual(fileNode->name, BAD_CAST "update")) - continue; - - updateFile file; - file.name = XML::getProperty(fileNode, "file", ""); - file.hash = XML::getProperty(fileNode, "hash", ""); - file.type = XML::getProperty(fileNode, "type", "data"); - file.desc = XML::getProperty(fileNode, "description", ""); - if (XML::getProperty(fileNode, "required", "yes") == "yes") - file.required = true; - else - file.required = false; - - files.push_back(file); - } - - return files; -} - -std::vector loadTxtFile(const std::string &fileName) -{ - std::vector files; - std::ifstream fileHandler; - fileHandler.open(fileName.c_str(), std::ios::in); - - if (fileHandler.is_open()) - { - while (fileHandler.good()) - { - char name[256], hash[50]; - fileHandler.getline(name, 256, ' '); - fileHandler.getline(hash, 50); - - updateFile thisFile; - thisFile.name = name; - thisFile.hash = hash; - thisFile.type = "data"; - thisFile.required = true; - thisFile.desc = ""; - - if (!thisFile.name.empty()) - files.push_back(thisFile); - } - } - else - { - logger->log("Error loading update file: %s", fileName.c_str()); - } - fileHandler.close(); - - return files; -} - -UpdaterWindow::UpdaterWindow(const std::string &updateHost, - const std::string &updatesDir, - bool applyUpdates, - int updateType): - Window(_("Updating...")), - mDownloadStatus(UPDATE_NEWS), - mUpdateHost(updateHost), - mUpdatesDir(updatesDir), - mCurrentFile("news.txt"), - mDownloadProgress(0.0f), - mCurrentChecksum(0), - mStoreInMemory(true), - mDownloadComplete(true), - mUserCancel(false), - mDownloadedBytes(0), - mMemoryBuffer(NULL), - mDownload(NULL), - mUpdateIndex(0), - mLoadUpdates(applyUpdates), - mUpdateType(updateType) -{ - mBrowserBox = new BrowserBox; - mScrollArea = new ScrollArea(mBrowserBox); - mLabel = new Label(_("Connecting...")); - mProgressBar = new ProgressBar(0.0, 310, 20); - mCancelButton = new Button(_("Cancel"), "cancel", this); - mPlayButton = new Button(_("Play"), "play", this); - - mProgressBar->setSmoothProgress(false); - mBrowserBox->setOpaque(false); - mPlayButton->setEnabled(false); - - ContainerPlacer place; - place = getPlacer(0, 0); - - place(0, 0, mScrollArea, 5, 3).setPadding(3); - place(0, 3, mLabel, 5); - place(0, 4, mProgressBar, 5); - place(3, 5, mCancelButton); - place(4, 5, mPlayButton); - - reflowLayout(450, 400); - - Layout &layout = getLayout(); - layout.setRowHeight(0, Layout::AUTO_SET); - - addKeyListener(this); - - center(); - setVisible(true); - mCancelButton->requestFocus(); - - // Try to download the updates list - download(); -} - -UpdaterWindow::~UpdaterWindow() -{ - if (mLoadUpdates) - loadUpdates(); - - if (mDownload) - { - mDownload->cancel(); - - delete mDownload; - mDownload = 0; - } - free(mMemoryBuffer); -} - -void UpdaterWindow::setProgress(float p) -{ - // Do delayed progress bar update, since Guichan isn't thread-safe - MutexLocker lock(&mDownloadMutex); - mDownloadProgress = p; -} - -void UpdaterWindow::setLabel(const std::string &str) -{ - // Do delayed label text update, since Guichan isn't thread-safe - MutexLocker lock(&mDownloadMutex); - mNewLabelCaption = str; -} - -void UpdaterWindow::enable() -{ - mCancelButton->setEnabled(false); - mPlayButton->setEnabled(true); - mPlayButton->requestFocus(); - - if (mUpdateType & LoginData::Upd_Close) - Client::setState(STATE_LOAD_DATA); -} - -void UpdaterWindow::action(const gcn::ActionEvent &event) -{ - if (event.getId() == "cancel") - { - // Register the user cancel - mUserCancel = true; - // Skip the updating process - if (mDownloadStatus != UPDATE_COMPLETE) - { - mDownload->cancel(); - mDownloadStatus = UPDATE_ERROR; - } - } - else if (event.getId() == "play") - { - Client::setState(STATE_LOAD_DATA); - } -} - -void UpdaterWindow::keyPressed(gcn::KeyEvent &keyEvent) -{ - gcn::Key key = keyEvent.getKey(); - - if (key.getValue() == Key::ESCAPE) - { - action(gcn::ActionEvent(NULL, mCancelButton->getActionEventId())); - Client::setState(STATE_WORLD_SELECT); - } - else if (key.getValue() == Key::ENTER) - { - if (mDownloadStatus == UPDATE_COMPLETE || - mDownloadStatus == UPDATE_ERROR) - { - action(gcn::ActionEvent(NULL, mPlayButton->getActionEventId())); - } - else - { - action(gcn::ActionEvent(NULL, mCancelButton->getActionEventId())); - } - } -} - -void UpdaterWindow::loadNews() -{ - if (!mMemoryBuffer) - { - logger->log1("Couldn't load news"); - return; - } - - // Reallocate and include terminating 0 character - mMemoryBuffer = static_cast(realloc( - mMemoryBuffer, mDownloadedBytes + 1)); - - mMemoryBuffer[mDownloadedBytes] = '\0'; - - mBrowserBox->clearRows(); - - // Tokenize and add each line separately - char *line = strtok(mMemoryBuffer, "\n"); - while (line) - { - mBrowserBox->addRow(line); - line = strtok(NULL, "\n"); - } - - // Free the memory buffer now that we don't need it anymore - free(mMemoryBuffer); - mMemoryBuffer = NULL; - mDownloadedBytes = 0; - - mScrollArea->setVerticalScrollAmount(0); -} - -void UpdaterWindow::loadPatch() -{ - if (!mMemoryBuffer) - { - logger->log1("Couldn't load patch"); - return; - } - - // Reallocate and include terminating 0 character - mMemoryBuffer = static_cast( - realloc(mMemoryBuffer, mDownloadedBytes + 1)); - mMemoryBuffer[mDownloadedBytes] = '\0'; - - std::string version; - - // Tokenize and add each line separately - char *line = strtok(mMemoryBuffer, "\n"); - if (line) - { - version = line; - if (version > CHECK_VERSION) - { - mBrowserBox->addRow("", true); - mBrowserBox->addRow(" ##1http://manaplus.evolonline.org/", true); - mBrowserBox->addRow("##1You can download it from", true); - mBrowserBox->addRow("##1ManaPlus updated.", true); - } - else - { - mBrowserBox->addRow("You have latest client version.", true); - } - } - - // Free the memory buffer now that we don't need it anymore - free(mMemoryBuffer); - mMemoryBuffer = NULL; - mDownloadedBytes = 0; - - mScrollArea->setVerticalScrollAmount(0); -} - -int UpdaterWindow::updateProgress(void *ptr, DownloadStatus status, - size_t dt, size_t dn) -{ - UpdaterWindow *uw = reinterpret_cast(ptr); - if (!uw) - return -1; - - if (status == DOWNLOAD_STATUS_COMPLETE) - { - uw->mDownloadComplete = true; - } - else if (status == DOWNLOAD_STATUS_ERROR || - status == DOWNLOAD_STATUS_CANCELLED) - { - if (uw->mDownloadStatus == UPDATE_COMPLETE) - { // ignoring error in last state (was UPDATE_PATCH) - uw->mDownloadStatus = UPDATE_COMPLETE; - uw->mDownloadComplete = true; - free(uw->mMemoryBuffer); - uw->mMemoryBuffer = NULL; - } - else - { - uw->mDownloadStatus = UPDATE_ERROR; - } - } - - if (!dt) - dt = 1; - - float progress = static_cast(dn) / - static_cast(dt); - - if (progress != progress) - progress = 0.0f; // check for NaN - if (progress < 0.0f) - progress = 0.0f; // no idea how this could ever happen, - // but why not check for it anyway. - if (progress > 1.0f) - progress = 1.0f; - - uw->setLabel(uw->mCurrentFile + " (" - + toString(static_cast(progress * 100)) + "%)"); - - uw->setProgress(progress); - - if (Client::getState() != STATE_UPDATE - || uw->mDownloadStatus == UPDATE_ERROR) - { - // If the action was canceled return an error code to stop the mThread - return -1; - } - - return 0; -} - -size_t UpdaterWindow::memoryWrite(void *ptr, size_t size, - size_t nmemb, void *stream) -{ - UpdaterWindow *uw = reinterpret_cast(stream); - size_t totalMem = size * nmemb; - uw->mMemoryBuffer = static_cast(realloc(uw->mMemoryBuffer, - uw->mDownloadedBytes + totalMem)); - if (uw->mMemoryBuffer) - { - memcpy(&(uw->mMemoryBuffer[uw->mDownloadedBytes]), ptr, totalMem); - uw->mDownloadedBytes += static_cast(totalMem); - } - - return totalMem; -} - -void UpdaterWindow::download() -{ - if (mDownload) - { - mDownload->cancel(); - delete mDownload; - } - if (mDownloadStatus == UPDATE_PATCH) - { - mDownload = new Net::Download(this, - "http://manaplus.evolonline.org/update/" + mCurrentFile, - updateProgress, true); - } - else - { - mDownload = new Net::Download(this, mUpdateHost + "/" + mCurrentFile, - updateProgress); - } - - if (mStoreInMemory) - { - mDownload->setWriteFunction(UpdaterWindow::memoryWrite); - } - else - { - if (mDownloadStatus == UPDATE_RESOURCES) - { - mDownload->setFile(mUpdatesDir + "/" + mCurrentFile, - mCurrentChecksum); - } - else - { - mDownload->setFile(mUpdatesDir + "/" + mCurrentFile); - } - } - - if (mDownloadStatus != UPDATE_RESOURCES) - mDownload->noCache(); - - setLabel(mCurrentFile + " (0%)"); - mDownloadComplete = false; - - // TODO: check return - mDownload->start(); -} - -void UpdaterWindow::loadUpdates() -{ - ResourceManager *resman = ResourceManager::getInstance(); - - if (mUpdateFiles.empty()) - { // updates not downloaded - mUpdateFiles = loadXMLFile(mUpdatesDir + "/" + xmlUpdateFile); - if (mUpdateFiles.empty()) - { - logger->log("Warning this server does not have a" - " %s file falling back to %s", xmlUpdateFile.c_str(), - txtUpdateFile.c_str()); - mUpdateFiles = loadTxtFile(mUpdatesDir + "/" + txtUpdateFile); - } - } - - std::string fixPath = mUpdatesDir + "/fix"; - for (mUpdateIndex = 0; mUpdateIndex < mUpdateFiles.size(); mUpdateIndex++) - { - UpdaterWindow::addUpdateFile(resman, mUpdatesDir, fixPath, - mUpdateFiles[mUpdateIndex].name, false); - } -} - -void UpdaterWindow::loadLocalUpdates(std::string dir) -{ - ResourceManager *resman = ResourceManager::getInstance(); - - std::vector updateFiles - = loadXMLFile(dir + "/" + xmlUpdateFile); - - if (updateFiles.empty()) - { - logger->log("Warning this server does not have a" - " %s file falling back to %s", xmlUpdateFile.c_str(), - txtUpdateFile.c_str()); - updateFiles = loadTxtFile(dir + "/" + txtUpdateFile); - } - - std::string fixPath = dir + "/fix"; - for (unsigned int updateIndex = 0; - updateIndex < updateFiles.size(); updateIndex++) - { - UpdaterWindow::addUpdateFile(resman, dir, fixPath, - updateFiles[updateIndex].name, false); - } -} - -void UpdaterWindow::addUpdateFile(ResourceManager *resman, std::string path, - std::string fixPath, std::string file, - bool append) -{ - if (!append) - resman->addToSearchPath(path + "/" + file, append); - - const std::string fixFile = fixPath + "/" + file; - struct stat statbuf; - if (!stat(fixFile.c_str(), &statbuf)) - resman->addToSearchPath(fixFile, append); - - if (append) - resman->addToSearchPath(path + "/" + file, append); -} - -void UpdaterWindow::logic() -{ - // Update Scroll logic - mScrollArea->logic(); - - // Synchronize label caption when necessary - { - MutexLocker lock(&mDownloadMutex); - - if (mLabel->getCaption() != mNewLabelCaption) - { - mLabel->setCaption(mNewLabelCaption); - mLabel->adjustSize(); - } - - mProgressBar->setProgress(mDownloadProgress); - if (mUpdateFiles.size() && mUpdateIndex <= mUpdateFiles.size()) - { - mProgressBar->setText(strprintf("%d/%d", - mUpdateIndex + 1, (int)mUpdateFiles.size() + 1)); - } - else - { - mProgressBar->setText(""); - } - } - - switch (mDownloadStatus) - { - case UPDATE_ERROR: - // TODO: Only send complete sentences to gettext - mBrowserBox->addRow(""); - mBrowserBox->addRow(_("##1 The update process is incomplete.")); - // TRANSLATORS: Continues "you try again later.". - mBrowserBox->addRow(_("##1 It is strongly recommended that")); - // TRANSLATORS: Begins "It is strongly recommended that". - mBrowserBox->addRow(_("##1 you try again later.")); - - mBrowserBox->addRow(mDownload->getError()); - mScrollArea->setVerticalScrollAmount( - mScrollArea->getVerticalMaxScroll()); - mDownloadStatus = UPDATE_COMPLETE; - break; - case UPDATE_NEWS: - if (mDownloadComplete) - { - // Parse current memory buffer as news and dispose of the data - loadNews(); - - mCurrentFile = xmlUpdateFile; - mStoreInMemory = false; - mDownloadStatus = UPDATE_LIST; - download(); // download() changes mDownloadComplete to false - } - break; - case UPDATE_PATCH: - if (mDownloadComplete) - { - // Parse current memory buffer as news and dispose of the data - loadPatch(); - -/* - mCurrentFile = "news.txt"; - mStoreInMemory = true; - mDownloadStatus = UPDATE_NEWS; - download(); // download() changes mDownloadComplete to false -*/ - mDownloadStatus = UPDATE_COMPLETE; - } - break; - - case UPDATE_LIST: - if (mDownloadComplete) - { - if (mCurrentFile == xmlUpdateFile) - { - mUpdateFiles = loadXMLFile( - mUpdatesDir + "/" + xmlUpdateFile); - - if (mUpdateFiles.empty()) - { - logger->log("Warning this server does not have a %s" - " file falling back to %s", - xmlUpdateFile.c_str(), - txtUpdateFile.c_str()); - - // If the resources.xml file fails, - // fall back onto a older version - mCurrentFile = txtUpdateFile; - mStoreInMemory = false; - mDownloadStatus = UPDATE_LIST; - download(); - break; - } - } - else if (mCurrentFile == txtUpdateFile) - { - mUpdateFiles = loadTxtFile( - mUpdatesDir + "/" + txtUpdateFile); - } - mStoreInMemory = false; - mDownloadStatus = UPDATE_RESOURCES; - } - break; - case UPDATE_RESOURCES: - if (mDownloadComplete) - { - if (mUpdateIndex < mUpdateFiles.size()) - { - updateFile thisFile = mUpdateFiles[mUpdateIndex]; - if (!thisFile.required) - { - // This statement checks to see if the file type - // is music, and if download-music is true - // If it fails, this statement returns true, - // and results in not downloading the file - // Else it will ignore the break, - // and download the file. - - if (!(thisFile.type == "music" - && config.getBoolValue("download-music"))) - { - mUpdateIndex++; - break; - } - } - mCurrentFile = thisFile.name; - std::string checksum; - checksum = thisFile.hash; - std::stringstream ss(checksum); - ss >> std::hex >> mCurrentChecksum; - - std::ifstream temp( - (mUpdatesDir + "/" + mCurrentFile).c_str()); - - if (!temp.is_open() || !validateFile(mUpdatesDir + "/" - + mCurrentFile, mCurrentChecksum)) - { - temp.close(); - download(); - } - else - { - temp.close(); - logger->log("%s already here", mCurrentFile.c_str()); - } - mUpdateIndex++; - } - else - { - // Download of updates completed -// mDownloadStatus = UPDATE_COMPLETE; - mCurrentFile = "latest.txt"; - mStoreInMemory = true; - mDownloadStatus = UPDATE_PATCH; - download(); // download() changes - // mDownloadComplete to false - } - } - break; - case UPDATE_COMPLETE: - enable(); - setLabel(_("Completed")); - break; - case UPDATE_IDLE: - break; - default: - logger->log("UpdaterWindow::logic unknown status: " - + toString(static_cast(mDownloadStatus))); - break; - } -} - -bool UpdaterWindow::validateFile(std::string filePath, unsigned long hash) -{ - FILE *file = fopen(filePath.c_str(), "rb"); - if (!file) - return false; - - unsigned long adler = Net::Download::fadler32(file); - fclose(file); - return adler == hash; -} diff --git a/src/gui/updatewindow.h b/src/gui/updatewindow.h deleted file mode 100644 index a1dc556d5..000000000 --- a/src/gui/updatewindow.h +++ /dev/null @@ -1,213 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 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 . - */ - -#ifndef UPDATERWINDOW_H -#define UPDATERWINDOW_H - -#include "gui/widgets/window.h" - -#include "net/download.h" - -#include "utils/mutex.h" - -#include -#include - -#include -#include - -class BrowserBox; -class Button; -class ProgressBar; -class ResourceManager; -class ScrollArea; - -struct updateFile -{ - public: - std::string name; - std::string hash; - std::string type; - bool required; - std::string desc; -}; - -/** - * Update progress window GUI - * - * \ingroup GUI - */ -class UpdaterWindow : public Window, public gcn::ActionListener, - public gcn::KeyListener -{ - public: - /** - * Constructor. - * - * @param updateHost Host where to get the updated files. - * @param updatesDir Directory where to store updates (should be absolute - * and already created). - * @param applyUpdates If true, the update window will pass the updates to teh - * resource manager - */ - UpdaterWindow(const std::string &updateHost, - const std::string &updatesDir, - bool applyUpdates, int updateType); - - /** - * Destructor - */ - ~UpdaterWindow(); - - /** - * Set's progress bar status - */ - void setProgress(float p); - - /** - * Set's label above progress - */ - void setLabel(const std::string &); - - /** - * Enables play button - */ - void enable(); - - /** - * Loads and display news. Assumes the news file contents have been loaded - * into the memory buffer. - */ - void loadNews(); - - void loadPatch(); - - void action(const gcn::ActionEvent &event); - - void keyPressed(gcn::KeyEvent &keyEvent); - - void logic(); - - static void loadLocalUpdates(std::string dir); - - static void addUpdateFile(ResourceManager *resman, std::string path, - std::string fixPath, std::string file, - bool append); - - int updateState; - -private: - void download(); - - /** - * Loads the updates this window has gotten into the resource manager - */ - void loadUpdates(); - - - /** - * A download callback for progress updates. - */ - static int updateProgress(void *ptr, DownloadStatus status, - size_t dt, size_t dn); - - /** - * A libcurl callback for writing to memory. - */ - static size_t memoryWrite(void *ptr, size_t size, size_t nmemb, - void *stream); - - bool validateFile(std::string filePath, unsigned long hash); - - enum UpdateDownloadStatus - { - UPDATE_ERROR = 0, - UPDATE_IDLE, - UPDATE_LIST, - UPDATE_COMPLETE, - UPDATE_NEWS, - UPDATE_RESOURCES, - UPDATE_PATCH - }; - - /** Status of the current download. */ - UpdateDownloadStatus mDownloadStatus; - - /** Host where we get the updated files. */ - std::string mUpdateHost; - - /** Place where the updates are stored (absolute path). */ - std::string mUpdatesDir; - - /** The file currently downloading. */ - std::string mCurrentFile; - - /** The new label caption to be set in the logic method. */ - std::string mNewLabelCaption; - - /** The new progress value to be set in the logic method. */ - float mDownloadProgress; - - /** The mutex used to guard access to mNewLabelCaption and mDownloadProgress. */ - Mutex mDownloadMutex; - - /** The Adler32 checksum of the file currently downloading. */ - unsigned long mCurrentChecksum; - - /** A flag to indicate whether to use a memory buffer or a regular file. */ - bool mStoreInMemory; - - /** Flag that show if current download is complete. */ - bool mDownloadComplete; - - /** Flag that show if the user has canceled the update. */ - bool mUserCancel; - - /** Byte count currently downloaded in mMemoryBuffer. */ - int mDownloadedBytes; - - /** Buffer for files downloaded to memory. */ - char *mMemoryBuffer; - - /** Download handle. */ - Net::Download *mDownload; - - /** List of files to download. */ - std::vector mUpdateFiles; - - /** Index of the file to be downloaded. */ - unsigned int mUpdateIndex; - - /** Tells ~UpdaterWindow() if it should load updates */ - bool mLoadUpdates; - - int mUpdateType; - - gcn::Label *mLabel; /**< Progress bar caption. */ - Button *mCancelButton; /**< Button to stop the update process. */ - Button *mPlayButton; /**< Button to start playing. */ - ProgressBar *mProgressBar; /**< Update progress bar. */ - BrowserBox *mBrowserBox; /**< Box to display news. */ - ScrollArea *mScrollArea; /**< Used to scroll news box. */ -}; - -#endif -- cgit v1.2.3-70-g09d2 From a15b0fd17f1f79074743c530a5f7afd3e83367a5 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 12 Aug 2011 03:56:04 +0300 Subject: Fix define once label names in logger.h and chatlogger.h. --- src/chatlogger.h | 4 ++-- src/logger.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/chatlogger.h b/src/chatlogger.h index 2e9545b04..6e096ac89 100644 --- a/src/chatlogger.h +++ b/src/chatlogger.h @@ -21,8 +21,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef M_CHATLOG_H -#define M_CHATLOG_H +#ifndef M_CHATLOGGER_H +#define M_CHATLOGGER_H #include #include diff --git a/src/logger.h b/src/logger.h index b8517f696..c2fabb383 100644 --- a/src/logger.h +++ b/src/logger.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef M_LOG_H -#define M_LOG_H +#ifndef M_LOGGER_H +#define M_LOGGER_H #include "main.h" #include -- cgit v1.2.3-70-g09d2 From b2c9a0fa784997232141336dca358295bd57a75f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 12 Aug 2011 04:03:26 +0300 Subject: Rename file name ministatus to correct ministatuswindow. --- manaplus.cbp | 4 +- src/CMakeLists.txt | 4 +- src/Makefile.am | 4 +- src/game.cpp | 2 +- src/gui/ministatus.cpp | 473 ---------------------------------------- src/gui/ministatus.h | 127 ----------- src/gui/ministatuswindow.cpp | 473 ++++++++++++++++++++++++++++++++++++++++ src/gui/ministatuswindow.h | 127 +++++++++++ src/gui/popupmenu.cpp | 2 +- src/gui/viewport.cpp | 2 +- src/localplayer.cpp | 2 +- src/net/ea/inventoryhandler.cpp | 2 +- 12 files changed, 611 insertions(+), 611 deletions(-) delete mode 100644 src/gui/ministatus.cpp delete mode 100644 src/gui/ministatus.h create mode 100644 src/gui/ministatuswindow.cpp create mode 100644 src/gui/ministatuswindow.h (limited to 'src') diff --git a/manaplus.cbp b/manaplus.cbp index de71b2947..0083d9c8b 100644 --- a/manaplus.cbp +++ b/manaplus.cbp @@ -196,8 +196,8 @@ - - + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8a0135790..655d4896c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -267,8 +267,8 @@ SET(SRCS gui/logindialog.h gui/minimap.cpp gui/minimap.h - gui/ministatus.cpp - gui/ministatus.h + gui/ministatuswindow.cpp + gui/ministatuswindow.h gui/npcdialog.cpp gui/npcdialog.h gui/npcpostdialog.cpp diff --git a/src/Makefile.am b/src/Makefile.am index e6d84e016..8bacf6803 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -270,8 +270,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ gui/logindialog.h \ gui/minimap.cpp \ gui/minimap.h \ - gui/ministatus.cpp \ - gui/ministatus.h \ + gui/ministatuswindow.cpp \ + gui/ministatuswindow.h \ gui/npcdialog.cpp \ gui/npcdialog.h \ gui/npcpostdialog.cpp \ diff --git a/src/game.cpp b/src/game.cpp index 4967231b0..4e7345340 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -60,7 +60,7 @@ #include "gui/inventorywindow.h" #include "gui/killstats.h" #include "gui/minimap.h" -#include "gui/ministatus.h" +#include "gui/ministatuswindow.h" #include "gui/npcpostdialog.h" #include "gui/okdialog.h" #include "gui/outfitwindow.h" diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp deleted file mode 100644 index 817cd74a5..000000000 --- a/src/gui/ministatus.cpp +++ /dev/null @@ -1,473 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 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 . - */ - -#include "gui/ministatus.h" - -#include "animatedsprite.h" -#include "configuration.h" -#include "graphics.h" -#include "playerinfo.h" - -#include "gui/chatwindow.h" -#include "gui/gui.h" -#include "gui/statuswindow.h" -#include "gui/statuspopup.h" -#include "gui/textpopup.h" -#include "gui/theme.h" -#include "gui/viewport.h" - -#include "gui/widgets/chattab.h" -#include "gui/widgets/label.h" -#include "gui/widgets/progressbar.h" - -#include "net/net.h" -#include "net/playerhandler.h" -#include "net/gamehandler.h" - -#include "utils/dtor.h" -#include "utils/gettext.h" -#include "utils/stringutils.h" - -#include "debug.h" - -extern volatile int tick_time; - -MiniStatusWindow::MiniStatusWindow(): - Popup("MiniStatus") -{ - listen(Mana::CHANNEL_ATTRIBUTES); - - mHpBar = createBar(0, 100, 20, Theme::PROG_HP, "hp bar", _("health bar")); - StatusWindow::updateHPBar(mHpBar); - - if (Net::getGameHandler()->canUseMagicBar()) - { - mMpBar = createBar(0, 100, 20, Net::getPlayerHandler()->canUseMagic() - ? Theme::PROG_MP : Theme::PROG_NO_MP, "mp bar", _("mana bar")); - StatusWindow::updateMPBar(mMpBar); - } - else - { - mMpBar = 0; - } - - int job = Net::getPlayerHandler()->getJobLocation() - && serverConfig.getValueBool("showJob", false); - - mXpBar = createBar(0, 100, 20, Theme::PROG_EXP, - "xp bar", _("experience bar")); - StatusWindow::updateXPBar(mXpBar); - - if (job) - { - mJobBar = createBar(0, 100, 20, Theme::PROG_JOB, "job bar", - _("job bar")); - StatusWindow::updateJobBar(mJobBar); - } - else - { - mJobBar = 0; - } - - mWeightBar = createBar(0, 140, 20, Theme::PROG_WEIGHT, - "weight bar", _("weight bar")); - - mInvSlotsBar = createBar(0, 45, 20, Theme::PROG_INVY_SLOTS, - "inventory slots bar", _("inventory slots bar")); - - mMoneyBar = createBar(0, 130, 20, Theme::PROG_INVY_SLOTS, - "money bar", _("money bar")); - - mArrowsBar = createBar(0, 50, 20, Theme::PROG_INVY_SLOTS, - "arrows bar", _("arrows bar")); - - mStatusBar = createBar(100, 150, 20, Theme::PROG_EXP, - "status bar", _("status bar")); - - loadBars(); - updateBars(); - - setVisible(config.getValueBool(getPopupName() + "Visible", true)); - - mStatusPopup = new StatusPopup(); - mTextPopup = new TextPopup(); - - addMouseListener(this); - Inventory *inv = PlayerInfo::getInventory(); - if (inv) - inv->addInventoyListener(this); - - StatusWindow::updateMoneyBar(mMoneyBar); - StatusWindow::updateArrowsBar(mArrowsBar); - updateStatus(); -} - -MiniStatusWindow::~MiniStatusWindow() -{ - delete mTextPopup; - mTextPopup = 0; - delete mStatusPopup; - mStatusPopup = 0; - delete_all(mIcons); - mIcons.clear(); - - Inventory *inv = PlayerInfo::getInventory(); - if (inv) - inv->removeInventoyListener(this); - - std::vector ::iterator it, it_end; - for (it = mBars.begin(), it_end = mBars.end(); it != it_end; ++it) - { - ProgressBar *bar = *it; - if (!bar) - continue; - if (!bar->isVisible()) - delete bar; - } -} - -ProgressBar *MiniStatusWindow::createBar(float progress, int width, int height, - int color, std::string name, - std::string description) -{ - ProgressBar *bar = new ProgressBar(progress, width, height, color); - bar->setActionEventId(name); - bar->setId(description); - mBars.push_back(bar); - mBarNames[name] = bar; - return bar; -} - -void MiniStatusWindow::updateBars() -{ - int x = 0; - std::vector ::iterator it, it_end; - ProgressBar* lastBar = 0; - for (it = mBars.begin(), it_end = mBars.end(); it != it_end; ++it) - safeRemove(*it); - for (it = mBars.begin(), it_end = mBars.end(); it != it_end; ++it) - { - ProgressBar *bar = *it; - if (!bar) - continue; - if (bar->isVisible()) - { - bar->setPosition(x, 3); - add(bar); - x += bar->getWidth() + 3; - lastBar = bar; - } - } - - if (lastBar) - { - setContentSize(lastBar->getX() + lastBar->getWidth(), - lastBar->getY() + lastBar->getHeight()); - } -} - -void MiniStatusWindow::setIcon(int index, AnimatedSprite *sprite) -{ - if (index >= static_cast(mIcons.size())) - mIcons.resize(index + 1, 0); - - delete mIcons[index]; - - mIcons[index] = sprite; -} - -void MiniStatusWindow::eraseIcon(int index) -{ - if (index < static_cast(mIcons.size())) - { - delete mIcons[index]; - mIcons.erase(mIcons.begin() + index); - } -} - -void MiniStatusWindow::drawIcons(Graphics *graphics) -{ - // Draw icons - int icon_x = mStatusBar->getX() + mStatusBar->getWidth() + 4; - for (unsigned int i = 0; i < mIcons.size(); i++) - { - if (mIcons[i]) - { - mIcons[i]->draw(graphics, icon_x, 3); - icon_x += 2 + mIcons[i]->getWidth(); - } - } -} - -void MiniStatusWindow::event(Mana::Channels channel A_UNUSED, - const Mana::Event &event) -{ - if (event.getName() == Mana::EVENT_UPDATEATTRIBUTE) - { - int id = event.getInt("id"); - if (id == HP || id == MAX_HP) - StatusWindow::updateHPBar(mHpBar); - else if (id == MP || id == MAX_MP) - StatusWindow::updateMPBar(mMpBar); - else if (id == EXP || id == EXP_NEEDED) - StatusWindow::updateXPBar(mXpBar); - else if (id == TOTAL_WEIGHT || id == MAX_WEIGHT) - StatusWindow::updateWeightBar(mWeightBar); - else if (id == MONEY) - StatusWindow::updateMoneyBar(mMoneyBar); - } - else if (event.getName() == Mana::EVENT_UPDATESTAT) - { - StatusWindow::updateMPBar(mMpBar); - StatusWindow::updateJobBar(mJobBar); - } -} - -void MiniStatusWindow::updateStatus() -{ - StatusWindow::updateStatusBar(mStatusBar); - if (mStatusPopup && mStatusPopup->isVisible()) - mStatusPopup->update(); -} - -void MiniStatusWindow::logic() -{ - Popup::logic(); - - for (unsigned int i = 0; i < mIcons.size(); i++) - { - if (mIcons[i]) - mIcons[i]->update(tick_time * 10); - } -} - -void MiniStatusWindow::draw(gcn::Graphics *graphics) -{ - drawChildren(graphics); -} - -void MiniStatusWindow::mouseMoved(gcn::MouseEvent &event) -{ - Popup::mouseMoved(event); - - const int x = event.getX(); - const int y = event.getY(); - - if (event.getSource() == mStatusBar) - { - mStatusPopup->view(x + getX(), y + getY()); - mTextPopup->hide(); - } - else if (event.getSource() == mXpBar) - { - if (PlayerInfo::getAttribute(EXP) - > PlayerInfo::getAttribute(EXP_NEEDED)) - { - mTextPopup->show(x + getX(), y + getY(), - event.getSource()->getId(), - strprintf("%u/%u", PlayerInfo::getAttribute(EXP), - PlayerInfo::getAttribute(EXP_NEEDED))); - } - else - { - mTextPopup->show(x + getX(), y + getY(), - event.getSource()->getId(), - strprintf("%u/%u", PlayerInfo::getAttribute(EXP), - PlayerInfo::getAttribute(EXP_NEEDED)), - strprintf("%s: %u", _("Need"), - PlayerInfo::getAttribute(EXP_NEEDED) - - PlayerInfo::getAttribute(EXP))); - } - mStatusPopup->hide(); - } - else if (event.getSource() == mHpBar) - { - mTextPopup->show(x + getX(), y + getY(), - event.getSource()->getId(), - strprintf("%u/%u", PlayerInfo::getAttribute(HP), - PlayerInfo::getAttribute(MAX_HP))); - mStatusPopup->hide(); - } - else if (event.getSource() == mMpBar) - { - mTextPopup->show(x + getX(), y + getY(), - event.getSource()->getId(), - strprintf("%u/%u", PlayerInfo::getAttribute(MP), - PlayerInfo::getAttribute(MAX_MP))); - mStatusPopup->hide(); - } - else if (event.getSource() == mJobBar) - { - std::pair exp = PlayerInfo::getStatExperience( - Net::getPlayerHandler()->getJobLocation()); - - if (exp.first > exp.second) - { - mTextPopup->show(x + getX(), y + getY(), - event.getSource()->getId(), - strprintf("%u/%u", exp.first, - exp.second)); - } - else - { - mTextPopup->show(x + getX(), y + getY(), - event.getSource()->getId(), - strprintf("%u/%u", exp.first, - exp.second), - strprintf("%s: %u", _("Need"), - exp.second - - exp.first)); - } - mStatusPopup->hide(); - } - else if (event.getSource() == mWeightBar) - { - mTextPopup->show(x + getX(), y + getY(), - event.getSource()->getId(), - strprintf("%u/%u", PlayerInfo::getAttribute(TOTAL_WEIGHT), - PlayerInfo::getAttribute(MAX_WEIGHT))); - mStatusPopup->hide(); - } - else if (event.getSource() == mInvSlotsBar) - { - Inventory *inv = PlayerInfo::getInventory(); - if (inv) - { - const int usedSlots = inv->getNumberOfSlotsUsed(); - const int maxSlots = inv->getSize(); - - mTextPopup->show(x + getX(), y + getY(), - event.getSource()->getId(), - strprintf("%u/%u", usedSlots, maxSlots)); - } - mStatusPopup->hide(); - } - else if (event.getSource() == mMoneyBar) - { - mTextPopup->show(x + getX(), y + getY(), - event.getSource()->getId(), - toString(PlayerInfo::getAttribute(MONEY))); - } - else - { - mTextPopup->hide(); - mStatusPopup->hide(); - } -} - -void MiniStatusWindow::mousePressed(gcn::MouseEvent &event) -{ - if (!viewport) - return; - - if (event.getButton() == gcn::MouseEvent::RIGHT) - { - ProgressBar *bar = dynamic_cast(event.getSource()); - if (!bar) - return; - if (viewport) - { - viewport->showPopup(getX() + event.getX(), - getY() + event.getY(), bar); - } - } -} - -void MiniStatusWindow::mouseExited(gcn::MouseEvent &event) -{ - Popup::mouseExited(event); - - mTextPopup->hide(); - mStatusPopup->hide(); -} - -void MiniStatusWindow::showBar(std::string name, bool isVisible) -{ - ProgressBar *bar = mBarNames[name]; - if (!bar) - return; - bar->setVisible(isVisible); - updateBars(); - saveBars(); -} - -void MiniStatusWindow::loadBars() -{ - if (!config.getValue("ministatussaved", 0)) - { - if (mWeightBar) - mWeightBar->setVisible(false); - if (mInvSlotsBar) - mInvSlotsBar->setVisible(false); - if (mMoneyBar) - mMoneyBar->setVisible(false); - if (mArrowsBar) - mArrowsBar->setVisible(false); - return; - } - - for (int f = 0; f < 10; f ++) - { - std::string str = config.getValue("ministatus" + toString(f), ""); - if (str == "" || str == "status bar") - continue; - ProgressBar *bar = mBarNames[str]; - if (!bar) - continue; - bar->setVisible(false); - } -} - -void MiniStatusWindow::saveBars() -{ - std::vector ::iterator it, it_end; - int i = 0; - for (it = mBars.begin(), it_end = mBars.end(); - it != it_end; ++it) - { - ProgressBar *bar = *it; - if (!bar->isVisible()) - { - config.setValue("ministatus" + toString(i), - bar->getActionEventId()); - i ++; - } - } - for (int f = i; f < 10; f ++) - config.deleteKey("ministatus" + toString(f)); - - config.setValue("ministatussaved", true); -} - -void MiniStatusWindow::slotsChanged(Inventory* inventory) -{ - if (!inventory) - return; - - if (inventory->getType() == Inventory::INVENTORY) - StatusWindow::updateInvSlotsBar(mInvSlotsBar); -} - -void MiniStatusWindow::updateArrows() -{ - StatusWindow::updateArrowsBar(mArrowsBar); -} diff --git a/src/gui/ministatus.h b/src/gui/ministatus.h deleted file mode 100644 index f19055305..000000000 --- a/src/gui/ministatus.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 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 . - */ - -#ifndef MINISTATUS_H -#define MINISTATUS_H - -#include "inventory.h" -#include "listener.h" - -#include "gui/widgets/popup.h" -#include "gui/widgets/window.h" - -#include - -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - -class AnimatedSprite; -class Graphics; -class ProgressBar; -class StatusPopup; -class TextPopup; - -/** - * The player mini-status dialog. - * - * \ingroup Interface - */ -class MiniStatusWindow : public Popup, - public InventoryListener, - public Mana::Listener -{ - public: - MiniStatusWindow(); - - ~MiniStatusWindow(); - - /** - * Sets one of the icons. - */ - void setIcon(int index, AnimatedSprite *sprite); - - void eraseIcon(int index); - - void drawIcons(Graphics *graphics); - - void event(Mana::Channels channel, const Mana::Event &event); - - void updateStatus(); - - void logic(); // Updates icons - - void draw(gcn::Graphics *graphics); - - void mouseMoved(gcn::MouseEvent &mouseEvent); - - void mousePressed(gcn::MouseEvent &event); - - void mouseExited(gcn::MouseEvent &event); - - void showBar(std::string name, bool isVisible); - - void updateBars(); - - void updateArrows(); - - void slotsChanged(Inventory* inventory); - - std::vector &getBars() - { return mBars; } - - private: - bool isInBar(ProgressBar *bar, int x, int y) const; - - ProgressBar *createBar(float progress, int width, int height, - int color, std::string name, - std::string description); - - void loadBars(); - - void saveBars(); - - /* - * Mini Status Bars - */ - ProgressBar *mHpBar; - ProgressBar *mMpBar; - ProgressBar *mXpBar; - ProgressBar *mJobBar; - ProgressBar *mWeightBar; - ProgressBar *mInvSlotsBar; - ProgressBar *mMoneyBar; - ProgressBar *mArrowsBar; - ProgressBar *mStatusBar; - TextPopup *mTextPopup; - StatusPopup *mStatusPopup; - std::vector mBars; - std::map mBarNames; - - std::vector mIcons; -}; - -extern MiniStatusWindow *miniStatusWindow; - -#endif diff --git a/src/gui/ministatuswindow.cpp b/src/gui/ministatuswindow.cpp new file mode 100644 index 000000000..08e3d0053 --- /dev/null +++ b/src/gui/ministatuswindow.cpp @@ -0,0 +1,473 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 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 . + */ + +#include "gui/ministatuswindow.h" + +#include "animatedsprite.h" +#include "configuration.h" +#include "graphics.h" +#include "playerinfo.h" + +#include "gui/chatwindow.h" +#include "gui/gui.h" +#include "gui/statuswindow.h" +#include "gui/statuspopup.h" +#include "gui/textpopup.h" +#include "gui/theme.h" +#include "gui/viewport.h" + +#include "gui/widgets/chattab.h" +#include "gui/widgets/label.h" +#include "gui/widgets/progressbar.h" + +#include "net/net.h" +#include "net/playerhandler.h" +#include "net/gamehandler.h" + +#include "utils/dtor.h" +#include "utils/gettext.h" +#include "utils/stringutils.h" + +#include "debug.h" + +extern volatile int tick_time; + +MiniStatusWindow::MiniStatusWindow(): + Popup("MiniStatus") +{ + listen(Mana::CHANNEL_ATTRIBUTES); + + mHpBar = createBar(0, 100, 20, Theme::PROG_HP, "hp bar", _("health bar")); + StatusWindow::updateHPBar(mHpBar); + + if (Net::getGameHandler()->canUseMagicBar()) + { + mMpBar = createBar(0, 100, 20, Net::getPlayerHandler()->canUseMagic() + ? Theme::PROG_MP : Theme::PROG_NO_MP, "mp bar", _("mana bar")); + StatusWindow::updateMPBar(mMpBar); + } + else + { + mMpBar = 0; + } + + int job = Net::getPlayerHandler()->getJobLocation() + && serverConfig.getValueBool("showJob", false); + + mXpBar = createBar(0, 100, 20, Theme::PROG_EXP, + "xp bar", _("experience bar")); + StatusWindow::updateXPBar(mXpBar); + + if (job) + { + mJobBar = createBar(0, 100, 20, Theme::PROG_JOB, "job bar", + _("job bar")); + StatusWindow::updateJobBar(mJobBar); + } + else + { + mJobBar = 0; + } + + mWeightBar = createBar(0, 140, 20, Theme::PROG_WEIGHT, + "weight bar", _("weight bar")); + + mInvSlotsBar = createBar(0, 45, 20, Theme::PROG_INVY_SLOTS, + "inventory slots bar", _("inventory slots bar")); + + mMoneyBar = createBar(0, 130, 20, Theme::PROG_INVY_SLOTS, + "money bar", _("money bar")); + + mArrowsBar = createBar(0, 50, 20, Theme::PROG_INVY_SLOTS, + "arrows bar", _("arrows bar")); + + mStatusBar = createBar(100, 150, 20, Theme::PROG_EXP, + "status bar", _("status bar")); + + loadBars(); + updateBars(); + + setVisible(config.getValueBool(getPopupName() + "Visible", true)); + + mStatusPopup = new StatusPopup(); + mTextPopup = new TextPopup(); + + addMouseListener(this); + Inventory *inv = PlayerInfo::getInventory(); + if (inv) + inv->addInventoyListener(this); + + StatusWindow::updateMoneyBar(mMoneyBar); + StatusWindow::updateArrowsBar(mArrowsBar); + updateStatus(); +} + +MiniStatusWindow::~MiniStatusWindow() +{ + delete mTextPopup; + mTextPopup = 0; + delete mStatusPopup; + mStatusPopup = 0; + delete_all(mIcons); + mIcons.clear(); + + Inventory *inv = PlayerInfo::getInventory(); + if (inv) + inv->removeInventoyListener(this); + + std::vector ::iterator it, it_end; + for (it = mBars.begin(), it_end = mBars.end(); it != it_end; ++it) + { + ProgressBar *bar = *it; + if (!bar) + continue; + if (!bar->isVisible()) + delete bar; + } +} + +ProgressBar *MiniStatusWindow::createBar(float progress, int width, int height, + int color, std::string name, + std::string description) +{ + ProgressBar *bar = new ProgressBar(progress, width, height, color); + bar->setActionEventId(name); + bar->setId(description); + mBars.push_back(bar); + mBarNames[name] = bar; + return bar; +} + +void MiniStatusWindow::updateBars() +{ + int x = 0; + std::vector ::iterator it, it_end; + ProgressBar* lastBar = 0; + for (it = mBars.begin(), it_end = mBars.end(); it != it_end; ++it) + safeRemove(*it); + for (it = mBars.begin(), it_end = mBars.end(); it != it_end; ++it) + { + ProgressBar *bar = *it; + if (!bar) + continue; + if (bar->isVisible()) + { + bar->setPosition(x, 3); + add(bar); + x += bar->getWidth() + 3; + lastBar = bar; + } + } + + if (lastBar) + { + setContentSize(lastBar->getX() + lastBar->getWidth(), + lastBar->getY() + lastBar->getHeight()); + } +} + +void MiniStatusWindow::setIcon(int index, AnimatedSprite *sprite) +{ + if (index >= static_cast(mIcons.size())) + mIcons.resize(index + 1, 0); + + delete mIcons[index]; + + mIcons[index] = sprite; +} + +void MiniStatusWindow::eraseIcon(int index) +{ + if (index < static_cast(mIcons.size())) + { + delete mIcons[index]; + mIcons.erase(mIcons.begin() + index); + } +} + +void MiniStatusWindow::drawIcons(Graphics *graphics) +{ + // Draw icons + int icon_x = mStatusBar->getX() + mStatusBar->getWidth() + 4; + for (unsigned int i = 0; i < mIcons.size(); i++) + { + if (mIcons[i]) + { + mIcons[i]->draw(graphics, icon_x, 3); + icon_x += 2 + mIcons[i]->getWidth(); + } + } +} + +void MiniStatusWindow::event(Mana::Channels channel A_UNUSED, + const Mana::Event &event) +{ + if (event.getName() == Mana::EVENT_UPDATEATTRIBUTE) + { + int id = event.getInt("id"); + if (id == HP || id == MAX_HP) + StatusWindow::updateHPBar(mHpBar); + else if (id == MP || id == MAX_MP) + StatusWindow::updateMPBar(mMpBar); + else if (id == EXP || id == EXP_NEEDED) + StatusWindow::updateXPBar(mXpBar); + else if (id == TOTAL_WEIGHT || id == MAX_WEIGHT) + StatusWindow::updateWeightBar(mWeightBar); + else if (id == MONEY) + StatusWindow::updateMoneyBar(mMoneyBar); + } + else if (event.getName() == Mana::EVENT_UPDATESTAT) + { + StatusWindow::updateMPBar(mMpBar); + StatusWindow::updateJobBar(mJobBar); + } +} + +void MiniStatusWindow::updateStatus() +{ + StatusWindow::updateStatusBar(mStatusBar); + if (mStatusPopup && mStatusPopup->isVisible()) + mStatusPopup->update(); +} + +void MiniStatusWindow::logic() +{ + Popup::logic(); + + for (unsigned int i = 0; i < mIcons.size(); i++) + { + if (mIcons[i]) + mIcons[i]->update(tick_time * 10); + } +} + +void MiniStatusWindow::draw(gcn::Graphics *graphics) +{ + drawChildren(graphics); +} + +void MiniStatusWindow::mouseMoved(gcn::MouseEvent &event) +{ + Popup::mouseMoved(event); + + const int x = event.getX(); + const int y = event.getY(); + + if (event.getSource() == mStatusBar) + { + mStatusPopup->view(x + getX(), y + getY()); + mTextPopup->hide(); + } + else if (event.getSource() == mXpBar) + { + if (PlayerInfo::getAttribute(EXP) + > PlayerInfo::getAttribute(EXP_NEEDED)) + { + mTextPopup->show(x + getX(), y + getY(), + event.getSource()->getId(), + strprintf("%u/%u", PlayerInfo::getAttribute(EXP), + PlayerInfo::getAttribute(EXP_NEEDED))); + } + else + { + mTextPopup->show(x + getX(), y + getY(), + event.getSource()->getId(), + strprintf("%u/%u", PlayerInfo::getAttribute(EXP), + PlayerInfo::getAttribute(EXP_NEEDED)), + strprintf("%s: %u", _("Need"), + PlayerInfo::getAttribute(EXP_NEEDED) + - PlayerInfo::getAttribute(EXP))); + } + mStatusPopup->hide(); + } + else if (event.getSource() == mHpBar) + { + mTextPopup->show(x + getX(), y + getY(), + event.getSource()->getId(), + strprintf("%u/%u", PlayerInfo::getAttribute(HP), + PlayerInfo::getAttribute(MAX_HP))); + mStatusPopup->hide(); + } + else if (event.getSource() == mMpBar) + { + mTextPopup->show(x + getX(), y + getY(), + event.getSource()->getId(), + strprintf("%u/%u", PlayerInfo::getAttribute(MP), + PlayerInfo::getAttribute(MAX_MP))); + mStatusPopup->hide(); + } + else if (event.getSource() == mJobBar) + { + std::pair exp = PlayerInfo::getStatExperience( + Net::getPlayerHandler()->getJobLocation()); + + if (exp.first > exp.second) + { + mTextPopup->show(x + getX(), y + getY(), + event.getSource()->getId(), + strprintf("%u/%u", exp.first, + exp.second)); + } + else + { + mTextPopup->show(x + getX(), y + getY(), + event.getSource()->getId(), + strprintf("%u/%u", exp.first, + exp.second), + strprintf("%s: %u", _("Need"), + exp.second + - exp.first)); + } + mStatusPopup->hide(); + } + else if (event.getSource() == mWeightBar) + { + mTextPopup->show(x + getX(), y + getY(), + event.getSource()->getId(), + strprintf("%u/%u", PlayerInfo::getAttribute(TOTAL_WEIGHT), + PlayerInfo::getAttribute(MAX_WEIGHT))); + mStatusPopup->hide(); + } + else if (event.getSource() == mInvSlotsBar) + { + Inventory *inv = PlayerInfo::getInventory(); + if (inv) + { + const int usedSlots = inv->getNumberOfSlotsUsed(); + const int maxSlots = inv->getSize(); + + mTextPopup->show(x + getX(), y + getY(), + event.getSource()->getId(), + strprintf("%u/%u", usedSlots, maxSlots)); + } + mStatusPopup->hide(); + } + else if (event.getSource() == mMoneyBar) + { + mTextPopup->show(x + getX(), y + getY(), + event.getSource()->getId(), + toString(PlayerInfo::getAttribute(MONEY))); + } + else + { + mTextPopup->hide(); + mStatusPopup->hide(); + } +} + +void MiniStatusWindow::mousePressed(gcn::MouseEvent &event) +{ + if (!viewport) + return; + + if (event.getButton() == gcn::MouseEvent::RIGHT) + { + ProgressBar *bar = dynamic_cast(event.getSource()); + if (!bar) + return; + if (viewport) + { + viewport->showPopup(getX() + event.getX(), + getY() + event.getY(), bar); + } + } +} + +void MiniStatusWindow::mouseExited(gcn::MouseEvent &event) +{ + Popup::mouseExited(event); + + mTextPopup->hide(); + mStatusPopup->hide(); +} + +void MiniStatusWindow::showBar(std::string name, bool isVisible) +{ + ProgressBar *bar = mBarNames[name]; + if (!bar) + return; + bar->setVisible(isVisible); + updateBars(); + saveBars(); +} + +void MiniStatusWindow::loadBars() +{ + if (!config.getValue("ministatussaved", 0)) + { + if (mWeightBar) + mWeightBar->setVisible(false); + if (mInvSlotsBar) + mInvSlotsBar->setVisible(false); + if (mMoneyBar) + mMoneyBar->setVisible(false); + if (mArrowsBar) + mArrowsBar->setVisible(false); + return; + } + + for (int f = 0; f < 10; f ++) + { + std::string str = config.getValue("ministatus" + toString(f), ""); + if (str == "" || str == "status bar") + continue; + ProgressBar *bar = mBarNames[str]; + if (!bar) + continue; + bar->setVisible(false); + } +} + +void MiniStatusWindow::saveBars() +{ + std::vector ::iterator it, it_end; + int i = 0; + for (it = mBars.begin(), it_end = mBars.end(); + it != it_end; ++it) + { + ProgressBar *bar = *it; + if (!bar->isVisible()) + { + config.setValue("ministatus" + toString(i), + bar->getActionEventId()); + i ++; + } + } + for (int f = i; f < 10; f ++) + config.deleteKey("ministatus" + toString(f)); + + config.setValue("ministatussaved", true); +} + +void MiniStatusWindow::slotsChanged(Inventory* inventory) +{ + if (!inventory) + return; + + if (inventory->getType() == Inventory::INVENTORY) + StatusWindow::updateInvSlotsBar(mInvSlotsBar); +} + +void MiniStatusWindow::updateArrows() +{ + StatusWindow::updateArrowsBar(mArrowsBar); +} diff --git a/src/gui/ministatuswindow.h b/src/gui/ministatuswindow.h new file mode 100644 index 000000000..19517326b --- /dev/null +++ b/src/gui/ministatuswindow.h @@ -0,0 +1,127 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 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 . + */ + +#ifndef MINISTATUSWINDOW_H +#define MINISTATUSWINDOW_H + +#include "inventory.h" +#include "listener.h" + +#include "gui/widgets/popup.h" +#include "gui/widgets/window.h" + +#include + +#ifdef __GNUC__ +#define A_UNUSED __attribute__ ((unused)) +#else +#define A_UNUSED +#endif + +class AnimatedSprite; +class Graphics; +class ProgressBar; +class StatusPopup; +class TextPopup; + +/** + * The player mini-status dialog. + * + * \ingroup Interface + */ +class MiniStatusWindow : public Popup, + public InventoryListener, + public Mana::Listener +{ + public: + MiniStatusWindow(); + + ~MiniStatusWindow(); + + /** + * Sets one of the icons. + */ + void setIcon(int index, AnimatedSprite *sprite); + + void eraseIcon(int index); + + void drawIcons(Graphics *graphics); + + void event(Mana::Channels channel, const Mana::Event &event); + + void updateStatus(); + + void logic(); // Updates icons + + void draw(gcn::Graphics *graphics); + + void mouseMoved(gcn::MouseEvent &mouseEvent); + + void mousePressed(gcn::MouseEvent &event); + + void mouseExited(gcn::MouseEvent &event); + + void showBar(std::string name, bool isVisible); + + void updateBars(); + + void updateArrows(); + + void slotsChanged(Inventory* inventory); + + std::vector &getBars() + { return mBars; } + + private: + bool isInBar(ProgressBar *bar, int x, int y) const; + + ProgressBar *createBar(float progress, int width, int height, + int color, std::string name, + std::string description); + + void loadBars(); + + void saveBars(); + + /* + * Mini Status Bars + */ + ProgressBar *mHpBar; + ProgressBar *mMpBar; + ProgressBar *mXpBar; + ProgressBar *mJobBar; + ProgressBar *mWeightBar; + ProgressBar *mInvSlotsBar; + ProgressBar *mMoneyBar; + ProgressBar *mArrowsBar; + ProgressBar *mStatusBar; + TextPopup *mTextPopup; + StatusPopup *mStatusPopup; + std::vector mBars; + std::map mBarNames; + + std::vector mIcons; +}; + +extern MiniStatusWindow *miniStatusWindow; + +#endif diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 86ddfda53..c95864396 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -44,7 +44,7 @@ #include "gui/equipmentwindow.h" #include "gui/inventorywindow.h" #include "gui/itemamountwindow.h" -#include "gui/ministatus.h" +#include "gui/ministatuswindow.h" #include "gui/outfitwindow.h" #include "gui/selldialog.h" #include "gui/socialwindow.h" diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 2ca59f524..70d02b016 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -36,7 +36,7 @@ #include "gui/beingpopup.h" #include "gui/chatwindow.h" #include "gui/gui.h" -#include "gui/ministatus.h" +#include "gui/ministatuswindow.h" #include "gui/popupmenu.h" #include "gui/statuspopup.h" #include "gui/textpopup.h" diff --git a/src/localplayer.cpp b/src/localplayer.cpp index a9e9d1f21..9f0a7c5f3 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -46,7 +46,7 @@ #include "gui/gui.h" #include "gui/inventorywindow.h" #include "gui/killstats.h" -#include "gui/ministatus.h" +#include "gui/ministatuswindow.h" #include "gui/okdialog.h" #include "gui/outfitwindow.h" #include "gui/palette.h" diff --git a/src/net/ea/inventoryhandler.cpp b/src/net/ea/inventoryhandler.cpp index d921b5e2a..01000f8f1 100644 --- a/src/net/ea/inventoryhandler.cpp +++ b/src/net/ea/inventoryhandler.cpp @@ -26,7 +26,7 @@ #include "localplayer.h" #include "logger.h" -#include "gui/ministatus.h" +#include "gui/ministatuswindow.h" #include "net/messagein.h" -- cgit v1.2.3-70-g09d2 From 0c7a728ea5c63769c59e7cdbd13fc56cf3dd63fc Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 12 Aug 2011 04:21:44 +0300 Subject: Rename file name table to correct guitable. --- manaplus.cbp | 4 +- src/CMakeLists.txt | 4 +- src/Makefile.am | 4 +- src/gui/botcheckerwindow.cpp | 2 +- src/gui/setup_relations.cpp | 2 +- src/gui/textcommandeditor.cpp | 2 +- src/gui/widgets/guitable.cpp | 595 ++++++++++++++++++++++++++++++++++++++++++ src/gui/widgets/guitable.h | 196 ++++++++++++++ src/gui/widgets/table.cpp | 595 ------------------------------------------ src/gui/widgets/table.h | 196 -------------- 10 files changed, 800 insertions(+), 800 deletions(-) create mode 100644 src/gui/widgets/guitable.cpp create mode 100644 src/gui/widgets/guitable.h delete mode 100644 src/gui/widgets/table.cpp delete mode 100644 src/gui/widgets/table.h (limited to 'src') diff --git a/manaplus.cbp b/manaplus.cbp index 0083d9c8b..f47e5c271 100644 --- a/manaplus.cbp +++ b/manaplus.cbp @@ -365,8 +365,8 @@ - - + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 655d4896c..fba255c1c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -197,8 +197,8 @@ SET(SRCS gui/widgets/tab.h gui/widgets/tabbedarea.cpp gui/widgets/tabbedarea.h - gui/widgets/table.cpp - gui/widgets/table.h + gui/widgets/guitable.cpp + gui/widgets/guitable.h gui/widgets/tablemodel.cpp gui/widgets/tablemodel.h gui/widgets/textbox.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 8bacf6803..697575b97 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -200,8 +200,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ gui/widgets/tab.h \ gui/widgets/tabbedarea.cpp \ gui/widgets/tabbedarea.h \ - gui/widgets/table.cpp \ - gui/widgets/table.h \ + gui/widgets/guitable.cpp \ + gui/widgets/guitable.h \ gui/widgets/tablemodel.cpp \ gui/widgets/tablemodel.h \ gui/widgets/textbox.cpp \ diff --git a/src/gui/botcheckerwindow.cpp b/src/gui/botcheckerwindow.cpp index aa44df2f3..2851d3d1d 100644 --- a/src/gui/botcheckerwindow.cpp +++ b/src/gui/botcheckerwindow.cpp @@ -36,7 +36,7 @@ #include "gui/widgets/label.h" #include "gui/widgets/layout.h" #include "gui/widgets/layouthelper.h" -#include "gui/widgets/table.h" +#include "gui/widgets/guitable.h" #include "actorspritemanager.h" #include "configuration.h" diff --git a/src/gui/setup_relations.cpp b/src/gui/setup_relations.cpp index 93887b133..489d5a818 100644 --- a/src/gui/setup_relations.cpp +++ b/src/gui/setup_relations.cpp @@ -36,7 +36,7 @@ #include "gui/widgets/label.h" #include "gui/widgets/layouthelper.h" #include "gui/widgets/scrollarea.h" -#include "gui/widgets/table.h" +#include "gui/widgets/guitable.h" #include "gui/widgets/textfield.h" #include "utils/dtor.h" diff --git a/src/gui/textcommandeditor.cpp b/src/gui/textcommandeditor.cpp index 1f1273600..8cf9fa398 100644 --- a/src/gui/textcommandeditor.cpp +++ b/src/gui/textcommandeditor.cpp @@ -38,7 +38,7 @@ #include "gui/widgets/layout.h" #include "gui/widgets/layouthelper.h" #include "gui/widgets/radiobutton.h" -#include "gui/widgets/table.h" +#include "gui/widgets/guitable.h" #include "gui/widgets/textfield.h" #include "configuration.h" diff --git a/src/gui/widgets/guitable.cpp b/src/gui/widgets/guitable.cpp new file mode 100644 index 000000000..e25e0bb8c --- /dev/null +++ b/src/gui/widgets/guitable.cpp @@ -0,0 +1,595 @@ +/* + * The ManaPlus Client + * Copyright (C) 2008-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 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 . + */ + +#include "gui/widgets/guitable.h" + +#include "client.h" +#include "configuration.h" + +#include "gui/sdlinput.h" +#include "gui/theme.h" + +#include "utils/dtor.h" + +#include +#include +#include + +#include "debug.h" + +float GuiTable::mAlpha = 1.0; + +class GuiTableActionListener : public gcn::ActionListener +{ +public: + GuiTableActionListener(GuiTable *_table, gcn::Widget *_widget, + int _row, int _column); + + virtual ~GuiTableActionListener(); + + virtual void action(const gcn::ActionEvent& actionEvent); + +protected: + GuiTable *mTable; + int mRow; + int mColumn; + gcn::Widget *mWidget; +}; + + +GuiTableActionListener::GuiTableActionListener(GuiTable *table, + gcn::Widget *widget, int row, + int column) : + mTable(table), + mRow(row), + mColumn(column), + mWidget(widget) +{ + if (widget) + { + widget->addActionListener(this); + widget->_setParent(table); + } +} + +GuiTableActionListener::~GuiTableActionListener() +{ + if (mWidget) + { + mWidget->removeActionListener(this); + mWidget->_setParent(NULL); + } +} + +void GuiTableActionListener::action(const gcn::ActionEvent + &actionEvent A_UNUSED) +{ + mTable->setSelected(mRow, mColumn); + mTable->distributeActionEvent(); +} + + +GuiTable::GuiTable(TableModel *initial_model, gcn::Color background, + bool opacity) : + mLinewiseMode(false), + mWrappingEnabled(false), + mOpaque(opacity), + mBackgroundColor(background), + mModel(NULL), + mSelectedRow(0), + mSelectedColumn(0), + mTopWidget(NULL) +{ + setModel(initial_model); + setFocusable(true); + + addMouseListener(this); + addKeyListener(this); +} + +GuiTable::~GuiTable() +{ + uninstallActionListeners(); + delete mModel; + mModel = 0; +} + +TableModel *GuiTable::getModel() const +{ + return mModel; +} + +void GuiTable::setModel(TableModel *new_model) +{ + if (mModel) + { + uninstallActionListeners(); + mModel->removeListener(this); + } + + mModel = new_model; + installActionListeners(); + + if (new_model) + { + new_model->installListener(this); + recomputeDimensions(); + } +} + +void GuiTable::recomputeDimensions() +{ + if (!mModel) + return; + + int rows_nr = mModel->getRows(); + int columns_nr = mModel->getColumns(); + int width = 0; + int height = 0; + + if (mSelectedRow >= rows_nr) + mSelectedRow = rows_nr - 1; + + if (mSelectedColumn >= columns_nr) + mSelectedColumn = columns_nr - 1; + + for (int i = 0; i < columns_nr; i++) + width += getColumnWidth(i); + + height = getRowHeight() * rows_nr; + + setWidth(width); + setHeight(height); +} + +void GuiTable::setSelected(int row, int column) +{ + mSelectedColumn = column; + mSelectedRow = row; +} + +int GuiTable::getSelectedRow() const +{ + return mSelectedRow; +} + +int GuiTable::getSelectedColumn() const +{ + return mSelectedColumn; +} + +void GuiTable::setLinewiseSelection(bool linewise) +{ + mLinewiseMode = linewise; +} + +int GuiTable::getRowHeight() const +{ + if (mModel) + return mModel->getRowHeight() + 1; // border + else + return 0; +} + +int GuiTable::getColumnWidth(int i) const +{ + if (mModel) + return mModel->getColumnWidth(i) + 1; // border + else + return 0; +} + +void GuiTable::setSelectedRow(int selected) +{ + if (!mModel) + { + mSelectedRow = -1; + } + else + { + if (selected < 0 && !mWrappingEnabled) + { + mSelectedRow = -1; + } + else if (selected >= mModel->getRows() && mWrappingEnabled) + { + mSelectedRow = 0; + } + else if ((selected >= mModel->getRows() && !mWrappingEnabled) || + (selected < 0 && mWrappingEnabled)) + { + mSelectedRow = mModel->getRows() - 1; + } + else + { + mSelectedRow = selected; + } + } +} + +void GuiTable::setSelectedColumn(int selected) +{ + if (!mModel) + { + mSelectedColumn = -1; + } + else + { + if ((selected >= mModel->getColumns() && mWrappingEnabled) || + (selected < 0 && !mWrappingEnabled)) + { + mSelectedColumn = 0; + } + else if ((selected >= mModel->getColumns() && !mWrappingEnabled) || + (selected < 0 && mWrappingEnabled)) + { + mSelectedColumn = mModel->getColumns() - 1; + } + else + { + mSelectedColumn = selected; + } + } +} + +void GuiTable::uninstallActionListeners() +{ + delete_all(mActionListeners); + mActionListeners.clear(); +} + +void GuiTable::installActionListeners() +{ + if (!mModel) + return; + + int rows = mModel->getRows(); + int columns = mModel->getColumns(); + + for (int row = 0; row < rows; ++row) + { + for (int column = 0; column < columns; ++column) + { + gcn::Widget *widget = mModel->getElementAt(row, column); + if (widget) + { + mActionListeners.push_back(new GuiTableActionListener( + this, widget, row, column)); + } + } + } + + _setFocusHandler(_getFocusHandler()); // propagate focus handler to widgets +} + +// -- widget ops +void GuiTable::draw(gcn::Graphics* graphics) +{ + if (!mModel || !getRowHeight()) + return; + + if (Client::getGuiAlpha() != mAlpha) + mAlpha = Client::getGuiAlpha(); + + if (mOpaque) + { + graphics->setColor(Theme::getThemeColor(Theme::BACKGROUND, + static_cast(mAlpha * 255.0f))); + graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); + } + + // First, determine how many rows we need to draw, and where we should start. + int first_row = -(getY() / getRowHeight()); + + if (first_row < 0) + first_row = 0; + + unsigned rows_nr = 1 + (getHeight() / getRowHeight()); // May overestimate + // by one. + + unsigned max_rows_nr; + if (mModel->getRows() < first_row) + max_rows_nr = 0; + else + max_rows_nr = mModel->getRows() - first_row; // clip if neccessary: + if (max_rows_nr < rows_nr) + rows_nr = max_rows_nr; + + // Now determine the first and last column + // Take the easy way out; these are usually bounded and all visible. + unsigned first_column = 0; + unsigned last_column1 = mModel->getColumns(); + + // Set up everything for drawing + int height = getRowHeight(); + int y_offset = first_row * height; + + for (unsigned r = first_row; r < first_row + rows_nr; ++r) + { + int x_offset = 0; + + for (unsigned c = first_column; c + 1 <= last_column1; ++c) + { + gcn::Widget *widget = mModel->getElementAt(r, c); + int width = getColumnWidth(c); + if (widget) + { + gcn::Rectangle bounds(x_offset, y_offset, width, height); + + if (widget == mTopWidget) + { + bounds.height = widget->getHeight(); + bounds.width = widget->getWidth(); + } + + widget->setDimension(bounds); + + graphics->setColor(Theme::getThemeColor(Theme::HIGHLIGHT, + static_cast(mAlpha * 255.0f))); + + if (mSelectedRow > 0) + { + if (mLinewiseMode && r == (unsigned)mSelectedRow && c == 0) + { + graphics->fillRectangle(gcn::Rectangle(0, y_offset, + getWidth(), height)); + } + else if (!mLinewiseMode && mSelectedColumn > 0 + && c == (unsigned)mSelectedColumn + && r == (unsigned)mSelectedRow) + { + graphics->fillRectangle(gcn::Rectangle( + x_offset, y_offset, width, height)); + } + } + graphics->pushClipArea(bounds); + widget->draw(graphics); + graphics->popClipArea(); + } + + x_offset += width; + } + + y_offset += height; + } + + if (mTopWidget) + { + gcn::Rectangle bounds = mTopWidget->getDimension(); + graphics->pushClipArea(bounds); + mTopWidget->draw(graphics); + graphics->popClipArea(); + } +} + +void GuiTable::moveToTop(gcn::Widget *widget) +{ + gcn::Widget::moveToTop(widget); + mTopWidget = widget; +} + +void GuiTable::moveToBottom(gcn::Widget *widget) +{ + gcn::Widget::moveToBottom(widget); + if (widget == mTopWidget) + mTopWidget = NULL; +} + +gcn::Rectangle GuiTable::getChildrenArea() +{ + return gcn::Rectangle(0, 0, getWidth(), getHeight()); +} + +// -- KeyListener notifications +void GuiTable::keyPressed(gcn::KeyEvent& keyEvent) +{ + gcn::Key key = keyEvent.getKey(); + + if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) + { + distributeActionEvent(); + keyEvent.consume(); + } + else if (key.getValue() == Key::UP) + { + setSelectedRow(mSelectedRow - 1); + keyEvent.consume(); + } + else if (key.getValue() == Key::DOWN) + { + setSelectedRow(mSelectedRow + 1); + keyEvent.consume(); + } + else if (key.getValue() == Key::LEFT) + { + setSelectedColumn(mSelectedColumn - 1); + keyEvent.consume(); + } + else if (key.getValue() == Key::RIGHT) + { + setSelectedColumn(mSelectedColumn + 1); + keyEvent.consume(); + } + else if (key.getValue() == Key::HOME) + { + setSelectedRow(0); + setSelectedColumn(0); + keyEvent.consume(); + } + else if (key.getValue() == Key::END && mModel) + { + setSelectedRow(mModel->getRows() - 1); + setSelectedColumn(mModel->getColumns() - 1); + keyEvent.consume(); + } +} + +// -- MouseListener notifications +void GuiTable::mousePressed(gcn::MouseEvent& mouseEvent) +{ + if (!mModel) + return; + + if (mouseEvent.getButton() == gcn::MouseEvent::LEFT) + { + int row = getRowForY(mouseEvent.getY()); + int column = getColumnForX(mouseEvent.getX()); + + if (row > -1 && column > -1 && + row < mModel->getRows() && column < mModel->getColumns()) + { + mSelectedColumn = column; + mSelectedRow = row; + } + + distributeActionEvent(); + } +} + +void GuiTable::mouseWheelMovedUp(gcn::MouseEvent& mouseEvent) +{ + if (isFocused()) + { + if (getSelectedRow() > 0 || (getSelectedRow() == 0 + && mWrappingEnabled)) + { + setSelectedRow(getSelectedRow() - 1); + } + + mouseEvent.consume(); + } +} + +void GuiTable::mouseWheelMovedDown(gcn::MouseEvent& mouseEvent) +{ + if (isFocused()) + { + setSelectedRow(getSelectedRow() + 1); + + mouseEvent.consume(); + } +} + +void GuiTable::mouseDragged(gcn::MouseEvent& mouseEvent) +{ + if (mouseEvent.getButton() != gcn::MouseEvent::LEFT) + return; + + // Make table selection update on drag + const int x = std::max(0, mouseEvent.getX()); + const int y = std::max(0, mouseEvent.getY()); + + setSelectedRow(getRowForY(y)); + setSelectedColumn(getColumnForX(x)); +} + +// -- TableModelListener notifications +void GuiTable::modelUpdated(bool completed) +{ + if (completed) + { + recomputeDimensions(); + installActionListeners(); + } + else + { // before the update? + mTopWidget = NULL; // No longer valid in general + uninstallActionListeners(); + } +} + +gcn::Widget *GuiTable::getWidgetAt(int x, int y) +{ + int row = getRowForY(y); + int column = getColumnForX(x); + + if (mTopWidget && mTopWidget->getDimension().isPointInRect(x, y)) + return mTopWidget; + + if (mModel && row > -1 && column > -1) + { + gcn::Widget *w = mModel->getElementAt(row, column); + if (w && w->isFocusable()) + return w; + else + return NULL; // Grab the event locally + } + else + return NULL; +} + +int GuiTable::getRowForY(int y) const +{ + int row = -1; + + if (getRowHeight() > 0) + row = y / getRowHeight(); + + if (!mModel || row < 0 || row >= mModel->getRows()) + return -1; + else + return row; +} + +int GuiTable::getColumnForX(int x) const +{ + if (!mModel) + return -1; + + int column; + int delta = 0; + + for (column = 0; column < mModel->getColumns(); column++) + { + delta += getColumnWidth(column); + if (x <= delta) + break; + } + + if (column < 0 || column >= mModel->getColumns()) + return -1; + else + return column; +} + +void GuiTable::_setFocusHandler(gcn::FocusHandler* focusHandler) +{ +// add check for focusHandler. may be need remove it? + + if (!mModel || !focusHandler) + return; + + gcn::Widget::_setFocusHandler(focusHandler); + + if (mModel) + { + for (int r = 0; r < mModel->getRows(); ++r) + { + for (int c = 0; c < mModel->getColumns(); ++c) + { + gcn::Widget *w = mModel->getElementAt(r, c); + if (w) + w->_setFocusHandler(focusHandler); + } + } + } +} diff --git a/src/gui/widgets/guitable.h b/src/gui/widgets/guitable.h new file mode 100644 index 000000000..c4fab6a0d --- /dev/null +++ b/src/gui/widgets/guitable.h @@ -0,0 +1,196 @@ +/* + * The ManaPlus Client + * Copyright (C) 2008-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 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 . + */ + +#ifndef TABLE_H +#define TABLE_H + +#include "gui/widgets/tablemodel.h" + +#include +#include +#include + +#include + +#ifdef __GNUC__ +#define A_UNUSED __attribute__ ((unused)) +#else +#define A_UNUSED +#endif + +class GuiTableActionListener; + +/** + * A table, with rows and columns made out of sub-widgets. Largely inspired by + * (and can be thought of as a generalisation of) the guichan listbox + * implementation. + * + * Normally you want this within a ScrollArea. + * + * \ingroup GUI + */ +class GuiTable : public gcn::Widget, + public gcn::MouseListener, + public gcn::KeyListener, + public TableModelListener +{ + // so that the action listener can call distributeActionEvent + friend class GuiTableActionListener; + +public: + GuiTable(TableModel * initial_model = NULL, + gcn::Color background = 0xffffff, + bool opacity = true); + + virtual ~GuiTable(); + + /** + * Retrieves the active table model + */ + TableModel *getModel() const; + + /** + * Sets the table model + * + * Note that actions issued by widgets returned from the model will update + * the table selection, but only AFTER any event handlers installed within + * the widget have been triggered. To be notified after such an update, add + * an action listener to the table instead. + */ + void setModel(TableModel *m); + + void setSelected(int row, int column); + + int getSelectedRow() const; + + int getSelectedColumn() const; + + void setSelectedRow(int selected); + + void setSelectedColumn(int selected); + + bool isWrappingEnabled() const + { return mWrappingEnabled; } + + void setWrappingEnabled(bool wrappingEnabled) + { mWrappingEnabled = wrappingEnabled; } + + gcn::Rectangle getChildrenArea(); + + /** + * Toggle whether to use linewise selection mode, in which the table selects + * an entire line at a time, rather than a single cell. + * + * Note that column information is tracked even in linewise selection mode; + * this mode therefore only affects visualisation. + * + * Disabled by default. + * + * \param linewise: Whether to enable linewise selection mode + */ + void setLinewiseSelection(bool linewise); + + // Inherited from Widget + virtual void draw(gcn::Graphics* graphics); + + virtual gcn::Widget *getWidgetAt(int x, int y); + + virtual void moveToTop(gcn::Widget *child); + + virtual void moveToBottom(gcn::Widget *child); + + virtual void _setFocusHandler(gcn::FocusHandler* focusHandler); + + // Inherited from KeyListener + virtual void keyPressed(gcn::KeyEvent& keyEvent); + + /** + * Sets the table to be opaque, that is sets the table + * to display its background. + * + * @param opaque True if the table should be opaque, false otherwise. + */ + virtual void setOpaque(bool opaque) + { mOpaque = opaque; } + + /** + * Checks if the table is opaque, that is if the table area displays its + * background. + * + * @return True if the table is opaque, false otherwise. + */ + virtual bool isOpaque() const + { return mOpaque; } + + // Inherited from MouseListener + virtual void mousePressed(gcn::MouseEvent& mouseEvent); + + virtual void mouseWheelMovedUp(gcn::MouseEvent& mouseEvent); + + virtual void mouseWheelMovedDown(gcn::MouseEvent& mouseEvent); + + virtual void mouseDragged(gcn::MouseEvent& mouseEvent); + + // Constraints inherited from TableModelListener + virtual void modelUpdated(bool); + +protected: + /** Frees all action listeners on inner widgets. */ + virtual void uninstallActionListeners(); + /** Installs all action listeners on inner widgets. */ + virtual void installActionListeners(); + + virtual int getRowHeight() const; + virtual int getColumnWidth(int i) const; + +private: + int getRowForY(int y) const; // -1 on error + int getColumnForX(int x) const; // -1 on error + void recomputeDimensions(); + bool mLinewiseMode; + bool mWrappingEnabled; + bool mOpaque; + + static float mAlpha; + + /** + * Holds the background color of the table. + */ + gcn::Color mBackgroundColor; + + TableModel *mModel; + + int mSelectedRow; + int mSelectedColumn; + + /** Number of frames to skip upwards when drawing the selected widget. */ + int mPopFramesNr; + + /** If someone moves a fresh widget to the top, we must display it. */ + gcn::Widget *mTopWidget; + + /** Vector for compactness; used as a list in practice. */ + std::vector mActionListeners; +}; + + +#endif // TABLE_H diff --git a/src/gui/widgets/table.cpp b/src/gui/widgets/table.cpp deleted file mode 100644 index 04ae41ad7..000000000 --- a/src/gui/widgets/table.cpp +++ /dev/null @@ -1,595 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2008-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 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 . - */ - -#include "gui/widgets/table.h" - -#include "client.h" -#include "configuration.h" - -#include "gui/sdlinput.h" -#include "gui/theme.h" - -#include "utils/dtor.h" - -#include -#include -#include - -#include "debug.h" - -float GuiTable::mAlpha = 1.0; - -class GuiTableActionListener : public gcn::ActionListener -{ -public: - GuiTableActionListener(GuiTable *_table, gcn::Widget *_widget, - int _row, int _column); - - virtual ~GuiTableActionListener(); - - virtual void action(const gcn::ActionEvent& actionEvent); - -protected: - GuiTable *mTable; - int mRow; - int mColumn; - gcn::Widget *mWidget; -}; - - -GuiTableActionListener::GuiTableActionListener(GuiTable *table, - gcn::Widget *widget, int row, - int column) : - mTable(table), - mRow(row), - mColumn(column), - mWidget(widget) -{ - if (widget) - { - widget->addActionListener(this); - widget->_setParent(table); - } -} - -GuiTableActionListener::~GuiTableActionListener() -{ - if (mWidget) - { - mWidget->removeActionListener(this); - mWidget->_setParent(NULL); - } -} - -void GuiTableActionListener::action(const gcn::ActionEvent - &actionEvent A_UNUSED) -{ - mTable->setSelected(mRow, mColumn); - mTable->distributeActionEvent(); -} - - -GuiTable::GuiTable(TableModel *initial_model, gcn::Color background, - bool opacity) : - mLinewiseMode(false), - mWrappingEnabled(false), - mOpaque(opacity), - mBackgroundColor(background), - mModel(NULL), - mSelectedRow(0), - mSelectedColumn(0), - mTopWidget(NULL) -{ - setModel(initial_model); - setFocusable(true); - - addMouseListener(this); - addKeyListener(this); -} - -GuiTable::~GuiTable() -{ - uninstallActionListeners(); - delete mModel; - mModel = 0; -} - -TableModel *GuiTable::getModel() const -{ - return mModel; -} - -void GuiTable::setModel(TableModel *new_model) -{ - if (mModel) - { - uninstallActionListeners(); - mModel->removeListener(this); - } - - mModel = new_model; - installActionListeners(); - - if (new_model) - { - new_model->installListener(this); - recomputeDimensions(); - } -} - -void GuiTable::recomputeDimensions() -{ - if (!mModel) - return; - - int rows_nr = mModel->getRows(); - int columns_nr = mModel->getColumns(); - int width = 0; - int height = 0; - - if (mSelectedRow >= rows_nr) - mSelectedRow = rows_nr - 1; - - if (mSelectedColumn >= columns_nr) - mSelectedColumn = columns_nr - 1; - - for (int i = 0; i < columns_nr; i++) - width += getColumnWidth(i); - - height = getRowHeight() * rows_nr; - - setWidth(width); - setHeight(height); -} - -void GuiTable::setSelected(int row, int column) -{ - mSelectedColumn = column; - mSelectedRow = row; -} - -int GuiTable::getSelectedRow() const -{ - return mSelectedRow; -} - -int GuiTable::getSelectedColumn() const -{ - return mSelectedColumn; -} - -void GuiTable::setLinewiseSelection(bool linewise) -{ - mLinewiseMode = linewise; -} - -int GuiTable::getRowHeight() const -{ - if (mModel) - return mModel->getRowHeight() + 1; // border - else - return 0; -} - -int GuiTable::getColumnWidth(int i) const -{ - if (mModel) - return mModel->getColumnWidth(i) + 1; // border - else - return 0; -} - -void GuiTable::setSelectedRow(int selected) -{ - if (!mModel) - { - mSelectedRow = -1; - } - else - { - if (selected < 0 && !mWrappingEnabled) - { - mSelectedRow = -1; - } - else if (selected >= mModel->getRows() && mWrappingEnabled) - { - mSelectedRow = 0; - } - else if ((selected >= mModel->getRows() && !mWrappingEnabled) || - (selected < 0 && mWrappingEnabled)) - { - mSelectedRow = mModel->getRows() - 1; - } - else - { - mSelectedRow = selected; - } - } -} - -void GuiTable::setSelectedColumn(int selected) -{ - if (!mModel) - { - mSelectedColumn = -1; - } - else - { - if ((selected >= mModel->getColumns() && mWrappingEnabled) || - (selected < 0 && !mWrappingEnabled)) - { - mSelectedColumn = 0; - } - else if ((selected >= mModel->getColumns() && !mWrappingEnabled) || - (selected < 0 && mWrappingEnabled)) - { - mSelectedColumn = mModel->getColumns() - 1; - } - else - { - mSelectedColumn = selected; - } - } -} - -void GuiTable::uninstallActionListeners() -{ - delete_all(mActionListeners); - mActionListeners.clear(); -} - -void GuiTable::installActionListeners() -{ - if (!mModel) - return; - - int rows = mModel->getRows(); - int columns = mModel->getColumns(); - - for (int row = 0; row < rows; ++row) - { - for (int column = 0; column < columns; ++column) - { - gcn::Widget *widget = mModel->getElementAt(row, column); - if (widget) - { - mActionListeners.push_back(new GuiTableActionListener( - this, widget, row, column)); - } - } - } - - _setFocusHandler(_getFocusHandler()); // propagate focus handler to widgets -} - -// -- widget ops -void GuiTable::draw(gcn::Graphics* graphics) -{ - if (!mModel || !getRowHeight()) - return; - - if (Client::getGuiAlpha() != mAlpha) - mAlpha = Client::getGuiAlpha(); - - if (mOpaque) - { - graphics->setColor(Theme::getThemeColor(Theme::BACKGROUND, - static_cast(mAlpha * 255.0f))); - graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); - } - - // First, determine how many rows we need to draw, and where we should start. - int first_row = -(getY() / getRowHeight()); - - if (first_row < 0) - first_row = 0; - - unsigned rows_nr = 1 + (getHeight() / getRowHeight()); // May overestimate - // by one. - - unsigned max_rows_nr; - if (mModel->getRows() < first_row) - max_rows_nr = 0; - else - max_rows_nr = mModel->getRows() - first_row; // clip if neccessary: - if (max_rows_nr < rows_nr) - rows_nr = max_rows_nr; - - // Now determine the first and last column - // Take the easy way out; these are usually bounded and all visible. - unsigned first_column = 0; - unsigned last_column1 = mModel->getColumns(); - - // Set up everything for drawing - int height = getRowHeight(); - int y_offset = first_row * height; - - for (unsigned r = first_row; r < first_row + rows_nr; ++r) - { - int x_offset = 0; - - for (unsigned c = first_column; c + 1 <= last_column1; ++c) - { - gcn::Widget *widget = mModel->getElementAt(r, c); - int width = getColumnWidth(c); - if (widget) - { - gcn::Rectangle bounds(x_offset, y_offset, width, height); - - if (widget == mTopWidget) - { - bounds.height = widget->getHeight(); - bounds.width = widget->getWidth(); - } - - widget->setDimension(bounds); - - graphics->setColor(Theme::getThemeColor(Theme::HIGHLIGHT, - static_cast(mAlpha * 255.0f))); - - if (mSelectedRow > 0) - { - if (mLinewiseMode && r == (unsigned)mSelectedRow && c == 0) - { - graphics->fillRectangle(gcn::Rectangle(0, y_offset, - getWidth(), height)); - } - else if (!mLinewiseMode && mSelectedColumn > 0 - && c == (unsigned)mSelectedColumn - && r == (unsigned)mSelectedRow) - { - graphics->fillRectangle(gcn::Rectangle( - x_offset, y_offset, width, height)); - } - } - graphics->pushClipArea(bounds); - widget->draw(graphics); - graphics->popClipArea(); - } - - x_offset += width; - } - - y_offset += height; - } - - if (mTopWidget) - { - gcn::Rectangle bounds = mTopWidget->getDimension(); - graphics->pushClipArea(bounds); - mTopWidget->draw(graphics); - graphics->popClipArea(); - } -} - -void GuiTable::moveToTop(gcn::Widget *widget) -{ - gcn::Widget::moveToTop(widget); - mTopWidget = widget; -} - -void GuiTable::moveToBottom(gcn::Widget *widget) -{ - gcn::Widget::moveToBottom(widget); - if (widget == mTopWidget) - mTopWidget = NULL; -} - -gcn::Rectangle GuiTable::getChildrenArea() -{ - return gcn::Rectangle(0, 0, getWidth(), getHeight()); -} - -// -- KeyListener notifications -void GuiTable::keyPressed(gcn::KeyEvent& keyEvent) -{ - gcn::Key key = keyEvent.getKey(); - - if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) - { - distributeActionEvent(); - keyEvent.consume(); - } - else if (key.getValue() == Key::UP) - { - setSelectedRow(mSelectedRow - 1); - keyEvent.consume(); - } - else if (key.getValue() == Key::DOWN) - { - setSelectedRow(mSelectedRow + 1); - keyEvent.consume(); - } - else if (key.getValue() == Key::LEFT) - { - setSelectedColumn(mSelectedColumn - 1); - keyEvent.consume(); - } - else if (key.getValue() == Key::RIGHT) - { - setSelectedColumn(mSelectedColumn + 1); - keyEvent.consume(); - } - else if (key.getValue() == Key::HOME) - { - setSelectedRow(0); - setSelectedColumn(0); - keyEvent.consume(); - } - else if (key.getValue() == Key::END && mModel) - { - setSelectedRow(mModel->getRows() - 1); - setSelectedColumn(mModel->getColumns() - 1); - keyEvent.consume(); - } -} - -// -- MouseListener notifications -void GuiTable::mousePressed(gcn::MouseEvent& mouseEvent) -{ - if (!mModel) - return; - - if (mouseEvent.getButton() == gcn::MouseEvent::LEFT) - { - int row = getRowForY(mouseEvent.getY()); - int column = getColumnForX(mouseEvent.getX()); - - if (row > -1 && column > -1 && - row < mModel->getRows() && column < mModel->getColumns()) - { - mSelectedColumn = column; - mSelectedRow = row; - } - - distributeActionEvent(); - } -} - -void GuiTable::mouseWheelMovedUp(gcn::MouseEvent& mouseEvent) -{ - if (isFocused()) - { - if (getSelectedRow() > 0 || (getSelectedRow() == 0 - && mWrappingEnabled)) - { - setSelectedRow(getSelectedRow() - 1); - } - - mouseEvent.consume(); - } -} - -void GuiTable::mouseWheelMovedDown(gcn::MouseEvent& mouseEvent) -{ - if (isFocused()) - { - setSelectedRow(getSelectedRow() + 1); - - mouseEvent.consume(); - } -} - -void GuiTable::mouseDragged(gcn::MouseEvent& mouseEvent) -{ - if (mouseEvent.getButton() != gcn::MouseEvent::LEFT) - return; - - // Make table selection update on drag - const int x = std::max(0, mouseEvent.getX()); - const int y = std::max(0, mouseEvent.getY()); - - setSelectedRow(getRowForY(y)); - setSelectedColumn(getColumnForX(x)); -} - -// -- TableModelListener notifications -void GuiTable::modelUpdated(bool completed) -{ - if (completed) - { - recomputeDimensions(); - installActionListeners(); - } - else - { // before the update? - mTopWidget = NULL; // No longer valid in general - uninstallActionListeners(); - } -} - -gcn::Widget *GuiTable::getWidgetAt(int x, int y) -{ - int row = getRowForY(y); - int column = getColumnForX(x); - - if (mTopWidget && mTopWidget->getDimension().isPointInRect(x, y)) - return mTopWidget; - - if (mModel && row > -1 && column > -1) - { - gcn::Widget *w = mModel->getElementAt(row, column); - if (w && w->isFocusable()) - return w; - else - return NULL; // Grab the event locally - } - else - return NULL; -} - -int GuiTable::getRowForY(int y) const -{ - int row = -1; - - if (getRowHeight() > 0) - row = y / getRowHeight(); - - if (!mModel || row < 0 || row >= mModel->getRows()) - return -1; - else - return row; -} - -int GuiTable::getColumnForX(int x) const -{ - if (!mModel) - return -1; - - int column; - int delta = 0; - - for (column = 0; column < mModel->getColumns(); column++) - { - delta += getColumnWidth(column); - if (x <= delta) - break; - } - - if (column < 0 || column >= mModel->getColumns()) - return -1; - else - return column; -} - -void GuiTable::_setFocusHandler(gcn::FocusHandler* focusHandler) -{ -// add check for focusHandler. may be need remove it? - - if (!mModel || !focusHandler) - return; - - gcn::Widget::_setFocusHandler(focusHandler); - - if (mModel) - { - for (int r = 0; r < mModel->getRows(); ++r) - { - for (int c = 0; c < mModel->getColumns(); ++c) - { - gcn::Widget *w = mModel->getElementAt(r, c); - if (w) - w->_setFocusHandler(focusHandler); - } - } - } -} diff --git a/src/gui/widgets/table.h b/src/gui/widgets/table.h deleted file mode 100644 index c4fab6a0d..000000000 --- a/src/gui/widgets/table.h +++ /dev/null @@ -1,196 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2008-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 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 . - */ - -#ifndef TABLE_H -#define TABLE_H - -#include "gui/widgets/tablemodel.h" - -#include -#include -#include - -#include - -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - -class GuiTableActionListener; - -/** - * A table, with rows and columns made out of sub-widgets. Largely inspired by - * (and can be thought of as a generalisation of) the guichan listbox - * implementation. - * - * Normally you want this within a ScrollArea. - * - * \ingroup GUI - */ -class GuiTable : public gcn::Widget, - public gcn::MouseListener, - public gcn::KeyListener, - public TableModelListener -{ - // so that the action listener can call distributeActionEvent - friend class GuiTableActionListener; - -public: - GuiTable(TableModel * initial_model = NULL, - gcn::Color background = 0xffffff, - bool opacity = true); - - virtual ~GuiTable(); - - /** - * Retrieves the active table model - */ - TableModel *getModel() const; - - /** - * Sets the table model - * - * Note that actions issued by widgets returned from the model will update - * the table selection, but only AFTER any event handlers installed within - * the widget have been triggered. To be notified after such an update, add - * an action listener to the table instead. - */ - void setModel(TableModel *m); - - void setSelected(int row, int column); - - int getSelectedRow() const; - - int getSelectedColumn() const; - - void setSelectedRow(int selected); - - void setSelectedColumn(int selected); - - bool isWrappingEnabled() const - { return mWrappingEnabled; } - - void setWrappingEnabled(bool wrappingEnabled) - { mWrappingEnabled = wrappingEnabled; } - - gcn::Rectangle getChildrenArea(); - - /** - * Toggle whether to use linewise selection mode, in which the table selects - * an entire line at a time, rather than a single cell. - * - * Note that column information is tracked even in linewise selection mode; - * this mode therefore only affects visualisation. - * - * Disabled by default. - * - * \param linewise: Whether to enable linewise selection mode - */ - void setLinewiseSelection(bool linewise); - - // Inherited from Widget - virtual void draw(gcn::Graphics* graphics); - - virtual gcn::Widget *getWidgetAt(int x, int y); - - virtual void moveToTop(gcn::Widget *child); - - virtual void moveToBottom(gcn::Widget *child); - - virtual void _setFocusHandler(gcn::FocusHandler* focusHandler); - - // Inherited from KeyListener - virtual void keyPressed(gcn::KeyEvent& keyEvent); - - /** - * Sets the table to be opaque, that is sets the table - * to display its background. - * - * @param opaque True if the table should be opaque, false otherwise. - */ - virtual void setOpaque(bool opaque) - { mOpaque = opaque; } - - /** - * Checks if the table is opaque, that is if the table area displays its - * background. - * - * @return True if the table is opaque, false otherwise. - */ - virtual bool isOpaque() const - { return mOpaque; } - - // Inherited from MouseListener - virtual void mousePressed(gcn::MouseEvent& mouseEvent); - - virtual void mouseWheelMovedUp(gcn::MouseEvent& mouseEvent); - - virtual void mouseWheelMovedDown(gcn::MouseEvent& mouseEvent); - - virtual void mouseDragged(gcn::MouseEvent& mouseEvent); - - // Constraints inherited from TableModelListener - virtual void modelUpdated(bool); - -protected: - /** Frees all action listeners on inner widgets. */ - virtual void uninstallActionListeners(); - /** Installs all action listeners on inner widgets. */ - virtual void installActionListeners(); - - virtual int getRowHeight() const; - virtual int getColumnWidth(int i) const; - -private: - int getRowForY(int y) const; // -1 on error - int getColumnForX(int x) const; // -1 on error - void recomputeDimensions(); - bool mLinewiseMode; - bool mWrappingEnabled; - bool mOpaque; - - static float mAlpha; - - /** - * Holds the background color of the table. - */ - gcn::Color mBackgroundColor; - - TableModel *mModel; - - int mSelectedRow; - int mSelectedColumn; - - /** Number of frames to skip upwards when drawing the selected widget. */ - int mPopFramesNr; - - /** If someone moves a fresh widget to the top, we must display it. */ - gcn::Widget *mTopWidget; - - /** Vector for compactness; used as a list in practice. */ - std::vector mActionListeners; -}; - - -#endif // TABLE_H -- cgit v1.2.3-70-g09d2 From 47f0e16e34cf22701b7c0670297bb7288a55310d Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 15 Aug 2011 01:57:55 +0300 Subject: Add option to hide ip addresses on screenshots. --- src/defaults.cpp | 1 + src/game.cpp | 14 +++++++++++- src/graphics.cpp | 3 ++- src/graphics.h | 7 ++++++ src/gui/setup_players.cpp | 3 +++ src/gui/widgets/avatarlistbox.cpp | 46 ++++++++++++++++++++++++++++----------- 6 files changed, 59 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/defaults.cpp b/src/defaults.cpp index 3824aafc9..e614a489b 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -214,6 +214,7 @@ DefaultsData* getConfigDefaults() AddDEF(configData, "disableAdvBeingCaching", false); AddDEF(configData, "disableBeingCaching", false); AddDEF(configData, "enableReorderSprites", true); + AddDEF(configData, "showip", false); return configData; } diff --git a/src/game.cpp b/src/game.cpp index 4e7345340..8457cf079 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -431,8 +431,20 @@ Game::~Game() static bool saveScreenshot() { static unsigned int screenshotCount = 0; + SDL_Surface *screenshot = 0; + + if (!config.getBoolValue("showip")) + { + graphics->setSecure(true); + gui->draw(); + screenshot = graphics->getScreenshot(); + graphics->setSecure(false); + } + else + { + screenshot = graphics->getScreenshot(); + } - SDL_Surface *screenshot = graphics->getScreenshot(); if (!screenshot) return false; diff --git a/src/graphics.cpp b/src/graphics.cpp index a86ac7fd0..c5dc38b72 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -48,7 +48,8 @@ Graphics::Graphics(): mHWAccel(false), mBlitMode(BLIT_NORMAL), mRedraw(false), - mDoubleBuffer(false) + mDoubleBuffer(false), + mSecure(false) { mRect.x = 0; mRect.y = 0; diff --git a/src/graphics.h b/src/graphics.h index 237d16dc2..a2e25b5a8 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -269,6 +269,12 @@ class Graphics : public gcn::SDLGraphics bool getRedraw() { return mRedraw; } + void setSecure(bool n) + { mSecure = n; } + + bool getSecure() + { return mSecure; } + int mWidth; int mHeight; @@ -283,6 +289,7 @@ class Graphics : public gcn::SDLGraphics bool mRedraw; bool mDoubleBuffer; SDL_Rect mRect; + bool mSecure; }; extern Graphics *graphics; diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp index d2664adbd..acc6b3d3c 100644 --- a/src/gui/setup_players.cpp +++ b/src/gui/setup_players.cpp @@ -75,6 +75,9 @@ Setup_Players::Setup_Players() new SetupItemCheckBox(_("Show statuses"), "", "showPlayersStatus", this, "showPlayersStatusEvent"); + new SetupItemCheckBox(_("Show ip addresses on screenshots"), "", + "showip", this, "showipEvent"); + setDimension(gcn::Rectangle(0, 0, 550, 350)); } diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp index 5ac6721a5..0d35ad188 100644 --- a/src/gui/widgets/avatarlistbox.cpp +++ b/src/gui/widgets/avatarlistbox.cpp @@ -242,25 +242,45 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics) } } - if (mShowGender) + if (graphics->getSecure()) { - switch (a->getGender()) + if (mShowGender) { - case GENDER_FEMALE: - text += strprintf(" \u2640 %s", - a->getAdditionString().c_str()); - break; - case GENDER_MALE: - text += strprintf(" \u2642 %s", - a->getAdditionString().c_str()); - break; - default: - break; + switch (a->getGender()) + { + case GENDER_FEMALE: + text += strprintf(" \u2640 "); + break; + case GENDER_MALE: + text += strprintf(" \u2642 "); + break; + default: + break; + } } } else { - text += a->getAdditionString(); + if (mShowGender) + { + switch (a->getGender()) + { + case GENDER_FEMALE: + text += strprintf(" \u2640 %s", + a->getAdditionString().c_str()); + break; + case GENDER_MALE: + text += strprintf(" \u2642 %s", + a->getAdditionString().c_str()); + break; + default: + break; + } + } + else + { + text += a->getAdditionString(); + } } graphics->setColor(Theme::getThemeColor(Theme::TEXT)); -- cgit v1.2.3-70-g09d2 From 34e386d0c2d4ae844d50185f70bba945960bad62 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 15 Aug 2011 02:52:07 +0300 Subject: Add warp menu item for gms in navigation items. --- src/gui/popupmenu.cpp | 13 +++++++++++++ src/net/adminhandler.h | 1 + src/net/ea/adminhandler.cpp | 6 ++++++ src/net/ea/adminhandler.h | 2 ++ src/net/manaserv/adminhandler.cpp | 5 +++++ src/net/manaserv/adminhandler.h | 2 ++ 6 files changed, 29 insertions(+) (limited to 'src') diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index c95864396..a7c008684 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -502,6 +502,11 @@ void PopupMenu::showPopup(int x, int y, MapItem *mapItem) mBrowserBox->addRow(strprintf("@@rename map|%s@@", _("Rename"))); mBrowserBox->addRow(strprintf("@@remove map|%s@@", _("Remove"))); + if (player_node && player_node->isGM()) + { + mBrowserBox->addRow("##3---"); + mBrowserBox->addRow(strprintf("@@warp map|%s@@", _("Warp"))); + } mBrowserBox->addRow("##3---"); mBrowserBox->addRow(strprintf("@@cancel|%s@@", _("Cancel"))); @@ -1144,6 +1149,14 @@ void PopupMenu::handleLink(const std::string &link, if (chatWindow) chatWindow->clearTab(); } + else if (link == "warp map" && mMapItem) + { + if (Game::instance()) + { + Net::getAdminHandler()->warp(Game::instance()->getCurrentMapName(), + mMapItem->getX(), mMapItem->getY()); + } + } else if (link == "remove map" && mMapItem) { if (viewport) diff --git a/src/net/adminhandler.h b/src/net/adminhandler.h index 2d7eccebf..d063c4eb1 100644 --- a/src/net/adminhandler.h +++ b/src/net/adminhandler.h @@ -53,6 +53,7 @@ class AdminHandler virtual void mute(int playerId, int type, int limit) = 0; + virtual void warp(std::string map, int x, int y) = 0; // TODO }; diff --git a/src/net/ea/adminhandler.cpp b/src/net/ea/adminhandler.cpp index 5440d14d0..bdd43b3f8 100644 --- a/src/net/ea/adminhandler.cpp +++ b/src/net/ea/adminhandler.cpp @@ -63,4 +63,10 @@ void AdminHandler::mute(int playerId A_UNUSED, int type A_UNUSED, return; // Still looking into this } +void AdminHandler::warp(std::string map, int x, int y) +{ + Net::getChatHandler()->talk(strprintf( + "@warp %s %d %d", map.c_str(), x, y)); +} + } // namespace Ea diff --git a/src/net/ea/adminhandler.h b/src/net/ea/adminhandler.h index 6f77c0e18..fcf1e25b2 100644 --- a/src/net/ea/adminhandler.h +++ b/src/net/ea/adminhandler.h @@ -51,6 +51,8 @@ class AdminHandler : public Net::AdminHandler virtual void unban(const std::string &name); virtual void mute(int playerId, int type, int limit); + + virtual void warp(std::string map, int x, int y); }; } // namespace Ea diff --git a/src/net/manaserv/adminhandler.cpp b/src/net/manaserv/adminhandler.cpp index 72e7c7ca8..2c76e99a3 100644 --- a/src/net/manaserv/adminhandler.cpp +++ b/src/net/manaserv/adminhandler.cpp @@ -91,4 +91,9 @@ void AdminHandler::mute(int playerId A_UNUSED, int type A_UNUSED, // TODO } +void AdminHandler::warp(std::string map, int x, int y) +{ + // TODO +} + } // namespace ManaServ diff --git a/src/net/manaserv/adminhandler.h b/src/net/manaserv/adminhandler.h index a91841085..65e9ea2b0 100644 --- a/src/net/manaserv/adminhandler.h +++ b/src/net/manaserv/adminhandler.h @@ -58,6 +58,8 @@ class AdminHandler : public Net::AdminHandler void unban(const std::string &name); void mute(int playerId, int type, int limit); + + void warp(std::string map, int x, int y); }; } // namespace ManaServ -- cgit v1.2.3-70-g09d2 From 178af146d00873e632802dcbdbc77dcb9198d6b1 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 15 Aug 2011 02:53:26 +0300 Subject: Remove some debug messages. --- src/itemshortcut.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/itemshortcut.cpp b/src/itemshortcut.cpp index 464eeda14..625e8d90a 100644 --- a/src/itemshortcut.cpp +++ b/src/itemshortcut.cpp @@ -193,8 +193,8 @@ void ItemShortcut::setItemSelected(Item *item) { if (item) { - logger->log("set selected id: %d", item->getId()); - logger->log("set selected color: %d", item->getColor()); +// logger->log("set selected id: %d", item->getId()); +// logger->log("set selected color: %d", item->getColor()); mItemSelected = item->getId(); mItemColorSelected = item->getColor(); } -- cgit v1.2.3-70-g09d2 From 243628a5d2d12a02708b14b0cbac1498bdcec844 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 15 Aug 2011 15:47:09 +0300 Subject: Add button in status window to copy player stats to chat. --- src/gui/statuswindow.cpp | 34 ++++++++++++++++++++++++++++++++++ src/gui/statuswindow.h | 7 ++++++- 2 files changed, 40 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp index b96720341..fcc324730 100644 --- a/src/gui/statuswindow.cpp +++ b/src/gui/statuswindow.cpp @@ -22,6 +22,7 @@ #include "gui/statuswindow.h" +#include "chatwindow.h" #include "configuration.h" #include "event.h" #include "equipment.h" @@ -71,6 +72,14 @@ class AttrDisplay : public Container virtual Type getType() { return UNKNOWN; } + std::string getValue() + { + if (!mValue) + return "-"; + else + return mValue->getCaption(); + } + protected: AttrDisplay(int id, const std::string &name); @@ -228,6 +237,10 @@ StatusWindow::StatusWindow(): mCharacterPointsLabel = new Label("C"); place(0, 6, mCharacterPointsLabel, 5); + mCopyButton = new Button(_("Copy to chat"), "copy", this); + + place(0, 5, mCopyButton); + if (Net::getPlayerHandler()->canCorrectAttributes()) { mCorrectionPointsLabel = new Label("C"); @@ -890,6 +903,27 @@ void StatusWindow::updateStatusBar(ProgressBar *bar, bool percent A_UNUSED) } } +void StatusWindow::action(const gcn::ActionEvent &event) +{ + if (!chatWindow) + return; + + if (event.getId() == "copy") + { + Attrs::iterator it = mAttrs.begin(); + Attrs::iterator it_end = mAttrs.end(); + std::string str; + while (it != it_end) + { + ChangeDisplay *attr = dynamic_cast((*it).second); + if (attr) + str += attr->getValue() + " "; + ++ it; + } + chatWindow->addInputText(str); + } +} + AttrDisplay::AttrDisplay(int id, const std::string &name): mId(id), mName(name) diff --git a/src/gui/statuswindow.h b/src/gui/statuswindow.h index 74eb2c401..44d052004 100644 --- a/src/gui/statuswindow.h +++ b/src/gui/statuswindow.h @@ -48,7 +48,9 @@ class VertContainer; * * \ingroup Interface */ -class StatusWindow : public Window, public Mana::Listener +class StatusWindow : public Window, + public gcn::ActionListener, + public Mana::Listener { public: /** @@ -77,6 +79,8 @@ class StatusWindow : public Window, public Mana::Listener void updateProgressBar(ProgressBar *bar, int id, bool percent = true); + void action(const gcn::ActionEvent &event); + private: static std::string translateLetter(char* letters); @@ -97,6 +101,7 @@ class StatusWindow : public Window, public Mana::Listener gcn::Label *mCharacterPointsLabel; gcn::Label *mCorrectionPointsLabel; + gcn::Button *mCopyButton; typedef std::map Attrs; Attrs mAttrs; -- cgit v1.2.3-70-g09d2 From dec741233dc709950fe542bcd4f69b254b33eb80 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 15 Aug 2011 17:31:22 +0300 Subject: Move setupitem class to widgets directory. --- manaplus.cbp | 2 + po/POTFILES.in | 2 +- src/CMakeLists.txt | 4 +- src/Makefile.am | 4 +- src/gui/setup_chat.cpp | 2 +- src/gui/setup_other.cpp | 3 +- src/gui/setup_perfomance.cpp | 2 +- src/gui/setup_players.cpp | 2 +- src/gui/setupitem.cpp | 507 ------------------------------------- src/gui/setupitem.h | 244 ------------------ src/gui/widgets/setupitem.cpp | 507 +++++++++++++++++++++++++++++++++++++ src/gui/widgets/setupitem.h | 244 ++++++++++++++++++ src/gui/widgets/setuptabscroll.cpp | 3 +- 13 files changed, 763 insertions(+), 763 deletions(-) delete mode 100644 src/gui/setupitem.cpp delete mode 100644 src/gui/setupitem.h create mode 100644 src/gui/widgets/setupitem.cpp create mode 100644 src/gui/widgets/setupitem.h (limited to 'src') diff --git a/manaplus.cbp b/manaplus.cbp index f47e5c271..8ed18dbed 100644 --- a/manaplus.cbp +++ b/manaplus.cbp @@ -349,6 +349,8 @@ + + diff --git a/po/POTFILES.in b/po/POTFILES.in index 76bbeb48a..311ca756d 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -42,7 +42,6 @@ src/gui/setup_audio.cpp src/gui/setup_chat.cpp src/gui/setup_colors.cpp src/gui/setup.cpp -src/gui/setupitem.cpp src/gui/setup_joystick.cpp src/gui/setup_keyboard.cpp src/gui/setup_other.cpp @@ -67,6 +66,7 @@ src/gui/whoisonline.cpp src/gui/widgets/battletab.cpp src/gui/widgets/channeltab.cpp src/gui/widgets/chattab.cpp +src/gui/widgets/setupitem.cpp src/gui/widgets/tradetab.cpp src/gui/widgets/whispertab.cpp src/gui/windowmenu.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fba255c1c..413a72f65 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -181,6 +181,8 @@ SET(SRCS gui/widgets/resizegrip.h gui/widgets/scrollarea.cpp gui/widgets/scrollarea.h + gui/widgets/setupitem.cpp + gui/widgets/setupitem.h gui/widgets/setuptab.cpp gui/widgets/setuptab.h gui/widgets/setuptabscroll.cpp @@ -299,8 +301,6 @@ SET(SRCS gui/serverdialog.h gui/setup.cpp gui/setup.h - gui/setupitem.cpp - gui/setupitem.h gui/setup_audio.cpp gui/setup_audio.h gui/setup_colors.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 697575b97..57bb4e620 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -184,6 +184,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ gui/widgets/resizegrip.h \ gui/widgets/scrollarea.cpp \ gui/widgets/scrollarea.h \ + gui/widgets/setupitem.cpp \ + gui/widgets/setupitem.h \ gui/widgets/setuptab.cpp \ gui/widgets/setuptab.h \ gui/widgets/setuptabscroll.cpp \ @@ -302,8 +304,6 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ gui/serverdialog.h \ gui/setup.cpp \ gui/setup.h \ - gui/setupitem.cpp \ - gui/setupitem.h \ gui/setup_audio.cpp \ gui/setup_audio.h \ gui/setup_colors.cpp \ diff --git a/src/gui/setup_chat.cpp b/src/gui/setup_chat.cpp index 7ce44a552..722a3f8b2 100644 --- a/src/gui/setup_chat.cpp +++ b/src/gui/setup_chat.cpp @@ -25,7 +25,6 @@ #include "gui/chatwindow.h" #include "gui/editdialog.h" -#include "gui/setupitem.h" #include "gui/widgets/button.h" #include "gui/widgets/chattab.h" @@ -34,6 +33,7 @@ #include "gui/widgets/label.h" #include "gui/widgets/layouthelper.h" #include "gui/widgets/scrollarea.h" +#include "gui/widgets/setupitem.h" #include "configuration.h" #include "localplayer.h" diff --git a/src/gui/setup_other.cpp b/src/gui/setup_other.cpp index 3b603a8ee..b405f5045 100644 --- a/src/gui/setup_other.cpp +++ b/src/gui/setup_other.cpp @@ -23,10 +23,9 @@ #include "gui/setup_other.h" -#include "gui/setupitem.h" - #include "gui/widgets/layouthelper.h" #include "gui/widgets/scrollarea.h" +#include "gui/widgets/setupitem.h" #include "configuration.h" #include "logger.h" diff --git a/src/gui/setup_perfomance.cpp b/src/gui/setup_perfomance.cpp index 583f2909a..dfb119b91 100644 --- a/src/gui/setup_perfomance.cpp +++ b/src/gui/setup_perfomance.cpp @@ -25,7 +25,6 @@ #include "gui/chatwindow.h" #include "gui/editdialog.h" -#include "gui/setupitem.h" #include "gui/widgets/button.h" #include "gui/widgets/chattab.h" @@ -34,6 +33,7 @@ #include "gui/widgets/label.h" #include "gui/widgets/layouthelper.h" #include "gui/widgets/scrollarea.h" +#include "gui/widgets/setupitem.h" #include "configuration.h" #include "localplayer.h" diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp index acc6b3d3c..78c77f6f1 100644 --- a/src/gui/setup_players.cpp +++ b/src/gui/setup_players.cpp @@ -25,7 +25,6 @@ #include "gui/chatwindow.h" #include "gui/editdialog.h" -#include "gui/setupitem.h" #include "gui/widgets/button.h" #include "gui/widgets/chattab.h" @@ -34,6 +33,7 @@ #include "gui/widgets/label.h" #include "gui/widgets/layouthelper.h" #include "gui/widgets/scrollarea.h" +#include "gui/widgets/setupitem.h" #include "configuration.h" #include "localplayer.h" diff --git a/src/gui/setupitem.cpp b/src/gui/setupitem.cpp deleted file mode 100644 index defdb4005..000000000 --- a/src/gui/setupitem.cpp +++ /dev/null @@ -1,507 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011 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 . - */ - -#include "gui/setupitem.h" - -#include "configuration.h" -#include "main.h" -#include "logger.h" - -#include "gui/editdialog.h" - -#include "gui/widgets/button.h" -#include "gui/widgets/checkbox.h" -#include "gui/widgets/horizontcontainer.h" -#include "gui/widgets/inttextfield.h" -#include "gui/widgets/label.h" -#include "gui/widgets/layouthelper.h" -#include "gui/widgets/tabbedarea.h" -#include "gui/widgets/textfield.h" -#include "gui/widgets/vertcontainer.h" - -#include "utils/dtor.h" -#include "utils/gettext.h" - - -SetupItem::SetupItem(std::string text, std::string description, - std::string keyName, SetupTabScroll *parent, - std::string eventName, bool mainConfig) : - mText(text), - mDescription(description), - mKeyName(keyName), - mParent(parent), - mEventName(eventName), - mMainConfig(mainConfig), - mUseDefault(false), - mValue(""), - mDefault(""), - mWidget(0), - mValueType(VBOOL) -{ -} - -SetupItem::SetupItem(std::string text, std::string description, - std::string keyName, SetupTabScroll *parent, - std::string eventName, std::string def, bool mainConfig) : - mText(text), - mDescription(description), - mKeyName(keyName), - mParent(parent), - mEventName(eventName), - mMainConfig(mainConfig), - mUseDefault(true), - mValue(""), - mDefault(def), - mWidget(0), - mValueType(VBOOL) -{ -} - -SetupItem::~SetupItem() -{ - -} - -Configuration *SetupItem::getConfig() -{ - if (mMainConfig) - return &config; - else - return &serverConfig; -} - -void SetupItem::load() -{ - Configuration *cfg = getConfig(); - if (mUseDefault) - { - mValue = cfg->getValue(mKeyName, mDefault); - } - else - { - switch (mValueType) - { - case VBOOL: - if (cfg->getBoolValue(mKeyName)) - mValue = "1"; - else - mValue = "0"; - break; - case VSTR: - default: - mValue = cfg->getStringValue(mKeyName); - break; - case VINT: - mValue = toString(cfg->getIntValue(mKeyName)); - break; - case VNONE: - break; - } - } -} - -void SetupItem::save() -{ - Configuration *cfg = getConfig(); - cfg->setValue(mKeyName, mValue); -} - -std::string SetupItem::getActionEventId() -{ - if (!mWidget) - return ""; - - return mWidget->getActionEventId(); -} - -void SetupItem::action(const gcn::ActionEvent &event) -{ - if (!mWidget) - return; - - if (event.getId() == mWidget->getActionEventId()) - action(); -} - -void SetupItem::action() -{ - fromWidget(); -} - -void SetupItem::apply(std::string eventName A_UNUSED) -{ - save(); -} - -void SetupItem::cancel(std::string eventName A_UNUSED) -{ - load(); - toWidget(); -} - -void SetupItem::externalUpdated(std::string eventName A_UNUSED) -{ - load(); - toWidget(); -} - -SetupItemCheckBox::SetupItemCheckBox(std::string text, std::string description, - std::string keyName, - SetupTabScroll *parent, - std::string eventName, bool mainConfig) : - SetupItem(text, description, keyName, parent, eventName, mainConfig) -{ - createControls(); -} - -SetupItemCheckBox::SetupItemCheckBox(std::string text, std::string description, - std::string keyName, - SetupTabScroll *parent, - std::string eventName, std::string def, - bool mainConfig) : - SetupItem(text, description, keyName, parent, eventName, def, mainConfig) -{ - createControls(); -} - -SetupItemCheckBox::~SetupItemCheckBox() -{ - mWidget = 0; -} - -void SetupItemCheckBox::createControls() -{ - load(); - mCheckBox = new CheckBox(mText, mValue != "0", mParent, mEventName); - mWidget = mCheckBox; - mParent->getContainer()->add(mWidget); - mParent->addControl(this); - mParent->addActionListener(this); - mWidget->addActionListener(this); -} - -void SetupItemCheckBox::fromWidget() -{ - if (!mCheckBox) - return; - - if (mCheckBox->isSelected()) - mValue = "1"; - else - mValue = "0"; -} - -void SetupItemCheckBox::toWidget() -{ - if (!mCheckBox) - return; - - mCheckBox->setSelected(mValue != "0"); -} - - -SetupItemTextField::SetupItemTextField(std::string text, - std::string description, - std::string keyName, - SetupTabScroll *parent, - std::string eventName, - bool mainConfig) : - SetupItem(text, description, keyName, parent, eventName, mainConfig), - mHorizont(0), - mLabel(0), - mTextField(0), - mButton(0), - mEditDialog(0) -{ - mValueType = VSTR; - createControls(); -} - -SetupItemTextField::SetupItemTextField(std::string text, - std::string description, - std::string keyName, - SetupTabScroll *parent, - std::string eventName, std::string def, - bool mainConfig) : - SetupItem(text, description, keyName, parent, eventName, def, mainConfig), - mHorizont(0), - mLabel(0), - mTextField(0), - mButton(0), - mEditDialog(0) -{ - mValueType = VSTR; - createControls(); -} - -SetupItemTextField::~SetupItemTextField() -{ - mHorizont = 0; - mWidget = 0; - mTextField = 0; - mLabel = 0; - mButton = 0; -} - -void SetupItemTextField::createControls() -{ - load(); - mHorizont = new HorizontContainer(32, 2); - - mLabel = new Label(mText); - mTextField = new TextField(mValue, true, mParent, mEventName); - mButton = new Button(_("Edit"), mEventName + "_EDIT", mParent); - mWidget = mTextField; - mTextField->setWidth(200); - mHorizont->add(mLabel); - mHorizont->add(mTextField); - mHorizont->add(mButton); - - mParent->getContainer()->add(mHorizont, true, 4); - mParent->addControl(this); - mParent->addControl(this, mEventName + "_EDIT"); - mParent->addControl(this, mEventName + "_EDIT_OK"); - mParent->addActionListener(this); - mWidget->addActionListener(this); - mButton->addActionListener(this); -} - -void SetupItemTextField::fromWidget() -{ - if (!mTextField) - return; - - mValue = mTextField->getText(); -} - -void SetupItemTextField::toWidget() -{ - if (!mTextField) - return; - - mTextField->setText(mValue); -} - -void SetupItemTextField::action(const gcn::ActionEvent &event) -{ - if (!mTextField) - return; - - if (event.getId() == mWidget->getActionEventId()) - { - fromWidget(); - } - else if (event.getId() == mEventName + "_EDIT") - { - mEditDialog = new EditDialog(mText, mTextField->getText(), - mEventName + "_EDIT_OK"); - mEditDialog->addActionListener(this); - } - else if (event.getId() == mEventName + "_EDIT_OK") - { - mTextField->setText(mEditDialog->getMsg()); - mEditDialog = 0; - } -} - -void SetupItemTextField::apply(std::string eventName) -{ - if (eventName != mEventName) - return; - - fromWidget(); - save(); -} - - -SetupItemIntTextField::SetupItemIntTextField(std::string text, - std::string description, - std::string keyName, - SetupTabScroll *parent, - std::string eventName, - int min, int max, - bool mainConfig) : - SetupItem(text, description, keyName, parent, eventName, mainConfig), - mHorizont(0), - mLabel(0), - mTextField(0), - mButton(0), - mMin(min), - mMax(max), - mEditDialog(0) -{ - mValueType = VSTR; - createControls(); -} - -SetupItemIntTextField::SetupItemIntTextField(std::string text, - std::string description, - std::string keyName, - SetupTabScroll *parent, - std::string eventName, - int min, int max, - std::string def, - bool mainConfig) : - SetupItem(text, description, keyName, parent, eventName, def, mainConfig), - mHorizont(0), - mLabel(0), - mTextField(0), - mButton(0), - mMin(min), - mMax(max), - mEditDialog(0) -{ - mValueType = VSTR; - createControls(); -} - -SetupItemIntTextField::~SetupItemIntTextField() -{ - mHorizont = 0; - mWidget = 0; - mTextField = 0; - mLabel = 0; - mButton = 0; -} - -void SetupItemIntTextField::createControls() -{ - load(); - mHorizont = new HorizontContainer(32, 2); - - mLabel = new Label(mText); - mTextField = new IntTextField(atoi(mValue.c_str()), mMin, mMax, true, 30); - mTextField->setActionEventId(mEventName); - mTextField->addActionListener(mParent); - - mButton = new Button(_("Edit"), mEventName + "_EDIT", mParent); - mWidget = mTextField; - mTextField->setWidth(50); - mHorizont->add(mLabel); - mHorizont->add(mTextField); - mHorizont->add(mButton); - - mParent->getContainer()->add(mHorizont, true, 4); - mParent->addControl(this); - mParent->addControl(this, mEventName + "_EDIT"); - mParent->addControl(this, mEventName + "_EDIT_OK"); - mParent->addActionListener(this); - mWidget->addActionListener(this); - mButton->addActionListener(this); -} - -void SetupItemIntTextField::fromWidget() -{ - if (!mTextField) - return; - - mValue = mTextField->getText(); -} - -void SetupItemIntTextField::toWidget() -{ - if (!mTextField) - return; - - mTextField->setText(mValue); -} - -void SetupItemIntTextField::action(const gcn::ActionEvent &event) -{ - if (!mTextField) - return; - - if (event.getId() == mWidget->getActionEventId()) - { - fromWidget(); - } - else if (event.getId() == mEventName + "_EDIT") - { - mEditDialog = new EditDialog(mText, mTextField->getText(), - mEventName + "_EDIT_OK"); - mEditDialog->addActionListener(this); - } - else if (event.getId() == mEventName + "_EDIT_OK") - { - mTextField->setValue(atoi(mEditDialog->getMsg().c_str())); - mEditDialog = 0; - } -} - -void SetupItemIntTextField::apply(std::string eventName) -{ - if (eventName != mEventName) - return; - - fromWidget(); - save(); -} - -SetupItemLabel::SetupItemLabel(std::string text, std::string description, - SetupTabScroll *parent, bool separator) : - SetupItem(text, description, "", parent, "", "", true), - mLabel(0), - mIsSeparator(separator) -{ - mValueType = VNONE; - createControls(); -} - -SetupItemLabel::~SetupItemLabel() -{ - mWidget = 0; - mLabel = 0; -} - -void SetupItemLabel::createControls() -{ - if (mIsSeparator) - { - const std::string str = " \342\200\225\342\200\225\342\200\225" - "\342\200\225\342\200\225 "; - mLabel = new Label(str + mText + str); - } - else - { - mLabel = new Label(mText); - } - - mWidget = mLabel; - mParent->getContainer()->add(mWidget); - mParent->addControl(this); - mParent->addActionListener(this); - mWidget->addActionListener(this); -} - -void SetupItemLabel::fromWidget() -{ -} - -void SetupItemLabel::toWidget() -{ -} - -void SetupItemLabel::action(const gcn::ActionEvent &event A_UNUSED) -{ -} - -void SetupItemLabel::apply(std::string eventName A_UNUSED) -{ -} diff --git a/src/gui/setupitem.h b/src/gui/setupitem.h deleted file mode 100644 index 3396edea3..000000000 --- a/src/gui/setupitem.h +++ /dev/null @@ -1,244 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011 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 . - */ - -#ifndef SETUPITEM_H -#define SETUPITEM_H - -#include "gui/widgets/tabbedarea.h" - -#include "guichanfwd.h" - -#include "gui/widgets/setuptabscroll.h" -#include "gui/widgets/window.h" - -#include -#include - -#include - -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - -class CheckBox; -class Configuration; -class ContainerPlacer; -class EditDialog; -class HorizontContainer; -class IntTextField; -class Label; -class TextField; - -class SetupItem : public gcn::ActionListener -{ - public: - enum - { - VBOOL = 0, - VSTR, - VINT, - VNONE - }; - - SetupItem(std::string text, std::string description, - std::string keyName, SetupTabScroll *parent, - std::string eventName, bool mainConfig); - - SetupItem(std::string text, std::string description, - std::string keyName, SetupTabScroll *parent, - std::string eventName, std::string def, bool mainConfig); - - ~SetupItem(); - - void load(); - - void save(); - - virtual void fromWidget() = 0; - - virtual void toWidget() = 0; - - void setWidget(gcn::Widget *widget) - { mWidget = widget; } - - gcn::Widget *getWidget() - { return mWidget; } - - Configuration *getConfig(); - - virtual std::string getActionEventId(); - - virtual void action(const gcn::ActionEvent &event); - - virtual void action(); - - virtual void apply(std::string eventName); - - virtual void cancel(std::string eventName); - - virtual void externalUpdated(std::string eventName); -// virtual int add(ContainerPlacer &place, int x, int y, int width); - - bool isMainConfig() - { return mMainConfig; } - - protected: - std::string mText; - - std::string mDescription; - - std::string mKeyName; - - SetupTabScroll *mParent; - - std::string mEventName; - - bool mMainConfig; - - bool mUseDefault; - - std::string mValue; - - std::string mDefault; - - gcn::Widget *mWidget; - - std::list mTempWidgets; - - int mValueType; -}; - -class SetupItemCheckBox : public SetupItem -{ - public: - SetupItemCheckBox(std::string text, std::string description, - std::string keyName, SetupTabScroll *parent, - std::string eventName, bool mainConfig = true); - - SetupItemCheckBox(std::string text, std::string description, - std::string keyName, SetupTabScroll *parent, - std::string eventName, std::string def, - bool mainConfig = true); - - ~SetupItemCheckBox(); - - void createControls(); - - void fromWidget(); - - void toWidget(); - - protected: - CheckBox *mCheckBox; -}; - -class SetupItemTextField : public SetupItem -{ - public: - SetupItemTextField(std::string text, std::string description, - std::string keyName, SetupTabScroll *parent, - std::string eventName, bool mainConfig = true); - - SetupItemTextField(std::string text, std::string description, - std::string keyName, SetupTabScroll *parent, - std::string eventName, std::string def, - bool mainConfig = true); - - ~SetupItemTextField(); - - void createControls(); - - void fromWidget(); - - void toWidget(); - - void action(const gcn::ActionEvent &event); - - void apply(std::string eventName); - - protected: - HorizontContainer *mHorizont; - Label *mLabel; - TextField *mTextField; - Button *mButton; - EditDialog *mEditDialog; -}; - -class SetupItemIntTextField : public SetupItem -{ - public: - SetupItemIntTextField(std::string text, std::string description, - std::string keyName, SetupTabScroll *parent, - std::string eventName, int min, int max, - bool mainConfig = true); - - SetupItemIntTextField(std::string text, std::string description, - std::string keyName, SetupTabScroll *parent, - std::string eventName, int min, int max, - std::string def, bool mainConfig = true); - - ~SetupItemIntTextField(); - - void createControls(); - - void fromWidget(); - - void toWidget(); - - void action(const gcn::ActionEvent &event); - - void apply(std::string eventName); - - protected: - HorizontContainer *mHorizont; - Label *mLabel; - IntTextField *mTextField; - Button *mButton; - int mMin; - int mMax; - EditDialog *mEditDialog; -}; - -class SetupItemLabel : public SetupItem -{ - public: - SetupItemLabel(std::string text, std::string description, - SetupTabScroll *parent, bool separator = true); - - ~SetupItemLabel(); - - void createControls(); - - void fromWidget(); - - void toWidget(); - - void action(const gcn::ActionEvent &event); - - void apply(std::string eventName); - - protected: - Label *mLabel; - bool mIsSeparator; -}; - -#endif diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp new file mode 100644 index 000000000..fd2c937dc --- /dev/null +++ b/src/gui/widgets/setupitem.cpp @@ -0,0 +1,507 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011 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 . + */ + +#include "gui/widgets/setupitem.h" + +#include "configuration.h" +#include "main.h" +#include "logger.h" + +#include "gui/editdialog.h" + +#include "gui/widgets/button.h" +#include "gui/widgets/checkbox.h" +#include "gui/widgets/horizontcontainer.h" +#include "gui/widgets/inttextfield.h" +#include "gui/widgets/label.h" +#include "gui/widgets/layouthelper.h" +#include "gui/widgets/tabbedarea.h" +#include "gui/widgets/textfield.h" +#include "gui/widgets/vertcontainer.h" + +#include "utils/dtor.h" +#include "utils/gettext.h" + + +SetupItem::SetupItem(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, bool mainConfig) : + mText(text), + mDescription(description), + mKeyName(keyName), + mParent(parent), + mEventName(eventName), + mMainConfig(mainConfig), + mUseDefault(false), + mValue(""), + mDefault(""), + mWidget(0), + mValueType(VBOOL) +{ +} + +SetupItem::SetupItem(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, std::string def, bool mainConfig) : + mText(text), + mDescription(description), + mKeyName(keyName), + mParent(parent), + mEventName(eventName), + mMainConfig(mainConfig), + mUseDefault(true), + mValue(""), + mDefault(def), + mWidget(0), + mValueType(VBOOL) +{ +} + +SetupItem::~SetupItem() +{ + +} + +Configuration *SetupItem::getConfig() +{ + if (mMainConfig) + return &config; + else + return &serverConfig; +} + +void SetupItem::load() +{ + Configuration *cfg = getConfig(); + if (mUseDefault) + { + mValue = cfg->getValue(mKeyName, mDefault); + } + else + { + switch (mValueType) + { + case VBOOL: + if (cfg->getBoolValue(mKeyName)) + mValue = "1"; + else + mValue = "0"; + break; + case VSTR: + default: + mValue = cfg->getStringValue(mKeyName); + break; + case VINT: + mValue = toString(cfg->getIntValue(mKeyName)); + break; + case VNONE: + break; + } + } +} + +void SetupItem::save() +{ + Configuration *cfg = getConfig(); + cfg->setValue(mKeyName, mValue); +} + +std::string SetupItem::getActionEventId() +{ + if (!mWidget) + return ""; + + return mWidget->getActionEventId(); +} + +void SetupItem::action(const gcn::ActionEvent &event) +{ + if (!mWidget) + return; + + if (event.getId() == mWidget->getActionEventId()) + action(); +} + +void SetupItem::action() +{ + fromWidget(); +} + +void SetupItem::apply(std::string eventName A_UNUSED) +{ + save(); +} + +void SetupItem::cancel(std::string eventName A_UNUSED) +{ + load(); + toWidget(); +} + +void SetupItem::externalUpdated(std::string eventName A_UNUSED) +{ + load(); + toWidget(); +} + +SetupItemCheckBox::SetupItemCheckBox(std::string text, std::string description, + std::string keyName, + SetupTabScroll *parent, + std::string eventName, bool mainConfig) : + SetupItem(text, description, keyName, parent, eventName, mainConfig) +{ + createControls(); +} + +SetupItemCheckBox::SetupItemCheckBox(std::string text, std::string description, + std::string keyName, + SetupTabScroll *parent, + std::string eventName, std::string def, + bool mainConfig) : + SetupItem(text, description, keyName, parent, eventName, def, mainConfig) +{ + createControls(); +} + +SetupItemCheckBox::~SetupItemCheckBox() +{ + mWidget = 0; +} + +void SetupItemCheckBox::createControls() +{ + load(); + mCheckBox = new CheckBox(mText, mValue != "0", mParent, mEventName); + mWidget = mCheckBox; + mParent->getContainer()->add(mWidget); + mParent->addControl(this); + mParent->addActionListener(this); + mWidget->addActionListener(this); +} + +void SetupItemCheckBox::fromWidget() +{ + if (!mCheckBox) + return; + + if (mCheckBox->isSelected()) + mValue = "1"; + else + mValue = "0"; +} + +void SetupItemCheckBox::toWidget() +{ + if (!mCheckBox) + return; + + mCheckBox->setSelected(mValue != "0"); +} + + +SetupItemTextField::SetupItemTextField(std::string text, + std::string description, + std::string keyName, + SetupTabScroll *parent, + std::string eventName, + bool mainConfig) : + SetupItem(text, description, keyName, parent, eventName, mainConfig), + mHorizont(0), + mLabel(0), + mTextField(0), + mButton(0), + mEditDialog(0) +{ + mValueType = VSTR; + createControls(); +} + +SetupItemTextField::SetupItemTextField(std::string text, + std::string description, + std::string keyName, + SetupTabScroll *parent, + std::string eventName, std::string def, + bool mainConfig) : + SetupItem(text, description, keyName, parent, eventName, def, mainConfig), + mHorizont(0), + mLabel(0), + mTextField(0), + mButton(0), + mEditDialog(0) +{ + mValueType = VSTR; + createControls(); +} + +SetupItemTextField::~SetupItemTextField() +{ + mHorizont = 0; + mWidget = 0; + mTextField = 0; + mLabel = 0; + mButton = 0; +} + +void SetupItemTextField::createControls() +{ + load(); + mHorizont = new HorizontContainer(32, 2); + + mLabel = new Label(mText); + mTextField = new TextField(mValue, true, mParent, mEventName); + mButton = new Button(_("Edit"), mEventName + "_EDIT", mParent); + mWidget = mTextField; + mTextField->setWidth(200); + mHorizont->add(mLabel); + mHorizont->add(mTextField); + mHorizont->add(mButton); + + mParent->getContainer()->add(mHorizont, true, 4); + mParent->addControl(this); + mParent->addControl(this, mEventName + "_EDIT"); + mParent->addControl(this, mEventName + "_EDIT_OK"); + mParent->addActionListener(this); + mWidget->addActionListener(this); + mButton->addActionListener(this); +} + +void SetupItemTextField::fromWidget() +{ + if (!mTextField) + return; + + mValue = mTextField->getText(); +} + +void SetupItemTextField::toWidget() +{ + if (!mTextField) + return; + + mTextField->setText(mValue); +} + +void SetupItemTextField::action(const gcn::ActionEvent &event) +{ + if (!mTextField) + return; + + if (event.getId() == mWidget->getActionEventId()) + { + fromWidget(); + } + else if (event.getId() == mEventName + "_EDIT") + { + mEditDialog = new EditDialog(mText, mTextField->getText(), + mEventName + "_EDIT_OK"); + mEditDialog->addActionListener(this); + } + else if (event.getId() == mEventName + "_EDIT_OK") + { + mTextField->setText(mEditDialog->getMsg()); + mEditDialog = 0; + } +} + +void SetupItemTextField::apply(std::string eventName) +{ + if (eventName != mEventName) + return; + + fromWidget(); + save(); +} + + +SetupItemIntTextField::SetupItemIntTextField(std::string text, + std::string description, + std::string keyName, + SetupTabScroll *parent, + std::string eventName, + int min, int max, + bool mainConfig) : + SetupItem(text, description, keyName, parent, eventName, mainConfig), + mHorizont(0), + mLabel(0), + mTextField(0), + mButton(0), + mMin(min), + mMax(max), + mEditDialog(0) +{ + mValueType = VSTR; + createControls(); +} + +SetupItemIntTextField::SetupItemIntTextField(std::string text, + std::string description, + std::string keyName, + SetupTabScroll *parent, + std::string eventName, + int min, int max, + std::string def, + bool mainConfig) : + SetupItem(text, description, keyName, parent, eventName, def, mainConfig), + mHorizont(0), + mLabel(0), + mTextField(0), + mButton(0), + mMin(min), + mMax(max), + mEditDialog(0) +{ + mValueType = VSTR; + createControls(); +} + +SetupItemIntTextField::~SetupItemIntTextField() +{ + mHorizont = 0; + mWidget = 0; + mTextField = 0; + mLabel = 0; + mButton = 0; +} + +void SetupItemIntTextField::createControls() +{ + load(); + mHorizont = new HorizontContainer(32, 2); + + mLabel = new Label(mText); + mTextField = new IntTextField(atoi(mValue.c_str()), mMin, mMax, true, 30); + mTextField->setActionEventId(mEventName); + mTextField->addActionListener(mParent); + + mButton = new Button(_("Edit"), mEventName + "_EDIT", mParent); + mWidget = mTextField; + mTextField->setWidth(50); + mHorizont->add(mLabel); + mHorizont->add(mTextField); + mHorizont->add(mButton); + + mParent->getContainer()->add(mHorizont, true, 4); + mParent->addControl(this); + mParent->addControl(this, mEventName + "_EDIT"); + mParent->addControl(this, mEventName + "_EDIT_OK"); + mParent->addActionListener(this); + mWidget->addActionListener(this); + mButton->addActionListener(this); +} + +void SetupItemIntTextField::fromWidget() +{ + if (!mTextField) + return; + + mValue = mTextField->getText(); +} + +void SetupItemIntTextField::toWidget() +{ + if (!mTextField) + return; + + mTextField->setText(mValue); +} + +void SetupItemIntTextField::action(const gcn::ActionEvent &event) +{ + if (!mTextField) + return; + + if (event.getId() == mWidget->getActionEventId()) + { + fromWidget(); + } + else if (event.getId() == mEventName + "_EDIT") + { + mEditDialog = new EditDialog(mText, mTextField->getText(), + mEventName + "_EDIT_OK"); + mEditDialog->addActionListener(this); + } + else if (event.getId() == mEventName + "_EDIT_OK") + { + mTextField->setValue(atoi(mEditDialog->getMsg().c_str())); + mEditDialog = 0; + } +} + +void SetupItemIntTextField::apply(std::string eventName) +{ + if (eventName != mEventName) + return; + + fromWidget(); + save(); +} + +SetupItemLabel::SetupItemLabel(std::string text, std::string description, + SetupTabScroll *parent, bool separator) : + SetupItem(text, description, "", parent, "", "", true), + mLabel(0), + mIsSeparator(separator) +{ + mValueType = VNONE; + createControls(); +} + +SetupItemLabel::~SetupItemLabel() +{ + mWidget = 0; + mLabel = 0; +} + +void SetupItemLabel::createControls() +{ + if (mIsSeparator) + { + const std::string str = " \342\200\225\342\200\225\342\200\225" + "\342\200\225\342\200\225 "; + mLabel = new Label(str + mText + str); + } + else + { + mLabel = new Label(mText); + } + + mWidget = mLabel; + mParent->getContainer()->add(mWidget); + mParent->addControl(this); + mParent->addActionListener(this); + mWidget->addActionListener(this); +} + +void SetupItemLabel::fromWidget() +{ +} + +void SetupItemLabel::toWidget() +{ +} + +void SetupItemLabel::action(const gcn::ActionEvent &event A_UNUSED) +{ +} + +void SetupItemLabel::apply(std::string eventName A_UNUSED) +{ +} diff --git a/src/gui/widgets/setupitem.h b/src/gui/widgets/setupitem.h new file mode 100644 index 000000000..3396edea3 --- /dev/null +++ b/src/gui/widgets/setupitem.h @@ -0,0 +1,244 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011 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 . + */ + +#ifndef SETUPITEM_H +#define SETUPITEM_H + +#include "gui/widgets/tabbedarea.h" + +#include "guichanfwd.h" + +#include "gui/widgets/setuptabscroll.h" +#include "gui/widgets/window.h" + +#include +#include + +#include + +#ifdef __GNUC__ +#define A_UNUSED __attribute__ ((unused)) +#else +#define A_UNUSED +#endif + +class CheckBox; +class Configuration; +class ContainerPlacer; +class EditDialog; +class HorizontContainer; +class IntTextField; +class Label; +class TextField; + +class SetupItem : public gcn::ActionListener +{ + public: + enum + { + VBOOL = 0, + VSTR, + VINT, + VNONE + }; + + SetupItem(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, bool mainConfig); + + SetupItem(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, std::string def, bool mainConfig); + + ~SetupItem(); + + void load(); + + void save(); + + virtual void fromWidget() = 0; + + virtual void toWidget() = 0; + + void setWidget(gcn::Widget *widget) + { mWidget = widget; } + + gcn::Widget *getWidget() + { return mWidget; } + + Configuration *getConfig(); + + virtual std::string getActionEventId(); + + virtual void action(const gcn::ActionEvent &event); + + virtual void action(); + + virtual void apply(std::string eventName); + + virtual void cancel(std::string eventName); + + virtual void externalUpdated(std::string eventName); +// virtual int add(ContainerPlacer &place, int x, int y, int width); + + bool isMainConfig() + { return mMainConfig; } + + protected: + std::string mText; + + std::string mDescription; + + std::string mKeyName; + + SetupTabScroll *mParent; + + std::string mEventName; + + bool mMainConfig; + + bool mUseDefault; + + std::string mValue; + + std::string mDefault; + + gcn::Widget *mWidget; + + std::list mTempWidgets; + + int mValueType; +}; + +class SetupItemCheckBox : public SetupItem +{ + public: + SetupItemCheckBox(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, bool mainConfig = true); + + SetupItemCheckBox(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, std::string def, + bool mainConfig = true); + + ~SetupItemCheckBox(); + + void createControls(); + + void fromWidget(); + + void toWidget(); + + protected: + CheckBox *mCheckBox; +}; + +class SetupItemTextField : public SetupItem +{ + public: + SetupItemTextField(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, bool mainConfig = true); + + SetupItemTextField(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, std::string def, + bool mainConfig = true); + + ~SetupItemTextField(); + + void createControls(); + + void fromWidget(); + + void toWidget(); + + void action(const gcn::ActionEvent &event); + + void apply(std::string eventName); + + protected: + HorizontContainer *mHorizont; + Label *mLabel; + TextField *mTextField; + Button *mButton; + EditDialog *mEditDialog; +}; + +class SetupItemIntTextField : public SetupItem +{ + public: + SetupItemIntTextField(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, int min, int max, + bool mainConfig = true); + + SetupItemIntTextField(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, int min, int max, + std::string def, bool mainConfig = true); + + ~SetupItemIntTextField(); + + void createControls(); + + void fromWidget(); + + void toWidget(); + + void action(const gcn::ActionEvent &event); + + void apply(std::string eventName); + + protected: + HorizontContainer *mHorizont; + Label *mLabel; + IntTextField *mTextField; + Button *mButton; + int mMin; + int mMax; + EditDialog *mEditDialog; +}; + +class SetupItemLabel : public SetupItem +{ + public: + SetupItemLabel(std::string text, std::string description, + SetupTabScroll *parent, bool separator = true); + + ~SetupItemLabel(); + + void createControls(); + + void fromWidget(); + + void toWidget(); + + void action(const gcn::ActionEvent &event); + + void apply(std::string eventName); + + protected: + Label *mLabel; + bool mIsSeparator; +}; + +#endif diff --git a/src/gui/widgets/setuptabscroll.cpp b/src/gui/widgets/setuptabscroll.cpp index 805c0c8c7..30bb66469 100644 --- a/src/gui/widgets/setuptabscroll.cpp +++ b/src/gui/widgets/setuptabscroll.cpp @@ -20,10 +20,9 @@ #include "gui/widgets/setuptabscroll.h" -#include "gui/setupitem.h" - #include "gui/widgets/layouthelper.h" #include "gui/widgets/scrollarea.h" +#include "gui/widgets/setupitem.h" #include "gui/widgets/vertcontainer.h" #include "debug.h" -- cgit v1.2.3-70-g09d2 From b1f8a2eaab592b59b5946bdbe38f0d8f775cc434 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 15 Aug 2011 23:04:44 +0300 Subject: Add drop down widget for setup pages. Known issue: popup listbox drawed under other widgets. --- src/gui/widgets/horizontcontainer.h | 3 + src/gui/widgets/setupitem.cpp | 86 +++++++++++++++++++++++++- src/gui/widgets/setupitem.h | 29 +++++++++ src/gui/widgets/vertcontainer.cpp | 2 +- src/guichan/include/guichan/basiccontainer.hpp | 2 +- 5 files changed, 119 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/gui/widgets/horizontcontainer.h b/src/gui/widgets/horizontcontainer.h index 4a959190e..80014c171 100644 --- a/src/gui/widgets/horizontcontainer.h +++ b/src/gui/widgets/horizontcontainer.h @@ -41,8 +41,11 @@ class HorizontContainer : public Container, public gcn::WidgetListener { public: HorizontContainer(int height, int spacing); + virtual void add(gcn::Widget *widget); + virtual void clear(); + void widgetResized(const gcn::Event &event); protected: diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp index fd2c937dc..698e133dd 100644 --- a/src/gui/widgets/setupitem.cpp +++ b/src/gui/widgets/setupitem.cpp @@ -28,6 +28,7 @@ #include "gui/widgets/button.h" #include "gui/widgets/checkbox.h" +#include "gui/widgets/dropdown.h" #include "gui/widgets/horizontcontainer.h" #include "gui/widgets/inttextfield.h" #include "gui/widgets/label.h" @@ -330,7 +331,6 @@ void SetupItemTextField::apply(std::string eventName) save(); } - SetupItemIntTextField::SetupItemIntTextField(std::string text, std::string description, std::string keyName, @@ -454,6 +454,8 @@ void SetupItemIntTextField::apply(std::string eventName) save(); } + + SetupItemLabel::SetupItemLabel(std::string text, std::string description, SetupTabScroll *parent, bool separator) : SetupItem(text, description, "", parent, "", "", true), @@ -505,3 +507,85 @@ void SetupItemLabel::action(const gcn::ActionEvent &event A_UNUSED) void SetupItemLabel::apply(std::string eventName A_UNUSED) { } + + +SetupItemDropDown::SetupItemDropDown(std::string text, + std::string description, + std::string keyName, + SetupTabScroll *parent, + std::string eventName, + gcn::ListModel *model, + bool mainConfig) : + SetupItem(text, description, keyName, parent, eventName, mainConfig), + mHorizont(0), + mLabel(0), + mModel(model), + mDropDown(0) +{ + mValueType = VSTR; + createControls(); +} + +SetupItemDropDown::SetupItemDropDown(std::string text, + std::string description, + std::string keyName, + SetupTabScroll *parent, + std::string eventName, + gcn::ListModel *model, + std::string def, + bool mainConfig) : + SetupItem(text, description, keyName, parent, eventName, def, mainConfig), + mHorizont(0), + mLabel(0), + mModel(model), + mDropDown(0) +{ + mValueType = VSTR; + createControls(); +} + +SetupItemDropDown::~SetupItemDropDown() +{ + mHorizont = 0; + mWidget = 0; + mModel = 0; + mDropDown = 0; + mLabel = 0; +} + +void SetupItemDropDown::createControls() +{ + load(); + mHorizont = new HorizontContainer(32, 2); + + mLabel = new Label(mText); + mDropDown = new DropDown(mModel); + mDropDown->setActionEventId(mEventName); + mDropDown->addActionListener(mParent); + + mWidget = mDropDown; +// mTextField->setWidth(50); + mHorizont->add(mLabel); + mHorizont->add(mDropDown); + + mParent->getContainer()->add(mHorizont, true, 4); + mParent->addControl(this); + mParent->addActionListener(this); + mWidget->addActionListener(this); +} + +void SetupItemDropDown::fromWidget() +{ + if (!mDropDown) + return; + + mValue = mDropDown->getSelectedString(); +} + +void SetupItemDropDown::toWidget() +{ + if (!mDropDown) + return; + + mDropDown->setSelectedString(mValue); +} diff --git a/src/gui/widgets/setupitem.h b/src/gui/widgets/setupitem.h index 3396edea3..15d2d41ea 100644 --- a/src/gui/widgets/setupitem.h +++ b/src/gui/widgets/setupitem.h @@ -42,6 +42,7 @@ class CheckBox; class Configuration; class ContainerPlacer; +class DropDown; class EditDialog; class HorizontContainer; class IntTextField; @@ -241,4 +242,32 @@ class SetupItemLabel : public SetupItem bool mIsSeparator; }; +class SetupItemDropDown : public SetupItem +{ + public: + SetupItemDropDown(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, gcn::ListModel *model, + bool mainConfig = true); + + SetupItemDropDown(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, gcn::ListModel *model, + std::string def, bool mainConfig = true); + + ~SetupItemDropDown(); + + void createControls(); + + void fromWidget(); + + void toWidget(); + + protected: + HorizontContainer *mHorizont; + Label *mLabel; + gcn::ListModel *mModel; + DropDown *mDropDown; +}; + #endif diff --git a/src/gui/widgets/vertcontainer.cpp b/src/gui/widgets/vertcontainer.cpp index d65274f20..ea6b4d520 100644 --- a/src/gui/widgets/vertcontainer.cpp +++ b/src/gui/widgets/vertcontainer.cpp @@ -49,7 +49,7 @@ void VertContainer::add(gcn::Widget *widget, bool resizable, int spacing) widget->setPosition(mLeftSpacing, mNextY); if (resizable) { - widget->setSize(getWidth() - mLeftSpacing, mVerticalItemSize); + widget->setSize(getWidth() - mLeftSpacing, mVerticalItemSize * 5); mResizableWidgets.push_back(widget); } else if (widget->getHeight() > mVerticalItemSize) diff --git a/src/guichan/include/guichan/basiccontainer.hpp b/src/guichan/include/guichan/basiccontainer.hpp index b63b83cd8..998e1f601 100644 --- a/src/guichan/include/guichan/basiccontainer.hpp +++ b/src/guichan/include/guichan/basiccontainer.hpp @@ -132,7 +132,7 @@ namespace gcn * @see remove, clear */ virtual void clear(); - + /** * Draws the children widgets of the basic container. * -- cgit v1.2.3-70-g09d2 From 92311f100efe888df9f8101d22ba9f2d7b483074 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 16 Aug 2011 19:04:43 +0300 Subject: Enable japanese language in gettext. Add ability to use japanese font if current locale is japan locale. --- po/LINGUAS | 2 +- src/client.cpp | 4 ++++ src/defaults.cpp | 2 ++ src/gui/gui.cpp | 13 +++++++++++-- src/gui/setup_theme.cpp | 47 +++++++++++++++++++++++++++++++++-------------- src/gui/setup_theme.h | 4 ++++ 6 files changed, 55 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/po/LINGUAS b/po/LINGUAS index b917eab69..66da28559 100644 --- a/po/LINGUAS +++ b/po/LINGUAS @@ -17,7 +17,7 @@ hr hu id #it # Not enough translations -#ja # Disabled because of current client limitations (font fallbacking) +ja #ka # Not enough translations #nb # Not enough translations #nds # Not enough translations diff --git a/src/client.cpp b/src/client.cpp index cc3c384f7..0e871ed91 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -1802,6 +1802,7 @@ void Client::storeSafeParameters() std::string particleFont; std::string helpFont; std::string secureFont; + std::string japanFont; bool showBackground; bool enableMumble; bool enableMapReduce; @@ -1829,6 +1830,7 @@ void Client::storeSafeParameters() particleFont = config.getStringValue("particleFont"); helpFont = config.getStringValue("helpFont"); secureFont = config.getStringValue("secureFont"); + japanFont = config.getStringValue("japanFont"); showBackground = config.getBoolValue("showBackground"); enableMumble = config.getBoolValue("enableMumble"); @@ -1847,6 +1849,7 @@ void Client::storeSafeParameters() config.setValue("particleFont", "fonts/dejavusans.ttf"); config.setValue("helpFont", "fonts/dejavusansmono.ttf"); config.setValue("secureFont", "fonts/dejavusansmono.ttf"); + config.setValue("japanFont", "fonts/mplus-1p-regular.ttf"); config.setValue("showBackground", false); config.setValue("enableMumble", false); config.setValue("enableMapReduce", false); @@ -1872,6 +1875,7 @@ void Client::storeSafeParameters() config.setValue("particleFont", particleFont); config.setValue("helpFont", helpFont); config.setValue("secureFont", secureFont); + config.setValue("japanFont", japanFont); config.setValue("showBackground", showBackground); config.setValue("enableMumble", enableMumble); config.setValue("enableMapReduce", enableMapReduce); diff --git a/src/defaults.cpp b/src/defaults.cpp index e614a489b..e1cb08299 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -159,6 +159,7 @@ DefaultsData* getConfigDefaults() AddDEF(configData, "particleFont", "fonts/dejavusans.ttf"); AddDEF(configData, "helpFont", "fonts/dejavusansmono.ttf"); AddDEF(configData, "secureFont", "fonts/dejavusansmono.ttf"); + AddDEF(configData, "japanFont", "fonts/mplus-1p-regular.ttf"); AddDEF(configData, "showBackground", true); AddDEF(configData, "enableTradeTab", true); AddDEF(configData, "logToChat", false); @@ -242,6 +243,7 @@ DefaultsData* getBrandingDefaults() AddDEF(brandingData, "particleFont", "fonts/dejavusans.ttf"); AddDEF(brandingData, "helpFont", "fonts/dejavusansmono.ttf"); AddDEF(brandingData, "secureFont", "fonts/dejavusansmono.ttf"); + AddDEF(brandingData, "japanFont", "fonts/mplus-1p-regular.ttf"); AddDEF(brandingData, "guiPath", "graphics/gui/"); AddDEF(brandingData, "guiThemePath", "themes/"); diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 3e4ec764f..7d38b1025 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -107,9 +107,18 @@ Gui::Gui(Graphics *graphics): // Set global font const int fontSize = config.getIntValue("fontSize"); + std::string fontFile = config.getValue("font", ""); -// may be here need get paths from paths.getValue? -// std::string path = resman->getPath(fontFile); + + std::vector langs = getLang(); + if (!langs.empty() && langs[0].size() > 3 + && langs[0].substr(0, 3) == "ja_") + { + fontFile = config.getValue("japanFont", ""); + if (fontFile.empty()) + fontFile = branding.getStringValue("japanFont"); + } + if (fontFile.empty()) fontFile = branding.getStringValue("font"); diff --git a/src/gui/setup_theme.cpp b/src/gui/setup_theme.cpp index 7a2c66595..05f8c7315 100644 --- a/src/gui/setup_theme.cpp +++ b/src/gui/setup_theme.cpp @@ -51,6 +51,7 @@ const char* ACTION_BOLD_FONT = "bold font"; const char* ACTION_PARTICLE_FONT = "particle font"; const char* ACTION_HELP_FONT = "help font"; const char* ACTION_SECURE_FONT = "secure font"; +const char* ACTION_JAPAN_FONT = "japan font"; class NamesModel : public gcn::ListModel { @@ -136,6 +137,7 @@ Setup_Theme::Setup_Theme(): mParticleFont(config.getStringValue("particleFont")), mHelpFont(config.getStringValue("helpFont")), mSecureFont(config.getStringValue("secureFont")), + mJapanFont(config.getStringValue("japanFont")), mFontSize(config.getIntValue("fontSize")) { setName(_("Theme")); @@ -146,6 +148,7 @@ Setup_Theme::Setup_Theme(): mParticleFontLabel = new Label(_("Particle font")); mHelpFontLabel = new Label(_("Help font")); mSecureFontLabel = new Label(_("Secure font")); + mJapanFontLabel = new Label(_("Japanese font")); mThemesModel = new ThemesModel(); mFontsModel = new FontsModel(); @@ -173,6 +176,10 @@ Setup_Theme::Setup_Theme(): mSecureFontDropDown->setActionEventId(ACTION_SECURE_FONT); mSecureFontDropDown->addActionListener(this); + mJapanFontDropDown = new DropDown(mFontsModel); + mJapanFontDropDown->setActionEventId(ACTION_JAPAN_FONT); + mJapanFontDropDown->addActionListener(this); + fontSizeLabel = new Label(_("Font size")); mFontSizeListModel = new FontSizeChoiceListModel; mFontSizeDropDown = new DropDown(mFontSizeListModel); @@ -195,25 +202,30 @@ Setup_Theme::Setup_Theme(): config.getStringValue("helpFont"))); mSecureFontDropDown->setSelectedString(getFileName( config.getStringValue("secureFont"))); + mJapanFontDropDown->setSelectedString(getFileName( + config.getStringValue("japanFont"))); // Do the layout LayoutHelper h(this); ContainerPlacer place = h.getPlacer(0, 0); - place(0, 0, mThemeLabel, 10); - place(0, 1, mThemeDropDown, 6); - place(0, 2, fontSizeLabel, 10); - place(0, 3, mFontSizeDropDown, 6); - place(0, 4, mFontLabel, 10); - place(0, 5, mFontDropDown, 6); - place(0, 6, mBoldFontLabel, 10); - place(0, 7, mBoldFontDropDown, 6); - place(0, 8, mParticleFontLabel, 10); - place(0, 9, mParticleFontDropDown, 6); - place(0, 10, mHelpFontLabel, 10); - place(0, 11, mHelpFontDropDown, 6); - place(0, 12, mSecureFontLabel, 10); - place(0, 13, mSecureFontDropDown, 6); + place(0, 0, mThemeLabel, 5); + place(0, 1, fontSizeLabel, 5); + place(0, 2, mFontLabel, 5); + place(0, 3, mBoldFontLabel, 5); + place(0, 4, mParticleFontLabel, 5); + place(0, 5, mHelpFontLabel, 5); + place(0, 6, mSecureFontLabel, 5); + place(0, 7, mJapanFontLabel, 5); + + place(6, 0, mThemeDropDown, 10); + place(6, 1, mFontSizeDropDown, 10); + place(6, 2, mFontDropDown, 10); + place(6, 3, mBoldFontDropDown, 10); + place(6, 4, mParticleFontDropDown, 10); + place(6, 5, mHelpFontDropDown, 10); + place(6, 6, mSecureFontDropDown, 10); + place(6, 7, mJapanFontDropDown, 10); place.getCell().matchColWidth(0, 0); place = h.getPlacer(0, 1); @@ -262,6 +274,10 @@ void Setup_Theme::action(const gcn::ActionEvent &event) { mSecureFont = mSecureFontDropDown->getSelectedString(); } + else if (event.getId() == ACTION_JAPAN_FONT) + { + mJapanFont = mJapanFontDropDown->getSelectedString(); + } } void Setup_Theme::cancel() @@ -272,6 +288,7 @@ void Setup_Theme::cancel() mParticleFont = getFileName(config.getStringValue("particleFont")); mHelpFont = getFileName(config.getStringValue("helpFont")); mSecureFont = getFileName(config.getStringValue("secureFont")); + mJapanFont = getFileName(config.getStringValue("japanFont")); } void Setup_Theme::apply() @@ -290,6 +307,7 @@ void Setup_Theme::apply() || config.getValue("particleFont", "dejavusans.ttf") != mParticleFont || config.getValue("helpFont", "dejavusansmono.ttf") != mHelpFont || config.getValue("secureFont", "dejavusansmono.ttf") != mSecureFont + || config.getValue("japanFont", "mplus-1p-regular.ttf") != mJapanFont || config.getIntValue("fontSize") != static_cast(mFontSizeDropDown->getSelected()) + 10) { @@ -298,6 +316,7 @@ void Setup_Theme::apply() config.setValue("particleFont", "fonts/" + getFileName(mParticleFont)); config.setValue("helpFont", "fonts/" + getFileName(mHelpFont)); config.setValue("secureFont", "fonts/" + getFileName(mSecureFont)); + config.setValue("japanFont", "fonts/" + getFileName(mJapanFont)); config.setValue("fontSize", mFontSizeDropDown->getSelected() + 10); gui->updateFonts(); } diff --git a/src/gui/setup_theme.h b/src/gui/setup_theme.h index 1952a88c6..c803cc296 100644 --- a/src/gui/setup_theme.h +++ b/src/gui/setup_theme.h @@ -74,6 +74,10 @@ class Setup_Theme : public SetupTab DropDown *mSecureFontDropDown; std::string mSecureFont; + gcn::Label *mJapanFontLabel; + DropDown *mJapanFontDropDown; + std::string mJapanFont; + FontSizeChoiceListModel *mFontSizeListModel; gcn::Label *fontSizeLabel; int mFontSize; -- cgit v1.2.3-70-g09d2 From 658a7a325114783627c7c6c870bfe01791f9f63e Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 16 Aug 2011 22:07:30 +0300 Subject: Add header to mumblemanager and some clean. --- src/mumblemanager.cpp | 4 +++- src/mumblemanager.h | 4 +++- src/resources/iteminfo.cpp | 3 ++- src/resources/iteminfo.h | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/mumblemanager.cpp b/src/mumblemanager.cpp index a9a8146b6..bace077cd 100644 --- a/src/mumblemanager.cpp +++ b/src/mumblemanager.cpp @@ -1,4 +1,6 @@ -/* Code taken from: http://mumble.sourceforge.net/Link */ +/* + *Code taken from: http://mumble.sourceforge.net/Link + */ #include "mumblemanager.h" diff --git a/src/mumblemanager.h b/src/mumblemanager.h index a3eddee02..f7617233f 100644 --- a/src/mumblemanager.h +++ b/src/mumblemanager.h @@ -1,4 +1,6 @@ -/* Code taken from: http://mumble.sourceforge.net/Link */ +/* + * Code taken from: http://mumble.sourceforge.net/Link + */ #ifndef MUMBLEMANAGER_H #define MUMBLEMANAGER_H diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp index 6658236f3..56cfc01f6 100644 --- a/src/resources/iteminfo.cpp +++ b/src/resources/iteminfo.cpp @@ -32,7 +32,7 @@ #include "debug.h" - +/* ItemInfo::ItemInfo(ItemInfo &info) { mMissileParticleFile = info.mMissileParticleFile; @@ -61,6 +61,7 @@ ItemInfo::ItemInfo(ItemInfo &info) mDrawPriority[f] = info.mDrawPriority[f]; } } +*/ ItemInfo::ItemInfo() : mMissileParticleFile(""), diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index daa9d590c..1fe8f3bad 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -107,7 +107,7 @@ class ItemInfo */ ItemInfo(); - ItemInfo(ItemInfo &info); +// ItemInfo(ItemInfo &info); ~ItemInfo(); -- cgit v1.2.3-70-g09d2 From fa68f4ad4b2f776af834f8209b51761f6c2ba125 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 16 Aug 2011 22:52:46 +0300 Subject: Show shop sign to other players only if shop is not empty. --- src/gui/shopwindow.cpp | 9 +++++++++ src/gui/shopwindow.h | 2 ++ src/gui/widgets/shopitems.cpp | 5 +++++ src/gui/widgets/shopitems.h | 2 ++ src/localplayer.cpp | 3 ++- 5 files changed, 20 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/shopwindow.cpp b/src/gui/shopwindow.cpp index 68ea57314..4311a04d2 100644 --- a/src/gui/shopwindow.cpp +++ b/src/gui/shopwindow.cpp @@ -803,3 +803,12 @@ int ShopWindow::sumAmount(Item *shopItem) } return sum; } + +bool ShopWindow::isShopEmpty() +{ + if (!mBuyShopItems || !mSellShopItems) + return true; + if (mBuyShopItems->empty() && mSellShopItems->empty()) + return true; + return false; +} diff --git a/src/gui/shopwindow.h b/src/gui/shopwindow.h index e07803225..e3fd9a5ca 100644 --- a/src/gui/shopwindow.h +++ b/src/gui/shopwindow.h @@ -133,6 +133,8 @@ class ShopWindow : public Window, public gcn::ActionListener, bool checkFloodCounter(int &counterTime); + bool isShopEmpty(); + private: void startTrade(); diff --git a/src/gui/widgets/shopitems.cpp b/src/gui/widgets/shopitems.cpp index c5bcd88c4..e15445b77 100644 --- a/src/gui/widgets/shopitems.cpp +++ b/src/gui/widgets/shopitems.cpp @@ -43,6 +43,11 @@ int ShopItems::getNumberOfElements() return static_cast(mShopItems.size()); } +bool ShopItems::empty() +{ + return mShopItems.empty(); +} + std::string ShopItems::getElementAt(int i) { if (i < 0 || static_cast(i) >= mShopItems.size() diff --git a/src/gui/widgets/shopitems.h b/src/gui/widgets/shopitems.h index abfcffb71..29d24cb64 100644 --- a/src/gui/widgets/shopitems.h +++ b/src/gui/widgets/shopitems.h @@ -76,6 +76,8 @@ class ShopItems : public gcn::ListModel */ int getNumberOfElements(); + bool empty(); + /** * Returns the name of item number i in the shop. * diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 9f0a7c5f3..0dcf7e7c2 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -50,6 +50,7 @@ #include "gui/okdialog.h" #include "gui/outfitwindow.h" #include "gui/palette.h" +#include "gui/shopwindow.h" #include "gui/skilldialog.h" #include "gui/socialwindow.h" #include "gui/statuswindow.h" @@ -344,7 +345,7 @@ void LocalPlayer::logic() if (mEnableAdvert && !mBlockAdvert && mAdvertTime < cur_time) { Uint8 smile = FLAG_SPECIAL; - if (mTradebot) + if (mTradebot && shopWindow && !shopWindow->isShopEmpty()) smile += FLAG_SHOP; if (mAwayMode) -- cgit v1.2.3-70-g09d2 From 4e4f7204f8e0f67924ced03be6330b6bc8766c28 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 16 Aug 2011 23:57:17 +0300 Subject: Enable by default putting server and magic messages in debug tab. --- src/defaults.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/defaults.cpp b/src/defaults.cpp index e1cb08299..16f4620d4 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -168,9 +168,9 @@ DefaultsData* getConfigDefaults() AddDEF(configData, "floorItemsHighlight", true); AddDEF(configData, "enableBotCheker", true); AddDEF(configData, "removeColors", true); - AddDEF(configData, "showMagicInDebug", false); + AddDEF(configData, "showMagicInDebug", true); AddDEF(configData, "allowCommandsInChatTabs", true); - AddDEF(configData, "serverMsgInDebug", false); + AddDEF(configData, "serverMsgInDebug", true); AddDEF(configData, "hideShopMessages", true); AddDEF(configData, "showChatHistory", true); AddDEF(configData, "showChatColorsList", true); -- cgit v1.2.3-70-g09d2 From 04bc4f2b057c99a7b82ab95973180381824c85ab Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 17 Aug 2011 20:15:17 +0300 Subject: Fix chat auto scroll to down if input field is visible. --- src/gui/widgets/chattab.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index e27af8b25..785bdd6be 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -249,12 +249,13 @@ void ChatTab::chatLog(std::string line, Own own, // 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() >= + if (mScrollArea->getVerticalScrollAmount() + 2 >= mScrollArea->getVerticalMaxScroll()) { addRow(line); mScrollArea->setVerticalScrollAmount( mScrollArea->getVerticalMaxScroll()); + } else { -- cgit v1.2.3-70-g09d2 From 4a0c7b37814792f774ba288e28fa63cf12b3244f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 17 Aug 2011 21:20:59 +0300 Subject: Change attack logic if enabled auto switching knife to bow. --- src/localplayer.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src') diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 0dcf7e7c2..5192390bc 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -3464,10 +3464,7 @@ void LocalPlayer::attack2(Being *target, bool keep, bool dontChangeEquipment) if (target && target->getType() != Being::NPC) { mKeepAttacking = true; - if (mAttackWeaponType == 1) - moveToTarget(); - else - moveToTarget(mAttackRange); + moveToTarget(); } } } -- cgit v1.2.3-70-g09d2 From d4e2ffacb744f76c84c94cb16b2cc0e0e49153f7 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 18 Aug 2011 01:50:40 +0300 Subject: Create boxes in equipment window on the fly. --- src/gui/equipmentwindow.cpp | 94 ++++++++++++++++++++++++++------------------- src/gui/equipmentwindow.h | 15 +++----- 2 files changed, 60 insertions(+), 49 deletions(-) (limited to 'src') diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 5a2820550..065e3b5ef 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -55,24 +55,6 @@ static const int BOX_WIDTH = 36; static const int BOX_HEIGHT = 36; -// Positions of the boxes, 2nd dimension is X and Y respectively. -static const int boxPosition[][2] = -{ - { 90, 40 }, // EQUIP_TORSO_SLOT - { 8, 78 }, // EQUIP_GLOVES_SLOT - { 70, 0 }, // EQUIP_HEAD_SLOT - { 50, 253 }, // EQUIP_LEGS_SLOT - { 90, 253 }, // EQUIP_FEET_SLOT - { 8, 213 }, // EQUIP_RING1_SLOT - { 129, 213 }, // EQUIP_RING2_SLOT - { 50, 40 }, // EQUIP_NECK_SLOT - { 8, 168 }, // EQUIP_FIGHT1_SLOT - { 129, 168 }, // EQUIP_FIGHT2_SLOT - { 129, 78 }, // EQUIP_PROJECTILE_SLOT - { 8, 123 }, // EQUIP_EVOL_RING1_SLOT - { 129, 123 }, // EQUIP_EVOL_RING2_SLOT -}; - EquipmentWindow::EquipmentWindow(Equipment *equipment, Being *being, bool foring): Window(_("Equipment")), @@ -80,6 +62,7 @@ EquipmentWindow::EquipmentWindow(Equipment *equipment, Being *being, mSelected(-1), mForing(foring) { + fillBoxes(); mBeing = being; mItemPopup = new ItemPopup; if (setupWindow) @@ -109,11 +92,6 @@ EquipmentWindow::EquipmentWindow(Equipment *equipment, Being *being, add(mPlayerBox); add(mUnequip); - for (int i = 0; i < Equipment::EQUIP_VECTOREND; i++) - { - mEquipBox[i].posX = boxPosition[i][0] + getPadding(); - mEquipBox[i].posY = boxPosition[i][1] + getTitleBarHeight(); - } } EquipmentWindow::~EquipmentWindow() @@ -138,23 +116,30 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) Window::drawChildren(graphics); - for (int i = 0; i < Equipment::EQUIP_VECTOREND; i++) + int i = 0; + const int fontHeight = getFont()->getHeight(); + + std::vector*>::const_iterator it; + std::vector*>::const_iterator it_end = mBoxes.end(); + + for (it = mBoxes.begin(); it != it_end; ++ it, ++ i) { + std::pair *box = *it; if (i == mSelected) { const gcn::Color color = Theme::getThemeColor(Theme::HIGHLIGHT); // Set color to the highlight color g->setColor(gcn::Color(color.r, color.g, color.b, getGuiAlpha())); - g->fillRectangle(gcn::Rectangle(mEquipBox[i].posX, - mEquipBox[i].posY, BOX_WIDTH, BOX_HEIGHT)); + g->fillRectangle(gcn::Rectangle(box->first, + box->second, BOX_WIDTH, BOX_HEIGHT)); } // Set color black g->setColor(gcn::Color(0, 0, 0)); // Draw box border - g->drawRectangle(gcn::Rectangle(mEquipBox[i].posX, mEquipBox[i].posY, - BOX_WIDTH, BOX_HEIGHT)); + g->drawRectangle(gcn::Rectangle(box->first, box->second, + BOX_WIDTH, BOX_HEIGHT)); if (!mEquipment) continue; @@ -168,15 +153,13 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) { image->setAlpha(1.0f); // Ensure the image is drawn // with maximum opacity - g->drawImage(image, - mEquipBox[i].posX + 2, - mEquipBox[i].posY + 2); + g->drawImage(image, box->first + 2, box->second + 2); if (i == EQUIP_PROJECTILE_SLOT) { g->setColor(Theme::getThemeColor(Theme::TEXT)); graphics->drawText(toString(item->getQuantity()), - mEquipBox[i].posX + (BOX_WIDTH / 2), - mEquipBox[i].posY - getFont()->getHeight(), + box->first + (BOX_WIDTH / 2), + box->second - fontHeight, gcn::Graphics::CENTER); } } @@ -202,10 +185,15 @@ Item *EquipmentWindow::getItem(int x, int y) const if (!mEquipment) return 0; - for (int i = 0; i < Equipment::EQUIP_VECTOREND; i++) + std::vector*>::const_iterator it; + std::vector*>::const_iterator it_end = mBoxes.end(); + int i = 0; + + for (it = mBoxes.begin(); it != it_end; ++ it, ++ i) { - gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY, - BOX_WIDTH, BOX_HEIGHT); + std::pair *box = *it; + const gcn::Rectangle tRect(box->first, box->second, + BOX_WIDTH, BOX_HEIGHT); if (tRect.isPointInRect(x, y)) return mEquipment->getEquipment(i); @@ -228,11 +216,16 @@ void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent) if (mForing) return; // Checks if any of the presses were in the equip boxes. - for (int i = 0; i < Equipment::EQUIP_VECTOREND; i++) + std::vector*>::const_iterator it; + std::vector*>::const_iterator it_end = mBoxes.end(); + int i = 0; + + for (it = mBoxes.begin(); it != it_end; ++ it, ++ i) { + std::pair *box = *it; Item *item = mEquipment->getEquipment(i); - gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY, - BOX_WIDTH, BOX_HEIGHT); + const gcn::Rectangle tRect(box->first, box->second, + BOX_WIDTH, BOX_HEIGHT); if (tRect.isPointInRect(x, y) && item) setSelected(i); @@ -326,3 +319,26 @@ void EquipmentWindow::resetBeing(Being *being) if (being == mBeing) setBeing(0); } + +void EquipmentWindow::fillBoxes() +{ + addBox(90, 40); // torso + addBox(8, 78); // gloves + addBox(70, 0); // hat + addBox(50, 253); // pants + addBox(90, 253); // boots + addBox(8, 213); // FREE + addBox(129, 213); // wings + addBox(50, 40); // scarf + addBox(8, 168); // weapon + addBox(129, 168); // shield + addBox(129, 78); // ammo + addBox(8, 123); // amulet + addBox(129, 123); // ring +} + +void EquipmentWindow::addBox(int x, int y) +{ + mBoxes.push_back(new std::pair( + x + getPadding(), y + getTitleBarHeight())); +} diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h index 84353dfd2..91ee44253 100644 --- a/src/gui/equipmentwindow.h +++ b/src/gui/equipmentwindow.h @@ -81,24 +81,18 @@ class EquipmentWindow : public Window, public gcn::ActionListener private: void mouseExited(gcn::MouseEvent &event); + void mouseMoved(gcn::MouseEvent &event); Item *getItem(int x, int y) const; void setSelected(int index); - Equipment *mEquipment; + void fillBoxes(); - /** - * Equipment box. - */ - struct EquipBox - { - int posX; - int posY; - }; + void addBox(int x, int y); - EquipBox mEquipBox[Equipment::EQUIP_VECTOREND]; /***> mBoxes; }; extern EquipmentWindow *equipmentWindow; -- cgit v1.2.3-70-g09d2 From 0cc939c1c9f82e5688e2903e38d164db5bc749c1 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 18 Aug 2011 03:03:40 +0300 Subject: Load equipment window configuration from equipmentwindow.xml file. Now possible move or replace slots or play image. --- src/gui/equipmentwindow.cpp | 167 +++++++++++++++++++++++++++++++++++++++----- src/gui/equipmentwindow.h | 14 +++- 2 files changed, 162 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 065e3b5ef..eab0561ee 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -62,7 +62,6 @@ EquipmentWindow::EquipmentWindow(Equipment *equipment, Being *being, mSelected(-1), mForing(foring) { - fillBoxes(); mBeing = being; mItemPopup = new ItemPopup; if (setupWindow) @@ -81,6 +80,13 @@ EquipmentWindow::EquipmentWindow(Equipment *equipment, Being *being, setCloseButton(true); setSaveVisible(true); setDefaultSize(180, 345, ImageRect::CENTER); + + mBoxes.reserve(13); + for (int f = 0; f < 13; f ++) + mBoxes.push_back(0); + + fillBoxes(); + loadWindowState(); mUnequip = new Button(_("Unequip"), "unequip", this); @@ -125,6 +131,8 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) for (it = mBoxes.begin(); it != it_end; ++ it, ++ i) { std::pair *box = *it; + if (!box) + continue; if (i == mSelected) { const gcn::Color color = Theme::getThemeColor(Theme::HIGHLIGHT); @@ -192,6 +200,8 @@ Item *EquipmentWindow::getItem(int x, int y) const for (it = mBoxes.begin(); it != it_end; ++ it, ++ i) { std::pair *box = *it; + if (!box) + continue; const gcn::Rectangle tRect(box->first, box->second, BOX_WIDTH, BOX_HEIGHT); @@ -217,12 +227,15 @@ void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent) return; // Checks if any of the presses were in the equip boxes. std::vector*>::const_iterator it; - std::vector*>::const_iterator it_end = mBoxes.end(); + std::vector*>::const_iterator + it_end = mBoxes.end(); int i = 0; for (it = mBoxes.begin(); it != it_end; ++ it, ++ i) { std::pair *box = *it; + if (!box) + continue; Item *item = mEquipment->getEquipment(i); const gcn::Rectangle tRect(box->first, box->second, BOX_WIDTH, BOX_HEIGHT); @@ -322,23 +335,141 @@ void EquipmentWindow::resetBeing(Being *being) void EquipmentWindow::fillBoxes() { - addBox(90, 40); // torso - addBox(8, 78); // gloves - addBox(70, 0); // hat - addBox(50, 253); // pants - addBox(90, 253); // boots - addBox(8, 213); // FREE - addBox(129, 213); // wings - addBox(50, 40); // scarf - addBox(8, 168); // weapon - addBox(129, 168); // shield - addBox(129, 78); // ammo - addBox(8, 123); // amulet - addBox(129, 123); // ring + XML::Document *doc = new XML::Document("equipmentwindow.xml"); + xmlNodePtr root = doc->rootNode(); + if (!root) + { + delete doc; + fillDefault(); + return; + } + + for_each_xml_child_node(node, root) + { + if (xmlStrEqual(node->name, BAD_CAST "window")) + loadWindow(node); + else if (xmlStrEqual(node->name, BAD_CAST "playerbox")) + loadPlayerBox(node); + else if (xmlStrEqual(node->name, BAD_CAST "slot")) + loadSlot(node); + } +} + +void EquipmentWindow::loadWindow(xmlNodePtr windowNode) +{ + setDefaultSize(XML::getProperty(windowNode, "width", 180), + XML::getProperty(windowNode, "height", 345), ImageRect::CENTER); +} + +void EquipmentWindow::loadPlayerBox(xmlNodePtr playerBoxNode) +{ + mPlayerBox->setDimension(gcn::Rectangle( + XML::getProperty(playerBoxNode, "x", 50), + XML::getProperty(playerBoxNode, "y", 80), + XML::getProperty(playerBoxNode, "width", 74), + XML::getProperty(playerBoxNode, "height", 168))); +} + +void EquipmentWindow::loadSlot(xmlNodePtr slotNode) +{ + int slot = parseSlotName(XML::getProperty(slotNode, "name", "")); + if (slot < 0) + return; + + const int x = XML::getProperty(slotNode, "x", 0) + getPadding(); + const int y = XML::getProperty(slotNode, "y", 0) + getTitleBarHeight(); + + if (mBoxes[slot]) + { + std::pair *pair = mBoxes[slot]; + pair->first = x; + pair->second = y; + } + else + { + mBoxes[slot] = new std::pair(x, y); + } +} + +int EquipmentWindow::parseSlotName(std::string name) +{ + int id = -1; + if (name == "shoes" || name == "boot" || name == "boots") + { + id = 4; + } + else if (name == "bottomclothes" || name == "bottom" || name == "pants") + { + id = 3; + } + else if (name == "topclothes" || name == "top" + || name == "torso" || name == "body") + { + id = 0; + } + else if (name == "free" || name == "misc1") + { + id = 5; + } + else if (name == "misc2" || name == "scarf" || name == "scarfs") + { + id = 7; + } + else if (name == "hat" || name == "hats") + { + id = 2; + } + else if (name == "wings") + { + id = 6; + } + else if (name == "glove" || name == "gloves") + { + id = 1; + } + else if (name == "weapon" || name == "weapons") + { + id = 8; + } + else if (name == "shield" || name == "shields") + { + id = 9; + } + else if (name == "amulet" || name == "amulets") + { + id = 11; + } + else if (name == "ring" || name == "rings") + { + id = 12; + } + else if (name == "arrow" || name == "arrows" || name == "ammo") + { + id = 10; + } + + return id; +} + +void EquipmentWindow::fillDefault() +{ + addBox(0, 90, 40); // torso + addBox(1, 8, 78); // gloves + addBox(2, 70, 0); // hat + addBox(3, 50, 253); // pants + addBox(4, 90, 253); // boots + addBox(5, 8, 213); // FREE + addBox(6, 129, 213); // wings + addBox(7, 50, 40); // scarf + addBox(8, 8, 168); // weapon + addBox(9, 129, 168); // shield + addBox(10, 129, 78); // ammo + addBox(11, 8, 123); // amulet + addBox(12, 129, 123); // ring } -void EquipmentWindow::addBox(int x, int y) +void EquipmentWindow::addBox(int idx, int x, int y) { - mBoxes.push_back(new std::pair( - x + getPadding(), y + getTitleBarHeight())); + mBoxes[idx] = new std::pair( + x + getPadding(), y + getTitleBarHeight()); } diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h index 91ee44253..082a9b409 100644 --- a/src/gui/equipmentwindow.h +++ b/src/gui/equipmentwindow.h @@ -28,6 +28,8 @@ #include "gui/widgets/window.h" +#include "utils/xml.h" + #include #ifdef __GNUC__ @@ -90,7 +92,17 @@ class EquipmentWindow : public Window, public gcn::ActionListener void fillBoxes(); - void addBox(int x, int y); + void fillDefault(); + + void addBox(int idx, int x, int y); + + void loadWindow(xmlNodePtr windowNode); + + void loadPlayerBox(xmlNodePtr playerBoxNode); + + void loadSlot(xmlNodePtr slotNode); + + int parseSlotName(std::string name); Equipment *mEquipment; -- cgit v1.2.3-70-g09d2 From 8eb694f537eafa137aaee7111e4971f75358164b Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 18 Aug 2011 16:19:01 +0300 Subject: Improve "auto adjust perfomance". --- src/game.cpp | 12 +++++++++++- src/game.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/game.cpp b/src/game.cpp index 8457cf079..82f919976 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -338,7 +338,8 @@ Game::Game(): mValidSpeed(true), mLastAction(0), mNextAdjustTime(cur_time + adjustDelay), - mAdjustLevel(0) + mAdjustLevel(0), + mLowerCounter(0) { spellManager = new SpellManager; spellShortcut = new SpellShortcut; @@ -586,6 +587,13 @@ void Game::adjustPerfomance() if (fps < maxFps - 10) { + if (mLowerCounter < 2) + { + mLowerCounter ++; + mNextAdjustTime = cur_time + 1; + return; + } + mLowerCounter = 0; mAdjustLevel ++; switch (mAdjustLevel) { @@ -604,6 +612,7 @@ void Game::adjustPerfomance() else { mNextAdjustTime = cur_time + 1; + mLowerCounter = 2; } break; } @@ -621,6 +630,7 @@ void Game::adjustPerfomance() else { mNextAdjustTime = cur_time + 1; + mLowerCounter = 2; } break; case 3: diff --git a/src/game.h b/src/game.h index 88dc9166b..84dca08e9 100644 --- a/src/game.h +++ b/src/game.h @@ -117,6 +117,7 @@ class Game unsigned mNextAdjustTime; int mAdjustLevel; bool mAdjustPerfomance; + int mLowerCounter; static Game *mInstance; }; -- cgit v1.2.3-70-g09d2 From 05d7793aa71a600d76d169ca80744768b277c17b Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 19 Aug 2011 19:56:45 +0300 Subject: Fix memory leaks in equipment window. --- src/gui/equipmentwindow.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index eab0561ee..67ec78e49 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -45,6 +45,7 @@ #include "resources/iteminfo.h" #include "resources/resourcemanager.h" +#include "utils/dtor.h" #include "utils/gettext.h" #include "utils/stringutils.h" @@ -111,6 +112,8 @@ EquipmentWindow::~EquipmentWindow() delete mEquipment; mEquipment = 0; } + delete_all(mBoxes); + mBoxes.clear(); } void EquipmentWindow::draw(gcn::Graphics *graphics) @@ -353,6 +356,7 @@ void EquipmentWindow::fillBoxes() else if (xmlStrEqual(node->name, BAD_CAST "slot")) loadSlot(node); } + delete doc; } void EquipmentWindow::loadWindow(xmlNodePtr windowNode) -- cgit v1.2.3-70-g09d2 From 7191eefef8c7a02c7cf56f598ea76fe791328434 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 19 Aug 2011 20:42:46 +0300 Subject: Fix adding items to trade. Now possible add same items from all ways. Also added protection from adding same stackable items. --- src/gui/inventorywindow.cpp | 2 +- src/gui/popupmenu.cpp | 6 +++--- src/gui/tradewindow.cpp | 33 ++++++++++++++++++++++++--------- src/gui/tradewindow.h | 4 +++- src/inventory.cpp | 3 +++ 5 files changed, 34 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 27fbf7760..3b7b7b273 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -427,7 +427,7 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event) else { if (tradeWindow) - tradeWindow->tradeItem(item, item->getQuantity()); + tradeWindow->tradeItem(item, item->getQuantity(), true); } } } diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index a7c008684..eefa83500 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -1066,18 +1066,18 @@ void PopupMenu::handleLink(const std::string &link, int cnt = 10; if (cnt > mItem->getQuantity()) cnt = mItem->getQuantity(); - tradeWindow->tradeItem(mItem, cnt); + tradeWindow->tradeItem(mItem, cnt, true); } } else if (link == "addtrade half" && mItem) { if (tradeWindow) - tradeWindow->tradeItem(mItem, mItem->getQuantity() / 2); + tradeWindow->tradeItem(mItem, mItem->getQuantity() / 2, true); } else if (link == "addtrade all" && mItem) { if (tradeWindow) - tradeWindow->tradeItem(mItem, mItem->getQuantity()); + tradeWindow->tradeItem(mItem, mItem->getQuantity(), true); } else if (link == "retrieve" && mItem) { diff --git a/src/gui/tradewindow.cpp b/src/gui/tradewindow.cpp index c607636d9..d00fb61f4 100644 --- a/src/gui/tradewindow.cpp +++ b/src/gui/tradewindow.cpp @@ -246,8 +246,11 @@ void TradeWindow::receivedOk(bool own) } } -void TradeWindow::tradeItem(Item *item, int quantity) +void TradeWindow::tradeItem(Item *item, int quantity, bool check) { + if (check && !checkItem(item)) + return; + Net::getTradeHandler()->addItem(item, quantity); } @@ -325,15 +328,9 @@ void TradeWindow::action(const gcn::ActionEvent &event) if (mMyInventory->getFreeSlot() == -1) return; - if (mMyInventory->contains(item)) - { - if (localChatTab) - { - localChatTab->chatLog(_("Failed adding item. You can not " - "overlap one kind of item on the window."), BY_SERVER); - } + + if (!checkItem(item)) return; - } // Choose amount of items to trade ItemAmountWindow::showWindow(ItemAmountWindow::TradeAdd, this, item); @@ -442,3 +439,21 @@ void TradeWindow::initTrade(std::string nick) if (!player_relations.isGoodName(nick)) setCaptionFont(gui->getSecureFont()); } + +bool TradeWindow::checkItem(Item *item) +{ + Item *tradeItem = mMyInventory->findItem( + item->getId(), item->getColor()); + + if (tradeItem && (tradeItem->getQuantity() > 1 + || item->getQuantity() > 1)) + { + if (localChatTab) + { + localChatTab->chatLog(_("Failed adding item. You can not " + "overlap one kind of item on the window."), BY_SERVER); + } + return false; + } + return true; +} diff --git a/src/gui/tradewindow.h b/src/gui/tradewindow.h index 3c5ed56b0..16b3d9d6f 100644 --- a/src/gui/tradewindow.h +++ b/src/gui/tradewindow.h @@ -95,7 +95,7 @@ class TradeWindow : public Window, gcn::ActionListener, gcn::SelectionListener /** * Send trade packet. */ - void tradeItem(Item *item, int quantity); + void tradeItem(Item *item, int quantity, bool check = false); /** * Updates the labels and makes sure only one item is selected in @@ -131,6 +131,8 @@ class TradeWindow : public Window, gcn::ActionListener, gcn::SelectionListener std::string getAutoTradeNick() { return mAutoAddToNick; } + bool checkItem(Item *item); + private: enum Status { diff --git a/src/inventory.cpp b/src/inventory.cpp index acd35efdd..f907b2cc2 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -155,6 +155,9 @@ void Inventory::removeItemAt(int index) bool Inventory::contains(Item *item) const { + if (!item) + return false; + for (unsigned i = 0; i < mSize; i++) { if (mItems[i] && mItems[i]->getId() == item->getId()) -- cgit v1.2.3-70-g09d2 From 0896958465444277fdf5891bdbc4ede53e808db0 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 20 Aug 2011 04:13:58 +0300 Subject: Improve drawing invisible npc like arrows or rain. --- src/being.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/being.cpp b/src/being.cpp index 7c2a6bf40..d3181c32a 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -476,7 +476,7 @@ void Being::setSpeech(const std::string &text, int time) mSpeech = mSpeech.substr(0, lineLim); trim(mSpeech); - if (mSpeech.length() < 1) + if (mSpeech.empty()) return; if (!time && mSpeech.size() < 200) @@ -1363,7 +1363,7 @@ void Being::drawEmotion(Graphics *graphics, int offsetX, int offsetY) void Being::drawSpeech(int offsetX, int offsetY) { - if (!mSpeechBubble) + if (!mSpeechBubble || mSpeech.empty()) return; const int px = getPixelX() - offsetX; @@ -1554,6 +1554,9 @@ void Being::showName() font = gui->getSecureFont(); } + if (mDisplayName.empty()) + return; + mDispName = new FlashText(mDisplayName, getPixelX(), getPixelY(), gcn::Graphics::CENTER, mNameColor, font); -- cgit v1.2.3-70-g09d2 From 80990bd472f849fc33083bbc5eceab1df129c223 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 20 Aug 2011 17:57:03 +0300 Subject: Fix compilation warning. --- src/gui/serverdialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index 37870a87f..143d3e5a3 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -124,7 +124,7 @@ std::string ServersListModel::getElementAt(int elementIndex) void ServersListModel::setVersionString(int index, const std::string &version) { - if (index >= mVersionStrings.size()) + if (index >= (int)mVersionStrings.size()) return; if (version.empty()) -- cgit v1.2.3-70-g09d2 From 3689ea3de59012d8abee08431b802cec81ba76e9 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 20 Aug 2011 18:09:11 +0300 Subject: Change version to 1.1.8.21 --- ChangeLog | 23 +++++++++++++++++++++++ README | 2 +- README.txt | 2 +- configure.ac | 2 +- packwin | 2 +- src/main.h | 4 ++-- 6 files changed, 29 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/ChangeLog b/ChangeLog index 96897a843..b0ad8f4bb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2011-08-21 New release 1.1.8.21 +ManaPlus: +fix: moving near npc. +fix: crash in server dialog if press load button twice. +fix: saving opened whisper tabs. +fix: hide/show setup window by hot key. +fix: show shop sign on players only if shop enabled and shop not empty. +fix: chat auto scroll. +fix: mode with switching bow to knife. +fix: adding limits to adding items to trade. +fix: perfomance issue with invisible npcs. +add: auto improve perfomance by disabling different draphics features. +add: perfomance tab. most perfomance related settings moved to this tab. +add: new perfomance related options to perfomance tab. +add: split players setup tab to relations and players. +add: ability to add comments to npcs. +add: option to hide ip addresses on screen shots. +add: warp menu item navigation points menu (for gms only). +add: copy to chat button in status window to copy player stats to chat. +add: enable auto switching to janapese font if used japan locale. +add: update dejavu and mplus fonts. +add: updated translations. + 2011-08-07 New release 1.1.8.7 ManaPlus: fix: player attack animation length. diff --git a/README b/README index 90d368360..3f2cb5244 100644 --- a/README +++ b/README @@ -1,7 +1,7 @@ THE MANA PLUS CLIENT =============== - Version: 1.1.8.7 Date: 2011-08-07 + Version: 1.1.8.21 Date: 2011-08-21 Development team: - See AUTHORS file for a list diff --git a/README.txt b/README.txt index ab33f1c91..b9ad19133 100644 --- a/README.txt +++ b/README.txt @@ -1,7 +1,7 @@ THE MANA PLUS CLIENT =============== - Version: 1.1.8.7 Date: 2011-08-07 + Version: 1.1.8.21 Date: 2011-08-21 Development team: - See AUTHORS file for a list diff --git a/configure.ac b/configure.ac index d893b7e7c..cd70c8d2d 100755 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ(2.59) -AC_INIT([ManaPlus], [1.1.8.7], [akaras@inbox.ru], [manaplus]) +AC_INIT([ManaPlus], [1.1.8.21], [akaras@inbox.ru], [manaplus]) AM_INIT_AUTOMAKE([1.9]) AC_CONFIG_HEADERS([config.h:config.h.in]) AC_LANG_CPLUSPLUS diff --git a/packwin b/packwin index 8980b0e50..7d630dc98 100755 --- a/packwin +++ b/packwin @@ -5,7 +5,7 @@ dir=`pwd` cd packaging/windows ./make-translations.sh makensis -DDLLDIR=$dir/../mana_win/libs/dll/ \ - -DPRODUCT_VERSION="1.1.8.7" \ + -DPRODUCT_VERSION="1.1.8.21" \ -DEXESUFFIX=/src \ -DUPX=true \ setup.nsi diff --git a/src/main.h b/src/main.h index 35a25fc02..9f8bbc6ac 100644 --- a/src/main.h +++ b/src/main.h @@ -85,8 +85,8 @@ //define DEBUG_ALPHA_CACHE 1 //define DEBUG_OPENGL_LEAKS 1 -#define SMALL_VERSION "1.1.8.7" -#define CHECK_VERSION "01.01.08.07" +#define SMALL_VERSION "1.1.8.21" +#define CHECK_VERSION "01.01.08.21" #define PACKAGE_EXTENDED_VERSION "ManaPlus (" PACKAGE_OS \ -- cgit v1.2.3-70-g09d2 From a19ff6d060d0be8a7cb25bde5c7ad9f0b8027231 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 21 Aug 2011 22:31:24 +0300 Subject: Fix compilation with external guichan library. --- src/gui/equipmentwindow.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h index 082a9b409..c59600dd8 100644 --- a/src/gui/equipmentwindow.h +++ b/src/gui/equipmentwindow.h @@ -32,6 +32,8 @@ #include +#include + #ifdef __GNUC__ #define A_UNUSED __attribute__ ((unused)) #else -- cgit v1.2.3-70-g09d2 From 6dd62fd1082bad225e02312094332630b0debd07 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 21 Aug 2011 23:20:57 +0300 Subject: Show dead hp bar if monster have current damage more than counted maximum value. --- src/being.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/being.cpp b/src/being.cpp index d3181c32a..cc88d8f6e 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -2039,14 +2039,28 @@ void Being::drawHpBar(Graphics *graphics, int maxHP, int hp, int damage, int dx = static_cast(static_cast(width) / p); + if (!damage || (!hp && maxHP == damage)) + { + graphics->setColor(userPalette->getColorWithAlpha(color1)); + + graphics->fillRectangle(gcn::Rectangle( + x, y, dx, height)); + return; + } + else if (width - dx <= 0) + { + graphics->setColor(userPalette->getColorWithAlpha(color2)); + + graphics->fillRectangle(gcn::Rectangle( + x, y, width, height)); + return; + } + graphics->setColor(userPalette->getColorWithAlpha(color1)); graphics->fillRectangle(gcn::Rectangle( x, y, dx, height)); - if (width - dx <= 0) - return; - graphics->setColor(userPalette->getColorWithAlpha(color2)); graphics->fillRectangle(gcn::Rectangle( -- cgit v1.2.3-70-g09d2 From 07c2eb8ffd62fe69f410cc045efc837441a6b6d4 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 22 Aug 2011 00:42:03 +0300 Subject: Replace typo dont to don't. --- src/gui/popupmenu.cpp | 2 +- src/gui/statuswindow.cpp | 4 ++-- src/gui/widgets/button.cpp | 2 +- src/gui/widgets/scrollarea.cpp | 2 +- src/map.cpp | 2 +- src/net/tmwa/beinghandler.cpp | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index eefa83500..61769bc7e 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -574,7 +574,7 @@ void PopupMenu::showChatPopup(int x, int y, ChatTab *tab) if (tab->getRemoveNames()) { mBrowserBox->addRow(strprintf("@@dont remove name|%s@@", - _("Dont remove name"))); + _("Don't remove name"))); } else { diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp index fcc324730..a60707f4c 100644 --- a/src/gui/statuswindow.cpp +++ b/src/gui/statuswindow.cpp @@ -356,7 +356,7 @@ void StatusWindow::event(Mana::Channels channel A_UNUSED, if (!lvl) { - // possible server broken and dont send job level, + // possible server broken and don't send job level, // then we fixing it :) if (exp.second < 20000) { @@ -372,7 +372,7 @@ void StatusWindow::event(Mana::Channels channel A_UNUSED, } if (exp.first < oldExp && exp.second >= 20000) - { // possible job level up. but server broken and dont send + { // possible job level up. but server broken and don't send // new job exp limit, we fixing it lvl ++; blocked = true; diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index 2d9678a53..41fbc1093 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -202,7 +202,7 @@ void Button::draw(gcn::Graphics *graphics) } else { - // because we dont know where parent windows was moved, + // because we don't know where parent windows was moved, // need recalc vertexes gcn::ClipRectangle &rect = static_cast( graphics)->getTopClip(); diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index 08f0b5a70..03f5f8c4c 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -336,7 +336,7 @@ void ScrollArea::drawFrame(gcn::Graphics *graphics) } else { - // because we dont know where parent windows was moved, + // because we don't know where parent windows was moved, // need recalc vertexes gcn::ClipRectangle &rect = static_cast( graphics)->getTopClip(); diff --git a/src/map.cpp b/src/map.cpp index 700f6d0d2..721967b25 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -918,7 +918,7 @@ void Map::draw(Graphics *graphics, int scrollX, int scrollY) } } - // Dont draw if gui opacity == 1 + // Don't draw if gui opacity == 1 if (mBeingOpacity && mOpacity != 1.0f) { // Draws beings with a lower opacity to make them visible diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp index 17503a406..5016b2f8c 100644 --- a/src/net/tmwa/beinghandler.cpp +++ b/src/net/tmwa/beinghandler.cpp @@ -552,7 +552,7 @@ void BeingHandler::processPlayerMoveUpdate(Net::MessageIn &msg, int msgType) dstBeing->setTileCoords(srcX, srcY); dstBeing->setDestination(dstX, dstY); - // because server dont send direction in move packet, + // because server don't send direction in move packet, // we fixing it if (srcX != dstX || srcY != dstY) -- cgit v1.2.3-70-g09d2 From dddfb405de9d04f50d3a95cc3b0ebc3e49884a65 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 22 Aug 2011 03:07:13 +0300 Subject: Add highlight list option. Before in highlight was only player nick. --- src/gui/chatwindow.cpp | 20 +++++++++++++++++++- src/gui/chatwindow.h | 5 +++++ src/gui/setup_chat.cpp | 8 ++++++++ src/gui/widgets/chattab.cpp | 4 +--- src/utils/stringutils.cpp | 17 +++++++++++++++-- src/utils/stringutils.h | 5 ++++- 6 files changed, 52 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index 1ef3139db..8896ca028 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -211,6 +211,7 @@ ChatWindow::ChatWindow(): fillCommands(); initTradeFilter(); loadCustomList(); + parseHighlights(); } ChatWindow::~ChatWindow() @@ -1503,7 +1504,7 @@ void ChatWindow::addToAwayLog(std::string line) if (mAwayLog.size() > 20) mAwayLog.pop_front(); - if (line.find(player_node->getName()) != std::string::npos) + if (findI(line, mHighlights) != std::string::npos) mAwayLog.push_back("##9away:" + line); } @@ -1520,3 +1521,20 @@ void ChatWindow::displayAwayLog() ++i; } } + +void ChatWindow::parseHighlights() +{ + mHighlights.clear(); + if (!player_node) + return; + + splitToStringVector(mHighlights, config.getStringValue( + "highlightWords"), ','); + + mHighlights.push_back(player_node->getName()); +} + +bool ChatWindow::findHighlight(std::string &str) +{ + return findI(str, mHighlights) != std::string::npos; +} \ No newline at end of file diff --git a/src/gui/chatwindow.h b/src/gui/chatwindow.h index b6a37ef79..6e1d548a3 100644 --- a/src/gui/chatwindow.h +++ b/src/gui/chatwindow.h @@ -260,6 +260,10 @@ class ChatWindow : public Window, void clearAwayLog() { mAwayLog.clear(); } + void parseHighlights(); + + bool findHighlight(std::string &str); + protected: friend class ChatTab; friend class WhisperTab; @@ -329,6 +333,7 @@ class ChatWindow : public Window, int mChatColor; unsigned int mChatHistoryIndex; std::list mAwayLog; + std::vector mHighlights; }; extern ChatWindow *chatWindow; diff --git a/src/gui/setup_chat.cpp b/src/gui/setup_chat.cpp index 722a3f8b2..9e75b9c0a 100644 --- a/src/gui/setup_chat.cpp +++ b/src/gui/setup_chat.cpp @@ -120,6 +120,11 @@ Setup_Chat::Setup_Chat() new SetupItemCheckBox(_("Use local time"), "", "useLocalTime", this, "useLocalTimeEvent"); + new SetupItemLabel(_("Other"), "", this); + + new SetupItemTextField(_("Highlight words (separated by comma)"), "", + "highlightWords", this, "highlightWordsEvent"); + setDimension(gcn::Rectangle(0, 0, 550, 350)); } @@ -128,5 +133,8 @@ void Setup_Chat::apply() SetupTabScroll::apply(); if (chatWindow) + { chatWindow->adjustTabSize(); + chatWindow->parseHighlights(); + } } diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index 785bdd6be..81c0d277f 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -283,9 +283,7 @@ void ChatTab::chatLog(std::string line, Own own, { if (player_node) { - std::string::size_type pos - = tmp.text.find(player_node->getName()); - if (pos != std::string::npos) + if (chatWindow && chatWindow->findHighlight(tmp.text)) setFlash(2); else setFlash(1); diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 13170092e..0243c4315 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -181,9 +181,9 @@ unsigned long findI(std::string str, std::string subStr) return str.find(subStr); } -unsigned long findI(std::string str, std::vector &list) +unsigned long findI(std::string &text, std::vector &list) { - str = toLower(str); + std::string str = toLower(text); unsigned long idx; for (std::vector::iterator i = list.begin(); i != list.end(); ++i) @@ -414,6 +414,19 @@ std::list splitToStringList(const std::string &text, return tokens; } +void splitToStringVector(std::vector &tokens, + const std::string &text, char separator) +{ + std::stringstream ss(text); + std::string item; + while(std::getline(ss, item, separator)) + { + item = trim(item); + if (!item.empty()) + tokens.push_back(item); + } +} + std::string combineDye(std::string file, std::string dye) { if (dye.empty()) diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 94747d2fe..4fe6369e9 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -133,7 +133,7 @@ bool isWordSeparator(char chr); unsigned long findI(std::string str, std::string subStr); -unsigned long findI(std::string str, std::vector &list); +unsigned long findI(std::string &text, std::vector &list); const std::string encodeStr(unsigned int value, unsigned int size = 0); @@ -176,6 +176,9 @@ std::list splitToIntList(const std::string &text, char separator); std::list splitToStringList(const std::string &text, char separator); +void splitToStringVector(std::vector &tokens, + const std::string &text, char separator); + std::string combineDye(std::string file, std::string dye); std::string combineDye2(std::string file, std::string dye); -- cgit v1.2.3-70-g09d2 From 8257d7d35e0dd915512df06cafb810f4611be06a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 22 Aug 2011 04:38:03 +0300 Subject: Fix some theme font colors in different gui elements. Add new color ITEM_NOT_EQUIPPED. --- data/graphics/gui/colors.xml | 1 + data/themes/blackwood/colors.xml | 1 + data/themes/enchilado/colors.xml | 3 ++- data/themes/mana/colors.xml | 1 + data/themes/pink/colors.xml | 1 + data/themes/redandblack/colors.xml | 1 + data/themes/wood/colors.xml | 1 + src/gui/equipmentwindow.cpp | 2 +- src/gui/itempopup.cpp | 3 ++- src/gui/spellpopup.cpp | 5 +++-- src/gui/statuspopup.cpp | 29 +++++++++++++++-------------- src/gui/textpopup.cpp | 10 ++++++---- src/gui/theme.cpp | 1 + src/gui/theme.h | 1 + src/gui/widgets/itemcontainer.cpp | 2 +- src/gui/widgets/label.cpp | 1 + src/gui/widgets/radiobutton.cpp | 1 + 17 files changed, 40 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/data/graphics/gui/colors.xml b/data/graphics/gui/colors.xml index df42dcdfd..b17e4b80c 100644 --- a/data/graphics/gui/colors.xml +++ b/data/graphics/gui/colors.xml @@ -16,6 +16,7 @@ + diff --git a/data/themes/blackwood/colors.xml b/data/themes/blackwood/colors.xml index 51eba63fe..b30121a6b 100644 --- a/data/themes/blackwood/colors.xml +++ b/data/themes/blackwood/colors.xml @@ -16,6 +16,7 @@ + diff --git a/data/themes/enchilado/colors.xml b/data/themes/enchilado/colors.xml index e7ab17da2..839f06772 100644 --- a/data/themes/enchilado/colors.xml +++ b/data/themes/enchilado/colors.xml @@ -16,11 +16,12 @@ + - + diff --git a/data/themes/mana/colors.xml b/data/themes/mana/colors.xml index 557ba34d5..9e7b73c69 100644 --- a/data/themes/mana/colors.xml +++ b/data/themes/mana/colors.xml @@ -16,6 +16,7 @@ + diff --git a/data/themes/pink/colors.xml b/data/themes/pink/colors.xml index b49be8015..2e56c6e3c 100644 --- a/data/themes/pink/colors.xml +++ b/data/themes/pink/colors.xml @@ -16,6 +16,7 @@ + diff --git a/data/themes/redandblack/colors.xml b/data/themes/redandblack/colors.xml index 50384ce3a..fc026b361 100644 --- a/data/themes/redandblack/colors.xml +++ b/data/themes/redandblack/colors.xml @@ -16,6 +16,7 @@ + diff --git a/data/themes/wood/colors.xml b/data/themes/wood/colors.xml index 13d942d62..67c2da3c7 100644 --- a/data/themes/wood/colors.xml +++ b/data/themes/wood/colors.xml @@ -16,6 +16,7 @@ + diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 67ec78e49..ddcd6b81c 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -147,7 +147,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) } // Set color black - g->setColor(gcn::Color(0, 0, 0)); + g->setColor(Theme::getThemeColor(Theme::OUTLINE)); // Draw box border g->drawRectangle(gcn::Rectangle(box->first, box->second, BOX_WIDTH, BOX_HEIGHT)); diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index f5117ed5a..4d401a627 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -32,6 +32,7 @@ #include "gui/theme.h" #include "gui/widgets/icon.h" +#include "gui/widgets/label.h" #include "gui/widgets/textbox.h" #include "utils/gettext.h" @@ -54,7 +55,7 @@ ItemPopup::ItemPopup(): mLastColor(1) { // Item Name - mItemName = new gcn::Label; + mItemName = new Label; mItemName->setFont(boldFont); mItemName->setPosition(getPadding(), getPadding()); diff --git a/src/gui/spellpopup.cpp b/src/gui/spellpopup.cpp index 86aeb2206..a918e037d 100644 --- a/src/gui/spellpopup.cpp +++ b/src/gui/spellpopup.cpp @@ -27,6 +27,8 @@ #include "gui/gui.h" #include "gui/palette.h" +#include "gui/widgets/label.h" + #include "textcommand.h" #include "graphics.h" @@ -36,7 +38,6 @@ #include "utils/stringutils.h" #include -#include #include "debug.h" @@ -44,7 +45,7 @@ SpellPopup::SpellPopup(): Popup("SpellPopup") { // Item Name - mItemName = new gcn::Label; + mItemName = new Label; mItemName->setFont(boldFont); mItemName->setPosition(getPadding(), getPadding()); diff --git a/src/gui/statuspopup.cpp b/src/gui/statuspopup.cpp index 08400a916..bb7a295ab 100644 --- a/src/gui/statuspopup.cpp +++ b/src/gui/statuspopup.cpp @@ -28,6 +28,7 @@ #include "gui/palette.h" #include "gui/viewport.h" +#include "gui/widgets/label.h" #include "gui/widgets/layout.h" #include "gui/widgets/textbox.h" @@ -50,51 +51,51 @@ StatusPopup::StatusPopup(): const int fontHeight = getFont()->getHeight(); - mMoveType = new gcn::Label; + mMoveType = new Label; mMoveType->setPosition(getPadding(), getPadding()); - mCrazyMoveType = new gcn::Label; + mCrazyMoveType = new Label; mCrazyMoveType->setPosition(getPadding(), fontHeight + getPadding()); - mMoveToTargetType = new gcn::Label; + mMoveToTargetType = new Label; mMoveToTargetType->setPosition(getPadding(), 2 * fontHeight + getPadding()); - mFollowMode = new gcn::Label; + mFollowMode = new Label; mFollowMode->setPosition(getPadding(), 3 * fontHeight + getPadding()); - mAttackWeaponType = new gcn::Label; + mAttackWeaponType = new Label; mAttackWeaponType->setPosition(getPadding(), 4 + 4 * fontHeight + getPadding()); - mAttackType = new gcn::Label; + mAttackType = new Label; mAttackType->setPosition(getPadding(), 4 + 5 * fontHeight + getPadding()); - mMagicAttackType = new gcn::Label; + mMagicAttackType = new Label; mMagicAttackType->setPosition(getPadding(), 4 + 6 * fontHeight + getPadding()); - mDropCounter = new gcn::Label; + mDropCounter = new Label; mDropCounter->setPosition(getPadding(), 8 + 7 * fontHeight + getPadding()); - mPickUpType = new gcn::Label; + mPickUpType = new Label; mPickUpType->setPosition(getPadding(), 8 + 8 * fontHeight + getPadding()); - mMapType = new gcn::Label; + mMapType = new Label; mMapType->setPosition(getPadding(), 12 + 9 * fontHeight + getPadding()); - mImitationMode = new gcn::Label; + mImitationMode = new Label; mImitationMode->setPosition(getPadding(), 16 + 10 * fontHeight + getPadding()); - mAwayMode = new gcn::Label; + mAwayMode = new Label; mAwayMode->setPosition(getPadding(), 16 + 11 * fontHeight + getPadding()); - mCameraMode = new gcn::Label; + mCameraMode = new Label; mCameraMode->setPosition(getPadding(), 16 + 12 * fontHeight + getPadding()); - mDisableGameModifiers = new gcn::Label; + mDisableGameModifiers = new Label; mDisableGameModifiers->setPosition(getPadding(), 20 + 13 * fontHeight + getPadding()); diff --git a/src/gui/textpopup.cpp b/src/gui/textpopup.cpp index 7f1e0e6b8..1ff601154 100644 --- a/src/gui/textpopup.cpp +++ b/src/gui/textpopup.cpp @@ -26,6 +26,9 @@ #include "gui/gui.h" #include "gui/palette.h" +#include "gui/theme.h" + +#include "gui/widgets/label.h" #include "graphics.h" #include "units.h" @@ -34,7 +37,6 @@ #include "utils/stringutils.h" #include -#include #include "debug.h" @@ -43,13 +45,13 @@ TextPopup::TextPopup(): { const int fontHeight = getFont()->getHeight(); - mText1 = new gcn::Label; + mText1 = new Label; mText1->setPosition(getPadding(), getPadding()); - mText2 = new gcn::Label; + mText2 = new Label; mText2->setPosition(getPadding(), fontHeight + 2 * getPadding()); - mText3 = new gcn::Label; + mText3 = new Label; mText3->setPosition(getPadding(), (2 * fontHeight) + 2 * getPadding()); add(mText1); diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index 056eafc0f..e126c0505 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -613,6 +613,7 @@ static int readColorType(const std::string &type) "TAB_PLAYER_FLASH", "SHOP_WARNING", "ITEM_EQUIPPED", + "ITEM_NOT_EQUIPPED", "CHAT", "GM", "PLAYER", diff --git a/src/gui/theme.h b/src/gui/theme.h index 120214232..5fe938a20 100644 --- a/src/gui/theme.h +++ b/src/gui/theme.h @@ -157,6 +157,7 @@ class Theme : public Palette, public ConfigListener TAB_PLAYER_FLASH, SHOP_WARNING, ITEM_EQUIPPED, + ITEM_NOT_EQUIPPED, CHAT, GM, PLAYER, diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index b79f26226..c2a5ec1b7 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -206,7 +206,7 @@ void ItemContainer::draw(gcn::Graphics *graphics) if (item->isEquipped()) g->setColor(Theme::getThemeColor(Theme::ITEM_EQUIPPED)); else - g->setColor(gcn::Color(0, 0, 0)); + g->setColor(Theme::getThemeColor(Theme::ITEM_NOT_EQUIPPED)); g->drawText(caption, itemX + BOX_WIDTH / 2, itemY + BOX_HEIGHT - 14, gcn::Graphics::CENTER); diff --git a/src/gui/widgets/label.cpp b/src/gui/widgets/label.cpp index 16b813dd5..67e8bd12b 100644 --- a/src/gui/widgets/label.cpp +++ b/src/gui/widgets/label.cpp @@ -26,6 +26,7 @@ Label::Label() { + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); } Label::Label(const std::string &caption) : diff --git a/src/gui/widgets/radiobutton.cpp b/src/gui/widgets/radiobutton.cpp index a82ec3e8d..e641be323 100644 --- a/src/gui/widgets/radiobutton.cpp +++ b/src/gui/widgets/radiobutton.cpp @@ -46,6 +46,7 @@ RadioButton::RadioButton(const std::string &caption, const std::string &group, gcn::RadioButton(caption, group, marked), mHasMouse(false) { + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); if (instances == 0) { radioNormal = Theme::getImageFromTheme("radioout.png"); -- cgit v1.2.3-70-g09d2 From 7bedfccf5982534a9cbcb2c18ca0d37df117bfc8 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 22 Aug 2011 16:28:01 +0300 Subject: Add new colors to themes: BORDER, BACKGROUND_GRAY, SCROLLBAR_GRAY. --- data/graphics/gui/colors.xml | 3 +++ data/themes/blackwood/colors.xml | 3 +++ data/themes/enchilado/colors.xml | 3 +++ data/themes/mana/colors.xml | 3 +++ data/themes/pink/colors.xml | 3 +++ data/themes/redandblack/colors.xml | 3 +++ data/themes/wood/colors.xml | 3 +++ src/gui/botcheckerwindow.cpp | 1 - src/gui/equipmentwindow.cpp | 2 +- src/gui/outfitwindow.cpp | 5 +++-- src/gui/statuswindow.cpp | 2 -- src/gui/theme.cpp | 3 +++ src/gui/theme.h | 3 +++ src/gui/widgets/desktop.cpp | 7 ++++--- src/gui/widgets/itemcontainer.cpp | 2 ++ src/gui/widgets/scrollarea.cpp | 8 ++++---- src/gui/widgets/spellshortcutcontainer.cpp | 1 - 17 files changed, 41 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/data/graphics/gui/colors.xml b/data/graphics/gui/colors.xml index b17e4b80c..017b55400 100644 --- a/data/graphics/gui/colors.xml +++ b/data/graphics/gui/colors.xml @@ -2,6 +2,7 @@ + @@ -11,6 +12,8 @@ + + diff --git a/data/themes/blackwood/colors.xml b/data/themes/blackwood/colors.xml index b30121a6b..b85ccdfc7 100644 --- a/data/themes/blackwood/colors.xml +++ b/data/themes/blackwood/colors.xml @@ -2,6 +2,7 @@ + @@ -11,6 +12,8 @@ + + diff --git a/data/themes/enchilado/colors.xml b/data/themes/enchilado/colors.xml index 839f06772..38167192d 100644 --- a/data/themes/enchilado/colors.xml +++ b/data/themes/enchilado/colors.xml @@ -2,6 +2,7 @@ + @@ -11,6 +12,8 @@ + + diff --git a/data/themes/mana/colors.xml b/data/themes/mana/colors.xml index 9e7b73c69..96a929a5e 100644 --- a/data/themes/mana/colors.xml +++ b/data/themes/mana/colors.xml @@ -2,6 +2,7 @@ + @@ -11,6 +12,8 @@ + + diff --git a/data/themes/pink/colors.xml b/data/themes/pink/colors.xml index 2e56c6e3c..44aac3527 100644 --- a/data/themes/pink/colors.xml +++ b/data/themes/pink/colors.xml @@ -2,6 +2,7 @@ + @@ -11,6 +12,8 @@ + + diff --git a/data/themes/redandblack/colors.xml b/data/themes/redandblack/colors.xml index fc026b361..b705241fb 100644 --- a/data/themes/redandblack/colors.xml +++ b/data/themes/redandblack/colors.xml @@ -2,6 +2,7 @@ + @@ -11,6 +12,8 @@ + + diff --git a/data/themes/wood/colors.xml b/data/themes/wood/colors.xml index 67c2da3c7..1080f2022 100644 --- a/data/themes/wood/colors.xml +++ b/data/themes/wood/colors.xml @@ -2,6 +2,7 @@ + @@ -11,6 +12,8 @@ + + diff --git a/src/gui/botcheckerwindow.cpp b/src/gui/botcheckerwindow.cpp index 2851d3d1d..4a8f8cf0d 100644 --- a/src/gui/botcheckerwindow.cpp +++ b/src/gui/botcheckerwindow.cpp @@ -290,7 +290,6 @@ BotCheckerWindow::BotCheckerWindow(): } mPlayerTitleTable = new GuiTable(mPlayerTableTitleModel); - //mPlayerTitleTable->setBackgroundColor(gcn::Color(0xbf, 0xbf, 0xbf)); mPlayerTitleTable->setHeight(1); mPlayerTableTitleModel->set(0, 0, new Label(_("Name"))); diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index ddcd6b81c..3284301ec 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -147,7 +147,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) } // Set color black - g->setColor(Theme::getThemeColor(Theme::OUTLINE)); + g->setColor(Theme::getThemeColor(Theme::BORDER)); // Draw box border g->drawRectangle(gcn::Rectangle(box->first, box->second, BOX_WIDTH, BOX_HEIGHT)); diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp index 09e75856f..79ac88d94 100644 --- a/src/gui/outfitwindow.cpp +++ b/src/gui/outfitwindow.cpp @@ -32,6 +32,7 @@ #include "playerinfo.h" #include "gui/chatwindow.h" +#include "gui/theme.h" #include "gui/viewport.h" #include "gui/widgets/button.h" @@ -303,9 +304,9 @@ void OutfitWindow::draw(gcn::Graphics *graphics) const int itemX = 10 + ((i % mGridWidth) * mBoxWidth); const int itemY = 25 + ((i / mGridWidth) * mBoxHeight); - graphics->setColor(gcn::Color(0, 0, 0, 64)); + graphics->setColor(Theme::getThemeColor(Theme::BORDER, 64)); graphics->drawRectangle(gcn::Rectangle(itemX, itemY, 32, 32)); - graphics->setColor(gcn::Color(255, 255, 255, 32)); + graphics->setColor(Theme::getThemeColor(Theme::BACKGROUND, 32)); graphics->fillRectangle(gcn::Rectangle(itemX, itemY, 32, 32)); if (mItems[mCurrentOutfit][i] < 0) diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp index a60707f4c..7ab2afa2d 100644 --- a/src/gui/statuswindow.cpp +++ b/src/gui/statuswindow.cpp @@ -889,7 +889,6 @@ void StatusWindow::updateStatusBar(ProgressBar *bar, bool percent A_UNUSED) col.r = 100; col.g = 100; col.b = 100; -// bar->setColor(new gcn::Color(100, 100, 100)); bar->setColor(col); } else @@ -898,7 +897,6 @@ void StatusWindow::updateStatusBar(ProgressBar *bar, bool percent A_UNUSED) col.r = 255; col.g = 255; col.b = 0; -// bar->setColor(new gcn::Color(255, 255, 0)); bar->setColor(col); } } diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index e126c0505..5fcfeade2 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -599,6 +599,7 @@ static int readColorType(const std::string &type) "TEXT", "SHADOW", "OUTLINE", + "BORDER", "PROGRESS_BAR", "BUTTON", "BUTTON_DISABLED", @@ -608,6 +609,8 @@ static int readColorType(const std::string &type) "GUILD_CHAT_TAB", "GUILD_SOCIAL_TAB", "BACKGROUND", + "BACKGROUND_GRAY", + "SCROLLBAR_GRAY", "HIGHLIGHT", "TAB_FLASH", "TAB_PLAYER_FLASH", diff --git a/src/gui/theme.h b/src/gui/theme.h index 5fe938a20..bdcdafc74 100644 --- a/src/gui/theme.h +++ b/src/gui/theme.h @@ -143,6 +143,7 @@ class Theme : public Palette, public ConfigListener TEXT = 0, SHADOW, OUTLINE, + BORDER, PROGRESS_BAR, BUTTON, BUTTON_DISABLED, @@ -152,6 +153,8 @@ class Theme : public Palette, public ConfigListener GUILD_CHAT_TAB, GUILD_SOCIAL_TAB, BACKGROUND, + BACKGROUND_GRAY, + SCROLLBAR_GRAY, HIGHLIGHT, TAB_FLASH, TAB_PLAYER_FLASH, diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp index cfb757638..40d90ba11 100644 --- a/src/gui/widgets/desktop.cpp +++ b/src/gui/widgets/desktop.cpp @@ -53,7 +53,8 @@ Desktop::Desktop() : mVersionLabel = new Label(strprintf("%s (Mana %s)", appName.c_str(), FULL_VERSION)); - mVersionLabel->setBackgroundColor(gcn::Color(255, 255, 255, 128)); + mVersionLabel->setBackgroundColor( + Theme::getThemeColor(Theme::BACKGROUND, 128)); add(mVersionLabel, 25, 2); } @@ -85,7 +86,7 @@ void Desktop::draw(gcn::Graphics *graphics) getHeight() > mWallpaper->getHeight())) { // TODO: Color from palette - g->setColor(gcn::Color(64, 64, 64)); + g->setColor(Theme::getThemeColor(Theme::BACKGROUND_GRAY)); g->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); } @@ -106,7 +107,7 @@ void Desktop::draw(gcn::Graphics *graphics) } // Draw a thin border under the application version... - g->setColor(gcn::Color(255, 255, 255, 128)); + g->setColor(Theme::getThemeColor(Theme::BACKGROUND, 128)); g->fillRectangle(gcn::Rectangle(mVersionLabel->getDimension())); Container::draw(graphics); diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index c2a5ec1b7..c28e4fb4c 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -213,6 +213,7 @@ void ItemContainer::draw(gcn::Graphics *graphics) } } +/* // Draw an orange box around the selected item if (isFocused() && mHighlightedIndex != -1 && mGridColumns) { @@ -221,6 +222,7 @@ void ItemContainer::draw(gcn::Graphics *graphics) g->setColor(gcn::Color(255, 128, 0)); g->drawRectangle(gcn::Rectangle(itemX, itemY, BOX_WIDTH, BOX_HEIGHT)); } +*/ } void ItemContainer::selectNone() diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index 03f5f8c4c..3e90bf4c7 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -439,17 +439,17 @@ void ScrollArea::drawRightButton(gcn::Graphics *graphics) void ScrollArea::drawVBar(gcn::Graphics *graphics) { const gcn::Rectangle dim = getVerticalBarDimension(); - graphics->setColor(gcn::Color(0, 0, 0, 32)); + graphics->setColor(Theme::getThemeColor(Theme::SCROLLBAR_GRAY, 32)); graphics->fillRectangle(dim); - graphics->setColor(gcn::Color(255, 255, 255)); + graphics->setColor(Theme::getThemeColor(Theme::BACKGROUND)); } void ScrollArea::drawHBar(gcn::Graphics *graphics) { const gcn::Rectangle dim = getHorizontalBarDimension(); - graphics->setColor(gcn::Color(0, 0, 0, 32)); + graphics->setColor(Theme::getThemeColor(Theme::SCROLLBAR_GRAY, 32)); graphics->fillRectangle(dim); - graphics->setColor(gcn::Color(255, 255, 255)); + graphics->setColor(Theme::getThemeColor(Theme::BACKGROUND)); } void ScrollArea::drawVMarker(gcn::Graphics *graphics) diff --git a/src/gui/widgets/spellshortcutcontainer.cpp b/src/gui/widgets/spellshortcutcontainer.cpp index 8d5b563bb..7e19b0348 100644 --- a/src/gui/widgets/spellshortcutcontainer.cpp +++ b/src/gui/widgets/spellshortcutcontainer.cpp @@ -106,7 +106,6 @@ void SpellShortcutContainer::draw(gcn::Graphics *graphics) Graphics *g = static_cast(graphics); - graphics->setColor(gcn::Color(0, 0, 0, 255)); graphics->setFont(getFont()); int selectedId = spellShortcut->getSelectedItem(); -- cgit v1.2.3-70-g09d2 From 2d17967845119a77aec6388bb27c47339052704a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 22 Aug 2011 21:16:34 +0300 Subject: Improve draw perfomance. Add new theme color DROPDOWN_SHADOW. --- data/graphics/gui/colors.xml | 1 + data/themes/blackwood/colors.xml | 1 + data/themes/enchilado/colors.xml | 1 + data/themes/mana/colors.xml | 1 + data/themes/pink/colors.xml | 1 + data/themes/redandblack/colors.xml | 1 + data/themes/wood/colors.xml | 1 + src/gui/equipmentwindow.cpp | 12 +++++---- src/gui/equipmentwindow.h | 2 ++ src/gui/outfitwindow.cpp | 7 ++++-- src/gui/outfitwindow.h | 2 ++ src/gui/serverdialog.cpp | 24 +++++++++++------- src/gui/skilldialog.cpp | 12 ++++++--- src/gui/theme.cpp | 1 + src/gui/theme.h | 1 + src/gui/widgets/avatarlistbox.cpp | 13 ++++++---- src/gui/widgets/avatarlistbox.h | 1 + src/gui/widgets/browserbox.cpp | 10 +++++--- src/gui/widgets/browserbox.h | 4 +++ src/gui/widgets/button.cpp | 7 ++++-- src/gui/widgets/button.h | 2 ++ src/gui/widgets/checkbox.cpp | 4 ++- src/gui/widgets/desktop.cpp | 8 +++--- src/gui/widgets/desktop.h | 2 ++ src/gui/widgets/dropdown.cpp | 22 ++++++++-------- src/gui/widgets/dropdown.h | 3 +++ src/gui/widgets/dropshortcutcontainer.cpp | 14 ++++------- src/gui/widgets/dropshortcutcontainer.h | 2 ++ src/gui/widgets/emoteshortcutcontainer.cpp | 14 ++--------- src/gui/widgets/guitable.cpp | 16 ++++++------ src/gui/widgets/guitable.h | 3 ++- src/gui/widgets/itemcontainer.cpp | 7 ++++-- src/gui/widgets/itemcontainer.h | 2 ++ src/gui/widgets/itemshortcutcontainer.cpp | 14 +++++------ src/gui/widgets/itemshortcutcontainer.h | 3 ++- src/gui/widgets/listbox.cpp | 8 +++--- src/gui/widgets/listbox.h | 1 + src/gui/widgets/scrollarea.cpp | 12 +++++---- src/gui/widgets/scrollarea.h | 3 +++ src/gui/widgets/shoplistbox.cpp | 40 +++++++++++++++++------------- src/gui/widgets/shoplistbox.h | 6 +++++ src/gui/widgets/spellshortcutcontainer.cpp | 3 ++- src/gui/widgets/tab.cpp | 8 +++--- src/gui/widgets/tab.h | 2 ++ src/gui/widgets/textfield.cpp | 4 ++- src/gui/widgets/window.cpp | 8 ++---- 46 files changed, 190 insertions(+), 124 deletions(-) (limited to 'src') diff --git a/data/graphics/gui/colors.xml b/data/graphics/gui/colors.xml index 017b55400..2091494b3 100644 --- a/data/graphics/gui/colors.xml +++ b/data/graphics/gui/colors.xml @@ -14,6 +14,7 @@ + diff --git a/data/themes/blackwood/colors.xml b/data/themes/blackwood/colors.xml index b85ccdfc7..ef06fdc9f 100644 --- a/data/themes/blackwood/colors.xml +++ b/data/themes/blackwood/colors.xml @@ -14,6 +14,7 @@ + diff --git a/data/themes/enchilado/colors.xml b/data/themes/enchilado/colors.xml index 38167192d..f4ae878e4 100644 --- a/data/themes/enchilado/colors.xml +++ b/data/themes/enchilado/colors.xml @@ -14,6 +14,7 @@ + diff --git a/data/themes/mana/colors.xml b/data/themes/mana/colors.xml index 96a929a5e..c623b8396 100644 --- a/data/themes/mana/colors.xml +++ b/data/themes/mana/colors.xml @@ -14,6 +14,7 @@ + diff --git a/data/themes/pink/colors.xml b/data/themes/pink/colors.xml index 44aac3527..6be3ab630 100644 --- a/data/themes/pink/colors.xml +++ b/data/themes/pink/colors.xml @@ -14,6 +14,7 @@ + diff --git a/data/themes/redandblack/colors.xml b/data/themes/redandblack/colors.xml index b705241fb..8fe785114 100644 --- a/data/themes/redandblack/colors.xml +++ b/data/themes/redandblack/colors.xml @@ -14,6 +14,7 @@ + diff --git a/data/themes/wood/colors.xml b/data/themes/wood/colors.xml index 1080f2022..1f1ac1776 100644 --- a/data/themes/wood/colors.xml +++ b/data/themes/wood/colors.xml @@ -14,6 +14,7 @@ + diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 3284301ec..3abd97c73 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -99,6 +99,9 @@ EquipmentWindow::EquipmentWindow(Equipment *equipment, Being *being, add(mPlayerBox); add(mUnequip); + mHighlightColor = Theme::getThemeColor(Theme::HIGHLIGHT); + mBorderColor = Theme::getThemeColor(Theme::BORDER); + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); } EquipmentWindow::~EquipmentWindow() @@ -138,16 +141,15 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) continue; if (i == mSelected) { - const gcn::Color color = Theme::getThemeColor(Theme::HIGHLIGHT); - + mHighlightColor.a = getGuiAlpha(); // Set color to the highlight color - g->setColor(gcn::Color(color.r, color.g, color.b, getGuiAlpha())); + g->setColor(mHighlightColor); g->fillRectangle(gcn::Rectangle(box->first, box->second, BOX_WIDTH, BOX_HEIGHT)); } // Set color black - g->setColor(Theme::getThemeColor(Theme::BORDER)); + g->setColor(mBorderColor); // Draw box border g->drawRectangle(gcn::Rectangle(box->first, box->second, BOX_WIDTH, BOX_HEIGHT)); @@ -167,7 +169,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) g->drawImage(image, box->first + 2, box->second + 2); if (i == EQUIP_PROJECTILE_SLOT) { - g->setColor(Theme::getThemeColor(Theme::TEXT)); + g->setColor(getForegroundColor()); graphics->drawText(toString(item->getQuantity()), box->first + (BOX_WIDTH / 2), box->second - fontHeight, diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h index c59600dd8..cadf27620 100644 --- a/src/gui/equipmentwindow.h +++ b/src/gui/equipmentwindow.h @@ -116,6 +116,8 @@ class EquipmentWindow : public Window, public gcn::ActionListener bool mForing; Being *mBeing; std::vector*> mBoxes; + gcn::Color mHighlightColor; + gcn::Color mBorderColor; }; extern EquipmentWindow *equipmentWindow; diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp index 79ac88d94..d3bc6a302 100644 --- a/src/gui/outfitwindow.cpp +++ b/src/gui/outfitwindow.cpp @@ -78,6 +78,9 @@ OutfitWindow::OutfitWindow(): addMouseListener(this); + mBorderColor = Theme::getThemeColor(Theme::BORDER, 64); + mBackgroundColor = Theme::getThemeColor(Theme::BACKGROUND, 32); + mPreviousButton = new Button(_("<"), "previous", this); mNextButton = new Button(_(">"), "next", this); mCurrentLabel = new Label(strprintf(_("Outfit: %d"), 1)); @@ -304,9 +307,9 @@ void OutfitWindow::draw(gcn::Graphics *graphics) const int itemX = 10 + ((i % mGridWidth) * mBoxWidth); const int itemY = 25 + ((i / mGridWidth) * mBoxHeight); - graphics->setColor(Theme::getThemeColor(Theme::BORDER, 64)); + graphics->setColor(mBorderColor); graphics->drawRectangle(gcn::Rectangle(itemX, itemY, 32, 32)); - graphics->setColor(Theme::getThemeColor(Theme::BACKGROUND, 32)); + graphics->setColor(mBackgroundColor); graphics->fillRectangle(gcn::Rectangle(itemX, itemY, 32, 32)); if (mItems[mCurrentOutfit][i] < 0) diff --git a/src/gui/outfitwindow.h b/src/gui/outfitwindow.h index 60634dbdd..8dd5fd6a3 100644 --- a/src/gui/outfitwindow.h +++ b/src/gui/outfitwindow.h @@ -137,6 +137,8 @@ class OutfitWindow : public Window, gcn::ActionListener int mAwayOutfit; Image *mBackgroundImg; + gcn::Color mBorderColor; + gcn::Color mBackgroundColor; static float mAlpha; }; diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index 143d3e5a3..763c190d6 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -158,6 +158,10 @@ public: ServersListBox(ServersListModel *model): ListBox(model) { + mHighlightColor = Theme::getThemeColor(Theme::HIGHLIGHT); + mTextColor = Theme::getThemeColor(Theme::TEXT); + mNotSupportedColor = Theme::getThemeColor( + Theme::SERVER_VERSION_NOT_SUPPORTED); } void draw(gcn::Graphics *graphics) @@ -169,20 +173,18 @@ public: updateAlpha(); - graphics->setColor(Theme::getThemeColor(Theme::HIGHLIGHT, - static_cast(mAlpha * 255.0f))); + mHighlightColor.a = static_cast(mAlpha * 255.0f); + graphics->setColor(mHighlightColor); graphics->setFont(getFont()); const int height = getRowHeight(); - const gcn::Color unsupported = - Theme::getThemeColor(Theme::SERVER_VERSION_NOT_SUPPORTED, - static_cast(mAlpha * 255.0f)); + mNotSupportedColor.a = static_cast(mAlpha * 255.0f); // Draw filled rectangle around the selected list element if (mSelected >= 0) { - graphics->fillRectangle(gcn::Rectangle(0, height * mSelected, - getWidth(), height)); + graphics->fillRectangle(gcn::Rectangle(0, + height * mSelected, getWidth(), height)); } // Draw the list elements @@ -191,7 +193,7 @@ public: { ServerInfo info = model->getServer(i); - graphics->setColor(Theme::getThemeColor(Theme::TEXT)); + graphics->setColor(mTextColor); int top; @@ -212,7 +214,7 @@ public: if (info.version.first > 0) { - graphics->setColor(unsupported); + graphics->setColor(mNotSupportedColor); graphics->drawText(info.version.second, getWidth() - info.version.first - 2, top); @@ -224,6 +226,10 @@ public: { return 2 * getFont()->getHeight(); } +private: + gcn::Color mHighlightColor; + gcn::Color mTextColor; + gcn::Color mNotSupportedColor; }; diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index 896f06cab..ff57195a9 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -152,7 +152,9 @@ public: SkillListBox(SkillModel *model): ListBox(model), mModel(model), - mPopup(new TextPopup()) + mPopup(new TextPopup()), + mHighlightColor(Theme::getThemeColor(Theme::HIGHLIGHT)), + mTextColor(Theme::getThemeColor(Theme::TEXT)) { } @@ -187,8 +189,8 @@ public: Graphics *graphics = static_cast(gcnGraphics); - graphics->setColor(Theme::getThemeColor(Theme::HIGHLIGHT, - static_cast(mAlpha * 255.0f))); + mHighlightColor.a = static_cast(mAlpha * 255.0f); + graphics->setColor(mHighlightColor); graphics->setFont(getFont()); // Draw filled rectangle around the selected list element @@ -199,7 +201,7 @@ public: } // Draw the list elements - graphics->setColor(Theme::getThemeColor(Theme::TEXT)); + graphics->setColor(mTextColor); for (int i = 0, y = 1; i < model->getNumberOfElements(); ++i, y += getRowHeight()) @@ -239,6 +241,8 @@ public: private: SkillModel *mModel; TextPopup *mPopup; + gcn::Color mHighlightColor; + gcn::Color mTextColor; }; class SkillTab : public Tab diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index 5fcfeade2..15554044d 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -611,6 +611,7 @@ static int readColorType(const std::string &type) "BACKGROUND", "BACKGROUND_GRAY", "SCROLLBAR_GRAY", + "DROPDOWN_SHADOW", "HIGHLIGHT", "TAB_FLASH", "TAB_PLAYER_FLASH", diff --git a/src/gui/theme.h b/src/gui/theme.h index bdcdafc74..4e6a64a6f 100644 --- a/src/gui/theme.h +++ b/src/gui/theme.h @@ -155,6 +155,7 @@ class Theme : public Palette, public ConfigListener BACKGROUND, BACKGROUND_GRAY, SCROLLBAR_GRAY, + DROPDOWN_SHADOW, HIGHLIGHT, TAB_FLASH, TAB_PLAYER_FLASH, diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp index 0d35ad188..d4764cba5 100644 --- a/src/gui/widgets/avatarlistbox.cpp +++ b/src/gui/widgets/avatarlistbox.cpp @@ -66,6 +66,9 @@ AvatarListBox::AvatarListBox(AvatarListModel *model): config.addListener("showgender", this); config.addListener("showlevel", this); + + mHighlightColor = Theme::getThemeColor(Theme::HIGHLIGHT); + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); } AvatarListBox::~AvatarListBox() @@ -102,8 +105,8 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics) Graphics *graphics = static_cast(gcnGraphics); - graphics->setColor(Theme::getThemeColor(Theme::HIGHLIGHT, - static_cast(mAlpha * 255.0f))); + mHighlightColor.a = static_cast(mAlpha * 255.0f); + graphics->setColor(mHighlightColor); graphics->setFont(getFont()); const int fontHeight = getFont()->getHeight(); @@ -113,7 +116,7 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics) const std::string name = player_node->getName(); // Draw the list elements - graphics->setColor(Theme::getThemeColor(Theme::TEXT)); + graphics->setColor(getForegroundColor()); for (int i = 0, y = 0; i < model->getNumberOfElements(); ++i, y += fontHeight) @@ -206,7 +209,7 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics) if (a->getLevel() > 1) { - graphics->setColor(Theme::getThemeColor(Theme::TEXT)); + graphics->setColor(getForegroundColor()); int minHp = 40 + ((a->getLevel() - 1) * 5); if (minHp < 0) minHp = 40; @@ -283,7 +286,7 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics) } } - graphics->setColor(Theme::getThemeColor(Theme::TEXT)); + graphics->setColor(getForegroundColor()); // Draw Name if (a->getType() == MapItem::SEPARATOR) diff --git a/src/gui/widgets/avatarlistbox.h b/src/gui/widgets/avatarlistbox.h index 2fe1dfe3d..afb4abdf5 100644 --- a/src/gui/widgets/avatarlistbox.h +++ b/src/gui/widgets/avatarlistbox.h @@ -62,6 +62,7 @@ public: private: bool mShowGender; bool mShowLevel; + gcn::Color mHighlightColor; static int instances; static Image *onlineIcon; diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index 7df70bd04..bb83c1159 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -64,6 +64,10 @@ BrowserBox::BrowserBox(unsigned int mode, bool opaque): { setFocusable(true); addMouseListener(this); + + mBackgroundColor = Theme::getThemeColor(Theme::BACKGROUND); + mHighlightColor = Theme::getThemeColor(Theme::HIGHLIGHT); + mHyperLinkColor = Theme::getThemeColor(Theme::HYPERLINK); } BrowserBox::~BrowserBox() @@ -310,7 +314,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) if (mOpaque) { - graphics->setColor(Theme::getThemeColor(Theme::BACKGROUND)); + graphics->setColor(mBackgroundColor); graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); } @@ -319,7 +323,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) { if ((mHighMode & BACKGROUND)) { - graphics->setColor(Theme::getThemeColor(Theme::HIGHLIGHT)); + graphics->setColor(mHighlightColor); graphics->fillRectangle(gcn::Rectangle( mLinks[mSelectedLink].x1, mLinks[mSelectedLink].y1, @@ -330,7 +334,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) if ((mHighMode & UNDERLINE)) { - graphics->setColor(Theme::getThemeColor(Theme::HYPERLINK)); + graphics->setColor(mHyperLinkColor); graphics->drawLine( mLinks[mSelectedLink].x1, mLinks[mSelectedLink].y2, diff --git a/src/gui/widgets/browserbox.h b/src/gui/widgets/browserbox.h index 6fdb40042..9969bfd3b 100644 --- a/src/gui/widgets/browserbox.h +++ b/src/gui/widgets/browserbox.h @@ -225,6 +225,10 @@ class BrowserBox : public gcn::Widget, bool mAlwaysUpdate; bool mProcessVersion; bool mEnableImages; + + gcn::Color mBackgroundColor; + gcn::Color mHighlightColor; + gcn::Color mHyperLinkColor; }; #endif diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index 41fbc1093..7c46ae9df 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -135,6 +135,9 @@ void Button::init() } updateAlpha(); } + mEnabledColor = Theme::getThemeColor(Theme::BUTTON); + mDisabledColor = Theme::getThemeColor(Theme::BUTTON_DISABLED); + mInstances++; } @@ -238,9 +241,9 @@ void Button::draw(gcn::Graphics *graphics) // drawImageRect(0, 0, getWidth(), getHeight(), button[mode]); if (mode == BUTTON_DISABLED) - graphics->setColor(Theme::getThemeColor(Theme::BUTTON_DISABLED)); + graphics->setColor(mDisabledColor); else - graphics->setColor(Theme::getThemeColor(Theme::BUTTON)); + graphics->setColor(mEnabledColor); int textX; int textY = getHeight() / 2 - getFont()->getHeight() / 2; diff --git a/src/gui/widgets/button.h b/src/gui/widgets/button.h index 8c43b6ddd..1b62179b3 100644 --- a/src/gui/widgets/button.h +++ b/src/gui/widgets/button.h @@ -101,6 +101,8 @@ class Button : public gcn::Button, public gcn::WidgetListener int mMode; int mXOffset; int mYOffset; + gcn::Color mEnabledColor; + gcn::Color mDisabledColor; }; #endif diff --git a/src/gui/widgets/checkbox.cpp b/src/gui/widgets/checkbox.cpp index 61e5d9118..65d26e196 100644 --- a/src/gui/widgets/checkbox.cpp +++ b/src/gui/widgets/checkbox.cpp @@ -86,6 +86,8 @@ CheckBox::CheckBox(const std::string &caption, bool selected, if (listener) addActionListener(listener); + + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); } CheckBox::~CheckBox() @@ -114,7 +116,7 @@ void CheckBox::draw(gcn::Graphics* graphics) drawBox(graphics); graphics->setFont(getFont()); - graphics->setColor(Theme::getThemeColor(Theme::TEXT)); + graphics->setColor(getForegroundColor()); const int h = getHeight() + getHeight() / 2; diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp index 40d90ba11..46240f76d 100644 --- a/src/gui/widgets/desktop.cpp +++ b/src/gui/widgets/desktop.cpp @@ -56,6 +56,9 @@ Desktop::Desktop() : mVersionLabel->setBackgroundColor( Theme::getThemeColor(Theme::BACKGROUND, 128)); add(mVersionLabel, 25, 2); + + mBackgroundColor = Theme::getThemeColor(Theme::BACKGROUND, 128); + mBackgroundGrayColor = Theme::getThemeColor(Theme::BACKGROUND_GRAY); } Desktop::~Desktop() @@ -85,8 +88,7 @@ void Desktop::draw(gcn::Graphics *graphics) if (!mWallpaper || (getWidth() > mWallpaper->getWidth() || getHeight() > mWallpaper->getHeight())) { - // TODO: Color from palette - g->setColor(Theme::getThemeColor(Theme::BACKGROUND_GRAY)); + g->setColor(mBackgroundGrayColor); g->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); } @@ -107,7 +109,7 @@ void Desktop::draw(gcn::Graphics *graphics) } // Draw a thin border under the application version... - g->setColor(Theme::getThemeColor(Theme::BACKGROUND, 128)); + g->setColor(mBackgroundColor); g->fillRectangle(gcn::Rectangle(mVersionLabel->getDimension())); Container::draw(graphics); diff --git a/src/gui/widgets/desktop.h b/src/gui/widgets/desktop.h index 962cc3c01..6364ecfe9 100644 --- a/src/gui/widgets/desktop.h +++ b/src/gui/widgets/desktop.h @@ -68,6 +68,8 @@ class Desktop : public Container, gcn::WidgetListener Image *mWallpaper; gcn::Label *mVersionLabel; + gcn::Color mBackgroundColor; + gcn::Color mBackgroundGrayColor; }; #endif // DESKTOP_H diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 681d7736e..f01d3fb55 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -101,6 +101,10 @@ DropDown::DropDown(gcn::ListModel *listModel): } instances++; + + mHighlightColor = Theme::getThemeColor(Theme::HIGHLIGHT); + mShadowColor = Theme::getThemeColor(Theme::DROPDOWN_SHADOW); + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); } DropDown::~DropDown() @@ -163,25 +167,20 @@ void DropDown::draw(gcn::Graphics* graphics) updateAlpha(); const int alpha = static_cast(mAlpha * 255.0f); - gcn::Color faceColor = getBaseColor(); - faceColor.a = alpha; - const gcn::Color *highlightColor = &Theme::getThemeColor(Theme::HIGHLIGHT, - alpha); - gcn::Color shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + mHighlightColor.a = alpha; + mShadowColor.a = alpha; if (mListBox->getListModel() && mListBox->getSelected() >= 0) { graphics->setFont(getFont()); - graphics->setColor(Theme::getThemeColor(Theme::TEXT)); + graphics->setColor(getForegroundColor()); graphics->drawText(mListBox->getListModel()->getElementAt( mListBox->getSelected()), 1, 0); } if (isFocused()) { - if (highlightColor) - graphics->setColor(*highlightColor); + graphics->setColor(mHighlightColor); graphics->drawRectangle(gcn::Rectangle(0, 0, getWidth() - h, h)); } @@ -193,10 +192,9 @@ void DropDown::draw(gcn::Graphics* graphics) // Draw two lines separating the ListBox with selected // element view. - if (highlightColor) - graphics->setColor(*highlightColor); + graphics->setColor(mHighlightColor); graphics->drawLine(0, h, getWidth(), h); - graphics->setColor(shadowColor); + graphics->setColor(mShadowColor); graphics->drawLine(0, h + 1, getWidth(), h + 1); } } diff --git a/src/gui/widgets/dropdown.h b/src/gui/widgets/dropdown.h index d85c3166c..6a22ba497 100644 --- a/src/gui/widgets/dropdown.h +++ b/src/gui/widgets/dropdown.h @@ -87,6 +87,9 @@ class DropDown : public gcn::DropDown */ void drawButton(gcn::Graphics *graphics); + gcn::Color mShadowColor; + gcn::Color mHighlightColor; + // Add own Images. static int instances; static Image *buttons[2][2]; diff --git a/src/gui/widgets/dropshortcutcontainer.cpp b/src/gui/widgets/dropshortcutcontainer.cpp index 92f02c78f..b628cf2d4 100644 --- a/src/gui/widgets/dropshortcutcontainer.cpp +++ b/src/gui/widgets/dropshortcutcontainer.cpp @@ -73,6 +73,8 @@ DropShortcutContainer::DropShortcutContainer(): mBoxHeight = 1; mBoxWidth = 1; } + mEquipedColor = Theme::getThemeColor(Theme::ITEM_EQUIPPED); + mUnEquipedColor = Theme::getThemeColor(Theme::ITEM_NOT_EQUIPPED); } DropShortcutContainer::~DropShortcutContainer() @@ -110,12 +112,6 @@ void DropShortcutContainer::draw(gcn::Graphics *graphics) if (mBackgroundImg) g->drawImage(mBackgroundImg, itemX, itemY); -/* // Draw item keyboard shortcut. - const char *key = SDL_GetKeyName( - (SDLKey) keyboard.getKeyValue(keyboard.KEY_SHORTCUT_1 + i)); - graphics->setColor(guiPalette->getColor(Palette::TEXT)); - g->drawText(key, itemX + 2, itemY + 2, gcn::Graphics::LEFT); -*/ if (dropShortcut->getItem(i) < 0) continue; @@ -142,11 +138,11 @@ void DropShortcutContainer::draw(gcn::Graphics *graphics) image->setAlpha(1.0f); g->drawImage(image, itemX, itemY); if (item->isEquipped()) - g->setColor(Theme::getThemeColor(Theme::ITEM_EQUIPPED)); + g->setColor(mEquipedColor); else - g->setColor(Theme::getThemeColor(Theme::TEXT)); + g->setColor(mUnEquipedColor); g->drawText(caption, itemX + mBoxWidth / 2, - itemY + mBoxHeight - 14, gcn::Graphics::CENTER); + itemY + mBoxHeight - 14, gcn::Graphics::CENTER); } } } diff --git a/src/gui/widgets/dropshortcutcontainer.h b/src/gui/widgets/dropshortcutcontainer.h index 723b215cf..b2d63a7dd 100644 --- a/src/gui/widgets/dropshortcutcontainer.h +++ b/src/gui/widgets/dropshortcutcontainer.h @@ -84,6 +84,8 @@ class DropShortcutContainer : public ShortcutContainer Item *mItemMoved; ItemPopup *mItemPopup; + gcn::Color mEquipedColor; + gcn::Color mUnEquipedColor; }; #endif diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp index 5bb972adc..5aced193f 100644 --- a/src/gui/widgets/emoteshortcutcontainer.cpp +++ b/src/gui/widgets/emoteshortcutcontainer.cpp @@ -80,6 +80,7 @@ EmoteShortcutContainer::EmoteShortcutContainer(): mBoxHeight = 1; mBoxWidth = 1; } + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); } EmoteShortcutContainer::~EmoteShortcutContainer() @@ -118,20 +119,9 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics) std::string key = keyboard.getKeyValueString( keyboard.KEY_EMOTE_1 + i); - graphics->setColor(Theme::getThemeColor(Theme::TEXT)); + graphics->setColor(getForegroundColor()); g->drawText(key, emoteX + 2, emoteY + 2, gcn::Graphics::LEFT); -/* - if (emoteShortcut->getEmote(i) - && static_cast(emoteShortcut->getEmote(i)) - 1 - < mEmoteImg.size() - && mEmoteImg[emoteShortcut->getEmote(i) - 1]) - { - mEmoteImg[emoteShortcut->getEmote(i) - 1]->draw(g, emoteX + 2, - emoteY + 10); - } -*/ - if (i < mEmoteImg.size() && mEmoteImg[i] && mEmoteImg[i]->sprite) mEmoteImg[i]->sprite->draw(g, emoteX + 2, emoteY + 10); } diff --git a/src/gui/widgets/guitable.cpp b/src/gui/widgets/guitable.cpp index e25e0bb8c..e02eda88c 100644 --- a/src/gui/widgets/guitable.cpp +++ b/src/gui/widgets/guitable.cpp @@ -88,17 +88,17 @@ void GuiTableActionListener::action(const gcn::ActionEvent } -GuiTable::GuiTable(TableModel *initial_model, gcn::Color background, - bool opacity) : +GuiTable::GuiTable(TableModel *initial_model, bool opacity) : mLinewiseMode(false), mWrappingEnabled(false), mOpaque(opacity), - mBackgroundColor(background), mModel(NULL), mSelectedRow(0), mSelectedColumn(0), mTopWidget(NULL) { + mBackgroundColor = Theme::getThemeColor(Theme::BACKGROUND); + mHighlightColor = Theme::getThemeColor(Theme::HIGHLIGHT); setModel(initial_model); setFocusable(true); @@ -292,8 +292,8 @@ void GuiTable::draw(gcn::Graphics* graphics) if (mOpaque) { - graphics->setColor(Theme::getThemeColor(Theme::BACKGROUND, - static_cast(mAlpha * 255.0f))); + mBackgroundColor.a = static_cast(mAlpha * 255.0f); + graphics->setColor(mBackgroundColor); graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); } @@ -304,7 +304,7 @@ void GuiTable::draw(gcn::Graphics* graphics) first_row = 0; unsigned rows_nr = 1 + (getHeight() / getRowHeight()); // May overestimate - // by one. + // by one. unsigned max_rows_nr; if (mModel->getRows() < first_row) @@ -343,8 +343,8 @@ void GuiTable::draw(gcn::Graphics* graphics) widget->setDimension(bounds); - graphics->setColor(Theme::getThemeColor(Theme::HIGHLIGHT, - static_cast(mAlpha * 255.0f))); + mHighlightColor.a = static_cast(mAlpha * 255.0f); + graphics->setColor(mHighlightColor); if (mSelectedRow > 0) { diff --git a/src/gui/widgets/guitable.h b/src/gui/widgets/guitable.h index c4fab6a0d..d248c4820 100644 --- a/src/gui/widgets/guitable.h +++ b/src/gui/widgets/guitable.h @@ -58,7 +58,6 @@ class GuiTable : public gcn::Widget, public: GuiTable(TableModel * initial_model = NULL, - gcn::Color background = 0xffffff, bool opacity = true); virtual ~GuiTable(); @@ -190,6 +189,8 @@ private: /** Vector for compactness; used as a list in practice. */ std::vector mActionListeners; + + gcn::Color mHighlightColor; }; diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index c28e4fb4c..91b674018 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -118,6 +118,9 @@ ItemContainer::ItemContainer(Inventory *inventory, bool forceQuantity): if (!mSelImg) logger->log1("Error: Unable to load selection.png"); + mEquipedColor = Theme::getThemeColor(Theme::ITEM_EQUIPPED); + mUnEquipedColor = Theme::getThemeColor(Theme::ITEM_NOT_EQUIPPED); + addKeyListener(this); addMouseListener(this); addWidgetListener(this); @@ -204,9 +207,9 @@ void ItemContainer::draw(gcn::Graphics *graphics) caption = "Eq."; if (item->isEquipped()) - g->setColor(Theme::getThemeColor(Theme::ITEM_EQUIPPED)); + g->setColor(mEquipedColor); else - g->setColor(Theme::getThemeColor(Theme::ITEM_NOT_EQUIPPED)); + g->setColor(mUnEquipedColor); g->drawText(caption, itemX + BOX_WIDTH / 2, itemY + BOX_HEIGHT - 14, gcn::Graphics::CENTER); diff --git a/src/gui/widgets/itemcontainer.h b/src/gui/widgets/itemcontainer.h index 5fd897a29..df7de63ee 100644 --- a/src/gui/widgets/itemcontainer.h +++ b/src/gui/widgets/itemcontainer.h @@ -202,6 +202,8 @@ class ItemContainer : public gcn::Widget, typedef SelectionListenerList::iterator SelectionListenerIterator; SelectionListenerList mSelectionListeners; + gcn::Color mEquipedColor; + gcn::Color mUnEquipedColor; }; #endif diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp index 328d5ae4d..79685fe45 100644 --- a/src/gui/widgets/itemshortcutcontainer.cpp +++ b/src/gui/widgets/itemshortcutcontainer.cpp @@ -77,6 +77,9 @@ ItemShortcutContainer::ItemShortcutContainer(unsigned number): mBoxHeight = 1; mBoxWidth = 1; } + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); + mEquipedColor = Theme::getThemeColor(Theme::ITEM_EQUIPPED); + mUnEquipedColor = Theme::getThemeColor(Theme::ITEM_NOT_EQUIPPED); } ItemShortcutContainer::~ItemShortcutContainer() @@ -119,7 +122,7 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics) // Draw item keyboard shortcut. std::string key = keyboard.getKeyValueString( keyboard.KEY_SHORTCUT_1 + i); - graphics->setColor(Theme::getThemeColor(Theme::TEXT)); + graphics->setColor(getForegroundColor()); g->drawText(key, itemX + 2, itemY + 2, gcn::Graphics::LEFT); @@ -154,14 +157,9 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics) image->setAlpha(1.0f); g->drawImage(image, itemX, itemY); if (item->isEquipped()) - { - g->setColor(Theme::getThemeColor( - Theme::ITEM_EQUIPPED)); - } + g->setColor(mEquipedColor); else - { - graphics->setColor(Theme::getThemeColor(Theme::TEXT)); - } + g->setColor(mUnEquipedColor); g->drawText(caption, itemX + mBoxWidth / 2, itemY + mBoxHeight - 14, gcn::Graphics::CENTER); } diff --git a/src/gui/widgets/itemshortcutcontainer.h b/src/gui/widgets/itemshortcutcontainer.h index 7eac431ec..e6b32c6f8 100644 --- a/src/gui/widgets/itemshortcutcontainer.h +++ b/src/gui/widgets/itemshortcutcontainer.h @@ -88,7 +88,8 @@ class ItemShortcutContainer : public ShortcutContainer ItemPopup *mItemPopup; SpellPopup *mSpellPopup; + gcn::Color mEquipedColor; + gcn::Color mUnEquipedColor; }; -//extern SpellManager *spellManager; #endif diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp index de8707406..53299ca46 100644 --- a/src/gui/widgets/listbox.cpp +++ b/src/gui/widgets/listbox.cpp @@ -41,6 +41,8 @@ float ListBox::mAlpha = 1.0; ListBox::ListBox(gcn::ListModel *listModel): gcn::ListBox(listModel) { + mHighlightColor = Theme::getThemeColor(Theme::HIGHLIGHT); + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); } ListBox::~ListBox() @@ -63,8 +65,8 @@ void ListBox::draw(gcn::Graphics *graphics) updateAlpha(); - graphics->setColor(Theme::getThemeColor(Theme::HIGHLIGHT, - static_cast(mAlpha * 255.0f))); + mHighlightColor.a = static_cast(mAlpha * 255.0f); + graphics->setColor(mHighlightColor); graphics->setFont(getFont()); const int height = getRowHeight(); @@ -77,7 +79,7 @@ void ListBox::draw(gcn::Graphics *graphics) } // Draw the list elements - graphics->setColor(Theme::getThemeColor(Theme::TEXT)); + graphics->setColor(getForegroundColor()); for (int i = 0, y = 0; i < mListModel->getNumberOfElements(); ++i, y += height) { diff --git a/src/gui/widgets/listbox.h b/src/gui/widgets/listbox.h index 5f8c20059..418b83f58 100644 --- a/src/gui/widgets/listbox.h +++ b/src/gui/widgets/listbox.h @@ -73,6 +73,7 @@ class ListBox : public gcn::ListBox void mouseDragged(gcn::MouseEvent &event); protected: + gcn::Color mHighlightColor; static float mAlpha; }; diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index 3e90bf4c7..2796d3ab2 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -73,7 +73,6 @@ ScrollArea::ScrollArea(gcn::Widget *widget): mDrawWidth(0), mDrawHeight(0) { -// addWidgetListener(this); init(); } @@ -219,6 +218,9 @@ void ScrollArea::init() } instances++; + + mGray = Theme::getThemeColor(Theme::SCROLLBAR_GRAY, 32); + mBackground = Theme::getThemeColor(Theme::BACKGROUND); } void ScrollArea::logic() @@ -439,17 +441,17 @@ void ScrollArea::drawRightButton(gcn::Graphics *graphics) void ScrollArea::drawVBar(gcn::Graphics *graphics) { const gcn::Rectangle dim = getVerticalBarDimension(); - graphics->setColor(Theme::getThemeColor(Theme::SCROLLBAR_GRAY, 32)); + graphics->setColor(mGray); graphics->fillRectangle(dim); - graphics->setColor(Theme::getThemeColor(Theme::BACKGROUND)); + graphics->setColor(mBackground); } void ScrollArea::drawHBar(gcn::Graphics *graphics) { const gcn::Rectangle dim = getHorizontalBarDimension(); - graphics->setColor(Theme::getThemeColor(Theme::SCROLLBAR_GRAY, 32)); + graphics->setColor(mGray); graphics->fillRectangle(dim); - graphics->setColor(Theme::getThemeColor(Theme::BACKGROUND)); + graphics->setColor(mBackground); } void ScrollArea::drawVMarker(gcn::Graphics *graphics) diff --git a/src/gui/widgets/scrollarea.h b/src/gui/widgets/scrollarea.h index 440fcec15..095010f3c 100644 --- a/src/gui/widgets/scrollarea.h +++ b/src/gui/widgets/scrollarea.h @@ -156,6 +156,9 @@ class ScrollArea : public gcn::ScrollArea, public gcn::WidgetListener int mYOffset; int mDrawWidth; int mDrawHeight; + + gcn::Color mGray; + gcn::Color mBackground; }; #endif diff --git a/src/gui/widgets/shoplistbox.cpp b/src/gui/widgets/shoplistbox.cpp index 2fe28181b..793491808 100644 --- a/src/gui/widgets/shoplistbox.cpp +++ b/src/gui/widgets/shoplistbox.cpp @@ -50,9 +50,7 @@ ShopListBox::ShopListBox(gcn::ListModel *listModel): mShopItems(0) { mRowHeight = getFont()->getHeight(); - mPriceCheck = true; - - mItemPopup = new ItemPopup; + init(); } ShopListBox::ShopListBox(gcn::ListModel *listModel, ShopItems *shopListModel): @@ -61,9 +59,17 @@ ShopListBox::ShopListBox(gcn::ListModel *listModel, ShopItems *shopListModel): mShopItems(shopListModel) { mRowHeight = std::max(getFont()->getHeight(), ITEM_ICON_SIZE); - mPriceCheck = true; + init(); +} +void ShopListBox::init() +{ + mPriceCheck = true; mItemPopup = new ItemPopup; + mHighlightColor = Theme::getThemeColor(Theme::HIGHLIGHT); + mBackgroundColor = Theme::getThemeColor(Theme::BACKGROUND); + mWarningColor = Theme::getThemeColor(Theme::SHOP_WARNING); + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); } void ShopListBox::setPlayersMoney(int money) @@ -80,8 +86,7 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) mAlpha = Client::getGuiAlpha(); int alpha = static_cast(mAlpha * 255.0f); - const gcn::Color* highlightColor = - &Theme::getThemeColor(Theme::HIGHLIGHT, alpha); + mHighlightColor.a = alpha; Graphics *graphics = static_cast(gcnGraphics); @@ -93,29 +98,30 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) ++i, y += mRowHeight) { gcn::Color temp; - const gcn::Color* backgroundColor = - &Theme::getThemeColor(Theme::BACKGROUND, alpha); + gcn::Color* backgroundColor = &mBackgroundColor; + mBackgroundColor.a = alpha; if (mShopItems && mShopItems->at(i) && mPlayerMoney < mShopItems->at(i)->getPrice() && mPriceCheck) { if (i != mSelected) { - backgroundColor = &Theme::getThemeColor(Theme::SHOP_WARNING, - alpha); + backgroundColor = &mWarningColor; + backgroundColor->a = alpha; } else { - temp = Theme::getThemeColor(Theme::SHOP_WARNING, alpha); - temp.r = (temp.r + highlightColor->r) / 2; - temp.g = (temp.g + highlightColor->g) / 2; - temp.b = (temp.g + highlightColor->b) / 2; + temp = mWarningColor; + temp.r = (temp.r + mHighlightColor.r) / 2; + temp.g = (temp.g + mHighlightColor.g) / 2; + temp.b = (temp.g + mHighlightColor.b) / 2; + temp.a = alpha; backgroundColor = &temp; } } else if (i == mSelected) { - backgroundColor = highlightColor; + backgroundColor = &mHighlightColor; } graphics->setColor(*backgroundColor); @@ -130,9 +136,9 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) graphics->drawImage(icon, 1, y); } } - graphics->setColor(Theme::getThemeColor(Theme::TEXT)); + graphics->setColor(getForegroundColor()); graphics->drawText(mListModel->getElementAt(i), ITEM_ICON_SIZE + 5, - y + (ITEM_ICON_SIZE - getFont()->getHeight()) / 2); + y + (ITEM_ICON_SIZE - getFont()->getHeight()) / 2); } } diff --git a/src/gui/widgets/shoplistbox.h b/src/gui/widgets/shoplistbox.h index 917f46729..38e238f20 100644 --- a/src/gui/widgets/shoplistbox.h +++ b/src/gui/widgets/shoplistbox.h @@ -85,6 +85,8 @@ class ShopListBox : public ListBox void mouseExited(gcn::MouseEvent& mouseEvent A_UNUSED); private: + void init(); + int mPlayerMoney; /** @@ -100,6 +102,10 @@ class ShopListBox : public ListBox static float mAlpha; bool mPriceCheck; + + gcn::Color mHighlightColor; + gcn::Color mBackgroundColor; + gcn::Color mWarningColor; }; #endif // SHOPLISTBOX_H diff --git a/src/gui/widgets/spellshortcutcontainer.cpp b/src/gui/widgets/spellshortcutcontainer.cpp index 7e19b0348..8abe727b5 100644 --- a/src/gui/widgets/spellshortcutcontainer.cpp +++ b/src/gui/widgets/spellshortcutcontainer.cpp @@ -81,6 +81,7 @@ SpellShortcutContainer::SpellShortcutContainer(unsigned number): mBoxHeight = 1; mBoxWidth = 1; } + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); } SpellShortcutContainer::~SpellShortcutContainer() @@ -109,7 +110,7 @@ void SpellShortcutContainer::draw(gcn::Graphics *graphics) graphics->setFont(getFont()); int selectedId = spellShortcut->getSelectedItem(); - g->setColor(Theme::getThemeColor(Theme::TEXT)); + g->setColor(getForegroundColor()); for (unsigned i = 0; i < mMaxItems; i++) { diff --git a/src/gui/widgets/tab.cpp b/src/gui/widgets/tab.cpp index b7d6b4458..530f1ac82 100644 --- a/src/gui/widgets/tab.cpp +++ b/src/gui/widgets/tab.cpp @@ -77,6 +77,8 @@ Tab::Tab() : gcn::Tab(), mMode(0) { init(); + mFlashColor = Theme::getThemeColor(Theme::TAB_FLASH); + mPlayerFlashColor = Theme::getThemeColor(Theme::TAB_PLAYER_FLASH); } Tab::~Tab() @@ -177,12 +179,10 @@ void Tab::draw(gcn::Graphics *graphics) switch (mFlash) { case 1: - mLabel->setForegroundColor(Theme::getThemeColor( - Theme::TAB_FLASH)); + mLabel->setForegroundColor(mFlashColor); break; case 2: - mLabel->setForegroundColor(Theme::getThemeColor( - Theme::TAB_PLAYER_FLASH)); + mLabel->setForegroundColor(mPlayerFlashColor); break; default: break; diff --git a/src/gui/widgets/tab.h b/src/gui/widgets/tab.h index 5847bd505..ba51e6c74 100644 --- a/src/gui/widgets/tab.h +++ b/src/gui/widgets/tab.h @@ -91,6 +91,8 @@ class Tab : public gcn::Tab, public gcn::WidgetListener GraphicsVertexes *mVertexes; bool mRedraw; int mMode; + gcn::Color mFlashColor; + gcn::Color mPlayerFlashColor; }; #endif diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index f80039650..2729e5407 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -59,6 +59,8 @@ TextField::TextField(const std::string &text, bool loseFocusOnTab, mLoseFocusOnTab = loseFocusOnTab; + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); + if (instances == 0) { // Load the skin @@ -136,7 +138,7 @@ void TextField::draw(gcn::Graphics *graphics) mXScroll); } - graphics->setColor(Theme::getThemeColor(Theme::TEXT)); + graphics->setColor(getForegroundColor()); graphics->setFont(getFont()); graphics->drawText(mText, 1 - mXScroll, 1); } diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 9a7c689e6..cdb9d3d55 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -95,6 +95,7 @@ Window::Window(const std::string &caption, bool modal, Window *parent, addWidgetListener(this); mCaptionFont = getFont(); + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); } Window::~Window() @@ -146,15 +147,10 @@ void Window::draw(gcn::Graphics *graphics) g->drawImageRect2(mVertexes, mSkin->getBorder()); -/* - g->drawImageRect(0, 0, getWidth(), - getHeight(), mSkin->getBorder()); -*/ - // Draw title if (mShowTitle) { - g->setColor(Theme::getThemeColor(Theme::TEXT)); + g->setColor(getForegroundColor()); g->setFont(mCaptionFont); g->drawText(getCaption(), 7, 5, gcn::Graphics::LEFT); } -- cgit v1.2.3-70-g09d2 From 9505e3789cc9db6a10a68b9794a586604271b76f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 23 Aug 2011 01:48:25 +0300 Subject: Add protection against infinite loop in viewport and add debug message if some thing wrong happend. --- src/gui/viewport.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 70d02b016..a5b541a8e 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -145,8 +145,10 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) if (mScrollLaziness < 1) mScrollLaziness = 1; // Avoids division by zero + int cnt = 0; + // Apply lazy scrolling - while (lastTick < tick_time) + while (lastTick < tick_time && cnt < 32) { if (player_x > static_cast(mPixelViewX) + mScrollRadius) { @@ -172,19 +174,26 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) - static_cast(mPixelViewY) + mScrollRadius) / static_cast(mScrollLaziness); } - lastTick++; + lastTick ++; + cnt ++; } // Auto center when player is off screen - if (player_x - static_cast(mPixelViewX) > graphics->mWidth / 2 - || static_cast(mPixelViewX) - player_x > graphics->mWidth / 2 - || static_cast(mPixelViewY) - player_y - > graphics->getHeight() / 2 - || player_y - static_cast(mPixelViewY) - > graphics->getHeight() / 2) + if (cnt > 30 || player_x - static_cast(mPixelViewX) + > graphics->mWidth / 2 || static_cast(mPixelViewX) + - player_x > graphics->mWidth / 2 || static_cast(mPixelViewY) + - player_y > graphics->getHeight() / 2 || player_y + - static_cast(mPixelViewY) > graphics->getHeight() / 2) { mPixelViewX = static_cast(player_x); mPixelViewY = static_cast(player_y); + if (player_x <= 0 || player_y <= 0) + { + if (debugChatTab) + debugChatTab->chatLog("incorrect player position!"); + logger->log("incorrect player position: %d, %d", + player_x, player_y); + } }; // Don't move camera so that the end of the map is on screen -- cgit v1.2.3-70-g09d2