[Orxonox-commit 2653] r7358 - in code/branches/notifications: data/gui/scripts data/levels src/modules/notifications/dispatchers

dafrick at orxonox.net dafrick at orxonox.net
Sun Sep 5 22:26:37 CEST 2010


Author: dafrick
Date: 2010-09-05 22:26:37 +0200 (Sun, 05 Sep 2010)
New Revision: 7358

Modified:
   code/branches/notifications/data/gui/scripts/KeyBindMenu.lua
   code/branches/notifications/data/levels/tutorial.oxw
   code/branches/notifications/src/modules/notifications/dispatchers/CommandNotification.cc
   code/branches/notifications/src/modules/notifications/dispatchers/CommandNotification.h
Log:
Adding method that puts a keybinding into a more human readable form.


Modified: code/branches/notifications/data/gui/scripts/KeyBindMenu.lua
===================================================================
--- code/branches/notifications/data/gui/scripts/KeyBindMenu.lua	2010-09-05 16:50:17 UTC (rev 7357)
+++ code/branches/notifications/data/gui/scripts/KeyBindMenu.lua	2010-09-05 20:26:37 UTC (rev 7358)
@@ -112,7 +112,7 @@
     elseif( string.find(group, "JoyStickButtons") ~= nil ) then
         return "Joystick " .. name
     elseif( string.find(group, "JoyStickAxes") ~= nil ) then
-        return "Joystick Axis" .. string.sub(name, 5, 6) .. string.sub(name, string.find(name, 'Axis%d%d(.*)')+6)
+        return "Joystick Axis " .. string.sub(name, 5, 6) .. string.sub(name, string.find(name, 'Axis%d%d(.*)')+6)
     elseif( group == "MouseAxes" ) then
         return "Mouse " .. string.sub(name, string.find(name, '.(.*)')+1) .. " " .. string.sub(name, 1, 1) .. "-Axis"
     end

Modified: code/branches/notifications/data/levels/tutorial.oxw
===================================================================
--- code/branches/notifications/data/levels/tutorial.oxw	2010-09-05 16:50:17 UTC (rev 7357)
+++ code/branches/notifications/data/levels/tutorial.oxw	2010-09-05 20:26:37 UTC (rev 7358)
@@ -18,7 +18,7 @@
    skybox       = "Orxonox/skypanoramagen1"
   >
 
-      <CommandNotification preMessage="Press '" postMessage="' to fire your primary weapon." command="fire 0">
+      <CommandNotification preMessage="Move '" postMessage="' to look left." command="scale 1 rotateYaw">
         <events>
             <trigger>
                 <DistanceTrigger name=trigger position="0,0,-100" distance=10 target="Pawn" />

Modified: code/branches/notifications/src/modules/notifications/dispatchers/CommandNotification.cc
===================================================================
--- code/branches/notifications/src/modules/notifications/dispatchers/CommandNotification.cc	2010-09-05 16:50:17 UTC (rev 7357)
+++ code/branches/notifications/src/modules/notifications/dispatchers/CommandNotification.cc	2010-09-05 20:26:37 UTC (rev 7358)
@@ -37,6 +37,7 @@
 #include "core/XMLPort.h"
 #include "core/input/KeyBinderManager.h"
 #include "core/input/KeyBinder.h"
+#include "util/SubString.h"
 
 #include <sstream>
 
@@ -87,11 +88,41 @@
     {
         std::stringstream stream;
         stream << this->getPreMessage();
-        //TODO: Add niceifyer.
-        stream << KeyBinderManager::getInstance().getCurrent()->getBinding(this->getCommand());
+        stream << this->bindingNiceifyer(KeyBinderManager::getInstance().getCurrent()->getBinding(this->getCommand()));
         stream << this->getPostMessage();
-        std::string* message = new std::string(stream.str());
-        return *message;
+        return *(new std::string(stream.str()));
     }
+
+    /**
+    @brief
+        Transforms the input binding into a human readable form.
+    @param binding
+        The binding to be transformed
+    @return
+        Returns a human readable version of the input binding.
+    */
+    const std::string& CommandNotification::bindingNiceifyer(const std::string& binding)
+    {
+        SubString* string = new SubString(binding, '.');
+        std::string name = string->getString(1);
+        std::string group = string->getString(0);
+
+        std::stringstream stream;
+        if(group.compare("Keys") == 0)
+            stream << "Key " << name.substr(3);
+        else if(group.compare("MouseButtons") == 0)
+            stream << "Mouse " << name;
+        else if(group.compare("JoyStickButtons") == 0)
+            stream << "Joystick " << name;
+        else if(group.compare("JoyStickAxes") == 0)
+            stream << "Joystick Axis" << name.substr(5, 6) << name.substr(name.find("Axis")+6);
+        else if(group.compare("MouseAxes") == 0)
+            stream << "Mouse " << name.substr(1,3) << " " << name.substr(0, 1) << "-Axis";
+        else
+            stream << binding;
+
+        delete string;
+        return *(new std::string(stream.str()));
+    }
     
 }

Modified: code/branches/notifications/src/modules/notifications/dispatchers/CommandNotification.h
===================================================================
--- code/branches/notifications/src/modules/notifications/dispatchers/CommandNotification.h	2010-09-05 16:50:17 UTC (rev 7357)
+++ code/branches/notifications/src/modules/notifications/dispatchers/CommandNotification.h	2010-09-05 20:26:37 UTC (rev 7358)
@@ -103,6 +103,8 @@
             void setPostMessage(const std::string& message)
                  { this->postMessage_ = message; }
 
+            const std::string& bindingNiceifyer(const std::string& binding);
+
     };
 
 }




More information about the Orxonox-commit mailing list