From d14523b36c53d3fda35a6344435d8fbd2608da33 Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Wed, 16 Mar 2016 12:11:52 +0200 Subject: [PATCH] slightly better message system --- xmain_d2d.d | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/xmain_d2d.d b/xmain_d2d.d index 603d59f..18dd5d5 100644 --- a/xmain_d2d.d +++ b/xmain_d2d.d @@ -204,7 +204,7 @@ struct Message { int pauseMsecs; MonoTime removeTime; char[256] text; - const(char)[] txt; + usize textlen; } private import core.sync.mutex : Mutex; @@ -216,10 +216,11 @@ __gshared Mutex messageLock; shared static this () { messageLock = new Mutex(); } -void addMessage (const(char)[] msgtext, int pauseMsecs=3000) { +void addMessage (const(char)[] msgtext, int pauseMsecs=3000, bool noreplace=false) { messageLock.lock(); scope(exit) messageLock.unlock(); if (msgtext.length == 0) return; + conwriteln(msgtext); if (pauseMsecs <= 50) return; if (messagesUsed == messages.length) { // remove top message @@ -227,19 +228,32 @@ void addMessage (const(char)[] msgtext, int pauseMsecs=3000) { messages.ptr[0].alpha = 255; --messagesUsed; } + // quick replace + if (!noreplace && messagesUsed == 1) { + switch (messages.ptr[0].phase) { + case Message.Phase.FadeIn: + messages.ptr[0].phase = Message.Phase.FadeOut; + break; + case Message.Phase.Stay: + messages.ptr[0].phase = Message.Phase.FadeOut; + messages.ptr[0].alpha = 255; + break; + default: + } + } auto msg = messages.ptr+messagesUsed; + ++messagesUsed; msg.phase = Message.Phase.FadeIn; msg.alpha = 0; msg.pauseMsecs = pauseMsecs; // copy text if (msgtext.length > msg.text.length) { msg.text = msgtext[0..msg.text.length]; - msg.txt = msg.text[0..$]; + msg.textlen = msg.text.length; } else { - msg.text[0..msgtext.length] = msgtext[0..$]; - msg.txt = msg.text[0..msgtext.length]; + msg.text[0..msgtext.length] = msgtext[]; + msg.textlen = msgtext.length; } - ++messagesUsed; } @@ -283,8 +297,7 @@ void doMessages (MonoTime curtime) { break; } - //glColor4f(1.0f, 1.0f, 1.0f, 0.5f); - smDrawText(10, 10, msg.txt); + smDrawText(10, 10, msg.text[0..msg.textlen]); } -- 2.11.4.GIT