Advertisement
WarPie90

Rafiki Player Manager [Simba 1.2RC]

Jan 17th, 2018
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 28.99 KB | None | 0 0
  1. (*
  2. Rafiki Player Manager
  3. =====================
  4.  
  5. The Rafiki file stores the functions related to the Rafiki Player Manager. This
  6. file is undocumented because scripters do not need to use any methods directly.
  7.  
  8. The source for this file can be found `here <https://github.com/SRL/SRL-6/blob/master/lib/misc/rafiki.simba>`_.
  9.  
  10. *)
  11. const
  12.   RAFIKI_VERSION = '2.00';
  13.  
  14. type
  15.   THoverButton = packed record
  16.     img1, img2: TImage;
  17.  end;
  18.  
  19. type
  20.   TArmy = packed record
  21.     name: string;
  22.     encrpyted: boolean;
  23.     players: array of TPlayer;
  24.  end;
  25.  
  26. type
  27.   TRafikiForm = packed record
  28.     frm: TForm;
  29.     playerList: TListBox;
  30.     labelPlayerCount: TLabel;
  31.     mainMenu: TMainMenu;
  32.     fileMenu, encyrptionMenu, helpMenu: TMenuItem;
  33.     btnAddPlayer, btnDeletePlayer: THoverButton;
  34.     playerEdits: array [0..3] of TEdit;
  35.     newLabel: TLabel;
  36.     playerCheckBoxMembers: TCheckBox;
  37.     btnSave, btnSavePlayer: TButton;
  38.     groupBoxes: array [0..1] of TGroupBox;
  39.     editArmyName: TEdit;
  40.     playerCheckBox: TCheckBox;
  41.     saveButtons: array [0..1] of TButton;
  42.     fileMenu_Items: array [0..2] of TMenuItem;
  43.     encyrptionMenu_Item: TMenuItem;
  44.     memo_DebugBox: TListBox;
  45.   end;
  46.  
  47. type
  48.   TOpenArmyForm = packed record
  49.     frm: TForm;
  50.     comboBox: TComboBox;
  51.     newLabel: TLabel;
  52.     btnLoad: TButton;
  53.     timer: TTimer;
  54.     selectedArmy: string;
  55.  end;
  56.  
  57.  
  58. var
  59.   openArmyForm: TOpenArmyForm;
  60.   rafikiForm: TRafikiForm;
  61.   army: TArmy;
  62.   loadedBitmaps: array of TBitmap;
  63.  
  64. // nice little trick to writeln to simba's debug box. :)
  65. procedure _writeln(); override; begin end;
  66. procedure _write(s: string); override;
  67. begin
  68.   if (assigned(rafikiForm.frm)) then
  69.   begin
  70.     rafikiForm.memo_DebugBox.getItems().append(s);
  71.     rafikiForm.memo_DebugBox.setItemIndex(rafikiForm.memo_DebugBox.getItems().getCount() - 1);  // trick to get listbox to scroll to bottom
  72.     rafikiForm.memo_DebugBox.setItemIndex(-1); // :)
  73.   end else
  74.     client.writeln(s);
  75. end;
  76.  
  77. // returns a TStringArray of all army names.
  78. function openArmyForm_GetArmys(): TStringArray;
  79. begin
  80.   with settings do
  81.   begin
  82.     setPrefix('Rafiki/');
  83.     listKeys('Armys/', result);
  84.   end;
  85.  
  86.   writeln('Armys found: '+toStr(result));
  87. end;
  88.  
  89. procedure openArmyForm_OnTimer(_, sender: TObject);
  90. begin
  91.   openArmyForm.btnLoad.setCaption('Load Army "'+openArmyForm.comboBox.getText()+'"');
  92. end;
  93.  
  94. procedure openArmyForm_OnClick(_, sender: TObject);
  95. begin
  96.   openArmyForm.selectedArmy := openArmyForm.comboBox.getCaption();
  97.   openArmyForm.frm.close();
  98. end;
  99.  
  100. procedure openArmyForm_Init();
  101. var
  102.   armys: TStringArray;
  103.   i: integer;
  104. begin
  105.   armys := openArmyForm_GetArmys();
  106.  
  107.   if (length(armys) < 1) then
  108.   begin
  109.     writeln('No saved armys; cannot open any!');
  110.     exit();
  111.   end;
  112.  
  113.   with openArmyForm do
  114.   begin
  115.     frm.init(nil);
  116.  
  117.     with frm do
  118.     begin
  119.       setCaption('Open Army');
  120.       setPosition(poScreenCenter);
  121.       setBorderStyle(bsDialog);
  122.       setWidth(240);
  123.       setHeight(75);
  124.     end;
  125.  
  126.     comboBox.init(frm);
  127.  
  128.     with comboBox do
  129.     begin
  130.       setParent(frm);
  131.       setBounds(48, 7, 180, 100);
  132.       setReadOnly(true);
  133.  
  134.       for i := 0 to high(armys) do
  135.         getItems().add(armys[i]);
  136.  
  137.       setCaption(armys[0]);
  138.     end;
  139.  
  140.     newLabel.init(frm);
  141.  
  142.     with newLabel do
  143.     begin
  144.       setParent(frm);
  145.       setLeft(10);
  146.       setTop(10);
  147.       setCaption('Army:');
  148.     end;
  149.  
  150.     btnLoad.init(frm);
  151.  
  152.     with btnLoad do
  153.     begin
  154.       setParent(frm);
  155.       setBounds(20, 40, 200, 25);
  156.       setCaption('Load Army');
  157.       setOnClick(@openArmyForm_OnClick);
  158.     end;
  159.  
  160.     timer.init(frm);
  161.  
  162.     with timer do
  163.     begin
  164.       setInterval(150);
  165.       setOnTimer(@openArmyForm_OnTimer);
  166.     end;
  167.  
  168.     frm.showModal();
  169.     frm.free();
  170.   end;
  171. end;
  172.  
  173. {$IFNDEF CODEINSIGHT} function loadArmy(const armyName: string): boolean; forward; {$ENDIF}
  174. procedure openArmyForm_Show(_,sender: TObject);
  175. begin
  176.   try
  177.     sync(@openArmyForm_Init);
  178.   except
  179.     writeln('ERROR: Unable to show OpenArmyForm');
  180.   finally
  181.     loadArmy(openArmyForm.selectedArmy);
  182.   end;
  183. end;
  184.  
  185. procedure updatePlayerCount();
  186. begin
  187.   rafikiForm.labelPlayerCount.setCaption('Players ('+intToStr(rafikiForm.playerList.getCount())+')');
  188. end;
  189.  
  190. (*
  191. *** Returns the postion of the player in the army based by searching for loginname.
  192. *)
  193. function getPlayerIndex(LoginName: string): integer;
  194. var
  195.   i: integer;
  196. begin
  197.   result := -1;
  198.  
  199.   for i := 0 to high(army.players) do
  200.     if (army.players[i].loginName = loginName) then
  201.       exit(i);
  202. end;
  203.  
  204. (*
  205. *** When we click on a item in the listbox, we edit the propities of the player.
  206. *)
  207. procedure editPlayer();
  208. var
  209.   index: integer;
  210. begin
  211.   if (rafikiForm.groupBoxes[0].getEnabled() = false) then
  212.     rafikiForm.groupBoxes[0].setEnabled(true);
  213.  
  214.   index := getPlayerIndex(rafikiForm.playerList.getSelectedText());
  215.  
  216.   if (index > -1) then
  217.   begin
  218.     writeln(format('Editing player "%s"', [rafikiForm.playerList.getSelectedText()]));
  219.     rafikiForm.playerEdits[0].setCaption(army.players[index].loginName);
  220.     rafikiForm.playerEdits[1].setCaption(army.players[index].password);
  221.     rafikiForm.playerEdits[2].setCaption(army.players[index].nickname);
  222.     rafikiForm.playerEdits[3].setCaption(army.players[index].bankpin);
  223.  
  224.     if (army.players[index].isMember) then
  225.       rafikiForm.playerCheckBoxMembers.setState(cbChecked)
  226.     else
  227.       rafikiForm.playerCheckBoxMembers.setState(cbUnChecked)
  228.   end else
  229.     writeln('Error editing player, could not get player index');
  230. end;
  231.  
  232. procedure disablePlayerBox();
  233. var
  234.   i: integer;
  235. begin
  236.   for i := 0 to high(rafikiForm.playerEdits) do // clear the captions
  237.       rafikiForm.playerEdits[i].clear();
  238.  
  239.   rafikiForm.playerCheckBoxMembers.setState(cbUnchecked); // reset the checkbox
  240.  
  241.   if (rafikiForm.groupBoxes[0].getEnabled() = true) then // disable groupbox
  242.     rafikiForm.groupBoxes[0].setEnabled(false);
  243.  
  244.   rafikiForm.playerList.setItemIndex(-1); // no need to keep it active. :)
  245. end;
  246.  
  247. (*
  248. *** Saves the current player based on the data in the player group box.
  249. *)
  250. procedure savePlayer();
  251. var
  252.   index: integer;
  253. begin
  254.   index := getPlayerIndex(rafikiForm.playerList.getItems().getStrings(rafikiForm.playerList.getItemIndex())); // get the player index in army
  255.  
  256.   if (index > -1) then
  257.   begin
  258.     rafikiForm.playerList.getItems().setStrings(rafikiForm.playerList.getItemIndex(), rafikiForm.playerEdits[0].getCaption()); // update loginname on list
  259.  
  260.     with army.players[index] do // update the player based on what is in the edits
  261.     begin
  262.       loginName := rafikiForm.playerEdits[0].getCaption();
  263.       password := rafikiForm.playerEdits[1].getCaption();
  264.       nickname := rafikiForm.playerEdits[2].getCaption();
  265.       bankPin := rafikiForm.playerEdits[3].getCaption();
  266.       isMember := rafikiForm.playerCheckBoxMembers.getState() = cbChecked;
  267.     end;
  268.  
  269.     disablePlayerBox();
  270.  
  271.     writeln('Saved player "'+army.players[index].loginName+'"');
  272.   end else
  273.     writeln('Unable to save player, Could not get player index!');
  274. end;
  275.  
  276. procedure newArmy(_,sender: TObject);
  277. begin
  278.   setLength(army.players, 0);
  279.  
  280.   rafikiForm.encyrptionMenu_Item.setChecked(false);
  281.   army.encrpyted := false;
  282.   army.name := 'default';
  283.  
  284.   with rafikiForm do
  285.   begin
  286.     playerList.clear();
  287.     editArmyName.setCaption('default');
  288.     updatePlayerCount();
  289.   end;
  290.  
  291.   disablePlayerBox();
  292.  
  293.   writeln('New army created');
  294. end;
  295.  
  296. // deletes the current loaded army
  297. procedure deleteArmy(_,sender: TObject);
  298.  
  299.   // can't use the native version
  300.   procedure newArmy();
  301.   begin
  302.     setLength(army.players, 0);
  303.  
  304.     army.encrpyted := false;
  305.     army.name := 'default';
  306.  
  307.     with rafikiForm do
  308.     begin
  309.       playerList.clear();
  310.       editArmyName.setCaption('default');
  311.       updatePlayerCount();
  312.     end;
  313.  
  314.     disablePlayerBox();
  315.  
  316.     writeln('New army created');
  317.   end;
  318.  
  319. var
  320.   armyName: string;
  321. begin
  322.   armyName := rafikiForm.editArmyName.getCaption();
  323.  
  324.   with settings do
  325.   begin
  326.     setPrefix('Rafiki/Armys/');
  327.  
  328.     if (isDirectory(armyName)) then
  329.       if (deleteKey(armyName)) then
  330.       begin
  331.         writeln('Succesfully deleted army "'+armyName+'"');
  332.  
  333.         if (getKeyValue('Recent_Army') = armyName) then // case the deleted army, is the default
  334.           setKeyValue('Recent_Army', '');
  335.  
  336.         with rafikiForm do
  337.         begin
  338.           playerList.clear();
  339.           editArmyName.clear();
  340.         end;
  341.  
  342.         newArmy();
  343.       end;
  344.   end;
  345. end;
  346.  
  347. procedure deletePlayer();
  348.  
  349.   procedure deleteIndex(var arr: array of TPlayer; const index : Integer);
  350.   var
  351.     I: Integer;
  352.   begin
  353.     for I := index to high(arr) -1 do
  354.       arr[I] := arr[I+1];
  355.  
  356.     setLength(arr, length(arr) - 1);
  357.   end;
  358.  
  359. var
  360.   index, i: Integer;
  361. begin
  362.   index := getPlayerIndex(rafikiForm.playerList.getItems().getStrings(rafikiForm.playerList.getItemIndex()));
  363.  
  364.   if (index > -1) then
  365.   begin
  366.     deleteIndex(army.players, index);
  367.     rafikiForm.playerlist.getItems().delete(rafikiForm.playerList.getItemIndex());
  368.     disablePlayerBox();
  369.     updatePlayerCount();
  370.   end;
  371. end;
  372.  
  373. (*
  374. *** Adds a new player to the army.
  375. *)
  376. procedure addPlayer();
  377. var
  378.   len: integer;
  379. begin
  380.   len := length(army.players);
  381.   setLength(army.players, len + 1);
  382.  
  383.   with army.players[len] do
  384.   begin
  385.     loginName := 'New Player';
  386.     password := '';
  387.     nickname := '';
  388.     isMember := false;
  389.   end;
  390.  
  391.   rafikiForm.playerList.getItems().insert(0, 'New Player');
  392.   rafikiForm.playerList.setItemIndex(0); // we insert item to the top, so we need to set the selected item index at 0
  393.   updatePlayerCount();
  394.   editPlayer();
  395. end;
  396.  
  397. // converts the army into a single string
  398. function armyToString(): string;
  399.  
  400.   procedure appendString(var toAppend: string; const s: string);
  401.   begin
  402.     insert(s, toAppend, length(toAppend) + 1);
  403.   end;
  404.  
  405. var
  406.   i, h: integer;
  407.   str, p: string;
  408. begin
  409.   h := high(army.players);
  410.   str := '';
  411.  
  412.   for i := 0 to h do
  413.     with (army.players[i]) do
  414.     begin
  415.       appendString(str, '<player>');
  416.       appendString(str, '<loginName>' + loginName + '</loginName>');
  417.       appendString(str, '<password>' + password + '</password>');
  418.       appendString(str, '<nickName>' + nickName + '</nickName>');
  419.       appendString(str, '<bankPin>' + bankPin + '</bankPin>');
  420.       appendString(str, '<isMember>' + boolToStr(isMember) + '</isMember>');
  421.       appendString(str, '</player>');
  422.     end;
  423.  
  424.   if (army.encrpyted) then
  425.   begin
  426.     writeln('Army is encrpyted, we need the password to encrpyt with with');
  427.  
  428.     if (InputQuery('Rafiki Player Manager', 'Please enter the password you want to encrpyt your army with:', p)) then
  429.       rc2_encrypt(p, htSHA512, str)
  430.     else
  431.       writeln('Password was canceled, not using encrpytion!');
  432.   end;
  433.  
  434.   result := base64Encode(compressString(str));
  435.   writeln(format('Converted army into a string of %d', [length(result)]));
  436. end;
  437.  
  438. // saves the current army
  439. procedure saveArmy();
  440. begin
  441.   army.name := rafikiForm.editArmyName.getCaption();
  442.   army.name := Replace(Lowercase(Army.Name), ' ', '_', [rfReplaceAll]);
  443.  
  444.   if (length(army.players) > 0) then
  445.   begin
  446.     with settings do
  447.     begin
  448.       setPrefix('Rafiki/');
  449.       setKeyValue('Recent_Army', army.name); // update last saved army to be loaded by default
  450.  
  451.       setPrefix('Rafiki/Armys/'+army.name+'/'); // add army section
  452.       setKeyValue('Encrpyted', boolToStr(army.encrpyted)); // added encrpytion boolean
  453.       setKeyValue('Player_Data', armyToString()); // finally add player data
  454.  
  455.       if (army.encrpyted) then
  456.         rafikiForm.encyrptionMenu_Item.setChecked(army.encrpyted);
  457.     end;
  458.  
  459.     writeln('Succesfully saved army "'+army.name+'"');
  460.   end else
  461.     writeln('Unable to save army - no players to save!');
  462. end;
  463.  
  464. // fills the form from getting the army data linked to 'armyName'):
  465. function loadArmy(const armyName: string): boolean;
  466. var
  467.   armyData, src: string;
  468.   players: TStringArray;
  469.   i: integer;
  470.   s: string := settings.getPrefix();
  471. begin
  472.   setLength(players, 0); // clear
  473.  
  474.   if (not Raf_FindArmy(armyName)) then
  475.   begin
  476.     printf('Army "%s" doesn''t exist', [armyName]);
  477.     print('Rafiki_GetPlayersFromArmy(): result = false', TDebug.FOOTER);
  478.     exit();
  479.   end;
  480.  
  481.   if (Raf_GetPlayers(armyName, army.players)) then
  482.   begin
  483.     settings.setPrefix('Rafiki/Armys/'+armyName+'/');
  484.     army.encrpyted := strToBoolDef(settings.getKeyValue('Encrpyted'), false);
  485.     rafikiForm.encyrptionMenu_Item.setChecked(army.encrpyted); // to-do fix me? :s.
  486.     settings.setPrefix(s);
  487.  
  488.     rafikiForm.playerList.clear();
  489.  
  490.     for i := 0 to high(army.players) do
  491.       rafikiForm.playerList.getItems().add(army.players[i].loginName);
  492.  
  493.     rafikiForm.editArmyName.setCaption(armyName);
  494.     updatePlayerCount();
  495.     writeln(format('Succesfully loaded army "%s"', [armyName]));
  496.   end else begin
  497.     writeln('ERROR: Failed to decrypt army - Wrong password, will create a new army');
  498.     rafikiForm.fileMenu_Items[0].click(); // new army
  499.     exit();
  500.   end;
  501. end;
  502.  
  503. procedure onClick(_,sender: TObject);
  504. var
  505.   index: integer;
  506. begin
  507.   with rafikiForm do
  508.   begin
  509.     case (sender) of
  510.       playerList:
  511.         if (playerList.getItemIndex() > -1) then
  512.           editPlayer();
  513.  
  514.       btnDeletePlayer.img2:
  515.         if (playerList.getItemIndex() > -1) then
  516.           deletePlayer();
  517.  
  518.       btnAddPlayer.img2:
  519.         addPlayer();
  520.  
  521.       saveButtons[0]: savePlayer();
  522.       saveButtons[1]: saveArmy();
  523.     end;
  524.   end
  525. end;
  526.  
  527. procedure onHoverButton(_,Sender: TObject);
  528. begin
  529.   with rafikiForm do
  530.   case sender of
  531.     btnAddPlayer.img1:
  532.       btnaddPlayer.switch(true);
  533.  
  534.     btnAddPlayer.img2:
  535.       btnaddPlayer.switch(false);
  536.  
  537.     btnDeletePlayer.img1:
  538.       btnDeletePlayer.switch(true);
  539.  
  540.     btnDeletePlayer.img2:
  541.       btnDeletePlayer.switch(false);
  542.   end;
  543. end;
  544.  
  545. procedure onShow(_,Sender: TObject);
  546. begin
  547.   rafikiForm.memo_DebugBox.setItemIndex(rafikiForm.memo_DebugBox.getItems().getCount() - 1);  // trick to get listbox to scroll to bottom
  548.   rafikiForm.memo_DebugBox.setItemIndex(-1); // :)
  549. end;
  550.  
  551. procedure THoverButton.add(parent: TWinControl; bmp1, bmp2: TBitmap; bounds: TBox; hint: string);
  552. begin
  553.   with rafikiForm do
  554.   begin
  555.   self.img1.init(parent);
  556.   self.img1.setParent(parent);
  557.   self.img1.setBounds(bounds.x1, bounds.y1, bounds.x2, bounds.y2);
  558.   self.img1.getPicture().setBitmap(bmp1);
  559.   self.img1.setOnMouseEnter(@onHoverButton);
  560.  
  561.   self.img2.init(parent);
  562.   self.img2.setParent(parent);
  563.   self.img2.setBounds(bounds.x1, bounds.y1, bounds.x2, bounds.y2);
  564.   self.img2.getPicture().setBitmap(bmp2);
  565.   self.img2.setOnMouseLeave(@onHoverButton);
  566.   self.img2.setOnClick(@onClick);
  567.   self.img2.hide();
  568.   self.img2.setHint(hint);
  569.   self.img2.setShowHint(true);
  570.   end;
  571. end;
  572.  
  573. procedure THoverButton.switch(a: boolean);
  574. begin
  575.   if (a) then
  576.   begin
  577.     self.img1.hide();
  578.     self.img2.show();
  579.   end else begin
  580.     self.img2.hide();
  581.     self.img1.show();
  582.   end;
  583. end;
  584.  
  585. // getBitmap: Returns a TBitmap of the desired image.
  586. function getBitmap(name: string): TBitmap;
  587. begin
  588.   result.init();
  589.   insert(result, loadedBitmaps);
  590.  
  591.   case name of
  592.     'plus': result.loadFromString(12, 12, 16777215, 'F0F0F0F0F0F0F0F0F0299114299114299114299114299114F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F029BA1437EA0237DA0237B702299114175B0BF0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F029911437EA0237DA0237DA02299114175B0BF0F0F0F0F0F0F0F0F029911429911429911429911437DA0237DA0237DA02299114299114299114299114F0F0F029BA1437EA0237DA0237DA0237DA0237DA0237DA0237DA0237B70237B702299114175B0B29BA1478FD4D37EA0237DA0237DA0237DA0237DA0237DA0237DA0237DA02299114175B0B29BA1478FD4D78FD4D37EA0237DA0237DA0237DA0237DA0237DA0237DA02299114175B0B29BA1429BA1429BA1429BA1478FD4D37DA0237DA02299114299114299114299114175B0BF0F0F0175B0B175B0B29BA1478FD4D37EA0237DA02299114175B0B175B0B175B0B175B0BF0F0F0F0F0F0F0F0F029BA1478FD4D78FD4D37DA02299114175B0BF0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F029BA1429BA1429BA1429BA14299114175B0BF0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0175B0B175B0B175B0B175B0B175B0BF0F0F0F0F0F0F0F0F0');
  593.     'plus_hover': result.loadFromString(12, 12, 16777215, 'F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F029911429BA1429BA1429BA1429BA14F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F029911437DA0278FD4D78FD4D29BA14F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F029911437DA0237EA0278FD4D29BA14F0F0F0F0F0F0F0F0F0F0F0F029911429911429911429911437DA0237DA0278FD4D29BA1429BA1429BA1429BA14F0F0F029911437DA0237DA0237DA0237DA0237DA0237DA0237EA0278FD4D78FD4D29BA14F0F0F029911437DA0237DA0237DA0237DA0237DA0237DA0237DA0237EA0278FD4D29BA14F0F0F029911437B70237B70237DA0237DA0237DA0237DA0237DA0237DA0237EA0229BA14F0F0F029911429911429911429911437DA0237DA0237DA02299114299114299114299114F0F0F0F0F0F0F0F0F0F0F0F029911437DA0237DA0237EA02299114F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F029911437B70237DA0237EA0229BA14F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0299114299114299114299114299114F0F0F0F0F0F0F0F0F0');
  594.  
  595.     'del': result.loadFromString(11, 11, 16777215, '0502C0050285050285ABB4B4F0F0F0F0F0F0F0F0F0050285050285050285ABB4B40502C00502FF0502FF050285ABB4B4F0F0F00502850502FF0502FF050285ABB4B40502C01A5BFF0502FF0502FF0502850502850502FF0502FF0502FF050285ABB4B4F0F0F00502C00502FF0502FF0502FF0502FF0502FF0502FF050285ABB4B4F0F0F0F0F0F0F0F0F00502C01A5BFF0502FF0502FF0502FF050285ABB4B4F0F0F0F0F0F0F0F0F0F0F0F00502C01A5BFF0502FF0502FF0502FF050285ABB4B4F0F0F0F0F0F0F0F0F00502C01A5BFF0502FF1A5BFF1A5BFF0502FF0502FF050285ABB4B4F0F0F00502C01A5BFF0502FF0502FF0502850502C01A5BFF0502FF0502FF050285ABB4B40502C01A5BFF0502FF050285ABB4B4F0F0F00502C01A5BFF0502FF050285ABB4B40502C00502C0050285ABB4B4F0F0F0F0F0F0F0F0F00502C0050285050285ABB4B4F0F0F0ABB4B4ABB4B4ABB4B4F0F0F0F0F0F0F0F0F0F0F0F0ABB4B4ABB4B4ABB4B4');
  596.     'del_hover': result.loadFromString(11, 11, 16777215, 'F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F00502850502850502C0F0F0F0F0F0F0F0F0F0F0F0F00502850502C00502C0F0F0F00502850502FF1A5BFF0502C0F0F0F0F0F0F00502850502FF1A5BFF0502C0F0F0F00502850502FF0502FF1A5BFF0502C00502850502FF0502FF1A5BFF0502C0F0F0F0F0F0F00502850502FF0502FF1A5BFF1A5BFF0502FF1A5BFF0502C0F0F0F0F0F0F0F0F0F0F0F0F00502850502FF0502FF0502FF1A5BFF0502C0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F00502850502FF0502FF0502FF1A5BFF0502C0F0F0F0F0F0F0F0F0F0F0F0F00502850502FF0502FF0502FF0502FF0502FF0502FF0502C0F0F0F0F0F0F00502850502FF0502FF0502FF0502850502850502FF0502FF1A5BFF0502C0F0F0F00502850502FF0502FF050285F0F0F0F0F0F00502850502FF0502FF0502C0F0F0F0050285050285050285F0F0F0F0F0F0F0F0F0F0F0F00502850502850502C0');
  597.  
  598.     'open': result.loadFromString(16, 16, 16777215, 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF59C2E03CB5DB41B4DC40AEDC39ADDB3BA8DB3BA3DB3C9DDB3B97DB3690DA529CDFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF61C3E2FDFEFEF7FCFEF1FAFDE8F6FBFEFFFFF6FCFEF2FAFDEFFAFEDCF0FA348CD9FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF63C4E3FEFFFF8EE4F894DEF570BCE7F8FDFF94E5F894E6F893E5F898E1F6348BD9FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF63C4E3FEFEFF91DEF593DCF455AAE2F6FDFF93E5F892E5F88FE4F895E0F6348CD9FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF63C4E3FDFEFF9FE0F564BCE94DA5E0F5FCFF93E5F890E5F889E3F892DFF6348CD9FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF62C4E3FEFFFFACE1F63594DA91C9EBF3FCFE91E5F88BE3F882E1F78EDEF5348CD9EAC39DE5BE96E4BB93E4BB92E4BB92E4BB91E4BA91CA84523594DAFAF3EF9AE4F493DBE986E2F77ADFF789DCF5348CD9E6BF96FFFFFEFEF5EDFEF6F0FEF7F1FFF7F2FFF7F0FFF7F13594DAFDFEFD9AE6F793D7E37FE1F771DEF685DAF4348CD9E4BB92FDF3E9FCDEC5FCE2CDFCE5D2FEE7D5FFE7D5FFE9D93594DAFFFDFC9BE6F693D2DC77DEF667DBF580D9F4348CD9E4BB92FDF3EAFBE0C7FCE3CDFCE4D1FEE7D5FDE7D6FFEADB3594DAFFFDFC9DE5F590CED76CDCF65BD8F47AD7F3348CD9D3A472FCF2E8F9DCC2FADFC8FBE2CCFDE5D1FDE6D4FFE9D93594DAFEFDFC9EE5F58CC8CF5ED9F44DD4F374D5F3348CD9D2A172FAEFE3F5D3B4F7D9BCF9DDC4FAE0CAFCE4D0FFE7D73594DAFEFCFB9FE5F486C1C64FD5F340D1F270D3F2348BD9D3A576FAF2E7FEF9F3F5E9DDF6D7BBF9DEC4FBE3CBFFE5D23594DAFEFEFDDAF3F8C9D8D6CCF2FBCAF2FBC2EAF8348CD9E2BDA2EABB88FAE2C4FAF3EBF3D1AFF7D9BCFADCC2FFE2CB3594DA3594DA3594DA3594DA3594DA3594DA3594DA529CDFFCFAF8DDA988ECC193FBF8F3FAEFE4FDF2E7FEF3E8FFF7F1FBF6EFEFF2E8FDF4EECA8155FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBF8F6DCB496CA8354CC8759CC8758CC8657CB8556CC8356CE8156CB8358CD865CFFFFFFFFFFFFFFFFFFFFFFFF');
  599.     'delete': result.loadFromString(16, 16, 16777215, 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFEFFB9B9E1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB9B9F0FEFEFFFFFFFFFFFFFFFFFFFFFEFEFF6969BC0000938787CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8787E20000C86969E2FEFEFFFFFFFFFFFFFFB9B9DE00008D0000930000998787D2FFFFFFFFFFFFFFFFFFFFFFFF8787E00000C30000C80000CEB9B9F3FFFFFFFFFFFFFFFFFF8787CA00009300009900009F8787D5FFFFFFFFFFFF8787DD0000BD0000C30000C98787E8FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8787CD00009900009F0000A58787D78787DA0000B70000BD0000C38787E6FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8787CF00009F0000A50000AB0000B10000B70000BD8787E3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8787D20000A50000AB0000B10000B78787E0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8787D20000A60000AB0000B10000B78787E0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8787CF0000A00000A60000AC0000B10000B70000BD8787E3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8787CD00009A0000A00000A68787D88787DB0000B70000BD0000C38787E6FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8787CA00009400009A0000A08787D5FFFFFFFFFFFF8787DD0000BD0000C30000C98787E8FFFFFFFFFFFFFFFFFFB9B9DE00008E00009400009A8787D2FFFFFFFFFFFFFFFFFFFFFFFF8787E00000C30000C90000CFB9B9F3FFFFFFFFFFFFFEFEFF6969BD0000948787CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8787E30000C96969E3FEFEFFFFFFFFFFFFFFFFFFFFFEFEFFB9B9E2FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB9B9F0FEFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF');
  600.     'new': result.loadFromString(16, 16, 16777215, 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE8CEB9D2A274CA925AC88D52C88D51C88D51C88C50C88C4FC8884DC7864BC78448C68046C37C42C27740C57C4DE2C0AAD7AA7CF8F3EDFAF6F2F9F5F1F9F5F1F9F4F0F9F4EFF9F4EDF9F3ECF8F2EBF8F1E8F7F0E6F7EDE3F5EBDFF8F2EBCC8D66CC945BF8F4EEFAE0C7FCE3CDFCE3CFFCE6D3FEE7D7FEE8D8FEE8D6FEE7D6FEE5D5F8B455FDC26EFDBF68F7ECDFC07140CA9055F8F4EDFBE1C9FBE3CEFBE4D0FCE6D4FDE7D6FEE8D8FEE8D7FDE7D6FDE5D3F7B456FFD8A0FCBD67F6EBDEBC6B36CA9055F8F3EDFBE2C9FBE3CDFCE4CFFDE7D3FDE7D5FEE8D7FDE7D6FDE7D6FDE5D3F7B554FFD79EFBBE65F6EADEBC6B36CA9055F8F3EDFBE0C8FBE2CBFCE3CDFCE4D1FDE6D4FEE7D6FDE7D6FDE7D6FCE5D3F8B453FFD69BFCBE64F6EADCBC6B36CA9155F8F3EDF9DFC5F9E0C8FAE1CAFBE3CDFCE6D2FDE5D3FDE7D5FDE6D5FCE5D3F8B253FFD798FCBE64F6EADCBC6A36CB9055F8F2ECF8DBC1F8DCC2F9DDC4FAE0C8FBE1CCFCE4D1FDE5D3FDE5D3FCE4D1F7B352FFD696FCBD62FAF3EBBC6A36C98F55F7F2ECF4D6B8F5D6BAF6D9BCF8DCC2FADFC7FBE1CCFBE4D0FCE4D1FCE2CEF7B352FFD695FBBD63FAF3EBBB6A35CF9D69F2E6D7FFFBF8FDFBF8F4E9DFF5D6BBF8DCC2FAE0C7FBE3CCFCE2CDFCE2CCF7B251FFD594FBBC61FAF2EABB6A35DDB190E2B27DF6D8B4FCE6CDF7F2ECF3D4B5F6DABDF9DDC3FADFC7FBE1CBFBE0C9F7B24FFFD493FCBE60FCF7F3BB6935FDFBFADC986BE1B07DFAE5C9FBF7F3F1D2B3F6D8BBF8DCC2FADFC6FBE1C9FBE1C8F7B24FFBBE65FCBC62FCF8F4BD6E3BFFFFFFFDFBFADC9669E2B684F5EFE9F8F4F0FAF4EFFAF4EDFAF2EAFBF7F2FDFAF7FCF9F5FBF7F4FDFBF8FEFEFDCA8B63FFFFFFFFFFFFFDFBFAD5A884C38048C6864CC8874CC8864BC88448C78045C37A41C1743CBD6C37BC6B37C37A4DE3C2AEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF');
  601.   end;
  602. end;
  603.  
  604. // toggleEncyption: Called when encrpytion is clicked.
  605. procedure toggleEncyption(_, sender: TObject);
  606. begin
  607.   army.encrpyted := (not army.encrpyted);
  608.   rafikiForm.encyrptionMenu_Item.setChecked(army.encrpyted);
  609.  
  610.   writeln(Format('Encrpytion has been toggled! [%s]', [lowercase(boolToStr(army.encrpyted))]));
  611.  
  612.   if (army.encrpyted) then
  613.     writeln('** You will be asked for your encrpytion password when you save your army');
  614. end;
  615.  
  616. // loadFormSettings: Called to load settings into the forms (previous army. etc).
  617. procedure loadFormSettings();
  618. var
  619.   armyName: string;
  620. begin
  621.   armyName := settings.getKeyValueDef('Recent_Army', '');
  622.  
  623.   if (armyName <> '') then
  624.     loadArmy(armyName)
  625.   else
  626.     writeln('No previously loaded army to load!');
  627.  
  628.   rafikiForm.encyrptionMenu_Item.setChecked(false);
  629. end;
  630.  
  631. // initForm: initializes the form.
  632. procedure initForm();
  633. var
  634.   i: integer;
  635.   strings: TStringArray;
  636.   boxes: TBoxArray;
  637. begin
  638.   with rafikiForm do
  639.   begin
  640.     frm.init(nil);
  641.  
  642.     with frm do
  643.     begin
  644.       setCaption('Rafiki Player Manager - Version ' + RAFIKI_VERSION);
  645.       setPosition(poScreenCenter);
  646.       setBorderStyle(bsSingle);
  647.       setWidth(500);
  648.       setHeight(383);
  649.       setOnShow(@onShow);
  650.     end;
  651.  
  652.     playerList.init(frm);
  653.  
  654.     with playerList do
  655.     begin
  656.       setParent(frm);
  657.       setBounds(10, 30, 260, 200);
  658.       setOnClick(@onClick);
  659.     end;
  660.  
  661.     labelPlayerCount.init(frm);
  662.  
  663.     with labelPlayerCount do
  664.     begin
  665.       setParent(frm);
  666.       setTop(10);
  667.       setLeft(11);
  668.       setCaption('Players (0)');
  669.     end;
  670.  
  671.     {Group Boxes}
  672.  
  673.     strings := ['Player Info', 'Army'];
  674.     boxes := [intToBox(285, 69, 200, 201), intToBox(285, 10, 200, 52)];
  675.  
  676.     for i := 0 to high(groupBoxes) do
  677.     begin
  678.       groupBoxes[i].init(frm);
  679.  
  680.       with groupBoxes[i] do
  681.       begin
  682.         setParent(frm);
  683.         setCaption(strings[i]);
  684.         setBounds(boxes[i].x1, boxes[i].y1, boxes[i].x2, boxes[i].y2);
  685.  
  686.         if (i = 0) then
  687.           setEnabled(false);
  688.       end;
  689.     end;
  690.  
  691.     {Player TEdits}
  692.  
  693.     for i := 0 to high(playerEdits) do
  694.     begin
  695.       playerEdits[i].init(groupBoxes[0]);
  696.  
  697.       with playerEdits[i] do
  698.       begin
  699.         setParent(groupBoxes[0]);
  700.         setLeft(70);
  701.         setTop(i * 28  + 6);
  702.         setWidth(120);
  703.  
  704.         if (i = 3) then
  705.         begin
  706.           setPasswordChar('*');
  707.           setMaxLength(4);
  708.         end else if (i = 1) then
  709.           setPasswordChar('*');
  710.       end;
  711.     end;
  712.  
  713.     {Player Members CheckBox}
  714.  
  715.     playerCheckBoxMembers.init(groupBoxes[0]);
  716.  
  717.     with playerCheckBoxMembers do
  718.     begin
  719.       setParent(groupBoxes[0]);
  720.       setLeft(70);
  721.       setTop(121);
  722.     end;
  723.  
  724.     {Misc Static Labels}
  725.  
  726.     strings := ['Username', 'Password', 'Nickname', 'Bank Pin', 'Members'];
  727.  
  728.     for i := 0 to high(strings) do
  729.     begin
  730.       newLabel.init(groupBoxes[0]);
  731.  
  732.       with newLabel do
  733.       begin
  734.         setParent(groupBoxes[0]);
  735.         setTop(i * 28 + 10);
  736.         setLeft(5);
  737.         setCaption(strings[i]);
  738.       end;
  739.     end;
  740.  
  741.     {Army name TEdit}
  742.  
  743.     editArmyName.init(groupBoxes[1]);
  744.  
  745.     with editArmyName do
  746.     begin
  747.       setParent(groupBoxes[1]);
  748.       setTop(4);
  749.       setLeft(80);
  750.       setWidth(110);
  751.       setCaption('default');
  752.     end;
  753.  
  754.     newLabel.init(groupBoxes[1]);
  755.  
  756.     with newLabel do
  757.     begin
  758.       setParent(groupBoxes[1]);
  759.       setCaption('Army Name');
  760.       setLeft(5);
  761.       setTop(6);
  762.     end;
  763.  
  764.     {Save buttons}
  765.  
  766.     strings := ['Save Player', 'Save Army'];
  767.  
  768.     setLength(boxes, 0);
  769.     boxes := [intToBox(7, 147, 180, 27), intToBox(10, 240, 260, 30)];
  770.  
  771.     for i := 0 to 1 do
  772.     begin
  773.       if (i = 0) then
  774.         saveButtons[i].init(groupBoxes[0])
  775.       else
  776.         saveButtons[i].init(frm)
  777.  
  778.       with saveButtons[i] do
  779.       begin
  780.         if (i = 0) then
  781.           setParent(groupBoxes[0])
  782.         else
  783.           setParent(frm);
  784.  
  785.         setBounds(boxes[i].x1, boxes[i].y1, boxes[i].x2, boxes[i].y2);
  786.         setCaption(strings[i]);
  787.         setOnClick(@onClick);
  788.       end;
  789.     end;
  790.  
  791.     btnAddPlayer.add(frm, getBitmap('plus'), getBitmap('plus_hover'), intToBox(236, 14, 15, 15), 'Add Player');
  792.     btnDeletePlayer.add(frm, getBitmap('del'), getBitmap('del_hover'), intTobox(252, 15, 15, 15), 'Delete Player');
  793.  
  794.     mainMenu.init(frm);
  795.  
  796.     {File menu}
  797.  
  798.     fileMenu := mainMenu.addMenu('File');
  799.     strings := ['New Army', 'Load Army', 'Delete Army'];
  800.  
  801.     for i := 0 to high(fileMenu_Items) do
  802.     begin
  803.       fileMenu_Items[i] := fileMenu.addMenu(strings[i]);
  804.  
  805.       case i of
  806.         0: fileMenu_Items[i].setBitmap(getBitmap('new'));
  807.         1: fileMenu_Items[i].setBitmap(getBitmap('open'));
  808.         2: fileMenu_Items[i].setBitmap(getBitmap('delete'));
  809.       end;
  810.  
  811.       case i of
  812.         0: fileMenu_Items[i].setOnClick(@newArmy);
  813.         1: fileMenu_Items[i].setOnClick(@openArmyForm_Show);
  814.         2: fileMenu_Items[i].setOnClick(@deleteArmy);
  815.       end;
  816.     end;
  817.  
  818.     {Encrpytion menu}
  819.  
  820.     encyrptionMenu := mainMenu.addMenu('Encryption');
  821.     encyrptionMenu_Item := encyrptionMenu.addMenu('Enable (Click to activate)');
  822.     encyrptionMenu_Item.setOnClick(@toggleEncyption);
  823.  
  824.     memo_DebugBox.init(frm);
  825.  
  826.     with memo_DebugBox do
  827.     begin
  828.       setParent(frm);
  829.       setBounds(10, 282, 478, 70);
  830.     end;
  831.  
  832.     writeln('Welcome to Rafiki player manager');
  833.     loadFormSettings();
  834.  
  835.     frm.showModal();
  836.     frm.free();
  837.   end;
  838. end;
  839.  
  840. procedure Rafiki_RunPlayerManager();
  841. var
  842.   i: byte;
  843.   s: string := settings.getPrefix();
  844. begin
  845.   clearDebug();
  846.   disableSRLLog := true;
  847.  
  848.   settings.setPrefix('Rafiki/');
  849.   writeln('Showing Rafiki player manager');
  850.  
  851.   try
  852.     sync(@initForm);
  853.   except
  854.     writeln('ERROR: Unable to show Rafiki player manager');
  855.   finally
  856.     for i := 0 to high(loadedBitmaps) do
  857.       loadedBitmaps[i].free();
  858.  
  859.     settings.setPrefix(s);
  860.   end;
  861. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement