Skip to content

Commit

Permalink
Merge remote-tracking branch 'scrawl/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
zinnschlag committed Mar 28, 2014
2 parents 7026a0c + d7df9ca commit 2c21062
Show file tree
Hide file tree
Showing 42 changed files with 765 additions and 542 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -132,6 +132,7 @@ set(OENGINE_OGRE

set(OENGINE_GUI
${LIBDIR}/openengine/gui/manager.cpp
${LIBDIR}/openengine/gui/layout.hpp
)

set(OENGINE_BULLET
Expand Down
2 changes: 1 addition & 1 deletion apps/openmw/CMakeLists.txt
Expand Up @@ -33,7 +33,7 @@ add_openmw_dir (mwgui
merchantrepair repair soulgemdialog companionwindow bookpage journalviewmodel journalbooks
keywordsearch itemmodel containeritemmodel inventoryitemmodel sortfilteritemmodel itemview
tradeitemmodel companionitemmodel pickpocketitemmodel fontloader controllers savegamedialog
recharge
recharge mode videowidget
)

add_openmw_dir (mwdialogue
Expand Down
28 changes: 25 additions & 3 deletions apps/openmw/engine.cpp
Expand Up @@ -339,6 +339,9 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
std::string aa = settings.getString("antialiasing", "Video");
windowSettings.fsaa = (aa.substr(0, 4) == "MSAA") ? aa.substr(5, aa.size()-5) : "0";

SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS,
settings.getBool("minimize on focus loss", "Video") ? "1" : "0");

mOgre->createWindow("OpenMW", windowSettings);

Bsa::registerResources (mFileCollections, mArchives, true, mFSStrict);
Expand All @@ -356,6 +359,16 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
mCfgMgr.getCachePath ().string(), mScriptConsoleMode, mTranslationDataStorage, mEncoding);
mEnvironment.setWindowManager (window);

// Create sound system
mEnvironment.setSoundManager (new MWSound::SoundManager(mUseSound));

if (!mSkipMenu)
{
std::string logo = mFallbackMap["Movies_Company_Logo"];
if (!logo.empty())
window->playVideo(logo, 1);
}

// Create the world
mEnvironment.setWorld( new MWWorld::World (*mOgre, mFileCollections, mContentFiles,
mResDir, mCfgMgr.getCachePath(), mEncoder, mFallbackMap,
Expand All @@ -373,9 +386,6 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)

Compiler::registerExtensions (mExtensions);

// Create sound system
mEnvironment.setSoundManager (new MWSound::SoundManager(mUseSound));

// Create script system
mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full);
mScriptContext->setExtensions (&mExtensions);
Expand Down Expand Up @@ -434,7 +444,19 @@ void OMW::Engine::go()

// start in main menu
if (!mSkipMenu)
{
MWBase::Environment::get().getWindowManager()->pushGuiMode (MWGui::GM_MainMenu);
try
{
// Is there an ini setting for this filename or something?
MWBase::Environment::get().getSoundManager()->streamMusic("Special/morrowind title.mp3");

std::string logo = mFallbackMap["Movies_Morrowind_Logo"];
if (!logo.empty())
MWBase::Environment::get().getWindowManager()->playVideo(logo, true);
}
catch (...) {}
}
else
MWBase::Environment::get().getStateManager()->newGame (true);

Expand Down
2 changes: 1 addition & 1 deletion apps/openmw/mwbase/inputmanager.hpp
Expand Up @@ -25,7 +25,7 @@ namespace MWBase

virtual ~InputManager() {}

virtual void update(float dt, bool loading) = 0;
virtual void update(float dt, bool disableControls, bool disableEvents=false) = 0;

virtual void changeInputMode(bool guiMode) = 0;

Expand Down
2 changes: 1 addition & 1 deletion apps/openmw/mwbase/mechanicsmanager.hpp
Expand Up @@ -156,7 +156,7 @@ namespace MWBase
/// paused we may want to do it manually (after equipping permanent enchantment)
virtual void updateMagicEffects (const MWWorld::Ptr& ptr) = 0;

virtual void toggleAI() = 0;
virtual bool toggleAI() = 0;
virtual bool isAIActive() = 0;

virtual void getObjectsInRange (const Ogre::Vector3& position, float radius, std::vector<MWWorld::Ptr>& objects) = 0;
Expand Down
4 changes: 4 additions & 0 deletions apps/openmw/mwbase/windowmanager.hpp
Expand Up @@ -96,6 +96,10 @@ namespace MWBase
*/
virtual void update() = 0;

/// @note This method will block until the video finishes playing
/// (and will continually update the window while doing so)
virtual void playVideo(const std::string& name, bool allowSkipping) = 0;

virtual void setNewGame(bool newgame) = 0;

virtual void pushGuiMode (MWGui::GuiMode mode) = 0;
Expand Down
2 changes: 0 additions & 2 deletions apps/openmw/mwbase/world.hpp
Expand Up @@ -420,8 +420,6 @@ namespace MWBase
virtual MWRender::Animation* getAnimation(const MWWorld::Ptr &ptr) = 0;

/// \todo this does not belong here
virtual void playVideo(const std::string& name, bool allowSkipping) = 0;
virtual void stopVideo() = 0;
virtual void frameStarted (float dt, bool paused) = 0;
virtual void screenshot (Ogre::Image& image, int w, int h) = 0;

Expand Down
2 changes: 1 addition & 1 deletion apps/openmw/mwgui/loadingscreen.cpp
Expand Up @@ -226,7 +226,7 @@ namespace MWGui
}
mSceneMgr->setSpecialCaseRenderQueueMode(Ogre::SceneManager::SCRQM_EXCLUDE);

MWBase::Environment::get().getInputManager()->update(0, true);
MWBase::Environment::get().getInputManager()->update(0, true, true);

// First, swap buffers from last draw, then, queue an update of the
// window contents, but don't swap buffers (which would have
Expand Down
105 changes: 97 additions & 8 deletions apps/openmw/mwgui/mainmenu.cpp
Expand Up @@ -13,6 +13,7 @@
#include "../mwstate/character.hpp"

#include "savegamedialog.hpp"
#include "confirmationdialog.hpp"

namespace MWGui
{
Expand All @@ -21,12 +22,13 @@ namespace MWGui
: OEngine::GUI::Layout("openmw_mainmenu.layout")
, mButtonBox(0), mWidth (w), mHeight (h)
, mSaveGameDialog(NULL)
, mBackground(NULL)
{
getWidget(mVersionText, "VersionText");
std::stringstream sstream;
sstream << "OpenMW version: " << OPENMW_VERSION;

// adding info about git hash if availible
// adding info about git hash if available
std::string rev = OPENMW_VERSION_COMMITHASH;
std::string tag = OPENMW_VERSION_TAGHASH;
if (!rev.empty() && !tag.empty())
Expand Down Expand Up @@ -58,10 +60,24 @@ namespace MWGui
{
if (visible)
updateMenu();
else
showBackground(
MWBase::Environment::get().getWindowManager()->containsMode(MWGui::GM_MainMenu) &&
MWBase::Environment::get().getStateManager()->getState() == MWBase::StateManager::State_NoGame);

OEngine::GUI::Layout::setVisible (visible);
}

void MainMenu::onNewGameConfirmed()
{
MWBase::Environment::get().getStateManager()->newGame();
}

void MainMenu::onExitConfirmed()
{
MWBase::Environment::get().getStateManager()->requestQuit();
}

void MainMenu::onButtonClicked(MyGUI::Widget *sender)
{
std::string name = *sender->getUserData<std::string>();
Expand All @@ -73,11 +89,33 @@ namespace MWGui
}
else if (name == "options")
MWBase::Environment::get().getWindowManager ()->pushGuiMode (GM_Settings);
else if (name == "credits")
MWBase::Environment::get().getWindowManager()->playVideo("mw_credits.bik", true);
else if (name == "exitgame")
MWBase::Environment::get().getStateManager()->requestQuit();
{
if (MWBase::Environment::get().getStateManager()->getState() == MWBase::StateManager::State_NoGame)
onExitConfirmed();
else
{
ConfirmationDialog* dialog = MWBase::Environment::get().getWindowManager()->getConfirmationDialog();
dialog->open("#{sMessage2}");
dialog->eventOkClicked.clear();
dialog->eventOkClicked += MyGUI::newDelegate(this, &MainMenu::onExitConfirmed);
dialog->eventCancelClicked.clear();
}
}
else if (name == "newgame")
{
MWBase::Environment::get().getStateManager()->newGame();
if (MWBase::Environment::get().getStateManager()->getState() == MWBase::StateManager::State_NoGame)
onNewGameConfirmed();
else
{
ConfirmationDialog* dialog = MWBase::Environment::get().getWindowManager()->getConfirmationDialog();
dialog->open("#{sNotifyMessage54}");
dialog->eventOkClicked.clear();
dialog->eventOkClicked += MyGUI::newDelegate(this, &MainMenu::onNewGameConfirmed);
dialog->eventCancelClicked.clear();
}
}

else
Expand All @@ -92,18 +130,51 @@ namespace MWGui
}
}

void MainMenu::showBackground(bool show)
{
if (mBackground)
{
MyGUI::Gui::getInstance().destroyWidget(mBackground);
mBackground = NULL;
}
if (show)
{
if (!mBackground)
{
mBackground = MyGUI::Gui::getInstance().createWidgetReal<MyGUI::ImageBox>("ImageBox", 0,0,1,1,
MyGUI::Align::Stretch, "Menu");
mBackground->setImageTexture("black.png");

// Use black bars to correct aspect ratio. The video player also does it, so we need to do it
// for mw_logo.bik to align correctly with menu_morrowind.dds.
MyGUI::IntSize screenSize = MyGUI::RenderManager::getInstance().getViewSize();

// No way to un-hardcode this right now, menu_morrowind.dds is 1024x512 but was designed for 4:3
double imageaspect = 4.0/3.0;

int leftPadding = std::max(0.0, (screenSize.width - screenSize.height * imageaspect) / 2);
int topPadding = std::max(0.0, (screenSize.height - screenSize.width / imageaspect) / 2);

MyGUI::ImageBox* image = mBackground->createWidget<MyGUI::ImageBox>("ImageBox",
leftPadding, topPadding, screenSize.width - leftPadding*2, screenSize.height - topPadding*2, MyGUI::Align::Default);
image->setImageTexture("textures\\menu_morrowind.dds");
}
}
}

void MainMenu::updateMenu()
{
setCoord(0,0, mWidth, mHeight);


if (!mButtonBox)
mButtonBox = mMainWidget->createWidget<MyGUI::Widget>("", MyGUI::IntCoord(0, 0, 0, 0), MyGUI::Align::Default);

int curH = 0;

MWBase::StateManager::State state = MWBase::Environment::get().getStateManager()->getState();

showBackground(state == MWBase::StateManager::State_NoGame);

std::vector<std::string> buttons;

if (state==MWBase::StateManager::State_Running)
Expand All @@ -120,7 +191,10 @@ namespace MWGui
buttons.push_back("savegame");

buttons.push_back("options");
//buttons.push_back("credits");

if (state==MWBase::StateManager::State_NoGame)
buttons.push_back("credits");

buttons.push_back("exitgame");

// Create new buttons if needed
Expand Down Expand Up @@ -155,12 +229,27 @@ namespace MWGui
assert(mButtons.find(*it) != mButtons.end());
MWGui::ImageButton* button = mButtons[*it];
button->setVisible(true);

MyGUI::IntSize requested = button->getRequestedSize();
button->setCoord((maxwidth-requested.width) / 2, curH, requested.width, requested.height);
curH += requested.height;

// Trim off some of the excessive padding
// TODO: perhaps do this within ImageButton?
int trim = 8;
button->setImageCoord(MyGUI::IntCoord(0, trim, requested.width, requested.height-trim));
int height = requested.height-trim*2;
button->setImageTile(MyGUI::IntSize(requested.width, height));
button->setCoord((maxwidth-requested.width) / 2, curH, requested.width, height);
curH += height;
}

mButtonBox->setCoord (mWidth/2 - maxwidth/2, mHeight/2 - curH/2, maxwidth, curH);
if (state == MWBase::StateManager::State_NoGame)
{
// Align with the background image
int bottomPadding=48;
mButtonBox->setCoord (mWidth/2 - maxwidth/2, mHeight - curH - bottomPadding, maxwidth, curH);
}
else
mButtonBox->setCoord (mWidth/2 - maxwidth/2, mHeight/2 - curH/2, maxwidth, curH);

}
}
6 changes: 6 additions & 0 deletions apps/openmw/mwgui/mainmenu.hpp
Expand Up @@ -29,9 +29,15 @@ namespace MWGui
MyGUI::Widget* mButtonBox;
MyGUI::TextBox* mVersionText;

MyGUI::ImageBox* mBackground;

std::map<std::string, MWGui::ImageButton*> mButtons;

void onButtonClicked (MyGUI::Widget* sender);
void onNewGameConfirmed();
void onExitConfirmed();

void showBackground(bool show);

void updateMenu();

Expand Down
4 changes: 1 addition & 3 deletions apps/openmw/mwgui/mode.hpp
Expand Up @@ -47,9 +47,7 @@ namespace MWGui
GM_Loading,
GM_LoadingWallpaper,

GM_QuickKeysMenu,

GM_Video
GM_QuickKeysMenu
};

// Windows shown in inventory mode
Expand Down
27 changes: 25 additions & 2 deletions apps/openmw/mwgui/savegamedialog.cpp
Expand Up @@ -86,7 +86,21 @@ namespace MWGui
{
std::stringstream title;
title << it->getSignature().mPlayerName;
title << " (Level " << it->getSignature().mPlayerLevel << " " << it->getSignature().mPlayerClass << ")";

// For a custom class, we will not find it in the store (unless we loaded the savegame first).
// Fall back to name stored in savegame header in that case.
std::string className;
if (it->getSignature().mPlayerClassId.empty())
className = it->getSignature().mPlayerClassName;
else
{
// Find the localised name for this class from the store
const ESM::Class* class_ = MWBase::Environment::get().getWorld()->getStore().get<ESM::Class>().find(
it->getSignature().mPlayerClassId);
className = class_->mName;
}

title << " (Level " << it->getSignature().mPlayerLevel << " " << className << ")";

mCharacterSelection->addItem (title.str());

Expand Down Expand Up @@ -169,7 +183,10 @@ namespace MWGui
else
{
if (mCurrentCharacter && slot)
{
MWBase::Environment::get().getStateManager()->loadGame (mCurrentCharacter, slot);
MWBase::Environment::get().getWindowManager()->removeGuiMode (MWGui::GM_MainMenu);
}
}

setVisible(false);
Expand Down Expand Up @@ -241,7 +258,13 @@ namespace MWGui
struct tm* timeinfo;
timeinfo = localtime(&time);

text << asctime(timeinfo) << "\n";
// Use system/environment locale settings for datetime formatting
std::setlocale(LC_TIME, "");

const int size=1024;
char buffer[size];
if (std::strftime(buffer, size, "%x %X", timeinfo) > 0)
text << buffer << "\n";
text << "Level " << slot->mProfile.mPlayerLevel << "\n";
text << slot->mProfile.mPlayerCell << "\n";
// text << "Time played: " << slot->mProfile.mTimePlayed << "\n";
Expand Down

0 comments on commit 2c21062

Please sign in to comment.