From 7774f5f2c1b1e16b9bd3eefe0fd8b4287d03fef7 Mon Sep 17 00:00:00 2001
From: Alexander Gavrilov
Date: Sat, 19 May 2012 19:50:36 +0400
Subject: [PATCH 1/2] Add a mechanism converting ui focus to a string
representation.
The idea is to make ui handling more modular, dispensing with
huge functions that switch or if/else on lots of variables.
For now, used to split up functions in the sort plugin.
---
LUA_API.rst | 9 +
Lua API.html | 7 +
library/LuaApi.cpp | 3 +
library/MiscUtils.cpp | 24 ++
library/include/DataDefs.h | 3 +
library/include/MiscUtils.h | 45 +++
library/include/modules/Gui.h | 4 +
library/modules/Gui.cpp | 320 ++++++++++++++++++++
plugins/sort.cpp | 553 ++++++++++++++--------------------
9 files changed, 648 insertions(+), 320 deletions(-)
diff --git a/LUA_API.rst b/LUA_API.rst
index 9ecd2e55e..59a52e596 100644
--- a/LUA_API.rst
+++ b/LUA_API.rst
@@ -613,6 +613,15 @@ can be omitted.
Gui module
----------
+* ``dfhack.gui.getCurViewscreen()``
+
+ Returns the viewscreen that is current in the core.
+
+* ``dfhack.gui.getFocusString(viewscreen)``
+
+ Returns a string representation of the current focus position
+ in the ui. The string has a "screen/foo/bar/baz..." format.
+
* ``dfhack.gui.getSelectedWorkshopJob([silent])``
When a job is selected in *'q'* mode, returns the job, else
diff --git a/Lua API.html b/Lua API.html
index 7ce777c42..e2d4ec23e 100644
--- a/Lua API.html
+++ b/Lua API.html
@@ -868,6 +868,13 @@ can be omitted.
+dfhack.gui.getCurViewscreen()
+Returns the viewscreen that is current in the core.
+
+dfhack.gui.getFocusString(viewscreen)
+Returns a string representation of the current focus position
+in the ui. The string has a "screen/foo/bar/baz..." format.
+
dfhack.gui.getSelectedWorkshopJob([silent])
When a job is selected in 'q' mode, returns the job, else
prints error unless silent and returns nil.
diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp
index d4c3b157d..9dfb39754 100644
--- a/library/LuaApi.cpp
+++ b/library/LuaApi.cpp
@@ -61,6 +61,7 @@ distribution.
#include "df/unit.h"
#include "df/item.h"
#include "df/material.h"
+#include "df/viewscreen.h"
#include "df/assumed_identity.h"
#include "df/nemesis_record.h"
#include "df/historical_figure.h"
@@ -652,6 +653,8 @@ static const LuaWrapper::FunctionReg dfhack_module[] = {
/***** Gui module *****/
static const LuaWrapper::FunctionReg dfhack_gui_module[] = {
+ WRAPM(Gui, getCurViewscreen),
+ WRAPM(Gui, getFocusString),
WRAPM(Gui, getSelectedWorkshopJob),
WRAPM(Gui, getSelectedJob),
WRAPM(Gui, getSelectedUnit),
diff --git a/library/MiscUtils.cpp b/library/MiscUtils.cpp
index 8658788bb..b73d730c1 100644
--- a/library/MiscUtils.cpp
+++ b/library/MiscUtils.cpp
@@ -36,6 +36,7 @@ distribution.
#include
#include
+#include
#include
#include