Add building and unit hotkeys

This commit is contained in:
Rampoina 2022-07-15 18:40:16 +02:00
parent ff9c9ad864
commit e9b771241f
1 changed files with 16 additions and 18 deletions

View File

@ -408,22 +408,22 @@ void Gui::hotKey(SDL_KeyboardEvent key) {
centerCameraOnSelection(); centerCameraOnSelection();
} }
//else if(key == configKeys.getCharKey("HotKeySelectIdleHarvesterUnit")) { //else if(key == configKeys.getCharKey("HotKeySelectIdleHarvesterUnit")) {
else if(isKeyPressed(configKeys.getSDLKey("HotKeySelectIdleHarvesterUnit"),key) == true) { if(isKeyPressed(configKeys.getSDLKey("HotKeySelectIdleHarvesterUnit"),key) == true) {
selectInterestingUnit(iutIdleHarvester); selectInterestingUnit(iutIdleHarvester);
} }
//else if(key == configKeys.getCharKey("HotKeySelectBuiltBuilding")) { //else if(key == configKeys.getCharKey("HotKeySelectBuiltBuilding")) {
else if(isKeyPressed(configKeys.getSDLKey("HotKeySelectBuiltBuilding"),key) == true) { if(isKeyPressed(configKeys.getSDLKey("HotKeySelectBuiltBuilding"),key) == true) {
selectInterestingUnit(iutBuiltBuilding); selectInterestingUnit(iutBuiltBuilding);
} }
//else if(key == configKeys.getCharKey("HotKeyDumpWorldToLog")) { //else if(key == configKeys.getCharKey("HotKeyDumpWorldToLog")) {
else if(isKeyPressed(configKeys.getSDLKey("HotKeyDumpWorldToLog"),key) == true) { if(isKeyPressed(configKeys.getSDLKey("HotKeyDumpWorldToLog"),key) == true) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled == true) { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled == true) {
std::string worldLog = world->DumpWorldToLog(); std::string worldLog = world->DumpWorldToLog();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] worldLog dumped to [%s]\n",__FILE__,__FUNCTION__,__LINE__,worldLog.c_str()); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] worldLog dumped to [%s]\n",__FILE__,__FUNCTION__,__LINE__,worldLog.c_str());
} }
} }
//else if(key == configKeys.getCharKey("HotKeyRotateUnitDuringPlacement")){ //else if(key == configKeys.getCharKey("HotKeyRotateUnitDuringPlacement")){
else if(isKeyPressed(configKeys.getSDLKey("HotKeyRotateUnitDuringPlacement"),key) == true) { if(isKeyPressed(configKeys.getSDLKey("HotKeyRotateUnitDuringPlacement"),key) == true) {
// Here the user triggers a unit rotation while placing a unit // Here the user triggers a unit rotation while placing a unit
if(isPlacingBuilding()) { if(isPlacingBuilding()) {
if(getBuilding()->getRotationAllowed()){ if(getBuilding()->getRotationAllowed()){
@ -432,34 +432,32 @@ void Gui::hotKey(SDL_KeyboardEvent key) {
} }
} }
//else if(key == configKeys.getCharKey("HotKeySelectDamagedUnit")) { //else if(key == configKeys.getCharKey("HotKeySelectDamagedUnit")) {
else if(isKeyPressed(configKeys.getSDLKey("HotKeySelectDamagedUnit"),key) == true) { if(isKeyPressed(configKeys.getSDLKey("HotKeySelectDamagedUnit"),key) == true) {
selectInterestingUnit(iutDamaged); selectInterestingUnit(iutDamaged);
} }
//else if(key == configKeys.getCharKey("HotKeySelectStoreUnit")) { //else if(key == configKeys.getCharKey("HotKeySelectStoreUnit")) {
else if(isKeyPressed(configKeys.getSDLKey("HotKeySelectStoreUnit"),key) == true) { if(isKeyPressed(configKeys.getSDLKey("HotKeySelectStoreUnit"),key) == true) {
selectInterestingUnit(iutStore); selectInterestingUnit(iutStore);
} }
//else if(key == configKeys.getCharKey("HotKeySelectedUnitsAttack")) { //else if(key == configKeys.getCharKey("HotKeySelectedUnitsAttack")) {
else if(isKeyPressed(configKeys.getSDLKey("HotKeySelectedUnitsAttack"),key) == true) { if(isKeyPressed(configKeys.getSDLKey("HotKeySelectedUnitsAttack"),key) == true) {
clickCommonCommand(ccAttack); clickCommonCommand(ccAttack);
} }
//else if(key == configKeys.getCharKey("HotKeySelectedUnitsStop")) { //else if(key == configKeys.getCharKey("HotKeySelectedUnitsStop")) {
else if(isKeyPressed(configKeys.getSDLKey("HotKeySelectedUnitsStop"),key) == true) { if(isKeyPressed(configKeys.getSDLKey("HotKeySelectedUnitsStop"),key) == true) {
clickCommonCommand(ccStop); clickCommonCommand(ccStop);
} }
else if(isKeyPressed(configKeys.getSDLKey("HotKeyBuild1"),key) == true) { for (int i=0; i<10; i++) {
const CommandType *ct; string name = "HotKeyBuild" + intToStr(i+1);
for(int i=0; i<selection.getCount(); ++i){ if(isKeyPressed(configKeys.getSDLKey(name.c_str()),key) == true) {
const Unit *unit= selection.getUnit(i); if(activeCommandType != NULL && activeCommandType->getClass() == ccBuild) {
ct= unit->getType()->getFirstCtOfClass(ccBuild); mouseDownDisplayUnitBuild(i);
if(ct != NULL) { } else {
break; mouseDownDisplayUnitSkills(i);
} }
} }
clickCommonCommand(ct->getClass());
} }
} }
void Gui::switchToNextDisplayColor(){ void Gui::switchToNextDisplayColor(){
@ -756,7 +754,7 @@ void Gui::mouseDownDisplayUnitBuild(int posDisplay) {
activeCommandType->getClass() == ccBuild) { activeCommandType->getClass() == ccBuild) {
const BuildCommandType *bct = dynamic_cast<const BuildCommandType*>(activeCommandType); const BuildCommandType *bct = dynamic_cast<const BuildCommandType*>(activeCommandType);
if(bct != NULL) { if(bct != NULL && bct->getBuildingCount() > posDisplay) {
const UnitType *ut = bct->getBuilding(posDisplay); const UnitType *ut = bct->getBuilding(posDisplay);
const Unit *unit = selection.getFrontUnit(); const Unit *unit = selection.getFrontUnit();