Area Mex - Page 6

Area Mex

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

mk_fg
Posts: 6
Joined: 07 Feb 2010, 07:40

Re: Area Mex

Post by mk_fg » 13 May 2010, 19:41

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
Attachments
gui_red_buildordermenu_mk2.lua
(15.38 KiB) Downloaded 42 times
0 x

polemarque_
Posts: 3
Joined: 08 May 2010, 19:51

Re: Area Mex

Post by polemarque_ » 13 May 2010, 21:28

Works fine. thanks !!!

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

User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

Re: Area Mex

Post by Pxtl » 13 May 2010, 21:30

Does this thing still blow up when faced with a metal map?
0 x

mk_fg
Posts: 6
Joined: 07 Feb 2010, 07:40

Re: Area Mex

Post by mk_fg » 14 May 2010, 03:01

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.
0 x

Google_Frog
Moderator
Posts: 2440
Joined: 12 Oct 2007, 09:24

Re: Area Mex

Post by Google_Frog » 14 May 2010, 08:13

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.
0 x

Chojin
Posts: 141
Joined: 04 Oct 2006, 11:22

Re: Area Mex

Post by Chojin » 21 Oct 2010, 21:16

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!
0 x

Chojin
Posts: 141
Joined: 04 Oct 2006, 11:22

Re: Area Mex

Post by Chojin » 21 Oct 2010, 21:21

Also.. there is no way to activate the metal-map view when the button is clicked/shortcut is pressed.. is there?
0 x

Google_Frog
Moderator
Posts: 2440
Joined: 12 Oct 2007, 09:24

Re: Area Mex

Post by Google_Frog » 22 Oct 2010, 08:59

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.
0 x

User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7017
Joined: 16 Nov 2004, 13:08

Re: Area Mex

Post by zwzsg » 22 Oct 2010, 09:45

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!
0 x

Chojin
Posts: 141
Joined: 04 Oct 2006, 11:22

Re: Area Mex

Post by Chojin » 22 Oct 2010, 15:01

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)?
0 x

User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7017
Joined: 16 Nov 2004, 13:08

Re: Area Mex

Post by zwzsg » 22 Oct 2010, 15:46

local _,cmd=Spring.GetActiveCommand()

Player moar KP!
0 x

User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: Area Mex

Post by CarRepairer » 22 Oct 2010, 17:15

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.
0 x

User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7017
Joined: 16 Nov 2004, 13:08

Re: Area Mex

Post by zwzsg » 22 Oct 2010, 18:07

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!
0 x

Chojin
Posts: 141
Joined: 04 Oct 2006, 11:22

Re: Area Mex

Post by Chojin » 23 Oct 2010, 00:59

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 :)
0 x

User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: Area Mex

Post by Niobium » 23 Oct 2010, 02:09

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
0 x

Chojin
Posts: 141
Joined: 04 Oct 2006, 11:22

Re: Area Mex

Post by Chojin » 23 Oct 2010, 13:53

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!
0 x

User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: Area Mex

Post by Niobium » 23 Oct 2010, 14:33

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.)
0 x

Chojin
Posts: 141
Joined: 04 Oct 2006, 11:22

Re: Area Mex

Post by Chojin » 23 Oct 2010, 16:53

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.
Attachments
cmd_area_mex.lua
Modified version 2.2 (originally no_button, but that depends on the mod played): shows metal-map view; should work for XTA too; ensures command button shows only for units able to build mexes.
(10.41 KiB) Downloaded 49 times
gui_red_buildordermenu.lua
Modified to handle customCommands (like areamex), from BA v7.19.
(15.06 KiB) Downloaded 32 times
0 x

User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: Area Mex

Post by aegis » 24 Oct 2010, 00:40

NTG wrote:Image
what kind of tsp solver is this using?
0 x

User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: Area Mex

Post by Niobium » 24 Oct 2010, 01:27

aegis wrote:
NTG wrote:Image
what kind of tsp solver is this using?
Bizarrely written repeated nearest-neighbour
0 x

Post Reply

Return to “Lua Scripts”