implement global settings page

develop
Myk Taylor 2023-02-27 10:16:58 -08:00
parent 9f794a0710
commit 1d855014c2
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
2 changed files with 40 additions and 2 deletions

@ -603,6 +603,20 @@ static int getAvailableItems(lua_State *L) {
return 1;
}
static int getGlobalSettings(lua_State *L) {
color_ostream *out = Lua::GetOutput(L);
if (!out)
out = &Core::getInstance().getConsole();
DEBUG(status,*out).print("entering getGlobalSettings\n");
map<string, bool> settings;
settings.emplace("blocks", get_config_bool(config, CONFIG_BLOCKS));
settings.emplace("logs", get_config_bool(config, CONFIG_LOGS));
settings.emplace("boulders", get_config_bool(config, CONFIG_BOULDERS));
settings.emplace("bars", get_config_bool(config, CONFIG_BARS));
Lua::Push(L, settings);
return 1;
}
static int countAvailableItems(color_ostream &out, df::building_type type, int16_t subtype, int32_t custom, int index) {
DEBUG(status,out).print(
"entering countAvailableItems building_type=%d subtype=%d custom=%d index=%d\n",
@ -762,8 +776,7 @@ DFHACK_PLUGIN_LUA_FUNCTIONS {
DFHACK_LUA_FUNCTION(isPlannedBuilding),
DFHACK_LUA_FUNCTION(addPlannedBuilding),
DFHACK_LUA_FUNCTION(doCycle),
DFHACK_LUA_FUNCTION(scheduleCycle),
DFHACK_LUA_FUNCTION(countAvailableItems),
DFHACK_LUA_FUNCTION(scheduleCycle), DFHACK_LUA_FUNCTION(countAvailableItems),
DFHACK_LUA_FUNCTION(hasFilter),
DFHACK_LUA_FUNCTION(setMaterialFilter),
DFHACK_LUA_FUNCTION(setHeatSafetyFilter),
@ -774,6 +787,7 @@ DFHACK_PLUGIN_LUA_FUNCTIONS {
};
DFHACK_PLUGIN_LUA_COMMANDS {
DFHACK_LUA_COMMAND(getGlobalSettings),
DFHACK_LUA_COMMAND(getAvailableItems),
DFHACK_LUA_COMMAND(getMaterialFilter),
DFHACK_LUA_COMMAND(getHeatSafetyFilter),

@ -906,30 +906,54 @@ function GlobalSettingsPage:init()
frame={h=1},
},
widgets.ToggleHotkeyLabel{
view_id='blocks',
frame={l=0},
key='CUSTOM_B',
label='Blocks',
label_width=8,
on_change=self:callback('update_setting', 'blocks'),
},
widgets.ToggleHotkeyLabel{
view_id='logs',
frame={l=0},
key='CUSTOM_L',
label='Logs',
label_width=8,
on_change=self:callback('update_setting', 'logs'),
},
widgets.ToggleHotkeyLabel{
view_id='boulders',
frame={l=0},
key='CUSTOM_O',
label='Boulders',
label_width=8,
on_change=self:callback('update_setting', 'boulders'),
},
widgets.ToggleHotkeyLabel{
view_id='bars',
frame={l=0},
key='CUSTOM_R',
label='Bars',
label_width=8,
on_change=self:callback('update_setting', 'bars'),
},
}
self:init_settings()
end
function GlobalSettingsPage:init_settings()
local settings = getGlobalSettings()
local subviews = self.subviews
subviews.blocks:setOption(settings.blocks)
subviews.logs:setOption(settings.logs)
subviews.boulders:setOption(settings.boulders)
subviews.bars:setOption(settings.bars)
end
function GlobalSettingsPage:update_setting(setting, val)
dfhack.run_command('buildingplan', 'set', setting, tostring(val))
self:init_settings()
end
--------------------------------