Page 6 of 7

Re: Area Mex

Posted: 13 May 2010, 19:41
by mk_fg
polemarque_ wrote: I mist it sorry.
But your "updated red" does not work with me (BAV7.12)
Probably because of bogus (now-obsolete) version check.
Try the attached version I've pulled from my ~/.spring, should work. The only change from previously posted one is

Code: Select all

-       if (Game.modVersion ~= 'V7.1') then return end
+       if (string.find(Game.modVersion, 'V7.1') ~= 1) then return end

Re: Area Mex

Posted: 13 May 2010, 21:28
by polemarque_
Works fine. thanks !!!

PS : can you tell me what you change between the two version of the widget (original VS yours)

Re: Area Mex

Posted: 13 May 2010, 21:30
by Pxtl
Does this thing still blow up when faced with a metal map?

Re: Area Mex

Posted: 14 May 2010, 03:01
by mk_fg
polemarque_ wrote:Works fine. thanks !!!

PS : can you tell me what you change between the two version of the widget (original VS yours)
AreaMex adds it's commands to widgetHandler.customCommands table, which is used by some default layout handlers.

RedUI sets layout handler with "widgetHandler:ConfigLayoutHandler(dummylayouthandler)", and "dummylayouthandler" should return something like "menuName, xIcons, yIcons, removeCmds, customCmds, onlyTexCmds, reTexCmds, reNamedCmds, reTooltipCmds, reParamsCmds, iconList", what it actually returns is

Code: Select all

return "", xIcons, yIcons, {}, {}, {}, {}, {}, {}, {}, iconList
so it doesn't grabs widgetHandler.customCommands and passes them on, always passing an empty table for these.
Dunno if it's done intentionally, so widgets won't mess the interface with their buttons, or if it's just some oversight (that might be already fixed in later RedUI versions).

I've changed it like that:

Code: Select all

local custom_cmdz = widgetHandler.customCommands
return "", xIcons, yIcons, {}, custom_cmdz, {}, {}, {}, {}, {}, iconList
fixing the problem.

Re: Area Mex

Posted: 14 May 2010, 08:13
by Google_Frog
Does this thing still blow up when faced with a metal map?
No there's been a check for large metal counts for a while. Though go ahead and test latest to see if something doesn't work.

Re: Area Mex

Posted: 21 Oct 2010, 21:16
by Chojin
When using BA's Red GUI (currently v7.19) and adjusting it to accept customCommands (as mk_fg suggested; thanks!), the button is shown as command no matter if you use the no_button version or not and no matter what unit is selected.

I added a check to make sure a builder is selected here:

Code: Select all

function widget:CommandsChanged()
        local units=spGetSelectedUnits()

        for i, id in pairs(units) do
                if mexBuilder[id] then
                        local customCommands = widgetHandler.customCommands

                        table.insert(customCommands, { 
                                id      = CMD_AREA_MEX,
                                type    = CMDTYPE.ICON_AREA,
                                tooltip = 'Define an area to make mexes in',
                                name    = 'Mex',
                                cursor  = 'Repair',
                                action  = 'areamex',
                        })
                        return
                end
        end
end
It works - but is it a bad idea to do the check there? Had no other idea where else to put it.

Thank you for this nice widget!

Re: Area Mex

Posted: 21 Oct 2010, 21:21
by Chojin
Also.. there is no way to activate the metal-map view when the button is clicked/shortcut is pressed.. is there?

Re: Area Mex

Posted: 22 Oct 2010, 08:59
by Google_Frog
Not that I know of. I attempted something similar with the heightmap display once. Widgets can toggle the metalmap but I haven't found a way to detect if the metalmap is already on before toggling it.

Re: Area Mex

Posted: 22 Oct 2010, 09:45
by zwzsg
Google_Frog wrote:I haven't found a way to detect if the metalmap is already on before toggling it.
Spring.GetMapDrawMode()=="metal"

Play moar KP!

Re: Area Mex

Posted: 22 Oct 2010, 15:01
by Chojin
I found that function, but as far as I understood the actual action of clicking the button/pressing the shortcut and doing the area selection is done outside the widget and afterward sets parameters for the widget.

Maybe a function (to switch to metal-map view and back) could be attached to the CustomCommand itself, triggered when the selection mode is started/has ended (right before the widget processes the coordinates)?

Re: Area Mex

Posted: 22 Oct 2010, 15:46
by zwzsg
local _,cmd=Spring.GetActiveCommand()

Player moar KP!

Re: Area Mex

Posted: 22 Oct 2010, 17:15
by CarRepairer
Google_Frog wrote:Not that I know of. I attempted something similar with the heightmap display once. Widgets can toggle the metalmap but I haven't found a way to detect if the metalmap is already on before toggling it.
Easymetal has been in CA for years, it does it.

Re: Area Mex

Posted: 22 Oct 2010, 18:07
by zwzsg
Years? Damn you CA! "Kernel Panic Geos Highlight ("Highlight the Geovents when placing Buildings, or when in metal view)" has only been in Kernel Panic for 1.8 year!

Re: Area Mex

Posted: 23 Oct 2010, 00:59
by Chojin
Cool, thanks for the tips! I managed to have it show the metal-map view and switch back to normal view once the command was given.

But now I'm wondering how to disable the metal-map view when canceling the command. I searched the wiki and the source for call-ins handling this case, but couldn't find any useful ones.

Sorry for bothering with so many questions. Any more hints would be greatly appreciated :)

Re: Area Mex

Posted: 23 Oct 2010, 02:09
by Niobium
Chojin wrote:But now I'm wondering how to disable the metal-map view when canceling the command. I searched the wiki and the source for call-ins handling this case, but couldn't find any useful ones.
Afaik you have to poll the active command on :Update or some other frequent callin

Re: Area Mex

Posted: 23 Oct 2010, 13:53
by Chojin
I was afraid I had to do it like that, but the lua profiler doesn't show much cpu usage - so I guess it's ok:

Code: Select all

local spGetActiveCommand = Spring.GetActiveCommand
local spGetMapDrawMode = Spring.GetMapDrawMode
local spSendCommands = Spring.SendCommands

local toggledMetal

function widget:DrawScreen()
        local _,cmd,_ = spGetActiveCommand()
        if (cmd == CMD_AREA_MEX) then
                if (spGetMapDrawMode() ~= 'metal') then
                        spSendCommands({'ShowMetalMap'})
                        toggledMetal = true
                end
        else
                if toggledMetal then
                        spSendCommands({'ShowStandard'})
                        toggledMetal = false
                end
        end
end
It has to be done via Spring.SendCommands, right? There is no function to modify the view directly? Also, should I add a GetGameFrame() check to run this every n frames instead of every game frame? Would that be better?

Thanks again!

Re: Area Mex

Posted: 23 Oct 2010, 14:33
by Niobium
The way you are doing it is perfect. As for performance what you are doing will have absolutely no impact, especially relative performance of other parts of area mex.

In regards to callins, :GameFrame does not fire when the game is paused (yet user can still click area mex and change commands etc) so you want it on :Update (You can put it on one of the draw callins and it'll work perfectly, but it'll look odd as it isn't drawing anything. Also the multithreaded spring build apparently has issues with widgets and draw callins, so the less you put in them the better I guess.)

Re: Area Mex

Posted: 23 Oct 2010, 16:53
by Chojin
Great! Thank you for your reply, Niobium!

I attached what I have so far.

Edit: Sorry, removed file:close() from cmd_area_mex, which caused an error. Re-uploaded.

Re: Area Mex

Posted: 24 Oct 2010, 00:40
by aegis
NTG wrote:Image
what kind of tsp solver is this using?

Re: Area Mex

Posted: 24 Oct 2010, 01:27
by Niobium
aegis wrote:
NTG wrote:Image
what kind of tsp solver is this using?
Bizarrely written repeated nearest-neighbour