Skip to content

Commit e966655

Browse files
committed
Add support for links in text with drop-down menus
1 parent cf0c553 commit e966655

File tree

5 files changed

+57
-4
lines changed

5 files changed

+57
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
* URQL interpreter:
88
+ Added: UTF-8 encoding support for games and plugins.
9+
+ Added: Ability to add a drop-down menu with a list of actions to links in the text and hide individual menu items depending on the values ??of special variables.
910
+ Added: Ability to execute JavaScript code from URQL code and retrieve its result using the javascript system variable.
1011
+ Added: Ability to read any file from the game package and get its contents as text using the fileread system variable.
1112
+ Added: System variables image_caption, time, date (only when urq_mode specific rules are absent), urqw_title, urqw_game_ifid, urqw_game_lang, urqw_version.

css/style.css

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ div.clearfix + div,
5454
margin: 5px 0;
5555
max-width: 100%;
5656
box-sizing: border-box;
57-
border: 1px solid currentColor; /* Рамка цвета текста */
57+
border: 1px solid currentColor; /* Text color frame */
5858
padding: 10px;
5959
border-radius: 5px;
6060
}
@@ -128,6 +128,18 @@ div.clearfix + div,
128128
}
129129

130130

131+
/* Drop-down menu links */
132+
133+
.dropdownmenulinks > ul.dropdown-menu > li {
134+
padding: 3px 20px;
135+
color: #939191;
136+
}
137+
138+
.dropdownmenulinks > ul.dropdown-menu > li > a {
139+
padding: 0;
140+
}
141+
142+
131143
/** footer */
132144

133145
html {

js/Client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ var ul = $('<ul role="presentation" class="dropdown-menu">');
392392
* @param {int} action
393393
*/
394394
Client.prototype.convertToLink = function(text, action) {
395-
return "<a data-action='" + action + "' class='button' href='#'>" + text + "</a>";
395+
return '<a data-action="' + action + '" class="button" href="#">' + text + '</a>';
396396
};
397397

398398
/**

js/Parser.js

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (C) 2015, 2018 Akela <akela88@bk.ru>
2+
* Copyright (C) 2015, 2017, 2018 Akela <akela88@bk.ru>
33
* Copyright (C) 2025 Nikita Tseykovets <tseikovets@rambler.ru>
44
* This file is part of UrqW.
55
* SPDX-License-Identifier: GPL-2.0-or-later
@@ -245,8 +245,47 @@ Parser.prototype.openLinks = function(line) {
245245

246246
if (exp.indexOf('|') > 0) {
247247
var exptmp = exp.split('|');
248-
command = exptmp.slice(1).join('|').trim();
248+
command = exptmp[1].trim();
249249
text = exptmp[0].trim();
250+
251+
// Link with drop-down menu
252+
if ((exp.match(/\|/g) || []).length > 1) {
253+
var command2 = exptmp[2].split(',');
254+
255+
var links = [];
256+
var action = '';
257+
var label;
258+
for (var i = 0; i < command2.length; i++) {
259+
label = command + '_' + command2[i].trim();
260+
if (Game.getVar('hide_' + label) > 0) {
261+
continue;
262+
}
263+
if (Game.getLabel(label)) {
264+
action = label;
265+
} else {
266+
action = '';
267+
// The label was not found, so there is no such action.
268+
// You can execute something here, for example:
269+
// action = `pln You cannot ${command2[i].trim()} ${command}!`;
270+
}
271+
272+
var actionNum = GlobalPlayer.link(action);
273+
links.push(`<li><a data-action="${actionNum}" class="button" href="#">${command2[i].replace(/_/g, ' ').trim()}</a></li>`);
274+
}
275+
276+
if (links.length == 0) {
277+
return text;
278+
} else {
279+
return '<span class="dropdown dropdownmenulinks">' +
280+
'<a href="#" class="dropdown dropdown-toggle" type="button" id="dropdownMenu' + actionNum + '" data-toggle="dropdown">' +
281+
text +
282+
'</a>' +
283+
'<ul class="dropdown-menu">' +
284+
links.join('') +
285+
'</ul>' +
286+
'</span>';
287+
}
288+
}
250289
} else {
251290
command = exp.trim();
252291
text = exp;

md/ru/other/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
* Интерпретатор URQL:
88
+ Добавлено: Поддержка кодировки UTF-8 для игр и плагинов.
9+
+ Добавлено: Возможность добавить ссылкам в тексте выпадающее меню со списком действий и скрывать отдельные пункты меню в зависимости от значений специальных переменных.
910
+ Добавлено: Возможность выполнить код JavaScript из кода URQL и получить его результат с помощью системной переменной javascript.
1011
+ Добавлено: Возможность прочитать любой файл из пакета игры и получить его содержимое как текст с помощью системной переменной fileread.
1112
+ Добавлено: Системные переменные image_caption, time, date (только при отсутствии специальных правил urq_mode), urqw_title, urqw_game_ifid, urqw_game_lang, urqw_version.

0 commit comments

Comments
 (0)