Browse Source

Can now also bind mouse actions

Thomas Buck 10 years ago
parent
commit
9fd1622471
7 changed files with 32 additions and 22 deletions
  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 View File

@@ -34,7 +34,7 @@ public:
34 34
 
35 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 39
 private:
40 40
 

+ 1
- 1
include/OpenRaider.h View File

@@ -62,7 +62,7 @@ public:
62 62
 
63 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 67
     void handleMouseMotion(int xrel, int yrel);
68 68
 

+ 3
- 7
include/Window.h View File

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

+ 4
- 1
src/Console.cpp View File

@@ -145,7 +145,10 @@ void Console::handleKeyboard(KeyboardButton key, bool pressed) {
145 145
         if ((mInputBufferPointer > 0) && (mInputBuffer[0] != '\0')) {
146 146
             mHistory.push_back(bufferString("> %s", mInputBuffer));
147 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 152
         } else {
150 153
             mHistory.push_back(bufferString("> "));
151 154
         }

+ 2
- 2
src/Menu.cpp View File

@@ -152,10 +152,10 @@ void Menu::handleKeyboard(KeyboardButton key, bool pressed) {
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 156
     int items = (gOpenRaider->mWindow->mHeight - 110) / 25;
157 157
 
158
-    if ((!released) || (button != leftButton))
158
+    if ((!released) || (button != leftmouse))
159 159
         return;
160 160
 
161 161
     if ((y >= 100) && (y <= (unsigned int)(100 + (25 * items)))) {

+ 17
- 6
src/OpenRaider.cpp View File

@@ -83,7 +83,10 @@ int OpenRaider::loadConfig(const char *config) {
83 83
 
84 84
     char buffer[256];
85 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 92
     fclose(f);
@@ -132,14 +135,14 @@ int OpenRaider::command(const char *command, std::vector<char *> *args) {
132 135
 
133 136
     if (strcmp(command, "set") == 0) {
134 137
         if (args->size() != 2) {
135
-            mConsole->print("Invalid use of set-command ");
138
+            mConsole->print("Invalid use of set-command");
136 139
             return -2;
137 140
         } else {
138 141
             return set(args->at(0), args->at(1));
139 142
         }
140 143
     } else if (strcmp(command, "bind") == 0) {
141 144
         if (args->size() != 2) {
142
-            mConsole->print("Invalid use of bind-command ");
145
+            mConsole->print("Invalid use of bind-command");
143 146
             return -3;
144 147
         } else {
145 148
             return bind(args->at(0), args->at(1));
@@ -157,8 +160,8 @@ int OpenRaider::command(const char *command, std::vector<char *> *args) {
157 160
         } else if (args->size() == 1) {
158 161
             return help(args->at(0));
159 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 166
     } else {
164 167
         mConsole->print("Unknown command: %s ", command);
@@ -185,6 +188,8 @@ int OpenRaider::help(const char *cmd) {
185 188
         mConsole->print("  volume      BOOL");
186 189
         mConsole->print("  mouse_x     FLOAT");
187 190
         mConsole->print("  mouse_y     FLOAT");
191
+        mConsole->print("Enclose STRINGs with \"\"!");
192
+        mConsole->print("size expects a STRING in the specified format");
188 193
     } else if (strcmp(cmd, "bind") == 0) {
189 194
         mConsole->print("bind-Command Usage:");
190 195
         mConsole->print("  bind ACTION KEY");
@@ -477,6 +482,12 @@ int OpenRaider::bind(ActionEvents action, const char *key) {
477 482
             keyBindings[action] = space;
478 483
         } else if (strcmp(tmp, "tab") == 0) {
479 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 491
         } else {
481 492
             mConsole->print("bind-\"\"-Error: Unknown key (%s)", key);
482 493
             delete [] tmp;
@@ -642,7 +653,7 @@ void OpenRaider::handleText(char *text, bool notFinished) {
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 657
     if (mMenu->isVisible()) {
647 658
         mMenu->handleMouseClick(x, y, button, released);
648 659
     }

+ 4
- 4
src/WindowSDL.cpp View File

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

Loading…
Cancel
Save