Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions server/ServerNetworkEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,16 @@ var ServerNetworkEvents = {
}
},

_onCustomButtonClick: function (data, clientId) {
var player = ige.game.getPlayerByClientId(clientId);
if(player) {
ige.trigger.fire("playerClicksCustomButton", {
playerId: player.id(),
buttonId: data.buttonId
})
}
},

_onSomeBullshit: function () {
//bullshit
}
Expand Down
3 changes: 2 additions & 1 deletion server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,8 @@ var Server = IgeClass.extend({
ige.network.define('playerCustomInput', self._onPlayerCustomInput);
ige.network.define('playerAbsoluteAngle', self._onPlayerAbsoluteAngle);
ige.network.define('playerDialogueSubmit', self._onPlayerDialogueSubmit);

ige.network.define('playerButtonClick', self._onCustomButtonClick);

ige.network.define('buyItem', self._onBuyItem);
ige.network.define('buyUnit', self._onBuyUnit);
ige.network.define('buySkin', self._onBuySkin);
Expand Down
25 changes: 24 additions & 1 deletion src/gameClasses/ClientNetworkEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,30 @@ var ClientNetworkEvents = {
case 'showCustomModal':
ige.playerUi.showCustomModal(data);
break;

case 'addCustomButton':
ige.playerUi.addCustomButton(data);
break;
case 'removeCustomButton':
ige.playerUi.removeCustomButton(data.buttonId);
break;
case 'hideCustomButton':
ige.playerUi.hideCustomButton(data.buttonId);
break;
case 'showCustomButton':
ige.playerUi.showCustomButton(data.buttonId);
break;
case 'toggleCustomButtonVisibility':
ige.playerUi.toggleCustomButtonVisibility(data.buttonId);
break;
case 'disableCustomButton':
ige.playerUi.disableCustomButton(data.buttonId);
break;
case 'enableCustomButton':
ige.playerUi.enableCustomButton(data.buttonId);
break;
case 'toggleCustomButtonUsability':
ige.playerUi.toggleCustomButtonUsability(data.buttonId);
break;
case 'openWebsite':
ige.playerUi.openWebsite(data);
break;
Expand Down
88 changes: 88 additions & 0 deletions src/gameClasses/components/script/ActionComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2586,6 +2586,94 @@ var ActionComponent = IgeEntity.extend({
player.loadPersistentData();
}
break;

case 'addCustomButtonForPlayer':
var player = ige.variable.getValue(action.player, vars);

if(player && player._stats && player._stats.clientId) {
ige.network.send('ui', {
command: 'addCustomButton',
button: action.button
}, player._stats.clientId);
};
break;

case 'removeCustomButtonFromPlayer':
var player = ige.variable.getValue(action.player, vars);

if(player && player._stats && player._stats.clientId) {
ige.network.send('ui', {
command: 'removeCustomButton',
buttonId: action.id
}, player._stats.clientId);
};
break;

case 'hideCustomButtonFromPlayer': // hides existing custom button from player
var player = ige.variable.getValue(action.player, vars);

if(player && player._stats && player._stats.clientId) {
ige.network.send('ui', {
command: 'hideCustomButton',
buttonId: action.id
}, player._stats.clientId);
};
break;

case 'showCustomButtonForPlayer': // show existing custom button from player
var player = ige.variable.getValue(action.player, vars);

if(player && player._stats && player._stats.clientId) {
ige.network.send('ui', {
command: 'showCustomButton',
buttonId: action.id
}, player._stats.clientId);
};
break;

case 'toggleCustomButtonVisibilityForPlayer': // toggles visibility of a button to player
var player = ige.variable.getValue(action.player, vars);

if(player && player._stats && player._stats.clientId) {
ige.network.send('ui', {
command: 'toggleCustomButtonVisibility',
buttonId: action.id
}, player._stats.clientId);
};
break;

case 'disableCustomButtonForPlayer':
var player = ige.variable.getValue(action.player, vars);

if(player && player._stats && player._stats.clientId) {
ige.network.send('ui', {
command: 'disableCustomButton',
buttonId: action.id
}, player._stats.clientId);
};
break;

case 'enableCustomButtonForPlayer':
var player = ige.variable.getValue(action.player, vars);

if(player && player._stats && player._stats.clientId) {
ige.network.send('ui', {
command: 'enableCustomButton',
buttonId: action.id
}, player._stats.clientId);
}
break;

case 'toggleCustomButtonUsabilityForPlyer':
var player = ige.variable.getValue(action.player, vars);

if(player && player._stats && player._stats.clientId) {
ige.network.send('ui', {
command: 'toggleCustomButtonUsability',
buttonId: action.id
}, player._stats.clientId);
};
break;

case 'comment':
break;
Expand Down
63 changes: 62 additions & 1 deletion src/gameClasses/components/ui/PlayerUiComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ var PlayerUiComponent = IgeEntity.extend({
var self = this;

config.isDismissible = config.isDismissible === undefined ? true : !!(config.isDismissible);
var newWin = window.open(config.url);
var newWin = window.open(config.url)

if (!newWin || newWin.closed || typeof newWin.closed == 'undefined') {
swal({
Expand Down Expand Up @@ -443,6 +443,67 @@ var PlayerUiComponent = IgeEntity.extend({
option: optionId
});
}
},
addCustomButton: function (data) {
if(data && typeof data.button == 'object') {
var button = document.createElement('button');
var { text, id, type, height, width, x, y } = data.button;
button.id = `${id ?? "default"}`;
button.className = `btn btn-${type ?? "secondary"}`;
button.onclick = () => {
ige.network.send('playerButtonClick', {
buttonId: button.id
})
};
button.innerText = text;
$(button).css({
"height": `${height}px`,
"width": `${width}px`,
"position": "absolute",
"top": `${y}`,
"left": `${x}`
});
document.getElementById("game-div").appendChild(button);
};
},
removeCustomButton: function (id) {
if(id) {
$(`#${id}`).remove();
};
},
hideCustomButton: function (id) {
if(id) {
$(`#${id}`).hide();
};
},
showCustomButton: function (id) {
if(id) {
$(`#${id}`).show();
};
},
toggleCustomButtonVisibility: function (id) {
if(id) {
$(`#${id}`).toggle();
};
},
disableCustomButton: function (id) {
if(id) {
$(`#${id}`).prop({ disabled: true });
};
},
enableCustomButton: function (id) {
if(id) {
$(`#${id}`).prop({ disabled: false });
};
},
toggleCustomButtonUsability: function (id) {
if(id) {
if($(`#${id}`).prop('disabled')) {
$(`#${id}`).prop({ disabled: false })
} else {
$(`#${id}`).prop({ disabled: true })
}
}
}
});

Expand Down