From 5fb764e4b5cd603c63e638f912a4c39772db8480 Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Sun, 28 Oct 2018 14:13:39 -0700 Subject: Basic working UI --- Source/Main.cpp | 225 ++++++++++++++++++++---------------------- Source/Main.h | 3 - Source/Memory.h | 2 +- Source/Randomizer.cpp | 50 ++++------ Source/Randomizer.h | 2 + Source/Source.vcxproj | 3 +- Source/Source.vcxproj.filters | 3 - 7 files changed, 128 insertions(+), 160 deletions(-) delete mode 100644 Source/Main.h diff --git a/Source/Main.cpp b/Source/Main.cpp index 4748b73..5c7cefa 100644 --- a/Source/Main.cpp +++ b/Source/Main.cpp @@ -2,177 +2,162 @@ // #include "stdafx.h" -#include "Main.h" +#include "resource.h" +#include "tchar.h" +#include "Randomizer.h" +#include +#include +#include +#include #define MAX_LOADSTRING 100 +#define IDC_RANDOMIZE 0x464 -// Global Variables: -HINSTANCE hInst; // current instance -WCHAR szTitle[MAX_LOADSTRING]; // The title bar text -WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name +HINSTANCE hInst; +WCHAR szWindowClass[MAX_LOADSTRING]; +HWND hwndSeed; +std::shared_ptr randomizer; -// Forward declarations of functions included in this code module: +// Forward declares ATOM MyRegisterClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); -int APIENTRY wWinMain(_In_ HINSTANCE hInstance, - _In_opt_ HINSTANCE hPrevInstance, - _In_ LPWSTR lpCmdLine, - _In_ int nCmdShow) +int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) { - UNREFERENCED_PARAMETER(hPrevInstance); - UNREFERENCED_PARAMETER(lpCmdLine); - - // TODO: Place code here. - - // Initialize global strings - LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); - LoadStringW(hInstance, IDC_SOURCE, szWindowClass, MAX_LOADSTRING); + LoadStringW(hInstance, IDC_SOURCE, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); - - // Perform application initialization: - if (!InitInstance (hInstance, nCmdShow)) - { + if (!InitInstance(hInstance, nCmdShow)) { return FALSE; } - - HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SOURCE)); + randomizer = std::make_shared(); + if (randomizer == nullptr) { + return FALSE; + } MSG msg; - - // Main message loop: - while (GetMessage(&msg, nullptr, 0, 0)) + while (!GetMessage(&msg, nullptr, 0, 0) == 0) { - if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } + TranslateMessage(&msg); + DispatchMessage(&msg); } return (int) msg.wParam; } - - -// -// FUNCTION: MyRegisterClass() -// -// PURPOSE: Registers the window class. -// ATOM MyRegisterClass(HINSTANCE hInstance) { - WNDCLASSEXW wcex; - - wcex.cbSize = sizeof(WNDCLASSEX); - - wcex.style = CS_HREDRAW | CS_VREDRAW; - wcex.lpfnWndProc = WndProc; - wcex.cbClsExtra = 0; - wcex.cbWndExtra = 0; - wcex.hInstance = hInstance; - wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SOURCE)); - wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); - wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); - wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_SOURCE); - wcex.lpszClassName = szWindowClass; - wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); + WNDCLASSEXW wcex = { + sizeof(WNDCLASSEX), + CS_HREDRAW | CS_VREDRAW, + WndProc, + 0, + 0, + hInstance, + LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SOURCE)), + LoadCursor(nullptr, IDC_ARROW), + (HBRUSH)(COLOR_WINDOW+1), + MAKEINTRESOURCEW(IDC_SOURCE), + szWindowClass, + LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)), + }; return RegisterClassExW(&wcex); } -// -// FUNCTION: InitInstance(HINSTANCE, int) -// -// PURPOSE: Saves instance handle and creates main window -// -// COMMENTS: -// -// In this function, we save the instance handle in a global variable and -// create and display the main program window. -// BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { - hInst = hInstance; // Store instance handle in our global variable + hInst = hInstance; // Store instance handle in our global variable - HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, + WCHAR szTitle[MAX_LOADSTRING]; + LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); + HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr); - if (!hWnd) - { - return FALSE; - } - - ShowWindow(hWnd, nCmdShow); - UpdateWindow(hWnd); - - return TRUE; + if (!hWnd) + { + return FALSE; + } + + LoadLibrary(L"Msftedit.dll"); + HWND label = CreateWindow(L"BUTTON", L"Enter a seed:", + WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, + 10, 10, 100, 26, hWnd, NULL, hInst, NULL); + + hwndSeed = CreateWindowEx(0, MSFTEDIT_CLASS, L"", + ES_MULTILINE | WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP, + 120, 10, 50, 26, hWnd, NULL, hInst, NULL); + + HWND hwndRandomize = CreateWindow(L"BUTTON", L"Randomize", + WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, + 180, 10, 100, 26, hWnd, (HMENU)IDC_RANDOMIZE, hInst, NULL); + + HDC hdc = GetDC(hWnd); + RECT rect; + GetClientRect(hWnd, &rect); + LPCWSTR text = L"this Window cannot be used"; + DrawText(hdc, text, static_cast(wcslen(text)), &rect, DT_CENTER | DT_VCENTER); + ReleaseDC(hWnd, hdc); + + ShowWindow(hWnd, nCmdShow); + UpdateWindow(hWnd); + return TRUE; } -// -// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) -// -// PURPOSE: Processes messages for the main window. -// -// WM_COMMAND - process the application menu -// WM_PAINT - Paint the main window -// WM_DESTROY - post a quit message and return -// -// LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - switch (message) - { - case WM_COMMAND: - { - int wmId = LOWORD(wParam); - // Parse the menu selections: - switch (wmId) - { - case IDM_ABOUT: - DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); - break; - case IDM_EXIT: - DestroyWindow(hWnd); - break; - default: - return DefWindowProc(hWnd, message, wParam, lParam); - } - } - break; - case WM_PAINT: + if (WM_COMMAND == WM_DESTROY) { + PostQuitMessage(0); + } else { + int wmId = LOWORD(wParam); + // Parse the menu selections: + switch (wmId) { - PAINTSTRUCT ps; - HDC hdc = BeginPaint(hWnd, &ps); - // TODO: Add any drawing code that uses hdc here... - EndPaint(hWnd, &ps); + case IDM_ABOUT: + DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); + break; + case IDC_RANDOMIZE: + { + std::wstring text(100, '\0'); + GetWindowText(hwndSeed, &text[0], 100); + int seed = 0; + if (wcslen(text.c_str()) == 0) { + srand(static_cast(time(nullptr))); // Seed from the time in milliseconds + rand(); + seed = rand() % 100000; + std::wstring seedString = std::to_wstring(seed); + SetWindowText(hwndSeed, seedString.c_str()); + } else { + seed = _wtoi(text.c_str()); + } + randomizer->Randomize(seed); + + break; + } + case IDM_EXIT: + DestroyWindow(hWnd); + break; + default: + return DefWindowProc(hWnd, message, wParam, lParam); } - break; - case WM_DESTROY: - PostQuitMessage(0); - break; - default: - return DefWindowProc(hWnd, message, wParam, lParam); - } - return 0; + } + return DefWindowProc(hWnd, message, wParam, lParam); } -// Message handler for about box. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { UNREFERENCED_PARAMETER(lParam); switch (message) { case WM_INITDIALOG: - return (INT_PTR)TRUE; + return TRUE; case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { EndDialog(hDlg, LOWORD(wParam)); - return (INT_PTR)TRUE; + return TRUE; } break; } diff --git a/Source/Main.h b/Source/Main.h deleted file mode 100644 index d00d47e..0000000 --- a/Source/Main.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include "resource.h" diff --git a/Source/Memory.h b/Source/Memory.h index 8e8bbc3..53fa1e0 100644 --- a/Source/Memory.h +++ b/Source/Memory.h @@ -39,7 +39,7 @@ public: } ThrowError(); } - + private: void ThrowError(); diff --git a/Source/Randomizer.cpp b/Source/Randomizer.cpp index 75b3cf7..b8462e5 100644 --- a/Source/Randomizer.cpp +++ b/Source/Randomizer.cpp @@ -6,7 +6,6 @@ This seems to cause crashes when pivots appear elsewhere in the world. * Some panels are impossible casually: (idc, I think) ** Town Stars, Invisible dots - * Shadows burn marks are not appearing * Something is wrong with jungle re: softlocks * FEATURES: * SWAP_TARGETS should still require the full panel sequence (and have ways to prevent softlocks?) @@ -37,34 +36,23 @@ size_t find(const std::vector &data, T search, size_t startIndex = 0) { exit(-1); } -int main(int argc, char** argv) +void Randomizer::Randomize(int seed) { - Randomizer randomizer = Randomizer(); - - if (argc == 2) { - srand(atoi(argv[1])); // Seed from the command line - } else { - srand(static_cast(time(nullptr))); - int seed = rand() % (1 << 16); // Seed from the time in milliseconds - std::cout << "Selected seed: " << seed << std::endl; - srand(seed); - } - // Content swaps -- must happen before squarePanels - randomizer.Randomize(tallUpDownPanels, SWAP_LINES | SWAP_STYLE); - randomizer.Randomize(upDownPanels, SWAP_LINES | SWAP_STYLE); - randomizer.Randomize(leftForwardRightPanels, SWAP_LINES); + Randomize(tallUpDownPanels, SWAP_LINES | SWAP_STYLE); + Randomize(upDownPanels, SWAP_LINES | SWAP_STYLE); + Randomize(leftForwardRightPanels, SWAP_LINES); - randomizer.Randomize(squarePanels, SWAP_LINES | SWAP_STYLE); + Randomize(squarePanels, SWAP_LINES | SWAP_STYLE); // Frame swaps -- must happen after squarePanels - randomizer.Randomize(burnablePanels, SWAP_LINES | SWAP_STYLE); + Randomize(burnablePanels, SWAP_LINES | SWAP_STYLE); // Target swaps, can happen whenever - randomizer.Randomize(lasers, SWAP_TARGETS); + Randomize(lasers, SWAP_TARGETS); // Read the target of keep front laser, and write it to keep back laser. - std::vector keepFrontLaserTarget = randomizer.ReadPanelData(0x0360E, TARGET, 1); - randomizer.WritePanelData(0x03317, TARGET, keepFrontLaserTarget); + std::vector keepFrontLaserTarget = ReadPanelData(0x0360E, TARGET, 1); + WritePanelData(0x03317, TARGET, keepFrontLaserTarget); std::vector randomOrder; @@ -77,7 +65,7 @@ int main(int argc, char** argv) // Randomize Pitches 1-6 onto themselves randomizer.RandomizeRange(randomOrder, SWAP_NONE, 7, 13); randomizer.ReassignTargets(junglePanels, randomOrder); - */ + */ /* Bunker */ randomOrder = std::vector(bunkerPanels.size(), 0); @@ -85,23 +73,23 @@ int main(int argc, char** argv) // Randomize Tutorial 2-Advanced Tutorial 4 + Glass 1 // Tutorial 1 cannot be randomized, since no other panel can start on // Glass 1 will become door + glass 1, due to the targetting system - randomizer.RandomizeRange(randomOrder, SWAP_NONE, 1, 10); + RandomizeRange(randomOrder, SWAP_NONE, 1, 10); // Randomize Glass 1-3 into everything after the door const size_t glassDoorIndex = find(randomOrder, 9) + 1; - randomizer.RandomizeRange(randomOrder, SWAP_NONE, glassDoorIndex, 12); - randomizer.ReassignTargets(bunkerPanels, randomOrder); + RandomizeRange(randomOrder, SWAP_NONE, glassDoorIndex, 12); + ReassignTargets(bunkerPanels, randomOrder); /* Shadows */ randomOrder = std::vector(shadowsPanels.size(), 0); std::iota(randomOrder.begin(), randomOrder.end(), 0); - randomizer.RandomizeRange(randomOrder, SWAP_NONE, 0, 8); // Tutorial - randomizer.RandomizeRange(randomOrder, SWAP_NONE, 8, 16); // Avoid - randomizer.RandomizeRange(randomOrder, SWAP_NONE, 16, 21); // Follow - randomizer.ReassignTargets(shadowsPanels, randomOrder); + RandomizeRange(randomOrder, SWAP_NONE, 0, 8); // Tutorial + RandomizeRange(randomOrder, SWAP_NONE, 8, 16); // Avoid + RandomizeRange(randomOrder, SWAP_NONE, 16, 21); // Follow + ReassignTargets(shadowsPanels, randomOrder); // Turn off original starting panel - randomizer.WritePanelData(shadowsPanels[0], POWER, {0.0f, 0.0f}); + WritePanelData(shadowsPanels[0], POWER, {0.0f, 0.0f}); // Turn on new starting panel - randomizer.WritePanelData(shadowsPanels[randomOrder[0]], POWER, {1.0f, 1.0f}); + WritePanelData(shadowsPanels[randomOrder[0]], POWER, {1.0f, 1.0f}); /* Monastery randomOrder = std::vector(monasteryPanels.size(), 0); diff --git a/Source/Randomizer.h b/Source/Randomizer.h index b644a1d..6615e31 100644 --- a/Source/Randomizer.h +++ b/Source/Randomizer.h @@ -13,6 +13,8 @@ class Randomizer { public: Randomizer(); + void Randomize(int seed); + void Randomize(std::vector& panels, int flags); void RandomizeRange(std::vector &panels, int flags, size_t startIndex, size_t endIndex); void SwapPanels(int panel1, int panel2, int flags); diff --git a/Source/Source.vcxproj b/Source/Source.vcxproj index 8a6c8eb..55d54d9 100644 --- a/Source/Source.vcxproj +++ b/Source/Source.vcxproj @@ -46,7 +46,7 @@ Unicode - StaticLibrary + Application false v141 true @@ -153,7 +153,6 @@ - diff --git a/Source/Source.vcxproj.filters b/Source/Source.vcxproj.filters index aad417a..b650d44 100644 --- a/Source/Source.vcxproj.filters +++ b/Source/Source.vcxproj.filters @@ -24,9 +24,6 @@ Header Files - - Header Files - Header Files -- cgit 1.4.1