Load.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #include "Load.h"
  2. #include <Array.h>
  3. #include <AsynchronCall.h>
  4. #include <File.h>
  5. #include <FileSystem.h>
  6. #include <GraphicsApi.h>
  7. #include <M3File.h>
  8. #include <Text.h>
  9. #include <Texture.h>
  10. #include "FactoryClient.h"
  11. #include "Globals.h"
  12. #include "Initialization.h"
  13. #include "ServerSelection.h"
  14. LoadMenu::LoadMenu(Screen* zScreen)
  15. : Menu(zScreen)
  16. {
  17. Point center = zScreen->getBackBufferSize() / 2;
  18. all = initProgressBar(
  19. center.x - 100, center.y - 65, 200, 30, ProgressBar::Style::normal);
  20. stageTitle = initTextField(center.x - 100,
  21. center.y - 30,
  22. zScreen->getBackBufferSize().x - center.x + 100,
  23. 15,
  24. TextField::Style::Text,
  25. "");
  26. stage = initProgressBar(
  27. center.x - 100, center.y - 15, 200, 30, ProgressBar::Style::normal);
  28. stage->removeStyle(ProgressBar::Style::Visible);
  29. stepTitle = initTextField(center.x - 100,
  30. center.y + 20,
  31. zScreen->getBackBufferSize().x - center.x + 100,
  32. 15,
  33. TextField::Style::Text,
  34. "");
  35. step = initProgressBar(
  36. center.x - 100, center.y + 35, 200, 30, ProgressBar::Style::normal);
  37. step->removeStyle(ProgressBar::Style::Visible);
  38. elements.add(step);
  39. elements.add(stepTitle);
  40. elements.add(stage);
  41. elements.add(stageTitle);
  42. elements.add(all);
  43. }
  44. void LoadMenu::stepProgress(int stepSize)
  45. {
  46. step->actionPlus(stepSize);
  47. }
  48. void LoadMenu::beginNextStep(const char* title, int nextStepSize)
  49. {
  50. stepTitle->setText(title);
  51. step->setActionCount(nextStepSize);
  52. step->reset();
  53. step->addStyle(ProgressBar::Style::Visible);
  54. }
  55. void LoadMenu::stageProgress(int stepSize)
  56. {
  57. stage->actionPlus(stepSize);
  58. step->removeStyle(ProgressBar::Style::Visible);
  59. }
  60. void LoadMenu::beginNextStage(const char* title, int nextStageSize)
  61. {
  62. stageTitle->setText(title);
  63. stage->setActionCount(nextStageSize);
  64. stage->reset();
  65. stage->addStyle(ProgressBar::Style::Visible);
  66. step->removeStyle(ProgressBar::Style::Visible);
  67. }
  68. void LoadMenu::allProgress(int stepSize)
  69. {
  70. all->actionPlus(stepSize);
  71. stage->removeStyle(ProgressBar::Style::Visible);
  72. step->removeStyle(ProgressBar::Style::Visible);
  73. }
  74. void LoadMenu::load(FactoryClient* client,
  75. Text name,
  76. Text secret,
  77. unsigned short port,
  78. std::function<void(int, Text)> onFinish)
  79. {
  80. all->setActionCount(9);
  81. all->reset();
  82. stageTitle->setText("");
  83. stepTitle->setText("");
  84. step->removeStyle(ProgressBar::Style::Visible);
  85. stage->removeStyle(ProgressBar::Style::Visible);
  86. new AsynchronCall(
  87. "Load Menu", [this, client, name, secret, port, onFinish]() {
  88. Text tmp = secret;
  89. int result = client->join(name, tmp, port);
  90. onFinish(result, tmp);
  91. });
  92. }
  93. Image* loadImage(Framework::Text path)
  94. {
  95. if (path.beginnsWith("itemType:"))
  96. {
  97. Text* typeIdName = path.getTeilText(9);
  98. for (int i = 0; i < itemTypeCount; i++)
  99. {
  100. if (itemTypes[i]->getName().isEqual(*typeIdName))
  101. {
  102. Image* img
  103. = dynamic_cast<Image*>(itemTypes[i]->zIcon()->getThis());
  104. typeIdName->release();
  105. return img;
  106. }
  107. }
  108. typeIdName->release();
  109. return 0;
  110. }
  111. else
  112. {
  113. LTDBFile file;
  114. file.setFile(
  115. path.getTeilText(0, path.positionOf("/", path.countOf("/") - 1)));
  116. file.readData(0);
  117. return file.load(0,
  118. path.getTeilText(path.positionOf("/", path.countOf("/") - 1) + 1));
  119. }
  120. }