📄 xmain.java
字号:
while (n > 0) {
drawObject(g, object, n % 10, 0, x, y);
n = n / 10;
x -= w;
}
}
// ************************************
// data
// ************************************
private static final String FILE_DATA = "d.x";
private static final String FILE_RESOURCE = "r.x";
private byte[] bufferData;
private byte[] bufferResource;
private short[][][] dataObject;
private short[][][] dataFrame;
private short[][] dataClip;
private Image[] dataImage;
private int[] dataImageOffset;
private boolean[] dataImageActive;
private int[] dataSceneOffset;
private int[] dataValueOffset;
private int[] dataTextOffset;
// ************************************
// data
// ************************************
protected final void dataLoad() {
DataInputStream input = null;
//showInfo("dataLoad begin freeMemory2:"+Runtime.getRuntime().freeMemory());
try {
input = new DataInputStream(midlet.getClass().getResourceAsStream(
FILE_DATA));
bufferData = new byte[input.readInt()];
input.read(bufferData);
input.close();
input = new DataInputStream(midlet.getClass().getResourceAsStream(
FILE_RESOURCE));
bufferResource = new byte[input.readInt()];
input.read(bufferResource);
input.close();
input = new DataInputStream(new ByteArrayInputStream(bufferData));
// object
int nObject = input.readShort();
//showInfo("Object:"+nObject);
dataObject = new short[nObject][][];
for (int i = 0; i < nObject; i++) {
int nMotion = input.readShort();
dataObject[i] = new short[nMotion][];
for (int j = 0; j < nMotion; j++) {
int nFrame = input.readShort();
dataObject[i][j] = new short[nFrame];
for (int k = 0; k < nFrame; k++) {
dataObject[i][j][k] = input.readShort();
}
}
}
// frame
int nFrame = input.readShort();
//showInfo("nFrame:"+nFrame);
dataFrame = new short[nFrame][][];
for (int i = 0; i < nFrame; i++) {
int nPiece = input.readShort();
dataFrame[i] = new short[nPiece][3];
for (int j = 0; j < nPiece; j++) {
dataFrame[i][j][0] = input.readShort();
dataFrame[i][j][1] = input.readShort();
dataFrame[i][j][2] = input.readShort();
}
}
// clip
int nClip = input.readShort();
//showInfo("nClip:"+nClip);
dataClip = new short[nClip][5];
for (int i = 0; i < nClip; i++) {
dataClip[i][0] = input.readShort();
dataClip[i][1] = input.readShort();
dataClip[i][2] = input.readShort();
dataClip[i][3] = input.readShort();
dataClip[i][4] = input.readShort();
}
input.close();
input = new DataInputStream(
new ByteArrayInputStream(bufferResource));
// image
int nImage = input.readShort();
dataImage = new Image[nImage];
dataImageOffset = new int[nImage];
dataImageActive = new boolean[nImage];
for (int i = 0; i < nImage; i++) {
dataImage[i] = null;
dataImageOffset[i] = input.readInt();
dataImageActive[i] = false;
}
// scene
int nScene = input.readShort();
dataSceneOffset = new int[nScene];
for (int i = 0; i < nScene; i++) {
dataSceneOffset[i] = input.readInt();
}
// value
int nValue = input.readShort();
dataValueOffset = new int[nValue];
for (int i = 0; i < nValue; i++) {
dataValueOffset[i] = input.readInt();
}
// text
int nText = input.readShort();
dataTextOffset = new int[nText];
for (int i = 0; i < nText; i++) {
dataTextOffset[i] = input.readInt();
}
} catch (IOException e) {
showError(e);
} finally {
try {
if (input != null) {
input.close();
}
} catch (Exception e) {
showError(e);
}
}
System.gc();
//showInfo("dataLoad end freeMemory2:"+Runtime.getRuntime().freeMemory());
}
protected final void loadObject(int object) {
for (int i = 0; i < dataObject[object].length; i++) {
for (int j = 0; j < dataObject[object][i].length; j++) {
int frame = dataObject[object][i][j];
for (int k = 0; k < dataFrame[frame].length; k++) {
int image = dataClip[dataFrame[frame][k][0]][0];
dataImageActive[image] = true;
}
}
}
}
protected final void loadImage() {
if (objectArrow != -1) {
loadObject(objectArrow);
}
if (objectButton != -1) {
loadObject(objectButton);
}
for (int i = 0; i < dataImage.length; i++) {
if (!dataImageActive[i]) {
dataImage[i] = null;
}
}
System.gc();
DataInputStream input = null;
try {
input = new DataInputStream(
new ByteArrayInputStream(bufferResource));
input.skipBytes(dataImageOffset[0]);
//showInfo("dataIamge length:"+dataImage.length);
for (int i = 0; i < dataImage.length; i++) {
if ((dataImage[i] == null) && (dataImageActive[i])) {
int size = input.readInt();
byte[] temp = new byte[size];
input.read(temp);
dataImage[i] = Image.createImage(temp, 0, size);
} else if (i < dataImage.length - 1) {
int delta = dataImageOffset[i + 1] - dataImageOffset[i];
input.skipBytes(delta);
}
}
} catch (IOException e) {
showError(e);
} finally {
try {
if (input != null) {
input.close();
}
} catch (Exception e) {
showError(e);
}
}
}
protected final void unloadImage() {
for (int i = 0; i < dataImageActive.length; i++) {
dataImageActive[i] = false;
}
}
protected final void drawObject(Graphics g, int object, int motion,
int frame, int x, int y) {
int length = dataObject[object][motion].length;
int temp = dataObject[object][motion][frame % length];
for (int i = 0; i < dataFrame[temp].length; i++) {
int clip = dataFrame[temp][i][0];
int posX = dataFrame[temp][i][1] + x;
int posY = dataFrame[temp][i][2] + y;
int image = dataClip[clip][0];
int clipX = dataClip[clip][1];
int clipY = dataClip[clip][2];
int clipW = dataClip[clip][3];
int clipH = dataClip[clip][4];
drawClip(g, dataImage[image], posX, posY, clipX, clipY, clipW,
clipH);
}
}
protected final short[][][] loadScene(int scene) {
short[][][] result = null;
DataInputStream input = null;
try {
input = new DataInputStream(
new ByteArrayInputStream(bufferResource));
input.skipBytes(dataSceneOffset[scene]);
int w = input.readShort();
int h = input.readShort();
result = new short[w][h][2];
for (int i = 0; i < w; i++) {
for (int j = 0; j < h; j++) {
result[i][j][0] = input.readShort();
result[i][j][1] = input.readShort();
}
}
} catch (IOException e) {
showError(e);
} finally {
try {
if (input != null) {
input.close();
}
} catch (Exception e) {
showError(e);
}
}
return result;
}
protected final short[][] loadValue(int value) {
short[][] result = null;
DataInputStream input = null;
try {
input = new DataInputStream(
new ByteArrayInputStream(bufferResource));
input.skipBytes(dataValueOffset[value]);
int rol = input.readShort();
int col = input.readShort();
result = new short[rol][col];
for (int i = 0; i < rol; i++) {
for (int j = 0; j < col; j++) {
result[i][j] = input.readShort();
}
}
} catch (IOException e) {
showError(e);
} finally {
try {
if (input != null) {
input.close();
}
} catch (Exception e) {
showError(e);
}
}
return result;
}
protected final String[] loadText(int text) {
String[] result = null;
DataInputStream input = null;
try {
input = new DataInputStream(
new ByteArrayInputStream(bufferResource));
input.skipBytes(dataTextOffset[text]);
int rol = input.readShort();
result = new String[rol];
for (int i = 0; i < rol; i++) {
result[i] = input.readUTF();
}
} catch (IOException e) {
showError(e);
} finally {
try {
if (input != null) {
input.close();
}
} catch (Exception e) {
showError(e);
}
}
return result;
}
// ************************************
// text
// ************************************
private String[] text;
private int textX;
private int textY;
private int textW;
private int textH;
private int textTop;
private int textColor;
protected final void createText(String text, int x, int y, int w, int h,
int color) {
textX = x;
textY = y;
textW = w;
textH = h;
textTop = 0;
textColor = color;
this.text = breakString(text, w);
}
protected final void textUp() {
if (textTop > 0) {
textTop--;
}
}
protected final void textDown() {
if (textTop < text.length - textH / fontHeight) {
textTop++;
}
}
protected final void drawText(Graphics g) {
int n = textH / fontHeight;
if (n > text.length) {
n = text.length;
}
int space = (textH - fontHeight * n) / n + 1;
if (space > 3) {
space = 3;
}
int start = text.length - n;
if (start > textTop) {
start = textTop;
}
g.setColor(textColor);
int y = textY + (textH - fontHeight * n - space * (n + 1)) / 2 + space;
for (int i = 0; i < n; i++) {
g.drawString(text[start + i], textX, y, TOP_LEFT);
y += fontHeight + space;
}
if (objectArrow >= 0) {
if (start > 0) {
drawObject(g, objectArrow, 0, counter, textX + textW / 2, textY);
}
if (start < text.length - n) {
drawObject(g, objectArrow, 1, counter, textX + textW / 2, textY
+ textH);
}
}
}
protected final String[] breakString(String s, int w) {
Vector temp = new Vector();
int beginIndex = 0;
int endIndex = 0;
while (endIndex < s.length()) {
beginIndex = endIndex;
while (s.charAt(beginIndex) == ' ') {
beginIndex++;
if (s.charAt(beginIndex) == '/') {
beginIndex++;
}
}
endIndex = breakIndex(s, beginIndex, w);
temp.addElement(s.substring(beginIndex, endIndex));
if ((endIndex < s.length()) && (s.charAt(endIndex) == '/')) {
endIndex++;
}
}
String[] result = new String[temp.size()];
for (int i = 0; i < temp.size(); i++) {
result[i] = (String) (temp.elementAt(i));
}
return result;
}
private int breakIndex(String s, int beginIndex, int w) {
int result = beginIndex;
int nextLine = s.indexOf('/', beginIndex);
result += w / font.stringWidth("@LANGUAGE_CHARACTER@") + 1;
while ((result <= s.length())
&& (font.substringWidth(s, beginIndex, result - beginIndex) < w)) {
result++;
}
result--;
if ((nextLine != -1) && (nextLine < result)) {
result = nextLine;
} else if (s.length() < result) {
result = s.length();
}
return result;
}
// ************************************
// pane
// ************************************
protected int paneOffsetX;
protected int paneOffsetY;
private int paneX;
private int paneY;
private int paneW;
private int paneH;
private int paneContentW;
private int paneContentH;
protected final void createPane(int x, int y, int w, int h, int contentW,
int contentH) {
paneX = x;
paneY = y;
paneW = w;
paneH = h;
paneContentW = contentW;
paneContentH = contentH;
paneOffsetX = paneX;
paneOffsetY = paneY;
if (paneW > paneContentW) {
paneOffsetX += (paneW - paneContentW) / 2;
}
if (paneH > paneContentH) {
paneOffsetY += (paneH - paneContentH) / 2;
}
}
protected final void paneMoveTo(int x, int y) {
if (paneW < paneContentW) {
int temp = paneContentW - paneW;
if (x > temp) {
x = temp;
}
if (x < 0) {
x = 0;
}
paneOffsetX = paneX - x;
}
if (paneH < paneContentH) {
int temp = paneContentH - paneH;
if (y > temp) {
y = temp;
}
if (y < 0) {
y = 0;
}
paneOffsetY = paneY - y;
}
}
protected final void paneMove(int x, int y) {
x += paneX - paneOffsetX;
y += paneY - paneOffsetY;
paneMoveTo(x, y);
}
protected final void paneCenter(int x, int y) {
x -= paneW / 2;
y -= paneH / 2;
paneMoveTo(x, y);
}
protected final void paneDraw(Graphics g) {
g.setClip(paneX, paneY, paneW, paneH);
if ((paneW > paneContentW) || (paneH > paneContentH)) {
g.setColor(0x000000);
g.fillRect(paneX, paneY, paneW, paneH);
}
}
// ************************************
// record
// ************************************
private byte[][] recordData;
protected byte[][] recordInitialData() {
return null;
}
protected final void recordLoad(byte[][] data, int index) {
RecordStore record = null;
try {
record = RecordStore.openRecordStore("x", false);
for (int i = 0; i < data.length; i++) {
data[i] = record.getRecord(index + i + 1);
}
} catch (RecordStoreNotFoundException e) {
for (int i = 0; i < data.length; i++) {
data[i] = recordData[index + i];
}
recordInitialize();
} catch (RecordStoreException e) {
showError(e);
} finally {
try {
if (record != null) {
record.closeRecordStore();
}
} catch (Exception e) {
showError(e);
}
}
}
protected final void recordSave(byte[][] data, int index) {
RecordStore record = null;
try {
record = RecordStore.openRecordStore("x", false);
for (int i = 0; i < data.length; i++) {
record.setRecord(index + i + 1, data[i], 0, data[i].length);
}
} catch (RecordStoreNotFoundException e) {
for (int i = 0; i < data.length; i++) {
recordData[index + i] = data[i];
}
recordInitialize();
} catch (RecordStoreException e) {
showError(e);
} finally {
try {
if (record != null) {
record.closeRecordStore();
}
} catch (Exception e) {
showError(e);
}
}
}
private void recordInitialize() {
RecordStore record = null;
try {
record = RecordStore.openRecordStore("x", true);
for (int i = 0; i < recordData.length; i++) {
record.addRecord(recordData[i], 0, recordData[i].length);
}
} catch (RecordStoreException e) {
showError(e);
} finally {
try {
if (record != null) {
record.closeRecordStore();
}
} catch (Exception e) {
showError(e);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -