Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Immersive Mode for Stonesense (replacement for Overlay mode) #165

Draft
wants to merge 29 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
17c867b
Begin fixing Overlay Mode
realSquidCoder Jan 24, 2025
ca5e27b
Fix whitespace
realSquidCoder Jan 24, 2025
220d65e
Comment out the broken parts so that it still builds.
realSquidCoder Jan 24, 2025
a75ad05
again with the whitespace
realSquidCoder Jan 24, 2025
df460f8
Merge branch 'DFHack:master' into squid-ssense-overlay
realSquidCoder Jan 25, 2025
8ceb39f
More overlay clean up
realSquidCoder Jan 26, 2025
2d16edc
whitespace
realSquidCoder Jan 26, 2025
3aac95e
Merge branch 'master' into squid-ssense-overlay
realSquidCoder Jan 27, 2025
3ea0ac2
Merge branch 'master' into squid-ssense-overlay
realSquidCoder Jan 28, 2025
2ab16b9
more refactor
realSquidCoder Jan 28, 2025
5bf444f
Perma-enable "overlay" mode and smooth out the movement code
realSquidCoder Jan 29, 2025
d1bb1e7
Merge branch 'master' into squid-ssense-overlay
realSquidCoder Jan 29, 2025
38082e4
First Pass for Immersive info
realSquidCoder Jan 29, 2025
13cee40
Merge branch 'squid-ssense-overlay' of https://github.com/SquidCoderI…
realSquidCoder Jan 29, 2025
5fdfd48
Merge branch 'master' into squid-ssense-overlay
realSquidCoder Jan 30, 2025
c203538
clicking in immersive mode is now a lot like using the cursor
realSquidCoder Jan 30, 2025
c113c45
bunch of controls to test and dbug with
realSquidCoder Jan 30, 2025
137cadd
Merge branch 'master' into squid-ssense-overlay
realSquidCoder Jan 30, 2025
fc331dc
Stonesense Immersive Mode now can do most designations
realSquidCoder Jan 30, 2025
cc0ed48
Fix warnings as errors
realSquidCoder Jan 30, 2025
422986a
various changes see description
realSquidCoder Feb 1, 2025
e86105d
made blueprints WAY cleaner and added `dig_auto` indicator too (its g…
realSquidCoder Feb 1, 2025
6ebd0a6
Merge branch 'master' into squid-ssense-overlay
realSquidCoder Feb 1, 2025
ae49270
no need to perma enable overlay mode now
realSquidCoder Feb 1, 2025
9eb28e6
various changes
realSquidCoder Feb 1, 2025
582654e
various changes
realSquidCoder Feb 1, 2025
2f27b5b
Fix whitespace and designation bug
realSquidCoder Feb 1, 2025
6e32000
Remove unused config references
realSquidCoder Feb 1, 2025
1157ec6
See description
realSquidCoder Feb 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,10 @@ namespace {
}
}

bool isViewTracking() {
auto& ssConfig = stonesenseState.ssConfig;
return ssConfig.config.track_mode != Config::TRACKING_NONE;
}

bool loadConfigFile()
{
Expand Down
1 change: 1 addition & 0 deletions Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,6 @@ struct action_name_mapper {
void (*func)(uint32_t);
};

bool isViewTracking();
bool loadConfigFile();
std::optional<std::string> trim_line(std::string line);
286 changes: 250 additions & 36 deletions GUI.cpp

Large diffs are not rendered by default.

24 changes: 23 additions & 1 deletion GameState.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <stdint.h>
#include <string>

#include "common.h"
#include "commonTypes.h"
Expand All @@ -16,10 +17,31 @@ struct GameState{

//position of the cursor
Crd3D dfCursor;
//position of the selection cursor
//position of the selection cursors
Crd3D dfSelection;
Crd3D dfSelection2;

//the width and height of the stonesense window
int ScreenW;
int ScreenH;

bool blueprinting = false;
bool rectangleSelect = true;
bool veinMining = false;
bool clickedOnceYet = false;

enum modeTypes {
DEFAULT,
DIG,
CHOP,
GATHER,
SMOOTH,
ERASE,
BUILDING,
TRAFFIC,
};

//the current mode we're in
enum modeTypes mode = DEFAULT;
std::string submode = "None";
};
171 changes: 127 additions & 44 deletions Keybinds.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "vector"
#include "common.h"
#include "Config.h"
#include "StonesenseState.h"
#include "UserInput.h"

//should match allegrow/keycodes.h
Expand Down Expand Up @@ -173,7 +175,112 @@ void action_invalid(uint32_t keymod){
PrintMessage("invalid action\n");
}

action_name_mapper actionnamemap[] = {
std::vector<action_name_mapper> actionnamemap;

void (*actionkeymap[ALLEGRO_KEY_UNKNOWN])(uint32_t);
void (*actionkeymap_default[ALLEGRO_KEY_UNKNOWN])(uint32_t);
bool actionrepeatmap[ALLEGRO_KEY_UNKNOWN];

void parseKeymapLine( std::string line )
{
auto ll = trim_line(line);
if (!ll) return;
line = *ll;

//second-last character should tell us if this is a repeating action
auto c = line[ line.length() -2 ];

for(int i=0; actionnamemap[i].func != action_invalid; i++) {
if(line.find(actionnamemap[i].name)!=std::string::npos) {
for(int j=0; j<ALLEGRO_KEY_UNKNOWN; j++){
if(line.find(keynames[j])!=std::string::npos) {
actionkeymap[j] = actionnamemap[i].func;
if( c == '*' ) {
actionrepeatmap[j] = true;
#ifdef DEBUG
PrintMessage("successfully mapped: op:%i key:%i repeatable\n",i,j);
} else {
PrintMessage("successfully mapped: op:%i key:%i\n",i,j);
#endif
}
break;
}
}
break;
}
}
}

bool loadKeymapFile(){
std::string line;
std::filesystem::path path = std::filesystem::path{} / "dfhack-config" / "stonesense" / "keybinds.txt";
std::ifstream myfile (path);

if (myfile.is_open() == false) {
LogError( "cannot find keybinds file\n" );
return false;
}


//initialize the default keymap to all noops
for (int i = 0; i < ALLEGRO_KEY_UNKNOWN; i++) {
actionkeymap_default[i] = action_noop;
}
if (stonesenseState.ssConfig.overlay_mode) {

actionkeymap_default[ALLEGRO_KEY_1] = action_option1;
actionkeymap_default[ALLEGRO_KEY_2] = action_option2;
actionkeymap_default[ALLEGRO_KEY_3] = action_option3;
actionkeymap_default[ALLEGRO_KEY_4] = action_option4;
actionkeymap_default[ALLEGRO_KEY_5] = action_option5;
actionkeymap_default[ALLEGRO_KEY_6] = action_option6;
actionkeymap_default[ALLEGRO_KEY_7] = action_option7;
actionkeymap_default[ALLEGRO_KEY_8] = action_option8;
actionkeymap_default[ALLEGRO_KEY_9] = action_option9;

actionkeymap_default[ALLEGRO_KEY_SPACE] = action_togglePause;

actionnamemap = {
{"NOOP", action_noop},
{"ROTATE", action_incrrotation},
{"TOGGLE_OCCLUSION", action_toggleocclusion},
{"CHOP_WALLS", action_chopwall},
{"RESET_VIEW_OFFSET", action_resetscreen},
{"TOGGLE_SHADE_HIDDEN_TILES", action_toggleshadehidden},
{"TOGGLE_SHOW_HIDDEN_TILES", action_toggleshowhidden},
{"TOGGLE_OSD", action_toggleosd},
{"TOGGLE_KEYBINDS", action_togglekeybinds},
{"TOGGLE_DEBUG", action_toggledebug},
{"INCR_ZOOM", action_incrzoom},
{"DECR_ZOOM", action_decrzoom},
{"SCREENSHOT", action_screenshot},
{"INCR_RELOAD_TIME", action_incrreloadtime},
{"DECR_RELOAD_TIME", action_decrreloadtime},

{"DECR_Z", action_decrZ},
{"INCR_Z", action_incrZ},

{"DECR_Y", action_decrY},
{"INCR_Y", action_incrY},
{"DECR_X", action_decrX},
{"INCR_X", action_incrX},

{"TOGGLEPAUSE", action_togglePause},

{"OPTION1",action_option1},
{"OPTION2",action_option2},
{"OPTION3",action_option3},
{"OPTION4",action_option4},
{"OPTION5",action_option5},
{"OPTION6",action_option6},
{"OPTION7",action_option7},
{"OPTION8",action_option8},
{"OPTION9",action_option9},
{"INVALID", action_invalid}//this is the stop condition
};
}
else {
actionnamemap = {
{"NOOP", action_noop},
{"ROTATE", action_incrrotation},
{"RELOAD_SEGMENT", action_reloadsegment},
Expand Down Expand Up @@ -220,55 +327,31 @@ action_name_mapper actionnamemap[] = {
{"INCR_X", action_incrX},
//add extra action here!

{"INVALID", action_invalid}//this is the stop condition
};
{"TOGGLEPAUSE", action_togglePause},

void (*actionkeymap[ALLEGRO_KEY_UNKNOWN])(uint32_t);
bool actionrepeatmap[ALLEGRO_KEY_UNKNOWN];
{"OPTION1",action_option1},
{"OPTION2",action_option2},
{"OPTION3",action_option3},
{"OPTION4",action_option4},
{"OPTION5",action_option5},
{"OPTION6",action_option6},
{"OPTION7",action_option7},
{"OPTION8",action_option8},
{"OPTION9",action_option9},

void parseKeymapLine( std::string line )
{
auto ll = trim_line(line);
if (!ll) return;
line = *ll;

//second-last character should tell us if this is a repeating action
auto c = line[ line.length() -2 ];

for(int i=0; actionnamemap[i].func != action_invalid; i++) {
if(line.find(actionnamemap[i].name)!=std::string::npos) {
for(int j=0; j<ALLEGRO_KEY_UNKNOWN; j++){
if(line.find(keynames[j])!=std::string::npos) {
actionkeymap[j] = actionnamemap[i].func;
if( c == '*' ) {
actionrepeatmap[j] = true;
#ifdef DEBUG
PrintMessage("successfully mapped: op:%i key:%i repeatable\n",i,j);
} else {
PrintMessage("successfully mapped: op:%i key:%i\n",i,j);
#endif
}
break;
}
}
break;
}
}
}

bool loadKeymapFile(){
std::string line;
std::filesystem::path path = std::filesystem::path{} / "dfhack-config" / "stonesense" / "keybinds.txt";
std::ifstream myfile (path);

if (myfile.is_open() == false) {
LogError( "cannot find keybinds file\n" );
return false;
{"INVALID", action_invalid}//this is the stop condition
};
}

//initialize the keymap to all noops
//initialize the keymap to all noops or defaults
for(int i=0; i<ALLEGRO_KEY_UNKNOWN; i++) {
actionkeymap[i] = action_noop;
if (actionkeymap_default[i] == action_noop) {
actionkeymap[i] = action_noop;
}
else {
actionkeymap[i] = actionkeymap_default[i];
}
actionrepeatmap[i] = false;
}

Expand Down
2 changes: 1 addition & 1 deletion MapLoading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ void read_segment( void *arg)
ssState.dfSelection.z = df::global::selection_rect->start_z;
}

if (firstLoad || stonesenseState.ssConfig.config.track_mode != Config::TRACKING_NONE) {
if (firstLoad || isViewTracking()) {
firstLoad = 0;
if (stonesenseState.ssConfig.config.track_mode == Config::TRACKING_CENTER) {
followCurrentDFCenter();
Expand Down
38 changes: 22 additions & 16 deletions Overlay.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "GameState.h"
#include "StonesenseState.h"
#include "Overlay.h"
#include "TrackingModes.h"
#include "Hooks.h"
Expand Down Expand Up @@ -180,14 +182,14 @@ void Overlay::Flip()
{
al_unlock_bitmap(front);

if(al_get_bitmap_width(front) != ssState.ScreenW
|| al_get_bitmap_height(front) != ssState.ScreenH){
if(al_get_bitmap_width(front) != stonesenseState.ssState.ScreenW
|| al_get_bitmap_height(front) != stonesenseState.ssState.ScreenH){
al_destroy_bitmap(front);
int32_t flags = al_get_new_bitmap_flags();
if(al_get_current_display() != NULL){
al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP | ALLEGRO_ALPHA_TEST);
}
front = al_create_bitmap(ssState.ScreenW, ssState.ScreenH);
front = al_create_bitmap(stonesenseState.ssState.ScreenW, stonesenseState.ssState.ScreenH);
al_set_new_bitmap_flags(flags);
}

Expand All @@ -201,22 +203,22 @@ void Overlay::Flip()
front_updated = true;
al_unlock_mutex(front_mutex);

if(al_get_bitmap_width(back) != ssState.ScreenW
|| al_get_bitmap_height(back) != ssState.ScreenH){
if(al_get_bitmap_width(back) != stonesenseState.ssState.ScreenW
|| al_get_bitmap_height(back) != stonesenseState.ssState.ScreenH){
al_destroy_bitmap(back);
int32_t flags = al_get_new_bitmap_flags();
if(al_get_current_display() != NULL){
al_set_new_bitmap_flags(al_get_bitmap_flags(al_get_backbuffer(al_get_current_display())));
}
back = al_create_bitmap(ssState.ScreenW, ssState.ScreenH);
back = al_create_bitmap(stonesenseState.ssState.ScreenW, stonesenseState.ssState.ScreenH);
al_set_new_bitmap_flags(flags);
}

al_set_target_bitmap(back);

//do the ending timer stuff
clock_t donetime = clock();
ssTimers.overlay_time = (donetime - starttime)*0.1 + ssTimers.overlay_time*0.9;
stonesenseState.stoneSenseTimers.overlay_time.update(donetime - starttime);
}

bool Overlay::GoodViewscreen()
Expand Down Expand Up @@ -258,26 +260,30 @@ void Overlay::render()
}

//get the SDL surface information so we can do a blit
DFHack::DFSDL_Surface * dfsurf = (DFHack::DFSDL_Surface *) DFHack::DFSDL::DFSDL_GetVideoSurface();
DFHack::DFSDL_Surface * sssurf = (DFHack::DFSDL_Surface *) DFHack::DFSDL::DFSDL_CreateRGBSurfaceFrom( ((char*) front_data->data) + dataoffset,
/* FIXME: need to get the DF video surface
DFHack::DFTileSurface * dfsurf = (DFHack::DFTileSurface*) DFHack::DFSDL::DFSDL_GetVideoSurface();
*/
DFHack::DFTileSurface * sssurf = (DFHack::DFTileSurface*) DFHack::DFSDL::DFSDL_CreateRGBSurfaceFrom( ((char*) front_data->data) + dataoffset,
al_get_bitmap_width(front), al_get_bitmap_height(front), 8*front_data->pixel_size, neg*front_data->pitch, 0, 0, 0, 0);

DFSDL_Rect src;
/*FIXME SDL_Rect is an incomplete type
SDL_Rect src;
src.x = 0;
src.y = 0;
src.w = ssState.ScreenW;
src.h = ssState.ScreenH;
src.w = stonesenseState.ssState.ScreenW;
src.h = stonesenseState.ssState.ScreenH;

DFSDL_Rect pos;
SDL_Rect pos;
pos.x = offsetx;
pos.y = offsety;
pos.w = 0;
pos.h = 0;

//do the blit
DFHack::DFSDL::DFSDL_UpperBlit(sssurf, &src, dfsurf, &pos);

DFHack::DFSDL::DFSDL_FreeSurface(sssurf);
//do the blit
DFHack::DFSDL::DFSDL_UpperBlit(sssurf->surface, &src, dfsurf->surface, &pos);
*/
DFHack::DFSDL::DFSDL_FreeSurface(sssurf->surface);
}
front_updated = false;
} else {
Expand Down
6 changes: 6 additions & 0 deletions SpriteColors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ ALLEGRO_COLOR uiColor(int32_t index)
case 3:
//lime
return ssConfig.config.colors.getDfColor(dfColors::lgreen, ssConfig.config.useDfColors);
case 4:
//light blue
return ssConfig.config.colors.getDfColor(dfColors::lblue, ssConfig.config.useDfColors);
case 5:
//light red
return ssConfig.config.colors.getDfColor(dfColors::lred, ssConfig.config.useDfColors);
default:
//white
return ssConfig.config.colors.getDfColor(dfColors::white, ssConfig.config.useDfColors);
Expand Down
6 changes: 6 additions & 0 deletions SpriteObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,12 @@ void c_sprite::assemble_world_offset(int x, int y, int z, int plateoffset, Tile
}

ALLEGRO_COLOR shade_color = shadeAdventureMode(get_color(b), b->fog_of_war, b->designation.bits.outside);
if (ssConfig.show_designations) {
if (b->occ.bits.dig_auto && containsDesignations(b->designation, b->occ)) { shade_color = al_map_rgba(0, 255, 127, 127); }
if (b->occ.bits.dig_marked && containsDesignations(b->designation, b->occ)) { shade_color = al_map_rgba(0, 127, 255, 127); }
if (b->occ.bits.dig_marked && b->occ.bits.dig_auto && containsDesignations(b->designation, b->occ)) { shade_color = partialBlend(shade_color, al_map_rgba(0, 255, 127, 127), 25); }
}

if(chop && ( halftile == HALFPLATECHOP)) {
if(shade_color.a > 0.001f) {
b->AssembleSprite(
Expand Down
Loading