almost finish porting menu options screens to C

This commit is contained in:
UnknownShadow200 2018-04-19 10:26:48 +10:00
parent d11a36a30f
commit cc85c297ee
12 changed files with 462 additions and 391 deletions

View File

@ -73,32 +73,27 @@ namespace ClassicalSharp.Network {
}
#endif
/// <summary> Asynchronously downloads a bitmap image from the specified url. </summary>
public void AsyncGetImage(string url, bool priority, string identifier) {
AddRequest(url, priority, identifier, RequestType.Bitmap,
DateTime.MinValue, null, null);
}
/// <summary> Asynchronously downloads a string from the specified url. </summary>
public void AsyncGetString(string url, bool priority, string identifier) {
AddRequest(url, priority, identifier, RequestType.String,
DateTime.MinValue, null, null);
}
/// <summary> Asynchronously downloads a byte array. </summary>
public void AsyncGetData(string url, bool priority, string identifier) {
AddRequest(url, priority, identifier, RequestType.ByteArray,
DateTime.MinValue, null, null);
}
/// <summary> Asynchronously downloads a bitmap image. </summary>
public void AsyncGetImage(string url, bool priority, string identifier,
DateTime lastModified, string etag) {
AddRequest(url, priority, identifier, RequestType.Bitmap,
lastModified, etag, null);
}
/// <summary> Asynchronously downloads a byte array. </summary>
public void AsyncGetData(string url, bool priority, string identifier,
DateTime lastModified, string etag) {
AddRequest(url, priority, identifier, RequestType.ByteArray,
@ -106,13 +101,11 @@ namespace ClassicalSharp.Network {
}
#if !LAUNCHER
/// <summary> Asynchronously retrieves the content length of the body response. </summary>
public void AsyncGetContentLength(string url, bool priority, string identifier) {
AddRequest(url, priority, identifier, RequestType.ContentLength,
DateTime.MinValue, null, null);
}
#else
/// <summary> Asynchronously retrieves the content length of the body response. </summary>
public void AsyncPostString(string url, bool priority, string identifier, string contents) {
AddRequest(url, priority, identifier, RequestType.String,
DateTime.MinValue, null, contents);

View File

@ -141,10 +141,7 @@ bool anims_validated, anims_useLavaAnim, anims_useWaterAnim;
void Animations_LogFail(STRING_TRANSIENT String* line, const UInt8* raw) {
UInt8 msgBuffer[String_BufferSize(128)];
String msg = String_InitAndClearArray(msgBuffer);
String_AppendConst(&msg, raw);
String_Append(&msg, ':'); String_Append(&msg, ' ');
String_AppendString(&msg, line);
String_Format2(&msg, "%c: %s", raw, line);
Chat_Add(&msg);
}

View File

@ -139,6 +139,7 @@ typedef struct NetPlayer_ {
NetInterpComp Interp;
bool ShouldRender;
} NetPlayer;
void NetPlayer_Init(NetPlayer* player);
/* Represents the user/player's own entity. */
typedef struct LocalPlayer_ {
@ -152,5 +153,6 @@ typedef struct LocalPlayer_ {
LocalPlayer LocalPlayer_Instance;
void LocalPlayer_Init(void);
void NetPlayer_Init(NetPlayer* player);
Real32 LocalPlayer_JumpHeight(void);
void LocalPlayer_ChecksHackConsistency();
#endif

View File

@ -55,8 +55,7 @@ void Game_GetDefaultTexturePack(STRING_TRANSIENT String* texPack) {
}
void Game_SetDefaultTexturePack(STRING_PURE String* texPack) {
String_Clear(&game_defTexPack);
String_AppendString(&game_defTexPack, texPack);
String_Set(&game_defTexPack, texPack);
Options_Set(OPT_DEFAULT_TEX_PACK, texPack);
}

View File

@ -131,7 +131,7 @@ bool InputHandler_DoFovZoom(Real32 deltaPrecise) {
HacksComp* h = &LocalPlayer_Instance.Hacks;
if (!h->Enabled || !h->CanAnyHacks || !h->CanUseThirdPersonCamera) return false;
if (input_fovIndex == -1.0f) input_fovIndex = Game_ZoomFov;
if (input_fovIndex == -1.0f) input_fovIndex = (Real32)Game_ZoomFov;
input_fovIndex -= deltaPrecise * 5.0f;
Math_Clamp(input_fovIndex, 1.0f, Game_DefaultFov);
@ -340,7 +340,7 @@ void InputHandler_MouseMove(void* obj, Int32 xDelta, Int32 yDelta) {
active->VTABLE->HandlesMouseMove(active, Mouse_X, Mouse_Y);
}
void InputHandler_MouseDown(void* obj, MouseButton button) {
void InputHandler_MouseDown(void* obj, Int32 button) {
GuiElement* active = (GuiElement*)Gui_GetActiveScreen();
if (!active->VTABLE->HandlesMouseDown(active, Mouse_X, Mouse_Y, button)) {
bool left = button == MouseButton_Left;
@ -352,7 +352,7 @@ void InputHandler_MouseDown(void* obj, MouseButton button) {
}
}
void InputHandler_MouseUp(void* obj, MouseButton button) {
void InputHandler_MouseUp(void* obj, Int32 button) {
GuiElement* active = (GuiElement*)Gui_GetActiveScreen();
if (!active->VTABLE->HandlesMouseUp(active, Mouse_X, Mouse_Y, button)) {
if (ServerConnection_SupportsPlayerClick && button <= MouseButton_Middle) {
@ -374,7 +374,7 @@ bool InputHandler_SimulateMouse(Key key, bool pressed) {
return true;
}
void InputHandler_KeyDown(void* obj, Key key) {
void InputHandler_KeyDown(void* obj, Int32 key) {
if (InputHandler_SimulateMouse(key, true)) return;
GuiElement* active = (GuiElement*)Gui_GetActiveScreen();
@ -401,7 +401,7 @@ void InputHandler_KeyDown(void* obj, Key key) {
}
}
void InputHandler_KeyUp(void* obj, Key key) {
void InputHandler_KeyUp(void* obj, Int32 key) {
if (InputHandler_SimulateMouse(key, false)) return;
if (key == KeyBind_Get(KeyBind_ZoomScrolling)) {

File diff suppressed because it is too large Load Diff

View File

@ -8,18 +8,26 @@
Screen* PauseScreen_MakeInstance(void);
Screen* OptionsGroupScreen_MakeInstance(void);
Screen* GenLevelScreen_MakeInstance(void);
Screen* ClassicGenScreen_MakeInstance(void);
Screen* LoadLevelScreen_MakeInstance(void);
Screen* SaveLevelScreen_MakeInstance(void);
Screen* TexturePackScreen_MakeInstance(void);
Screen* HotkeyListScreen_MakeInstance(void);
Screen* NostalgiaScreen_MakeInstance(void);
Screen* ClassicOptionsScreen_MakeInstance(void);
Screen* ClassicKeyBindingsScreen_MakeInstance(void);
Screen* ClassicHacksKeyBindingsScreen_MakeInstance(void);
Screen* NormalKeyBindingsScreen_MakeInstance(void);
Screen* HacksKeyBindingsScreen_MakeInstance(void);
Screen* OtherKeyBindingsScreen_MakeInstance(void);
Screen* MouseKeyBindingsScreen_MakeInstance(void);
Screen* GenLevelScreen_MakeInstance(void);
Screen* ClassicGenScreen_MakeInstance(void);
Screen* LoadLevelScreen_MakeInstance(void);
Screen* SaveLevelScreen_MakeInstance(void);
Screen* TexturePackScreen_MakeInstance(void);
Screen* HotkeyListScreen_MakeInstance(void);
Screen* MiscOptionsScreen_MakeInstance(void);
Screen* GuiOptionsScreen_MakeInstance(void);
Screen* GraphicsOptionsScreen_MakeInstance(void);
Screen* HacksSettingsScreen_MakeInstance(void);
Screen* EnvSettingsScreen_MakeInstance(void);
Screen* NostalgiaScreen_MakeInstance(void);
#endif

View File

@ -206,10 +206,7 @@ void Options_Save(void) {
for (i = 0; i < Options_Keys.Count; i++) {
String key = StringsBuffer_UNSAFE_Get(&Options_Keys, i);
String value = StringsBuffer_UNSAFE_Get(&Options_Values, i);
String_AppendString(&line, &key);
String_Append(&line, '=');
String_AppendString(&line, &value);
String_Format2(&line, "%s=%s", &key, &value);
Stream_WriteLine(&stream, &line);
String_Clear(&line);

View File

@ -694,8 +694,7 @@ void ChatScreen_OpenInput(ChatScreen* screen, STRING_PURE String* initialText) {
ChatScreen_SetHandlesAllInput(screen, true);
Key_KeyRepeat = true;
String_Clear(&screen->Input.Base.Text);
String_AppendString(&screen->Input.Base.Text, initialText);
String_Set(&screen->Input.Base.Text, initialText);
Elem_Recreate(&screen->Input.Base);
}

View File

@ -58,6 +58,11 @@ void String_Clear(STRING_TRANSIENT String* str) {
str->length = 0;
}
void String_Set(STRING_TRANSIENT String* str, STRING_PURE String* value) {
String_Clear(str);
String_AppendString(str, value);
}
String String_UNSAFE_Substring(STRING_REF String* str, Int32 offset, Int32 length) {
if (offset < 0 || offset > str->length) {
ErrorHandler_Fail("Offset for substring out of range");
@ -515,7 +520,7 @@ bool Convert_TryParseReal32(STRING_PURE String* str, Real32* value) {
Int32 i = 0;
*value = 0.0f;
bool foundDecimalPoint = false;
Real32 whole = 0.0f, fract = 0.0f, divide = 10.0f;
Real64 whole = 0.0f, fract = 0.0f, divide = 10.0f;
/* Handle number signs */
bool negate = false;
@ -542,9 +547,9 @@ bool Convert_TryParseReal32(STRING_PURE String* str, Real32* value) {
}
}
Real32 sum = whole + fract;
Real64 sum = whole + fract;
if (negate) sum = -sum;
*value = sum;
*value = (Real32)sum;
return true;
}

View File

@ -43,6 +43,7 @@ String String_FromReadonly(STRING_REF const UInt8* buffer);
void String_MakeLowercase(STRING_TRANSIENT String* str);
void String_Clear(STRING_TRANSIENT String* str);
void String_Set(STRING_TRANSIENT String* str, STRING_PURE String* value);
/* Returns a string that points directly to a substring of the given string.
NOTE: THIS IS UNSAFE - IT MAINTAINS A REFERENCE TO THE ORIGINAL BUFFER, AND THE SUBSTRING IS NOT NULL TERMINATED */
String String_UNSAFE_Substring(STRING_REF String* str, Int32 offset, Int32 length);
@ -61,7 +62,7 @@ bool String_AppendBool(STRING_TRANSIENT String* str, bool value);
bool String_AppendInt32(STRING_TRANSIENT String* str, Int32 num);
bool String_AppendUInt32(STRING_TRANSIENT String* str, UInt32 num);
bool String_AppendInt64(STRING_TRANSIENT String* str, Int64 num);
bool String_AppendReal32(STRING_TRANSIENT String* str, Real32 num, Int32 fracDigits);
bool String_AppendReal32(STRING_TRANSIENT String* str, Real32 num, Int32 fracDigits); /* TODO: Need to account for , or . for decimal */
bool String_AppendConst(STRING_TRANSIENT String* str, const UInt8* toAppend);
bool String_AppendString(STRING_TRANSIENT String* str, STRING_PURE String* toAppend);
bool String_AppendColorless(STRING_TRANSIENT String* str, STRING_PURE String* toAppend);

View File

@ -1656,8 +1656,7 @@ void ChatInputWidget_UpKey(GuiElement* elem) {
if (widget->TypingLogPos == Chat_InputLog.Count) {
String orig = String_FromRawArray(widget->OrigBuffer);
String_Clear(&orig);
String_AppendString(&orig, &input->Text);
String_Set(&orig, &input->Text);
}
if (Chat_InputLog.Count == 0) return;