Skip to content

Commit

Permalink
Merge pull request #1680 from Th3C0D3R/beta
Browse files Browse the repository at this point in the history
Infoboard filter custom text
  • Loading branch information
Th3OnlyC0D3R authored Dec 11, 2020
2 parents 4507986 + 256d72b commit a70ed2f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 50 deletions.
7 changes: 7 additions & 0 deletions js/web/infoboard/css/infoboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,10 @@ table.info-table tr td {
#BackgroundInfoTable .gbg-undefined td:first-child {
background-image: url(../images/gbg-undefined.png);
}

input.textfilter{
width: 100%;
width: -moz-available; /* WebKit-based browsers will ignore this. */
width: -webkit-fill-available; /* Mozilla-based browsers will ignore this. */
width: fill-available;
}
113 changes: 63 additions & 50 deletions js/web/infoboard/js/infoboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ FoEproxy.addHandler('ConversationService', 'getOverview', (data, postData) => {
});

// when a great building where the player has invested has been levelled
FoEproxy.addHandler('BlueprintService','newReward', (data, postData) => {
FoEproxy.addHandler('BlueprintService', 'newReward', (data, postData) => {

if ( data && data['responseData'] && data['responseData'] ) {
if (data && data['responseData'] && data['responseData']) {
// save the number of returned FPs to show in the infoboard message
Info.ReturnFPPoints = ( data['responseData']['strategy_point_amount'] ) ? data.responseData.strategy_point_amount : 0;
Info.ReturnFPPoints = (data['responseData']['strategy_point_amount']) ? data.responseData.strategy_point_amount : 0;

// If the Info.OtherPlayerService_newEventgreat_building_contribution ran earlier than this
// the ReturnFPPoints was 0 so no message was posted. Therefore recreate the message using
// the stored data (and the correct value of Info.ReturnFPPoints) and post it
if ( Info.ReturnFPMessageData ){
let bd = Info.OtherPlayerService_newEventgreat_building_contribution( Info.ReturnFPMessageData );
if (Info.ReturnFPMessageData) {
let bd = Info.OtherPlayerService_newEventgreat_building_contribution(Info.ReturnFPMessageData);
Info.ReturnFPMessageData = null;
Infoboard.PostMessage(bd);
}
Expand All @@ -63,7 +63,8 @@ let Infoboard = {
InjectionLoaded: false,
PlayInfoSound: true,
SoundFile: new Audio(extUrl + 'vendor/sounds/ping.mp3'),
SavedFilter: ["auction", "gex", "gbg", "trade", "level", "msg"],
SavedFilter: ["auction", "gex", "gbg", "trade", "level", "msg", "text"],
SavedTextFilter: "",
DebugWebSocket: false,


Expand Down Expand Up @@ -117,6 +118,12 @@ let Infoboard = {
else
Infoboard.SavedFilter = JSON.parse(localStorage.getItem("infoboxSavedFilter"));

if (localStorage.getItem("infoboxTextFilter") === null)
localStorage.setItem("infoboxTextFilter", Infoboard.SavedTextFilter);
else
Infoboard.SavedTextFilter = localStorage.getItem("infoboxTextFilter");


HTML.Box({
'id': 'BackgroundInfo',
'title': i18n('Boxes.Infobox.Title'),
Expand All @@ -132,7 +139,7 @@ let Infoboard = {

} else {
return HTML.CloseOpenBox('BackgroundInfo');
}
}

let div = $('#BackgroundInfo'),
h = [];
Expand All @@ -150,6 +157,7 @@ let Infoboard = {
h.push('<li><label class="game-cursor"><input type="checkbox" data-type="trade" class="filter-msg game-cursor" ' + (Infoboard.SavedFilter.includes("trade") ? "checked" : "") + '> ' + i18n('Boxes.Infobox.FilterTrade') + '</label></li>');
h.push('<li><label class="game-cursor"><input type="checkbox" data-type="level" class="filter-msg game-cursor" ' + (Infoboard.SavedFilter.includes("level") ? "checked" : "") + '> ' + i18n('Boxes.Infobox.FilterLevel') + '</label></li>');
h.push('<li><label class="game-cursor"><input type="checkbox" data-type="msg" class="filter-msg game-cursor" ' + (Infoboard.SavedFilter.includes("msg") ? "checked" : "") + '> ' + i18n('Boxes.Infobox.FilterMessage') + '</label></li>');
h.push('<li><label class="game-cursor"><input type="text" data-type="text" placeholder="1.9|A1: M" class="textfilter filter-msg game-cursor" value=' + (Infoboard.SavedFilter.includes("text") ? Infoboard.SavedTextFilter : "") + '></label></li>');
h.push('</ul>');
h.push('</div>');

Expand Down Expand Up @@ -178,7 +186,7 @@ let Infoboard = {
msg: i18n('Boxes.Infobox.Messages.Welcome'),
});

$('#BackgroundInfo').on('click', '#infoboxTone', function() {
$('#BackgroundInfo').on('click', '#infoboxTone', function () {

let disabled = $(this).hasClass('deactivated');

Expand Down Expand Up @@ -236,10 +244,11 @@ let Infoboard = {

if ($('#BackgroundInfo').length > 0) {
let status = $('input[data-type="' + bd['class'] + '"]').prop('checked'),
textfilter = $('input[data-type="text"]').val().split("|"),
msg = bd['msg'], img = bd['img'], type = bd['type'], tr = $('<tr />');

// wenn nicht angezeigt werden soll, direkt verstecken
if (!status && bd.class !== 'welcome') {
// wenn nicht angezeigt werden soll, direkt verstecken
if ((!status || !(textfilter.some(e => msg.includes(e)))) && bd.class !== 'welcome') {
tr.hide();
}

Expand Down Expand Up @@ -269,26 +278,30 @@ let Infoboard = {
*
*/
FilterInput: () => {
$('#BackgroundInfo').on('change', '.filter-msg', function() {
$('#BackgroundInfo').on('change', '.filter-msg', function () {
let active = [];

$('.filter-msg').each(function() {
if ($(this).is(':checked')) {
$('.filter-msg').each(function () {
if ($(this).is(':checked') || ($(this).data("type") === "text" && $(this).val() !== "")) {
active.push($(this).data('type'));
if (!Infoboard.SavedFilter.includes($(this).data('type')))
Infoboard.SavedFilter.push($(this).data('type'));
} else {
}
else {
if (Infoboard.SavedFilter.includes($(this).data('type')))
Infoboard.SavedFilter.splice(Infoboard.SavedFilter.indexOf($(this).data('type')), 1);
}
});

localStorage.setItem("infoboxSavedFilter", JSON.stringify(Infoboard.SavedFilter));

$('#BackgroundInfoTable tbody tr').each(function() {
let tr = $(this), type = tr.attr('class');

if (active.some(e => type.startsWith(e)) || tr.hasClass('welcome')) {
localStorage.setItem("infoboxTextFilter", $('input[data-type="text"]').val());

$('#BackgroundInfoTable tbody tr').each(function () {
let tr = $(this),
textfilter = $('input[data-type="text"]').val().split("|"),
type = tr.attr('class');

if ((active.some(e => type.startsWith(e)) && textfilter.some(e => $(tr.children()[2]).html().includes(e))) || tr.hasClass('welcome')) {
tr.show();
} else {
tr.hide();
Expand All @@ -303,7 +316,7 @@ let Infoboard = {
*
*/
ResetBox: () => {
$('#BackgroundInfo').on('click', '.btn-reset-box', function() {
$('#BackgroundInfo').on('click', '.btn-reset-box', function () {
$('#BackgroundInfoTable tbody').html('');
});
}
Expand Down Expand Up @@ -433,8 +446,8 @@ let Info = {
*/
GuildBattlegroundService_getProvinces: (d) => {

GildFights.PrepareColors();
GildFights.PrepareColors();

let data = d[0];

let bP = GildFights.MapData['battlegroundParticipants'],
Expand Down Expand Up @@ -462,12 +475,12 @@ let Info = {
type: i18n('Boxes.Infobox.FilterGildFights'),
msg: HTML.i18nReplacer(
i18n('Boxes.Infobox.Messages.GildFightOccupied'), {
provinceName: prov['name'],
attackerColor: tc,
attackerShadow: ts,
attackerName: p['clan']['name'],
untilOccupied: moment.unix(data['lockedUntil']).format('HH:mm:ss')
}),
provinceName: prov['name'],
attackerColor: tc,
attackerShadow: ts,
attackerName: p['clan']['name'],
untilOccupied: moment.unix(data['lockedUntil']).format('HH:mm:ss')
}),
img: 'gbg-lock'
};
}
Expand Down Expand Up @@ -497,14 +510,14 @@ let Info = {
if (color) {
let tc = colors['highlight'], sc = color['highlight'],
ts = colors['shadow'], ss = color['shadow'];
t += '<span style="color:' + tc + ';text-shadow: 0 1px 1px ' + ts + '">' + p['clan']['name'] + '</span> ⚔️ <span style="color:' + sc + ';text-shadow: 0 1px 1px ' + ss + '">' + prov['name'] + '</span> (<strong>' + d['progress'] + '</strong>/<strong>' + d['maxProgress'] + '</strong>)<br>';

t += '<span style="color:' + tc + ';text-shadow: 0 1px 1px ' + ts + '">' + p['clan']['name'] + '</span> ⚔️ <span style="color:' + sc + ';text-shadow: 0 1px 1px ' + ss + '">' + prov['name'] + '</span> (<strong>' + d['progress'] + '</strong>/<strong>' + d['maxProgress'] + '</strong>)<br>';
} else {
let tc = colors['highlight'],
ts = colors['shadow'];

t += '<span style="color:' + tc + ';text-shadow: 0 1px 1px ' + ts + '">' + p['clan']['name'] + '</span> ⚔️ ' + prov['name'] + ' (<strong>' + d['progress'] + '</strong>/<strong>' + d['maxProgress'] + '</strong>)<br>';
t += '<span style="color:' + tc + ';text-shadow: 0 1px 1px ' + ts + '">' + p['clan']['name'] + '</span> ⚔️ ' + prov['name'] + ' (<strong>' + d['progress'] + '</strong>/<strong>' + d['maxProgress'] + '</strong>)<br>';

}
if (image) {
image = 'gbg-undefined';
Expand Down Expand Up @@ -537,27 +550,27 @@ let Info = {
OtherPlayerService_newEventgreat_building_contribution: (d) => {

let newFP = Info.ReturnFPPoints;
if ( d['rank'] >= 6 ){ newFP = 0; }
if (d['rank'] >= 6) { newFP = 0; }

let data = {
class: 'level',
type: 'Level-Up',
msg: HTML.i18nReplacer(
i18n('Boxes.Infobox.Messages.LevelUp'), {
player: d['other_player']['name'],
building: d['great_building_name'],
level: d['level'],
rank: d['rank'],
fps: newFP
}
player: d['other_player']['name'],
building: d['great_building_name'],
level: d['level'],
rank: d['rank'],
fps: newFP
}
)
};

// If the ReturnFPPoints is -1 the BlueprintService.newReward handler has not run yet
// so store the data and post the message from that handler (using the stored data)
// ... but only if the rank is 5 and higher (1-5), otherwise, there is no reward
// (and BlueprintService.newReward is not triggered)
if ( d['rank'] < 6 && Info.ReturnFPPoints == -1 ){
if (d['rank'] < 6 && Info.ReturnFPPoints == -1) {
Info.ReturnFPMessageData = d;
return undefined;
}
Expand All @@ -582,12 +595,12 @@ let Info = {
type: i18n('Boxes.Infobox.FilterTrade'),
msg: HTML.i18nReplacer(
i18n('Boxes.Infobox.Messages.Trade'), {
'player': d['other_player']['name'],
'offer': GoodsData[d['offer']['good_id']]['name'],
'offerValue': d['offer']['value'],
'need': GoodsData[d['need']['good_id']]['name'],
'needValue': d['need']['value']
}
'player': d['other_player']['name'],
'offer': GoodsData[d['offer']['good_id']]['name'],
'offerValue': d['offer']['value'],
'need': GoodsData[d['need']['good_id']]['name'],
'needValue': d['need']['value']
}
)
}
},
Expand All @@ -611,9 +624,9 @@ let Info = {
type: 'GEX',
msg: HTML.i18nReplacer(
i18n('Boxes.Infobox.Messages.GEX'), {
'player': d['player']['name'],
'points': HTML.Format(d['expeditionPoints'])
}
'player': d['player']['name'],
'points': HTML.Format(d['expeditionPoints'])
}
)
};
}
Expand Down

0 comments on commit a70ed2f

Please sign in to comment.