Skip to content

Commit

Permalink
Active state for the buttons; deactivate by clicking twice.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Bruch committed Feb 17, 2024
1 parent dba6a72 commit 659495c
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 17 deletions.
Binary file modified Sources/ButtonFilled3.psd
Binary file not shown.
Binary file added images/buttons/button-digging-active.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/buttons/button-digging.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/buttons/button-drop-active.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/buttons/button-scan-active.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/buttons/button-scan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions scripts/gameStage.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,12 @@ var gameStage = function() {
}

function handleTileRightClick(mapTile, mouseEvent) {
interactionHelper.setNextMode(null);

mapTile.toggleTileMarking();
if (interactionHelper.getNextMode()) {
interactionHelper.setNextMode(null);
}
else {
mapTile.toggleTileMarking();
}
}

function handleTileReveal(mapTile) {
Expand Down
6 changes: 6 additions & 0 deletions scripts/interactionHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ var interactionHelper = function() {
}

function setNextMode(interaction) {
if (interaction) {
interactionMenuHelper.setButtonActive(interaction);
}
else {
interactionMenuHelper.setAllInactive();
}
selectedInteraction = interaction;
}

Expand Down
62 changes: 48 additions & 14 deletions scripts/interactionMenuHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,86 @@ var interactionMenuHelper = function() {

async function addButton(interactionType, disable) {
var asset = await PIXI.Assets.load('images/buttons/button-' + interactionType + '.png');
var assetActive = await PIXI.Assets.load('images/buttons/button-' + interactionType + '-active.png');
var sprite = new PIXI.Sprite(asset);
buttonRegister[interactionType] = sprite;
var spriteActive = new PIXI.Sprite(assetActive);
spriteActive.alpha = 0;

sprite.x = buttonPosition;
sprite.y = appInstance.view.height - 70;


sprite.on('click', function() {
interactionHelper.setNextMode(interactionType);
var container = new PIXI.Container();
container.eventMode = 'static';
container.cursor = 'pointer';
container.x = buttonPosition;
container.y = appInstance.view.height - 70;
container.width = 70;
container.height = 70;
container.addChild(sprite);
container.addChild(spriteActive);

container.on('click', function() {
if (interactionType === interactionHelper.getNextMode()) {
interactionHelper.setNextMode(null);
}
else {
interactionHelper.setNextMode(interactionType);
}
});

appInstance.stage.addChild(sprite);
appInstance.stage.addChild(container);

if (disable) {
sprite.eventMode = 'none';
container.eventMode = 'none';
sprite.alpha = 0.5;
}
else {
sprite.eventMode = 'static';
container.eventMode = 'static';
}

buttonPosition += 80;


buttonRegister[interactionType] = sprite;
buttonRegister[interactionType + '-active'] = spriteActive;
buttonRegister[interactionType + '-container'] = container;
}

function setButtonActive(interactionType) {
setAllInactive();

soundHelper.play(soundHelper.soundKey.Interaction);
buttonRegister[interactionType + '-active'].alpha = 1;
}

function setAllInactive() {
buttonRegister[interactionHelper.interactionTypes.Digging + '-active'].alpha = 0;
buttonRegister[interactionHelper.interactionTypes.Scan + '-active'].alpha = 0;
buttonRegister[interactionHelper.interactionTypes.Drop + '-active'].alpha = 0;
}

function handleStatUpdate(stats) {
if (stats.credits >= 2) {
buttonRegister[interactionHelper.interactionTypes.Scan].eventMode = 'static';
buttonRegister[interactionHelper.interactionTypes.Scan + '-container'].eventMode = 'static';
buttonRegister[interactionHelper.interactionTypes.Scan].alpha = 1;
}
else {
buttonRegister[interactionHelper.interactionTypes.Scan].eventMode = 'none';
buttonRegister[interactionHelper.interactionTypes.Scan + '-container'].eventMode = 'none';
buttonRegister[interactionHelper.interactionTypes.Scan].alpha = 0.5;
}

if (stats.credits >= 8) {
buttonRegister[interactionHelper.interactionTypes.Drop].eventMode = 'static';
buttonRegister[interactionHelper.interactionTypes.Drop + '-container'].eventMode = 'static';
buttonRegister[interactionHelper.interactionTypes.Drop].alpha = 1;
}
else {
buttonRegister[interactionHelper.interactionTypes.Drop].eventMode = 'none';
buttonRegister[interactionHelper.interactionTypes.Drop + '-container'].eventMode = 'none';
buttonRegister[interactionHelper.interactionTypes.Drop].alpha = 0.5;
}
}

return {
initialize: initialize,
handleStatUpdate: handleStatUpdate
handleStatUpdate: handleStatUpdate,
setButtonActive: setButtonActive,
setAllInactive: setAllInactive
}
}();

0 comments on commit 659495c

Please sign in to comment.