📄 xmain.java
字号:
}
}
protected final void loadImage() {
if (objectArrow != -1) {
loadObject(objectArrow);
}
if (objectButton != -1) {
loadObject(objectButton);
}
#if(${ant.handset_memory}!="memory_l")
for (int i = 0; i < dataImage.length; i++) {
if (!dataImageActive[i]) {
dataImage[i] = null;
}
}
System.gc();
#end
DataInputStream input = null;
try {
#if(${ant.handset_memory}=="memory_s")
input = new DataInputStream(midlet.getClass().getResourceAsStream(
FILE_RESOURCE));
input.readInt();
#else
input = new DataInputStream(
new ByteArrayInputStream(bufferResource));
#end
input.skipBytes(dataImageOffset[0]);
//showInfo("dataIamge length:"+dataImage.length);
for (int i = 0; i < dataImage.length; i++) {
#if(${ant.project_nomerging})
if(dataImageActive[i]){
//showInfo("image index: "+i);
}
if ((dataImage[i] == null) && (dataImageActive[i])) {
dataImage[i] = Image.createImage("/" + (10 + i) + ".png");
}
#else
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);
}
#end
}
} 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 {
#if(${ant.handset_memory}=="memory_s")
input = new DataInputStream(midlet.getClass().getResourceAsStream(
FILE_RESOURCE));
input.readInt();
#else
input = new DataInputStream(
new ByteArrayInputStream(bufferResource));
#end
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 {
#if(${ant.handset_memory}=="memory_s")
input = new DataInputStream(midlet.getClass().getResourceAsStream(
FILE_RESOURCE));
input.readInt();
#else
input = new DataInputStream(
new ByteArrayInputStream(bufferResource));
#end
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 {
#if(${ant.handset_memory}=="memory_s")
input = new DataInputStream(midlet.getClass().getResourceAsStream(
FILE_RESOURCE));
input.readInt();
#else
input = new DataInputStream(
new ByteArrayInputStream(bufferResource));
#end
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);
#if(${ant.language_character})
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();
}
#else
int nextWord = s.indexOf(' ', beginIndex);
if ((nextLine != -1) && ((nextLine < nextWord) || (nextWord == -1))) {
result = nextLine;
} else if (nextWord == -1) {
result = s.length();
} else {
result = nextWord;
while (font.substringWidth(s, beginIndex, nextWord - beginIndex) < w) {
result = nextWord;
if ((nextWord == nextLine) || (nextWord == s.length())) {
break;
}
nextWord = s.indexOf(' ', nextWord + 1);
if ((nextLine != -1)
&& ((nextLine < nextWord) || (nextWord == -1))) {
nextWord = nextLine;
} else if (nextWord == -1) {
nextWord = s.length();
}
}
}
#end
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 + -