diff --git a/binaries/data/mods/public/gui/session_new_old/input.js b/binaries/data/mods/public/gui/session_new_old/input.js deleted file mode 100644 index daddf76e77..0000000000 --- a/binaries/data/mods/public/gui/session_new_old/input.js +++ /dev/null @@ -1,568 +0,0 @@ -const SDL_BUTTON_LEFT = 1; -const SDL_BUTTON_MIDDLE = 2; -const SDL_BUTTON_RIGHT = 3; -const SDLK_RSHIFT = 303; -const SDLK_LSHIFT = 304; -// TODO: these constants should be defined somewhere else instead, in -// case any other code wants to use them too - -var INPUT_NORMAL = 0; -var INPUT_SELECTING = 1; -var INPUT_BANDBOXING = 2; -var INPUT_BUILDING_PLACEMENT = 3; -var INPUT_BUILDING_CLICK = 4; -var INPUT_BUILDING_DRAG = 5; -var INPUT_BATCHTRAINING = 6; - -var inputState = INPUT_NORMAL; - -var defaultPlacementAngle = Math.PI*3/4; -var placementAngle; -var placementPosition; -var placementEntity; - -var mouseX = 0; -var mouseY = 0; -var specialKeyStates = {}; -specialKeyStates[SDLK_RSHIFT] = 0; -specialKeyStates[SDLK_LSHIFT] = 0; -// (TODO: maybe we should fix the hotkey system to be usable in this situation, -// rather than hardcoding Shift into this code?) - -function updateCursor() -{ - if (inputState == INPUT_NORMAL) - { - var action = determineAction(mouseX, mouseY); - if (action) - { - if (action.cursor) - { - Engine.SetCursor(action.cursor); - return; - } - } - } - - Engine.SetCursor("arrow-default"); -} - -function findGatherType(gatherer, supply) -{ - if (!gatherer || !supply) - return; - if (gatherer[supply.type.generic+"."+supply.type.specific]) - return supply.type.specific; - if (gatherer[supply.type.generic]) - return supply.type.generic; -} - -/** - * Determine the context-sensitive action that should be performed when the mouse is at (x,y) - */ -function determineAction(x, y) -{ - var selection = g_Selection.toList(); - - // No action if there's no selection - if (!selection.length) - return; - - // If the selection doesn't exist, no action - var entState = Engine.GuiInterfaceCall("GetEntityState", selection[0]); - if (!entState) - return; - - // If the selection isn't friendly units, no action - var player = Engine.GetPlayerID(); - if (entState.player != player && !g_DevSettings.controlAll) - return; - - var targets = Engine.PickEntitiesAtPoint(x, y); - - // If there's no unit, just walk - if (!targets.length) - return {"type": "move"}; - - // Look at the first targeted entity - // (TODO: maybe we eventually want to look at more, and be more context-sensitive? - // e.g. prefer to attack an enemy unit, even if some friendly units are closer to the mouse) - var targetState = Engine.GuiInterfaceCall("GetEntityState", targets[0]); - - // Resource -> gather - var resource = findGatherType(entState.resourceGatherRates, targetState.resourceSupply); - if (resource) - return {"type": "gather", "cursor": "action-gather-"+resource, "target": targets[0]}; - - // Different owner -> attack - // (TODO: this should only happen if the target is really targetable, not e.g. a tree that this unit can't gather) - if (entState.attack && targetState.player != entState.player) - return {"type": "attack", "cursor": "action-attack", "target": targets[0]}; - - // If a builder, then: Foundation -> build - if (entState.buildEntities && targetState.foundation) - return {"type": "build", "cursor": "action-build", "target": targets[0]}; - - // TODO: need more actions - - // If we don't do anything more specific, just walk - return {"type": "move"}; -} - -/* - -Selection methods: (not all currently implemented) - -- Left-click on entity to select (always chooses the 'closest' one if the mouse is over several). - Includes non-controllable units (e.g. trees, enemy units). -- Double-left-click to select entity plus all of the same type on the screen. -- Triple-left-click to select entity plus all of the same type in the world. -- Left-click-and-drag to select all in region. Only includes controllable units. -- Left-click on empty space to deselect all. -- Hotkeys to select various groups. -- Shift plus left-click on entity to toggle selection of that unit. Only includes controllable. -- Shift plus any other selection method above, to add them to current selection. - -*/ - -var dragStart; // used for remembering mouse coordinates at start of drag operations - -function tryPlaceBuilding() -{ - var selection = g_Selection.toList(); - - // Use the preview to check it's a valid build location - var ok = Engine.GuiInterfaceCall("SetBuildingPlacementPreview", { - "template": placementEntity, - "x": placementPosition.x, - "z": placementPosition.z, - "angle": placementAngle - }); - if (!ok) - { - // invalid location - don't build it - return false; - } - - // Remove the preview - Engine.GuiInterfaceCall("SetBuildingPlacementPreview", {"template": ""}); - - // Start the construction - Engine.PostNetworkCommand({ - "type": "construct", - "template": placementEntity, - "x": placementPosition.x, - "z": placementPosition.z, - "angle": placementAngle, - "entities": selection - }); - - return true; -} - -function handleInputBeforeGui(ev) -{ - // Capture mouse position so we can use it for displaying cursors, - // and key states - switch (ev.type) - { - case "mousebuttonup": - case "mousebuttondown": - case "mousemotion": - mouseX = ev.x; - mouseY = ev.y; - break; - case "keydown": - if (ev.keysym.sym in specialKeyStates) - specialKeyStates[ev.keysym.sym] = 1; - break; - case "keyup": - if (ev.keysym.sym in specialKeyStates) - specialKeyStates[ev.keysym.sym] = 0; - break; - } - - // State-machine processing: - // - // (This is for states which should override the normal GUI processing - events will - // be processed here before being passed on, and propagation will stop if this function - // returns true) - // - // TODO: it'd probably be nice to have a better state-machine system, with guaranteed - // entry/exit functions, since this is a bit broken now - - switch (inputState) - { - case INPUT_BANDBOXING: - switch (ev.type) - { - case "mousemotion": - var x0 = dragStart[0]; - var y0 = dragStart[1]; - var x1 = ev.x; - var y1 = ev.y; - if (x0 > x1) { var t = x0; x0 = x1; x1 = t; } - if (y0 > y1) { var t = y0; y0 = y1; y1 = t; } - - var bandbox = getGUIObjectByName("bandbox"); - bandbox.size = [x0, y0, x1, y1].join(" "); - bandbox.hidden = false; - - var ents = Engine.PickFriendlyEntitiesInRect(x0, y0, x1, y1, Engine.GetPlayerID()); - g_Selection.setHighlightList(ents); - - return false; - - case "mousebuttonup": - if (ev.button == SDL_BUTTON_LEFT) - { - var x0 = dragStart[0]; - var y0 = dragStart[1]; - var x1 = ev.x; - var y1 = ev.y; - if (x0 > x1) { var t = x0; x0 = x1; x1 = t; } - if (y0 > y1) { var t = y0; y0 = y1; y1 = t; } - - var bandbox = getGUIObjectByName("bandbox"); - bandbox.hidden = true; - - var ents = Engine.PickFriendlyEntitiesInRect(x0, y0, x1, y1, Engine.GetPlayerID()); - g_Selection.setHighlightList([]); - g_Selection.reset(); - g_Selection.addList(ents); - - inputState = INPUT_NORMAL; - return true; - } - else if (ev.button == SDL_BUTTON_RIGHT) - { - // Cancel selection - - var bandbox = getGUIObjectByName("bandbox"); - bandbox.hidden = true; - - g_Selection.setHighlightList([]); - - inputState = INPUT_NORMAL; - return true; - } - break; - } - break; - - case INPUT_BUILDING_CLICK: - switch (ev.type) - { - case "mousemotion": - // If the mouse moved far enough from the original click location, - // then switch to drag-orientatio mode - var dragDeltaX = ev.x - dragStart[0]; - var dragDeltaY = ev.y - dragStart[1]; - var maxDragDelta = 16; - if (Math.abs(dragDeltaX) >= maxDragDelta || Math.abs(dragDeltaY) >= maxDragDelta) - { - inputState = INPUT_BUILDING_DRAG; - return false; - } - break; - - case "mousebuttonup": - if (ev.button == SDL_BUTTON_LEFT) - { - if (tryPlaceBuilding()) - { - // If shift is down, let the player continue placing another of the same building - if (specialKeyStates[SDLK_RSHIFT] || specialKeyStates[SDLK_LSHIFT]) - inputState = INPUT_BUILDING_PLACEMENT; - else - inputState = INPUT_NORMAL; - } - else - { - inputState = INPUT_BUILDING_PLACEMENT; - } - return true; - } - break; - - case "mousebuttondown": - if (ev.button == SDL_BUTTON_RIGHT) - { - // Cancel building - Engine.GuiInterfaceCall("SetBuildingPlacementPreview", {"template": ""}); - inputState = INPUT_NORMAL; - return true; - } - break; - } - break; - - case INPUT_BUILDING_DRAG: - switch (ev.type) - { - case "mousemotion": - var dragDeltaX = ev.x - dragStart[0]; - var dragDeltaY = ev.y - dragStart[1]; - var maxDragDelta = 16; - if (Math.abs(dragDeltaX) >= maxDragDelta || Math.abs(dragDeltaY) >= maxDragDelta) - { - // Rotate in the direction of the mouse - var target = Engine.GetTerrainAtPoint(ev.x, ev.y); - placementAngle = Math.atan2(target.x - placementPosition.x, target.z - placementPosition.z); - } - else - { - // If the mouse is near the center, snap back to the default orientation - placementAngle = defaultPlacementAngle; - } - - Engine.GuiInterfaceCall("SetBuildingPlacementPreview", { - "template": placementEntity, - "x": placementPosition.x, - "z": placementPosition.z, - "angle": placementAngle - }); - - break; - - case "mousebuttonup": - if (ev.button == SDL_BUTTON_LEFT) - { - if (tryPlaceBuilding()) - inputState = INPUT_NORMAL; - else - inputState = INPUT_BUILDING_PLACEMENT; - return true; - } - break; - - case "mousebuttondown": - if (ev.button == SDL_BUTTON_RIGHT) - { - // Cancel building - Engine.GuiInterfaceCall("SetBuildingPlacementPreview", {"template": ""}); - inputState = INPUT_NORMAL; - return true; - } - break; - } - break; - - case INPUT_BATCHTRAINING: - switch (ev.type) - { - case "keyup": - if (ev.keysym.sym == SDLK_RSHIFT || ev.keysym.sym == SDLK_LSHIFT) - { - flushTrainingQueueBatch(); - inputState = INPUT_NORMAL; - } - break; - } - } - - return false; -} - -function handleInputAfterGui(ev) -{ - // State-machine processing: - - switch (inputState) - { - case INPUT_NORMAL: - switch (ev.type) - { - case "mousemotion": - var ents = Engine.PickEntitiesAtPoint(ev.x, ev.y); - g_Selection.setHighlightList(ents); - return false; - - case "mousebuttondown": - if (ev.button == SDL_BUTTON_LEFT) - { - dragStart = [ ev.x, ev.y ]; - inputState = INPUT_SELECTING; - return true; - } - else if (ev.button == SDL_BUTTON_RIGHT) - { - var action = determineAction(ev.x, ev.y); - if (!action) - break; - - var selection = g_Selection.toList(); - - switch (action.type) - { - case "move": - var target = Engine.GetTerrainAtPoint(ev.x, ev.y); - Engine.PostNetworkCommand({"type": "walk", "entities": selection, "x": target.x, "z": target.z}); - return true; - - case "attack": - Engine.PostNetworkCommand({"type": "attack", "entities": selection, "target": action.target}); - return true; - - case "build": // (same command as repair) - case "repair": - Engine.PostNetworkCommand({"type": "repair", "entities": selection, "target": action.target}); - return true; - - case "gather": - Engine.PostNetworkCommand({"type": "gather", "entities": selection, "target": action.target}); - return true; - - default: - throw new Error("Invalid action.type "+action.type); - } - } - break; - } - break; - - case INPUT_SELECTING: - switch (ev.type) - { - case "mousemotion": - // If the mouse moved further than a limit, switch to bandbox mode - var dragDeltaX = ev.x - dragStart[0]; - var dragDeltaY = ev.y - dragStart[1]; - var maxDragDelta = 4; - if (Math.abs(dragDeltaX) >= maxDragDelta || Math.abs(dragDeltaY) >= maxDragDelta) - { - inputState = INPUT_BANDBOXING; - return false; - } - - var ents = Engine.PickEntitiesAtPoint(ev.x, ev.y); - g_Selection.setHighlightList(ents); - return false; - - case "mousebuttonup": - if (ev.button == SDL_BUTTON_LEFT) - { - var ents = Engine.PickEntitiesAtPoint(ev.x, ev.y); - if (!ents.length) - { - g_Selection.reset(); - - inputState = INPUT_NORMAL; - return true; - } - - g_Selection.reset(); - g_Selection.addList([ents[0]]); - - inputState = INPUT_NORMAL; - return true; - } - break; - } - break; - - case INPUT_BUILDING_PLACEMENT: - switch (ev.type) - { - case "mousemotion": - var target = Engine.GetTerrainAtPoint(ev.x, ev.y); - Engine.GuiInterfaceCall("SetBuildingPlacementPreview", { - "template": placementEntity, - "x": target.x, - "z": target.z, - "angle": placementAngle - }); - - return false; // continue processing mouse motion - - case "mousebuttondown": - if (ev.button == SDL_BUTTON_LEFT) - { - placementPosition = Engine.GetTerrainAtPoint(ev.x, ev.y); - dragStart = [ ev.x, ev.y ]; - inputState = INPUT_BUILDING_CLICK; - return true; - } - else if (ev.button == SDL_BUTTON_RIGHT) - { - // Cancel building - Engine.GuiInterfaceCall("SetBuildingPlacementPreview", {"template": ""}); - inputState = INPUT_NORMAL; - return true; - } - break; - } - break; - } - return false; -} - -// Called by GUI when user clicks construction button -function startBuildingPlacement(buildEntType) -{ - placementEntity = buildEntType; - placementAngle = defaultPlacementAngle; - inputState = INPUT_BUILDING_PLACEMENT; -} - -// Batch training: -// When the user shift-clicks, we set these variables and switch to INPUT_BATCHTRAINING -// When the user releases shift, or clicks on a different training button, we create the batched units -var batchTrainingEntity; -var batchTrainingType; -var batchTrainingCount; -const batchIncrementSize = 5; - -function flushTrainingQueueBatch() -{ - Engine.PostNetworkCommand({"type": "train", "entity": batchTrainingEntity, "template": batchTrainingType, "count": batchTrainingCount}); -} - -// Called by GUI when user clicks training button -function addToTrainingQueue(entity, trainEntType) -{ - if (specialKeyStates[SDLK_RSHIFT] || specialKeyStates[SDLK_LSHIFT]) - { - if (inputState == INPUT_BATCHTRAINING) - { - // If we're already creating a batch of this unit, then just extend it - if (batchTrainingEntity == entity && batchTrainingType == trainEntType) - { - batchTrainingCount += batchIncrementSize; - return; - } - // Otherwise start a new one - else - { - flushTrainingQueueBatch(); - // fall through to create the new batch - } - } - inputState = INPUT_BATCHTRAINING; - batchTrainingEntity = entity; - batchTrainingType = trainEntType; - batchTrainingCount = batchIncrementSize; - } - else - { - // Non-batched - just create a single entity - Engine.PostNetworkCommand({"type": "train", "entity": entity, "template": trainEntType, "count": 1}); - } -} - -// Returns the number of units that will be present in a batch if the user clicks -// the training button with shift down -function getTrainingQueueBatchStatus(entity, trainEntType) -{ - if (inputState == INPUT_BATCHTRAINING && batchTrainingEntity == entity && batchTrainingType == trainEntType) - return [batchTrainingCount, batchIncrementSize]; - else - return [0, batchIncrementSize]; -} - -// Called by GUI when user clicks production queue item -function removeFromTrainingQueue(entity, id) -{ - Engine.PostNetworkCommand({"type": "stop-train", "entity": entity, "id": id}); -} - diff --git a/binaries/data/mods/public/gui/session_new_old/music.js b/binaries/data/mods/public/gui/session_new_old/music.js deleted file mode 100644 index d049f80615..0000000000 --- a/binaries/data/mods/public/gui/session_new_old/music.js +++ /dev/null @@ -1,34 +0,0 @@ -var g_CurrentMusic = null; - -/* - * At some point, this ought to be extended to do dynamic music selection and - * crossfading - it at least needs to pick the music track based on the player's - * civ and peace/battle - */ - -function startMusic() -{ - var ambient1 = new Sound("audio/ambient/dayscape/day_temperate_gen_03.ogg"); - if (ambient1) - { - ambient1.loop(); - ambient1.setGain(0.8); - } - - var gain = 0.3; - g_CurrentMusic = new Sound("audio/music/germanic_peace_1.ogg"); - if (g_CurrentMusic) - { - g_CurrentMusic.loop(); - g_CurrentMusic.fade(0.0, gain, 10.0); - } -} - -function stopMusic() -{ - if (g_CurrentMusic) - { - g_CurrentMusic.fade(-1, 0.0, 5.0); - g_CurrentMusic = null; - } -} diff --git a/binaries/data/mods/public/gui/session_new_old/selection.js b/binaries/data/mods/public/gui/session_new_old/selection.js deleted file mode 100644 index c494947d58..0000000000 --- a/binaries/data/mods/public/gui/session_new_old/selection.js +++ /dev/null @@ -1,112 +0,0 @@ -var g_ActiveSelectionColour = { r:1, g:1, b:1, a:1 }; -var g_HighlightSelectionColour = { r:1, g:1, b:1, a:0.5 }; -var g_InactiveSelectionColour = { r:1, g:1, b:1, a:0 }; - -function _setHighlight(ents, colour) -{ - if (ents.length) - Engine.GuiInterfaceCall("SetSelectionHighlight", { "entities":ents, "colour":colour }); -} - -function _setMotionOverlay(ents, enabled) -{ - if (ents.length) - Engine.GuiInterfaceCall("SetMotionDebugOverlay", { "entities":ents, "enabled":enabled }); -} - -function EntitySelection() -{ - // Private properties: - this.selected = {}; // { id:id, id:id, ... } for each selected entity ID 'id' - this.highlighted = {}; // { id:id, ... } for mouseover-highlighted entity IDs - // (in these, the key is a string and the value is an int; we want to use the - // int form wherever possible since it's more efficient to send to the simulation code) - this.motionDebugOverlay = false; - - // Public properties: - this.dirty = false; // set whenever the selection has changed -} - -EntitySelection.prototype.toggle = function(ent) -{ - if (this.selected[ent]) - { - _setHighlight([ent], g_InactiveSelectionColour); - _setMotionOverlay([ent], false); - delete this.selected[ent]; - } - else - { - _setHighlight([ent], g_ActiveSelectionColour); - _setMotionOverlay([ent], this.motionDebugOverlay); - this.selected[ent] = ent; - } - this.dirty = true; -}; - -EntitySelection.prototype.addList = function(ents) -{ - var added = []; - for each (var ent in ents) - { - if (!this.selected[ent]) - { - added.push(ent); - this.selected[ent] = ent; - } - } - _setHighlight(added, g_ActiveSelectionColour); - _setMotionOverlay(added, this.motionDebugOverlay); - this.dirty = true; -}; - -EntitySelection.prototype.reset = function() -{ - _setHighlight(this.toList(), g_InactiveSelectionColour); - _setMotionOverlay(this.toList(), false); - this.selected = {}; - this.dirty = true; -}; - -EntitySelection.prototype.toList = function() -{ - var ents = []; - for each (var ent in this.selected) - ents.push(ent); - return ents; -}; - -EntitySelection.prototype.setHighlightList = function(ents) -{ - var removed = []; - var added = []; - - // Remove highlighting for the old units (excluding ones that are actively selected too) - for each (var ent in this.highlighted) - if (!this.selected[ent]) - removed.push(ent); - - // Add new highlighting - for each (var ent in ents) - if (!this.selected[ent]) - added.push(ent); - - _setHighlight(removed, g_InactiveSelectionColour); - _setHighlight(added, g_HighlightSelectionColour); - - // TODO: this could be a bit more efficient by only changing the ones that - // have entered/left the highlight list - - // Store the new list - this.highlighted = {}; - for each (var ent in ents) - this.highlighted[ent] = ent; -}; - -EntitySelection.prototype.SetMotionDebugOverlay = function(enabled) -{ - this.motionDebugOverlay = enabled; - _setMotionOverlay(this.toList(), enabled); -}; - -var g_Selection = new EntitySelection(); diff --git a/binaries/data/mods/public/gui/session_new_old/session.js b/binaries/data/mods/public/gui/session_new_old/session.js deleted file mode 100644 index 059f310c5e..0000000000 --- a/binaries/data/mods/public/gui/session_new_old/session.js +++ /dev/null @@ -1,315 +0,0 @@ -// Cache dev-mode settings that are frequently or widely used -var g_DevSettings = { - controlAll: false -}; - -function init(initData, hotloadData) -{ - if (hotloadData) - { - g_Selection.selected = hotloadData.selection; - } - else - { - // Starting for the first time: - startMusic(); - } - - onSimulationUpdate(); -} - -function leaveGame() -{ - stopMusic(); - endGame(); - Engine.SwitchGuiPage("page_pregame.xml"); -} - -// Return some data that we'll use when hotloading this file after changes -function getHotloadData() -{ - return { selection: g_Selection.selected }; -} - -function onTick() -{ - g_DevSettings.controlAll = getGUIObjectByName("devControlAll").checked; - // TODO: at some point this controlAll needs to disable the simulation code's - // player checks (once it has some player checks) - - updateCursor(); - - // If the selection changed, we need to regenerate the sim display - if (g_Selection.dirty) - onSimulationUpdate(); -} - -function onSimulationUpdate() -{ - g_Selection.dirty = false; - - var simState = Engine.GuiInterfaceCall("GetSimulationState"); - - // If we're called during init when the game is first loading, there will be - // no simulation yet, so do nothing - if (!simState) - return; - - updateDebug(simState); - - updatePlayerDisplay(simState); - - updateUnitDisplay(); -} - -function updateDebug(simState) -{ - var debug = getGUIObjectByName("debug"); - - if (getGUIObjectByName("devDisplayState").checked) - { - debug.hidden = false; - } - else - { - debug.hidden = true; - return; - } - - var text = uneval(simState); - - var selection = g_Selection.toList(); - if (selection.length) - { - var entState = Engine.GuiInterfaceCall("GetEntityState", selection[0]); - if (entState) - { - var template = Engine.GuiInterfaceCall("GetTemplateData", entState.template); - text += "\n\n" + uneval(entState) + "\n\n" + uneval(template); - } - } - - debug.caption = text; -} - -function updatePlayerDisplay(simState) -{ - var playerState = simState.players[Engine.GetPlayerID()]; - - getGUIObjectByName("resourceFood").caption = playerState.resourceCounts.food; - getGUIObjectByName("resourceWood").caption = playerState.resourceCounts.wood; - getGUIObjectByName("resourceStone").caption = playerState.resourceCounts.stone; - getGUIObjectByName("resourceMetal").caption = playerState.resourceCounts.metal; - getGUIObjectByName("resourcePop").caption = playerState.popCount + "/" + playerState.popLimit; -} - -function damageTypesToText(dmg) -{ - if (!dmg) - return "(None)"; - return dmg.hack + " Hack\n" + dmg.pierce + " Pierce\n" + dmg.crush + " Crush"; -} - -// The number of currently visible buttons (used to optimise showing/hiding) -var g_unitPanelButtons = { "Construction": 0, "Training": 0, "Queue": 0 }; - -// The unitSomethingPanel objects, which are displayed in a stack at the bottom of the screen, -// ordered with *lowest* first -var g_unitPanels = ["Stance", "Formation", "Construction", "Research", "Training", "Queue"]; - -// Helper function for updateUnitDisplay -function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback) -{ - usedPanels[guiName] = 1; - var i = 0; - for each (var item in items) - { - var entType; - if (guiName == "Queue") - entType = item.template; - else - entType = item; - - var button = getGUIObjectByName("unit"+guiName+"Button["+i+"]"); - var icon = getGUIObjectByName("unit"+guiName+"Icon["+i+"]"); - - var template = Engine.GuiInterfaceCall("GetTemplateData", entType); - if (!template) - continue; // ignore attempts to use invalid templates (an error should have been reported already) - - var name; - if (template.name.specific && template.name.generic) - name = template.name.specific + " (" + template.name.generic + ")"; - else - name = template.name.specific || template.name.generic || "???"; - - var tooltip; - if (guiName == "Queue") - { - var progress = Math.round(item.progress*100) + "%"; - tooltip = name + " - " + progress; - - getGUIObjectByName("unit"+guiName+"Count["+i+"]").caption = (item.count > 1 ? item.count : ""); - getGUIObjectByName("unit"+guiName+"Progress["+i+"]").caption = (item.progress ? progress : ""); - } - else - { - tooltip = "[font=\"serif-bold-16\"]" + name + "[/font]"; - - if (template.cost) - { - var font1 = "[font=\"serif-bold-13\"]"; - var costs = []; - if (template.cost.food) costs.push(font1 + "Food:[/font] " + template.cost.food); - if (template.cost.wood) costs.push(font1 + "Wood:[/font] " + template.cost.wood); - if (template.cost.metal) costs.push(font1 + "Metal:[/font] " + template.cost.metal); - if (template.cost.stone) costs.push(font1 + "Stone:[/font] " + template.cost.stone); - if (costs.length) - tooltip += "\n" + costs.join(", "); - } - - if (guiName == "Training") - { - var font1 = "[font=\"serif-13\"]"; - var font2 = "[font=\"serif-bold-13\"]"; - var [batchSize, batchIncrement] = getTrainingQueueBatchStatus(unitEntState.id, entType); - tooltip += "\n" + font1; - if (batchSize) tooltip += "Training " + font2 + batchSize + font1 + " units; "; - tooltip += "Shift-click to train " + font2 + (batchSize+batchIncrement) + font1 + " units[/font]"; - } - } - - button.hidden = false; - button.tooltip = tooltip; - button.onpress = (function(e) { return function() { callback(e) } })(item); - // (need nested functions to get the closure right) - - icon.sprite = "snPortraitSheetHele"; // TODO - if (typeof template.icon_cell == "undefined") - icon.cell_id = 0; - else - icon.cell_id = template.icon_cell; - ++i; - } - var numButtons = i; - // Position the visible buttons - // (TODO: if there's lots, maybe they should be squeezed together to fit) - for (i = 0; i < numButtons; ++i) - { - var button = getGUIObjectByName("unit"+guiName+"Button["+i+"]"); - var size = button.size; - size.left = 40*i; - size.right = 40*i + size.bottom; - button.size = size; - } - - // Hide any buttons we're no longer using - for (i = numButtons; i < g_unitPanelButtons[guiName]; ++i) - getGUIObjectByName("unit"+guiName+"Button["+i+"]").hidden = true; - g_unitPanelButtons[guiName] = numButtons; -} - -function updateUnitDisplay() -{ - var detailsPanel = getGUIObjectByName("selectionDetails"); - var commandsPanel = getGUIObjectByName("unitCommands"); - - var selection = g_Selection.toList(); - if (selection.length == 0) - { - detailsPanel.hidden = true; - commandsPanel.hidden = true; - return; - } - - var entState = Engine.GuiInterfaceCall("GetEntityState", selection[0]); - - // If the unit has no data (e.g. it was killed), don't try displaying any - // data for it. (TODO: it should probably be removed from the selection too; - // also need to handle multi-unit selections) - if (!entState) - { - detailsPanel.hidden = true; - commandsPanel.hidden = true; - return; - } - - var template = Engine.GuiInterfaceCall("GetTemplateData", entState.template); - - detailsPanel.hidden = false; - commandsPanel.hidden = false; - - getGUIObjectByName("selectionDetailsIcon").sprite = "snPortraitSheetHele"; - getGUIObjectByName("selectionDetailsIcon").cell_id = template.icon_cell; - - var healthSize = getGUIObjectByName("selectionDetailsHealthBar").size; - healthSize.rright = 100*Math.max(0, Math.min(1, entState.hitpoints / entState.maxHitpoints)); - getGUIObjectByName("selectionDetailsHealthBar").size = healthSize; - getGUIObjectByName("selectionDetailsHealth").tooltip = "Hitpoints " + entState.hitpoints + " / " + entState.maxHitpoints; - - getGUIObjectByName("selectionDetailsSpecific").caption = template.name.specific; - if (template.name.generic == template.name.specific) - { - getGUIObjectByName("selectionDetailsGeneric").hidden = true; - } - else - { - getGUIObjectByName("selectionDetailsGeneric").hidden = false; - getGUIObjectByName("selectionDetailsGeneric").caption = template.name.generic; - } - - getGUIObjectByName("selectionDetailsPlayer").caption = "Player " + entState.player; // TODO: get player name - - getGUIObjectByName("selectionDetailsAttack").caption = damageTypesToText(entState.attack); - getGUIObjectByName("selectionDetailsArmour").caption = damageTypesToText(entState.armour); - - var usedPanels = {}; - - // If the selection is friendly units, add the command panels - var player = Engine.GetPlayerID(); - if (entState.player == player || g_DevSettings.controlAll) - { - if (entState.attack) // TODO - this should be based on some AI properties - { - //usedPanels["Stance"] = 1; - //usedPanels["Formation"] = 1; - // (These are disabled since they're not implemented yet) - } - else // TODO - this should be based on various other things - { - //usedPanels["Research"] = 1; - } - - if (entState.buildEntities && entState.buildEntities.length) - setupUnitPanel("Construction", usedPanels, entState, entState.buildEntities, startBuildingPlacement); - - if (entState.training && entState.training.entities.length) - setupUnitPanel("Training", usedPanels, entState, entState.training.entities, - function (trainEntType) { addToTrainingQueue(entState.id, trainEntType); } ); - - if (entState.training && entState.training.queue.length) - setupUnitPanel("Queue", usedPanels, entState, entState.training.queue, - function (item) { removeFromTrainingQueue(entState.id, item.id); } ); - } - - // Lay out all the used panels in a stack at the bottom of the screen - var offset = 0; - for each (var panelName in g_unitPanels) - { - var panel = getGUIObjectByName("unit"+panelName+"Panel"); - if (usedPanels[panelName]) - { - var size = panel.size; - var h = size.bottom - size.top; - size.bottom = offset; - size.top = offset - h; - panel.size = size; - panel.hidden = false; - offset -= (h + 12); - } - else - { - panel.hidden = true; - } - } -} diff --git a/binaries/data/mods/public/gui/session_new_old/session.xml b/binaries/data/mods/public/gui/session_new_old/session.xml deleted file mode 100644 index d77b7c9014..0000000000 --- a/binaries/data/mods/public/gui/session_new_old/session.xml +++ /dev/null @@ -1,275 +0,0 @@ - - - - -