~melchizedek6809/WolkenWelten

ref: 19a5ae3cc7ddc83c7cd41598efcaf8af9dfff1f7 WolkenWelten/client/src/gui/chat.c -rw-r--r-- 2.7 KiB
19a5ae3cBen (X13/Arch) Increased melee range for chars/animals 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
 * Wolkenwelten - Copyright (C) 2020-2021 - Benjamin Vincent Schulenburg
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "chat.h"

#include "../main.h"
#include "../gfx/gfx.h"
#include "../gfx/textMesh.h"
#include "../gui/gui.h"
#include "../gui/menu.h"
#include "../gui/textInput.h"
#include "../gui/widget.h"
#include "../network/chat.h"
#include "../sdl/sdl.h"

#include <string.h>

widget *chatPanel;
widget *chatText;

bool chatOpen(){
	if(gameControlsInactive()){return true;}
	widgetSlideH(chatPanel, 64);
	widgetFocus(chatText);
	return false;
}

void chatClose(){
	chatText->vals[0]  = 0;
	widgetSlideH(chatPanel, 0);
}

bool chatIsOpen(){
	return (widgetFocused == chatText);
}

void handlerChatSubmit(widget *wid){
	if(chatText->vals[0] != 0){
		msgSendChatMessage(chatText->vals);
		chatResetHistorySel();
	}
	handlerRootHud(wid);
}

void handlerChatSelectPrev(widget *wid){
	const char *msg = chatGetPrevHistory();
	if(*msg == 0){return;}
	memcpy(wid->vals,msg,256);
	textInputFocus(wid);
}

void handlerChatSelectNext(widget *wid){
	const char *msg = chatGetNextHistory();
	if(*msg == 0){return;}
	memcpy(wid->vals,msg,256);
	textInputFocus(wid);
}

void handlerChatBlur(widget *wid){
	(void)wid;
	chatResetHistorySel();
}

void chatInit(){
	chatText  = widgetNewCPLH(wTextInput,chatPanel,16,16,440,32,"Chat Message","submit",handlerChatSubmit);
	widgetBind(chatText,"blur",handlerChatBlur);
	widgetBind(chatText,"selectPrev",handlerChatSelectPrev);
	widgetBind(chatText,"selectNext",handlerChatSelectNext);
	widgetNewCPLH(wButton,chatPanel,-16,16,24,32,"\xA8","click",handlerChatSubmit);
}

void chatDraw(textMesh *guim){
	guim->sy   = screenHeight - (9*16) - (chatPanel->h-8);
	guim->sx   = 24;
	guim->size = 1;
	guim->font = 1;
	for(int i=0;i<8;i++){
		textMeshAddString(guim,chatLog[i]);
		guim->sy += 8;
		guim->fgc = colorPalette[15];
		guim->bgc = colorPalette[0];
	}
	guim->size = 2;
	for(int i=8;i<12;i++){
		textMeshAddString(guim,chatLog[i]);
		guim->sy += 16;
		guim->fgc = colorPalette[15];
		guim->bgc = colorPalette[0];
	}
	textMeshResetFont(guim);
}