Skip to content

Commit

Permalink
[ui] add button to open inventory management any time while outside (…
Browse files Browse the repository at this point in the history
…dropping unwanted resources)
  • Loading branch information
nroutasuo committed Mar 6, 2023
1 parent 7e01c70 commit 91fe274
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 49 deletions.
10 changes: 9 additions & 1 deletion changelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
"phase": "alpha",
"final": false,
"changes": [
{
"type": "UI",
"summary": "Remove many repetitive log messages and add some new ones.",
},
{
"type": "GD",
"summary": "Add milestones and limits to evidence / rumour / favour accumulation based on milestones"
Expand All @@ -17,6 +21,10 @@
"type": "GD",
"summary": "Add breaking and repairing items"
},
{
"type": "GD",
"summary": "Add luxury resources"
},
{
"type": "GD",
"summary": "Add robots"
Expand All @@ -39,7 +47,7 @@
},
{
"type": "UI",
"summary": "Show potential crafting ingredient scavenging spots as soon as the sector is scouted"
"summary": "Many smaller UI improvements"
},
{
"type": "UI",
Expand Down
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,10 @@ <h3>Locations</h3>
</div>
</div>
<div class="unit one-quarter">
<div class="subheader" id="header-self-bag-actions"><h3>Use</h3></div>
<div id="self-bag-actions" class="actionbox">
<button id="btn-self-manage-inventory">Manage inventory</button>
</div>
<div class="subheader" id="header-self-use-items"><h3>Use</h3></div>
<div id="self-use-items" class="actionbox">
<table>
Expand Down
19 changes: 19 additions & 0 deletions src/game/PlayerActionFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,25 @@ define(['ash',
});
},

startInventoryManagement: function () {
let player = this.playerStatsNodes.head.entity;
let resultVO = new ResultVO("manage_inventory");

player.add(new PlayerActionResultComponent(resultVO));

let cb = function (isTakeAll) {
player.remove(PlayerActionResultComponent);
GameGlobals.playerActionResultsHelper.collectRewards(isTakeAll, resultVO);
GlobalSignals.inventoryChangedSignal.dispatch();
};

let options = {
forceShowInventoryManagement: true,
};

GameGlobals.uiFunctions.showResultPopup("Manage inventory", "", resultVO, cb, options);
},

logResultMessages: function (messages) {
for (let i = 0; i < messages.length; i++) {
let message = messages[i];
Expand Down
46 changes: 32 additions & 14 deletions src/game/UIFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1196,42 +1196,55 @@ define(['ash',

showInfoPopup: function (title, msg, buttonLabel, resultVO, callback, isMeta, isDismissable) {
if (!buttonLabel) buttonLabel = "Continue";
this.popupManager.showPopup(title, msg, buttonLabel, false, resultVO, callback, null, isMeta, isDismissable);
let options = {
isMeta: isMeta,
isDismissable: isDismissable,
};
this.popupManager.showPopup(title, msg, buttonLabel, false, resultVO, callback, null, options);
},

showResultPopup: function (title, msg, resultVO, callback) {
this.popupManager.showPopup(title, msg, "Continue", false, resultVO, callback);
showResultPopup: function (title, msg, resultVO, callback, options) {
this.popupManager.showPopup(title, msg, "Continue", false, resultVO, callback, null, options);
},

showConfirmation: function (msg, callback, isMeta) {
var uiFunctions = this;
var okCallback = function (e) {
let uiFunctions = this;

let okCallback = function (e) {
uiFunctions.popupManager.closePopup("common-popup");
callback();
};
var cancelCallback = function () {
let cancelCallback = function () {
uiFunctions.popupManager.closePopup("common-popup");
};
this.popupManager.showPopup("Confirmation", msg, "Confirm", "Cancel", null, okCallback, cancelCallback, isMeta);
let options = {
isMeta: isMeta,
isDismissable: false,
};

this.popupManager.showPopup("Confirmation", msg, "Confirm", "Cancel", null, okCallback, cancelCallback, options);
},

showQuestionPopup: function (title, msg, buttonLabel, cancelButtonLabel, callbackOK, callbackNo, isMeta) {
var uiFunctions = this;
var okCallback = function (e) {
let uiFunctions = this;
let okCallback = function (e) {
uiFunctions.popupManager.closePopup("common-popup");
callbackOK();
};
var cancelCallback = function () {
let cancelCallback = function () {
uiFunctions.popupManager.closePopup("common-popup");
if (callbackNo) callbackNo();
};
this.popupManager.showPopup(title, msg, buttonLabel, cancelButtonLabel, null, okCallback, cancelCallback, isMeta);
let options = {
isMeta: isMeta,
isDismissable: false,
};
this.popupManager.showPopup(title, msg, buttonLabel, cancelButtonLabel, null, okCallback, cancelCallback, options);
},

showInput: function (title, msg, defaultValue, allowCancel, confirmCallback, inputCallback) {
// TODO improve input validation (check and show feedback on input, not just on confirm)

var okCallback = function () {
let okCallback = function () {
let input = $("#common-popup input").val();
input = GameGlobals.uiFunctions.cleanUpInput(input);
let ok = input && input.length > 0 && (inputCallback ? inputCallback(input) : true);
Expand All @@ -1244,7 +1257,12 @@ define(['ash',
}
};
let cancelButtonLabel = allowCancel ? "Cancel" : null;
this.popupManager.showPopup(title, msg, "Confirm", cancelButtonLabel, null, okCallback, null, false, false);
let options = {
isMeta: false,
isDismissable: false,
};

this.popupManager.showPopup(title, msg, "Confirm", cancelButtonLabel, null, okCallback, null, options);

var uiFunctions = this;
var maxChar = 40;
Expand Down
32 changes: 18 additions & 14 deletions src/game/helpers/PlayerActionResultsHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,14 +622,16 @@ define([
return { msg: msg, replacements: replacements, values: values };
},

getRewardDiv: function (resultVO, isFight) {
var itemsComponent = this.playerStatsNodes.head.items;
var followersComponent = this.playerStatsNodes.head.followers;
var hasBag = itemsComponent.getCurrentBonus(ItemConstants.itemBonusTypes.bag) > 0;
var bagComponent = this.playerResourcesNodes.head.entity.get(BagComponent);
var isInitialSelectionValid = bagComponent.usedCapacity <= bagComponent.totalCapacity;
getRewardDiv: function (resultVO, isFight, forceShowInventoryManagement) {
forceShowInventoryManagement = forceShowInventoryManagement || false;

let itemsComponent = this.playerStatsNodes.head.items;
let followersComponent = this.playerStatsNodes.head.followers;
let hasBag = itemsComponent.getCurrentBonus(ItemConstants.itemBonusTypes.bag) > 0;
let bagComponent = this.playerResourcesNodes.head.entity.get(BagComponent);
let isInitialSelectionValid = bagComponent.usedCapacity <= bagComponent.totalCapacity;

var div = "<div id='reward-div'>";
let div = "<div id='reward-div'>";

if (resultVO.gainedResourcesFromFollowers.getTotal() > 0 || resultVO.gainedItemsFromFollowers.length > 0) {
// assuming only followers of certain type find items
Expand Down Expand Up @@ -693,7 +695,7 @@ define([
}
}

var gainedhtml = "";
let gainedhtml = "";
gainedhtml += "<ul class='resultlist resultlist-positive'>";
if (resultVO.gainedEvidence) {
gainedhtml += "<li>" + resultVO.gainedEvidence + " evidence</li>";
Expand All @@ -715,10 +717,13 @@ define([
}

gainedhtml += "</ul>";
var hasGainedStuff = gainedhtml.indexOf("<li") > 0;
if (hasGainedStuff) div += gainedhtml;
let hasGainedStuff = gainedhtml.indexOf("<li") > 0;
if (hasGainedStuff || forceShowInventoryManagement) div += gainedhtml;

let hasLostInventoryStuff = resultVO.lostResources.getTotal() > 0 || resultVO.lostItems.length > 0 || resultVO.lostCurrency > 0;
let hasLostSomething = resultVO.lostResources.getTotal() > 0 || resultVO.lostItems.length > 0 || resultVO.lostCurrency > 0 || resultVO.brokenItems > 0 || resultVO.lostFollowers.length > 0 || resultVO.gainedInjuries.length > 0 || resultVO.lostPerks.length > 0;

if (resultVO.lostResources.getTotal() > 0 || resultVO.lostItems.length > 0 || resultVO.lostCurrency > 0) {
if (hasLostInventoryStuff) {
var lostMsg = resultVO.lostItems.length > 1 ? "Lost some items." : resultVO.lostItems.length > 0 ? "Lost an item." : ""
var losthtml = "<div id='resultlist-loststuff' class='infobox'>";
var losthtml = "<div class='warning'>" + lostMsg + "</span>";
Expand All @@ -737,7 +742,7 @@ define([
}
}

if (resultVO.gainedResources.getTotal() > 0 || resultVO.gainedItems.length > 0 || !isInitialSelectionValid) {
if (resultVO.gainedResources.getTotal() > 0 || resultVO.gainedItems.length > 0 || !isInitialSelectionValid || forceShowInventoryManagement) {
var baghtml = "<div id='resultlist-inventorymanagement' class='unselectable'>";

baghtml += "<div id='resultlist-inventorymanagement-found' class='infobox inventorybox'>";
Expand All @@ -756,9 +761,8 @@ define([
}

hasGainedStuff = hasGainedStuff || resultVO.gainedResources.getTotal() > 0 || resultVO.gainedItems.length > 0 || resultVO.gainedFollowers.length > 0;
var hasLostStuff = resultVO.lostResources.getTotal() > 0 || resultVO.lostItems.length > 0 || resultVO.brokenItems > 0 || resultVO.lostFollowers.length > 0 || resultVO.gainedInjuries.length > 0 || resultVO.lostPerks.length > 0 || resultVO.lostCurrency > 0;

if (!hasGainedStuff && !hasLostStuff) {
if (!hasGainedStuff && !hasLostSomething && !forceShowInventoryManagement) {
if (isFight) div += "<p class='p-meta'>Nothing left behind.</p>"
else if (resultVO.action === "despair") div += "";
else if (resultVO.action === "clear_workshop") div += "";
Expand Down
45 changes: 27 additions & 18 deletions src/game/helpers/ui/UIPopupManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,30 @@ function (Ash, ExceptionHandler, GameGlobals, GlobalSignals) {
GlobalSignals.add(this, GlobalSignals.popupResizedSignal, this.onPopupResized);
},

showPopup: function (title, msg, okButtonLabel, cancelButtonLabel, resultVO, okCallback, cancelCallback, isMeta, isDismissable) {
// options:
// - isMeta (bool) - default false
// - isDismissable (bool) - default derived from other params
// - forceShowInventoryManagement (bool) - default false
showPopup: function (title, msg, okButtonLabel, cancelButtonLabel, resultVO, okCallback, cancelCallback, options) {
options = options || {};
let isMeta = options.isMeta || false;
let forceShowInventoryManagement = options.forceShowInventoryManagement;

let hasResult = resultVO && typeof resultVO !== 'undefined';
let hasNonEmptyResult = hasResult && !resultVO.isEmpty();
let showInventoryManagement = hasResult || forceShowInventoryManagement;

let isDismissable = options.isDismissable || (typeof options.isDismissable == 'undefined' && !showInventoryManagement && !cancelButtonLabel);

if (GameGlobals.gameState.uiStatus.isHidden && !isMeta) {
log.i("queue popup (" + title + ")", "ui");
this.hiddenQueue.push({title: title, msg: msg, okButtonLabel: okButtonLabel, cancelButtonLabel: cancelButtonLabel, resultVO: resultVO, okCallback: okCallback, cancelCallback: cancelCallback, isDismissable: isDismissable });
this.hiddenQueue.push({ title: title, msg: msg, okButtonLabel: okButtonLabel, cancelButtonLabel: cancelButtonLabel, resultVO: resultVO, okCallback: okCallback, cancelCallback: cancelCallback, options: options });
return;
}

if (this.hasOpenPopup()) {
log.i("queue popup (" + title + ")", "ui");
this.popupQueue.push({title: title, msg: msg, okButtonLabel: okButtonLabel, cancelButtonLabel: cancelButtonLabel, resultVO: resultVO, okCallback: okCallback, cancelCallback: cancelCallback, isMeta: isMeta, isDismissable: isDismissable });
this.popupQueue.push({ title: title, msg: msg, okButtonLabel: okButtonLabel, cancelButtonLabel: cancelButtonLabel, resultVO: resultVO, okCallback: okCallback, cancelCallback: cancelCallback, options: options });
return;
}

Expand All @@ -40,12 +54,10 @@ function (Ash, ExceptionHandler, GameGlobals, GlobalSignals) {
$("#common-popup p#common-popup-desc").html(msg);

// results and rewards
var hasResult = resultVO && typeof resultVO !== 'undefined';
var hasNonEmptyResult = hasResult && !resultVO.isEmpty();
GameGlobals.uiFunctions.toggle("#info-results", hasResult);
GameGlobals.uiFunctions.toggle("#info-results", showInventoryManagement);
$("#info-results").empty();
if (hasResult) {
var rewardDiv = GameGlobals.playerActionResultsHelper.getRewardDiv(resultVO, false);
if (showInventoryManagement) {
let rewardDiv = GameGlobals.playerActionResultsHelper.getRewardDiv(resultVO, false, forceShowInventoryManagement);
$("#info-results").append(rewardDiv);
GameGlobals.uiFunctions.generateCallouts("#reward-div");
}
Expand All @@ -54,16 +66,16 @@ function (Ash, ExceptionHandler, GameGlobals, GlobalSignals) {
var $defaultButton = null;
$("#common-popup .buttonbox").empty();
$("#common-popup .buttonbox").append("<button id='info-ok' class='action'>" + okButtonLabel + "</button>");
$("#info-ok").attr("action", hasResult ? "accept_inventory" : null);
$("#info-ok").toggleClass("inventory-selection-ok", hasResult);
$("#info-ok").toggleClass("action", hasResult);
$("#info-ok").attr("action", showInventoryManagement ? "accept_inventory" : null);
$("#info-ok").toggleClass("inventory-selection-ok", showInventoryManagement);
$("#info-ok").toggleClass("action", showInventoryManagement);
$("#info-ok").click(ExceptionHandler.wrapClick(function (e) {
e.stopPropagation();
popUpManager.handleOkButton(false, okCallback);
}));
$defaultButton = $("#info-ok");

var showTakeAll = hasResult && resultVO.hasSelectable();
let showTakeAll = hasResult && resultVO.hasSelectable();
if (showTakeAll) {
$("#common-popup .buttonbox").append("<button id='confirmation-takeall' class='action' action='take_all'>Take all</button>");
$("#confirmation-takeall").click(ExceptionHandler.wrapClick(function (e) {
Expand Down Expand Up @@ -100,9 +112,6 @@ function (Ash, ExceptionHandler, GameGlobals, GlobalSignals) {
GameGlobals.uiFunctions.generateButtonOverlays("#common-popup .buttonbox");
GameGlobals.uiFunctions.generateCallouts("#common-popup .buttonbox");

if (typeof isDismissable == 'undefined') {
isDismissable = !hasNonEmptyResult && !cancelButtonLabel;
}
popup.attr("data-dismissable", isDismissable);
popup.attr("data-dismissed", "false");
if (isDismissable) {
Expand Down Expand Up @@ -162,7 +171,7 @@ function (Ash, ExceptionHandler, GameGlobals, GlobalSignals) {

closeHidden: function (ok) {
if (this.hiddenQueue.length > 0) {
var hidden = this.hiddenQueue.pop();
let hidden = this.hiddenQueue.pop();
if (ok) {
if (hidden.okCallback) hidden.okCallback();
} else {
Expand Down Expand Up @@ -195,8 +204,8 @@ function (Ash, ExceptionHandler, GameGlobals, GlobalSignals) {

showQueuedPopup: function () {
if (this.popupQueue.length > 0) {
var queued = this.popupQueue.pop();
this.showPopup(queued.title, queued.msg, queued.okButtonLabel, queued.cancelButtonLabel, queued.resultVO, queued.okCallback, queued.cancelCallback, queued.isMeta);
let queued = this.popupQueue.pop();
this.showPopup(queued.title, queued.msg, queued.okButtonLabel, queued.cancelButtonLabel, queued.resultVO, queued.okCallback, queued.cancelCallback, queued.options);
}
},

Expand Down
17 changes: 17 additions & 0 deletions src/game/systems/ui/UIOutBagSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ define([

initElements: function () {
this.initItemSlots();
this.initBagActions();
this.initCraftingButtons();
this.initUseItemButtons();
this.initRepairItemButtons();
Expand All @@ -71,6 +72,10 @@ define([
});
});
},

initBagActions: function() {
$("#btn-self-manage-inventory").click($.proxy(this.showInventoryManageemntPopup, this));
},

initCraftingButtons: function () {
var itemDefinitions = this.getCraftableItemDefinitionsByType();
Expand Down Expand Up @@ -189,6 +194,7 @@ define([
}

this.updateItems();
this.updateBagActions();
this.updateUseItems();
this.updateRepairItems();
this.updateCrafting();
Expand All @@ -214,6 +220,13 @@ define([
GameGlobals.uiFunctions.toggle("#switch-bag .bubble", bubbleNumber > 0 || isStatIncreaseAvailable);
});
},

updateBagActions: function () {
let inCamp = this.itemNodes.head.entity.get(PositionComponent).inCamp;

GameGlobals.uiFunctions.toggle("#header-self-bag-actions", !inCamp);
GameGlobals.uiFunctions.toggle("#self-bag-actions", !inCamp);
},

updateItems: function () {
this.updateItemLists();
Expand Down Expand Up @@ -529,6 +542,10 @@ define([
});
},

showInventoryManageemntPopup: function () {
GameGlobals.playerActionFunctions.startInventoryManagement();
},

onObsoleteToggled: function () {
this.updateCrafting();
},
Expand Down
2 changes: 1 addition & 1 deletion src/game/systems/ui/UIOutFightSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ define([
GameGlobals.uiFunctions.toggle("#fight-results-lose-items", !isWon && false);

GameGlobals.playerActionResultsHelper.preCollectRewards(resultVO);
$("#fight-popup-results").html(GameGlobals.playerActionResultsHelper.getRewardDiv(resultVO, true));
$("#fight-popup-results").html(GameGlobals.playerActionResultsHelper.getRewardDiv(resultVO, true, false));
GameGlobals.uiFunctions.generateCallouts("#fight-popup-results");
},

Expand Down
4 changes: 3 additions & 1 deletion src/game/vos/ResultVO.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ define(['ash', 'game/vos/ResourcesVO'], function (Ash, ResourcesVO) {
&& this.gainedEvidence == 0
&& this.gainedRumours == 0
&& this.gainedFavour == 0
&& this.gainedReputation == 0;
&& this.gainedReputation == 0
&& this.discardedItems.length == 0
&& this.discardedResources.getTotal() == 0;
},

clone: function () {
Expand Down

0 comments on commit 91fe274

Please sign in to comment.