Skip to content

Commit

Permalink
check if inputbox is valid (scp-fs2open#6092)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Nelson authored Apr 11, 2024
1 parent 55c2063 commit ecb9fae
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions code/network/multi_pxo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3202,6 +3202,11 @@ void multi_pxo_chat_process()
char msg[512];
int msg_pixel_width;

// Bail if the input box is not ready to go
if (!Multi_pxo_chat_input.is_valid()) {
return;
}

// if the chat line is getting too long, fire off the message, putting the last
// word on the next input line.
memset(msg, 0, 512);
Expand Down
8 changes: 8 additions & 0 deletions code/ui/inputbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ void UI_INPUTBOX::create(UI_WINDOW *wnd, int _x, int _y, int _w, int _text_len,
locked = 0;
valid_chars = NULL;
invalid_chars = NULL;
valid = true;
}

void UI_INPUTBOX::set_valid_chars(const char *vchars)
Expand Down Expand Up @@ -183,6 +184,8 @@ void UI_INPUTBOX::destroy()
passwd_text = NULL;
}

valid = false;

UI_GADGET::destroy();
}

Expand Down Expand Up @@ -497,6 +500,11 @@ int UI_INPUTBOX::pressed()
return pressed_down;
}

bool UI_INPUTBOX::is_valid()
{
return valid;
}

void UI_INPUTBOX::get_text(char *out, size_t max_out_len)
{
strncpy(out, text, max_out_len);
Expand Down
6 changes: 6 additions & 0 deletions code/ui/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ class UI_INPUTBOX : public UI_GADGET
color *text_color;
char *valid_chars;
char *invalid_chars;
bool valid; // is invalid until created and then is valid until destroyed

// cursor drawing
int cursor_first_frame;
Expand Down Expand Up @@ -392,6 +393,11 @@ class UI_INPUTBOX : public UI_GADGET
*/
int pressed();

/**
* @brief Returns true if valid
*/
bool is_valid();

/**
* @brief Retrieves the string currently in the inputbox
* @param[out] out Destination char[] to copy the string to
Expand Down

0 comments on commit ecb9fae

Please sign in to comment.