mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-19 04:26:52 -04:00
Allow ampersands in passwords in launcher (Thanks OK)
This commit is contained in:
parent
cdd5485a1f
commit
46ae0bb41b
@ -421,6 +421,10 @@ static void ColoursScreen_ResetAll(void* w, int x, int y) {
|
||||
Launcher_Redraw();
|
||||
}
|
||||
|
||||
static bool ColoursScreen_InputFilter(char c) {
|
||||
return c >= '0' && c <= '9';
|
||||
}
|
||||
|
||||
static void ColoursScreen_Init(struct LScreen* s_) {
|
||||
struct ColoursScreen* s = (struct ColoursScreen*)s_;
|
||||
int i;
|
||||
@ -431,6 +435,7 @@ static void ColoursScreen_Init(struct LScreen* s_) {
|
||||
|
||||
for (i = 0; i < 5 * 3; i++) {
|
||||
LInput_Init(s_, &s->iptColours[i], 55, NULL);
|
||||
s->iptColours[i].TextFilter = ColoursScreen_InputFilter;
|
||||
s->iptColours[i].TextChanged = ColoursScreen_TextChanged;
|
||||
}
|
||||
|
||||
@ -706,6 +711,10 @@ static void MainScreen_Singleplayer(void* w, int x, int y) {
|
||||
Launcher_StartGame(user, &String_Empty, &String_Empty, &String_Empty, &String_Empty);
|
||||
}
|
||||
|
||||
static bool MainScreen_PasswordFilter(char c) {
|
||||
return c >= ' ' && c <= '~';
|
||||
}
|
||||
|
||||
static void MainScreen_Init(struct LScreen* s_) {
|
||||
String user, pass; char passBuffer[STRING_SIZE];
|
||||
struct MainScreen* s = (struct MainScreen*)s_;
|
||||
@ -739,7 +748,8 @@ static void MainScreen_Init(struct LScreen* s_) {
|
||||
/* need to set text here for right size */
|
||||
s->lblUpdate.Font = &Launcher_HintFont;
|
||||
LLabel_SetConst(&s->lblUpdate, "&eChecking..");
|
||||
s->iptPassword.Password = true;
|
||||
s->iptPassword.Password = true;
|
||||
s->iptPassword.TextFilter = MainScreen_PasswordFilter;
|
||||
|
||||
String_InitArray(pass, passBuffer);
|
||||
Options_UNSAFE_Get("launcher-cc-username", &user);
|
||||
|
@ -430,6 +430,10 @@ static void LInput_KeyChar(void* widget, char c) {
|
||||
LInput_Append(w, c);
|
||||
}
|
||||
|
||||
static bool LInput_DefaultInputFilter(char c) {
|
||||
return c >= ' ' && c <= '~' && c != '&';
|
||||
}
|
||||
|
||||
static struct LWidgetVTABLE linput_VTABLE = {
|
||||
LInput_Draw, LInput_TickCaret,
|
||||
LInput_KeyDown, LInput_KeyChar, /* Key */
|
||||
@ -440,6 +444,7 @@ static struct LWidgetVTABLE linput_VTABLE = {
|
||||
void LInput_Init(struct LScreen* s, struct LInput* w, int width, const char* hintText) {
|
||||
w->VTABLE = &linput_VTABLE;
|
||||
w->TabSelectable = true;
|
||||
w->TextFilter = LInput_DefaultInputFilter;
|
||||
String_InitArray(w->Text, w->_TextBuffer);
|
||||
|
||||
w->Width = Display_ScaleX(width);
|
||||
@ -468,7 +473,7 @@ void LInput_SetText(struct LInput* w, const String* text_) {
|
||||
}
|
||||
|
||||
static CC_NOINLINE bool LInput_AppendRaw(struct LInput* w, char c) {
|
||||
if (c >= ' ' && c <= '~' && c != '&' && w->Text.length < w->Text.capacity) {
|
||||
if (w->TextFilter(c) && w->Text.length < w->Text.capacity) {
|
||||
if (w->CaretPos == -1) {
|
||||
String_Append(&w->Text, c);
|
||||
} else {
|
||||
|
@ -71,6 +71,8 @@ struct LInput {
|
||||
void (*ClipboardFilter)(String* str);
|
||||
/* Callback invoked when the text is changed. Can be NULL. */
|
||||
void (*TextChanged)(struct LInput* w);
|
||||
/* Callback invoked whenever user attempts to append a character to the text. */
|
||||
bool (*TextFilter)(char c);
|
||||
/* Specifies the position that characters are inserted/deleted from. */
|
||||
/* NOTE: -1 to insert/delete characters at end of the text. */
|
||||
int CaretPos;
|
||||
|
@ -1755,7 +1755,6 @@ void Cursor_SetPosition(int x, int y) {
|
||||
void Window_OpenKeyboard(void) { }
|
||||
void Window_CloseKeyboard(void) { }
|
||||
|
||||
|
||||
void Window_EnableRawMouse(void) {
|
||||
Window_DefaultEnableRawMouse();
|
||||
CGAssociateMouseAndMouseCursorPosition(0);
|
||||
@ -3696,6 +3695,7 @@ static void Window_WillClose(id self, SEL cmd, id notification) {
|
||||
static id Window_MakeDelegate(void) {
|
||||
Class c = objc_allocateClassPair(objc_getClass("NSObject"), "CC_WindowFuncs", 0);
|
||||
|
||||
// TODO: derive from NSWindow and implement keydown so no beeps when pressing keys.
|
||||
class_addMethod(c, sel_registerName("windowDidResize:"), Window_DidResize, "v@:@");
|
||||
class_addMethod(c, sel_registerName("windowDidMove:"), Window_DidMove, "v@:@");
|
||||
class_addMethod(c, sel_registerName("windowDidBecomeKey:"), Window_DidBecomeKey, "v@:@");
|
||||
@ -3705,7 +3705,7 @@ static id Window_MakeDelegate(void) {
|
||||
class_addMethod(c, sel_registerName("windowWillClose:"), Window_WillClose, "v@:@");
|
||||
|
||||
objc_registerClassPair(c);
|
||||
return objc_msgSend(c, sel_registerName("alloc"));
|
||||
return objc_msgSend((id)c, sel_registerName("alloc"));
|
||||
}
|
||||
|
||||
void Window_Init(void) {
|
||||
@ -3732,6 +3732,7 @@ void Window_Create(int width, int height) {
|
||||
winHandle = objc_msgSend((id)objc_getClass("NSWindow"), sel_registerName("alloc"));
|
||||
objc_msgSend(winHandle, sel_registerName("initWithContentRect:styleMask:backing:defer:"), rect, (NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask), 0, false);
|
||||
|
||||
// TODO: why is the menubar broken
|
||||
Window_CommonCreate();
|
||||
funcs = Window_MakeDelegate();
|
||||
objc_msgSend(winHandle, sel_registerName("setDelegate:"), funcs);
|
||||
@ -3823,6 +3824,7 @@ void Window_ProcessEvents(void) {
|
||||
loc = Send_CGPoint((id)objc_getClass("NSEvent"), sel_registerName("mouseLocation"));
|
||||
mouseX = (int)loc.x - windowX;
|
||||
mouseY = (int)loc.y - windowY;
|
||||
// TODO: this seems to be off by 1
|
||||
/* need to flip Y coordinates because cocoa has window origin at bottom left */
|
||||
mouseY = Window_Height - mouseY;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user