mirror of
https://bitbucket.org/CPMADevs/cnq3
synced 2025-04-05 09:00:51 +00:00
improved shader edit (re)open/close logic
fixed shader edit reopen keeping the old code
This commit is contained in:
parent
4498c13a35
commit
b37b542b89
1 changed files with 31 additions and 24 deletions
|
@ -92,6 +92,7 @@ struct ShaderEditWindow
|
|||
int currentLineCursor;
|
||||
int currentLineX;
|
||||
int cursor;
|
||||
int delayedShaderOpen = -1;
|
||||
bool active;
|
||||
bool validCursorCoords;
|
||||
};
|
||||
|
@ -393,21 +394,31 @@ static void OpenShaderDetails(shader_t* shader)
|
|||
FormatShaderCode(shaderWindow.formattedCode, sizeof(shaderWindow.formattedCode), shader);
|
||||
}
|
||||
|
||||
static void CloseShaderEdit(bool force = false)
|
||||
{
|
||||
ShaderEditWindow& window = shaderEditWindow;
|
||||
if(window.active || force)
|
||||
{
|
||||
R_SetShaderData(window.shader, &window.originalShader);
|
||||
window.active = false;
|
||||
window.delayedShaderOpen = -1;
|
||||
}
|
||||
}
|
||||
|
||||
static void OpenShaderEdit(shader_t* shader)
|
||||
{
|
||||
CloseShaderEdit();
|
||||
|
||||
ImGui::SetWindowFocus(EDIT_WINDOW_NAME);
|
||||
|
||||
if(shaderEditWindow.active)
|
||||
{
|
||||
R_SetShaderData(shaderEditWindow.shader, &shaderEditWindow.originalShader);
|
||||
}
|
||||
|
||||
shaderEditWindow.active = true;
|
||||
shaderEditWindow.shader = shader;
|
||||
shaderEditWindow.originalShader = *shader;
|
||||
shaderEditWindow.shaderFilePath[0] = '\0';
|
||||
FormatShaderCode(shaderEditWindow.code, sizeof(shaderEditWindow.code), shader);
|
||||
Q_strncpyz(shaderEditWindow.originalCode, shaderEditWindow.code, sizeof(shaderEditWindow.originalCode));
|
||||
ShaderEditWindow& window = shaderEditWindow;
|
||||
window.active = true;
|
||||
window.shader = shader;
|
||||
window.originalShader = *shader;
|
||||
window.shaderFilePath[0] = '\0';
|
||||
window.delayedShaderOpen = -1;
|
||||
FormatShaderCode(window.code, sizeof(window.code), shader);
|
||||
Q_strncpyz(window.originalCode, window.code, sizeof(window.originalCode));
|
||||
tr.shaderParseFailed = qfalse;
|
||||
tr.shaderParseNumWarnings = 0;
|
||||
}
|
||||
|
@ -2083,20 +2094,21 @@ static void SaveShaderCodeToFile()
|
|||
|
||||
static void DrawShaderEdit()
|
||||
{
|
||||
ShaderEditWindow& window = shaderEditWindow;
|
||||
|
||||
// handle the keyboard shortcut and delayed opening
|
||||
static int delayedShaderOpen = -1;
|
||||
if(delayedShaderOpen >= 0)
|
||||
if(window.delayedShaderOpen >= 0)
|
||||
{
|
||||
delayedShaderOpen--;
|
||||
window.delayedShaderOpen--;
|
||||
}
|
||||
const bool mapLoaded = tr.world != NULL;
|
||||
if((mapLoaded && IsShortcutPressed(ImGuiKey_E, ShortcutOptions::Global)) || delayedShaderOpen == 0)
|
||||
if((mapLoaded && IsShortcutPressed(ImGuiKey_E, ShortcutOptions::Global)) || window.delayedShaderOpen == 0)
|
||||
{
|
||||
const bool isCheating = IsEditingAllowed();
|
||||
if(isCheating && !tr.traceWorldShader)
|
||||
{
|
||||
tr.traceWorldShader = qtrue;
|
||||
delayedShaderOpen = 4;
|
||||
window.delayedShaderOpen = 4;
|
||||
}
|
||||
else if(
|
||||
isCheating &&
|
||||
|
@ -2105,12 +2117,10 @@ static void DrawShaderEdit()
|
|||
tr.tracedWorldShaderIndex < tr.numShaders)
|
||||
{
|
||||
OpenShaderEdit(tr.shaders[tr.tracedWorldShaderIndex]);
|
||||
delayedShaderOpen = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// handle the window itself
|
||||
ShaderEditWindow& window = shaderEditWindow;
|
||||
const bool wasActive = window.active;
|
||||
shader_t* const shader = window.shader;
|
||||
if(window.active && shader != NULL)
|
||||
|
@ -2185,7 +2195,7 @@ static void DrawShaderEdit()
|
|||
ImGuiInputTextFlags_CallbackCharFilter |
|
||||
ImGuiInputTextFlags_CallbackAlways;
|
||||
ImGui::InputTextMultiline(
|
||||
"##Shader Code", window.code, sizeof(window.code), inputSize,
|
||||
va("##Shader Code: %s", shader->name), window.code, sizeof(window.code), inputSize,
|
||||
callbackFlags, &ShaderEditCallback);
|
||||
|
||||
ImGuiContext& imguiContext = *GImGui;
|
||||
|
@ -2427,7 +2437,7 @@ static void DrawShaderEdit()
|
|||
|
||||
if(wasActive && !window.active)
|
||||
{
|
||||
R_SetShaderData(window.shader, &window.originalShader);
|
||||
CloseShaderEdit(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3283,10 +3293,7 @@ void R_ShutDownGUI()
|
|||
// this is necessary to avoid crashes in the detail windows
|
||||
// following a map change or video restart:
|
||||
// the renderer is shut down and the pointers become stale
|
||||
if(shaderEditWindow.active)
|
||||
{
|
||||
R_SetShaderData(shaderEditWindow.shader, &shaderEditWindow.originalShader);
|
||||
}
|
||||
CloseShaderEdit();
|
||||
memset(&imageWindow, 0, sizeof(imageWindow));
|
||||
memset(&shaderWindow, 0, sizeof(shaderWindow));
|
||||
memset(&shaderEditWindow, 0, sizeof(shaderEditWindow));
|
||||
|
|
Loading…
Reference in a new issue