📄 interiormapdata.java
字号:
/*
* Light And Shadow. A Persistent Universe based on Robert Jordan's Wheel of Time Books.
* Copyright (C) 2001-2002 WOTLAS Team
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package wotlas.client;
import wotlas.client.screen.JClientScreen;
import wotlas.common.message.description.*;
import wotlas.common.message.movement.*;
import wotlas.common.universe.*;
import wotlas.common.*;
import wotlas.libs.graphics2D.*;
import wotlas.libs.graphics2D.drawable.*;
import wotlas.libs.graphics2D.filter.BrightnessFilter;
import wotlas.libs.pathfinding.AStarDouble;
import wotlas.libs.sound.SoundLibrary;
import wotlas.utils.Debug;
import wotlas.utils.ScreenPoint;
import wotlas.utils.ScreenRectangle;
import java.awt.image.BufferedImage;
import java.awt.Rectangle;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.util.Hashtable;
public class InteriorMapData implements MapData {
/*------------------------------------------------------------------------------------*/
/** True if we show debug informations
*/
public static boolean SHOW_DEBUG = false;
/** if true, the player can change its MapData
* otherwise, the server didn't send a message to do so => player stay where he is
*/
public boolean canChangeMap;
/** Our default dataManager
*/
private DataManager dataManager;
/** tells if the player could be moving to another room
*/
private boolean couldBeMovingToAnotherRoom = false;
/** tells if the player is going to another map
*/
private boolean isNotMovingToAnotherMap = true;
/** current RoomLink considered for intersection
*/
private RoomLink latestRoomLink;
/** Display current location name
*/
private MultiLineText mltLocationName;
/** Associated InteriorMap of this InteriorMapData.
*/
private InteriorMap imap;
/** true if we must reset the room
*/
private boolean resetRoom = false;
/** previous location
*/
private int currentInteriorMapID = -1;
private int currentRoomID = -1;
/*------------------------------------------------------------------------------------*/
/** Set to true to show debug information
*/
public void showDebug(boolean value) {
SHOW_DEBUG = value;
}
/*------------------------------------------------------------------------------------*/
/** To set isNotMovingToAnotherMap
*/
public void setIsNotMovingToAnotherMap(boolean value) {
isNotMovingToAnotherMap = value;
}
/*------------------------------------------------------------------------------------*/
/** To init the display<br>
* - load background and mask images<br>
* - init the AStar algorithm
* - init the Graphics Director
* - show the other images (shadows, buildings, towns...)
*/
public void initDisplay(PlayerImpl myPlayer, DataManager dataManager ) {
this.dataManager = dataManager;
if (DataManager.SHOW_DEBUG)
System.out.println("-- initDisplay in InteriorMapData --");
ImageIdentifier backgroundImageID = null; // background image identifier
Drawable background = null; // background image
GraphicsDirector gDirector = dataManager.getGraphicsDirector();
// 0 - Some inits...
myPlayer.init();
// 1 - We load the InteriorMap
WotlasLocation location = myPlayer.getLocation();
currentInteriorMapID = location.getInteriorMapID();
currentRoomID = location.getRoomID();
imap = dataManager.getWorldManager().getInteriorMap(location);
if (SHOW_DEBUG) {
System.out.println("InteriorMap");
System.out.println("\tfullName = " + imap.getFullName());
System.out.println("\tshortName = " + imap.getShortName());
}
// 2 - We load the room ...
// ... and set the player's position (if his position is incorrect)
Room room = dataManager.getWorldManager().getRoom(location);
if (SHOW_DEBUG) {
System.out.println("Room");
System.out.println("\tfullName = " + room.getFullName());
System.out.println("\tshortName = " + room.getShortName());
}
dataManager.getClientScreen().getChatPanel().changeMainJChatRoom(room.getShortName());
if (SHOW_DEBUG)
System.out.println("Adding a new player : " + myPlayer + "to dataManager");
dataManager.addPlayer(myPlayer);
if (myPlayer.getX() == -1) {
ScreenPoint insertionPoint = room.getInsertionPoint();
if (SHOW_DEBUG)
System.out.println("\tinsertionPoint = " + insertionPoint);
myPlayer.setX(insertionPoint.x);
myPlayer.setY(insertionPoint.y);
myPlayer.setPosition(insertionPoint);
}
// 3 - We load the image
backgroundImageID = imap.getInteriorMapImage();
if (SHOW_DEBUG)
System.out.println("\tbackgroundImageID = " + backgroundImageID);
background = (Drawable) new MultiRegionImage( myPlayer.getDrawable(), // our reference for image loading
500, // perception radius
imap.getImageRegionWidth(), // grid deltax
imap.getImageRegionHeight(), // grid deltay
imap.getImageWidth(), // image's total width
imap.getImageHeight(), // image's total height
imap.getInteriorMapImage() // base image identifier
);
// 4 - We load the mask
BufferedImage bufIm = null;
try {
ImageIdentifier mapMaskID = gDirector.getImageLibrary().getImageIdentifier( backgroundImageID, "mask" );
if(mapMaskID!=null) {
String maskFile = gDirector.getImageLibrary().getImageFile( mapMaskID );
if(maskFile!=null)
bufIm = gDirector.getImageLibrary().loadBufferedImage( maskFile, BufferedImage.TYPE_INT_ARGB );
}
if(bufIm==null) {
Debug.signal( Debug.CRITICAL, this, "Mask not found" );
Debug.exit();
}
}
catch( ImageLibraryException e ) {
Debug.signal( Debug.CRITICAL, this, "Image Library Corrupted: "+e );
Debug.exit();
}
// 4.1 - We load the mask brightness
BufferedImage bufIm2 = null;
try {
ImageIdentifier brightnessMaskID = gDirector.getImageLibrary().getImageIdentifier( backgroundImageID, "brightness" );
if(brightnessMaskID!=null) {
String brightnessMaskFile = gDirector.getImageLibrary().getImageFile( brightnessMaskID );
if(brightnessMaskFile!=null)
bufIm2 = gDirector.getImageLibrary().loadBufferedImage( brightnessMaskFile, BufferedImage.TYPE_INT_ARGB );
}
if(bufIm2==null) {
Debug.signal( Debug.WARNING, this, "Brightness mask not found" );
BrightnessFilter.setBrightnessMask(null, 10);
} else {
BrightnessFilter.setBrightnessMask(GrayMask.create( bufIm2 ), 10);
Debug.signal( Debug.NOTICE, this, "Brightness mask found..." );
}
}
catch( ImageLibraryException e ) {
Debug.signal( Debug.CRITICAL, this, "Brightness mask not found: "+e );
BrightnessFilter.setBrightnessMask(null, 10);
}
// 5 - We initialize the AStar algo
myPlayer.getMovementComposer().setMovementMask( BinaryMask.create( bufIm ), 5, 4 );
myPlayer.getMovementComposer().resetMovement();
bufIm.flush(); // free image resource
// 6 - We init the GraphicsDirector
gDirector.init( background, // background drawable
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -