Mercurial > traipse_dev
comparison orpg/mapper/map.py @ 105:2f2bebe9c77f alpha
Traipse Alpha 'OpenRPG' {091006-03}
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:
00:
Adds Bookmarks (Alpha) with cool Smiley Star and Plus Symbol images!
01:
Forgot the default_server_bookmarks.xml; added.
02:
Bookmarks working with no errors now! Sweet!
03:
Changes made to the map for increased portability. SnowDog has changes planned in Core,
though.
Added an initial push to the BCG. Not much to see, just shows off how it is re-writing
Main code.
author | sirebral |
---|---|
date | Tue, 06 Oct 2009 22:16:34 -0500 |
parents | 37a11fea3304 |
children | 217fb049bd00 |
comparison
equal
deleted
inserted
replaced
104:15e32ec131cb | 105:2f2bebe9c77f |
---|---|
106 self.cacheSizeSet = False | 106 self.cacheSizeSet = False |
107 self.inside = 0 | 107 self.inside = 0 |
108 # miniatures drag | 108 # miniatures drag |
109 self.drag = None | 109 self.drag = None |
110 | 110 |
111 #self.Bind(wx.EVT_MOUSEWHEEL, self.MouseWheel) | |
112 | |
113 def MouseWheel(self, evt): | |
114 if evt.CmdDown(): | |
115 print evt.GetWheelRotation() | |
116 if evt.GetWheelRotation() > 0: self.on_zoom_in(None) | |
117 elif evt.GetWheelRotation() < 0: self.on_zoom_out(None) | |
118 else: pass | |
119 | |
111 def better_refresh(self, event=None): | 120 def better_refresh(self, event=None): |
112 self.Refresh(True) | 121 self.Refresh(True) |
113 | 122 |
114 def pre_destory_cleanup(self): | 123 def pre_destory_cleanup(self): |
115 self.layers["miniatures"].del_all_miniatures() | 124 self.layers["miniatures"].del_all_miniatures() |
116 | 125 |
117 def processImages(self, evt=None): | 126 def processImages(self, evt=None): |
118 self.session = component.get("session") | 127 self.session = component.get("session") |
119 if self.session.my_role() == self.session.ROLE_LURKER or (str(self.session.group_id) == '0' and str(self.session.status) == '1'): | 128 if self.session.my_role() == self.session.ROLE_LURKER or (str(self.session.group_id) == '0' and str(self.session.status) == '1'): |
120 cidx = self.parent.get_tab_index("Background") | 129 cidx = self.parent.get_tab_index("Background") |
121 self.parent.layer_tabs.EnableTab(cidx, False) | 130 self.parent.tabs.EnableTab(cidx, False) |
122 cidx = self.parent.get_tab_index("Grid") | 131 cidx = self.parent.get_tab_index("Grid") |
123 self.parent.layer_tabs.EnableTab(cidx, False) | 132 self.parent.tabs.EnableTab(cidx, False) |
124 cidx = self.parent.get_tab_index("Miniatures") | 133 cidx = self.parent.get_tab_index("Miniatures") |
125 self.parent.layer_tabs.EnableTab(cidx, False) | 134 self.parent.tabs.EnableTab(cidx, False) |
126 cidx = self.parent.get_tab_index("Whiteboard") | 135 cidx = self.parent.get_tab_index("Whiteboard") |
127 self.parent.layer_tabs.EnableTab(cidx, False) | 136 self.parent.tabs.EnableTab(cidx, False) |
128 cidx = self.parent.get_tab_index("Fog") | 137 cidx = self.parent.get_tab_index("Fog") |
129 self.parent.layer_tabs.EnableTab(cidx, False) | 138 self.parent.tabs.EnableTab(cidx, False) |
130 cidx = self.parent.get_tab_index("General") | 139 cidx = self.parent.get_tab_index("General") |
131 self.parent.layer_tabs.EnableTab(cidx, False) | 140 self.parent.tabs.EnableTab(cidx, False) |
132 else: | 141 else: |
133 cidx = self.parent.get_tab_index("Background") | 142 cidx = self.parent.get_tab_index("Background") |
134 if not self.parent.layer_tabs.GetEnabled(cidx): | 143 if not self.parent.tabs.GetEnabled(cidx): |
135 cidx = self.parent.get_tab_index("Miniatures") | 144 cidx = self.parent.get_tab_index("Miniatures") |
136 self.parent.layer_tabs.EnableTab(cidx, True) | 145 self.parent.tabs.EnableTab(cidx, True) |
137 cidx = self.parent.get_tab_index("Whiteboard") | 146 cidx = self.parent.get_tab_index("Whiteboard") |
138 self.parent.layer_tabs.EnableTab(cidx, True) | 147 self.parent.tabs.EnableTab(cidx, True) |
139 cidx = self.parent.get_tab_index("Background") | 148 cidx = self.parent.get_tab_index("Background") |
140 self.parent.layer_tabs.EnableTab(cidx, False) | 149 self.parent.tabs.EnableTab(cidx, False) |
141 cidx = self.parent.get_tab_index("Grid") | 150 cidx = self.parent.get_tab_index("Grid") |
142 self.parent.layer_tabs.EnableTab(cidx, False) | 151 self.parent.tabs.EnableTab(cidx, False) |
143 cidx = self.parent.get_tab_index("Fog") | 152 cidx = self.parent.get_tab_index("Fog") |
144 self.parent.layer_tabs.EnableTab(cidx, False) | 153 self.parent.tabs.EnableTab(cidx, False) |
145 cidx = self.parent.get_tab_index("General") | 154 cidx = self.parent.get_tab_index("General") |
146 self.parent.layer_tabs.EnableTab(cidx, False) | 155 self.parent.tabs.EnableTab(cidx, False) |
147 if self.session.my_role() == self.session.ROLE_GM: | 156 if self.session.my_role() == self.session.ROLE_GM: |
148 cidx = self.parent.get_tab_index("Background") | 157 cidx = self.parent.get_tab_index("Background") |
149 self.parent.layer_tabs.EnableTab(cidx, True) | 158 self.parent.tabs.EnableTab(cidx, True) |
150 cidx = self.parent.get_tab_index("Grid") | 159 cidx = self.parent.get_tab_index("Grid") |
151 self.parent.layer_tabs.EnableTab(cidx, True) | 160 self.parent.tabs.EnableTab(cidx, True) |
152 cidx = self.parent.get_tab_index("Fog") | 161 cidx = self.parent.get_tab_index("Fog") |
153 self.parent.layer_tabs.EnableTab(cidx, True) | 162 self.parent.tabs.EnableTab(cidx, True) |
154 cidx = self.parent.get_tab_index("General") | 163 cidx = self.parent.get_tab_index("General") |
155 self.parent.layer_tabs.EnableTab(cidx, True) | 164 self.parent.tabs.EnableTab(cidx, True) |
156 if not self.cacheSizeSet: | 165 if not self.cacheSizeSet: |
157 self.cacheSizeSet = True | 166 self.cacheSizeSet = True |
158 cacheSize = component.get('settings').get_setting("ImageCacheSize") | 167 cacheSize = component.get('settings').get_setting("ImageCacheSize") |
159 if len(cacheSize): self.cacheSize = int(cacheSize) | 168 if len(cacheSize): self.cacheSize = int(cacheSize) |
160 else: pass | 169 else: pass |
170 self.layers['bg'].bg_bmp = img | 179 self.layers['bg'].bg_bmp = img |
171 if image_type == "background": self.set_size([img.GetWidth(), img.GetHeight()]) | 180 if image_type == "background": self.set_size([img.GetWidth(), img.GetHeight()]) |
172 except: pass | 181 except: pass |
173 # Flag that we now need to refresh! | 182 # Flag that we now need to refresh! |
174 self.requireRefresh += 1 | 183 self.requireRefresh += 1 |
175 | |
176 """ Randomly purge an item from the cache, while this is lamo, it does | 184 """ Randomly purge an item from the cache, while this is lamo, it does |
177 keep the cache from growing without bounds, which is pretty important!""" | 185 keep the cache from growing without bounds, which is pretty important!""" |
178 if len(ImageHandler.Cache) >= self.cacheSize: | 186 if len(ImageHandler.Cache) >= self.cacheSize: |
179 ImageHandler.cleanCache() | 187 ImageHandler.cleanCache() |
180 else: | 188 else: |
189 self.lastRefreshTime = time.time() | 197 self.lastRefreshTime = time.time() |
190 self.Refresh(True) | 198 self.Refresh(True) |
191 else: self.lastRefreshValue = self.requireRefresh | 199 else: self.lastRefreshValue = self.requireRefresh |
192 | 200 |
193 def on_scroll(self, evt): | 201 def on_scroll(self, evt): |
202 print 'scrolling' | |
194 if self.drag: self.drag.Hide() | 203 if self.drag: self.drag.Hide() |
195 if component.get('settings').get_setting("AlwaysShowMapScale") == "1": self.printscale() | 204 if component.get('settings').get_setting("AlwaysShowMapScale") == "1": self.printscale() |
196 evt.Skip() | 205 evt.Skip() |
197 | 206 |
198 def on_char(self, evt): | 207 def on_char(self, evt): |
719 self.session = component.get('session') | 728 self.session = component.get('session') |
720 self.chat = component.get('chat') | 729 self.chat = component.get('chat') |
721 self.top_frame = component.get('frame') | 730 self.top_frame = component.get('frame') |
722 self.root_dir = os.getcwd() | 731 self.root_dir = os.getcwd() |
723 self.current_layer = 2 | 732 self.current_layer = 2 |
724 self.layer_tabs = orpgTabberWnd(self, style=FNB.FNB_NO_X_BUTTON|FNB.FNB_BOTTOM|FNB.FNB_NO_NAV_BUTTONS) | 733 self.tabs = orpgTabberWnd(self, style=FNB.FNB_NO_X_BUTTON|FNB.FNB_BOTTOM|FNB.FNB_NO_NAV_BUTTONS) |
725 self.layer_handlers = [] | 734 self.handlers = {} |
726 self.layer_handlers.append(background_handler(self.layer_tabs,-1,self.canvas)) | 735 self.handlers[0]=(background_handler(self.tabs,-1,self.canvas)) |
727 self.layer_tabs.AddPage(self.layer_handlers[0],"Background") | 736 self.tabs.AddPage(self.handlers[0],"Background") |
728 self.layer_handlers.append(grid_handler(self.layer_tabs,-1,self.canvas)) | 737 self.handlers[1]=(grid_handler(self.tabs,-1,self.canvas)) |
729 self.layer_tabs.AddPage(self.layer_handlers[1],"Grid") | 738 self.tabs.AddPage(self.handlers[1],"Grid") |
730 self.layer_handlers.append(miniatures_handler(self.layer_tabs,-1,self.canvas)) | 739 self.handlers[2]=(miniatures_handler(self.tabs,-1,self.canvas)) |
731 self.layer_tabs.AddPage(self.layer_handlers[2],"Miniatures", True) | 740 self.tabs.AddPage(self.handlers[2],"Miniatures", True) |
732 self.layer_handlers.append(whiteboard_handler(self.layer_tabs,-1,self.canvas)) | 741 self.handlers[3]=(whiteboard_handler(self.tabs,-1,self.canvas)) |
733 self.layer_tabs.AddPage(self.layer_handlers[3],"Whiteboard") | 742 self.tabs.AddPage(self.handlers[3],"Whiteboard") |
734 self.layer_handlers.append(fog_handler(self.layer_tabs,-1,self.canvas)) | 743 self.handlers[4]=(fog_handler(self.tabs,-1,self.canvas)) |
735 self.layer_tabs.AddPage(self.layer_handlers[4],"Fog") | 744 self.tabs.AddPage(self.handlers[4],"Fog") |
736 self.layer_handlers.append(map_handler(self.layer_tabs,-1,self.canvas)) | 745 self.handlers[5]=(map_handler(self.tabs,-1,self.canvas)) |
737 self.layer_tabs.AddPage(self.layer_handlers[5],"General") | 746 self.tabs.AddPage(self.handlers[5],"General") |
738 self.layer_tabs.SetSelection(2) | 747 self.tabs.SetSelection(2) |
739 self.sizer = wx.BoxSizer(wx.VERTICAL) | 748 self.sizer = wx.BoxSizer(wx.VERTICAL) |
740 self.sizer.Add(self.canvas, 1, wx.EXPAND) | 749 self.sizer.Add(self.canvas, 1, wx.EXPAND) |
741 self.sizer.Add(self.layer_tabs, 0, wx.EXPAND) | 750 self.sizer.Add(self.tabs, 0, wx.EXPAND) |
742 self.SetSizer(self.sizer) | 751 self.SetSizer(self.sizer) |
743 self.Bind(FNB.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.on_layer_change) | 752 self.Bind(FNB.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.on_layer_change) |
744 #self.Bind(wx.EVT_SIZE, self.on_size) | 753 #self.Bind(wx.EVT_SIZE, self.on_size) |
745 self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave) | 754 self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave) |
746 self.load_default() | 755 self.load_default() |
756 | |
757 ## Components for making Map Based plugins that create new tabs. | |
758 component.add('map_tabs', self.tabs) | |
759 component.add('map_layers', self.handlers) | |
760 component.add('map_wnd', self) | |
747 | 761 |
748 def OnLeave(self, evt): | 762 def OnLeave(self, evt): |
749 if "__WXGTK__" in wx.PlatformInfo: wx.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) | 763 if "__WXGTK__" in wx.PlatformInfo: wx.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) |
750 | 764 |
751 def load_default(self): | 765 def load_default(self): |
796 self.session.update_role("GM") | 810 self.session.update_role("GM") |
797 d.Destroy() | 811 d.Destroy() |
798 os.chdir(self.root_dir) | 812 os.chdir(self.root_dir) |
799 | 813 |
800 def get_current_layer_handler(self): | 814 def get_current_layer_handler(self): |
801 return self.layer_handlers[self.current_layer] | 815 return self.handlers[self.current_layer] |
802 | 816 |
803 def get_tab_index(self, layer): | 817 def get_tab_index(self, layer): |
804 """Return the index of a chatpanel in the wxNotebook.""" | 818 """Return the index of a chatpanel in the wxNotebook.""" |
805 for i in xrange(self.layer_tabs.GetPageCount()): | 819 for i in xrange(self.tabs.GetPageCount()): |
806 if (self.layer_tabs.GetPageText(i) == layer): | 820 if (self.tabs.GetPageText(i) == layer): |
807 return i | 821 return i |
808 return 0 | 822 return 0 |
809 | 823 |
810 def on_layer_change(self, evt): | 824 def on_layer_change(self, evt): |
811 layer = self.layer_tabs.GetPage(evt.GetSelection()) | 825 layer = self.tabs.GetPage(evt.GetSelection()) |
812 for i in xrange(0, len(self.layer_handlers)): | 826 for i in xrange(0, len(self.handlers)): |
813 if layer == self.layer_handlers[i]: self.current_layer = i | 827 if layer == self.handlers[i]: self.current_layer = i |
814 if self.current_layer == 0: | 828 if self.current_layer == 0: |
815 bg = self.layer_handlers[0] | 829 bg = self.handlers[0] |
816 if (self.session.my_role() != self.session.ROLE_GM): bg.url_path.Show(False) | 830 if (self.session.my_role() != self.session.ROLE_GM): bg.url_path.Show(False) |
817 else: bg.url_path.Show(True) | 831 else: bg.url_path.Show(True) |
818 self.canvas.Refresh(False) | 832 self.canvas.Refresh(False) |
819 evt.Skip() | 833 evt.Skip() |
820 | 834 |
821 def on_left_down(self, evt): | 835 def on_left_down(self, evt): |
822 self.layer_handlers[self.current_layer].on_left_down(evt) | 836 self.handlers[self.current_layer].on_left_down(evt) |
823 | 837 |
824 #double click handler added by Snowdog 5/03 | 838 #double click handler added by Snowdog 5/03 |
825 def on_left_dclick(self, evt): | 839 def on_left_dclick(self, evt): |
826 self.layer_handlers[self.current_layer].on_left_dclick(evt) | 840 self.handlers[self.current_layer].on_left_dclick(evt) |
827 | 841 |
828 def on_right_down(self, evt): | 842 def on_right_down(self, evt): |
829 self.layer_handlers[self.current_layer].on_right_down(evt) | 843 self.handlers[self.current_layer].on_right_down(evt) |
830 | 844 |
831 def on_left_up(self, evt): | 845 def on_left_up(self, evt): |
832 self.layer_handlers[self.current_layer].on_left_up(evt) | 846 self.handlers[self.current_layer].on_left_up(evt) |
833 | 847 |
834 def on_motion(self, evt): | 848 def on_motion(self, evt): |
835 self.layer_handlers[self.current_layer].on_motion(evt) | 849 self.handlers[self.current_layer].on_motion(evt) |
836 | 850 |
837 def MapBar(self, id, data): | 851 def MapBar(self, id, data): |
838 self.canvas.MAP_MODE = data | 852 self.canvas.MAP_MODE = data |
839 if id == 1: self.canvas.MAP_MODE = data | 853 if id == 1: self.canvas.MAP_MODE = data |
840 | 854 |
847 ImageHandler.flushCache() | 861 ImageHandler.flushCache() |
848 self.canvas.pre_destory_cleanup() | 862 self.canvas.pre_destory_cleanup() |
849 except: pass | 863 except: pass |
850 | 864 |
851 def update_tools(self): | 865 def update_tools(self): |
852 for h in self.layer_handlers: | 866 for h in self.handlers: |
853 h.update_info() | 867 self.handlers[h].update_info() |
854 | 868 |
855 def on_hk_map_layer(self, evt): | 869 def on_hk_map_layer(self, evt): |
856 id = self.top_frame.mainmenu.GetHelpString(evt.GetId()) | 870 id = self.top_frame.mainmenu.GetHelpString(evt.GetId()) |
857 if id == "Background Layer": self.current_layer = self.get_tab_index("Background") | 871 if id == "Background Layer": self.current_layer = self.get_tab_index("Background") |
858 if id == "Grid Layer": self.current_layer = self.get_tab_index("Grid") | 872 if id == "Grid Layer": self.current_layer = self.get_tab_index("Grid") |
859 if id == "Miniature Layer": self.current_layer = self.get_tab_index("Miniatures") | 873 if id == "Miniature Layer": self.current_layer = self.get_tab_index("Miniatures") |
860 elif id == "Whiteboard Layer": self.current_layer = self.get_tab_index("Whiteboard") | 874 elif id == "Whiteboard Layer": self.current_layer = self.get_tab_index("Whiteboard") |
861 elif id == "Fog Layer": self.current_layer = self.get_tab_index("Fog") | 875 elif id == "Fog Layer": self.current_layer = self.get_tab_index("Fog") |
862 elif id == "General Properties": self.current_layer = self.get_tab_index("General") | 876 elif id == "General Properties": self.current_layer = self.get_tab_index("General") |
863 self.layer_tabs.SetSelection(self.current_layer) | 877 self.tabs.SetSelection(self.current_layer) |
864 | 878 |
865 def on_flush_cache(self, evt): | 879 def on_flush_cache(self, evt): |
866 ImageHandler.flushCache() | 880 ImageHandler.flushCache() |
867 | 881 |
868 def build_menu(self): | 882 def build_menu(self): |