Readded global log
This commit is contained in:
parent
3c5e41af94
commit
19db2a57ea
4 changed files with 56 additions and 37 deletions
|
|
@ -48,6 +48,7 @@ MainProgram::MainProgram():
|
||||||
logMessages.emplace_front(Toolbar::LogMessage{text, Toolbar::LogMessage::COLOR_ERROR});
|
logMessages.emplace_front(Toolbar::LogMessage{text, Toolbar::LogMessage::COLOR_ERROR});
|
||||||
if(logMessages.size() == LOG_SIZE)
|
if(logMessages.size() == LOG_SIZE)
|
||||||
logMessages.pop_back();
|
logMessages.pop_back();
|
||||||
|
g.gui.set_to_layout();
|
||||||
});
|
});
|
||||||
|
|
||||||
Logger::get().add_log("USERINFO", [&](const std::string& text) {
|
Logger::get().add_log("USERINFO", [&](const std::string& text) {
|
||||||
|
|
@ -56,11 +57,13 @@ MainProgram::MainProgram():
|
||||||
logMessages.emplace_front(Toolbar::LogMessage{text, Toolbar::LogMessage::COLOR_NORMAL});
|
logMessages.emplace_front(Toolbar::LogMessage{text, Toolbar::LogMessage::COLOR_NORMAL});
|
||||||
if(logMessages.size() == LOG_SIZE)
|
if(logMessages.size() == LOG_SIZE)
|
||||||
logMessages.pop_back();
|
logMessages.pop_back();
|
||||||
|
g.gui.set_to_layout();
|
||||||
});
|
});
|
||||||
|
|
||||||
Logger::get().add_log("CHAT", [&](const std::string& text) {
|
Logger::get().add_log("CHAT", [&](const std::string& text) {
|
||||||
*logFile << "[CHAT] " << text << std::endl;
|
*logFile << "[CHAT] " << text << std::endl;
|
||||||
std::cout << "[CHAT] " << text << std::endl;
|
std::cout << "[CHAT] " << text << std::endl;
|
||||||
|
g.gui.set_to_layout();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,8 +84,11 @@ void MainProgram::update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
g.update();
|
g.update();
|
||||||
|
toolbar.update();
|
||||||
|
|
||||||
NetLibrary::update();
|
NetLibrary::update();
|
||||||
|
|
||||||
|
post_callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainProgram::app_close_requested() {
|
bool MainProgram::app_close_requested() {
|
||||||
|
|
@ -318,6 +324,7 @@ bool MainProgram::input_keybind_callback(const Vector2ui32& newKey) {
|
||||||
input.keyAssignments.emplace(newKey, v);
|
input.keyAssignments.emplace(newKey, v);
|
||||||
keybindWaiting = std::nullopt;
|
keybindWaiting = std::nullopt;
|
||||||
g.gui.set_to_layout();
|
g.gui.set_to_layout();
|
||||||
|
post_callback();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -81,8 +81,6 @@ class MainProgram {
|
||||||
std::ofstream* logFile;
|
std::ofstream* logFile;
|
||||||
std::deque<Toolbar::LogMessage> logMessages;
|
std::deque<Toolbar::LogMessage> logMessages;
|
||||||
|
|
||||||
std::string newAddr;
|
|
||||||
|
|
||||||
MainProgram();
|
MainProgram();
|
||||||
void update();
|
void update();
|
||||||
void draw(SkCanvas* canvas, std::shared_ptr<World> worldToDraw, const DrawData& drawData);
|
void draw(SkCanvas* canvas, std::shared_ptr<World> worldToDraw, const DrawData& drawData);
|
||||||
|
|
|
||||||
|
|
@ -246,6 +246,17 @@ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR I
|
||||||
)";
|
)";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Toolbar::update() {
|
||||||
|
std::erase_if(main.logMessages, [&](auto& logM) {
|
||||||
|
logM.time.update_time_since();
|
||||||
|
if(logM.time > LogMessage::FADE_START_TIME) {
|
||||||
|
main.g.gui.set_to_layout();
|
||||||
|
return logM.time >= LogMessage::DISPLAY_TIME;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void Toolbar::layout_run() {
|
void Toolbar::layout_run() {
|
||||||
auto& gui = main.g.gui;
|
auto& gui = main.g.gui;
|
||||||
auto& io = gui.io;
|
auto& io = gui.io;
|
||||||
|
|
@ -1149,41 +1160,41 @@ void Toolbar::global_log() {
|
||||||
},
|
},
|
||||||
.floating = {.offset = {0, 10}, .attachPoints = {.element = CLAY_ATTACH_POINT_RIGHT_TOP, .parent = CLAY_ATTACH_POINT_RIGHT_BOTTOM}, .attachTo = CLAY_ATTACH_TO_PARENT}
|
.floating = {.offset = {0, 10}, .attachPoints = {.element = CLAY_ATTACH_POINT_RIGHT_TOP, .parent = CLAY_ATTACH_POINT_RIGHT_BOTTOM}, .attachTo = CLAY_ATTACH_TO_PARENT}
|
||||||
}) {
|
}) {
|
||||||
// constexpr float DISPLAY_TIME = 8.0f;
|
int i = 0;
|
||||||
// constexpr float FADE_START_TIME = 7.0f;
|
for(auto& logM : main.logMessages) {
|
||||||
// int i = 0;
|
logM.time.update_time_since();
|
||||||
// for(auto& logM : main.logMessages) {
|
if(logM.time < LogMessage::DISPLAY_TIME) {
|
||||||
// logM.time.update_time_since();
|
float a = 1.0f - lerp_time<float>(logM.time, LogMessage::DISPLAY_TIME, LogMessage::FADE_START_TIME);
|
||||||
// if(logM.time < DISPLAY_TIME) {
|
gui.new_id(i, [&] {
|
||||||
// float a = 1.0f - lerp_time<float>(logM.time, DISPLAY_TIME, FADE_START_TIME);
|
gui.element<LayoutElement>("GLOBAL LOG", [&] (LayoutElement*, const Clay_ElementId& lId) {
|
||||||
// Clay_ElementId elemId = CLAY_IDI_LOCAL("GLOBAL LOG", i++);
|
CLAY(lId, {
|
||||||
// CLAY(elemId, {
|
.layout = {
|
||||||
// .layout = {
|
.sizing = {.width = CLAY_SIZING_FIT(300), .height = CLAY_SIZING_FIT(0) },
|
||||||
// .sizing = {.width = CLAY_SIZING_FIT(300), .height = CLAY_SIZING_FIT(0) },
|
.padding = CLAY_PADDING_ALL(io.theme->padding1),
|
||||||
// .padding = CLAY_PADDING_ALL(io.theme->padding1),
|
.childGap = 0,
|
||||||
// .childGap = 0,
|
.childAlignment = { .x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_TOP},
|
||||||
// .childAlignment = { .x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_TOP},
|
.layoutDirection = CLAY_TOP_TO_BOTTOM
|
||||||
// .layoutDirection = CLAY_TOP_TO_BOTTOM
|
},
|
||||||
// },
|
.backgroundColor = convert_vec4<Clay_Color>(color_mul_alpha(io.theme->backColor1, a)),
|
||||||
// .backgroundColor = convert_vec4<Clay_Color>(color_mul_alpha(io.theme->backColor1, a)),
|
.cornerRadius = CLAY_CORNER_RADIUS(io.theme->windowCorners1)
|
||||||
// .cornerRadius = CLAY_CORNER_RADIUS(io.theme->windowCorners1)
|
}) {
|
||||||
// }) {
|
SkColor4f c{0, 0, 0, 0};
|
||||||
// gui.obstructing_window(elemId);
|
switch(logM.color) {
|
||||||
// SkColor4f c{0, 0, 0, 0};
|
case LogMessage::COLOR_NORMAL:
|
||||||
// switch(logM.color) {
|
c = io.theme->frontColor1;
|
||||||
// case LogMessage::COLOR_NORMAL:
|
break;
|
||||||
// c = io.theme->frontColor1;
|
case LogMessage::COLOR_ERROR:
|
||||||
// break;
|
c = io.theme->errorColor;
|
||||||
// case LogMessage::COLOR_ERROR:
|
break;
|
||||||
// c = io.theme->errorColor;
|
}
|
||||||
// break;
|
text_label_color(gui, logM.text, color_mul_alpha(c, a));
|
||||||
// }
|
}
|
||||||
// gui.text_label_color(logM.text, color_mul_alpha(c, a));
|
});
|
||||||
// }
|
});
|
||||||
// }
|
}
|
||||||
// else
|
else
|
||||||
// break;
|
break;
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ class MainProgram;
|
||||||
class Toolbar {
|
class Toolbar {
|
||||||
public:
|
public:
|
||||||
struct LogMessage {
|
struct LogMessage {
|
||||||
|
static constexpr float DISPLAY_TIME = 8.0f;
|
||||||
|
static constexpr float FADE_START_TIME = 7.0f;
|
||||||
std::string text;
|
std::string text;
|
||||||
enum {
|
enum {
|
||||||
COLOR_NORMAL = 0,
|
COLOR_NORMAL = 0,
|
||||||
|
|
@ -41,6 +43,7 @@ class Toolbar {
|
||||||
std::string chatMessageInput;
|
std::string chatMessageInput;
|
||||||
|
|
||||||
Toolbar(MainProgram& initMain);
|
Toolbar(MainProgram& initMain);
|
||||||
|
void update();
|
||||||
void layout_run();
|
void layout_run();
|
||||||
struct ColorSelectorData {
|
struct ColorSelectorData {
|
||||||
std::function<void()> onChange;
|
std::function<void()> onChange;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue