Remember window positions

actorid
scrawl 11 years ago
parent 5f1878eb54
commit f695deb29d

@ -37,10 +37,6 @@ namespace MWGui
, mPreviewDirty(true) , mPreviewDirty(true)
, mDragAndDrop(dragAndDrop) , mDragAndDrop(dragAndDrop)
, mSelectedItem(-1) , mSelectedItem(-1)
, mPositionInventory(0, 342, 498, 258)
, mPositionContainer(0, 342, 498, 258)
, mPositionCompanion(0, 342, 498, 258)
, mPositionBarter(0, 342, 498, 258)
, mGuiMode(GM_Inventory) , mGuiMode(GM_Inventory)
{ {
static_cast<MyGUI::Window*>(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &InventoryWindow::onWindowResize); static_cast<MyGUI::Window*>(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &InventoryWindow::onWindowResize);
@ -71,8 +67,19 @@ namespace MWGui
mFilterAll->setStateSelected(true); mFilterAll->setStateSelected(true);
setCoord(mPositionInventory.left, mPositionInventory.top, mPositionInventory.width, mPositionInventory.height); setGuiMode(mGuiMode);
onWindowResize(static_cast<MyGUI::Window*>(mMainWidget));
adjustPanes();
}
void InventoryWindow::adjustPanes()
{
const float aspect = 0.5; // fixed aspect ratio for the left pane
mLeftPane->setSize( (mMainWidget->getSize().height-44) * aspect, mMainWidget->getSize().height-44 );
mRightPane->setCoord( mLeftPane->getPosition().left + (mMainWidget->getSize().height-44) * aspect + 4,
mRightPane->getPosition().top,
mMainWidget->getSize().width - 12 - (mMainWidget->getSize().height-44) * aspect - 15,
mMainWidget->getSize().height-44 );
} }
void InventoryWindow::updatePlayer() void InventoryWindow::updatePlayer()
@ -87,27 +94,36 @@ namespace MWGui
void InventoryWindow::setGuiMode(GuiMode mode) void InventoryWindow::setGuiMode(GuiMode mode)
{ {
std::string setting = "inventory";
mGuiMode = mode; mGuiMode = mode;
switch(mode) { switch(mode) {
case GM_Container: case GM_Container:
setPinButtonVisible(false); setPinButtonVisible(false);
mMainWidget->setCoord(mPositionContainer); setting += " container";
break; break;
case GM_Companion: case GM_Companion:
setPinButtonVisible(false); setPinButtonVisible(false);
mMainWidget->setCoord(mPositionCompanion); setting += " companion";
break; break;
case GM_Barter: case GM_Barter:
setPinButtonVisible(false); setPinButtonVisible(false);
mMainWidget->setCoord(mPositionBarter); setting += " barter";
break; break;
case GM_Inventory: case GM_Inventory:
default: default:
setPinButtonVisible(true); setPinButtonVisible(true);
mMainWidget->setCoord(mPositionInventory);
break; break;
} }
onWindowResize(static_cast<MyGUI::Window*>(mMainWidget));
MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize();
MyGUI::IntPoint pos (Settings::Manager::getFloat(setting + " x", "Windows") * viewSize.width,
Settings::Manager::getFloat(setting + " y", "Windows") * viewSize.height);
MyGUI::IntSize size (Settings::Manager::getFloat(setting + " w", "Windows") * viewSize.width,
Settings::Manager::getFloat(setting + " h", "Windows") * viewSize.height);
mMainWidget->setPosition(pos);
mMainWidget->setSize(size);
adjustPanes();
mPreviewDirty = true;
} }
TradeItemModel* InventoryWindow::getTradeModel() TradeItemModel* InventoryWindow::getTradeModel()
@ -256,32 +272,37 @@ namespace MWGui
mItemView->update(); mItemView->update();
notifyContentChanged(); notifyContentChanged();
adjustPanes();
} }
void InventoryWindow::onWindowResize(MyGUI::Window* _sender) void InventoryWindow::onWindowResize(MyGUI::Window* _sender)
{ {
const float aspect = 0.5; // fixed aspect ratio for the left pane adjustPanes();
mLeftPane->setSize( (_sender->getSize().height-44) * aspect, _sender->getSize().height-44 ); std::string setting = "inventory";
mRightPane->setCoord( mLeftPane->getPosition().left + (_sender->getSize().height-44) * aspect + 4,
mRightPane->getPosition().top,
_sender->getSize().width - 12 - (_sender->getSize().height-44) * aspect - 15,
_sender->getSize().height-44 );
switch(mGuiMode) { switch(mGuiMode) {
case GM_Container: case GM_Container:
mPositionContainer = _sender->getCoord(); setting += " container";
break; break;
case GM_Companion: case GM_Companion:
mPositionCompanion = _sender->getCoord(); setting += " companion";
break; break;
case GM_Barter: case GM_Barter:
mPositionBarter = _sender->getCoord(); setting += " barter";
break; break;
case GM_Inventory:
default: default:
mPositionInventory = _sender->getCoord(); break;
} }
MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize();
float x = _sender->getPosition().left / float(viewSize.width);
float y = _sender->getPosition().top / float(viewSize.height);
float w = _sender->getSize().width / float(viewSize.width);
float h = _sender->getSize().height / float(viewSize.height);
Settings::Manager::setFloat(setting + " x", "Windows", x);
Settings::Manager::setFloat(setting + " y", "Windows", y);
Settings::Manager::setFloat(setting + " w", "Windows", w);
Settings::Manager::setFloat(setting + " h", "Windows", h);
if (mMainWidget->getSize().width != mLastXSize || mMainWidget->getSize().height != mLastYSize) if (mMainWidget->getSize().width != mLastXSize || mMainWidget->getSize().height != mLastYSize)
{ {
mLastXSize = mMainWidget->getSize().width; mLastXSize = mMainWidget->getSize().width;

@ -76,11 +76,6 @@ namespace MWGui
MyGUI::Button* mFilterMagic; MyGUI::Button* mFilterMagic;
MyGUI::Button* mFilterMisc; MyGUI::Button* mFilterMisc;
MyGUI::IntCoord mPositionInventory;
MyGUI::IntCoord mPositionContainer;
MyGUI::IntCoord mPositionCompanion;
MyGUI::IntCoord mPositionBarter;
GuiMode mGuiMode; GuiMode mGuiMode;
int mLastXSize; int mLastXSize;
@ -105,6 +100,8 @@ namespace MWGui
void updateEncumbranceBar(); void updateEncumbranceBar();
void notifyContentChanged(); void notifyContentChanged();
void adjustPanes();
}; };
} }

@ -154,10 +154,6 @@ namespace MWGui
size.width = mFixedWidth; size.width = mFixedWidth;
size.height = 100; // dummy size.height = 100; // dummy
MyGUI::IntCoord coord;
coord.left = 10; // dummy
coord.top = 10; // dummy
mMessageWidget->setSize(size); mMessageWidget->setSize(size);
MyGUI::IntSize textSize = mMessageWidget->getTextSize(); MyGUI::IntSize textSize = mMessageWidget->getTextSize();

@ -37,6 +37,8 @@ namespace MWGui
void setBounty (int bounty) { if (bounty != mBounty) mChanged = true; this->mBounty = bounty; } void setBounty (int bounty) { if (bounty != mBounty) mChanged = true; this->mBounty = bounty; }
void updateSkillArea(); void updateSkillArea();
virtual void open() { onWindowResize(static_cast<MyGUI::Window*>(mMainWidget)); }
private: private:
void addSkills(const SkillList &skills, const std::string &titleId, const std::string &titleDefault, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); void addSkills(const SkillList &skills, const std::string &titleId, const std::string &titleDefault, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2);
void addSeparator(MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); void addSeparator(MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2);

@ -203,16 +203,22 @@ namespace MWGui
mRecharge = new Recharge(); mRecharge = new Recharge();
mMenu = new MainMenu(w,h); mMenu = new MainMenu(w,h);
mMap = new MapWindow(""); mMap = new MapWindow("");
trackWindow(mMap, "map");
mStatsWindow = new StatsWindow(); mStatsWindow = new StatsWindow();
trackWindow(mStatsWindow, "stats");
mConsole = new Console(w,h, mConsoleOnlyScripts); mConsole = new Console(w,h, mConsoleOnlyScripts);
trackWindow(mConsole, "console");
mJournal = JournalWindow::create(JournalViewModel::create ()); mJournal = JournalWindow::create(JournalViewModel::create ());
mMessageBoxManager = new MessageBoxManager(); mMessageBoxManager = new MessageBoxManager();
mInventoryWindow = new InventoryWindow(mDragAndDrop); mInventoryWindow = new InventoryWindow(mDragAndDrop);
mTradeWindow = new TradeWindow(); mTradeWindow = new TradeWindow();
trackWindow(mTradeWindow, "barter");
mSpellBuyingWindow = new SpellBuyingWindow(); mSpellBuyingWindow = new SpellBuyingWindow();
mTravelWindow = new TravelWindow(); mTravelWindow = new TravelWindow();
mDialogueWindow = new DialogueWindow(); mDialogueWindow = new DialogueWindow();
trackWindow(mDialogueWindow, "dialogue");
mContainerWindow = new ContainerWindow(mDragAndDrop); mContainerWindow = new ContainerWindow(mDragAndDrop);
trackWindow(mContainerWindow, "container");
mHud = new HUD(w,h, mShowFPSLevel, mDragAndDrop); mHud = new HUD(w,h, mShowFPSLevel, mDragAndDrop);
mToolTips = new ToolTips(); mToolTips = new ToolTips();
mScrollWindow = new ScrollWindow(); mScrollWindow = new ScrollWindow();
@ -221,7 +227,9 @@ namespace MWGui
mSettingsWindow = new SettingsWindow(); mSettingsWindow = new SettingsWindow();
mConfirmationDialog = new ConfirmationDialog(); mConfirmationDialog = new ConfirmationDialog();
mAlchemyWindow = new AlchemyWindow(); mAlchemyWindow = new AlchemyWindow();
trackWindow(mAlchemyWindow, "alchemy");
mSpellWindow = new SpellWindow(); mSpellWindow = new SpellWindow();
trackWindow(mSpellWindow, "spells");
mQuickKeysMenu = new QuickKeysMenu(); mQuickKeysMenu = new QuickKeysMenu();
mLevelupDialog = new LevelupDialog(); mLevelupDialog = new LevelupDialog();
mWaitDialog = new WaitDialog(); mWaitDialog = new WaitDialog();
@ -232,6 +240,7 @@ namespace MWGui
mRepair = new Repair(); mRepair = new Repair();
mSoulgemDialog = new SoulgemDialog(mMessageBoxManager); mSoulgemDialog = new SoulgemDialog(mMessageBoxManager);
mCompanionWindow = new CompanionWindow(mDragAndDrop, mMessageBoxManager); mCompanionWindow = new CompanionWindow(mDragAndDrop, mMessageBoxManager);
trackWindow(mCompanionWindow, "companion");
mInputBlocker = mGui->createWidget<MyGUI::Widget>("",0,0,w,h,MyGUI::Align::Default,"Windows",""); mInputBlocker = mGui->createWidget<MyGUI::Widget>("",0,0,w,h,MyGUI::Align::Default,"Windows","");
@ -926,6 +935,17 @@ namespace MWGui
mLoadingScreen->onResChange (x,y); mLoadingScreen->onResChange (x,y);
if (!mHud) if (!mHud)
return; // UI not initialized yet return; // UI not initialized yet
for (std::map<MyGUI::Window*, std::string>::iterator it = mTrackedWindows.begin(); it != mTrackedWindows.end(); ++it)
{
MyGUI::IntPoint pos (Settings::Manager::getFloat(it->second + " x", "Windows") * x,
Settings::Manager::getFloat(it->second+ " y", "Windows") * y);
MyGUI::IntSize size (Settings::Manager::getFloat(it->second + " w", "Windows") * x,
Settings::Manager::getFloat(it->second + " h", "Windows") * y);
it->first->setPosition(pos);
it->first->setSize(size);
}
mHud->onResChange(x, y); mHud->onResChange(x, y);
mConsole->onResChange(x, y); mConsole->onResChange(x, y);
mMenu->onResChange(x, y); mMenu->onResChange(x, y);
@ -1364,4 +1384,35 @@ namespace MWGui
return mCursorVisible; return mCursorVisible;
} }
void WindowManager::trackWindow(OEngine::GUI::Layout *layout, const std::string &name)
{
MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize();
MyGUI::IntPoint pos (Settings::Manager::getFloat(name + " x", "Windows") * viewSize.width,
Settings::Manager::getFloat(name + " y", "Windows") * viewSize.height);
MyGUI::IntSize size (Settings::Manager::getFloat(name + " w", "Windows") * viewSize.width,
Settings::Manager::getFloat(name + " h", "Windows") * viewSize.height);
layout->mMainWidget->setPosition(pos);
layout->mMainWidget->setSize(size);
MyGUI::Window* window = dynamic_cast<MyGUI::Window*>(layout->mMainWidget);
if (!window)
throw std::runtime_error("Attempting to track size of a non-resizable window");
window->eventWindowChangeCoord += MyGUI::newDelegate(this, &WindowManager::onWindowChangeCoord);
mTrackedWindows[window] = name;
}
void WindowManager::onWindowChangeCoord(MyGUI::Window *_sender)
{
std::string setting = mTrackedWindows[_sender];
MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize();
float x = _sender->getPosition().left / float(viewSize.width);
float y = _sender->getPosition().top / float(viewSize.height);
float w = _sender->getSize().width / float(viewSize.width);
float h = _sender->getSize().height / float(viewSize.height);
Settings::Manager::setFloat(setting + " x", "Windows", x);
Settings::Manager::setFloat(setting + " y", "Windows", y);
Settings::Manager::setFloat(setting + " w", "Windows", w);
Settings::Manager::setFloat(setting + " h", "Windows", h);
}
} }

@ -16,6 +16,7 @@ namespace MyGUI
{ {
class Gui; class Gui;
class Widget; class Widget;
class Window;
class UString; class UString;
} }
@ -283,6 +284,10 @@ namespace MWGui
private: private:
bool mConsoleOnlyScripts; bool mConsoleOnlyScripts;
std::map<MyGUI::Window*, std::string> mTrackedWindows;
void trackWindow(OEngine::GUI::Layout* layout, const std::string& name);
void onWindowChangeCoord(MyGUI::Window* _sender);
OEngine::GUI::MyGUIManager *mGuiManager; OEngine::GUI::MyGUIManager *mGuiManager;
OEngine::Render::OgreRenderer *mRendering; OEngine::Render::OgreRenderer *mRendering;
HUD *mHud; HUD *mHud;

@ -2,7 +2,7 @@
<MyGUI type="Layout"> <MyGUI type="Layout">
<Widget type="ExposedWindow" skin="MW_Window_Pinnable" layer="Windows" position="0 0 500 342" name="_Main"> <Widget type="ExposedWindow" skin="MW_Window_Pinnable" layer="Windows" position="0 0 500 342" name="_Main">
<Property key="MinSize" value="500 342"/> <Property key="MinSize" value="300 200"/>
<Widget type="Widget" skin="" name="LeftPane" position="0 0 220 342"> <Widget type="Widget" skin="" name="LeftPane" position="0 0 220 342">

@ -169,3 +169,69 @@ ui y multiplier = 1.0
[Game] [Game]
# Always use the most powerful attack when striking with a weapon (chop, slash or thrust) # Always use the most powerful attack when striking with a weapon (chop, slash or thrust)
best attack = false best attack = false
[Windows]
inventory x = 0
inventory y = 0.4275
inventory w = 0.6225
inventory h = 0.5725
inventory container x = 0
inventory container y = 0.4275
inventory container w = 0.6225
inventory container h = 0.5725
inventory barter x = 0
inventory barter y = 0.4275
inventory barter w = 0.6225
inventory barter h = 0.5725
inventory companion x = 0
inventory companion y = 0.4275
inventory companion w = 0.6225
inventory companion h = 0.5725
container x = 0.25
container y = 0
container w = 0.75
container h = 0.375
companion x = 0.25
companion y = 0
companion w = 0.75
companion h = 0.375
map x = 0.625
map y = 0
map w = 0.375
map h = 0.5725
barter x = 0.25
barter y = 0
barter w = 0.75
barter h = 0.375
alchemy x = 0.25
alchemy y = 0.25
alchemy w = 0.5
alchemy h = 0.5
stats x = 0
stats y = 0
stats w = 0.375
stats h = 0.4275
spells x = 0.3775
spells y = 0.4275
spells w = 0.375
spells h = 0.5725
console x = 0
console y = 0
console w = 1
console h = 0.5
dialogue h = 0.810
dialogue w = 0.810
dialogue x = 0.095
dialogue y = 0.095

@ -150,10 +150,10 @@ namespace GUI
MyGUI::IntSize size = button->getTextSize(); MyGUI::IntSize size = button->getTextSize();
button->setSize(size.width + 24, button->getSize().height); button->setSize(size.width + 24, button->getSize().height);
} }
MyGUI::Widget* mMainWidget;
protected: protected:
MyGUI::Widget* mMainWidget;
std::string mPrefix; std::string mPrefix;
std::string mLayoutName; std::string mLayoutName;
MyGUI::VectorWidgetPtr mListWindowRoot; MyGUI::VectorWidgetPtr mListWindowRoot;

Loading…
Cancel
Save