Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "StdAfx.h"
#include "DTreePlanter.h"
-#include "funchandlers.h"
-bool DTreePlanter::OnMouseMove( guint32 nFlags, gdouble x, gdouble y ) {
- return false;
-}
+#include <list>
+#include "str.h"
+
+#include "DPoint.h"
+#include "DPlane.h"
+#include "DBrush.h"
+#include "DEPair.h"
+#include "DPatch.h"
+#include "DEntity.h"
+
+#include "ScriptParser.h"
+#include "misc.h"
+#include "scenelib.h"
+
-bool DTreePlanter::OnLButtonDown( guint32 nFlags, gdouble x, gdouble y ) {
- VIEWTYPE vt = m_XYWrapper->GetViewType();
+
+#include "funchandlers.h"
+
+SignalHandlerResult DTreePlanter::mouseDown( const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers ){
+ if ( button != c_buttonLeft ) {
+ return SIGNAL_CONTINUE_EMISSION;
+ }
+ VIEWTYPE vt = GlobalRadiant().XYWindow_getViewType();
switch ( vt ) {
case XY:
case YZ:
case XZ:
default:
- return false;
+ return SIGNAL_CONTINUE_EMISSION;
}
- vec3_t pt, vhit;
+ Vector3 pt, vhit;
- m_XYWrapper->SnapToGrid( static_cast< int >( x ), static_cast< int >( y ), pt );
+ pt = vector3_snapped( GlobalRadiant().XYWindow_windowToWorld( position ), GlobalRadiant().getGridSize() );
- if ( FindDropPoint( pt, vhit ) ) {
+ if ( FindDropPoint( vector3_to_array( pt ), vector3_to_array( vhit ) ) ) {
vhit[2] += m_offset;
char buffer[128];
e.AddEPair( "origin", buffer );
if ( m_autoLink ) {
- entity_t* pLastEntity = NULL;
- entity_t* pThisEntity = NULL;
- int entNum = -1, lastEntNum = -1, entpos;
+ const scene::Path* pLastEntity = NULL;
+ const scene::Path* pThisEntity = NULL;
+
+ int entpos;
for ( int i = 0; i < 256; i++ ) {
sprintf( buffer, m_linkName, i );
- pThisEntity = FindEntityFromTargetname( buffer, &entNum );
+ pThisEntity = FindEntityFromTargetname( buffer );
if ( pThisEntity ) {
entpos = i;
- lastEntNum = entNum;
pLastEntity = pThisEntity;
}
}
if ( pLastEntity ) {
DEntity e2;
- e2.LoadFromEntity( lastEntNum, TRUE );
+ e2.LoadFromEntity( pLastEntity->top(), true );
e2.AddEPair( "target", buffer );
e2.RemoveFromRadiant();
- e2.BuildInRadiant( FALSE );
+ e2.BuildInRadiant( false );
}
+
}
if ( m_setAngles ) {
e.AddEPair( "modelscale", buffer );
}
- e.BuildInRadiant( FALSE );
+ e.BuildInRadiant( false );
}
if ( m_autoLink ) {
DoTrainPathPlot();
}
- return true;
-}
-
-bool DTreePlanter::OnLButtonUp( guint32 nFlags, gdouble x, gdouble y ) {
- return false;
-}
-
-bool DTreePlanter::OnRButtonDown( guint32 nFlags, gdouble x, gdouble y ) {
- return false;
-}
-
-bool DTreePlanter::OnRButtonUp( guint32 nFlags, gdouble x, gdouble y ) {
- return false;
-}
-
-bool DTreePlanter::OnMButtonDown( guint32 nFlags, gdouble x, gdouble y ) {
- return false;
-}
-
-bool DTreePlanter::OnMButtonUp( guint32 nFlags, gdouble x, gdouble y ) {
- return false;
+ return SIGNAL_STOP_EMISSION;
}
bool DTreePlanter::FindDropPoint( vec3_t in, vec3_t out ) {
return found;
}
-void DTreePlanter::DropEntsToGround( void ) {
- // tell Radiant we want to access the selected brushes
- g_FuncTable.m_pfnAllocateSelectedBrushHandles();
-
- DEntity ent;
-
- int cnt = g_FuncTable.m_pfnSelectedBrushCount();
- for ( int i = 0; i < cnt; i++ ) {
- brush_t *brush = (brush_t*)g_FuncTable.m_pfnGetSelectedBrushHandle( i );
-
- ent.LoadFromEntity( brush->owner, TRUE );
+class TreePlanterDropEntityIfSelected
+{
+mutable DEntity ent;
+DTreePlanter& planter;
+public:
+TreePlanterDropEntityIfSelected( DTreePlanter& planter ) : planter( planter ){
+}
+void operator()( scene::Instance& instance ) const {
+ if ( !instance.isSelected() ) {
+ return;
+ }
+ ent.LoadFromEntity( instance.path().top() );
- DEPair* pEpair = ent.FindEPairByKey( "origin" );
- if ( !pEpair ) {
- continue;
- }
+ DEPair* pEpair = ent.FindEPairByKey( "origin" );
+ if ( !pEpair ) {
+ return;
+ }
- vec3_t vec, out;
- sscanf( pEpair->value.GetBuffer(), "%f %f %f", &vec[0], &vec[1], &vec[2] );
+ vec3_t vec, out;
+ sscanf( pEpair->value.GetBuffer(), "%f %f %f", &vec[0], &vec[1], &vec[2] );
- FindDropPoint( vec, out );
+ planter.FindDropPoint( vec, out );
- char buffer[256];
- sprintf( buffer, "%f %f %f", out[0], out[1], out[2] );
- ent.AddEPair( "origin", buffer );
- ent.RemoveFromRadiant();
- ent.BuildInRadiant( FALSE );
- }
+ char buffer[256];
+ sprintf( buffer, "%f %f %f", out[0], out[1], out[2] );
+ ent.AddEPair( "origin", buffer );
+ ent.RemoveFromRadiant();
+ ent.BuildInRadiant( false );
+}
+};
- g_FuncTable.m_pfnReleaseSelectedBrushHandles();
+void DTreePlanter::DropEntsToGround( void ) {
+ Scene_forEachEntity( TreePlanterDropEntityIfSelected( *this ) );
}
-void DTreePlanter::MakeChain( void ) {
+void DTreePlanter::MakeChain( int linkNum, const char* linkName ) {
char buffer[256];
int i;
-
- for ( i = 0; i < m_linkNum; i++ ) {
+ for ( i = 0; i < linkNum; i++ ) {
DEntity e( "info_train_spline_main" );
- sprintf( buffer, "%s_pt%i", m_linkName, i );
+ sprintf( buffer, "%s_pt%i", linkName, i );
e.AddEPair( "targetname", buffer );
sprintf( buffer, "0 %i 0", i * 64 );
e.AddEPair( "origin", buffer );
if ( i != m_linkNum - 1 ) {
- sprintf( buffer, "%s_pt%i", m_linkName, i + 1 );
+ sprintf( buffer, "%s_pt%i", linkName, i + 1 );
e.AddEPair( "target", buffer );
- sprintf( buffer, "%s_ctl%i", m_linkName, i );
+ sprintf( buffer, "%s_ctl%i", linkName, i );
e.AddEPair( "control", buffer );
}
-
- e.BuildInRadiant( FALSE );
+ e.BuildInRadiant( false );
}
- for ( i = 0; i < m_linkNum - 1; i++ ) {
+ for ( i = 0; i < linkNum - 1; i++ ) {
DEntity e( "info_train_spline_control" );
- sprintf( buffer, "%s_ctl%i", m_linkName, i );
+ sprintf( buffer, "%s_ctl%i", linkName, i );
e.AddEPair( "targetname", buffer );
sprintf( buffer, "0 %i 0", ( i * 64 ) + 32 );
e.AddEPair( "origin", buffer );
- e.BuildInRadiant( FALSE );
+ e.BuildInRadiant( false );
}
}
e.AddEPair( "control", buffer );
}
- e.BuildInRadiant( FALSE );
+ e.BuildInRadiant( false );
}
for(int i = 0; i < m_linkNum-1; i++) {
sprintf( buffer, "0 %i 0", (i * 64) + 32);
e.AddEPair( "origin", buffer );
- e.BuildInRadiant( FALSE );
+ e.BuildInRadiant( false );
}*/
}