Quellcode durchsuchen

Can now also bind mouse actions

Thomas Buck vor 10 Jahren
Ursprung
Commit
9fd1622471
7 geänderte Dateien mit 32 neuen und 22 gelöschten Zeilen
  1. 1
    1
      include/Menu.h
  2. 1
    1
      include/OpenRaider.h
  3. 3
    7
      include/Window.h
  4. 4
    1
      src/Console.cpp
  5. 2
    2
      src/Menu.cpp
  6. 17
    6
      src/OpenRaider.cpp
  7. 4
    4
      src/WindowSDL.cpp

+ 1
- 1
include/Menu.h Datei anzeigen

34
 
34
 
35
     void handleKeyboard(KeyboardButton key, bool pressed);
35
     void handleKeyboard(KeyboardButton key, bool pressed);
36
 
36
 
37
-    void handleMouseClick(unsigned int x, unsigned int y, MouseButton button, bool released);
37
+    void handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released);
38
 
38
 
39
 private:
39
 private:
40
 
40
 

+ 1
- 1
include/OpenRaider.h Datei anzeigen

62
 
62
 
63
     void handleText(char *text, bool notFinished);
63
     void handleText(char *text, bool notFinished);
64
 
64
 
65
-    void handleMouseClick(unsigned int x, unsigned int y, MouseButton button, bool released);
65
+    void handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released);
66
 
66
 
67
     void handleMouseMotion(int xrel, int yrel);
67
     void handleMouseMotion(int xrel, int yrel);
68
 
68
 

+ 3
- 7
include/Window.h Datei anzeigen

37
     leftgui, leftshift, minus, numlock, pagedown,
37
     leftgui, leftshift, minus, numlock, pagedown,
38
     pageup, pause, dot, rightalt, rightctrl, enter,
38
     pageup, pause, dot, rightalt, rightctrl, enter,
39
     rightgui, rightbracket, rightshift, scrolllock,
39
     rightgui, rightbracket, rightshift, scrolllock,
40
-    semicolon, slash, space, tab, unknown
40
+    semicolon, slash, space, tab,
41
+    leftmouse, middlemouse, rightmouse,
42
+    unknown
41
 } KeyboardButton;
43
 } KeyboardButton;
42
 
44
 
43
-typedef enum {
44
-    leftButton,
45
-    rightButton,
46
-    middleButton
47
-} MouseButton;
48
-
49
 typedef struct {
45
 typedef struct {
50
     char *text;
46
     char *text;
51
     unsigned int x;
47
     unsigned int x;

+ 4
- 1
src/Console.cpp Datei anzeigen

145
         if ((mInputBufferPointer > 0) && (mInputBuffer[0] != '\0')) {
145
         if ((mInputBufferPointer > 0) && (mInputBuffer[0] != '\0')) {
146
             mHistory.push_back(bufferString("> %s", mInputBuffer));
146
             mHistory.push_back(bufferString("> %s", mInputBuffer));
147
             mCommandHistory.push_back(bufferString("%s", mInputBuffer));
147
             mCommandHistory.push_back(bufferString("%s", mInputBuffer));
148
-            gOpenRaider->command(mInputBuffer);
148
+            int error = gOpenRaider->command(mInputBuffer);
149
+            if (error != 0) {
150
+                print("Error Code: %d", error);
151
+            }
149
         } else {
152
         } else {
150
             mHistory.push_back(bufferString("> "));
153
             mHistory.push_back(bufferString("> "));
151
         }
154
         }

+ 2
- 2
src/Menu.cpp Datei anzeigen

152
     }
152
     }
153
 }
153
 }
154
 
154
 
155
-void Menu::handleMouseClick(unsigned int x, unsigned int y, MouseButton button, bool released) {
155
+void Menu::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
156
     int items = (gOpenRaider->mWindow->mHeight - 110) / 25;
156
     int items = (gOpenRaider->mWindow->mHeight - 110) / 25;
157
 
157
 
158
-    if ((!released) || (button != leftButton))
158
+    if ((!released) || (button != leftmouse))
159
         return;
159
         return;
160
 
160
 
161
     if ((y >= 100) && (y <= (unsigned int)(100 + (25 * items)))) {
161
     if ((y >= 100) && (y <= (unsigned int)(100 + (25 * items)))) {

+ 17
- 6
src/OpenRaider.cpp Datei anzeigen

83
 
83
 
84
     char buffer[256];
84
     char buffer[256];
85
     while (fgets(buffer, 256, f) != NULL) {
85
     while (fgets(buffer, 256, f) != NULL) {
86
-        command(buffer);
86
+        int error = command(buffer);
87
+        if (error != 0) {
88
+            mConsole->print("Error Code: %d", error);
89
+        }
87
     }
90
     }
88
 
91
 
89
     fclose(f);
92
     fclose(f);
132
 
135
 
133
     if (strcmp(command, "set") == 0) {
136
     if (strcmp(command, "set") == 0) {
134
         if (args->size() != 2) {
137
         if (args->size() != 2) {
135
-            mConsole->print("Invalid use of set-command ");
138
+            mConsole->print("Invalid use of set-command");
136
             return -2;
139
             return -2;
137
         } else {
140
         } else {
138
             return set(args->at(0), args->at(1));
141
             return set(args->at(0), args->at(1));
139
         }
142
         }
140
     } else if (strcmp(command, "bind") == 0) {
143
     } else if (strcmp(command, "bind") == 0) {
141
         if (args->size() != 2) {
144
         if (args->size() != 2) {
142
-            mConsole->print("Invalid use of bind-command ");
145
+            mConsole->print("Invalid use of bind-command");
143
             return -3;
146
             return -3;
144
         } else {
147
         } else {
145
             return bind(args->at(0), args->at(1));
148
             return bind(args->at(0), args->at(1));
157
         } else if (args->size() == 1) {
160
         } else if (args->size() == 1) {
158
             return help(args->at(0));
161
             return help(args->at(0));
159
         } else {
162
         } else {
160
-            mConsole->print("Invalid use of help-command ");
161
-            return -4;
163
+            mConsole->print("Invalid use of help-command");
164
+            return -5;
162
         }
165
         }
163
     } else {
166
     } else {
164
         mConsole->print("Unknown command: %s ", command);
167
         mConsole->print("Unknown command: %s ", command);
185
         mConsole->print("  volume      BOOL");
188
         mConsole->print("  volume      BOOL");
186
         mConsole->print("  mouse_x     FLOAT");
189
         mConsole->print("  mouse_x     FLOAT");
187
         mConsole->print("  mouse_y     FLOAT");
190
         mConsole->print("  mouse_y     FLOAT");
191
+        mConsole->print("Enclose STRINGs with \"\"!");
192
+        mConsole->print("size expects a STRING in the specified format");
188
     } else if (strcmp(cmd, "bind") == 0) {
193
     } else if (strcmp(cmd, "bind") == 0) {
189
         mConsole->print("bind-Command Usage:");
194
         mConsole->print("bind-Command Usage:");
190
         mConsole->print("  bind ACTION KEY");
195
         mConsole->print("  bind ACTION KEY");
477
             keyBindings[action] = space;
482
             keyBindings[action] = space;
478
         } else if (strcmp(tmp, "tab") == 0) {
483
         } else if (strcmp(tmp, "tab") == 0) {
479
             keyBindings[action] = tab;
484
             keyBindings[action] = tab;
485
+        } else if (strcmp(tmp, "leftmouse") == 0) {
486
+            keyBindings[action] = leftmouse;
487
+        } else if (strcmp(tmp, "middlemouse") == 0) {
488
+            keyBindings[action] = middlemouse;
489
+        } else if (strcmp(tmp, "rightmouse") == 0) {
490
+            keyBindings[action] = rightmouse;
480
         } else {
491
         } else {
481
             mConsole->print("bind-\"\"-Error: Unknown key (%s)", key);
492
             mConsole->print("bind-\"\"-Error: Unknown key (%s)", key);
482
             delete [] tmp;
493
             delete [] tmp;
642
     }
653
     }
643
 }
654
 }
644
 
655
 
645
-void OpenRaider::handleMouseClick(unsigned int x, unsigned int y, MouseButton button, bool released) {
656
+void OpenRaider::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
646
     if (mMenu->isVisible()) {
657
     if (mMenu->isVisible()) {
647
         mMenu->handleMouseClick(x, y, button, released);
658
         mMenu->handleMouseClick(x, y, button, released);
648
     }
659
     }

+ 4
- 4
src/WindowSDL.cpp Datei anzeigen

187
 
187
 
188
             case SDL_MOUSEBUTTONDOWN:
188
             case SDL_MOUSEBUTTONDOWN:
189
             case SDL_MOUSEBUTTONUP:
189
             case SDL_MOUSEBUTTONUP:
190
-                MouseButton button;
190
+                KeyboardButton button;
191
                 if (event.button.button == SDL_BUTTON_LEFT)
191
                 if (event.button.button == SDL_BUTTON_LEFT)
192
-                    button = leftButton;
192
+                    button = leftmouse;
193
                 else if (event.button.button == SDL_BUTTON_RIGHT)
193
                 else if (event.button.button == SDL_BUTTON_RIGHT)
194
-                    button = rightButton;
194
+                    button = rightmouse;
195
                 else
195
                 else
196
-                    button = middleButton;
196
+                    button = middlemouse;
197
                 gOpenRaider->handleMouseClick(event.button.x, event.button.y, button, (event.type == SDL_MOUSEBUTTONUP));
197
                 gOpenRaider->handleMouseClick(event.button.x, event.button.y, button, (event.type == SDL_MOUSEBUTTONUP));
198
                 break;
198
                 break;
199
 
199
 

Laden…
Abbrechen
Speichern