summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordominik <dominik@openttd.org>2004-12-14 16:53:38 +0000
committerdominik <dominik@openttd.org>2004-12-14 16:53:38 +0000
commit967425b368211a702bf6b78b17031ae105078a32 (patch)
treee09e6c8a106ac219b9216044e093bbf41a198c8b
parenta63b2f3061931ad37af316d58a23327a8edd9d76 (diff)
downloadopenttd-967425b368211a702bf6b78b17031ae105078a32.tar.xz
(svn r1082) Feature: Chat toolbar
- to chat with all players press Return (or Shift-T) and type in the message - Press Return again to send the message
-rw-r--r--gui.h2
-rw-r--r--lang/english.txt2
-rw-r--r--main_gui.c7
-rw-r--r--network_gui.c130
-rw-r--r--saveload.c1
-rw-r--r--texteff.c2
-rw-r--r--window.c4
7 files changed, 143 insertions, 5 deletions
diff --git a/gui.h b/gui.h
index 45ea66a15..0da9e557c 100644
--- a/gui.h
+++ b/gui.h
@@ -102,7 +102,7 @@ static const byte _fios_colors[] = {13, 9, 9, 6, 5, 6, 5};
/* network gui */
void ShowNetworkGameWindow();
-
+void ShowChatWindow(StringID str, StringID caption, int maxlen, int maxwidth, byte window_class, uint16 window_number);
/* bridge_gui.c */
void ShowBuildBridgeWindow(uint start, uint end, byte type);
diff --git a/lang/english.txt b/lang/english.txt
index ffad7434f..cc1d46d97 100644
--- a/lang/english.txt
+++ b/lang/english.txt
@@ -1353,6 +1353,8 @@ STR_NETWORK_GIVE_MONEY :gave you some money ({CURRENCY})
STR_NETWORK_SERVER_SHUTDOWN :{WHITE} The server closed the session
STR_NETWORK_SERVER_REBOOT :{WHITE} The server is restarting...{}Please wait...
+STR_NETWORK_SEND :{BLACK}Send
+
############ end network gui strings
diff --git a/main_gui.c b/main_gui.c
index 011733e53..92b285944 100644
--- a/main_gui.c
+++ b/main_gui.c
@@ -334,11 +334,12 @@ static void MenuClickBuildAir(int index)
}
#ifdef ENABLE_NETWORK
+
void ShowNetworkChatQueryWindow(byte desttype, byte dest)
{
_rename_id = desttype + (dest << 8);
_rename_what = 2;
- ShowQueryString(STR_EMPTY, STR_NETWORK_CHAT_QUERY_CAPTION, 60, 250, 1, 0);
+ ShowChatWindow(STR_EMPTY, STR_NETWORK_CHAT_QUERY_CAPTION, 60, 250, 1, 0);
}
void ShowNetworkGiveMoneyWindow(byte player)
@@ -2337,8 +2338,10 @@ static void MainWindowWndProc(Window *w, WindowEvent *e) {
break;
#ifdef ENABLE_NETWORK
+ case WKC_RETURN:
case 'T' | WKC_SHIFT:
- ShowNetworkChatQueryWindow(DESTTYPE_BROADCAST, 0);
+ if(_networking)
+ ShowNetworkChatQueryWindow(DESTTYPE_BROADCAST, 0);
break;
#endif /* ENABLE_NETWORK */
diff --git a/network_gui.c b/network_gui.c
index 6a80a3fd8..839e227ab 100644
--- a/network_gui.c
+++ b/network_gui.c
@@ -1285,4 +1285,134 @@ void ShowJoinStatusWindow()
}
+
+
+#define MAX_QUERYSTR_LEN 64
+
+static void ChatWindowWndProc(Window *w, WindowEvent *e)
+{
+ static bool closed = false;
+ switch(e->event) {
+ case WE_PAINT: {
+
+ DrawWindowWidgets(w);
+
+ DrawEditBox(w, 1);
+ } break;
+
+ case WE_CLICK:
+ switch(e->click.widget) {
+ case 3: DeleteWindow(w); break; // Cancel
+ case 2: // Send
+press_ok:;
+ if (str_eq(WP(w,querystr_d).buf, WP(w,querystr_d).buf + MAX_QUERYSTR_LEN)) {
+ DeleteWindow(w);
+ } else {
+ byte *buf = WP(w,querystr_d).buf;
+ WindowClass wnd_class = WP(w,querystr_d).wnd_class;
+ WindowNumber wnd_num = WP(w,querystr_d).wnd_num;
+ Window *parent;
+
+ // Mask the edit-box as closed, so we don't send out a CANCEL
+ closed = true;
+
+ DeleteWindow(w);
+
+ parent = FindWindowById(wnd_class, wnd_num);
+ if (parent != NULL) {
+ WindowEvent e;
+ e.event = WE_ON_EDIT_TEXT;
+ e.edittext.str = buf;
+ parent->wndproc(parent, &e);
+ }
+ }
+ break;
+ }
+ break;
+
+ case WE_MOUSELOOP: {
+ if (!FindWindowById(WP(w,querystr_d).wnd_class, WP(w,querystr_d).wnd_num)) {
+ DeleteWindow(w);
+ return;
+ }
+ HandleEditBox(w, 1);
+ } break;
+
+ case WE_KEYPRESS: {
+ switch(HandleEditBoxKey(w, 1, e)) {
+ case 1: // Return
+ goto press_ok;
+ case 2: // Escape
+ DeleteWindow(w);
+ break;
+ }
+ } break;
+
+ case WE_CREATE:
+ closed = false;
+ break;
+
+ case WE_DESTROY:
+ // If the window is not closed yet, it means it still needs to send a CANCEL
+ if (!closed) {
+ Window *parent = FindWindowById(WP(w,querystr_d).wnd_class, WP(w,querystr_d).wnd_num);
+ if (parent != NULL) {
+ WindowEvent e;
+ e.event = WE_ON_EDIT_TEXT_CANCEL;
+ parent->wndproc(parent, &e);
+ }
+ }
+ break;
+ }
+}
+
+static const Widget _chat_window_widgets[] = {
+{ WWT_IMGBTN, 14, 0, 639, 0, 13, 0x0, STR_NULL}, // background
+{ WWT_IMGBTN, 14, 2, 379, 1, 12, 0x0, STR_NULL}, // text box
+{ WWT_TEXTBTN, 14, 380, 509, 1, 12, STR_NETWORK_SEND,STR_NULL}, // send button
+{ WWT_TEXTBTN, 14, 510, 639, 1, 12, STR_012E_CANCEL, STR_NULL}, // cancel button
+{ WIDGETS_END},
+};
+
+static const WindowDesc _chat_window_desc = {
+ WDP_CENTER, -26, 640, 14, // x, y, width, height
+ WC_SEND_NETWORK_MSG,0,
+ WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
+ _chat_window_widgets,
+ ChatWindowWndProc
+};
+
+static byte _edit_str_buf[MAX_QUERYSTR_LEN*2];
+
+void ShowChatWindow(StringID str, StringID caption, int maxlen, int maxwidth, byte window_class, uint16 window_number)
+{
+ Window *w;
+
+#define _orig_edit_str_buf (_edit_str_buf+MAX_QUERYSTR_LEN)
+
+ DeleteWindowById(WC_SEND_NETWORK_MSG, 0);
+
+ if (str == 0xFFFF) {
+ memcpy(_orig_edit_str_buf, str_buffr, MAX_QUERYSTR_LEN);
+ } else {
+ GetString(_orig_edit_str_buf, str);
+ }
+
+ _orig_edit_str_buf[maxlen] = 0;
+
+ memcpy(_edit_str_buf, _orig_edit_str_buf, MAX_QUERYSTR_LEN);
+
+ w = AllocateWindowDesc(&_chat_window_desc);
+
+ w->click_state = 1 << 1;
+ WP(w,querystr_d).caption = caption;
+ WP(w,querystr_d).wnd_class = window_class;
+ WP(w,querystr_d).wnd_num = window_number;
+ WP(w,querystr_d).caret = 0;
+ WP(w,querystr_d).maxlen = maxlen;
+ WP(w,querystr_d).maxwidth = maxwidth;
+ WP(w,querystr_d).buf = _edit_str_buf;
+}
+
+
#endif /* ENABLE_NETWORK */
diff --git a/saveload.c b/saveload.c
index ffb6fd280..b85eb9525 100644
--- a/saveload.c
+++ b/saveload.c
@@ -1150,7 +1150,6 @@ void DoExitSave()
{
char buf[200];
sprintf(buf, "%s%sexit.sav", _path.autosave_dir, PATHSEP);
- debug(buf);
SaveOrLoad(buf, SL_SAVE);
}
diff --git a/texteff.c b/texteff.c
index bccab3c9f..5e8730c4c 100644
--- a/texteff.c
+++ b/texteff.c
@@ -35,7 +35,7 @@ bool _textmessage_visible = false;
const int _textmessage_box_left = 10; // Pixels from left
const int _textmessage_box_y = 150; // Height of box
-const int _textmessage_box_bottom = 20; // Pixels from bottom
+const int _textmessage_box_bottom = 30; // Pixels from bottom
const int _textmessage_box_max_width = 400; // Max width of box
static byte _textmessage_backup[150*400]; // (y * max_width)
diff --git a/window.c b/window.c
index c61e6921b..a24afb7c4 100644
--- a/window.c
+++ b/window.c
@@ -554,6 +554,7 @@ Window *AllocateWindowDesc(const WindowDesc *desc)
} else {
if (pt.x == WDP_CENTER) pt.x = (_screen.width - desc->width) >> 1;
if (pt.y == WDP_CENTER) pt.y = (_screen.height - desc->height) >> 1;
+ else if(pt.y < 0) pt.y = _screen.height + pt.y; // if y is negative, it's from the bottom of the screen
}
}
@@ -1366,6 +1367,9 @@ void RelocateAllWindows(int neww, int newh)
} else if (w->window_class == WC_STATUS_BAR) {
top = newh - w->height;
left = (neww - w->width) >> 1;
+ } else if (w->window_class == WC_SEND_NETWORK_MSG) {
+ top = (newh - 26); // 26 = height of status bar + height of chat bar
+ left = (neww - w->width) >> 1;
} else {
left = w->left;
if (left + (w->width>>1) >= neww) left = neww - w->width;