view orpg/mapper/map_prop_dialog.py @ 28:ff154cf3350c ornery-orc

Traipse 'OpenRPG' {100203-00} 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 (Stable) 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 Wed, 03 Feb 2010 22:16:49 -0600
parents 97265586402b
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/map_prop_dialog.py
# Author: OpenRPG
# Maintainer:
# Version:
#   $Id: map_prop_dialog.py,v Traipse 'Ornery-Orc' prof.ebral Exp $
#
# Description:
#
__version__ = "$Id: map_prop_dialog.py,v Traipse 'Ornery-Orc' prof.ebral Exp $"

from orpg.orpg_windows import *
from background import *
from grid import *
from miniatures import *
from whiteboard import *

##-----------------------------
## map prop dialog
##-----------------------------

CTRL_WIDTH = wx.NewId()
CTRL_HEIGHT = wx.NewId()
CTRL_BG_COLOR = wx.NewId()
CTRL_BG_COLOR_VALUE = wx.NewId()
CTRL_TEXTURE = wx.NewId()
CTRL_TEXTURE_PATH = wx.NewId()
CTRL_IMAGE = wx.NewId()
CTRL_IMAGE_PATH  = wx.NewId()
CTRL_GRID = wx.NewId()
CTRL_GRID_SNAP = wx.NewId()
CTRL_GRID_COLOR = wx.NewId()
CTRL_GRID_MODE_RECT = wx.NewId()
CTRL_GRID_MODE_HEX = wx.NewId()
CTRL_GRID_LINE_NONE = wx.NewId()
CTRL_GRID_LINE_DOTTED = wx.NewId()
CTRL_GRID_LINE_SOLID = wx.NewId()

class general_map_prop_dialog(wx.Dialog):
    def __init__(self,parent,size,bg_layer,grid_layer):
        wx.Dialog.__init__(self,parent,-1,"General Map Properties",wx.DefaultPosition,wx.Size(425,405))
        self.size = size
        self.bg_layer = bg_layer
        self.grid_layer = grid_layer
        #build controls
        self.ctrls = {  CTRL_WIDTH : wx.TextCtrl(self, CTRL_WIDTH, str(size[0])),
                        CTRL_HEIGHT : wx.TextCtrl(self, CTRL_HEIGHT, str(size[1])),
                        CTRL_BG_COLOR : wx.RadioButton(self, CTRL_BG_COLOR, "Color", style=wx.RB_GROUP),
                        CTRL_BG_COLOR_VALUE : wx.Button(self, CTRL_BG_COLOR_VALUE, "Color"),
                        CTRL_TEXTURE : wx.RadioButton(self, CTRL_TEXTURE, "Texture"),
                        CTRL_TEXTURE_PATH: wx.TextCtrl(self, CTRL_TEXTURE_PATH,"http://"),
                        CTRL_IMAGE : wx.RadioButton(self, CTRL_IMAGE, "Image"),
                        CTRL_IMAGE_PATH :wx.TextCtrl(self, CTRL_IMAGE_PATH,"http://"),
                        CTRL_GRID : wx.TextCtrl(self, CTRL_GRID),
                        CTRL_GRID_SNAP : wx.CheckBox(self, CTRL_GRID_SNAP, " Snap to grid"),
                        CTRL_GRID_COLOR : wx.Button(self, CTRL_GRID_COLOR, "Grid Color"),
                        CTRL_GRID_MODE_RECT : wx.RadioButton(self, CTRL_GRID_MODE_RECT, "Rectangular", style=wx.RB_GROUP),
                        CTRL_GRID_MODE_HEX : wx.RadioButton(self, CTRL_GRID_MODE_HEX, "Hexagonal"),
                        CTRL_GRID_LINE_NONE : wx.RadioButton(self, CTRL_GRID_LINE_NONE, "No Lines", style=wx.RB_GROUP),
                        CTRL_GRID_LINE_DOTTED : wx.RadioButton(self, CTRL_GRID_LINE_DOTTED, "Dotted Lines"),
                        CTRL_GRID_LINE_SOLID : wx.RadioButton(self, CTRL_GRID_LINE_SOLID, "Solid Lines")
                     }
        # set values of bg controls
        self.ctrls[CTRL_BG_COLOR].SetValue(False)
        self.ctrls[CTRL_TEXTURE].SetValue(False)
        self.ctrls[CTRL_IMAGE].SetValue(False)

        # Begin ted's changes for map bg persistency.
        if bg_layer.bg_color != None: self.ctrls[CTRL_BG_COLOR_VALUE].SetBackgroundColour(bg_layer.bg_color)
        if bg_layer.img_path != None:
            self.ctrls[CTRL_TEXTURE_PATH].SetValue(bg_layer.img_path)
            self.ctrls[CTRL_IMAGE_PATH].SetValue(bg_layer.img_path)
        # End ted's changes

        if bg_layer.type == BG_COLOR: self.ctrls[CTRL_BG_COLOR].SetValue(True)
        elif bg_layer.type == BG_TEXTURE: self.ctrls[CTRL_TEXTURE].SetValue(True)
        elif bg_layer.type == BG_IMAGE:
            self.ctrls[CTRL_WIDTH].Enable(False)
            self.ctrls[CTRL_HEIGHT].Enable(False)
            self.ctrls[CTRL_IMAGE].SetValue(True)
            # self.ctrls[CTRL_IMAGE_PATH].SetValue(bg_layer.img_path)

        # set grid layer control values
        self.ctrls[CTRL_GRID].SetValue(str(grid_layer.unit_size))
        self.ctrls[CTRL_GRID_SNAP].SetValue(grid_layer.snap)
        self.ctrls[CTRL_GRID_COLOR].SetBackgroundColour(grid_layer.color)
        self.ctrls[CTRL_GRID_MODE_RECT].SetValue(grid_layer.mode == GRID_RECTANGLE)
        self.ctrls[CTRL_GRID_MODE_HEX].SetValue(grid_layer.mode == GRID_HEXAGON)
        self.ctrls[CTRL_GRID_LINE_NONE].SetValue(grid_layer.line == LINE_NONE)
        self.ctrls[CTRL_GRID_LINE_DOTTED].SetValue(grid_layer.line == LINE_DOTTED)
        self.ctrls[CTRL_GRID_LINE_SOLID].SetValue(grid_layer.line == LINE_SOLID)

        #create sizers
        sizers = {}
        sizers['main'] = wx.BoxSizer(wx.VERTICAL)

        #size
        sizers['size'] = wx.StaticBoxSizer(wx.StaticBox(self,-1,"Size"), wx.HORIZONTAL)
        sizers['size'].Add(wx.StaticText(self, -1, "Width: "), 0, wx.ALIGN_CENTER)
        sizers['size'].Add(self.ctrls[CTRL_WIDTH], 0, wx.ALIGN_CENTER)
        sizers['size'].Add(wx.Size(20,25))
        sizers['size'].Add(wx.StaticText(self, -1, "Height: "), 0, wx.ALIGN_CENTER)
        sizers['size'].Add(self.ctrls[CTRL_HEIGHT], 0, wx.ALIGN_CENTER)

        #bg
        sizers['bg'] = wx.StaticBoxSizer(wx.StaticBox(self,-1,"Background"), wx.HORIZONTAL)
        sizers['bg_layout'] = wx.FlexGridSizer(3, 2,10,10)
        sizers['bg_layout'].AddMany([(self.ctrls[CTRL_BG_COLOR],0,wx.EXPAND),
                              (self.ctrls[CTRL_BG_COLOR_VALUE],1,wx.EXPAND),
                              (self.ctrls[CTRL_TEXTURE],0,wx.EXPAND),
                              (self.ctrls[CTRL_TEXTURE_PATH],1,wx.EXPAND),
                              (self.ctrls[CTRL_IMAGE],0,wx.EXPAND),
                              (self.ctrls[CTRL_IMAGE_PATH],1,wx.EXPAND)
                            ])
        sizers['bg_layout'].AddGrowableCol(1)
        sizers['bg'].Add(sizers['bg_layout'], 0, wx.EXPAND)

        #grid
        sizers['grid'] = wx.StaticBoxSizer(wx.StaticBox(self,-1,"Grid"), wx.HORIZONTAL)
        sizers['grid_layout'] = wx.FlexGridSizer(2, 3,10,10)
        sizers['grid_layout'].AddMany([(wx.StaticText(self, -1, "Pixels per Square: "),2,wx.ALIGN_CENTER),
                              (self.ctrls[CTRL_GRID],1,wx.EXPAND),
                              (self.ctrls[CTRL_GRID_COLOR],1,wx.EXPAND),
                              (self.ctrls[CTRL_GRID_SNAP],2,wx.EXPAND),
                              (self.ctrls[CTRL_GRID_MODE_RECT],1,wx.EXPAND),
                              (self.ctrls[CTRL_GRID_MODE_HEX],1,wx.EXPAND),
                              (self.ctrls[CTRL_GRID_LINE_NONE],1,wx.EXPAND),
                              (self.ctrls[CTRL_GRID_LINE_DOTTED],1,wx.EXPAND),
                              (self.ctrls[CTRL_GRID_LINE_SOLID],1,wx.EXPAND)
                            ])
        sizers['grid'].Add(sizers['grid_layout'], 0, wx.EXPAND)

        # buttons
        sizers['but'] = wx.BoxSizer(wx.HORIZONTAL)
        sizers['but'].Add(wx.Button(self, wx.ID_OK, "Apply"), 1, wx.EXPAND)
        sizers['but'].Add(wx.Size(10,10))
        sizers['but'].Add(wx.Button(self, wx.ID_CANCEL, "Cancel"), 1, wx.EXPAND)
        self.sizers = sizers

        #main sizer
        self.sizers['main'].Add(sizers['size'],1, wx.EXPAND)
        self.sizers['main'].Add(sizers['bg'], 1, wx.EXPAND)
        self.sizers['main'].Add(sizers['grid'], 1, wx.EXPAND)
        self.sizers['main'].Add(sizers['but'], 0, wx.EXPAND)
        self.SetSizer(self.sizers['main'])
        self.SetAutoLayout(True)
        self.Fit()

        #event handlers
        self.Bind(wx.EVT_BUTTON, self.on_ok, id=wx.ID_OK)
        self.Bind(wx.EVT_RADIOBUTTON, self.on_click, id=CTRL_BG_COLOR)
        self.Bind(wx.EVT_RADIOBUTTON, self.on_click, id=CTRL_TEXTURE)
        self.Bind(wx.EVT_RADIOBUTTON, self.on_click, id=CTRL_IMAGE)
        self.Bind(wx.EVT_BUTTON, self.on_click, id=CTRL_BG_COLOR_VALUE)
        self.Bind(wx.EVT_BUTTON, self.on_click, id=CTRL_GRID_COLOR)
        self.Bind(wx.EVT_RADIOBUTTON, self.on_click, id=CTRL_GRID_MODE_RECT)
        self.Bind(wx.EVT_RADIOBUTTON, self.on_click, id=CTRL_GRID_MODE_HEX)
        self.Bind(wx.EVT_RADIOBUTTON, self.on_click, id=CTRL_GRID_LINE_NONE)
        self.Bind(wx.EVT_RADIOBUTTON, self.on_click, id=CTRL_GRID_LINE_DOTTED)
        self.Bind(wx.EVT_RADIOBUTTON, self.on_click, id=CTRL_GRID_LINE_SOLID)

    def on_click(self,evt):
        id = evt.GetId()
        if id == CTRL_BG_COLOR or id == CTRL_TEXTURE:
            self.ctrls[CTRL_WIDTH].Enable(True)
            self.ctrls[CTRL_HEIGHT].Enable(True)
        elif id == CTRL_IMAGE:
            self.ctrls[CTRL_WIDTH].Enable(False)
            self.ctrls[CTRL_HEIGHT].Enable(False)
        elif id == CTRL_BG_COLOR_VALUE:
            data = wx.ColourData()
            data.SetChooseFull(True)
            dlg = wx.ColourDialog(self, data)
            if dlg.ShowModal() == wx.ID_OK:
                data = dlg.GetColourData()
                self.ctrls[CTRL_BG_COLOR_VALUE].SetBackgroundColour(data.GetColour())
            dlg.Destroy()
        elif id == CTRL_GRID_COLOR:
            data = wx.ColourData()
            data.SetChooseFull(True)
            dlg = wx.ColourDialog(self, data)
            if dlg.ShowModal() == wx.ID_OK:
                data = dlg.GetColourData()
                self.ctrls[CTRL_GRID_COLOR].SetBackgroundColour(data.GetColour())
            dlg.Destroy()

    def on_ok(self,evt):
        try: self.size = (int(self.ctrls[CTRL_WIDTH].GetValue()),int(self.ctrls[CTRL_HEIGHT].GetValue()))
        except: pass
        if self.ctrls[CTRL_BG_COLOR].GetValue() == True:
            self.bg_layer.set_color(self.ctrls[CTRL_BG_COLOR_VALUE].GetBackgroundColour())
        elif self.ctrls[CTRL_TEXTURE].GetValue() == True:
            self.bg_layer.set_texture(self.ctrls[CTRL_TEXTURE_PATH].GetValue())
        elif self.ctrls[CTRL_IMAGE].GetValue() == True:
            self.size = self.bg_layer.set_image(self.ctrls[CTRL_IMAGE_PATH].GetValue(),self.grid_layer.mapscale)
        else: self.bg_layer.clear()
        if self.ctrls[CTRL_GRID_MODE_RECT].GetValue() == True: grid_mode = GRID_RECTANGLE
        else: grid_mode = GRID_HEXAGON
        if self.ctrls[CTRL_GRID_LINE_NONE].GetValue() == True: grid_line = LINE_NONE
        elif self.ctrls[CTRL_GRID_LINE_DOTTED].GetValue() == True: grid_line = LINE_DOTTED
        else: grid_line = LINE_SOLID
        self.grid_layer.set_grid(int(self.ctrls[CTRL_GRID].GetValue()),
                                 self.ctrls[CTRL_GRID_SNAP].GetValue(),
                                 self.ctrls[CTRL_GRID_COLOR].GetBackgroundColour(),
                                 grid_mode,
                                 grid_line)
        self.EndModal(wx.ID_OK)