Skip to content

Commit d22b703

Browse files
authored
Disambiguate GuiOpenCommsButton states in UI (#2677)
* Manage, display comms state in GuiOpenCommsButton - Change the button text to indicate why the button is disabled. This reduces ambiguity about why the "Open comms" button is disabled while on Strategic Map when comms are engaged outside of its view. - Hide the "Open comms" button entirely if the ship lacks a CommsTransmitter. * Use layout container for Relay functions on Ops To accommodate hiding the comms button on Ops when a ship lacks a CommsTransmitter component, use a layout container for waypoint and comms buttons.
1 parent 9405eaf commit d22b703

File tree

5 files changed

+45
-34
lines changed

5 files changed

+45
-34
lines changed
Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,39 @@
11
#include "openCommsButton.h"
2-
2+
#include <i18n.h>
33
#include "targetsContainer.h"
44
#include "playerInfo.h"
55
#include "components/comms.h"
66

77

8-
GuiOpenCommsButton::GuiOpenCommsButton(GuiContainer* owner, string id, string name, TargetsContainer* targets)
8+
GuiOpenCommsButton::GuiOpenCommsButton(GuiContainer* owner, string id, string name, TargetsContainer* targets, bool allow_comms)
99
: GuiButton(owner, id, name, [this]() {
1010
if (my_spaceship && this->targets->get())
1111
my_player_info->commandOpenTextComm(this->targets->get());
12-
}), targets(targets)
12+
}), targets(targets), allow_comms(allow_comms)
1313
{
1414
}
1515

1616
void GuiOpenCommsButton::onDraw(sp::RenderTarget& renderer)
1717
{
1818
disable();
19+
// Indicate the comms state on the comms button, or hide the button if this
20+
// ship lacks a comms transmitter.
1921
auto transmitter = my_spaceship.getComponent<CommsTransmitter>();
20-
if (transmitter && transmitter->state == CommsTransmitter::State::Inactive)
22+
setVisible(transmitter);
23+
if (transmitter && isVisible())
2124
{
22-
auto target = targets->get();
23-
if (target.hasComponent<CommsReceiver>() || target.hasComponent<CommsTransmitter>())
24-
enable();
25+
if (transmitter->state == CommsTransmitter::State::Inactive)
26+
{
27+
auto target = targets->get();
28+
if (target.hasComponent<CommsReceiver>() || target.hasComponent<CommsTransmitter>())
29+
{
30+
enable();
31+
setText(allow_comms ? tr("Open comms") : tr("Link to comms"));
32+
}
33+
else setText(tr("No comms target"));
34+
}
35+
else setText(tr("Transmitting..."));
2536
}
37+
2638
GuiButton::onDraw(renderer);
2739
}
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#ifndef OPEN_COMMS_BUTTON_H
2-
#define OPEN_COMMS_BUTTON_H
1+
#pragma once
32

43
#include "gui/gui2_button.h"
54

@@ -8,10 +7,10 @@ class TargetsContainer;
87
class GuiOpenCommsButton : public GuiButton
98
{
109
TargetsContainer* targets;
10+
private:
11+
bool allow_comms = true;
1112
public:
12-
GuiOpenCommsButton(GuiContainer* owner, string id, string name, TargetsContainer* targets);
13+
GuiOpenCommsButton(GuiContainer* owner, string id, string name, TargetsContainer* targets, bool allow_comms = true);
1314

1415
virtual void onDraw(sp::RenderTarget& target) override;
1516
};
16-
17-
#endif//OPEN_COMMS_BUTTON_H

src/screens/crew4/operationsScreen.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,29 @@ OperationScreen::OperationScreen(GuiContainer* owner)
7272
);
7373
science->science_radar->setAutoRotating(PreferencesManager::get("operations_radar_lock","0")=="1");
7474

75-
(new GuiOpenCommsButton(science->radar_view, "OPEN_COMMS_BUTTON", tr("Open Comms"), &science->targets))->setPosition(-270, -20, sp::Alignment::BottomRight)->setSize(200, 50);
75+
// Limited relay functions: comms and waypoints.
76+
GuiElement* relay_functions = new GuiElement(science->radar_view, "RELAY_FUNCTIONS");
77+
relay_functions
78+
->setPosition(-270.0f, -20.0f, sp::Alignment::BottomRight)
79+
->setSize(200.0f, 150.0f)
80+
->setAttribute("layout", "verticalbottom");
81+
82+
// Manage comms.
83+
(new GuiOpenCommsButton(relay_functions, "OPEN_COMMS_BUTTON", tr("Open comms"), &science->targets))
84+
->setSize(200.0f, 50.0f);
7685

7786
// Manage waypoints.
78-
place_waypoint_button = new GuiButton(science->radar_view, "WAYPOINT_PLACE_BUTTON", tr("Place Waypoint"), [this]() {
79-
mode = WaypointPlacement;
80-
});
81-
place_waypoint_button->setPosition(-270, -70, sp::Alignment::BottomRight)->setSize(200, 50);
87+
place_waypoint_button = new GuiButton(relay_functions, "WAYPOINT_PLACE_BUTTON", tr("Place waypoint"), [this]() { mode = WaypointPlacement; });
88+
place_waypoint_button->setSize(200.0f, 50.0f);
8289

83-
delete_waypoint_button = new GuiButton(science->radar_view, "WAYPOINT_DELETE_BUTTON", tr("Delete Waypoint"), [this]() {
84-
if (my_spaceship && science->targets.getWaypointIndex() >= 0)
90+
delete_waypoint_button = new GuiButton(relay_functions, "WAYPOINT_DELETE_BUTTON", tr("Delete waypoint"),
91+
[this]()
8592
{
86-
my_player_info->commandRemoveWaypoint(science->targets.getWaypointIndex());
93+
if (my_spaceship && science->targets.getWaypointIndex() >= 0)
94+
my_player_info->commandRemoveWaypoint(science->targets.getWaypointIndex());
8795
}
88-
});
89-
delete_waypoint_button->setPosition(-270, -120, sp::Alignment::BottomRight)->setSize(200, 50);
96+
);
97+
delete_waypoint_button->setSize(200.0f, 50.0f);
9098

9199
auto stats = new GuiElement(this, "OPERATIONS_STATS");
92100
stats->setPosition(20, 60, sp::Alignment::TopLeft)->setSize(240, 80)->setAttribute("layout", "vertical");

src/screens/crew6/relayScreen.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static bool canHack(sp::ecs::Entity entity)
3636
}
3737

3838
RelayScreen::RelayScreen(GuiContainer* owner, bool allow_comms)
39-
: GuiOverlay(owner, "RELAY_SCREEN", colorConfig.background), mode(TargetSelection)
39+
: GuiOverlay(owner, "RELAY_SCREEN", colorConfig.background)
4040
{
4141
targets.setAllowWaypointSelection();
4242
radar = new GuiRadarView(this, "RELAY_RADAR", 50000.0f, &targets);
@@ -114,11 +114,7 @@ RelayScreen::RelayScreen(GuiContainer* owner, bool allow_comms)
114114
option_buttons->setPosition(20, 50, sp::Alignment::TopLeft)->setSize(250, GuiElement::GuiSizeMax)->setAttribute("layout", "vertical");
115115

116116
// Open comms button.
117-
if (allow_comms == true)
118-
(new GuiOpenCommsButton(option_buttons, "OPEN_COMMS_BUTTON", tr("Open Comms"), &targets))->setSize(GuiElement::GuiSizeMax, 50);
119-
else
120-
(new GuiOpenCommsButton(option_buttons, "OPEN_COMMS_BUTTON", tr("Link to Comms"), &targets))->setSize(GuiElement::GuiSizeMax, 50);
121-
117+
(new GuiOpenCommsButton(option_buttons, "OPEN_COMMS_BUTTON", tr("Open comms"), &targets, allow_comms))->setSize(GuiElement::GuiSizeMax, 50);
122118

123119
// Hack target
124120
hack_target_button = new GuiButton(option_buttons, "HACK_TARGET", tr("Start hacking"), [this](){

src/screens/crew6/relayScreen.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#ifndef RELAY_SCREEN_H
2-
#define RELAY_SCREEN_H
1+
#pragma once
32

43
#include "screenComponents/targetsContainer.h"
54
#include "gui/gui2_overlay.h"
@@ -21,9 +20,8 @@ class RelayScreen : public GuiOverlay
2120
WaypointPlacement,
2221
LaunchProbe,
2322
MoveWaypoint
24-
};
23+
} mode = TargetSelection;
2524

26-
EMode mode;
2725
TargetsContainer targets;
2826
int drag_waypoint_index;
2927
GuiRadarView* radar;
@@ -51,5 +49,3 @@ class RelayScreen : public GuiOverlay
5149

5250
virtual void onDraw(sp::RenderTarget& target) override;
5351
};
54-
55-
#endif//RELAY_SCREEN_H

0 commit comments

Comments
 (0)