| 682 | } |
| 683 | |
| 684 | virtual void key(int code, bool isdown) |
| 685 | { |
| 686 | keym *km; |
| 687 | if(!capture || !((km = findbindc(code)))) return; |
| 688 | if(code == SDLK_ESCAPE) |
| 689 | { |
| 690 | capture = false; |
| 691 | parent->init(); |
| 692 | return; |
| 693 | } |
| 694 | bool known = newkeys.find(code) >= 0; |
| 695 | if(isdown) |
| 696 | { |
| 697 | if(!known) |
| 698 | { |
| 699 | if(km->actions[bindtype][0] && strcmp(km->actions[bindtype], bindcmd)) |
| 700 | { |
| 701 | static defformatstring(keybound)("\f3Warning: \"%s\" key is already in use. You can press ESC to cancel.", km->name); |
| 702 | menuheader(parent, NULL, keybound); |
| 703 | } |
| 704 | newkeys.add(code); |
| 705 | concatformatstring(keynames, "%s or ", km->name); |
| 706 | keyname = keynames; |
| 707 | } |
| 708 | } |
| 709 | else |
| 710 | { |
| 711 | if(known && ++isup == newkeys.length()) |
| 712 | { |
| 713 | for(keym **km = findbinda(bindcmd, bindtype); *km; km++) bindkey(*km, "", bindtype); // clear existing binds to this cmd |
| 714 | bool bindfailed = false; |
| 715 | loopv(newkeys) bindfailed = !bindc(newkeys[i], bindcmd, bindtype) || bindfailed; |
| 716 | if(bindfailed) conoutf("\f3could not bind key"); |
| 717 | else parent->init(); // show new keys |
| 718 | } |
| 719 | } |
| 720 | } |
| 721 | |
| 722 | virtual const char* gettext() { return text; } |
| 723 | }; |
nothing calls this directly
no test coverage detected