src/misc_gui.cpp
branchnoai
changeset 9601 b499fdd106d5
parent 9599 949374e83b78
child 9624 b71483f2330f
equal deleted inserted replaced
9600:59cc173953ae 9601:b499fdd106d5
   275 		/* If the last text has scrolled start anew from the start */
   275 		/* If the last text has scrolled start anew from the start */
   276 		if (y < 50) WP(w, scroller_d).height = w->height - 40;
   276 		if (y < 50) WP(w, scroller_d).height = w->height - 40;
   277 
   277 
   278 		DoDrawStringCentered(210, w->height - 25, "Website: http://www.openttd.org", 16);
   278 		DoDrawStringCentered(210, w->height - 25, "Website: http://www.openttd.org", 16);
   279 		DrawStringCentered(210, w->height - 15, STR_00BA_COPYRIGHT_OPENTTD, 0);
   279 		DrawStringCentered(210, w->height - 15, STR_00BA_COPYRIGHT_OPENTTD, 0);
   280 	}	break;
   280 	} break;
   281 	case WE_MOUSELOOP: // Timer to scroll the text and adjust the new top
   281 	case WE_MOUSELOOP: // Timer to scroll the text and adjust the new top
   282 		if (WP(w, scroller_d).counter++ % 3 == 0) {
   282 		if (WP(w, scroller_d).counter++ % 3 == 0) {
   283 			WP(w, scroller_d).height--;
   283 			WP(w, scroller_d).height--;
   284 			SetWindowDirty(w);
   284 			SetWindowDirty(w);
   285 		}
   285 		}
   675 			break;
   675 			break;
   676 	}
   676 	}
   677 }
   677 }
   678 
   678 
   679 /** Shows a tooltip
   679 /** Shows a tooltip
   680 * @param str String to be displayed
   680  * @param str String to be displayed
   681 * @param params (optional) up to 5 pieces of additional information that may be
   681  * @param paramcount number of params to deal with
   682 * added to a tooltip; currently only supports parameters of {NUM} (integer) */
   682  * @param params (optional) up to 5 pieces of additional information that may be
       
   683  * added to a tooltip; currently only supports parameters of {NUM} (integer) */
   683 void GuiShowTooltipsWithArgs(StringID str, uint paramcount, const uint32 params[])
   684 void GuiShowTooltipsWithArgs(StringID str, uint paramcount, const uint32 params[])
   684 {
   685 {
   685 	char buffer[512];
   686 	char buffer[512];
   686 	BoundingRect br;
   687 	BoundingRect br;
   687 	Window *w;
   688 	Window *w;
   822 }
   823 }
   823 
   824 
   824 /**
   825 /**
   825  * Delete a character from a textbuffer, either with 'Delete' or 'Backspace'
   826  * Delete a character from a textbuffer, either with 'Delete' or 'Backspace'
   826  * The character is delete from the position the caret is at
   827  * The character is delete from the position the caret is at
   827  * @param tb @Textbuf type to be changed
   828  * @param tb Textbuf type to be changed
   828  * @param delmode Type of deletion, either @WKC_BACKSPACE or @WKC_DELETE
   829  * @param delmode Type of deletion, either WKC_BACKSPACE or WKC_DELETE
   829  * @return Return true on successfull change of Textbuf, or false otherwise
   830  * @return Return true on successfull change of Textbuf, or false otherwise
   830  */
   831  */
   831 bool DeleteTextBufferChar(Textbuf *tb, int delmode)
   832 bool DeleteTextBufferChar(Textbuf *tb, int delmode)
   832 {
   833 {
   833 	if (delmode == WKC_BACKSPACE && tb->caretpos != 0) {
   834 	if (delmode == WKC_BACKSPACE && tb->caretpos != 0) {
   841 	return false;
   842 	return false;
   842 }
   843 }
   843 
   844 
   844 /**
   845 /**
   845  * Delete every character in the textbuffer
   846  * Delete every character in the textbuffer
   846  * @param tb @Textbuf buffer to be emptied
   847  * @param tb Textbuf buffer to be emptied
   847  */
   848  */
   848 void DeleteTextBufferAll(Textbuf *tb)
   849 void DeleteTextBufferAll(Textbuf *tb)
   849 {
   850 {
   850 	memset(tb->buf, 0, tb->maxlength);
   851 	memset(tb->buf, 0, tb->maxlength);
   851 	tb->length = tb->width = 0;
   852 	tb->length = tb->width = 0;
   854 
   855 
   855 /**
   856 /**
   856  * Insert a character to a textbuffer. If maxwidth of the Textbuf is zero,
   857  * Insert a character to a textbuffer. If maxwidth of the Textbuf is zero,
   857  * we don't care about the visual-length but only about the physical
   858  * we don't care about the visual-length but only about the physical
   858  * length of the string
   859  * length of the string
   859  * @param tb @Textbuf type to be changed
   860  * @param tb Textbuf type to be changed
   860  * @param key Character to be inserted
   861  * @param key Character to be inserted
   861  * @return Return true on successfull change of Textbuf, or false otherwise
   862  * @return Return true on successfull change of Textbuf, or false otherwise
   862  */
   863  */
   863 bool InsertTextBufferChar(Textbuf *tb, WChar key)
   864 bool InsertTextBufferChar(Textbuf *tb, WChar key)
   864 {
   865 {
   878 }
   879 }
   879 
   880 
   880 /**
   881 /**
   881  * Handle text navigation with arrow keys left/right.
   882  * Handle text navigation with arrow keys left/right.
   882  * This defines where the caret will blink and the next characer interaction will occur
   883  * This defines where the caret will blink and the next characer interaction will occur
   883  * @param tb @Textbuf type where navigation occurs
   884  * @param tb Textbuf type where navigation occurs
   884  * @param navmode Direction in which navigation occurs @WKC_LEFT, @WKC_RIGHT, @WKC_END, @WKC_HOME
   885  * @param navmode Direction in which navigation occurs WKC_LEFT, WKC_RIGHT, WKC_END, WKC_HOME
   885  * @return Return true on successfull change of Textbuf, or false otherwise
   886  * @return Return true on successfull change of Textbuf, or false otherwise
   886  */
   887  */
   887 bool MoveTextBufferPos(Textbuf *tb, int navmode)
   888 bool MoveTextBufferPos(Textbuf *tb, int navmode)
   888 {
   889 {
   889 	switch (navmode) {
   890 	switch (navmode) {
   922 }
   923 }
   923 
   924 
   924 /**
   925 /**
   925  * Initialize the textbuffer by supplying it the buffer to write into
   926  * Initialize the textbuffer by supplying it the buffer to write into
   926  * and the maximum length of this buffer
   927  * and the maximum length of this buffer
   927  * @param tb @Textbuf type which is getting initialized
   928  * @param tb Textbuf type which is getting initialized
   928  * @param buf the buffer that will be holding the data for input
   929  * @param buf the buffer that will be holding the data for input
   929  * @param maxlength maximum length in characters of this buffer
   930  * @param maxlength maximum length in characters of this buffer
   930  * @param maxwidth maximum length in pixels of this buffer. If reached, buffer
   931  * @param maxwidth maximum length in pixels of this buffer. If reached, buffer
   931  * cannot grow, even if maxlength would allow because there is space. A length
   932  * cannot grow, even if maxlength would allow because there is space. A length
   932  * of zero '0' means the buffer is only restricted by maxlength */
   933  * of zero '0' means the buffer is only restricted by maxlength */
   938 	tb->caret = true;
   939 	tb->caret = true;
   939 	UpdateTextBufferSize(tb);
   940 	UpdateTextBufferSize(tb);
   940 }
   941 }
   941 
   942 
   942 /**
   943 /**
   943  * Update @Textbuf type with its actual physical character and screenlength
   944  * Update Textbuf type with its actual physical character and screenlength
   944  * Get the count of characters in the string as well as the width in pixels.
   945  * Get the count of characters in the string as well as the width in pixels.
   945  * Useful when copying in a larger amount of text at once
   946  * Useful when copying in a larger amount of text at once
   946  * @param tb @Textbuf type which length is calculated
   947  * @param tb Textbuf type which length is calculated
   947  */
   948  */
   948 void UpdateTextBufferSize(Textbuf *tb)
   949 void UpdateTextBufferSize(Textbuf *tb)
   949 {
   950 {
   950 	const char *buf = tb->buf;
   951 	const char *buf = tb->buf;
   951 	WChar c = Utf8Consume(&buf);
   952 	WChar c = Utf8Consume(&buf);
  1269  * NOTE: You cannot use BindCString as parameter for this window!
  1270  * NOTE: You cannot use BindCString as parameter for this window!
  1270  * @param caption string shown as window caption
  1271  * @param caption string shown as window caption
  1271  * @param message string that will be shown for the window
  1272  * @param message string that will be shown for the window
  1272  * @param parent pointer to parent window, if this pointer is NULL the parent becomes
  1273  * @param parent pointer to parent window, if this pointer is NULL the parent becomes
  1273  * the main window WC_MAIN_WINDOW
  1274  * the main window WC_MAIN_WINDOW
  1274  * @param x,y coordinates to show the window at
  1275  * @param callback callback function pointer to set in the window descriptor*/
  1275  * @param yes_no_callback callback function called when window is closed through any button */
       
  1276 void ShowQuery(StringID caption, StringID message, Window *parent, void (*callback)(Window*, bool))
  1276 void ShowQuery(StringID caption, StringID message, Window *parent, void (*callback)(Window*, bool))
  1277 {
  1277 {
  1278 	Window *w = AllocateWindowDesc(&_query_desc);
  1278 	Window *w = AllocateWindowDesc(&_query_desc);
  1279 	if (w == NULL) return;
  1279 	if (w == NULL) return;
  1280 
  1280 
  1455 			y += 10;
  1455 			y += 10;
  1456 			if (y >= w->vscroll.cap * 10 + w->widget[7].top + 1) break;
  1456 			if (y >= w->vscroll.cap * 10 + w->widget[7].top + 1) break;
  1457 		}
  1457 		}
  1458 
  1458 
  1459 		if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) {
  1459 		if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) {
  1460 			DrawEditBox(w, &WP(w,querystr_d), 10);
  1460 			DrawEditBox(w, &WP(w, querystr_d), 10);
  1461 		}
  1461 		}
  1462 		break;
  1462 		break;
  1463 	}
  1463 	}
  1464 
  1464 
  1465 	case WE_CLICK:
  1465 	case WE_CLICK:
  1548 		/* This test protects against using widgets 11 and 12 which are only available
  1548 		/* This test protects against using widgets 11 and 12 which are only available
  1549 		 * in those two saveload mode  */
  1549 		 * in those two saveload mode  */
  1550 		if (!(_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO)) break;
  1550 		if (!(_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO)) break;
  1551 
  1551 
  1552 		if (IsWindowWidgetLowered(w, 11)) { // Delete button clicked
  1552 		if (IsWindowWidgetLowered(w, 11)) { // Delete button clicked
  1553 			if (!FiosDelete(WP(w,querystr_d).text.buf)) {
  1553 			if (!FiosDelete(WP(w, querystr_d).text.buf)) {
  1554 				ShowErrorMessage(INVALID_STRING_ID, STR_4008_UNABLE_TO_DELETE_FILE, 0, 0);
  1554 				ShowErrorMessage(INVALID_STRING_ID, STR_4008_UNABLE_TO_DELETE_FILE, 0, 0);
  1555 			} else {
  1555 			} else {
  1556 				BuildFileList();
  1556 				BuildFileList();
  1557 				/* Reset file name to current date on successfull delete */
  1557 				/* Reset file name to current date on successfull delete */
  1558 				if (_saveload_mode == SLD_SAVE_GAME) GenerateFileName();
  1558 				if (_saveload_mode == SLD_SAVE_GAME) GenerateFileName();
  1560 
  1560 
  1561 			UpdateTextBufferSize(&WP(w, querystr_d).text);
  1561 			UpdateTextBufferSize(&WP(w, querystr_d).text);
  1562 			SetWindowDirty(w);
  1562 			SetWindowDirty(w);
  1563 		} else if (IsWindowWidgetLowered(w, 12)) { // Save button clicked
  1563 		} else if (IsWindowWidgetLowered(w, 12)) { // Save button clicked
  1564 			_switch_mode = SM_SAVE;
  1564 			_switch_mode = SM_SAVE;
  1565 			FiosMakeSavegameName(_file_to_saveload.name, WP(w,querystr_d).text.buf, sizeof(_file_to_saveload.name));
  1565 			FiosMakeSavegameName(_file_to_saveload.name, WP(w, querystr_d).text.buf, sizeof(_file_to_saveload.name));
  1566 
  1566 
  1567 			/* In the editor set up the vehicle engines correctly (date might have changed) */
  1567 			/* In the editor set up the vehicle engines correctly (date might have changed) */
  1568 			if (_game_mode == GM_EDITOR) StartupEngines();
  1568 			if (_game_mode == GM_EDITOR) StartupEngines();
  1569 		}
  1569 		}
  1570 		break;
  1570 		break;
  1720 	return _local_player;
  1720 	return _local_player;
  1721 }
  1721 }
  1722 
  1722 
  1723 /**
  1723 /**
  1724  * @param p1 -1 or +1 (down/up)
  1724  * @param p1 -1 or +1 (down/up)
       
  1725  * @param p2 unused
  1725  */
  1726  */
  1726 static int32 ClickChangeClimateCheat(int32 p1, int32 p2)
  1727 static int32 ClickChangeClimateCheat(int32 p1, int32 p2)
  1727 {
  1728 {
  1728 	if (p1 == -1) p1 = 3;
  1729 	if (p1 == -1) p1 = 3;
  1729 	if (p1 ==  4) p1 = 0;
  1730 	if (p1 ==  4) p1 = 0;
  1733 }
  1734 }
  1734 
  1735 
  1735 extern void EnginesMonthlyLoop();
  1736 extern void EnginesMonthlyLoop();
  1736 
  1737 
  1737 /**
  1738 /**
       
  1739  * @param p1 unused
  1738  * @param p2 1 (increase) or -1 (decrease)
  1740  * @param p2 1 (increase) or -1 (decrease)
  1739  */
  1741  */
  1740 static int32 ClickChangeDateCheat(int32 p1, int32 p2)
  1742 static int32 ClickChangeDateCheat(int32 p1, int32 p2)
  1741 {
  1743 {
  1742 	YearMonthDay ymd;
  1744 	YearMonthDay ymd;