Fixed calculator
This commit is contained in:
parent
0b2c42533b
commit
cf95e96345
|
@ -25,7 +25,7 @@ public class CalculatorComponent {
|
||||||
@Reference
|
@Reference
|
||||||
private VrGem4LocaleService localeService;
|
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;
|
private final DeskAppLauncher launcher;
|
||||||
|
|
||||||
public CalculatorComponent() {
|
public CalculatorComponent() {
|
||||||
|
|
|
@ -16,11 +16,13 @@ import love.distributedrebirth.unicode4d.BaseGlyphSet;
|
||||||
public class CalculatorDeskApp extends AbstractDeskApp implements DeskAppRenderer {
|
public class CalculatorDeskApp extends AbstractDeskApp implements DeskAppRenderer {
|
||||||
|
|
||||||
private ResourceBundle bundle;
|
private ResourceBundle bundle;
|
||||||
|
private int valueNum = 0;
|
||||||
private String value = "";
|
private String value = "";
|
||||||
private String valueLoc = "";
|
private String valueLoc = "";
|
||||||
private String valueArg = "";
|
private String valueArg = "";
|
||||||
private Operation operation = Operation.NONE;
|
private Operation operation = Operation.NONE;
|
||||||
private ImInt selectedNumberGlyph = new ImInt();
|
private ImInt selectedNumberGlyph = new ImInt();
|
||||||
|
private float buttonSize = 64f;
|
||||||
|
|
||||||
public CalculatorDeskApp(ResourceBundle bundle) {
|
public CalculatorDeskApp(ResourceBundle bundle) {
|
||||||
this.bundle = bundle;
|
this.bundle = bundle;
|
||||||
|
@ -52,107 +54,123 @@ public class CalculatorDeskApp extends AbstractDeskApp implements DeskAppRendere
|
||||||
}
|
}
|
||||||
String[] items = new String[bases.size()];
|
String[] items = new String[bases.size()];
|
||||||
items = bases.toArray(items);
|
items = bases.toArray(items);
|
||||||
ImGui.combo(getTxt("selectedNumberGlyph"), selectedNumberGlyph, items);
|
boolean changedLoc = ImGui.combo(getTxt("selectedNumberGlyph"), selectedNumberGlyph, items);
|
||||||
String selectedItem = items[selectedNumberGlyph.get()];
|
String selectedItem = items[selectedNumberGlyph.get()];
|
||||||
BaseGlyphSet baseNumber = BaseGlyphSet.valueOf(selectedItem);
|
BaseGlyphSet baseNumber = BaseGlyphSet.valueOf(selectedItem);
|
||||||
|
if (changedLoc) {
|
||||||
|
valueLoc = baseNumber.BȍőnPrintNumber10(valueNum, 9999999);
|
||||||
|
}
|
||||||
|
|
||||||
ImGui.text("Value:");
|
ImGui.text("Value:");
|
||||||
ImGui.sameLine();
|
ImGui.sameLine();
|
||||||
ImGui.text(valueLoc);
|
ImGui.text(valueLoc);
|
||||||
ImGui.separator();
|
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(7), buttonSize, buttonSize)) {
|
||||||
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))) {
|
|
||||||
value+="7";
|
value+="7";
|
||||||
|
valueNum = Integer.parseInt(value);
|
||||||
valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(7);
|
valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(7);
|
||||||
}
|
}
|
||||||
ImGui.sameLine();
|
ImGui.sameLine();
|
||||||
if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(8))) {
|
if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(8), buttonSize, buttonSize)) {
|
||||||
value+="8";
|
value+="8";
|
||||||
|
valueNum = Integer.parseInt(value);
|
||||||
valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(8);
|
valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(8);
|
||||||
}
|
}
|
||||||
ImGui.sameLine();
|
ImGui.sameLine();
|
||||||
if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(9))) {
|
if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(9), buttonSize, buttonSize)) {
|
||||||
value+="9";
|
value+="9";
|
||||||
|
valueNum = Integer.parseInt(value);
|
||||||
valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(9);
|
valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(9);
|
||||||
}
|
}
|
||||||
|
ImGui.sameLine();
|
||||||
|
if (ImGui.button("/", buttonSize, buttonSize)) {
|
||||||
|
valueArg=value;
|
||||||
|
value="";
|
||||||
|
valueLoc="";
|
||||||
|
operation = Operation.DIVIDE;
|
||||||
|
}
|
||||||
|
|
||||||
|
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("C")) {
|
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="";
|
value="";
|
||||||
valueLoc="";
|
valueLoc="";
|
||||||
valueArg="";
|
valueArg="";
|
||||||
operation = Operation.NONE;
|
operation = Operation.NONE;
|
||||||
}
|
}
|
||||||
if (ImGui.button("+")) {
|
ImGui.sameLine();
|
||||||
|
if (ImGui.button("+", buttonSize, buttonSize)) {
|
||||||
valueArg=value;
|
valueArg=value;
|
||||||
value="";
|
value="";
|
||||||
valueLoc="";
|
valueLoc="";
|
||||||
operation = Operation.PLUS;
|
operation = Operation.PLUS;
|
||||||
}
|
}
|
||||||
ImGui.sameLine();
|
ImGui.sameLine();
|
||||||
if (ImGui.button("-")) {
|
if (ImGui.button("=", buttonSize, buttonSize)) {
|
||||||
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 (value.isEmpty()) {
|
if (value.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int v2 = Integer.parseInt(value);
|
int v2 = Integer.parseInt(value);
|
||||||
if (valueArg.isEmpty()) {
|
if (valueArg.isEmpty()) {
|
||||||
valueLoc = baseNumber.BȍőnPrintNumber10(v2, 9999999);;
|
valueLoc = baseNumber.BȍőnPrintNumber10(v2, 9999999);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
int v1 = Integer.parseInt(valueArg);
|
int v1 = Integer.parseInt(valueArg);
|
||||||
|
|
||||||
|
@ -173,8 +191,9 @@ public class CalculatorDeskApp extends AbstractDeskApp implements DeskAppRendere
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
value = "" + result;
|
valueNum = result;
|
||||||
valueLoc = baseNumber.BȍőnPrintNumber10(result, 9999999);;
|
value = "" + valueNum;
|
||||||
|
valueLoc = baseNumber.BȍőnPrintNumber10(valueNum, 9999999);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue