Stage 1 of blocks gui rewrite

This commit is contained in:
UnknownShadow200 2017-05-27 13:15:22 +10:00
parent 5ee315b29b
commit 0dc366c44a
10 changed files with 971 additions and 825 deletions

View File

@ -147,7 +147,7 @@ namespace MCGalaxy.Gui.Eco {
}
private void comboBoxRank_SelectionChangeCommitted(object sender, EventArgs e) {
Economy.Ranks.MaxRank = Program.GetPermission(comboBoxRank, LevelPermission.AdvBuilder);
Economy.Ranks.MaxRank = GuiPerms.GetPermission(comboBoxRank, LevelPermission.AdvBuilder);
UpdateRanks();
}

56
GUI/GuiPerms.cs Normal file
View File

@ -0,0 +1,56 @@
/*
Copyright 2015 MCGalaxy
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace MCGalaxy.Gui {
internal static class GuiPerms {
internal static string[] RankNames;
internal static LevelPermission[] RankPerms;
internal static void UpdateRankNames() {
List<string> names = new List<string>(Group.GroupList.Count);
List<LevelPermission> perms = new List<LevelPermission>(Group.GroupList.Count);
foreach (Group group in Group.GroupList) {
names.Add(group.name);
perms.Add(group.Permission);
}
RankNames = names.ToArray();
RankPerms = perms.ToArray();
}
internal static LevelPermission GetPermission(ComboBox box, LevelPermission defPerm) {
Group grp = Group.Find(box.SelectedItem.ToString());
return grp == null ? defPerm : grp.Permission;
}
internal static void SetDefaultIndex(ComboBox box, LevelPermission perm) {
Group grp = Group.findPerm(perm);
if (grp == null) {
box.SelectedIndex = 1;
} else {
int idx = Array.IndexOf<string>(RankNames, grp.name);
box.SelectedIndex = idx >= 0 ? idx : 1;
}
}
}
}

View File

@ -16,7 +16,6 @@
permissions and limitations under the Licenses.
*/
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
@ -32,11 +31,6 @@ namespace MCGalaxy.Gui {
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
internal static LevelPermission GetPermission(ComboBox box, LevelPermission defPerm) {
Group grp = Group.Find(box.SelectedItem.ToString());
return grp == null ? defPerm : grp.Permission;
}
// NOTE: //Console.ReadLine() is ignored while Starter is set as Windows Application in properties. (At least on Windows)
static bool useConsole, useHighQualityGui, isWindows;

View File

@ -20,48 +20,98 @@ using MCGalaxy.Blocks;
namespace MCGalaxy.Gui {
public partial class PropertyWindow : Form {
bool blockSupressEvents = true;
ComboBox[] blockAllowBoxes, blockDisallowBoxes;
BlockPerms blockPerms;
void listBlocks_SelectedIndexChanged(object sender, EventArgs e) {
byte b = Block.Byte(listBlocks.SelectedItem.ToString());
BlockPerms bs = storedBlocks.Find(bS => bS.BlockID == b);
txtBlLowest.Text = (int)bs.MinRank + "";
bool foundOne = false;
txtBlDisallow.Text = "";
if (bs.Disallowed != null) {
foreach ( LevelPermission perm in bs.Disallowed ) {
foundOne = true;
txtBlDisallow.Text += "," + (int)perm;
byte b = Block.Byte(blk_list.SelectedItem.ToString());
blockPerms = storedBlocks.Find(bS => bS.BlockID == b);
BlockInitSpecificArrays();
blockSupressEvents = true;
GuiPerms.SetDefaultIndex(blk_cmbMin, blockPerms.MinRank);
BlockSetSpecificPerms(blockPerms.Allowed, blockAllowBoxes);
BlockSetSpecificPerms(blockPerms.Disallowed, blockDisallowBoxes);
blockSupressEvents = false;
}
void BlockInitSpecificArrays() {
if (blockAllowBoxes != null) return;
blockAllowBoxes = new ComboBox[] { blk_cmbAlw1, blk_cmbAlw2, blk_cmbAlw3 };
blockDisallowBoxes = new ComboBox[] { blk_cmbDis1, blk_cmbDis2, blk_cmbDis3 };
for (int i = 0; i < blockAllowBoxes.Length; i++) {
blockAllowBoxes[i].Items.Add("(add rank)");
blockDisallowBoxes[i].Items.Add("(add rank)");
}
}
void BlockSetSpecificPerms(List<LevelPermission> perms, ComboBox[] boxes) {
ComboBox box = null;
for (int i = 0; i < boxes.Length; i++) {
box = boxes[i];
// Hide the non-visible specific permissions
box.Text = "";
box.Enabled = false;
box.Visible = false;
// Show the non-visible specific permissions previously set
if (perms.Count > i) {
box.Visible = true;
box.Enabled = true;
GuiPerms.SetDefaultIndex(box, perms[i]);
}
}
if ( foundOne ) txtBlDisallow.Text = txtBlDisallow.Text.Remove(0, 1);
foundOne = false;
txtBlAllow.Text = "";
if (bs.Allowed != null) {
foreach ( LevelPermission perm in bs.Allowed ) {
foundOne = true;
txtBlAllow.Text += "," + (int)perm;
}
// Show (add rank) for the last item
if (perms.Count >= boxes.Length) return;
BlockSetAddRank(boxes[perms.Count]);
}
void BlockSetAddRank(ComboBox box) {
box.Visible = true;
box.Enabled = true;
box.SelectedIndex = box.Items.Count - 1;
}
void blk_cmbMin_SelectedIndexChanged(object sender, EventArgs e) {
int idx = blk_cmbMin.SelectedIndex;
if (idx == -1 || blockSupressEvents) return;
blockPerms.MinRank = GuiPerms.RankPerms[idx];
}
void blk_cmbSpecific_SelectedIndexChanged(object sender, EventArgs e) {
ComboBox box = (ComboBox)sender;
if (blockSupressEvents) return;
int idx = box.SelectedIndex;
if (idx == box.Items.Count - 1) return;
List<LevelPermission> perms = blockPerms.Allowed;
ComboBox[] boxes = blockAllowBoxes;
int boxIdx = Array.IndexOf<ComboBox>(boxes, box);
if (boxIdx == -1) {
perms = blockPerms.Disallowed;
boxes = blockDisallowBoxes;
boxIdx = Array.IndexOf<ComboBox>(boxes, box);
}
if (boxIdx < perms.Count) {
perms[boxIdx] = GuiPerms.RankPerms[idx];
} else {
perms.Add(GuiPerms.RankPerms[idx]);
}
// Activate next box
if (boxIdx < boxes.Length - 1 && !boxes[boxIdx + 1].Visible) {
BlockSetAddRank(boxes[boxIdx + 1]);
}
if ( foundOne ) txtBlAllow.Text = txtBlAllow.Text.Remove(0, 1);
}
void txtBlLowest_TextChanged(object sender, EventArgs e) {
fillLowest(ref txtBlLowest, ref storedBlocks[Block.Byte(listBlocks.SelectedItem.ToString())].MinRank);
}
void txtBlDisallow_TextChanged(object sender, EventArgs e) {
if (storedBlocks[listBlocks.SelectedIndex].Disallowed == null)
storedBlocks[listBlocks.SelectedIndex].Disallowed = new List<LevelPermission>();
fillAllowance(ref txtBlDisallow, ref storedBlocks[listBlocks.SelectedIndex].Disallowed);
}
void txtBlAllow_TextChanged(object sender, EventArgs e) {
if (storedBlocks[listBlocks.SelectedIndex].Allowed == null)
storedBlocks[listBlocks.SelectedIndex].Allowed = new List<LevelPermission>();
fillAllowance(ref txtBlAllow, ref storedBlocks[listBlocks.SelectedIndex].Allowed);
}
void btnBlHelp_Click(object sender, EventArgs e) {
getHelp(listBlocks.SelectedItem.ToString());
getHelp(blk_list.SelectedItem.ToString());
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -27,6 +27,7 @@ namespace MCGalaxy.Gui {
afk_txtTimer.Text = Server.afkminutes.ToString();
afk_txtKickTime.Text = Server.afkkick.ToString();
GuiPerms.SetDefaultIndex(afk_cmbKickPerm, Server.afkkickperm);
chkPhysicsRest.Checked = Server.physicsRestart;
txtRP.Text = Server.rpLimit.ToString();
@ -53,7 +54,7 @@ namespace MCGalaxy.Gui {
Server.afkminutes = int.Parse(afk_txtTimer.Text);
Server.afkkick = int.Parse(afk_txtKickTime.Text);
Server.afkkickperm = Program.GetPermission(afk_cmbKickPerm, LevelPermission.AdvBuilder);
Server.afkkickperm = GuiPerms.GetPermission(afk_cmbKickPerm, LevelPermission.AdvBuilder);
Server.physicsRestart = chkPhysicsRest.Checked;
Server.rpLimit = int.Parse(txtRP.Text);

View File

@ -21,9 +21,16 @@ namespace MCGalaxy.Gui {
public partial class PropertyWindow : Form {
void LoadRankProps() {
string defRank = Server.defaultRank.ToLower();
if (rank_cmbDefault.Items.IndexOf(defRank) != -1 )
rank_cmbDefault.SelectedIndex = rank_cmbDefault.Items.IndexOf(defRank);
GuiPerms.SetDefaultIndex(rank_cmbDefault, Group.standard.Permission);
GuiPerms.SetDefaultIndex(rank_cmbOsMap, Server.osPerbuildDefault);
LevelPermission adminChatRank =
CommandExtraPerms.MinPerm("adminchat", LevelPermission.Admin);
LevelPermission opChatRank =
CommandExtraPerms.MinPerm("opchat", LevelPermission.Operator);
GuiPerms.SetDefaultIndex(rank_cmbOpChat, opChatRank);
GuiPerms.SetDefaultIndex(rank_cmbAdminChat, adminChatRank);
rank_chkTpToHigherRanks.Checked = Server.higherranktp;
chkAdminsJoinSilent.Checked = Server.adminsjoinsilent;
}
@ -33,11 +40,11 @@ namespace MCGalaxy.Gui {
Server.higherranktp = rank_chkTpToHigherRanks.Checked;
Server.adminsjoinsilent = chkAdminsJoinSilent.Checked;
Server.osPerbuildDefault = Program.GetPermission(rank_cmbOsMap, LevelPermission.Nobody);
Server.osPerbuildDefault = GuiPerms.GetPermission(rank_cmbOsMap, LevelPermission.Nobody);
var perms = CommandExtraPerms.Find("opchat");
perms.MinRank = Program.GetPermission(rank_cmbOpChat, LevelPermission.Operator);
perms.MinRank = GuiPerms.GetPermission(rank_cmbOpChat, LevelPermission.Operator);
perms = CommandExtraPerms.Find("adminchat");
perms.MinRank = Program.GetPermission(rank_cmbAdminChat, LevelPermission.Admin);
perms.MinRank = GuiPerms.GetPermission(rank_cmbAdminChat, LevelPermission.Admin);
}

View File

@ -23,6 +23,8 @@ namespace MCGalaxy.Gui {
sec_cbLogNotes.Checked = Server.LogNotes;
sec_cbVerifyAdmins.Checked = Server.verifyadmins;
sec_cbWhitelist.Checked = Server.useWhitelist;
GuiPerms.SetDefaultIndex(sec_cmbVerifyRank, Server.verifyadminsrank);
sec_cmbVerifyRank.Enabled = Server.verifyadmins;
sec_cbChatAuto.Checked = Server.checkspam;
sec_numChatMsgs.Value = Server.spamcounter;
@ -47,7 +49,7 @@ namespace MCGalaxy.Gui {
void ApplySecurityProps() {
Server.LogNotes = sec_cbLogNotes.Checked;
Server.verifyadmins = sec_cbVerifyAdmins.Checked;
Server.verifyadminsrank = Program.GetPermission(sec_cmbVerifyRank, LevelPermission.Operator);
Server.verifyadminsrank = GuiPerms.GetPermission(sec_cmbVerifyRank, LevelPermission.Operator);
Server.useWhitelist = sec_cbWhitelist.Checked;
if (Server.useWhitelist && Server.whiteList == null)
Server.whiteList = PlayerList.Load("whitelist.txt");

View File

@ -40,47 +40,28 @@ namespace MCGalaxy.Gui {
chat_cmbSyntax.Items.AddRange(colors);
chat_cmbDesc.Items.AddRange(colors);
cmbColor.Items.AddRange(colors);
sec_cmbVerifyRank.Enabled = Server.verifyadmins;
ToggleIrcSettings(Server.irc);
ToggleMySQLSettings(Server.useMySQL);
ToggleChatSpamSettings(Server.checkspam);
ToggleCmdSpamSettings(Server.CmdSpamCheck);
ToggleBlocksSpamSettings(Server.BlockSpamCheck);
string opchatperm = "", adminchatperm = "";
string verifyadminsperm = "", afkkickrank = "", osmaprank = "";
LevelPermission adminChatRank =
CommandExtraPerms.MinPerm("adminchat", LevelPermission.Admin);
LevelPermission opChatRank =
CommandExtraPerms.MinPerm("opchat", LevelPermission.Operator);
foreach (Group grp in Group.GroupList) {
rank_cmbDefault.Items.Add(grp.name);
rank_cmbOpChat.Items.Add(grp.name);
rank_cmbAdminChat.Items.Add(grp.name);
sec_cmbVerifyRank.Items.Add(grp.name);
afk_cmbKickPerm.Items.Add(grp.name);
rank_cmbOsMap.Items.Add(grp.name);
if (grp.Permission == opChatRank)
opchatperm = grp.name;
if (grp.Permission == adminChatRank)
adminchatperm = grp.name;
if (grp.Permission == Server.verifyadminsrank)
verifyadminsperm = grp.name;
if (grp.Permission == Server.afkkickperm)
afkkickrank = grp.name;
if (grp.Permission == Server.osPerbuildDefault)
osmaprank = grp.name;
}
GuiPerms.UpdateRankNames();
rank_cmbDefault.Items.AddRange(GuiPerms.RankNames);
rank_cmbOpChat.Items.AddRange(GuiPerms.RankNames);
rank_cmbAdminChat.Items.AddRange(GuiPerms.RankNames);
rank_cmbOsMap.Items.AddRange(GuiPerms.RankNames);
sec_cmbVerifyRank.Items.AddRange(GuiPerms.RankNames);
afk_cmbKickPerm.Items.AddRange(GuiPerms.RankNames);
rank_cmbDefault.SelectedIndex = 1;
rank_cmbOpChat.SelectedIndex = ( opchatperm != String.Empty ? rank_cmbOpChat.Items.IndexOf(opchatperm) : 1 );
rank_cmbAdminChat.SelectedIndex = ( adminchatperm != String.Empty ? rank_cmbAdminChat.Items.IndexOf(adminchatperm) : 1 );
sec_cmbVerifyRank.SelectedIndex = ( verifyadminsperm != String.Empty ? sec_cmbVerifyRank.Items.IndexOf(verifyadminsperm) : 1 );
afk_cmbKickPerm.SelectedIndex = ( afkkickrank != String.Empty ? afk_cmbKickPerm.Items.IndexOf(afkkickrank) : 1 );
rank_cmbOsMap.SelectedIndex = ( osmaprank != String.Empty ? rank_cmbOsMap.Items.IndexOf(osmaprank) : 1 );
blk_cmbMin.Items.AddRange(GuiPerms.RankNames);
blk_cmbAlw1.Items.AddRange(GuiPerms.RankNames);
blk_cmbAlw2.Items.AddRange(GuiPerms.RankNames);
blk_cmbAlw3.Items.AddRange(GuiPerms.RankNames);
blk_cmbDis1.Items.AddRange(GuiPerms.RankNames);
blk_cmbDis2.Items.AddRange(GuiPerms.RankNames);
blk_cmbDis3.Items.AddRange(GuiPerms.RankNames);
//Load server stuff
LoadProp("properties/server.properties");
@ -145,7 +126,7 @@ namespace MCGalaxy.Gui {
txtcmdranks2.Text += " " + grp.name + " (" + (int)grp.Permission + ")\r\n";
listRanks.Items.Add(grp.trueName + " = " + (int)grp.Permission);
}
txtBlRanks.Text = txtCmdRanks.Text;
//txtBlRanks.Text = txtCmdRanks.Text;
listRanks.SelectedIndex = 0;
}
public void SaveRanks() {
@ -174,15 +155,15 @@ namespace MCGalaxy.Gui {
}
public void LoadBlocks() {
listBlocks.Items.Clear();
blk_list.Items.Clear();
storedBlocks.Clear();
storedBlocks.AddRange(BlockPerms.List);
foreach ( BlockPerms bs in storedBlocks ) {
if ( Block.Name(bs.BlockID) != "unknown" )
listBlocks.Items.Add(Block.Name(bs.BlockID));
blk_list.Items.Add(Block.Name(bs.BlockID));
}
if ( listBlocks.SelectedIndex == -1 )
listBlocks.SelectedIndex = 0;
if ( blk_list.SelectedIndex == -1 )
blk_list.SelectedIndex = 0;
}
public void SaveBlocks() {
@ -251,7 +232,7 @@ namespace MCGalaxy.Gui {
void saveStuff() {
foreach ( Control tP in tabControl.Controls )
if ( tP is TabPage && tP != pageCommands && tP != pageBlocks )
if ( tP is TabPage && tP != pageCommands && tP != tabBlocks )
foreach ( Control ctrl in tP.Controls )
if ( ctrl is TextBox && ctrl.Name.ToLower() != "txtgrpmotd" )
if ( ctrl.Text == "" ) {

View File

@ -50,6 +50,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Descriptors.cs" />
<Compile Include="GuiPerms.cs" />
<Compile Include="LineFormatter.cs" />
<Compile Include="Handlers.cs" />
<Compile Include="Program.cs" />