UI: doube-click planets to open production screen

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Post Reply
Message
Author
User avatar
The Silent One
Graphics
Posts: 1129
Joined: Tue Jul 01, 2003 8:27 pm

UI: doube-click planets to open production screen

#1 Post by The Silent One »

I'm trying to implement the "planet doubleclick opens production screen" feature, but I'm stuck. My basic idea was to take inspiration / copy from how double-clicking systems works, and that didn't look too hard at first:

Code: Select all

- MapWnd.h: declaration of function SystemDoubleClicked
- MapWnd.cpp:
    - LeftDoubleClickedSignal of system icon(s) is connected to the SystemDoubleClicked function (while initialising MapWnd)
    - SystemDoubleClicked function opens production screen
- SystemIcon.h:
    - declare/fetch boost-signal LeftDoubleClickedSignal (?)
- SystemIcon.cpp:
    - LDoubleClick calls LeftDoubleClickedSignal
Unfortunately, things are more complicated in sidepanel.cpp. Here I find
- the SidePanel
- the PlanetPanel and
- the PlanetPanelContainer,
and all of them seem to need their own code to allow left-doubleclicking of a planet.
I gave it a try, repeating the following for every class:

- declare boost-signal:
boost::signals2::signal<void (int)> SidePanel::PlanetLeftDoubleClickedSignal;
- bind signal to function in constructor:
GG::Connect(m_planet_panel_container->PlanetLeftDoubleClickedSignal, &SidePanel::PlanetDoubleClicked, this);
- write dummy funcion that reports when it has been called:
void PlanetDoubleClicked(int planet_id) [...]

I'm not sure what I'm doing wrong, everything compiles fine, but the PlanetDoubleClicked function does not get executed. Basically I do not understand how I detect that a planet(-panel) has been doubleclicked so I can then execute a function that opens the production screen.
Help would be appreciated :wink:
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

Re: UI: doube-click planets to open production screen

#2 Post by Dilvish »

The Silent One wrote:Help would be appreciated :wink:
I would suggest you follow the existing code for simple left or right clicking on a planet in the side panel-- it already tracks that and you can change which planet counts as currently selected, such as for the Production Window, even when the production window is closed. The naming used for the series of rightclick signals probably mirrors the one you'll want for double-clicking better, so you might want to follow that line.

Follow the line carefully, there are several connections to be made, from PlanetPanel to SidePanel and then over in MapWnd.cpp as well (I think that is the point at which you would actually open the ProductionWnd).

besides the connections, be sure to look at the multiple places that PlanetRightClickedSignal is referenced (and the two different declarations, one for SidePanel and one for PlanetPanelContainer), within SidePanel.h and SidePanel.cpp (it looks to me like you were a little skimpy with PlanetLeftDoubleClickedSignal)
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
The Silent One
Graphics
Posts: 1129
Joined: Tue Jul 01, 2003 8:27 pm

Re: UI: doube-click planets to open production screen

#3 Post by The Silent One »

Dilvish wrote:
The Silent One wrote:Help would be appreciated :wink:
I would suggest you follow the existing code for simple left or right clicking on a planet in the side panel-- it already tracks that and you can change which planet counts as currently selected, such as for the Production Window, even when the production window is closed.
That's what I did (following the code for left-clicking a planet), ... guess I'll try again in a few days (following right-clicking).
Thanks.
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

Re: UI: doube-click planets to open production screen

#4 Post by Dilvish »

The Silent One wrote:That's what I did (following the code for left-clicking a planet), ... guess I'll try again in a few days (following right-clicking).
Yeah, following the LeftClicks should have worked fine as well (although they it does have a somewhat different pattern of declarations for some reason not immediately apparent to me). If you still have any trouble, post it (in whatever you feel is the best version you have) as a PR to my fork and I'll try to help you finish it off.
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
The Silent One
Graphics
Posts: 1129
Joined: Tue Jul 01, 2003 8:27 pm

Re: UI: doube-click planets to open production screen

#5 Post by The Silent One »

Dilvish wrote:Yeah, following the LeftClicks should have worked fine as well (although they it does have a somewhat different pattern of declarations for some reason not immediately apparent to me). If you still have any trouble, post it (in whatever you feel is the best version you have) as a PR to my fork and I'll try to help you finish it off.
Thanks, I appreciate it. The whole signal thing didn't leave me alone, so I got back to it today, and I got it working! :)
Pull request: https://github.com/freeorion/freeorion/pull/194

One question: what setting do I need to change in VC2013 so it creates "spaces" instead of one "tabulator"? Hope it's understandable what I mean.
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: UI: doube-click planets to open production screen

#6 Post by Geoff the Medio »

The Silent One wrote:One question: what setting do I need to change in VC2013 so it creates "spaces" instead of one "tabulator"?
Tools -> Options -> Text Editor -> All Languages -> Tabs -> Tab -> Tab Size (4) and check Insert Spaces. Alternatively, set just in the C/C++ section.

User avatar
The Silent One
Graphics
Posts: 1129
Joined: Tue Jul 01, 2003 8:27 pm

Re: UI: doube-click planets to open production screen

#7 Post by The Silent One »

Thanks!
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

User avatar
MatGB
Creative Contributor
Posts: 3310
Joined: Fri Jun 28, 2013 11:45 pm

Re: UI: doube-click planets to open production screen

#8 Post by MatGB »

Just an observation, when you said you wanted to do this I was a bit meh, can't see the point of that. It took me 5 minutes playing with it to consider it one of the best features ever, especially with the new colonising mechanics, brilliant.
Mat Bowles

Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

User avatar
The Silent One
Graphics
Posts: 1129
Joined: Tue Jul 01, 2003 8:27 pm

Re: UI: doube-click planets to open production screen

#9 Post by The Silent One »

Glad you like it!
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

Post Reply