Initial load text from file method
This commit is contained in:
parent
73d9c4da1e
commit
a538178c9c
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
build
|
build
|
||||||
ideas.txt
|
ideas.txt
|
||||||
|
tools/bin
|
BIN
assets/silly/txt/t_mainmenu.silly
Normal file
BIN
assets/silly/txt/t_mainmenu.silly
Normal file
Binary file not shown.
7
raw/text/t_mainmenu.txt
Normal file
7
raw/text/t_mainmenu.txt
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
new game
|
||||||
|
load game
|
||||||
|
instructions
|
||||||
|
options
|
||||||
|
leaderboard
|
||||||
|
credits
|
||||||
|
exit game
|
@ -5,7 +5,7 @@ import javax.microedition.lcdui.Display;
|
|||||||
import javax.microedition.midlet.MIDlet;
|
import javax.microedition.midlet.MIDlet;
|
||||||
|
|
||||||
import sillysagiri.Sagiri;
|
import sillysagiri.Sagiri;
|
||||||
import sillysagiri.scene.Intro;
|
import sillysagiri.scene.MainMenu;
|
||||||
import sillysagiri.scene.MainMenu;
|
import sillysagiri.scene.MainMenu;
|
||||||
|
|
||||||
public class DotHack extends MIDlet implements Runnable {
|
public class DotHack extends MIDlet implements Runnable {
|
||||||
@ -26,7 +26,7 @@ public class DotHack extends MIDlet implements Runnable {
|
|||||||
thread.setPriority(Thread.MAX_PRIORITY);
|
thread.setPriority(Thread.MAX_PRIORITY);
|
||||||
thread.start();
|
thread.start();
|
||||||
|
|
||||||
sagiri.Set_Scene(new Intro());
|
sagiri.Set_Scene(new MainMenu());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pauseApp() {}
|
public void pauseApp() {}
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
package sillysagiri;
|
package sillysagiri;
|
||||||
|
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
|
||||||
import javax.microedition.lcdui.Graphics;
|
import javax.microedition.lcdui.Graphics;
|
||||||
import javax.microedition.lcdui.Image;
|
import javax.microedition.lcdui.Image;
|
||||||
|
|
||||||
import dothack.Global;
|
import dothack.Global;
|
||||||
|
import sillysagiri.scene.DeathError;
|
||||||
|
|
||||||
public final class Utils {
|
public final class Utils {
|
||||||
public static int ARGB15to255(char argb15)
|
public static int ARGB15to255(char argb15)
|
||||||
@ -72,4 +78,35 @@ public final class Utils {
|
|||||||
public static double clamp(double value, double min, double max) {
|
public static double clamp(double value, double min, double max) {
|
||||||
return Math.max(min, Math.min(value, max));
|
return Math.max(min, Math.min(value, max));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: support utf-16
|
||||||
|
public static String[] Get_StringSilly(String path_sillystring, int size)
|
||||||
|
{
|
||||||
|
String[] str = new String[size];
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
byte[] temp = new byte[128];
|
||||||
|
InputStream in = str.getClass().getResourceAsStream(path_sillystring);
|
||||||
|
|
||||||
|
for (int i=0; i<size; i++)
|
||||||
|
{
|
||||||
|
int res = in.read(temp, 0, 2);
|
||||||
|
if (res == -1) break;
|
||||||
|
|
||||||
|
int size_str = (temp[1] << 8) | (temp[0] & 0xff);
|
||||||
|
res = in.read(temp, 0, size_str);
|
||||||
|
if (res == -1) break;
|
||||||
|
|
||||||
|
str[i] = new String(temp, 0, size_str, "UTF-8");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Sagiri._instance.Set_Scene(new DeathError(e));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,19 +12,20 @@ public class MainMenu extends Scene {
|
|||||||
private long counter = 0;
|
private long counter = 0;
|
||||||
private int state = 0;
|
private int state = 0;
|
||||||
|
|
||||||
private Image img_bg;
|
|
||||||
private Image img_box;
|
|
||||||
private Image img_bandai;
|
|
||||||
private BMF bmf_white;
|
private BMF bmf_white;
|
||||||
private BMF bmf_blue;
|
private BMF bmf_blue;
|
||||||
|
|
||||||
|
private Image img_bg;
|
||||||
|
private Image img_box;
|
||||||
|
private Image img_bandai;
|
||||||
private Image img_head1;
|
private Image img_head1;
|
||||||
private Image img_head2;
|
private Image img_head2;
|
||||||
private Image img_head3;
|
private Image img_head3;
|
||||||
private Image img_head4;
|
private Image img_head4;
|
||||||
|
|
||||||
private Image img_arrow;
|
private Image img_arrow;
|
||||||
|
|
||||||
|
private String[] list_strmenu;
|
||||||
|
|
||||||
public void Preload() {
|
public void Preload() {
|
||||||
try {
|
try {
|
||||||
bmf_white = BMF.Create("/silly/bmf/onds12_0.silly.gz", "/silly/bmf/onds12.fnt", 0xffffffff);
|
bmf_white = BMF.Create("/silly/bmf/onds12_0.silly.gz", "/silly/bmf/onds12.fnt", 0xffffffff);
|
||||||
@ -42,8 +43,20 @@ public class MainMenu extends Scene {
|
|||||||
for (int i = 0; i<loopCount; i++)
|
for (int i = 0; i<loopCount; i++)
|
||||||
g_bg.drawImage(img_loop, 0, i*img_loop.getHeight(), Graphics.LEFT | Graphics.TOP);
|
g_bg.drawImage(img_loop, 0, i*img_loop.getHeight(), Graphics.LEFT | Graphics.TOP);
|
||||||
|
|
||||||
int boxw = (int)(bmf_blue.Measure("INSTRUCTION")[0]+bmf_blue.lineHeight*1.4);
|
int maxlength = 0;
|
||||||
int boxh = bmf_blue.lineHeight*8;
|
list_strmenu = Utils.Get_StringSilly("/silly/txt/t_mainmenu.silly", 7);
|
||||||
|
for (int i=0; i<list_strmenu.length; i++)
|
||||||
|
{
|
||||||
|
if (list_strmenu[i].length() >= list_strmenu[maxlength].length())
|
||||||
|
maxlength = i;
|
||||||
|
|
||||||
|
list_strmenu[i] = list_strmenu[i].toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(list_strmenu[maxlength]);
|
||||||
|
|
||||||
|
int boxw = (int)(bmf_blue.Measure(list_strmenu[maxlength])[0]+bmf_blue.lineHeight*1.4);
|
||||||
|
int boxh = bmf_blue.lineHeight*(list_strmenu.length+1);
|
||||||
int[] temp = new int[boxw*boxh];
|
int[] temp = new int[boxw*boxh];
|
||||||
for (int i=0; i<temp.length; i++) temp[i] = 0x93800000;
|
for (int i=0; i<temp.length; i++) temp[i] = 0x93800000;
|
||||||
img_box = Image.createRGBImage(temp, boxw, boxh, true);
|
img_box = Image.createRGBImage(temp, boxw, boxh, true);
|
||||||
@ -108,13 +121,16 @@ public class MainMenu extends Scene {
|
|||||||
int cursor = (int)(Utils.GetScreenHeight()*0.35);
|
int cursor = (int)(Utils.GetScreenHeight()*0.35);
|
||||||
g.drawImage(img_box, Utils.GetScreenWidth()/2, cursor-(bmf_blue.lineHeight/2), Graphics.HCENTER | Graphics.TOP);
|
g.drawImage(img_box, Utils.GetScreenWidth()/2, cursor-(bmf_blue.lineHeight/2), Graphics.HCENTER | Graphics.TOP);
|
||||||
|
|
||||||
bmf_blue.DrawEx(g, "NEW GAME", Utils.GetScreenWidth()/2, cursor, Graphics.HCENTER | Graphics.TOP);
|
for(int i=0; i<list_strmenu.length; i++)
|
||||||
bmf_blue.DrawEx(g, "LOAD GAME", Utils.GetScreenWidth()/2, cursor+=bmf_blue.lineHeight, Graphics.HCENTER | Graphics.TOP);
|
bmf_blue.DrawEx(g, list_strmenu[i], Utils.GetScreenWidth()/2, cursor+bmf_blue.lineHeight*i, Graphics.HCENTER | Graphics.TOP);
|
||||||
bmf_blue.DrawEx(g, "INSTRUCTION", Utils.GetScreenWidth()/2, cursor+=bmf_blue.lineHeight, Graphics.HCENTER | Graphics.TOP);
|
|
||||||
bmf_blue.DrawEx(g, "OPTIONS", Utils.GetScreenWidth()/2, cursor+=bmf_blue.lineHeight, Graphics.HCENTER | Graphics.TOP);
|
// bmf_blue.DrawEx(g, "NEW GAME", Utils.GetScreenWidth()/2, cursor, Graphics.HCENTER | Graphics.TOP);
|
||||||
bmf_blue.DrawEx(g, "LEADERBOARD", Utils.GetScreenWidth()/2, cursor+=bmf_blue.lineHeight, Graphics.HCENTER | Graphics.TOP);
|
// bmf_blue.DrawEx(g, "LOAD GAME", Utils.GetScreenWidth()/2, cursor+=bmf_blue.lineHeight, Graphics.HCENTER | Graphics.TOP);
|
||||||
bmf_blue.DrawEx(g, "CREDITS", Utils.GetScreenWidth()/2, cursor+=bmf_blue.lineHeight, Graphics.HCENTER | Graphics.TOP);
|
// bmf_blue.DrawEx(g, "INSTRUCTION", Utils.GetScreenWidth()/2, cursor+=bmf_blue.lineHeight, Graphics.HCENTER | Graphics.TOP);
|
||||||
bmf_blue.DrawEx(g, "EXIT GAME", Utils.GetScreenWidth()/2, cursor+=bmf_blue.lineHeight, Graphics.HCENTER | Graphics.TOP);
|
// bmf_blue.DrawEx(g, "OPTIONS", Utils.GetScreenWidth()/2, cursor+=bmf_blue.lineHeight, Graphics.HCENTER | Graphics.TOP);
|
||||||
|
// bmf_blue.DrawEx(g, "LEADERBOARD", Utils.GetScreenWidth()/2, cursor+=bmf_blue.lineHeight, Graphics.HCENTER | Graphics.TOP);
|
||||||
|
// bmf_blue.DrawEx(g, "CREDITS", Utils.GetScreenWidth()/2, cursor+=bmf_blue.lineHeight, Graphics.HCENTER | Graphics.TOP);
|
||||||
|
// bmf_blue.DrawEx(g, "EXIT GAME", Utils.GetScreenWidth()/2, cursor+=bmf_blue.lineHeight, Graphics.HCENTER | Graphics.TOP);
|
||||||
|
|
||||||
// if (counter > 360) counter = 0;
|
// if (counter > 360) counter = 0;
|
||||||
|
|
||||||
|
55
tools/string2bin/string2bin.cpp
Normal file
55
tools/string2bin/string2bin.cpp
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
#include <cstdint>
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
void writeBinaryFile(const std::string& inputFileName, const std::string& outputFileName) {
|
||||||
|
std::ifstream inputFile(inputFileName);
|
||||||
|
std::ofstream outputFile(outputFileName, std::ios::binary);
|
||||||
|
|
||||||
|
if (!inputFile) {
|
||||||
|
std::cerr << "Error opening input file: " << inputFileName << std::endl;
|
||||||
|
std::exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!outputFile) {
|
||||||
|
std::cerr << "Error opening output file: " << outputFileName << std::endl;
|
||||||
|
std::exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string line;
|
||||||
|
while (std::getline(inputFile, line)) {
|
||||||
|
// Get the size of the string
|
||||||
|
std::size_t size = line.size();
|
||||||
|
|
||||||
|
// Write size as 2 bytes (big-endian)
|
||||||
|
uint16_t sizeInBytes = static_cast<uint16_t>(size);
|
||||||
|
outputFile.write(reinterpret_cast<const char*>(&sizeInBytes), sizeof(sizeInBytes));
|
||||||
|
|
||||||
|
// Write the string followed by a null terminator
|
||||||
|
outputFile.write(line.c_str(), size);
|
||||||
|
|
||||||
|
// char nullChar = '\0';
|
||||||
|
// outputFile.write(&nullChar, sizeof(nullChar));
|
||||||
|
}
|
||||||
|
|
||||||
|
inputFile.close();
|
||||||
|
outputFile.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
if (argc != 3) {
|
||||||
|
std::cerr << "Usage: " << argv[0] << " <input_file> <output_file>" << std::endl;
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string inputFileName = argv[1]; // Input file name from args
|
||||||
|
std::string outputFileName = argv[2]; // Output binary file name from args
|
||||||
|
|
||||||
|
writeBinaryFile(inputFileName, outputFileName);
|
||||||
|
|
||||||
|
std::cout << "Strings written to binary file successfully." << std::endl;
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user