Skip to content

Commit 8140ed1

Browse files
authored
Merge pull request #11 from Bob-Rust/correct-scaling-size
fix: Correct Size
2 parents 0c240d0 + fd7cbbe commit 8140ed1

13 files changed

+225
-96
lines changed
823 KB
Loading

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ HardCoded
1111
Sekwah41
1212
* Generation
1313

14-
# Can I get banned?
15-
We have reached out to the Rust team and they told us that our application is ok.
16-
We are still waiting for a response from the EAC team.
14+
If you have any problem with the program please create a new issue and tell us what went wrong.
1715

1816
# Usage
19-
Work in progress...
17+
Check out our wiki for more information
18+
[Wiki](https://github.com/Bob-Rust/Bob-Rust-Java/wiki)
2019

21-
# Preview
22-
![Example](.github/assets/screenshots/example_1.jpg)
20+
# FAQ
2321

24-
# Issue
25-
If you have any problem with the program please create a new issue and tell us what went wrong.
22+
## How many colors?
23+
This tool can approximate most colors from the color spectrum.
24+
![Example](.github/assets/screenshots/example_2.jpg)
25+
26+
## Can I get banned?
27+
We have reached out to the Rust team and they told us that our application is ok.
28+
We are still waiting for a response from the EAC team.

src/main/java/com/bobrust/gui/BobRustDrawDialog.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,18 +212,18 @@ private void showPaletteWarning() {
212212

213213
private boolean findColorPalette() {
214214
// The bounds of the screen.
215-
Rectangle screen = overlay.dialog.getBounds();
215+
Rectangle screenBounds = overlay.dialog.getBounds();
216216

217217
// Check for bright red on the edge of the screen.
218218
try {
219-
BufferedImage screenshot = new Robot().createScreenCapture(screen);
219+
BufferedImage screenshot = new Robot().createScreenCapture(screenBounds);
220220
Point paletteLocation = rustPalette.findPalette(screenshot);
221221

222222
if(paletteLocation != null) {
223223
overlay.colorRegion.setLocation(paletteLocation.x, paletteLocation.y + 132 + 100);
224-
Point paletteScreenLocation = new Point(screen.x + paletteLocation.x, screen.y + paletteLocation.y);
224+
Point paletteScreenLocation = new Point(screenBounds.x + paletteLocation.x, screenBounds.y + paletteLocation.y);
225225

226-
if(rustPalette.analyse(dialog, screenshot, screen.getLocation(), paletteScreenLocation)) {
226+
if(rustPalette.analyse(dialog, screenshot, screenBounds, paletteScreenLocation)) {
227227
// Found the palette.
228228
LogUtils.info("Found the color palette (%d, %d)", paletteScreenLocation.x, paletteScreenLocation.y);
229229
overlay.repaint();

src/main/java/com/bobrust/gui/BobRustOverlay.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ private void startGeneration() {
582582
signType.width,
583583
signType.height,
584584
bgColor,
585-
RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR
585+
gui.getSettingsScaling()
586586
);
587587

588588
// Apply the ICC cmyk lut filter.

src/main/java/com/bobrust/gui/BobRustSettingsDialog.java

Lines changed: 98 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class BobRustSettingsDialog {
1919
private final JDialog dialog;
2020

2121
private final JComboBox<Integer> alphaCombobox;
22+
private final JComboBox<String> scalingCombobox;
2223
private final JIntegerField maxShapesField;
2324
private final JIntegerField callbackIntervalField;
2425
private final JIntegerField clickIntervalField;
@@ -95,73 +96,105 @@ public BobRustSettingsDialog(BobRustEditor gui, JDialog parent) {
9596
});
9697
signPanel.add(btnSign);
9798

98-
JPanel alphaPanel = new JPanel();
99-
alphaPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
100-
alphaPanel.setBorder(new EmptyBorder(5, 5, 0, 5));
101-
alphaPanel.setPreferredSize(optionSize);
102-
alphaPanel.setMinimumSize(optionSize);
103-
alphaPanel.setMaximumSize(optionSize);
104-
panel.add(alphaPanel);
105-
alphaPanel.setLayout(new BoxLayout(alphaPanel, BoxLayout.Y_AXIS));
106-
107-
JLabel alphaLabel = new JLabel(RustUI.getString(Type.SETTINGS_ALPHAINDEX_LABEL));
108-
alphaLabel.setToolTipText(RustUI.getString(Type.SETTINGS_ALPHAINDEX_TOOLTIP));
109-
alphaLabel.setHorizontalTextPosition(SwingConstants.CENTER);
110-
alphaLabel.setHorizontalAlignment(SwingConstants.CENTER);
111-
alphaPanel.add(alphaLabel);
112-
113-
alphaCombobox = new JComboBox<Integer>();
114-
alphaCombobox.setAlignmentX(Component.LEFT_ALIGNMENT);
115-
alphaCombobox.setFocusable(false);
116-
alphaLabel.setLabelFor(alphaCombobox);
117-
alphaCombobox.setMaximumSize(new Dimension(116, 20));
118-
alphaCombobox.setModel(new DefaultComboBoxModel<Integer>(new Integer[] { 0, 1, 2, 3, 4, 5 }));
119-
alphaCombobox.setSelectedIndex(gui.getSettingsAlpha());
120-
alphaPanel.add(alphaCombobox);
121-
122-
JPanel shapesPanel = new JPanel();
123-
shapesPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
124-
shapesPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
125-
shapesPanel.setPreferredSize(optionSize);
126-
shapesPanel.setMinimumSize(optionSize);
127-
shapesPanel.setMaximumSize(optionSize);
128-
panel.add(shapesPanel);
129-
shapesPanel.setLayout(new BoxLayout(shapesPanel, BoxLayout.Y_AXIS));
130-
131-
JLabel shapesLabel = new JLabel(RustUI.getString(Type.SETTINGS_MAXSHAPES_LABEL));
132-
shapesLabel.setToolTipText(RustUI.getString(Type.SETTINGS_MAXSHAPES_TOOLTIP));
133-
shapesLabel.setHorizontalTextPosition(SwingConstants.CENTER);
134-
shapesLabel.setHorizontalAlignment(SwingConstants.CENTER);
135-
shapesPanel.add(shapesLabel);
136-
137-
maxShapesField = new JIntegerField(gui.getSettingsMaxShapes());
138-
maxShapesField.setAlignmentX(Component.LEFT_ALIGNMENT);
139-
maxShapesField.setFocusable(true);
140-
maxShapesField.setMaximumSize(new Dimension(116, 20));
141-
shapesLabel.setLabelFor(maxShapesField);
142-
shapesPanel.add(maxShapesField);
99+
{
100+
JPanel alphaPanel = new JPanel();
101+
alphaPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
102+
alphaPanel.setBorder(new EmptyBorder(5, 5, 0, 5));
103+
alphaPanel.setPreferredSize(optionSize);
104+
alphaPanel.setMinimumSize(optionSize);
105+
alphaPanel.setMaximumSize(optionSize);
106+
panel.add(alphaPanel);
107+
alphaPanel.setLayout(new BoxLayout(alphaPanel, BoxLayout.Y_AXIS));
108+
109+
JLabel alphaLabel = new JLabel(RustUI.getString(Type.SETTINGS_ALPHAINDEX_LABEL));
110+
alphaLabel.setToolTipText(RustUI.getString(Type.SETTINGS_ALPHAINDEX_TOOLTIP));
111+
alphaLabel.setHorizontalTextPosition(SwingConstants.CENTER);
112+
alphaLabel.setHorizontalAlignment(SwingConstants.CENTER);
113+
alphaPanel.add(alphaLabel);
114+
115+
alphaCombobox = new JComboBox<Integer>();
116+
alphaCombobox.setAlignmentX(Component.LEFT_ALIGNMENT);
117+
alphaCombobox.setFocusable(false);
118+
alphaLabel.setLabelFor(alphaCombobox);
119+
alphaCombobox.setMaximumSize(new Dimension(116, 20));
120+
alphaCombobox.setModel(new DefaultComboBoxModel<Integer>(new Integer[] { 0, 1, 2, 3, 4, 5 }));
121+
alphaCombobox.setSelectedIndex(gui.getSettingsAlpha());
122+
alphaPanel.add(alphaCombobox);
123+
}
143124

144-
JPanel callbackPanel = new JPanel();
145-
callbackPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
146-
callbackPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
147-
callbackPanel.setPreferredSize(optionSize);
148-
callbackPanel.setMinimumSize(optionSize);
149-
callbackPanel.setMaximumSize(optionSize);
150-
panel.add(callbackPanel);
151-
callbackPanel.setLayout(new BoxLayout(callbackPanel, BoxLayout.Y_AXIS));
125+
{
126+
JPanel scalingPanel = new JPanel();
127+
scalingPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
128+
scalingPanel.setBorder(new EmptyBorder(5, 5, 0, 5));
129+
scalingPanel.setPreferredSize(optionSize);
130+
scalingPanel.setMinimumSize(optionSize);
131+
scalingPanel.setMaximumSize(optionSize);
132+
panel.add(scalingPanel);
133+
scalingPanel.setLayout(new BoxLayout(scalingPanel, BoxLayout.Y_AXIS));
134+
135+
JLabel scalingLabel = new JLabel(RustUI.getString(Type.SETTINGS_SCALINGTYPE_LABEL));
136+
scalingLabel.setToolTipText(RustUI.getString(Type.SETTINGS_SCALINGTYPE_TOOLTIP));
137+
scalingLabel.setHorizontalTextPosition(SwingConstants.CENTER);
138+
scalingLabel.setHorizontalAlignment(SwingConstants.CENTER);
139+
scalingPanel.add(scalingLabel);
140+
141+
scalingCombobox = new JComboBox<String>();
142+
scalingCombobox.setAlignmentX(Component.LEFT_ALIGNMENT);
143+
scalingCombobox.setFocusable(false);
144+
scalingLabel.setLabelFor(scalingCombobox);
145+
scalingCombobox.setMaximumSize(new Dimension(116, 20));
146+
scalingCombobox.setModel(new DefaultComboBoxModel<String>(new String[] { "NEAREST", "BILINEAR", "BICUBIC" }));
147+
scalingCombobox.setSelectedIndex(gui.getSettingsScaling());
148+
scalingPanel.add(scalingCombobox);
149+
}
152150

153-
JLabel callbackLabel = new JLabel(RustUI.getString(Type.SETTINGS_CALLBACKINTERVAL_LABEL));
154-
callbackLabel.setToolTipText(RustUI.getString(Type.SETTINGS_CALLBACKINTERVAL_TOOLTIP));
155-
callbackLabel.setHorizontalTextPosition(SwingConstants.CENTER);
156-
callbackLabel.setHorizontalAlignment(SwingConstants.CENTER);
157-
callbackPanel.add(callbackLabel);
151+
{
152+
JPanel shapesPanel = new JPanel();
153+
shapesPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
154+
shapesPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
155+
shapesPanel.setPreferredSize(optionSize);
156+
shapesPanel.setMinimumSize(optionSize);
157+
shapesPanel.setMaximumSize(optionSize);
158+
panel.add(shapesPanel);
159+
shapesPanel.setLayout(new BoxLayout(shapesPanel, BoxLayout.Y_AXIS));
160+
161+
JLabel shapesLabel = new JLabel(RustUI.getString(Type.SETTINGS_MAXSHAPES_LABEL));
162+
shapesLabel.setToolTipText(RustUI.getString(Type.SETTINGS_MAXSHAPES_TOOLTIP));
163+
shapesLabel.setHorizontalTextPosition(SwingConstants.CENTER);
164+
shapesLabel.setHorizontalAlignment(SwingConstants.CENTER);
165+
shapesPanel.add(shapesLabel);
166+
167+
maxShapesField = new JIntegerField(gui.getSettingsMaxShapes());
168+
maxShapesField.setAlignmentX(Component.LEFT_ALIGNMENT);
169+
maxShapesField.setFocusable(true);
170+
maxShapesField.setMaximumSize(new Dimension(116, 20));
171+
shapesLabel.setLabelFor(maxShapesField);
172+
shapesPanel.add(maxShapesField);
173+
}
158174

159-
callbackIntervalField = new JIntegerField(gui.getSettingsCallbackInterval());
160-
callbackIntervalField.setAlignmentX(Component.LEFT_ALIGNMENT);
161-
callbackIntervalField.setFocusable(true);
162-
callbackIntervalField.setMaximumSize(new Dimension(116, 20));
163-
callbackLabel.setLabelFor(callbackIntervalField);
164-
callbackPanel.add(callbackIntervalField);
175+
{
176+
JPanel callbackPanel = new JPanel();
177+
callbackPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
178+
callbackPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
179+
callbackPanel.setPreferredSize(optionSize);
180+
callbackPanel.setMinimumSize(optionSize);
181+
callbackPanel.setMaximumSize(optionSize);
182+
panel.add(callbackPanel);
183+
callbackPanel.setLayout(new BoxLayout(callbackPanel, BoxLayout.Y_AXIS));
184+
185+
JLabel callbackLabel = new JLabel(RustUI.getString(Type.SETTINGS_CALLBACKINTERVAL_LABEL));
186+
callbackLabel.setToolTipText(RustUI.getString(Type.SETTINGS_CALLBACKINTERVAL_TOOLTIP));
187+
callbackLabel.setHorizontalTextPosition(SwingConstants.CENTER);
188+
callbackLabel.setHorizontalAlignment(SwingConstants.CENTER);
189+
callbackPanel.add(callbackLabel);
190+
191+
callbackIntervalField = new JIntegerField(gui.getSettingsCallbackInterval());
192+
callbackIntervalField.setAlignmentX(Component.LEFT_ALIGNMENT);
193+
callbackIntervalField.setFocusable(true);
194+
callbackIntervalField.setMaximumSize(new Dimension(116, 20));
195+
callbackLabel.setLabelFor(callbackIntervalField);
196+
callbackPanel.add(callbackIntervalField);
197+
}
165198

166199
{
167200
JPanel clickIntervalPanel = new JPanel();
@@ -351,6 +384,7 @@ public void openDialog(Point point) {
351384
dialog.setVisible(true);
352385

353386
gui.setSettingsAlpha(alphaCombobox.getSelectedIndex());
387+
gui.setSettingsScaling(scalingCombobox.getSelectedIndex());
354388

355389
try {
356390
gui.setSettingsMaxShapes(maxShapesField.getNumberValue());

src/main/java/com/bobrust/lang/RustUI.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public enum Type {
1010
SETTINGS_AUTOSAVEINTERVAL_TOOLTIP("How many presses done between saves"),
1111
SETTINGS_ALPHAINDEX_LABEL("Alpha Index"),
1212
SETTINGS_ALPHAINDEX_TOOLTIP("The alpha value used when drawing the image"),
13+
SETTINGS_SCALINGTYPE_LABEL("Scaling Type"),
14+
SETTINGS_SCALINGTYPE_TOOLTIP("The type of scaling performed when resizing the image"),
1315
SETTINGS_MAXSHAPES_LABEL("Max Shapes"),
1416
SETTINGS_MAXSHAPES_TOOLTIP("The max amount of shapes used when drawing the image"),
1517
SETTINGS_SIGNTYPE_LABEL("Sign Type"),

src/main/java/com/bobrust/robot/BobRustPainter.java

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.bobrust.generator.sorter.BlobList;
1010
import com.bobrust.gui.BobRustEditor;
1111
import com.bobrust.gui.BobRustOverlay;
12+
import com.bobrust.logging.LogUtils;
1213
import com.bobrust.util.RustUtil;
1314
import com.bobrust.util.Sign;
1415

@@ -30,6 +31,8 @@ public BobRustPainter(BobRustEditor gui, BobRustOverlay overlay, BobRustPalette
3031
}
3132

3233
public boolean startDrawing(BlobList list) throws Exception {
34+
if(list.size() < 1) return true;
35+
3336
Robot robot = new Robot();
3437

3538
Rectangle canvas = overlay.getCanvasArea();
@@ -56,13 +59,13 @@ public boolean startDrawing(BlobList list) throws Exception {
5659

5760
{
5861
// Make sure that we have selected the game.
59-
clickPoint(robot, palette.getFocusPoint(), 4, autoDelay);
62+
clickPoint(robot, palette.getFocusPoint(), 4, 50);
6063

6164
// Make sure that we have selected the correct alpha.
62-
clickPoint(robot, palette.getAlphaButton(alphaSetting), 4, autoDelay);
65+
clickPoint(robot, palette.getAlphaButton(alphaSetting), 4, 50);
6366

6467
// Make sure that we have selected the correct shape.
65-
clickPoint(robot, palette.getShapeButton(shapeSetting), 4, autoDelay);
68+
clickPoint(robot, palette.getShapeButton(shapeSetting), 4, 50);
6669
}
6770

6871
// We create an update thread because repainting graphics
@@ -98,19 +101,31 @@ public boolean startDrawing(BlobList list) throws Exception {
98101
Point lastPoint = new Point(0, 0);
99102
int lastColor = -1;
100103
int lastSize = -1;
104+
105+
{
106+
Blob first = blobList.get(0);
107+
108+
// Select first color to prevent exception.
109+
clickPoint(robot, palette.getColorButton(BorstUtils.getClosestColor(first.color)), 4, 50);
110+
lastColor = first.colorIndex;
111+
}
112+
101113
for(int i = 0, l = 1; i < count; i++, l++) {
102114
Blob blob = blobList.get(i);
103115

104116
// Change the size.
105117
if(lastSize != blob.sizeIndex) {
106-
clickPoint(robot, palette.getSizeButton(blob.sizeIndex), autoDelay);
118+
clickSize(robot, palette.getSizeButton(blob.sizeIndex), 20, autoDelay);
107119
lastSize = blob.sizeIndex;
108120
l++;
109121
}
110122

111123
// Change the color.
112124
if(lastColor != blob.colorIndex) {
113-
clickPoint(robot, palette.getColorButton(BorstUtils.getClosestColor(blob.color)), autoDelay);
125+
if(!clickColor(robot, palette.getColorButton(BorstUtils.getClosestColor(blob.color)), 20, autoDelay)) {
126+
LogUtils.warn("Potentially failed to change color! Will still keep try drawing");
127+
}
128+
114129
lastColor = blob.colorIndex;
115130
l++;
116131
}
@@ -179,6 +194,38 @@ private void clickPoint(Robot robot, Point point, double delay) {
179194
//System.out.printf("Time: took %.4f, wanted: %.4f\n", time, delay * 3.0);
180195
}
181196

197+
private void clickSize(Robot robot, Point point, int maxAttempts, double delay) {
198+
// Make sure that we press the size
199+
while(maxAttempts-- > 0) {
200+
clickPoint(robot, point, delay);
201+
202+
Color after = robot.getPixelColor(point.x, point.y + 8);
203+
if(after.getGreen() > 120) {
204+
return;
205+
}
206+
}
207+
208+
throw new IllegalStateException("Failed to select size");
209+
}
210+
211+
private boolean clickColor(Robot robot, Point point, int maxAttempts, double delay) {
212+
Point colorPreview = palette.getColorPreview();
213+
Color before = robot.getPixelColor(colorPreview.x, colorPreview.y);
214+
215+
// Make sure that we press the size
216+
while(maxAttempts-- > 0) {
217+
clickPoint(robot, point, delay);
218+
219+
Color after = robot.getPixelColor(colorPreview.x, colorPreview.y);
220+
if(!before.equals(after)) {
221+
return true;
222+
}
223+
}
224+
225+
// throw new IllegalStateException("Failed to select color");
226+
return false;
227+
}
228+
182229
/**
183230
* This method is used to provide a more accurate timing than {@code Robot.setAutoDelay}.
184231
*/

0 commit comments

Comments
 (0)