diff options
author | Simei Yin | 2018-04-01 18:02:14 +0200 |
---|---|---|
committer | Simei Yin | 2018-04-01 18:02:14 +0200 |
commit | 2ea485579932e9e470cb825ed107eba2a86a85c9 (patch) | |
tree | ea972e29e84f35b4dce3fb7fd51e203145313593 | |
parent | 506ed95cdcf11523efb06f8816c4f99a32a6a243 (diff) | |
download | scummvm-rg350-2ea485579932e9e470cb825ed107eba2a86a85c9.tar.gz scummvm-rg350-2ea485579932e9e470cb825ed107eba2a86a85c9.tar.bz2 scummvm-rg350-2ea485579932e9e470cb825ed107eba2a86a85c9.zip |
SLUDGE: Move global variable pastePalette to TextManager and refactor a little
-rw-r--r-- | engines/sludge/builtin.cpp | 7 | ||||
-rw-r--r-- | engines/sludge/fonttext.cpp | 16 | ||||
-rw-r--r-- | engines/sludge/fonttext.h | 9 | ||||
-rw-r--r-- | engines/sludge/sludger.cpp | 1 | ||||
-rw-r--r-- | engines/sludge/speech.cpp | 5 | ||||
-rw-r--r-- | engines/sludge/sprites.h | 29 | ||||
-rw-r--r-- | engines/sludge/statusba.cpp | 12 |
7 files changed, 40 insertions, 39 deletions
diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp index 7385d4d861..dba5f01694 100644 --- a/engines/sludge/builtin.cpp +++ b/engines/sludge/builtin.cpp @@ -55,7 +55,6 @@ namespace Sludge { int speechMode = 0; -SpritePalette pastePalette; Variable *launchResult = NULL; @@ -775,7 +774,7 @@ builtIn(setPasteColour) { if (!getRGBParams(red, green, blue, fun)) return BR_ERROR; - setFontColour(pastePalette, (byte)red, (byte)green, (byte)blue); + g_sludge->_txtMan->setPasterColor((byte)red, (byte)green, (byte)blue); return BR_CONTINUE; } @@ -846,7 +845,7 @@ builtIn(pasteString) { trimStack(fun->stack); if (x == IN_THE_CENTRE) x = g_sludge->_gfxMan->getCenterX(g_sludge->_txtMan->stringWidth(newText)); - g_sludge->_txtMan->pasteStringToBackdrop(newText, x, y, pastePalette); + g_sludge->_txtMan->pasteStringToBackdrop(newText, x, y); return BR_CONTINUE; } @@ -2160,7 +2159,7 @@ builtIn(burnString) { trimStack(fun->stack); if (x == IN_THE_CENTRE) x = g_sludge->_gfxMan->getCenterX(g_sludge->_txtMan->stringWidth(newText)); - g_sludge->_txtMan->burnStringToBackdrop(newText, x, y, pastePalette); + g_sludge->_txtMan->burnStringToBackdrop(newText, x, y); return BR_CONTINUE; } diff --git a/engines/sludge/fonttext.cpp b/engines/sludge/fonttext.cpp index 0f63c6e24f..da380f4f0b 100644 --- a/engines/sludge/fonttext.cpp +++ b/engines/sludge/fonttext.cpp @@ -48,11 +48,13 @@ void TextManager::init() { _loadedFontNum = 0; _fontSpace = -1; + _pastePalette.init(); _fontTable.clear(); } void TextManager::kill() { GraphicsManager::forgetSpriteBank(_theFont); + _pastePalette.kill(); } bool TextManager::isInFont(const Common::String &theText) { @@ -110,7 +112,7 @@ void TextManager::pasteString(const Common::String &theText, int xOff, int y, Sp } } -void TextManager::pasteStringToBackdrop(const Common::String &theText, int xOff, int y, SpritePalette &thePal) { +void TextManager::pasteStringToBackdrop(const Common::String &theText, int xOff, int y) { if (_fontTable.empty()) return; @@ -120,12 +122,12 @@ void TextManager::pasteStringToBackdrop(const Common::String &theText, int xOff, for (uint32 i = 0; i < str32.size(); ++i) { uint32 c = str32[i]; Sprite *mySprite = &_theFont.sprites[fontInTable(c)]; - g_sludge->_gfxMan->pasteSpriteToBackDrop(xOff, y, *mySprite, thePal); + g_sludge->_gfxMan->pasteSpriteToBackDrop(xOff, y, *mySprite, _pastePalette); xOff += mySprite->surface.w + _fontSpace; } } -void TextManager::burnStringToBackdrop(const Common::String &theText, int xOff, int y, SpritePalette &thePal) { +void TextManager::burnStringToBackdrop(const Common::String &theText, int xOff, int y) { if (_fontTable.empty()) return; @@ -135,17 +137,11 @@ void TextManager::burnStringToBackdrop(const Common::String &theText, int xOff, for (uint i = 0; i < str32.size(); ++i) { uint32 c = str32[i]; Sprite *mySprite = &_theFont.sprites[fontInTable(c)]; - g_sludge->_gfxMan->burnSpriteToBackDrop(xOff, y, *mySprite, thePal); + g_sludge->_gfxMan->burnSpriteToBackDrop(xOff, y, *mySprite, _pastePalette); xOff += mySprite->surface.w + _fontSpace; } } -void setFontColour(SpritePalette &sP, byte r, byte g, byte b) { - sP.originalRed = r; - sP.originalGreen = g; - sP.originalBlue = b; -} - bool TextManager::loadFont(int filenum, const Common::String &charOrder, int h) { _fontOrder.setUTF8String(charOrder); diff --git a/engines/sludge/fonttext.h b/engines/sludge/fonttext.h index 26b12d9f11..7018c75213 100644 --- a/engines/sludge/fonttext.h +++ b/engines/sludge/fonttext.h @@ -46,12 +46,14 @@ public: bool loadFont(int filenum, const Common::String &charOrder, int); void pasteString(const Common::String &theText, int, int, SpritePalette &); - void pasteStringToBackdrop(const Common::String &theText, int xOff, int y, SpritePalette &thePal); - void burnStringToBackdrop(const Common::String &theText, int xOff, int y, SpritePalette &thePal); + void pasteStringToBackdrop(const Common::String &theText, int xOff, int y); + void burnStringToBackdrop(const Common::String &theText, int xOff, int y); bool isInFont(const Common::String &theText); + // setter & getter void setFontSpace(int fontSpace) { _fontSpace = fontSpace; } int getFontHeight() const { return _fontHeight; } + void setPasterColor(byte r, byte g, byte b) { _pastePalette.setColor(r, g, b); } // load & save void saveFont(Common::WriteStream *stream); @@ -62,6 +64,7 @@ private: int _fontHeight, _numFontColours, _loadedFontNum; UTF8Converter _fontOrder; int16 _fontSpace; + SpritePalette _pastePalette; Common::HashMap<uint32, uint32> _fontTable; @@ -69,8 +72,6 @@ private: }; -void setFontColour(SpritePalette &sP, byte r, byte g, byte b); - } // End of namespace Sludge #endif diff --git a/engines/sludge/sludger.cpp b/engines/sludge/sludger.cpp index 812f42fb5d..9526ddf4df 100644 --- a/engines/sludge/sludger.cpp +++ b/engines/sludge/sludger.cpp @@ -196,7 +196,6 @@ void killSludge() { g_sludge->_cursorMan->kill(); // global variables - pastePalette.reset(); numBIFNames = numUserFunc = 0; delete []allUserFunc; delete []allBIFNames; diff --git a/engines/sludge/speech.cpp b/engines/sludge/speech.cpp index 1d342a1b65..b3fedac70e 100644 --- a/engines/sludge/speech.cpp +++ b/engines/sludge/speech.cpp @@ -74,7 +74,7 @@ void SpeechManager::kill() { } void SpeechManager::setObjFontColour(ObjectType *t) { - setFontColour(_speech->talkCol, t->r, t->g, t->b); + _speech->talkCol.setColor(t->r, t->g, t->b); } void SpeechManager::addSpeechLine(const Common::String &theLine, int x, int &offset) { @@ -264,8 +264,7 @@ bool SpeechManager::load(Common::SeekableReadStream *stream) { byte r = stream->readByte(); byte g = stream->readByte(); byte b = stream->readByte(); - setFontColour(_speech->talkCol, r, g, b); - + _speech->talkCol.setColor(r, g, b); _speechSpeed = stream->readFloatLE(); // Read y co-ordinate diff --git a/engines/sludge/sprites.h b/engines/sludge/sprites.h index e138c6f14f..e18d16e5df 100644 --- a/engines/sludge/sprites.h +++ b/engines/sludge/sprites.h @@ -42,15 +42,8 @@ public: byte originalRed, originalGreen, originalBlue, total; SpritePalette() { init(); } - ~SpritePalette() { kill(); } - void reset() { - kill(); - init(); - } - -private: void init() { pal = nullptr; r = g = b = nullptr; @@ -59,15 +52,29 @@ private: } void kill() { - if (pal) + if (pal) { delete[] pal; - if (r) + pal = nullptr; + } + if (r) { delete[] r; - if (g) + r = nullptr; + } + if (g) { delete[] g; - if (b) + g = nullptr; + } + if (b) { delete[] b; + b = nullptr; + } } + + void setColor(byte red, byte green, byte blue) { + originalRed = red; + originalGreen = green; + originalBlue = blue; + } }; struct SpriteBank { diff --git a/engines/sludge/statusba.cpp b/engines/sludge/statusba.cpp index 1aa24971f1..04fa18e957 100644 --- a/engines/sludge/statusba.cpp +++ b/engines/sludge/statusba.cpp @@ -114,14 +114,14 @@ void drawStatusBar() { } void statusBarColour(byte r, byte g, byte b) { - setFontColour(verbLinePalette, r, g, b); + verbLinePalette.setColor(r, g, b); nowStatus->statusR = r; nowStatus->statusG = g; nowStatus->statusB = b; } void statusBarLitColour(byte r, byte g, byte b) { - setFontColour(litVerbLinePalette, r, g, b); + litVerbLinePalette.setColor(r, g, b); nowStatus->statusLR = r; nowStatus->statusLG = g; nowStatus->statusLB = b; @@ -152,8 +152,8 @@ StatusStuff *copyStatusBarStuff(StatusStuff *here) { void restoreBarStuff(StatusStuff *here) { delete nowStatus; - setFontColour(verbLinePalette, here->statusR, here->statusG, here->statusB); - setFontColour(litVerbLinePalette, here->statusLR, here->statusLG, here->statusLB); + verbLinePalette.setColor((byte)here->statusR, (byte)here->statusG, (byte)here->statusB); + litVerbLinePalette.setColor((byte)here->statusLR, (byte)here->statusLG, (byte)here->statusLB); nowStatus = here; } @@ -215,8 +215,8 @@ bool loadStatusBars(Common::SeekableReadStream *stream) { nowStatus->statusLG = stream->readByte(); nowStatus->statusLB = stream->readByte(); - setFontColour(verbLinePalette, nowStatus->statusR, nowStatus->statusG, nowStatus->statusB); - setFontColour(litVerbLinePalette, nowStatus->statusLR, nowStatus->statusLG, nowStatus->statusLB); + verbLinePalette.setColor((byte)nowStatus->statusR, (byte)nowStatus->statusG, (byte)nowStatus->statusB); + litVerbLinePalette.setColor((byte)nowStatus->statusLR, (byte)nowStatus->statusLG, (byte)nowStatus->statusLB); // Read what's being said StatusBar **viewLine = & (nowStatus->firstStatusBar); StatusBar *newOne; |