Skip to content

Interface: a screen that is up has the focus, as the original's (isFocused) - #169

Open
MortenLyhr wants to merge 1 commit into
bssth:masterfrom
MortenLyhr:fix/interface-focus
Open

MortenLyhr wants to merge 1 commit into
bssth:masterfrom
MortenLyhr:fix/interface-focus

Conversation

@MortenLyhr

Copy link
Copy Markdown
Contributor

OpenCiv4's CvInterface::isFocused() was a stub that always returned false. The game core uses it to hold back the map's controls while a screen is up: CvGame::canDoControl lets the unit cycles, the camera, quick save and load, the globe and ending the turn run only when nothing has the focus. Its note in CvDLLWidgetData::doUnitModel says "if a screen is up". So with the city screen or an advisor up, those keys still ran:

  • W (Cycle Units, Alt) and Return (Cycle Units) closed the city screen and selected a unit;
  • Shift+F5 saved the game from under the city screen or an advisor.

In the original (seen in Wine, BtS 3.19) W and Shift+F5 do nothing on the city screen or under an advisor, and Return on the city screen only leaves it.

Now isFocused() is true while the city screen or a script's own screen (an advisor, the Civilopedia, a movie) is up. The city screen counts because CvMainInterface.py asks not isFocused() or isCityScreenUp() for its own keys there. Popups and the diplomacy screen don't count; the core asks isDiploOrPopupWaiting for those. Whether a script's screen is up is read once a frame on the main thread, because the core also calls isFocused during the turn's work. Return on the city screen leaves it, as Esc does. --keys gains %- for F11 to test the globe.

Wine (original) / OpenCiv4
W on the city screen, before
W on the city screen, after
Return on the city screen, before
Return on the city screen, after
Wine: Shift+F5 under an advisor / on the map

Checks

  • Scripted keys on the TestMap (Roma's city screen, the Financial Advisor, the map): W, Return, Shift+F5 and F11 now do what Wine does (F11 under a screen is assumed from the same check). On the map they still cycle units, quick save and show the globe.
  • ctest 15/15.
  • Checksum at turn 100 (--turns 100 --map Fractal --size STANDARD --seed 7): D7D43800, unchanged.
  • Conflicts only by being next to the bundle 4 lines in Interface.h (Bundle 4/6: the options screen #148–Bundle 6/6: screens and advisors #150): keep both.

🤖 Generated with Claude Code

CvInterface::isFocused was a stub that said no, so with the city screen or
an advisor up the map's controls still ran: W (Cycle Units, Alt) and
Return (Cycle Units) closed the city screen and selected a unit, and
Shift+F5 saved the game from under the city screen or the Financial
Advisor. In the original (seen in Wine) W and Shift+F5 do nothing there,
and Return on the city screen only leaves it. The game core holds back
those controls itself when isFocused says so (CvGame::canDoControl; its
note in CvDLLWidgetData::doUnitModel: "if a screen is up"), and
CvMainInterface.py treats the city screen as focused ("not isFocused() or
isCityScreenUp()").

isFocused now says yes while the city screen or a script's own screen (an
advisor, the Civilopedia, a movie) is up; popups and diplomacy are not
counted, the core asks isDiploOrPopupWaiting for them. Which screen is up
is asked once a frame on the main thread, since the core also asks
isFocused during the turn's work. Return on the city screen leaves it, as
Esc. --keys gets "%-" for F11 (the globe) to test it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant