view orpg/mapper/fog_handler.py @ 193:6debef714365 beta

Traipse Beta 'OpenRPG' {100201-02} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Beta) New Features: New Bookmarks Feature New 'boot' command to remote admin New confirmation window for sent nodes Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG New Zoom Mouse plugin added New Images added to Plugin UI Switching to Element Tree New Map efficiency, from FlexiRPG New Status Bar to Update Manager New TrueDebug Class in orpg_log (See documentation for usage) New Portable Mercurial New Tip of the Day, from Core and community New Reference Syntax added for custom PC sheets New Child Reference for gametree New Parent Reference for gametree New Gametree Recursion method, mapping, context sensitivity, and effeciency.. New Features node with bonus nodes and Node Referencing help added New Dieroller structure from Core New DieRoller portability for odd Dice New 7th Sea die roller; ie [7k3] = [7d10.takeHighest(3).open(10)] New 'Mythos' System die roller added New vs. die roller method for WoD; ie [3v3] = [3d10.vs(3)]. Included for Mythos roller also New Warhammer FRPG Die Roller (Special thanks to Puu-san for the support) New EZ_Tree Reference system. Push a button, Traipse the tree, get a reference (Beta!) New Grids act more like Spreadsheets in Use mode, with Auto Calc Fixes: Fix to allow for portability to an OpenSUSE linux OS Fix to mplay_client for Fedora and OpenSUSE Fix to Text based Server Fix to Remote Admin Commands Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Fix to Map from gametree not showing to all clients Fix to gametree about menus Fix to Password Manager check on startup Fix to PC Sheets from tool nodes. They now use the tabber_panel Fix to Whiteboard ID to prevent random line or text deleting. Fixes to Server, Remote Server, and Server GUI Fix to Update Manager; cleaner clode for saved repositories Fixes made to Settings Panel and now reactive settings when Ok is pressed Fixes to Alternity roller's attack roll. Uses a simple Tuple instead of a Splice Fix to Use panel of Forms and Tabbers. Now longer enters design mode Fix made Image Fetching. New fetching image and new failed image Fix to whiteboard ID's to prevent non updated clients from ruining the fix. default_manifest.xml renamed to default_upmana.xml
author sirebral
date Mon, 01 Feb 2010 14:22:20 -0600
parents c54768cffbd4
children
line wrap: on
line source

# Copyright (C) 2000-2001 The OpenRPG Project
#
#    openrpg-dev@lists.sourceforge.net
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# --
#
# File: mapper/fog_handler.py
# Author: Mark Tarrabain
#
# Description: Handler for fog layer
#

from fog import *
from base_handler import *
from region import *

#CTRL_REVEAL = wx.NewId()
#CTRL_HIDE = wx.NewId()
#CTRL_REMOVE = wx.NewId()
#CTRL_SHOWALL = wx.NewId()
#CTRL_HIDEALL = wx.NewId()
#CTRL_COLOR = wx.NewId()
#CTRL_PEN = wx.NewId()

class fog_handler(base_layer_handler):
    def __init__(self, parent, id, canvas):
        self.showmode = 1
        self.drawing = False
        self.pencolor=wx.WHITE
        base_layer_handler.__init__(self, parent, id, canvas)

    def build_ctrls(self):
        foglayer = self.canvas.layers['fog']
        base_layer_handler.build_ctrls(self)
        self.f_type_radio = {}
        self.fogshow = wx.RadioButton(self, wx.ID_ANY, "Show", style=wx.RB_GROUP)
        self.foghide = wx.RadioButton(self, wx.ID_ANY, "Hide")
        self.sizer.Add(self.foghide, 0, wx.ALIGN_CENTER)
        self.sizer.Add(self.fogshow, 0, wx.ALIGN_CENTER)
        self.sizer.Add(wx.Size(20,25),1)

    def build_menu(self,label = "fog"):
        base_layer_handler.build_menu(self,label)
        self.main_menu.AppendSeparator()
        item = wx.MenuItem(self.main_menu, wx.ID_ANY, "&Hide All", "Hide All")
        self.canvas.Bind(wx.EVT_MENU, self.on_hideall, item)
        self.main_menu.AppendItem(item)
        item = wx.MenuItem(self.main_menu, wx.ID_ANY, "&Fog Mask", "Fog Mask")
        self.canvas.Bind(wx.EVT_MENU, self.on_color, item)
        self.main_menu.AppendItem(item)
        item = wx.MenuItem(self.main_menu, wx.ID_ANY, "&Remove Fog Layer", "Remove Fog Layer")
        self.canvas.Bind(wx.EVT_MENU, self.on_remove, item)
        self.main_menu.AppendItem(item)
        item = wx.MenuItem(self.main_menu, wx.ID_ANY, "&Pen Color", "Pen Color")
        self.canvas.Bind(wx.EVT_MENU, self.on_pen_color, item)
        self.main_menu.AppendItem(item)

    def on_remove(self,evt):
        session=self.canvas.frame.session
        if (session.my_role() != session.ROLE_GM):
            component.get("chat").InfoPost("You must be a GM to use this feature")
            return
        self.canvas.layers['fog'].remove_fog()
        self.canvas.Refresh(False)

    def on_showall(self,evt):
        session=self.canvas.frame.session
        if (session.my_role() != session.ROLE_GM):
            component.get("chat").InfoPost("You must be a GM to use this feature")
            return
        foglayer = self.canvas.layers['fog']
        foglayer.showall()
        self.canvas.Refresh(False)

    def on_pen_color(self,evt):
        data = wx.ColourData()
        data.SetChooseFull(True)
        data.SetColour(self.pencolor)
        dlg = wx.ColourDialog(self.canvas, data)
        if dlg.ShowModal() == wx.ID_OK:
            data = dlg.GetColourData()
            color = data.GetColour()
            self.pencolor=color
        dlg.Destroy()

    def on_hideall(self,evt):
        session=self.canvas.frame.session
        if (session.my_role() != session.ROLE_GM):
            component.get("chat").InfoPost("You must be a GM to use this feature")
            return
        foglayer=self.canvas.layers['fog']
        foglayer.clear()
        self.canvas.Refresh(False)

    def on_color(self,evt):
        session=self.canvas.frame.session
        if (session.my_role() != session.ROLE_GM):
            component.get("chat").InfoPost("You must be a GM to use this feature")
            return
        data = wx.ColourData()
        data.SetChooseFull(True)
        data.SetColour(self.canvas.layers['fog'].color)
        dlg = wx.ColourDialog(self.canvas, data)
        if dlg.ShowModal() == wx.ID_OK:
            data = dlg.GetColourData()
            color = data.GetColour()
            if "__WXGTK__" not in wx.PlatformInfo: color = wx.Color(color.Red(), color.Green(), color.Blue(), 128)
            self.canvas.layers['fog'].color = color
        dlg.Destroy()
        self.canvas.layers['fog'].fill_fog()
        self.canvas.Refresh(False)

    def update_info(self):
        foglayer = self.canvas.layers['fog']
        pass

    def on_motion(self, evt):
        scale = self.canvas.layers['grid'].mapscale
        dc = wx.ClientDC(self.canvas)
        dc.SetUserScale(scale, scale)
        self.canvas.PrepareDC(dc)
        pos = evt.GetLogicalPosition(dc)
        pos.x /= COURSE
        pos.y /= COURSE
        pos.x /= scale
        pos.y /= scale

        if evt.m_leftDown:
            if not self.drawing:
                self.line = []
                self.line.append(IPoint().make(pos.x, pos.y))
            elif pos.x != self.last.x or pos.y != self.last.y:
                pen= wx.Pen(self.pencolor)
                pen.SetWidth(COURSE/2+1)
                dc.SetPen(pen)
                multi = scale*COURSE
                dc.DrawLine(self.last.x*multi, self.last.y*multi, pos.x*multi, pos.y*multi)
                dc.SetPen(wx.NullPen)
                self.line.append(IPoint().make(pos.x, pos.y))
            self.last = pos
            self.drawing = True
        del dc

    def on_left_up(self,evt):
        if self.drawing == True:
            session=self.canvas.frame.session
            if (session.my_role() != session.ROLE_GM):
                component.get("chat").InfoPost("You must be a GM to use this feature")
            else:
                # This code sets the mode to either new or del 
                # depending on the action to function with the updated createregen code.
                if (self.fogshow.GetValue() == 1):
                    showmode = 'new'
                else:
                    showmode = 'del'
                scale = self.canvas.layers['grid'].mapscale
                dc = wx.ClientDC(self.canvas)
                self.canvas.PrepareDC(dc)
                dc.SetUserScale(scale,scale)
                pen= wx.Pen(self.pencolor)
                pen.SetWidth(COURSE/2+1)
                dc.SetPen(pen)
                dc.DrawLine(self.last.x*scale*COURSE,self.last.y*scale*COURSE,
                    self.line[0].X*scale*COURSE,self.line[0].Y*scale*COURSE)
                dc.SetPen(wx.NullPen)
                wx.BeginBusyCursor()
                # This prevents the divide by zero error by not even 
                # sending the line to be proccessed if it contains less then 3 points
                if (len(self.line)>1): self.canvas.layers['fog'].createregn(self.line, showmode)
                else: pass
                wx.EndBusyCursor()
                del dc
            self.canvas.Refresh(False)
            self.drawing = False