Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "StdAfx.h"
+#include "DTreePlanter.h"
-#include "gtkr_list.h"
+#include <list>
#include "str.h"
#include "DPoint.h"
#include "ScriptParser.h"
#include "misc.h"
+#include "scenelib.h"
-#include "DTreePlanter.h"
#include "funchandlers.h"
-bool DTreePlanter::OnMouseMove(guint32 nFlags, gdouble x, gdouble y) {
- return false;
-}
-
-bool DTreePlanter::OnLButtonDown(guint32 nFlags, gdouble x, gdouble y) {
- VIEWTYPE vt = m_XYWrapper->GetViewType();
+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) {
-#if 0
- 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);
}
-#endif
+
}
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 ) {
-#if 0
- // 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;
+ return;
}
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);
- }
+ ent.BuildInRadiant(false);
+ }
+};
- g_FuncTable.m_pfnReleaseSelectedBrushHandles();
-#endif
+void DTreePlanter::DropEntsToGround( void ) {
+ Scene_forEachEntity(TreePlanterDropEntityIfSelected(*this));
}
void DTreePlanter::MakeChain( void ) {
e.AddEPair( "control", buffer );
}
- e.BuildInRadiant( FALSE );
+ e.BuildInRadiant( false );
}
for(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 );
}
}
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 );
}*/
}