Kaynağa Gözat

slightly simplified code

quantumde1 1 ay önce
ebeveyn
işleme
06abdda048
3 değiştirilmiş dosya ile 13 ekleme ve 14 silme
  1. 7 7
      source/dialogs/dialogbox.d
  2. 4 5
      source/scripts/lua.d
  3. 2 2
      source/variables.d

+ 7 - 7
source/dialogs/dialogbox.d

@@ -172,10 +172,10 @@ void displayDialog(string[] pages, string[] choices, ref int selectedChoice,
     
     // Draw text lines with shadow effect
     immutable float lineHeight = MeasureTextEx(dialogFont, "A", fontSize, spacing).y * 1.4;
-    foreach(i, line; lines) {
+    for (int i = 0; i < lines.length; i++) {
         Vector2 pos = Vector2(dialogRect.x + textLeftMargin, dialogRect.y + textTopMargin + i*lineHeight);
-        DrawTextEx(dialogFont, line.toStringz(), pos + Vector2(3*scale, 3*scale), fontSize, spacing, Colors.BLACK);
-        DrawTextEx(dialogFont, line.toStringz(), pos, fontSize, spacing, Colors.WHITE);
+        DrawTextEx(dialogFont, lines[i].toStringz(), pos + Vector2(3*scale, 3*scale), fontSize, spacing, Colors.BLACK);
+        DrawTextEx(dialogFont, lines[i].toStringz(), pos, fontSize, spacing, Colors.WHITE);
     }
     
     // Draw continue indicator when text is fully displayed
@@ -217,7 +217,7 @@ void displayDialog(string[] pages, string[] choices, ref int selectedChoice,
         Vector2 mousePos = GetMousePosition();
         bool mouseClicked = IsMouseButtonPressed(MouseButton.MOUSE_BUTTON_LEFT);
         
-        foreach(i, choice; choices) {
+        for (int i = 0; i < choices.length; i++) {
             Rectangle choiceRect = Rectangle(
                 choiceWindow.x + 40,
                 choiceWindow.y + verticalPadding + i*(choiceHeight + choiceSpacing),
@@ -228,14 +228,14 @@ void displayDialog(string[] pages, string[] choices, ref int selectedChoice,
             bool hovered = CheckCollisionPointRec(mousePos, choiceRect);
             if (hovered) selectedChoice = cast(int)i;
             
-            Vector2 textSize = MeasureTextEx(dialogFont, choice.toStringz(), fontSize, spacing);
+            Vector2 textSize = MeasureTextEx(dialogFont, choices[i].toStringz(), fontSize, spacing);
             Vector2 textPos = Vector2(
                 choiceRect.x + (choiceRect.width - textSize.x)/2,
                 choiceRect.y + (choiceRect.height - textSize.y)/2
             );
             
-            DrawTextEx(dialogFont, choice.toStringz(), textPos + Vector2(3*scale, 3*scale), fontSize, spacing, Colors.BLACK);
-            DrawTextEx(dialogFont, choice.toStringz(), textPos, fontSize, spacing, 
+            DrawTextEx(dialogFont, choices[i].toStringz(), textPos + Vector2(3*scale, 3*scale), fontSize, spacing, Colors.BLACK);
+            DrawTextEx(dialogFont, choices[i].toStringz(), textPos, fontSize, spacing, 
                       (i == selectedChoice) ? Colors.YELLOW : (hovered ? Colors.LIGHTGRAY : Colors.WHITE));
             
             if (hovered && mouseClicked) {

+ 4 - 5
source/scripts/lua.d

@@ -31,7 +31,7 @@ extern (C) nothrow int luaL_dialogBox(lua_State* L)
     int textTableLength = cast(int) lua_objlen(L, 1);
     messageGlobal = new string[](textTableLength); 
 
-    foreach (i; 0..textTableLength) {
+    for (int i = 0; i < textTableLength; i++) {
         lua_rawgeti(L, 1, i + 1);
         messageGlobal[i] = luaL_checkstring(L, -1).to!string;
         lua_pop(L, 1);
@@ -41,8 +41,7 @@ extern (C) nothrow int luaL_dialogBox(lua_State* L)
     luaL_checktype(L, 2, LUA_TTABLE);
     int choicesLength = cast(int) lua_objlen(L, 2);
     choices = new string[choicesLength];
-    foreach (i; 0..choicesLength)
-    {
+    for (int i = 0; i < choicesLength; i++) {
         lua_rawgeti(L, 2, i + 1);
         choices[i] = luaL_checkstring(L, -1).to!string;
         lua_pop(L, 1);
@@ -401,11 +400,11 @@ extern (C) nothrow int luaL_loadFont(lua_State* L)
     debugWriteln("Setting custom font: ", x.to!string);
     int[512] codepoints = 0;
     //configuring both cyrillic and latin fonts if available
-    foreach (i; 0 .. 95)
+    for (int i = 0; i < 95; i++)
     {
         codepoints[i] = 32 + i;
     }
-    foreach (i; 0 .. 255)
+    for (int i = 0; i < 255; i++)
     {
         codepoints[96 + i] = 0x400 + i;
     }

+ 2 - 2
source/variables.d

@@ -9,12 +9,12 @@ import system.abstraction;
 nothrow void resetAllScriptValues() {
     debugWriteln("Resetting all values!");
     selectedChoice = 0;
-    foreach (i; 0..characterTextures.length)
+    for (int i = 0; i < characterTextures.length; i++)
     {
         characterTextures[i].drawTexture = false;
         UnloadTexture(characterTextures[i].texture);
     }
-    foreach (i; 0..backgroundTextures.length)
+    for (int i = 0; i < backgroundTextures.length; i++)
     {
         backgroundTextures[i].drawTexture = false;
         UnloadTexture(backgroundTextures[i].texture);