Skip to content
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
wants to merge 21 commits into from

Conversation

mel-odious
Copy link
Owner

TODO

  • [done] Add most (if not all) non-self-positioning CUIWnd subclasses
    • (-> list them somewhere)
  • [done] Change CUIWnd subclass ctors to take default_x, default_y, default_w, default_h parameters
    • and/or add CUIWnd::SetDefaults() function?
  • [done] Make windows go to the top of the z-order when activated via toolbar button
  • [done] Add option descriptions to stringtable
  • [done] Auto-reposition windows in response to windowed/fullscreen changes based on their stored OptionsDB values
  • [done] Disable CUIWnd::SaveOptions() whilst move-dragging or resize-dragging a CUIWnd
  • [done] Make remembering visibility actually work
  • [minimizing is currently broken, this doesn't make it any worse at least] Make sure that it interacts with minimizing correctly (if there are any plans to actually enable that for any windows?)
  • [awkward, modal windows would be missed, can already delete the section from config.xml or (new) specify -w on the command line] Add button to OptionsWnd to reset all window properties.
  • [done] Make sure only one window can use a name at any given time.
    • Can't call Remove() in ~CUIWnd() because then the properties won't be saved. Static CUIWnd set?
  • [belongs in a different branch] Make parented CUIWnds move to top of parent's z-order on LButtonDown()

Considering:

  • Only add options to the DB if they are relevant (e.g. don't add "pinned" if the window isn't pinable). Need to make sure that options are added if these properties are changed! I know at least pinning a window will modify m_resizable...
    • Could make these private & use getters/setters which make sure options are added, so subclasses can't accidentally break this.
    • It's only a "cosmetic" change so that windows don't have irrelevant options listed in config.xml, might be too much work to justify it. It could possibly prevent user confusion?

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 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 mel-odious force-pushed the remember-window-positions-c3 branch from 4ab3754 to 6aaeec2 Compare July 10, 2015 05:46
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.
@mel-odious
Copy link
Owner Author

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.

@mel-odious mel-odious closed this Jul 15, 2015
@mel-odious mel-odious deleted the remember-window-positions-c3 branch July 15, 2015 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants