Chaosy
Tutorial Reviewer
- Joined
- Jun 9, 2011
- Messages
- 13,239
This is a project I started a week back, though I did most of the code today.
The code is a complete mess and is not fully MUI yet, (the periodic text is not, rest should be).
I will work more on the code, I don't want to highlight it, however this has not been done before as far as I know.
(gif in 16fps, the text appear smoother in the actual map, the gif is also slightly out of date)
https://i.gyazo.com/204ac1a3799f9930d3f5883044a65522.gif
The text is created by using # in the string.
The code is a complete mess and is not fully MUI yet, (the periodic text is not, rest should be).
I will work more on the code, I don't want to highlight it, however this has not been done before as far as I know.
(gif in 16fps, the text appear smoother in the actual map, the gif is also slightly out of date)

https://i.gyazo.com/204ac1a3799f9930d3f5883044a65522.gif
The text is created by using # in the string.
JASS:
//! zinc
library DEMO requires Board, BoardMessage
{
Board b;
function endOfMsgOne()
{
RowMsg.create(b, "Roses are #red#, violets are blue, I got a #random# message for #you#.", 1);
}
function onZero()
{
RowMsg bm;
b = Board.create();
b[0][0].width = 0.385;
b.visible[Player(0)] = true;
bm = RowMsg.create(b, "hello! this is a test #message# which should appear periodically.", 0);
bm.callback = endOfMsgOne;
}
function onInit()
{
TimerStart(CreateTimer(), 0, false, function onZero);
}
}
//! endzinc
JASS:
//! zinc
library BoardMessage requires TimerUtils, Board, ARGB, StrFlash
{
type onEnd extends function();
function onEndFunc(onEnd oE)
{
oE.evaluate();
}
public struct RowMsg
{
integer currentChar = 1, endChar, row;
boolean first = false, finished = false;
string color, colorEnd = "|r", cColor, toWrite, toWriteOriginal;
timer loopT;
Board bb;
ARGB c1, c2;
onEnd callback;
static method onLoop()
{
thistype this = GetTimerData(GetExpiredTimer());
string char = SubString(toWrite, currentChar, currentChar + 1), pre, end;
if(char == " ")
{
currentChar += 1;
char = SubString(toWrite, currentChar, currentChar + 1);
}
if(char == "#")
{
pre = SubString(toWrite, 0, currentChar);
end = SubString(toWrite, currentChar + 1, StringLength(toWrite));
if(!first)
{
toWrite = pre + color + end;
currentChar += StringLength(color);
first = true;
}
else if(first)
{
toWrite = pre + colorEnd + end;
currentChar += StringLength(colorEnd);
first = false;
}
}
bb[0][row].text = SubString(toWrite, 0, currentChar);
currentChar += 1;
if(currentChar > StringLength(toWrite))
{
StrFlash.create(toWriteOriginal, bb, row, c1, c2);
DestroyTimer(loopT);
if(callback != null)
{
onEndFunc(callback);
}
this.deallocate();
}
}
static method create(Board b, string s, integer r) -> thistype
{
thistype this = thistype.allocate();
bb = b;
toWrite = s;
toWriteOriginal = s;
c1 = ARGB.create(0, 255, 255, 0);
c2 = ARGB.create(0, 255, 0, 0);
row = r;
color = c1.GetColor();
if(r > b.row.count - 1)
{
b.row.count = r;
b[0][r].width = 0.385;
}
loopT = NewTimerEx(this);
TimerStart(loopT, 0.05, true, function thistype.onLoop);
return this;
}
}
}
//! endzinc
JASS:
//! zinc
library StrFlash requires TimerUtils, ARGB, Board
{
public struct StrFlash
{
integer rdif, gdif, bdif,
oR , oG , oB,
dR , dG , dB,
cR , cG , cB;
timer t;
integer row;
string text, otext;
real time = 0;
Board bb;
ARGB c, o, d;
static method onLoop()
{
thistype this = GetTimerData(GetExpiredTimer());
integer i = 0;
string pre, end, char;
boolean first = false;
if(cR != dR)
{
cR += rdif / 30;
if(cR > 255){
cR = 255;
}
else if(cR < 0){
cR = 0;
}
}
if(cB != dB)
{
cB += bdif / 30;
if(cB > 255){
cB = 255;
}
else if(cB < 0){
cB = 0;
}
}
if(cG != dG)
{
cG += gdif / 30;
if(cG > 255){
cG = 255;
}
else if(cG < 0){
cG = 0;
}
}
c = ARGB.create(0, cR, cG, cB);
while(i < StringLength(text))
{
char = SubString(text, i, i + 1);
if(char == "#")
{
pre = SubString(text, 0, i);
end = SubString(text, i + 1, StringLength(text));
if(!first)
{
text = pre + c.GetColor() + end;
i += StringLength(c.GetColor());
first = true;
}
else if(first)
{
text = pre + "|r" + end;
i += 2;
first = false;
}
bb[0][row].text = text;
}
i += 1;
}
text = otext;
if(cB == dB && cR == dR && cG == dG)
{
ReleaseTimer(t);
thistype.create(otext, bb, row, d, o);
this.destroy();
}
}
static method create(string s, Board b, integer r, ARGB c1, ARGB c2) -> thistype
{
thistype this = thistype.allocate();
o = c1;
d = c2;
oR = c1.red;
oG = c1.green;
oB = c1.blue;
cR = oR;
cG = oG;
cB = oB;
dR = c2.red;
dG = c2.green;
dB = c2.blue;
rdif = dR - oR;
gdif = dG - oG;
bdif = dB - oB;
text = s;
otext = s;
row = r;
bb = b;
t = NewTimerEx(this);
TimerStart(t, 0.03, true, function thistype.onLoop);
return this;
}
}
}
//! endzinc
Last edited: