Skip to content

Commit

Permalink
game main menu btn to start editor
Browse files Browse the repository at this point in the history
  • Loading branch information
cryham committed Mar 31, 2024
1 parent fed8874 commit 3fd130a
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 12 deletions.
13 changes: 11 additions & 2 deletions data/gui/Game_Main.layout
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<MyGUI type="Layout" version="3.2.0">

<Widget type="Window" skin="WindowC" position="1768 156 600 650" align="Center" layer="Overlapped" name="MainMenuWnd">
<Widget type="Window" skin="WindowC" position="1768 156 600 730" align="Center" layer="Overlapped" name="MainMenuWnd">
<Property key="MinSize" value="500 400"/>
<Property key="Caption" value="Stunt Rally #{GameVersion}"/>
<Property key="Alpha" value="0.7"/>
Expand All @@ -10,7 +10,7 @@

<!-- 0 pan +8 img +12 btn +72 12 84 156 228 300 336 408 480 -->

<Widget type="ImageBox" skin="ImageBox" position="0 420 589 201">
<Widget type="ImageBox" skin="ImageBox" position="0 520 589 201">
<Property key="ImageTexture" value="stuntrally-logo.jpg"/>
<!-- <Property key="ImageCoord" value="0 0 1892 645"/> 2.933 -->
<Property key="InheritsAlpha" value="false"/>
Expand Down Expand Up @@ -88,6 +88,15 @@
<Property key="InheritsAlpha" value="false"/>
<Property key="FontName" value="font.big"/>
</Widget>

<Widget type="Button" skin="Button" position="108 426 404 50" align="Left" name="BtnTrackEditor">
<Property key="Caption" value="#{TrackEditor}"/>
<Property key="Colour" value="0.7 0.9 0.9"/>
<Property key="TextColour" value="0.7 1.0 1.0"/>
<Property key="InheritsAlpha" value="false"/>
<Property key="FontName" value="font.big"/>
<UserString key="tip" value="#{TipTrackEditor}"/>
</Widget>
</Widget>

<!-- 0 pan +8 img +12 btn +72 12 84 156 228 300 336 408 480 -->
Expand Down
1 change: 1 addition & 0 deletions src/game/CGui.h
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ class CGui : public BGui


// 🔗 open urls
void btnTrackEditor(WP); // start ed exe
void btnWelcome(WP), btnWebsite(WP), btnWiki(WP), btnWikiInput(WP);
void btnForum(WP), btnSources(WP), btnEdTut(WP), btnTransl(WP), btnDonations(WP);
};
1 change: 1 addition & 0 deletions src/game/Gui_Init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ void CGui::InitGui()


// 🔗 open url btns -------------
Btn("BtnTrackEditor", btnTrackEditor);
Btn("OpenWelcome", btnWelcome); Btn("OpenWebsite", btnWebsite); Btn("OpenSources", btnSources);
Btn("OpenForum", btnForum); Btn("OpenDonations", btnDonations);
// wiki
Expand Down
11 changes: 11 additions & 0 deletions src/game/Gui_Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,17 @@ void CGui::GuiUpdate()

// 🔗 open urls
//.......................................................................................
// start ed exe
void CGui::btnTrackEditor(WP)
{
auto path = PATHS::Bin();
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
PATHS::OpenBin(path + "\\SR-Editor3.exe", path);
#else
PATHS::OpenBin(path + "/sr-editor3", path);
#endif
}

void CGui::btnWelcome(WP)
{
app->mWndWelcome->setVisible(true);
Expand Down
41 changes: 32 additions & 9 deletions src/vdrift/paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace
string /*PATHS::ogre_plugin,*/ PATHS::home_dir,
PATHS::user_config, PATHS::game_config,
PATHS::user_data, PATHS::game_data,
PATHS::cache_dir;
PATHS::cache_dir, PATHS::game_bin;
stringstream PATHS::info;


Expand Down Expand Up @@ -141,6 +141,10 @@ void PATHS::Init(bool log_paths)

CreateDir(DataUser()); // user data


fs::path exe = execname(); // binary dir
game_bin = exe.parent_path();


// Find game data dir and defaults config dir
char *datadir = getenv("STUNTRALLY3_DATA_ROOT");
Expand All @@ -154,14 +158,14 @@ void PATHS::Init(bool log_paths)
//dirs.push_back(user_data_dir);

// Adding relative path for running from sources
dirs.push_back(execname().parent_path().parent_path().parent_path() / "data");
dirs.push_back(execname().parent_path().parent_path().parent_path());
dirs.push_back(execname().parent_path().parent_path() / "data");
dirs.push_back(execname().parent_path().parent_path());
dirs.push_back(execname().parent_path() / "data");
dirs.push_back(execname().parent_path());
dirs.push_back(exe.parent_path().parent_path().parent_path() / "data");
dirs.push_back(exe.parent_path().parent_path().parent_path());
dirs.push_back(exe.parent_path().parent_path() / "data");
dirs.push_back(exe.parent_path().parent_path());
dirs.push_back(exe.parent_path() / "data");
dirs.push_back(exe.parent_path());
// Adding relative path from installed executable
dirs.push_back(execname().parent_path().parent_path() / shareDir);
dirs.push_back(exe.parent_path().parent_path() / shareDir);
#ifndef _WIN32
// Adding XDG_DATA_DIRS
{
Expand Down Expand Up @@ -220,6 +224,7 @@ void PATHS::Init(bool log_paths)
info << "Paths info" << endl;
info << "-------------" << endl;
// info << "Ogre plugin-: " << ogre_plugin << endl;
info << "Bin exe: " << Bin() << endl;
info << "Data: " << Data() << endl;
info << "ConfigDir: " << GameConfigDir() << endl; //?
// info << "Home: " << home_dir << endl;
Expand Down Expand Up @@ -395,7 +400,7 @@ namespace
}


// open web browser with url
// Open web browser with Url
void PATHS::OpenUrl(const string& url)
{
#ifdef WIN32
Expand All @@ -405,3 +410,21 @@ void PATHS::OpenUrl(const string& url)
system(cmd.c_str());
#endif
}

// Start binary, exe ----
// Crucial for starting Track Editor
// from Linux .AppImage pack which starts game only
void PATHS::OpenBin(const string& cmd, const string& path)
{
#ifdef WIN32
ShellExecuteA(
0, // hwnd
0, // str operation
cmd.c_str(), // file
0, // params
path.c_str(), // dir
SW_SHOW);
#else
system(cmd.c_str()); // no path, uses pwd?
#endif
}
4 changes: 3 additions & 1 deletion src/vdrift/paths.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PATHS
private:
static std::string /*ogre_plugin,*/ home_dir;
static std::string user_config, game_config;
static std::string user_data, game_data, cache_dir;
static std::string user_data, game_data, cache_dir, game_bin;

public:
static void Init(bool log_paths=true);
Expand All @@ -33,6 +33,7 @@ class PATHS
{
return user_config +"/"+ (ed ? "editor" : "game") + (old ? "_old" : "") + ".cfg";
}
static std::string Bin() { return game_bin; } // exe
static std::string Data() { return game_data; }
static std::string DataUser() { return user_data + "/data"; }
static std::string Tracks() { return game_data + "/tracks"; }
Expand All @@ -59,5 +60,6 @@ class PATHS
static bool CreateDir(const std::string& path);

static void OpenUrl(const std::string& url);
static void OpenBin(const std::string& cmd, const std::string& path);

};

0 comments on commit 3fd130a

Please sign in to comment.