From 39a12ab9cf0dcfdfd75a6899409e38f26affef4c Mon Sep 17 00:00:00 2001 From: k1ll Date: Thu, 27 Jun 2013 19:20:14 +0200 Subject: [PATCH 01/10] CXX Flags aren't definitions --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6948a3420..f2b1fcd4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -321,15 +321,15 @@ endif() # Compiler settings if (CMAKE_COMPILER_IS_GNUCC) - add_definitions (-Wall -Wextra -Wno-unused-parameter -Wno-reorder -std=c++98 -pedantic -Wno-long-long) + SET(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-reorder -std=c++98 -pedantic -Wno-long-long ${CMAKE_CXX_FLAGS}") # Silence warnings in OGRE headers. Remove once OGRE got fixed! - add_definitions (-Wno-ignored-qualifiers) + SET(CMAKE_CXX_FLAGS "-Wno-ignored-qualifiers ${CMAKE_CXX_FLAGS}") execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) if ("${GCC_VERSION}" VERSION_GREATER 4.6 OR "${GCC_VERSION}" VERSION_EQUAL 4.6) - add_definitions (-Wno-unused-but-set-parameter) + SET(CMAKE_CXX_FLAGS "-Wno-unused-but-set-parameter ${CMAKE_CXX_FLAGS}") endif("${GCC_VERSION}" VERSION_GREATER 4.6 OR "${GCC_VERSION}" VERSION_EQUAL 4.6) endif (CMAKE_COMPILER_IS_GNUCC) From b095c2485418d3588b811dcd7da37f23a5fefabd Mon Sep 17 00:00:00 2001 From: Vincent Heuken Date: Thu, 27 Jun 2013 14:11:20 -0700 Subject: [PATCH 02/10] resize actor collision boxes on death --- apps/openmw/mwbase/world.hpp | 2 ++ apps/openmw/mwmechanics/character.cpp | 4 ++++ apps/openmw/mwworld/worldimp.cpp | 14 ++++++++++++++ apps/openmw/mwworld/worldimp.hpp | 2 ++ 4 files changed, 22 insertions(+) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 86a6a89d2..cf41f97df 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -345,6 +345,8 @@ namespace MWBase virtual void getItemsOwnedBy (const MWWorld::Ptr& npc, std::vector& out) = 0; ///< get all items in active cells owned by this Npc + virtual void enableActorCollision(const MWWorld::Ptr& actor, bool enable) = 0; + virtual void setupExternalRendering (MWRender::ExternalRendering& rendering) = 0; virtual int canRest() = 0; diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index abc6b82c4..d3dbb9325 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -462,6 +462,10 @@ void CharacterController::update(float duration, Movement &movement) mAnimation->disable("torch"); } } + else if (cls.getCreatureStats(mPtr).isDead()) + { + MWBase::Environment::get().getWorld()->enableActorCollision(mPtr, false); + } if(mAnimation && !mSkipAnim) { diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 16cba2ea8..662d46a4b 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1751,4 +1751,18 @@ namespace MWWorld out.push_back(searchPtrViaHandle(*it)); } } + + void World::enableActorCollision(const MWWorld::Ptr& actor, bool enable) + { + OEngine::Physic::PhysicActor *physicActor = mPhysEngine->getCharacter(actor.getRefData().getHandle()); + + if (!enable) + { + physicActor->setScale(0.15); + } + else + { + physicActor->setScale(1); + } + } } diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 12438efd4..5cf3a24bf 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -394,6 +394,8 @@ namespace MWWorld virtual void getItemsOwnedBy (const MWWorld::Ptr& npc, std::vector& out); ///< get all items in active cells owned by this Npc + virtual void enableActorCollision(const MWWorld::Ptr& actor, bool enable); + virtual void setupExternalRendering (MWRender::ExternalRendering& rendering); virtual int canRest(); From f43b48015e487f80810e52c12f0d4f5b4f5df2bb Mon Sep 17 00:00:00 2001 From: Vincent Heuken Date: Thu, 27 Jun 2013 19:42:27 -0700 Subject: [PATCH 03/10] remove actor's collisionbox on death --- apps/openmw/mwworld/worldimp.cpp | 6 +++--- libs/openengine/bullet/physic.cpp | 10 ++++++++++ libs/openengine/bullet/physic.hpp | 3 +++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 662d46a4b..0a1e0ccdc 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1756,13 +1756,13 @@ namespace MWWorld { OEngine::Physic::PhysicActor *physicActor = mPhysEngine->getCharacter(actor.getRefData().getHandle()); - if (!enable) + if (enable) { - physicActor->setScale(0.15); + physicActor->enableCollisionBody(); } else { - physicActor->setScale(1); + physicActor->disableCollisionBody(); } } } diff --git a/libs/openengine/bullet/physic.cpp b/libs/openengine/bullet/physic.cpp index bbe633847..550e71b3c 100644 --- a/libs/openengine/bullet/physic.cpp +++ b/libs/openengine/bullet/physic.cpp @@ -146,6 +146,16 @@ namespace Physic return collisionMode && onGround; } + void PhysicActor::disableCollisionBody() + { + mEngine->dynamicsWorld->removeRigidBody(mBody); + } + + void PhysicActor::enableCollisionBody() + { + mEngine->dynamicsWorld->addRigidBody(mBody); + } + //////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/libs/openengine/bullet/physic.hpp b/libs/openengine/bullet/physic.hpp index 80c681fe5..baeb31678 100644 --- a/libs/openengine/bullet/physic.hpp +++ b/libs/openengine/bullet/physic.hpp @@ -129,6 +129,9 @@ namespace Physic bool getOnGround() const; + void disableCollisionBody(); + void enableCollisionBody(); + //HACK: in Visual Studio 2010 and presumably above, this structures alignment // must be 16, but the built in operator new & delete don't properly // perform this alignment. From cd538538b563e3ac99948032b56ba52fc4a1c586 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Fri, 28 Jun 2013 09:00:21 +0200 Subject: [PATCH 04/10] fixed weather code --- apps/openmw/mwworld/weather.cpp | 53 +++++++++++++++++---------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index 10dbdae9b..467d7e7c8 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -572,35 +572,36 @@ Ogre::String WeatherManager::nextWeather(const ESM::Region* region) const int chance = (rand() % 100) + 1; // 1..100 int sum = 0; - for (int i = 0; i < 10; ++i) + int i = 0; + for (; i < 10; ++i) { sum += probability[i]; if (chance < sum) - { - switch (i) - { - case 1: - return "cloudy"; - case 2: - return "foggy"; - case 3: - return "overcast"; - case 4: - return "rain"; - case 5: - return "thunderstorm"; - case 6: - return "ashstorm"; - case 7: - return "blight"; - case 8: - return "snow"; - case 9: - return "blizzard"; - default: // case 0 - return "clear"; - } - } + break; + } + + switch (i) + { + case 1: + return "cloudy"; + case 2: + return "foggy"; + case 3: + return "overcast"; + case 4: + return "rain"; + case 5: + return "thunderstorm"; + case 6: + return "ashstorm"; + case 7: + return "blight"; + case 8: + return "snow"; + case 9: + return "blizzard"; + default: // case 0 + return "clear"; } } From 8bdc9ff3aeaf4b81ce1fb9b976b9fb38a8f83ab2 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Mon, 1 Jul 2013 03:56:33 +0200 Subject: [PATCH 05/10] set position of the window for multiple monitors --- apps/openmw/engine.cpp | 1 + libs/openengine/ogre/renderer.cpp | 8 ++++++-- libs/openengine/ogre/renderer.hpp | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index c0b212550..2918f5d8b 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -369,6 +369,7 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings) windowSettings.fullscreen = settings.getBool("fullscreen", "Video"); windowSettings.window_x = settings.getInt("resolution x", "Video"); windowSettings.window_y = settings.getInt("resolution y", "Video"); + windowSettings.screen = settings.getInt("screen", "Video"); windowSettings.vsync = settings.getBool("vsync", "Video"); windowSettings.icon = "openmw.png"; std::string aa = settings.getString("antialiasing", "Video"); diff --git a/libs/openengine/ogre/renderer.cpp b/libs/openengine/ogre/renderer.cpp index 5807a9482..2ac52d31a 100644 --- a/libs/openengine/ogre/renderer.cpp +++ b/libs/openengine/ogre/renderer.cpp @@ -266,11 +266,15 @@ void OgreRenderer::createWindow(const std::string &title, const WindowSettings& params.insert(std::make_pair("FSAA", settings.fsaa)); params.insert(std::make_pair("vsync", settings.vsync ? "true" : "false")); + SDL_Rect display_bounds; + if(SDL_GetDisplayBounds(settings.screen, &display_bounds) != 0) + throw std::runtime_error("Couldn't get display bounds!"); + // Create an application window with the following settings: mSDLWindow = SDL_CreateWindow( "OpenMW", // window title - SDL_WINDOWPOS_UNDEFINED, // initial x position - SDL_WINDOWPOS_UNDEFINED, // initial y position + display_bounds.x, // initial x position + display_bounds.y, // initial y position settings.window_x, // width, in pixels settings.window_y, // height, in pixels SDL_WINDOW_SHOWN diff --git a/libs/openengine/ogre/renderer.hpp b/libs/openengine/ogre/renderer.hpp index a451490fb..f4b38c52d 100644 --- a/libs/openengine/ogre/renderer.hpp +++ b/libs/openengine/ogre/renderer.hpp @@ -56,6 +56,7 @@ namespace OEngine bool vsync; bool fullscreen; int window_x, window_y; + int screen; std::string fsaa; std::string icon; }; From 72b7e113cc99a972606022aba6dfe99d4905d509 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Mon, 1 Jul 2013 04:08:26 +0200 Subject: [PATCH 06/10] only apply in fullscreen --- libs/openengine/ogre/renderer.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/libs/openengine/ogre/renderer.cpp b/libs/openengine/ogre/renderer.cpp index 2ac52d31a..00d94a004 100644 --- a/libs/openengine/ogre/renderer.cpp +++ b/libs/openengine/ogre/renderer.cpp @@ -266,15 +266,23 @@ void OgreRenderer::createWindow(const std::string &title, const WindowSettings& params.insert(std::make_pair("FSAA", settings.fsaa)); params.insert(std::make_pair("vsync", settings.vsync ? "true" : "false")); - SDL_Rect display_bounds; - if(SDL_GetDisplayBounds(settings.screen, &display_bounds) != 0) - throw std::runtime_error("Couldn't get display bounds!"); + int pos_x = SDL_WINDOWPOS_UNDEFINED, + pos_y = SDL_WINDOWPOS_UNDEFINED; + + if(settings.fullscreen) + { + SDL_Rect display_bounds; + if(SDL_GetDisplayBounds(settings.screen, &display_bounds) != 0) + throw std::runtime_error("Couldn't get display bounds!"); + pos_x = display_bounds.x; + pos_y = display_bounds.y; + } // Create an application window with the following settings: mSDLWindow = SDL_CreateWindow( "OpenMW", // window title - display_bounds.x, // initial x position - display_bounds.y, // initial y position + pos_x, // initial x position + pos_y, // initial y position settings.window_x, // width, in pixels settings.window_y, // height, in pixels SDL_WINDOW_SHOWN From e3d8bdbafefe032aa6e14c224363da5c1abfa9c7 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Tue, 2 Jul 2013 17:29:47 +0200 Subject: [PATCH 07/10] autorepeat scrollbar --- apps/openmw/mwgui/waitdialog.cpp | 7 +- apps/openmw/mwgui/waitdialog.hpp | 3 +- apps/openmw/mwgui/widgets.cpp | 92 ++++++++++++++++++++++++++ apps/openmw/mwgui/widgets.hpp | 31 +++++++++ apps/openmw/mwgui/windowmanagerimp.cpp | 1 + files/mygui/openmw_wait_dialog.layout | 2 +- 6 files changed, 130 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwgui/waitdialog.cpp b/apps/openmw/mwgui/waitdialog.cpp index ad2b4710c..f9a03de71 100644 --- a/apps/openmw/mwgui/waitdialog.cpp +++ b/apps/openmw/mwgui/waitdialog.cpp @@ -15,8 +15,6 @@ #include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/npcstats.hpp" -#include "widgets.hpp" - namespace MWGui { @@ -53,15 +51,14 @@ namespace MWGui getWidget(mDateTimeText, "DateTimeText"); getWidget(mRestText, "RestText"); getWidget(mHourText, "HourText"); - getWidget(mHourSlider, "HourSlider"); getWidget(mUntilHealedButton, "UntilHealedButton"); getWidget(mWaitButton, "WaitButton"); getWidget(mCancelButton, "CancelButton"); + getWidget(mHourSlider, "HourSlider"); mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &WaitDialog::onCancelButtonClicked); mUntilHealedButton->eventMouseButtonClick += MyGUI::newDelegate(this, &WaitDialog::onUntilHealedButtonClicked); mWaitButton->eventMouseButtonClick += MyGUI::newDelegate(this, &WaitDialog::onWaitButtonClicked); - mHourSlider->eventScrollChangePosition += MyGUI::newDelegate(this, &WaitDialog::onHourSliderChangedPosition); mProgressBar.setVisible (false); @@ -231,6 +228,8 @@ namespace MWGui void WaitDialog::onFrame(float dt) { + mHourSlider->updateTime(dt); + if (!mWaiting) return; diff --git a/apps/openmw/mwgui/waitdialog.hpp b/apps/openmw/mwgui/waitdialog.hpp index d06d7d112..2723f7a80 100644 --- a/apps/openmw/mwgui/waitdialog.hpp +++ b/apps/openmw/mwgui/waitdialog.hpp @@ -2,6 +2,7 @@ #define MWGUI_WAIT_DIALOG_H #include "windowbase.hpp" +#include "widgets.hpp" namespace MWGui { @@ -38,10 +39,10 @@ namespace MWGui MyGUI::TextBox* mDateTimeText; MyGUI::TextBox* mRestText; MyGUI::TextBox* mHourText; - MyGUI::ScrollBar* mHourSlider; MyGUI::Button* mUntilHealedButton; MyGUI::Button* mWaitButton; MyGUI::Button* mCancelButton; + MWGui::Widgets::MWScrollBar* mHourSlider; bool mWaiting; bool mSleeping; diff --git a/apps/openmw/mwgui/widgets.cpp b/apps/openmw/mwgui/widgets.cpp index 1662c0597..7752b6a94 100644 --- a/apps/openmw/mwgui/widgets.cpp +++ b/apps/openmw/mwgui/widgets.cpp @@ -893,5 +893,97 @@ namespace MWGui { align(); } + + MWScrollBar::MWScrollBar() + : mEnableRepeat(true) + , mRepeatTriggerTime(0.5) + , mRepeatStepTime(0.1) + , mStepDecrease(0) + , mStepIncrease(0) + { + } + + MWScrollBar::~MWScrollBar() + { + } + + void MWScrollBar::initialiseOverride() + { + Base::initialiseOverride(); + + mWidgetStart->eventMouseButtonPressed += MyGUI::newDelegate(this, &MWScrollBar::onDecreaseButtonPressed); + mWidgetStart->eventMouseButtonReleased += MyGUI::newDelegate(this, &MWScrollBar::onDecreaseButtonReleased); + mWidgetEnd->eventMouseButtonPressed += MyGUI::newDelegate(this, &MWScrollBar::onIncreaseButtonPressed); + mWidgetEnd->eventMouseButtonReleased += MyGUI::newDelegate(this, &MWScrollBar::onIncreaseButtonReleased); + } + + void MWScrollBar::setEnableRepeat(bool enable) + { + mEnableRepeat = enable; + } + + bool MWScrollBar::getEnableRepeat() + { + return mEnableRepeat; + } + + void MWScrollBar::getRepeat(float &trigger, float &step) + { + trigger = mRepeatTriggerTime; + step = mRepeatStepTime; + } + + void MWScrollBar::setRepeat(float trigger, float step) + { + mRepeatTriggerTime = trigger; + mRepeatStepTime = step; + } + + void MWScrollBar::updateTime(float dt) + { + if(!mEnableRepeat) + return; + + if(mStepDecrease > 0) + { + mStepDecrease -= dt; + if(mStepDecrease <= 0 && mScrollPosition > 0) + { + mScrollPosition -= 1; + eventScrollChangePosition(this, mScrollPosition); + mStepDecrease += mRepeatStepTime; + } + } + if(mStepIncrease > 0) + { + mStepIncrease -= dt; + if(mStepIncrease <= 0 && mScrollPosition < mScrollRange-1) + { + mScrollPosition += 1; + eventScrollChangePosition(this, mScrollPosition); + mStepIncrease += mRepeatStepTime; + } + } + } + + void MWScrollBar::onDecreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id) + { + mStepDecrease = mRepeatTriggerTime; + } + + void MWScrollBar::onDecreaseButtonReleased(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id) + { + mStepDecrease = 0; + } + + void MWScrollBar::onIncreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id) + { + mStepIncrease = mRepeatTriggerTime; + } + + void MWScrollBar::onIncreaseButtonReleased(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id) + { + mStepIncrease = 0; + } } } diff --git a/apps/openmw/mwgui/widgets.hpp b/apps/openmw/mwgui/widgets.hpp index 156794691..362746ae2 100644 --- a/apps/openmw/mwgui/widgets.hpp +++ b/apps/openmw/mwgui/widgets.hpp @@ -6,6 +6,7 @@ #include #include +#include namespace MyGUI { @@ -407,6 +408,36 @@ namespace MWGui virtual void onWidgetCreated(MyGUI::Widget* _widget); }; + + class MWScrollBar : public MyGUI::ScrollBar + { + MYGUI_RTTI_DERIVED(MWScrollBar) + + public: + MWScrollBar(); + + void setEnableRepeat(bool enable); + bool getEnableRepeat(); + void getRepeat(float &trigger, float &step); + void setRepeat(float trigger, float step); + void updateTime(float dt); + + protected: + virtual ~MWScrollBar(); + virtual void initialiseOverride(); + + bool mEnableRepeat; + float mRepeatTriggerTime; + float mRepeatStepTime; + float mStepDecrease; + float mStepIncrease; + + private: + void onDecreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id); + void onDecreaseButtonReleased(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id); + void onIncreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id); + void onIncreaseButtonReleased(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id); + }; } } diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 38efbbff0..06fb96c12 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -142,6 +142,7 @@ namespace MWGui MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); BookPage::registerMyGUIComponents (); ItemView::registerComponents(); diff --git a/files/mygui/openmw_wait_dialog.layout b/files/mygui/openmw_wait_dialog.layout index 66e0ec22f..eeb7012eb 100644 --- a/files/mygui/openmw_wait_dialog.layout +++ b/files/mygui/openmw_wait_dialog.layout @@ -16,7 +16,7 @@ - + From b43f41c2bddefa18ebe012e75328163491a323ae Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Fri, 5 Jul 2013 19:17:00 +0200 Subject: [PATCH 08/10] use a mygui controller for scrollbar repeat --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwgui/controllers.cpp | 54 ++++++++++++++++++++++++++ apps/openmw/mwgui/controllers.hpp | 46 ++++++++++++++++++++++ apps/openmw/mwgui/waitdialog.cpp | 2 - apps/openmw/mwgui/widgets.cpp | 50 ++++++++++++------------ apps/openmw/mwgui/widgets.hpp | 8 ++-- apps/openmw/mwgui/windowmanagerimp.cpp | 2 + 7 files changed, 131 insertions(+), 33 deletions(-) create mode 100644 apps/openmw/mwgui/controllers.cpp create mode 100644 apps/openmw/mwgui/controllers.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 501e5c5ae..6dbc3e28f 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -33,7 +33,7 @@ add_openmw_dir (mwgui enchantingdialog trainingwindow travelwindow imagebutton exposedwindow cursor spellicons merchantrepair repair soulgemdialog companionwindow bookpage journalviewmodel journalbooks keywordsearch itemmodel containeritemmodel inventoryitemmodel sortfilteritemmodel itemview - tradeitemmodel companionitemmodel pickpocketitemmodel fontloader + tradeitemmodel companionitemmodel pickpocketitemmodel fontloader controllers ) add_openmw_dir (mwdialogue diff --git a/apps/openmw/mwgui/controllers.cpp b/apps/openmw/mwgui/controllers.cpp new file mode 100644 index 000000000..2c3ef4ae0 --- /dev/null +++ b/apps/openmw/mwgui/controllers.cpp @@ -0,0 +1,54 @@ +#include "controllers.hpp" + +namespace MWGui +{ + namespace Controllers + { + + ControllerRepeatClick::ControllerRepeatClick() : + mInit(0.5), + mStep(0.1), + mEnabled(true), + mTimeLeft(0) + { + } + + ControllerRepeatClick::~ControllerRepeatClick() + { + } + + bool ControllerRepeatClick::addTime(MyGUI::Widget* _widget, float _time) + { + if(mTimeLeft == 0) + mTimeLeft = mInit; + + mTimeLeft -= _time; + if(mTimeLeft <= 0) + { + mTimeLeft = mStep; + eventRepeatClick(_widget, this); + } + return true; + } + + void ControllerRepeatClick::setRepeat(float init, float step) + { + mInit = init; + mStep = step; + } + + void ControllerRepeatClick::setEnabled(bool enable) + { + mEnabled = enable; + } + + void ControllerRepeatClick::setProperty(const std::string& _key, const std::string& _value) + { + } + + void ControllerRepeatClick::prepareItem(MyGUI::Widget* _widget) + { + } + + } +} diff --git a/apps/openmw/mwgui/controllers.hpp b/apps/openmw/mwgui/controllers.hpp new file mode 100644 index 000000000..798acde62 --- /dev/null +++ b/apps/openmw/mwgui/controllers.hpp @@ -0,0 +1,46 @@ +#ifndef MWGUI_CONTROLLERS_H +#define MWGUI_CONTROLLERS_H + +#include +#include + + +namespace MWGui +{ + namespace Controllers + { + class ControllerRepeatClick : + public MyGUI::ControllerItem + { + MYGUI_RTTI_DERIVED( ControllerRepeatClick ) + + public: + ControllerRepeatClick(); + virtual ~ControllerRepeatClick(); + + void setRepeat(float init, float step); + void setEnabled(bool enable); + virtual void setProperty(const std::string& _key, const std::string& _value); + + // Events + typedef MyGUI::delegates::CMultiDelegate2 EventHandle_RepeatClickVoid; + + /** Event : Repeat Click.\n + signature : void method(MyGUI::Widget* _sender, MyGUI::ControllerItem *_controller)\n + */ + EventHandle_RepeatClickVoid eventRepeatClick; + + private: + bool addTime(MyGUI::Widget* _widget, float _time); + void prepareItem(MyGUI::Widget* _widget); + + private: + float mInit; + float mStep; + bool mEnabled; + float mTimeLeft; + }; + } +} + +#endif diff --git a/apps/openmw/mwgui/waitdialog.cpp b/apps/openmw/mwgui/waitdialog.cpp index f9a03de71..97c869b07 100644 --- a/apps/openmw/mwgui/waitdialog.cpp +++ b/apps/openmw/mwgui/waitdialog.cpp @@ -228,8 +228,6 @@ namespace MWGui void WaitDialog::onFrame(float dt) { - mHourSlider->updateTime(dt); - if (!mWaiting) return; diff --git a/apps/openmw/mwgui/widgets.cpp b/apps/openmw/mwgui/widgets.cpp index 7752b6a94..d147b28b1 100644 --- a/apps/openmw/mwgui/widgets.cpp +++ b/apps/openmw/mwgui/widgets.cpp @@ -4,6 +4,7 @@ #include #include +#include #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" @@ -898,8 +899,6 @@ namespace MWGui : mEnableRepeat(true) , mRepeatTriggerTime(0.5) , mRepeatStepTime(0.1) - , mStepDecrease(0) - , mStepIncrease(0) { } @@ -939,51 +938,50 @@ namespace MWGui mRepeatStepTime = step; } - void MWScrollBar::updateTime(float dt) + void MWScrollBar::repeatClick(MyGUI::Widget* _widget, MyGUI::ControllerItem* _controller) { - if(!mEnableRepeat) - return; - - if(mStepDecrease > 0) + if(mIsIncreasing && mScrollPosition < mScrollRange-1) { - mStepDecrease -= dt; - if(mStepDecrease <= 0 && mScrollPosition > 0) - { - mScrollPosition -= 1; - eventScrollChangePosition(this, mScrollPosition); - mStepDecrease += mRepeatStepTime; - } + mScrollPosition += 1; + eventScrollChangePosition(this, mScrollPosition); } - if(mStepIncrease > 0) + else if(!mIsIncreasing && mScrollPosition > 0) { - mStepIncrease -= dt; - if(mStepIncrease <= 0 && mScrollPosition < mScrollRange-1) - { - mScrollPosition += 1; - eventScrollChangePosition(this, mScrollPosition); - mStepIncrease += mRepeatStepTime; - } + mScrollPosition -= 1; + eventScrollChangePosition(this, mScrollPosition); } } void MWScrollBar::onDecreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id) { - mStepDecrease = mRepeatTriggerTime; + mIsIncreasing = false; + MyGUI::ControllerItem* item = MyGUI::ControllerManager::getInstance().createItem(MWGui::Controllers::ControllerRepeatClick::getClassTypeName()); + MWGui::Controllers::ControllerRepeatClick* controller = item->castType(); + controller->eventRepeatClick += newDelegate(this, &MWScrollBar::repeatClick); + controller->setEnabled(mEnableRepeat); + controller->setRepeat(mRepeatTriggerTime, mRepeatStepTime); + MyGUI::ControllerManager::getInstance().addItem(this, controller); } void MWScrollBar::onDecreaseButtonReleased(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id) { - mStepDecrease = 0; + MyGUI::ControllerManager::getInstance().removeItem(this); } void MWScrollBar::onIncreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id) { - mStepIncrease = mRepeatTriggerTime; + mIsIncreasing = true; + MyGUI::ControllerItem* item = MyGUI::ControllerManager::getInstance().createItem(MWGui::Controllers::ControllerRepeatClick::getClassTypeName()); + MWGui::Controllers::ControllerRepeatClick* controller = item->castType(); + controller->eventRepeatClick += newDelegate(this, &MWScrollBar::repeatClick); + controller->setEnabled(mEnableRepeat); + controller->setRepeat(mRepeatTriggerTime, mRepeatStepTime); + MyGUI::ControllerManager::getInstance().addItem(this, controller); } void MWScrollBar::onIncreaseButtonReleased(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id) { - mStepIncrease = 0; + MyGUI::ControllerManager::getInstance().removeItem(this); } } } diff --git a/apps/openmw/mwgui/widgets.hpp b/apps/openmw/mwgui/widgets.hpp index 362746ae2..1630ab3c9 100644 --- a/apps/openmw/mwgui/widgets.hpp +++ b/apps/openmw/mwgui/widgets.hpp @@ -3,6 +3,7 @@ #include "../mwworld/esmstore.hpp" #include "../mwmechanics/stat.hpp" +#include "controllers.hpp" #include #include @@ -415,22 +416,21 @@ namespace MWGui public: MWScrollBar(); + virtual ~MWScrollBar(); void setEnableRepeat(bool enable); bool getEnableRepeat(); void getRepeat(float &trigger, float &step); void setRepeat(float trigger, float step); - void updateTime(float dt); protected: - virtual ~MWScrollBar(); virtual void initialiseOverride(); + void repeatClick(MyGUI::Widget* _widget, MyGUI::ControllerItem* _controller); bool mEnableRepeat; float mRepeatTriggerTime; float mRepeatStepTime; - float mStepDecrease; - float mStepIncrease; + bool mIsIncreasing; private: void onDecreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id); diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 06fb96c12..f20f03611 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -146,6 +146,8 @@ namespace MWGui BookPage::registerMyGUIComponents (); ItemView::registerComponents(); + MyGUI::FactoryManager::getInstance().registerFactory("Controller"); + MyGUI::FactoryManager::getInstance().registerFactory("Resource", "ResourceImageSetPointer"); MyGUI::ResourceManager::getInstance().load("core.xml"); From 26bd2a5301d5b75e70c7c21f0abff4546bd5899c Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Fri, 5 Jul 2013 20:28:46 +0200 Subject: [PATCH 09/10] use the new scrollbar; range dependent step size; fix --- apps/openmw/mwgui/widgets.cpp | 46 +++++++++++++++++++---- apps/openmw/mwgui/widgets.hpp | 3 ++ files/mygui/openmw_chargen_race.layout | 2 +- files/mygui/openmw_count_window.layout | 2 +- files/mygui/openmw_dialogue_window.layout | 2 +- files/mygui/openmw_edit.skin.xml | 2 +- files/mygui/openmw_edit_effect.layout | 8 ++-- files/mygui/openmw_list.skin.xml | 4 +- files/mygui/openmw_map_window_skin.xml | 4 +- files/mygui/openmw_scroll_skin.xml | 4 +- files/mygui/openmw_settings_window.layout | 22 +++++------ 11 files changed, 67 insertions(+), 32 deletions(-) diff --git a/apps/openmw/mwgui/widgets.cpp b/apps/openmw/mwgui/widgets.cpp index d147b28b1..c57630f08 100644 --- a/apps/openmw/mwgui/widgets.cpp +++ b/apps/openmw/mwgui/widgets.cpp @@ -899,6 +899,7 @@ namespace MWGui : mEnableRepeat(true) , mRepeatTriggerTime(0.5) , mRepeatStepTime(0.1) + , mStepSize(0) { } @@ -908,12 +909,18 @@ namespace MWGui void MWScrollBar::initialiseOverride() { - Base::initialiseOverride(); + ScrollBar::initialiseOverride(); - mWidgetStart->eventMouseButtonPressed += MyGUI::newDelegate(this, &MWScrollBar::onDecreaseButtonPressed); - mWidgetStart->eventMouseButtonReleased += MyGUI::newDelegate(this, &MWScrollBar::onDecreaseButtonReleased); - mWidgetEnd->eventMouseButtonPressed += MyGUI::newDelegate(this, &MWScrollBar::onIncreaseButtonPressed); - mWidgetEnd->eventMouseButtonReleased += MyGUI::newDelegate(this, &MWScrollBar::onIncreaseButtonReleased); + if(mWidgetStart) + { + mWidgetStart->eventMouseButtonPressed += MyGUI::newDelegate(this, &MWScrollBar::onDecreaseButtonPressed); + mWidgetStart->eventMouseButtonReleased += MyGUI::newDelegate(this, &MWScrollBar::onDecreaseButtonReleased); + } + if(mWidgetEnd) + { + mWidgetEnd->eventMouseButtonPressed += MyGUI::newDelegate(this, &MWScrollBar::onIncreaseButtonPressed); + mWidgetEnd->eventMouseButtonReleased += MyGUI::newDelegate(this, &MWScrollBar::onIncreaseButtonReleased); + } } void MWScrollBar::setEnableRepeat(bool enable) @@ -938,17 +945,42 @@ namespace MWGui mRepeatStepTime = step; } + void MWScrollBar::setStepSize(int step) + { + mStepSize = step; + } + + int MWScrollBar::getStepSize() + { + return mStepSize; + } + void MWScrollBar::repeatClick(MyGUI::Widget* _widget, MyGUI::ControllerItem* _controller) { + int stepSize = mStepSize; + if(stepSize == 0) + stepSize = mScrollRange/20; + if(mIsIncreasing && mScrollPosition < mScrollRange-1) { - mScrollPosition += 1; + if(mScrollPosition + stepSize > mScrollRange-1) + mScrollPosition = mScrollRange-1; + else + mScrollPosition += stepSize; + eventScrollChangePosition(this, mScrollPosition); + updateTrack(); } else if(!mIsIncreasing && mScrollPosition > 0) { - mScrollPosition -= 1; + int newPos = mScrollPosition - stepSize; + if(newPos < 0) + mScrollPosition = 0; + else + mScrollPosition -= stepSize; + eventScrollChangePosition(this, mScrollPosition); + updateTrack(); } } diff --git a/apps/openmw/mwgui/widgets.hpp b/apps/openmw/mwgui/widgets.hpp index 1630ab3c9..136056bf4 100644 --- a/apps/openmw/mwgui/widgets.hpp +++ b/apps/openmw/mwgui/widgets.hpp @@ -422,6 +422,8 @@ namespace MWGui bool getEnableRepeat(); void getRepeat(float &trigger, float &step); void setRepeat(float trigger, float step); + void setStepSize(int step); + int getStepSize(); protected: virtual void initialiseOverride(); @@ -431,6 +433,7 @@ namespace MWGui float mRepeatTriggerTime; float mRepeatStepTime; bool mIsIncreasing; + int mStepSize; private: void onDecreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id); diff --git a/files/mygui/openmw_chargen_race.layout b/files/mygui/openmw_chargen_race.layout index c569abb86..55dbe3218 100644 --- a/files/mygui/openmw_chargen_race.layout +++ b/files/mygui/openmw_chargen_race.layout @@ -14,7 +14,7 @@ - + diff --git a/files/mygui/openmw_count_window.layout b/files/mygui/openmw_count_window.layout index 5812ec7fd..4e24277af 100644 --- a/files/mygui/openmw_count_window.layout +++ b/files/mygui/openmw_count_window.layout @@ -16,7 +16,7 @@ - + diff --git a/files/mygui/openmw_dialogue_window.layout b/files/mygui/openmw_dialogue_window.layout index 46090d000..a314ba312 100644 --- a/files/mygui/openmw_dialogue_window.layout +++ b/files/mygui/openmw_dialogue_window.layout @@ -10,7 +10,7 @@ - + diff --git a/files/mygui/openmw_edit.skin.xml b/files/mygui/openmw_edit.skin.xml index da21385e2..1f14f6f66 100644 --- a/files/mygui/openmw_edit.skin.xml +++ b/files/mygui/openmw_edit.skin.xml @@ -45,7 +45,7 @@ - + diff --git a/files/mygui/openmw_edit_effect.layout b/files/mygui/openmw_edit_effect.layout index cad22c064..fa1e58b9d 100644 --- a/files/mygui/openmw_edit_effect.layout +++ b/files/mygui/openmw_edit_effect.layout @@ -31,7 +31,7 @@ - + @@ -39,7 +39,7 @@ - + @@ -56,7 +56,7 @@ - + @@ -72,7 +72,7 @@ - + diff --git a/files/mygui/openmw_list.skin.xml b/files/mygui/openmw_list.skin.xml index a5065c7ca..d680f80d2 100644 --- a/files/mygui/openmw_list.skin.xml +++ b/files/mygui/openmw_list.skin.xml @@ -120,7 +120,7 @@ - + @@ -150,7 +150,7 @@ - + diff --git a/files/mygui/openmw_map_window_skin.xml b/files/mygui/openmw_map_window_skin.xml index 13f18c6d3..2f5bb4faf 100644 --- a/files/mygui/openmw_map_window_skin.xml +++ b/files/mygui/openmw_map_window_skin.xml @@ -5,7 +5,7 @@ - - + + diff --git a/files/mygui/openmw_scroll_skin.xml b/files/mygui/openmw_scroll_skin.xml index 1b94f0c29..76e22c69f 100644 --- a/files/mygui/openmw_scroll_skin.xml +++ b/files/mygui/openmw_scroll_skin.xml @@ -4,12 +4,12 @@ - + - + diff --git a/files/mygui/openmw_settings_window.layout b/files/mygui/openmw_settings_window.layout index 3c65bb690..b4ac8a247 100644 --- a/files/mygui/openmw_settings_window.layout +++ b/files/mygui/openmw_settings_window.layout @@ -15,7 +15,7 @@ - + @@ -30,7 +30,7 @@ - + @@ -64,35 +64,35 @@ - + - + - + - + - + @@ -117,7 +117,7 @@ - + @@ -182,7 +182,7 @@ - + @@ -207,7 +207,7 @@ - + @@ -215,7 +215,7 @@ - + From 76d95dffb658e3fe93d53df31c92e9f0b199971e Mon Sep 17 00:00:00 2001 From: greye Date: Fri, 5 Jul 2013 23:52:46 +0400 Subject: [PATCH 10/10] special case for loading StartScript records --- apps/openmw/mwworld/store.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apps/openmw/mwworld/store.hpp b/apps/openmw/mwworld/store.hpp index b49569f24..4ccd0e689 100644 --- a/apps/openmw/mwworld/store.hpp +++ b/apps/openmw/mwworld/store.hpp @@ -273,6 +273,14 @@ namespace MWWorld mStatic[scpt.mId] = scpt; } + template <> + inline void Store::load(ESM::ESMReader &esm, const std::string &id) { + ESM::StartScript s; + s.load(esm); + s.mId = Misc::StringUtils::toLower(s.mScript); + mStatic[s.mId] = s; + } + template <> class Store : public StoreBase {