Skip to content

Commit

Permalink
shard creation gump, checkboxes, and other python ui stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
spin committed Nov 5, 2012
1 parent 22e48d4 commit 1c93650
Show file tree
Hide file tree
Showing 23 changed files with 370 additions and 321 deletions.
48 changes: 48 additions & 0 deletions data/gumps/createshard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

from gumps import *
from data import *
import client
import theme

#In case you want to redesign this gump, keep in mind that at this point, you can not
#access any uo data (e.g. art.mul graphics, hues), as the mul files are not loaded yet.
def create(args):
g = GumpMenu("createshard", 400, 300)
g.draggable = False
g.onEnter = createShard
theme.setFont(g)

g.addImage((0, 0), Texture(TextureSource.THEME, "images/background_350x190.png"))

g.addLabel((15, 16), "Name:")
g.addImage((115, 13, 220, 22), Texture(TextureSource.THEME, "images/lineedit_back.png"))
le = g.addLineEdit((120, 15, 215, 20))
le.name = "shardname"

g.addLabel((15, 46), "UO path:")
g.addImage((115, 43, 220, 22), Texture(TextureSource.THEME, "images/lineedit_back.png"))
le = g.addLineEdit((120, 45, 215, 20))
le.name = "uopath"

cb = theme.addCheckbox(g, (15, 80))
cb.name = "highseas"
g.addLabel((35, 80), "High seas")

btnCreate = theme.addPythonButton(g, (30, 150, 130, 25), createShardButton)
btnCreate.text = "Create shard"

btnCancel = theme.addPythonButton(g, (190, 150, 130, 25), cancel)
btnCancel.text = "Cancel"

def createShardButton(btn):
return createShard(btn.gump)

def createShard(gump):
if client.createShard(gump.component("shardname").text, gump.component("uopath").text, gump.component("highseas").checked):
return True
else:
return False

def cancel(_):
# close gump
return True
2 changes: 0 additions & 2 deletions data/gumps/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import theme

def create(args):
theme.themeTest()

g = GumpMenu("login", 337, 289, True)
theme.setFont(g)
g.closable = False
Expand Down
3 changes: 2 additions & 1 deletion data/gumps/shardselection.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def create(args):
btnExit.text = "Exit"

def createShard(button):
print "todo"
client.openGump("createshard")
# don't close the gump, shard creation can be cancelled
return False

def shutdown(button):
Expand Down
8 changes: 4 additions & 4 deletions data/gumps/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ def create(args):
i2.hue = 2

but = g.addPythonButton((10, 10, 100, 60), Texture(TextureSource.THEME, "images/button.png"), onButtonClick)
but.mouseOver.hue = 13
but.mouseDown.rgba = (1.0, 1.0, 0.0)
but.state("mouseOver").hue = 13
but.state("mouseDown").rgba = (1.0, 1.0, 0.0)
but.text = "foooobert"
but.mouseDown.fontRgba = rgba(4)
but.mouseOver.fontRgba = rgba("#00ffff")
but.state("mouseDown").fontRgba = rgba(4)
but.state("mouseOver").fontRgba = rgba("#00ffff")
but.setFont("Arial", 8);
i1.name = "i1"
g.store["i2"] = i2
Expand Down
87 changes: 82 additions & 5 deletions src/fluorescence/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <iostream>
#include <iomanip>
#include <boost/filesystem/fstream.hpp>

#include <misc/config.hpp>
#include <misc/log.hpp>
Expand Down Expand Up @@ -78,11 +79,6 @@ bool Client::shutdown(ui::GumpMenu* menu, const UnicodeString& action, unsigned
return true;
}

bool Client::selectShard(ui::GumpMenu* menu, const UnicodeString& action, unsigned int parameterCount, const UnicodeString* parameters) {
selectShard(parameters[0]);
return true;
}

void Client::selectShard(const UnicodeString& shardName) {
config_.setShardName(shardName);
setState(STATE_PRE_LOGIN);
Expand Down Expand Up @@ -432,4 +428,85 @@ timeval Client::getElapsedTime() const {
return t;
}

bool Client::createShard(const UnicodeString& name, const UnicodeString& pathStr, bool highSeas) {
boost::filesystem::path path(StringConverter::toUtf8String(pathStr));

boost::filesystem::path clientPath = path / "client.exe";
if (!boost::filesystem::exists(clientPath)) {
clientPath = path / "Client.exe";
if (!boost::filesystem::exists(clientPath)) {
LOG_ERROR << "Invalid Ultima Online directory" << std::endl;
ui::GumpMenus::openMessageBox("Invalid Ultima Online directory");
return false;
}
}

boost::filesystem::path shardPath(StringConverter::toUtf8String(name));
shardPath = "shards" / shardPath;
if (boost::filesystem::exists(shardPath)) {
LOG_ERROR << "Shard already exists" << std::endl;
ui::GumpMenus::openMessageBox("Shard already exists");
return false;
}

try {
if (!boost::filesystem::create_directory(shardPath)) {
LOG_ERROR << "Failed to create shard directory: " << std::endl;
ui::GumpMenus::openMessageBox("Failed to create shard directory");
return false;
}
} catch (std::exception& ex) {
LOG_ERROR << "Failed to create shard directory: " << ex.what() << std::endl;
ui::GumpMenus::openMessageBox("Failed to create shard directory");
return false;
}

boost::filesystem::path configPath = shardPath / "config.xml";
boost::filesystem::ofstream configStream(configPath);
if (!configStream) {
LOG_ERROR << "Failed to create shard config file: " << std::endl;
ui::GumpMenus::openMessageBox("Failed to create shard config file");
boost::filesystem::remove(shardPath);
return false;
} else {
configStream << "<?xml version=\"1.0\"?>\n<fluo>\n<files";
if (highSeas) {
configStream << " format=\"mul-hs\"";
}
configStream << ">\n<mul-directory path=\"" << path.string();
configStream << "\" />\n</files>\n</fluo>";
configStream.close();
}

boost::filesystem::path macroPath = shardPath / "macros.xml";
boost::filesystem::ofstream macroStream(macroPath);
if (!macroStream) {
LOG_ERROR << "Failed to create macros file: " << std::endl;
ui::GumpMenus::openMessageBox("Failed to create macros file");
boost::filesystem::remove(shardPath);
return false;
} else {
macroStream << "<?xml version=\"1.0\"?>\n<macros>\n";
macroStream << "<macro key=\"return\">\n\t<command name=\"speechentry\" />\n</macro>\n";
macroStream << "<macro key=\"q\" ctrl=\"true\">\n\t<command name=\"effect\" param=\"countdown\" />\n</macro>\n";
macroStream << "<macro key=\"w\" ctrl=\"true\">\n\t<command name=\"effect\" param=\"badsmell\" />\n</macro>\n";
macroStream << "<macro key=\"e\" ctrl=\"true\">\n\t<command name=\"effect\" param=\"deadlyfog\" />\n</macro>\n";
macroStream << "<macro key=\"r\" ctrl=\"true\">\n\t<command name=\"effect\" param=\"explosion\" />\n</macro>\n";
macroStream << "<macro key=\"t\" ctrl=\"true\">\n\t<command name=\"effect\" param=\"rain\" />\n</macro>\n";
macroStream << "<macro key=\"a\" ctrl=\"true\">\n\t<command name=\"directionlight\" param=\"on\" />\n</macro>\n";
macroStream << "<macro key=\"s\" ctrl=\"true\">\n\t<command name=\"directionlight\" param=\"off\" />\n</macro>\n";
macroStream << "<macro key=\"s\" ctrl=\"true\">\n\t<command name=\"directionlight\" param=\"off\" />\n</macro>\n";
macroStream << "<macro key=\"add\">\n\t<command name=\"zoom\" param=\"in\" />\n</macro>\n";
macroStream << "<macro key=\"subtract\">\n\t<command name=\"zoom\" param=\"out\" />\n</macro>\n";
macroStream << "<macro key=\"multiply\">\n\t<command name=\"zoom\" param=\"reset\" />\n</macro>\n";
macroStream << "<macro key=\"tab\">\n\t<command name=\"togglewarmode\" />\n</macro>\n";
macroStream << "<macro key=\"escape\">\n\t<command name=\"cancel\" />\n</macro>\n";
macroStream << "</macros>";
macroStream.close();
}

selectShard(name);
return true;
}

}
2 changes: 1 addition & 1 deletion src/fluorescence/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ class Client {
unsigned int getState();
void loginComplete(); /// < called when the game window should be displayed => setState(playing)
void selectShard(const UnicodeString& shardName);
bool createShard(const UnicodeString& name, const UnicodeString& path, bool highSeas);

// gump callbacks
bool disconnect(ui::GumpMenu* menu, const UnicodeString& action, unsigned int parameterCount, const UnicodeString* parameters);
bool shutdown(ui::GumpMenu* menu, const UnicodeString& action, unsigned int parameterCount, const UnicodeString* parameters);
bool selectShard(ui::GumpMenu* menu, const UnicodeString& action, unsigned int parameterCount, const UnicodeString* parameters);
bool selectCharacter(ui::GumpMenu* menu, const UnicodeString& action, unsigned int parameterCount, const UnicodeString* parameters);
bool deleteCharacter(ui::GumpMenu* menu, const UnicodeString& action, unsigned int parameterCount, const UnicodeString* parameters);

Expand Down
8 changes: 0 additions & 8 deletions src/fluorescence/ui/components/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,6 @@ void Button::updateState() {
}
}

ImageState* Button::getStateMouseOver() {
return getState("mouseOver");
}

ImageState* Button::getStateMouseDown() {
return getState("mouseDown");
}

Button::ButtonType Button::getButtonType() const {
return type_;
}
Expand Down
3 changes: 0 additions & 3 deletions src/fluorescence/ui/components/button.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ class Button : public Image {
void setFontColor(unsigned int index, const CL_Colorf& color);
void setFontHue(unsigned int index, unsigned int hue);

ImageState* getStateMouseOver();
ImageState* getStateMouseDown();

ButtonType getButtonType() const;
void setButtonType(ButtonType type);

Expand Down
25 changes: 11 additions & 14 deletions src/fluorescence/ui/components/checkbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ namespace fluo {
namespace ui {
namespace components {

Checkbox::Checkbox(CL_GUIComponent* parent) : MultiTextureImage(parent, 4), mouseOver_(false), checked_(false), switchId_(0) {
Checkbox::Checkbox(CL_GUIComponent* parent) : Image(parent, "unchecked"), mouseOver_(false), checked_(false), switchId_(0) {
func_input_pressed().set(this, &Checkbox::onInputPressed);
func_pointer_enter().set(this, &Checkbox::onPointerEnter);
func_pointer_exit().set(this, &Checkbox::onPointerExit);

set_double_click_enabled(false);

set_type_name("checkbox");

updateState();
}

bool Checkbox::onInputPressed(const CL_InputEvent & e) {
Expand All @@ -47,42 +49,37 @@ bool Checkbox::onInputPressed(const CL_InputEvent & e) {

bool Checkbox::onPointerEnter() {
mouseOver_ = true;
updateTexture();
updateState();

return true;
}

bool Checkbox::onPointerExit() {
mouseOver_ = false;
updateTexture();
updateState();

return true;
}

void Checkbox::updateTexture() {
unsigned int idx = calcTextureId();
activateTexture(idx);
}

unsigned int Checkbox::calcTextureId() const {
void Checkbox::updateState() {
if (checked_) {
if (mouseOver_) {
return TEX_INDEX_CHECKED_MOUSEOVER;
setCurrentState("checkedMouseOver");
} else {
return TEX_INDEX_CHECKED;
setCurrentState("checked");
}
} else {
if (mouseOver_) {
return TEX_INDEX_UNCHECKED_MOUSEOVER;
setCurrentState("uncheckedMouseOver");
} else {
return TEX_INDEX_UNCHECKED;
setCurrentState("unchecked");
}
}
}

void Checkbox::setChecked(bool value) {
checked_ = value;
updateTexture();
updateState();
}

bool Checkbox::isChecked() const {
Expand Down
17 changes: 3 additions & 14 deletions src/fluorescence/ui/components/checkbox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,16 @@
#include <boost/shared_ptr.hpp>
#include <ClanLib/Display/Window/input_event.h>

#include "multitextureimage.hpp"
#include "image.hpp"

namespace fluo {
namespace ui {
namespace components {

class Checkbox : public MultiTextureImage {

class Checkbox : public Image {
public:
enum TextureIndex {
TEX_INDEX_UNCHECKED = 0,
TEX_INDEX_UNCHECKED_MOUSEOVER = 1,
TEX_INDEX_CHECKED = 2,
TEX_INDEX_CHECKED_MOUSEOVER = 3,
};

Checkbox(CL_GUIComponent* parent);

void updateTexture();

void setChecked(bool value);
bool isChecked() const;

Expand All @@ -57,10 +47,9 @@ class Checkbox : public MultiTextureImage {

bool mouseOver_;
bool checked_;
void updateState();

unsigned int switchId_;

unsigned int calcTextureId() const;
};

}
Expand Down
4 changes: 2 additions & 2 deletions src/fluorescence/ui/components/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace fluo {
namespace ui {
namespace components {

Image::Image(CL_GUIComponent* parent) : GumpComponent(parent),
Image::Image(CL_GUIComponent* parent, const char* defaultStateName) : GumpComponent(parent),
autoResize_(false), defaultState_(nullptr), overrideGumpFont_(false),
vAlign_(MIDDLE), hAlign_(CENTER) {
func_render().set(this, &Image::render);
Expand All @@ -55,7 +55,7 @@ Image::Image(CL_GUIComponent* parent) : GumpComponent(parent),
comp = comp->get_parent_component();
}

setCurrentState("normal");
setCurrentState(defaultStateName);
}

void Image::render(CL_GraphicContext& gc, const CL_Rect& clipRect) {
Expand Down
2 changes: 1 addition & 1 deletion src/fluorescence/ui/components/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace components {

class Image : public GumpComponent {
public:
Image(CL_GUIComponent* parent);
Image(CL_GUIComponent* parent, const char* defaultStateName = "normal");

void render(CL_GraphicContext& gc, const CL_Rect& clipRect);

Expand Down
Loading

0 comments on commit 1c93650

Please sign in to comment.