Merge remote-tracking branch 'tmj/master' into sim

This commit is contained in:
milek7
2020-10-18 23:35:14 +02:00
244 changed files with 54164 additions and 11636 deletions

View File

@@ -16,7 +16,8 @@ http://mozilla.org/MPL/2.0/.
#include "AnimModel.h"
#include "Track.h"
#include "Event.h"
#include "opengl33renderer.h"
#include "MemCell.h"
#include "renderer.h"
#include "utilities.h"
void
@@ -35,12 +36,26 @@ itemproperties_panel::update( scene::basic_node const *Node ) {
auto const &camera { Global.pCamera };
if( node == nullptr ) {
auto const mouseposition { camera.Pos + GfxRenderer.Mouse_Position() };
auto const mouseposition { camera.Pos + GfxRenderer->Mouse_Position() };
textline = "mouse location: [" + to_string( mouseposition.x, 2 ) + ", " + to_string( mouseposition.y, 2 ) + ", " + to_string( mouseposition.z, 2 ) + "]";
text_lines.emplace_back( textline, Global.UITextColor );
return;
}
/*
// TODO: bind receiver in the constructor
if( ( m_itemproperties != nullptr )
&& ( m_itemproperties->node != nullptr ) ) {
// fetch node data; skip properties which were changed until they're retrieved by the observer
auto const *node { m_itemproperties->node };
if( m_itemproperties->name.second == false ) {
m_itemproperties->name.first = ( node->name().empty() ? "(none)" : node->name() );
}
if( m_itemproperties->location.second == false ) {
m_itemproperties->location.first = node->location();
}
}
*/
textline =
"name: " + ( node->name().empty() ? "(none)" : node->name() )
+ "\nlocation: [" + to_string( node->location().x, 2 ) + ", " + to_string( node->location().y, 2 ) + ", " + to_string( node->location().z, 2 ) + "]"
@@ -82,7 +97,7 @@ itemproperties_panel::update( scene::basic_node const *Node ) {
// texture
auto texturefile { (
( subnode->Material()->replacable_skins[ 1 ] != null_handle ) ?
GfxRenderer.Material( subnode->Material()->replacable_skins[ 1 ] ).name :
GfxRenderer->Material( subnode->Material()->replacable_skins[ 1 ] ).name :
"(none)" ) };
if( texturefile.find( szTexturePath ) == 0 ) {
// don't include 'textures/' in the path
@@ -105,14 +120,14 @@ itemproperties_panel::update( scene::basic_node const *Node ) {
// textures
auto texturefile { (
( subnode->m_material1 != null_handle ) ?
GfxRenderer.Material( subnode->m_material1 ).name :
GfxRenderer->Material( subnode->m_material1 ).name :
"(none)" ) };
if( texturefile.find( szTexturePath ) == 0 ) {
texturefile.erase( 0, std::string{ szTexturePath }.size() );
}
auto texturefile2{ (
( subnode->m_material2 != null_handle ) ?
GfxRenderer.Material( subnode->m_material2 ).name :
GfxRenderer->Material( subnode->m_material2 ).name :
"(none)" ) };
if( texturefile2.find( szTexturePath ) == 0 ) {
texturefile2.erase( 0, std::string{ szTexturePath }.size() );
@@ -282,49 +297,145 @@ itemproperties_panel::render_group() {
return true;
}
nodebank_panel::nodebank_panel() : ui_panel("nodebank", true) {
nodebank_panel::nodebank_panel( std::string const &Name, bool const Isopen ) : ui_panel( Name, Isopen ) {
size_min = { 100, 50 };
size_max = { 1000, 1000 };
title = "nodebank";
memset( m_nodesearch, 0, sizeof( m_nodesearch ) );
std::ifstream file;
file.open("nodebank.txt", std::ios_base::in | std::ios_base::binary);
std::string line;
while (std::getline(file, line))
if (line.size() > 2)
m_nodebank.push_back(std::make_unique<std::string>(line));
while( std::getline( file, line ) ) {
if( line.size() < 4 ) {
continue;
}
auto const labelend { line.find( "node" ) };
auto const nodedata { (
labelend == std::string::npos ? "" :
labelend == 0 ? line :
line.substr( labelend ) ) };
auto const label { (
labelend == std::string::npos ? line :
labelend == 0 ? generate_node_label( nodedata ) :
line.substr( 0, labelend ) ) };
m_nodebank.push_back( { label, std::make_shared<std::string>( nodedata ) } );
}
// sort alphabetically content of each group
auto groupbegin { m_nodebank.begin() };
auto groupend { groupbegin };
while( groupbegin != m_nodebank.end() ) {
groupbegin =
std::find_if(
groupend, m_nodebank.end(),
[]( auto const &Entry ) {
return ( false == Entry.second->empty() ); } );
groupend =
std::find_if(
groupbegin, m_nodebank.end(),
[]( auto const &Entry ) {
return ( Entry.second->empty() ); } );
std::sort(
groupbegin, groupend,
[]( auto const &Left, auto const &Right ) {
return ( Left.first < Right.first ); } );
}
}
void
nodebank_panel::render_contents() {
ImGui::RadioButton("modify", (int*)&mode, MODIFY);
ImGui::RadioButton("clone", (int*)&mode, COPY);
ImGui::RadioButton("add", (int*)&mode, ADD);
nodebank_panel::render() {
ImGui::PushItemWidth(-1);
if (ImGui::ListBoxHeader("##nodebank", ImVec2(-1, -1)))
{
int i = 0;
for (auto const entry : m_nodebank) {
std::string label = *entry + "##" + std::to_string(i);
if (ImGui::Selectable(label.c_str(), entry == m_selectedtemplate))
m_selectedtemplate = entry;
i++;
}
if( false == is_open ) { return; }
ImGui::ListBoxFooter();
}
auto flags =
ImGuiWindowFlags_NoFocusOnAppearing
| ImGuiWindowFlags_NoCollapse
| ( size.x > 0 ? ImGuiWindowFlags_NoResize : 0 );
if( size.x > 0 ) {
ImGui::SetNextWindowSize( ImVec2( size.x, size.y ) );
}
if( size_min.x > 0 ) {
ImGui::SetNextWindowSizeConstraints( ImVec2( size_min.x, size_min.y ), ImVec2( size_max.x, size_max.y ) );
}
auto const panelname { (
title.empty() ?
name() :
title )
+ "###" + name() };
if( true == ImGui::Begin( panelname.c_str(), nullptr, flags ) ) {
ImGui::RadioButton("modify node", (int*)&mode, MODIFY);
ImGui::SameLine();
ImGui::RadioButton("insert from bank", (int*)&mode, ADD);
ImGui::SameLine();
ImGui::RadioButton( "copy to bank", (int*)&mode, COPY );
ImGui::PushItemWidth(-1);
ImGui::InputTextWithHint( "Search", "Search node bank", m_nodesearch, IM_ARRAYSIZE( m_nodesearch ) );
if (ImGui::ListBoxHeader("##nodebank", ImVec2(-1, -1)))
{
auto idx { 0 };
auto isvisible { false };
auto const searchfilter { std::string( m_nodesearch ) };
for (auto const &entry : m_nodebank) {
if( entry.second->empty() ) {
// special case, header indicator
isvisible = ImGui::CollapsingHeader( entry.first.c_str() );
}
else {
if( false == isvisible ) {
continue;
}
if( ( false == searchfilter.empty() )
&& ( entry.first.find( searchfilter ) == std::string::npos ) ) {
continue;
}
auto const label { " " + entry.first + "##" + std::to_string( idx ) };
if( ImGui::Selectable( label.c_str(), entry.second == m_selectedtemplate ) )
m_selectedtemplate = entry.second;
++idx;
}
}
ImGui::ListBoxFooter();
}
}
ImGui::End();
}
void nodebank_panel::add_template(const std::string &desc) {
void
nodebank_panel::add_template(const std::string &desc) {
auto const label { generate_node_label( desc ) };
m_nodebank.push_back( { label, std::make_shared<std::string>( desc ) } );
std::ofstream file;
file.open("nodebank.txt", std::ios_base::out | std::ios_base::app | std::ios_base::binary);
file << desc;
m_nodebank.push_back(std::make_unique<std::string>(desc));
file << label << " " << desc;
}
const std::string *nodebank_panel::get_active_template() {
return m_selectedtemplate.get();
}
std::string
nodebank_panel::generate_node_label( std::string Input ) const {
auto tokenizer{ cParser( Input ) };
tokenizer.getTokens( 9, false ); // skip leading tokens
auto model{ tokenizer.getToken<std::string>( false ) };
auto texture{ tokenizer.getToken<std::string>( false ) };
replace_slashes( model );
erase_extension( model );
replace_slashes( texture );
return (
texture == "none" ?
model :
model + " (" + texture + ")" );
}