about summary refs log tree commit diff stats
path: root/Archipelago/load.gd
blob: cb592ff2aea0d39a99468e1788ba9da75ec74aed (plain) (blame)
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
extends "res://scripts/load.gd"


func _load():
	global._print("Hooked Load Start")

	var apclient = global.get_node("Archipelago")

	# TODO: Override the YOU panel with the AP slot name

	# This is the best time to create the location nodes, since the map is now
	# loaded but the panels haven't been solved from the save file yet.
	var panels_parent = self.get_node("Panels")
	var location_script = ResourceLoader.load("user://maps/Archipelago/location.gd")
	for location_name in apclient._location_name_to_id:
		var location = location_script.new()
		location.ap_name = location_name
		location.ap_id = apclient._location_name_to_id[location_name]
		location.name = "AP_location_" + location.ap_id
		self.add_child(location)

		var panels = apclient._panel_ids_by_location[String(location.ap_id)]
		location.total = panels.size()

		for panel in panels:
			var that_panel = panels_parent.get_node(panel)
			that_panel.get_node("Viewport/GUI/Panel/TextEdit").connect(
				"answer_correct", location, "handle_correct"
			)

	# Proceed with the rest of the load.
	global._print("Hooked Load End")
	._load()

	# Process any items received while the map was loading, and send the checks
	# from the save load.
	apclient.mapFinishedLoading()
class="w"> wxBITMAP_TYPE_PNG); if (!owl_image_.IsOk()) { return; } tree_ = std::make_unique<quadtree::Quadtree<int, GetItemBox>>( quadtree::Box<float>{0, 0, static_cast<float>(map_image_.GetWidth()), static_cast<float>(map_image_.GetHeight())}); for (const SubwayItem &subway_item : GD_GetSubwayItems()) { tree_->add(subway_item.id); } Redraw(); Bind(wxEVT_PAINT, &SubwayMap::OnPaint, this); Bind(wxEVT_MOTION, &SubwayMap::OnMouseMove, this); } void SubwayMap::UpdateIndicators() { Redraw(); } void SubwayMap::OnPaint(wxPaintEvent &event) { if (GetSize() != rendered_.GetSize()) { Redraw(); } wxPaintDC dc(this); dc.DrawBitmap(rendered_, 0, 0); event.Skip(); } void SubwayMap::OnMouseMove(wxMouseEvent &event) { int mouse_x = std::clamp( (event.GetX() - render_x_) * map_image_.GetWidth() / render_width_, 0, map_image_.GetWidth() - 1); int mouse_y = std::clamp( (event.GetY() - render_y_) * map_image_.GetWidth() / render_width_, 0, map_image_.GetHeight() - 1); std::vector<int> hovered = tree_->query( {static_cast<float>(mouse_x), static_cast<float>(mouse_y), 2, 2}); std::optional<int> new_hovered_item; if (!hovered.empty()) { new_hovered_item = hovered[0]; } if (new_hovered_item != hovered_item_) { if (new_hovered_item) { wxLogVerbose("Hovered: %d", *new_hovered_item); } else { wxLogVerbose("Un-hovered: %d", *hovered_item_); } hovered_item_ = new_hovered_item; } event.Skip(); } void SubwayMap::Redraw() { wxSize panel_size = GetSize(); wxSize image_size = map_image_.GetSize(); render_x_ = 0; render_y_ = 0; render_width_ = panel_size.GetWidth(); render_height_ = panel_size.GetHeight(); if (image_size.GetWidth() * panel_size.GetHeight() > panel_size.GetWidth() * image_size.GetHeight()) { render_height_ = (panel_size.GetWidth() * image_size.GetHeight()) / image_size.GetWidth(); render_y_ = (panel_size.GetHeight() - render_height_) / 2; } else { render_width_ = (image_size.GetWidth() * panel_size.GetHeight()) / image_size.GetHeight(); render_x_ = (panel_size.GetWidth() - render_width_) / 2; } rendered_ = wxBitmap( map_image_ .Scale(render_width_, render_height_, wxIMAGE_QUALITY_BILINEAR) .Size(panel_size, {render_x_, render_y_}, 0, 0, 0)); wxMemoryDC dc; dc.SelectObject(rendered_); int real_area_size = render_width_ * AREA_ACTUAL_SIZE / image_size.GetWidth(); if (real_area_size == 0) { real_area_size = 1; } wxBitmap owl_bitmap = wxBitmap(owl_image_.Scale( real_area_size * 1.25, real_area_size * 1.25, wxIMAGE_QUALITY_BILINEAR)); for (const SubwayItem &subway_item : GD_GetSubwayItems()) { ItemDrawType draw_type = ItemDrawType::kNone; const wxBrush *brush_color = wxGREY_BRUSH; if (subway_item.door) { draw_type = ItemDrawType::kBox; if (IsDoorOpen(*subway_item.door)) { if (!subway_item.paintings.empty()) { draw_type = ItemDrawType::kOwl; } else { brush_color = wxGREEN_BRUSH; } } else { brush_color = wxRED_BRUSH; } } else if (!subway_item.paintings.empty()) { draw_type = ItemDrawType::kOwl; } int real_area_x = render_x_ + subway_item.x * render_width_ / image_size.GetWidth(); int real_area_y = render_y_ + subway_item.y * render_width_ / image_size.GetWidth(); if (draw_type == ItemDrawType::kBox) { dc.SetPen(*wxThePenList->FindOrCreatePen(*wxBLACK, 1)); dc.SetBrush(*brush_color); dc.DrawRectangle({real_area_x, real_area_y}, {real_area_size, real_area_size}); } else if (draw_type == ItemDrawType::kOwl) { dc.DrawBitmap(owl_bitmap, {real_area_x, real_area_y}); } } } quadtree::Box<float> SubwayMap::GetItemBox::operator()(const int& id) const { const SubwayItem &subway_item = GD_GetSubwayItem(id); return {static_cast<float>(subway_item.x), static_cast<float>(subway_item.y), AREA_ACTUAL_SIZE, AREA_ACTUAL_SIZE}; }