macroscript SetGridType category:"Custom" tooltip:"Set Grid Type" buttonText:"Set Grid Type" Icon:#("Maintoolbar",76) ( --Function that return value by its name which was readed from ini file. fn LoadValueFromFile FilePath SectionString KeyString = ( local theFile = FilePath as string local theSection = SectionString as string local theKey = KeyString as string -- If file is not exists if not doesFileExist theFile then ( return undefined ) return getINISetting theFile theSection theKey )--end of function --A function which is used to save defaults to a file fn SaveToFile FilePath SectionString KeyString ValueString = ( local theFile = FilePath as string local theSection = SectionString as string local theKey = KeyString as string local theValue = ValueString as string if not doesFileExist theFile then ( --take directory path part of a full file name local Directory = getFilenamePath theFile --Create a directory makeDir Directory --OutPut to log format "Directory % has been created\n" Directory ) --if write sucessfull if (setINISetting theFile theSection theKey theValue) then format "File has been updated sucessfully in %\n" theFile else format "ERROR: File was not saved in %\n" theFile )--end of function --variables related to the file naming and paths for saving defaults local ScriptName = "GridSpacingTool" local ScriptsFolder = pathconfig.getdir #userscripts local DefaultsFolder = pathconfig.appendPath ScriptsFolder "\\GridSpacingTool" local DefaultsFilePath = pathconfig.appendPath DefaultsFolder ("\\" + ScriptName + "_Defaults.ini") fn GW_PrintGrid = ( local GridSize = GetGridSpacing() local GridTypeString = "Grid Type: " + (GridType as string) local GridSizeString = "Grid Size: " + (GridSize as string) local Offset = 32 /*wPos = gw.getWinSizeX() - Offset - (GetTextExtent GridTypeString).x -- horizontal position max = gw.getWinSizeX() 0 is left hPos = gw.getWinSizeY() - Offset -- vertical position max = gw.getWinSizeY() . 0 is lower left gw.htext [wPos,hPos,0] GridTypeString color:white gw.updateScreen() */ wPos = gw.getWinSizeX() - Offset - (GetTextExtent GridSizeString).x -- horizontal position max = gw.getWinSizeX() 0 is left hPos = gw.getWinSizeY() - Offset - (GetTextExtent GridSizeString).y - 5 -- vertical position max = gw.getWinSizeY() . 0 is lower left gw.htext [wPos,hPos,0] GridSizeString color:white gw.updateScreen() ) on execute do ( rcMenu rcMapSize ( menuItem setGridDecimal "Decimal" checked:false menuItem setGridPow2 "Power of two" checked:false on setGridDecimal picked do ( --saving settings to a file SaveToFile DefaultsFilePath "Defaults" "GridType" "Decimal" SetGridSpacing 10 /*try ( */ unregisterRedrawViewsCallback GW_PrintGrid registerRedrawViewsCallback GW_PrintGrid /*) catch()*/ ) on setGridPow2 picked do ( --saving settings to a file SaveToFile DefaultsFilePath "Defaults" "GridType" "Pow2" SetGridSpacing 8 try ( unregisterRedrawViewsCallback GW_PrintGrid registerRedrawViewsCallback GW_PrintGrid ) catch() ) ) rcPos = mouse.screenpos popUpMenu rcMapSize pos:rcPos align:#align_vcentercenter ) ) macroscript IncreaseGrid category:"Custom" tooltip:"Increase Grid" buttonText:">>" ( fn GW_PrintGrid = ( local GridSize = GetGridSpacing() local GridTypeString = "Grid Type: " + (GridType as string) local GridSizeString = "Grid Size: " + (GridSize as string) local Offset = 32 /*wPos = gw.getWinSizeX() - Offset - (GetTextExtent GridTypeString).x -- horizontal position max = gw.getWinSizeX() 0 is left hPos = gw.getWinSizeY() - Offset -- vertical position max = gw.getWinSizeY() . 0 is lower left gw.htext [wPos,hPos,0] GridTypeString color:white gw.updateScreen() */ wPos = gw.getWinSizeX() - Offset - (GetTextExtent GridSizeString).x -- horizontal position max = gw.getWinSizeX() 0 is left hPos = gw.getWinSizeY() - Offset - (GetTextExtent GridSizeString).y - 5 -- vertical position max = gw.getWinSizeY() . 0 is lower left gw.htext [wPos,hPos,0] GridSizeString color:white gw.updateScreen() ) --variables related to the file naming and paths for saving defaults local ScriptName = "GridSpacingTool" local ScriptsFolder = pathconfig.getdir #userscripts local DefaultsFolder = pathconfig.appendPath ScriptsFolder "\\GridSpacingTool" local DefaultsFilePath = pathconfig.appendPath DefaultsFolder ("\\" + ScriptName + "_Defaults.ini") --Function that return value by its name which was readed from ini file. fn LoadValueFromFile FilePath SectionString KeyString = ( local theFile = FilePath as string local theSection = SectionString as string local theKey = KeyString as string -- If file is not exists if not doesFileExist theFile then ( return undefined ) return getINISetting theFile theSection theKey )--end of function on execute do ( local CurrentGridSpacing = GetGridSpacing() local GridType = LoadValueFromFile DefaultsFilePath "Defaults" "GridType" if GridType == "Pow2" then ( (SetGridSpacing (CurrentGridSpacing*2)) ) if GridType == "Decimal" then ( case CurrentGridSpacing of ( 1: SetGridSpacing 5 5: SetGridSpacing 10 10: SetGridSpacing 20 20: SetGridSpacing 30 30: SetGridSpacing 40 40: SetGridSpacing 50 50: SetGridSpacing 100 100: SetGridSpacing 200 200: SetGridSpacing 300 300: SetGridSpacing 400 400: SetGridSpacing 500 500: SetGridSpacing 1000 ) ) try ( unregisterRedrawViewsCallback GW_PrintGrid registerRedrawViewsCallback GW_PrintGrid ) catch() ) ) macroscript DecreaseGrid category:"Custom" tooltip:"Decrease Grid" buttonText:"<<" ( fn GW_PrintGrid = ( local GridSize = GetGridSpacing() local GridTypeString = "Grid Type: " + (GridType as string) local GridSizeString = "Grid Size: " + (GridSize as string) local Offset = 32 /*wPos = gw.getWinSizeX() - Offset - (GetTextExtent GridTypeString).x -- horizontal position max = gw.getWinSizeX() 0 is left hPos = gw.getWinSizeY() - Offset -- vertical position max = gw.getWinSizeY() . 0 is lower left gw.htext [wPos,hPos,0] GridTypeString color:white gw.updateScreen() */ wPos = gw.getWinSizeX() - Offset - (GetTextExtent GridSizeString).x -- horizontal position max = gw.getWinSizeX() 0 is left hPos = gw.getWinSizeY() - Offset - (GetTextExtent GridSizeString).y - 5 -- vertical position max = gw.getWinSizeY() . 0 is lower left gw.htext [wPos,hPos,0] GridSizeString color:white gw.updateScreen() ) --variables related to the file naming and paths for saving defaults local ScriptName = "GridSpacingTool" local ScriptsFolder = pathconfig.getdir #userscripts local DefaultsFolder = pathconfig.appendPath ScriptsFolder "\\GridSpacingTool" local DefaultsFilePath = pathconfig.appendPath DefaultsFolder ("\\" + ScriptName + "_Defaults.ini") --Function that return value by its name which was readed from ini file. fn LoadValueFromFile FilePath SectionString KeyString = ( local theFile = FilePath as string local theSection = SectionString as string local theKey = KeyString as string -- If file is not exists if not doesFileExist theFile then ( return undefined ) return getINISetting theFile theSection theKey )--end of function on execute do ( local CurrentGridSpacing = GetGridSpacing() local GridType = LoadValueFromFile DefaultsFilePath "Defaults" "GridType" if GridType == "Pow2" then ( if CurrentGridSpacing != 1 then SetGridSpacing (CurrentGridSpacing/2) ) if GridType == "Decimal" then ( case CurrentGridSpacing of ( 5: SetGridSpacing 1 10: SetGridSpacing 5 20: SetGridSpacing 10 30: SetGridSpacing 20 40: SetGridSpacing 30 50: SetGridSpacing 40 100: SetGridSpacing 50 200: SetGridSpacing 100 300: SetGridSpacing 200 400: SetGridSpacing 300 500: SetGridSpacing 400 1000: SetGridSpacing 500 ) ) try ( unregisterRedrawViewsCallback GW_PrintGrid registerRedrawViewsCallback GW_PrintGrid ) catch() ) )