From cf95e96345b581318ee04fa60f188f44c5e3e9dc Mon Sep 17 00:00:00 2001 From: Willem Cazander Date: Sat, 26 Mar 2022 22:11:05 +0100 Subject: [PATCH] Fixed calculator --- .../app/calculator/CalculatorComponent.java | 2 +- .../app/calculator/CalculatorDeskApp.java | 153 ++++++++++-------- .../{Main.properties => Messages.properties} | 0 ...o.properties => Messages_hiero.properties} | 0 4 files changed, 87 insertions(+), 68 deletions(-) rename gdxapp4d-app-calculator/src/main/resources/love/distributedrebirth/gdxapp4d/app/calculator/{Main.properties => Messages.properties} (100%) rename gdxapp4d-app-calculator/src/main/resources/love/distributedrebirth/gdxapp4d/app/calculator/{Main_hiero.properties => Messages_hiero.properties} (100%) diff --git a/gdxapp4d-app-calculator/src/main/java/love/distributedrebirth/gdxapp4d/app/calculator/CalculatorComponent.java b/gdxapp4d-app-calculator/src/main/java/love/distributedrebirth/gdxapp4d/app/calculator/CalculatorComponent.java index df62f3ec..59582705 100644 --- a/gdxapp4d-app-calculator/src/main/java/love/distributedrebirth/gdxapp4d/app/calculator/CalculatorComponent.java +++ b/gdxapp4d-app-calculator/src/main/java/love/distributedrebirth/gdxapp4d/app/calculator/CalculatorComponent.java @@ -25,7 +25,7 @@ public class CalculatorComponent { @Reference private VrGem4LocaleService localeService; - private final static String I18N_BUNDLE = "love.distributedrebirth.gdxapp4d.app.calculator.Main"; + private final static String I18N_BUNDLE = "love.distributedrebirth.gdxapp4d.app.calculator.Messages"; private final DeskAppLauncher launcher; public CalculatorComponent() { diff --git a/gdxapp4d-app-calculator/src/main/java/love/distributedrebirth/gdxapp4d/app/calculator/CalculatorDeskApp.java b/gdxapp4d-app-calculator/src/main/java/love/distributedrebirth/gdxapp4d/app/calculator/CalculatorDeskApp.java index 7de8918c..a2666d8d 100644 --- a/gdxapp4d-app-calculator/src/main/java/love/distributedrebirth/gdxapp4d/app/calculator/CalculatorDeskApp.java +++ b/gdxapp4d-app-calculator/src/main/java/love/distributedrebirth/gdxapp4d/app/calculator/CalculatorDeskApp.java @@ -16,11 +16,13 @@ import love.distributedrebirth.unicode4d.BaseGlyphSet; public class CalculatorDeskApp extends AbstractDeskApp implements DeskAppRenderer { private ResourceBundle bundle; + private int valueNum = 0; private String value = ""; private String valueLoc = ""; private String valueArg = ""; private Operation operation = Operation.NONE; private ImInt selectedNumberGlyph = new ImInt(); + private float buttonSize = 64f; public CalculatorDeskApp(ResourceBundle bundle) { this.bundle = bundle; @@ -52,107 +54,123 @@ public class CalculatorDeskApp extends AbstractDeskApp implements DeskAppRendere } String[] items = new String[bases.size()]; items = bases.toArray(items); - ImGui.combo(getTxt("selectedNumberGlyph"), selectedNumberGlyph, items); + boolean changedLoc = ImGui.combo(getTxt("selectedNumberGlyph"), selectedNumberGlyph, items); String selectedItem = items[selectedNumberGlyph.get()]; BaseGlyphSet baseNumber = BaseGlyphSet.valueOf(selectedItem); - + if (changedLoc) { + valueLoc = baseNumber.BȍőnPrintNumber10(valueNum, 9999999); + } + ImGui.text("Value:"); ImGui.sameLine(); ImGui.text(valueLoc); ImGui.separator(); - if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(0))) { - value+="0"; - valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(0); - } - ImGui.sameLine(); - if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(1))) { - value+="1"; - valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(1); - } - ImGui.sameLine(); - if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(2))) { - value+="2"; - valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(2); - } - ImGui.sameLine(); - if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(3))) { - value+="3"; - valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(3); - } - ImGui.sameLine(); - if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(4))) { - value+="4"; - valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(4); - } - - if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(5))) { - value+="5"; - valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(5); - } - ImGui.sameLine(); - if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(6))) { - value+="6"; - valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(6); - } - ImGui.sameLine(); - if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(7))) { + if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(7), buttonSize, buttonSize)) { value+="7"; + valueNum = Integer.parseInt(value); valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(7); } ImGui.sameLine(); - if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(8))) { + if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(8), buttonSize, buttonSize)) { value+="8"; + valueNum = Integer.parseInt(value); valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(8); } ImGui.sameLine(); - if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(9))) { + if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(9), buttonSize, buttonSize)) { value+="9"; + valueNum = Integer.parseInt(value); valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(9); } - + ImGui.sameLine(); + if (ImGui.button("/", buttonSize, buttonSize)) { + valueArg=value; + value=""; + valueLoc=""; + operation = Operation.DIVIDE; + } - if (ImGui.button("C")) { + if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(4), buttonSize, buttonSize)) { + value+="4"; + valueNum = Integer.parseInt(value); + valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(4); + } + ImGui.sameLine(); + if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(5), buttonSize, buttonSize)) { + value+="5"; + valueNum = Integer.parseInt(value); + valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(5); + } + ImGui.sameLine(); + if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(6), buttonSize, buttonSize)) { + value+="6"; + valueNum = Integer.parseInt(value); + valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(6); + } + ImGui.sameLine(); + if (ImGui.button("*", buttonSize, buttonSize)) { + valueArg=value; + value=""; + valueLoc=""; + operation = Operation.MULTIPLY; + } + + if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(1), buttonSize, buttonSize)) { + value+="1"; + valueNum = Integer.parseInt(value); + valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(1); + } + ImGui.sameLine(); + if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(2), buttonSize, buttonSize)) { + value+="2"; + valueNum = Integer.parseInt(value); + valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(2); + } + ImGui.sameLine(); + if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(3), buttonSize, buttonSize)) { + value+="3"; + valueNum = Integer.parseInt(value); + valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(3); + } + ImGui.sameLine(); + if (ImGui.button("-", buttonSize, buttonSize)) { + valueArg=value; + value=""; + valueLoc=""; + operation = Operation.MINUS; + } + + if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(0), buttonSize, buttonSize)) { + value+="0"; + valueNum = Integer.parseInt(value); + valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(0); + } + ImGui.sameLine(); + if (ImGui.button("C", buttonSize, buttonSize)) { + valueNum = 0; value=""; valueLoc=""; valueArg=""; operation = Operation.NONE; } - if (ImGui.button("+")) { + ImGui.sameLine(); + if (ImGui.button("+", buttonSize, buttonSize)) { valueArg=value; value=""; valueLoc=""; operation = Operation.PLUS; } ImGui.sameLine(); - if (ImGui.button("-")) { - valueArg=value; - value=""; - valueLoc=""; - operation = Operation.MINUS; - } - ImGui.sameLine(); - if (ImGui.button("*")) { - valueArg=value; - value=""; - valueLoc=""; - operation = Operation.MULTIPLY; - } - ImGui.sameLine(); - if (ImGui.button("/")) { - valueArg=value; - value=""; - valueLoc=""; - operation = Operation.DIVIDE; - } - if (ImGui.button("=")) { + if (ImGui.button("=", buttonSize, buttonSize)) { if (value.isEmpty()) { return; } int v2 = Integer.parseInt(value); if (valueArg.isEmpty()) { - valueLoc = baseNumber.BȍőnPrintNumber10(v2, 9999999);; + valueLoc = baseNumber.BȍőnPrintNumber10(v2, 9999999); + return; } int v1 = Integer.parseInt(valueArg); @@ -173,8 +191,9 @@ public class CalculatorDeskApp extends AbstractDeskApp implements DeskAppRendere default: break; } - value = "" + result; - valueLoc = baseNumber.BȍőnPrintNumber10(result, 9999999);; + valueNum = result; + value = "" + valueNum; + valueLoc = baseNumber.BȍőnPrintNumber10(valueNum, 9999999); } } } diff --git a/gdxapp4d-app-calculator/src/main/resources/love/distributedrebirth/gdxapp4d/app/calculator/Main.properties b/gdxapp4d-app-calculator/src/main/resources/love/distributedrebirth/gdxapp4d/app/calculator/Messages.properties similarity index 100% rename from gdxapp4d-app-calculator/src/main/resources/love/distributedrebirth/gdxapp4d/app/calculator/Main.properties rename to gdxapp4d-app-calculator/src/main/resources/love/distributedrebirth/gdxapp4d/app/calculator/Messages.properties diff --git a/gdxapp4d-app-calculator/src/main/resources/love/distributedrebirth/gdxapp4d/app/calculator/Main_hiero.properties b/gdxapp4d-app-calculator/src/main/resources/love/distributedrebirth/gdxapp4d/app/calculator/Messages_hiero.properties similarity index 100% rename from gdxapp4d-app-calculator/src/main/resources/love/distributedrebirth/gdxapp4d/app/calculator/Main_hiero.properties rename to gdxapp4d-app-calculator/src/main/resources/love/distributedrebirth/gdxapp4d/app/calculator/Messages_hiero.properties