Skip to content

Commit

Permalink
Code cleanup and minor GUI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Buras committed May 4, 2017
1 parent 22768ad commit 8a7e620
Show file tree
Hide file tree
Showing 10 changed files with 1,452 additions and 201 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ Archived/Amidst Seed Hunter/StringSize.au3
Archived/Amidst Seed Hunter/Toast.au3
Archived/Toast.zip
Settings.ini
Settings.ini
258 changes: 93 additions & 165 deletions AmidstSeedHunter.au3
Original file line number Diff line number Diff line change
Expand Up @@ -22,175 +22,21 @@ AutoItSetOption("MustDeclareVars", 1)
#include <GuiConstantsEx.au3>
#include <GuiEdit.au3>
#include <GuiListBox.au3>
#include <GuiMenu.au3>
#include <GuiTab.au3>
#include <StaticConstants.au3>
#include <String.au3>
#include <WinAPI.au3>
#include <WinAPIDlg.au3>
#include <WindowsConstants.au3>
#include "Include\Toast.au3"
#include "Include\GuiFunctions.au3"
#include "Include\AmidstFunctions.au3"
#include "Include\SearchFunctions.au3"
#include "Include\PresetFunctions.au3"

#Region Globals
Global $debugBuffer, $searchResults, $newSearch
Global $versionNumber = "0.2.2"

; GUI control globals
Global $form, $tabSet, $biomesTab, $structuresTab, $optionsTab, $resultsTab, $debugTab
Global $cancelQuitButton, $beginSearchButton, $currentTab, $previousTab

Global $availableBiomeList, $includedBiomeList, $excludedBiomeList
Global $availableBiomeLabel, $includedBiomeLabel, $excludedBiomeLabel
Global $includeBiomeButton, $removeIncludedBiomeButton, $removeAllIncludedBiomeButton
Global $excludeBiomeButton, $removeExcludedBiomeButton, $removeAllExcludedBiomeButton
Global $preset0Button, $preset1Button, $preset2Button, $preset3Button, $preset4Button

Global $availableStructList, $includedStructList, $excludedStructList
Global $availableStructLabel, $includedStructLabel, $excludedStructLabel
Global $includeStructButton, $removeIncludedStructButton, $removeAllIncludedStructButton
Global $excludeStructButton, $removeExcludedStructButton, $removeAllExcludedStructButton
Global $preset5Button, $preset6Button, $preset7Button, $preset8Button, $preset9Button

Global $seedOptionsGroup, $searchOptionsGroup, $otherOptionsGroup
Global $useRandomSeedsRadio, $useSeedListFileRadio, $seedListFileLabel, $seedListFileInput
Global $seedListFileBrowseButton, $seedOffsetLabel, $seedOffsetInput, $seedListInfoLabel
Global $searchForBiomeChkbx, $searchForStructChkbx, $saveResultsToFileChkbx
Global $includeRejectedSeedsChkbx, $resultsOutputFileLabel, $resultsOutputFileInput
Global $resultsOutputFileBrowseButton, $overwriteOutputFileChkbx
Global $maxSeedsLabel, $maxSeedsInput, $numSeedsToEvaluateLabel, $numSeedsToEvaluateInput
Global $guidedAmidstSetupChkbx, $saveScreenshotChkbx, $rememberAmidstWinSizeChkbx
Global $macLinuxCompatChkbx, $showProgressPopupChkbx, $showResultsTabChkbx, $enableDebugChkbx
Global $restoreHiddenDialogsButton, $reloadSettingsINIButton, $resetAllOptionsButton
Global $removePresetButton

Global $resultsEdit, $clearResultsButton, $copyResultsButton, $saveResultsButton

Global $debugEdit, $clearDebugButton, $copyDebugButton, $saveDebugButton

Global $biomeTabControlsArray = []
Global $structTabControlsArray = []
Global $optionsTabControlsArray = []
Global $resultsTabControlsArray = []
Global $debugTabControlsArray = []

Global $removePresetsForm = -1
Global $msg, $cancelButton, $okButton
Global $preset0Chkbx, $preset1Chkbx, $preset2Chkbx, $preset3Chkbx, $preset4Chkbx
Global $preset5Chkbx, $preset6Chkbx, $preset7Chkbx, $preset8Chkbx, $preset9Chkbx
Global $presetsSet = []

; Settings globals
Global $settingsINIFile, $useRandomSeeds, $seedListFile, $seedOffset, $seedFileInfo
Global $searchForBiomes, $searchForStructures, $saveSearchResultsToFile, $includeRejectedSeeds
Global $maxSeedsToEvaluate, $seedsToFind, $resultsFile, $overwriteResults, $guidedAmidstSetup
Global $saveScreenshots, $rememberAmidstWindowSize, $showProgressPopupWindow, $macLinuxCompatibility
Global $showResultsTab, $enableDebugging
Global $amidstSetupComplete = False
Global $presetArray = []
Global $biomeArray = []
Global $structArray = []
Global $amidstWindowTitle = "Amidst v4.2"

Func UpdateGlobals()
$settingsINIFile = @ScriptDir & "\Settings.ini"

If FileExists($settingsINIFile) Then
$useRandomSeeds = IniRead($settingsINIFile, "Options", "UseRandomSeeds", 1)
$seedListFile = IniRead($settingsINIFile, "Options", "SeedListFile", "")
$seedOffset = IniRead($settingsINIFile, "Options", "SeedOffset", 0)
$seedFileInfo = IniRead($settingsINIFile, "Options", "SeedFileInfo", "")
$searchForBiomes = IniRead($settingsINIFile, "Options", "SearchForBiomes", 1)
$saveSearchResultsToFile = IniRead($settingsINIFile, "Options", "SaveSearchResultsToFile", 0)
$searchForStructures = IniRead($settingsINIFile, "Options", "SearchForStructures", 0)
$includeRejectedSeeds = IniRead($settingsINIFile, "Options", "IncludeRejectedSeeds", 0)
$maxSeedsToEvaluate = IniRead($settingsINIFile, "Options", "MaxSeedsToEvaluate", 100)
$seedsToFind = IniRead($settingsINIFile, "Options", "SeedsToFind", 1)
$resultsFile = IniRead($settingsINIFile, "Options", "ResultsFile", "")
$overwriteResults = IniRead($settingsINIFile, "Options", "OverwriteResults", 0)
$guidedAmidstSetup = IniRead($settingsINIFile, "Options", "GuidedAmidstSetup", 1)
$saveScreenshots = IniRead($settingsINIFile, "Options", "SaveScreenshots", 0)
$rememberAmidstWindowSize = IniRead($settingsINIFile, "Options", "RememberAmidstWindowSize", 0)
$showProgressPopupWindow = IniRead($settingsINIFile, "Options", "ShowProgressPopupWindow", 1)
$macLinuxCompatibility = IniRead($settingsINIFile, "Options", "MacLinuxCompatibility", 0)
$showResultsTab = IniRead($settingsINIFile, "Options", "ShowResultsTab", 0)
$enableDebugging = IniRead($settingsINIFile, "Options", "EnableDebugging", 0)
$presetArray = IniReadSection($settingsINIFile, "Presets")
$biomeArray = IniReadSection($settingsINIFile, "BiomeList")
$structArray = IniReadSection($settingsINIFile, "StructureList")
Else
DoResetINIFileToDefaults(False) ; Create INI File
IniWriteSection($settingsINIFile, "Presets", "Preset0Name=" & @LF & "Preset0Include=" & @LF & _
"Preset0Exclude=" & @LF & "Preset1Name=" & @LF & "Preset1Include=" & @LF & "Preset1Exclude=" & _
@LF & "Preset2Name=" & @LF & "Preset2Include=" & @LF & "Preset2Exclude=" & @LF & "Preset3Name=" _
& @LF & "Preset3Include=" & @LF & "Preset3Exclude=" & @LF & "Preset4Name=" & @LF & _
"Preset4Include=" & @LF & "Preset4Exclude=" & @LF & "Preset5Name=" & @LF & "Preset5Include=" & _
@LF & "Preset5Exclude=" & @LF & "Preset6Name=" & @LF & "Preset6Include=" & @LF & _
"Preset6Exclude=" & @LF & "Preset7Name=" & @LF & "Preset7Include=" & @LF & "Preset7Exclude=" & _
@LF & "Preset8Name=" & @LF & "Preset8Include=" & @LF & "Preset8Exclude=" & @LF & "Preset9Name=" _
& @LF & "Preset9Include=" & @LF & "Preset9Exclude=")
IniWriteSection($settingsINIFile, "BiomeList", "Beach=0xFADE55" & @LF & "Beach M=0xFFFF7D" & @LF & _
"Birch Forest=0x307444" & @LF & "Birch Forest Hills=0x1F5F32" & @LF & _
"Birch Forest Hills M=0x47875A" & @LF & "Birch Forest M=0x589C6C" & @LF & "Cold Beach=0xFAF0C0" _
& @LF & "Cold Beach M=0xFFFFE8" & @LF & "Cold Taiga=0x31554A" & @LF & "Cold Taiga Hills=0x243F36" _
& @LF & "Cold Taiga Hills M=0x4C675E" & @LF & "Cold Taiga M=0x597D72" & @LF & "Deep Ocean=0x000030" _
& @LF & "Deep Ocean M=0x282858" & @LF & "Desert=0xFA9418" & @LF & "Desert Hills=0xD25F12" & @LF & _
"Desert Hills M=0xFA873A" & @LF & "Desert M=0xFFBC40" & @LF & "Extreme Hills+=0x507050" & @LF & _
"Extreme Hills=0x606060" & @LF & "Extreme Hills Edge=0x72789A" & @LF & _
"Extreme Hills Edge M=0x9AA0C2" & @LF & "Extreme Hills M=0x888888" & @LF & _
"Extreme Hills+ M=0x789878" & @LF & "Flower Forest=0x2D8E49" & @LF & "Forest=0x056621" & @LF & _
"Forest Hills=0x22551C" & @LF & "Forest Hills M=0x4A7D44" & @LF & "Frozen Ocean=0x9090A0" & @LF _
& "Frozen Ocean M=0xB8B8C8" & @LF & "Frozen River=0xA0A0FF" & @LF & "Frozen River M=0xC8C8FF" & _
@LF & "Ice Mountains=0xA0A0A0" & @LF & "Ice Mountains M=0xC8C8C8" & @LF & "Ice Plains=0xFFFFFF" & _
@LF & "Ice Plains Spikes=0xB4DCDC" & @LF & "Jungle=0x537B09" & @LF & "Jungle Edge=0x628B17" & @LF _
& "Jungle Edge M=0x8AB33F" & @LF & "Jungle Hills=0x2C4205" & @LF & "Jungle Hills M=0x546A2D" & @LF _
& "Jungle M=0x7BA331" & @LF & "Mega Spruce Taiga=0x818E79" & @LF & _
"Mega Spruce Taiga (Hills)=0x6D7766" & @LF & "Mega Taiga=0x596651" & @LF & _
"Mega Taiga Hills=0x454F3E" & @LF & "Mesa=0xD94515" & @LF & "Mesa (Bryce)=0xFF6D3D" & @LF & _
"Mesa Plateau=0xCA8C65" & @LF & "Mesa Plateau F=0xB09765" & @LF & "Mesa Plateau F M=0xD8BF8D" & @LF _
& "Mesa Plateau M=0xF2B48D" & @LF & "Mushroom Island=0xFF00FF" & @LF & "Mushroom Island M=0xFF28FF" _
& @LF & "Mushroom Island Shore=0xA000FF" & @LF & "Mushroom Island Shore M=0xC828FF" & @LF & _
"Ocean=0x000070" & @LF & "Ocean M=0x282898" & @LF & "Plains=0x8DB360" & @LF & "River=0x0000FF" & @LF _
& "River M=0x2828FF" & @LF & "Roofed Forest=0x40511A" & @LF & "Roofed Forest M=0x687942" & @LF & _
"Savanna=0xBDB25F" & @LF & "Savanna M=0xE5DA87" & @LF & "Savanna Plateau=0xA79D64" & @LF & _
"Savanna Plateau M=0xCFC58C" & @LF & "Stone Beach=0xA2A284" & @LF & "Stone Beach M=0xCACAAC" & @LF & _
"Sunflower Plains=0xB5DB88" & @LF & "Swampland=0x07F9B2" & @LF & "Swampland M=0x2FFFDA" & @LF & _
"Taiga=0x0B6659" & @LF & "Taiga Hills=0x163933" & @LF & "Taiga Hills M=0x3E615B" & @LF & _
"Taiga M=0x338E81")
IniWriteSection($settingsINIFile, "StructureList", "Desert Temple=0xBBB36D" & @LF & "Igloo=0xA7B8FF" & @LF & _
"Jungle Temple=0x364636" & @LF & "Mineshaft=0x76613C" & @LF & "Nether Fortress=0x311E24" & @LF & _
"Ocean Monument=0x285A45" & @LF & "Stronghold=0x4D5A35" & @LF & "Village=0x75472F" & @LF & _
"Witch Hut=0x0F41FB")
UpdateGlobals()
EndIf
EndFunc
#EndRegion

#Region Debug Functions
Func DebugWrite($data)
If $enableDebugging = 1 Then
Dim $timestampedData = GetTimestamp() & " >> " & $data & @CRLF
If @Compiled = 0 Then ConsoleWrite($timestampedData & @CRLF)
If $debugEdit = Null Then ; Debug edit control does not exist
$debugBuffer = $debugBuffer & $timestampedData
Else
_GUICtrlEdit_AppendText($debugEdit, $debugBuffer)
_GUICtrlEdit_AppendText($debugEdit, $timestampedData)

; Scroll to the bottom of the control
_GUICtrlEdit_LineScroll($debugEdit, 0, _GUICtrlEdit_GetLineCount($debugEdit))

; Buffer is no longer needed, since control exists
$debugBuffer = ""
EndIf
EndIf
EndFunc

Func GetTimestamp()
Return _Date_Time_SystemTimeToDateTimeStr(_Date_Time_GetLocalTime())
EndFunc
#EndRegion
#include "Include\ASH_Amidst.au3"
#include "Include\ASH_Debug.au3"
#include "Include\ASH_Globals.au3"
#include "Include\ASH_GUI.au3"
#include "Include\ASH_Presets.au3"
#include "Include\ASH_Search.au3"
#include "Include\ASH_Toast.au3" ; This is a lightly modified version of Melba23's Toast UDF

Func Main()
UpdateGlobals()
Expand All @@ -200,24 +46,34 @@ Func Main()
DebugWrite("Initializing main GUI")
DoBuildMainGUI()

; Register message handlers
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

$previousTab = _GUICtrlTab_GetCurFocus($tabSet)

; Main loop
While 1
$msg = GUIGetMsg($GUI_EVENT_ARRAY)

;_ArrayDisplay($msg)

If $msg[1] = $form Then
Switch $msg[0]
Case $GUI_EVENT_CLOSE
Exit
Case $GUI_EVENT_SECONDARYUP ; Right-click released
DoRightClickAction()
Case $cancelQuitButton
DebugWrite("Cancel/Quit button pressed")
Exit
Case $beginSearchButton
DebugWrite("Begin Search button pressed")
DoSearch()
Case $advancedSearchMenuItem
DoAdvancedSearch()
;Case $includedBiomeGroupButton
; DoBiomeGroupPopupMenu($includedBiomeGroupButton)
;Case $excludedBiomeGroupButton
; DoBiomeGroupPopupMenu($excludedBiomeGroupButton)
Case $includeBiomeButton
DebugWrite("Include biome button pressed")
DoMoveListItems($availableBiomeList, $includedBiomeList)
Expand All @@ -241,18 +97,33 @@ Func Main()
Case $preset0Button
DebugWrite("Preset 0 button pressed")
DoPresetButton(0)
Case $removePreset0
DoRemovePreset(0, True)
DoUpdatePresets()
Case $preset1Button
DebugWrite("Preset 1 button pressed")
DoPresetButton(1)
Case $removePreset1
DoRemovePreset(1, True)
DoUpdatePresets()
Case $preset2Button
DebugWrite("Preset 2 button pressed")
DoPresetButton(2)
Case $removePreset2
DoRemovePreset(2, True)
DoUpdatePresets()
Case $preset3Button
DebugWrite("Preset 3 button pressed")
DoPresetButton(3)
Case $removePreset3
DoRemovePreset(3, True)
DoUpdatePresets()
Case $preset4Button
DebugWrite("Preset 4 button pressed")
DoPresetButton(4)
Case $removePreset4
DoRemovePreset(4, True)
DoUpdatePresets()
Case $includeStructButton
DebugWrite("Include structure button pressed")
DoMoveListItems($availableStructList, $includedStructList)
Expand All @@ -276,18 +147,33 @@ Func Main()
Case $preset5Button
DebugWrite("Preset 5 button pressed")
DoPresetButton(5)
Case $removePreset5
DoRemovePreset(5, True)
DoUpdatePresets()
Case $preset6Button
DebugWrite("Preset 6 button pressed")
DoPresetButton(6)
Case $removePreset6
DoRemovePreset(6, True)
DoUpdatePresets()
Case $preset7Button
DebugWrite("Preset 7 button pressed")
DoPresetButton(7)
Case $removePreset7
DoRemovePreset(7, True)
DoUpdatePresets()
Case $preset8Button
DebugWrite("Preset 8 button pressed")
DoPresetButton(8)
Case $removePreset8
DoRemovePreset(8, True)
DoUpdatePresets()
Case $preset9Button
DebugWrite("Preset 9 button pressed")
DoPresetButton(9)
Case $removePreset9
DoRemovePreset(9, True)
DoUpdatePresets()
Case $useRandomSeedsRadio
If $useRandomSeeds = 0 Then
IniWrite($settingsINIFile, "Options", "UseRandomSeeds", 1)
Expand Down Expand Up @@ -326,6 +212,18 @@ Func Main()
UpdateGlobals()
DebugWrite("SearchForBiomes set to '" & $searchForBiomes & "'")
EndIf
Case $enableBiomeGroupsChkbx
If $enableBiomeGroups = 0 Then
IniWrite($settingsINIFile, "Options", "EnableBiomeGroups", 1)
DoAddBiomeGroupsToList()
UpdateGlobals()
DebugWrite("EnableBiomeGroups set to '" & $enableBiomeGroups & "'")
Else
IniWrite($settingsINIFile, "Options", "EnableBiomeGroups", 0)
DoRemoveBiomeGroupsFromList()
UpdateGlobals()
DebugWrite("EnableBiomeGroups set to '" & $enableBiomeGroups & "'")
EndIf
Case $searchForStructChkbx
If $searchForStructures = 0 Then
IniWrite($settingsINIFile, "Options", "SearchForStructures", 1)
Expand Down Expand Up @@ -579,6 +477,36 @@ Func Main()
; Do nothing
EndSwitch
EndIf



#cs
; Show a tooltip for biome group items in the AvailableBiomeList
If $enableBiomeGroups = 1 Then
; Tooltip on hover
Dim $cursorInfo = GUIGetCursorInfo($form)
If $cursorInfo[4] = GUICtrlGetHandle($availableBiomeList) Then
;Dim $itemIndex = _GUICtrlListBox_ItemFromPoint($availableBiomeList, $cursorInfo[0] - 8, $cursorInfo[1] - 55)
Dim $itemIndex = _GUICtrlListBox_GetSelItems($availableBiomeList)
If UBound($itemIndex) <> 2 Then
ToolTip("")
Else
Dim $itemText = _GUICtrlListBox_GetText($availableBiomeList, $itemIndex[1])
Dim $itemLeft3Letters = StringLeft($itemText, 3)
If $itemLeft3Letters = "Any" Or $itemLeft3Letters = "All" Then
Dim $index = _ArraySearch($biomeGroupArray, $itemText)
Dim $tooltip = $biomeGroupArray[$index][1]
ToolTip($tooltip)
EndIf
EndIf
Else
ToolTip("")
EndIf
Else
ToolTip("")
EndIf
#ce
Wend
EndFunc

Expand Down
9 changes: 4 additions & 5 deletions Include/AmidstFunctions.au3 → Include/ASH_Amidst.au3
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
; =============================================================================
; Amidst Seed Hunter - Amidst Functions (AmidstFunctions.au3)
; Amidst Seed Hunter - Amidst (ASH_Amidst.au3)
;
; Author: Azuntik ([email protected])
; Date: 2017.4.22
; Download: https://github.com/azuntik/Amidst-Seed-Hunter/releases
; Author: Azuntik
; Date: 2017.5.2
; License: CC BY-NC-SA 4.0 (https://creativecommons.org/licenses/by-nc-sa/4.0/)
;
; For use with Amidst v4.2 (https://github.com/toolbox4minecraft/amidst).
; This file is part of the Amidst Seed Hunter project
; =============================================================================

Func AmidstIsRunning()
Expand Down
Loading

0 comments on commit 8a7e620

Please sign in to comment.