Tuesday, July 24, 2018

New GUI lib

GUI.1016 lib.


This is a ModPE library that some of my mod uses, this library is simple yet useful. this library helps you create an in-game GUI (Graphical User Interface) like menus, buttons, screen texts, etc. You can even change and customize your GUI with your own bitmap/texture image from your local storage or mod texture.



To use this library :
  • Create a lib folder with the library in it and place the folder inside your current texturepack or zip the lib folder with the library inside then load it to your blocklauncher.
  •  To activate library copy the line below and paste it at the first part of your script.
var activity = com.mojang.minecraftpe.MainActivity.currentMainActivity.get();                                                     eval(""+new java.lang.String(ModPE.getBytesFromTexturePack("lib/Mhafy1016.library.gui.js"))+"");

                If the library loaded, a small text will popup and says Patched! then the Author’s name.

                                                “If the text didn’t appear review your script.”



Terms

Font.setGlobal – change the font of all text related elements.
    usage
        Font.setGlobal = Font.fromTexture( location of font inside texture );
        Font.fromLocal = Font.fromTexture( location local storage );
Tip : If Font not found returns to original font.
   
screen.width - integer returns the screen actual width.
screen.height - integer returns the screen actual height;


color.red - returns color red;
color.blue - returns color blue;
color.yellow - returns color yellow;
color.green - returns color green;
color.cyan - returns color cyan;
color.black - returns color black;
color.white - returns color white;
color.gray - returns color gray;
color.transparent - returns color transparent;
color.rgb(red, green, blue) - returns the combination of color red, green, blue ranging from 0 to 255.
color.argb(alpha, red, green, blue) - returns the combination of color red, green, blue ranging from 0 to 255 with a transparency from 0 to 1.
color.hex( color hex value ) - returns the color according to the hex value.
color.setColor( color ) - set the color according to the color value.
color.setColorHex( color hex value ) - set the color according to the hex value.
Tip : When changing the background color use color.setColor or color.setColorHex otherwise leave it with null.


alignment.LEFT - change the alignment to the left.
alignment.RIGHT - change the alignment to the right.
alignment.TOP - change the alignment to the top.
alignment.BOTTOM - change the alignment to the bottom.
alignment.CENTER - change the alignment to the center.
Tip : When changing the alignment of window pick two from above and add | at the center.
e.g alignment.LEFT | alignment.TOP.


runUI( your function ) - run ui thread from device.
Tip : use this when changing ui components.
e.g in a newLevel function
    function newLevel(){
        runUI(function(){
            put something here
        });
    }


new android.widget.RelativeLayout(activity) - creates a new layout.
e.g
    var your_variable_name = new android.widget.RelativeLayout(activity);
    when adding an element to the layout -
    your_variable_name.addView( your_element_name );
   

createGUI.window( widget, x, y, width, height, alignment) - returns newly created window.
    widget - Layout to be displayed on the window (object).
    x - Position of window in X-axis of the screen (integer).
    y - Position of window in Y-axis of the screen (integer).
    width – width of window to be displayed (integer).
    height – height of window to be displayed (integer).
    alignment – is where the window will be placed (object).
Tip : When closing the window use .dismiss()
e.g var your_gui_name = createGUI.window( widget, x, y, width, height, alignment);


createGUI.button( text, textShadow, textSize, font, textColor, action, background) - returns the button to be displayed.
    text - text to be displayed at the button (string).
    textShadow - add shadow to the text (boolean).
    textSize - change the text size of the button (integer).
    font - change text font of the button (object).
    textColor - change text color of the button (object).
    action - add action when the button was clicked (function).
    background - change the background of button (object).
Tip : when adding action change action to your function.
e.g createGUI.button( text, textShadow, textSize, font, textColor, function(){
        add something here.
    }, background);
Tip : When changing the button size use createGUI.customLayout(your button, x, y, width, height);

   
createGUI.bitMapButton(text, shadow, textSize, font, textColor, x, y, width, height, fromTexture1, bitmapUnpressed, fromTexture2, bitmapPressed, bitmapWidth, bitmapHeight, lr, tb, centerWidth, centerheight, action, pixelSize) - returns the button with bitmap to be displayed.
    text - text to be displayed at the button (string).
    textShadow - add shadow to the text (boolean).
    textSize - change the text size of the button (integer).
    font - change text font of the button (object).
    textColor - change text color of the button (object).
    x - Position of button in X-axis (integer).
    y - Position of button in Y-axis (integer).
    width – width of button to be displayed (integer).
    height – height of button to be displayed (integer).
    fromTexture1 - check if the first bitmap is from texture or localStorage (boolean).
    bitmapUnpressed - location of the bitmap (string).
    fromTexture2 - check if the second bitmap is from texture or localStorage (boolean).
    bitmapPressed - location of the bitmap (string).
    bitmapWidth - original width of the used bitmap image (integer).
    bitmapHeight - original height of the used bitmap image (integer).
    lr - left and right border of the bitmap image (integer).
    tb - top and bottom border of the bitmap image (integer).
    centerWidth - width of the center of bitmap image to be stretched (integer).
    centerHeight - height of the center of bitmap image to be stretched (integer).
    action - add action when the button was clicked (function).
    pixelSize - adjust the pixels of th bitmap image (integer).
e.g createGUI.bitMapButton("CLOSE", true, 8, null, color.black, 80,64,96,48, true, "ui/slider_button_default.png", true, "ui/slider_button_hover.png", 6, 6, 2, 2, 2, 2, function(v){
           
        }, 1);
       
       
createGUI.icon(fromTexture, bitmap, offsetX, offsetY, imageWidth, imageHeight, x, y, width, height) - returns the bitmap image to be displayed.
    fromTexture - check if the first bitmap is from texture or localStorage (boolean).
    bitmap - location of the bitmap (string).
    offsetX - starting offset of the image from the X-Axis (integer).
    offsetY - starting offset of the image from the Y-Axis (integer).
    imageWidth - the with of the image from offsetX (integer).
    imageHeight - the with of the image from offsetY (integer).
    x - Position of icon in X-axis (integer).
    y - Position of icon in Y-axis (integer).
    width – width of icon to be displayed (integer).
    height – height of icon to be displayed (integer).
e.g createGUI.icon(true, "ui/mashup_hangar.png",0,0,24,24,0,0,32,32);


createGUI.textLabel(text, x, y, width, height, textShadow, textSize, textColor, font, alignment) - returns the text layout to be displayed.
    text - text to be displayed at the button (string).
    x - Position of text in X-axis (integer).
    y - Position of text in Y-axis (integer).
    width – width of text to be displayed (integer).
    height – height of text to be displayed (integer).
    textShadow - add shadow to the text (boolean).
    textSize - change the text size of the button (integer).
    font - change text font of the button (object).
    textColor - change text color of the button (object).
    alignment – is where the window will be placed (object).
Tip : aligning the textLabel use only one alignment.
e.g createGUI.textLabel("text label", 0, 0, 128, 64, true, 12, color.red, null, alignment.CENTER);



createGUI.customLayout(widget, x, y, width, height, background) - set a layout to a given widget;
    widget - Layout to be displayed on the window (object).
    x - Position of window in X-axis of the screen (integer).
    y - Position of window in Y-axis of the screen (integer).
    width – width of window to be displayed (integer).
    height – height of window to be displayed (integer).
    background - change the background of button (object).
   
   
   
   
Bitmap.drawableBitmap(fromTexture, bitmap, offsetX, offsetY, imageWidth, imageHeight, dip(imageWidth), dip(imageHeight)).getBitmap() - change bkacground to bitmap image.

    fromTexture - check if the first bitmap is from texture or localStorage (boolean).
    bitmap - location of the bitmap (string).
    offsetX - starting offset of the image from the X-Axis (integer).
    offsetY - starting offset of the image from the Y-Axis (integer).
    imageWidth - the with of the image from offsetX (integer).
    imageHeight - the with of the image from offsetY (integer).

Tip : just copy the dip() thing, it is for the pixel something...


Bitmap.bitmapStretch(btimap, lr, tb, centerWidth, centerHeight, width, height, pixelSize) - stretch the bitmap to a new size.
    bitmap - the bitmap image to be stretched.
    lr - left and right border of the bitmap image (integer).
    tb - top and bottom border of the bitmap image (integer).
    centerWidth - width of the center of bitmap image to be stretched (integer).
    centerHeight - height of the center of bitmap image to be stretched (integer).
    width – new width of the bitmap (integer)
    height – new height of the bitmap (integer).
    pixelSize - adjust the pixels of th bitmap image (integer).
Tip : only use Bitmap.bitmapStretch() to Bitmap.drawableBitmap(), change the bitmap of Bitmap.bitmapStretch() to the value Bitmap.drawableBitmap().
e.g
    Bitmap.bitmapStretch(Bitmap.drawableBitmap(true, "ui/dialog_background_opaque.png",0,0,16,16,dip(16),dip(16)).getBitmap(),/*<= the bitmap*/ dip(5),dip(5),dip(6),dip(6),256,128,1);
   
   

Others


getEntId( entity ) - get the id of the entity.
    entity - selected entity.

checkInArray(object, array)- checks if the given object exists inside the array.
Tip : if the object exists returns to true otherwise false.

checkNear(entity1, entity12, distance, height) - check if the two entities were near each other in a given distance.
Tip : if near returns to true otherwise false.

function vector3d(x, y, z) - returns new x, y, z coordinates.





Sample Scripts

Plain gui + text + button


var activity = com.mojang.minecraftpe.MainActivity.currentMainActivity.get();
eval(""+new java.lang.String(ModPE.getBytesFromTexturePack("lib/Mhafy1016.library.gui.js"))+"");

var gui;
var layout;
var text;
var btn;
function sampleGUI(){
                runUI(function(){
                                layout = new android.widget.RelativeLayout(activity);

                                text = createGUI.textLabel("Sample GUI",0,0,256,64,true,18,color.black,null,alignment.CENTER);
                                btn = createGUI.customLayout(createGUI.button("Close",false,12,null,color.black,function(){
                                                if(gui != null){
                                                                gui.dismiss();
                                                                gui = null;
                                                }
                                }), 80, 64, 96, 64);
                                layout.addView(text);
                                layout.addView(btn);

                                gui = createGUI. window(layout,0,0,256,128,alignment.CENTER | alignment.CENTER, color.setColor(color.white));
                });
}

function newLevel(){
                sampleGUI();
}


screenshot
 



Gui with Bitmap



var activity = com.mojang.minecraftpe.MainActivity.currentMainActivity.get();
eval(""+new java.lang.String(ModPE.getBytesFromTexturePack("lib/Mhafy1016.library.gui.js"))+"");

var gui;
var layout;
var text;
var btn;
var background;
function sampleGUI(){
            runUI(function(){
                        layout = new android.widget.RelativeLayout(activity);
                       
                        background = Bitmap.bitmapStretch(Bitmap.drawableBitmap(true, "ui/dialog_background_opaque.png",0,0,16,16,dip(16),dip(16)).getBitmap(),dip(5),dip(5),dip(6),dip(6),256,128,1);
                       
                        layout.setBackgroundDrawable(background);
                       
                        text = createGUI.textLabel("Sample GUI",0,0,256,64,true,18,color.black,null,alignment.CENTER);
                        btn = createGUI.bitMapButton("CLOSE", true, 8, null, color.black, 80,64,96,48, true, "ui/slider_button_default.png", true, "ui/slider_button_hover.png", 6, 6, 2, 2, 2, 2, function(v){
                                    if(gui != null){
                                                gui.dismiss();
                                                gui = null;
                                    }
                        }, 1);
                       
                        layout.addView(text);
                        layout.addView(btn);
                       
                        gui = createGUI. window(layout,0,0,256,128,alignment.CENTER | alignment.CENTER);
            });
}

function newLevel(){
            sampleGUI();
}

 screenshot
 


var activity = com.mojang.minecraftpe.MainActivity.currentMainActivity.get();
eval(""+new java.lang.String(ModPE.getBytesFromTexturePack("lib/Mhafy1016.library.gui.js"))+"");

var gui;
var main_layout;
var layout;
var text;
var btn;
function sampleGUI(){
    runUI(function(){
        main_layout = new android.widget.RelativeLayout(activity);
        layout = createGUI.customLayout(new android.widget.RelativeLayout(activity), 16, 16, 224, 96, Bitmap.bitmapStretch(Bitmap.drawableBitmap(true, "ui/dialog_background_opaque.png",0,0,16,16,dip(16),dip(16)).getBitmap(),dip(5),dip(5),dip(6),dip(6),224,96,1));
      
        text = createGUI.textLabel("Arranging Elements",0,0,224,96,true,18,color.black,null,alignment.CENTER);
      
        btn = createGUI.customLayout(new android.widget.RelativeLayout(activity),208,0,48,48,Bitmap.bitmapStretch(Bitmap.drawableBitmap(true, "ui/recipe_back_panel.png",0,0,16,16,dip(16),dip(16)).getBitmap(),dip(4),dip(4),dip(8),dip(8),48,48,1));
        btn.addView(createGUI.bitMapButton("", true, 12, null, color.black, 8, 8, 32, 32, true, "ui/close_button_default.png", true, "ui/close_button_pressed.png", 15, 15, 1, 1, 13, 13, function(v, e){
      
            if(gui != null){
                gui.dismiss();
                gui = null;
            }
          
        }, 1));
        layout.addView(text);
      
        main_layout.addView(layout);
        main_layout.addView(btn);
      
        gui = createGUI.window(main_layout,0,0,256,128,alignment.CENTER | alignment.CENTER);
    });
}

function newLevel(){
    sampleGUI();
}

screenshot
 






No comments:

Post a Comment