Changeset - r10646:b3b2c1ecae0d
[Not reviewed]
master
0 2 0
smatz - 16 years ago 2009-01-09 23:49:46
smatz@openttd.org
(svn r14948) -Codechange: enumification and more comments in the statusbar code
2 files changed with 47 insertions and 33 deletions:
0 comments (0 inline, 0 general)
src/statusbar_gui.cpp
Show inline comments
 
@@ -65,16 +65,31 @@ static bool DrawScrollingStatusText(cons
 

	
 
struct StatusBarWindow : Window {
 
	bool saving;
 
	int ticker_scroll;
 
	int reminder_timeout;
 

	
 
	enum {
 
		TICKER_START   =   360, ///< initial value of the ticker counter (scrolling news)
 
		TICKER_STOP    = -1280, ///< scrolling is finished when counter reaches this value
 
		REMINDER_START =    91, ///< initial value of the reminder counter (right dot on the right)
 
		REMINDER_STOP  =     0, ///< reminder disappears when counter reaches this value
 
		COUNTER_STEP   =     2, ///< this is subtracted from active counters every tick
 
	};
 

	
 
	enum StatusbarWidget {
 
		SBW_LEFT,   ///< left part of the statusbar; date is shown there
 
		SBW_MIDDLE, ///< middle part; current news or company name or *** SAVING *** or *** PAUSED ***
 
		SBW_RIGHT,  ///< right part; bank balance
 
	};
 

	
 
	StatusBarWindow(const WindowDesc *desc) : Window(desc)
 
	{
 
		CLRBITS(this->flags4, WF_WHITE_BORDER_MASK);
 
		this->ticker_scroll = -1280;
 
		this->ticker_scroll    =   TICKER_STOP;
 
		this->reminder_timeout = REMINDER_STOP;
 

	
 
		this->FindWindowPlacementAndResize(desc);
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
@@ -84,81 +99,81 @@ struct StatusBarWindow : Window {
 
		SetDParam(0, _date);
 
		DrawStringCentered(70, 1, (_pause_game || _settings_client.gui.status_long_date) ? STR_00AF : STR_00AE, TC_FROMSTRING);
 

	
 
		if (c != NULL) {
 
			/* Draw company money */
 
			SetDParam(0, c->money);
 
			DrawStringCentered(this->widget[2].left + 70, 1, STR_0004, TC_FROMSTRING);
 
			DrawStringCentered(this->widget[SBW_RIGHT].left + 70, 1, STR_0004, TC_FROMSTRING);
 
		}
 

	
 
		/* Draw status bar */
 
		if (this->saving) { // true when saving is active
 
			DrawStringCenteredTruncated(this->widget[1].left + 1, this->widget[1].right - 1, 1, STR_SAVING_GAME, TC_FROMSTRING);
 
			DrawStringCenteredTruncated(this->widget[SBW_MIDDLE].left + 1, this->widget[SBW_MIDDLE].right - 1, 1, STR_SAVING_GAME, TC_FROMSTRING);
 
		} else if (_do_autosave) {
 
			DrawStringCenteredTruncated(this->widget[1].left + 1, this->widget[1].right - 1, 1, STR_032F_AUTOSAVE, TC_FROMSTRING);
 
			DrawStringCenteredTruncated(this->widget[SBW_MIDDLE].left + 1, this->widget[SBW_MIDDLE].right - 1, 1, STR_032F_AUTOSAVE, TC_FROMSTRING);
 
		} else if (_pause_game) {
 
			DrawStringCenteredTruncated(this->widget[1].left + 1, this->widget[1].right - 1, 1, STR_0319_PAUSED, TC_FROMSTRING);
 
		} else if (this->ticker_scroll > -1280 && FindWindowById(WC_NEWS_WINDOW, 0) == NULL && _statusbar_news_item.string_id != 0) {
 
			DrawStringCenteredTruncated(this->widget[SBW_MIDDLE].left + 1, this->widget[SBW_MIDDLE].right - 1, 1, STR_0319_PAUSED, TC_FROMSTRING);
 
		} else if (this->ticker_scroll > TICKER_STOP && FindWindowById(WC_NEWS_WINDOW, 0) == NULL && _statusbar_news_item.string_id != 0) {
 
			/* Draw the scrolling news text */
 
			if (!DrawScrollingStatusText(&_statusbar_news_item, this->ticker_scroll, this->widget[1].right - this->widget[1].left - 2)) {
 
				this->ticker_scroll = -1280;
 
			if (!DrawScrollingStatusText(&_statusbar_news_item, this->ticker_scroll, this->widget[SBW_MIDDLE].right - this->widget[SBW_MIDDLE].left - 2)) {
 
				this->ticker_scroll = TICKER_STOP;
 
				if (c != NULL) {
 
					/* This is the default text */
 
					SetDParam(0, c->index);
 
					DrawStringCenteredTruncated(this->widget[1].left + 1, this->widget[1].right - 1, 1, STR_02BA, TC_FROMSTRING);
 
					DrawStringCenteredTruncated(this->widget[SBW_MIDDLE].left + 1, this->widget[SBW_MIDDLE].right - 1, 1, STR_02BA, TC_FROMSTRING);
 
				}
 
			}
 
		} else {
 
			if (c != NULL) {
 
				/* This is the default text */
 
				SetDParam(0, c->index);
 
				DrawStringCenteredTruncated(this->widget[1].left + 1, this->widget[1].right - 1, 1, STR_02BA, TC_FROMSTRING);
 
				DrawStringCenteredTruncated(this->widget[SBW_MIDDLE].left + 1, this->widget[SBW_MIDDLE].right - 1, 1, STR_02BA, TC_FROMSTRING);
 
			}
 
		}
 

	
 
		if (this->reminder_timeout > 0) DrawSprite(SPR_BLOT, PALETTE_TO_RED, this->widget[1].right - 11, 2);
 
		if (this->reminder_timeout > 0) DrawSprite(SPR_BLOT, PALETTE_TO_RED, this->widget[SBW_MIDDLE].right - 11, 2);
 
	}
 

	
 
	virtual void OnInvalidateData(int data)
 
	{
 
		switch (data) {
 
			default: NOT_REACHED();
 
			case SBI_SAVELOAD_START:  this->saving = true;  break;
 
			case SBI_SAVELOAD_FINISH: this->saving = false; break;
 
			case SBI_SHOW_TICKER:     this->ticker_scroll    = 360; break;
 
			case SBI_SHOW_REMINDER:   this->reminder_timeout =  91; break;
 
			case SBI_SHOW_TICKER:     this->ticker_scroll    =   TICKER_START; break;
 
			case SBI_SHOW_REMINDER:   this->reminder_timeout = REMINDER_START; break;
 
			case SBI_NEWS_DELETED:
 
				this->ticker_scroll    = -1280; // reset ticker ...
 
				this->reminder_timeout =     0; // ... and reminder
 
				this->ticker_scroll    =   TICKER_STOP; // reset ticker ...
 
				this->reminder_timeout = REMINDER_STOP; // ... and reminder
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget)
 
	{
 
		switch (widget) {
 
			case 1: ShowLastNewsMessage(); break;
 
			case 2: if (_local_company != COMPANY_SPECTATOR) ShowCompanyFinances(_local_company); break;
 
			case SBW_MIDDLE: ShowLastNewsMessage(); break;
 
			case SBW_RIGHT:  if (_local_company != COMPANY_SPECTATOR) ShowCompanyFinances(_local_company); break;
 
			default: ResetObjectToPlace();
 
		}
 
	}
 

	
 
	virtual void OnTick()
 
	{
 
		if (_pause_game) return;
 

	
 
		if (this->ticker_scroll > -1280) { // Scrolling text
 
			this->ticker_scroll -= 2;
 
			this->InvalidateWidget(1);
 
		if (this->ticker_scroll > TICKER_STOP) { // Scrolling text
 
			this->ticker_scroll -= COUNTER_STEP;
 
			this->InvalidateWidget(SBW_MIDDLE);
 
		}
 

	
 
		if (this->reminder_timeout > 0) { // Red blot to show there are new unread newsmessages
 
			this->reminder_timeout -= 2;
 
		} else if (this->reminder_timeout < 0) {
 
			this->reminder_timeout = 0;
 
			this->InvalidateWidget(1);
 
		if (this->reminder_timeout > REMINDER_STOP) { // Red blot to show there are new unread newsmessages
 
			this->reminder_timeout -= COUNTER_STEP;
 
		} else if (this->reminder_timeout < REMINDER_STOP) {
 
			this->reminder_timeout = REMINDER_STOP;
 
			this->InvalidateWidget(SBW_MIDDLE);
 
		}
 
	}
 
};
 

	
 
static const Widget _main_status_widgets[] = {
 
{      WWT_PANEL,   RESIZE_NONE,   COLOUR_GREY,     0,   139,     0,    11, 0x0, STR_NULL},
 
@@ -177,13 +192,13 @@ static WindowDesc _main_status_desc = {
 
/**
 
 * Checks whether the news ticker is currently being used.
 
 */
 
bool IsNewsTickerShown()
 
{
 
	const StatusBarWindow *w = dynamic_cast<StatusBarWindow*>(FindWindowById(WC_STATUS_BAR, 0));
 
	return w != NULL && w->ticker_scroll > -1280;
 
	return w != NULL && w->ticker_scroll > StatusBarWindow::TICKER_STOP;
 
}
 

	
 
void ShowStatusBar()
 
{
 
	_main_status_desc.top = _screen.height - 12;
 
	new StatusBarWindow(&_main_status_desc);
src/statusbar_gui.h
Show inline comments
 
@@ -2,19 +2,18 @@
 

	
 
/** @file statusbar_gui.h Functions, definitions and such used only by the GUI. */
 

	
 
#ifndef STATUSBAR_GUI_H
 
#define STATUSBAR_GUI_H
 

	
 
enum StatusBarInvalidate
 
{
 
	SBI_SAVELOAD_START,
 
	SBI_SAVELOAD_FINISH,
 
	SBI_SHOW_TICKER,
 
	SBI_SHOW_REMINDER,
 
	SBI_NEWS_DELETED,
 
enum StatusBarInvalidate {
 
	SBI_SAVELOAD_START,  ///< started saving
 
	SBI_SAVELOAD_FINISH, ///< finished saving
 
	SBI_SHOW_TICKER,     ///< start scolling news
 
	SBI_SHOW_REMINDER,   ///< show a reminder (dot on the right side of the statusbar)
 
	SBI_NEWS_DELETED,    ///< abort current news display (active news were deleted)
 
	SBI_END
 
};
 

	
 
bool IsNewsTickerShown();
 
void ShowStatusBar();
 

	
0 comments (0 inline, 0 general)