Hey guys!
I've been getting requests on a written tutorial on popup windows and I wanted to finally do it! Remember that this is not all Javascript and I do recommend learning Java first before starting any UI stuff. Anyways, let's get started.
First decide how you want to activate this. Tap on a certain block? Button? Any way will work!
For now we are going to use the useItem() hook for this.
Now, let's start by defining the dialog and the layout. You may use the addView method to add any other views to your layout (Buttons, TexViews, EditTexts, etc...)
function useItem(x, y, x, itemId, blockId){ var ctx = com.mojang.minecraftpe.MainActivity.currentMainActivity.get(); if(itemId == 280){//If the item you are holding is a stick ctx.runOnUiThread(new java.lang.Runnable(){//Define a new Ui Thread run: function(){ try{ var dialog = new android.app.Dialog(ctx);//Dialog that will pop up var layout = new android.widget.LinearLayout(ctx);//Layout that will hold all views var tv = new android.widget.TextView(ctx);//The view that will display text }catch(e){ print("Error: " + e); } } }); } }
Now that you have the objects defined let's put them all in the dialog!
function useItem(x, y, x, itemId, blockId){ var ctx = com.mojang.minecraftpe.MainActivity.currentMainActivity.get(); if(itemId == 280){//If the item you are holding is a stick ctx.runOnUiThread(new java.lang.Runnable(){//Define a new Ui Thread run: function(){ try{ var dialog = new android.app.Dialog(ctx);//Dialog that will pop up var layout = new android.widget.LinearLayout(ctx);//Layout that will hold all views var tv = new android.widget.TextView(ctx);//The view that will display text tv.setText("This dialog was opened!");//Add text to the text view layout.addView(tv);//Add the textview to the layout dialog.setContentView(layout);//Sets the content of the dialog to a specified layout }catch(e){ print("Error: " + e); } } }); } }
Ok, let's customize the dialog and show it off!
function useItem(x, y, x, itemId, blockId){ var ctx = com.mojang.minecraftpe.MainActivity.currentMainActivity.get(); if(itemId == 280){//If the item you are holding is a stick ctx.runOnUiThread(new java.lang.Runnable(){//Define a new Ui Thread run: function(){ try{ var dialog = new android.app.Dialog(ctx);//Dialog that will pop up var layout = new android.widget.LinearLayout(ctx);//Layout that will hold all views var tv = new android.widget.TextView(ctx);//The view that will display text tv.setText("This dialog was opened!");//Add text to the text view tv.setTextColor(android.graphics.Color.GREEN);//Text color is set to green layout.addView(tv);//Add the textview to the layout layout.setBackgroundColor(android.graphics.Color.RED);//Sets the background color to red dialog.setContentView(layout);//Sets the content of the dialog to a specified layout dialog.setTitle("Dialog");//Sets a title dialog.show();//Show off your masterpiece! }catch(e){ print("Error: " + e); } } }); } }
Anymore requests would be great!
I'm glad I could help
1
Hey Byteandahalf, there arw a few bugs I would like to bring to your attention. Its understandable why there are so many bugs, so you can take your time to call the exterminator for em
(Image 1) This would work, but for some reason the bottom piston is extending before the top one so the top pistone cannot extend. I dont know why this happens but it should work.
(Image 2) Also, this should work as well. The top pistons extend and update the bottom wuth a thing called BUD (Block Update Detector), but sadly they arent working.
(Image 3) T- Flip Flops dont work either. This isnt really a bug more than it is a forgotten game mechanic. When a piston extends, it should take a .5 tick delay before extending, but it extends instantaneous in the mod. Also, when a sticky piston is extended for shorter than a whole tick, it wont retract the block because it was too fast, and the block should stay out, but again, it doesnt in the mod.
I couldnt get an image, but when u break a block with powered redstone on it, the mod crashes.
But hey, I can still build some pretty sweet stuff! Currently, I am making a Can You Escape map, and here is a combonation code lock I saw on line and built myself. I am not that genius to come up with that, it was a YT Tutorial