forked from freeorion/freeorion
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Remember window positions in OptionsDB #1
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add functions SaveOptions(), LoadOptions() and static AddWindowOptions() (to be called from AddOptions() ) to CUIWnd. Implement the feature for SitRepPanel, which involves calling AddWindowOptions() with the desired name for the window in the config file (UI.windows.[name].left etc.) and supplying the constructor with that same name. The window will then save & load its position, visibility etc. under that name. Make GG::Wnd::Hide() virtual so that CUIWnd can override it and call SaveOptions().
mel-odious
changed the title
Remember window positions in OptionsDB
[WIP] Remember window positions in OptionsDB
Jul 10, 2015
EncyclopediaDetailPanel, ObjectListWnd, CombatReportWnd and ModeratorActionsWnd now have position and other properties saved in the config file and are preserved between executions. Rename width/height parameters in their ctors to reflect that they will be overridden by any values present in the config. Make CUIWnd::AddWindowOptions() non-static and call it from the CUIWnd ctor rather than RegisterOptions(). Make CUIWnd::m_config_name const. Allowing it to change would just introduce extra bookkeeping and doesn't seem useful. Rearrange CUIWnd ctor to make sure LoadOptions() is called after InitButtons() to prevent potential crash (calling functions on uninitialized button objects).
Add bool CUIWnd::m_config_save. When false, prevents SaveOptions() from writing to the OptionsDB, so LoadOptions() can temporarily call SizeMove() etc. without triggering SaveOptions().
...when activating them from the toolbar. Prevents the map scale line overlapping those windows now that they aren't always in the same position on game load, plus it makes those functions more consistent.
...like other top-level CUIWnds owned by MapWnd, i.e. don't repeatedly Register() and Remove() them but just rely on Show() and Hide(), calling MoveUp() on them when they are shown. Haven't noticed any issues with doing so, if there are any obscure problems this commit can be ignored.
mel-odious
force-pushed
the
remember-window-positions-c3
branch
from
July 10, 2015 05:46
4ab3754
to
6aaeec2
Compare
Change the ctors for the CUIWnd subclasses which have had position-saving implemented so far to: a) Have the config_name first because most if not all CUIWnds should have a name specified so their properties saved whereas some can use the default position and size. Less commonly used parameters go last. b) Take default x,y,w,h as parameters so they can be set as defaults in ctor without calling MoveTo() etc. on them afterwards (which would override the saved position!) Considering changing the CUIWnd constructor itself to match the above but that would break all other subclass ctor implementations so that will have to wait until they have all been updated to use this feature.
Modify CUIWnd::LButtonDown() to set m_config_save = false and CUIWnd::LButtonUp() to set m_config_save = true, so that the window isn't constantly writing its properties to the config file when the user drags it. It appears that LButtonUp() always gets called eventually, even if the cursor is dragged offscreen (it is called when the cursor is brought back onto the window).
...and allow several top-level CUIWnds to enforce that effectively without being overridden by now-redundant calls to Show()/Hide(). Remove calls to GG::GUI::Register() and CUIWnd::Hide() for some floating map windows in the MapWnd ctor. Delete MapWnd::m_moderator_wnd in MapWnd dtor. Ensure that MapWnd::m_sitrep_panel is updated properly in MapWnd::InitTurn() because the sitrep panel can now be open when a game is started (without the update, the panel wouldn't update itself when loading a game on turn 1). Add MapWnd::RegisterWindows() and ::RemoveWindows() Which are called from the FSM to enable/disable their rendering without affecting their visibility flag. Would be more elegant to parent them to a container GG::Wnd but that causes some issues with mouse events being intercepted... Remove Hide[...]() calls from MapWnd::Cleanup(), the windows can determine their own visibility. Replace Show/Hide calls for message and player list wnds in the HumanClientFSM with calls to Regiter()/Remove(), again in order to avoid overwriting their stored state.
In MapWnd ctor, ensure that the correct images are displayed on the toolbar buttons based on visibility of their respective windows, since those windows remember their own properties and apply them before game start/load. Fix constant name to MAP_PEDIA_WND_NAME.
Update many ctors for CUIWnd-derived classes to be more consistent and support passing a config_name so that they can save their properties to the config file. Add config_names to many CUIWnd-derived wnds, including BuildDesignatorWnd::BuildSelector, SidePanel (in production window), SidePanel (in map view), MessageWnd, PlayerListWnd, DesignWnd::PartPalette, DesignWnd::BaseSelector, DesignWnd::MainPanel, FleetWnd (disabled when multiple fleet window mode is enabled!), MapWndPopup, FilterDialog, OptionsWnd, TechTreeWnd::TechTreeControls... Remove redundant static FleetWnd members. Remove redundant position checking code in FleetWnd::Init() and MapWnd::SelectFleet(). Remove SidePanel cleanup from MapWnd::Sanitize() since the sidepanel now remembers its own properties. Remove OptionsDB options "UI.sidepanel-width", "UI.chat-wnd-width" and "UI.chat-wnd-height" because they are now redundant.
Change "production-[...]" etc. options to "production.[...]" for map, production, research and design options so that they will appear grouped together in XML. Modify a TODO to make a more sensible suggestion.
Add a function to check if a window is being dragged by a certain mouse button. Currently has no bounds checking on the mouse_button parameter, max is 2! Use this function to disable CUIWnd::SaveOptions() when the CUIWnd is being moved/resized by dragging it, instead of using CUIWnd::m_config_save.
...and connect to it in CUIWnd ctor. Add a signal that is sent from HumanClientApp::Reinitialize() when it detects a fullscreen/windowed transition. Can't rely on OptionsDB::OptionChangedSignal("fullscreen") because that can change without actually triggering a video mode change (e.g. user still has to click the apply button in the OptionsWnd) and HumanClientApp::HandleWindowResize() doesn't provide video-mode-change info. Connect this signal to CUIWnd::LoadOptions() in the CUIWnd ctor if config_name is specified so that it automatically loads the new options when switching between fullscreen and windowed modes.
...so that certain windows can specify that they default to being hidden. CombatReportWnd, EncyclopediaDetailPanel, ModeratorActionsWnd and ObjectListWnd now do this, and they are not visible by default when entering a game (but the SitRepPanel is).
...WindowOptions() to take and return a string. CUIWnd::AddWindowOptions() now uses a new OptionsDB option to check if a new CUIWnd should use the config_name it has been provided, and if not, returns an empty string (which means to not save window properties). This allows it to be used to initialize the const m_config_name member without letting two windows have the same m_config_name.
Fixes issues with translated text being too long and getting cut off, user can now make the window wider to show all text. TODO: add automatic text wrapping...
...reset all window properties to their defaults. While checked, the option will cause all current CUIWnds and any new ones to reset their saved values to the defaults (the defaults are calculated when the window is constructed). Change MapWnd ctor to use the default dimensions of the SitRepPanel to calculate defaults for EncyclopediaDetailPanel, instead of the current position of the SitRepPanel.
...temporarily disable m_config_save while it calculates its own height.
...production or design windows are open. Show/Hide Research/Production/Design now call RemoveWindows() and RegisterWindows() instead of calling Show()/Hide() on the map view panels (SitRepPanel, ObjectListWnd etc.), which allows those panels to remember their state. When the panels' toolbar icons are clicked, the production/research/design windows are closed and all of the panels are restored. Add calls to ShowAllPopups() and RemoveWindows() to MapWnd::Cleanup() to ensure that popups don't save ".visible = false" to the config and that windows are properly hidden when entering/leaving a game.
Going to move to a new branch, interactive rebase onto a fresh master and set up a PR on the main fork with the cleaned up commits. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TODO
Make parented CUIWnds move to top of parent's z-order on LButtonDown()Considering: