Merge pull request #858 from derekdinan/master

Add more announcement MessageTypes
This commit is contained in:
UnknownShadow200 2021-06-16 19:49:57 +10:00 committed by GitHub
commit c767738d04
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 5 deletions

View file

@ -19,13 +19,19 @@
#include "Options.h"
#include "Drawer2D.h"
static char msgs[10][STRING_SIZE];
static char msgs[12][STRING_SIZE];
cc_string Chat_Status[4] = { String_FromArray(msgs[0]), String_FromArray(msgs[1]), String_FromArray(msgs[2]), String_FromArray(msgs[3]) };
cc_string Chat_BottomRight[3] = { String_FromArray(msgs[4]), String_FromArray(msgs[5]), String_FromArray(msgs[6]) };
cc_string Chat_ClientStatus[2] = { String_FromArray(msgs[7]), String_FromArray(msgs[8]) };
cc_string Chat_Announcement = String_FromArray(msgs[9]);
cc_string Chat_BigAnnouncement = String_FromArray(msgs[10]);
cc_string Chat_SmallAnnouncement = String_FromArray(msgs[11]);
double Chat_AnnouncementReceived;
double Chat_BigAnnouncementReceived;
double Chat_SmallAnnouncementReceived;
struct StringsBuffer Chat_Log, Chat_InputLog;
cc_bool Chat_Logging;
@ -225,6 +231,12 @@ void Chat_AddOf(const cc_string* text, int msgType) {
} else if (msgType == MSG_TYPE_ANNOUNCEMENT) {
String_Copy(&Chat_Announcement, text);
Chat_AnnouncementReceived = Game.Time;
} else if (msgType == MSG_TYPE_BIGANNOUNCEMENT) {
String_Copy(&Chat_BigAnnouncement, text);
Chat_BigAnnouncementReceived = Game.Time;
} else if (msgType == MSG_TYPE_SMALLANNOUNCEMENT) {
String_Copy(&Chat_SmallAnnouncement, text);
Chat_SmallAnnouncementReceived = Game.Time;
} else if (msgType >= MSG_TYPE_CLIENTSTATUS_1 && msgType <= MSG_TYPE_CLIENTSTATUS_2) {
String_Copy(&Chat_ClientStatus[msgType - MSG_TYPE_CLIENTSTATUS_1], text);
}
@ -641,6 +653,8 @@ static void OnInit(void) {
static void ClearCPEMessages(void) {
Chat_AddOf(&String_Empty, MSG_TYPE_ANNOUNCEMENT);
Chat_AddOf(&String_Empty, MSG_TYPE_BIGANNOUNCEMENT);
Chat_AddOf(&String_Empty, MSG_TYPE_SMALLANNOUNCEMENT);
Chat_AddOf(&String_Empty, MSG_TYPE_STATUS_1);
Chat_AddOf(&String_Empty, MSG_TYPE_STATUS_2);
Chat_AddOf(&String_Empty, MSG_TYPE_STATUS_3);

View file

@ -17,11 +17,13 @@ enum MsgType {
MSG_TYPE_BOTTOMRIGHT_2 = 12,
MSG_TYPE_BOTTOMRIGHT_3 = 13,
MSG_TYPE_ANNOUNCEMENT = 100,
MSG_TYPE_BIGANNOUNCEMENT = 101,
MSG_TYPE_SMALLANNOUNCEMENT = 102,
MSG_TYPE_CLIENTSTATUS_1 = 256, /* Cuboid messages */
MSG_TYPE_CLIENTSTATUS_2 = 257 /* Tab list matching names */
};
extern cc_string Chat_Status[4], Chat_BottomRight[3], Chat_ClientStatus[2], Chat_Announcement;
extern cc_string Chat_Status[4], Chat_BottomRight[3], Chat_ClientStatus[2], Chat_Announcement, Chat_BigAnnouncement, Chat_SmallAnnouncement;
/* All chat messages received. */
extern struct StringsBuffer Chat_Log;
/* Time each chat message was received at. */
@ -31,8 +33,10 @@ extern struct StringsBuffer Chat_InputLog;
/* Whether chat messages are logged to disc. */
extern cc_bool Chat_Logging;
/* Time at which last announcement message was received. */
/* Times at which last announcement messages were received. */
extern double Chat_AnnouncementReceived;
extern double Chat_BigAnnouncementReceived;
extern double Chat_SmallAnnouncementReceived;
struct ChatCommand;
/* Represents a client-side command/action. */

View file

@ -742,8 +742,8 @@ static struct ChatScreen {
cc_bool suppressNextPress;
int chatIndex, paddingX, paddingY;
int lastDownloadStatus;
struct FontDesc chatFont, announcementFont;
struct TextWidget announcement;
struct FontDesc chatFont, announcementFont, bigAnnouncementFont, smallAnnouncementFont;
struct TextWidget announcement, bigAnnouncement, smallAnnouncement;
struct ChatInputWidget input;
struct TextGroupWidget status, bottomRight, chat, clientStatus;
struct SpecialInputWidget altText;
@ -795,6 +795,8 @@ static cc_string ChatScreen_GetClientStatus(int i) { return Chat_ClientStatus[i]
static void ChatScreen_FreeChatFonts(struct ChatScreen* s) {
Font_Free(&s->chatFont);
Font_Free(&s->announcementFont);
Font_Free(&s->bigAnnouncementFont);
Font_Free(&s->smallAnnouncementFont);
}
static cc_bool ChatScreen_ChatUpdateFont(struct ChatScreen* s) {
@ -810,6 +812,8 @@ static cc_bool ChatScreen_ChatUpdateFont(struct ChatScreen* s) {
size = (int)(16 * Gui_GetChatScale());
Math_Clamp(size, 8, 60);
Drawer2D_MakeFont(&s->announcementFont, size, FONT_FLAGS_NONE);
Drawer2D_MakeFont(&s->bigAnnouncementFont, size * 1.33, FONT_FLAGS_NONE);
Drawer2D_MakeFont(&s->smallAnnouncementFont, size * 0.67, FONT_FLAGS_NONE);
ChatInputWidget_SetFont(&s->input, &s->chatFont);
TextGroupWidget_SetFont(&s->status, &s->chatFont);
@ -822,6 +826,8 @@ static cc_bool ChatScreen_ChatUpdateFont(struct ChatScreen* s) {
static void ChatScreen_Redraw(struct ChatScreen* s) {
TextGroupWidget_RedrawAll(&s->chat);
TextWidget_Set(&s->announcement, &Chat_Announcement, &s->announcementFont);
TextWidget_Set(&s->bigAnnouncement, &Chat_BigAnnouncement, &s->bigAnnouncementFont);
TextWidget_Set(&s->smallAnnouncement, &Chat_SmallAnnouncement, &s->smallAnnouncementFont);
TextGroupWidget_RedrawAll(&s->status);
TextGroupWidget_RedrawAll(&s->bottomRight);
TextGroupWidget_RedrawAll(&s->clientStatus);
@ -927,6 +933,10 @@ static void ChatScreen_ChatReceived(void* screen, const cc_string* msg, int type
TextGroupWidget_Redraw(&s->bottomRight, 2 - (type - MSG_TYPE_BOTTOMRIGHT_1));
} else if (type == MSG_TYPE_ANNOUNCEMENT) {
TextWidget_Set(&s->announcement, msg, &s->announcementFont);
} else if (type == MSG_TYPE_BIGANNOUNCEMENT) {
TextWidget_Set(&s->bigAnnouncement, msg, &s->bigAnnouncementFont);
} else if (type == MSG_TYPE_SMALLANNOUNCEMENT) {
TextWidget_Set(&s->smallAnnouncement, msg, &s->smallAnnouncementFont);
} else if (type >= MSG_TYPE_CLIENTSTATUS_1 && type <= MSG_TYPE_CLIENTSTATUS_2) {
TextGroupWidget_Redraw(&s->clientStatus, type - MSG_TYPE_CLIENTSTATUS_1);
ChatScreen_UpdateChatYOffsets(s);
@ -993,7 +1003,18 @@ static void ChatScreen_DrawChat(struct ChatScreen* s, double delta) {
if (s->announcement.tex.ID && now > Chat_AnnouncementReceived + 5) {
Elem_Free(&s->announcement);
}
if (s->bigAnnouncement.tex.ID && now > Chat_BigAnnouncementReceived + 5) {
Elem_Free(&s->bigAnnouncement);
}
if (s->smallAnnouncement.tex.ID && now > Chat_SmallAnnouncementReceived + 5) {
Elem_Free(&s->smallAnnouncement);
}
Elem_Render(&s->announcement, delta);
Elem_Render(&s->bigAnnouncement, delta);
Elem_Render(&s->smallAnnouncement, delta);
if (s->grabsInput) {
Elem_Render(&s->input.base, delta);
@ -1021,6 +1042,8 @@ static void ChatScreen_ContextLost(void* screen) {
Elem_Free(&s->bottomRight);
Elem_Free(&s->clientStatus);
Elem_Free(&s->announcement);
Elem_Free(&s->bigAnnouncement);
Elem_Free(&s->smallAnnouncement);
#ifdef CC_BUILD_TOUCH
if (!Input_TouchMode) return;
@ -1071,6 +1094,14 @@ static void ChatScreen_Layout(void* screen) {
s->announcement.yOffset = -WindowInfo.Height / 4;
Widget_Layout(&s->announcement);
Widget_SetLocation(&s->bigAnnouncement, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 0);
s->bigAnnouncement.yOffset = -WindowInfo.Height / 16;
Widget_Layout(&s->bigAnnouncement);
Widget_SetLocation(&s->smallAnnouncement, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 0);
s->smallAnnouncement.yOffset = WindowInfo.Height / 20;
Widget_Layout(&s->smallAnnouncement);
#ifdef CC_BUILD_TOUCH
if (!Input_TouchMode) return;
if (WindowInfo.SoftKeyboard == SOFT_KEYBOARD_SHIFT) {
@ -1255,6 +1286,8 @@ static void ChatScreen_Init(void* screen) {
TextGroupWidget_Create(&s->clientStatus, CHAT_MAX_CLIENTSTATUS,
s->clientStatusTextures, ChatScreen_GetClientStatus);
TextWidget_Init(&s->announcement);
TextWidget_Init(&s->bigAnnouncement);
TextWidget_Init(&s->smallAnnouncement);
s->status.collapsible[0] = true; /* Texture pack download status */
s->clientStatus.collapsible[0] = true;