-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui_builder.py
More file actions
828 lines (713 loc) · 35.6 KB
/
ui_builder.py
File metadata and controls
828 lines (713 loc) · 35.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
from PyQt6 import QtWidgets, QtCore, QtGui
from PyQt6.QtCore import Qt
from PIL import Image
import logging
logger = logging.getLogger(__name__)
def build_noise_ui(win, layout):
"""Create noise tab UI and attach widgets as attributes on the window instance.
This is a direct port of MainWindow._build_noise_ui with `self` replaced by `win`.
"""
scroll = QtWidgets.QScrollArea()
scroll.setWidgetResizable(True)
scroll.setFixedWidth(420)
controls_container = QtWidgets.QWidget()
scroll.setWidget(controls_container)
vbox = QtWidgets.QVBoxLayout(controls_container)
vbox.setContentsMargins(8,8,8,8)
vbox.setSpacing(12)
basic_group = QtWidgets.QGroupBox('Basic Settings')
basic_layout = QtWidgets.QFormLayout(basic_group)
basic_layout.setLabelAlignment(QtCore.Qt.AlignmentFlag.AlignLeft)
win.size_spin = QtWidgets.QSpinBox()
win.size_spin.setRange(64,2048)
win.size_spin.setValue(256)
try:
win.size_spin.setButtonSymbols(QtWidgets.QAbstractSpinBox.ButtonSymbols.NoButtons)
except Exception:
pass
# Add inline +/- buttons for better increment controls
size_container = QtWidgets.QWidget()
size_h = QtWidgets.QHBoxLayout(size_container)
size_h.setContentsMargins(0,0,0,0)
size_h.addWidget(win.size_spin)
size_minus = QtWidgets.QPushButton('-')
size_minus.setFixedWidth(24)
size_plus = QtWidgets.QPushButton('+')
size_plus.setFixedWidth(24)
size_h.addWidget(size_minus)
size_h.addWidget(size_plus)
basic_layout.addRow('Image Size', size_container)
size_minus.clicked.connect(lambda: [win.size_spin.setValue(max(win.size_spin.minimum(), win.size_spin.value() - win.size_spin.singleStep())), win.request_preview()])
size_plus.clicked.connect(lambda: [win.size_spin.setValue(min(win.size_spin.maximum(), win.size_spin.value() + win.size_spin.singleStep())), win.request_preview()])
win.scale_spin = QtWidgets.QDoubleSpinBox()
win.scale_spin.setRange(1.0,500.0)
win.scale_spin.setValue(150.0)
basic_layout.addRow('Scale', win.scale_spin)
win._link_slider_to_spinbox(win.scale_spin, basic_layout)
win.seed_spin = QtWidgets.QSpinBox()
win.seed_spin.setRange(0,2 **31 -1)
win.seed_spin.setValue(42)
try:
win.seed_spin.setButtonSymbols(QtWidgets.QAbstractSpinBox.ButtonSymbols.NoButtons)
except Exception:
pass
seed_container = QtWidgets.QWidget()
seed_h = QtWidgets.QHBoxLayout(seed_container)
seed_h.setContentsMargins(0,0,0,0)
seed_h.addWidget(win.seed_spin)
seed_minus = QtWidgets.QPushButton('-')
seed_minus.setFixedWidth(24)
seed_plus = QtWidgets.QPushButton('+')
seed_plus.setFixedWidth(24)
seed_h.addWidget(seed_minus)
seed_h.addWidget(seed_plus)
basic_layout.addRow('Seed', seed_container)
seed_minus.clicked.connect(lambda: [win.seed_spin.setValue(max(win.seed_spin.minimum(), win.seed_spin.value() - win.seed_spin.singleStep())), win.request_preview()])
seed_plus.clicked.connect(lambda: [win.seed_spin.setValue(min(win.seed_spin.maximum(), win.seed_spin.value() + win.seed_spin.singleStep())), win.request_preview()])
vbox.addWidget(basic_group)
height_group = QtWidgets.QGroupBox('Teardown / Heightmap')
height_layout = QtWidgets.QFormLayout(height_group)
win.noise_type = QtWidgets.QComboBox()
win.noise_type.addItems(['Perlin noise', 'Fractal noise', 'Turbulence noise'])
height_layout.addRow('Noise Type', win.noise_type)
win.octaves_spin = QtWidgets.QSpinBox()
win.octaves_spin.setRange(1,16)
win.octaves_spin.setValue(7)
height_layout.addRow('Octaves', win.octaves_spin)
win._octaves_slider = win._link_slider_to_spinbox(win.octaves_spin, height_layout)
win.persistence_spin = QtWidgets.QDoubleSpinBox()
win.persistence_spin.setRange(0.0,1.0)
win.persistence_spin.setSingleStep(0.01)
win.persistence_spin.setValue(0.6)
height_layout.addRow('Persistence', win.persistence_spin)
win._persistence_slider = win._link_slider_to_spinbox(win.persistence_spin, height_layout)
win.lacunarity_spin = QtWidgets.QDoubleSpinBox()
win.lacunarity_spin.setRange(0.1,8.0)
win.lacunarity_spin.setSingleStep(0.1)
win.lacunarity_spin.setValue(2.0)
height_layout.addRow('Lacunarity', win.lacunarity_spin)
win._link_slider_to_spinbox(win.lacunarity_spin, height_layout)
win.min_height_spin = QtWidgets.QDoubleSpinBox()
win.min_height_spin.setRange(-2.0,2.0)
win.min_height_spin.setSingleStep(0.1)
win.min_height_spin.setValue(1.0)
height_layout.addRow('Min Height', win.min_height_spin)
win._link_slider_to_spinbox(win.min_height_spin, height_layout)
win.max_height_spin = QtWidgets.QDoubleSpinBox()
win.max_height_spin.setRange(0.0,2.0)
win.max_height_spin.setSingleStep(0.1)
win.max_height_spin.setValue(0.5)
height_layout.addRow('Max Height', win.max_height_spin)
win._link_slider_to_spinbox(win.max_height_spin, height_layout)
win.grass_amount_spin = QtWidgets.QSpinBox()
win.grass_amount_spin.setRange(0,255)
win.grass_amount_spin.setValue(0)
try:
win.grass_amount_spin.setButtonSymbols(QtWidgets.QAbstractSpinBox.ButtonSymbols.NoButtons)
except Exception:
pass
grass_amt_container = QtWidgets.QWidget()
grass_amt_h = QtWidgets.QHBoxLayout(grass_amt_container)
grass_amt_h.setContentsMargins(0,0,0,0)
grass_amt_h.addWidget(win.grass_amount_spin)
grass_amt_minus = QtWidgets.QPushButton('-')
grass_amt_minus.setFixedWidth(24)
grass_amt_plus = QtWidgets.QPushButton('+')
grass_amt_plus.setFixedWidth(24)
grass_amt_h.addWidget(grass_amt_minus)
grass_amt_h.addWidget(grass_amt_plus)
height_layout.addRow('Grass Amount', grass_amt_container)
grass_amt_minus.clicked.connect(lambda: [win.grass_amount_spin.setValue(max(win.grass_amount_spin.minimum(), win.grass_amount_spin.value() - win.grass_amount_spin.singleStep())), win.request_preview()])
grass_amt_plus.clicked.connect(lambda: [win.grass_amount_spin.setValue(min(win.grass_amount_spin.maximum(), win.grass_amount_spin.value() + win.grass_amount_spin.singleStep())), win.request_preview()])
win.special_value_spin = QtWidgets.QSpinBox()
win.special_value_spin.setRange(0,255)
win.special_value_spin.setValue(0)
try:
win.special_value_spin.setButtonSymbols(QtWidgets.QAbstractSpinBox.ButtonSymbols.NoButtons)
except Exception:
pass
special_container = QtWidgets.QWidget()
special_h = QtWidgets.QHBoxLayout(special_container)
special_h.setContentsMargins(0,0,0,0)
special_h.addWidget(win.special_value_spin)
special_minus = QtWidgets.QPushButton('-')
special_minus.setFixedWidth(24)
special_plus = QtWidgets.QPushButton('+')
special_plus.setFixedWidth(24)
special_h.addWidget(special_minus)
special_h.addWidget(special_plus)
height_layout.addRow('Special Value', special_container)
special_minus.clicked.connect(lambda: [win.special_value_spin.setValue(max(win.special_value_spin.minimum(), win.special_value_spin.value() - win.special_value_spin.singleStep())), win.request_preview()])
special_plus.clicked.connect(lambda: [win.special_value_spin.setValue(min(win.special_value_spin.maximum(), win.special_value_spin.value() + win.special_value_spin.singleStep())), win.request_preview()])
win.use_noise_grass_cb = QtWidgets.QCheckBox('Use Noise Grass')
height_layout.addRow(win.use_noise_grass_cb)
vbox.addWidget(height_group)
grass_noise_group = QtWidgets.QGroupBox('Grass Noise Settings')
grass_noise_layout = QtWidgets.QFormLayout(grass_noise_group)
win.grass_noise_octaves = QtWidgets.QSpinBox()
win.grass_noise_octaves.setRange(1,8)
win.grass_noise_octaves.setValue(4)
grass_noise_layout.addRow('Grass Noise Octaves', win.grass_noise_octaves)
win.grass_noise_persistence = QtWidgets.QDoubleSpinBox()
win.grass_noise_persistence.setRange(0.0,1.0)
win.grass_noise_persistence.setSingleStep(0.01)
win.grass_noise_persistence.setValue(0.5)
grass_noise_layout.addRow('Grass Noise Persistence', win.grass_noise_persistence)
win.grass_noise_scale = QtWidgets.QDoubleSpinBox()
win.grass_noise_scale.setRange(1.0,500.0)
win.grass_noise_scale.setValue(50.0)
grass_noise_layout.addRow('Grass Noise Scale', win.grass_noise_scale)
win.noise_grass_density = QtWidgets.QDoubleSpinBox()
win.noise_grass_density.setRange(0.0,1.0)
win.noise_grass_density.setSingleStep(0.01)
win.noise_grass_density.setValue(0.5)
grass_noise_layout.addRow('Noise Grass Density', win.noise_grass_density)
win.grass_noise_group = grass_noise_group
win.grass_noise_group.setVisible(False)
vbox.addWidget(win.grass_noise_group)
win.use_noise_grass_cb.stateChanged.connect(win._update_grass_noise_visibility)
vignette_group = QtWidgets.QGroupBox('Vignette')
vignette_layout = QtWidgets.QFormLayout(vignette_group)
win.vignette_strength_spin = QtWidgets.QDoubleSpinBox()
win.vignette_strength_spin.setRange(0.0,1.0)
win.vignette_strength_spin.setSingleStep(0.01)
win.vignette_strength_spin.setValue(0.0)
vignette_layout.addRow('Vignette Strength', win.vignette_strength_spin)
win.vignette_radius_spin = QtWidgets.QDoubleSpinBox()
win.vignette_radius_spin.setRange(0.0,1.0)
win.vignette_radius_spin.setSingleStep(0.01)
win.vignette_radius_spin.setValue(0.5)
vignette_layout.addRow('Vignette Radius', win.vignette_radius_spin)
win.vignette_group = vignette_group
vbox.addWidget(win.vignette_group)
canyon_group = QtWidgets.QGroupBox('Canyon Settings')
canyon_layout = QtWidgets.QFormLayout(canyon_group)
win.canyon_strength_spin = QtWidgets.QDoubleSpinBox()
win.canyon_strength_spin.setRange(0.0,1.0)
win.canyon_strength_spin.setSingleStep(0.01)
win.canyon_strength_spin.setValue(0.0)
canyon_layout.addRow('Canyon Strength', win.canyon_strength_spin)
win.canyon_length_spin = QtWidgets.QDoubleSpinBox()
win.canyon_length_spin.setRange(0.1,1.0)
win.canyon_length_spin.setSingleStep(0.01)
win.canyon_length_spin.setValue(0.7)
canyon_layout.addRow('Canyon Length', win.canyon_length_spin)
win.canyon_branch_density_spin = QtWidgets.QDoubleSpinBox()
win.canyon_branch_density_spin.setRange(0.0,1.0)
win.canyon_branch_density_spin.setSingleStep(0.01)
win.canyon_branch_density_spin.setValue(0.15)
canyon_layout.addRow('Canyon Branch Density', win.canyon_branch_density_spin)
win.canyon_count_spin = QtWidgets.QSpinBox()
win.canyon_count_spin.setRange(0,50)
win.canyon_count_spin.setValue(6)
try:
win.canyon_count_spin.setButtonSymbols(QtWidgets.QAbstractSpinBox.ButtonSymbols.NoButtons)
except Exception:
pass
canyon_count_container = QtWidgets.QWidget()
canyon_count_h = QtWidgets.QHBoxLayout(canyon_count_container)
canyon_count_h.setContentsMargins(0,0,0,0)
canyon_count_h.addWidget(win.canyon_count_spin)
canyon_count_minus = QtWidgets.QPushButton('-')
canyon_count_minus.setFixedWidth(24)
canyon_count_plus = QtWidgets.QPushButton('+')
canyon_count_plus.setFixedWidth(24)
canyon_count_h.addWidget(canyon_count_minus)
canyon_count_h.addWidget(canyon_count_plus)
canyon_layout.addRow('Canyon Count', canyon_count_container)
canyon_count_minus.clicked.connect(lambda: [win.canyon_count_spin.setValue(max(win.canyon_count_spin.minimum(), win.canyon_count_spin.value() - win.canyon_count_spin.singleStep())), win.request_preview()])
canyon_count_plus.clicked.connect(lambda: [win.canyon_count_spin.setValue(min(win.canyon_count_spin.maximum(), win.canyon_count_spin.value() + win.canyon_count_spin.singleStep())), win.request_preview()])
win.canyon_seed_spin = QtWidgets.QSpinBox()
win.canyon_seed_spin.setRange(0,2 **31 -1)
win.canyon_seed_spin.setValue(42)
try:
win.canyon_seed_spin.setButtonSymbols(QtWidgets.QAbstractSpinBox.ButtonSymbols.NoButtons)
except Exception:
pass
canyon_seed_container = QtWidgets.QWidget()
canyon_seed_h = QtWidgets.QHBoxLayout(canyon_seed_container)
canyon_seed_h.setContentsMargins(0,0,0,0)
canyon_seed_h.addWidget(win.canyon_seed_spin)
canyon_seed_minus = QtWidgets.QPushButton('-')
canyon_seed_minus.setFixedWidth(24)
canyon_seed_plus = QtWidgets.QPushButton('+')
canyon_seed_plus.setFixedWidth(24)
canyon_seed_h.addWidget(canyon_seed_minus)
canyon_seed_h.addWidget(canyon_seed_plus)
canyon_layout.addRow('Canyon Seed', canyon_seed_container)
canyon_seed_minus.clicked.connect(lambda: [win.canyon_seed_spin.setValue(max(win.canyon_seed_spin.minimum(), win.canyon_seed_spin.value() - win.canyon_seed_spin.singleStep())), win.request_preview()])
canyon_seed_plus.clicked.connect(lambda: [win.canyon_seed_spin.setValue(min(win.canyon_seed_spin.maximum(), win.canyon_seed_spin.value() + win.canyon_seed_spin.singleStep())), win.request_preview()])
win.canyon_group = canyon_group
vbox.addWidget(canyon_group)
# Keep a hidden cancel button available for exports (placed in controls)
win.cancel_export_btn = QtWidgets.QPushButton('Cancel Export')
win.cancel_export_btn.setEnabled(False)
win.cancel_export_btn.hide()
vbox.addWidget(win.cancel_export_btn)
vbox.addStretch(1)
layout.addWidget(scroll)
preview_frame = QtWidgets.QFrame()
preview_layout = QtWidgets.QVBoxLayout(preview_frame)
title = QtWidgets.QLabel('NOISE PREVIEW')
title.setAlignment(Qt.AlignmentFlag.AlignCenter)
font = title.font()
font.setPointSize(14)
font.setBold(True)
title.setFont(font)
preview_layout.addWidget(title)
# Add export buttons above the progress bar (keeps them visually separate)
btn_row = QtWidgets.QWidget()
btn_layout = QtWidgets.QHBoxLayout(btn_row)
btn_layout.setContentsMargins(0, 0, 0, 0)
win.export_heightmap_btn = QtWidgets.QPushButton('Export Heightmap')
win.export_heightmap_grey_btn = QtWidgets.QPushButton('Export Greyscale Heightmap')
btn_layout.addWidget(win.export_heightmap_btn)
btn_layout.addWidget(win.export_heightmap_grey_btn)
preview_layout.addWidget(btn_row)
# Progress bar placed above preview for visibility (below export buttons)
win.export_progress = QtWidgets.QProgressBar()
win.export_progress.setRange(0,100)
win.export_progress.hide()
preview_layout.addWidget(win.export_progress)
win.preview_label = QtWidgets.QLabel()
win.preview_label.setFixedSize(600,600)
win.preview_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
win.preview_label.setStyleSheet('background: #1e272e;')
preview_layout.addWidget(win.preview_label, alignment=Qt.AlignmentFlag.AlignCenter)
try:
win.preview_label.installEventFilter(win)
except Exception:
logging.exception('Failed to install event filter on preview_label')
layout.addWidget(preview_frame, stretch=1)
# Export buttons in preview area
try:
win.export_heightmap_btn.clicked.connect(win.generate_heightmap_export)
except Exception:
pass
try:
win.export_heightmap_grey_btn.clicked.connect(win.generate_heightmap_export_greyscale)
except Exception:
pass
for w in (win.noise_type, win.size_spin, win.scale_spin, win.seed_spin,
win.octaves_spin, win.persistence_spin, win.lacunarity_spin,
win.min_height_spin, win.max_height_spin, win.grass_amount_spin, win.special_value_spin,
win.grass_noise_octaves, win.grass_noise_persistence, win.grass_noise_scale, win.noise_grass_density,
win.vignette_strength_spin, win.vignette_radius_spin,
win.canyon_strength_spin, win.canyon_length_spin, win.canyon_branch_density_spin, win.canyon_count_spin, win.canyon_seed_spin):
if isinstance(w, QtWidgets.QComboBox):
w.currentIndexChanged.connect(win.request_preview)
else:
try:
w.valueChanged.connect(win.request_preview)
except Exception:
pass
win.use_noise_grass_cb.stateChanged.connect(win.request_preview)
def _on_noise_type_change(idx):
win._update_noise_controls_enabled()
win.request_preview()
win.noise_type.currentIndexChanged.connect(_on_noise_type_change)
try:
if hasattr(win, 'mode_selector'):
win._apply_mode(win.mode_selector.currentText())
win.mode_selector.currentIndexChanged.connect(lambda idx: win._apply_mode(win.mode_selector.currentText()))
except Exception:
pass
win._update_noise_controls_enabled()
win.size_spin.valueChanged.connect(win._on_size_change)
def build_grass_ui(win, layout):
scroll = QtWidgets.QScrollArea()
scroll.setWidgetResizable(True)
scroll.setFixedWidth(420)
container = QtWidgets.QWidget()
scroll.setWidget(container)
vbox = QtWidgets.QVBoxLayout(container)
vbox.setContentsMargins(8,8,8,8)
vbox.setSpacing(12)
# --- Basic Settings Group ---
basic_group = QtWidgets.QGroupBox('Basic Settings')
basic_layout = QtWidgets.QFormLayout(basic_group)
basic_layout.setLabelAlignment(QtCore.Qt.AlignmentFlag.AlignLeft)
win.grass_size = QtWidgets.QSpinBox()
win.grass_size.setRange(64,2048)
win.grass_size.setValue(256)
try:
win.grass_size.setButtonSymbols(QtWidgets.QAbstractSpinBox.ButtonSymbols.NoButtons)
except Exception:
pass
# Add inline +/- buttons for better increment controls
grass_size_container = QtWidgets.QWidget()
grass_size_h = QtWidgets.QHBoxLayout(grass_size_container)
grass_size_h.setContentsMargins(0,0,0,0)
grass_size_h.addWidget(win.grass_size)
grass_size_minus = QtWidgets.QPushButton('-')
grass_size_minus.setFixedWidth(24)
grass_size_plus = QtWidgets.QPushButton('+')
grass_size_plus.setFixedWidth(24)
grass_size_h.addWidget(grass_size_minus)
grass_size_h.addWidget(grass_size_plus)
basic_layout.addRow('Image Size', grass_size_container)
grass_size_minus.clicked.connect(lambda: [win.grass_size.setValue(max(win.grass_size.minimum(), win.grass_size.value() - win.grass_size.singleStep())), win.request_grass_preview()])
grass_size_plus.clicked.connect(lambda: [win.grass_size.setValue(min(win.grass_size.maximum(), win.grass_size.value() + win.grass_size.singleStep())), win.request_grass_preview()])
win.grass_scale_spin = QtWidgets.QDoubleSpinBox()
win.grass_scale_spin.setRange(1.0,500.0)
win.grass_scale_spin.setValue(150.0)
basic_layout.addRow('Scale', win.grass_scale_spin)
# linked slider for quick adjustments
win._link_slider_to_spinbox(win.grass_scale_spin, basic_layout)
win.grass_seed_spin = QtWidgets.QSpinBox()
win.grass_seed_spin.setRange(0,2 **31 -1)
win.grass_seed_spin.setValue(42)
try:
win.grass_seed_spin.setButtonSymbols(QtWidgets.QAbstractSpinBox.ButtonSymbols.NoButtons)
except Exception:
pass
seed_container = QtWidgets.QWidget()
seed_h = QtWidgets.QHBoxLayout(seed_container)
seed_h.setContentsMargins(0,0,0,0)
seed_h.addWidget(win.grass_seed_spin)
seed_minus = QtWidgets.QPushButton('-')
seed_minus.setFixedWidth(24)
seed_plus = QtWidgets.QPushButton('+')
seed_plus.setFixedWidth(24)
seed_h.addWidget(seed_minus)
seed_h.addWidget(seed_plus)
basic_layout.addRow('Seed', seed_container)
seed_minus.clicked.connect(lambda: [win.grass_seed_spin.setValue(max(win.grass_seed_spin.minimum(), win.grass_seed_spin.value() - win.grass_seed_spin.singleStep())), win.request_grass_preview()])
seed_plus.clicked.connect(lambda: [win.grass_seed_spin.setValue(min(win.grass_seed_spin.maximum(), win.grass_seed_spin.value() + win.grass_seed_spin.singleStep())), win.request_grass_preview()])
vbox.addWidget(basic_group)
# --- Grass Parameters ---
grass_params_group = QtWidgets.QGroupBox('Grass Parameters')
grass_params_layout = QtWidgets.QFormLayout(grass_params_group)
win.grass_density_spin = QtWidgets.QDoubleSpinBox()
win.grass_density_spin.setRange(0.0, 1.0)
win.grass_density_spin.setSingleStep(0.01)
win.grass_density_spin.setValue(0.5)
grass_params_layout.addRow('Density', win.grass_density_spin)
win.perlin_noise_amount_spin = QtWidgets.QDoubleSpinBox()
win.perlin_noise_amount_spin.setRange(0.0, 4.0)
win.perlin_noise_amount_spin.setSingleStep(0.01)
win.perlin_noise_amount_spin.setValue(0.5)
grass_params_layout.addRow('Perlin Amount', win.perlin_noise_amount_spin)
win.simple_noise_amount_spin = QtWidgets.QDoubleSpinBox()
win.simple_noise_amount_spin.setRange(0.0, 2.0)
win.simple_noise_amount_spin.setSingleStep(0.01)
win.simple_noise_amount_spin.setValue(0.5)
grass_params_layout.addRow('Simple Amount', win.simple_noise_amount_spin)
win.lightness_spin = QtWidgets.QDoubleSpinBox()
win.lightness_spin.setRange(0.0, 1.0)
win.lightness_spin.setSingleStep(0.01)
win.lightness_spin.setValue(0.0)
grass_params_layout.addRow('Lightness', win.lightness_spin)
vbox.addWidget(grass_params_group)
# No left-side Actions panel for grass; push controls to top
vbox.addStretch(1)
layout.addWidget(scroll)
preview_frame = QtWidgets.QFrame()
preview_layout = QtWidgets.QVBoxLayout(preview_frame)
title = QtWidgets.QLabel('GRASS NOISE PREVIEW')
title.setAlignment(Qt.AlignmentFlag.AlignCenter)
font = title.font()
font.setPointSize(14)
font.setBold(True)
title.setFont(font)
preview_layout.addWidget(title)
# Add export button above the progress bar (keeps it visually separate)
grass_btn_row = QtWidgets.QWidget()
grass_btn_layout = QtWidgets.QHBoxLayout(grass_btn_row)
grass_btn_layout.setContentsMargins(0, 0, 0, 0)
win.grass_export_btn = QtWidgets.QPushButton('Export Grass Map')
grass_btn_layout.addWidget(win.grass_export_btn)
preview_layout.addWidget(grass_btn_row)
# Progress bar placed above grass preview for visibility (below export button)
win.grass_export_progress = QtWidgets.QProgressBar()
win.grass_export_progress.setRange(0,100)
win.grass_export_progress.hide()
preview_layout.addWidget(win.grass_export_progress)
win.grass_preview_label = QtWidgets.QLabel()
win.grass_preview_label.setFixedSize(600,600)
win.grass_preview_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
win.grass_preview_label.setStyleSheet('background: #1e272e;')
preview_layout.addWidget(win.grass_preview_label, alignment=Qt.AlignmentFlag.AlignCenter)
# Install event filter so mouse pan/zoom events are received for grass preview
try:
win.grass_preview_label.installEventFilter(win)
except Exception:
logging.exception('Failed to install event filter on grass_preview_label')
layout.addWidget(preview_frame, stretch=1)
# Connections
win.grass_export_btn.clicked.connect(win.export_grass_map)
for w in (win.grass_scale_spin, win.grass_seed_spin,
win.grass_density_spin, win.perlin_noise_amount_spin, win.simple_noise_amount_spin, win.lightness_spin):
if isinstance(w, QtWidgets.QComboBox):
w.currentIndexChanged.connect(win.request_grass_preview)
else:
try:
w.valueChanged.connect(win.request_grass_preview)
except Exception:
pass
def build_landmass_ui(win, layout):
scroll = QtWidgets.QScrollArea()
scroll.setWidgetResizable(True)
scroll.setFixedWidth(420)
container = QtWidgets.QWidget()
scroll.setWidget(container)
vbox = QtWidgets.QVBoxLayout(container)
vbox.setContentsMargins(8,8,8,8)
vbox.setSpacing(12)
# expose the left controls container so visibility can be toggled
win.land_group = container
# Basic controls group
basic_group = QtWidgets.QGroupBox('Basic')
basic_layout = QtWidgets.QFormLayout(basic_group)
basic_layout.setLabelAlignment(QtCore.Qt.AlignmentFlag.AlignLeft)
win.land_size = QtWidgets.QSpinBox()
win.land_size.setRange(64,2048)
win.land_size.setValue(256)
try:
win.land_size.setButtonSymbols(QtWidgets.QAbstractSpinBox.ButtonSymbols.NoButtons)
except Exception:
pass
land_size_container = QtWidgets.QWidget()
land_size_h = QtWidgets.QHBoxLayout(land_size_container)
land_size_h.setContentsMargins(0,0,0,0)
land_size_h.addWidget(win.land_size)
land_size_minus = QtWidgets.QPushButton('-')
land_size_minus.setFixedWidth(24)
land_size_plus = QtWidgets.QPushButton('+')
land_size_plus.setFixedWidth(24)
land_size_h.addWidget(land_size_minus)
land_size_h.addWidget(land_size_plus)
basic_layout.addRow('Landmass Size', land_size_container)
land_size_minus.clicked.connect(lambda: [win.land_size.setValue(max(win.land_size.minimum(), win.land_size.value() - win.land_size.singleStep())), win.request_landmass_preview()])
land_size_plus.clicked.connect(lambda: [win.land_size.setValue(min(win.land_size.maximum(), win.land_size.value() + win.land_size.singleStep())), win.request_landmass_preview()])
win.land_proportion = QtWidgets.QDoubleSpinBox()
win.land_proportion.setRange(0.0,1.0)
win.land_proportion.setSingleStep(0.01)
win.land_proportion.setValue(0.6)
basic_layout.addRow('Land Proportion', win.land_proportion)
try:
win._link_slider_to_spinbox(win.land_proportion, basic_layout)
except Exception:
pass
win.plain_factor = QtWidgets.QDoubleSpinBox()
win.plain_factor.setRange(0.1,10.0)
win.plain_factor.setSingleStep(0.1)
win.plain_factor.setValue(2.5)
basic_layout.addRow('Plain Factor', win.plain_factor)
try:
win._link_slider_to_spinbox(win.plain_factor, basic_layout)
except Exception:
pass
win.shore_height = QtWidgets.QDoubleSpinBox()
win.shore_height.setRange(0.0,1.0)
win.shore_height.setSingleStep(0.01)
win.shore_height.setValue(0.05)
basic_layout.addRow('Shore Height', win.shore_height)
try:
win._link_slider_to_spinbox(win.shore_height, basic_layout)
except Exception:
pass
vbox.addWidget(basic_group)
# Noise controls group
noise_group = QtWidgets.QGroupBox('Noise')
noise_layout = QtWidgets.QFormLayout(noise_group)
noise_layout.setLabelAlignment(QtCore.Qt.AlignmentFlag.AlignLeft)
win.land_noise_scale = QtWidgets.QDoubleSpinBox()
win.land_noise_scale.setRange(1.0,1000.0)
win.land_noise_scale.setValue(100.0)
noise_layout.addRow('Noise Scale', win.land_noise_scale)
try:
win._link_slider_to_spinbox(win.land_noise_scale, noise_layout)
except Exception:
pass
win.land_octaves = QtWidgets.QSpinBox()
win.land_octaves.setRange(1,16)
win.land_octaves.setValue(6)
noise_layout.addRow('Octaves', win.land_octaves)
try:
win._link_slider_to_spinbox(win.land_octaves, noise_layout)
except Exception:
pass
win.land_seed = QtWidgets.QSpinBox()
win.land_seed.setRange(0,2 **31 -1)
win.land_seed.setValue(0)
try:
win.land_seed.setButtonSymbols(QtWidgets.QAbstractSpinBox.ButtonSymbols.NoButtons)
except Exception:
pass
land_seed_container = QtWidgets.QWidget()
land_seed_h = QtWidgets.QHBoxLayout(land_seed_container)
land_seed_h.setContentsMargins(0,0,0,0)
land_seed_h.addWidget(win.land_seed)
land_seed_minus = QtWidgets.QPushButton('-')
land_seed_minus.setFixedWidth(24)
land_seed_plus = QtWidgets.QPushButton('+')
land_seed_plus.setFixedWidth(24)
land_seed_h.addWidget(land_seed_minus)
land_seed_h.addWidget(land_seed_plus)
noise_layout.addRow('Seed', land_seed_container)
land_seed_minus.clicked.connect(lambda: [win.land_seed.setValue(max(win.land_seed.minimum(), win.land_seed.value() - win.land_seed.singleStep())), win.request_landmass_preview()])
land_seed_plus.clicked.connect(lambda: [win.land_seed.setValue(min(win.land_seed.maximum(), win.land_seed.value() + win.land_seed.singleStep())), win.request_landmass_preview()])
vbox.addWidget(noise_group)
# Heights controls group
heights_group = QtWidgets.QGroupBox('Heights')
heights_layout = QtWidgets.QFormLayout(heights_group)
heights_layout.setLabelAlignment(QtCore.Qt.AlignmentFlag.AlignLeft)
win.land_min_height_spin = QtWidgets.QDoubleSpinBox()
win.land_min_height_spin.setRange(-2.0, 2.0)
win.land_min_height_spin.setSingleStep(0.1)
win.land_min_height_spin.setValue(1.0)
heights_layout.addRow('Min Height', win.land_min_height_spin)
try:
win._link_slider_to_spinbox(win.land_min_height_spin, heights_layout)
except Exception:
pass
try:
win.land_min_height_spin.valueChanged.connect(win.request_landmass_preview)
except Exception:
pass
win.land_max_height_spin = QtWidgets.QDoubleSpinBox()
win.land_max_height_spin.setRange(0.0, 2.0)
win.land_max_height_spin.setSingleStep(0.1)
win.land_max_height_spin.setValue(0.5)
heights_layout.addRow('Max Height', win.land_max_height_spin)
try:
win._link_slider_to_spinbox(win.land_max_height_spin, heights_layout)
except Exception:
pass
try:
win.land_max_height_spin.valueChanged.connect(win.request_landmass_preview)
except Exception:
pass
vbox.addWidget(heights_group)
# Export helper group (export buttons remain in preview area)
export_group = QtWidgets.QGroupBox('Export')
export_layout = QtWidgets.QVBoxLayout(export_group)
export_layout.addWidget(QtWidgets.QLabel('Use the buttons on the preview area to export maps.'))
vbox.addWidget(export_group)
# Keep a hidden cancel button available for exports (placed in controls)
win.cancel_export_btn = QtWidgets.QPushButton('Cancel Export')
win.cancel_export_btn.setEnabled(False)
win.cancel_export_btn.hide()
vbox.addWidget(win.cancel_export_btn)
vbox.addStretch(1)
layout.addWidget(scroll)
preview_frame = QtWidgets.QFrame()
preview_layout = QtWidgets.QVBoxLayout(preview_frame)
title = QtWidgets.QLabel('LANDMASS PREVIEW')
title.setAlignment(Qt.AlignmentFlag.AlignCenter)
font = title.font()
font.setPointSize(14)
font.setBold(True)
title.setFont(font)
preview_layout.addWidget(title)
# Add export button above the progress bar (keeps it visually separate)
land_btn_row = QtWidgets.QWidget()
land_btn_layout = QtWidgets.QHBoxLayout(land_btn_row)
land_btn_layout.setContentsMargins(0, 0, 0, 0)
win.land_export_btn = QtWidgets.QPushButton('Export Landmass Map')
land_btn_layout.addWidget(win.land_export_btn)
# Greyscale export button placed next to color export
win.land_export_grey_btn = QtWidgets.QPushButton('Export Greyscale Landmass Map')
land_btn_layout.addWidget(win.land_export_grey_btn)
preview_layout.addWidget(land_btn_row)
# Progress bar placed above landmass preview for visibility (below export button)
win.land_export_progress = QtWidgets.QProgressBar()
win.land_export_progress.setRange(0,100)
win.land_export_progress.hide()
preview_layout.addWidget(win.land_export_progress)
win.land_preview_label = QtWidgets.QLabel()
win.land_preview_label.setFixedSize(600,600)
win.land_preview_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
win.land_preview_label.setStyleSheet('background: #1e272e;')
preview_layout.addWidget(win.land_preview_label, alignment=Qt.AlignmentFlag.AlignCenter)
layout.addWidget(preview_frame, stretch=1)
win.land_export_btn.clicked.connect(win.export_landmass_map)
try:
# Connect greyscale export button to corresponding handler in main window
win.land_export_grey_btn.clicked.connect(win.export_landmass_map_greyscale)
except Exception:
pass
for w in (win.land_size, win.land_proportion, win.plain_factor, win.shore_height,
win.land_noise_scale, win.land_octaves, win.land_seed):
try:
w.valueChanged.connect(win.request_landmass_preview)
except Exception:
pass
def build_image_ui(win, layout):
controls = QtWidgets.QFrame()
controls.setFixedWidth(420)
vbox = QtWidgets.QVBoxLayout(controls)
win.import_btn = QtWidgets.QPushButton('Import Image')
vbox.addWidget(win.import_btn)
win.import_btn.setToolTip('Import an image to convert into a heightmap')
vbox.addWidget(QtWidgets.QLabel('Target Size'))
win.image_size_spin = QtWidgets.QSpinBox()
win.image_size_spin.setRange(64,4096)
win.image_size_spin.setValue(512)
vbox.addWidget(win.image_size_spin)
win.image_size_spin.setToolTip('Maximum target size when importing images (aspect preserved)')
vbox.addWidget(QtWidgets.QLabel('Red Channel Value'))
win.red_channel_value = QtWidgets.QDoubleSpinBox()
win.red_channel_value.setRange(0.0,1.0)
win.red_channel_value.setSingleStep(0.01)
win.red_channel_value.setValue(0.5)
vbox.addWidget(win.red_channel_value)
win.red_channel_value.setToolTip('Scale applied to the red channel when converting to grayscale')
vbox.addWidget(QtWidgets.QLabel('Red Lightness'))
win.red_lightness = QtWidgets.QDoubleSpinBox()
win.red_lightness.setRange(0.0,1.0)
win.red_lightness.setSingleStep(0.01)
win.red_lightness.setValue(0.5)
vbox.addWidget(win.red_lightness)
win.red_lightness.setToolTip('Brightness adjustment applied to the red channel before conversion')
win.invert_red = QtWidgets.QCheckBox('Invert Red')
vbox.addWidget(win.invert_red)
win.invert_red.setToolTip('Invert the red channel before conversion')
vbox.addWidget(QtWidgets.QLabel('Green Overlay Alpha'))
win.green_channel_value = QtWidgets.QDoubleSpinBox()
win.green_channel_value.setRange(0.0,1.0)
win.green_channel_value.setSingleStep(0.01)
win.green_channel_value.setValue(0.5)
vbox.addWidget(win.green_channel_value)
win.green_channel_value.setToolTip('Alpha (0..1) for green overlay on imported images')
vbox.addWidget(QtWidgets.QLabel('Gaussian Blur'))
win.gaussian_blur = QtWidgets.QDoubleSpinBox()
win.gaussian_blur.setRange(0.0,50.0)
win.gaussian_blur.setSingleStep(0.5)
win.gaussian_blur.setValue(0.0)
vbox.addWidget(win.gaussian_blur)
win.gaussian_blur.setToolTip('Apply Gaussian blur to the imported image (pixels)')
win.convert_gray_btn = QtWidgets.QPushButton('Convert to Grayscale (Red)')
vbox.addWidget(win.convert_gray_btn)
win.convert_gray_btn.setToolTip('Convert the imported image to a red-channel grayscale preview')
win.export_image_btn = QtWidgets.QPushButton('Export Image')
vbox.addWidget(win.export_image_btn)
win.export_image_btn.setToolTip('Save the currently processed image to disk')
vbox.addStretch()
layout.addWidget(controls)
preview_frame = QtWidgets.QFrame()
preview_layout = QtWidgets.QVBoxLayout(preview_frame)
title = QtWidgets.QLabel('IMAGE PREVIEW')
title.setAlignment(Qt.AlignmentFlag.AlignCenter)
font = title.font()
font.setPointSize(14)
font.setBold(True)
title.setFont(font)
preview_layout.addWidget(title)
win.image_canvas = QtWidgets.QLabel()
win.image_canvas.setFixedSize(600,600)
win.image_canvas.setAlignment(Qt.AlignmentFlag.AlignCenter)
win.image_canvas.setStyleSheet('background: #1e272e;')
preview_layout.addWidget(win.image_canvas, alignment=Qt.AlignmentFlag.AlignCenter)
win.image_canvas.setToolTip('Preview of the imported/processed image')
layout.addWidget(preview_frame, stretch=1)
win.import_btn.clicked.connect(win._import_image)
win.red_channel_value.valueChanged.connect(win._update_image_preview)
win.red_lightness.valueChanged.connect(win._update_image_preview)
win.green_channel_value.valueChanged.connect(win._update_image_preview)
win.invert_red.stateChanged.connect(win._update_image_preview)
win.gaussian_blur.valueChanged.connect(win._update_image_preview)
win.image_size_spin.valueChanged.connect(win._update_image_preview)
win.convert_gray_btn.clicked.connect(win._convert_to_grayscale)
win.export_image_btn.clicked.connect(win._export_image)