[Orxonox-commit 3754] r8434 - in code/branches/dockingsystem2: data/gui/layouts data/gui/scripts data/levels src/modules/docking
sven at orxonox.net
sven at orxonox.net
Mon May 9 16:26:37 CEST 2011
Author: sven
Date: 2011-05-09 16:26:37 +0200 (Mon, 09 May 2011)
New Revision: 8434
Added:
code/branches/dockingsystem2/data/gui/layouts/DockingDialog.layout
code/branches/dockingsystem2/data/gui/scripts/DockingDialog.lua
Modified:
code/branches/dockingsystem2/data/levels/docking.oxw
code/branches/dockingsystem2/src/modules/docking/CMakeLists.txt
code/branches/dockingsystem2/src/modules/docking/Dock.cc
code/branches/dockingsystem2/src/modules/docking/Dock.h
Log:
Added simple GUI for docking..
Added: code/branches/dockingsystem2/data/gui/layouts/DockingDialog.layout
===================================================================
--- code/branches/dockingsystem2/data/gui/layouts/DockingDialog.layout (rev 0)
+++ code/branches/dockingsystem2/data/gui/layouts/DockingDialog.layout 2011-05-09 14:26:37 UTC (rev 8434)
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<GUILayout >
+ <Window Type="MenuWidgets/StaticImage" Name="orxonox/DockingBackground" >
+ <Property Name="FrameEnabled" Value="False" />
+ <Property Name="InheritsAlpha" Value="False" />
+ <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+ <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{1,0}}" />
+ <Property Name="BackgroundEnabled" Value="False" />
+ <Window Type="MenuWidgets/StaticText" Name="orxonox/DockingTitle" >
+ <Property Name="Text" Value="Docking" />
+ <Property Name="Alpha" Value="0.8" />
+ <Property Name="InheritsAlpha" Value="False" />
+ <Property Name="HorzFormatting" Value="HorzCentred" />
+ <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+ <Property Name="VertFormatting" Value="TopAligned" />
+ <Property Name="UnifiedAreaRect" Value="{{0.25,0},{0.2875,0},{0.75,0},{0.7,0}}" />
+ <Window Type="MenuWidgets/Listbox" Name="orxonox/DockingDocks" >
+ <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+ <Property Name="UnifiedAreaRect" Value="{{0.05,0},{0.15,0},{0.95,0},{0.85,0}}" />
+ </Window>
+ </Window>
+ <Window Type="MenuWidgets/Button" Name="orxonox/DockingDockButton" >
+ <Property Name="Text" Value="Dock" />
+ <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+ <Property Name="UnifiedAreaRect" Value="{{0.2875,0},{0.725,0},{0.4875,0},{0.775,0}}" />
+ <Event Name="Clicked" Function="DockingDialog.dockButton_clicked"/>
+ </Window>
+ <Window Type="MenuWidgets/Button" Name="orxonox/DockingCancelButton" >
+ <Property Name="Text" Value="Cancel" />
+ <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+ <Property Name="UnifiedAreaRect" Value="{{0.5125,0},{0.725,0},{0.7125,0},{0.775,0}}" />
+ <Event Name="Clicked" Function="DockingDialog.cancelButton_clicked"/>
+ </Window>
+ </Window>
+</GUILayout>
Added: code/branches/dockingsystem2/data/gui/scripts/DockingDialog.lua
===================================================================
--- code/branches/dockingsystem2/data/gui/scripts/DockingDialog.lua (rev 0)
+++ code/branches/dockingsystem2/data/gui/scripts/DockingDialog.lua 2011-05-09 14:26:37 UTC (rev 8434)
@@ -0,0 +1,58 @@
+-- DockingDialog.lua
+
+local P = createMenuSheet("DockingDialog")
+
+P.docks = {}
+
+function P.onLoad()
+
+end
+
+function P.onShow()
+ P.update()
+ orxonox.CommandExecutor:execute("pause")
+end
+
+function P.onHide()
+ orxonox.CommandExecutor:execute("pause")
+end
+
+function P.update()
+ -- update dock list
+ P.docks = {}
+ local docks = orxonox.Dock:getNumberOfActiveDocks()
+ for i = 0, docks-1 do
+ table.insert(P.docks, orxonox.Dock:getActiveDockAtIndex(i))
+ end
+
+ local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/DockingDocks"))
+ listbox:resetList()
+
+ for k in pairs(P.docks) do
+ local item = CEGUI.createListboxTextItem("Dock " .. k)
+ item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
+ listbox:addItem(item)
+ end
+end
+
+function P.dockButton_clicked(e)
+ local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/DockingDocks"))
+ local choice = listbox:getFirstSelectedItem()
+ if choice ~= nil then
+ local index = listbox:getItemIndex(choice)
+ local dock = P.docks[index+1]
+ cout(0, index )--.. ": " .. P.docks[index])
+ if dock ~= nil then
+ cout(0, "LUA>Docking")
+ dock:dock()
+ end
+ end
+ hideMenuSheet(P.name)
+end
+
+function P.cancelButton_clicked(e)
+ --P.hideMe()
+ hideMenuSheet(P.name)
+end
+
+return P
Modified: code/branches/dockingsystem2/data/levels/docking.oxw
===================================================================
--- code/branches/dockingsystem2/data/levels/docking.oxw 2011-05-09 13:58:48 UTC (rev 8433)
+++ code/branches/dockingsystem2/data/levels/docking.oxw 2011-05-09 14:26:37 UTC (rev 8434)
@@ -26,29 +26,34 @@
<Light type="directional" position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
+
+
<?lua for i = 1, 10, 1 do ?>
- <SpawnPoint position="<?lua print(math.random() * 500 - 250) ?>,<?lua print(math.random() * 500 - 250) ?>,<?lua print(math.random() * 500 - 250) ?>" lookat="0,0,0" spawnclass="SpaceShip" pawndesign="spaceshipassff" />
+ <SpawnPoint position="<?lua print(math.random() * 200 - 100) ?>,<?lua print(math.random() * 200 - 100) ?>,<?lua print(math.random() * 200 - 100) ?>" lookat="0,0,0" spawnclass="SpaceShip" pawndesign="spaceshipassff" />
<?lua end ?>
- <Dock position="-50,-100,50">
- <effects>
- <DockToShip target="theDestroyer" />
- </effects>
- <events>
- <execute>
- <EventListener event="dockMe" />
- </execute>
- </events>
- <attached>
- <DistanceTrigger position="0,0,0" distance="20" target="Pawn" beaconMode="exclude" targetname="destroyerBeacon" name="dockMe" />
- <Billboard material="Examples/Flare" colour="1.0, 0, 0" />
- </attached>
- </Dock>
-
+ <Dock>
+ <effects>
+ <DockToShip target="destroyer" />
+ </effects>
+ <events>
+ <execute>
+ <EventListener event="dockMe" />
+ </execute>
+ </events>
+ <attached>
+ <DistanceTrigger position="0,0,0" distance="50" target="Pawn" beaconMode="exclude" targetname="destroyerBeacon" name="dockMe" />
+ <Billboard material="Examples/Flare" colour="1.0, 0, 0" />
+ </attached>
+ </Dock>
+
+
+
<SpaceShip
+ position = "-150,-50,-100"
hudtemplate = "spaceshiphud"
camerapositiontemplate = "spaceshipassffcameras"
engine = "spaceshipassffengine"
@@ -70,8 +75,8 @@
angularDamping = "0.9999999"
>
<attached>
- <DistanceTriggerBeacon name="beacon1" />
- <DockingTarget name="asdf" />
+ <DistanceTriggerBeacon name="bcnSpaceShip1" />
+ <DockingTarget name="spaceShip1" />
<Model position="0,0,0" yaw="90" pitch="-90" roll="0" scale="4" mesh="assff.mesh" />
<BlinkingBillboard position="17,-1.5,0" material="Examples/Flare" colour="1.0, 0.5, 0.3" amplitude="0.1" frequency="0.5" quadratic="1" />
@@ -95,7 +100,7 @@
<Destroyer
- position = "100,150,0"
+ position = "100,150,100"
collisionType = "dynamic"
mass = "100000"
velocity = "0,0,0"
@@ -107,8 +112,8 @@
<attached>
- <DistanceTriggerBeacon name="destroyerBeacon" />
- <DockingTarget name="theDestroyer" />
+ <DistanceTriggerBeacon name="bcnDestroyer" />
+ <DockingTarget name="destroyer" />
<TeamSpawnPoint team="1" position="150,0,7" direction="-1,0,0" roll="90" yaw="0" spawnclass="SpaceShip" pawndesign="spaceshipassff" />
Modified: code/branches/dockingsystem2/src/modules/docking/CMakeLists.txt
===================================================================
--- code/branches/dockingsystem2/src/modules/docking/CMakeLists.txt 2011-05-09 13:58:48 UTC (rev 8433)
+++ code/branches/dockingsystem2/src/modules/docking/CMakeLists.txt 2011-05-09 14:26:37 UTC (rev 8434)
@@ -9,6 +9,7 @@
MODULE
FIND_HEADER_FILES
TOLUA_FILES
+ Dock.h
PCH_FILE
DockingPrecompiledHeaders.h
LINK_LIBRARIES
Modified: code/branches/dockingsystem2/src/modules/docking/Dock.cc
===================================================================
--- code/branches/dockingsystem2/src/modules/docking/Dock.cc 2011-05-09 13:58:48 UTC (rev 8433)
+++ code/branches/dockingsystem2/src/modules/docking/Dock.cc 2011-05-09 14:26:37 UTC (rev 8434)
@@ -33,16 +33,21 @@
#include "Dock.h"
+#include "core/CoreIncludes.h"
+#include "core/LuaState.h"
+#include "core/GUIManager.h"
#include "infos/HumanPlayer.h"
#include "worldentities/pawns/Pawn.h"
#include "interfaces/PlayerTrigger.h"
-#include "controllers/HumanController.h"
#include "core/command/ConsoleCommand.h"
+#include "ToluaBindDocking.h"
-
namespace orxonox
{
+ // Register tolua_open function when loading the library
+ DeclareToluaInterface(Docking);
+
CreateFactory(Dock);
SetConsoleCommand("Dock", "dock", &Dock::cmdDock).addShortcut().setAsInputCommand();
@@ -110,12 +115,17 @@
COUT(0) << "Dock triggered by player: " << player->getName() << ".." << std::endl;
- if(bTriggered) {
+ if(bTriggered)
+ {
// Add player to this Docks candidates
candidates.insert(player);
+ // Show docking dialog
+ GUIManager::showGUI("DockingDialog");
//DockingEffect::invokeEffect(docking::DOCKING, player, effects_);
- } else {
+ }
+ else
+ {
// Remove player from candidates list
candidates.erase(player);
@@ -126,27 +136,33 @@
}
- void Dock::cmdDock() {
+ void Dock::cmdDock()
+ {
PlayerInfo* player = HumanController::getLocalControllerSingleton()->getPlayer();
- for(ObjectList<Dock>::iterator it = ObjectList<Dock>::begin(); it != ObjectList<Dock>::end(); ++it) {
+ for(ObjectList<Dock>::iterator it = ObjectList<Dock>::begin(); it != ObjectList<Dock>::end(); ++it)
+ {
if(it->dock(player))
break;
}
}
- void Dock::cmdUndock() {
+ void Dock::cmdUndock()
+ {
PlayerInfo* player = HumanController::getLocalControllerSingleton()->getPlayer();
- for(ObjectList<Dock>::iterator it = ObjectList<Dock>::begin(); it != ObjectList<Dock>::end(); ++it) {
+ for(ObjectList<Dock>::iterator it = ObjectList<Dock>::begin(); it != ObjectList<Dock>::end(); ++it)
+ {
if(it->undock(player))
break;
}
}
- bool Dock::dock(PlayerInfo* player) {
+ bool Dock::dock(PlayerInfo* player)
+ {
// Check if player is a candidate
- if(candidates.find(player) == candidates.end()) {
- COUT(0) << "Player is not a candidate!";
+ if(candidates.find(player) == candidates.end())
+ {
+ COUT(0) << "Player is not a candidate!" << std::endl;
return false;
}
@@ -157,9 +173,11 @@
return true;
}
- bool Dock::undock(PlayerInfo* player) {
+ bool Dock::undock(PlayerInfo* player)
+ {
// Check if player is docked to this Dock
- if(docked.find(player) == docked.end()) {
+ if(docked.find(player) == docked.end())
+ {
COUT(0) << "Player is not docked to this Dock." << std::endl;
return false;
}
@@ -172,15 +190,46 @@
}
- bool Dock::addEffect(DockingEffect* effect) {
+ unsigned int Dock::getNumberOfActiveDocks()
+ {
+ int i = 0;
+ PlayerInfo* player = HumanController::getLocalControllerSingleton()->getPlayer();
+ for(ObjectList<Dock>::iterator it = ObjectList<Dock>::begin(); it != ObjectList<Dock>::end(); ++it)
+ {
+ if(it->candidates.find(player) != it->candidates.end())
+ i++;
+ }
+ return i;
+ }
+
+ Dock* Dock::getActiveDockAtIndex(unsigned int index)
+ {
+ PlayerInfo* player = HumanController::getLocalControllerSingleton()->getPlayer();
+ for(ObjectList<Dock>::iterator it = ObjectList<Dock>::begin(); it != ObjectList<Dock>::end(); ++it)
+ {
+ if(it->candidates.find(player) != it->candidates.end())
+ {
+ if(index == 0)
+ return *it;
+ index--;
+ }
+ }
+ return NULL;
+ }
+
+
+ bool Dock::addEffect(DockingEffect* effect)
+ {
assert(effect);
effects.push_back(effect);
return true;
}
- const DockingEffect* Dock::getEffect(unsigned int index) const {
+ const DockingEffect* Dock::getEffect(unsigned int index) const
+ {
int i = index;
- for (std::list<DockingEffect*>::const_iterator effect = this->effects.begin(); effect != this->effects.end(); ++effect) {
+ for (std::list<DockingEffect*>::const_iterator effect = this->effects.begin(); effect != this->effects.end(); ++effect)
+ {
if(i == 0)
return *effect;
i--;
Modified: code/branches/dockingsystem2/src/modules/docking/Dock.h
===================================================================
--- code/branches/dockingsystem2/src/modules/docking/Dock.h 2011-05-09 13:58:48 UTC (rev 8433)
+++ code/branches/dockingsystem2/src/modules/docking/Dock.h 2011-05-09 14:26:37 UTC (rev 8434)
@@ -42,14 +42,17 @@
#include "core/EventIncludes.h"
#include "worldentities/StaticEntity.h"
-#include "notifications/NotificationManager.h"
+#include "controllers/HumanController.h"
#include "DockingEffect.h"
#include "DockingPrereqs.h"
-namespace orxonox {
+namespace orxonox // tolua_export
+{ // tolua_export
- class _DockingExport Dock : public StaticEntity {
+ class _DockingExport Dock // tolua_export
+ : public StaticEntity
+ { // tolua_export
public:
Dock(BaseObject* creator);
virtual ~Dock();
@@ -65,6 +68,10 @@
bool dock(PlayerInfo* player); //!< Returns true if given player docked successfully (player must be a candidate)
bool undock(PlayerInfo* player); //!< Undocks a player (player must be docked)
+ void dock() { this->dock(HumanController::getLocalControllerSingleton()->getPlayer()); } // tolua_export
+ static unsigned int getNumberOfActiveDocks(); // tolua_export
+ static Dock* getActiveDockAtIndex(unsigned int index); // tolua_export
+
static void cmdDock();
static void cmdUndock();
@@ -72,9 +79,7 @@
std::set<PlayerInfo*> candidates; //!< A set of all players which are allowed to dock using the console command.
std::set<PlayerInfo*> docked; //!< A set of all docked players
std::list<DockingEffect*> effects; //!< The list of DockingEffects to be executed when a player docks.
- };
+ }; // tolua_export
+} // tolua_export
-
-}
-
#endif /* _Dock_H__ */
More information about the Orxonox-commit
mailing list