Jump to content

Recommended Posts

Posted (edited)

I'm trying to make a coding game, for players to start learning Java. I created a post yesterday about the multi-row textfield(I need it for the actual in-game Java IDE). Since then I started to work on a multi-row text filed. I added the basics:

https://streamable.com/buse32

 

As you can see from the video it works, but there are some things missing(cursor, navigating trough code with arrow keys, CTRL+A, select, CTRL+C, CTRL+V, etc). I have no idea how to imlement theese things. Here is may code(GUI class):

Console console = new Console();

	@Override
	public void drawScreen(int x, int y, float ticks) {
		returns[0] = 0;
		int guiX = (width - guiWidth) / 2;
		int guiY = (height - guiHeight) / 2;
		
		//GL11.glColor4f(1, 1, 1, 1);
	
		mc.renderEngine.bindTexture(new ResourceLocation("jp", "textures/gui/java_final.png"));
		drawTexturedModalRect(guiX, guiY, 0, 0, guiWidth, guiHeight);
		
		
		
		for(int j = 1; j <= rows; j++) {
			String row = "nothing yet";
			int i;
			for(i = 1, row = ""; i <= letterCount; i++) {
				if(returns[j] != 0) {
					if(i < returns[j] && i >= returns[j-1]) {
					
						row += Keys[i];
						fontRendererObj.drawString(row, guiX + 10, guiY + 40 + (j - 1) * 10, 0x5e757d);
					
					}
				}
				if(returns[j] == 0) {
					if(i >= returns[j-1]) {
						row += Keys[i];
						fontRendererObj.drawString(row, guiX + 10, guiY + 40 + (j - 1) * 10, 0x5e757d);
						
					}
				}
				
				
				
			}
			
			
		}
		super.drawScreen(x, y, ticks);
				
		
		
	}
	
	
	
	@Override
	protected void keyTyped(char c, int key) {
		//change the "fontRendererObj.drawString("String before any key", guiX + 10, guiY + 40, 0x5e757d);" text to the key tapped
		switch(key) {
		case Keyboard.KEY_BACK:
			if(letterCount >= 1) {
				Keys[letterCount] = null;
				letterCount--;
				if(returns[returnCount] == letterCount + 1) {
					returns[returnCount] = 0;
					returnCount--;
					rows--;
				}
				
			}
			console.log("Returns: ");
			for(int cnt = 1;cnt <= returnCount; cnt++) {
				console.log(returns[cnt] + " ");
				
			}
			console.newline();
			console.log("Keys: ");
			for(int cnt = 1;cnt <= letterCount; cnt++) {
				console.log(Keys[cnt] + " ");
				
			}
			console.newline();
			console.log("Retrun Count: " + returnCount);
			console.newline();
			console.log("Rows: " + rows);
			console.newline();
			console.log("Letter Count: " + letterCount);
			console.newline();
			break;
		case Keyboard.KEY_ESCAPE:
			mc.displayGuiScreen(null);
			break;
		case Keyboard.KEY_RETURN:
			rows++;
			returnCount++;
			returns[returnCount]=letterCount + 1;
			console.log("Returns: ");
			for(int cnt = 1;cnt <= returnCount; cnt++) {
				console.log(returns[cnt] + " ");
				
			}
			console.newline();
			console.log("Keys: ");
			for(int cnt = 1;cnt <= letterCount; cnt++) {
				console.log(Keys[cnt] + " ");
				
			}
			console.newline();
			console.log("Retrun Count: " + returnCount);
			console.newline();
			console.log("Rows: " + rows);
			console.newline();
			console.log("Letter Count: " + letterCount);
			console.newline();
			break;
			
		default:
			if(c >= 32 && c <= 127) {
				letterCount++;
				Keys[letterCount] = c + "";
				console.log("Returns: ");
				for(int cnt = 1;cnt <= returnCount; cnt++) {
					console.log(returns[cnt] + " ");
					
				}
				console.newline();
				console.log("Keys: ");
				for(int cnt = 1;cnt <= letterCount; cnt++) {
					console.log(Keys[cnt] + " ");
					
				}
				console.newline();
				console.log("Retrun Count: " + returnCount);
				console.newline();
				console.log("Rows: " + rows);
				console.newline();
				console.log("Letter Count: " + letterCount);
				console.newline();
				
			}
			break;
		
		}
		
		
		
	}

 The console class is just a class I made to avoid writing "System.out.println" every time I want to print in console something:

package com.mikeyjy.methods;

public class Console {

	public void log(Object obj) {
		System.out.print(obj);
	}
	public void newline() {
		System.out.println();
	}
}

 

Edited by MikeyJY

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.