new message styles

This commit is contained in:
Zeno Rogue 2017-10-08 14:49:49 +02:00
parent 081d24edd7
commit 7384f5ca34
4 changed files with 77 additions and 9 deletions

View File

@ -762,27 +762,79 @@ int colormix(int a, int b, int c) {
return a;
}
int rhypot(int a, int b) { return (int) sqrt(a*a - b*b); }
void drawmessage(const string& s, int& y, int col) {
int rrad = min(vid.radius, min(vid.xres, vid.yres) / 2);
int space;
if(y > vid.ycenter + rrad)
space = vid.xres;
else if(y > vid.ycenter)
space = vid.xcenter - rhypot(rrad, y-vid.ycenter);
else if(y > vid.ycenter - vid.fsize)
space = vid.xcenter - rrad;
else if(y > vid.ycenter - vid.fsize - rrad)
space = vid.xcenter - rhypot(rrad, vid.ycenter-vid.fsize-y);
else
space = vid.xres;
if(textwidth(vid.fsize, s) <= space) {
displayfr(0, y, 1, vid.fsize, s, col, 0);
y -= vid.fsize;
return;
}
for(int i=1; i<size(s); i++)
if(s[i-1] == ' ' && textwidth(vid.fsize, "..."+s.substr(i)) <= space) {
displayfr(0, y, 1, vid.fsize, "..."+s.substr(i), col, 0);
y -= vid.fsize;
drawmessage(s.substr(0, i-1), y, col);
return;
}
// no chance
displayfr(0, y, 1, vid.fsize, s, col, 0);
y -= vid.fsize;
return;
}
void drawmessages() {
DEBB(DF_GRAPH, (debugfile,"draw messages\n"));
int i = 0;
int t = ticks;
for(int j=0; j<size(msgs) && j<5; j++) {
for(int j=0; j<size(msgs); j++) {
if(j < size(msgs) - vid.msglimit) continue;
int age = msgs[j].flashout * (t - msgs[j].stamp);
if(msgs[j].spamtype) {
for(int i=j+1; i<size(msgs); i++) if(msgs[i].spamtype == msgs[j].spamtype)
msgs[j].flashout = 2;
}
if(age < 256*vid.flashtime) {
int x = vid.xres / 2;
if(age < 256*vid.flashtime)
msgs[i++] = msgs[j];
}
msgs.resize(i);
if(vid.msgleft == 2) {
int y = vid.yres - vid.fsize - (ISIOS ? 4 : 0);
for(int j=size(msgs)-1; j>=0; j--) {
int age = msgs[j].flashout * (t - msgs[j].stamp);
poly_outline = gradient(bordcolor, backcolor, 0, age, 256*vid.flashtime) << 8;
int col = gradient(forecolor, backcolor, 0, age, 256*vid.flashtime);
string s = msgs[j].msg;
if(msgs[j].quantity > 1) s += " (x" + its(msgs[j].quantity) + ")";
drawmessage(s, y, col);
}
}
else {
for(int j=0; j<size(msgs); j++) {
int age = msgs[j].flashout * (t - msgs[j].stamp);
int x = vid.msgleft ? 0 : vid.xres / 2;
int y = vid.yres - vid.fsize * (size(msgs) - j) - (ISIOS ? 4 : 0);
string s = msgs[j].msg;
if(msgs[j].quantity > 1) s += " (x" + its(msgs[j].quantity) + ")";
poly_outline = gradient(bordcolor, backcolor, 0, age, 256*vid.flashtime) << 8;
displayfr(x, y, 1, vid.fsize, s, gradient(forecolor, backcolor, 0, age, 256*vid.flashtime), 8);
msgs[i++] = msgs[j];
displayfr(x, y, 1, vid.fsize, s, gradient(forecolor, backcolor, 0, age, 256*vid.flashtime), vid.msgleft ? 0 : 8);
}
}
msgs.resize(i);
}
int gradient(int c0, int c1, ld v0, ld v, ld v1) {

View File

@ -301,6 +301,9 @@ void initConfig() {
addsaverenum(specialland, "land for special modes");
addsaver(viewdists, "expansion mode");
addsaver(vid.msgleft, "message style", 2);
addsaver(vid.msglimit, "message limit", 5);
#if CAP_SHMUP
shmup::initConfig();
@ -752,6 +755,11 @@ void showBasicConfig() {
dialog::addBoolItem(XLAT("draw circle around the target"), (vid.drawmousecircle), 'd');
dialog::addSelItem(XLAT("message flash time"), its(vid.flashtime), 't');
dialog::addSelItem(XLAT("limit messages shown"), its(vid.msglimit), 'z');
const char* msgstyles[3] = {"centered", "left-aligned", "line-broken"};
dialog::addSelItem(XLAT("message style"), XLAT(msgstyles[vid.msgleft]), 'a');
#if ISMOBILE
dialog::addBoolItem(XLAT("targetting ranged Orbs long-click only"), (vid.shifttarget&2), 'i');
@ -821,8 +829,14 @@ void showBasicConfig() {
if(xuni == 't')
dialog::editNumber(vid.flashtime, 0, 64, 1, 8, XLAT("message flash time"),
XLAT("How long should the messages stay on the screen."));
if(xuni == 'z')
dialog::editNumber(vid.msglimit, 0, 64, 1, 5, XLAT("limit messages shown"),
XLAT("Maximum number of messages on screen."));
if(xuni == 'i') { vid.shifttarget = vid.shifttarget^3; }
if(xuni == 'a') { vid.msgleft = (1+vid.msgleft) % 3; }
handleAllConfig(sym, xuni);
};

View File

@ -90,7 +90,7 @@ int glyphsortkey = 0;
int glyphcorner(int i) {
if(i < ittypes)
return itemclass(eItem(i)) == IC_ORB ? 2 : 0;
return itemclass(eItem(i)) == IC_ORB ? 3 : 0;
else
return 1;
}
@ -333,7 +333,7 @@ void drawStats() {
updatesort();
stable_sort(glyphorder, glyphorder+glyphs, glyphsort);
int rad = min(vid.xres, vid.yres) / 2;
for(int cor=0; cor<3; cor++) {
for(int cor=0; cor<4; cor++) {
for(int a=5; a<41; a++) {
int s = min(vid.xres, vid.yres) / a;
int spots = 0;
@ -372,7 +372,7 @@ void drawStats() {
instat = false;
bool portrait = vid.xres < vid.yres;
int colspace = portrait ? (vid.yres - vid.xres - vid.fsize*3) : (vid.xres - vid.yres - 16) / 2;
int rowspace = portrait ? vid.xres - 16 : vid.yres - vid.fsize * 4;
int rowspace = portrait ? vid.xres - 16 : vid.yres - vid.fsize * (vid.msgleft ? 9 : 4);
int colid[4], rowid[4];
int maxbyclass[4];
for(int z=0; z<4; z++) maxbyclass[z] = 0;

View File

@ -334,6 +334,8 @@ struct videopar {
int wallmode, monmode, axes;
bool revcontrol;
int msgleft, msglimit;
// for OpenGL
float scrdist;