Commit 92c8a60a authored by Supernature2k's avatar Supernature2k

netplay step 6

parent 59450422
......@@ -50,5 +50,3 @@ CPackSourceConfig.cmake
*.cbp
*.cmake
test_exe
es-app/src/EmulationStation.h
\ No newline at end of file
This diff is collapsed.
......@@ -5,89 +5,83 @@
#include <string>
#include <map>
extern const uint16_t arrow_svg_size;
extern const uint8_t arrow_svg_data[];
extern const uint16_t option_arrow_svg_size;
extern const uint8_t option_arrow_svg_data[];
extern const uint16_t slider_knob_svg_size;
extern const uint8_t slider_knob_svg_data[];
extern const uint16_t fav_remove_svg_size;
extern const uint8_t fav_remove_svg_data[];
extern const uint16_t button_filled_png_size;
extern const uint8_t button_filled_png_data[];
extern const uint16_t on_svg_size;
extern const uint8_t on_svg_data[];
extern const uint16_t frame_png_size;
extern const uint8_t frame_png_data[];
extern const uint16_t star_unfilled_svg_size;
extern const uint8_t star_unfilled_svg_data[];
extern const uint16_t off_svg_size;
extern const uint8_t off_svg_data[];
extern const uint16_t star_unfilled_svg_size;
extern const uint8_t star_unfilled_svg_data[];
extern const uint16_t button_png_size;
extern const uint8_t button_png_data[];
extern const uint16_t textinput_ninepatch_active_png_size;
extern const uint8_t textinput_ninepatch_active_png_data[];
extern const uint16_t checkbox_checked_svg_size;
extern const uint8_t checkbox_checked_svg_data[];
extern const uint16_t splash_svg_size;
extern const uint8_t splash_svg_data[];
extern const uint16_t fav_add_svg_size;
extern const uint8_t fav_add_svg_data[];
extern const uint16_t busy_1_png_size;
extern const uint8_t busy_1_png_data[];
extern const uint16_t busy_0_png_size;
extern const uint8_t busy_0_png_data[];
extern const uint32_t scroll_gradient_png_size;
extern const uint8_t scroll_gradient_png_data[];
extern const uint16_t option_arrow_svg_size;
extern const uint8_t option_arrow_svg_data[];
extern const uint16_t busy_3_png_size;
extern const uint8_t busy_3_png_data[];
extern const uint16_t arrow_svg_size;
extern const uint8_t arrow_svg_data[];
extern const uint16_t button_png_size;
extern const uint8_t button_png_data[];
extern const uint16_t button_filled_png_size;
extern const uint8_t button_filled_png_data[];
extern const uint16_t star_filled_svg_size;
extern const uint8_t star_filled_svg_data[];
extern const uint32_t fontawesome_webfont_ttf_size;
extern const uint8_t fontawesome_webfont_ttf_data[];
extern const uint16_t window_icon_256_png_size;
extern const uint8_t window_icon_256_png_data[];
extern const uint32_t ubuntu_condensed_ttf_size;
extern const uint8_t ubuntu_condensed_ttf_data[];
extern const uint32_t scroll_gradient_png_size;
extern const uint8_t scroll_gradient_png_data[];
extern const uint16_t checkbox_unchecked_svg_size;
extern const uint8_t checkbox_unchecked_svg_data[];
extern const uint16_t busy_2_png_size;
extern const uint8_t busy_2_png_data[];
extern const uint16_t fav_add_svg_size;
extern const uint8_t fav_add_svg_data[];
extern const uint16_t frame_png_size;
extern const uint8_t frame_png_data[];
extern const uint32_t fontawesome_webfont_ttf_size;
extern const uint8_t fontawesome_webfont_ttf_data[];
extern const uint16_t on_svg_size;
extern const uint8_t on_svg_data[];
extern const uint16_t textinput_ninepatch_png_size;
extern const uint8_t textinput_ninepatch_png_data[];
extern const uint16_t busy_0_png_size;
extern const uint8_t busy_0_png_data[];
extern const uint16_t textinput_ninepatch_active_png_size;
extern const uint8_t textinput_ninepatch_active_png_data[];
extern const uint16_t slider_knob_svg_size;
extern const uint8_t slider_knob_svg_data[];
extern const uint16_t busy_3_png_size;
extern const uint8_t busy_3_png_data[];
extern const uint16_t checkbox_unchecked_svg_size;
extern const uint8_t checkbox_unchecked_svg_data[];
extern const uint16_t busy_1_png_size;
extern const uint8_t busy_1_png_data[];
extern const uint16_t help__dpad_leftright_svg_size;
extern const uint8_t help__dpad_leftright_svg_data[];
extern const uint16_t splash_svg_size;
extern const uint8_t splash_svg_data[];
extern const uint16_t help__button_hotkey_svg_size;
extern const uint8_t help__button_hotkey_svg_data[];
extern const uint32_t ubuntu_condensed_ttf_size;
extern const uint8_t ubuntu_condensed_ttf_data[];
extern const uint16_t help__dpad_updown_svg_size;
extern const uint8_t help__dpad_updown_svg_data[];
extern const uint16_t help__button_start_svg_size;
extern const uint8_t help__button_start_svg_data[];
extern const uint16_t help__joystick_left_svg_size;
extern const uint8_t help__joystick_left_svg_data[];
......@@ -95,54 +89,60 @@ extern const uint8_t help__joystick_left_svg_data[];
extern const uint16_t help__dpad_up_svg_size;
extern const uint8_t help__dpad_up_svg_data[];
extern const uint16_t help__button_l_svg_size;
extern const uint8_t help__button_l_svg_data[];
extern const uint16_t help__button_r_svg_size;
extern const uint8_t help__button_r_svg_data[];
extern const uint16_t help__joystick_up_svg_size;
extern const uint8_t help__joystick_up_svg_data[];
extern const uint16_t help__dpad_down_svg_size;
extern const uint8_t help__dpad_down_svg_data[];
extern const uint16_t help__dpad_left_svg_size;
extern const uint8_t help__dpad_left_svg_data[];
extern const uint16_t help__button_hotkey_svg_size;
extern const uint8_t help__button_hotkey_svg_data[];
extern const uint16_t help__button_r2_svg_size;
extern const uint8_t help__button_r2_svg_data[];
extern const uint16_t help__button_x_svg_size;
extern const uint8_t help__button_x_svg_data[];
extern const uint16_t help__button_select_svg_size;
extern const uint8_t help__button_select_svg_data[];
extern const uint16_t help__button_l3_svg_size;
extern const uint8_t help__button_l3_svg_data[];
extern const uint16_t help__button_select_svg_size;
extern const uint8_t help__button_select_svg_data[];
extern const uint16_t help__dpad_leftright_svg_size;
extern const uint8_t help__dpad_leftright_svg_data[];
extern const uint16_t help__button_l2_svg_size;
extern const uint8_t help__button_l2_svg_data[];
extern const uint16_t help__dpad_all_svg_size;
extern const uint8_t help__dpad_all_svg_data[];
extern const uint16_t help__button_r2_svg_size;
extern const uint8_t help__button_r2_svg_data[];
extern const uint16_t help__joystick_up_svg_size;
extern const uint8_t help__joystick_up_svg_data[];
extern const uint16_t help__button_b_svg_size;
extern const uint8_t help__button_b_svg_data[];
extern const uint16_t help__dpad_updown_svg_size;
extern const uint8_t help__dpad_updown_svg_data[];
extern const uint16_t help__dpad_right_svg_size;
extern const uint8_t help__dpad_right_svg_data[];
extern const uint16_t help__button_start_svg_size;
extern const uint8_t help__button_start_svg_data[];
extern const uint16_t help__button_r_svg_size;
extern const uint8_t help__button_r_svg_data[];
extern const uint16_t help__button_l_svg_size;
extern const uint8_t help__button_l_svg_data[];
extern const uint16_t help__button_r3_svg_size;
extern const uint8_t help__button_r3_svg_data[];
extern const uint16_t help__dpad_down_svg_size;
extern const uint8_t help__dpad_down_svg_data[];
extern const uint16_t help__dpad_all_svg_size;
extern const uint8_t help__dpad_all_svg_data[];
extern const uint16_t help__button_a_svg_size;
extern const uint8_t help__button_a_svg_data[];
extern const uint16_t help__button_b_svg_size;
extern const uint8_t help__button_b_svg_data[];
extern const uint16_t help__button_y_svg_size;
extern const uint8_t help__button_y_svg_data[];
......
This diff is collapsed.
......@@ -40,6 +40,7 @@ public:
virtual ~FileData();
inline const std::string& getName() const { return metadata.get("name"); }
inline const std::string& getHash() const { return metadata.get("hash"); }
inline FileType getType() const { return mType; }
inline const boost::filesystem::path& getPath() const { return mPath; }
inline FileData* getParent() const { return mParent; }
......
......@@ -12,6 +12,7 @@ std::vector<MetaDataDecl> folderMDD;
void initMetadata() {
gameMDD.push_back(MetaDataDecl("name", MD_STRING, "", false, true, _("Name"), _("enter game name")));
gameMDD.push_back(MetaDataDecl("hash", MD_STRING, "", false, true, _("hash"), _("enter game hash")));
gameMDD.push_back(MetaDataDecl("rating", MD_RATING, "0.000000", false, true, _("Rating"), _("enter rating")));
gameMDD.push_back(MetaDataDecl("favorite", MD_BOOL, "false", false, true, _("Favorite"), _("enter favorite")));
gameMDD.push_back(MetaDataDecl("hidden", MD_BOOL, "false", false, true, _("Hidden"), _("set hidden")));
......
......@@ -156,7 +156,7 @@ std::string escapePath(const boost::filesystem::path& path)
#endif
}
void SystemData::launchGame(Window* window, FileData* game, std::string netplay)
void SystemData::launchGame(Window* window, FileData* game, std::string netplay, std::string core, std::string ip, std::string port)
{
LOG(LogInfo) << "Attempting to launch game...";
......@@ -176,17 +176,22 @@ void SystemData::launchGame(Window* window, FileData* game, std::string netplay)
const std::string basename = game->getPath().stem().string();
const std::string rom_raw = fs::path(game->getPath()).make_preferred().string();
command = strreplace(command, "%ROM%", rom);
command = strreplace(command, "%CONTROLLERSCONFIG%", controlersConfig);
command = strreplace(command, "%SYSTEM%", game->metadata.get("system"));
command = strreplace(command, "%BASENAME%", basename);
command = strreplace(command, "%ROM_RAW%", rom_raw);
command = strreplace(command, "%EMULATOR%", game->metadata.get("emulator"));
command = strreplace(command, "%CORE%", game->metadata.get("core"));
command = strreplace(command, "%RATIO%", game->metadata.get("ratio"));
command = strreplace(command, "%ROM%", rom);
command = strreplace(command, "%CONTROLLERSCONFIG%", controlersConfig);
command = strreplace(command, "%SYSTEM%", game->metadata.get("system"));
command = strreplace(command, "%BASENAME%", basename);
command = strreplace(command, "%ROM_RAW%", rom_raw);
if (core != "") {
command = strreplace(command, "%EMULATOR%", "libretro");
command = strreplace(command, "%CORE%", core);
} else {
command = strreplace(command, "%EMULATOR%", game->metadata.get("emulator"));
command = strreplace(command, "%CORE%", game->metadata.get("core"));
}
command = strreplace(command, "%RATIO%", game->metadata.get("ratio"));
if (netplay == "client") {
command = strreplace(command, "%NETPLAY%", "-netplay client -netplay_port " + RecalboxConf::getInstance()->get("global.netplay.port"));
command = strreplace(command, "%NETPLAY%", "-netplay client -netplay_port " + port + "netplay_ip " + ip);
} else if (netplay == "host") {
command = strreplace(command, "%NETPLAY%", "-netplay host -netplay_port " + RecalboxConf::getInstance()->get("global.netplay.port"));
} else {
......
......@@ -46,7 +46,7 @@ public:
unsigned int getFavoritesCount() const;
unsigned int getHiddenCount() const;
void launchGame(Window* window, FileData* game, std::string netplay = "");
void launchGame(Window* window, FileData* game, std::string netplay = "", std::string core = "", std::string ip = "", std::string port = "");
static void deleteSystems();
static bool loadConfig(); //Load the system config file at getConfigPath(). Returns true if no errors were encountered. An example will be written if the file doesn't exist.
......
......@@ -2,6 +2,9 @@
// Created by xizor on 20/05/18.
//
#include <RecalboxConf.h>
#include <SystemData.h>
#include <views/ViewController.h>
#include "GuiNetPlay.h"
#include "components/TextComponent.h"
#include "components/ButtonComponent.h"
......@@ -38,20 +41,36 @@ GuiNetPlay::GuiNetPlay(Window* window) : GuiComponent(window),
mGrid.setEntry(mGridMeta, Vector2i(0, 1), true);
mMetaText = std::make_shared<TextComponent>(mWindow, "", menuTheme->menuTextSmall.font, menuTheme->menuTextSmall.color, ALIGN_LEFT);
mMetaText->setVerticalAlignment(ALIGN_TOP);
mLaunchText = std::make_shared<TextComponent>(mWindow, "", menuTheme->menuText.font, menuTheme->menuTextSmall.color, ALIGN_LEFT);
mLaunchText->setVerticalAlignment(ALIGN_BOTTOM);
mGridMeta->setEntry(mLaunchText, Vector2i(1, 0), false, true);
mGridMeta->setEntry(mMetaText, Vector2i(1, 0), false, true, Eigen::Vector2i(1, 1), GridFlags::BORDER_LEFT);
ComponentListRow row;
std::shared_ptr<GuiComponent> ed;
int i = 0;
for (auto v : mRooms) {
row.elements.clear();
ed = std::make_shared<TextComponent>(mWindow, v.second.get<std::string>("fields.game_name"), menuTheme->menuText.font, menuTheme->menuText.color, ALIGN_LEFT);
std::string text;
if (mGames[i]) {
if (mGames[i]->getHash() == v.second.get<std::string>("fields.game_crc")) {
text = "\uf1c0 " + v.second.get<std::string>("fields.game_name");
} else {
text = "\uf1c1 " + v.second.get<std::string>("fields.game_name");
}
} else {
text = "\uf1c2 " + v.second.get<std::string>("fields.game_name");
}
ed = std::make_shared<TextComponent>(mWindow, text, menuTheme->menuText.font, menuTheme->menuText.color, ALIGN_LEFT);
row.addElement(ed, true);
row.makeAcceptInputHandler([this] { launch();});
addRow(row);
i++;
}
populateGridMeta(0);
mList->setCursorChangedCallback([this](CursorState state){populateGridMeta(mList->getCursor());});
mList->setFocusLostCallback([this]{mMetaText->setText("");});
mList->setFocusLostCallback([this]{mMetaText->setText(""); mLaunchText->setText("");});
mList->setFocusGainedCallback([this]{populateGridMeta(mList->getCursor());});
} else {
auto text = std::make_shared<TextComponent>(mWindow, _("NO GAMES OR NO CONNECTION"), menuTheme->menuText.font, menuTheme->menuText.color, ALIGN_CENTER);
......@@ -98,16 +117,43 @@ void GuiNetPlay::populateGridMeta(int i)
text += "\n " + _("Core ver.") + " : " + mRooms[i].second.get<std::string>("fields.core_version", "N/A");
text += "\n " + _("RA ver.") + " : " + mRooms[i].second.get<std::string>("fields.retroarch_version", "N/A");
mMetaText->setText(text);
mMetaText->setVerticalAlignment(ALIGN_TOP);
std::string text2 = " " + _("Can join") + " : ";
if (mGames[i]) {
if (mGames[i]->getHash() == mRooms[i].second.get<std::string>("fields.game_crc")) {
text2 += "Yes";
mLaunchText->setColor(0x26B14AFF);
} else {
text2 += "Maybe";
mLaunchText->setColor(0x36A9E0FF);
}
} else {
text2 += "No";
mLaunchText->setColor(0xDC1F26FF);
}
mLaunchText->setText(text2);
}
void GuiNetPlay::launch()
{
mWindow->pushGui(new GuiMsgBoxScroll(
mWindow, _("NETPLAY"),
mRooms[mList->getCursor()].second.get<std::string>("fields.game_name") + "\n" + mRooms[mList->getCursor()].second.get<std::string>("fields.game_crc"),
_("OK"),
[] {}, "", nullptr, "", nullptr, ALIGN_CENTER));
if (mGames[mList->getCursor()]) {
mWindow->pushGui(new GuiMsgBoxScroll(
mWindow, _("NETPLAY"),
mRooms[mList->getCursor()].second.get<std::string>("fields.game_name") + "\n" + mRooms[mList->getCursor()].second.get<std::string>("fields.game_crc"),
_("OK"),
[] {}, "", nullptr, "", nullptr, ALIGN_CENTER));
}
/*Eigen::Vector3f target(Renderer::getScreenWidth() / 2.0f, Renderer::getScreenHeight() / 2.0f, 0);
int index = mList->getCursor();
std::string core = "";
std::string ip, port;
if (mRooms[index].second.get<std::string>("fields.host_method") == "3") {
ip = mRooms[index].second.get<std::string>("fields.mitm_ip");
port = mRooms[index].second.get<std::string>("fields.mitm_port");
} else {
ip = mRooms[index].second.get<std::string>("fields.ip");
port = mRooms[index].second.get<std::string>("fields.port");
}
ViewController::get()->launch(mGames[index], target, "client", core, ip, port);*/
}
float GuiNetPlay::getButtonGridHeight() const
......@@ -128,7 +174,7 @@ bool GuiNetPlay::input(InputConfig* config, Input input)
void GuiNetPlay::updateSize()
{
const float height = Renderer::getScreenHeight() * 0.7f;
const float width = Renderer::getScreenWidth() * 0.7f;
const float width = Renderer::getScreenWidth() * 0.8f;
setSize(width, height);
}
......@@ -154,7 +200,8 @@ std::vector<HelpPrompt> GuiNetPlay::getHelpPrompts()
bool GuiNetPlay::parseLobby()
{
mRooms.clear();
auto json_req = RecalboxSystem::getInstance()->execute("curl -s http://lobby.libretro.com/list/");
std::string lobby = RecalboxConf::getInstance()->get("global.netplay.lobby");
auto json_req = RecalboxSystem::getInstance()->execute("curl -s " + lobby);
if (json_req.second == 0) {
json::ptree root;
std::stringstream ss;
......@@ -167,10 +214,53 @@ bool GuiNetPlay::parseLobby()
}
for (json::ptree::value_type &array_element : root) {
if (array_element.second.get<std::string>("fields.game_crc") == "00000000") {
mGames.push_back(findGame(array_element.second.get<std::string>("fields.game_name")));
} else {
mGames.push_back(findGame(array_element.second.get<std::string>("fields.game_crc")));
}
mRooms.push_back(array_element);
}
return true;
} else {
return false;
}
}
FileData* GuiNetPlay::findGame(std::string gameNameOrHash)
{
for (auto tmp : SystemData::sSystemVector) {
if (RecalboxConf::getInstance()->isInList("global.netplay.systems", tmp->getName())) {
std::vector<FileData*> games = tmp->getRootFolder()->getChildren();
FileData* result = findRecursive(games, gameNameOrHash);
if (result != NULL) {
std::cout << gameNameOrHash << " found : " << result->getName() << "\n";
return result;
}
}
}
return nullptr;
}
FileData* GuiNetPlay::findRecursive(const std::vector<FileData*>& gameFolder, const std::string& gameNameOrHash, const std::string& relativePath) {
// Recursively look for the game in subfolders too
for (auto game = gameFolder.begin(); game != gameFolder.end(); ++game) {
std::string gameAndPath;
if (relativePath.empty()) {
gameAndPath = (*game)->getPath().stem().c_str();
} else {
gameAndPath = relativePath + '/' + (*game)->getPath().stem().c_str();
}
//LOG(LogInfo) << "Checking game " << gameNameOrHash << " in path: " << gameAndPath;
if ((*game)->getType() == FOLDER) {
FileData* foundGame = findRecursive((*game)->getChildren(), gameNameOrHash, gameAndPath);
if ( foundGame != NULL ) {
return foundGame;
}
}
if ((*game)->getType() == GAME and (gameAndPath == gameNameOrHash or (*game)->getHash() == gameNameOrHash)) {
return *game;
}
}
return NULL;
}
\ No newline at end of file
......@@ -13,6 +13,7 @@
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <recalbox/RecalboxSystem.h>
#include "FileData.h"
namespace json = boost::property_tree;
......@@ -33,7 +34,7 @@ public:
bool input(InputConfig* config, Input input) override;
inline void clear() { mList->clear(); }
inline ~GuiNetPlay() { if (mList) mList->clear(); }
std::vector<HelpPrompt> getHelpPrompts() override;
......@@ -43,6 +44,10 @@ public:
void launch();
FileData* findGame(std::string game);
FileData* findRecursive(const std::vector<FileData*>& gameFolder, const std::string& gameName, const std::string& relativePath = "");
private:
......@@ -60,9 +65,11 @@ private:
std::shared_ptr<ComponentGrid> mButtonGrid;
std::shared_ptr<ComponentList> mList;
std::vector<FileData*> mGames;
std::vector<json::ptree::value_type> mRooms;
std::shared_ptr<TextComponent> mMetaText;
std::shared_ptr<TextComponent> mLaunchText;
};
#endif //EMULATIONSTATION_ALL_GUINETPLAY_H
......@@ -265,7 +265,7 @@ void ViewController::onFileChanged(FileData* file, FileChangeType change)
}
}
void ViewController::launch(FileData* game, Eigen::Vector3f center, std::string netplay)
void ViewController::launch(FileData* game, Eigen::Vector3f center, std::string netplay, std::string core, std::string ip, std::string port)
{
if(game->getType() != GAME)
{
......
......@@ -42,7 +42,8 @@ public:
// Plays a nice launch effect and launches the game at the end of it.
// Once the game terminates, plays a return effect.
void launch(FileData* game, Eigen::Vector3f centerCameraOn = Eigen::Vector3f(Renderer::getScreenWidth() / 2.0f, Renderer::getScreenHeight() / 2.0f, 0), std::string netplay = "");
void launch(FileData* game, Eigen::Vector3f centerCameraOn = Eigen::Vector3f(Renderer::getScreenWidth() / 2.0f, Renderer::getScreenHeight() / 2.0f, 0),
std::string netplay = "", std::string core = "", std::string ip = "", std::string port = "");
bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment