Various improvements

You can now right click empty slots to insert one from swap.
Added unique sounds for the swap slot count incrementing/decrementing.
Material placement now plays sounds.
This commit is contained in:
Kae 2023-08-18 23:14:53 +10:00
parent cd36a269fd
commit f6f91b18e8
15 changed files with 76 additions and 28 deletions

View File

@ -1,7 +1,8 @@
{
"paneLayout" : {
"portrait" : {
"renderHumanoid" : true
}
"paneLayout" : { "portrait" : { "renderHumanoid" : true } },
"sounds" : {
"someup" : [ "/sfx/interface/inventory_someup.ogg" ],
"somedown" : [ "/sfx/interface/inventory_somedown.ogg" ]
}
}

Binary file not shown.

Binary file not shown.

View File

@ -35,27 +35,29 @@ InventoryPane::InventoryPane(MainInterface* parent, PlayerPtr player, ContainerI
auto itemGrid = convert<ItemGridWidget>(widget);
InventorySlot inventorySlot = BagSlot(bagType, itemGrid->selectedIndex());
auto inventory = m_player->inventory();
if (context()->shiftHeld()) {
if (auto sourceItem = itemGrid->selectedItem()) {
if (auto activeMerchantPane = m_parent->activeMerchantPane()) {
auto remainder = activeMerchantPane->addItems(m_player->inventory()->takeSlot(inventorySlot));
auto remainder = activeMerchantPane->addItems(inventory->takeSlot(inventorySlot));
if (remainder && !remainder->empty())
m_player->inventory()->setItem(inventorySlot, remainder);
inventory->setItem(inventorySlot, remainder);
} else if (m_containerInteractor->containerOpen()) {
m_player->inventory()->takeSlot(inventorySlot);
inventory->takeSlot(inventorySlot);
m_containerInteractor->addToContainer(sourceItem);
m_containerSource = inventorySlot;
m_expectingSwap = true;
}
}
} else {
m_player->inventory()->shiftSwap(inventorySlot);
inventory->shiftSwap(inventorySlot);
}
};
auto rightClickCallback = [this](InventorySlot slot) {
if (ItemPtr slotItem = m_player->inventory()->itemsAt(slot)) {
auto swapItem = m_player->inventory()->swapSlotItem();
auto inventory = m_player->inventory();
if (ItemPtr slotItem = inventory->itemsAt(slot)) {
auto swapItem = inventory->swapSlotItem();
if (!swapItem || swapItem->empty() || swapItem->couldStack(slotItem)) {
uint64_t count = swapItem ? swapItem->couldStack(slotItem) : slotItem->maxStack();
if (context()->shiftHeld())
@ -67,14 +69,27 @@ InventoryPane::InventoryPane(MainInterface* parent, PlayerPtr player, ContainerI
if (swapItem)
swapItem->stackWith(taken);
else
m_player->inventory()->setSwapSlotItem(taken);
inventory->setSwapSlotItem(taken);
}
} else if (auto augment = as<AugmentItem>(swapItem)) {
if (auto augmented = augment->applyTo(slotItem))
m_player->inventory()->setItem(slot, augmented);
inventory->setItem(slot, augmented);
}
}
else {
auto swapSlot = inventory->swapSlotItem();
if (auto es = slot.ptr<EquipmentSlot>()) {
if (inventory->itemAllowedAsEquipment(swapSlot, *es))
inventory->setItem(slot, swapSlot->take(1));
} else if (slot.is<TrashSlot>()) {
inventory->setItem(slot, swapSlot->take(1));
} else if (auto bs = slot.ptr<BagSlot>()) {
if (inventory->itemAllowedInBag(swapSlot, bs->first))
inventory->setItem(slot, swapSlot->take(1));
}
}
};
auto bagGridCallback = [rightClickCallback](String const& bagType, Widget* widget) {
auto slot = BagSlot(bagType, convert<ItemGridWidget>(widget)->selectedIndex());
rightClickCallback(slot);
@ -163,6 +178,8 @@ InventoryPane::InventoryPane(MainInterface* parent, PlayerPtr player, ContainerI
m_currentSwapSlotItem = item->descriptor();
m_pickUpSounds = jsonToStringList(config.get("sounds").get("pickup"));
m_putDownSounds = jsonToStringList(config.get("sounds").get("putdown"));
m_someUpSounds = jsonToStringList(config.get("sounds").get("someup"));
m_someDownSounds = jsonToStringList(config.get("sounds").get("somedown"));
}
void InventoryPane::displayed() {
@ -406,10 +423,12 @@ void InventoryPane::update(float dt) {
}
if (auto item = inventory->swapSlotItem()) {
if (!m_currentSwapSlotItem || !item->matches(*m_currentSwapSlotItem, true) || item->count() > m_currentSwapSlotItem->count())
if (!m_currentSwapSlotItem || !item->matches(*m_currentSwapSlotItem, true))
context->playAudio(RandomSource().randFrom(m_pickUpSounds));
else if (item->count() > m_currentSwapSlotItem->count())
context->playAudio(RandomSource().randFrom(m_someUpSounds));
else if (item->count() < m_currentSwapSlotItem->count())
context->playAudio(RandomSource().randFrom(m_putDownSounds));
context->playAudio(RandomSource().randFrom(m_someDownSounds));
m_currentSwapSlotItem = item->descriptor();
} else {

View File

@ -58,6 +58,8 @@ private:
StringList m_pickUpSounds;
StringList m_putDownSounds;
StringList m_someUpSounds;
StringList m_someDownSounds;
Maybe<ItemDescriptor> m_currentSwapSlotItem;
List<ImageWidgetPtr> m_disabledTechOverlays;

View File

@ -1024,7 +1024,7 @@ float Npc::beamGunRadius() const {
void Npc::addParticles(List<Particle> const&) {}
void Npc::addSound(String const&, float) {}
void Npc::addSound(String const&, float, float) {}
bool Npc::inToolRange() const {
return true;

View File

@ -147,7 +147,7 @@ public:
Vec4B favoriteColor() const override;
float beamGunRadius() const override;
void addParticles(List<Particle> const& particles) override;
void addSound(String const& sound, float volume = 1.0f) override;
void addSound(String const& sound, float volume = 1.0f, float pitch = 1.0f) override;
bool inToolRange() const override;
bool inToolRange(Vec2F const& position) const override;
void addEphemeralStatusEffects(List<EphemeralStatusEffect> const& statusEffects) override;

View File

@ -412,8 +412,8 @@ void Player::addParticles(List<Particle> const& particles) {
m_callbackParticles.appendAll(particles);
}
void Player::addSound(String const& sound, float volume) {
m_callbackSounds.append({sound, volume});
void Player::addSound(String const& sound, float volume, float pitch) {
m_callbackSounds.emplaceAppend(sound, volume, pitch);
}
void Player::addEphemeralStatusEffects(List<EphemeralStatusEffect> const& statusEffects) {
@ -1100,8 +1100,9 @@ void Player::render(RenderCallback* renderCallback) {
renderCallback->addAudios(m_statusController->pullNewAudios());
for (auto const& p : take(m_callbackSounds)) {
auto audio = make_shared<AudioInstance>(*Root::singleton().assets()->audio(p.first));
audio->setVolume(p.second);
auto audio = make_shared<AudioInstance>(*Root::singleton().assets()->audio(get<0>(p)));
audio->setVolume(get<1>(p));
audio->setPitchMultiplier(get<2>(p));
audio->setPosition(position());
renderCallback->addAudio(move(audio));
}

View File

@ -342,7 +342,7 @@ public:
bool inInteractionRange(Vec2F aimPos) const;
void addParticles(List<Particle> const& particles) override;
void addSound(String const& sound, float volume = 1.0f) override;
void addSound(String const& sound, float volume = 1.0f, float pitch = 1.0f) override;
bool wireToolInUse() const;
void setWireConnector(WireConnector* wireConnector) const;
@ -611,7 +611,7 @@ private:
List<RpcPromise<InteractAction>> m_pendingInteractActions;
List<Particle> m_callbackParticles;
List<pair<String, float>> m_callbackSounds;
List<tuple<String, float, float>> m_callbackSounds;
List<String> m_queuedMessages;
List<ItemPtr> m_queuedItemPickups;

View File

@ -1126,6 +1126,7 @@ void WorldClient::update(float dt) {
if (itemDrop->canTake() && !m_requestedDrops.contains(itemDrop->entityId()) && distSquared < square(DropDist)) {
m_requestedDrops.add(itemDrop->entityId());
if (m_mainPlayer->itemsCanHold(itemDrop->item()) != 0) {
m_startupHiddenEntities.erase(itemDrop->entityId());
itemDrop->takeBy(m_mainPlayer->entityId(), (float)m_latency / 1000);
m_outgoingPackets.append(make_shared<RequestDropPacket>(itemDrop->entityId()));
}

View File

@ -94,7 +94,7 @@ public:
// FIXME: This is a dumb way of getting limited animation support
virtual void addEffectEmitters(StringSet const& emitters) = 0;
virtual void addParticles(List<Particle> const& particles) = 0;
virtual void addSound(String const& sound, float volume = 1.0f) = 0;
virtual void addSound(String const& sound, float volume = 1.0f, float pitch = 1.0f) = 0;
virtual void setCameraFocusEntity(Maybe<EntityId> const& cameraFocusEntity) = 0;
};

View File

@ -1,5 +1,6 @@
#include "StarMaterialItem.hpp"
#include "StarJson.hpp"
#include "StarJsonExtra.hpp"
#include "StarMaterialDatabase.hpp"
#include "StarRoot.hpp"
#include "StarAssets.hpp"
@ -31,8 +32,20 @@ MaterialItem::MaterialItem(Json const& config, String const& directory, Json con
setCooldownTime(config.queryFloat("materialItems.cooldown", defaultParameters.queryFloat("materialItems.cooldown")));
m_blockRadius = config.getFloat("blockRadius", defaultParameters.getFloat("blockRadius"));
m_altBlockRadius = config.getFloat("altBlockRadius", defaultParameters.getFloat("altBlockRadius"));
m_multiplace = config.getBool("allowMultiplace", BlockCollisionSet.contains(Root::singleton().materialDatabase()->materialCollisionKind(m_material)));
auto materialDatabase = Root::singleton().materialDatabase();
m_multiplace = config.getBool("allowMultiplace", BlockCollisionSet.contains(materialDatabase->materialCollisionKind(m_material)));
m_placeSounds = jsonToStringList(config.get("placeSounds", JsonArray()));
if (m_placeSounds.empty()) {
auto miningSound = materialDatabase->miningSound(m_material);
if (!miningSound.empty())
m_placeSounds.append(move(miningSound));
auto stepSound = materialDatabase->footstepSound(m_material);
if (!stepSound.empty())
m_placeSounds.append(move(stepSound));
else if (m_placeSounds.empty())
m_placeSounds.append(materialDatabase->defaultFootstepSound());
}
m_shifting = false;
}
@ -98,6 +111,7 @@ void MaterialItem::fire(FireMode mode, bool shifting, bool edgeTriggered) {
steps = (int)ceil(magnitude);
}
unsigned total = 0;
bool fail = true;
for (int i = 0; i != steps; ++i) {
auto placementOrigin = aimPosition + diff * ((float)i / steps);
@ -110,12 +124,20 @@ void MaterialItem::fire(FireMode mode, bool shifting, bool edgeTriggered) {
size_t failed = world()->applyTileModifications(modifications, false).size();
if (failed < modifications.size()) {
fail = false;
consume(modifications.size() - failed);
unsigned placed = modifications.size() - failed;
consume(placed);
total += placed;
}
}
if (!fail)
if (!fail) {
auto sound = Random::randValueFrom(m_placeSounds, "");
if (total && !sound.empty()) {
float intensity = clamp((float)total / 20, 0.0f, 1.0f);
owner()->addSound(sound, 1.0f + intensity, (1.25f - intensity * 0.75f) * Random::randf(0.9f, 1.1f));
}
FireableItem::fire(mode, shifting, edgeTriggered);
}
m_lastAimPosition = aimPosition;
}

View File

@ -45,6 +45,7 @@ private:
float m_altBlockRadius;
bool m_shifting;
bool m_multiplace;
StringList m_placeSounds;
Maybe<Vec2F> m_lastAimPosition;
};

View File

@ -421,11 +421,12 @@ void GuiContext::playAudio(AudioInstancePtr audioInstance) {
m_mixer->play(audioInstance);
}
void GuiContext::playAudio(String const& audioAsset, int loops, float volume) {
void GuiContext::playAudio(String const& audioAsset, int loops, float volume, float pitch) {
auto assets = Root::singleton().assets();
auto config = Root::singleton().configuration();
auto audioInstance = make_shared<AudioInstance>(*assets->audio(audioAsset));
audioInstance->setVolume(volume);
audioInstance->setPitchMultiplier(pitch);
audioInstance->setLoops(loops);
m_mixer->play(move(audioInstance));
}

View File

@ -118,7 +118,7 @@ public:
StringList wrapInterfaceText(String const& s, Maybe<unsigned> wrapWidth);
void playAudio(AudioInstancePtr audioInstance);
void playAudio(String const& audioAsset, int loops = 0, float volume = 1);
void playAudio(String const& audioAsset, int loops = 0, float volume = 1.0f, float pitch = 1.0f);
bool shiftHeld() const;
void setShiftHeld(bool held);