In some situations, having the Components being able to be selected and dragged to another position makes for an intuitive control method for the end-user. This is not readily made possible for Components to do so, however, it can be done. Here are two ways this could be made possible:
Overriding clickAnimation() to Return Modified Animation with a Modified Input Controller
ComponentVessel
and overriding functionality with the controller is bad. Getting rid of the ComponentVessel
is the recommended course of action.GenericDataSnapper - The snapper that holds the component(s).
GenericModelComponent - The component we're trying to move.
Component:
public Animation clickAnimation(Space space, str->Object args=null) { ?CoreObject relative = args.get("pickSurface").PickSurface3D.?owner; if (!relative) ?relative = args.get("owner"); Vessel vessel = generateVessel(relative=relative); return GenericDragVesselClickAnimation(AnimationEnv(space=space, selection=VesselSelection(vessel), args=args)); }
Vessel click animation:
public class GenericDragVesselClickAnimation extends VesselClickAnimation { /** * Constructor. */ public constructor(AnimationEnv env, props: a) { super(env, args=a); } /** * Init controller. */ public AnimationInputController initController() { return GenericDragAnimationInputController(this); } }
Animation input controller:
public class GenericDragAnimationInputController extends ToolAnimationG2InputController { /** * Drag. */ public void drag(AnimationMouseInfo mi) { if (animation as VesselAnimation) { if (?ComponentVessel cv = animation.selection.?main) { if (?GenericModelComponent comp = cv._component) { if (?GenericDataSnapper snapper = comp.snapper) { point pp = snapper.toSnapper(mi.onFloorPos); if (pp != comp.pos) { comp.setPos(pp); snapper.invalidate(); } } } } } super(..); } }
Using a Manipulator
The idea is to have a special Manipulator(a subclass of Connector) to move the components around. The Manipulator will reside in the Snapper and appear when the Component is selected.
Since this is a Manipulator, we can override stretchAnimation()
in Snapper to return a custom Animation. This Animation would then be up to your imagination to implement.
An example is that usually when inserting Components, a custom Insert Animation is created to specify which areas within the Snapper can the Components be inserted into. Therefore we can modify the Insert Animation into a Drag Animation to also show the possible areas the Components can be dragged into:
Comments
0 comments
Please sign in to leave a comment.