[Scummvm-git-logs] scummvm master -> 0d43e8e9aeb226fcbffb389c978d6c39fea90a71
dreammaster
noreply at scummvm.org
Fri Feb 24 05:49:34 UTC 2023
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
a01be65ee4 MM: MM1: Properly line wrap long spell names in Cast Spell dialog
0d43e8e9ae MM: MM1: Middle align spell failure messages
Commit: a01be65ee48d5c8a7b17fde44be237e110a56de1
https://github.com/scummvm/scummvm/commit/a01be65ee48d5c8a7b17fde44be237e110a56de1
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2023-02-23T21:49:27-08:00
Commit Message:
MM: MM1: Properly line wrap long spell names in Cast Spell dialog
Changed paths:
engines/mm/mm1/views_enh/text_view.cpp
engines/mm/mm1/views_enh/text_view.h
diff --git a/engines/mm/mm1/views_enh/text_view.cpp b/engines/mm/mm1/views_enh/text_view.cpp
index 6a642ed4103..51556322655 100644
--- a/engines/mm/mm1/views_enh/text_view.cpp
+++ b/engines/mm/mm1/views_enh/text_view.cpp
@@ -80,7 +80,9 @@ void TextView::writeChar(int x, int y, char c) {
writeChar(c);
}
-void TextView::writeString(const Common::String &str) {
+void TextView::rawWriteString(const Common::String &str) {
+ int y = _textPos.y;
+
for (const char *s = (const char *)str.c_str(); *s; ++s) {
char c = *s;
@@ -96,39 +98,64 @@ void TextView::writeString(const Common::String &str) {
writeChar(c);
}
}
-}
-void TextView::writeString(int x, int y, const Common::String &str,
- TextAlign align) {
- _textPos.x = x;
_textPos.y = y;
+}
- Common::StringArray lines = splitLines(str);
+void TextView::writeString(const Common::String &str, TextAlign align) {
+ if (_textPos.x == 0) {
+ if (align == ALIGN_RIGHT)
+ _textPos.x = _innerBounds.width();
+ else if (align == ALIGN_MIDDLE)
+ _textPos.x = _innerBounds.width() / 2;
+ }
+ // Figure out line widths
+ int lineWidth;
+ switch (align) {
+ case ALIGN_RIGHT:
+ lineWidth = _textPos.x;
+ break;
+ case ALIGN_MIDDLE:
+ lineWidth = MIN(_textPos.x, (int16)(_innerBounds.width() - _textPos.x)) * 2;
+ break;
+ default:
+ lineWidth = _innerBounds.width() - _textPos.x;
+ break;
+ }
+
+ // Split the string into lines
+ Common::StringArray lines = splitLines(str, lineWidth);
+
+ int xStart = _textPos.x;
for (auto line : lines) {
- if (line != lines.front())
+ if (line != lines.front()) {
newLine();
+ _textPos.x = xStart;
+ }
if (align != ALIGN_LEFT) {
int strWidth = getFont()->getStringWidth(line);
- if (x == 0) {
- if (align == ALIGN_MIDDLE)
- x = _innerBounds.width() / 2;
- else
- x = _innerBounds.width();
- }
-
if (align == ALIGN_MIDDLE)
- _textPos.x = MAX(x - (strWidth / 2), 0);
+ _textPos.x = xStart - strWidth / 2;
else
- _textPos.x = MAX(x - strWidth, 0);
+ // Right align
+ _textPos.x = xStart - strWidth;
}
- writeString(line);
+ rawWriteString(line);
}
}
+void TextView::writeString(int x, int y, const Common::String &str,
+ TextAlign align) {
+ _textPos.x = x;
+ _textPos.y = y;
+
+ writeString(str, align);
+}
+
void TextView::writeNumber(int val) {
writeString(Common::String::format("%d", val));
}
@@ -149,6 +176,52 @@ void TextView::newLine() {
_textPos.y += ROW_HEIGHT;
}
+Common::StringArray TextView::splitLines(const Common::String &str,
+ int lineWidth) {
+ Graphics::Font &font = _fontReduced ?
+ g_globals->_fontReduced : g_globals->_fontNormal;
+ const char *startP = str.c_str();
+ const char *endP;
+
+ if (lineWidth == -1)
+ lineWidth = _innerBounds.width();
+
+ Common::StringArray lines;
+ if (str.empty())
+ return lines;
+
+ do {
+ endP = strchr(startP, '\n');
+ int strWidth = font.getStringWidth(endP ?
+ Common::String(startP, endP) : Common::String(startP));
+
+ if (strWidth > lineWidth) {
+ // Find the last space before a full line
+ endP = startP + strlen(startP) - 1;
+ while (strWidth > lineWidth) {
+ // Move back to a prior space
+ for (--endP; endP > startP && *endP != ' '; --endP) {
+ }
+ assert(endP > startP);
+
+ strWidth = font.getStringWidth(Common::String(startP, endP));
+ }
+ }
+
+ // Add line to results
+ lines.push_back(endP ? Common::String(startP, endP) : Common::String(startP));
+
+ if (!endP)
+ break;
+
+ // Start next line after space or carriage return
+ startP = endP + 1;
+
+ } while (*startP);
+
+ return lines;
+}
+
void TextView::clearSurface() {
UIElement::clearSurface();
_textPos.x = _textPos.y = 0;
diff --git a/engines/mm/mm1/views_enh/text_view.h b/engines/mm/mm1/views_enh/text_view.h
index 1ce1c52f776..4676e72af90 100644
--- a/engines/mm/mm1/views_enh/text_view.h
+++ b/engines/mm/mm1/views_enh/text_view.h
@@ -36,6 +36,12 @@ enum TextAlign {
class TextView : public UIElement {
private:
Graphics::Font *getFont() const;
+
+ /**
+ * Raw write string
+ */
+ void rawWriteString(const Common::String &str);
+
protected:
Common::Point _textPos;
int _colorsNum = 0;
@@ -55,7 +61,8 @@ protected:
/**
* Write some text
*/
- void writeString(const Common::String &str);
+ void writeString(const Common::String &str,
+ TextAlign align = ALIGN_LEFT);
void writeString(int x, int y, const Common::String &str,
TextAlign align = ALIGN_LEFT);
@@ -76,6 +83,12 @@ protected:
*/
void newLine();
+ /**
+ * Split lines
+ */
+ Common::StringArray splitLines(const Common::String &str,
+ int firstLineWidth = -1);
+
/**
* Clear the surface
*/
Commit: 0d43e8e9aeb226fcbffb389c978d6c39fea90a71
https://github.com/scummvm/scummvm/commit/0d43e8e9aeb226fcbffb389c978d6c39fea90a71
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2023-02-23T21:49:27-08:00
Commit Message:
MM: MM1: Middle align spell failure messages
Changed paths:
devtools/create_mm/files/mm1/strings_en.yml
engines/mm/mm1/messages.cpp
engines/mm/mm1/messages.h
engines/mm/mm1/views_enh/game_messages.cpp
engines/mm/mm1/views_enh/spells/cast_spell.cpp
engines/mm/mm1/views_enh/text_view.h
diff --git a/devtools/create_mm/files/mm1/strings_en.yml b/devtools/create_mm/files/mm1/strings_en.yml
index b7c78204b7e..294115ae1b0 100644
--- a/devtools/create_mm/files/mm1/strings_en.yml
+++ b/devtools/create_mm/files/mm1/strings_en.yml
@@ -848,17 +848,17 @@ movement:
view:
darkness: " darkness"
spells:
- not_enough_gold: "not enough gold"
- not_enough_gems: "not enough gems"
- not_enough_sp: "not enough spell points"
- done: "done"
- combat_only: "combat only"
- noncombat_only: "non combat only"
- magic_doesnt_work: "magic doesn't work here"
- outdoors_only: "outdoor only"
- failed: "spell failed"
- no_effect: "no effect!"
- monsters_destroyed: "some monsters were destroyed!"
+ not_enough_gold: "Not enough gold"
+ not_enough_gems: "Not enough gems"
+ not_enough_sp: "Not enough spell points"
+ done: "Done"
+ combat_only: "Combat only"
+ noncombat_only: "Non combat only"
+ magic_doesnt_work: "Magic doesn't work here"
+ outdoors_only: "Outdoor only"
+ failed: "Spell failed"
+ no_effect: "No effect!"
+ monsters_destroyed: "Some monsters were destroyed!"
casts_spell: "casts a spell:"
enter_to_cast: "'enter' to cast"
diff --git a/engines/mm/mm1/messages.cpp b/engines/mm/mm1/messages.cpp
index f646f571b57..913720f99e8 100644
--- a/engines/mm/mm1/messages.cpp
+++ b/engines/mm/mm1/messages.cpp
@@ -41,12 +41,14 @@ MouseMessage::MouseMessage(Common::EventType type,
InfoMessage::InfoMessage() : Message() {}
-InfoMessage::InfoMessage(const Common::String &str) : Message() {
- _lines.push_back(str);
+InfoMessage::InfoMessage(const Common::String &str,
+ TextAlign align) : Message() {
+ _lines.push_back(Line(str, align));
}
-InfoMessage::InfoMessage(int x, int y, const Common::String &str) {
- _lines.push_back(Line(x, y, str));
+InfoMessage::InfoMessage(int x, int y, const Common::String &str,
+ TextAlign align) {
+ _lines.push_back(Line(x, y, str, align));
}
InfoMessage::InfoMessage(int x1, int y1, const Common::String &str1,
diff --git a/engines/mm/mm1/messages.h b/engines/mm/mm1/messages.h
index 2b9c7706c0a..017a86667fe 100644
--- a/engines/mm/mm1/messages.h
+++ b/engines/mm/mm1/messages.h
@@ -30,6 +30,10 @@
namespace MM {
namespace MM1 {
+enum TextAlign {
+ ALIGN_LEFT, ALIGN_RIGHT, ALIGN_MIDDLE
+};
+
struct Message {};
struct FocusMessage : public Message {};
struct UnfocusMessage : public Message {};
@@ -94,14 +98,16 @@ struct HeaderMessage : public Message {
struct Line : public Common::Point {
Common::String _text;
+ TextAlign _align = ALIGN_LEFT;
Line() {
}
- Line(const Common::String &text) :
- Common::Point(-1, -1), _text(text) {
+ Line(const Common::String &text, TextAlign align = ALIGN_LEFT) :
+ Common::Point(-1, -1), _text(text), _align(align) {
}
- Line(int x1, int y1, const Common::String &text) :
- Common::Point(x1, y1), _text(text) {
+ Line(int x1, int y1, const Common::String &text,
+ TextAlign align = ALIGN_LEFT) :
+ Common::Point(x1, y1), _text(text), _align(align) {
}
size_t size() const;
@@ -120,8 +126,8 @@ struct InfoMessage : public Message {
int _delaySeconds = 0;
InfoMessage();
- InfoMessage(const Common::String &str);
- InfoMessage(int x, int y, const Common::String &str);
+ InfoMessage(const Common::String &str, TextAlign align = ALIGN_LEFT);
+ InfoMessage(int x, int y, const Common::String &str, TextAlign align = ALIGN_LEFT);
InfoMessage(int x1, int y1, const Common::String &str1,
int x2, int y2, const Common::String &str2);
@@ -147,10 +153,11 @@ struct InfoMessage : public Message {
struct SoundMessage : public InfoMessage {
public:
SoundMessage() : InfoMessage() { _sound = true; }
- SoundMessage(const Common::String &str) :
- InfoMessage(0, 1, str) { _sound = true; }
- SoundMessage(int x, int y, const Common::String &str) :
- InfoMessage(x, y, str) { _sound = true; }
+ SoundMessage(const Common::String &str, TextAlign align = ALIGN_LEFT) :
+ InfoMessage(0, 1, str, align) { _sound = true; }
+ SoundMessage(int x, int y, const Common::String &str,
+ TextAlign align = ALIGN_LEFT) :
+ InfoMessage(x, y, str, align) { _sound = true; }
SoundMessage(int x1, int y1, const Common::String &str1,
int x2, int y2, const Common::String &str2) :
InfoMessage(x1, y1, str1, x2, y2, str2) { _sound = true; }
diff --git a/engines/mm/mm1/views_enh/game_messages.cpp b/engines/mm/mm1/views_enh/game_messages.cpp
index 238af78b5b9..fe3f965fa71 100644
--- a/engines/mm/mm1/views_enh/game_messages.cpp
+++ b/engines/mm/mm1/views_enh/game_messages.cpp
@@ -82,7 +82,7 @@ bool GameMessages::msgInfo(const InfoMessage &msg) {
// Process the lines
clear();
for (auto line : msg._lines)
- addText(line._text, line.y, 0, ALIGN_LEFT, line.x * 8);
+ addText(line._text, line.y, 0, line._align, line.x * 8);
redraw();
return true;
diff --git a/engines/mm/mm1/views_enh/spells/cast_spell.cpp b/engines/mm/mm1/views_enh/spells/cast_spell.cpp
index d00fe37f832..d04c372557b 100644
--- a/engines/mm/mm1/views_enh/spells/cast_spell.cpp
+++ b/engines/mm/mm1/views_enh/spells/cast_spell.cpp
@@ -149,7 +149,7 @@ void CastSpell::spellError() {
g_events->drawElements();
Common::String msg = getSpellError();
- send(SoundMessage(msg));
+ send(SoundMessage(msg, ALIGN_MIDDLE));
}
} // namespace Spells
diff --git a/engines/mm/mm1/views_enh/text_view.h b/engines/mm/mm1/views_enh/text_view.h
index 4676e72af90..3e3828129f4 100644
--- a/engines/mm/mm1/views_enh/text_view.h
+++ b/engines/mm/mm1/views_enh/text_view.h
@@ -29,10 +29,6 @@ namespace MM {
namespace MM1 {
namespace ViewsEnh {
-enum TextAlign {
- ALIGN_LEFT, ALIGN_RIGHT, ALIGN_MIDDLE
-};
-
class TextView : public UIElement {
private:
Graphics::Font *getFont() const;
More information about the Scummvm-git-logs
mailing list