Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@ public void mouseClicked(MouseEvent e) {
if (modPanel.checkBox.isEnabled()) {
modPanel.checkBox.setSelected(!modPanel.checkBox.isSelected());
repaint();
return;
}
}

if (e.getClickCount() == 2) {
String alias = JOptionPane.showInputDialog("Please enter an alias:");
modPanel.setAlias(alias);
}
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javax.swing.border.MatteBorder;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

@SuppressWarnings("serial")
Expand Down Expand Up @@ -96,6 +97,8 @@ public ModPanel(ModInfo info, File modFile, JModPanelCheckBoxList parent) {
parent.publishBoxChecked();
});
parent.publishBoxChecked();

setToolTipText("Double click to add an alias for this mod");
}

public void recalcModWarnings(JModPanelCheckBoxList parent)
Expand Down Expand Up @@ -196,7 +199,7 @@ public void filter(String[] filterKeys) {
System.out.println("ModPanel.filter failed to get workshop info of " + info.ID + ": " + ex);
}

String modInfoKey = String.format("%s %s %s %s", info.ID, info.Name, String.join(" ", info.Authors), workshopInfoKey).toLowerCase();
String modInfoKey = String.format("%s %s %s %s %s", info.ID, info.Name, infoPanel.alias, String.join(" ", info.Authors), workshopInfoKey).toLowerCase();
boolean isFilteredOut = false;
for (String filterKey : filterKeys) {
if (!modInfoKey.contains(filterKey)) {
Expand All @@ -211,8 +214,21 @@ public boolean isFilteredOut() {
return isFilteredOut;
}

// set the alias for this mod and save
public void setAlias(String alias) {
if (alias == null || alias.isEmpty()) return;
infoPanel.setNameText(alias);
Loader.MTS_CONFIG.setString(info.ID, alias);
try {
Loader.MTS_CONFIG.save();
} catch (IOException ex) {
ex.printStackTrace();
}
}

public class InfoPanel extends JPanel
{
String alias = "";
JLabel name = new JLabel();
JLabel version = new JLabel();

Expand All @@ -234,10 +250,23 @@ public InfoPanel()
}
add(version, BorderLayout.SOUTH);

String alias = Loader.MTS_CONFIG.getString(info.ID);
setNameText(alias);

checkBox.setBackground(Color.WHITE);
setBackground(Color.WHITE);
}

public void setNameText(String alias) {
if (alias == null) return;
this.alias = alias;
if (alias.isEmpty()) {
name.setText(info.Name);
} else {
name.setText(String.format("<html>[%s] <font color=#a0a0a0>%s</font></html>", alias, info.Name));
}
}

@Override
public void setBackground(Color c)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javax.swing.border.TitledBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.plaf.basic.BasicSplitPaneUI;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
Expand Down Expand Up @@ -81,6 +82,7 @@ public static Properties getDefaults()
properties.setProperty("y", "center");
properties.setProperty("width", Integer.toString(DEFAULT_WIDTH));
properties.setProperty("height", Integer.toString(DEFAULT_HEIGHT));
properties.setProperty("split_location", Float.toString(0.275f));
properties.setProperty("maximize", Boolean.toString(false));
return properties;
}
Expand Down Expand Up @@ -203,11 +205,17 @@ private void initUI(boolean skipLauncher)
setLayout(new BorderLayout());
getContentPane().setPreferredSize(new Dimension(location.width, location.height));

getContentPane().add(makeModListPanel(), BorderLayout.WEST);
getContentPane().add(makeInfoPanel(), BorderLayout.CENTER);
JSplitPane splitPane = makeMainPanel();
getContentPane().add(splitPane, BorderLayout.CENTER);
getContentPane().add(makeTopPanel(), BorderLayout.NORTH);

pack();

float loc = Loader.MTS_CONFIG.getFloat("split_location");
if (loc > 0.05f && loc < 0.95f) {
splitPane.setDividerLocation(loc);
}

if (isCentered) {
setLocationRelativeTo(null);
} else {
Expand All @@ -224,11 +232,34 @@ private void initUI(boolean skipLauncher)
}
}

private JPanel makeModListPanel()
{
private JSplitPane makeMainPanel() {
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
splitPane.setLeftComponent(makeModListPanel());
splitPane.setRightComponent(makeInfoPanel());

BasicSplitPaneUI spui = (BasicSplitPaneUI)splitPane.getUI();
spui.getDivider().addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
float percent = splitPane.getDividerLocation() / (float)(splitPane.getWidth() - splitPane.getDividerSize());
Loader.MTS_CONFIG.setFloat("split_location", percent);
try {
Loader.MTS_CONFIG.save();
} catch (IOException ex) {
ex.printStackTrace();
}
}
});


return splitPane;
}

private JPanel makeModListPanel() {
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.setPreferredSize(new Dimension(220, 300));
panel.setMinimumSize(new Dimension(50, 300));

// Mod List
DefaultListModel<ModPanel> model = new DefaultListModel<>();
Expand Down Expand Up @@ -442,6 +473,7 @@ private JPanel makeInfoPanel()
{
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.setMinimumSize(new Dimension(400, 300));

// Top mod banner panel
panel.add(makeModBannerPanel(), BorderLayout.NORTH);
Expand Down