Vendor raptor source files (was embedded gitlink)
Tree vendored at upstream 0019c5dd; origin + license recorded in raptor/VENDOR.txt. Windows SDL dev packages excluded via .gitignore.
This commit is contained in:
1 parent
bd3ea30d55
commit
f7c9b7a02d
809 files changed
+337824
-1
No files matched your search
@@ -0,0 +1,499 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "textscreen.h"
|
||||
#include "main.h"
|
||||
#include "input.h"
|
||||
|
||||
extern "C" {
|
||||
#include "txt_keyinput.h"
|
||||
#include "txt_mouseinput.h"
|
||||
#include "txt_joyinput.h"
|
||||
}
|
||||
|
||||
int ControllerType;
|
||||
|
||||
int key_up = KEY_UPARROW;
|
||||
int key_down = KEY_DOWNARROW;
|
||||
int key_left = KEY_LEFTARROW;
|
||||
int key_right = KEY_RIGHTARROW;
|
||||
int key_fire = KEY_RCTRL;
|
||||
int key_special = KEY_LALT;
|
||||
int key_mega = ' ';
|
||||
int convertflagkey;
|
||||
int writeflagkey;
|
||||
int key_up_convert, key_down_convert, key_left_convert, key_right_convert, key_fire_convert, key_special_convert, key_mega_convert;
|
||||
static int* controls[] = { &key_up, &key_down, &key_left, &key_right, &key_fire, &key_special, &key_mega, NULL };
|
||||
|
||||
static const int scantokey[128] =
|
||||
{
|
||||
0 , 27, '1', '2', '3', '4', '5', '6',
|
||||
'7', '8', '9', '0', '-', '=', KEY_BACKSPACE, 9,
|
||||
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i',
|
||||
'o', 'p', '[', ']', 13, KEY_RCTRL, 'a', 's',
|
||||
'd', 'f', 'g', 'h', 'j', 'k', 'l', ';',
|
||||
'\'', '`', KEY_RSHIFT,'\\', 'z', 'x', 'c', 'v',
|
||||
'b', 'n', 'm', ',', '.', '/', KEY_RSHIFT,KEYP_MULTIPLY,
|
||||
KEY_RALT, ' ', KEY_CAPSLOCK,KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5,
|
||||
KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, /*KEY_NUMLOCK?*/KEY_PAUSE,KEY_SCRLCK,KEY_HOME,
|
||||
KEY_UPARROW,KEY_PGUP,KEY_MINUS,KEY_LEFTARROW,KEYP_5,KEY_RIGHTARROW,KEYP_PLUS,KEY_END,
|
||||
KEY_DOWNARROW,KEY_PGDN,KEY_INS,KEY_DEL,0, 0, 0, KEY_F11,
|
||||
KEY_F12, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, KEY_PRTSCR, 0
|
||||
};
|
||||
|
||||
int mousebfire, mousebchweapon, mousebmega;
|
||||
int mousebfireout, mousebchweaponout, mousebmegaout;
|
||||
int writeflagmouse;
|
||||
|
||||
static int* all_mouse_buttons[] = {
|
||||
&mousebfire,
|
||||
&mousebchweapon,
|
||||
&mousebmega,
|
||||
};
|
||||
|
||||
int joybfire, joybchweapon, joybmega, joybspeed;
|
||||
int joybfireout, joybchweaponout, joybmegaout;
|
||||
int writeflagjoy, writeflagjoybfire, writeflagjoybchweapon, writeflagjoybmega;
|
||||
|
||||
txt_window_t* getcontrolkeyboardwindow;
|
||||
txt_window_t* getcontrolmousewindow;
|
||||
txt_window_t* getcontroljoystickwindow;
|
||||
|
||||
void GetControl(TXT_UNCAST_ARG(widget), void* user_data)
|
||||
{
|
||||
if (strcmp((char*)user_data, "Keyboard") == 0)
|
||||
{
|
||||
ControllerType = 1000;
|
||||
textbox_control = (char*)"Keyboard ";
|
||||
}
|
||||
if (strcmp((char*)user_data, "Mouse") == 0)
|
||||
{
|
||||
ControllerType = 1;
|
||||
textbox_control = (char*)"Mouse ";
|
||||
}
|
||||
if (strcmp((char*)user_data, "Joystick") == 0)
|
||||
{
|
||||
ControllerType = 2;
|
||||
textbox_control = (char*)"Joystick ";
|
||||
}
|
||||
|
||||
TXT_ClearTable(infotable);
|
||||
infotable = TXT_NewTable(2);
|
||||
TXT_AddWidgets(infotable,
|
||||
TXT_NewLabel("Control Type : "),
|
||||
TXT_NewLabel(textbox_control),
|
||||
TXT_NewLabel("Music Card : "),
|
||||
TXT_NewLabel(textbox_musiccard),
|
||||
TXT_NewLabel("Sound FX Card : "),
|
||||
TXT_NewLabel(textbox_soundfx),
|
||||
NULL);
|
||||
TXT_AddWidget(infowindow, infotable);
|
||||
}
|
||||
////////////////////////////////////////////////Select ControlButtonConfigKeyboard///////////////////////////////////////////////////
|
||||
static int VarInGroup(int* variable, int** group)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; group[i] != NULL; ++i)
|
||||
{
|
||||
if (group[i] == variable)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void CheckKeyGroup(int* variable, int** group)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
// Don't check unless the variable is in this group.
|
||||
|
||||
if (!VarInGroup(variable, group))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// If another variable has the same value as the new value, reset it.
|
||||
|
||||
for (i = 0; group[i] != NULL; ++i)
|
||||
{
|
||||
if (*variable == *group[i] && group[i] != variable)
|
||||
{
|
||||
// A different key has the same value. Clear the existing
|
||||
// value. This ensures that no two keys can have the same
|
||||
// value.
|
||||
|
||||
*group[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void KeySetCallback(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(variable))
|
||||
{
|
||||
TXT_CAST_ARG(int, variable);
|
||||
|
||||
CheckKeyGroup(variable, controls);
|
||||
}
|
||||
|
||||
void ConvertKey(TXT_UNCAST_ARG(widget), void* user_data)
|
||||
{
|
||||
int s;
|
||||
|
||||
writeflagkey = 1;
|
||||
|
||||
for (s = 0; s < 128; ++s)
|
||||
{
|
||||
if (scantokey[s] == key_up)
|
||||
{
|
||||
key_up_convert = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (s = 0; s < 128; ++s)
|
||||
{
|
||||
if (scantokey[s] == key_down)
|
||||
{
|
||||
key_down_convert = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (s = 0; s < 128; ++s)
|
||||
{
|
||||
if (scantokey[s] == key_left)
|
||||
{
|
||||
key_left_convert = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (s = 0; s < 128; ++s)
|
||||
{
|
||||
if (scantokey[s] == key_right)
|
||||
{
|
||||
key_right_convert = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (s = 0; s < 128; ++s)
|
||||
{
|
||||
if (scantokey[s] == key_fire)
|
||||
{
|
||||
key_fire_convert = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (s = 0; s < 128; ++s)
|
||||
{
|
||||
if (scantokey[s] == key_special)
|
||||
{
|
||||
key_special_convert = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (s = 0; s < 128; ++s)
|
||||
{
|
||||
if (scantokey[s] == key_mega)
|
||||
{
|
||||
key_mega_convert = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void AddKeyControl(TXT_UNCAST_ARG(table), const char* name, int* var)
|
||||
{
|
||||
TXT_CAST_ARG(txt_table_t, table);
|
||||
txt_key_input_t* key_input;
|
||||
|
||||
TXT_AddWidget(table, TXT_NewSpecialLabel(name));
|
||||
key_input = TXT_NewKeyInput(var);
|
||||
TXT_AddWidget(table, key_input);
|
||||
|
||||
TXT_SignalConnect(key_input, "set", KeySetCallback, var);
|
||||
|
||||
if (strcmp(name, " Up ") == 0)
|
||||
TXT_SetHelpLabel(key_input, "Move ship forward");
|
||||
|
||||
if (strcmp(name, " Down ") == 0)
|
||||
TXT_SetHelpLabel(key_input, "Move ship backwards");
|
||||
|
||||
if (strcmp(name, " Left ") == 0)
|
||||
TXT_SetHelpLabel(key_input, "Move ship to the left");
|
||||
|
||||
if (strcmp(name, " Right ") == 0)
|
||||
TXT_SetHelpLabel(key_input, "Move ship to the right");
|
||||
|
||||
if (strcmp(name, " Fire ") == 0)
|
||||
TXT_SetHelpLabel(key_input, "Fire main weapons");
|
||||
|
||||
if (strcmp(name, " Change Special ") == 0)
|
||||
TXT_SetHelpLabel(key_input, "Fire special weapons the you pickup/buy");
|
||||
|
||||
if (strcmp(name, " Mega Bomb ") == 0)
|
||||
TXT_SetHelpLabel(key_input, "Change to next available special weapon");
|
||||
}
|
||||
|
||||
void GetControlKeyboard(TXT_UNCAST_ARG(widget), void* user_data)
|
||||
{
|
||||
txt_window_action_t* close_button;
|
||||
txt_window_action_t* accept_button;
|
||||
txt_window_action_t* select_button;
|
||||
|
||||
if (!convertflagkey)
|
||||
{
|
||||
key_up = scantokey[keymoveup];
|
||||
key_down = scantokey[keymovedown];
|
||||
key_left = scantokey[keymoveleft];
|
||||
key_right = scantokey[keymoveright];
|
||||
key_fire = scantokey[keyfire];
|
||||
key_special = scantokey[keyspecial];
|
||||
key_mega = scantokey[keymega];
|
||||
convertflagkey = 1;
|
||||
}
|
||||
|
||||
getcontrolkeyboardwindow = TXT_NewWindow("Keyboard Configuration ");
|
||||
TXT_SetWindowPosition(getcontrolkeyboardwindow, TXT_HORIZ_CENTER, TXT_VERT_TOP, 39, 3);
|
||||
|
||||
TXT_AddWidget(getcontrolkeyboardwindow, TXT_TABLE_EMPTY);
|
||||
|
||||
TXT_SetTableColumns(getcontrolkeyboardwindow, 2);
|
||||
TXT_SetColumnWidths(getcontrolkeyboardwindow, 4, 3);
|
||||
TXT_AddWidget(getcontrolkeyboardwindow, TXT_NewSpecialSeparator(" Movement ", 6, 6, TXT_COLOR_BRIGHT_BLUE));
|
||||
AddKeyControl(getcontrolkeyboardwindow, " Up ", &key_up);
|
||||
AddKeyControl(getcontrolkeyboardwindow, " Down ", &key_down);
|
||||
AddKeyControl(getcontrolkeyboardwindow, " Left ", &key_left);
|
||||
AddKeyControl(getcontrolkeyboardwindow, " Right ", &key_right);
|
||||
|
||||
TXT_AddWidget(getcontrolkeyboardwindow, TXT_NewStrut(0, 2));
|
||||
|
||||
TXT_AddWidget(getcontrolkeyboardwindow, TXT_NewSpecialSeparator(" Action ", 6, 5, TXT_COLOR_BRIGHT_BLUE));
|
||||
AddKeyControl(getcontrolkeyboardwindow, " Fire ", &key_fire);
|
||||
AddKeyControl(getcontrolkeyboardwindow, " Change Special ", &key_special);
|
||||
AddKeyControl(getcontrolkeyboardwindow, " Mega Bomb ", &key_mega);
|
||||
|
||||
TXT_AddWidget(getcontrolkeyboardwindow, TXT_NewStrut(0, 1));
|
||||
|
||||
accept_button = TXT_NewWindowAction(KEY_F10, "Accept");
|
||||
select_button = TXT_NewWindowAction(KEY_ENTER, "Select");
|
||||
close_button = TXT_NewWindowAction(KEY_ESCAPE, "Abort");
|
||||
|
||||
TXT_SetHelpLabel(close_button, " Press ESC to Abort");
|
||||
TXT_SetHelpLabel(accept_button, " Press F10 to Accept");
|
||||
TXT_SetHelpLabel(select_button, " Press ENTER to Select");
|
||||
|
||||
TXT_SignalConnect(close_button, "pressed", ClosePwnBox, getcontrolkeyboardwindow);
|
||||
|
||||
TXT_SignalConnect(select_button, "pressed", WindowSelect, getcontrolkeyboardwindow);
|
||||
|
||||
TXT_SignalConnect(accept_button, "pressed", ClosePwnBox, getcontrolkeyboardwindow);
|
||||
TXT_SignalConnect(accept_button, "pressed", ConvertKey, NULL);
|
||||
|
||||
TXT_SetWindowAction(getcontrolkeyboardwindow, TXT_HORIZ_LEFT, close_button);
|
||||
TXT_SetWindowAction(getcontrolkeyboardwindow, TXT_HORIZ_CENTER, select_button);
|
||||
TXT_SetWindowAction(getcontrolkeyboardwindow, TXT_HORIZ_RIGHT, accept_button);
|
||||
}
|
||||
////////////////////////////////////////////////Select ControlButtonConfigMouse///////////////////////////////////////////////////
|
||||
static void MouseSetCallback(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(variable))
|
||||
{
|
||||
TXT_CAST_ARG(int, variable);
|
||||
unsigned int i;
|
||||
|
||||
// Check if the same mouse button is used for a different action
|
||||
// If so, set the other action(s) to -1 (unset)
|
||||
|
||||
for (i = 0; i < arrlen(all_mouse_buttons); ++i)
|
||||
{
|
||||
if (*all_mouse_buttons[i] == *variable
|
||||
&& all_mouse_buttons[i] != variable)
|
||||
{
|
||||
*all_mouse_buttons[i] = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void AddMouseControl(TXT_UNCAST_ARG(table), const char* label, int* var)
|
||||
{
|
||||
TXT_CAST_ARG(txt_table_t, table);
|
||||
txt_mouse_input_t* mouse_input;
|
||||
|
||||
TXT_AddWidget(table, TXT_NewLabel(label));
|
||||
|
||||
mouse_input = TXT_NewMouseInput(var);
|
||||
TXT_AddWidget(table, mouse_input);
|
||||
|
||||
TXT_SignalConnect(mouse_input, "set", MouseSetCallback, var);
|
||||
|
||||
if (strcmp(label, " Fire ") == 0)
|
||||
TXT_SetHelpLabel(mouse_input, "Fire main weapons");
|
||||
|
||||
if (strcmp(label, " Change Weapon ") == 0)
|
||||
TXT_SetHelpLabel(mouse_input, "Change to next available special weapon");
|
||||
|
||||
if (strcmp(label, " Mega Bomb ") == 0)
|
||||
TXT_SetHelpLabel(mouse_input, "Launch a Mega Bomb");
|
||||
}
|
||||
|
||||
void SaveMouseConfig(TXT_UNCAST_ARG(widget), void* user_data)
|
||||
{
|
||||
txt_window_t* window;
|
||||
txt_window_action_t* close_button;
|
||||
|
||||
if ((mousebfire > 2) || (mousebchweapon > 2) || (mousebmega > 2))
|
||||
{
|
||||
window = TXT_CustomMessageBox("Error", ("Only LEFT BUTTON, RIGHT BUTTON and MID BUTTON are supported!\n"
|
||||
"Please reconfigure mouse buttons before save!"), TXT_COLOR_BRIGHT_WHITE, TXT_COLOR_RED, TXT_COLOR_RED, TXT_COLOR_BRIGHT_WHITE, TXT_COLOR_BRIGHT_WHITE, TXT_COLOR_BRIGHT_WHITE, TXT_COLOR_BRIGHT_WHITE);
|
||||
|
||||
close_button = TXT_NewWindowAction(KEY_ESCAPE, "Abort");
|
||||
|
||||
TXT_SetHelpLabel(close_button, " Press ESC to Abort");
|
||||
|
||||
TXT_SignalConnect(close_button, "pressed", ClosePwnBox, window);
|
||||
|
||||
TXT_SetWindowAction(window, TXT_HORIZ_CENTER, close_button);
|
||||
|
||||
writeflagmouse = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
writeflagmouse = 1;
|
||||
}
|
||||
|
||||
void GetControlMouse(TXT_UNCAST_ARG(widget), void* user_data)
|
||||
{
|
||||
txt_window_action_t* close_button;
|
||||
txt_window_action_t* accept_button;
|
||||
txt_window_action_t* select_button;
|
||||
|
||||
getcontrolmousewindow = TXT_NewWindow("Mouse Configuration ");
|
||||
TXT_SetWindowPosition(getcontrolmousewindow, TXT_HORIZ_CENTER, TXT_VERT_TOP, 40, 5);
|
||||
|
||||
TXT_AddWidget(getcontrolmousewindow, TXT_NewStrut(0, 1));
|
||||
|
||||
TXT_SetTableColumns(getcontrolmousewindow, 2);
|
||||
|
||||
AddMouseControl(getcontrolmousewindow, " Fire ", &mousebfire);
|
||||
AddMouseControl(getcontrolmousewindow, " Change Weapon ", &mousebchweapon);
|
||||
AddMouseControl(getcontrolmousewindow, " Mega Bomb ", &mousebmega);
|
||||
|
||||
TXT_AddWidget(getcontrolmousewindow, TXT_NewStrut(0, 1));
|
||||
|
||||
accept_button = TXT_NewWindowAction(KEY_F10, "Accept");
|
||||
select_button = TXT_NewWindowAction(KEY_ENTER, "Select");
|
||||
close_button = TXT_NewWindowAction(KEY_ESCAPE, "Abort");
|
||||
|
||||
TXT_SetHelpLabel(close_button, " Press ESC to Abort");
|
||||
TXT_SetHelpLabel(accept_button, " Press F10 to Accept");
|
||||
TXT_SetHelpLabel(select_button, " Press ENTER to Select");
|
||||
|
||||
TXT_SignalConnect(close_button, "pressed", ClosePwnBox, getcontrolmousewindow);
|
||||
|
||||
TXT_SignalConnect(select_button, "pressed", WindowSelect, getcontrolmousewindow);
|
||||
|
||||
TXT_SignalConnect(accept_button, "pressed", ClosePwnBox, getcontrolmousewindow);
|
||||
TXT_SignalConnect(accept_button, "pressed", SaveMouseConfig, NULL);
|
||||
|
||||
TXT_SetWindowAction(getcontrolmousewindow, TXT_HORIZ_LEFT, close_button);
|
||||
TXT_SetWindowAction(getcontrolmousewindow, TXT_HORIZ_CENTER, select_button);
|
||||
TXT_SetWindowAction(getcontrolmousewindow, TXT_HORIZ_RIGHT, accept_button);
|
||||
}
|
||||
////////////////////////////////////////////////Select ControlButtonConfigJoystick////////////////////////////////////////////////
|
||||
static void AddJoystickControl(TXT_UNCAST_ARG(table), const char* label, int* var)
|
||||
{
|
||||
TXT_CAST_ARG(txt_table_t, table);
|
||||
txt_joystick_input_t* joy_input;
|
||||
|
||||
TXT_AddWidget(table, TXT_NewLabel(label));
|
||||
|
||||
joy_input = TXT_NewJoystickInput(var);
|
||||
|
||||
TXT_AddWidget(table, joy_input);
|
||||
|
||||
if (strcmp(label, " Fire ") == 0)
|
||||
TXT_SetHelpLabel(joy_input, "Fire main weapons");
|
||||
|
||||
if (strcmp(label, " Change Special ") == 0)
|
||||
TXT_SetHelpLabel(joy_input, "Change to the next available special weapon");
|
||||
|
||||
if (strcmp(label, " Mega ") == 0)
|
||||
TXT_SetHelpLabel(joy_input, "Fires a Mega Bomb");
|
||||
}
|
||||
|
||||
void SaveJoyConfig(TXT_UNCAST_ARG(widget), void* user_data)
|
||||
{
|
||||
txt_window_t* window;
|
||||
txt_window_action_t* close_button;
|
||||
|
||||
if ((joybfireout > 3) || (joybchweaponout > 3) || (joybmegaout > 3))
|
||||
{
|
||||
window = TXT_CustomMessageBox("Error", ("Only BUTTON 1, BUTTON 2, BUTTON 3 and BUTTON 4 are supported!\n"
|
||||
"Please reconfigure joystick/gamepad buttons before save!"), TXT_COLOR_BRIGHT_WHITE, TXT_COLOR_RED, TXT_COLOR_RED, TXT_COLOR_BRIGHT_WHITE, TXT_COLOR_BRIGHT_WHITE, TXT_COLOR_BRIGHT_WHITE, TXT_COLOR_BRIGHT_WHITE);
|
||||
|
||||
close_button = TXT_NewWindowAction(KEY_ESCAPE, "Abort");
|
||||
|
||||
TXT_SetHelpLabel(close_button, " Press ESC to Abort");
|
||||
|
||||
TXT_SignalConnect(close_button, "pressed", ClosePwnBox, window);
|
||||
|
||||
TXT_SetWindowAction(window, TXT_HORIZ_CENTER, close_button);
|
||||
|
||||
writeflagjoy = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
writeflagjoy = 1;
|
||||
}
|
||||
|
||||
void GetControlJoystick(TXT_UNCAST_ARG(widget), void* user_data)
|
||||
{
|
||||
txt_window_action_t* close_button;
|
||||
txt_window_action_t* accept_button;
|
||||
txt_window_action_t* select_button;
|
||||
|
||||
if (!joybfireout)
|
||||
joybfireout = joybfire;
|
||||
if (!joybchweaponout)
|
||||
joybchweaponout = joybchweapon;
|
||||
if (!joybmegaout)
|
||||
joybmegaout = joybmega;
|
||||
|
||||
getcontroljoystickwindow = TXT_NewWindow("Joystick/Gamepad Config ");
|
||||
TXT_SetWindowPosition(getcontroljoystickwindow, TXT_HORIZ_CENTER, TXT_VERT_TOP, 39, 7);
|
||||
|
||||
TXT_AddWidget(getcontroljoystickwindow, TXT_NewStrut(0, 1));
|
||||
|
||||
TXT_SetTableColumns(getcontroljoystickwindow, 2);
|
||||
|
||||
AddJoystickControl(getcontroljoystickwindow, " Fire ", &joybfire);
|
||||
AddJoystickControl(getcontroljoystickwindow, " Change Special ", &joybchweapon);
|
||||
AddJoystickControl(getcontroljoystickwindow, " Mega ", &joybmega);
|
||||
|
||||
TXT_AddWidget(getcontroljoystickwindow, TXT_NewStrut(0, 1));
|
||||
|
||||
accept_button = TXT_NewWindowAction(KEY_F10, "Accept");
|
||||
select_button = TXT_NewWindowAction(KEY_ENTER, "Select");
|
||||
close_button = TXT_NewWindowAction(KEY_ESCAPE, "Abort");
|
||||
|
||||
TXT_SetHelpLabel(close_button, " Press ESC to Abort");
|
||||
TXT_SetHelpLabel(accept_button, " Press F10 to Accept");
|
||||
TXT_SetHelpLabel(select_button, " Press ENTER to Select");
|
||||
|
||||
TXT_SignalConnect(close_button, "pressed", ClosePwnBox, getcontroljoystickwindow);
|
||||
|
||||
TXT_SignalConnect(select_button, "pressed", WindowSelect, getcontroljoystickwindow);
|
||||
|
||||
TXT_SignalConnect(accept_button, "pressed", ClosePwnBox, getcontroljoystickwindow);
|
||||
TXT_SignalConnect(accept_button, "pressed", SaveJoyConfig, NULL);
|
||||
|
||||
TXT_SetWindowAction(getcontroljoystickwindow, TXT_HORIZ_LEFT, close_button);
|
||||
TXT_SetWindowAction(getcontroljoystickwindow, TXT_HORIZ_CENTER, select_button);
|
||||
TXT_SetWindowAction(getcontroljoystickwindow, TXT_HORIZ_RIGHT, accept_button);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
#include "textscreen.h"
|
||||
|
||||
#define arrlen(s) (sizeof(s)/sizeof(*s))
|
||||
|
||||
extern txt_window_t* getcontrolkeyboardwindow;
|
||||
extern txt_window_t* getcontrolmousewindow;
|
||||
extern txt_window_t* getcontroljoystickwindow;
|
||||
|
||||
extern int ControllerType;
|
||||
extern int key_up_convert, key_down_convert, key_left_convert, key_right_convert, key_fire_convert, key_special_convert, key_mega_convert;
|
||||
extern int writeflagkey;
|
||||
|
||||
extern int mousebfire, mousebchweapon, mousebmega;
|
||||
extern int mousebfireout, mousebchweaponout, mousebmegaout;
|
||||
extern int writeflagmouse;
|
||||
|
||||
extern int joybfire, joybchweapon, joybmega, joybspeed;
|
||||
extern int joybfireout, joybchweaponout, joybmegaout;
|
||||
extern int writeflagjoy, writeflagjoybfire, writeflagjoybchweapon, writeflagjoybmega;
|
||||
|
||||
void GetControl(TXT_UNCAST_ARG(widget), void* user_data);
|
||||
void GetControlKeyboard(TXT_UNCAST_ARG(widget), void* user_data);
|
||||
void GetControlMouse(TXT_UNCAST_ARG(widget), void* user_data);
|
||||
void GetControlJoystick(TXT_UNCAST_ARG(widget), void* user_data);
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include "textscreen.h"
|
||||
|
||||
extern txt_window_t* infowindow;
|
||||
extern txt_table_t* infotable;
|
||||
|
||||
extern char* textbox_control;
|
||||
extern char* textbox_musiccard;
|
||||
extern char* textbox_soundfx;
|
||||
|
||||
extern int keymoveup, keymovedown, keymoveleft, keymoveright, keyfire, keyspecial, keymega;
|
||||
|
||||
void MusicCard(TXT_UNCAST_ARG(widget), void* user_data);
|
||||
void MainMenu(TXT_UNCAST_ARG(widget), void* user_data);
|
||||
void FXCard(TXT_UNCAST_ARG(widget), void* user_data);
|
||||
void ControlButtonConfig(TXT_UNCAST_ARG(widget), void* user_data);
|
||||
void SaveSettings(TXT_UNCAST_ARG(widget), void* user_data);
|
||||
void WindowSelect(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(window));
|
||||
void ClosePwnBox(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(window));
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "textscreen.h"
|
||||
#include "main.h"
|
||||
|
||||
int MidiPort;
|
||||
int CardType;
|
||||
int BasePort;
|
||||
|
||||
|
||||
void GetMusiccard(TXT_UNCAST_ARG(widget), void* user_data)
|
||||
{
|
||||
if (strcmp((char*)user_data, "General Midi") == 0)
|
||||
{
|
||||
CardType = 8;
|
||||
textbox_musiccard = (char*)"General Midi ";
|
||||
}
|
||||
if (strcmp((char*)user_data, "Roland Sound Canvas") == 0)
|
||||
{
|
||||
CardType = 7;
|
||||
textbox_musiccard = (char*)"Roland Sound Canvas ";
|
||||
}
|
||||
if (strcmp((char*)user_data, "WaveBlaster") == 0)
|
||||
{
|
||||
CardType = 6;
|
||||
textbox_musiccard = (char*)"WaveBlaster ";
|
||||
}
|
||||
if (strcmp((char*)user_data, "Sound Blaster AWE 32") == 0)
|
||||
{
|
||||
CardType = 9;
|
||||
textbox_musiccard = (char*)"Sound Blaster AWE 32 ";
|
||||
}
|
||||
if (strcmp((char*)user_data, "Sound Blaster") == 0)
|
||||
{
|
||||
CardType = 5;
|
||||
textbox_musiccard = (char*)"Sound Blaster ";
|
||||
}
|
||||
if (strcmp((char*)user_data, "Pro Audio Spectrum") == 0)
|
||||
{
|
||||
CardType = 4;
|
||||
textbox_musiccard = (char*)"Pro Audio Spectrum ";
|
||||
}
|
||||
if (strcmp((char*)user_data, "UltraSound") == 0)
|
||||
{
|
||||
CardType = 3;
|
||||
textbox_musiccard = (char*)"Gravis Ultra Sound ";
|
||||
}
|
||||
if (strcmp((char*)user_data, "Adlib") == 0)
|
||||
{
|
||||
CardType = 2;
|
||||
textbox_musiccard = (char*)"Adlib ";
|
||||
}
|
||||
if (strcmp((char*)user_data, "NONE") == 0)
|
||||
{
|
||||
CardType = 1000;
|
||||
textbox_musiccard = (char*)"None ";
|
||||
}
|
||||
|
||||
TXT_ClearTable(infotable);
|
||||
infotable = TXT_NewTable(2);
|
||||
TXT_AddWidgets(infotable,
|
||||
TXT_NewLabel("Control Type : "),
|
||||
TXT_NewLabel(textbox_control),
|
||||
TXT_NewLabel("Music Card : "),
|
||||
TXT_NewLabel(textbox_musiccard),
|
||||
TXT_NewLabel("Sound FX Card : "),
|
||||
TXT_NewLabel(textbox_soundfx),
|
||||
NULL);
|
||||
TXT_AddWidget(infowindow, infotable);
|
||||
}
|
||||
|
||||
void GetMusicGMPort(TXT_UNCAST_ARG(widget), void* user_data)
|
||||
{
|
||||
BasePort = 0;
|
||||
|
||||
if (strcmp((char*)user_data, "220") == 0)
|
||||
MidiPort = 220;
|
||||
if (strcmp((char*)user_data, "230") == 0)
|
||||
MidiPort = 230;
|
||||
if (strcmp((char*)user_data, "240") == 0)
|
||||
MidiPort = 240;
|
||||
if (strcmp((char*)user_data, "250") == 0)
|
||||
MidiPort = 250;
|
||||
if (strcmp((char*)user_data, "300") == 0)
|
||||
MidiPort = 300;
|
||||
if (strcmp((char*)user_data, "320") == 0)
|
||||
MidiPort = 320;
|
||||
if (strcmp((char*)user_data, "330") == 0)
|
||||
MidiPort = 330;
|
||||
if (strcmp((char*)user_data, "332") == 0)
|
||||
MidiPort = 332;
|
||||
if (strcmp((char*)user_data, "334") == 0)
|
||||
MidiPort = 334;
|
||||
if (strcmp((char*)user_data, "336") == 0)
|
||||
MidiPort = 336;
|
||||
if (strcmp((char*)user_data, "340") == 0)
|
||||
MidiPort = 340;
|
||||
if (strcmp((char*)user_data, "360") == 0)
|
||||
MidiPort = 360;
|
||||
}
|
||||
|
||||
void GetMusicBasePort(TXT_UNCAST_ARG(widget), void* user_data)
|
||||
{
|
||||
MidiPort = 0;
|
||||
|
||||
if (strcmp((char*)user_data, "210") == 0)
|
||||
BasePort = 210;
|
||||
if (strcmp((char*)user_data, "220") == 0)
|
||||
BasePort = 220;
|
||||
if (strcmp((char*)user_data, "230") == 0)
|
||||
BasePort = 230;
|
||||
if (strcmp((char*)user_data, "240") == 0)
|
||||
BasePort = 240;
|
||||
if (strcmp((char*)user_data, "250") == 0)
|
||||
BasePort = 250;
|
||||
if (strcmp((char*)user_data, "260") == 0)
|
||||
BasePort = 260;
|
||||
if (strcmp((char*)user_data, "280") == 0)
|
||||
BasePort = 280;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
extern int MidiPort;
|
||||
extern int CardType;
|
||||
extern int BasePort;
|
||||
|
||||
void GetMusicBasePort(TXT_UNCAST_ARG(widget), void* user_data);
|
||||
void GetMusiccard(TXT_UNCAST_ARG(widget), void* user_data);
|
||||
void GetMusicGMPort(TXT_UNCAST_ARG(widget), void* user_data);
|
||||
@@ -0,0 +1,443 @@
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "../common.h"
|
||||
#include "prefapi.h"
|
||||
#include "main.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <io.h>
|
||||
#endif // _WIN32
|
||||
#ifdef __GNUC__
|
||||
#include <unistd.h>
|
||||
char* ltoa(long i, char* s, int dummy_radix) {
|
||||
sprintf(s, "%ld", i);
|
||||
return s;
|
||||
}
|
||||
#endif // __GNUC__
|
||||
#ifdef _MSC_VER
|
||||
#include <windows.h>
|
||||
#define PATH_MAX MAX_PATH
|
||||
#define access _access
|
||||
#define ltoa _ltoa
|
||||
#endif // _MSC_VER
|
||||
|
||||
static int INI_OpenFile(const char *section, const char *key, const char *defaultValue, char *value, int length, const char *filename)
|
||||
{
|
||||
char *va;
|
||||
char v9c[128];
|
||||
short v10, i;
|
||||
FILE *vs;
|
||||
|
||||
v10 = 0;
|
||||
vs = fopen(filename, "r");
|
||||
if (vs)
|
||||
{
|
||||
|
||||
while (!v10 && fgets(v9c, 128, vs) != 0)
|
||||
{
|
||||
if (v9c[0] == '[')
|
||||
{
|
||||
for (i = 0; v9c[i] != 0 && v9c[i] != ']'; i++) {
|
||||
}
|
||||
if (v9c[i] == ']')
|
||||
{
|
||||
v9c[i] = '\0';
|
||||
if (!strcmp(v9c + 1, section))
|
||||
v10 = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (v10 && fgets(v9c, 128, vs) != 0)
|
||||
{
|
||||
if (v9c[0] == '[')
|
||||
{
|
||||
v10 = 0;
|
||||
continue;
|
||||
}
|
||||
va = strtok(v9c, "=\r\n");
|
||||
if (va)
|
||||
{
|
||||
if (!strcmp(va, key))
|
||||
{
|
||||
fclose(vs);
|
||||
va = strtok(NULL, "\r\n");
|
||||
if (va)
|
||||
{
|
||||
strncpy(value, va, length);
|
||||
value[length-1] = '\0';
|
||||
}
|
||||
else
|
||||
value[0] = '\0';
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(vs);
|
||||
}
|
||||
if (defaultValue)
|
||||
strncpy(value, defaultValue, length);
|
||||
else
|
||||
value[0] = '\0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int INI_SaveFile(const char *section, const char *key, const char *value, const char *filename)
|
||||
{
|
||||
char *va;
|
||||
char va8[128];
|
||||
FILE *vs;
|
||||
short vc, i;
|
||||
int v28, vbp, vd, v10, l, v1c, v18, vdi, v20;
|
||||
int empty;
|
||||
|
||||
empty = 0;
|
||||
vc = 0;
|
||||
if (!section || !*section)
|
||||
return 0;
|
||||
vs = fopen(filename, "rb+");
|
||||
if (!vs)
|
||||
{
|
||||
vs = fopen(filename, "wb+");
|
||||
if (!vs)
|
||||
return 0;
|
||||
fseek(vs, 0, SEEK_SET);
|
||||
}
|
||||
v10 = 0;
|
||||
|
||||
while (!vc && fgets(va8, 128, vs) != 0)
|
||||
{
|
||||
if (va8[0] == '\r' || va8[0] == '\n')
|
||||
continue;
|
||||
if (va8[0] == '[')
|
||||
{
|
||||
for (i = 0; va8[i] != 0 && va8[i] != ']'; i++) {
|
||||
}
|
||||
if (va8[i] == ']')
|
||||
{
|
||||
va8[i] = '\0';
|
||||
if (!strcmp(va8 + 1, section))
|
||||
{
|
||||
vc = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
continue;
|
||||
}
|
||||
v10 = ftell(vs);
|
||||
}
|
||||
if (!vc)
|
||||
{
|
||||
fseek(vs, 0, SEEK_END);
|
||||
if (!key || !*key)
|
||||
{
|
||||
fclose(vs);
|
||||
return 1;
|
||||
}
|
||||
fprintf(vs, "\r\n[%s]\r\n", section);
|
||||
v28 = vbp = ftell(vs);
|
||||
}
|
||||
else
|
||||
{
|
||||
v28 = ftell(vs);
|
||||
while (fgets(va8, 128, vs) != 0)
|
||||
{
|
||||
vbp = ftell(vs);
|
||||
if (va8[0] == '[')
|
||||
{
|
||||
vc = 0;
|
||||
break;
|
||||
}
|
||||
va = strtok(va8, "=\r\n");
|
||||
if (va)
|
||||
{
|
||||
if (!strcmp(va, key))
|
||||
{
|
||||
va = strtok(NULL, "=\r\n");
|
||||
if (!va) //Delete line when after string=empty
|
||||
{
|
||||
value = "";
|
||||
va = (char*)"delete";
|
||||
empty = 1;
|
||||
}
|
||||
if (!strcmp(value, va))
|
||||
{
|
||||
fclose(vs);
|
||||
return 1;
|
||||
}
|
||||
vc = 1;
|
||||
break;
|
||||
}
|
||||
else
|
||||
v28 = vbp;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!vc)
|
||||
{
|
||||
if (vbp == v28)
|
||||
{
|
||||
if (!key || !*key || !value || !*value)
|
||||
{
|
||||
fclose(vs);
|
||||
return 1;
|
||||
}
|
||||
fseek(vs, 0, SEEK_END);
|
||||
fprintf(vs, "%s=%s\r\n", key, value);
|
||||
fclose(vs);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (key && *key)
|
||||
vd = 0;
|
||||
else
|
||||
{
|
||||
vd = v28 - v10;
|
||||
vbp = v28;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
vd = vbp - v28;
|
||||
}
|
||||
if (key && *key && value && *value)
|
||||
{
|
||||
sprintf(va8, "%s=%s\r\n", key, value);
|
||||
l = strlen(va8);
|
||||
}
|
||||
else
|
||||
l = 0;
|
||||
v1c = l - vd;
|
||||
if (key && *key)
|
||||
v10 = v28;
|
||||
if (v1c < 0)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
fseek(vs, vbp, SEEK_SET);
|
||||
vdi = fread(va8, 1, 128, vs);
|
||||
if (!vdi)
|
||||
break;
|
||||
v18 = ftell(vs);
|
||||
fseek(vs, v1c + vbp, SEEK_SET);
|
||||
vbp = v18;
|
||||
fwrite(va8, 1, vdi, vs);
|
||||
}
|
||||
fseek(vs, v1c, SEEK_END);
|
||||
#ifdef _MSC_VER
|
||||
_chsize(_fileno(vs), ftell(vs));
|
||||
#endif
|
||||
#ifdef __GNUC__
|
||||
ftruncate(fileno(vs), ftell(vs));
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
else if (v1c > 0)
|
||||
{
|
||||
fseek(vs, 0, SEEK_END);
|
||||
v20 = ftell(vs);
|
||||
vbp = 128;
|
||||
while (1)
|
||||
{
|
||||
int vd1;
|
||||
vd1 = v20 - vbp;
|
||||
if (vd1 < v10)
|
||||
{
|
||||
vbp = v20 - v10;
|
||||
if (vbp <= 0)
|
||||
break;
|
||||
vd1 = v10;
|
||||
}
|
||||
v20 = vd1;
|
||||
fseek(vs, v20, SEEK_SET);
|
||||
vdi = fread(va8, 1, vbp, vs);
|
||||
if (!vdi)
|
||||
break;
|
||||
fseek(vs, v1c + v20, SEEK_SET);
|
||||
fwrite(va8, 1, vdi, vs);
|
||||
fflush(vs);
|
||||
}
|
||||
}
|
||||
if (key && *key && value && *value)
|
||||
{
|
||||
fseek(vs, v10, SEEK_SET);
|
||||
fprintf(vs, "%s=%s\r\n", key, value);
|
||||
}
|
||||
fclose(vs);
|
||||
if (empty) //Save Settings again when after string=empty
|
||||
SaveSettings(0, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static char preference[PATH_MAX];
|
||||
|
||||
int INI_InitPreference(const char *section)
|
||||
{
|
||||
if (section)
|
||||
strcpy(preference, section);
|
||||
return !access(preference, 4);
|
||||
}
|
||||
|
||||
int INI_GetPreferenceLong(const char *section, const char *key, int defValue)
|
||||
{
|
||||
char s1[20], s2[20];
|
||||
ltoa(defValue, s1, 10);
|
||||
INI_GetPreference(section, key, s2, 20, s1);
|
||||
return atol(s2);
|
||||
}
|
||||
|
||||
int INI_GetPreferenceHex(const char* section, const char* key, int defValue)
|
||||
{
|
||||
char s1[32], s2[32];
|
||||
unsigned int t;
|
||||
|
||||
ltoa(defValue, s1, 10);
|
||||
INI_GetPreference(section, key, s2, 32, s1);
|
||||
sscanf(s2, "%x", &t);
|
||||
|
||||
return t & 0xFF;
|
||||
}
|
||||
/*int INI_GetPreferenceHex(const char *a1, const char *a2, int a3)
|
||||
{
|
||||
char s1[32], s2[32], t;
|
||||
ltoa(a3, s1, 10);
|
||||
INI_GetPreference(a1, a2, s2, 32, s1);
|
||||
sscanf(s2, "%x", &t);
|
||||
return t;
|
||||
}*/
|
||||
|
||||
int INI_GetPreferenceBool(const char *section, const char *key, short defValue)
|
||||
{
|
||||
char s2[10];
|
||||
if (defValue)
|
||||
INI_GetPreference(section, key, s2, 10, "TRUE");
|
||||
else
|
||||
INI_GetPreference(section, key, s2, 10, "FALSE");
|
||||
if (s2[0] == '1' || !strcmp(s2, "TRUE"))
|
||||
return 1;
|
||||
if (s2[0] == '0' || !strcmp(s2, "FALSE"))
|
||||
return 0;
|
||||
return atoi(s2);
|
||||
}
|
||||
|
||||
char *INI_GetPreference(const char *section, const char *key, char *retValue, int length, const char *defValue)
|
||||
{
|
||||
if (!section || !key || !retValue)
|
||||
{
|
||||
if (retValue)
|
||||
*retValue = 0;
|
||||
return NULL;
|
||||
}
|
||||
INI_OpenFile(section, key, defValue, retValue, length, preference);
|
||||
return retValue;
|
||||
}
|
||||
|
||||
int INI_PutPreferenceLong(const char *section, const char *key, int value)
|
||||
{
|
||||
char s1[32];
|
||||
if (value == -1)
|
||||
{
|
||||
INI_DeletePreference(section, key);
|
||||
return 0;
|
||||
}
|
||||
ltoa(value, s1, 10);
|
||||
return INI_PutPreference(section, key, s1);
|
||||
}
|
||||
|
||||
int INI_PutPreferenceHex(const char *section, const char *key, int value)
|
||||
{
|
||||
char s1[36];
|
||||
if (value == -1)
|
||||
{
|
||||
INI_DeletePreference(section, key);
|
||||
return 0;
|
||||
}
|
||||
sprintf(s1, "%x", value);
|
||||
return INI_PutPreference(section, key, s1);
|
||||
}
|
||||
|
||||
int INI_PutPreferenceBool(const char *section, const char *key, short value)
|
||||
{
|
||||
if (value)
|
||||
return INI_PutPreference(section, key, "TRUE");
|
||||
return INI_PutPreference(section, key, "FALSE");
|
||||
}
|
||||
|
||||
int INI_PutPreference(const char *section, const char *key, const char *value)
|
||||
{
|
||||
if (!section || !key || !value)
|
||||
return 0;
|
||||
return INI_SaveFile(section, key, value, preference);
|
||||
}
|
||||
|
||||
int INI_DeletePreference(const char *section, const char *key)
|
||||
{
|
||||
if (!section)
|
||||
return 0;
|
||||
//return FUN_0002f3b4(a1, a2, NULL, preference);
|
||||
return INI_SaveFile(section, key, "", preference);
|
||||
}
|
||||
|
||||
// Safe, portable vsnprintf().
|
||||
int M_vsnprintf(char* buf, size_t buf_len, const char* s, va_list args)
|
||||
{
|
||||
unsigned int result;
|
||||
|
||||
if (buf_len < 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Windows (and other OSes?) has a vsnprintf() that doesn't always
|
||||
// append a trailing \0. So we must do it, and write into a buffer
|
||||
// that is one byte shorter; otherwise this function is unsafe.
|
||||
result = vsnprintf(buf, buf_len, s, args);
|
||||
|
||||
// If truncated, change the final char in the buffer to a \0.
|
||||
// A negative result indicates a truncated buffer on Windows.
|
||||
if (result < 0 || result >= buf_len)
|
||||
{
|
||||
buf[buf_len - 1] = '\0';
|
||||
result = buf_len - 1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Safe, portable snprintf().
|
||||
int M_snprintf(char* buf, size_t buf_len, const char* s, ...)
|
||||
{
|
||||
va_list args;
|
||||
int result;
|
||||
va_start(args, s);
|
||||
result = M_vsnprintf(buf, buf_len, s, args);
|
||||
va_end(args);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// Safe string copy function that works like OpenBSD's strlcpy().
|
||||
// Returns true if the string was not truncated.
|
||||
|
||||
int M_StringCopy(char* dest, const char* src, size_t dest_size)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
if (dest_size >= 1)
|
||||
{
|
||||
dest[dest_size - 1] = '\0';
|
||||
strncpy(dest, src, dest_size - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
len = strlen(dest);
|
||||
return src[len] == '\0';
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
int INI_InitPreference(const char *section);
|
||||
int INI_GetPreferenceLong(const char* section, const char* key, int defValue);
|
||||
int INI_GetPreferenceHex(const char* section, const char* key, int defValue);
|
||||
int INI_GetPreferenceBool(const char* section, const char* key, short defValue);
|
||||
char* INI_GetPreference(const char* section, const char* key, char* retValue, int length, const char* defValue);
|
||||
int INI_PutPreferenceLong(const char* section, const char* key, int value);
|
||||
int INI_PutPreferenceHex(const char* section, const char* key, int value);
|
||||
int INI_PutPreferenceBool(const char* section, const char* key, short value);
|
||||
int INI_PutPreference(const char* section, const char* key, const char* value);
|
||||
int INI_DeletePreference(const char* section, const char* key);
|
||||
int M_snprintf(char* buf, size_t buf_len, const char* s, ...);
|
||||
int M_StringCopy(char* dest, const char* src, size_t dest_size);
|
||||
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "textscreen.h"
|
||||
#include "main.h"
|
||||
|
||||
int SoundCardType;
|
||||
int SoundMidiPort;
|
||||
int SoundBasePort;
|
||||
int SoundIrq;
|
||||
int SoundDma;
|
||||
int SoundChannels;
|
||||
|
||||
void GetSoundcard(TXT_UNCAST_ARG(widget), void* user_data)
|
||||
{
|
||||
if (strcmp((char*)user_data, "General Midi") == 0)
|
||||
{
|
||||
SoundCardType = 8;
|
||||
textbox_soundfx = (char*)"General Midi ";
|
||||
}
|
||||
if (strcmp((char*)user_data, "Sound Canvas") == 0)
|
||||
{
|
||||
SoundCardType = 7;
|
||||
textbox_soundfx = (char*)"Roland Sound Canvas ";
|
||||
}
|
||||
if (strcmp((char*)user_data, "Sound Blaster") == 0)
|
||||
{
|
||||
SoundCardType = 5;
|
||||
textbox_soundfx = (char*)"Sound Blaster ";
|
||||
}
|
||||
if (strcmp((char*)user_data, "Pro Audio Spectrum") == 0)
|
||||
{
|
||||
SoundCardType = 4;
|
||||
textbox_soundfx = (char*)"Pro Audio Spectrum ";
|
||||
}
|
||||
if (strcmp((char*)user_data, "UltraSound") == 0)
|
||||
{
|
||||
SoundCardType = 3;
|
||||
textbox_soundfx = (char*)"Gravis Ultra Sound ";
|
||||
}
|
||||
if (strcmp((char*)user_data, "Adlib") == 0)
|
||||
{
|
||||
SoundCardType = 2;
|
||||
textbox_soundfx = (char*)"Adlib ";
|
||||
}
|
||||
if (strcmp((char*)user_data, "PC Speaker") == 0)
|
||||
{
|
||||
SoundCardType = 1;
|
||||
textbox_soundfx = (char*)"PC Speaker ";
|
||||
}
|
||||
if (strcmp((char*)user_data, "NONE") == 0)
|
||||
{
|
||||
SoundCardType = 1000;
|
||||
textbox_soundfx = (char*)"None ";
|
||||
}
|
||||
|
||||
TXT_ClearTable(infotable);
|
||||
infotable = TXT_NewTable(2);
|
||||
TXT_AddWidgets(infotable,
|
||||
TXT_NewLabel("Control Type : "),
|
||||
TXT_NewLabel(textbox_control),
|
||||
TXT_NewLabel("Music Card : "),
|
||||
TXT_NewLabel(textbox_musiccard),
|
||||
TXT_NewLabel("Sound FX Card : "),
|
||||
TXT_NewLabel(textbox_soundfx),
|
||||
NULL);
|
||||
TXT_AddWidget(infowindow, infotable);
|
||||
}
|
||||
|
||||
void GetSoundChannels(TXT_UNCAST_ARG(widget), void* user_data)
|
||||
{
|
||||
if (strcmp((char*)user_data, "One") == 0)
|
||||
SoundChannels = 1;
|
||||
if (strcmp((char*)user_data, "Two") == 0)
|
||||
SoundChannels = 2;
|
||||
if (strcmp((char*)user_data, "Three") == 0)
|
||||
SoundChannels = 3;
|
||||
if (strcmp((char*)user_data, "Four") == 0)
|
||||
SoundChannels = 4;
|
||||
if (strcmp((char*)user_data, "Five") == 0)
|
||||
SoundChannels = 5;
|
||||
if (strcmp((char*)user_data, "Six") == 0)
|
||||
SoundChannels = 6;
|
||||
if (strcmp((char*)user_data, "Seven") == 0)
|
||||
SoundChannels = 7;
|
||||
if (strcmp((char*)user_data, "Eight") == 0)
|
||||
SoundChannels = 8;
|
||||
}
|
||||
|
||||
void GetSoundDma(TXT_UNCAST_ARG(widget), void* user_data)
|
||||
{
|
||||
if (strcmp((char*)user_data, "0") == 0)
|
||||
SoundDma = 1000;
|
||||
if (strcmp((char*)user_data, "1") == 0)
|
||||
SoundDma = 1;
|
||||
if (strcmp((char*)user_data, "3") == 0)
|
||||
SoundDma = 3;
|
||||
if (strcmp((char*)user_data, "5") == 0)
|
||||
SoundDma = 5;
|
||||
if (strcmp((char*)user_data, "6") == 0)
|
||||
SoundDma = 6;
|
||||
if (strcmp((char*)user_data, "7") == 0)
|
||||
SoundDma = 7;
|
||||
}
|
||||
|
||||
void GetSoundIrq(TXT_UNCAST_ARG(widget), void* user_data)
|
||||
{
|
||||
if (strcmp((char*)user_data, "2") == 0)
|
||||
SoundIrq = 2;
|
||||
if (strcmp((char*)user_data, "5") == 0)
|
||||
SoundIrq = 5;
|
||||
if (strcmp((char*)user_data, "7") == 0)
|
||||
SoundIrq = 7;
|
||||
if (strcmp((char*)user_data, "10") == 0)
|
||||
SoundIrq = 10;
|
||||
}
|
||||
|
||||
void GetSoundBasePort(TXT_UNCAST_ARG(widget), void* user_data)
|
||||
{
|
||||
if (strcmp((char*)user_data, "210") == 0)
|
||||
SoundBasePort = 210;
|
||||
if (strcmp((char*)user_data, "220") == 0)
|
||||
SoundBasePort = 220;
|
||||
if (strcmp((char*)user_data, "230") == 0)
|
||||
SoundBasePort = 230;
|
||||
if (strcmp((char*)user_data, "240") == 0)
|
||||
SoundBasePort = 240;
|
||||
if (strcmp((char*)user_data, "250") == 0)
|
||||
SoundBasePort = 250;
|
||||
if (strcmp((char*)user_data, "260") == 0)
|
||||
SoundBasePort = 260;
|
||||
if (strcmp((char*)user_data, "280") == 0)
|
||||
SoundBasePort = 280;
|
||||
}
|
||||
|
||||
void GetSoundGMPort(TXT_UNCAST_ARG(widget), void* user_data)
|
||||
{
|
||||
if (strcmp((char*)user_data, "220") == 0)
|
||||
SoundMidiPort = 220;
|
||||
if (strcmp((char*)user_data, "230") == 0)
|
||||
SoundMidiPort = 230;
|
||||
if (strcmp((char*)user_data, "240") == 0)
|
||||
SoundMidiPort = 240;
|
||||
if (strcmp((char*)user_data, "250") == 0)
|
||||
SoundMidiPort = 250;
|
||||
if (strcmp((char*)user_data, "300") == 0)
|
||||
SoundMidiPort = 300;
|
||||
if (strcmp((char*)user_data, "320") == 0)
|
||||
SoundMidiPort = 320;
|
||||
if (strcmp((char*)user_data, "330") == 0)
|
||||
SoundMidiPort = 330;
|
||||
if (strcmp((char*)user_data, "332") == 0)
|
||||
SoundMidiPort = 332;
|
||||
if (strcmp((char*)user_data, "334") == 0)
|
||||
SoundMidiPort = 334;
|
||||
if (strcmp((char*)user_data, "336") == 0)
|
||||
SoundMidiPort = 336;
|
||||
if (strcmp((char*)user_data, "340") == 0)
|
||||
SoundMidiPort = 340;
|
||||
if (strcmp((char*)user_data, "360") == 0)
|
||||
SoundMidiPort = 360;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
extern int SoundCardType;
|
||||
extern int SoundMidiPort;
|
||||
extern int SoundBasePort;
|
||||
extern int SoundIrq;
|
||||
extern int SoundDma;
|
||||
extern int SoundChannels;
|
||||
|
||||
void GetSoundChannels(TXT_UNCAST_ARG(widget), void* user_data);
|
||||
void GetSoundDma(TXT_UNCAST_ARG(widget), void* user_data);
|
||||
void GetSoundIrq(TXT_UNCAST_ARG(widget), void* user_data);
|
||||
void GetSoundBasePort(TXT_UNCAST_ARG(widget), void* user_data);
|
||||
void GetSoundcard(TXT_UNCAST_ARG(widget), void* user_data);
|
||||
void GetSoundGMPort(TXT_UNCAST_ARG(widget), void* user_data);
|
||||
@@ -0,0 +1,371 @@
|
||||
//
|
||||
// Copyright(C) 2005-2014 Simon Howard
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "SDL_joystick.h"
|
||||
|
||||
#include "doomkeys.h"
|
||||
#include "input.h"
|
||||
#include "prefapi.h"
|
||||
#include "main.h"
|
||||
|
||||
extern "C" {
|
||||
#include "txt_joyinput.h"
|
||||
#include "txt_gui.h"
|
||||
#include "txt_io.h"
|
||||
#include "txt_label.h"
|
||||
#include "txt_sdl.h"
|
||||
#include "txt_utf8.h"
|
||||
#include "txt_window.h"
|
||||
}
|
||||
|
||||
#define JOYSTICK_INPUT_WIDTH 10
|
||||
|
||||
int joystick_index;
|
||||
int joystick_physical_buttons[NUM_VIRTUAL_BUTTONS] = {
|
||||
0, 1, 2, 3
|
||||
};
|
||||
|
||||
// Joystick button variables.
|
||||
// The ordering of this array is important. We will always try to map
|
||||
// each variable to the virtual button with the same array index. For
|
||||
// example: joybfire should always be 0, and then we change
|
||||
// joystick_physical_buttons[0] to point to the physical joystick
|
||||
// button that the user wants to use for firing. We do this so that
|
||||
// the menus work (the game code is hard coded to interpret
|
||||
// button #0 = select menu item, button #1 = go back to previous menu).
|
||||
static int* all_joystick_buttons[NUM_VIRTUAL_BUTTONS] =
|
||||
{
|
||||
&joybfire,
|
||||
&joybchweapon,
|
||||
&joybmega,
|
||||
&joybspeed,
|
||||
};
|
||||
|
||||
static int PhysicalForVirtualButton(int vbutton)
|
||||
{
|
||||
if (vbutton < NUM_VIRTUAL_BUTTONS)
|
||||
{
|
||||
return joystick_physical_buttons[vbutton];
|
||||
}
|
||||
else
|
||||
{
|
||||
return vbutton;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the virtual button number for the given variable, ie. the
|
||||
// variable's index in all_joystick_buttons[NUM_VIRTUAL_BUTTONS].
|
||||
static int VirtualButtonForVariable(int* variable)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < arrlen(all_joystick_buttons); ++i)
|
||||
{
|
||||
if (variable == all_joystick_buttons[i])
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
//I_Error("Couldn't find virtual button");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Rearrange joystick button configuration to be in "canonical" form:
|
||||
// each joyb* variable should have a value equal to its index in
|
||||
// all_joystick_buttons[NUM_VIRTUAL_BUTTONS] above.
|
||||
static void CanonicalizeButtons(void)
|
||||
{
|
||||
int new_mapping[NUM_VIRTUAL_BUTTONS];
|
||||
int vbutton;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < arrlen(all_joystick_buttons); ++i)
|
||||
{
|
||||
vbutton = *all_joystick_buttons[i];
|
||||
|
||||
// Don't remap the speed key if it's bound to "always run".
|
||||
// Also preserve "unbound" variables.
|
||||
if ((all_joystick_buttons[i] == &joybspeed && vbutton >= 20)
|
||||
|| vbutton < 0)
|
||||
{
|
||||
new_mapping[i] = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
new_mapping[i] = PhysicalForVirtualButton(vbutton);
|
||||
*all_joystick_buttons[i] = i;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < NUM_VIRTUAL_BUTTONS; ++i)
|
||||
{
|
||||
joystick_physical_buttons[i] = new_mapping[i];
|
||||
}
|
||||
}
|
||||
|
||||
// Check all existing buttons and clear any using the specified physical
|
||||
// button.
|
||||
static void ClearVariablesUsingButton(int physbutton)
|
||||
{
|
||||
int vbutton;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < arrlen(all_joystick_buttons); ++i)
|
||||
{
|
||||
vbutton = *all_joystick_buttons[i];
|
||||
|
||||
if (vbutton >= 0 && physbutton == PhysicalForVirtualButton(vbutton))
|
||||
{
|
||||
*all_joystick_buttons[i] = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Called in response to SDL events when the prompt window is open:
|
||||
|
||||
static int EventCallback(SDL_Event* event, TXT_UNCAST_ARG(joystick_input))
|
||||
{
|
||||
TXT_CAST_ARG(txt_joystick_input_t, joystick_input);
|
||||
|
||||
// Got the joystick button press?
|
||||
|
||||
if (event->type == SDL_JOYBUTTONDOWN)
|
||||
{
|
||||
int vbutton, physbutton;
|
||||
|
||||
// Before changing anything, remap button configuration into
|
||||
// canonical form, to avoid conflicts.
|
||||
CanonicalizeButtons();
|
||||
|
||||
vbutton = VirtualButtonForVariable(joystick_input->variable);
|
||||
physbutton = event->jbutton.button;
|
||||
|
||||
if (joystick_input->check_conflicts)
|
||||
{
|
||||
ClearVariablesUsingButton(physbutton);
|
||||
}
|
||||
|
||||
// Set mapping.
|
||||
*joystick_input->variable = vbutton;
|
||||
joystick_physical_buttons[vbutton] = physbutton;
|
||||
|
||||
if (vbutton == 0)
|
||||
{
|
||||
joybfireout = physbutton;
|
||||
writeflagjoybfire = 1;
|
||||
}
|
||||
if (vbutton == 1)
|
||||
{
|
||||
joybchweaponout = physbutton;
|
||||
writeflagjoybchweapon = 1;
|
||||
}
|
||||
if (vbutton == 2)
|
||||
{
|
||||
joybmegaout = physbutton;
|
||||
writeflagjoybmega = 1;
|
||||
}
|
||||
|
||||
TXT_CloseWindow(joystick_input->prompt_window);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// When the prompt window is closed, disable the event callback function;
|
||||
// we are no longer interested in receiving notification of events.
|
||||
|
||||
static void PromptWindowClosed(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(joystick))
|
||||
{
|
||||
TXT_CAST_ARG(SDL_Joystick, joystick);
|
||||
|
||||
SDL_JoystickClose(joystick);
|
||||
TXT_SDL_SetEventCallback(NULL, NULL);
|
||||
SDL_JoystickEventState(SDL_DISABLE);
|
||||
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
|
||||
}
|
||||
|
||||
static void OpenErrorWindow(void)
|
||||
{
|
||||
txt_window_t* window;
|
||||
txt_window_action_t* close_button;
|
||||
|
||||
window = TXT_CustomMessageBox(NULL, "Please connect a controller first!", TXT_COLOR_BRIGHT_WHITE, TXT_COLOR_RED, TXT_COLOR_RED, TXT_COLOR_BRIGHT_WHITE, TXT_COLOR_BRIGHT_WHITE, TXT_COLOR_BRIGHT_WHITE, TXT_COLOR_BRIGHT_WHITE);
|
||||
|
||||
close_button = TXT_NewWindowAction(KEY_ESCAPE, "Abort");
|
||||
|
||||
TXT_SetHelpLabel(close_button, " Press ESC to Abort");
|
||||
|
||||
TXT_SignalConnect(close_button, "pressed", ClosePwnBox, window);
|
||||
|
||||
TXT_SetWidgetFocus(getcontroljoystickwindow, 1);
|
||||
|
||||
TXT_SetWindowAction(window, TXT_HORIZ_CENTER, close_button);
|
||||
}
|
||||
|
||||
static void OpenPromptWindow(txt_joystick_input_t* joystick_input)
|
||||
{
|
||||
txt_window_t* window;
|
||||
txt_window_action_t* close_button;
|
||||
SDL_Joystick* joystick;
|
||||
|
||||
// Silently update when the shift button is held down.
|
||||
|
||||
joystick_input->check_conflicts = !TXT_GetModifierState(TXT_MOD_SHIFT);
|
||||
|
||||
if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Check the current joystick is valid
|
||||
|
||||
joystick = SDL_JoystickOpen(joystick_index);
|
||||
|
||||
if (joystick == NULL)
|
||||
{
|
||||
OpenErrorWindow();
|
||||
return;
|
||||
}
|
||||
|
||||
// Open the prompt window
|
||||
|
||||
window = TXT_MessageBox(NULL, " Click the new Button ");
|
||||
TXT_SetWindowPosition(window, TXT_HORIZ_CENTER, TXT_VERT_TOP, 39, 10);
|
||||
|
||||
close_button = TXT_NewWindowAction(KEY_ESCAPE, "Abort");
|
||||
|
||||
TXT_SetHelpLabel(close_button, " Press ESC to Abort");
|
||||
|
||||
TXT_SignalConnect(close_button, "pressed", ClosePwnBox, window);
|
||||
|
||||
TXT_SDL_SetEventCallback(EventCallback, joystick_input);
|
||||
TXT_SignalConnect(window, "closed", PromptWindowClosed, joystick);
|
||||
joystick_input->prompt_window = window;
|
||||
|
||||
SDL_JoystickEventState(SDL_ENABLE);
|
||||
TXT_SetWidgetFocus(getcontroljoystickwindow, 1);
|
||||
|
||||
TXT_SetWindowAction(window, TXT_HORIZ_CENTER, close_button);
|
||||
}
|
||||
|
||||
static void TXT_JoystickInputSizeCalc(TXT_UNCAST_ARG(joystick_input))
|
||||
{
|
||||
TXT_CAST_ARG(txt_joystick_input_t, joystick_input);
|
||||
|
||||
// All joystickinputs are the same size.
|
||||
|
||||
joystick_input->widget.w = JOYSTICK_INPUT_WIDTH;
|
||||
joystick_input->widget.h = 1;
|
||||
}
|
||||
|
||||
static void GetJoystickButtonDescription(int vbutton, char* buf,
|
||||
size_t buf_len)
|
||||
{
|
||||
M_snprintf(buf, buf_len, "BUTTON %i",
|
||||
PhysicalForVirtualButton(vbutton) + 1);
|
||||
}
|
||||
|
||||
static void TXT_JoystickInputDrawer(TXT_UNCAST_ARG(joystick_input))
|
||||
{
|
||||
TXT_CAST_ARG(txt_joystick_input_t, joystick_input);
|
||||
char buf[20];
|
||||
int i;
|
||||
|
||||
if (*joystick_input->variable < 0)
|
||||
{
|
||||
M_StringCopy(buf, "(none)", sizeof(buf));
|
||||
}
|
||||
else
|
||||
{
|
||||
GetJoystickButtonDescription(*joystick_input->variable,
|
||||
buf, sizeof(buf));
|
||||
}
|
||||
|
||||
TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
|
||||
TXT_SetWidgetBG(joystick_input);
|
||||
|
||||
TXT_DrawString(buf);
|
||||
|
||||
for (i = TXT_UTF8_Strlen(buf); i < JOYSTICK_INPUT_WIDTH; ++i)
|
||||
{
|
||||
TXT_DrawString(" ");
|
||||
}
|
||||
}
|
||||
|
||||
static void TXT_JoystickInputDestructor(TXT_UNCAST_ARG(joystick_input))
|
||||
{
|
||||
}
|
||||
|
||||
static int TXT_JoystickInputKeyPress(TXT_UNCAST_ARG(joystick_input), int key)
|
||||
{
|
||||
TXT_CAST_ARG(txt_joystick_input_t, joystick_input);
|
||||
|
||||
if (key == KEY_ENTER)
|
||||
{
|
||||
// Open a window to prompt for the new joystick press
|
||||
|
||||
OpenPromptWindow(joystick_input);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (key == KEY_BACKSPACE || key == KEY_DEL)
|
||||
{
|
||||
*joystick_input->variable = -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void TXT_JoystickInputMousePress(TXT_UNCAST_ARG(widget),
|
||||
int x, int y, int b)
|
||||
{
|
||||
TXT_CAST_ARG(txt_joystick_input_t, widget);
|
||||
|
||||
// Clicking is like pressing enter
|
||||
|
||||
if (b == TXT_MOUSE_LEFT)
|
||||
{
|
||||
TXT_JoystickInputKeyPress(widget, KEY_ENTER);
|
||||
}
|
||||
}
|
||||
|
||||
txt_widget_class_t txt_joystick_input_class =
|
||||
{
|
||||
TXT_AlwaysSelectable,
|
||||
TXT_JoystickInputSizeCalc,
|
||||
TXT_JoystickInputDrawer,
|
||||
TXT_JoystickInputKeyPress,
|
||||
TXT_JoystickInputDestructor,
|
||||
TXT_JoystickInputMousePress,
|
||||
NULL,
|
||||
};
|
||||
|
||||
txt_joystick_input_t* TXT_NewJoystickInput(int* variable)
|
||||
{
|
||||
txt_joystick_input_t* joystick_input;
|
||||
|
||||
joystick_input = (txt_joystick_input_t * )malloc(sizeof(txt_joystick_input_t));
|
||||
|
||||
TXT_InitWidget(joystick_input, &txt_joystick_input_class);
|
||||
joystick_input->variable = variable;
|
||||
|
||||
return joystick_input;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// Copyright(C) 2005-2014 Simon Howard
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
|
||||
#ifndef TXT_JOYB_INPUT_H
|
||||
#define TXT_JOYB_INPUT_H
|
||||
#define NUM_VIRTUAL_BUTTONS 4
|
||||
|
||||
typedef struct txt_joystick_input_s txt_joystick_input_t;
|
||||
|
||||
#include "txt_widget.h"
|
||||
#include "txt_window.h"
|
||||
|
||||
//
|
||||
// A joystick input is like an input box. When selected, a box pops up
|
||||
// allowing a joystick button to be pressed to select it.
|
||||
//
|
||||
|
||||
struct txt_joystick_input_s
|
||||
{
|
||||
txt_widget_t widget;
|
||||
int* variable;
|
||||
txt_window_t* prompt_window;
|
||||
int check_conflicts;
|
||||
};
|
||||
|
||||
txt_joystick_input_t* TXT_NewJoystickInput(int* variable);
|
||||
|
||||
extern int joystick_index;
|
||||
|
||||
#endif /* #ifndef TXT_JOYB_INPUT_H */
|
||||
@@ -0,0 +1,200 @@
|
||||
//
|
||||
// Copyright(C) 2005-2014 Simon Howard
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "doomkeys.h"
|
||||
#include "prefapi.h"
|
||||
#include "input.h"
|
||||
#include "main.h"
|
||||
|
||||
extern "C" {
|
||||
#include "txt_keyinput.h"
|
||||
#include "txt_gui.h"
|
||||
#include "txt_io.h"
|
||||
#include "txt_label.h"
|
||||
#include "txt_utf8.h"
|
||||
#include "txt_window.h"
|
||||
}
|
||||
|
||||
#define KEY_INPUT_WIDTH 8
|
||||
|
||||
static int KeyPressCallback(txt_window_t* window, int key,
|
||||
TXT_UNCAST_ARG(key_input))
|
||||
{
|
||||
TXT_CAST_ARG(txt_key_input_t, key_input);
|
||||
|
||||
if (key != KEY_ESCAPE)
|
||||
{
|
||||
// Got the key press. Save to the variable and close the window.
|
||||
|
||||
*key_input->variable = key;
|
||||
|
||||
if (key_input->check_conflicts)
|
||||
{
|
||||
TXT_EmitSignal(key_input, "set");
|
||||
}
|
||||
|
||||
TXT_CloseWindow(window);
|
||||
|
||||
// Return to normal input mode now that we have the key.
|
||||
TXT_SetInputMode(TXT_INPUT_NORMAL);
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void ReleaseGrab(TXT_UNCAST_ARG(window), TXT_UNCAST_ARG(unused))
|
||||
{
|
||||
// SDL2-TODO: Needed?
|
||||
// SDL_WM_GrabInput(SDL_GRAB_OFF);
|
||||
}
|
||||
|
||||
static void OpenPromptWindow(txt_key_input_t* key_input)
|
||||
{
|
||||
txt_window_t* window;
|
||||
txt_window_action_t* close_button;
|
||||
|
||||
// Silently update when the shift button is held down.
|
||||
|
||||
key_input->check_conflicts = !TXT_GetModifierState(TXT_MOD_SHIFT);
|
||||
|
||||
window = TXT_CustomMessageBox(NULL, " Press New Key ", TXT_COLOR_BLUE, TXT_COLOR_GREY, TXT_COLOR_GREY, TXT_COLOR_BLUE, TXT_COLOR_BLUE, TXT_COLOR_BLUE, TXT_COLOR_BLUE);
|
||||
TXT_SetWindowPosition(window, TXT_HORIZ_CENTER, TXT_VERT_TOP, 40, 11);
|
||||
|
||||
close_button = TXT_NewWindowAction(KEY_ESCAPE, "Abort");
|
||||
|
||||
TXT_SetKeyListener(window, KeyPressCallback, key_input);
|
||||
|
||||
// Switch to raw input mode while we're grabbing the key.
|
||||
TXT_SetInputMode(TXT_INPUT_RAW);
|
||||
|
||||
// Grab input while reading the key. On Windows Mobile
|
||||
// handheld devices, the hardware keypresses are only
|
||||
// detected when input is grabbed.
|
||||
|
||||
// SDL2-TODO: Needed?
|
||||
//SDL_WM_GrabInput(SDL_GRAB_ON);
|
||||
TXT_SignalConnect(window, "closed", ReleaseGrab, NULL);
|
||||
|
||||
TXT_SetHelpLabel(close_button, " Press ESC to Abort");
|
||||
|
||||
TXT_SignalConnect(close_button, "pressed", ClosePwnBox, window);
|
||||
|
||||
TXT_SetWidgetFocus(window, 0);
|
||||
TXT_SetWidgetFocus(getcontrolkeyboardwindow, 1);
|
||||
|
||||
TXT_SetWindowAction(window, TXT_HORIZ_CENTER, close_button);
|
||||
}
|
||||
|
||||
static void TXT_KeyInputSizeCalc(TXT_UNCAST_ARG(key_input))
|
||||
{
|
||||
TXT_CAST_ARG(txt_key_input_t, key_input);
|
||||
|
||||
// All keyinputs are the same size.
|
||||
|
||||
key_input->widget.w = KEY_INPUT_WIDTH;
|
||||
key_input->widget.h = 1;
|
||||
}
|
||||
|
||||
static void TXT_KeyInputDrawer(TXT_UNCAST_ARG(key_input))
|
||||
{
|
||||
TXT_CAST_ARG(txt_key_input_t, key_input);
|
||||
char buf[20];
|
||||
int i;
|
||||
|
||||
if (*key_input->variable == 0)
|
||||
{
|
||||
M_StringCopy(buf, "(none)", sizeof(buf));
|
||||
}
|
||||
else
|
||||
{
|
||||
TXT_GetKeyDescription(*key_input->variable, buf, sizeof(buf));
|
||||
}
|
||||
|
||||
TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
|
||||
TXT_SetWidgetBG(key_input);
|
||||
|
||||
TXT_DrawString(buf);
|
||||
|
||||
for (i = TXT_UTF8_Strlen(buf); i < KEY_INPUT_WIDTH; ++i)
|
||||
{
|
||||
TXT_DrawString(" ");
|
||||
}
|
||||
}
|
||||
|
||||
static void TXT_KeyInputDestructor(TXT_UNCAST_ARG(key_input))
|
||||
{
|
||||
}
|
||||
|
||||
static int TXT_KeyInputKeyPress(TXT_UNCAST_ARG(key_input), int key)
|
||||
{
|
||||
TXT_CAST_ARG(txt_key_input_t, key_input);
|
||||
|
||||
if (key == KEY_ENTER)
|
||||
{
|
||||
// Open a window to prompt for the new key press
|
||||
|
||||
OpenPromptWindow(key_input);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (key == KEY_BACKSPACE || key == KEY_DEL)
|
||||
{
|
||||
*key_input->variable = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void TXT_KeyInputMousePress(TXT_UNCAST_ARG(widget), int x, int y, int b)
|
||||
{
|
||||
TXT_CAST_ARG(txt_key_input_t, widget);
|
||||
|
||||
// Clicking is like pressing enter
|
||||
|
||||
if (b == TXT_MOUSE_LEFT)
|
||||
{
|
||||
TXT_KeyInputKeyPress(widget, KEY_ENTER);
|
||||
}
|
||||
}
|
||||
|
||||
txt_widget_class_t txt_key_input_class =
|
||||
{
|
||||
TXT_AlwaysSelectable,
|
||||
TXT_KeyInputSizeCalc,
|
||||
TXT_KeyInputDrawer,
|
||||
TXT_KeyInputKeyPress,
|
||||
TXT_KeyInputDestructor,
|
||||
TXT_KeyInputMousePress,
|
||||
NULL,
|
||||
};
|
||||
|
||||
txt_key_input_t* TXT_NewKeyInput(int* variable)
|
||||
{
|
||||
txt_key_input_t* key_input;
|
||||
|
||||
key_input = (txt_key_input_t * )malloc(sizeof(txt_key_input_t));
|
||||
|
||||
TXT_InitWidget(key_input, &txt_key_input_class);
|
||||
key_input->variable = variable;
|
||||
|
||||
return key_input;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
//
|
||||
// Copyright(C) 2005-2014 Simon Howard
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
|
||||
#ifndef TXT_KEY_INPUT_H
|
||||
#define TXT_KEY_INPUT_H
|
||||
|
||||
typedef struct txt_key_input_s txt_key_input_t;
|
||||
|
||||
#include "txt_widget.h"
|
||||
|
||||
//
|
||||
// A key input is like an input box. When selected, a box pops up
|
||||
// allowing a key to be selected.
|
||||
//
|
||||
|
||||
struct txt_key_input_s
|
||||
{
|
||||
txt_widget_t widget;
|
||||
int* variable;
|
||||
int check_conflicts;
|
||||
};
|
||||
|
||||
txt_key_input_t* TXT_NewKeyInput(int* variable);
|
||||
|
||||
#endif /* #ifndef TXT_KEY_INPUT_H */
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
//
|
||||
// Copyright(C) 2005-2014 Simon Howard
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "doomkeys.h"
|
||||
#include "prefapi.h"
|
||||
#include "input.h"
|
||||
#include "main.h"
|
||||
|
||||
extern "C" {
|
||||
#include "txt_mouseinput.h"
|
||||
#include "txt_gui.h"
|
||||
#include "txt_io.h"
|
||||
#include "txt_label.h"
|
||||
#include "txt_utf8.h"
|
||||
#include "txt_window.h"
|
||||
}
|
||||
|
||||
// eg. "BUTTON #10"
|
||||
#define MOUSE_INPUT_WIDTH 10
|
||||
|
||||
static int MousePressCallback(txt_window_t* window,
|
||||
int x, int y, int b,
|
||||
TXT_UNCAST_ARG(mouse_input))
|
||||
{
|
||||
TXT_CAST_ARG(txt_mouse_input_t, mouse_input);
|
||||
|
||||
// Got the mouse press. Save to the variable and close the window.
|
||||
|
||||
*mouse_input->variable = b - TXT_MOUSE_BASE;
|
||||
|
||||
if (mouse_input->check_conflicts)
|
||||
{
|
||||
TXT_EmitSignal(mouse_input, "set");
|
||||
}
|
||||
|
||||
TXT_CloseWindow(window);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void OpenPromptWindow(txt_mouse_input_t* mouse_input)
|
||||
{
|
||||
txt_window_t* window;
|
||||
txt_window_action_t* close_button;
|
||||
|
||||
// Silently update when the shift key is held down.
|
||||
mouse_input->check_conflicts = !TXT_GetModifierState(TXT_MOD_SHIFT);
|
||||
|
||||
window = TXT_MessageBox(NULL, " Click the new Button ");
|
||||
TXT_SetWindowPosition(window, TXT_HORIZ_CENTER, TXT_VERT_TOP, 39, 10);
|
||||
|
||||
close_button = TXT_NewWindowAction(KEY_ESCAPE, "Abort");
|
||||
|
||||
TXT_SetMouseListener(window, MousePressCallback, mouse_input);
|
||||
|
||||
TXT_SetHelpLabel(close_button, " Press ESC to Abort");
|
||||
|
||||
TXT_SignalConnect(close_button, "pressed", ClosePwnBox, window);
|
||||
|
||||
TXT_SetWidgetFocus(getcontrolmousewindow, 1);
|
||||
|
||||
TXT_SetWindowAction(window, TXT_HORIZ_CENTER, close_button);
|
||||
}
|
||||
|
||||
static void TXT_MouseInputSizeCalc(TXT_UNCAST_ARG(mouse_input))
|
||||
{
|
||||
TXT_CAST_ARG(txt_mouse_input_t, mouse_input);
|
||||
|
||||
// All mouseinputs are the same size.
|
||||
|
||||
mouse_input->widget.w = MOUSE_INPUT_WIDTH;
|
||||
mouse_input->widget.h = 1;
|
||||
}
|
||||
|
||||
static void GetMouseButtonDescription(int button, char* buf, size_t buf_len)
|
||||
{
|
||||
switch (button)
|
||||
{
|
||||
case 0:
|
||||
M_StringCopy(buf, "LEFT BUTTON", buf_len);
|
||||
break;
|
||||
case 1:
|
||||
M_StringCopy(buf, "RIGHT BUTTON", buf_len);
|
||||
break;
|
||||
case 2:
|
||||
M_StringCopy(buf, "MID BUTTON", buf_len);
|
||||
break;
|
||||
default:
|
||||
M_snprintf(buf, buf_len, "BUTTON %i", button + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void TXT_MouseInputDrawer(TXT_UNCAST_ARG(mouse_input))
|
||||
{
|
||||
TXT_CAST_ARG(txt_mouse_input_t, mouse_input);
|
||||
char buf[20];
|
||||
int i;
|
||||
|
||||
if (*mouse_input->variable < 0)
|
||||
{
|
||||
M_StringCopy(buf, "(none)", sizeof(buf));
|
||||
}
|
||||
else
|
||||
{
|
||||
GetMouseButtonDescription(*mouse_input->variable, buf, sizeof(buf));
|
||||
}
|
||||
|
||||
TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
|
||||
TXT_SetWidgetBG(mouse_input);
|
||||
|
||||
TXT_DrawString(buf);
|
||||
|
||||
for (i = TXT_UTF8_Strlen(buf); i < MOUSE_INPUT_WIDTH; ++i)
|
||||
{
|
||||
TXT_DrawString(" ");
|
||||
}
|
||||
}
|
||||
|
||||
static void TXT_MouseInputDestructor(TXT_UNCAST_ARG(mouse_input))
|
||||
{
|
||||
}
|
||||
|
||||
static int TXT_MouseInputKeyPress(TXT_UNCAST_ARG(mouse_input), int key)
|
||||
{
|
||||
TXT_CAST_ARG(txt_mouse_input_t, mouse_input);
|
||||
|
||||
if (key == KEY_ENTER)
|
||||
{
|
||||
// Open a window to prompt for the new mouse press
|
||||
|
||||
OpenPromptWindow(mouse_input);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (key == KEY_BACKSPACE || key == KEY_DEL)
|
||||
{
|
||||
*mouse_input->variable = -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void TXT_MouseInputMousePress(TXT_UNCAST_ARG(widget), int x, int y, int b)
|
||||
{
|
||||
TXT_CAST_ARG(txt_mouse_input_t, widget);
|
||||
|
||||
// Clicking is like pressing enter
|
||||
|
||||
if (b == TXT_MOUSE_LEFT)
|
||||
{
|
||||
TXT_MouseInputKeyPress(widget, KEY_ENTER);
|
||||
}
|
||||
}
|
||||
|
||||
txt_widget_class_t txt_mouse_input_class =
|
||||
{
|
||||
TXT_AlwaysSelectable,
|
||||
TXT_MouseInputSizeCalc,
|
||||
TXT_MouseInputDrawer,
|
||||
TXT_MouseInputKeyPress,
|
||||
TXT_MouseInputDestructor,
|
||||
TXT_MouseInputMousePress,
|
||||
NULL,
|
||||
};
|
||||
|
||||
txt_mouse_input_t* TXT_NewMouseInput(int* variable)
|
||||
{
|
||||
txt_mouse_input_t* mouse_input;
|
||||
|
||||
mouse_input = (txt_mouse_input_t *) malloc(sizeof(txt_mouse_input_t));
|
||||
|
||||
TXT_InitWidget(mouse_input, &txt_mouse_input_class);
|
||||
mouse_input->variable = variable;
|
||||
|
||||
return mouse_input;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// Copyright(C) 2005-2014 Simon Howard
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
|
||||
#ifndef TXT_MOUSE_INPUT_H
|
||||
#define TXT_MOUSE_INPUT_H
|
||||
|
||||
typedef struct txt_mouse_input_s txt_mouse_input_t;
|
||||
|
||||
#include "txt_widget.h"
|
||||
|
||||
//
|
||||
// A mouse input is like an input box. When selected, a box pops up
|
||||
// allowing a mouse to be selected.
|
||||
//
|
||||
|
||||
struct txt_mouse_input_s
|
||||
{
|
||||
txt_widget_t widget;
|
||||
int* variable;
|
||||
int check_conflicts;
|
||||
};
|
||||
|
||||
txt_mouse_input_t* TXT_NewMouseInput(int* variable);
|
||||
|
||||
#endif /* #ifndef TXT_MOUSE_INPUT_H */
|
||||
|
||||
|
||||
Reference in new issue
Block a user