MACROS.C 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //
  2. // Choose which type of netplay
  3. //
  4. #include <dos.h>
  5. #include <conio.h>
  6. #include <string.h>
  7. #include "main.h"
  8. //
  9. // Line input routine -- totally crude!
  10. //
  11. int EditLine(item_t *item,char *string,int maxlen)
  12. {
  13. char c;
  14. int len;
  15. textbackground(0);
  16. textcolor(15);
  17. Clear(item);
  18. Pos(item);
  19. cprintf("%s",string);
  20. while(1)
  21. {
  22. c = getch();
  23. switch(c)
  24. {
  25. case 8: // BACKSPACE
  26. case 0x4b: // LEFT ARROW
  27. len = strlen(string);
  28. if (!len)
  29. {
  30. sound(2500);
  31. delay(3);
  32. nosound();
  33. continue;
  34. }
  35. string[len-1] = 0;
  36. Clear(item);
  37. Pos(item);
  38. cprintf("%s",string);
  39. case 77: // RIGHT ARROW
  40. sound(2500);
  41. delay(3);
  42. nosound();
  43. break;
  44. case KEY_ENTER:
  45. case KEY_ESC:
  46. return c;
  47. default:
  48. if (c < 0x20 || c > 0x7a)
  49. {
  50. sound(2500);
  51. delay(3);
  52. nosound();
  53. continue;
  54. }
  55. len = strlen(string);
  56. if (len+1 == maxlen)
  57. {
  58. sound(2500);
  59. delay(3);
  60. nosound();
  61. continue;
  62. }
  63. string[len] = c;
  64. string[len+1] = 0;
  65. Pos(item);
  66. cprintf("%s",string);
  67. break;
  68. }
  69. }
  70. }
  71. enum {MAC_MACRO0,MAC_MACRO1,MAC_MACRO2,MAC_MACRO3,MAC_MACRO4,MAC_MACRO5,
  72. MAC_MACRO6,MAC_MACRO7,MAC_MACRO8,MAC_MACRO9,MAC_MAX};
  73. item_t macrositems[]=
  74. {
  75. {MAC_MACRO0, 22,7,40, -1,-1},
  76. {MAC_MACRO1, 22,8,40, -1,-1},
  77. {MAC_MACRO2, 22,9,40, -1,-1},
  78. {MAC_MACRO3, 22,10,40, -1,-1},
  79. {MAC_MACRO4, 22,11,40, -1,-1},
  80. {MAC_MACRO5, 22,12,40, -1,-1},
  81. {MAC_MACRO6, 22,13,40, -1,-1},
  82. {MAC_MACRO7, 22,14,40, -1,-1},
  83. {MAC_MACRO8, 22,15,40, -1,-1},
  84. {MAC_MACRO9, 22,16,40, -1,-1}
  85. };
  86. menu_t macrosmenu=
  87. {
  88. &macrositems[0],
  89. MAC_MACRO0,
  90. MAC_MAX,
  91. 0x7f
  92. };
  93. void MacroConfig(void)
  94. {
  95. short key;
  96. short field;
  97. int i;
  98. char string[40];
  99. SaveScreen();
  100. DrawPup(&macros);
  101. textcolor(15);
  102. textbackground(1);
  103. for (i = 0;i < MAC_MAX; i++)
  104. {
  105. Clear(&macrositems[i]);
  106. Pos(&macrositems[i]);
  107. cprintf("%s",&chatmacros[i][0]);
  108. }
  109. gotoxy(1,25);
  110. while(1)
  111. {
  112. SetupMenu(&macrosmenu);
  113. field = GetMenuInput();
  114. key = menukey;
  115. switch(key)
  116. {
  117. case KEY_ENTER:
  118. strcpy(string,chatmacros[field]);
  119. key = EditLine(&macrositems[field],string,40);
  120. if (key == KEY_ENTER)
  121. strcpy(chatmacros[field],string);
  122. textbackground(1);
  123. textcolor(15);
  124. Clear(&macrositems[field]);
  125. Pos(&macrositems[field]);
  126. cprintf("%s",chatmacros[field]);
  127. gotoxy(1,25);
  128. continue;
  129. case KEY_ESC:
  130. RestoreScreen();
  131. return;
  132. }
  133. }
  134. };