main.js
var handle={
OnStoryStart:OnStoryStart,
};
RegGameHandler(handle);
function OnStoryStart(){
// 初级用法,支持系统内置数据格式
var heros = Story.GetHeros();
//var groups = Story.GetGroups();
//var armys = Story.GetArmys();
//var buildings = Story.GetBuildings();
var param = {
title:"请选择一名武将",
data:heros, //armys or buildings or groups
min_selection:1,
max_selection:1,
force_selection:false,
};
var selected = UI.ShowList(param);
if (selected == null){
console.log("传入数据异常");
return;
}
if (selected.length > 0){
for (var i=0 ;i<selected.length; i++){
var heroid = selected[i];
console.log("选择了:"+heroid);
}
}else{
console.log("选择了取消");
}
// 高级用法,支持自定义格式数据
var datalist = [
["保国",69,170,80],
["大理石",23,200,200],
];
var list_config = {
tabs:["一般","二般"],
titles:[
{
tabid:-1,
text:"姓名",
width:64,
halign:0
},
{
tabid:0,
text:"年龄",
width:64,
halign:0
},
{
tabid:1,
text:"身高",
width:64,
halign:0
},
{
tabid:1,
text:"体重",
width:64,
halign:0
},
]
};
var param_2 = {
title:"请选择一个",
config:list_config,
data:datalist,
min_selection:1,
max_selection:1,
force_selection:false,
};
var selected = UI.ShowList(param_2);
// 如果玩家点击取消,selected == null
// 如果玩家选择了第一项并确定,selected为选择项目索引的列表[0]
if (selected != null){
console.log("玩家选择了:")
for (var idx of selected){
console.log(datalist[idx]);
}
}else{
console.log("玩家啥也没选");
}
}