can specify text color, only use last palette last index for text bg

This commit is contained in:
wgroeneveld 2018-08-02 14:24:44 +02:00
parent b6f9297a89
commit e9c5f5da00
7 changed files with 576 additions and 520 deletions

View File

@ -28,7 +28,7 @@ public:
Background(int bgIndex, const void *data, int size, const void* map, int mapSize) : data(data), bgIndex(bgIndex), size(size), map(map), Background(int bgIndex, const void *data, int size, const void* map, int mapSize) : data(data), bgIndex(bgIndex), size(size), map(map),
screenBlockIndex(0), charBlockIndex(0), mapSize(mapSize) {} screenBlockIndex(0), charBlockIndex(0), mapSize(mapSize) {}
void persist(); virtual void persist();
void clearMap(); void clearMap();
}; };

File diff suppressed because it is too large Load Diff

View File

@ -3,8 +3,11 @@
// //
#include <engine/gba/tonc_memmap.h> #include <engine/gba/tonc_memmap.h>
#include <engine/palette_manager.h>
#include "text_stream.h" #include "text_stream.h"
#include <memory>
TextStream* TextStream::inst; TextStream* TextStream::inst;
void TextStream::clear() { void TextStream::clear() {
@ -15,6 +18,8 @@ void TextStream::clear() {
TextStream::TextStream() : Background(0, text_data, sizeof(text_data), nullptr, TILE_WIDTH * TILE_WIDTH), currCol(0), currRow(0) { TextStream::TextStream() : Background(0, text_data, sizeof(text_data), nullptr, TILE_WIDTH * TILE_WIDTH), currCol(0), currRow(0) {
useMapScreenBlock(24); useMapScreenBlock(24);
this->palette = std::unique_ptr<BackgroundPaletteManager>(new BackgroundPaletteManager());
persist(); persist();
clearMap(); clearMap();
} }
@ -79,4 +84,14 @@ TextStream& TextStream::operator<<(const char * s) {
setText(s, currRow, currCol); setText(s, currRow, currCol);
currRow++; currRow++;
return *this; return *this;
} }
void TextStream::setTextColor(COLOR color) {
palette.get()->change(PALETTE_TEXT_BANK, PALETTE_COLOR_INDEX, color);
}
void TextStream::persist() {
Background::persist();
// WARNING: stream hijacks last bg palette bank, last index, no matter what.
setTextColor(PaletteManager::color(31, 31, 31));
}

View File

@ -9,9 +9,13 @@
#include "text.h" #include "text.h"
#include <string> #include <string>
#include <memory>
#include <engine/palette_manager.h>
#define CHAR_OFFSET_INDEX 32 #define CHAR_OFFSET_INDEX 32
#define TILE_WIDTH 32 #define TILE_WIDTH 32
#define PALETTE_COLOR_INDEX 15
#define PALETTE_TEXT_BANK 15
#define failure(__mess) (consoleLog_func(__FILE__, __LINE__, __PRETTY_FUNCTION__, #__mess)) #define failure(__mess) (consoleLog_func(__FILE__, __LINE__, __PRETTY_FUNCTION__, #__mess))
void log_text(const char* text); void log_text(const char* text);
@ -20,6 +24,7 @@ void consoleLog_func(const char* fileName, const int lineNr, const char* fnName,
class TextStream : public Background { class TextStream : public Background {
private: private:
int currRow, currCol; int currRow, currCol;
std::unique_ptr<BackgroundPaletteManager> palette;
static TextStream* inst; static TextStream* inst;
TextStream(); TextStream();
@ -29,8 +34,11 @@ private:
public: public:
void clear(); void clear();
void setText(const char* text, int row, int col); void setText(const char* text, int row, int col);
void setTextColor(COLOR color);
static TextStream& instance(); static TextStream& instance();
void persist() override;
TextStream& operator << (const char* s); TextStream& operator << (const char* s);
TextStream& operator << (const int s); TextStream& operator << (const int s);
TextStream& operator << (const u32 s); TextStream& operator << (const u32 s);

View File

@ -6,5 +6,21 @@
#include "palette_manager.h" #include "palette_manager.h"
void PaletteManager::persist() { void PaletteManager::persist() {
dma3_cpy(this->palletteAddress(), this->data, this->size); dma3_cpy(this->paletteAddress(), this->data, this->size);
} }
COLOR PaletteManager::change(int bank, int index, COLOR newColor) {
auto palBank = this->paletteBank();
COLOR oldColor = palBank[bank][index];
palBank[bank][index] = newColor;
return oldColor;
}
COLOR PaletteManager::color(u32 red, u32 green, u32 blue) {
return red | (green<<5) | (blue<<10);
}
void PaletteManager::persistToBank(int bank) {
auto palBank = this->paletteBank();
dma3_cpy(palBank[bank], this->data, PALETTE_BANK_SIZE);
}

View File

@ -5,7 +5,7 @@
#ifndef GBA_SPRITE_ENGINE_PALETTE_MANAGER_H #ifndef GBA_SPRITE_ENGINE_PALETTE_MANAGER_H
#define GBA_SPRITE_ENGINE_PALETTE_MANAGER_H #define GBA_SPRITE_ENGINE_PALETTE_MANAGER_H
#include <engine/gba/tonc_memmap.h>
#include <engine/gba/tonc_types.h> #include <engine/gba/tonc_types.h>
#define PALETTE_BANK_SIZE 16 #define PALETTE_BANK_SIZE 16
@ -17,20 +17,30 @@ protected:
const u16 *data; const u16 *data;
int size; int size;
virtual void* palletteAddress() = 0; virtual void* paletteAddress() = 0;
virtual PALBANK* paletteBank() = 0;
public: public:
PaletteManager(const u16 paletteData[]) : data(paletteData), size(PALETTE_MAX_SIZE) {} PaletteManager(const u16 paletteData[]) : data(paletteData), size(PALETTE_MAX_SIZE) {}
PaletteManager(const u16 paletteData[], int size) : data(paletteData), size(size) {} PaletteManager(const u16 paletteData[], int size) : data(paletteData), size(size) {}
void persist(); void persist();
void persistToBank(int bank);
static COLOR color(u32 r, u32 g, u32 b);
COLOR change(int bank, int index, COLOR newColor);
}; };
class BackgroundPaletteManager : public PaletteManager { class BackgroundPaletteManager : public PaletteManager {
protected: protected:
void *palletteAddress() override { void *paletteAddress() override {
return pal_bg_mem; return pal_bg_mem;
} }
PALBANK *paletteBank() override {
return pal_bg_bank;
}
public: public:
BackgroundPaletteManager() : PaletteManager(nullptr) {}
BackgroundPaletteManager(const u16 paletteData[]) : PaletteManager(paletteData) {} BackgroundPaletteManager(const u16 paletteData[]) : PaletteManager(paletteData) {}
BackgroundPaletteManager(const u16 paletteData[], int size) : PaletteManager(paletteData, size) {} BackgroundPaletteManager(const u16 paletteData[], int size) : PaletteManager(paletteData, size) {}
}; };
@ -38,9 +48,14 @@ public:
class ForegroundPaletteManager : public PaletteManager { class ForegroundPaletteManager : public PaletteManager {
protected: protected:
void *palletteAddress() override { void *paletteAddress() override {
return pal_obj_mem; return pal_obj_mem;
} }
PALBANK *paletteBank() override {
return pal_obj_bank;
}
public: public:
ForegroundPaletteManager(const u16 paletteData[]) : PaletteManager(paletteData) {} ForegroundPaletteManager(const u16 paletteData[]) : PaletteManager(paletteData) {}
ForegroundPaletteManager(const u16 paletteData[], int size) : PaletteManager(paletteData, size) {} ForegroundPaletteManager(const u16 paletteData[], int size) : PaletteManager(paletteData, size) {}

View File

@ -522,7 +522,7 @@ const unsigned short bg_palette [] = {
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x7c1f, 0x0000, 0x7fff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000 0x0000, 0x0000, 0x0000, 0x0000
}; };