Skip to content

Commit

Permalink
Close button for tile brush window #475
Browse files Browse the repository at this point in the history
Also fix adding tile type doesn't show in editor
  • Loading branch information
cxong committed Feb 22, 2020
1 parent c26d844 commit 8870fa6
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 57 deletions.
56 changes: 29 additions & 27 deletions src/cdogsed/char_editor.c
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
/*
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (c) 2017-2019 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (c) 2017-2019 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include "char_editor.h"

Expand Down Expand Up @@ -60,7 +60,7 @@ static const char *IndexGunName(const int i);
static int NumGuns(void);
static int GunIndex(const WeaponClass *wc);
static void AddCharacterTextures(EditorContext *ec);
static void Draw(SDL_Window *win, struct nk_context *ctx, void *data);
static bool Draw(SDL_Window *win, struct nk_context *ctx, void *data);
void CharEditor(
GraphicsDevice *g, CampaignSetting *setting, EventHandlers *handlers,
bool *fileChanged)
Expand Down Expand Up @@ -242,7 +242,7 @@ static void DrawFlag(
static void DrawCharacter(
struct nk_context *ctx, Character *c, GLuint *texids,
const struct vec2i pos, const Animation *anim, const direction_e d);
static void Draw(SDL_Window *win, struct nk_context *ctx, void *data)
static bool Draw(SDL_Window *win, struct nk_context *ctx, void *data)
{
EditorContext *ec = data;
// Stretch char store with window
Expand Down Expand Up @@ -458,6 +458,8 @@ static void Draw(SDL_Window *win, struct nk_context *ctx, void *data)

AnimationUpdate(&ec->anim, 1);
AnimationUpdate(&ec->animSelection, 1);

return true;
}

static void AddCharacter(EditorContext *ec, const int cloneIdx)
Expand Down
2 changes: 2 additions & 0 deletions src/cdogsed/editor_ui_static.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ UIObject *CreateStaticMapObjs(
o2->ChangeFunc = BrushChangeMainType;
o2->OnFocusFunc = ActivateBrush;
o2->OnUnfocusFunc = DeactivateBrush;
o2->ReloadData = true; // may add new tile type
CSTRDUP(o2->Tooltip, "Left click to paint the map with this tile type");
o2->Pos = pos;
UIObjectAddChild(c, o2);
Expand All @@ -392,6 +393,7 @@ UIObject *CreateStaticMapObjs(
o2->ChangeFunc = BrushChangeSecondaryType;
o2->OnFocusFunc = ActivateBrush;
o2->OnUnfocusFunc = DeactivateBrush;
o2->ReloadData = true; // may add new tile type
CSTRDUP(o2->Tooltip, "Right click to paint the map with this tile type");
o2->Pos = pos;
UIObjectAddChild(c, o2);
Expand Down
18 changes: 13 additions & 5 deletions src/cdogsed/nk_window.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (c) 2019 Cong Xu
Copyright (c) 2019-2020 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -92,7 +92,7 @@ void NKWindowInit(NKWindowConfig *cfg)


static bool HandleEvents(EventHandlers *handler, const Uint32 ticks);
static void Draw(const NKWindowConfig cfg);
static bool Draw(const NKWindowConfig cfg);
void NKWindow(NKWindowConfig cfg)
{
CASSERT(cfg.win, "Error: did not initialise window");
Expand All @@ -116,7 +116,10 @@ void NKWindow(NKWindowConfig cfg)
{
goto bail;
}
Draw(cfg);
if (!Draw(cfg))
{
goto bail;
}
nk_input_end(cfg.ctx);

ticksElapsed = 0;
Expand All @@ -140,9 +143,12 @@ static bool HandleEvents(EventHandlers *handler, const Uint32 ticks)
handler->HasQuit = false;
return run;
}
static void Draw(const NKWindowConfig cfg)
static bool Draw(const NKWindowConfig cfg)
{
cfg.Draw(cfg.win, cfg.ctx, cfg.DrawData);
if (!cfg.Draw(cfg.win, cfg.ctx, cfg.DrawData))
{
return false;
}

int winWidth, winHeight;
SDL_GetWindowSize(cfg.win, &winWidth, &winHeight);
Expand All @@ -154,6 +160,8 @@ static void Draw(const NKWindowConfig cfg)

nk_sdl_render(NK_ANTI_ALIASING_ON);
SDL_GL_SwapWindow(cfg.win);

return true;
}

static void BeforeDrawTex(const GLuint texid);
Expand Down
46 changes: 23 additions & 23 deletions src/cdogsed/nk_window.h
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
/*
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (c) 2019, Cong Xu
All rights reserved.
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (c) 2019-2020 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once

Expand Down Expand Up @@ -68,7 +68,7 @@ typedef struct
color_t BG;
SDL_Surface *Icon;
EventHandlers *Handlers;
void (*Draw)(SDL_Window *, struct nk_context *, void *);
bool (*Draw)(SDL_Window *, struct nk_context *, void *);
void *DrawData;
} NKWindowConfig;
// Note: need to init before initialising textures
Expand Down
10 changes: 8 additions & 2 deletions src/cdogsed/tile_brush.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ typedef struct


static void ResetTexIds(TileBrushData *data);
static void Draw(SDL_Window *win, struct nk_context *ctx, void *data);
static bool Draw(SDL_Window *win, struct nk_context *ctx, void *data);
void TileBrush(
const PicManager *pm, EventHandlers *handlers, CampaignOptions *co,
int *brushIdx)
Expand Down Expand Up @@ -82,13 +82,18 @@ void TileBrush(
CArrayTerminate(&data.texIdsTileClasses);
}
static int DrawTileType(any_t data, any_t key);
static void Draw(SDL_Window *win, struct nk_context *ctx, void *data)
static bool Draw(SDL_Window *win, struct nk_context *ctx, void *data)
{
UNUSED(win);
bool result = true;
TileBrushData *tbData = data;
if (nk_begin(ctx, "", nk_rect(0, 0, WIDTH, HEIGHT), 0))
{
nk_layout_row_dynamic(ctx, ROW_HEIGHT, 5);
if (nk_button_label(ctx, "Close"))
{
result = false;
}
if (nk_button_label(ctx, "Add"))
{
TileClass tc;
Expand Down Expand Up @@ -135,6 +140,7 @@ static void Draw(SDL_Window *win, struct nk_context *ctx, void *data)
}
}
nk_end(ctx);
return result;
}
static void DrawTileClass(
struct nk_context *ctx, const PicManager *pm, const TileClass *tc,
Expand Down

0 comments on commit 8870fa6

Please sign in to comment.