Page 1 of 1

Development: resetting a tool

Posted: Mon Sep 22, 2008 12:43 pm
by JoeNotCharles
I'm trying to add a new tool to maptool (the line-of-sight/concealment tool I suggested here).

I have small set of data stored with the tool (the points clicked on, basically) and I want to clear them when the user chooses a new tool or loads a new map. Is there a method to override for this or something?

Also, since I'm posting I might as well ask - right now the lines my tool draws are only visible to the user. I'd like to add a button to reveal them to all players so that you can use the tool to show everyone that you have line of sight to settle arguments. The only way I can see to do this is to send a server "draw" command. Then to get rid of the diagram I'd need to draw over it with the same drawing set to erase. I haven't had time to test this yet - would that interfere with actual drawings done with the draw tool (ie. accidentally erase them if there's overlap)?

Posted: Mon Sep 22, 2008 3:43 pm
by trevor
There's an "attachTo()" and "detachFrom()" method on the tools that you can override. They are called when a tool is selected or deselected respectively.

You'd have to create a mechanism to transfer the data through the server API, using drawings probably isn't the most efficient way. Take a look at the way the pointer works (holding SPACE on a map shows an arrow where you are pointing)

Posted: Mon Sep 22, 2008 6:42 pm
by JoeNotCharles
Thanks, that's very helpful!

Now here's hoping I can get this finished and distributed to my players before my game on Wednesday...

Posted: Mon Sep 22, 2008 11:20 pm
by trevor
There's also a "resetTool()"

Posted: Sun Sep 28, 2008 1:46 pm
by JoeNotCharles
I'm starting on the "space bar reveals to all players" feature. I'm finding the keyboard handling is really unreliable. Half the time when I start the app, the space bar doesn't work at all (in this tool only) until I restart.

Here's the code so far (it just pops up a pointer at the moment):

Code: Select all

protected void hideLines() {
    MapTool.serverCommand().hidePointer(MapTool.getPlayer().getName());
    linesRevealed = false;    	
}
    
protected void revealLines() {
    Pointer pointer = new Pointer(renderer.getZone(), startPoint.x, startPoint.y, 0, Pointer.Type.THOUGHT_BUBBLE);
    MapTool.serverCommand().showPointer(MapTool.getPlayer().getName(), pointer);
    linesRevealed = true;
}

@Override
protected void installKeystrokes(Map<KeyStroke> actionMap) {
    super.installKeystrokes(actionMap);

    actionMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, false), new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            if (linesRevealed) {
                hideLines();
            } else {
                revealLines();
            }
        }
    });
}
Any idea what could be wrong?