Changeset - r27360:a9bafd45feb6
[Not reviewed]
master
0 3 0
Rubidium - 16 months ago 2023-05-06 10:49:28
rubidium@openttd.org
Codechange: use std::string to store script GUI's break string
3 files changed with 13 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/script/script_gui.cpp
Show inline comments
 
@@ -693,13 +693,13 @@ struct ScriptDebugWindow : public Window
 
	static CompanyID script_debug_company;                 ///< The AI that is (was last) being debugged.
 
	int redraw_timer;                                      ///< Timer for redrawing the window, otherwise it'll happen every tick.
 
	int last_vscroll_pos;                                  ///< Last position of the scrolling.
 
	bool autoscroll;                                       ///< Whether automatically scrolling should be enabled or not.
 
	bool show_break_box;                                   ///< Whether the break/debug box is visible.
 
	static bool break_check_enabled;                       ///< Stop an AI when it prints a matching string
 
	static char break_string[MAX_BREAK_STR_STRING_LENGTH]; ///< The string to match to the AI output
 
	static std::string break_string;                       ///< The string to match to the AI output
 
	QueryString break_editbox;                             ///< Break editbox
 
	static StringFilter break_string_filter;               ///< Log filter for break.
 
	static bool case_sensitive_break_check;                ///< Is the matching done case-sensitive
 
	int highlight_row;                                     ///< The output row that matches the given string, or -1
 
	Scrollbar *vscroll;                                    ///< Cache of the vertical scrollbar.
 

	
 
@@ -1019,13 +1019,13 @@ struct ScriptDebugWindow : public Window
 

	
 
	void OnEditboxChanged(int wid) override
 
	{
 
		if (wid != WID_SCRD_BREAK_STR_EDIT_BOX) return;
 

	
 
		/* Save the current string to static member so it can be restored next time the window is opened. */
 
		strecpy(this->break_string, this->break_editbox.text.buf, lastof(this->break_string));
 
		this->break_string = this->break_editbox.text.buf;
 
		break_string_filter.SetFilterTerm(this->break_string);
 
	}
 

	
 
	/**
 
	 * Some data on this window has become invalid.
 
	 * @param data Information about the changed data.
 
@@ -1095,13 +1095,13 @@ struct ScriptDebugWindow : public Window
 
	}
 

	
 
	static HotkeyList hotkeys;
 
};
 

	
 
CompanyID ScriptDebugWindow::script_debug_company = INVALID_COMPANY;
 
char ScriptDebugWindow::break_string[MAX_BREAK_STR_STRING_LENGTH] = "";
 
std::string ScriptDebugWindow::break_string;
 
bool ScriptDebugWindow::break_check_enabled = true;
 
bool ScriptDebugWindow::case_sensitive_break_check = false;
 
StringFilter ScriptDebugWindow::break_string_filter(&ScriptDebugWindow::case_sensitive_break_check);
 

	
 
/** Make a number of rows with buttons for each company for the Script debug window. */
 
NWidgetBase *MakeCompanyButtonRowsScriptDebug(int *biggest_index)
src/stringfilter.cpp
Show inline comments
 
@@ -81,12 +81,21 @@ void StringFilter::SetFilterTerm(const c
 
		memcpy(dest, pos, len);
 
		dest += len;
 
	}
 
}
 

	
 
/**
 
 * Set the term to filter on.
 
 * @param str Filter term
 
 */
 
void StringFilter::SetFilterTerm(const std::string &str)
 
{
 
	this->SetFilterTerm(str.c_str());
 
}
 

	
 
/**
 
 * Reset the matching state to process a new item.
 
 */
 
void StringFilter::ResetState()
 
{
 
	this->word_matches = 0;
 
	for (WordState &ws : this->word_index) {
src/stringfilter_type.h
Show inline comments
 
@@ -48,12 +48,13 @@ public:
 
	 * @param case_sensitive Pointer to a (usually static) variable controlling the case-sensitivity. nullptr means always case-insensitive.
 
	 */
 
	StringFilter(const bool *case_sensitive = nullptr) : filter_buffer(nullptr), word_matches(0), case_sensitive(case_sensitive) {}
 
	~StringFilter() { free(this->filter_buffer); }
 

	
 
	void SetFilterTerm(const char *str);
 
	void SetFilterTerm(const std::string &str);
 

	
 
	/**
 
	 * Check whether any filter words were entered.
 
	 * @return true if no words were entered.
 
	 */
 
	bool IsEmpty() const { return this->word_index.size() == 0; }
0 comments (0 inline, 0 general)