Skip to content

Commit

Permalink
Added 'tooltip_visible_max' to engine/tootlips.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
dorkster committed Jan 24, 2022
1 parent feac7ee commit 24d4831
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 13 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Engine features:
* Added a 'direction' property to map NPCs, indentical to the property of the same name for map enemies.
* Added 'vendor_ratio_buy', 'vendor_ratio_sell', and 'vendor_ratio_sell_old' properties to engine/loot.txt. These deprecate 'vendor_ratio' and 'vendor_ratio_buyback'.
* Added 'vendor_ratio_buy', 'vendor_ratio_sell', and 'vendor_ratio_sell_old' properties to NPCs. These can be used to override the global settings in engine/loot.txt.
* Added 'tooltip_visible_max' to engine/tootlips.txt to control the maximum number of visible floating tooltips.

Engine fixes:

Expand Down
2 changes: 2 additions & 0 deletions docs/attribute-reference.html
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ <h4>EngineSettings: Tooltips</h4>

<p><strong>tooltip_background_border</strong> | <code>int</code> | The pixel size of the border in "images/menus/tooltips.png".</p>

<p><strong>tooltip_visible_max</strong> | <code>int</code> | The maximum number of floating tooltips on screen at once. Defaults to 3.</p>

<hr />

<h4>EngineSettings: Loot</h4>
Expand Down
10 changes: 10 additions & 0 deletions src/EngineSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ void EngineSettings::Tooltips::load() {
margin = 0;
margin_npc = 0;
background_border = 0;
visible_max = 3;

FileParser infile;
// @CLASS EngineSettings: Tooltips|Description of engine/tooltips.txt
Expand All @@ -726,6 +727,15 @@ void EngineSettings::Tooltips::load() {
// @ATTR tooltip_background_border|int|The pixel size of the border in "images/menus/tooltips.png".
else if (infile.key == "tooltip_background_border")
background_border = Parse::toInt(infile.val);
// @ATTR tooltip_visible_max|int|The maximum number of floating tooltips on screen at once. Defaults to 3.
else if (infile.key == "tooltip_visible_max") {
visible_max = static_cast<size_t>(Parse::toInt(infile.val));

if (visible_max < 1) {
visible_max = 1;
infile.error("EngineSettings: tooltip_visible_max must be greater than or equal to 1.");
}
}

else infile.error("EngineSettings: '%s' is not a valid key.", infile.key.c_str());
}
Expand Down
1 change: 1 addition & 0 deletions src/EngineSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ class EngineSettings {
int margin;
int margin_npc;
int background_border;
size_t visible_max;
};

class Loot {
Expand Down
2 changes: 1 addition & 1 deletion src/MenuManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1724,7 +1724,7 @@ void MenuManager::pushMatchingItemsOf(const Point& hov_pos) {

//get equipped items of the same type
for (size_t i = 0; i < inv->equipped_area.size(); i++) {
if (tip_index >= TooltipManager::TOOLTIP_COUNT)
if (tip_index >= eset->tooltips.visible_max)
break; // can't show any more tooltips

if (inv->isActive(i)){
Expand Down
19 changes: 13 additions & 6 deletions src/TooltipManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,20 @@ FLARE. If not, see http://www.gnu.org/licenses/
* class TooltipManager
*/

#include "EngineSettings.h"
#include "SharedResources.h"
#include "TooltipManager.h"
#include "WidgetTooltip.h"

TooltipManager::TooltipManager()
: context(CONTEXT_NONE)
{
for (size_t i = 0; i < TOOLTIP_COUNT; ++i) {
tip.resize(eset->tooltips.visible_max);
tip_data.resize(eset->tooltips.visible_max);
pos.resize(eset->tooltips.visible_max);
style.resize(eset->tooltips.visible_max);

for (size_t i = 0; i < eset->tooltips.visible_max; ++i) {
tip[i] = new WidgetTooltip();
if (i > 0) {
tip[i]->parent = tip[i-1];
Expand All @@ -38,27 +45,27 @@ TooltipManager::TooltipManager()
}

TooltipManager::~TooltipManager() {
for (size_t i = 0; i < TOOLTIP_COUNT; ++i) {
for (size_t i = 0; i < tip.size(); ++i) {
delete tip[i];
}
}

void TooltipManager::clear() {
for (size_t i = 0; i < TOOLTIP_COUNT; ++i) {
for (size_t i = 0; i < eset->tooltips.visible_max; ++i) {
tip_data[i].clear();
}
}

bool TooltipManager::isEmpty() {
for (size_t i = 0; i < TOOLTIP_COUNT; ++i) {
for (size_t i = 0; i < eset->tooltips.visible_max; ++i) {
if (!tip_data[i].isEmpty())
return false;
}
return true;
}

void TooltipManager::push(const TooltipData& _tip_data, const Point& _pos, uint8_t _style, size_t tip_index) {
if (_tip_data.isEmpty() || tip_index >= TOOLTIP_COUNT)
if (_tip_data.isEmpty() || tip_index >= eset->tooltips.visible_max)
return;

tip_data[tip_index] = _tip_data;
Expand All @@ -74,7 +81,7 @@ void TooltipManager::render() {
context = CONTEXT_NONE;
}

for (size_t i = 0; i < TOOLTIP_COUNT; ++i) {
for (size_t i = 0; i < eset->tooltips.visible_max; ++i) {
tip[i]->render(tip_data[i], pos[i], style[i]);
}
}
9 changes: 4 additions & 5 deletions src/TooltipManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class WidgetTooltip;

class TooltipManager {
public:
static const size_t TOOLTIP_COUNT = 3;
enum {
CONTEXT_NONE = 0,
CONTEXT_MENU = 1,
Expand All @@ -48,10 +47,10 @@ class TooltipManager {
uint8_t context;

private:
WidgetTooltip* tip[TOOLTIP_COUNT];
TooltipData tip_data[TOOLTIP_COUNT];
Point pos[TOOLTIP_COUNT];
uint8_t style[TOOLTIP_COUNT];
std::vector<WidgetTooltip*> tip;
std::vector<TooltipData> tip_data;
std::vector<Point> pos;
std::vector<uint8_t> style;

};

Expand Down
2 changes: 1 addition & 1 deletion src/Version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ FLARE. If not, see http://www.gnu.org/licenses/

#include <SDL.h>

Version VersionInfo::ENGINE(1, 12, 88);
Version VersionInfo::ENGINE(1, 12, 89);
Version VersionInfo::MIN(0, 0, 0);
Version VersionInfo::MAX(USHRT_MAX, USHRT_MAX, USHRT_MAX);

Expand Down

0 comments on commit 24d4831

Please sign in to comment.