From d504f77a6aa11886f3b18e09ae9f66b947fdb8fc Mon Sep 17 00:00:00 2001 From: Beherith Date: Sun, 22 Dec 2024 19:56:35 +0100 Subject: [PATCH 01/14] Create info metal view shader and widget --- luaui/Widgets/Shaders/info_metal.frag.glsl | 77 +++++++++++++++ luaui/Widgets/Shaders/info_metal.vert.glsl | 19 ++++ luaui/Widgets/gui_info_metal.lua | 107 +++++++++++++++++++++ 3 files changed, 203 insertions(+) create mode 100644 luaui/Widgets/Shaders/info_metal.frag.glsl create mode 100644 luaui/Widgets/Shaders/info_metal.vert.glsl create mode 100644 luaui/Widgets/gui_info_metal.lua diff --git a/luaui/Widgets/Shaders/info_metal.frag.glsl b/luaui/Widgets/Shaders/info_metal.frag.glsl new file mode 100644 index 00000000000..d9715a4530e --- /dev/null +++ b/luaui/Widgets/Shaders/info_metal.frag.glsl @@ -0,0 +1,77 @@ +#version 420 +#extension GL_ARB_uniform_buffer_object : require +#extension GL_ARB_shading_language_420pack: require + +// This shader is (c) Beherith (mysterme@gmail.com), Licensed under the MIT License + +uniform sampler2D metalTex; +uniform sampler2D metalExtractionTex; +uniform sampler2D mapDepths; + +uniform float alpha = 1.0; +uniform float minimap = 0.0; +uniform float flipMiniMap = 0.0; + +//__DEFINES__ +//__ENGINEUNIFORMBUFFERDEFS__ + +in DataVS { + vec4 texCoord; +}; + +out vec4 fragColor; + +#if 0 + vec2 CubicSampler(vec2 uvsin, vec2 texdims){ + vec2 r = uvsin * texdims - 0.5; + vec2 tf = fract(r); + vec2 ti = r - tf; + tf = tf * tf * (3.0 - 2.0 * tf); + return (tf + ti + 0.5)/texdims; + } +#endif + +void main(void) { + vec2 infoUV = texCoord.xy; + + if (minimap < 0.5) { // world space + float mapdepth = texture(mapDepths, infoUV.xy).x; + vec4 fragWorldPos = vec4( vec3(infoUV.xy * 2.0 - 1.0, mapdepth), 1.0); + + // reconstruct view pos: + fragWorldPos = cameraViewProjInv * fragWorldPos; + fragWorldPos.xyz = fragWorldPos.xyz / fragWorldPos.w; // YAAAY this works! + + //clamp fragWorldPos to the infolos tex bounds: + infoUV = clamp(fragWorldPos.xz / mapSize.xy, 0, 1); + + }else{ + //minimap space is flipped fuck if i know why + infoUV.y = 1.0 - infoUV.y; + if (flipMiniMap > 0.5){ + infoUV = 1.0 - infoUV; + } + } + + vec2 texDims = vec2(METALTEXX, METALTEXY); + vec2 centroids = infoUV.xy * texDims; + + vec4 metalSample = texture2D(metalTex, infoUV).rgba; + //vec4 metalSample = texture2D(metalTex, CubicSampler(infoUV, texDims)).rgba; + vec4 metalExtractionSample = texture2D(metalExtractionTex, infoUV).rgba; + + vec4 outColor = vec4(0.0, 0.0, 0.0, 0.0); + outColor.rgb = mix(vec3(0.0, 0.0, 1.0), vec3(0.0, 1.0, 1.0), metalSample.r); // metalness + outColor.rgb = mix(outColor.rgb, vec3(1.0, 0.0, 0.0), metalExtractionSample.r); // extractedness + if (minimap < 0.5) { // world + + outColor.a = 1.0 * metalSample.r * alpha; // alpha + }else { // minimap + + outColor.rgb = mix(vec3(0), outColor.rgb, metalSample.r); + outColor.a = 1.0 * clamp(metalSample.r, 0.75, 1.0); // alpha + + } + + fragColor = outColor; +} \ No newline at end of file diff --git a/luaui/Widgets/Shaders/info_metal.vert.glsl b/luaui/Widgets/Shaders/info_metal.vert.glsl new file mode 100644 index 00000000000..b598e373fab --- /dev/null +++ b/luaui/Widgets/Shaders/info_metal.vert.glsl @@ -0,0 +1,19 @@ +#version 430 + + +// This shader is (c) Beherith (mysterme@gmail.com), Licensed under the MIT License + +//__DEFINES__ + +//__ENGINEUNIFORMBUFFERDEFS__ + +layout (location = 0) in vec4 position; // [-1,1], [0,1] , xyuv + +out DataVS { + vec4 texCoord; +}; + +void main(void) { + texCoord = position.zwzw; + gl_Position = vec4(position.xy * 1.0, 0.00, 1); +} \ No newline at end of file diff --git a/luaui/Widgets/gui_info_metal.lua b/luaui/Widgets/gui_info_metal.lua new file mode 100644 index 00000000000..68546cca503 --- /dev/null +++ b/luaui/Widgets/gui_info_metal.lua @@ -0,0 +1,107 @@ +function widget:GetInfo() + return { + name = "Info Metal View", + version = 3, + desc = "Draws Metal Amount and Metal Extraction maps", + author = "Beherith", + date = "2024.12.22", + license = "GPL V2", + layer = 10001, + enabled = true + } +end + +-- Author: Beherith (mysterme@gmail.com) +-- TODO: +-- [x] USE BICUBIC SAMPLER! + -- nope, tried, suxx +-- [x] Flip minimap? +-- [x] calc tex sizes from map size +-- [ ] override F4 keysym +-- [ ] fade alpha in + +local autoreload = true +local alpha = 0.75 + +local luaShaderDir = "LuaUI/Widgets/Include/" +local LuaShader = VFS.Include(luaShaderDir.."LuaShader.lua") +VFS.Include(luaShaderDir.."instancevbotable.lua") + +local getMiniMapFlipped = VFS.Include("luaui/Widgets/Include/minimap_utils.lua").getMiniMapFlipped + +local fullScreenQuadVAO +local infoMetalShader + +local shaderSourceCache = { + vssrcpath = "LuaUI/Widgets/Shaders/info_metal.vert.glsl", + fssrcpath = "LuaUI/Widgets/Shaders/info_metal.frag.glsl", + uniformInt = { + metalTex = 0, + metalExtractionTex = 1, + mapDepths = 2, + }, + uniformFloat = { + alpha = 0.5, + minimap = 0, + flipMiniMap = getMiniMapFlipped() and 1 or 0, + }, + shaderName = "Info Metal View GL4", + shaderConfig = { + METALTEXX = Game.mapSizeX/16, + METALTEXY = Game.mapSizeZ/16, + }, +} + +function widget:Initialize() + if not gl.CreateShader then -- no shader support, so just remove the widget itself, especially for headless + widgetHandler:RemoveWidget() + return + end + infoMetalShader = LuaShader.CheckShaderUpdates(shaderSourceCache) + shaderCompiled = infoMetalShader:Initialize() + if not shaderCompiled then Spring.Echo("Failed to compile Info Metal View GL4") end + + fullScreenQuadVAO = MakeTexRectVAO()-- -1, -1, 1, 0, 0,0,1, 0.5 +end + +function DrawInfoMetal(inminimap) + gl.Texture(0, "$info:metal") + gl.Texture(1, "$info:metalextraction") + if not inminimap then + gl.Texture(2, "$map_gbuffer_zvaltex") + end + + gl.Blending(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA) + gl.Culling(false) -- ffs + gl.DepthTest(false) + gl.DepthMask(false) --"BK OpenGL state resets", default is already false, could remove + infoMetalShader:Activate() + infoMetalShader:SetUniformFloat("alpha", alpha) + infoMetalShader:SetUniformFloat("minimap", inminimap and 1 or 0) + infoMetalShader:SetUniformFloat("flipMiniMap", getMiniMapFlipped() and 1 or 0) + fullScreenQuadVAO:DrawArrays(GL.TRIANGLES) + infoMetalShader:Deactivate() + gl.DepthTest(true) + gl.Texture(0, false) + gl.Texture(1, false) + if not inminimap then + gl.Texture(2, false) + end +end + +function widget:DrawWorldPreUnit() + if autoreload then + infoMetalShader = LuaShader.CheckShaderUpdates(shaderSourceCache) or infoMetalShader + end + DrawInfoMetal(false) +end + +function widget:DrawInMiniMap() + DrawInfoMetal(true) +end + +if autoreload then + function widget:DrawScreen() + if infoMetalShader.DrawPrintf then infoMetalShader.DrawPrintf() end + end +end \ No newline at end of file From 3cae1a5115e63dfcdd2f04a8656b8c25d4225e7b Mon Sep 17 00:00:00 2001 From: Saurtron Date: Thu, 9 Jan 2025 01:32:33 +0100 Subject: [PATCH 02/14] Add showinfometal [0/1] action. --- luaui/Widgets/gui_info_metal.lua | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/luaui/Widgets/gui_info_metal.lua b/luaui/Widgets/gui_info_metal.lua index 68546cca503..9b7ae3a1894 100644 --- a/luaui/Widgets/gui_info_metal.lua +++ b/luaui/Widgets/gui_info_metal.lua @@ -52,6 +52,22 @@ local shaderSourceCache = { }, } +local callins = {'DrawWorldPreUnit', 'DrawInMiniMap'} +if autoreload then + callins[#callins+1] = 'DrawScreen' +end + +local function ShowInfoMetal(cmd, line, words, playerID) + local enable = (words[1] == '1') + for _, callinName in pairs(callins) do + if enable then + widgetHandler:UpdateCallIn(callinName) + else + widgetHandler:RemoveCallIn(callinName) + end + end +end + function widget:Initialize() if not gl.CreateShader then -- no shader support, so just remove the widget itself, especially for headless widgetHandler:RemoveWidget() @@ -62,6 +78,13 @@ function widget:Initialize() if not shaderCompiled then Spring.Echo("Failed to compile Info Metal View GL4") end fullScreenQuadVAO = MakeTexRectVAO()-- -1, -1, 1, 0, 0,0,1, 0.5 + + widgetHandler:AddAction("showinfometal", ShowInfoMetal, nil, "tp") + ShowInfoMetal(nil, nil, "1") +end + +function widget:Shutdown() + widgetHandler:RemoveAction("showinfometal") end function DrawInfoMetal(inminimap) @@ -100,8 +123,6 @@ function widget:DrawInMiniMap() DrawInfoMetal(true) end -if autoreload then - function widget:DrawScreen() - if infoMetalShader.DrawPrintf then infoMetalShader.DrawPrintf() end - end -end \ No newline at end of file +function widget:DrawScreen() + if infoMetalShader.DrawPrintf then infoMetalShader.DrawPrintf() end +end From 4df3aea202169865662db8ce68122d0af523b28a Mon Sep 17 00:00:00 2001 From: Saurtron Date: Thu, 9 Jan 2025 01:35:09 +0100 Subject: [PATCH 03/14] Bind metal hotkeys to showinfometal. --- luaui/Widgets/gui_keybind_info.lua | 2 +- luaui/Widgets/gui_screen_mode_info.lua | 2 +- luaui/configs/hotkeys/grid_keys.txt | 2 +- luaui/configs/hotkeys/grid_keys_60pct.txt | 2 +- luaui/configs/hotkeys/legacy_keys.txt | 2 +- luaui/configs/hotkeys/legacy_keys_60pct.txt | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/luaui/Widgets/gui_keybind_info.lua b/luaui/Widgets/gui_keybind_info.lua index ab7448a202b..3c9250a585e 100644 --- a/luaui/Widgets/gui_keybind_info.lua +++ b/luaui/Widgets/gui_keybind_info.lua @@ -216,7 +216,7 @@ local function refreshText() { type = lineType.key, key = getActionHotkey('showelevation'), text = Spring.I18N('ui.keybinds.cameraModes.heightmap') }, { type = lineType.key, key = getActionHotkey('showpathtraversability'), text = Spring.I18N('ui.keybinds.cameraModes.traversability')}, { type = lineType.key, key = getActionHotkey('lastmsgpos'), text = Spring.I18N('ui.keybinds.cameraModes.mapmarks') }, - { type = lineType.key, key = getActionHotkey('showmetalmap'), text = Spring.I18N('ui.keybinds.cameraModes.resourceSpots') }, + { type = lineType.key, key = getActionHotkey('showinfometal'), text = Spring.I18N('ui.keybinds.cameraModes.resourceSpots') }, { type = lineType.key, key = getActionHotkey('hideinterface'), text = Spring.I18N('ui.keybinds.cameraModes.interface') }, { type = lineType.blank }, { type = lineType.title, text = Spring.I18N('ui.keybinds.sound.title') }, diff --git a/luaui/Widgets/gui_screen_mode_info.lua b/luaui/Widgets/gui_screen_mode_info.lua index 284a28eeb35..fb142d369e7 100644 --- a/luaui/Widgets/gui_screen_mode_info.lua +++ b/luaui/Widgets/gui_screen_mode_info.lua @@ -52,7 +52,7 @@ end local function updateKeys() currentLayout = spGetConfigString("KeyboardLayout", "qwerty") screenModeOverviewTable.keyset = getActionHotkey("toggleoverview") - metalKey = getActionHotkey("showmetalmap") + metalKey = getActionHotkey("showinfometal") heightKey = getActionHotkey("showelevation") pathKey = getActionHotkey("showpathtraversability") end diff --git a/luaui/configs/hotkeys/grid_keys.txt b/luaui/configs/hotkeys/grid_keys.txt index ca7b7090cba..73c8249a812 100644 --- a/luaui/configs/hotkeys/grid_keys.txt +++ b/luaui/configs/hotkeys/grid_keys.txt @@ -107,7 +107,7 @@ bind Ctrl+f6 viewspring bind Ctrl+f7 HideInterface bind Any+f5 LastMsgPos bind Any+f6 ShowPathTraversability -bind Any+f7 ShowMetalMap +bind Any+f7 showinfometal bind Any+f8 ShowElevation bind f10 options diff --git a/luaui/configs/hotkeys/grid_keys_60pct.txt b/luaui/configs/hotkeys/grid_keys_60pct.txt index b98ffd0fc94..76318145217 100644 --- a/luaui/configs/hotkeys/grid_keys_60pct.txt +++ b/luaui/configs/hotkeys/grid_keys_60pct.txt @@ -107,7 +107,7 @@ bind Ctrl+meta+6 viewspring bind Ctrl+meta+7 HideInterface bind meta+5 LastMsgPos bind meta+6 ShowPathTraversability -bind meta+7 ShowMetalMap +bind meta+7 showinfometal bind meta+8 ShowElevation bind f10 options diff --git a/luaui/configs/hotkeys/legacy_keys.txt b/luaui/configs/hotkeys/legacy_keys.txt index f674d429478..0f5acf388ae 100644 --- a/luaui/configs/hotkeys/legacy_keys.txt +++ b/luaui/configs/hotkeys/legacy_keys.txt @@ -92,7 +92,7 @@ bind Ctrl+f5 viewfree bind Any+f1 ShowElevation bind Any+f2 ShowPathTraversability bind Any+f3 LastMsgPos -bind Any+f4 ShowMetalMap +bind Any+f4 showinfometal bind Any+f5 HideInterface bind Any+f6 MuteSound bind Any+f7 DynamicSky diff --git a/luaui/configs/hotkeys/legacy_keys_60pct.txt b/luaui/configs/hotkeys/legacy_keys_60pct.txt index 255f0706072..3bc35acfcfe 100644 --- a/luaui/configs/hotkeys/legacy_keys_60pct.txt +++ b/luaui/configs/hotkeys/legacy_keys_60pct.txt @@ -97,7 +97,7 @@ bind Ctrl+meta+5 viewfree bind meta+1 ShowElevation bind meta+2 ShowPathTraversability bind meta+3 LastMsgPos -bind meta+4 ShowMetalMap +bind meta+4 showinfometal bind meta+5 HideInterface bind meta+6 MuteSound bind meta+7 DynamicSky From fb10989f2cd4d880ffaefce5dddfb4d69e7d7e85 Mon Sep 17 00:00:00 2001 From: Saurtron Date: Thu, 9 Jan 2025 01:36:09 +0100 Subject: [PATCH 04/14] Add automatic toggling of showinfometal. --- luaui/Widgets/cmd_area_mex.lua | 24 ----------------- luaui/Widgets/gui_metalmode.lua | 42 +++++++++++++++++++++++++++++ luaui/Widgets/gui_pregame_build.lua | 8 +++--- 3 files changed, 45 insertions(+), 29 deletions(-) create mode 100644 luaui/Widgets/gui_metalmode.lua diff --git a/luaui/Widgets/cmd_area_mex.lua b/luaui/Widgets/cmd_area_mex.lua index 87fe07f71d4..11ae7f63774 100644 --- a/luaui/Widgets/cmd_area_mex.lua +++ b/luaui/Widgets/cmd_area_mex.lua @@ -172,30 +172,6 @@ function widget:CommandNotify(id, params, options) end --- Adjust map view mode as needed -function widget:Update(dt) - local _, cmd, _ = spGetActiveCommand() - if cmd == CMD_AREA_MEX then - if spGetMapDrawMode() ~= 'metal' then - if Spring.GetMapDrawMode() == "los" then - retoggleLos = true - end - spSendCommands('ShowMetalMap') - toggledMetal = true - end - else - if toggledMetal then - spSendCommands('ShowStandard') - if retoggleLos then - Spring.SendCommands("togglelos") - retoggleLos = nil - end - toggledMetal = false - end - end -end - - function widget:SelectionChanged(sel) selectedUnits = sel end diff --git a/luaui/Widgets/gui_metalmode.lua b/luaui/Widgets/gui_metalmode.lua new file mode 100644 index 00000000000..c535db4a1f8 --- /dev/null +++ b/luaui/Widgets/gui_metalmode.lua @@ -0,0 +1,42 @@ +function widget:GetInfo() + return { + name = "Toggle metal view", + desc = "Toggles metal view when active command changes", + license = "GNU GPL, v2 or later", + layer = -50, + enabled = true + } +end + +VFS.Include("luarules/configs/customcmds.h.lua") + +local isMex = {} + +local function initMexes() + for uDefID, uDef in pairs(UnitDefs) do + if uDef.extractsMetal > 0 then + isMex[uDefID] = true + end + end +end + +function widget:Initialize() + if Spring.SetAutoShowMetal then + Spring.SetAutoShowMetal(false) + end + + local success, mapinfo = pcall(VFS.Include, "mapinfo.lua") + + if mapinfo and mapinfo["autoshowmetal"] then + initMexes() + else + widgetHandler:RemoveWidget() + end +end + +function widget:ActiveCommandChanged(cmdID) + local wantsMetal = (cmdID == CMD_AREA_MEX) or (cmdID and isMex[-cmdID]) or false + local onoff = wantsMetal and "1" or "0" + + Spring.SendCommands("showinfometal " .. onoff) +end diff --git a/luaui/Widgets/gui_pregame_build.lua b/luaui/Widgets/gui_pregame_build.lua index d1d3df153ec..095228a056a 100644 --- a/luaui/Widgets/gui_pregame_build.lua +++ b/luaui/Widgets/gui_pregame_build.lua @@ -190,11 +190,9 @@ local function setPreGamestartDefID(uDefID) local isMex = UnitDefs[uDefID] and UnitDefs[uDefID].extractsMetal > 0 if isMex then - if Spring.GetMapDrawMode() ~= "metal" then - Spring.SendCommands("ShowMetalMap") - end - elseif Spring.GetMapDrawMode() == "metal" then - Spring.SendCommands("ShowStandard") + Spring.SendCommands("showinfometal 1") + else + Spring.SendCommands("showinfometal 0") end end From fb461785ad209970d0d9aaf5e5beeb5f6c31afb9 Mon Sep 17 00:00:00 2001 From: Saurtron Date: Thu, 9 Jan 2025 01:37:36 +0100 Subject: [PATCH 05/14] Add chat autocomplete for showinfometal. --- luaui/Widgets/gui_chat.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/luaui/Widgets/gui_chat.lua b/luaui/Widgets/gui_chat.lua index 081c4904993..0a43ac9ae8b 100644 --- a/luaui/Widgets/gui_chat.lua +++ b/luaui/Widgets/gui_chat.lua @@ -309,6 +309,7 @@ local autocompleteCommands = { 'shadows', 'sharedialog', 'showelevation', + 'showinfometal', 'showmetalmap', 'showpathcost', 'showpathflow', From f553dbc3ce42a57aa5709b8b9042b2162252bede Mon Sep 17 00:00:00 2001 From: Saurtron Date: Thu, 9 Jan 2025 01:48:15 +0100 Subject: [PATCH 06/14] Allow toggle with /showinfometal when no parameter is given. --- luaui/Widgets/gui_info_metal.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/luaui/Widgets/gui_info_metal.lua b/luaui/Widgets/gui_info_metal.lua index 9b7ae3a1894..102823000e3 100644 --- a/luaui/Widgets/gui_info_metal.lua +++ b/luaui/Widgets/gui_info_metal.lua @@ -57,10 +57,16 @@ if autoreload then callins[#callins+1] = 'DrawScreen' end +local viewEnabled = false + local function ShowInfoMetal(cmd, line, words, playerID) - local enable = (words[1] == '1') + if #words > 0 then + viewEnabled = (words[1] == '1') + else + viewEnabled = not viewEnabled + end for _, callinName in pairs(callins) do - if enable then + if viewEnabled then widgetHandler:UpdateCallIn(callinName) else widgetHandler:RemoveCallIn(callinName) @@ -79,7 +85,7 @@ function widget:Initialize() fullScreenQuadVAO = MakeTexRectVAO()-- -1, -1, 1, 0, 0,0,1, 0.5 - widgetHandler:AddAction("showinfometal", ShowInfoMetal, nil, "tp") + widgetHandler:AddAction("showinfometal", ShowInfoMetal, nil, "t") -- 'p' is coming from somewhere else ShowInfoMetal(nil, nil, "1") end From cb4bb78b8785898707e79f74c3b886938344522f Mon Sep 17 00:00:00 2001 From: Saurtron Date: Thu, 9 Jan 2025 01:59:21 +0100 Subject: [PATCH 07/14] Add WG.metalView so widgets can check current metalView status. --- luaui/Widgets/gui_info_metal.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/luaui/Widgets/gui_info_metal.lua b/luaui/Widgets/gui_info_metal.lua index 102823000e3..20a80745fc7 100644 --- a/luaui/Widgets/gui_info_metal.lua +++ b/luaui/Widgets/gui_info_metal.lua @@ -61,7 +61,11 @@ local viewEnabled = false local function ShowInfoMetal(cmd, line, words, playerID) if #words > 0 then - viewEnabled = (words[1] == '1') + local enabled = (words[1] == '1') + + if enabled == viewEnabled then return end + + viewEnabled = enabled else viewEnabled = not viewEnabled end @@ -72,9 +76,11 @@ local function ShowInfoMetal(cmd, line, words, playerID) widgetHandler:RemoveCallIn(callinName) end end + WG.metalView = viewEnabled end function widget:Initialize() + WG.metalView = false if not gl.CreateShader then -- no shader support, so just remove the widget itself, especially for headless widgetHandler:RemoveWidget() return From 28325ee90dac83bc7002e7f9dccedec97997ce3e Mon Sep 17 00:00:00 2001 From: Saurtron Date: Thu, 9 Jan 2025 02:05:19 +0100 Subject: [PATCH 08/14] Adapt some more widgets for the new infometal view. --- luaui/Widgets/gui_metalspots.lua | 4 +--- luaui/Widgets/gui_reclaim_field_highlight.lua | 3 +-- luaui/Widgets/gui_screen_mode_info.lua | 4 ++-- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/luaui/Widgets/gui_metalspots.lua b/luaui/Widgets/gui_metalspots.lua index c4de98472ea..0ba0cd0d09f 100644 --- a/luaui/Widgets/gui_metalspots.lua +++ b/luaui/Widgets/gui_metalspots.lua @@ -58,7 +58,6 @@ local spIsSphereInView = Spring.IsSphereInView local spGetUnitsInSphere = Spring.GetUnitsInSphere local spGetUnitDefID = Spring.GetUnitDefID local spGetGroundHeight = Spring.GetGroundHeight -local spGetMapDrawMode = Spring.GetMapDrawMode local spIsUnitAllied = Spring.IsUnitAllied local mySpots = {} -- {spotKey = {x = spot.x, y= spGetGroundHeight(spot.x, spot.z), z = spot.z, value = value, scale = scale, occupied = occupied, t = currentClock, ally = false, enemy = false, instanceID = "1024_1023"}} @@ -511,8 +510,7 @@ function widget:GameFrame(gf) end function widget:DrawWorldPreUnit() - local mapDrawMode = spGetMapDrawMode() - if metalViewOnly and mapDrawMode ~= 'metal' then return end + if metalViewOnly and not WG.metalView then return end if chobbyInterface then return end if Spring.IsGUIHidden() then return end diff --git a/luaui/Widgets/gui_reclaim_field_highlight.lua b/luaui/Widgets/gui_reclaim_field_highlight.lua index 79a3f4c7a67..f9bfe69cd61 100644 --- a/luaui/Widgets/gui_reclaim_field_highlight.lua +++ b/luaui/Widgets/gui_reclaim_field_highlight.lua @@ -80,7 +80,6 @@ local spGetGroundHeight = Spring.GetGroundHeight local spIsGUIHidden = Spring.IsGUIHidden local spTraceScreenRay = Spring.TraceScreenRay local spGetActiveCommand = Spring.GetActiveCommand -local spGetMapDrawMode = Spring.GetMapDrawMode local spGetUnitDefID = Spring.GetUnitDefID local spGetCameraVectors = Spring.GetCameraVectors @@ -610,7 +609,7 @@ do local function onMapDrawMode() -- todo: would be nice to set only when it changes -- todo: eg widget:MapDrawModeChanged(newMode, oldMode) - return actionActive == true or spGetMapDrawMode() == 'metal' + return actionActive == true or WG.metalView end local function onSelectReclaimer() diff --git a/luaui/Widgets/gui_screen_mode_info.lua b/luaui/Widgets/gui_screen_mode_info.lua index fb142d369e7..3f068702a7d 100644 --- a/luaui/Widgets/gui_screen_mode_info.lua +++ b/luaui/Widgets/gui_screen_mode_info.lua @@ -81,7 +81,7 @@ function widget:DrawScreen() local screenmodeChanged = newScreenmode ~= screenmode screenmode = newScreenmode - if (screenmode ~= 'normal' and screenmode ~= 'los') or st.name == 'ov' then + if WG.metalView or (screenmode ~= 'normal' and screenmode ~= 'los') or st.name == 'ov' then if (screenmodeChanged) then updateKeys() end local description, title = '', '' @@ -98,7 +98,7 @@ function widget:DrawScreen() elseif screenmode == 'pathTraversability' then title = i18n('ui.screenMode.pathingTitle') description = i18n('ui.screenMode.pathing', { keyset = pathKey }) - elseif screenmode == 'metal' then + elseif WG.metalView then title = i18n('ui.screenMode.resourcesTitle') description = i18n('ui.screenMode.resources', { keyset = metalKey }) end From 5f2f1dff3fcf62b5edb6d0be2ef70cbbadb907ba Mon Sep 17 00:00:00 2001 From: Saurtron Date: Thu, 9 Jan 2025 02:05:43 +0100 Subject: [PATCH 09/14] Remove now unused spGetMapDrawMode from cmd_area_mex. --- luaui/Widgets/cmd_area_mex.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/luaui/Widgets/cmd_area_mex.lua b/luaui/Widgets/cmd_area_mex.lua index 11ae7f63774..4c8a3d16a0c 100644 --- a/luaui/Widgets/cmd_area_mex.lua +++ b/luaui/Widgets/cmd_area_mex.lua @@ -14,7 +14,6 @@ end VFS.Include("luarules/configs/customcmds.h.lua") local spGetActiveCommand = Spring.GetActiveCommand -local spGetMapDrawMode = Spring.GetMapDrawMode local spGetUnitPosition = Spring.GetUnitPosition local spSendCommands = Spring.SendCommands local taremove = table.remove From 47eb3fcdbbbcea06bdaf125b9ff3a6f1d5f6079c Mon Sep 17 00:00:00 2001 From: Saurtron Date: Thu, 9 Jan 2025 02:13:15 +0100 Subject: [PATCH 10/14] Adapt gui_prospector. --- luaui/Widgets/gui_prospector.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/luaui/Widgets/gui_prospector.lua b/luaui/Widgets/gui_prospector.lua index 1846bcf4423..ad3a72b071b 100644 --- a/luaui/Widgets/gui_prospector.lua +++ b/luaui/Widgets/gui_prospector.lua @@ -28,7 +28,6 @@ local GetMouseState = Spring.GetMouseState local TraceScreenRay = Spring.TraceScreenRay local GetGroundInfo = Spring.GetGroundInfo local GetGameFrame = Spring.GetGameFrame -local GetMapDrawMode = Spring.GetMapDrawMode local glLineWidth = gl.LineWidth local glColor = gl.Color @@ -208,8 +207,7 @@ function widget:DrawScreen() local mexDefInfo if GetGameFrame() < 1 then - local drawMode = GetMapDrawMode() - if drawMode == "metal" then + if WG.metalView then mexDefInfo = mexDefInfos[defaultDefID] end else From 148f6ddafdca62a4ec459e876db46e59421ef9cf Mon Sep 17 00:00:00 2001 From: Saurtron Date: Thu, 9 Jan 2025 02:14:00 +0100 Subject: [PATCH 11/14] Adapt gui_geothermalspots. --- luaui/Widgets/gui_geothermalspots.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/luaui/Widgets/gui_geothermalspots.lua b/luaui/Widgets/gui_geothermalspots.lua index c7fbae7f4b3..1fc182308a4 100644 --- a/luaui/Widgets/gui_geothermalspots.lua +++ b/luaui/Widgets/gui_geothermalspots.lua @@ -25,7 +25,6 @@ local spIsGUIHidden = Spring.IsGUIHidden local spGetUnitsInSphere = Spring.GetUnitsInSphere local spGetUnitDefID = Spring.GetUnitDefID local spGetGroundHeight = Spring.GetGroundHeight -local spGetMapDrawMode = Spring.GetMapDrawMode local spots = {} local previousOsClock = os.clock() @@ -376,8 +375,7 @@ end function widget:DrawWorldPreUnit() - local mapDrawMode = spGetMapDrawMode() - if metalViewOnly and mapDrawMode ~= 'metal' then return end + if metalViewOnly and not WG.metalView then return end if chobbyInterface then return end if spIsGUIHidden() then return end From ca54236d4b020e7ec29e39df8dc5f85304684434 Mon Sep 17 00:00:00 2001 From: Saurtron Date: Thu, 9 Jan 2025 02:18:13 +0100 Subject: [PATCH 12/14] Remove empty line. --- luaui/Widgets/gui_info_metal.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/luaui/Widgets/gui_info_metal.lua b/luaui/Widgets/gui_info_metal.lua index 20a80745fc7..4256484a963 100644 --- a/luaui/Widgets/gui_info_metal.lua +++ b/luaui/Widgets/gui_info_metal.lua @@ -62,7 +62,6 @@ local viewEnabled = false local function ShowInfoMetal(cmd, line, words, playerID) if #words > 0 then local enabled = (words[1] == '1') - if enabled == viewEnabled then return end viewEnabled = enabled From 48ae20621a04e065b1876f6b8f6511c48db05a4f Mon Sep 17 00:00:00 2001 From: Saurtron Date: Thu, 9 Jan 2025 02:22:51 +0100 Subject: [PATCH 13/14] Check for gl.CreateShader via depends. --- luaui/Widgets/gui_info_metal.lua | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/luaui/Widgets/gui_info_metal.lua b/luaui/Widgets/gui_info_metal.lua index 4256484a963..ae8e4f571f1 100644 --- a/luaui/Widgets/gui_info_metal.lua +++ b/luaui/Widgets/gui_info_metal.lua @@ -7,7 +7,8 @@ function widget:GetInfo() date = "2024.12.22", license = "GPL V2", layer = 10001, - enabled = true + enabled = true, + depends = {"shaders"}, } end @@ -80,10 +81,6 @@ end function widget:Initialize() WG.metalView = false - if not gl.CreateShader then -- no shader support, so just remove the widget itself, especially for headless - widgetHandler:RemoveWidget() - return - end infoMetalShader = LuaShader.CheckShaderUpdates(shaderSourceCache) shaderCompiled = infoMetalShader:Initialize() if not shaderCompiled then Spring.Echo("Failed to compile Info Metal View GL4") end From 25eac8616d67e5c42a4df94e898dce9ba6fb1713 Mon Sep 17 00:00:00 2001 From: Saurtron Date: Thu, 9 Jan 2025 02:27:22 +0100 Subject: [PATCH 14/14] Properly disable initially. --- luaui/Widgets/gui_info_metal.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/luaui/Widgets/gui_info_metal.lua b/luaui/Widgets/gui_info_metal.lua index ae8e4f571f1..18ceeed7e3b 100644 --- a/luaui/Widgets/gui_info_metal.lua +++ b/luaui/Widgets/gui_info_metal.lua @@ -58,7 +58,7 @@ if autoreload then callins[#callins+1] = 'DrawScreen' end -local viewEnabled = false +local viewEnabled = true -- will disable at Initialize local function ShowInfoMetal(cmd, line, words, playerID) if #words > 0 then @@ -88,7 +88,7 @@ function widget:Initialize() fullScreenQuadVAO = MakeTexRectVAO()-- -1, -1, 1, 0, 0,0,1, 0.5 widgetHandler:AddAction("showinfometal", ShowInfoMetal, nil, "t") -- 'p' is coming from somewhere else - ShowInfoMetal(nil, nil, "1") + ShowInfoMetal(nil, nil, {"0"}) end function widget:Shutdown()