Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/frontend
diff options
context:
space:
mode:
Diffstat (limited to 'source/frontend')
-rw-r--r--source/frontend/StarActionBar.cpp2
-rw-r--r--source/frontend/StarChat.cpp74
-rw-r--r--source/frontend/StarChat.hpp7
-rw-r--r--source/frontend/StarChatBubbleManager.cpp43
-rw-r--r--source/frontend/StarChatBubbleManager.hpp5
-rw-r--r--source/frontend/StarCinematic.cpp10
-rw-r--r--source/frontend/StarCinematic.hpp3
-rw-r--r--source/frontend/StarClientCommandProcessor.cpp2
-rw-r--r--source/frontend/StarInterfaceLuaBindings.cpp48
-rw-r--r--source/frontend/StarInterfaceLuaBindings.hpp2
-rw-r--r--source/frontend/StarMainInterface.cpp62
-rw-r--r--source/frontend/StarMainInterface.hpp2
-rw-r--r--source/frontend/StarMainInterfaceTypes.cpp10
-rw-r--r--source/frontend/StarMainInterfaceTypes.hpp11
-rw-r--r--source/frontend/StarNameplatePainter.cpp41
-rw-r--r--source/frontend/StarNameplatePainter.hpp9
-rw-r--r--source/frontend/StarTeamBar.cpp3
-rw-r--r--source/frontend/StarTeamBar.hpp2
18 files changed, 164 insertions, 172 deletions
diff --git a/source/frontend/StarActionBar.cpp b/source/frontend/StarActionBar.cpp
index fb08e3b..9f78626 100644
--- a/source/frontend/StarActionBar.cpp
+++ b/source/frontend/StarActionBar.cpp
@@ -83,9 +83,7 @@ ActionBar::ActionBar(MainInterfacePaneManager* paneManager, PlayerPtr player) {
TextPositioning countPosition = {jsonToVec2F(m_config.get("countMidAnchor")), HorizontalAnchor::HMidAnchor};
customBarLeft->setCountPosition(countPosition);
- customBarLeft->setCountFontMode(FontMode::Shadow);
customBarRight->setCountPosition(countPosition);
- customBarRight->setCountFontMode(FontMode::Shadow);
m_customBarWidgets.append({customBarLeft, customBarRight, customBarLeftOverlay, customBarRightOverlay});
}
diff --git a/source/frontend/StarChat.cpp b/source/frontend/StarChat.cpp
index 688bf4a..d780d23 100644
--- a/source/frontend/StarChat.cpp
+++ b/source/frontend/StarChat.cpp
@@ -20,32 +20,30 @@ Chat::Chat(UniverseClientPtr client) : m_client(client) {
m_historyOffset = 0;
auto assets = Root::singleton().assets();
+ auto config = assets->json("/interface/chat/chat.config:config");
m_timeChatLastActive = Time::monotonicMilliseconds();
- auto fontConfig = assets->json("/interface/chat/chat.config:config.font");
- m_fontSize = fontConfig.getInt("baseSize");
- m_fontDirectives = fontConfig.queryString("directives", "");
- m_font = fontConfig.queryString("type", "");
- m_chatLineHeight = assets->json("/interface/chat/chat.config:config.lineHeight").toFloat();
- m_chatVisTime = assets->json("/interface/chat/chat.config:config.visTime").toFloat();
- m_fadeRate = assets->json("/interface/chat/chat.config:config.fadeRate").toDouble();
- m_chatHistoryLimit = assets->json("/interface/chat/chat.config:config.chatHistoryLimit").toInt();
-
- m_portraitTextOffset = jsonToVec2I(assets->json("/interface/chat/chat.config:config.portraitTextOffset"));
- m_portraitImageOffset = jsonToVec2I(assets->json("/interface/chat/chat.config:config.portraitImageOffset"));
- m_portraitScale = assets->json("/interface/chat/chat.config:config.portraitScale").toFloat();
- m_portraitVerticalMargin = assets->json("/interface/chat/chat.config:config.portraitVerticalMargin").toFloat();
- m_portraitBackground = assets->json("/interface/chat/chat.config:config.portraitBackground").toString();
-
- m_bodyHeight = assets->json("/interface/chat/chat.config:config.bodyHeight").toInt();
- m_expandedBodyHeight = assets->json("/interface/chat/chat.config:config.expandedBodyHeight").toInt();
-
- m_colorCodes[MessageContext::Local] = assets->json("/interface/chat/chat.config:config.colors.local").toString();
- m_colorCodes[MessageContext::Party] = assets->json("/interface/chat/chat.config:config.colors.party").toString();
- m_colorCodes[MessageContext::Broadcast] = assets->json("/interface/chat/chat.config:config.colors.broadcast").toString();
- m_colorCodes[MessageContext::Whisper] = assets->json("/interface/chat/chat.config:config.colors.whisper").toString();
- m_colorCodes[MessageContext::CommandResult] = assets->json("/interface/chat/chat.config:config.colors.commandResult").toString();
- m_colorCodes[MessageContext::RadioMessage] = assets->json("/interface/chat/chat.config:config.colors.radioMessage").toString();
- m_colorCodes[MessageContext::World] = assets->json("/interface/chat/chat.config:config.colors.world").toString();
+ m_chatTextStyle = config.get("textStyle");
+ m_chatTextStyle.lineSpacing = config.get("lineHeight").toFloat();
+ m_chatVisTime = config.get("visTime").toFloat();
+ m_fadeRate = config.get("fadeRate").toDouble();
+ m_chatHistoryLimit = config.get("chatHistoryLimit").toInt();
+
+ m_portraitTextOffset = jsonToVec2I(config.get("portraitTextOffset"));
+ m_portraitImageOffset = jsonToVec2I(config.get("portraitImageOffset"));
+ m_portraitScale = config.get("portraitScale").toFloat();
+ m_portraitVerticalMargin = config.get("portraitVerticalMargin").toFloat();
+ m_portraitBackground = config.get("portraitBackground").toString();
+
+ m_bodyHeight = config.get("bodyHeight").toInt();
+ m_expandedBodyHeight = config.get("expandedBodyHeight").toInt();
+
+ m_colorCodes[MessageContext::Local] = config.query("colors.local").toString();
+ m_colorCodes[MessageContext::Party] = config.query("colors.party").toString();
+ m_colorCodes[MessageContext::Broadcast] = config.query("colors.broadcast").toString();
+ m_colorCodes[MessageContext::Whisper] = config.query("colors.whisper").toString();
+ m_colorCodes[MessageContext::CommandResult] = config.query("colors.commandResult").toString();
+ m_colorCodes[MessageContext::RadioMessage] = config.query("colors.radioMessage").toString();
+ m_colorCodes[MessageContext::World] = config.query("colors.world").toString();
GuiReader reader;
@@ -72,7 +70,7 @@ Chat::Chat(UniverseClientPtr client) : m_client(client) {
m_say = fetchChild<LabelWidget>("say");
m_chatLog = fetchChild<CanvasWidget>("chatLog");
- if (auto logPadding = fontConfig.optQuery("padding")) {
+ if (auto logPadding = config.optQuery("padding")) {
m_chatLogPadding = jsonToVec2I(logPadding.get());
m_chatLog->setSize(m_chatLog->size() + m_chatLogPadding * 2);
m_chatLog->setPosition(m_chatLog->position() - m_chatLogPadding);
@@ -133,8 +131,8 @@ String Chat::currentChat() const {
return m_textBox->getText();
}
-void Chat::setCurrentChat(String const& chat) {
- m_textBox->setText(chat);
+bool Chat::setCurrentChat(String const& chat, bool moveCursor) {
+ return m_textBox->setText(chat, true, moveCursor);
}
void Chat::clearCurrentChat() {
@@ -179,8 +177,7 @@ void Chat::addMessages(List<ChatReceivedMessage> const& messages, bool showPane)
if (message.portrait.empty())
wrapWidth = m_chatLog->size()[0] - m_chatLogPadding[0] * 2;
- guiContext.setFont(m_font);
- guiContext.setFontSize(m_fontSize);
+ guiContext.setTextStyle(m_chatTextStyle);
StringList lines;
if (message.fromNick != "" && message.portrait == "")
lines = guiContext.wrapInterfaceText(strf("<{}> {}", message.fromNick, message.text), wrapWidth);
@@ -239,10 +236,10 @@ void Chat::renderImpl() {
int messageIndex = -m_historyOffset;
GuiContext& guiContext = GuiContext::singleton();
- guiContext.setFont(m_font);
- guiContext.setFontSize(m_fontSize);
- guiContext.setLineSpacing(m_chatLineHeight);
- for (auto message : m_receivedMessages) {
+ float lineHeight = m_chatTextStyle.lineSpacing;
+ float fontSize = m_chatTextStyle.fontSize;
+ guiContext.setTextStyle(m_chatTextStyle);
+ for (auto& message : m_receivedMessages) {
if (!m_modeFilter.empty() && !m_modeFilter.contains(message.mode))
continue;
@@ -260,7 +257,7 @@ void Chat::renderImpl() {
String messageString = channelColorCode + message.text;
float messageHeight = 0;
- float lineHeightMargin = + ((m_chatLineHeight * m_fontSize) - m_fontSize);
+ float lineHeightMargin = ((lineHeight * fontSize) - fontSize);
unsigned wrapWidth = m_chatLog->size()[0] - m_chatLogPadding[0] * 2;
if (message.portrait != "") {
@@ -274,13 +271,14 @@ void Chat::renderImpl() {
m_chatLog->drawImage(m_portraitBackground, Vec2F(imagePosition), 1.0f, fade);
m_chatLog->drawImage(message.portrait, Vec2F(imagePosition + m_portraitImageOffset), m_portraitScale, fade);
tp.pos += Vec2F(0, floor(messageHeight / 2));
- m_chatLog->drawText(messageString, tp, m_fontSize, fade, FontMode::Normal, m_chatLineHeight, m_font, m_fontDirectives);
+ m_chatTextStyle.color = fade;
+ m_chatLog->drawText(messageString, tp, m_chatTextStyle);
} else {
TextPositioning tp = {Vec2F(chatMin), HorizontalAnchor::LeftAnchor, VerticalAnchor::BottomAnchor, wrapWidth};
messageHeight = guiContext.determineInterfaceTextSize(messageString, tp).size()[1] + lineHeightMargin;
-
- m_chatLog->drawText(messageString, tp, m_fontSize, fade, FontMode::Normal, m_chatLineHeight, m_font, m_fontDirectives);
+ m_chatTextStyle.color = fade;
+ m_chatLog->drawText(messageString, tp, m_chatTextStyle);
}
chatMin[1] += ceil(messageHeight);
diff --git a/source/frontend/StarChat.hpp b/source/frontend/StarChat.hpp
index 28117ff..80cf683 100644
--- a/source/frontend/StarChat.hpp
+++ b/source/frontend/StarChat.hpp
@@ -32,7 +32,7 @@ public:
void addHistory(String const& chat);
String currentChat() const;
- void setCurrentChat(String const& chat);
+ bool setCurrentChat(String const& chat, bool moveCursor = false);
void clearCurrentChat();
ChatSendMode sendMode() const;
@@ -66,10 +66,7 @@ private:
int64_t m_timeChatLastActive;
float m_chatVisTime;
float m_fadeRate;
- unsigned m_fontSize;
- String m_fontDirectives;
- String m_font;
- float m_chatLineHeight;
+ TextStyle m_chatTextStyle;
unsigned m_chatHistoryLimit;
int m_historyOffset;
diff --git a/source/frontend/StarChatBubbleManager.cpp b/source/frontend/StarChatBubbleManager.cpp
index b08e292..d837de7 100644
--- a/source/frontend/StarChatBubbleManager.cpp
+++ b/source/frontend/StarChatBubbleManager.cpp
@@ -20,9 +20,8 @@ ChatBubbleManager::ChatBubbleManager()
auto jsonData = assets->json("/interface/windowconfig/chatbubbles.config");
- m_color = jsonToColor(jsonData.get("textColor"));
-
- m_fontSize = jsonData.getInt("fontSize");
+ m_textStyle.color = jsonToColor(jsonData.get("textColor")).toRgba();
+ m_textStyle.loadJson(jsonData.get("textStyle"));
m_textPadding = jsonToVec2F(jsonData.get("textPadding"));
m_zoom = jsonData.getInt("textZoom");
@@ -196,9 +195,7 @@ void ChatBubbleManager::addChatActions(List<ChatAction> chatActions, bool silent
// bother me so bad if it weren't so fucking easy to do right.
// yea I agree
- m_guiContext->setFontSize(m_fontSize, m_zoom);
- m_guiContext->setFontProcessingDirectives("");
- m_guiContext->setDefaultFont();
+ m_guiContext->setTextStyle(m_textStyle);
auto result = m_guiContext->determineTextSize(sayAction.text, m_textTemplate);
float textWidth = result.width() / m_zoom + m_textPadding[0];
float textHeight = result.height() / m_zoom + m_textPadding[1];
@@ -252,14 +249,17 @@ void ChatBubbleManager::addChatActions(List<ChatAction> chatActions, bool silent
float verticalShift = (partSize * innerTiles[1] - textMultiLineShift) * 0.5f + textMultiLineShift;
Vec2F position = Vec2F(horizontalCenter, verticalShift);
List<BubbleText> bubbleTexts;
- auto fontSize = config.getUInt("fontSize", m_fontSize);
- auto color = config.opt("color").apply(jsonToColor).value(m_color);
- bubbleTexts.append(make_tuple(sayAction.text, fontSize, color.toRgba(), true, position));
+ TextStyle textStyle = m_textStyle;
+ textStyle.fontSize = config.getUInt("fontSize", textStyle.fontSize);
+ if (auto jColor = config.opt("color"))
+ textStyle.color = jsonToColor(*jColor).toRgba();
+ textStyle.loadJson(config.get("style", Json()));
+ bubbleTexts.append(make_tuple(sayAction.text, textStyle, true, position));
for (auto& backgroundImage : backgroundImages)
get<1>(backgroundImage) += Vec2F(-horizontalCenter, partSize);
for (auto& bubbleText : bubbleTexts)
- get<4>(bubbleText) += Vec2F(-horizontalCenter, partSize);
+ get<3>(bubbleText) += Vec2F(-horizontalCenter, partSize);
auto pos = m_camera.worldToScreen(sayAction.position + m_bubbleOffset);
RectF boundBox = fold(backgroundImages, RectF::null(), [pos, this](RectF const& boundBox, BubbleImage const& bubbleImage) {
@@ -272,7 +272,7 @@ void ChatBubbleManager::addChatActions(List<ChatAction> chatActions, bool silent
m_bubbles.filter([&sayAction](BubbleState<Bubble> const&, Bubble const& bubble) { return bubble.entity != sayAction.entity; });
m_bubbles.addBubble(pos, boundBox, std::move(bubble), m_interBubbleMargin * m_zoom);
oldBubbles.sort([](BubbleState<Bubble> const& a, BubbleState<Bubble> const& b) { return a.contents.age < b.contents.age; });
- for (auto bubble : oldBubbles.slice(0, m_maxMessagePerEntity - 1))
+ for (auto& bubble : oldBubbles.slice(0, m_maxMessagePerEntity - 1))
m_bubbles.addBubble(bubble.idealDestination, bubble.boundBox, bubble.contents, 0);
} else if (action.is<PortraitChatAction>()) {
@@ -286,12 +286,12 @@ void ChatBubbleManager::addChatActions(List<ChatAction> chatActions, bool silent
backgroundImages.append(make_tuple(m_portraitMoreImage, Vec2F(m_portraitMorePosition)));
backgroundImages.append(make_tuple(portraitAction.portrait, Vec2F(m_portraitPosition)));
List<BubbleText> bubbleTexts;
- bubbleTexts.append(make_tuple(portraitAction.text, m_fontSize, m_color.toRgba(), false, Vec2F(m_portraitTextPosition)));
+ bubbleTexts.append(make_tuple(portraitAction.text, m_textStyle, false, Vec2F(m_portraitTextPosition)));
for (auto& backgroundImage : backgroundImages)
get<1>(backgroundImage) += Vec2F(-m_portraitBackgroundSize[0] / 2, 0);
for (auto& bubbleText : bubbleTexts)
- get<4>(bubbleText) += Vec2F(-m_portraitBackgroundSize[0] / 2, 0);
+ get<3>(bubbleText) += Vec2F(-m_portraitBackgroundSize[0] / 2, 0);
m_portraitBubbles.prepend({
portraitAction.entity,
@@ -321,28 +321,19 @@ void ChatBubbleManager::addChatActions(List<ChatAction> chatActions, bool silent
RectF ChatBubbleManager::bubbleImageRect(Vec2F screenPos, BubbleImage const& bubbleImage, int pixelRatio) {
auto imgMetadata = Root::singleton().imageMetadataDatabase();
- auto image = get<0>(bubbleImage);
+ auto& image = get<0>(bubbleImage);
return RectF::withSize(screenPos + get<1>(bubbleImage) * pixelRatio, Vec2F(imgMetadata->imageSize(image)) * pixelRatio);
}
void ChatBubbleManager::drawBubbleImage(Vec2F screenPos, BubbleImage const& bubbleImage, int pixelRatio, int alpha) {
- auto image = get<0>(bubbleImage);
+ auto& image = get<0>(bubbleImage);
auto offset = get<1>(bubbleImage) * pixelRatio;
m_guiContext->drawQuad(image, screenPos + offset, pixelRatio, {255, 255, 255, alpha});
}
void ChatBubbleManager::drawBubbleText(Vec2F screenPos, BubbleText const& bubbleText, int pixelRatio, int alpha, bool isPortrait) {
- Vec4B const& baseColor = get<2>(bubbleText);
-
- // use the alpha as a blend value for the text colour as pulled from data.
- Vec4B const& displayColor = Vec4B(baseColor[0], baseColor[1], baseColor[2], (baseColor[3] * alpha) / 255);
-
- m_guiContext->setDefaultFont();
- m_guiContext->setFontProcessingDirectives("");
- m_guiContext->setFontColor(displayColor);
- m_guiContext->setFontSize(get<1>(bubbleText), m_zoom);
-
- auto offset = get<4>(bubbleText) * pixelRatio;
+ m_guiContext->setTextStyle(get<1>(bubbleText), m_zoom);
+ auto offset = get<3>(bubbleText) * pixelRatio;
TextPositioning tp = isPortrait ? m_portraitTextTemplate : m_textTemplate;
tp.pos = screenPos + offset;
diff --git a/source/frontend/StarChatBubbleManager.hpp b/source/frontend/StarChatBubbleManager.hpp
index cf46fcc..42b58db 100644
--- a/source/frontend/StarChatBubbleManager.hpp
+++ b/source/frontend/StarChatBubbleManager.hpp
@@ -26,7 +26,7 @@ public:
private:
typedef tuple<String, Vec2F> BubbleImage;
- typedef tuple<String, unsigned, Vec4B, bool, Vec2F> BubbleText;
+ typedef tuple<String, TextStyle, bool, Vec2F> BubbleText;
struct Bubble {
EntityId entity;
@@ -64,8 +64,7 @@ private:
TextPositioning m_textTemplate;
TextPositioning m_portraitTextTemplate;
- Color m_color;
- int m_fontSize;
+ TextStyle m_textStyle;
Vec2F m_textPadding;
BubbleSeparator<Bubble> m_bubbles;
diff --git a/source/frontend/StarCinematic.cpp b/source/frontend/StarCinematic.cpp
index abd638d..c2dbd20 100644
--- a/source/frontend/StarCinematic.cpp
+++ b/source/frontend/StarCinematic.cpp
@@ -45,8 +45,9 @@ void Cinematic::load(Json const& definition) {
panel->animationFrames = panelDefinition.getInt("animationFrames", std::numeric_limits<int>::max());
panel->text = panelDefinition.getString("text", "");
panel->textPosition = TextPositioning(panelDefinition.get("textPosition", JsonObject()));
- panel->fontColor = panelDefinition.opt("fontColor").apply(jsonToVec4B).value(Vec4B(255, 255, 255, 255));
- panel->fontSize = panelDefinition.getUInt("fontSize", 8);
+ panel->textStyle = panelDefinition.get("textStyle", Json());
+ panel->textStyle.color = panelDefinition.opt("fontColor").apply(jsonToVec4B).value(panel->textStyle.color);
+ panel->textStyle.fontSize = panelDefinition.getUInt("fontSize", panel->textStyle.fontSize);
panel->avatar = panelDefinition.getString("avatar", "");
panel->startTime = panelDefinition.getFloat("startTime", 0);
panel->endTime = panelDefinition.getFloat("endTime", 0);
@@ -208,8 +209,9 @@ void Cinematic::render() {
}
}
if (!panel->text.empty()) {
- textPainter->setFontSize(floor(panel->fontSize * drawableScale));
- auto fontColor = panel->fontColor;
+ textPainter->setTextStyle(panel->textStyle);
+ textPainter->setFontSize(floor(panel->textStyle.fontSize * drawableScale));
+ auto fontColor = panel->textStyle.color;
fontColor[3] *= values.alpha;
textPainter->setFontColor(fontColor);
Vec2F position = (m_offset + values.position + Vec2F(panel->textPosition.pos)) * drawableScale + drawableTranslation;
diff --git a/source/frontend/StarCinematic.hpp b/source/frontend/StarCinematic.hpp
index 15ff2cd..b2e3c81 100644
--- a/source/frontend/StarCinematic.hpp
+++ b/source/frontend/StarCinematic.hpp
@@ -62,8 +62,7 @@ private:
int animationFrames;
String text;
TextPositioning textPosition;
- Vec4B fontColor;
- unsigned fontSize;
+ TextStyle textStyle;
List<KeyFrame> keyFrames;
float startTime;
float endTime;
diff --git a/source/frontend/StarClientCommandProcessor.cpp b/source/frontend/StarClientCommandProcessor.cpp
index 52882d9..def1b43 100644
--- a/source/frontend/StarClientCommandProcessor.cpp
+++ b/source/frontend/StarClientCommandProcessor.cpp
@@ -91,7 +91,7 @@ StringList ClientCommandProcessor::handleCommand(String const& commandLine) {
}
} else {
auto player = m_universeClient->mainPlayer();
- if (auto messageResult = player->receiveMessage(connectionForEntity(player->entityId()), strf("/{}", command), { allArguments }))
+ if (auto messageResult = player->receiveMessage(connectionForEntity(player->entityId()), "/" + command, { allArguments }))
result.append(messageResult->isType(Json::Type::String) ? *messageResult->stringPtr() : messageResult->repr(1, true));
else
m_universeClient->sendChat(commandLine, ChatSendMode::Broadcast);
diff --git a/source/frontend/StarInterfaceLuaBindings.cpp b/source/frontend/StarInterfaceLuaBindings.cpp
index a023a71..9e0bb2e 100644
--- a/source/frontend/StarInterfaceLuaBindings.cpp
+++ b/source/frontend/StarInterfaceLuaBindings.cpp
@@ -4,6 +4,9 @@
#include "StarLuaGameConverters.hpp"
#include "StarMainInterface.hpp"
#include "StarGuiContext.hpp"
+#include "StarChat.hpp"
+#include "StarUniverseClient.hpp"
+#include "StarClientCommandProcessor.hpp"
namespace Star {
@@ -42,4 +45,49 @@ LuaCallbacks LuaBindings::makeInterfaceCallbacks(MainInterface* mainInterface) {
return callbacks;
}
+LuaCallbacks LuaBindings::makeChatCallbacks(MainInterface* mainInterface, UniverseClient* client) {
+ LuaCallbacks callbacks;
+
+ auto chat = as<Chat>(mainInterface->paneManager()->registeredPane(MainInterfacePanes::Chat).get());
+
+ callbacks.registerCallback("send", [chat, client](String const& message, Maybe<String> modeName, Maybe<bool> speak) {
+ auto sendMode = modeName ? ChatSendModeNames.getLeft(*modeName) : ChatSendMode::Broadcast;
+ client->sendChat(message, sendMode, speak);
+ });
+
+ // just for SE compat - this shoulda been a utility callback :moyai:
+ callbacks.registerCallback("parseArguments", [](String const& args) {
+ return Json::parseSequence(args);
+ });
+
+ callbacks.registerCallback("command", [mainInterface](String const& command) -> StringList {
+ return mainInterface->commandProcessor()->handleCommand(command);
+ });
+
+ callbacks.registerCallback("addMessage", [client, chat](String const& text, Maybe<Json> config) {
+ ChatReceivedMessage message({MessageContext::Mode::CommandResult, ""}, client->clientContext()->connectionId(), "", text);
+ if (config) {
+ if (auto mode = config->optString("mode"))
+ message.context.mode = MessageContextModeNames.getLeft(*mode);
+ if (auto channelName = config->optString("channelName"))
+ message.context.channelName = std::move(*channelName);
+ if (auto portrait = config->optString("portrait"))
+ message.portrait = std::move(*portrait);
+ if (auto fromNick = config->optString("fromNick"))
+ message.fromNick = std::move(*fromNick);
+ }
+ chat->addMessages({std::move(message)}, config ? config->getBool("showPane", true) : true);
+ });
+
+ callbacks.registerCallback("input", [chat]() -> String {
+ return chat->currentChat();
+ });
+
+ callbacks.registerCallback("setInput", [chat](String const& text, Maybe<bool> moveCursor) -> bool {
+ return chat->setCurrentChat(text, moveCursor.value(false));
+ });
+
+ return callbacks;
+}
+
}
diff --git a/source/frontend/StarInterfaceLuaBindings.hpp b/source/frontend/StarInterfaceLuaBindings.hpp
index 539cceb..2973f18 100644
--- a/source/frontend/StarInterfaceLuaBindings.hpp
+++ b/source/frontend/StarInterfaceLuaBindings.hpp
@@ -5,9 +5,11 @@
namespace Star {
STAR_CLASS(MainInterface);
+STAR_CLASS(UniverseClient);
namespace LuaBindings {
LuaCallbacks makeInterfaceCallbacks(MainInterface* mainInterface);
+ LuaCallbacks makeChatCallbacks(MainInterface* mainInterface, UniverseClient* client);
}
}
diff --git a/source/frontend/StarMainInterface.cpp b/source/frontend/StarMainInterface.cpp
index 4303a28..ece00a5 100644
--- a/source/frontend/StarMainInterface.cpp
+++ b/source/frontend/StarMainInterface.cpp
@@ -160,10 +160,8 @@ MainInterface::MainInterface(UniverseClientPtr client, WorldPainterPtr painter,
auto planetName = make_shared<Pane>();
m_planetText = make_shared<LabelWidget>();
- m_planetText->setFontSize(m_config->planetNameFontSize);
- m_planetText->setFontMode(FontMode::Normal);
+ m_planetText->setTextStyle(m_config->planetNameTextStyle);
m_planetText->setAnchor(HorizontalAnchor::HMidAnchor, VerticalAnchor::VMidAnchor);
- m_planetText->setDirectives(m_config->planetNameDirectives);
planetName->disableScissoring();
planetName->setPosition(m_config->planetNameOffset);
planetName->setAnchor(PaneAnchor::Center);
@@ -810,9 +808,7 @@ void MainInterface::renderInWorldElements() {
if (m_disableHud)
return;
- m_guiContext->setDefaultFont();
- m_guiContext->setFontProcessingDirectives("");
- m_guiContext->setFontColor(Vec4B::filled(255));
+ m_guiContext->clearTextStyle();
m_questIndicatorPainter->render();
m_nameplatePainter->render();
m_chatBubbleManager->render();
@@ -822,9 +818,7 @@ void MainInterface::render() {
if (m_disableHud)
return;
- m_guiContext->setDefaultFont();
- m_guiContext->setFontProcessingDirectives("");
- m_guiContext->setFontColor(Vec4B::filled(255));
+ m_guiContext->clearTextStyle();
renderBreath();
renderMessages();
renderMonsterHealthBar();
@@ -950,6 +944,10 @@ CanvasWidgetPtr MainInterface::fetchCanvas(String const& canvasName, bool ignore
return canvas;
}
+ClientCommandProcessorPtr MainInterface::commandProcessor() const {
+ return m_clientCommandProcessor;
+}
+
// For when the player swaps characters. We need to completely reload ScriptPanes,
// because a lot of ScriptPanes do not expect the character to suddenly change and may break or spill data over.
void MainInterface::takeScriptPanes(List<ScriptPaneInfo>& out) {
@@ -1084,9 +1082,7 @@ void MainInterface::renderMessages() {
m_guiContext->drawQuad(m_config->messageTextContainer,
RectF::withCenter(backgroundTextCenterPos, Vec2F(imgMetadata->imageSize(m_config->messageTextContainer) * interfaceScale())));
- m_guiContext->setFont(m_config->font);
- m_guiContext->setFontSize(m_config->fontSize);
- m_guiContext->setFontColor(Color::White.toRgba());
+ m_guiContext->setTextStyle(m_config->textStyle);
m_guiContext->renderText(message->message, {messageTextOffset, HorizontalAnchor::HMidAnchor, VerticalAnchor::VMidAnchor});
}
}
@@ -1112,9 +1108,7 @@ void MainInterface::renderMonsterHealthBar() {
m_guiContext->drawQuad(container, RectF::withCenter(backgroundCenterPos + offset, Vec2F(imgMetadata->imageSize(container) * interfaceScale())));
auto nameTextOffset = jsonToVec2F(assets->json("/interface.config:monsterHealth.nameTextOffset")) * interfaceScale();
- m_guiContext->setFont(m_config->font);
- m_guiContext->setFontSize(m_config->fontSize);
- m_guiContext->setFontColor(Color::White.toRgba());
+ m_guiContext->setTextStyle(m_config->textStyle);
m_guiContext->renderText(showDamageEntity->name(), backgroundCenterPos + nameTextOffset);
auto empty = assets->json("/interface.config:monsterHealth.progressEmpty").toString();
@@ -1176,11 +1170,11 @@ void MainInterface::renderSpecialDamageBar() {
m_guiContext->drawQuad(fill, RectF::withSize(bottomCenter + fillOffset, size * interfaceScale()));
auto nameOffset = jsonToVec2F(barConfig.get("nameOffset")) * interfaceScale();
- m_guiContext->setFontColor(jsonToColor(barConfig.get("nameColor")).toRgba());
+ m_guiContext->setFontColor(jsonToColor(barConfig.get("nameStyle")).toRgba());
m_guiContext->setFontSize(barConfig.getUInt("nameSize"));
m_guiContext->setFontProcessingDirectives(barConfig.getString("nameDirectives"));
m_guiContext->renderText(target->name(), TextPositioning(bottomCenter + nameOffset, HorizontalAnchor::HMidAnchor, VerticalAnchor::BottomAnchor));
- m_guiContext->setFontProcessingDirectives("");
+ m_guiContext->clearTextStyle();
}
}
@@ -1341,12 +1335,8 @@ void MainInterface::renderDebug() {
if (m_clientCommandProcessor->debugHudEnabled()) {
auto assets = Root::singleton().assets();
- m_guiContext->setFontSize(m_config->debugFontSize);
- m_guiContext->setFont(m_config->debugFont);
+ m_guiContext->setTextStyle(m_config->debugTextStyle);
m_guiContext->setLineSpacing(0.5f);
- m_guiContext->setFontProcessingDirectives(m_config->debugFontDirectives);
- m_guiContext->setFontColor(Color::White.toRgba());
- m_guiContext->setFontMode(FontMode::Normal);
bool clearMap = m_debugMapClearTimer.wrapTick();
auto logMapValues = LogMap::getValues();
@@ -1358,7 +1348,7 @@ void MainInterface::renderDebug() {
int counter = 0;
for (auto const& pair : logMapValues) {
- TextPositioning positioning = { Vec2F(m_config->debugOffset[0], windowHeight() - m_config->debugOffset[1] - m_config->fontSize * interfaceScale() * counter++) };
+ TextPositioning positioning = { Vec2F(m_config->debugOffset[0], windowHeight() - m_config->debugOffset[1] - m_config->textStyle.fontSize * interfaceScale() * counter++) };
String& text = formatted.emplace_back(strf("{}^lightgray;:^green,set; {}", pair.first, pair.second));
m_debugTextRect.combine(m_guiContext->determineTextSize(text, positioning).padded(m_config->debugBackgroundPad));
}
@@ -1373,15 +1363,9 @@ void MainInterface::renderDebug() {
m_debugTextRect = RectF::null();
for (size_t index = 0; index != formatted.size(); ++index) {
- TextPositioning positioning = { Vec2F(m_config->debugOffset[0], windowHeight() - m_config->debugOffset[1] - m_config->fontSize * interfaceScale() * index) };
+ TextPositioning positioning = { Vec2F(m_config->debugOffset[0], windowHeight() - m_config->debugOffset[1] - m_config->textStyle.fontSize * interfaceScale() * index) };
m_guiContext->renderText(formatted[index], positioning);
}
-
- m_guiContext->setFontSize(8);
- m_guiContext->setDefaultFont();
- m_guiContext->setDefaultLineSpacing();
- m_guiContext->setFontColor(Vec4B::filled(255));
- m_guiContext->setFontProcessingDirectives("");
}
auto const& camera = m_worldPainter->camera();
@@ -1413,7 +1397,7 @@ void MainInterface::renderDebug() {
m_guiContext->drawLine(position + Vec2F(2, -2), position + Vec2F(-2, -2), point.color, 1);
}
- m_guiContext->setFontSize(m_config->debugFontSize);
+ m_guiContext->setTextStyle(m_config->debugTextStyle);
for (auto const& logText : SpatialLogger::getText("world", clearSpatial)) {
m_guiContext->setFontColor(logText.color);
@@ -1424,7 +1408,7 @@ void MainInterface::renderDebug() {
m_guiContext->setFontColor(logText.color);
m_guiContext->renderText(logText.text.utf8Ptr(), logText.position);
}
- m_guiContext->setFontColor(Vec4B::filled(255));
+ m_guiContext->clearTextStyle();
}
void MainInterface::updateCursor() {
@@ -1483,24 +1467,26 @@ void MainInterface::renderCursor() {
auto assets = Root::singleton().assets();
auto imgDb = Root::singleton().imageMetadataDatabase();
- auto backgroundImage = assets->json("/interface.config:cursorTooltip.background").toString();
- auto rawCursorOffset = jsonToVec2I(assets->json("/interface.config:cursorTooltip.offset"));
+ auto config = assets->json("/interface.config:cursorTooltip");
+ auto backgroundImage = config.getString("background");
+ auto rawCursorOffset = jsonToVec2I(config.get("offset"));
Vec2I tooltipSize = Vec2I(imgDb->imageSize(backgroundImage)) * interfaceScale();
Vec2I cursorOffset = (Vec2I{0, -m_cursor.size().y()} + rawCursorOffset) * cursorScale;
Vec2I tooltipOffset = m_cursorScreenPos + cursorOffset;
- size_t fontSize = assets->json("/interface.config:cursorTooltip.fontSize").toUInt();
- String font = assets->json("/interface.config:cursorTooltip.font").toString();
- Vec4B fontColor = jsonToColor(assets->json("/interface.config:cursorTooltip.color")).toRgba();
+ TextStyle textStyle = config.get("textStyle");
+ size_t fontSize = config.get("fontSize").toUInt();
+ Vec4B fontColor = jsonToColor(config.get("color")).toRgba();
m_guiContext->drawQuad(backgroundImage, Vec2F(tooltipOffset) + Vec2F(-tooltipSize.x(), 0), interfaceScale());
+ m_guiContext->setTextStyle(textStyle);
m_guiContext->setFontSize(fontSize);
m_guiContext->setFontColor(fontColor);
- m_guiContext->setFont(font);
m_guiContext->renderText(*m_cursorTooltip,
TextPositioning(Vec2F(tooltipOffset) + Vec2F(-tooltipSize.x(), tooltipSize.y()) / 2,
HorizontalAnchor::HMidAnchor,
VerticalAnchor::VMidAnchor));
+ m_guiContext->clearTextStyle();
}
m_cursorItem->setPosition(m_cursorScreenPos / interfaceScale() + m_config->inventoryItemMouseOffset);
diff --git a/source/frontend/StarMainInterface.hpp b/source/frontend/StarMainInterface.hpp
index 0f1487e..ec79f68 100644
--- a/source/frontend/StarMainInterface.hpp
+++ b/source/frontend/StarMainInterface.hpp
@@ -119,6 +119,8 @@ public:
CanvasWidgetPtr fetchCanvas(String const& canvasName, bool ignoreInterfaceScale = false);
+ ClientCommandProcessorPtr commandProcessor() const;
+
struct ScriptPaneInfo {
ScriptPanePtr scriptPane;
Json config;
diff --git a/source/frontend/StarMainInterfaceTypes.cpp b/source/frontend/StarMainInterfaceTypes.cpp
index 1d67292..957b69d 100644
--- a/source/frontend/StarMainInterfaceTypes.cpp
+++ b/source/frontend/StarMainInterfaceTypes.cpp
@@ -39,8 +39,7 @@ MainInterfaceConfigPtr MainInterfaceConfig::loadFromAssets() {
auto config = make_shared<MainInterfaceConfig>();
- config->fontSize = assets->json("/interface.config:font.baseSize").toInt();
- config->font = assets->json("/interface.config:font.defaultFont").toString();
+ config->textStyle = assets->json("/interface.config:textStyle");
config->inventoryImage = assets->json("/interface.config:mainBar.inventory.base").toString();
config->inventoryImageHover = assets->json("/interface.config:mainBar.inventory.hover").toString();
config->inventoryImageGlow = assets->json("/interface.config:mainBar.inventory.glow").toString();
@@ -130,17 +129,14 @@ MainInterfaceConfigPtr MainInterfaceConfig::loadFromAssets() {
config->planetNameTime = assets->json("/interface.config:planetNameTime").toFloat();
config->planetNameFadeTime = assets->json("/interface.config:planetNameFadeTime").toFloat();
config->planetNameFormatString = assets->json("/interface.config:planetNameFormatString").toString();
- config->planetNameFontSize = assets->json("/interface.config:font.planetSize").toInt();
- config->planetNameDirectives = assets->json("/interface.config:planetNameDirectives").toString();
+ config->planetNameTextStyle = assets->json("/interface.config:planetTextStyle");
config->planetNameOffset = jsonToVec2I(assets->json("/interface.config:planetTextOffset"));
config->renderVirtualCursor = assets->json("/interface.config:renderVirtualCursor").toBool();
config->cursorItemSlot = assets->json("/interface.config:cursorItemSlot");
config->debugOffset = jsonToVec2I(assets->json("/interface.config:debugOffset"));
- config->debugFontSize = assets->json("/interface.config:debugFontSize").toUInt();
- config->debugFont = assets->json("/interface.config:debugFont").toString();
- config->debugFontDirectives = assets->json("/interface.config:debugFontDirectives").toString();
+ config->debugTextStyle = assets->json("/interface.config:debugTextStyle");
config->debugSpatialClearTime = assets->json("/interface.config:debugSpatialClearTime").toFloat();
config->debugMapClearTime = assets->json("/interface.config:debugMapClearTime").toFloat();
config->debugBackgroundColor = jsonToColor(assets->json("/interface.config:debugBackgroundColor"));
diff --git a/source/frontend/StarMainInterfaceTypes.hpp b/source/frontend/StarMainInterfaceTypes.hpp
index 6b0bca3..b5f228a 100644
--- a/source/frontend/StarMainInterfaceTypes.hpp
+++ b/source/frontend/StarMainInterfaceTypes.hpp
@@ -5,6 +5,7 @@
#include "StarBiMap.hpp"
#include "StarRegisteredPaneManager.hpp"
#include "StarAnimation.hpp"
+#include "StarText.hpp"
namespace Star {
@@ -43,8 +44,7 @@ typedef RegisteredPaneManager<MainInterfacePanes> MainInterfacePaneManager;
struct MainInterfaceConfig {
static MainInterfaceConfigPtr loadFromAssets();
- unsigned fontSize;
- String font;
+ TextStyle textStyle;
String inventoryImage;
String inventoryImageHover;
@@ -136,17 +136,14 @@ struct MainInterfaceConfig {
float planetNameTime;
float planetNameFadeTime;
String planetNameFormatString;
- unsigned planetNameFontSize;
- String planetNameDirectives;
+ TextStyle planetNameTextStyle;
Vec2I planetNameOffset;
bool renderVirtualCursor;
Json cursorItemSlot;
Vec2I debugOffset;
- unsigned debugFontSize;
- String debugFont;
- String debugFontDirectives;
+ TextStyle debugTextStyle;
float debugSpatialClearTime;
float debugMapClearTime;
Color debugBackgroundColor;
diff --git a/source/frontend/StarNameplatePainter.cpp b/source/frontend/StarNameplatePainter.cpp
index 4637232..0666af0 100644
--- a/source/frontend/StarNameplatePainter.cpp
+++ b/source/frontend/StarNameplatePainter.cpp
@@ -15,14 +15,11 @@ NameplatePainter::NameplatePainter() {
m_opacityRate = nametagConfig.getFloat("opacityRate");
m_inspectOpacityRate = nametagConfig.queryFloat("inspectOpacityRate", m_opacityRate);
m_offset = jsonToVec2F(nametagConfig.get("offset"));
- m_font = nametagConfig.queryString("font", "");
- m_fontDirectives = nametagConfig.queryString("fontDirectives", "");
- m_fontSize = nametagConfig.getFloat("fontSize");
- m_statusFont = nametagConfig.queryString("font", m_font);
- m_statusFontDirectives = nametagConfig.queryString("fontDirectives", m_fontDirectives);
- m_statusFontSize = nametagConfig.queryFloat("statusFontSize", m_fontSize);
+ Json textStyle = nametagConfig.get("textStyle");
+ m_textStyle = textStyle;
+ m_statusTextStyle = nametagConfig.get("statusTextStyle", textStyle);
m_statusOffset = jsonToVec2F(nametagConfig.get("statusOffset"));
- m_statusColor = jsonToColor(nametagConfig.get("statusColor"));
+ m_statusTextStyle.color = jsonToColor(nametagConfig.get("statusColor")).toRgba();
m_opacityBoost = nametagConfig.getFloat("opacityBoost");
m_nametags.setTweenFactor(nametagConfig.getFloat("tweenFactor"));
m_nametags.setMovementThreshold(nametagConfig.getFloat("movementThreshold"));
@@ -80,31 +77,18 @@ void NameplatePainter::render() {
if (nametag.opacity == 0.0f)
return;
- context.setFont(m_font);
- context.setFontProcessingDirectives(m_fontDirectives);
- context.setFontSize(m_fontSize);
-
+ auto& setStyle = context.setTextStyle(m_textStyle);
auto color = Color::rgb(nametag.color);
color.setAlphaF(nametag.opacity);
- context.setFontColor(color.toRgba());
- context.setFontMode(FontMode::Normal);
+ setStyle.color = color.toRgba();
context.renderText(nametag.name, namePosition(bubble.currentPosition));
if (nametag.statusText) {
- auto statusColor = m_statusColor;
- statusColor.setAlphaF(nametag.opacity);
- context.setFontColor(statusColor.toRgba());
-
- context.setFontSize(m_statusFontSize);
- context.setFontProcessingDirectives(m_statusFontDirectives);
- context.setFont(m_statusFont);
-
+ context.setTextStyle(m_statusTextStyle).color[3] *= nametag.opacity;
context.renderText(*nametag.statusText, statusPosition(bubble.currentPosition));
}
-
- context.setDefaultFont();
- context.setFontProcessingDirectives("");
+ context.clearTextStyle();
});
}
@@ -121,16 +105,13 @@ TextPositioning NameplatePainter::statusPosition(Vec2F bubblePosition) const {
RectF NameplatePainter::determineBoundBox(Vec2F bubblePosition, Nametag const& nametag) const {
auto& context = GuiContext::singleton();
- context.setFontSize(m_fontSize);
- context.setFontProcessingDirectives(m_fontDirectives);
- context.setFont(m_font);
+ context.setTextStyle(m_textStyle);
RectF nametagBox = context.determineTextSize(nametag.name, namePosition(bubblePosition));
if (nametag.statusText) {
- context.setFontSize(m_statusFontSize);
- context.setFontProcessingDirectives(m_statusFontDirectives);
- context.setFont(m_statusFont);
+ context.setTextStyle(m_statusTextStyle);
nametagBox.combine(context.determineTextSize(*nametag.statusText, statusPosition(bubblePosition)));
}
+ context.clearTextStyle();
return nametagBox;
}
diff --git a/source/frontend/StarNameplatePainter.hpp b/source/frontend/StarNameplatePainter.hpp
index d895cfb..06aa187 100644
--- a/source/frontend/StarNameplatePainter.hpp
+++ b/source/frontend/StarNameplatePainter.hpp
@@ -34,14 +34,9 @@ private:
float m_opacityRate;
float m_inspectOpacityRate;
Vec2F m_offset;
- String m_font;
- String m_statusFont;
- String m_fontDirectives;
- String m_statusFontDirectives;
- float m_fontSize;
- float m_statusFontSize;
Vec2F m_statusOffset;
- Color m_statusColor;
+ TextStyle m_textStyle;
+ TextStyle m_statusTextStyle;
float m_opacityBoost;
WorldCamera m_camera;
diff --git a/source/frontend/StarTeamBar.cpp b/source/frontend/StarTeamBar.cpp
index 767bb91..8a8f956 100644
--- a/source/frontend/StarTeamBar.cpp
+++ b/source/frontend/StarTeamBar.cpp
@@ -29,7 +29,8 @@ TeamBar::TeamBar(MainInterface* mainInterface, UniverseClientPtr client) {
m_teamInvitation = make_shared<TeamInvitation>(this);
m_teamMemberMenu = make_shared<TeamMemberMenu>(this);
- m_nameFontSize = assets->json("/interface.config:font.nameSize").toInt();
+ m_nameStyle = assets->json("/interface.config:teamBarNameStyle");
+ m_nameStyle.fontSize = assets->json("/interface.config:font.nameSize").toInt();
m_nameOffset = jsonToVec2F(assets->json("/interface.config:nameOffset"));
GuiReader reader;
diff --git a/source/frontend/StarTeamBar.hpp b/source/frontend/StarTeamBar.hpp
index 9ebbb50..ca50452 100644
--- a/source/frontend/StarTeamBar.hpp
+++ b/source/frontend/StarTeamBar.hpp
@@ -93,7 +93,7 @@ private:
GuiContext* m_guiContext;
- int m_nameFontSize;
+ TextStyle m_nameStyle;
Vec2F m_nameOffset;
TeamInvitePtr m_teamInvite;