Welcome to the tutorial on how to add a Graphical UI (GUI) for your mod
What it's explained in this tutorial:
- Simple Popup (with Linear Layout and Scroll)
- Popup with "OK" and "Cancel" (with Linear Layout and Scroll)
- Toast message
- Open URL
- Button
- Text
P.S.: At the end of every element I added the link to the official Android Reference.
I will add soon screenshots for these elements
Simple Popup:
First we need to add a variable of the BlockLauncher Activity:
var currentActivity = com.mojang.minecraftpe.MainActivity.currentMainActivity.get();<br>//You can add this code at the top of your script
Now inside a function we have to initialize the Linear Layout and the Scroll of the Popup that we are going to create:
var layout = new android.widget.LinearLayout(currentActivity);<br>//We have initialized the Linear Layout<br>//P.S.: after creating the Popup we will add the visual elements (buttons, switches, images, text) to the Layout<br><br>layout.setOrientation(android.widget.LinearLayout.VERTICAL);<br>//We have set the Layout to VERTICAL but we can also set it to HORIZONTAL<br><br>var scroll = new android.widget.ScrollView(currentActivity);<br>//We have initialized the Scroll (you can also have a Popup without the scroll but if you add something that goes out the maximum space you can't see it)<br><br>scroll.addView(layout);<br>//We have added the Linear Layout to the Scroll
Now we can initialize the Popup:
var popup = new android.app.Dialog(currentActivity);<br>//We have initialized the Popup<br><br>popup.setContentView(scroll);<br>// We have added the Scroll (do you remember that the Scroll contains the Linear Layout and the Linear Layout contains the visual element that we are going to add?)<br><br>popupInfo.setTitle("Title");<br>//Set the title of the Popup
Now we have a Popup that is ready to be shown (but it is blank because we haven't added any visual element), to show it use this code:
This is similar to Simple Popup (read it) but to initialize it we have to use a different code:
var popup = new android.app.AlertDialog.Builder(currentActivity);<br>//With the Simple Popup we used android.app.Dialog now we have to use android.app.AlertDialog
Now we can add to the Alert Dialog (the popup) the OK button and the Cancel button:
popup.setPositiveButton("OK", new android.content.DialogInterface.OnClickListener(){<br>//You can write also different things in the button, instead of "OK" you can write "Done" for example<br>onClick: function(viewarg)<br>//The onClick method is called when the user press OK<br>{<br>//Add your code here when the user press "OK"<br>}});<br><br>popup.setNegativeButton("Cancel", new android.content.DialogInterface.OnClickListener(){<br>onClick: function(viewarg)<br>{<br>//Add your code here when the user press "Cancel"<br>}});
var intentBrowser = new android.content.Intent(currentActivity);<br>//We have initialized an Intent with the name "intentBrowser"<br><br>intentBrowser.setAction(android.content.Intent.ACTION_VIEW);<br>//This set the action that the intent will perform, ACTION_VIEW it's the default action<br><br>intentBrowser.setData(android.net.Uri.parse("http://google.com"));<br>//We have set that the intent will open the URL "http://google.com"
var button = new android.widget.Button(currentActivity);
Now we can set the text of the button and what will happen if the user press the button:
button.setText("Text");<br>//Write what you want instead of "Text"<br><br>button.setOnClickListener(new android.view.View.OnClickListener()<br>{<br>onClick: function()<br>{<br>//here you can add you code<br>}<br>});
Now the latest thing (but maybe the most important thing), add the visual element that we have just created in the Layout:
var text = new android.widget.TextView(currentActivity);
Now we can set the text that is displayed (we can set also the color)
text.setText("Text");<br>//This set the text of the TextView element, you can change it and write what you want<br><br>text.setTextColor(android.graphics.Color.RED);<br>//This set the color of the text, you can also not write this line in your script if you want the text white
Now the latest thing (but maybe the most important thing), add the visual element that we have just created in the Layout:
If this tutorial is useful for someone I will add switch, image and input text tutorials.
Please, if you like this tutorial press the green button ("vote this post up") here below.
And sorry for my bad English.
Please give me an Internet. Please. Pretty Please with sprinkles on top
I have a twitter!! Follow me for regular updates on my mods! https://twitter.com/DamienMiller11
Please give me an Internet. Please. Pretty Please with sprinkles on top
I have a twitter!! Follow me for regular updates on my mods! https://twitter.com/DamienMiller11
var popup = new android.app.Dialog(currentActivity);
//We have initialized the Popup
I used my own custom function and it worked
In this line there isn't any error, the error maybe it's because it's missing something before this line
Look at the example that I have posted in the first post (open the GitHub link) and try to find the difference
Some of these tutorials are incomplete. The button tutorial mentions a non-existant layout variable. Followimg the button just gives layout isnt defined for layout.addView(button);
Some of these tutorials are incomplete. The button tutorial mentions a non-existant layout variable. Followimg the button just gives layout isnt defined for layout.addView(button);
Of course, because the tutorial it's only for the element (button, text, popup). I can't make a tutorial of everything in every element.
You can look at this link the code for the example and then add it to your code.
Of course, because the tutorial it's only for the element (button, text, popup). I can't make a tutorial of everything in every element.
You can look at this link the code for the example and then add it to your code.
Yes but that link also only has the examples for the popupsMaybe possible to give example for the button?
The Meaning of Life, the Universe, and Everything.
Join Date:
5/20/2014
Posts:
49
Member Details
function newLevel(){
var currentActivity = com.mojang.minecraftpe.MainActivity.currentMainActivity.get();
//You can add this code at the top of your script
var layout = new android.widget.LinearLayout(currentActivity);
//We have initialized the Linear Layout
//P.S.: after creating the Popup we will add the visual elements (buttons, switches, images, text) to the Layout
layout.setOrientation(android.widget.LinearLayout.VERTICAL);
//We have set the Layout to VERTICAL but we can also set it to HORIZONTAL
var scroll = new android.widget.ScrollView(currentActivity);
//We have initialized the Scroll (you can also have a Popup without the scroll but if you add something that goes out the maximum space you can't see it)
scroll.addView(layout);
//We have added the Linear Layout to the Scroll
var button = new android.widget.Button(currentActivity);
button.setText("Text");
//Write what you want instead of "Text"
button.setOnClickListener(new android.view.View.OnClickListener()
{
onClick: function()
{
//here you can add you code
}
});
layout.addView(button);
//Is their something wrong with this code I keep getting errors One Sec ILL show ulayout.addView(button);
org.mozilla.javascript.EvaluatorException: missing } after function body (untitled.js#30)
at org.mozilla.javascript.DefaultErrorReporter.runtimeError(Unknown Source)
at org.mozilla.javascript.DefaultErrorReporter.error(Unknown Source)
at org.mozilla.javascript.Parser.addError(Unknown Source)
at org.mozilla.javascript.Parser.addError(Unknown Source)
at org.mozilla.javascript.Parser.reportError(Unknown Source)
at org.mozilla.javascript.Parser.reportError(Unknown Source)
at org.mozilla.javascript.Parser.mustMatchToken(Unknown Source)
at org.mozilla.javascript.Parser.mustMatchToken(Unknown Source)
at org.mozilla.javascript.Parser.parseFunctionBody(Unknown Source)
at org.mozilla.javascript.Parser.function(Unknown Source)
at org.mozilla.javascript.Parser.parse(Unknown Source)
at org.mozilla.javascript.Parser.parse(Unknown Source)
at org.mozilla.javascript.Context.compileImpl(Unknown Source)
at org.mozilla.javascript.Context.compileReader(Unknown Source)
at net.zhuoweizhang.mcpelauncher.ScriptManager$ParseThread.run(ScriptManager.java:151)
at java.lang.Thread.run(Thread.java:856)
Welcome to the tutorial on how to add a Graphical UI (GUI) for your mod
What it's explained in this tutorial:
- Simple Popup (with Linear Layout and Scroll)
- Popup with "OK" and "Cancel" (with Linear Layout and Scroll)
- Toast message
- Open URL
- Button
- Text
P.S.: At the end of every element I added the link to the official Android Reference.
I will add soon screenshots for these elements
Simple Popup:
Now inside a function we have to initialize the Linear Layout and the Scroll of the Popup that we are going to create:
Now we can initialize the Popup:
Now we have a Popup that is ready to be shown (but it is blank because we haven't added any visual element), to show it use this code:
Official Android reference for the Popup: http://developer.and...app/Dialog.html
Popup with "OK" and "Cancel":
Now we can add to the Alert Dialog (the popup) the OK button and the Cancel button:
Official Android reference for the Popup with "OK" and "Cancel" (Alert Dialog): http://developer.and...lertDialog.html
Toast Message:
To create a toast message you can use this code:
Official Android reference for Toast messages: http://developer.and...dget/Toast.html
Open URL:
Now we can start the Intent:
Official Android reference for Intent: http://developer.and...ent/Intent.html
Official Android reference for Uri: http://developer.and...id/net/Uri.html
Button:
Now we can set the text of the button and what will happen if the user press the button:
Now the latest thing (but maybe the most important thing), add the visual element that we have just created in the Layout:
Official Android reference for Button: http://developer.and...get/Button.html
Text:
Now we can set the text that is displayed (we can set also the color)
Now the latest thing (but maybe the most important thing), add the visual element that we have just created in the Layout:
Official Android reference for TextView: http://developer.and...t/TextView.html
Example for every element of this tutorial:
(Open the Simple Popup by typing in chat /simple-popup or open the Popup with "OK" and "Cancel" by typing /popup-ok)
You can also look at the code here: GitHub
If this tutorial is useful for someone I will add switch, image and input text tutorials.
Please, if you like this tutorial press the green button ("vote this post up") here below.
And sorry for my bad English.
All the other things I've made for Minecraft: desno365.net/minecraft/
Follow me on Twitter: @desno365
Visit my website: desno365.net
I have a twitter!! Follow me for regular updates on my mods!
https://twitter.com/DamienMiller11
What do you mean for a menu?
All the other things I've made for Minecraft: desno365.net/minecraft/
Follow me on Twitter: @desno365
Visit my website: desno365.net
And me
I have a twitter!! Follow me for regular updates on my mods!
https://twitter.com/DamienMiller11
The popup it's like a menu and you can add on it buttons, text or whatever you want
All the other things I've made for Minecraft: desno365.net/minecraft/
Follow me on Twitter: @desno365
Visit my website: desno365.net
I will add it soon, an image that can be pressed by the user for make a thing
If you send me the code I will try to find where is the bug
All the other things I've made for Minecraft: desno365.net/minecraft/
Follow me on Twitter: @desno365
Visit my website: desno365.net
the error seems to happen at
I used my own custom function and it worked
In this line there isn't any error, the error maybe it's because it's missing something before this line
Look at the example that I have posted in the first post (open the GitHub link) and try to find the difference
All the other things I've made for Minecraft: desno365.net/minecraft/
Follow me on Twitter: @desno365
Visit my website: desno365.net
Of course, because the tutorial it's only for the element (button, text, popup). I can't make a tutorial of everything in every element.
You can look at this link the code for the example and then add it to your code.
All the other things I've made for Minecraft: desno365.net/minecraft/
Follow me on Twitter: @desno365
Visit my website: desno365.net
Yes but that link also only has the examples for the popupsMaybe possible to give example for the button?
In the example the popup contains buttons, it's impossible to make only buttons, you have to add buttons in a popup.
All the other things I've made for Minecraft: desno365.net/minecraft/
Follow me on Twitter: @desno365
Visit my website: desno365.net
Oh I thought it was to show a button like the M button
The M button of toomanyitems?
Also it uses pupop, it use the android.widget.PopupWindow() command.
All the other things I've made for Minecraft: desno365.net/minecraft/
Follow me on Twitter: @desno365
Visit my website: desno365.net
He means a menu that takes up a certain part of the screen. I don't know if you know how to do this, but here is how it goes:
For the height change getWidth() to getHeight(). This just gets the size of the screen's display and allows you to half it for a menu.
Want GUI Templates? Done!
https://github.com/BeATz-UnKNoWN/ModPE_Scripts/wiki/ModPE-Script-Templates
P.S. Feel free to follow me so you know when I post "awesome" content and make the MCForums a brighter place (totally).
If you need to contact me you can either shoot a Kik message to beatz_unknown or send an email to [email protected]
Now I understand, I didn't understand what kaikun97 mean for a menu
All the other things I've made for Minecraft: desno365.net/minecraft/
Follow me on Twitter: @desno365
Visit my website: desno365.net
When I have time I will update this tutorial
All the other things I've made for Minecraft: desno365.net/minecraft/
Follow me on Twitter: @desno365
Visit my website: desno365.net
var currentActivity = com.mojang.minecraftpe.MainActivity.currentMainActivity.get();
//You can add this code at the top of your script
var layout = new android.widget.LinearLayout(currentActivity);
//We have initialized the Linear Layout
//P.S.: after creating the Popup we will add the visual elements (buttons, switches, images, text) to the Layout
layout.setOrientation(android.widget.LinearLayout.VERTICAL);
//We have set the Layout to VERTICAL but we can also set it to HORIZONTAL
var scroll = new android.widget.ScrollView(currentActivity);
//We have initialized the Scroll (you can also have a Popup without the scroll but if you add something that goes out the maximum space you can't see it)
scroll.addView(layout);
//We have added the Linear Layout to the Scroll
var button = new android.widget.Button(currentActivity);
button.setText("Text");
//Write what you want instead of "Text"
button.setOnClickListener(new android.view.View.OnClickListener()
{
onClick: function()
{
//here you can add you code
}
});
layout.addView(button);
//Is their something wrong with this code I keep getting errors One Sec ILL show ulayout.addView(button);
org.mozilla.javascript.EvaluatorException: missing } after function body (untitled.js#30)
at org.mozilla.javascript.DefaultErrorReporter.runtimeError(Unknown Source)
at org.mozilla.javascript.DefaultErrorReporter.error(Unknown Source)
at org.mozilla.javascript.Parser.addError(Unknown Source)
at org.mozilla.javascript.Parser.addError(Unknown Source)
at org.mozilla.javascript.Parser.reportError(Unknown Source)
at org.mozilla.javascript.Parser.reportError(Unknown Source)
at org.mozilla.javascript.Parser.mustMatchToken(Unknown Source)
at org.mozilla.javascript.Parser.mustMatchToken(Unknown Source)
at org.mozilla.javascript.Parser.parseFunctionBody(Unknown Source)
at org.mozilla.javascript.Parser.function(Unknown Source)
at org.mozilla.javascript.Parser.parse(Unknown Source)
at org.mozilla.javascript.Parser.parse(Unknown Source)
at org.mozilla.javascript.Context.compileImpl(Unknown Source)
at org.mozilla.javascript.Context.compileReader(Unknown Source)
at net.zhuoweizhang.mcpelauncher.ScriptManager$ParseThread.run(ScriptManager.java:151)
at java.lang.Thread.run(Thread.java:856)