编辑 - 更具体,我根据评论尝试过,但它没有实现我的目标
所以我正在尝试为 ModPE 脚本编写者制作一个 Gui 库。我希望它们在类中预定义和组织,而不是让他们全部输入。所以我做了所有的思考和解决,他们可以更容易地创建 GUI mods。我修好了并尝试过...
var ctx = com.mojang.minecraftpe.MainActivity.currentMainActivity.get();
function newLevel()
{
ctx.runOnUiThread(new java.lang.Runnable() {
run: function()
{
try
{
var PopupsAndLayouts = {
PopupWindow: new android.widget.PopupWindow(ctx),
LinearLayout: new android.widget.LinearLayout(ctx),
Button: new android.widget.Button(ctx);
wrapContect: android.widget.LinearLayout.LayoutParams.WRAP_CONTENT;
fillParent: android.widget.LinearLayout.LayoutParams.FILL_PARENT;
leftTopCorner: [ctx.getWindow().getDecorView(), android.view.Gravity.TOP | android.view.Gravity.LEFT, 0, 0]
};
var myWindow = PopupsAndLayouts.PopupWindow;
var myLayout = PopupsAndLayouts.LinearLayout;
var myButton = PopupsAndLayouts.Button;
myLayout.addView(myButton);
myWindow.setContentView(myLayout);
myWindow.setHeight(wrapContent);
myWindow.setWidth(wrapContent);
myWindow.showAtLocation(leftTopCorner);
//Then they add more widgets or set their script
}
catch (libError)
{
print(error);
}
}
});
}
但这行不通。重点是有组织的课程,所以他们必须知道 var myButton = new android.widget.Button(ctx); 或者 var myLayout = new android.widget.LinearLayout(ctx);
他们只是打字 var myLayout = Layouts.LinearLayout; 或者 var myButton = Widgets.Buttons.Button;
我到底该怎么做?我迷失了,想建立这个图书馆有什么想法吗?
网格布局怎么样?尽管只是一般而言,但不是 OOP 明智的。
对于 GridLayout 你可以这样做
var ctx = com.mojang.minecraftpe.MainActivity.currentMainActivity.get();
function newLevel()
{
ctx.runOnUiThread(new java.lang.Runnable() {
run: function()
{
try
{
var l = new android.widget.GridLayout(ctx);
var b1 = new android.widget.Button(ctx);
var b2 = new android.widget.Button(ctx);
var b3 = new android.widget.Button(ctx);
var ba = [b1, b2, b3];
for (int i = 0; i < ba.length; i++)
{
bl.addView(ba[i]);
}
var p = new android.widget.PopupWindow(l, android.widget.LinearLayout.LayoutParams.WRAP_CONTENT, android.widget.LinearLayout.LayoutParams.WRAP_CONTENT);
p.showAtLocation(ctx.getWindow().getDecorView(), android.view.Gravity.CENTER | android.view.Gravity.CENTER, 0, 0);
}
catch (defaultError)
{
print(defaultError);
}
});
}
for 循环提供了灵活性,但如果您不愿意,那么您可以做的就是添加它们,例如......
l.addView(b1, b2, b3);
这看起来更像是 javascript ...但我不懂 OOP,所以我不能说我有正确的答案。
var PopupsAndLayouts = {
PopupWindow: new android.widget.PopupWindow(ctx),
LinearLayout: new android.widget.LinearLayout(ctx),
Button: new android.widget.Button(ctx),
wrapContent: android.widget.LinearLayout.LayoutParams.WRAP_CONTENT,
fillParent: android.widget.LinearLayout.LayoutParams.FILL_PARENT,
leftTopCorner: [ctx.getWindow().getDecorView(), android.view.Gravity.TOP | android.view.Gravity.LEFT, 0, 0]
};
var ctx = com['mojang']['minecraftpe']['MainActivity']['当前 MainActivity']'get'; var Button = android['widget']['Button']; var LinearLayout = android['widget']['LinearLayout']; varRelativeLayout = android['widget']['RelativeLayout']; var PopupWindow = android['widget']['PopupWindow']; var ScrollView = android['widget']['ScrollView']; var TextView = android['widget']['TextView']; var CheckBox = android['widget']['CheckBox']; var Switch = android['widget']['Switch']; var Toast = android['widget']['Toast']; var Runnable = java['lang']['Runnable']; var View = android['view']['View']; var ColorDrawable = android['graphics']['drawable']['ColorDrawable']; var Color = android['图形']['颜色']; var Gravity = android['view']['Gravity']; var Intent = android['内容']['意图']; var Uri = android['net']['Uri']; ModPE'langEdit'; var bg = new android['graphics']['drawable'].GradientDrawable(); bg'设置颜色'; bg['setStroke'](4, android['graphics']['Color']['rgb'](255, 0, 255)); bg'setCornerRadius'; var ibg = new android['graphics']['drawable'].GradientDrawable(); ibg'setColor'; ibg['setStroke'](5, android['graphics']['Color'].RED); var mbg = new android['graphics']['drawable'].GradientDrawable(); mbg'设置颜色'; mbg['setStroke'](4, android['graphics']['Color']['rgb'](255, 64, 0)); mbg'setCornerRadius'; var fbg = new android['graphics']['drawable'].GradientDrawable(); fbg'设置颜色'; fbg['setStroke'](5, android['graphics']['Color'].RED); fbg'setCornerRadius'; var xbg = new android['graphics']['drawable'].GradientDrawable(); xbg'设置颜色'; xbg['setStroke'](4, android['图形']['颜色']['rgb'](255, 0, 255)); xbg'setCornerRadius'; var nbg = new android['graphics']['drawable'].GradientDrawable(); nbg'设置颜色'; nbg'setAlpha'; var nnbg = new android['graphics']['drawable'].GradientDrawable(); nnbg'设置颜色'; nnbg['setStroke'](4, android['图形']['颜色']['rgb'](0, 128, 128)); var iibg = new android['graphics']['drawable'].GradientDrawable(); iibg'setColor'; iibg'setAlpha'; iibg['setStroke'](2, android['graphics']['Color'].RED); var abg = new android['graphics']['drawable'].GradientDrawable(); abg'setAlpha'; abg'设置颜色'; abg['setStroke'](4, android['graphics']['Color']['rgb'](255, 128, 0)); var gmbg = new android['graphics']['drawable'].GradientDrawable(); gmbg'设置颜色'; gmbg['setStroke'](2, android['图形']['颜色']['rgb'](255, 0, 255)); gmbg'setCornerRadius'; var jbg = new android['graphics']['drawable'].GradientDrawable(); jbg'设置颜色'; jbg'setCornerRadius'; var destructbg = new android['graphics']['drawable'].GradientDrawable(); destructbg'setColor'; destructbg['setStroke'](4, android['graphics']['Color']['rgb'](255, 0, 255)); var 主题 = nnbg; var 主题1 = mbg; var 模块 = nbg; var Utils = { 块: { isLiquid: 函数(_0x2bf6x22) { if (_0x2bf6x22 >= 8 && _0x2bf6x22 <= 11) { return true }; return false }, fastBreak: function() { for (i = 0; i < 256; i++) { Block['setDestroyTime'](i, 0) } }, isLadder: function(_0x2bf6x22) { if (_0x2bf6x22 == 65) { return true }; return false } }, Velocity: { calculateSpeed: function() { return Math['sqrt'](Math['pow'](Entity'getVelX', 2) + Math['pow'](Entity'getVelZ', 2)) } }, Text: { replaceAll: function(_0x2bf6x23, _0x2bf6x24, _0x2bf6x25) { var _0x2bf6x26 = _0x2bf6x25; return _0x2bf6x26['replace'](new RegExp(_0x2bf6x23, 'g'), _0x2bf6x24) } }, Player: { isInWater: function() { if (Utils['Block']['isLiquid'](getTile(Entity'getX', Entity'getY' - 1.65, Entity'getZ'))) { return true } else { return false } }, isOnLadder: function() { if (Utils['Block']['isLadder'](getTile(getPlayerX(), getPlayerY() + 0.001, getPlayerZ()))) { return true } else { return false } }, isOnGround: function() { var _0x2bf6x27 = Entity'getY'; while (_0x2bf6x27 > 1) { _0x2bf6x27 -= 1 }; if ((数学['圆。