From 926263bde04218c035b5d564287fb8309e35d728 Mon Sep 17 00:00:00 2001 From: Artyom Shalkhakov Date: Mon, 10 Feb 2025 11:50:44 -0700 Subject: [PATCH] Various changes to Decl Browser. - fix PathTreeCtrl node allocation, add selection & tooltips - Decl New dialog is mostly working - fix: Decl Browser no longer adds an extra root node - Decl Browser has a bug searching: still need to enter "*/" to skip the implicit root node ImGui issue: only one window is displayed by ImGui? repro: editDecls, then select any particle under particles, click New, enter a name, click OK. --- neo/framework/Common.cpp | 23 ++- neo/tools/imgui/ImGuiTools.cpp | 5 + neo/tools/imgui/decleditor/DeclBrowser.cpp | 185 ++++++-------------- neo/tools/imgui/decleditor/DeclBrowser.h | 13 +- neo/tools/imgui/decleditor/DeclEditor.cpp | 3 +- neo/tools/imgui/decleditor/DeclNew.cpp | 180 ++++++++++++------- neo/tools/imgui/decleditor/DeclNew.h | 14 +- neo/tools/imgui/decleditor/PathTreeCtrl.cpp | 22 ++- neo/tools/imgui/decleditor/PathTreeCtrl.h | 37 ++-- 9 files changed, 242 insertions(+), 240 deletions(-) diff --git a/neo/framework/Common.cpp b/neo/framework/Common.cpp index 5a70d2b0..281f409c 100644 --- a/neo/framework/Common.cpp +++ b/neo/framework/Common.cpp @@ -1310,18 +1310,6 @@ static void Com_EditParticles_f(const idCmdArgs& args) { #endif } - -#ifdef ID_ALLOW_TOOLS -/* -================== -Com_EditSounds_f -================== -*/ -static void Com_EditSounds_f( const idCmdArgs &args ) { - SoundEditorInit( NULL ); - cvarSystem->SetCVarInteger( "g_editEntityMode", 2 ); -} - /* ================== Com_EditDecls_f @@ -1352,6 +1340,17 @@ static void Com_EditScripts_f( const idCmdArgs &args ) { #endif } +#ifdef ID_ALLOW_TOOLS +/* +================== +Com_EditSounds_f +================== +*/ +static void Com_EditSounds_f( const idCmdArgs &args ) { + SoundEditorInit( NULL ); + cvarSystem->SetCVarInteger( "g_editEntityMode", 2 ); +} + #endif // ID_ALLOW_TOOLS /* diff --git a/neo/tools/imgui/ImGuiTools.cpp b/neo/tools/imgui/ImGuiTools.cpp index fddb6154..bcb56c90 100644 --- a/neo/tools/imgui/ImGuiTools.cpp +++ b/neo/tools/imgui/ImGuiTools.cpp @@ -220,6 +220,11 @@ void ScriptEditorInit(const idDict* spawnArgs) impl::SetReleaseToolMouse(true); + if ( spawnArgs ) { + const char *str = spawnArgs->GetString( "script" ); + ScriptEditor::Instance().OpenFile( str ); + } + D3::ImGuiHooks::OpenWindow(D3::ImGuiHooks::D3_ImGuiWin_ScriptEditor); } diff --git a/neo/tools/imgui/decleditor/DeclBrowser.cpp b/neo/tools/imgui/decleditor/DeclBrowser.cpp index ab85be16..65133ac9 100644 --- a/neo/tools/imgui/decleditor/DeclBrowser.cpp +++ b/neo/tools/imgui/decleditor/DeclBrowser.cpp @@ -32,9 +32,9 @@ If you have questions concerning this license or the applicable additional terms #include "framework/FileSystem.h" #include "PathTreeCtrl.h" -#include "DeclBrowser.h" -#include "DeclEditor.h" #include "DeclNew.h" +#include "DeclEditor.h" +#include "DeclBrowser.h" const int DECLTYPE_SHIFT = 24; const int DECLINDEX_MASK = ( 1 << DECLTYPE_SHIFT ) - 1; @@ -47,20 +47,12 @@ const int DECLTYPE_GUI = 127; namespace ImGuiTools { -/* -toolTip_t DialogDeclBrowser::toolTips[] = { - { IDC_DECLBROWSER_TREE, "decl browser" }, - { IDC_DECLBROWSER_EDIT_SEARCH_NAMES, "search for declarations with matching name, use meta characters: *, ? and [abc...]" }, - { IDC_DECLBROWSER_EDIT_SEARCH_TEXT, "search for declarations containing text" }, - { IDC_DECLBROWSER_BUTTON_FIND, "find declarations matching the search strings" }, - { IDC_DECLBROWSER_BUTTON_EDIT, "edit selected declaration" }, - { IDC_DECLBROWSER_BUTTON_NEW, "create new declaration" }, - { IDC_DECLBROWSER_BUTTON_RELOAD, "reload declarations" }, - { IDOK, "ok" }, - { IDCANCEL, "cancel" }, - { 0, NULL } -}; -*/ +bool DeclBrowserOnToolTipNotify( void *data, PathTreeNode *item, idStr &tooltipText ) { + return reinterpret_cast(data)->OnToolTipNotify( item, tooltipText ); +} +void DeclBrowserOnTreeSelChanged( void *data ) { + reinterpret_cast(data)->OnTreeSelChanged(); +} /* ================ @@ -84,6 +76,7 @@ DeclBrowser::DeclBrowser() , numListedDecls(0) , findNameString() , findTextString() + , declNewDlg() { } @@ -106,34 +99,44 @@ void DeclBrowser::Draw() { impl::SetReleaseToolMouse( true ); if ( ImGui::BeginChild( "Decl Tree", ImVec2( 300, 400 ) ) ) { - declTree.Draw(); + ImGui::SetItemTooltip( "decl browser" ); + declTree.Draw( DeclBrowserOnToolTipNotify, DeclBrowserOnTreeSelChanged, this ); ImGui::EndChild(); } if ( ImGui::InputTextStr( "Search names", &findNameEdit ) ) { } + ImGui::SetItemTooltip( "search for declarations with matching name, use meta characters: *, ? and [abc...]" ); if ( ImGui::InputTextStr( "Search text", &findTextEdit ) ) { } + ImGui::SetItemTooltip( "search for declarations containing text" ); if ( ImGui::Button( "Find" ) ) { OnBnClickedFind(); } + ImGui::SetItemTooltip( "find declarations matching the search strings" ); ImGui::SameLine(); if ( ImGui::Button( "Edit" ) ) { OnBnClickedEdit(); } + ImGui::SetItemTooltip( "edit selected declaration" ); ImGui::SameLine(); if ( ImGui::Button( "New" ) ) { OnBnClickedNew(); } + ImGui::SetItemTooltip( "create new declaration" ); ImGui::SameLine(); if ( ImGui::Button( "Reload" ) ) { ReloadDeclarations(); } + ImGui::SetItemTooltip( "reload declarations" ); ImGui::SameLine(); if ( ImGui::Button( "Close" ) ) { showTool = false; } + if ( declNewDlg.Draw() ) { + OnBnClickedNewAccepted(); + } } ImGui::End(); @@ -265,7 +268,7 @@ void DeclBrowser::GetDeclName( PathTreeNode *item, idStr &typeName, idStr &declN idStr itemName; declName.Clear(); - for( parent = declTree.GetParentItem( item ); parent; parent = declTree.GetParentItem( parent ) ) { + for( parent = declTree.GetParentItem( item ); parent && parent != declTree.GetRootItem(); parent = declTree.GetParentItem( parent ) ) { itemName = declTree.GetItemText( item ); declName = itemName + "/" + declName; item = parent; @@ -284,6 +287,10 @@ const idDecl *DeclBrowser::GetDeclFromTreeItem( PathTreeNode *item ) const { declType_t type; const idDecl *decl; + if ( !item ) { + return NULL; + } + if ( declTree.GetChildItem( item ) ) { return NULL; } @@ -336,33 +343,28 @@ void DeclBrowser::EditSelected( void ) const { case DECL_AF: { decl = declManager->DeclByIndex( type, index, false ); spawnArgs.Set( "articulatedFigure", decl->GetName() ); - //AFEditorInit( &spawnArgs ); + ImGuiTools::AfEditorInit(); // TODO: pass spawnArgs break; } case DECL_PARTICLE: { decl = declManager->DeclByIndex( type, index, false ); spawnArgs.Set( "model", decl->GetName() ); - //ParticleEditorInit( &spawnArgs ); + ImGuiTools::ParticleEditorInit( &spawnArgs ); break; } case DECL_PDA: { decl = declManager->DeclByIndex( type, index, false ); spawnArgs.Set( "pda", decl->GetName() ); - //PDAEditorInit( &spawnArgs ); + ImGuiTools::PDAEditorInit( &spawnArgs ); break; } case DECLTYPE_SCRIPT: case DECLTYPE_GUI: { idStr typeName, declName; GetDeclName( item, typeName, declName ); - /* - ScriptEditor* scriptEditor; - scriptEditor = new ScriptEditor; - scriptEditor->Create( IDD_DIALOG_SCRIPTEDITOR, GetParent() ); - scriptEditor->OpenFile( typeName + "/" + declName + ( ( type == DECLTYPE_SCRIPT ) ? ".script" : ".gui" ) ); - scriptEditor->ShowWindow( SW_SHOW ); - scriptEditor->SetFocus(); - */ + idStr fileName = typeName + "/" + declName + ( ( type == DECLTYPE_SCRIPT ) ? ".script" : ".gui" ); + spawnArgs.Set( "script", fileName ); + ImGuiTools::ScriptEditorInit( &spawnArgs ); break; } default: { @@ -442,10 +444,6 @@ DeclBrowser::Reset */ void DeclBrowser::Reset() { - //GetClientRect( initialRect ); - - //baseDeclTree.Create( 0, initialRect, this, IDC_DECLBROWSER_BASE_TREE ); - InitBaseDeclTree(); findNameString = "*"; @@ -469,82 +467,28 @@ void DeclBrowser::ReloadDeclarations( void ) { OnBnClickedFind(); } -/* -BEGIN_MESSAGE_MAP(DialogDeclBrowser, CDialog) - ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipNotify) - ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipNotify) - ON_WM_DESTROY() - ON_WM_ACTIVATE() - ON_WM_MOVE() - ON_WM_SIZE() - ON_WM_SIZING() - ON_WM_SETFOCUS() - ON_NOTIFY(TVN_SELCHANGED, IDC_DECLBROWSER_TREE, OnTreeSelChanged) - ON_NOTIFY(NM_DBLCLK, IDC_DECLBROWSER_TREE, OnTreeDblclk) - ON_BN_CLICKED(IDC_DECLBROWSER_BUTTON_FIND, OnBnClickedFind) - ON_BN_CLICKED(IDC_DECLBROWSER_BUTTON_EDIT, OnBnClickedEdit) - ON_BN_CLICKED(IDC_DECLBROWSER_BUTTON_NEW, OnBnClickedNew) - ON_BN_CLICKED(IDC_DECLBROWSER_BUTTON_RELOAD, OnBnClickedReload) - ON_BN_CLICKED(IDOK, OnBnClickedOk) - ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel) -END_MESSAGE_MAP() -*/ - // DeclBrowser message handlers /* ================ -DialogDeclBrowser::OnToolTipNotify +DeclBrowser::OnToolTipNotify ================ -*//* -BOOL DialogDeclBrowser::OnToolTipNotify( UINT id, NMHDR *pNMHDR, LRESULT *pResult ) { - // need to handle both ANSI and UNICODE versions of the message -#ifdef _UNICODE - TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR; -#else - TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR; -#endif - - if ( pNMHDR->hwndFrom == declTree.GetSafeHwnd() ) { - CString toolTip; - const idDecl *decl = GetDeclFromTreeItem( (HTREEITEM) pNMHDR->idFrom ); +*/ +bool DeclBrowser::OnToolTipNotify( PathTreeNode *item, idStr &tooltipText ) const { + if ( item ) { + const idDecl *decl = GetDeclFromTreeItem( item ); if ( !decl ) { - return FALSE; + return false; } - toolTip = va( "%s, line: %d", decl->GetFileName(), decl->GetLineNum() ); + tooltipText = va( "%s, line: %d", decl->GetFileName(), decl->GetLineNum() ); -#ifndef _UNICODE - if( pNMHDR->code == TTN_NEEDTEXTA ) { - delete m_pchTip; - m_pchTip = new TCHAR[toolTip.GetLength() + 2]; - lstrcpyn( m_pchTip, toolTip, toolTip.GetLength() + 1 ); - pTTTW->lpszText = (WCHAR*)m_pchTip; - } else { - delete m_pwchTip; - m_pwchTip = new WCHAR[toolTip.GetLength() + 2]; - _mbstowcsz( m_pwchTip, toolTip, toolTip.GetLength() + 1 ); - pTTTW->lpszText = (WCHAR*)m_pwchTip; - } -#else - if( pNMHDR->code == TTN_NEEDTEXTA ) { - delete m_pchTip; - m_pchTip = new TCHAR[toolTip.GetLength() + 2]; - _wcstombsz( m_pchTip, toolTip, toolTip.GetLength() + 1 ); - pTTTA->lpszText = (LPTSTR)m_pchTip; - } else { - delete m_pwchTip; - m_pwchTip = new WCHAR[toolTip.GetLength() + 2]; - lstrcpyn( m_pwchTip, toolTip, toolTip.GetLength() + 1 ); - pTTTA->lpszText = (LPTSTR) m_pwchTip; - } -#endif - return TRUE; + return true; } - return DefaultOnToolTipNotify( toolTips, id, pNMHDR, pResult ); -}*/ + return false; +} /* ================ @@ -615,37 +559,36 @@ void DeclBrowser::OnBnClickedNew() { PathTreeNode *item; idStr typeName, declName; const idDecl *decl; - DeclNew newDeclDlg; - newDeclDlg.SetDeclTree( &baseDeclTree ); + declNewDlg.SetDeclTree( &baseDeclTree ); item = declTree.GetSelectedItem(); if ( item ) { GetDeclName( item, typeName, declName ); - newDeclDlg.SetDefaultType( typeName ); - newDeclDlg.SetDefaultName( declName ); + declNewDlg.SetDefaultType( typeName ); + declNewDlg.SetDefaultName( declName ); } decl = GetSelectedDecl(); if ( decl ) { - newDeclDlg.SetDefaultFile( decl->GetFileName() ); + declNewDlg.SetDefaultFile( decl->GetFileName() ); } - /* - if ( newDeclDlg.DoModal() != IDOK ) { - return; - } - */ - decl = newDeclDlg.GetNewDecl(); + + declNewDlg.Start(); +} + +void DeclBrowser::OnBnClickedNewAccepted() { + const idDecl *decl = declNewDlg.GetNewDecl(); if ( decl ) { - declName = declManager->GetDeclNameFromType( decl->GetType() ); + idStr declName = declManager->GetDeclNameFromType( decl->GetType() ); declName += "/"; declName += decl->GetName(); int id = GetIdFromTypeAndIndex( decl->GetType(), decl->Index() ); baseDeclTree.InsertPathIntoTree( declName, id ); - item = declTree.InsertPathIntoTree( declName, id ); + PathTreeNode *item = declTree.InsertPathIntoTree( declName, id ); declTree.SelectItem( item ); EditSelected(); @@ -664,26 +607,4 @@ void DeclBrowser::OnBnClickedReload() { ReloadDeclarations(); } -/* -================ -DeclBrowser::OnBnClickedOk -================ -*/ -void DeclBrowser::OnBnClickedOk() { - // with a modeless dialog once it is closed and re-activated windows seems - // to enjoy mapping ENTER back to the default button ( OK ) even if you have - // it NOT set as the default.. in this case use cancel button exit and ignore - // default IDOK handling. - // OnOK(); -} - -/* -================ -DeclBrowser::OnBnClickedCancel -================ -*/ -void DeclBrowser::OnBnClickedCancel() { - //OnCancel(); -} - } diff --git a/neo/tools/imgui/decleditor/DeclBrowser.h b/neo/tools/imgui/decleditor/DeclBrowser.h index 79d57e58..7d3c382d 100644 --- a/neo/tools/imgui/decleditor/DeclBrowser.h +++ b/neo/tools/imgui/decleditor/DeclBrowser.h @@ -32,6 +32,7 @@ If you have questions concerning this license or the applicable additional terms #include "../../edit_public.h" #include "PathTreeCtrl.h" +#include "DeclNew.h" namespace ImGuiTools { @@ -45,6 +46,8 @@ public: void ReloadDeclarations( void ); bool CompareDecl( PathTreeNode *item, const char *name ) const; + bool OnToolTipNotify( PathTreeNode *item, idStr &tooltipText ) const; + void OnTreeSelChanged(); void Reset(); void Draw(); @@ -57,15 +60,12 @@ public: } private: - //bool OnToolTipNotify( UINT id, NMHDR *pNMHDR, LRESULT *pResult ); - void OnTreeSelChanged(); void OnTreeDblclk(); void OnBnClickedFind(); void OnBnClickedEdit(); void OnBnClickedNew(); + void OnBnClickedNewAccepted(); void OnBnClickedReload(); - void OnBnClickedOk(); - void OnBnClickedCancel(); private: bool isShown; @@ -81,16 +81,13 @@ private: bool reloadButtonEnabled; bool cancelButtonEnabled; - //static toolTip_t toolTips[]; - //CRect initialRect; PathTreeCtrl baseDeclTree; int numListedDecls; idStr findNameString; idStr findTextString; - //TCHAR * m_pchTip; - //WCHAR * m_pwchTip; + DeclNew declNewDlg; private: void AddDeclTypeToTree( declType_t type, const char *root, PathTreeCtrl &tree ); diff --git a/neo/tools/imgui/decleditor/DeclEditor.cpp b/neo/tools/imgui/decleditor/DeclEditor.cpp index 911e8074..19b6ae45 100644 --- a/neo/tools/imgui/decleditor/DeclEditor.cpp +++ b/neo/tools/imgui/decleditor/DeclEditor.cpp @@ -28,8 +28,9 @@ If you have questions concerning this license or the applicable additional terms #include "../util/ImGui_IdWidgets.h" -#include "DeclBrowser.h" +#include "PathTreeCtrl.h" #include "DeclEditor.h" +#include "DeclBrowser.h" namespace ImGuiTools { diff --git a/neo/tools/imgui/decleditor/DeclNew.cpp b/neo/tools/imgui/decleditor/DeclNew.cpp index 1c946ea1..e17f322e 100644 --- a/neo/tools/imgui/decleditor/DeclNew.cpp +++ b/neo/tools/imgui/decleditor/DeclNew.cpp @@ -30,51 +30,32 @@ If you have questions concerning this license or the applicable additional terms #include "framework/FileSystem.h" -#include "DeclBrowser.h" +#include "PathTreeCtrl.h" #include "DeclNew.h" +#include "DeclBrowser.h" namespace ImGuiTools { -/* -toolTip_t DialogDeclNew::toolTips[] = { - { IDC_DECLNEW_COMBO_NEW_TYPE, "select the declaration type to create" }, - { IDC_DECLNEW_EDIT_NEW_NAME, "enter a name for the new declaration" }, - { IDC_DECLNEW_EDIT_NEW_FILE, "enter the name of the file to add the declaration to" }, - { IDC_DECLNEW_BUTTON_NEW_FILE, "select existing file to add the declaration to" }, - { IDOK, "create new declaration" }, - { IDCANCEL, "cancel" }, - { 0, NULL } -};*/ - - /* ================ -DeclNew::DialogDeclNew +DeclNew::DeclNew ================ */ DeclNew::DeclNew() - : declTree(NULL) + : typeList() + , typeListSel(-1) + , nameEdit() + , fileEdit() + , errorText() + , declTree(NULL) + , defaultType() + , defaultName() , newDecl(NULL) + , state(DONE) + , selectDlg( DECL_AF, "af", ".af", "AFs" ) { } -/* -================ -DeclNew::DoDataExchange -================ -*//* -void DialogDeclNew::DoDataExchange(CDataExchange* pDX) { - CDialog::DoDataExchange(pDX); - //{{AFX_DATA_MAP(DialogDeclNew) - DDX_Control(pDX, IDC_DECLNEW_COMBO_NEW_TYPE, typeList); - DDX_Control(pDX, IDC_DECLNEW_EDIT_NEW_NAME, nameEdit); - DDX_Control(pDX, IDC_DECLNEW_EDIT_NEW_FILE, fileEdit); - DDX_Control(pDX, IDC_DECLNEW_BUTTON_NEW_FILE, fileButton); - DDX_Control(pDX, IDOK, okButton); - DDX_Control(pDX, IDCANCEL, cancelButton); - //}}AFX_DATA_MAP -}*/ - /* ================ DeclNew::InitTypeList @@ -87,6 +68,7 @@ void DeclNew::InitTypeList( void ) { for ( i = 0; i < declManager->GetNumDeclTypes(); i++ ) { typeList.Append( declManager->GetDeclNameFromType( (declType_t)i ) ); } + typeListSel = -1; } /* @@ -95,26 +77,98 @@ DeclNew::Reset ================ */ void DeclNew::Reset() { - InitTypeList(); - //SetSafeComboBoxSelection( &typeList, defaultType.c_str(), -1 ); + typeListSel = typeList.FindIndex( defaultType ); nameEdit = defaultName; fileEdit = defaultFile; + newDecl = NULL; + state = DONE; } -/* -BEGIN_MESSAGE_MAP(DialogDeclNew, CDialog) - ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipNotify) - ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipNotify) - ON_WM_DESTROY() - ON_WM_ACTIVATE() - ON_WM_SETFOCUS() - ON_BN_CLICKED(IDC_DECLNEW_BUTTON_NEW_FILE, OnBnClickedFile) - ON_BN_CLICKED(IDOK, OnBnClickedOk) - ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel) -END_MESSAGE_MAP() -*/ +void DeclNew::Start() { + Reset(); + + state = NAME; + + ImGui::OpenPopup("New Declaration"); +} + +bool DeclNew::Draw() { + if ( state == DONE ) { + return false; + } + + bool accepted = false; + bool canceled = false; + + if ( ImGui::BeginPopupModal( "New Declaration", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { + ImGui::TextColored( ImVec4( 1, 0, 0, 1 ), errorText ); + + const char *previewValue = typeListSel == -1 ? NULL : typeList[typeListSel].c_str(); + + if ( ImGui::BeginCombo( "Type##typeListSelect", previewValue ) ) { + ImGui::SetItemTooltip( "select the declaration type to create" ); + + for ( int i = 0; i < typeList.Num(); i++ ) { + bool selected = ( i == typeListSel ); + + ImGui::PushID( i ); + if ( ImGui::Selectable( typeList[i].c_str(), selected ) ) { + typeListSel = i; + } + if ( selected ) { + ImGui::SetItemDefaultFocus(); + } + ImGui::PopID(); + } + + ImGui::EndCombo(); + } + + if ( ImGui::InputTextStr( "Name", &nameEdit ) ) { + + } + ImGui::SetItemTooltip( "enter a name for the new declaration" ); + if ( ImGui::InputTextStr( "File", &fileEdit ) ) { + + } + ImGui::SetItemTooltip( "enter the name of the file to add the declaration to" ); + ImGui::SameLine(); + if ( ImGui::Button( "..." ) ) { + //selectDlg.Start(); + OnBnClickedFile(); + } + ImGui::SetItemTooltip( "select existing file to add the declaration to" ); + + if ( selectDlg.Draw() ) { + // accepted + //fileEdit = fileSystem->OSPathToRelativePath( dlgFile.m_ofn.lpstrFile ); + fileEdit = selectDlg.GetDecl()->GetFileName(); + } + + if ( ImGui::Button( "OK" ) ) { + OnBnClickedOk(); + if ( newDecl ) { + accepted = true; + state = DONE; + ImGui::CloseCurrentPopup(); + } + } + ImGui::SetItemTooltip( "create new declaration" ); + ImGui::SameLine(); + if ( ImGui::Button( "Cancel" ) ) { + accepted = false; + state = DONE; + ImGui::CloseCurrentPopup(); + } + ImGui::SetItemTooltip( "cancel" ); + + ImGui::EndPopup(); + } + + return accepted; +} // DeclNew message handlers @@ -126,16 +180,17 @@ DeclNew::OnBnClickedFile void DeclNew::OnBnClickedFile() { idStr typeName, folder, ext; idStr path; - const char *errorTitle = "Error selecting file."; - if ( 1/*GetSafeComboBoxSelection(&typeList, typeName, -1) == -1*/) { - //MessageBox( "Select a declaration type first.", errorTitle, MB_OK ); + errorText.Clear(); + + if ( typeListSel == -1 ) { + errorText = "Select a declaration type first."; return; } declType_t type = declManager->GetDeclTypeFromName( typeName ); if ( type >= declManager->GetNumDeclTypes() ) { - //MessageBox( "Unknown declaration type.", errorTitle, MB_OK | MB_ICONERROR ); + errorText = "Unknown declaration type."; return; } @@ -156,12 +211,7 @@ void DeclNew::OnBnClickedFile() { path = fileSystem->RelativePathToOSPath( folder ); path += "\\*"; - /* - CFileDialog dlgFile( TRUE, "decl", path, 0, ext, this ); - if ( dlgFile.DoModal() == IDOK ) { - path = fileSystem->OSPathToRelativePath( dlgFile.m_ofn.lpstrFile ); - fileEdit = path; - }*/ + selectDlg.Start(); } /* @@ -171,38 +221,40 @@ DeclNew::OnBnClickedOk */ void DeclNew::OnBnClickedOk() { idStr typeName, declName, fileName; - const char *errorTitle = "Error creating declaration."; + + errorText.Clear(); if ( !declTree ) { - //MessageBox( "No declaration tree available.", errorTitle, MB_OK | MB_ICONERROR ); + errorText = "No declaration tree available."; return; } - if ( 1/*GetSafeComboBoxSelection(&typeList, typeName, -1) == -1*/) { - //MessageBox( "No declaration type selected.", errorTitle, MB_OK | MB_ICONERROR ); + if ( typeListSel == -1 ) { + errorText = "No declaration type selected."; return; } + typeName = typeList[typeListSel]; declName = nameEdit; if ( declName.Length() == 0 ) { - //MessageBox( "No declaration name specified.", errorTitle, MB_OK | MB_ICONERROR ); + errorText = "No declaration name specified."; return; } fileName = fileEdit; if ( fileName.Length() == 0 ) { - //MessageBox( "No file name specified.", errorTitle, MB_OK | MB_ICONERROR ); + errorText = "No file name specified."; return; } if ( declTree->FindItem( idStr( typeName + "/" + declName ) ) ) { - //MessageBox( "Declaration already exists.", errorTitle, MB_OK | MB_ICONERROR ); + errorText = "Declaration already exists."; return; } declType_t type = declManager->GetDeclTypeFromName( typeName ); if ( type >= declManager->GetNumDeclTypes() ) { - //MessageBox( "Unknown declaration type.", errorTitle, MB_OK | MB_ICONERROR ); + errorText = "Unknown declaration type."; return; } diff --git a/neo/tools/imgui/decleditor/DeclNew.h b/neo/tools/imgui/decleditor/DeclNew.h index b6d477fe..756065bd 100644 --- a/neo/tools/imgui/decleditor/DeclNew.h +++ b/neo/tools/imgui/decleditor/DeclNew.h @@ -31,7 +31,7 @@ If you have questions concerning this license or the applicable additional terms namespace ImGuiTools { -// DialogDeclNew dialog +// DeclNew dialog class DeclNew { @@ -45,6 +45,8 @@ public: idDecl * GetNewDecl( void ) const { return newDecl; } void Reset(); + void Start(); + bool Draw(); private: void OnBnClickedFile(); @@ -52,21 +54,23 @@ private: void OnBnClickedCancel(); private: + enum state_t { DONE = 0, NAME }; idStrList typeList; + int typeListSel; idStr nameEdit; idStr fileEdit; - bool fileButtonEnabled; - bool okButtonEnabled; - bool cancelButtonEnabled; - //static toolTip_t toolTips[]; + idStr errorText; PathTreeCtrl * declTree; idStr defaultType; idStr defaultName; idStr defaultFile; idDecl * newDecl; + state_t state; + + DeclNewSelect selectDlg; private: void InitTypeList( void ); diff --git a/neo/tools/imgui/decleditor/PathTreeCtrl.cpp b/neo/tools/imgui/decleditor/PathTreeCtrl.cpp index c803dfa4..a3bb2b61 100644 --- a/neo/tools/imgui/decleditor/PathTreeCtrl.cpp +++ b/neo/tools/imgui/decleditor/PathTreeCtrl.cpp @@ -71,6 +71,10 @@ void PathTreeCtrl::SelectItem( PathTreeNode *item ) { } PathTreeNode *PathTreeCtrl::InsertItem( const idStr &name, PathTreeNode *parent, PathTreeNode *after ) { + if ( !parent && name.IsEmpty() ) { + // do not insert the root node again + return root; + } PathTreeNode *newNode = nodeAllocator.Alloc(); int id = numNodes++; newNode->Init( id ); @@ -96,12 +100,12 @@ int PathTreeCtrl::GetItemData( PathTreeNode *item ) const { return item->GetItem(); } -void PathTreeCtrl::Draw() { +void PathTreeCtrl::Draw( treeItemTooltip_t tooltip, treeItemSelected_t selected, void *data ) { PathTreeNode *parentNode = GetRootItem(); PathTreeNode *node; for ( node = GetChildItem( parentNode ) ; node ; node = GetNextSiblingItem( node ) ) { - DrawNode( node ); + DrawNode( node, tooltip, selected, data ); } } @@ -275,9 +279,10 @@ int PathTreeCtrl::SearchTree( treeItemCompare_t compare, void *data, PathTreeCtr return numItems; } -void PathTreeCtrl::DrawNode( PathTreeNode *node ) { +void PathTreeCtrl::DrawNode( PathTreeNode *node, treeItemTooltip_t tooltip, treeItemSelected_t selected, void *data ) { PathTreeNode *item; ImGuiTreeNodeFlags flags = 0; + idStr tooltipText; if ( node == selectedItem ) { flags |= ImGuiTreeNodeFlags_Selected; @@ -290,10 +295,19 @@ void PathTreeCtrl::DrawNode( PathTreeNode *node ) { if ( ImGui::TreeNodeEx( ( const void * )node->GetID(), flags, "%s", node->GetLabel().c_str() ) ) { if ( ImGui::IsItemClicked() && !ImGui::IsItemToggledOpen() ) { SelectItem( node ); + selected( data ); + } + if ( ImGui::IsItemHovered() ) { + tooltipText.Clear(); + if ( tooltip( data, node, tooltipText ) ) { + ImGui::BeginTooltip(); + ImGui::TextUnformatted( tooltipText.c_str() ); + ImGui::EndTooltip(); + } } for ( item = GetChildItem( node ); item; item = GetNextSiblingItem( item ) ) { - DrawNode( item ); + DrawNode( item, tooltip, selected, data ); } if ( GetChildItem( node ) ) { diff --git a/neo/tools/imgui/decleditor/PathTreeCtrl.h b/neo/tools/imgui/decleditor/PathTreeCtrl.h index 0bbb6093..e0bf005f 100644 --- a/neo/tools/imgui/decleditor/PathTreeCtrl.h +++ b/neo/tools/imgui/decleditor/PathTreeCtrl.h @@ -46,8 +46,15 @@ namespace ImGuiTools { class PathTreeNode { public: PathTreeNode() + : label() + , item(0) + , node() + , id(-1) { - Init(0); + + } + ~PathTreeNode() { + Shutdown(); } void Init(int _id) @@ -61,30 +68,26 @@ public: void Shutdown() { node.RemoveFromHierarchy(); - label.FreeData(); + label.Clear(); id = 0; } - ~PathTreeNode() { - - } - - ID_INLINE int GetItem() { + ID_INLINE int GetItem() { return item; } - ID_INLINE void SetItem( int _item ) { + ID_INLINE void SetItem( int _item ) { item = _item; } - ID_INLINE void SetLabel( const char *_label ) { + ID_INLINE void SetLabel( const char *_label ) { label = _label; } - ID_INLINE idStr & GetLabel() { + ID_INLINE idStr & GetLabel() { return label; } ID_INLINE idHierarchy& GetNode() { return node; } - ID_INLINE int GetID() { + ID_INLINE int GetID() { return id; } @@ -128,14 +131,20 @@ ID_INLINE void idPathTreeStack::Push( PathTreeNode *item, const char *name ) { } typedef bool (*treeItemCompare_t)( void *data, PathTreeNode *item, const char *name ); +typedef bool (*treeItemTooltip_t)( void *data, PathTreeNode *item, idStr &tooltipText ); +typedef void (*treeItemSelected_t)( void *data ); class PathTreeCtrl { public: PathTreeCtrl() : nodeAllocator() , root() - , selectedItem(NULL) { + , selectedItem(NULL) + , numNodes(0) + { root = nodeAllocator.Alloc(); + root->Init(0); + numNodes++; } ~PathTreeCtrl() { DeleteAllItems(); @@ -153,7 +162,7 @@ public: PathTreeNode * GetSelectedItem() const; void SelectItem( PathTreeNode *item ); - void Draw(); + void Draw( treeItemTooltip_t tooltip, treeItemSelected_t selected, void *data ); PathTreeNode * FindItem( const idStr &pathName ); PathTreeNode * InsertPathIntoTree( const idStr &pathName, const int id ); @@ -161,7 +170,7 @@ public: int SearchTree( treeItemCompare_t compare, void *data, PathTreeCtrl &result ); private: - void DrawNode( PathTreeNode *item ); + void DrawNode( PathTreeNode *item, treeItemTooltip_t tooltip, treeItemSelected_t selected, void *data ); void DeleteAllItemsOfNode( PathTreeNode *item ); idBlockAlloc nodeAllocator;