Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/session/developer_overlay.js
function DeveloperOverlay() | function DeveloperOverlay(playerViewControl) | ||||
{ | { | ||||
this.commandHeight = 20; | this.commandHeight = 20; | ||||
this.displayState = false; | this.displayState = false; | ||||
this.timeWarp = false; | this.timeWarp = false; | ||||
this.changePerspective = false; | |||||
this.controlAll = false; | this.controlAll = false; | ||||
this.playerViewControl = playerViewControl; | |||||
Engine.GetGUIObjectByName("devCommandsOverlay").onPress = this.toggle; | Engine.GetGUIObjectByName("devCommandsOverlay").onPress = this.toggle; | ||||
this.layout(); | this.layout(); | ||||
registerSimulationUpdateHandler(this.update.bind(this)); | |||||
registerEntitySelectionChangeHandler(this.update.bind(this)); | |||||
} | } | ||||
DeveloperOverlay.prototype.getCommands = function() { | DeveloperOverlay.prototype.getCommands = function() { | ||||
return [ | return [ | ||||
{ | { | ||||
"label": translate("Control all units"), | "label": translate("Control all units"), | ||||
"onPress": checked => { | "onPress": checked => { | ||||
Engine.PostNetworkCommand({ | Engine.PostNetworkCommand({ | ||||
"type": "control-all", | "type": "control-all", | ||||
"flag": checked | "flag": checked | ||||
}); | }); | ||||
}, | }, | ||||
"checked": () => this.controlAll, | "checked": () => this.controlAll, | ||||
}, | }, | ||||
{ | { | ||||
"label": translate("Change perspective"), | "label": translate("Change perspective"), | ||||
"onPress": checked => { | "onPress": checked => { | ||||
this.setChangePerspective(checked); | this.playerViewControl.setChangePerspective(checked); | ||||
}, | }, | ||||
}, | }, | ||||
{ | { | ||||
"label": translate("Display selection state"), | "label": translate("Display selection state"), | ||||
"onPress": checked => { | "onPress": checked => { | ||||
this.displayState = checked; | this.displayState = checked; | ||||
this.update(); | |||||
}, | }, | ||||
}, | }, | ||||
{ | { | ||||
"label": translate("Pathfinder overlay"), | "label": translate("Pathfinder overlay"), | ||||
"onPress": checked => { | "onPress": checked => { | ||||
Engine.GuiInterfaceCall("SetPathfinderDebugOverlay", checked); | Engine.GuiInterfaceCall("SetPathfinderDebugOverlay", checked); | ||||
}, | }, | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | DeveloperOverlay.prototype.layout = function() | ||||
overlaySize.bottom = overlaySize.top + overlayHeight; | overlaySize.bottom = overlaySize.top + overlayHeight; | ||||
overlay.size = overlaySize; | overlay.size = overlaySize; | ||||
this.updateValues(); | this.updateValues(); | ||||
}; | }; | ||||
DeveloperOverlay.prototype.updateValues = function() | DeveloperOverlay.prototype.updateValues = function() | ||||
{ | { | ||||
let commands = this.getCommands(); | this.getCommands().forEach((command, i) => { | ||||
for (let i = 0; i < commands.length; ++i) | |||||
{ | |||||
let command = commands[i]; | |||||
let body = Engine.GetGUIObjectByName("dev_command[" + i + "]"); | |||||
if (body.hidden) | |||||
continue; | |||||
let checkbox = Engine.GetGUIObjectByName("dev_command_checkbox[" + i + "]"); | let checkbox = Engine.GetGUIObjectByName("dev_command_checkbox[" + i + "]"); | ||||
if (command.checked) | if (command.checked) | ||||
checkbox.checked = command.checked(); | checkbox.checked = command.checked(); | ||||
} | }); | ||||
}; | }; | ||||
DeveloperOverlay.prototype.toggle = function() | DeveloperOverlay.prototype.toggle = function() | ||||
{ | { | ||||
if (!g_GameAttributes.settings.CheatsEnabled && !g_IsReplay) | if (!g_GameAttributes.settings.CheatsEnabled && !g_IsReplay) | ||||
return; | return; | ||||
let overlay = Engine.GetGUIObjectByName("devCommandsOverlay"); | let overlay = Engine.GetGUIObjectByName("devCommandsOverlay"); | ||||
Show All 13 Lines | Engine.PostNetworkCommand({ | ||||
"translateMessage": true, | "translateMessage": true, | ||||
"translateParameters": [], | "translateParameters": [], | ||||
"parameters": {} | "parameters": {} | ||||
}); | }); | ||||
}; | }; | ||||
DeveloperOverlay.prototype.update = function() | DeveloperOverlay.prototype.update = function() | ||||
{ | { | ||||
let playerState = g_SimState.players[g_ViewedPlayer]; | |||||
this.controlAll = playerState ? playerState.controlsAll : false; | |||||
this.updateValues(); | this.updateValues(); | ||||
this.updateEntityState(); | |||||
} | |||||
DeveloperOverlay.prototype.updateEntityState = function() | |||||
{ | |||||
let debug = Engine.GetGUIObjectByName("debugEntityState"); | let debug = Engine.GetGUIObjectByName("debugEntityState"); | ||||
if (!this.displayState) | if (!this.displayState) | ||||
{ | { | ||||
debug.hidden = true; | debug.hidden = true; | ||||
return; | return; | ||||
} | } | ||||
Show All 19 Lines | DeveloperOverlay.prototype.updateEntityState = function() | ||||
debug.caption = text.replace(/\[/g, "\\["); | debug.caption = text.replace(/\[/g, "\\["); | ||||
}; | }; | ||||
DeveloperOverlay.prototype.isTimeWarpEnabled = function() { | DeveloperOverlay.prototype.isTimeWarpEnabled = function() { | ||||
return this.timeWarp; | return this.timeWarp; | ||||
}; | }; | ||||
DeveloperOverlay.prototype.isChangePerspective = function() { | |||||
return this.changePerspective; | |||||
}; | |||||
DeveloperOverlay.prototype.setChangePerspective = function(value) { | |||||
this.changePerspective = value; | |||||
selectViewPlayer(g_ViewedPlayer); | |||||
}; | |||||
DeveloperOverlay.prototype.isControlAll = function() { | DeveloperOverlay.prototype.isControlAll = function() { | ||||
return this.controlAll; | return this.controlAll; | ||||
}; | }; | ||||
DeveloperOverlay.prototype.setControlAll = function(value) { | |||||
this.controlAll = value; | |||||
}; |
Wildfire Games · Phabricator