int sectorx = ((e.getX() / MapEditor.tileWidth) + getMapX()) / sectorWidth; int sectory = ((e.getY() / MapEditor.tileHeight) + getMapY()) / sectorHeight;  setSector(sectorx, sectory); tilesetList.setEnabled(knowssector); paletteBox.setEnabled(knowssector); musicBox.setEnabled(knowssector); editBox.setEnabled(knowssector); if (knowssector) { int oldTset = -1; if (tilesetList.isEnabled()) oldTset = tilesetList.getSelectedIndex(); EbMap.Sector sector = EbMap.getSectorData(sectorx, sectory); tilesetList.removeActionListener(this); tilesetList.setSelectedIndex(sector.getTileset()); tilesetList.addActionListener(this); paletteBox.removeActionListener(this); if (oldTset != sector.getTileset()) { paletteBox.removeAllItems(); TileEditor.Tileset tileset = TileEditor.tilesets[EbMap.getDrawTileset(sector.getTileset())]; for (int i = 0; i < tileset.getPaletteCount(); i++) if (tileset.getPalette(i).mtileset == sector.getTileset()) paletteBox.addItem(Integer.toString(tileset.getPalette(i).mpalette)); } paletteBox.setSelectedIndex(sector.getPalette()); paletteBox.addActionListener(this); musicBox.removeActionListener(this); musicBox.setSelectedIndex(sector.getMusic()); musicBox.addActionListener(this);  if (getModeProps()[2] == 1) { boolean isSame = editBox.setTsetPal( EbMap.getDrawTileset(sector.getTileset()), TileEditor.tilesets[EbMap.getDrawTileset( sector.getTileset())].getPaletteNum(sector.getTileset(), sector.getPalette())); if (! isSame) editBox.repaint(); } } else { tilesetList.removeActionListener(this); tilesetList.setSelectedIndex(-1); paletteBox.removeActionListener(this); paletteBox.removeAllItems(); paletteBox.setSelectedIndex(-1); musicBox.removeActionListener(this); musicBox.setSelectedIndex(-1); }  repaint(); editBox.repaint();
int sectorx = ((e.getX() / MapEditor.tileWidth) + getMapX()) / sectorWidth; int sectory = ((e.getY() / MapEditor.tileHeight) + getMapY()) / sectorHeight; setSector(sectorx, sectory);  updateSectorComponents();
        public void mouseClicked(MouseEvent e)        {        	if (e.getButton() == 1)        	{        		if (editBox.knowsTsetPal()         				&& (getModeProps()[2] == 1))        		{            		int mapx = e.getX() / MapEditor.tileWidth;            		int mapy = e.getY() / MapEditor.tileHeight;            		if (e.getModifiers() == 17)            		{            			int selected = EbMap.getTile(hm.rom,            					mapx + getMapX(),								mapy + getMapY());            			editBox.setSelected(selected);            			if (! editBox.isSelectedVisible())            				editBox.scrollToSelected();            			editBox.remoteRepaint();            		}            		else if (editBox.isSelected())            		{                		int tile = editBox.getSelected();                		int localtset = tile / 0x100;                		tile -= localtset * 0x100;                		                		EbMap.changeTile(                				getMapX() + mapx,    							getMapY() + mapy, (byte) (tile & 0xff));                		changeMapArray(mapx, mapy, tile);                		EbMap.setLocalTileset(hm.rom,                				getMapX() + mapx,    							getMapY() + mapy,                				localtset);                		reloadMap();                		repaint();            		}        		}        		else if ((getMode() == 3) || (getMode() == 4))        		{        			getSeekSource().returnSeek(        					e.getX(), e.getY(),        					getMapX(), getMapY());        			changeMode(getOldMode());        			repaint();        		}        	}            else if (e.getButton() == 3)            {            	if ((getModeProps()[3] >= 2)            			&& (movingData[0] == -1))            	{            		JPopupMenu popup = new JPopupMenu();                	int spNum = getSpriteNum(e.getX(), e.getY());                	if (spNum != -1)                	{                		int[] spLoc = getCoords(e.getX(), e.getY());                		PopupListener popupListener =                			new PopupListener(this, spLoc[0], spLoc[1],                					spLoc[2], spLoc[3], spNum, copyTpt);                		popup.add(EbHackModule.createJMenuItem(                        		"Add sprite", 'a', null, 								PopupListener.ADD_SPRITE, 								popupListener));                		popup.add(EbHackModule.createJMenuItem(                        		"Delete sprite", 'd', null, 								PopupListener.DEL_SPRITE, 								popupListener));                		popup.add(EbHackModule.createJMenuItem(                        		"Cut sprite", 'u', null, 								PopupListener.CUT_SPRITE, 								popupListener));                		popup.add(EbHackModule.createJMenuItem(                        		"Copy sprite", 'c', null, 								PopupListener.COPY_SPRITE, 								popupListener));                		if (copyTpt >= 0)                			popup.add(EbHackModule.createJMenuItem(                            		"Paste sprite", 'p', null,     								PopupListener.PASTE_SPRITE,     								popupListener));                		String tpt = addZeros(Integer.toHexString(                				EbMap.getSpriteTpt(                				spLoc[0], spLoc[1], spNum)),4);                		popup.add(EbHackModule.createJMenuItem(                				"Switch TPT entry (" + tpt + ")",								's', null,								PopupListener.CHANGE_TPT, 								popupListener));                		popup.add(EbHackModule.createJMenuItem(                				"Edit TPT entry (" + tpt + ")",								'e', null,								PopupListener.EDIT_TPT, 								popupListener));                	}                	else                	{                		int[] spLoc = getCoords(e.getX(), e.getY());                		PopupListener popupListener =                			new PopupListener(this, spLoc[0], spLoc[1],                					spLoc[2], spLoc[3], copyTpt);                		popup.add(EbHackModule.createJMenuItem(                        		"Add sprite", 'a', null, 								PopupListener.ADD_SPRITE, 								popupListener));                		if (copyTpt >= 0)                			popup.add(EbHackModule.createJMenuItem(                            		"Paste sprite", 'p', null,     								PopupListener.PASTE_SPRITE,     								popupListener));                	}                    popup.show(this, e.getX(), e.getY());            	}            	else if ((getModeProps()[4] == 2)            				&& (movingData[0] == -1))            	{               		JPopupMenu popup = new JPopupMenu();                	int num = getDoorNum(e.getX(), e.getY());                	int[] doorCoords =            			getCoords(e.getX(), e.getY());                	if (num != -1)                	{                		PopupListener popupListener =                			new PopupListener(this, doorCoords[0], doorCoords[1],                					doorCoords[2], doorCoords[3], num, copyTpt);                		popup.add(EbHackModule.createJMenuItem(                        		"Add door", 'a', null, 								PopupListener.ADD_DOOR, 								popupListener));                		popup.add(EbHackModule.createJMenuItem(                        		"Delete door", 'd', null, 								PopupListener.DEL_DOOR, 								popupListener));                		EbMap.DoorLocation doorLocation = EbMap.getDoorLocation(                				doorCoords[0], doorCoords[1], num);                		String dest;                		if (EbMap.getDoorDestType(doorLocation.getType()) >= 0)                			dest = "Destination #" + Integer.toString(doorLocation.getDestIndex());                		else                			dest = "No Destination";                   		popup.add(EbHackModule.createJMenuItem(                				"Edit entry (" + dest + ")",								's', null,								PopupListener.EDIT_DEST, 								popupListener));                		if (EbMap.getDoorDestType(doorLocation.getType()) == 0)                			popup.add(EbHackModule.createJMenuItem(                    				"Jump to destination", 'j', null,    								PopupListener.JUMP_DEST,     								popupListener));                	}                	else                	{                		PopupListener popupListener =                			new PopupListener(this, doorCoords[0], doorCoords[1],                					doorCoords[2], doorCoords[3], copyTpt);                		popup.add(EbHackModule.createJMenuItem(                        		"Add door", 'a', null, 								PopupListener.ADD_DOOR, 								popupListener));                	}                    popup.show(this, e.getX(), e.getY());            	}            	else if (getModeProps()[0] == 2)            	{                    int sectorx = ((e.getX() / MapEditor.tileWidth) + getMapX()) / sectorWidth;                    int sectory = ((e.getY() / MapEditor.tileHeight) + getMapY()) / sectorHeight;                                        setSector(sectorx, sectory);                    tilesetList.setEnabled(knowssector);                    paletteBox.setEnabled(knowssector);                    musicBox.setEnabled(knowssector);                    editBox.setEnabled(knowssector);                    if (knowssector)                    {                        int oldTset = -1;                        if (tilesetList.isEnabled())                        	oldTset = tilesetList.getSelectedIndex();                        EbMap.Sector sector = EbMap.getSectorData(sectorx, sectory);                        tilesetList.removeActionListener(this);                        tilesetList.setSelectedIndex(sector.getTileset());                        tilesetList.addActionListener(this);                        paletteBox.removeActionListener(this);                        if (oldTset != sector.getTileset())                        {                        	paletteBox.removeAllItems();                        	TileEditor.Tileset tileset = TileEditor.tilesets[EbMap.getDrawTileset(sector.getTileset())];                        	for (int i = 0; i < tileset.getPaletteCount(); i++)                            	if (tileset.getPalette(i).mtileset == sector.getTileset())                            		paletteBox.addItem(Integer.toString(tileset.getPalette(i).mpalette));                        }                        paletteBox.setSelectedIndex(sector.getPalette());                        paletteBox.addActionListener(this);                        musicBox.removeActionListener(this);                        musicBox.setSelectedIndex(sector.getMusic());                        musicBox.addActionListener(this);                                                if (getModeProps()[2] == 1)                        {                        	boolean isSame = editBox.setTsetPal(                        			EbMap.getDrawTileset(sector.getTileset()),                                    TileEditor.tilesets[EbMap.getDrawTileset(                                    		sector.getTileset())].getPaletteNum(sector.getTileset(),                                    				sector.getPalette()));                        	if (! isSame)                        		editBox.repaint();                        }                    }                    else                    {                    	tilesetList.removeActionListener(this);                        tilesetList.setSelectedIndex(-1);                        paletteBox.removeActionListener(this);                        paletteBox.removeAllItems();                        paletteBox.setSelectedIndex(-1);                        musicBox.removeActionListener(this);                        musicBox.setSelectedIndex(-1);                    }                                        repaint();                    editBox.repaint();            	}            }        }