Index: binaries/data/config/default.cfg =================================================================== --- binaries/data/config/default.cfg +++ binaries/data/config/default.cfg @@ -334,6 +334,28 @@ 7 = "M" ; add seventh unit type to queue 8 = Comma ; add eighth unit type to queue +[hotkey.session.building.place] ; > BUILDING SELECTION +House = "Space+H" +Storehouse = "Space+S" +Field = "Space+F" +Farmstead = "Shift+Space+F" +Corral = "Space+K" +Outpost = "Space+O" +Palisade = "Space+P" +SentryTower = "Space+Y" +Dock = "Space+G" +Barracks = "Space+B" +Blacksmith = "Space+N" +Temple = "Space+T" +Market = "Space+M" +DefenseTower = "Space+D" +Wall = "Space+W" +CivicCenter = "Space+C" +Fortress = "Space+A" +Wonder = "Space+V" +SeigeWall = "Space+J" + + [hotkey.session.timewarp] fastforward = Space ; If timewarp mode enabled, speed up the game rewind = Backspace ; If timewarp mode enabled, go back to earlier point in the game Index: binaries/data/mods/public/gui/session/hotkeys/building.xml =================================================================== --- binaries/data/mods/public/gui/session/hotkeys/building.xml +++ binaries/data/mods/public/gui/session/hotkeys/building.xml @@ -0,0 +1,62 @@ + + + + + hotkeyPlaceBuildingType("House") + + + hotkeyPlaceBuildingType("Storehouse") + + + hotkeyPlaceBuildingType("Farmstead") + + + hotkeyPlaceBuildingType("Field") + + + hotkeyPlaceBuildingType("Corral") + + + hotkeyPlaceBuildingType("Outpost") + + + hotkeyPlaceBuildingType("Wooden Wall") + + + hotkeyPlaceBuildingType("Sentry Tower") + + + hotkeyPlaceBuildingType("Dock") + + + hotkeyPlaceBuildingType("Barracks") + + + hotkeyPlaceBuildingType("Blacksmith") + + + hotkeyPlaceBuildingType("Temple") + + + hotkeyPlaceBuildingType("Market") + + + hotkeyPlaceBuildingType("Defense Tower") + + + hotkeyPlaceBuildingType("City Wall") + + + hotkeyPlaceBuildingType("Civic Center") + + + hotkeyPlaceBuildingType("Fortress") + + + hotkeyPlaceBuildingType("Wonder") + + + hotkeyPlaceBuildingType("Seige Wall") + + + Index: binaries/data/mods/public/gui/session/input.js =================================================================== --- binaries/data/mods/public/gui/session/input.js +++ binaries/data/mods/public/gui/session/input.js @@ -1040,42 +1040,9 @@ switch (ev.type) { case "mousemotion": + // continue processing mouse motion + return showBuildingPlacementTerrainSnap(ev.x,ev.y); - placementSupport.position = Engine.GetTerrainAtScreenPoint(ev.x, ev.y); - - if (placementSupport.mode === "wall") - { - // Including only the on-screen towers in the next snap candidate list is sufficient here, since the user is - // still selecting a starting point (which must necessarily be on-screen). (The update of the snap entities - // itself happens in the call to updateBuildingPlacementPreview below). - placementSupport.wallSnapEntitiesIncludeOffscreen = false; - } - else - { - // cancel if not enough resources - if (placementSupport.template && Engine.GuiInterfaceCall("GetNeededResources", { "cost": GetTemplateData(placementSupport.template).cost })) - { - placementSupport.Reset(); - inputState = INPUT_NORMAL; - return true; - } - - var snapData = Engine.GuiInterfaceCall("GetFoundationSnapData", { - "template": placementSupport.template, - "x": placementSupport.position.x, - "z": placementSupport.position.z, - }); - if (snapData) - { - placementSupport.angle = snapData.angle; - placementSupport.position.x = snapData.x; - placementSupport.position.z = snapData.z; - } - } - - updateBuildingPlacementPreview(); // includes an update of the snap entity candidates - return false; // continue processing mouse motion - case "mousebuttondown": if (ev.button == SDL_BUTTON_LEFT) { @@ -1324,8 +1291,49 @@ // add attack information to display a good tooltip placementSupport.attack = templateData.attack; } + + showBuildingPlacementTerrainSnap(mouseX,mouseY); } +// Snaps building placement to cursor and previews it +function showBuildingPlacementTerrainSnap(mousePosX,mousePosY) +{ + placementSupport.position = Engine.GetTerrainAtScreenPoint(mousePosX,mousePosY); + + if (placementSupport.mode === "wall") + { + // Including only the on-screen towers in the next snap candidate list is sufficient here, since the user is + // still selecting a starting point (which must necessarily be on-screen). (The update of the snap entities + // itself happens in the call to updateBuildingPlacementPreview below). + placementSupport.wallSnapEntitiesIncludeOffscreen = false; + } + else + { + // cancel if not enough resources + if (placementSupport.template && Engine.GuiInterfaceCall("GetNeededResources", { "cost": GetTemplateData(placementSupport.template).cost })) + { + placementSupport.Reset(); + inputState = INPUT_NORMAL; + return true; + } + + var snapData = Engine.GuiInterfaceCall("GetFoundationSnapData", { + "template": placementSupport.template, + "x": placementSupport.position.x, + "z": placementSupport.position.z, + }); + if (snapData) + { + placementSupport.angle = snapData.angle; + placementSupport.position.x = snapData.x; + placementSupport.position.z = snapData.z; + } + } + updateBuildingPlacementPreview(); // includes an update of the snap entity candidates + + return false; +} + // 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 @@ -1388,6 +1396,31 @@ return; } +// Select a building from the construction panel given the current unit selected +function hotkeyPlaceBuildingType(genericName) +{ + let playerState = GetSimState().players[Engine.GetPlayerID()]; + let selection = g_Selection.toList(); + + if (!playerState || !selection.length || Engine.GetGUIObjectByName("unitConstructionPanel").hidden) + return; + + let index = g_SelectionPanels.Construction.getItems(). + map(item => GetTemplateData(item).name.generic). + indexOf(genericName); + + if(index == -1) + return; + + let unitConstructionButton = Engine.GetGUIObjectByName("unitConstructionButton["+index+"]"); + + if( unitConstructionButton.hidden || !unitConstructionButton.enabled || !unitConstructionButton.onPress) + return; + + unitConstructionButton.onPress(); + return; +} + // Called by GUI when user clicks training button function addTrainingToQueue(selection, trainEntType, playerState) {