Skip to content

Commit

Permalink
new proxy screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Piglit committed Aug 30, 2024
1 parent d787489 commit 357958b
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
87 changes: 87 additions & 0 deletions src/menus/serverCreationScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,3 +658,90 @@ void ServerCampaignScreen::update(float delta)
}
}
}

ProxyJoinScreen::ProxyJoinScreen()
{
new GuiOverlay(this, "", colorConfig.background);
(new GuiOverlay(this, "", glm::u8vec4{255,255,255,255}))->setTextureTiled("gui/background/crosses.png");

auto container = new GuiElement(this, "");
container->setPosition(0,0,sp::Alignment::Center)->setSize(350+510+50+50+50, 370+50+50)->setAttribute("layout", "horizontal");
auto panel = new GuiPanel(container, "");
panel->setPosition(50 ,50, sp::Alignment::TopLeft)->setSize(350, 280);

// ship creation panel
auto ship_content = new GuiElement(panel, "");
ship_content->setMargins(25)->setPosition(0, 0)->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax)->setAttribute("layout", "vertical");
ship_content->setAttribute("layout", "vertical");
ship_content->setAttribute("alignment", "topleft");

(new GuiLabel(ship_content, "SHIP_CONFIG_LABEL", tr("Ship configuration"), 30))->addBackground()->setSize(GuiElement::GuiSizeMax, 50);
// Ship type selection
(new GuiLabel(ship_content, "SELECT_SHIP_LABEL", tr("Select ship type:"), 30))->setSize(GuiElement::GuiSizeMax, 50);

ship_template_selector = new GuiSelector(ship_content, "CREATE_SHIP_SELECTOR", nullptr);

// List only ships with templates designated for player use.
std::vector<string> template_names = campaign_client->getShips();

for(string& template_name : template_names)
{
P<ShipTemplate> ship_template = ShipTemplate::getTemplate(template_name);
ship_template_selector->addEntry(template_name + " (" + ship_template->getClass() + ": " + ship_template->getSubClass() + ")", template_name);
}
ship_template_selector->setSelectionIndex(0);
ship_template_selector->setSize(GuiElement::GuiSizeMax, 50);

// Ship drive selection

(new GuiLabel(ship_content, "SELECT_DRIVE_LABEL", tr("Select drive type:"), 30))->setSize(GuiElement::GuiSizeMax, 50);

ship_drive_selector = new GuiSelector(ship_content, "SHIP_DRIVE_SELECTOR", nullptr);
ship_drive_selector->addEntry("Jump drive", "jump");
ship_drive_selector->addEntry("Warp drive", "warp");
ship_drive_selector->setSelectionIndex(0);
ship_drive_selector->setSize(GuiElement::GuiSizeMax, 50);

// Spawn a ship of the selected template near 0,0 and give it a random heading.
ship_create_button = new GuiButton(ship_content, "CREATE_SHIP_BUTTON", tr("Create ship"), [this]() {
ship_create_button->disable();
string response = proxySpawn(ship_template_selector->getSelectionValue(), ship_drive_selector->getSelectionValue());
// my_player_info->commandSetShipId(ship->getMultiplayerId());
});
ship_create_button->setPosition(20, 20, sp::Alignment::TopLeft)->setSize(GuiElement::GuiSizeMax, 50);
}

string ProxyJoinScreen::proxySpawn(string templ, string drive)
{
string callsign = PreferencesManager::get("shipname", "");
string instance = PreferencesManager::get("instance_name", "");
string password = PreferencesManager::get("password", "");
string script = "getScriptStorage.players.onProxySpawn(\""
+ script + "\", \""
+ instance + "\", \""
+ callsign + "\", \""
+ templ + "\", \""
+ drive + "\", \""
+ password + "\")";

string server = PreferencesManager::get("proxy_addr");
string path = "/exec.lua";
sp::io::http::Request request(server, 8080); // XXX Port is hardcoded!
// request.setHeader("Content-Type", "application/json");

LOG(INFO) << "Sending Http request: " << server << ":8080" << path;

sp::io::http::Request::Response response;
response = request.request("get", path, script);
// warning: this will block until response is received
// start this function in a thread to avoid blocking
if (!response.success)
{
LOG(WARNING) << "Http request failed. (status " << response.status << ")";
}else{
LOG(INFO) << "Response:" << response.body;
return response.body;
}
return "";
}

12 changes: 11 additions & 1 deletion src/menus/serverCreationScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,15 @@ class ServerCampaignScreen: public GuiCanvas, Updatable
std::map<string, string> score;
};


class ProxyJoinScreen: public GuiCanvas//, Updatable
{
private:
GuiSelector* ship_template_selector;
GuiSelector* ship_drive_selector;
GuiButton* ship_create_button;
public:
ProxyJoinScreen();
//virtual void update(float delta) override;
string proxySpawn(string templ, string drive);
};
#endif//SERVER_CREATION_SCREEN_H

0 comments on commit 357958b

Please sign in to comment.