mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-18 00:49:19 +02:00
further WIP on launcher
This commit is contained in:
@@ -293,8 +293,8 @@ bool TAnimModel::Init(std::string const &asName, std::string const &asReplacable
|
|||||||
|
|
||||||
bool TAnimModel::Load(cParser *parser, bool ter)
|
bool TAnimModel::Load(cParser *parser, bool ter)
|
||||||
{ // rozpoznanie wpisu modelu i ustawienie świateł
|
{ // rozpoznanie wpisu modelu i ustawienie świateł
|
||||||
std::string name = parser->getToken<std::string>();
|
std::string name = ToLower(parser->getToken<std::string>());
|
||||||
std::string texture = parser->getToken<std::string>( false ); // tekstura (zmienia na małe)
|
std::string texture = ToLower(parser->getToken<std::string>());
|
||||||
replace_slashes( name );
|
replace_slashes( name );
|
||||||
replace_slashes( texture );
|
replace_slashes( texture );
|
||||||
if (!Init( name, texture ))
|
if (!Init( name, texture ))
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ class vehicle_table;
|
|||||||
struct light_array;
|
struct light_array;
|
||||||
class particle_manager;
|
class particle_manager;
|
||||||
struct dictionary_source;
|
struct dictionary_source;
|
||||||
|
class trainset_desc;
|
||||||
|
class scenery_desc;
|
||||||
|
|
||||||
namespace scene {
|
namespace scene {
|
||||||
struct node_data;
|
struct node_data;
|
||||||
|
|||||||
@@ -1636,7 +1636,7 @@ TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424"
|
|||||||
if (!MoverParameters->LoadFIZ(asBaseDir))
|
if (!MoverParameters->LoadFIZ(asBaseDir))
|
||||||
{ // jak wczytanie CHK się nie uda, to błąd
|
{ // jak wczytanie CHK się nie uda, to błąd
|
||||||
if (ConversionError == 666)
|
if (ConversionError == 666)
|
||||||
ErrorLog( "Bad vehicle: failed do locate definition file \"" + BaseDir + "/" + Type_Name + ".fiz" + "\"" );
|
ErrorLog( "Bad vehicle: failed to locate definition file \"" + BaseDir + "/" + Type_Name + ".fiz" + "\"" );
|
||||||
else {
|
else {
|
||||||
ErrorLog( "Bad vehicle: failed to load definition from file \"" + BaseDir + "/" + Type_Name + ".fiz\" (error " + to_string( ConversionError ) + ")" );
|
ErrorLog( "Bad vehicle: failed to load definition from file \"" + BaseDir + "/" + Type_Name + ".fiz\" (error " + to_string( ConversionError ) + ")" );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -239,6 +239,8 @@ struct global_settings {
|
|||||||
std::vector<std::pair<std::string, std::string>> network_servers;
|
std::vector<std::pair<std::string, std::string>> network_servers;
|
||||||
std::optional<std::pair<std::string, std::string>> network_client;
|
std::optional<std::pair<std::string, std::string>> network_client;
|
||||||
|
|
||||||
|
std::vector<std::pair<int, std::string>> trainset_overrides;
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
void LoadIniFile( std::string asFileName );
|
void LoadIniFile( std::string asFileName );
|
||||||
void ConfigParse( cParser &parser );
|
void ConfigParse( cParser &parser );
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ TModelsManager::GetModel(std::string const &Name, bool const Dynamic, bool const
|
|||||||
else {
|
else {
|
||||||
// there's nothing matching in the databank nor on the disk, report failure...
|
// there's nothing matching in the databank nor on the disk, report failure...
|
||||||
if( Logerrors ) {
|
if( Logerrors ) {
|
||||||
ErrorLog( "Bad file: failed do locate 3d model file \"" + filename + "\"", logtype::file );
|
ErrorLog( "Bad file: failed to locate 3d model file \"" + filename + "\"", logtype::file );
|
||||||
}
|
}
|
||||||
// ...and link it with the error model slot
|
// ...and link it with the error model slot
|
||||||
m_modelsmap.emplace( filename, null_handle );
|
m_modelsmap.emplace( filename, null_handle );
|
||||||
|
|||||||
@@ -1165,7 +1165,7 @@ texture_manager::create(std::string Filename, bool const Loadnow , GLint fh) {
|
|||||||
locator = find_on_disk( Filename );
|
locator = find_on_disk( Filename );
|
||||||
if( true == locator.first.empty() ) {
|
if( true == locator.first.empty() ) {
|
||||||
// there's nothing matching in the databank nor on the disk, report failure
|
// there's nothing matching in the databank nor on the disk, report failure
|
||||||
ErrorLog( "Bad file: failed do locate texture file \"" + Filename + "\"", logtype::file );
|
ErrorLog( "Bad file: failed to locate texture file \"" + Filename + "\"", logtype::file );
|
||||||
return npos;
|
return npos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -389,7 +389,22 @@ eu07_application::pop_mode() {
|
|||||||
bool
|
bool
|
||||||
eu07_application::push_mode( eu07_application::mode const Mode ) {
|
eu07_application::push_mode( eu07_application::mode const Mode ) {
|
||||||
|
|
||||||
if( Mode >= mode::count_ ) { return false; }
|
if( Mode >= mode::count_ )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!m_modes[Mode]) {
|
||||||
|
if (Mode == mode::launcher)
|
||||||
|
m_modes[Mode] = std::make_shared<launcher_mode>();
|
||||||
|
if (Mode == mode::scenarioloader)
|
||||||
|
m_modes[Mode] = std::make_shared<scenarioloader_mode>();
|
||||||
|
if (Mode == mode::driver)
|
||||||
|
m_modes[Mode] = std::make_shared<driver_mode>();
|
||||||
|
if (Mode == mode::editor)
|
||||||
|
m_modes[Mode] = std::make_shared<editor_mode>();
|
||||||
|
|
||||||
|
if (!m_modes[Mode]->init())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
m_modes[ Mode ]->enter();
|
m_modes[ Mode ]->enter();
|
||||||
m_modestack.push( Mode );
|
m_modestack.push( Mode );
|
||||||
@@ -766,21 +781,11 @@ eu07_application::init_audio() {
|
|||||||
|
|
||||||
int
|
int
|
||||||
eu07_application::init_modes() {
|
eu07_application::init_modes() {
|
||||||
|
if ((!Global.network_servers.empty() || Global.network_client) && Global.SceneryFile.empty()) {
|
||||||
|
ErrorLog("launcher mode is currently not supported in network mode");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// NOTE: we could delay creation/initialization until transition to specific mode is requested,
|
|
||||||
// but doing it in one go at the start saves us some error checking headache down the road
|
|
||||||
|
|
||||||
// create all application behaviour modes
|
|
||||||
m_modes[ mode::launcher ] = std::make_shared<launcher_mode>();
|
|
||||||
m_modes[ mode::scenarioloader ] = std::make_shared<scenarioloader_mode>();
|
|
||||||
m_modes[ mode::driver ] = std::make_shared<driver_mode>();
|
|
||||||
m_modes[ mode::editor ] = std::make_shared<editor_mode>();
|
|
||||||
// initialize the mode objects
|
|
||||||
for( auto &mode : m_modes ) {
|
|
||||||
if( false == mode->init() ) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// activate the default mode
|
// activate the default mode
|
||||||
if (Global.SceneryFile.empty())
|
if (Global.SceneryFile.empty())
|
||||||
push_mode( mode::launcher );
|
push_mode( mode::launcher );
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ buffer_manager::create( std::string const &Filename ) {
|
|||||||
return emplace( filelookup );
|
return emplace( filelookup );
|
||||||
}
|
}
|
||||||
// if we still didn't find anything, give up
|
// if we still didn't find anything, give up
|
||||||
ErrorLog( "Bad file: failed do locate audio file \"" + Filename + "\"", logtype::file );
|
ErrorLog( "Bad file: failed to locate audio file \"" + Filename + "\"", logtype::file );
|
||||||
return null_handle;
|
return null_handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,12 @@
|
|||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
#include "McZapkie/MOVER.h"
|
#include "McZapkie/MOVER.h"
|
||||||
|
#include "application.h"
|
||||||
|
#include "Logs.h"
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
ui::scenerylist_panel::scenerylist_panel(scenery_scanner &scanner)
|
ui::scenerylist_panel::scenerylist_panel(scenery_scanner &scanner)
|
||||||
: ui_panel(STR("Scenario list"), false), scanner(scanner)
|
: ui_panel(STR("Scenario list"), false), scanner(scanner), placeholder_mini("textures/mini/other")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,7 +27,7 @@ void ui::scenerylist_panel::render()
|
|||||||
std::string prev_prefix;
|
std::string prev_prefix;
|
||||||
bool collapse_open = false;
|
bool collapse_open = false;
|
||||||
|
|
||||||
for (auto const &desc : scanner.scenarios) {
|
for (auto &desc : scanner.scenarios) {
|
||||||
std::string name = desc.path.stem().string();
|
std::string name = desc.path.stem().string();
|
||||||
std::string prefix = name.substr(0, name.find_first_of("-_"));
|
std::string prefix = name.substr(0, name.find_first_of("-_"));
|
||||||
if (prefix.empty())
|
if (prefix.empty())
|
||||||
@@ -110,7 +112,7 @@ void ui::scenerylist_panel::render()
|
|||||||
if (ImGui::BeginChild("child5", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar)) {
|
if (ImGui::BeginChild("child5", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar)) {
|
||||||
ImGuiListClipper clipper(selected_scenery->trainsets.size());
|
ImGuiListClipper clipper(selected_scenery->trainsets.size());
|
||||||
while (clipper.Step()) for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
|
while (clipper.Step()) for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
|
||||||
auto const &trainset = selected_scenery->trainsets[i];
|
auto &trainset = selected_scenery->trainsets[i];
|
||||||
ImGui::PushID(i);
|
ImGui::PushID(i);
|
||||||
if (ImGui::Selectable("##set", selected_trainset == &trainset, 0, ImVec2(0, 30)))
|
if (ImGui::Selectable("##set", selected_trainset == &trainset, 0, ImVec2(0, 30)))
|
||||||
selected_trainset = &trainset;
|
selected_trainset = &trainset;
|
||||||
@@ -124,8 +126,57 @@ void ui::scenerylist_panel::render()
|
|||||||
|
|
||||||
if (selected_trainset) {
|
if (selected_trainset) {
|
||||||
ImGui::NextColumn();
|
ImGui::NextColumn();
|
||||||
|
|
||||||
ImGui::TextWrapped(selected_trainset->description.c_str());
|
ImGui::TextWrapped(selected_trainset->description.c_str());
|
||||||
ImGui::Button(STR_C("Launch"), ImVec2(-1, 0));
|
|
||||||
|
if (ImGui::Button(STR_C("Launch"), ImVec2(-1, 0))) {
|
||||||
|
bool found = false;
|
||||||
|
for (auto &veh : selected_trainset->vehicles) {
|
||||||
|
if (veh.drivertype.size() > 0 && veh.drivertype != "nobody") {
|
||||||
|
Global.local_start_vehicle = ToLower(veh.name);
|
||||||
|
Global.SceneryFile = selected_scenery->path;
|
||||||
|
|
||||||
|
std::string set = "trainset ";
|
||||||
|
set += selected_trainset->name + " ";
|
||||||
|
set += selected_trainset->track + " ";
|
||||||
|
set += std::to_string(selected_trainset->offset) + " ";
|
||||||
|
set += std::to_string(selected_trainset->velocity) + " ";
|
||||||
|
for (const auto &veh : selected_trainset->vehicles) {
|
||||||
|
set += "node -1 0 " + veh.name + " dynamic ";
|
||||||
|
set += veh.vehicle->path.parent_path().generic_string() + " ";
|
||||||
|
set += veh.skin->skin + " ";
|
||||||
|
set += veh.vehicle->path.stem().generic_string() + " ";
|
||||||
|
set += std::to_string(veh.offset) + " " + veh.drivertype + " ";
|
||||||
|
set += std::to_string(veh.coupling);
|
||||||
|
if (veh.params.size() > 0)
|
||||||
|
set += "." + veh.params;
|
||||||
|
set += " " + std::to_string(veh.loadcount) + " ";
|
||||||
|
if (veh.loadcount > 0)
|
||||||
|
set += veh.loadtype + " ";
|
||||||
|
set += "enddynamic ";
|
||||||
|
}
|
||||||
|
set += "endtrainset";
|
||||||
|
WriteLog(set);
|
||||||
|
|
||||||
|
Global.trainset_overrides.push_back(std::make_pair(selected_trainset->file_bounds.first, set));
|
||||||
|
|
||||||
|
Application.pop_mode();
|
||||||
|
Application.push_mode(eu07_application::mode::scenarioloader);
|
||||||
|
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found)
|
||||||
|
ImGui::OpenPopup("missing_driver");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui::BeginPopup("missing_driver")) {
|
||||||
|
ImGui::TextUnformatted(STR_C("Trainset not occupied"));
|
||||||
|
if (ImGui::Button(STR_C("OK"), ImVec2(-1, 0)))
|
||||||
|
ImGui::CloseCurrentPopup();
|
||||||
|
ImGui::EndPopup();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} ImGui::EndChild();
|
} ImGui::EndChild();
|
||||||
@@ -134,7 +185,7 @@ void ui::scenerylist_panel::render()
|
|||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui::scenerylist_panel::draw_trainset(const trainset_desc &trainset)
|
void ui::scenerylist_panel::draw_trainset(trainset_desc &trainset)
|
||||||
{
|
{
|
||||||
static std::unordered_map<coupling, std::string> coupling_names =
|
static std::unordered_map<coupling, std::string> coupling_names =
|
||||||
{
|
{
|
||||||
@@ -150,70 +201,93 @@ void ui::scenerylist_panel::draw_trainset(const trainset_desc &trainset)
|
|||||||
{ coupling::uic, STRN("uic") }
|
{ coupling::uic, STRN("uic") }
|
||||||
};
|
};
|
||||||
|
|
||||||
draw_droptarget();
|
int position = 0;
|
||||||
|
|
||||||
|
draw_droptarget(trainset, position++);
|
||||||
ImGui::SameLine(15.0f);
|
ImGui::SameLine(15.0f);
|
||||||
|
|
||||||
for (auto const &dyn_desc : trainset.vehicles) {
|
for (auto const &dyn_desc : trainset.vehicles) {
|
||||||
if (dyn_desc.skin && dyn_desc.skin->mini.get() != -1) {
|
deferred_image *mini = nullptr;
|
||||||
ImGui::PushID(static_cast<const void*>(&dyn_desc));
|
|
||||||
|
|
||||||
glm::ivec2 size = dyn_desc.skin->mini.size();
|
if (dyn_desc.skin && dyn_desc.skin->mini.get() != -1)
|
||||||
float width = 30.0f / size.y * size.x;
|
mini = &dyn_desc.skin->mini;
|
||||||
ImGui::Image(reinterpret_cast<void*>(dyn_desc.skin->mini.get()), ImVec2(width, 30), ImVec2(0, 1), ImVec2(1, 0));
|
else
|
||||||
|
mini = &placeholder_mini;
|
||||||
|
|
||||||
if (ImGui::IsItemHovered()) {
|
ImGui::PushID(static_cast<const void*>(&dyn_desc));
|
||||||
ImGui::BeginTooltip();
|
|
||||||
std::string name = (dyn_desc.vehicle->path.parent_path() / dyn_desc.vehicle->path.stem()).string();
|
|
||||||
std::string skin = dyn_desc.skin->skin;
|
|
||||||
ImGui::Text(STR_C("ID: %s"), dyn_desc.name.c_str());
|
|
||||||
ImGui::NewLine();
|
|
||||||
|
|
||||||
ImGui::Text(STR_C("Type: %s"), name.c_str());
|
glm::ivec2 size = mini->size();
|
||||||
ImGui::Text(STR_C("Skin: %s"), skin.c_str());
|
float width = 30.0f / size.y * size.x;
|
||||||
ImGui::NewLine();
|
ImGui::Image(reinterpret_cast<void*>(mini->get()), ImVec2(width, 30), ImVec2(0, 1), ImVec2(1, 0));
|
||||||
|
|
||||||
if (dyn_desc.drivertype != "nobody")
|
if (ImGui::IsItemHovered()) {
|
||||||
ImGui::Text(STR_C("Occupied: %s"), dyn_desc.drivertype.c_str());
|
ImGui::BeginTooltip();
|
||||||
if (dyn_desc.loadcount > 0)
|
std::string name = (dyn_desc.vehicle->path.parent_path() / dyn_desc.vehicle->path.stem()).string();
|
||||||
ImGui::Text(STR_C("Load: %s: %d"), dyn_desc.loadtype.c_str(), dyn_desc.loadcount);
|
std::string skin = dyn_desc.skin->skin;
|
||||||
if (!dyn_desc.params.empty())
|
ImGui::Text(STR_C("ID: %s"), dyn_desc.name.c_str());
|
||||||
ImGui::Text(STR_C("Parameters: %s"), dyn_desc.params.c_str());
|
ImGui::NewLine();
|
||||||
ImGui::NewLine();
|
|
||||||
|
|
||||||
ImGui::TextUnformatted(STR_C("Coupling:"));
|
ImGui::Text(STR_C("Type: %s"), name.c_str());
|
||||||
|
ImGui::Text(STR_C("Skin: %s"), skin.c_str());
|
||||||
|
ImGui::NewLine();
|
||||||
|
|
||||||
for (int i = 1; i <= 0x100; i <<= 1) {
|
if (dyn_desc.drivertype != "nobody")
|
||||||
bool dummy = true;
|
ImGui::Text(STR_C("Occupied: %s"), dyn_desc.drivertype.c_str());
|
||||||
|
if (dyn_desc.loadcount > 0)
|
||||||
|
ImGui::Text(STR_C("Load: %s: %d"), dyn_desc.loadtype.c_str(), dyn_desc.loadcount);
|
||||||
|
if (!dyn_desc.params.empty())
|
||||||
|
ImGui::Text(STR_C("Parameters: %s"), dyn_desc.params.c_str());
|
||||||
|
ImGui::NewLine();
|
||||||
|
|
||||||
if (dyn_desc.coupling & i) {
|
ImGui::TextUnformatted(STR_C("Coupling:"));
|
||||||
std::string label = STRN("unknown");
|
|
||||||
auto it = coupling_names.find(static_cast<coupling>(i));
|
for (int i = 1; i <= 0x100; i <<= 1) {
|
||||||
if (it != coupling_names.end())
|
bool dummy = true;
|
||||||
label = it->second;
|
|
||||||
ImGui::Checkbox(Translations.lookup_c(label.c_str()), &dummy);
|
if (dyn_desc.coupling & i) {
|
||||||
}
|
std::string label = STRN("unknown");
|
||||||
|
auto it = coupling_names.find(static_cast<coupling>(i));
|
||||||
|
if (it != coupling_names.end())
|
||||||
|
label = it->second;
|
||||||
|
ImGui::Checkbox(Translations.lookup_c(label.c_str()), &dummy);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::EndTooltip();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::SameLine(0, 0);
|
ImGui::EndTooltip();
|
||||||
float originX = ImGui::GetCursorPosX();
|
|
||||||
|
|
||||||
ImGui::SameLine(originX - 7.5f);
|
|
||||||
draw_droptarget();
|
|
||||||
ImGui::SameLine(originX);
|
|
||||||
|
|
||||||
ImGui::PopID();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui::SameLine(0, 0);
|
||||||
|
float originX = ImGui::GetCursorPosX();
|
||||||
|
|
||||||
|
ImGui::SameLine(originX - 7.5f);
|
||||||
|
draw_droptarget(trainset, position++);
|
||||||
|
ImGui::SameLine(originX);
|
||||||
|
|
||||||
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui::scenerylist_panel::draw_droptarget()
|
#include "Logs.h"
|
||||||
|
void ui::scenerylist_panel::draw_droptarget(trainset_desc &trainset, int position)
|
||||||
{
|
{
|
||||||
ImGui::Dummy(ImVec2(15, 30));
|
ImGui::Dummy(ImVec2(15, 30));
|
||||||
if (ImGui::BeginDragDropTarget()) {
|
if (ImGui::BeginDragDropTarget()) {
|
||||||
ImGui::AcceptDragDropPayload("skin");
|
const ImGuiPayload *payload = ImGui::AcceptDragDropPayload("vehicle_pure");
|
||||||
|
if (payload) {
|
||||||
|
skin_set *ptr = *(reinterpret_cast<skin_set**>(payload->Data));
|
||||||
|
std::shared_ptr<skin_set> skin;
|
||||||
|
for (auto &s : ptr->vehicle.lock()->matching_skinsets)
|
||||||
|
if (s.get() == ptr)
|
||||||
|
skin = s;
|
||||||
|
|
||||||
|
trainset.vehicles.emplace(trainset.vehicles.begin() + position);
|
||||||
|
dynamic_desc &desc = trainset.vehicles[position];
|
||||||
|
|
||||||
|
desc.name = skin->skin + "_" + std::to_string((int)LocalRandom(0.0, 10000000.0));
|
||||||
|
desc.vehicle = skin->vehicle.lock();
|
||||||
|
desc.skin = skin;
|
||||||
|
|
||||||
|
}
|
||||||
ImGui::EndDragDropTarget();
|
ImGui::EndDragDropTarget();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,10 +14,11 @@ class scenerylist_panel : public ui_panel
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
scenery_scanner &scanner;
|
scenery_scanner &scanner;
|
||||||
scenery_desc const *selected_scenery = nullptr;
|
scenery_desc *selected_scenery = nullptr;
|
||||||
trainset_desc const *selected_trainset = nullptr;
|
trainset_desc *selected_trainset = nullptr;
|
||||||
|
deferred_image placeholder_mini;
|
||||||
|
|
||||||
void draw_trainset(const trainset_desc &trainset);
|
void draw_trainset(trainset_desc &trainset);
|
||||||
void draw_droptarget();
|
void draw_droptarget(trainset_desc &trainset, int position);
|
||||||
};
|
};
|
||||||
} // namespace ui
|
} // namespace ui
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ scenery_scanner::scenery_scanner(ui::vehicles_bank &bank)
|
|||||||
void scenery_scanner::scan()
|
void scenery_scanner::scan()
|
||||||
{
|
{
|
||||||
for (auto &f : std::filesystem::directory_iterator("scenery")) {
|
for (auto &f : std::filesystem::directory_iterator("scenery")) {
|
||||||
std::filesystem::path path(f.path());
|
std::filesystem::path path(std::filesystem::relative(f.path(), "scenery/"));
|
||||||
|
|
||||||
if (*(path.filename().string().begin()) == '$')
|
if (*(path.filename().string().begin()) == '$')
|
||||||
continue;
|
continue;
|
||||||
@@ -30,7 +30,9 @@ void scenery_scanner::scan_scn(std::filesystem::path path)
|
|||||||
scenery_desc &desc = scenarios.back();
|
scenery_desc &desc = scenarios.back();
|
||||||
desc.path = path;
|
desc.path = path;
|
||||||
|
|
||||||
cParser parser(path.string(), cParser::buffer_FILE);
|
std::string file_path = "scenery/" + path.string();
|
||||||
|
|
||||||
|
cParser parser(file_path, cParser::buffer_FILE);
|
||||||
parser.expandIncludes = false;
|
parser.expandIncludes = false;
|
||||||
while (!parser.eof()) {
|
while (!parser.eof()) {
|
||||||
parser.getTokens();
|
parser.getTokens();
|
||||||
@@ -38,7 +40,7 @@ void scenery_scanner::scan_scn(std::filesystem::path path)
|
|||||||
parse_trainset(parser);
|
parse_trainset(parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ifstream stream(path.string(), std::ios_base::binary | std::ios_base::in);
|
std::ifstream stream(file_path, std::ios_base::binary | std::ios_base::in);
|
||||||
|
|
||||||
int line_counter = 0;
|
int line_counter = 0;
|
||||||
std::string line;
|
std::string line;
|
||||||
@@ -67,7 +69,7 @@ void scenery_scanner::scan_scn(std::filesystem::path path)
|
|||||||
desc.links.push_back(std::make_pair(file, label));
|
desc.links.push_back(std::make_pair(file, label));
|
||||||
}
|
}
|
||||||
else if (line[3] == 'o') {
|
else if (line[3] == 'o') {
|
||||||
for (trainset_desc &trainset : desc.trainsets) {
|
for (auto &trainset : desc.trainsets) {
|
||||||
if (line_counter < trainset.file_bounds.first
|
if (line_counter < trainset.file_bounds.first
|
||||||
|| line_counter > trainset.file_bounds.second)
|
|| line_counter > trainset.file_bounds.second)
|
||||||
continue;
|
continue;
|
||||||
@@ -82,7 +84,7 @@ void scenery_scanner::parse_trainset(cParser &parser)
|
|||||||
{
|
{
|
||||||
scenery_desc &desc = scenarios.back();
|
scenery_desc &desc = scenarios.back();
|
||||||
desc.trainsets.emplace_back();
|
desc.trainsets.emplace_back();
|
||||||
trainset_desc &trainset = desc.trainsets.back();
|
auto &trainset = desc.trainsets.back();
|
||||||
|
|
||||||
trainset.file_bounds.first = parser.Line();
|
trainset.file_bounds.first = parser.Line();
|
||||||
parser.getTokens(4);
|
parser.getTokens(4);
|
||||||
@@ -94,7 +96,6 @@ void scenery_scanner::parse_trainset(cParser &parser)
|
|||||||
dynamic_desc &dyn = trainset.vehicles.back();
|
dynamic_desc &dyn = trainset.vehicles.back();
|
||||||
|
|
||||||
std::string datafolder, skinfile, mmdfile, params;
|
std::string datafolder, skinfile, mmdfile, params;
|
||||||
int offset;
|
|
||||||
|
|
||||||
parser.getTokens(2); // range_max, range_min
|
parser.getTokens(2); // range_max, range_min
|
||||||
parser.getTokens(1, false); // name
|
parser.getTokens(1, false); // name
|
||||||
@@ -104,7 +105,7 @@ void scenery_scanner::parse_trainset(cParser &parser)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
parser.getTokens(7, false);
|
parser.getTokens(7, false);
|
||||||
parser >> datafolder >> skinfile >> mmdfile >> offset >> dyn.drivertype >> params >> dyn.loadcount;
|
parser >> datafolder >> skinfile >> mmdfile >> dyn.offset >> dyn.drivertype >> params >> dyn.loadcount;
|
||||||
|
|
||||||
size_t params_pos = params.find('.');
|
size_t params_pos = params.find('.');
|
||||||
if (params_pos != -1 && params_pos < params.size()) {
|
if (params_pos != -1 && params_pos < params.size()) {
|
||||||
|
|||||||
@@ -8,9 +8,10 @@
|
|||||||
|
|
||||||
struct dynamic_desc {
|
struct dynamic_desc {
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string drivertype;
|
std::string drivertype = "nobody";
|
||||||
|
|
||||||
std::string loadtype;
|
float offset;
|
||||||
|
std::string loadtype = "none";
|
||||||
int loadcount;
|
int loadcount;
|
||||||
|
|
||||||
unsigned int coupling;
|
unsigned int coupling;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ void ui::vehicles_bank::scan_textures()
|
|||||||
{
|
{
|
||||||
if (line.size() < 3)
|
if (line.size() < 3)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (line.back() == '\r')
|
if (line.back() == '\r')
|
||||||
line.pop_back();
|
line.pop_back();
|
||||||
|
|
||||||
@@ -41,6 +42,9 @@ void ui::vehicles_bank::parse_entry(const std::string &line)
|
|||||||
|
|
||||||
std::string param;
|
std::string param;
|
||||||
while (std::getline(stream, param, '=')) {
|
while (std::getline(stream, param, '=')) {
|
||||||
|
if (param.back() == ' ')
|
||||||
|
param.pop_back();
|
||||||
|
|
||||||
if (line[0] == '!')
|
if (line[0] == '!')
|
||||||
parse_category_entry(param);
|
parse_category_entry(param);
|
||||||
else if (line[0] == '*' && line[1] == '*')
|
else if (line[0] == '*' && line[1] == '*')
|
||||||
@@ -110,7 +114,10 @@ void ui::vehicles_bank::parse_texture_info(const std::string &target, const std:
|
|||||||
std::getline(stream, mini, ',');
|
std::getline(stream, mini, ',');
|
||||||
std::getline(stream, miniplus, ',');
|
std::getline(stream, miniplus, ',');
|
||||||
|
|
||||||
|
auto vehicle = get_vehicle(model);
|
||||||
|
|
||||||
skin_set set;
|
skin_set set;
|
||||||
|
set.vehicle = vehicle;
|
||||||
set.group = mini;
|
set.group = mini;
|
||||||
|
|
||||||
if (!mini.empty())
|
if (!mini.empty())
|
||||||
@@ -118,6 +125,8 @@ void ui::vehicles_bank::parse_texture_info(const std::string &target, const std:
|
|||||||
|
|
||||||
if (!miniplus.empty())
|
if (!miniplus.empty())
|
||||||
set.mini = std::move(deferred_image("textures/mini/" + ToLower(miniplus)));
|
set.mini = std::move(deferred_image("textures/mini/" + ToLower(miniplus)));
|
||||||
|
else if (!mini.empty())
|
||||||
|
set.mini = std::move(deferred_image("textures/mini/" + ToLower(mini)));
|
||||||
|
|
||||||
set.skin = ToLower(target);
|
set.skin = ToLower(target);
|
||||||
erase_extension(set.skin);
|
erase_extension(set.skin);
|
||||||
@@ -129,7 +138,6 @@ void ui::vehicles_bank::parse_texture_info(const std::string &target, const std:
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
auto vehicle = get_vehicle(model);
|
|
||||||
group_map[set.group].insert(vehicle);
|
group_map[set.group].insert(vehicle);
|
||||||
vehicle->matching_skinsets.push_back(std::make_shared<skin_set>(std::move(set)));
|
vehicle->matching_skinsets.push_back(std::make_shared<skin_set>(std::move(set)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,14 +22,17 @@ enum class vehicle_type {
|
|||||||
unknown
|
unknown
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct vehicle_desc;
|
||||||
|
|
||||||
struct skin_set {
|
struct skin_set {
|
||||||
|
std::weak_ptr<vehicle_desc> vehicle;
|
||||||
|
|
||||||
std::string skin;
|
std::string skin;
|
||||||
//std::vector<std::filesystem::path> skins;
|
//std::vector<std::filesystem::path> skins;
|
||||||
deferred_image mini;
|
deferred_image mini;
|
||||||
std::string group;
|
std::string group;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct vehicle_desc;
|
|
||||||
struct texture_rule {
|
struct texture_rule {
|
||||||
std::shared_ptr<vehicle_desc> previous_vehicle;
|
std::shared_ptr<vehicle_desc> previous_vehicle;
|
||||||
std::vector<std::pair<std::string, std::string>> replace_rules;
|
std::vector<std::pair<std::string, std::string>> replace_rules;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
|
|
||||||
ui::vehiclepicker_panel::vehiclepicker_panel()
|
ui::vehiclepicker_panel::vehiclepicker_panel()
|
||||||
: ui_panel(STR("Select vehicle"), false)
|
: ui_panel(STR("Select vehicle"), false), placeholder_mini("textures/mini/other")
|
||||||
{
|
{
|
||||||
bank.scan_textures();
|
bank.scan_textures();
|
||||||
}
|
}
|
||||||
@@ -162,7 +162,8 @@ void ui::vehiclepicker_panel::render()
|
|||||||
|
|
||||||
//std::string label = skin->skins[0].stem().string();
|
//std::string label = skin->skins[0].stem().string();
|
||||||
std::string label = skin->skin;
|
std::string label = skin->skin;
|
||||||
if (selectable_image(label.c_str(), skin == selected_skinset, &skin->mini, true))
|
auto mini = skin->mini ? &skin->mini : &placeholder_mini;
|
||||||
|
if (selectable_image(label.c_str(), skin == selected_skinset, mini, skin))
|
||||||
selected_skinset = skin;
|
selected_skinset = skin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -173,7 +174,7 @@ void ui::vehiclepicker_panel::render()
|
|||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ui::vehiclepicker_panel::selectable_image(const char *desc, bool selected, const deferred_image* image, bool pickable)
|
bool ui::vehiclepicker_panel::selectable_image(const char *desc, bool selected, const deferred_image* image, const skin_set *pickable)
|
||||||
{
|
{
|
||||||
bool ret = ImGui::Selectable(desc, selected, 0, ImVec2(0, 30));
|
bool ret = ImGui::Selectable(desc, selected, 0, ImVec2(0, 30));
|
||||||
if (pickable)
|
if (pickable)
|
||||||
@@ -194,10 +195,10 @@ bool ui::vehiclepicker_panel::selectable_image(const char *desc, bool selected,
|
|||||||
ImGui::SameLine(ImGui::GetContentRegionAvail().x - width);
|
ImGui::SameLine(ImGui::GetContentRegionAvail().x - width);
|
||||||
ImGui::InvisibleButton(desc, ImVec2(width, 30));
|
ImGui::InvisibleButton(desc, ImVec2(width, 30));
|
||||||
|
|
||||||
if (ImGui::BeginDragDropSource()) {
|
if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceAutoExpirePayload)) {
|
||||||
ImGui::Image(reinterpret_cast<void*>(tex), ImVec2(width, 30), ImVec2(0, 1), ImVec2(1, 0));
|
ImGui::Image(reinterpret_cast<void*>(tex), ImVec2(width, 30), ImVec2(0, 1), ImVec2(1, 0));
|
||||||
|
|
||||||
ImGui::SetDragDropPayload("skin", "aaaa", 5);
|
ImGui::SetDragDropPayload("vehicle_pure", &pickable, sizeof(skin_set*));
|
||||||
ImGui::EndDragDropSource();
|
ImGui::EndDragDropSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,13 +13,14 @@ class vehiclepicker_panel : public ui_panel
|
|||||||
void render() override;
|
void render() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool selectable_image(const char *desc, bool selected, const deferred_image *image, bool pickable = false);
|
bool selectable_image(const char *desc, bool selected, const deferred_image *image, const skin_set *pickable = nullptr);
|
||||||
|
|
||||||
vehicle_type selected_type = vehicle_type::none;
|
vehicle_type selected_type = vehicle_type::none;
|
||||||
std::shared_ptr<const vehicle_desc> selected_vehicle;
|
std::shared_ptr<const vehicle_desc> selected_vehicle;
|
||||||
const std::string *selected_group = nullptr;
|
const std::string *selected_group = nullptr;
|
||||||
const skin_set *selected_skinset = nullptr;
|
const skin_set *selected_skinset = nullptr;
|
||||||
bool display_by_groups = false;
|
bool display_by_groups = false;
|
||||||
|
deferred_image placeholder_mini;
|
||||||
|
|
||||||
vehicles_bank bank;
|
vehicles_bank bank;
|
||||||
};
|
};
|
||||||
|
|||||||
15
parser.cpp
15
parser.cpp
@@ -324,6 +324,17 @@ bool cParser::trimComments(std::string &String)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cParser::injectString(const std::string &str)
|
||||||
|
{
|
||||||
|
if (mIncludeParser) {
|
||||||
|
mIncludeParser->injectString(str);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mIncludeParser = std::make_shared<cParser>( str, buffer_TEXT, "", LoadTraction );
|
||||||
|
mIncludeParser->autoclear( m_autoclear );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int cParser::getProgress() const
|
int cParser::getProgress() const
|
||||||
{
|
{
|
||||||
return static_cast<int>( mStream->rdbuf()->pubseekoff(0, std::ios_base::cur) * 100 / mSize );
|
return static_cast<int>( mStream->rdbuf()->pubseekoff(0, std::ios_base::cur) * 100 / mSize );
|
||||||
@@ -374,3 +385,7 @@ cParser::Line() const {
|
|||||||
if( mIncludeParser ) { return mIncludeParser->Line(); }
|
if( mIncludeParser ) { return mIncludeParser->Line(); }
|
||||||
else { return mLine; }
|
else { return mLine; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int cParser::LineMain() const {
|
||||||
|
return mIncludeParser ? -1 : mLine;
|
||||||
|
}
|
||||||
|
|||||||
5
parser.h
5
parser.h
@@ -70,6 +70,9 @@ class cParser //: public std::stringstream
|
|||||||
false == tokens.empty() ?
|
false == tokens.empty() ?
|
||||||
tokens.front() :
|
tokens.front() :
|
||||||
"" ); }
|
"" ); }
|
||||||
|
// inject string as internal include
|
||||||
|
void injectString(const std::string &str);
|
||||||
|
|
||||||
// returns percentage of file processed so far
|
// returns percentage of file processed so far
|
||||||
int getProgress() const;
|
int getProgress() const;
|
||||||
int getFullProgress() const;
|
int getFullProgress() const;
|
||||||
@@ -81,6 +84,8 @@ class cParser //: public std::stringstream
|
|||||||
std::string Name() const;
|
std::string Name() const;
|
||||||
// returns number of currently processed line
|
// returns number of currently processed line
|
||||||
std::size_t Line() const;
|
std::size_t Line() const;
|
||||||
|
// returns number of currently processed line in main file, -1 if inside include
|
||||||
|
int LineMain() const;
|
||||||
bool expandIncludes = true;
|
bool expandIncludes = true;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
1
scene.h
1
scene.h
@@ -58,7 +58,6 @@ struct scratch_data {
|
|||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
bool initialized { false };
|
bool initialized { false };
|
||||||
//std::vector<trainset_desc> *trainsets_desc;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// basic element of rudimentary partitioning scheme for the section. fixed size, no further subdivision
|
// basic element of rudimentary partitioning scheme for the section. fixed size, no further subdivision
|
||||||
|
|||||||
@@ -643,14 +643,27 @@ state_serializer::deserialize_time( cParser &Input, scene::scratch_data &Scratch
|
|||||||
void
|
void
|
||||||
state_serializer::deserialize_trainset( cParser &Input, scene::scratch_data &Scratchpad ) {
|
state_serializer::deserialize_trainset( cParser &Input, scene::scratch_data &Scratchpad ) {
|
||||||
|
|
||||||
|
int line = Input.LineMain();
|
||||||
|
if (line != -1) {
|
||||||
|
for (const std::pair<int, std::string> &entry : Global.trainset_overrides) {
|
||||||
|
if (line != entry.first)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
skip_until(Input, "endtrainset");
|
||||||
|
Input.injectString(entry.second);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if( true == Scratchpad.trainset.is_open ) {
|
if( true == Scratchpad.trainset.is_open ) {
|
||||||
// shouldn't happen but if it does wrap up currently open trainset and report an error
|
// shouldn't happen but if it does wrap up currently open trainset and report an error
|
||||||
deserialize_endtrainset( Input, Scratchpad );
|
deserialize_endtrainset( Input, Scratchpad );
|
||||||
ErrorLog( "Bad scenario: encountered nested trainset definitions in file \"" + Input.Name() + "\" (line " + std::to_string( Input.Line() ) + ")" );
|
ErrorLog( "Bad scenario: encountered nested trainset definitions in file \"" + Input.Name() + "\" (line " + std::to_string( Input.Line() ) + ")" );
|
||||||
}
|
}
|
||||||
|
|
||||||
Scratchpad.trainset = scene::scratch_data::trainset_data();
|
Scratchpad.trainset = scene::scratch_data::trainset_data();
|
||||||
Scratchpad.trainset.is_open = true;
|
Scratchpad.trainset.is_open = true;
|
||||||
|
|
||||||
Input.getTokens( 4 );
|
Input.getTokens( 4 );
|
||||||
Input
|
Input
|
||||||
|
|||||||
Reference in New Issue
Block a user