Login  Register
 



Post new topicReply to topic Go to page 1, 2  Next
 
Author Message
 PostPosted: 14 Mar, 2011 
 
User avatar

Joined: 25 Mar, 2010
Posts: 1495
Offline
I want to split the Surface and the Submerge command from one button to two for Submersible units: Tigershark, Atlantis and Kraken.

The end result would be two buttons.

When I have a mixed group of subs that are both surfaced and submerged I could push one of these buttons to submerged them all or I could push one of these buttons to surface them all.

Here is the code from FA. LoD told me to make the code work just one way and add another toggle to go just the other way.
Code:
# used by subs that can dive/surface
local function DiveOrderBehavior(self, modifiers)
    if modifiers.Left then
       IssueCommand(GetUnitCommandFromCommandCap(self._order))
        self:ToggleCheck()
    elseif modifiers.Right then
        if self._isAutoMode then
            self._curHelpText = self._data.helpText
            if self.autoBuildEffect then
                self.autoBuildEffect:Destroy()
            end
            self.autoModeIcon:SetAlpha(0)
            self._isAutoMode = false
        else
            self._curHelpText = self._data.helpText .. "_auto"
            if not self.autoBuildEffect then
                self.autoBuildEffect = CreateAutoBuildEffect(self)
            end
            self.autoModeIcon:SetAlpha(1)
            self._isAutoMode = true
        end
        if controls.mouseoverDisplay.text then
            controls.mouseoverDisplay.text:SetText(self._curHelpText)
        end
       SetAutoSurfaceMode(currentSelection, self._isAutoMode)
    end
end

local function DiveInitFunction(control, unitList)
    if not control.autoModeIcon then
        control.autoModeIcon = Bitmap(control, UIUtil.UIFile('/game/orders/autocast_bmp.dds'))
        LayoutHelpers.AtCenterIn(control.autoModeIcon, control)
        control.autoModeIcon:DisableHitTest()
        control.autoModeIcon:SetAlpha(0)
        control.autoModeIcon.OnHide = function(self, hidden)
            if not hidden and control:IsDisabled() then
                return true
            end
        end
    end

    if not control.mixedModeIcon then
        control.mixedModeIcon = Bitmap(control.autoModeIcon, UIUtil.UIFile('/game/orders-panel/question-mark_bmp.dds'))
        LayoutHelpers.AtRightTopIn(control.mixedModeIcon, control)
        control.mixedModeIcon:DisableHitTest()
        control.mixedModeIcon:SetAlpha(0)
        control.mixedModeIcon.OnHide = function(self, hidden)
            if not hidden and control:IsDisabled() then
                return true
            end
        end
    end

    control._isAutoMode = GetIsAutoSurfaceMode(unitList)

    if control._isAutoMode then
        control._curHelpText = control._data.helpText .. "_auto"
        control.autoBuildEffect = CreateAutoBuildEffect(control)
        control.autoModeIcon:SetAlpha(1)
    else
        control._curHelpText = control._data.helpText
    end

    local submergedState = GetIsSubmerged(unitList)

    if submergedState == -1 then
        control:SetCheck(true)
    elseif submergedState == 1 then
        control:SetCheck(false)
    else
        control:SetCheck(false)
        control.mixedModeIcon:SetAlpha(1)
    end
end

function ToggleDiveOrder()
    local diveCB = orderCheckboxMap["RULEUCC_Dive"]
    if diveCB then
        DiveOrderBehavior(diveCB, {Left = true})
    end
end

_________________
Yeah Toast!


Last edited by Bastilean on 14 Mar, 2011, edited 1 time in total.

Top
 Profile  
 PostPosted: 14 Mar, 2011 
 
User avatar

Joined: 19 Jul, 2009
Posts: 2972
Offline
There's no way to 'edit' the behavior of actual command caps (generally anything that starts with RULEUCC). You'd have to create two new abilities that manually issue dive / surface commands, disabling themselves and enabling the other one, and assign these two abilities to each unit (making sure the correct one starts enabled in the unit's script; the Kraken and Atlantis are built surfaced and the Tigershark is built submerged).

It's possible to do, but it'll be a lot of work, probably won't work as smoothly as the actual command button, and would probably have to be placed in the ability section of the button bar.


Top
 Profile  
 PostPosted: 14 Mar, 2011 
 
User avatar

Joined: 25 Mar, 2010
Posts: 1495
Offline
That sounds like what I want. Why do you have to know whether the unit starts surfaced? Could the game check if the unit is surfaced or submerged upon creation? Maybe this would be more work?

Is there enough space fore the Atlantis in the abilities section of the command bar?

Also, why would it not work as well/smoothly as the current toggle?

_________________
Yeah Toast!


Top
 Profile  
 PostPosted: 14 Mar, 2011 
 

Joined: 01 Jan, 2011
Posts: 1025
Offline
I could be wrong here, but my recent experimentation with LoD's tech toggle ability has enlightened me to something that might be useful for your case.

I wanted to enable the Tech Toggle ability by default on factories. The change was simple in the unit's script, which is invoked only upon the unit's completion of being build:

Code:
OnStopBeingBuilt = function(self,builder,layer)
    FactoryUnit.OnStopBeingBuilt(self,builder,layer)
    self:SetAbilityEnabled('Tech_Toggle', true)
    self.EffectsBag = {}
end,


By default, LoD set the ability to false. Then, if you look at the Tech_Toggle_Ability.lua file that he created in Revamp_Expansion.scd/abilities he switches the toggle states as follows:

Code:
OnAbility = function( unit, abilityBp, state )
        unit:RestoreBuildRestrictions()
   if state == 'activate' then
            unit:AddBuildRestriction(categories.TECH1)
    if EntityCategoryContains(categories.FACTORY, unit) then
        IssueClearCommands({unit})
    end
   else
            unit:AddBuildRestriction(categories.TECH2)
    if EntityCategoryContains(categories.FACTORY, unit) then
        IssueClearCommands({unit})
    end
   end
end


I'm sure LoD and Mithy can give you a more coherent explanation, but I think the above approach might be similar to what you want to do, the main difference being in the actual ability code. In your case, you would not be changes the menus on the hud, but the states of the units.

_________________
Image


Top
 Profile  
 PostPosted: 15 Mar, 2011 
 
User avatar

Joined: 19 Jul, 2009
Posts: 2972
Offline
Bastilean wrote:
That sounds like what I want. Why do you have to know whether the unit starts surfaced? Could the game check if the unit is surfaced or submerged upon creation? Maybe this would be more work?

That's what I mean. You can't just have the toggle default one way or another and leave it be. You'd have to have both toggles start disabled, and hook the OnStopBeingBuilt of each submersible unit, enabling the appropriate toggle depending on whether layer == 'Water' or 'Sub'.

Bastilean wrote:
Is there enough space fore the Atlantis in the abilities section of the command bar?

Also, why would it not work as well/smoothly as the current toggle?

Bar space would be one issue - if you have 5-6 units selected of different types, the current submerge button will always be present. With abilities, this will not be true, especially with units with many abilities already.

You will also have to clear the command queue of a unit performing a dive or surface (canceling all their other orders). There is absolutely no way around this. If I remember correctly, the engine dive toggle can be used without clearing the command queue.


Top
 Profile  
 PostPosted: 15 Mar, 2011 
 
User avatar

Joined: 25 Mar, 2010
Posts: 1495
Offline
Why do you have to clear the command que?

Why is there so many things that clear the command que?

Example: when an engineer is commanded to guard a commander and the command helps assist a factory why does the engineer start to assist the factory and lose it's command to guard the commander?

Example2: You send 10 tanks to a transport. The transport is sitting pretty waiting for these tanks. You send 10 more tanks to a transport. The first tanks stop coming to the transport. Why did that happen? Why did the second batch clear the command for the first batch?

The code for TA was far more robust than the code for SupCom2 and it doesn't seem right that we have gone backwards this far.

_________________
Yeah Toast!


Top
 Profile  
 PostPosted: 15 Mar, 2011 
 
User avatar

Joined: 19 Jul, 2009
Posts: 2972
Offline
I can't answer the second part of that, but the answer to the first is simple (and may relate): we can't edit command queues on the sim side. We can clear them, we can add to them, but we can't view or remove things from them.

So, to use an ability to make a unit submerge, you have to do:
Code:
IssueClearCommands({self})
IssueDive({self})

If there's a way around this in SC2 that wasn't present in earlier games, I'd love to know about it, but I don't see any evidence of access to command queues.

Honestly, I have never issued a dive/surface order in SC2 with the normal button while a unit was moving. Does it still work on moving units? If so, then this would be a pretty huge loss in functionality for only a moderate gain. Assuming the units in question even have enough slots for two buttons with 2-3 types selected at once.


Top
 Profile  
 PostPosted: 15 Mar, 2011 
 
User avatar

Joined: 25 Mar, 2010
Posts: 1495
Offline
All my lovely UI suggestions so out of reach...

What about double clicking? Is there a way that if you double click on submerged units the surfaced units wouldn't be selected and vice versa?

_________________
Yeah Toast!


Top
 Profile  
 PostPosted: 15 Mar, 2011 
 
User avatar

Joined: 19 Jul, 2009
Posts: 2972
Offline
Well, in theory, it would be possible to add a custom keymap that runs a UI lua function in uimain.lua that selects units based on their layer.

This would require a lua.scd override though, because the keymap files and uimain.lua are loaded before mod shadowing is available. I'm also not 100% sure whether or not you can determine layer from the UI. UI is hardly my specialty, and I've only briefly experimented with UI selection via category in FA.

Fake edit: Nevermind, luadoc to the rescue:

GetIsSubmerged
INFO: Determine if units are submerged (-1), not submerged(1) or unable to tell (0)

So yes, if you want to override lua.scd, it would be trivial to add a hotkey to select only submerged or only surfaced units. You might even be able to make a hotkey that both selects surfaced or submerged units and issues a dive/surface order to only those units, before restoring the original selection. No promises on that one though.

Edit: Whoops, I forgot that for no good reason, you can't issue most orders in the UI layer (just non-mobile construction orders). I guess this was to prevent the creation of UI bots or something, but it's a really dumb limitation. So you can select with one key, and issue the equalizing dive or surface order with another.


Top
 Profile  
 PostPosted: 15 Mar, 2011 
 
User avatar

Joined: 25 Mar, 2010
Posts: 1495
Offline
Sweet, as long as I can select specific to a layer I can use the current toggle. This is really nice.

_________________
Yeah Toast!


Top
 Profile  
 PostPosted: 15 Mar, 2011 
 

Joined: 02 Jul, 2010
Posts: 1261
Offline
What about making the unit in the script change say its select order when submerged so 1 type on unit would brake into 2 groups so a simple double click would select all submerged unit of that type?

_________________
Creator of SupCom2
Revamp Expansion Mod
Image
Image
Image


Top
 Profile  
 PostPosted: 16 Mar, 2011 
 

Joined: 26 Feb, 2009
Posts: 2996
Offline
Hi,

with my experiance with orders in FA, this is 100% possible.. in fa, and would not be hard to acheive once you know what your doing in orders.lua

just add 2 extra pulse toggles one for dive and one for surface.. check in the order function if blah is surfaced or blah is submeged on each toggle.. disabling the opposite toggle on each click.. if the criteria for submerged or surface is met..

i could do this very easy in FA, im not blowing my own trumpet.. im just stating its possible :)

_________________
Domino.
______________


Top
 Profile  
 PostPosted: 17 Mar, 2011 
 
User avatar

Joined: 25 Mar, 2010
Posts: 1495
Offline
Domino wrote:
i could do this very easy in FA, im not blowing my own trumpet.. im just stating its possible :)


Would you? If you have time. It sounds like if we had the FA script to do this, LoD and I could figure out how to port it to SupCom2.

Also, wouldn't people like to see this in FA too?

_________________
Yeah Toast!


Top
 Profile  
 PostPosted: 17 Mar, 2011 
 

Joined: 26 Feb, 2009
Posts: 2996
Offline
Hi,

sadly im full up with my own projects atm, so i cant make it for you..
maybe i will after i have completed my own work.. but no promises :)

i might have exaggerated a little when i said it was easy..
for me its would be rather easy.. because i have a mod that lets me set up custom toggles and such.. for you to figure out from scratch.. it wouldnt be so easy..
it took me about a month to put down the code to toggles and abilities..

umm made a support mod for this kinda thing.. but i havent released it yet.. :)
i will soon though.. :)

_________________
Domino.
______________


Top
 Profile  
 PostPosted: 17 Mar, 2011 
 
User avatar

Joined: 19 Jul, 2009
Posts: 2972
Offline
Domino wrote:
i could do this very easy in FA, im not blowing my own trumpet.. im just stating its possible :)

Actually, I'm pretty sure that orders.lua is not even used anymore. It's never imported in the lua and its functions are no longer called from CommandMode, and it has all sorts of functions and such that the game clearly doesn't use (e.g. all of the leftover early code for handling abilities, none of which is removed or commented out). Also, RULEUTC toggles are all 100% broken and will instantly crash the game if you try to assign them to a unit via blueprint.

Of course you can use abilities to do many of the same things you would have done in unit.lua/orders.lua, with more sim-side flexibility and no need for a special addon framework, but you can't customize the exact behavior of the UI button (e.g. making a toggle button use two different icons for its two states) without some sim scripting that removes and adds different abilities on each affected unit.

You definitely can't do anything UI-only with the built-in button system. You could create your own separate button bar and possibly script UI-related things with that, but you'd be starting from scratch.


Don't assume that anything from FA will work in SC2, especially UI-related. As theshadowlord has discovered, you can definitely still create lua UI panels in SC2, but none of the existing UI is actually handled by lua, even though there ARE leftover files that initially indicate that it is (e.g. orders.lua).

The core stuff like commandmode and worldview are still there, but again, much if not all of the built-in UI does not use this, and it seems to remain only to allow mods and/or other basic UI lua code to hook in.


Top
 Profile  
 PostPosted: 17 Mar, 2011 
 
User avatar

Joined: 25 Mar, 2010
Posts: 1495
Offline
Quote:
So yes, if you want to override lua.scd, it would be trivial to add a hotkey to select only submerged or only surfaced units.


That sounds ok. Hotkey = all submerged units get selected. In fact I am surprised there isn't already one of those. I am already overriding the lua.scd and the dlc1_lua.scd.

Sounds like offering a double click solution would be a lot more work.
Side Note: It would be kind of interesting to have the sub icon turn into a destroyer icon when surfaced as functionally they are very similar when the sub is surfaced. Yenzoo icons change when they enter the water. I honestly don't like this, because if you have sonar the difference should be obvious.


Related question to User Interface and what a unit is currently doing and selecting. Has anyone found the code that adjusts the drag box selection criteria? Currently it is troops, engineers (inlcuding ACU) and finally structures. I was wondering if we could play with these and make the selection dependent on what the unit is currently doing or has queued to do.
Here is the original thread for my idea: viewtopic.php?f=51&t=50067

_________________
Yeah Toast!


Top
 Profile  
 PostPosted: 17 Mar, 2011 
 
User avatar

Joined: 19 Jul, 2009
Posts: 2972
Offline
You could make a hotkey to select all submerged units in your army, as well as one to filter the current selection down to only submerged units.

Keymaps are defined in /lua/keymap/defaultkeymap.lua, while their actions (referred to only by name) are defined in /lua/keymap/keyactions.lua.

Start by looking at the escape or pause keys, as those follow the format you want: calling a function in an imported lua file that does something in UI global scope (in this case, selection). You can create a new blank lua file for this in your mod's .scd, create the selection functions in that, and then import that file+function in the same way the two aforementioned hotkeys do theirs.

Something like this might be a good start, although I can't guarantee that this will work without any testing:
Code:
--Select all units with SUB category that are submerged (ignore current selection)
function SelectSubmergedSubs()
    --Get all subs
    UISelectionByCategory('SUB')
    local selsubs = GetSelectedUnits()
    --Filter by submerged status
    local newselection = {}
    for k, unit in selsubs do
        if GetIsSubmerged({unit}) < 0 then
            table.insert(newselection, unit)
        end
    end

    SelectUnits(newselection)
end


--Filter current selection down to only submerged units with SUB category.
function FilterSubmergedSubs()
    local selection = GetSelectedUnits()
    --Get all subs
    local selsubs = EntityCategoryFilterDown(categories.SUB, selection)
    --Filter by submerged status
    local newselection = {}
    for k, unit in selsubs do
        if GetIsSubmerged({unit}) < 0 then
            table.insert(newselection, unit)
        end
    end

    SelectUnits(newselection)
end

I'm not sure what SelectUnits will do if the selection table is empty. Probably clear the current selection. If it causes problems, it's easy enough to add a table.empty or table.getn check, and do nothing if there are no units that meet criteria.


Top
 Profile  
 PostPosted: 16 Apr, 2011 
 

Joined: 02 Jul, 2010
Posts: 1261
Offline
I got bored so i created 2 mods one adds 1 new toggle which syncs units this toggle doesn't work like the normal toggle does it will only issue a single command submerge or surface, any units that are already under that command will be skipped, The 2nd mod is the same but split so you have 2 buttons to ether submerge or surface units, Fell free to use my code as you wish :wink:

both needs mithy's mod support v5 or up and can be use with CerusVI SC2 Mod Manager

EDIT Just updated the toggles so they clear command instead of waiting for there current commands to finish.

http://www.mediafire.com/file/dw3a6v96dzu7af1/Submerge%20%26%20Surface.rar

Image

_________________
Creator of SupCom2
Revamp Expansion Mod
Image
Image
Image


Last edited by liveordie on 17 Apr, 2011, edited 2 times in total.

Top
 Profile  
 PostPosted: 17 Apr, 2011 
 
User avatar

Joined: 25 Mar, 2010
Posts: 1495
Offline
liveordie wrote:
I got bored so i created 2 mods one adds 1 new toggle which syncs units this toggle doesn't work like the normal toggle does it will only issue a single command submerge or surface, any units that are already under that command will be skipped, The 2nd mod is the same but split so you have 2 buttons to ether submerge or surface units, Fell free to use my code as you wish :wink:

both needs mithy's mod support v5 or up and can be use with CerusVI SC2 Mod Manager

http://www.mediafire.com/file/6c3zdhgamat6szs/Submerge%20%26%20Surface.rar

Awesomeness

_________________
Yeah Toast!


Top
 Profile  
 PostPosted: 17 Apr, 2011 
 
User avatar

Joined: 19 Jul, 2009
Posts: 2972
Offline
I assume this uses sim orders to surface/dive, i.e. it has to clear commands or wait until the unit's command queue is finished?


Top
 Profile  
 PostPosted: 17 Apr, 2011 
 

Joined: 02 Jul, 2010
Posts: 1261
Offline
Mithy wrote:
I assume this uses sim orders to surface/dive, i.e. it has to clear commands or wait until the unit's command queue is finished?


It uses IssueDive it waits for the units command queue to finished i could change that its a easy fix.

_________________
Creator of SupCom2
Revamp Expansion Mod
Image
Image
Image


Top
 Profile  
 PostPosted: 17 Apr, 2011 
 

Joined: 02 Jul, 2010
Posts: 1261
Offline
Sorry for the bubble post I've updated the link about with a version that clears commands.

_________________
Creator of SupCom2
Revamp Expansion Mod
Image
Image
Image


Top
 Profile  
 PostPosted: 17 Apr, 2011 
 
User avatar

Joined: 25 Mar, 2010
Posts: 1495
Offline
What was wrong with the first one?

_________________
Yeah Toast!


Top
 Profile  
 PostPosted: 17 Apr, 2011 
 
User avatar

Joined: 19 Jul, 2009
Posts: 2972
Offline
They both have the same problem, which is what I mentioned earlier in the thread - you can't issue a dive/surface on a selective basis without using sim commands, which end up in the command queue. This means they either get processed after all of the units' current commands are done, or you have to clear the units' command queues to force them to surface immediately.

The built-in engine UI toggle doesn't have this limitation, and can surface/dive while executing other orders.


Top
 Profile  
 PostPosted: 18 Apr, 2011 
 

Joined: 02 Jul, 2010
Posts: 1261
Offline
Bastilean wrote:
What was wrong with the first one?


Nothing but now if the units under a command like move when you toggle Surface or Submerge it will clear commands and issue Surface or Submerge when click instead of waiting for the current command to finish.

Mithy wrote:
They both have the same problem, which is what I mentioned earlier in the thread - you can't issue a dive/surface on a selective basis without using sim commands, which end up in the command queue. This means they either get processed after all of the units' current commands are done, or you have to clear the units' command queues to force them to surface immediately.

The built-in engine UI toggle doesn't have this limitation, and can surface/dive while executing other orders.


Mithy the default Dive toggle does clear commands if you haven't looked so I'm not sure what your talking about :? , If you place a movement order using Move then toggle dive it will clear the units command just the same as my toggle now does, If your think this will clear the units build commands no it doesn't effect that at all.

EDIT Mithy i found some thing out if you have 2 units selected and issue a submerge or Surface using my toggle or the normal SC2 toggle it clears commands but not the order test it out.

_________________
Creator of SupCom2
Revamp Expansion Mod
Image
Image
Image


Last edited by liveordie on 18 Apr, 2011, edited 2 times in total.

Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic Go to page 1, 2  Next



Quick Tools

Search for:
Jump to:  

© 2002-2010 Gas Powered Games Corp. All Rights Reserved. Gas Powered Games is the exclusive trademark of Gas Powered Games Corp.
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
 
Home| Games | Company | News & Press | Support
  Terms of Use   |    Copyright Information   |    Privacy Policy