Parse menu statement
This commit is contained in:
parent
e4f98c610a
commit
bbb9896794
@ -6,7 +6,7 @@ html, body {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
html, body, div, span, p {
|
||||
html, body, div, span, p, li, ul {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
@ -52,3 +52,35 @@ body {
|
||||
position: absolute;
|
||||
bottom: 0px;
|
||||
}
|
||||
|
||||
#menu {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
top: 0;
|
||||
text-align: center;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
padding: 10px;
|
||||
color: white;
|
||||
}
|
||||
#menuTitle {
|
||||
font-size: 120%;
|
||||
margin: 16px 0;
|
||||
}
|
||||
#menuChoose {
|
||||
list-style: none;
|
||||
width: 70%;
|
||||
margin: 0 auto;
|
||||
color: #eee;
|
||||
}
|
||||
#menuChoose li {
|
||||
display: block;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
padding: 5px;
|
||||
margin: 5px 10px;
|
||||
}
|
||||
#menuChoose li:hover {
|
||||
background-color: rgba(200, 200, 200, 0.5);
|
||||
cursor: pointer;
|
||||
color: #fff;
|
||||
}
|
@ -26,6 +26,11 @@
|
||||
<div id="textAuthor"></div>
|
||||
<div id="textContent"></div>
|
||||
</div>
|
||||
<div id="menu">
|
||||
<p id="menuTitle">Title</p>
|
||||
<ul id="menuChoose">
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -19,6 +19,11 @@ Parser.prototype.getInstance = function () {
|
||||
return this;
|
||||
};
|
||||
|
||||
Parser.prototype.setPosition = function (position) {
|
||||
this.position = position;
|
||||
this.next();
|
||||
};
|
||||
|
||||
Parser.prototype.jumpLabel = function (label) {
|
||||
if (label in this.labels) {
|
||||
this.position = this.labels[label];
|
||||
@ -72,7 +77,7 @@ Parser.prototype.statement = function() {
|
||||
if (this.match(token, TokenType.JUMP)) return this.jump();
|
||||
if (this.match(token, TokenType.IF)) return this.ifStatement();
|
||||
|
||||
/*if (this.lookMatch(1, TokenType.COLON)) {
|
||||
if (this.lookMatch(1, TokenType.COLON)) {
|
||||
// menu:
|
||||
if (this.match(token, TokenType.MENU)) return this.menu();
|
||||
|
||||
@ -87,7 +92,7 @@ Parser.prototype.statement = function() {
|
||||
if (this.hasEndIf) this.position += this.skipIf();
|
||||
return false;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
// Текст с именем автора реплики.
|
||||
if (this.lookMatch(1, TokenType.TEXT) && this.match(token, TokenType.WORD)) {
|
||||
@ -323,6 +328,48 @@ Parser.prototype.playAmbience = function() {
|
||||
return false;
|
||||
};
|
||||
|
||||
Parser.prototype.menu = function() {
|
||||
// menu: title?
|
||||
this.consume(TokenType.COLON);
|
||||
|
||||
var title = "";
|
||||
if (this.lookMatch(0, TokenType.TEXT) && !this.lookMatch(1, TokenType.COLON)) {
|
||||
title = this.consume(TokenType.TEXT).getText();
|
||||
}
|
||||
|
||||
if (!this.hasEndMenu) return false;
|
||||
// Ищем элементы выбора
|
||||
var menu = new Menu(title);
|
||||
var pos = 0;
|
||||
var level = 1; // уровень вложенности меню
|
||||
while (true) {
|
||||
// Расчёт уровня меню.
|
||||
if (this.lookMatch(pos, TokenType.MENU) && this.lookMatch(pos + 1, TokenType.COLON)) {
|
||||
level++;
|
||||
pos++;
|
||||
}
|
||||
if (this.lookMatch(pos, TokenType.ENDMENU)) {
|
||||
level--;
|
||||
// Завершаем работу по достижению ENDMENU первого уровня.
|
||||
if (level <= 0) break;
|
||||
}
|
||||
|
||||
if (level == 1) {
|
||||
// Добавляем только пункты из меню первого уровня.
|
||||
if (this.lookMatch(pos, TokenType.TEXT) && this.lookMatch(pos + 1, TokenType.COLON)) {
|
||||
menu.addItem(this.get(pos).getText(), this.position + pos + 2);
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.lookMatch(pos, TokenType.EOF)) return false;
|
||||
pos++;
|
||||
}
|
||||
|
||||
ViewActivity.getInstance().menu(menu);
|
||||
return true;
|
||||
};
|
||||
|
||||
Parser.prototype.jump = function() {
|
||||
var labelName = this.consume(TokenType.WORD).getText();
|
||||
this.jumpLabel(labelName);
|
||||
|
@ -76,3 +76,21 @@ var PathResolver = new function () {
|
||||
return path;
|
||||
};
|
||||
};
|
||||
|
||||
function Menu(title) {
|
||||
this.title = title;
|
||||
this.items = new Array();
|
||||
}
|
||||
|
||||
Menu.prototype.getTitle = function () { return this.title; };
|
||||
|
||||
Menu.prototype.getItems = function () { return this.items; };
|
||||
|
||||
Menu.prototype.addItem = function (name, position) {
|
||||
this.items.push({name: name, position: position});
|
||||
};
|
||||
|
||||
Menu.prototype.getPosition = function (itemIndex) {
|
||||
return this.items[itemIndex].position;
|
||||
};
|
||||
|
||||
|
@ -26,6 +26,8 @@ function Views(parser) {
|
||||
Views.blockTap = false;
|
||||
if (!Views.cancelNextStep) parser.next();
|
||||
};
|
||||
|
||||
$('#menu').hide();
|
||||
}
|
||||
|
||||
Views.prototype.getInstance = function () {
|
||||
@ -34,6 +36,7 @@ Views.prototype.getInstance = function () {
|
||||
|
||||
Views.prototype.onTouch = function (e) {
|
||||
if (this.blockTap) return;
|
||||
if ($('#menu').is(":visible")) return;
|
||||
|
||||
this.cancelNextStep = true;
|
||||
this.parser.next();
|
||||
@ -290,6 +293,30 @@ Views.prototype.showMap = function () {
|
||||
};
|
||||
|
||||
Views.prototype.menu = function (menu) {
|
||||
if (!TextUtils.isEmpty(menu.getTitle())) {
|
||||
$('#menuTitle').text(menu.getTitle());
|
||||
} else {
|
||||
$('#menuTitle').text('Выберите: ');
|
||||
}
|
||||
$('#menuChoose').empty();
|
||||
var items = menu.getItems();
|
||||
for(var i = 0; i < items.length; i++) {
|
||||
var li = $('<li>', {text: items[i].name});
|
||||
li.click(this.createMenuItemClickFunction(i, menu));
|
||||
li.appendTo($('#menuChoose'));
|
||||
}
|
||||
$('#menu').show();
|
||||
};
|
||||
|
||||
Views.prototype.createMenuItemClickFunction = function (index, menu) {
|
||||
var views = this;
|
||||
return function () {
|
||||
$('#menu').hide();
|
||||
views.parser.setPosition(menu.getPosition(index));
|
||||
};
|
||||
};
|
||||
|
||||
Views.prototype.showGameMenuDialog = function (menu) {
|
||||
};
|
||||
|
||||
Views.prototype.music = function (name, fade) {
|
||||
|
Loading…
Reference in New Issue
Block a user