Development: resetting a tool

Thoughts, Help, Feature Requests, Bug Reports, Developing code for...

Moderators: dorpond, trevor, Azhrei

Forum rules
PLEASE don't post images of your entire desktop, attach entire campaign files when only a single file is needed, or generally act in some other anti-social behavior. :)
Post Reply
JoeNotCharles
Kobold
Posts: 14
Joined: Wed Sep 17, 2008 11:17 pm

Development: resetting a tool

Post 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)?

User avatar
trevor
Codeum Arcanum (RPTools Founder)
Posts: 11311
Joined: Mon Jan 09, 2006 4:16 pm
Location: Austin, Tx
Contact:

Post 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)
Dreaming of a 1.3 release

JoeNotCharles
Kobold
Posts: 14
Joined: Wed Sep 17, 2008 11:17 pm

Post 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...

User avatar
trevor
Codeum Arcanum (RPTools Founder)
Posts: 11311
Joined: Mon Jan 09, 2006 4:16 pm
Location: Austin, Tx
Contact:

Post by trevor »

There's also a "resetTool()"
Dreaming of a 1.3 release

JoeNotCharles
Kobold
Posts: 14
Joined: Wed Sep 17, 2008 11:17 pm

Post 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?

Post Reply

Return to “MapTool”