Skip to content

Commit

Permalink
ENGINES: Add support for listbox sound customization
Browse files Browse the repository at this point in the history
  • Loading branch information
vkremianskii committed Jul 7, 2018
1 parent 4bb1b67 commit 2bfd388
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/engines/aurora/kotorjadegui/listbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ void WidgetListBox::selectItemByWidgetTag(const Common::UString &tag) {

if ((index >= 0) && (_selectedIndex != _startIndex + index)) {
_selectedIndex = _startIndex + index;
playSound("gui_actscroll", Sound::kSoundTypeSFX);
playSound(_soundSelectItem, Sound::kSoundTypeSFX);
refreshItemWidgets();
}
}
Expand All @@ -265,7 +265,7 @@ void WidgetListBox::selectNextItem() {
}

if (selectionChanged)
playSound("gui_actscroll", Sound::kSoundTypeSFX);
playSound(_soundSelectItem, Sound::kSoundTypeSFX);
} else if (_startIndex + _numVisibleItems < (int)_items.size()) {
++_startIndex;
refreshItemWidgets();
Expand All @@ -289,7 +289,7 @@ void WidgetListBox::selectPreviousItem() {
}

if (selectionChanged)
playSound("gui_actscroll", Sound::kSoundTypeSFX);
playSound(_soundSelectItem, Sound::kSoundTypeSFX);
} else if (_startIndex > 0) {
--_startIndex;
refreshItemWidgets();
Expand Down Expand Up @@ -318,6 +318,21 @@ void WidgetListBox::subActive(Widget &widget) {
raiseCallbackActive(widget);
}

void WidgetListBox::setSoundSelectItem(const Common::UString &resRef) {
_soundSelectItem = resRef;
applyChangesToItemWidgets();
}

void WidgetListBox::setSoundHoverItem(const Common::UString &resRef) {
_soundHoverItem = resRef;
applyChangesToItemWidgets();
}

void WidgetListBox::setSoundClickItem(const Common::UString &resRef) {
_soundClickItem = resRef;
applyChangesToItemWidgets();
}

void WidgetListBox::createScrollbar(const Aurora::GFF3Struct &gff) {
_scrollbar = new WidgetScrollbar(*_gui, _tag + "#" + gff.getString("TAG"));
_scrollbar->load(gff);
Expand Down Expand Up @@ -355,10 +370,15 @@ void WidgetListBox::positionItemWidgets() {
void WidgetListBox::applyChangesToItemWidgets() {
for (size_t i = 0; i < _itemWidgets.size(); ++i) {
_itemWidgets[i]->setDisableHighlight(_itemSelectionEnabled);

if (_textColorChanged)
_itemWidgets[i]->setTextColor(_textR, _textG, _textB, _textA);

if (_borderColorChanged)
_itemWidgets[i]->setBorderColor(_borderR, _borderG, _borderB, _borderA);

_itemWidgets[i]->setSoundHover(_soundHoverItem);
_itemWidgets[i]->setSoundClick(_soundClickItem);
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/engines/aurora/kotorjadegui/listbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ class WidgetListBox : public KotORJadeWidget {

void subActive(Widget &widget);

void setSoundSelectItem(const Common::UString &resRef);
void setSoundHoverItem(const Common::UString &resRef);
void setSoundClickItem(const Common::UString &resRef);

private:
const Aurora::GFF3Struct *_protoItem;
WidgetScrollbar *_scrollbar;
Expand All @@ -117,6 +121,10 @@ class WidgetListBox : public KotORJadeWidget {
bool _borderColorChanged;
float _borderR, _borderG, _borderB, _borderA;

Common::UString _soundSelectItem;
Common::UString _soundHoverItem;
Common::UString _soundClickItem;

void createScrollbar(const Aurora::GFF3Struct &gff);
void positionItemWidgets();
void applyChangesToItemWidgets();
Expand Down
15 changes: 15 additions & 0 deletions src/engines/aurora/kotorjadegui/protoitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "src/common/system.h"

#include "src/engines/aurora/gui.h"
#include "src/engines/aurora/util.h"

#include "src/engines/aurora/kotorjadegui/protoitem.h"

Expand Down Expand Up @@ -64,6 +65,9 @@ void WidgetProtoItem::enter() {
if (!_disableHighlight)
setHighlight(true);

if (!_soundHover.empty())
playSound(_soundHover, Sound::kSoundTypeSFX);

_hovered = true;
}

Expand All @@ -75,13 +79,24 @@ void WidgetProtoItem::leave() {
}

void WidgetProtoItem::mouseUp(uint8 UNUSED(state), float UNUSED(x), float UNUSED(y)) {
if (!_soundClick.empty())
playSound(_soundClick, Sound::kSoundTypeSFX);

setActive(true);
}

void WidgetProtoItem::setDisableHighlight(bool disableHighlight) {
_disableHighlight = disableHighlight;
}

void WidgetProtoItem::setSoundHover(const Common::UString &resRef) {
_soundHover = resRef;
}

void WidgetProtoItem::setSoundClick(const Common::UString &resRef) {
_soundClick = resRef;
}

void WidgetProtoItem::setDefaultHighlighting(Graphics::Aurora::Highlightable *highlightable) {
highlightable->setHighlightable(true);
highlightable->setHighlightDelta(0.0f, 0.0f, 0.0f, 0.05f);
Expand Down
6 changes: 6 additions & 0 deletions src/engines/aurora/kotorjadegui/protoitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,16 @@ class WidgetProtoItem : public KotORJadeWidget {

void setDisableHighlight(bool disableHighlight);

void setSoundHover(const Common::UString &resRef);
void setSoundClick(const Common::UString &resRef);

private:
bool _disableHighlight;
bool _hovered;

Common::UString _soundHover;
Common::UString _soundClick;

void setDefaultHighlighting(Graphics::Aurora::Highlightable *highlightable);
};

Expand Down

0 comments on commit 2bfd388

Please sign in to comment.